diff --git a/dist/esm/definitions.d.ts b/dist/esm/definitions.d.ts index d055414..d4fc256 100644 --- a/dist/esm/definitions.d.ts +++ b/dist/esm/definitions.d.ts @@ -1,155 +1,546 @@ import type { PluginListenerHandle } from '@capacitor/core'; -/** Full-screen ad formats supported by this plugin. Banners and native ads are intentionally not exposed. */ +/** + * Full-screen ad formats supported by this plugin. Banners and native ads are intentionally not exposed. + * + * @since 0.1.0 + */ export type AdFormat = 'rewarded' | 'interstitial'; +/** + * Options for `initialize()`. + * + * @since 0.1.0 + */ export interface InitOptions { - /** LevelPlay app key from the LevelPlay dashboard (one per platform). */ + /** + * LevelPlay app key from the LevelPlay dashboard. Android and iOS apps have different keys. + * + * @since 0.1.0 + */ appKey: string; - /** Optional user id, needed for server-to-server reward callbacks and the Ad Quality user journey. */ + /** + * Optional user id. Needed for server-to-server reward callbacks and the Ad Quality user journey. + * + * @since 0.1.0 + */ userId?: string; /** - * Enable the LevelPlay Integration Test Suite (sets the `is_test_suite=enable` meta data before init). - * Call {@link LevelPlayPlugin.launchTestSuite} after init resolves. Never ship this enabled. + * Enable the LevelPlay Integration Test Suite: sets the `is_test_suite=enable` meta data before init. + * Call `launchTestSuite()` after `initialize` resolves. Never ship this enabled. + * + * @default false + * @since 0.1.0 */ testSuite?: boolean; - /** Turn on mediated ad network debug logs (`setAdaptersDebug`). Development only. */ + /** + * Turn on debug logs of the mediated ad network adapters (`LevelPlay.setAdaptersDebug(true)`). Development only. + * + * @default false + * @since 0.1.0 + */ adaptersDebug?: boolean; /** - * Privacy flags applied right before init (LevelPlay recommends setting them before the SDK starts). - * Same as calling {@link LevelPlayPlugin.setConsent} first. + * Privacy signals applied right before init (LevelPlay recommends setting them before the SDK starts). + * Same as calling `setConsent()` first. + * + * @since 0.1.0 */ consent?: ConsentOptions; } +/** + * Result of `initialize()` and `getSdkVersion()`. + * + * @since 0.1.0 + */ export interface InitResult { - /** Native LevelPlay SDK version, for example `9.6.1`. */ + /** + * Native LevelPlay SDK version, for example `9.6.1`. `web` on the web. + * + * @since 0.1.0 + */ sdkVersion: string; } /** * Privacy signals forwarded to LevelPlay (`LevelPlayPrivacySettings` on Android, `LPMPrivacySettings` on iOS). * Omitted fields are left untouched. + * + * @since 0.1.0 */ export interface ConsentOptions { - /** GDPR: `true` when the user consented to personalised ads / data processing. */ + /** + * GDPR: `true` when the user consented to personalised ads and data processing, `false` when they did not. + * For users in the EEA, UK and Switzerland pass `false` until a consent management platform (CMP) says otherwise. + * + * @since 0.1.0 + */ gdprConsent?: boolean; - /** CCPA / US state privacy: `true` when the user opted OUT of the sale or sharing of personal data. */ + /** + * CCPA and other US state privacy laws: `true` when the user opted OUT of the sale or sharing of personal data + * ("do not sell"), `false` otherwise. + * + * @since 0.1.0 + */ ccpaDoNotSell?: boolean; - /** COPPA: `true` when the user must be treated as a child (child-directed treatment). */ + /** + * COPPA: `true` when the user must be treated as a child (child-directed treatment). + * + * @since 0.1.0 + */ coppa?: boolean; } +/** + * Options for `setMetaData()`. + * + * @since 0.1.0 + */ export interface MetaDataOptions { + /** + * Meta data key, for example `is_deviceid_optout` or a network-specific flag from Unity's docs. + * + * @since 0.1.0 + */ key: string; + /** + * Meta data value, always a string (for example `"true"`). + * + * @since 0.1.0 + */ value: string; } +/** + * Identifies one ad unit. + * + * @since 0.1.0 + */ export interface AdUnitOptions { - /** Ad unit id from the LevelPlay dashboard. */ + /** + * Ad unit id from the LevelPlay dashboard (Ad units page). Android and iOS ad units have different ids. + * + * @since 0.1.0 + */ adUnitId: string; } +/** + * Options for `showRewarded()` and `showInterstitial()`: `adUnitId` (see AdUnitOptions) plus an optional placement. + * + * @since 0.1.0 + */ export interface ShowOptions extends AdUnitOptions { - /** Optional placement name configured in the LevelPlay dashboard (capping / pacing / reward per placement). */ + /** + * Optional placement name configured in the LevelPlay dashboard (capping, pacing and reward per placement). + * Omit it to use the default placement. + * + * @since 0.1.0 + */ placementName?: string; } +/** + * Options for `isReady()`: `adUnitId` (see AdUnitOptions) plus the format. + * + * @since 0.1.0 + */ export interface IsReadyOptions extends AdUnitOptions { + /** + * Format of the ad unit. + * + * @since 0.1.0 + */ format: AdFormat; } +/** + * Result of `isReady()`. + * + * @since 0.1.0 + */ export interface IsReadyResult { + /** + * `true` when a loaded ad can be shown right now. + * + * @since 0.1.0 + */ ready: boolean; } +/** + * The reward of a rewarded ad, as configured in the LevelPlay dashboard (per ad unit or placement). + * + * @since 0.1.0 + */ export interface Reward { + /** + * Name of the reward, for example `Coins`. + * + * @since 0.1.0 + */ name: string; + /** + * Amount of the reward. + * + * @since 0.1.0 + */ amount: number; } +/** + * Error reported by the SDK (load / display failures) or by the plugin. + * + * @since 0.1.0 + */ export interface AdError { + /** + * LevelPlay error code, for example `509` (no fill). `-1` is used by the plugin for "Ad not ready" and for the web + * stub. + * + * @since 0.1.0 + */ code: number; + /** + * Human readable message. + * + * @since 0.1.0 + */ message: string; } -/** Subset of the native `LevelPlayAdInfo` / `LPMAdInfo` that is useful in JavaScript. */ +/** + * Subset of the native `LevelPlayAdInfo` (Android) / `LPMAdInfo` (iOS) that is useful in JavaScript. + * Fields the SDK does not report are omitted. + * + * @since 0.1.0 + */ export interface AdInfo { + /** + * Unique id of this ad. + * + * @since 0.1.0 + */ adId?: string; + /** + * Ad unit id. + * + * @since 0.1.0 + */ adUnitId: string; + /** + * Ad unit name from the dashboard. + * + * @since 0.1.0 + */ adUnitName?: string; + /** + * Ad format as reported by the SDK. + * + * @since 0.1.0 + */ adFormat?: string; + /** + * Placement name of the show call, when one was used. + * + * @since 0.1.0 + */ placementName?: string; + /** + * Name of the mediated network that served the ad. + * + * @since 0.1.0 + */ adNetwork?: string; + /** + * Mediation instance name. + * + * @since 0.1.0 + */ instanceName?: string; + /** + * Mediation instance id. + * + * @since 0.1.0 + */ instanceId?: string; + /** + * Country code of the impression. + * + * @since 0.1.0 + */ country?: string; + /** + * Auction id. + * + * @since 0.1.0 + */ auctionId?: string; - /** Impression revenue in USD as reported by the SDK (may be absent before display). */ + /** + * Impression revenue in USD as reported by the SDK (may be absent or 0 before display). + * + * @since 0.1.0 + */ revenue?: number; + /** + * Revenue precision as reported by the SDK. + * + * @since 0.1.0 + */ precision?: string; } +/** + * Result of `showRewarded()` and `showInterstitial()`, resolved after the ad + * closed or failed to display. + * + * @since 0.1.0 + */ export interface ShowResult { - /** The ad was displayed (`displayed` fired). */ + /** + * The ad was displayed (the `displayed` event fired). + * + * @since 0.1.0 + */ shown: boolean; - /** Rewarded only: the reward callback fired for this show. Grant the reward only when this is true. */ + /** + * Rewarded only: the reward callback fired for this show. Grant the reward only when this is `true`. + * Always `false` for interstitials. + * + * @since 0.1.0 + */ rewarded: boolean; + /** + * The reward, present when `rewarded` is `true`. + * + * @since 0.1.0 + */ reward?: Reward; - /** Present when the ad was not ready or failed to display. */ + /** + * Present when the ad was not ready (`code: -1`) or failed to display. + * + * @since 0.1.0 + */ error?: AdError; + /** + * Info of the displayed ad. + * + * @since 0.1.0 + */ adInfo?: AdInfo; } +/** + * Payload of the `loaded`, `displayed`, `clicked` and `closed` events. + * + * @since 0.1.0 + */ export interface AdEvent { + /** + * Format of the ad unit that fired the event. + * + * @since 0.1.0 + */ format: AdFormat; + /** + * Ad unit that fired the event. + * + * @since 0.1.0 + */ adUnitId: string; + /** + * Ad info, when the SDK provides it (not on `loadFailed`). + * + * @since 0.1.0 + */ adInfo?: AdInfo; } +/** + * Payload of the `loadFailed` and `displayFailed` events: the AdEvent fields plus `error`. + * + * @since 0.1.0 + */ export interface AdErrorEvent extends AdEvent { + /** + * What went wrong. + * + * @since 0.1.0 + */ error: AdError; } +/** + * Payload of the `rewarded` event: the AdEvent fields plus `reward`. + * + * @since 0.1.0 + */ export interface AdRewardEvent extends AdEvent { + /** + * The reward earned. + * + * @since 0.1.0 + */ reward: Reward; } +/** + * iOS App Tracking Transparency status. `unavailable` on Android, on the web and on unknown future iOS values. + * + * @since 0.1.0 + */ export type TrackingStatus = 'authorized' | 'denied' | 'restricted' | 'notDetermined' | 'unavailable'; +/** + * Result of `requestTrackingAuthorization()` and + * `getTrackingAuthorizationStatus()`. + * + * @since 0.1.0 + */ export interface TrackingResult { - /** iOS App Tracking Transparency status. Always `unavailable` on Android and web. */ + /** + * iOS App Tracking Transparency status. Always `unavailable` on Android and web. + * + * @since 0.1.0 + */ status: TrackingStatus; } +/** + * Event names emitted by the plugin. + * + * @since 0.1.0 + */ +export type LevelPlayEventName = 'loaded' | 'loadFailed' | 'displayed' | 'displayFailed' | 'clicked' | 'closed' | 'rewarded'; +/** + * Unity LevelPlay rewarded and interstitial ads (ad-unit API). + * + * @since 0.1.0 + */ export interface LevelPlayPlugin { /** - * Initialise the LevelPlay SDK. Resolves on `onInitSuccess`, rejects with the init error otherwise. - * Calling it again after a successful init resolves immediately. Load ads only after this resolves. + * Initialise the LevelPlay SDK (`LevelPlay.init`). Resolves on init success, rejects with the init error + * (code and message from the SDK) otherwise. Calling it again after a successful init resolves immediately; + * concurrent calls share one init. Load ads only after this resolves. + * + * Set consent (and on iOS ask for ATT) before calling it. + * + * On the web it rejects as unimplemented. + * + * @since 0.1.0 */ initialize(options: InitOptions): Promise; - /** Native SDK version (available before init). */ + /** + * Native LevelPlay SDK version. Works before init. + * + * @since 0.1.0 + */ getSdkVersion(): Promise; - /** Forward GDPR / CCPA / COPPA signals. Call before {@link initialize} when you can. */ + /** + * Forward GDPR / CCPA / COPPA signals to LevelPlay. Call it before `initialize()` when you + * can, and again whenever the user changes their choice. + * + * @since 0.1.0 + */ setConsent(options: ConsentOptions): Promise; - /** Raw `LevelPlay.setMetaData(key, value)` for network-specific flags. Call before init. */ + /** + * Raw `LevelPlay.setMetaData(key, value)` for SDK or network-specific flags. Call it before init. + * + * @since 0.1.0 + */ setMetaData(options: MetaDataOptions): Promise; /** - * iOS: show the App Tracking Transparency prompt (needs `NSUserTrackingUsageDescription` in Info.plist) and resolve - * with the resulting status. Call it before {@link initialize}. Android / web: resolves `unavailable`. + * iOS: show the App Tracking Transparency prompt and resolve with the resulting status. Needs + * `NSUserTrackingUsageDescription` in `Info.plist`. iOS only shows the prompt once; later calls resolve the stored + * status. Call it before `initialize()`, while the app is active. + * + * Android and web: resolves `unavailable`. + * + * @since 0.1.0 */ requestTrackingAuthorization(): Promise; - /** Current ATT status without prompting (iOS). Android / web: `unavailable`. */ + /** + * Current App Tracking Transparency status without prompting (iOS). Android and web: `unavailable`. + * + * @since 0.1.0 + */ getTrackingAuthorizationStatus(): Promise; /** - * Start loading a rewarded ad for the ad unit (the ad object is created on first use and reused). - * Resolves once the request is issued; the outcome arrives as `loaded` / `loadFailed` events. + * Start loading a rewarded ad for the ad unit. The native ad object is created on first use and reused for the + * ad unit. Resolves once the request is issued; the outcome arrives as a `loaded` or `loadFailed` event. + * Load the next ad after each show. + * + * @since 0.1.0 */ loadRewarded(options: AdUnitOptions): Promise; /** - * Show a loaded rewarded ad. Resolves after the ad closes (or failed to display) with what happened. - * Never rejects for "not ready": resolves `{ shown: false, error }` instead. + * Show a loaded rewarded ad. Resolves after the ad closed (or failed to display) with what happened. The reward + * and close callbacks can arrive in either order on some networks, so the plugin waits up to 1 second after the close + * for a late reward. Never rejects for "not ready": resolves `{ shown: false, rewarded: false, error }` instead. + * + * @since 0.1.0 */ showRewarded(options: ShowOptions): Promise; - /** Start loading an interstitial ad (see {@link loadRewarded}). */ + /** + * Start loading an interstitial ad for the ad unit. Works like `loadRewarded()`. + * + * @since 0.1.0 + */ loadInterstitial(options: AdUnitOptions): Promise; - /** Show a loaded interstitial. Resolves after it closes (or failed to display). */ + /** + * Show a loaded interstitial. Resolves after it closed (or failed to display). Never rejects for "not ready". + * + * @since 0.1.0 + */ showInterstitial(options: ShowOptions): Promise; - /** `isAdReady()` of the ad object for this ad unit (`false` when it was never loaded). */ + /** + * `isAdReady()` of the native ad object for this ad unit. `false` when the ad unit was never loaded. + * + * @since 0.1.0 + */ isReady(options: IsReadyOptions): Promise; - /** Open the LevelPlay Integration Test Suite. Requires `initialize({ testSuite: true })` first. */ + /** + * Open the LevelPlay Integration Test Suite. Requires `initialize({ testSuite: true })` first. + * Development builds only. Rejects on the web. + * + * @since 0.1.0 + */ launchTestSuite(): Promise; - /** Log the LevelPlay integration helper report to the native console (development only). */ + /** + * Write the LevelPlay integration helper report to the native log (Xcode console; Android logcat tag + * `IntegrationHelper`): SDK, adapter and network SDK versions, each `VERIFIED` or not. Development only. + * + * @since 0.1.0 + */ validateIntegration(): Promise; + /** + * An ad finished loading for the ad unit and can be shown. + * + * @since 0.1.0 + */ addListener(eventName: 'loaded', listenerFunc: (event: AdEvent) => void): Promise; + /** + * Loading failed, for example `509` (no fill). Retry later with a backoff. + * + * @since 0.1.0 + */ addListener(eventName: 'loadFailed', listenerFunc: (event: AdErrorEvent) => void): Promise; + /** + * The ad was displayed (impression). `adInfo.revenue` is available here. + * + * @since 0.1.0 + */ addListener(eventName: 'displayed', listenerFunc: (event: AdEvent) => void): Promise; + /** + * The ad failed to display. The pending show call resolves with the same error. + * + * @since 0.1.0 + */ addListener(eventName: 'displayFailed', listenerFunc: (event: AdErrorEvent) => void): Promise; + /** + * The user clicked the ad. + * + * @since 0.1.0 + */ addListener(eventName: 'clicked', listenerFunc: (event: AdEvent) => void): Promise; + /** + * The ad was closed and the app is back in front. + * + * @since 0.1.0 + */ addListener(eventName: 'closed', listenerFunc: (event: AdEvent) => void): Promise; + /** + * Rewarded only: the user earned the reward. Can fire before or after `closed`. + * + * @since 0.1.0 + */ addListener(eventName: 'rewarded', listenerFunc: (event: AdRewardEvent) => void): Promise; + /** + * Remove every listener of this plugin. + * + * @since 0.1.0 + */ removeAllListeners(): Promise; } -/** Event names emitted by the plugin. */ -export type LevelPlayEventName = 'loaded' | 'loadFailed' | 'displayed' | 'displayFailed' | 'clicked' | 'closed' | 'rewarded'; diff --git a/dist/esm/definitions.js.map b/dist/esm/definitions.js.map index 2344ece..6064034 100644 --- a/dist/esm/definitions.js.map +++ b/dist/esm/definitions.js.map @@ -1 +1 @@ -{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/** Full-screen ad formats supported by this plugin. Banners and native ads are intentionally not exposed. */\nexport type AdFormat = 'rewarded' | 'interstitial';\n\nexport interface InitOptions {\n /** LevelPlay app key from the LevelPlay dashboard (one per platform). */\n appKey: string;\n /** Optional user id, needed for server-to-server reward callbacks and the Ad Quality user journey. */\n userId?: string;\n /**\n * Enable the LevelPlay Integration Test Suite (sets the `is_test_suite=enable` meta data before init).\n * Call {@link LevelPlayPlugin.launchTestSuite} after init resolves. Never ship this enabled.\n */\n testSuite?: boolean;\n /** Turn on mediated ad network debug logs (`setAdaptersDebug`). Development only. */\n adaptersDebug?: boolean;\n /**\n * Privacy flags applied right before init (LevelPlay recommends setting them before the SDK starts).\n * Same as calling {@link LevelPlayPlugin.setConsent} first.\n */\n consent?: ConsentOptions;\n}\n\nexport interface InitResult {\n /** Native LevelPlay SDK version, for example `9.6.1`. */\n sdkVersion: string;\n}\n\n/**\n * Privacy signals forwarded to LevelPlay (`LevelPlayPrivacySettings` on Android, `LPMPrivacySettings` on iOS).\n * Omitted fields are left untouched.\n */\nexport interface ConsentOptions {\n /** GDPR: `true` when the user consented to personalised ads / data processing. */\n gdprConsent?: boolean;\n /** CCPA / US state privacy: `true` when the user opted OUT of the sale or sharing of personal data. */\n ccpaDoNotSell?: boolean;\n /** COPPA: `true` when the user must be treated as a child (child-directed treatment). */\n coppa?: boolean;\n}\n\nexport interface MetaDataOptions {\n key: string;\n value: string;\n}\n\nexport interface AdUnitOptions {\n /** Ad unit id from the LevelPlay dashboard. */\n adUnitId: string;\n}\n\nexport interface ShowOptions extends AdUnitOptions {\n /** Optional placement name configured in the LevelPlay dashboard (capping / pacing / reward per placement). */\n placementName?: string;\n}\n\nexport interface IsReadyOptions extends AdUnitOptions {\n format: AdFormat;\n}\n\nexport interface IsReadyResult {\n ready: boolean;\n}\n\nexport interface Reward {\n name: string;\n amount: number;\n}\n\nexport interface AdError {\n code: number;\n message: string;\n}\n\n/** Subset of the native `LevelPlayAdInfo` / `LPMAdInfo` that is useful in JavaScript. */\nexport interface AdInfo {\n adId?: string;\n adUnitId: string;\n adUnitName?: string;\n adFormat?: string;\n placementName?: string;\n adNetwork?: string;\n instanceName?: string;\n instanceId?: string;\n country?: string;\n auctionId?: string;\n /** Impression revenue in USD as reported by the SDK (may be absent before display). */\n revenue?: number;\n precision?: string;\n}\n\nexport interface ShowResult {\n /** The ad was displayed (`displayed` fired). */\n shown: boolean;\n /** Rewarded only: the reward callback fired for this show. Grant the reward only when this is true. */\n rewarded: boolean;\n reward?: Reward;\n /** Present when the ad was not ready or failed to display. */\n error?: AdError;\n adInfo?: AdInfo;\n}\n\nexport interface AdEvent {\n format: AdFormat;\n adUnitId: string;\n adInfo?: AdInfo;\n}\n\nexport interface AdErrorEvent extends AdEvent {\n error: AdError;\n}\n\nexport interface AdRewardEvent extends AdEvent {\n reward: Reward;\n}\n\nexport type TrackingStatus = 'authorized' | 'denied' | 'restricted' | 'notDetermined' | 'unavailable';\n\nexport interface TrackingResult {\n /** iOS App Tracking Transparency status. Always `unavailable` on Android and web. */\n status: TrackingStatus;\n}\n\nexport interface LevelPlayPlugin {\n /**\n * Initialise the LevelPlay SDK. Resolves on `onInitSuccess`, rejects with the init error otherwise.\n * Calling it again after a successful init resolves immediately. Load ads only after this resolves.\n */\n initialize(options: InitOptions): Promise;\n\n /** Native SDK version (available before init). */\n getSdkVersion(): Promise;\n\n /** Forward GDPR / CCPA / COPPA signals. Call before {@link initialize} when you can. */\n setConsent(options: ConsentOptions): Promise;\n\n /** Raw `LevelPlay.setMetaData(key, value)` for network-specific flags. Call before init. */\n setMetaData(options: MetaDataOptions): Promise;\n\n /**\n * iOS: show the App Tracking Transparency prompt (needs `NSUserTrackingUsageDescription` in Info.plist) and resolve\n * with the resulting status. Call it before {@link initialize}. Android / web: resolves `unavailable`.\n */\n requestTrackingAuthorization(): Promise;\n\n /** Current ATT status without prompting (iOS). Android / web: `unavailable`. */\n getTrackingAuthorizationStatus(): Promise;\n\n /**\n * Start loading a rewarded ad for the ad unit (the ad object is created on first use and reused).\n * Resolves once the request is issued; the outcome arrives as `loaded` / `loadFailed` events.\n */\n loadRewarded(options: AdUnitOptions): Promise;\n\n /**\n * Show a loaded rewarded ad. Resolves after the ad closes (or failed to display) with what happened.\n * Never rejects for \"not ready\": resolves `{ shown: false, error }` instead.\n */\n showRewarded(options: ShowOptions): Promise;\n\n /** Start loading an interstitial ad (see {@link loadRewarded}). */\n loadInterstitial(options: AdUnitOptions): Promise;\n\n /** Show a loaded interstitial. Resolves after it closes (or failed to display). */\n showInterstitial(options: ShowOptions): Promise;\n\n /** `isAdReady()` of the ad object for this ad unit (`false` when it was never loaded). */\n isReady(options: IsReadyOptions): Promise;\n\n /** Open the LevelPlay Integration Test Suite. Requires `initialize({ testSuite: true })` first. */\n launchTestSuite(): Promise;\n\n /** Log the LevelPlay integration helper report to the native console (development only). */\n validateIntegration(): Promise;\n\n addListener(eventName: 'loaded', listenerFunc: (event: AdEvent) => void): Promise;\n addListener(eventName: 'loadFailed', listenerFunc: (event: AdErrorEvent) => void): Promise;\n addListener(eventName: 'displayed', listenerFunc: (event: AdEvent) => void): Promise;\n addListener(eventName: 'displayFailed', listenerFunc: (event: AdErrorEvent) => void): Promise;\n addListener(eventName: 'clicked', listenerFunc: (event: AdEvent) => void): Promise;\n addListener(eventName: 'closed', listenerFunc: (event: AdEvent) => void): Promise;\n addListener(eventName: 'rewarded', listenerFunc: (event: AdRewardEvent) => void): Promise;\n\n removeAllListeners(): Promise;\n}\n\n/** Event names emitted by the plugin. */\nexport type LevelPlayEventName = 'loaded' | 'loadFailed' | 'displayed' | 'displayFailed' | 'clicked' | 'closed' | 'rewarded';\n"]} \ No newline at end of file +{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * Full-screen ad formats supported by this plugin. Banners and native ads are intentionally not exposed.\n *\n * @since 0.1.0\n */\nexport type AdFormat = 'rewarded' | 'interstitial';\n\n/**\n * Options for `initialize()`.\n *\n * @since 0.1.0\n */\nexport interface InitOptions {\n /**\n * LevelPlay app key from the LevelPlay dashboard. Android and iOS apps have different keys.\n *\n * @since 0.1.0\n */\n appKey: string;\n /**\n * Optional user id. Needed for server-to-server reward callbacks and the Ad Quality user journey.\n *\n * @since 0.1.0\n */\n userId?: string;\n /**\n * Enable the LevelPlay Integration Test Suite: sets the `is_test_suite=enable` meta data before init.\n * Call `launchTestSuite()` after `initialize` resolves. Never ship this enabled.\n *\n * @default false\n * @since 0.1.0\n */\n testSuite?: boolean;\n /**\n * Turn on debug logs of the mediated ad network adapters (`LevelPlay.setAdaptersDebug(true)`). Development only.\n *\n * @default false\n * @since 0.1.0\n */\n adaptersDebug?: boolean;\n /**\n * Privacy signals applied right before init (LevelPlay recommends setting them before the SDK starts).\n * Same as calling `setConsent()` first.\n *\n * @since 0.1.0\n */\n consent?: ConsentOptions;\n}\n\n/**\n * Result of `initialize()` and `getSdkVersion()`.\n *\n * @since 0.1.0\n */\nexport interface InitResult {\n /**\n * Native LevelPlay SDK version, for example `9.6.1`. `web` on the web.\n *\n * @since 0.1.0\n */\n sdkVersion: string;\n}\n\n/**\n * Privacy signals forwarded to LevelPlay (`LevelPlayPrivacySettings` on Android, `LPMPrivacySettings` on iOS).\n * Omitted fields are left untouched.\n *\n * @since 0.1.0\n */\nexport interface ConsentOptions {\n /**\n * GDPR: `true` when the user consented to personalised ads and data processing, `false` when they did not.\n * For users in the EEA, UK and Switzerland pass `false` until a consent management platform (CMP) says otherwise.\n *\n * @since 0.1.0\n */\n gdprConsent?: boolean;\n /**\n * CCPA and other US state privacy laws: `true` when the user opted OUT of the sale or sharing of personal data\n * (\"do not sell\"), `false` otherwise.\n *\n * @since 0.1.0\n */\n ccpaDoNotSell?: boolean;\n /**\n * COPPA: `true` when the user must be treated as a child (child-directed treatment).\n *\n * @since 0.1.0\n */\n coppa?: boolean;\n}\n\n/**\n * Options for `setMetaData()`.\n *\n * @since 0.1.0\n */\nexport interface MetaDataOptions {\n /**\n * Meta data key, for example `is_deviceid_optout` or a network-specific flag from Unity's docs.\n *\n * @since 0.1.0\n */\n key: string;\n /**\n * Meta data value, always a string (for example `\"true\"`).\n *\n * @since 0.1.0\n */\n value: string;\n}\n\n/**\n * Identifies one ad unit.\n *\n * @since 0.1.0\n */\nexport interface AdUnitOptions {\n /**\n * Ad unit id from the LevelPlay dashboard (Ad units page). Android and iOS ad units have different ids.\n *\n * @since 0.1.0\n */\n adUnitId: string;\n}\n\n/**\n * Options for `showRewarded()` and `showInterstitial()`: `adUnitId` (see AdUnitOptions) plus an optional placement.\n *\n * @since 0.1.0\n */\nexport interface ShowOptions extends AdUnitOptions {\n /**\n * Optional placement name configured in the LevelPlay dashboard (capping, pacing and reward per placement).\n * Omit it to use the default placement.\n *\n * @since 0.1.0\n */\n placementName?: string;\n}\n\n/**\n * Options for `isReady()`: `adUnitId` (see AdUnitOptions) plus the format.\n *\n * @since 0.1.0\n */\nexport interface IsReadyOptions extends AdUnitOptions {\n /**\n * Format of the ad unit.\n *\n * @since 0.1.0\n */\n format: AdFormat;\n}\n\n/**\n * Result of `isReady()`.\n *\n * @since 0.1.0\n */\nexport interface IsReadyResult {\n /**\n * `true` when a loaded ad can be shown right now.\n *\n * @since 0.1.0\n */\n ready: boolean;\n}\n\n/**\n * The reward of a rewarded ad, as configured in the LevelPlay dashboard (per ad unit or placement).\n *\n * @since 0.1.0\n */\nexport interface Reward {\n /**\n * Name of the reward, for example `Coins`.\n *\n * @since 0.1.0\n */\n name: string;\n /**\n * Amount of the reward.\n *\n * @since 0.1.0\n */\n amount: number;\n}\n\n/**\n * Error reported by the SDK (load / display failures) or by the plugin.\n *\n * @since 0.1.0\n */\nexport interface AdError {\n /**\n * LevelPlay error code, for example `509` (no fill). `-1` is used by the plugin for \"Ad not ready\" and for the web\n * stub.\n *\n * @since 0.1.0\n */\n code: number;\n /**\n * Human readable message.\n *\n * @since 0.1.0\n */\n message: string;\n}\n\n/**\n * Subset of the native `LevelPlayAdInfo` (Android) / `LPMAdInfo` (iOS) that is useful in JavaScript.\n * Fields the SDK does not report are omitted.\n *\n * @since 0.1.0\n */\nexport interface AdInfo {\n /**\n * Unique id of this ad.\n *\n * @since 0.1.0\n */\n adId?: string;\n /**\n * Ad unit id.\n *\n * @since 0.1.0\n */\n adUnitId: string;\n /**\n * Ad unit name from the dashboard.\n *\n * @since 0.1.0\n */\n adUnitName?: string;\n /**\n * Ad format as reported by the SDK.\n *\n * @since 0.1.0\n */\n adFormat?: string;\n /**\n * Placement name of the show call, when one was used.\n *\n * @since 0.1.0\n */\n placementName?: string;\n /**\n * Name of the mediated network that served the ad.\n *\n * @since 0.1.0\n */\n adNetwork?: string;\n /**\n * Mediation instance name.\n *\n * @since 0.1.0\n */\n instanceName?: string;\n /**\n * Mediation instance id.\n *\n * @since 0.1.0\n */\n instanceId?: string;\n /**\n * Country code of the impression.\n *\n * @since 0.1.0\n */\n country?: string;\n /**\n * Auction id.\n *\n * @since 0.1.0\n */\n auctionId?: string;\n /**\n * Impression revenue in USD as reported by the SDK (may be absent or 0 before display).\n *\n * @since 0.1.0\n */\n revenue?: number;\n /**\n * Revenue precision as reported by the SDK.\n *\n * @since 0.1.0\n */\n precision?: string;\n}\n\n/**\n * Result of `showRewarded()` and `showInterstitial()`, resolved after the ad\n * closed or failed to display.\n *\n * @since 0.1.0\n */\nexport interface ShowResult {\n /**\n * The ad was displayed (the `displayed` event fired).\n *\n * @since 0.1.0\n */\n shown: boolean;\n /**\n * Rewarded only: the reward callback fired for this show. Grant the reward only when this is `true`.\n * Always `false` for interstitials.\n *\n * @since 0.1.0\n */\n rewarded: boolean;\n /**\n * The reward, present when `rewarded` is `true`.\n *\n * @since 0.1.0\n */\n reward?: Reward;\n /**\n * Present when the ad was not ready (`code: -1`) or failed to display.\n *\n * @since 0.1.0\n */\n error?: AdError;\n /**\n * Info of the displayed ad.\n *\n * @since 0.1.0\n */\n adInfo?: AdInfo;\n}\n\n/**\n * Payload of the `loaded`, `displayed`, `clicked` and `closed` events.\n *\n * @since 0.1.0\n */\nexport interface AdEvent {\n /**\n * Format of the ad unit that fired the event.\n *\n * @since 0.1.0\n */\n format: AdFormat;\n /**\n * Ad unit that fired the event.\n *\n * @since 0.1.0\n */\n adUnitId: string;\n /**\n * Ad info, when the SDK provides it (not on `loadFailed`).\n *\n * @since 0.1.0\n */\n adInfo?: AdInfo;\n}\n\n/**\n * Payload of the `loadFailed` and `displayFailed` events: the AdEvent fields plus `error`.\n *\n * @since 0.1.0\n */\nexport interface AdErrorEvent extends AdEvent {\n /**\n * What went wrong.\n *\n * @since 0.1.0\n */\n error: AdError;\n}\n\n/**\n * Payload of the `rewarded` event: the AdEvent fields plus `reward`.\n *\n * @since 0.1.0\n */\nexport interface AdRewardEvent extends AdEvent {\n /**\n * The reward earned.\n *\n * @since 0.1.0\n */\n reward: Reward;\n}\n\n/**\n * iOS App Tracking Transparency status. `unavailable` on Android, on the web and on unknown future iOS values.\n *\n * @since 0.1.0\n */\nexport type TrackingStatus = 'authorized' | 'denied' | 'restricted' | 'notDetermined' | 'unavailable';\n\n/**\n * Result of `requestTrackingAuthorization()` and\n * `getTrackingAuthorizationStatus()`.\n *\n * @since 0.1.0\n */\nexport interface TrackingResult {\n /**\n * iOS App Tracking Transparency status. Always `unavailable` on Android and web.\n *\n * @since 0.1.0\n */\n status: TrackingStatus;\n}\n\n/**\n * Event names emitted by the plugin.\n *\n * @since 0.1.0\n */\nexport type LevelPlayEventName =\n | 'loaded'\n | 'loadFailed'\n | 'displayed'\n | 'displayFailed'\n | 'clicked'\n | 'closed'\n | 'rewarded';\n\n/**\n * Unity LevelPlay rewarded and interstitial ads (ad-unit API).\n *\n * @since 0.1.0\n */\nexport interface LevelPlayPlugin {\n /**\n * Initialise the LevelPlay SDK (`LevelPlay.init`). Resolves on init success, rejects with the init error\n * (code and message from the SDK) otherwise. Calling it again after a successful init resolves immediately;\n * concurrent calls share one init. Load ads only after this resolves.\n *\n * Set consent (and on iOS ask for ATT) before calling it.\n *\n * On the web it rejects as unimplemented.\n *\n * @since 0.1.0\n */\n initialize(options: InitOptions): Promise;\n\n /**\n * Native LevelPlay SDK version. Works before init.\n *\n * @since 0.1.0\n */\n getSdkVersion(): Promise;\n\n /**\n * Forward GDPR / CCPA / COPPA signals to LevelPlay. Call it before `initialize()` when you\n * can, and again whenever the user changes their choice.\n *\n * @since 0.1.0\n */\n setConsent(options: ConsentOptions): Promise;\n\n /**\n * Raw `LevelPlay.setMetaData(key, value)` for SDK or network-specific flags. Call it before init.\n *\n * @since 0.1.0\n */\n setMetaData(options: MetaDataOptions): Promise;\n\n /**\n * iOS: show the App Tracking Transparency prompt and resolve with the resulting status. Needs\n * `NSUserTrackingUsageDescription` in `Info.plist`. iOS only shows the prompt once; later calls resolve the stored\n * status. Call it before `initialize()`, while the app is active.\n *\n * Android and web: resolves `unavailable`.\n *\n * @since 0.1.0\n */\n requestTrackingAuthorization(): Promise;\n\n /**\n * Current App Tracking Transparency status without prompting (iOS). Android and web: `unavailable`.\n *\n * @since 0.1.0\n */\n getTrackingAuthorizationStatus(): Promise;\n\n /**\n * Start loading a rewarded ad for the ad unit. The native ad object is created on first use and reused for the\n * ad unit. Resolves once the request is issued; the outcome arrives as a `loaded` or `loadFailed` event.\n * Load the next ad after each show.\n *\n * @since 0.1.0\n */\n loadRewarded(options: AdUnitOptions): Promise;\n\n /**\n * Show a loaded rewarded ad. Resolves after the ad closed (or failed to display) with what happened. The reward\n * and close callbacks can arrive in either order on some networks, so the plugin waits up to 1 second after the close\n * for a late reward. Never rejects for \"not ready\": resolves `{ shown: false, rewarded: false, error }` instead.\n *\n * @since 0.1.0\n */\n showRewarded(options: ShowOptions): Promise;\n\n /**\n * Start loading an interstitial ad for the ad unit. Works like `loadRewarded()`.\n *\n * @since 0.1.0\n */\n loadInterstitial(options: AdUnitOptions): Promise;\n\n /**\n * Show a loaded interstitial. Resolves after it closed (or failed to display). Never rejects for \"not ready\".\n *\n * @since 0.1.0\n */\n showInterstitial(options: ShowOptions): Promise;\n\n /**\n * `isAdReady()` of the native ad object for this ad unit. `false` when the ad unit was never loaded.\n *\n * @since 0.1.0\n */\n isReady(options: IsReadyOptions): Promise;\n\n /**\n * Open the LevelPlay Integration Test Suite. Requires `initialize({ testSuite: true })` first.\n * Development builds only. Rejects on the web.\n *\n * @since 0.1.0\n */\n launchTestSuite(): Promise;\n\n /**\n * Write the LevelPlay integration helper report to the native log (Xcode console; Android logcat tag\n * `IntegrationHelper`): SDK, adapter and network SDK versions, each `VERIFIED` or not. Development only.\n *\n * @since 0.1.0\n */\n validateIntegration(): Promise;\n\n /**\n * An ad finished loading for the ad unit and can be shown.\n *\n * @since 0.1.0\n */\n addListener(eventName: 'loaded', listenerFunc: (event: AdEvent) => void): Promise;\n\n /**\n * Loading failed, for example `509` (no fill). Retry later with a backoff.\n *\n * @since 0.1.0\n */\n addListener(eventName: 'loadFailed', listenerFunc: (event: AdErrorEvent) => void): Promise;\n\n /**\n * The ad was displayed (impression). `adInfo.revenue` is available here.\n *\n * @since 0.1.0\n */\n addListener(eventName: 'displayed', listenerFunc: (event: AdEvent) => void): Promise;\n\n /**\n * The ad failed to display. The pending show call resolves with the same error.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'displayFailed',\n listenerFunc: (event: AdErrorEvent) => void,\n ): Promise;\n\n /**\n * The user clicked the ad.\n *\n * @since 0.1.0\n */\n addListener(eventName: 'clicked', listenerFunc: (event: AdEvent) => void): Promise;\n\n /**\n * The ad was closed and the app is back in front.\n *\n * @since 0.1.0\n */\n addListener(eventName: 'closed', listenerFunc: (event: AdEvent) => void): Promise;\n\n /**\n * Rewarded only: the user earned the reward. Can fire before or after `closed`.\n *\n * @since 0.1.0\n */\n addListener(eventName: 'rewarded', listenerFunc: (event: AdRewardEvent) => void): Promise;\n\n /**\n * Remove every listener of this plugin.\n *\n * @since 0.1.0\n */\n removeAllListeners(): Promise;\n}\n"]} \ No newline at end of file diff --git a/src/definitions.ts b/src/definitions.ts index 8a9063b..f4a8b85 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -1,189 +1,596 @@ import type { PluginListenerHandle } from '@capacitor/core'; -/** Full-screen ad formats supported by this plugin. Banners and native ads are intentionally not exposed. */ +/** + * Full-screen ad formats supported by this plugin. Banners and native ads are intentionally not exposed. + * + * @since 0.1.0 + */ export type AdFormat = 'rewarded' | 'interstitial'; +/** + * Options for `initialize()`. + * + * @since 0.1.0 + */ export interface InitOptions { - /** LevelPlay app key from the LevelPlay dashboard (one per platform). */ + /** + * LevelPlay app key from the LevelPlay dashboard. Android and iOS apps have different keys. + * + * @since 0.1.0 + */ appKey: string; - /** Optional user id, needed for server-to-server reward callbacks and the Ad Quality user journey. */ + /** + * Optional user id. Needed for server-to-server reward callbacks and the Ad Quality user journey. + * + * @since 0.1.0 + */ userId?: string; /** - * Enable the LevelPlay Integration Test Suite (sets the `is_test_suite=enable` meta data before init). - * Call {@link LevelPlayPlugin.launchTestSuite} after init resolves. Never ship this enabled. + * Enable the LevelPlay Integration Test Suite: sets the `is_test_suite=enable` meta data before init. + * Call `launchTestSuite()` after `initialize` resolves. Never ship this enabled. + * + * @default false + * @since 0.1.0 */ testSuite?: boolean; - /** Turn on mediated ad network debug logs (`setAdaptersDebug`). Development only. */ + /** + * Turn on debug logs of the mediated ad network adapters (`LevelPlay.setAdaptersDebug(true)`). Development only. + * + * @default false + * @since 0.1.0 + */ adaptersDebug?: boolean; /** - * Privacy flags applied right before init (LevelPlay recommends setting them before the SDK starts). - * Same as calling {@link LevelPlayPlugin.setConsent} first. + * Privacy signals applied right before init (LevelPlay recommends setting them before the SDK starts). + * Same as calling `setConsent()` first. + * + * @since 0.1.0 */ consent?: ConsentOptions; } +/** + * Result of `initialize()` and `getSdkVersion()`. + * + * @since 0.1.0 + */ export interface InitResult { - /** Native LevelPlay SDK version, for example `9.6.1`. */ + /** + * Native LevelPlay SDK version, for example `9.6.1`. `web` on the web. + * + * @since 0.1.0 + */ sdkVersion: string; } /** * Privacy signals forwarded to LevelPlay (`LevelPlayPrivacySettings` on Android, `LPMPrivacySettings` on iOS). * Omitted fields are left untouched. + * + * @since 0.1.0 */ export interface ConsentOptions { - /** GDPR: `true` when the user consented to personalised ads / data processing. */ + /** + * GDPR: `true` when the user consented to personalised ads and data processing, `false` when they did not. + * For users in the EEA, UK and Switzerland pass `false` until a consent management platform (CMP) says otherwise. + * + * @since 0.1.0 + */ gdprConsent?: boolean; - /** CCPA / US state privacy: `true` when the user opted OUT of the sale or sharing of personal data. */ + /** + * CCPA and other US state privacy laws: `true` when the user opted OUT of the sale or sharing of personal data + * ("do not sell"), `false` otherwise. + * + * @since 0.1.0 + */ ccpaDoNotSell?: boolean; - /** COPPA: `true` when the user must be treated as a child (child-directed treatment). */ + /** + * COPPA: `true` when the user must be treated as a child (child-directed treatment). + * + * @since 0.1.0 + */ coppa?: boolean; } +/** + * Options for `setMetaData()`. + * + * @since 0.1.0 + */ export interface MetaDataOptions { + /** + * Meta data key, for example `is_deviceid_optout` or a network-specific flag from Unity's docs. + * + * @since 0.1.0 + */ key: string; + /** + * Meta data value, always a string (for example `"true"`). + * + * @since 0.1.0 + */ value: string; } +/** + * Identifies one ad unit. + * + * @since 0.1.0 + */ export interface AdUnitOptions { - /** Ad unit id from the LevelPlay dashboard. */ + /** + * Ad unit id from the LevelPlay dashboard (Ad units page). Android and iOS ad units have different ids. + * + * @since 0.1.0 + */ adUnitId: string; } +/** + * Options for `showRewarded()` and `showInterstitial()`: `adUnitId` (see AdUnitOptions) plus an optional placement. + * + * @since 0.1.0 + */ export interface ShowOptions extends AdUnitOptions { - /** Optional placement name configured in the LevelPlay dashboard (capping / pacing / reward per placement). */ + /** + * Optional placement name configured in the LevelPlay dashboard (capping, pacing and reward per placement). + * Omit it to use the default placement. + * + * @since 0.1.0 + */ placementName?: string; } +/** + * Options for `isReady()`: `adUnitId` (see AdUnitOptions) plus the format. + * + * @since 0.1.0 + */ export interface IsReadyOptions extends AdUnitOptions { + /** + * Format of the ad unit. + * + * @since 0.1.0 + */ format: AdFormat; } +/** + * Result of `isReady()`. + * + * @since 0.1.0 + */ export interface IsReadyResult { + /** + * `true` when a loaded ad can be shown right now. + * + * @since 0.1.0 + */ ready: boolean; } +/** + * The reward of a rewarded ad, as configured in the LevelPlay dashboard (per ad unit or placement). + * + * @since 0.1.0 + */ export interface Reward { + /** + * Name of the reward, for example `Coins`. + * + * @since 0.1.0 + */ name: string; + /** + * Amount of the reward. + * + * @since 0.1.0 + */ amount: number; } +/** + * Error reported by the SDK (load / display failures) or by the plugin. + * + * @since 0.1.0 + */ export interface AdError { + /** + * LevelPlay error code, for example `509` (no fill). `-1` is used by the plugin for "Ad not ready" and for the web + * stub. + * + * @since 0.1.0 + */ code: number; + /** + * Human readable message. + * + * @since 0.1.0 + */ message: string; } -/** Subset of the native `LevelPlayAdInfo` / `LPMAdInfo` that is useful in JavaScript. */ +/** + * Subset of the native `LevelPlayAdInfo` (Android) / `LPMAdInfo` (iOS) that is useful in JavaScript. + * Fields the SDK does not report are omitted. + * + * @since 0.1.0 + */ export interface AdInfo { + /** + * Unique id of this ad. + * + * @since 0.1.0 + */ adId?: string; + /** + * Ad unit id. + * + * @since 0.1.0 + */ adUnitId: string; + /** + * Ad unit name from the dashboard. + * + * @since 0.1.0 + */ adUnitName?: string; + /** + * Ad format as reported by the SDK. + * + * @since 0.1.0 + */ adFormat?: string; + /** + * Placement name of the show call, when one was used. + * + * @since 0.1.0 + */ placementName?: string; + /** + * Name of the mediated network that served the ad. + * + * @since 0.1.0 + */ adNetwork?: string; + /** + * Mediation instance name. + * + * @since 0.1.0 + */ instanceName?: string; + /** + * Mediation instance id. + * + * @since 0.1.0 + */ instanceId?: string; + /** + * Country code of the impression. + * + * @since 0.1.0 + */ country?: string; + /** + * Auction id. + * + * @since 0.1.0 + */ auctionId?: string; - /** Impression revenue in USD as reported by the SDK (may be absent before display). */ + /** + * Impression revenue in USD as reported by the SDK (may be absent or 0 before display). + * + * @since 0.1.0 + */ revenue?: number; + /** + * Revenue precision as reported by the SDK. + * + * @since 0.1.0 + */ precision?: string; } +/** + * Result of `showRewarded()` and `showInterstitial()`, resolved after the ad + * closed or failed to display. + * + * @since 0.1.0 + */ export interface ShowResult { - /** The ad was displayed (`displayed` fired). */ + /** + * The ad was displayed (the `displayed` event fired). + * + * @since 0.1.0 + */ shown: boolean; - /** Rewarded only: the reward callback fired for this show. Grant the reward only when this is true. */ + /** + * Rewarded only: the reward callback fired for this show. Grant the reward only when this is `true`. + * Always `false` for interstitials. + * + * @since 0.1.0 + */ rewarded: boolean; + /** + * The reward, present when `rewarded` is `true`. + * + * @since 0.1.0 + */ reward?: Reward; - /** Present when the ad was not ready or failed to display. */ + /** + * Present when the ad was not ready (`code: -1`) or failed to display. + * + * @since 0.1.0 + */ error?: AdError; + /** + * Info of the displayed ad. + * + * @since 0.1.0 + */ adInfo?: AdInfo; } +/** + * Payload of the `loaded`, `displayed`, `clicked` and `closed` events. + * + * @since 0.1.0 + */ export interface AdEvent { + /** + * Format of the ad unit that fired the event. + * + * @since 0.1.0 + */ format: AdFormat; + /** + * Ad unit that fired the event. + * + * @since 0.1.0 + */ adUnitId: string; + /** + * Ad info, when the SDK provides it (not on `loadFailed`). + * + * @since 0.1.0 + */ adInfo?: AdInfo; } +/** + * Payload of the `loadFailed` and `displayFailed` events: the AdEvent fields plus `error`. + * + * @since 0.1.0 + */ export interface AdErrorEvent extends AdEvent { + /** + * What went wrong. + * + * @since 0.1.0 + */ error: AdError; } +/** + * Payload of the `rewarded` event: the AdEvent fields plus `reward`. + * + * @since 0.1.0 + */ export interface AdRewardEvent extends AdEvent { + /** + * The reward earned. + * + * @since 0.1.0 + */ reward: Reward; } +/** + * iOS App Tracking Transparency status. `unavailable` on Android, on the web and on unknown future iOS values. + * + * @since 0.1.0 + */ export type TrackingStatus = 'authorized' | 'denied' | 'restricted' | 'notDetermined' | 'unavailable'; +/** + * Result of `requestTrackingAuthorization()` and + * `getTrackingAuthorizationStatus()`. + * + * @since 0.1.0 + */ export interface TrackingResult { - /** iOS App Tracking Transparency status. Always `unavailable` on Android and web. */ + /** + * iOS App Tracking Transparency status. Always `unavailable` on Android and web. + * + * @since 0.1.0 + */ status: TrackingStatus; } +/** + * Event names emitted by the plugin. + * + * @since 0.1.0 + */ +export type LevelPlayEventName = + | 'loaded' + | 'loadFailed' + | 'displayed' + | 'displayFailed' + | 'clicked' + | 'closed' + | 'rewarded'; + +/** + * Unity LevelPlay rewarded and interstitial ads (ad-unit API). + * + * @since 0.1.0 + */ export interface LevelPlayPlugin { /** - * Initialise the LevelPlay SDK. Resolves on `onInitSuccess`, rejects with the init error otherwise. - * Calling it again after a successful init resolves immediately. Load ads only after this resolves. + * Initialise the LevelPlay SDK (`LevelPlay.init`). Resolves on init success, rejects with the init error + * (code and message from the SDK) otherwise. Calling it again after a successful init resolves immediately; + * concurrent calls share one init. Load ads only after this resolves. + * + * Set consent (and on iOS ask for ATT) before calling it. + * + * On the web it rejects as unimplemented. + * + * @since 0.1.0 */ initialize(options: InitOptions): Promise; - /** Native SDK version (available before init). */ + /** + * Native LevelPlay SDK version. Works before init. + * + * @since 0.1.0 + */ getSdkVersion(): Promise; - /** Forward GDPR / CCPA / COPPA signals. Call before {@link initialize} when you can. */ + /** + * Forward GDPR / CCPA / COPPA signals to LevelPlay. Call it before `initialize()` when you + * can, and again whenever the user changes their choice. + * + * @since 0.1.0 + */ setConsent(options: ConsentOptions): Promise; - /** Raw `LevelPlay.setMetaData(key, value)` for network-specific flags. Call before init. */ + /** + * Raw `LevelPlay.setMetaData(key, value)` for SDK or network-specific flags. Call it before init. + * + * @since 0.1.0 + */ setMetaData(options: MetaDataOptions): Promise; /** - * iOS: show the App Tracking Transparency prompt (needs `NSUserTrackingUsageDescription` in Info.plist) and resolve - * with the resulting status. Call it before {@link initialize}. Android / web: resolves `unavailable`. + * iOS: show the App Tracking Transparency prompt and resolve with the resulting status. Needs + * `NSUserTrackingUsageDescription` in `Info.plist`. iOS only shows the prompt once; later calls resolve the stored + * status. Call it before `initialize()`, while the app is active. + * + * Android and web: resolves `unavailable`. + * + * @since 0.1.0 */ requestTrackingAuthorization(): Promise; - /** Current ATT status without prompting (iOS). Android / web: `unavailable`. */ + /** + * Current App Tracking Transparency status without prompting (iOS). Android and web: `unavailable`. + * + * @since 0.1.0 + */ getTrackingAuthorizationStatus(): Promise; /** - * Start loading a rewarded ad for the ad unit (the ad object is created on first use and reused). - * Resolves once the request is issued; the outcome arrives as `loaded` / `loadFailed` events. + * Start loading a rewarded ad for the ad unit. The native ad object is created on first use and reused for the + * ad unit. Resolves once the request is issued; the outcome arrives as a `loaded` or `loadFailed` event. + * Load the next ad after each show. + * + * @since 0.1.0 */ loadRewarded(options: AdUnitOptions): Promise; /** - * Show a loaded rewarded ad. Resolves after the ad closes (or failed to display) with what happened. - * Never rejects for "not ready": resolves `{ shown: false, error }` instead. + * Show a loaded rewarded ad. Resolves after the ad closed (or failed to display) with what happened. The reward + * and close callbacks can arrive in either order on some networks, so the plugin waits up to 1 second after the close + * for a late reward. Never rejects for "not ready": resolves `{ shown: false, rewarded: false, error }` instead. + * + * @since 0.1.0 */ showRewarded(options: ShowOptions): Promise; - /** Start loading an interstitial ad (see {@link loadRewarded}). */ + /** + * Start loading an interstitial ad for the ad unit. Works like `loadRewarded()`. + * + * @since 0.1.0 + */ loadInterstitial(options: AdUnitOptions): Promise; - /** Show a loaded interstitial. Resolves after it closes (or failed to display). */ + /** + * Show a loaded interstitial. Resolves after it closed (or failed to display). Never rejects for "not ready". + * + * @since 0.1.0 + */ showInterstitial(options: ShowOptions): Promise; - /** `isAdReady()` of the ad object for this ad unit (`false` when it was never loaded). */ + /** + * `isAdReady()` of the native ad object for this ad unit. `false` when the ad unit was never loaded. + * + * @since 0.1.0 + */ isReady(options: IsReadyOptions): Promise; - /** Open the LevelPlay Integration Test Suite. Requires `initialize({ testSuite: true })` first. */ + /** + * Open the LevelPlay Integration Test Suite. Requires `initialize({ testSuite: true })` first. + * Development builds only. Rejects on the web. + * + * @since 0.1.0 + */ launchTestSuite(): Promise; - /** Log the LevelPlay integration helper report to the native console (development only). */ + /** + * Write the LevelPlay integration helper report to the native log (Xcode console; Android logcat tag + * `IntegrationHelper`): SDK, adapter and network SDK versions, each `VERIFIED` or not. Development only. + * + * @since 0.1.0 + */ validateIntegration(): Promise; + /** + * An ad finished loading for the ad unit and can be shown. + * + * @since 0.1.0 + */ addListener(eventName: 'loaded', listenerFunc: (event: AdEvent) => void): Promise; + + /** + * Loading failed, for example `509` (no fill). Retry later with a backoff. + * + * @since 0.1.0 + */ addListener(eventName: 'loadFailed', listenerFunc: (event: AdErrorEvent) => void): Promise; + + /** + * The ad was displayed (impression). `adInfo.revenue` is available here. + * + * @since 0.1.0 + */ addListener(eventName: 'displayed', listenerFunc: (event: AdEvent) => void): Promise; - addListener(eventName: 'displayFailed', listenerFunc: (event: AdErrorEvent) => void): Promise; + + /** + * The ad failed to display. The pending show call resolves with the same error. + * + * @since 0.1.0 + */ + addListener( + eventName: 'displayFailed', + listenerFunc: (event: AdErrorEvent) => void, + ): Promise; + + /** + * The user clicked the ad. + * + * @since 0.1.0 + */ addListener(eventName: 'clicked', listenerFunc: (event: AdEvent) => void): Promise; + + /** + * The ad was closed and the app is back in front. + * + * @since 0.1.0 + */ addListener(eventName: 'closed', listenerFunc: (event: AdEvent) => void): Promise; + + /** + * Rewarded only: the user earned the reward. Can fire before or after `closed`. + * + * @since 0.1.0 + */ addListener(eventName: 'rewarded', listenerFunc: (event: AdRewardEvent) => void): Promise; + /** + * Remove every listener of this plugin. + * + * @since 0.1.0 + */ removeAllListeners(): Promise; } - -/** Event names emitted by the plugin. */ -export type LevelPlayEventName = 'loaded' | 'loadFailed' | 'displayed' | 'displayFailed' | 'clicked' | 'closed' | 'rewarded'; diff --git a/tsconfig.json b/tsconfig.json index 2bf6f98..d074ff1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,6 @@ "declaration": true, "esModuleInterop": true, "inlineSources": true, - "lib": ["dom", "es2017"], "module": "esnext", "moduleResolution": "node", "noFallthroughCasesInSwitch": true,