# types, errors and size

Every type @filudi/game-sdk exports, what the SDK logs, the browsers it runs in and the 12 kB budget.

## Exported types

Every type is exported from the package root. The IIFE has the same shapes at runtime without the names.

| Type                                                                                                                                                                              | Page                                                                                       |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| `FiludiSdk`                                                                                                                                                                       | The shape of `sdk` and of `window.FiludiSDK`                                               |
| `InitOptions`, `InitResult`, `MockConfig`, `HostName`, `Features`, `Policy`, `AgeBand`                                                                                            | [init](/docs/sdk/init/)                                                                    |
| `AdResult`, `AdsAvailability`                                                                                                                                                     | [ads](/docs/sdk/ads/)                                                                      |
| `SaveRead<T>`, `SaveWrite`                                                                                                                                                        | [save](/docs/sdk/save/)                                                                    |
| `Period`, `LeaderboardEntry`, `SubmitResult`, `TopResult`, `MeResult`                                                                                                             | [leaderboard](/docs/sdk/leaderboard/)                                                      |
| `Player`                                                                                                                                                                          | [player](/docs/sdk/player/)                                                                |
| `TrackProps`                                                                                                                                                                      | [track](/docs/sdk/track/)                                                                  |
| `HostEvents`, `Consent`, `Device`, `Off`                                                                                                                                          | [host events, fullscreen and device](/docs/sdk/events/)                                    |
| `HostExtras`, `CrazygamesExtras`, `PokiExtras`, `PlaygamaExtras`                                                                                                                  | [host extras](/docs/sdk/host/)                                                             |
| `FiludiInit`, `Adapter`, `AdapterContext`, `AdapterEvent`, `AdapterInit`, `AdKind`, `ParentMessage`, `RemoteSaveWrite`, `ScoreSubmission`, `Session`, `SignedScore`, `TrackEvent` | The handshake and the adapter contract, for a hub or a host implementation, not for a game |

<CodePanel title="Typed wrappers">
  <Fragment slot="javascript">
    ```js
    import { sdk, version } from '@filudi/game-sdk';

    console.log(`Filudi SDK ${version}`);
    // Without a bundler: window.FiludiSDK.version
    ```

  </Fragment>
  <Fragment slot="typescript">
    ```ts
    import { sdk, version, type FiludiSdk, type SaveRead } from '@filudi/game-sdk';

    interface MySave { level: number }

    class Platform {
      constructor(private readonly api: FiludiSdk = sdk) {}
      load(): Promise<SaveRead<MySave>> {
        return this.api.save.get<MySave>();
      }
    }
    console.log(`Filudi SDK ${version}`);
    ```

  </Fragment>
</CodePanel>

## Errors and logging

Nothing throws after `init()`. Failures are statuses on the result: `unavailable`, `rejected`, `conflict`,
`too-large`, `error`. The programming errors that throw: a method called before `init()` was called at all,
and `player.get()`, `ads.available()`, `i18n.locale()` or `device()` called before `init()` resolved.

`init({ debug: true })` or `?filudi_debug=1` on the page URL logs every call and every host message to the
console with the prefix `[filudi-sdk]`. Leave it off in a release.

<CodePanel title="Debug logging">
  <Fragment slot="javascript">
    ```js
    await sdk.init({ gameId: 'gloop', debug: location.hostname === 'localhost' });
    ```

  </Fragment>
  <Fragment slot="typescript">
    ```ts
    await sdk.init({ gameId: 'gloop', debug: import.meta.env.DEV });
    ```

  </Fragment>
</CodePanel>

## Browsers and size

Last two versions of Chrome, Firefox, Safari and Edge; iOS 16 and later. Signed scores need
`crypto.subtle`; without it `submit` returns `rejected` with reason `signature` and everything else works.
No `eval`, no `document.write`, no inline script: the SDK runs under the `script-src 'self'` policy of the
bundle route.

Two builds, 12 kB gzipped each on every host path:

- ESM, `dist/index.js`: the core, the filudi adapter and the standalone adapter in the entry; the portal
  adapters and the rich mock as chunks loaded with `import()` when that host is detected.
- IIFE, `dist/filudi-sdk.iife.js`: one file with the core, filudi, standalone and the three portal
  adapters, as `window.FiludiSDK` plus `FiludiSDK.version`. No rich mock: host `mock` behaves as
  standalone.

Each release lists its changes in the package's changelog on npmjs.com. Pin the exact version and read
the changelog before moving.
