diff --git a/dist/apiprovide.cjs.js b/dist/apiprovide.cjs.js index 997da0b..8c1968a 100644 --- a/dist/apiprovide.cjs.js +++ b/dist/apiprovide.cjs.js @@ -2,36 +2,36 @@ Object.defineProperty(exports, '__esModule', { value: true }); -function provide(packageNameActual, packActual) { - // -- START -- static loader - var unresolvedPackages = {}; - var providedPackages = {}; - var loaderName = "pssmasloader"; - var loader = (window[loaderName] = window[loaderName] || { - _: { - u: unresolvedPackages, - p: providedPackages - }, - require: function (packageName, cb) { - var pack = providedPackages[packageName]; - if (pack !== undefined) { - cb(pack, null); - } - else { - unresolvedPackages[packageName] = unresolvedPackages[packageName] || []; - unresolvedPackages[packageName].push(cb); - } - } - }); - unresolvedPackages = loader._.u; - providedPackages = loader._.p; - // -- END -- static loader - var unresolvedRequires = unresolvedPackages[packageNameActual] || []; - providedPackages[packageNameActual] = packActual; - for (var i = 0; i < unresolvedRequires.length; i++) { - unresolvedRequires[i](packActual, null); - } - return packActual; +function provide(packageNameActual, packActual) { + // -- START -- static loader + var unresolvedPackages = {}; + var providedPackages = {}; + var loaderName = "pssmasloader"; + var loader = (window[loaderName] = window[loaderName] || { + _: { + u: unresolvedPackages, + p: providedPackages + }, + require: function (packageName, cb) { + var pack = providedPackages[packageName]; + if (pack !== undefined) { + cb(pack, null); + } + else { + unresolvedPackages[packageName] = unresolvedPackages[packageName] || []; + unresolvedPackages[packageName].push(cb); + } + } + }); + unresolvedPackages = loader._.u; + providedPackages = loader._.p; + // -- END -- static loader + var unresolvedRequires = unresolvedPackages[packageNameActual] || []; + providedPackages[packageNameActual] = packActual; + for (var i = 0; i < unresolvedRequires.length; i++) { + unresolvedRequires[i](packActual, null); + } + return packActual; } exports.provide = provide; diff --git a/dist/apiprovide.d.ts b/dist/apiprovide.d.ts index 0466cfd..f26808d 100644 --- a/dist/apiprovide.d.ts +++ b/dist/apiprovide.d.ts @@ -1 +1 @@ -export declare function provide(packageNameActual: string, packActual: any): any; +export declare function provide(packageNameActual: string, packActual: any): any; diff --git a/dist/apiprovide.esm.js b/dist/apiprovide.esm.js index e801f64..3cd0560 100644 --- a/dist/apiprovide.esm.js +++ b/dist/apiprovide.esm.js @@ -1,33 +1,33 @@ -function provide(packageNameActual, packActual) { - // -- START -- static loader - var unresolvedPackages = {}; - var providedPackages = {}; - var loaderName = "pssmasloader"; - var loader = (window[loaderName] = window[loaderName] || { - _: { - u: unresolvedPackages, - p: providedPackages - }, - require: function (packageName, cb) { - var pack = providedPackages[packageName]; - if (pack !== undefined) { - cb(pack, null); - } - else { - unresolvedPackages[packageName] = unresolvedPackages[packageName] || []; - unresolvedPackages[packageName].push(cb); - } - } - }); - unresolvedPackages = loader._.u; - providedPackages = loader._.p; - // -- END -- static loader - var unresolvedRequires = unresolvedPackages[packageNameActual] || []; - providedPackages[packageNameActual] = packActual; - for (var i = 0; i < unresolvedRequires.length; i++) { - unresolvedRequires[i](packActual, null); - } - return packActual; +function provide(packageNameActual, packActual) { + // -- START -- static loader + var unresolvedPackages = {}; + var providedPackages = {}; + var loaderName = "pssmasloader"; + var loader = (window[loaderName] = window[loaderName] || { + _: { + u: unresolvedPackages, + p: providedPackages + }, + require: function (packageName, cb) { + var pack = providedPackages[packageName]; + if (pack !== undefined) { + cb(pack, null); + } + else { + unresolvedPackages[packageName] = unresolvedPackages[packageName] || []; + unresolvedPackages[packageName].push(cb); + } + } + }); + unresolvedPackages = loader._.u; + providedPackages = loader._.p; + // -- END -- static loader + var unresolvedRequires = unresolvedPackages[packageNameActual] || []; + providedPackages[packageNameActual] = packActual; + for (var i = 0; i < unresolvedRequires.length; i++) { + unresolvedRequires[i](packActual, null); + } + return packActual; } export { provide }; diff --git a/dist/ps-web-apis.cjs.js b/dist/ps-web-apis.cjs.js index b6e9d5a..d9140ad 100644 --- a/dist/ps-web-apis.cjs.js +++ b/dist/ps-web-apis.cjs.js @@ -2,102 +2,102 @@ Object.defineProperty(exports, '__esModule', { value: true }); -function provide(packageNameActual, packActual) { - // -- START -- static loader - var unresolvedPackages = {}; - var providedPackages = {}; - var loaderName = "pssmasloader"; - var loader = (window[loaderName] = window[loaderName] || { - _: { - u: unresolvedPackages, - p: providedPackages - }, - require: function (packageName, cb) { - var pack = providedPackages[packageName]; - if (pack !== undefined) { - cb(pack, null); - } - else { - unresolvedPackages[packageName] = unresolvedPackages[packageName] || []; - unresolvedPackages[packageName].push(cb); - } - } - }); - unresolvedPackages = loader._.u; - providedPackages = loader._.p; - // -- END -- static loader - var unresolvedRequires = unresolvedPackages[packageNameActual] || []; - providedPackages[packageNameActual] = packActual; - for (var i = 0; i < unresolvedRequires.length; i++) { - unresolvedRequires[i](packActual, null); - } - return packActual; +function provide(packageNameActual, packActual) { + // -- START -- static loader + var unresolvedPackages = {}; + var providedPackages = {}; + var loaderName = "pssmasloader"; + var loader = (window[loaderName] = window[loaderName] || { + _: { + u: unresolvedPackages, + p: providedPackages + }, + require: function (packageName, cb) { + var pack = providedPackages[packageName]; + if (pack !== undefined) { + cb(pack, null); + } + else { + unresolvedPackages[packageName] = unresolvedPackages[packageName] || []; + unresolvedPackages[packageName].push(cb); + } + } + }); + unresolvedPackages = loader._.u; + providedPackages = loader._.p; + // -- END -- static loader + var unresolvedRequires = unresolvedPackages[packageNameActual] || []; + providedPackages[packageNameActual] = packActual; + for (var i = 0; i < unresolvedRequires.length; i++) { + unresolvedRequires[i](packActual, null); + } + return packActual; } -function requirePackage(name) { - // -- START -- static loader - var unresolvedPackages = {}; - var providedPackages = {}; - var loaderName = "pssmasloader"; - // set or reuse existing loader implementation - var loader = (window[loaderName] = window[loaderName] || { - // Requires packageName and returns it via callback - require: function (packageName, cb) { - var pack = providedPackages[packageName]; - if (pack !== undefined) { - // -- will callback directly if required functionality was already provided - cb(pack, null); - } - else { - // -- will queue callbacks if required functionality is not yet available - unresolvedPackages[packageName] = unresolvedPackages[packageName] || []; - unresolvedPackages[packageName].push(cb); - } - }, - // private state - _: { - u: unresolvedPackages, - p: providedPackages - } - }); - // -- END -- static loader - return new Promise(function (resolve, reject) { - loader.require(name, function (res, error) { - if (error) { - reject(error); - } - else { - resolve(res); - } - }); - }); -} -function whoamiV1() { - return requirePackage("whoami:v1"); -} -function utilsV1() { - return requirePackage("utils:v1"); -} -function waitingRoomV1() { - return requireApi("waiting_room:v1"); -} -function abV1() { - return requirePackage("ab:v1"); -} -function CligV1() { - return requirePackage("ppclig:v1"); -} -function CligV2() { - return requirePackage("clig:v2"); -} -var provideApi = provide; +function requirePackage(name) { + // -- START -- static loader + var unresolvedPackages = {}; + var providedPackages = {}; + var loaderName = "pssmasloader"; + // set or reuse existing loader implementation + var loader = (window[loaderName] = window[loaderName] || { + // Requires packageName and returns it via callback + require: function (packageName, cb) { + var pack = providedPackages[packageName]; + if (pack !== undefined) { + // -- will callback directly if required functionality was already provided + cb(pack, null); + } + else { + // -- will queue callbacks if required functionality is not yet available + unresolvedPackages[packageName] = unresolvedPackages[packageName] || []; + unresolvedPackages[packageName].push(cb); + } + }, + // private state + _: { + u: unresolvedPackages, + p: providedPackages + } + }); + // -- END -- static loader + return new Promise(function (resolve, reject) { + loader.require(name, function (res, error) { + if (error) { + reject(error); + } + else { + resolve(res); + } + }); + }); +} +function whoamiV1() { + return requirePackage("whoami:v1"); +} +function utilsV1() { + return requirePackage("utils:v1"); +} +function waitingRoomV1() { + return requireApi("waiting_room:v1"); +} +function abV1() { + return requirePackage("ab:v1"); +} +function CligV1() { + return requirePackage("ppclig:v1"); +} +function CligV2() { + return requirePackage("clig:v2"); +} +var provideApi = provide; var requireApi = requirePackage; -exports.whoamiV1 = whoamiV1; -exports.utilsV1 = utilsV1; -exports.waitingRoomV1 = waitingRoomV1; -exports.abV1 = abV1; exports.CligV1 = CligV1; exports.CligV2 = CligV2; +exports.abV1 = abV1; exports.provideApi = provideApi; exports.requireApi = requireApi; +exports.utilsV1 = utilsV1; +exports.waitingRoomV1 = waitingRoomV1; +exports.whoamiV1 = whoamiV1; diff --git a/dist/ps-web-apis.d.ts b/dist/ps-web-apis.d.ts index a70b9bc..df83561 100644 --- a/dist/ps-web-apis.d.ts +++ b/dist/ps-web-apis.d.ts @@ -1,183 +1,214 @@ -import { provide } from "./apiprovide"; -declare function requirePackage(name: string): Promise; -export interface WhoamiUserInfo { - user_id: string; - first_name?: string; - last_name?: string; -} -export interface PurchaseData { - entitlements: [string]; -} -export interface UserDataRequestResult { - success: boolean; - reason?: "userNotLoggedIn" | "generalError" | "userAborted"; -} -export declare type FetchOptions = RequestInit & { - timeout?: number; -}; -export declare type WaitingRoomQueueDefault = ""; -export declare type WaitingRoomQueue = WaitingRoomQueueDefault | "auth" | "checkout"; -/** - * Custom fetch interface which includes the possibility to customize timeouts for fetch requests - */ -export declare type Fetch = (input: RequestInfo, init?: FetchOptions) => Promise; -export declare type GetRosettaEnvByKey = (key: string) => string | undefined; -export declare type WaitForCapacity = (queue: WaitingRoomQueue) => Promise; -export declare type RegisterIframeMessageListener = (eventtype: string, listener: (event: any, iframe: HTMLIFrameElement) => void) => void; -export interface WhoamiV1 { - /** - * will assert valid not outdated session before fetch will be done. backend credentials will be added automatically - * an error is resolved if session is invalid and not refeshable (= user logged out) - * Important: as of version 1.9.9 all requests are timeout after 5s by default. - * Can be changed by adding the field timeout to the FetchOptions Interface - */ - authorizedFetch: Fetch; - /** - * gives information if user is currently loggedin from ui perspective - */ - isLoggedIn(): boolean; - /** - * gives information if the user is currently a C1 User. These are users which are not logged in from - * sso/mypass perspective. These users are originated from the apps and have potentially in app purchases. - * If this method resolves to true isLogged in will resolve to false. - * @deprecated there is not replacement for the client planned - */ - isC1User(): boolean; - /** - * gives information if the user is currently a Plenigo User. These are users which are not logged in from - * sso/mypass perspective. These users are originated from the apps and have potentially in app purchases. - * If this method resolves to true isLogged in will resolve to false. - */ - isPlenigoUser(): boolean; - /** - * will assert valid not outdated session before promise is resolved - * an error is resolved if session is invalid and not refeshable (= user logged out) - */ - ensureUserHasAuthorization(): Promise; - /** - * Ensures that the user has provided both a first name and a last name. - * If the user has not provided these details, the function will prompt the user - * to enter them. Depending on the `skippable` parameter, the user may be allowed - * to skip this step. - * - * @param skippable - If true, the user can choose to skip providing their first name - * and last name. - * @param title - Optional. A custom title for the prompt that asks for the user's - * first name and last name. If not set default will be used. - * @param text - Optional. A custom text or message to display in the prompt. If not - * set default will be used. - * - * @returns A promise that resolves to an object indicating whether the user provided - * the required information (`success: true`) or not, along with a `reason` if applicable. - * Possible reasons include "userNotLoggedIn", "error", or "userAborted". - */ - ensureUserHasFirstNameAndLastName(skippable: boolean, title?: string, text?: string): Promise; - /** - * Ensures that the user has opted in to a specific data collection or processing activity. - * If the user has not opted in, the function will prompt the user to do so. - * - * @param optIn - A string representing the specific opt-in name. - * This could be the new Marketing_AS_2024 or any other opt-in, - * which are present in agreement. - * - * @returns A promise that resolves to an object indicating whether the user opted in - * successfully (`success: true`) or not, along with a `reason` if applicable. - * Possible reasons include "userNotLoggedIn", "generalError", or "userAborted". - */ - ensureUserHasOptin(optIn: string): Promise; - /** - * will start login-process (e.g. go to sso-login) - */ - doLogin(additionalParameter?: Map): void; - /** - * will start registration-process (e.g. go to sso-register) - */ - doRegister(additionalParameter?: Map): void; - /** - * will start logout-process (e.g. go to sso-logout) - */ - doLogout(additionalParameter?: Map): void; - /** - * will start logout-process and redirect user to portal homepage afterwards (e.g. go to sso-logout) - */ - doLogoutToHome(additionalParameter?: Map): void; - /** - * will update access token and therefore content entitlements to current state - */ - forceAccessTokenRefresh(): Promise; - /** - * will request userinfo from whoami backend - * @return {WhoamiUserInfo} some relevant userdata - */ - getUserInfo(): Promise; - /** - * will request customer pseudo id for currently logged user from consent backend - * @param clientId The string identifier of the client for which the customer id is requested. - * @deprecated there is not replacement for the client planned - */ - getCustomerId(clientId: string): Promise; - /** - * will provide unsafe purchase data - */ - getUnsafePurchaseData(): Promise; - /** - * will provide users registration date if available otherwise returns null. - * Registration date in unix timestamp. - */ - getUnsafeRegistrationDate(): Promise; - /** - * will provide jaId for logged in users, otherwise - * @throws error - */ - getJaId(): string; -} -export interface UtilsV1 { - fetchWithTimeout: Fetch; - getRosettaEnvByKey: GetRosettaEnvByKey; - registerIframeMessageListener: RegisterIframeMessageListener; -} -export interface AbV1 { - userInTestGroupForFeature: (key: string) => { - canSeeFeature: boolean; - testGroup: "A" | "B"; - }; -} -export interface WaitingRoomV1 { - waitForCapacity: WaitForCapacity; -} -export declare type ILayer = "privacy" | "reject"; -export declare type IApp = "offerpage" | "checkout" | "cancellation"; -export declare type ITenant = "welt" | "bild"; -export interface IAccount { - accountId: number | string; - propertyId: number | string; - baseEndpoint: string; - purEntitlement: string; - layers: { - [key in ILayer]: number | string; - }; -} -export declare type IAppConfig = { - [key in ITenant]: IAccount; -} & { - urlsWithoutConsentLayer: string[]; -}; -export declare type IConfig = { - [key in IApp]: IAppConfig; -}; -export interface ICligV1 { - init: (app: IApp) => Promise; - open: (layer: ILayer) => void; -} -export declare type ICligV2 = (app: IApp) => Promise<{ - open: (layer: ILayer) => void; -}>; -export declare function whoamiV1(): Promise; -export declare function utilsV1(): Promise; -export declare function waitingRoomV1(): Promise; -export declare function abV1(): Promise; -export declare function CligV1(): Promise; -export declare function CligV2(): Promise; -export declare const provideApi: typeof provide; -export declare const requireApi: typeof requirePackage; -export {}; +import { provide } from "./apiprovide"; +declare function requirePackage(name: string): Promise; +export interface WhoamiUserInfo { + user_id: string; + first_name?: string; + last_name?: string; +} +export interface PurchaseData { + entitlements: [string]; +} +export interface UserDataRequestResult { + success: boolean; + reason?: "userNotLoggedIn" | "generalError" | "userAborted"; +} +export declare type FetchOptions = RequestInit & { + timeout?: number; +}; +export declare type WaitingRoomQueueDefault = ""; +export declare type WaitingRoomQueue = WaitingRoomQueueDefault | "auth" | "checkout" | "lefty-in-app-purchase"; +/** + * Custom fetch interface which includes the possibility to customize timeouts for fetch requests + */ +export declare type Fetch = (input: RequestInfo, init?: FetchOptions) => Promise; +export declare type GetRosettaEnvByKey = (key: string) => string | undefined; +export declare type WaitForCapacity = (queue: WaitingRoomQueue) => Promise; +export declare type RegisterIframeMessageListener = (eventtype: string, listener: (event: any, iframe: HTMLIFrameElement) => void) => void; +export interface WhoamiV1 { + /** + * will assert valid not outdated session before fetch will be done. backend credentials will be added automatically + * an error is resolved if session is invalid and not refeshable (= user logged out) + * Important: as of version 1.9.9 all requests are timeout after 5s by default. + * Can be changed by adding the field timeout to the FetchOptions Interface + */ + authorizedFetch: Fetch; + /** + * gives information if user is currently loggedin from ui perspective + */ + isLoggedIn(): boolean; + /** + * gives information if the user is currently a C1 User. These are users which are not logged in from + * sso/mypass perspective. These users are originated from the apps and have potentially in app purchases. + * If this method resolves to true isLogged in will resolve to false. + * @deprecated there is not replacement for the client planned + */ + isC1User(): boolean; + /** + * gives information if the user is currently a Plenigo User. These are users which are not logged in from + * sso/mypass perspective. These users are originated from the apps and have potentially in app purchases. + * If this method resolves to true isLogged in will resolve to false. + */ + isPlenigoUser(): boolean; + /** + * will assert valid not outdated session before promise is resolved + * an error is resolved if session is invalid and not refeshable (= user logged out) + */ + ensureUserHasAuthorization(): Promise; + /** + * Ensures that the user has provided both a first name and a last name. + * If the user has not provided these details, the function will prompt the user + * to enter them. Depending on the `skippable` parameter, the user may be allowed + * to skip this step. + * + * @param skippable - If true, the user can choose to skip providing their first name + * and last name. + * @param title - Optional. A custom title for the prompt that asks for the user's + * first name and last name. If not set default will be used. + * @param text - Optional. A custom text or message to display in the prompt. If not + * set default will be used. + * + * @returns A promise that resolves to an object indicating whether the user provided + * the required information (`success: true`) or not, along with a `reason` if applicable. + * Possible reasons include "userNotLoggedIn", "error", or "userAborted". + */ + ensureUserHasFirstNameAndLastName(skippable: boolean, title?: string, text?: string): Promise; + /** + * Ensures that the user has opted in to a specific data collection or processing activity. + * If the user has not opted in, the function will prompt the user to do so. + * + * @param optIn - A string representing the specific opt-in name. + * This could be the new Marketing_AS_2024 or any other opt-in, + * which are present in agreement. + * + * @returns A promise that resolves to an object indicating whether the user opted in + * successfully (`success: true`) or not, along with a `reason` if applicable. + * Possible reasons include "userNotLoggedIn", "generalError", or "userAborted". + */ + ensureUserHasOptin(optIn: string): Promise; + /** + * will start login-process (e.g. go to sso-login) + */ + doLogin(additionalParameter?: Map): void; + /** + * will start registration-process (e.g. go to sso-register) + */ + doRegister(additionalParameter?: Map): void; + /** + * will start logout-process (e.g. go to sso-logout) + */ + doLogout(additionalParameter?: Map): void; + /** + * will start logout-process and redirect user to portal homepage afterwards (e.g. go to sso-logout) + */ + doLogoutToHome(additionalParameter?: Map): void; + /** + * will update access token and therefore content entitlements to current state + */ + forceAccessTokenRefresh(): Promise; + /** + * will request userinfo from whoami backend + * @return {WhoamiUserInfo} some relevant userdata + */ + getUserInfo(): Promise; + /** + * will request customer pseudo id for currently logged user from consent backend + * @param clientId The string identifier of the client for which the customer id is requested. + * @deprecated there is not replacement for the client planned + */ + getCustomerId(clientId: string): Promise; + /** + * will provide unsafe purchase data + */ + getUnsafePurchaseData(): Promise; + /** + * will provide users registration date if available otherwise returns null. + * Registration date in unix timestamp. + */ + getUnsafeRegistrationDate(): Promise; + /** + * will provide jaId for logged in users, otherwise + * @throws error + */ + getJaId(): string; + /** + * will render the Wonderwall in the given container with the given props and call the callback after main functionality is done + * + * @param container - The HTML element in which the Wonderwall should be rendered. + * The container should be an HTML element. + * + * @param {Object} props - The props that should be passed, which will be passed to the auth component. + * @param {String} props.template - valid choices are "register" and "login" + * @param {String} props.variant - variant of the brand that should be shown e.g bild or welt + * @param {boolean} [props.abortable] - user can leave auth screen if true (not yet implemented) + * @param {String} [props.loginHeadline] + * @param {String} [props.registerHeadline] + * @param {String} [props.loginCta] + * @param {String} [props.registerCta] + * + */ + renderAuthComponent(container: HTMLElement, props: WonderwallProps): Promise; +} +export interface AuthRes { + isLoggedIn: boolean; + message: string; +} +export declare type WonderwallVariant = "welt" | "bild" | "bild-tv" | "sportbild" | "bild-markenshop" | "osp" | "computerbild-vip-lounge" | "autobild" | "autobild-vip-lounge" | "sportbild-fanmeile" | "lidlbild" | "bz"; +export declare type WonderwallProps = { + template: "login" | "register"; + variant: WonderwallVariant; + abortable?: boolean; + loginHeadline?: string; + registerHeadline?: string; + loginCta?: string; + registerCta?: string; +}; +export interface UtilsV1 { + fetchWithTimeout: Fetch; + getRosettaEnvByKey: GetRosettaEnvByKey; + registerIframeMessageListener: RegisterIframeMessageListener; +} +export interface AbV1 { + userInTestGroupForFeature: (key: string) => { + canSeeFeature: boolean; + testGroup: "A" | "B"; + }; +} +export interface WaitingRoomV1 { + waitForCapacity: WaitForCapacity; +} +export declare type ILayer = "privacy" | "reject"; +export declare type IApp = "offerpage" | "checkout" | "cancellation"; +export declare type ITenant = "welt" | "bild"; +export interface IAccount { + accountId: number | string; + propertyId: number | string; + baseEndpoint: string; + purEntitlement: string; + layers: { + [key in ILayer]: number | string; + }; +} +export declare type IAppConfig = { + [key in ITenant]: IAccount; +} & { + urlsWithoutConsentLayer: string[]; +}; +export declare type IConfig = { + [key in IApp]: IAppConfig; +}; +export interface ICligV1 { + init: (app: IApp) => Promise; + open: (layer: ILayer) => void; +} +export declare type ICligV2 = (app: IApp) => Promise<{ + open: (layer: ILayer) => void; +}>; +export declare function whoamiV1(): Promise; +export declare function utilsV1(): Promise; +export declare function waitingRoomV1(): Promise; +export declare function abV1(): Promise; +export declare function CligV1(): Promise; +export declare function CligV2(): Promise; +export declare const provideApi: typeof provide; +export declare const requireApi: typeof requirePackage; +export {}; diff --git a/dist/ps-web-apis.esm.js b/dist/ps-web-apis.esm.js index f402997..9a566da 100644 --- a/dist/ps-web-apis.esm.js +++ b/dist/ps-web-apis.esm.js @@ -1,92 +1,92 @@ -function provide(packageNameActual, packActual) { - // -- START -- static loader - var unresolvedPackages = {}; - var providedPackages = {}; - var loaderName = "pssmasloader"; - var loader = (window[loaderName] = window[loaderName] || { - _: { - u: unresolvedPackages, - p: providedPackages - }, - require: function (packageName, cb) { - var pack = providedPackages[packageName]; - if (pack !== undefined) { - cb(pack, null); - } - else { - unresolvedPackages[packageName] = unresolvedPackages[packageName] || []; - unresolvedPackages[packageName].push(cb); - } - } - }); - unresolvedPackages = loader._.u; - providedPackages = loader._.p; - // -- END -- static loader - var unresolvedRequires = unresolvedPackages[packageNameActual] || []; - providedPackages[packageNameActual] = packActual; - for (var i = 0; i < unresolvedRequires.length; i++) { - unresolvedRequires[i](packActual, null); - } - return packActual; +function provide(packageNameActual, packActual) { + // -- START -- static loader + var unresolvedPackages = {}; + var providedPackages = {}; + var loaderName = "pssmasloader"; + var loader = (window[loaderName] = window[loaderName] || { + _: { + u: unresolvedPackages, + p: providedPackages + }, + require: function (packageName, cb) { + var pack = providedPackages[packageName]; + if (pack !== undefined) { + cb(pack, null); + } + else { + unresolvedPackages[packageName] = unresolvedPackages[packageName] || []; + unresolvedPackages[packageName].push(cb); + } + } + }); + unresolvedPackages = loader._.u; + providedPackages = loader._.p; + // -- END -- static loader + var unresolvedRequires = unresolvedPackages[packageNameActual] || []; + providedPackages[packageNameActual] = packActual; + for (var i = 0; i < unresolvedRequires.length; i++) { + unresolvedRequires[i](packActual, null); + } + return packActual; } -function requirePackage(name) { - // -- START -- static loader - var unresolvedPackages = {}; - var providedPackages = {}; - var loaderName = "pssmasloader"; - // set or reuse existing loader implementation - var loader = (window[loaderName] = window[loaderName] || { - // Requires packageName and returns it via callback - require: function (packageName, cb) { - var pack = providedPackages[packageName]; - if (pack !== undefined) { - // -- will callback directly if required functionality was already provided - cb(pack, null); - } - else { - // -- will queue callbacks if required functionality is not yet available - unresolvedPackages[packageName] = unresolvedPackages[packageName] || []; - unresolvedPackages[packageName].push(cb); - } - }, - // private state - _: { - u: unresolvedPackages, - p: providedPackages - } - }); - // -- END -- static loader - return new Promise(function (resolve, reject) { - loader.require(name, function (res, error) { - if (error) { - reject(error); - } - else { - resolve(res); - } - }); - }); -} -function whoamiV1() { - return requirePackage("whoami:v1"); -} -function utilsV1() { - return requirePackage("utils:v1"); -} -function waitingRoomV1() { - return requireApi("waiting_room:v1"); -} -function abV1() { - return requirePackage("ab:v1"); -} -function CligV1() { - return requirePackage("ppclig:v1"); -} -function CligV2() { - return requirePackage("clig:v2"); -} -var provideApi = provide; +function requirePackage(name) { + // -- START -- static loader + var unresolvedPackages = {}; + var providedPackages = {}; + var loaderName = "pssmasloader"; + // set or reuse existing loader implementation + var loader = (window[loaderName] = window[loaderName] || { + // Requires packageName and returns it via callback + require: function (packageName, cb) { + var pack = providedPackages[packageName]; + if (pack !== undefined) { + // -- will callback directly if required functionality was already provided + cb(pack, null); + } + else { + // -- will queue callbacks if required functionality is not yet available + unresolvedPackages[packageName] = unresolvedPackages[packageName] || []; + unresolvedPackages[packageName].push(cb); + } + }, + // private state + _: { + u: unresolvedPackages, + p: providedPackages + } + }); + // -- END -- static loader + return new Promise(function (resolve, reject) { + loader.require(name, function (res, error) { + if (error) { + reject(error); + } + else { + resolve(res); + } + }); + }); +} +function whoamiV1() { + return requirePackage("whoami:v1"); +} +function utilsV1() { + return requirePackage("utils:v1"); +} +function waitingRoomV1() { + return requireApi("waiting_room:v1"); +} +function abV1() { + return requirePackage("ab:v1"); +} +function CligV1() { + return requirePackage("ppclig:v1"); +} +function CligV2() { + return requirePackage("clig:v2"); +} +var provideApi = provide; var requireApi = requirePackage; -export { whoamiV1, utilsV1, waitingRoomV1, abV1, CligV1, CligV2, provideApi, requireApi }; +export { CligV1, CligV2, abV1, provideApi, requireApi, utilsV1, waitingRoomV1, whoamiV1 }; diff --git a/src/ps-web-apis.ts b/src/ps-web-apis.ts index 7d85cc5..1825fdf 100644 --- a/src/ps-web-apis.ts +++ b/src/ps-web-apis.ts @@ -55,7 +55,7 @@ export interface UserDataRequestResult { export type FetchOptions = RequestInit & { timeout?: number }; export type WaitingRoomQueueDefault = ""; -export type WaitingRoomQueue = WaitingRoomQueueDefault | "auth" | "checkout"; +export type WaitingRoomQueue = WaitingRoomQueueDefault | "auth" | "checkout" | "lefty-in-app-purchase"; /** * Custom fetch interface which includes the possibility to customize timeouts for fetch requests