@schibsted/account-sdk-browser 5.2.7 → 6.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -59
- package/dist/RESTClient.d.ts +91 -0
- package/dist/SDKError.d.ts +27 -0
- package/dist/cache.d.ts +65 -0
- package/dist/config.d.ts +86 -0
- package/dist/global-registry.d.ts +23 -0
- package/dist/globals.d.ts +13 -0
- package/dist/identity-s4nofYmB.js +370 -0
- package/dist/identity-s4nofYmB.js.map +1 -0
- package/dist/identity.d.ts +523 -0
- package/dist/identity.js +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/monetization.d.ts +94 -0
- package/dist/monetization.js +72 -0
- package/dist/monetization.js.map +1 -0
- package/{src → dist}/object.d.ts +4 -9
- package/dist/popup.d.ts +9 -0
- package/{src → dist}/spidTalk.d.ts +4 -6
- package/dist/url.d.ts +8 -0
- package/dist/validate.d.ts +50 -0
- package/dist/version-spE-k97g.js +289 -0
- package/dist/version-spE-k97g.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/package.json +42 -49
- package/src/RESTClient.ts +226 -0
- package/src/SDKError.ts +59 -0
- package/src/{cache.js → cache.ts} +52 -37
- package/src/{config.js → config.ts} +7 -32
- package/src/global-registry.ts +39 -0
- package/src/globals.ts +10 -0
- package/src/{identity.js → identity.ts} +536 -437
- package/{index.js → src/index.ts} +1 -3
- package/src/{monetization.js → monetization.ts} +77 -48
- package/src/{object.js → object.ts} +8 -15
- package/src/popup.ts +74 -0
- package/src/{spidTalk.js → spidTalk.ts} +10 -12
- package/src/{url.js → url.ts} +6 -10
- package/src/{validate.js → validate.ts} +26 -42
- package/src/{version.js → version.ts} +1 -2
- package/es5/global.js +0 -12968
- package/es5/global.js.map +0 -1
- package/es5/global.min.js +0 -2
- package/es5/global.min.js.map +0 -1
- package/es5/identity.js +0 -12212
- package/es5/identity.js.map +0 -1
- package/es5/identity.min.js +0 -2
- package/es5/identity.min.js.map +0 -1
- package/es5/index.js +0 -12940
- package/es5/index.js.map +0 -1
- package/es5/index.min.js +0 -2
- package/es5/index.min.js.map +0 -1
- package/es5/monetization.js +0 -9176
- package/es5/monetization.js.map +0 -1
- package/es5/monetization.min.js +0 -2
- package/es5/monetization.min.js.map +0 -1
- package/es5/payment.js +0 -8853
- package/es5/payment.js.map +0 -1
- package/es5/payment.min.js +0 -2
- package/es5/payment.min.js.map +0 -1
- package/identity.d.ts +0 -1
- package/identity.js +0 -5
- package/index.d.ts +0 -4
- package/monetization.d.ts +0 -1
- package/monetization.js +0 -5
- package/payment.d.ts +0 -1
- package/payment.js +0 -5
- package/src/RESTClient.d.ts +0 -89
- package/src/RESTClient.js +0 -193
- package/src/SDKError.d.ts +0 -16
- package/src/SDKError.js +0 -55
- package/src/__mocks__/.eslintrc.yml +0 -8
- package/src/__mocks__/RESTClient.js +0 -54
- package/src/cache.d.ts +0 -64
- package/src/config.d.ts +0 -34
- package/src/es5/global.js +0 -13
- package/src/es5/identity.js +0 -10
- package/src/es5/index.js +0 -13
- package/src/es5/monetization.js +0 -10
- package/src/es5/payment.js +0 -10
- package/src/global-registry.js +0 -20
- package/src/identity.d.ts +0 -679
- package/src/monetization.d.ts +0 -80
- package/src/payment.d.ts +0 -115
- package/src/payment.js +0 -211
- package/src/popup.d.ts +0 -10
- package/src/popup.js +0 -59
- package/src/url.d.ts +0 -10
- package/src/validate.d.ts +0 -64
- package/src/version.d.ts +0 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import './globals.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Names of the SDK instance properties that can be registered on the global {@link Window} object.
|
|
5
|
+
*/
|
|
6
|
+
type Property = 'schIdentity' | 'schMonetization';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers an SDK instance on the global {@link Window} object's given property and dispatches a ready event.
|
|
10
|
+
*
|
|
11
|
+
* The dispatched event is a {@link CustomEvent} fired on `global` (i.e. `window`) with:
|
|
12
|
+
* - name: `${property}:ready` (e.g. `"schIdentity:ready"` or `"schMonetization:ready"`)
|
|
13
|
+
* - `detail.instance`: the registered SDK instance
|
|
14
|
+
*
|
|
15
|
+
* @typeParam T - Constrained to {@link Property}; inferred from the `property` argument.
|
|
16
|
+
* @param global - The `Window` object to register on.
|
|
17
|
+
* @param property - The window property name to assign the instance to, 'schIdentity' or 'schMonetization'.
|
|
18
|
+
* @param instance - The SDK instance to register. Must be non-nullable.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* registerAndDispatchInGlobal(window, 'schIdentity', identityInstance);
|
|
22
|
+
* / window.schIdentity === identityInstance
|
|
23
|
+
* / CustomEvent 'schIdentity:ready' has been dispatched on window
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export const registerAndDispatchInGlobal = <T extends Property>(
|
|
27
|
+
global: Window,
|
|
28
|
+
property: T,
|
|
29
|
+
instance: NonNullable<Window[T]>,
|
|
30
|
+
): void => {
|
|
31
|
+
if (!global[property]) {
|
|
32
|
+
global[property] = instance;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
global.dispatchEvent(
|
|
36
|
+
//TODO -> https://schibsted.ghe.com/connect/team/issues/645
|
|
37
|
+
new CustomEvent(`${property}:ready`, { detail: { instance: global[property] } }),
|
|
38
|
+
);
|
|
39
|
+
};
|
package/src/globals.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Identity } from './identity.js';
|
|
2
|
+
import type { Monetization } from './monetization.js';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
schIdentity?: Identity;
|
|
7
|
+
schMonetization?: Monetization;
|
|
8
|
+
SPiD?: { Talk?: { response?: (callbackName: string, data: unknown) => unknown } };
|
|
9
|
+
}
|
|
10
|
+
}
|