@transmitsecurity/platform-web-sdk 1.18.2 → 2.0.0
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/CHANGELOG.md +45 -0
- package/README.md +70 -59
- package/dist/common.cjs +1 -0
- package/dist/common.d.ts +11 -0
- package/dist/common.js +1 -0
- package/dist/drs.cjs +1 -1
- package/dist/drs.d.ts +26 -74
- package/dist/drs.js +1 -1
- package/dist/ido.cjs +1 -3
- package/dist/ido.d.ts +13 -22
- package/dist/ido.js +1 -3
- package/dist/idv.cjs +1 -1
- package/dist/idv.js +1 -1
- package/dist/index.cjs +1 -3
- package/dist/index.esm.js +1 -3
- package/dist/index.umd.js +1 -3
- package/dist/ts-platform-websdk.js +1 -3
- package/dist/web-sdk-drs+idv+webauthn+ido.js +1 -3
- package/dist/web-sdk.d.ts +576 -167
- package/dist/webauthn.cjs +1 -1
- package/dist/webauthn.d.ts +45 -24
- package/dist/webauthn.js +1 -1
- package/package.json +23 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,49 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
## 2.0.0 - Feb. 01, 2026
|
|
3
|
+
**Fraud Prevention**
|
|
4
|
+
* BREAKING CHANGE: The `serverPath` parameter is now required. In previous versions, it defaulted to the US region. To ensure correct routing to your region, you must update your configuration to include the `serverPath` property as specified in the documentation.
|
|
5
|
+
* BREAKING CHANGE: The DRS module is no longer initialized by default. If your application uses DRS, you must explicitly include the `drs` configuration object in your initialization.
|
|
6
|
+
* BREAKING CHANGE: DRS user identification APIs have been changed:
|
|
7
|
+
- `unidentifiedUser()` → `clearUser()`
|
|
8
|
+
- `identifyUser()` → `setAuthenticatedUser()`
|
|
9
|
+
- `setUser()` → `setAuthenticatedUser()`
|
|
10
|
+
|
|
11
|
+
**Identity Verification**
|
|
12
|
+
* BREAKING CHANGE: The `serverPath` parameter is now required. In previous versions, it defaulted to the US region. To ensure correct routing to your region, you must update your configuration to include the `serverPath` property as specified in the documentation.
|
|
13
|
+
|
|
14
|
+
**Orchestration**
|
|
15
|
+
* feat: Introducing CIAM Secure through IDO journeys
|
|
16
|
+
* feat: IDO module now uses separate typing files. You may need to update imports if your application consumes IDO types.
|
|
17
|
+
|
|
18
|
+
**Webauthn**
|
|
19
|
+
* BREAKING CHANGE: All major SDK methods have been refactored to use a single parameter object pattern instead of multiple positional parameters.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## 1.20.0 - Jan. 18, 2026
|
|
23
|
+
**Fraud Prevention**
|
|
24
|
+
* Add getSecureSessionToken public method for generating cryptographically signed session tokens
|
|
25
|
+
* Support optional actionType and expirationMinutes parameters in secure session token generation
|
|
26
|
+
|
|
27
|
+
**Orchestration**
|
|
28
|
+
* fix: Update ido-web-sdk to version 0.0.78 - Fix correlationId serialization to persist across external redirects
|
|
29
|
+
* Fixes issue where correlationId was lost during external redirects (e.g., IDV, external IDP)
|
|
30
|
+
* Ensures single correlation_id per invocation_id for consistent tracking
|
|
31
|
+
* Maintains backward compatibility with existing serialized states
|
|
32
|
+
|
|
33
|
+
**Identity Verification**
|
|
34
|
+
* feat: Add document silhouette on front image capture to help users do auto-capture
|
|
35
|
+
|
|
36
|
+
## 1.19.0 - Dec. 21, 2025
|
|
37
|
+
**Fraud Prevention**
|
|
38
|
+
* feat: Improved mouse movement sampling rate by using Pointer Events API.
|
|
39
|
+
* feat: Improved device identification speed by sending device data immediately.
|
|
40
|
+
* feat: Add current `publicKeyID` tracking for session token injection protection.
|
|
41
|
+
|
|
42
|
+
## 1.18.3 - Dec. 7, 2025
|
|
43
|
+
**Identity Verification**
|
|
44
|
+
* feat: Use ZXing lib for extraction of barcode data
|
|
45
|
+
* feat: Improve camera selection for capturing documents
|
|
46
|
+
* fix: Stability manager counter issue
|
|
2
47
|
|
|
3
48
|
## 1.18.2 - Nov. 9, 2025
|
|
4
49
|
**Identity Verification**
|
package/README.md
CHANGED
|
@@ -1,100 +1,111 @@
|
|
|
1
1
|
# Transmit Security Platform Web SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
A JavaScript client SDK offering comprehensive identity and security solution with Fraud prevention, WebAuthn authentication, Identity Verification, and Orchestration capabilities.
|
|
4
5
|
|
|
5
6
|
## Installation
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
Installs the latest v2 version:
|
|
9
|
+
|
|
8
10
|
```bash
|
|
9
|
-
npm install @transmitsecurity/platform-web-sdk
|
|
11
|
+
npm install @transmitsecurity/platform-web-sdk@^2
|
|
10
12
|
```
|
|
11
|
-
## Usage Patterns
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
For optimal bundle sizes and performance, import only the modules you need:
|
|
14
|
+
## Initialization
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
// Option 1: Individual function imports (best for tree-shaking)
|
|
18
|
-
import { triggerActionEvent, setUser, clearUser, initialize } from '@transmitsecurity/platform-web-sdk/drs';
|
|
19
|
-
import { isPlatformAuthenticatorSupported, register } from '@transmitsecurity/platform-web-sdk/webauthn';
|
|
20
|
-
import { start } from '@transmitsecurity/platform-web-sdk/idv';
|
|
16
|
+
To benefit from tree-shaking, initialize only the modules you need:
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
await triggerActionEvent('login', { correlationId: 'example' });
|
|
25
|
-
await setUser({ userId: 'user123' });
|
|
26
|
-
const isSupported = await isPlatformAuthenticatorSupported();
|
|
18
|
+
```javascript
|
|
19
|
+
import { initialize } from '@transmitsecurity/platform-web-sdk';
|
|
27
20
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
initialize({
|
|
22
|
+
clientId: 'your-client-id',
|
|
23
|
+
drs: {
|
|
24
|
+
serverPath: 'https://api.transmitsecurity.io/risk-collect/', // Required: Set serverPath based on your region or custom domain
|
|
25
|
+
enableSessionToken: true
|
|
26
|
+
},
|
|
27
|
+
ido: {
|
|
28
|
+
serverPath: 'https://api.transmitsecurity.io/ido' // Required: Set serverPath based on your region or custom domain
|
|
29
|
+
},
|
|
30
|
+
idv: {
|
|
31
|
+
serverPath: 'https://api.transmitsecurity.io/verify' // Required: Set serverPath based on your region or custom domain
|
|
32
|
+
},
|
|
33
|
+
webauthn: {
|
|
34
|
+
serverPath: 'https://api.transmitsecurity.io' // Required: Set serverPath based on your region or custom domain
|
|
35
|
+
}
|
|
36
|
+
});
|
|
32
37
|
```
|
|
33
38
|
|
|
39
|
+
## Usage Patterns
|
|
40
|
+
|
|
41
|
+
### Import Functions from Individual Subpaths (Recommended)
|
|
42
|
+
|
|
43
|
+
For optimal bundle sizes and performance, import specific functions from individual subpaths:
|
|
44
|
+
|
|
45
|
+
> The functions shown below are examples only. For the full list of functions in each module, see [SDK reference](https://developer.transmitsecurity.com/sdk-ref/platform/introduction).
|
|
34
46
|
|
|
35
47
|
```javascript
|
|
36
|
-
|
|
37
|
-
import {
|
|
48
|
+
// Individual function imports
|
|
49
|
+
import { triggerActionEvent, setAuthenticatedUser, clearUser, getSessionToken } from '@transmitsecurity/platform-web-sdk/drs';
|
|
50
|
+
import { isPlatformAuthenticatorSupported, register } from '@transmitsecurity/platform-web-sdk/webauthn';
|
|
51
|
+
import { start } from '@transmitsecurity/platform-web-sdk/idv';
|
|
52
|
+
import { startJourney } from '@transmitsecurity/platform-web-sdk/ido';
|
|
38
53
|
|
|
39
|
-
//
|
|
40
|
-
await
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
54
|
+
// Direct function calls
|
|
55
|
+
await triggerActionEvent('login', { correlationId: 'example' });
|
|
56
|
+
await setAuthenticatedUser('user123');
|
|
57
|
+
await getSessionToken();
|
|
58
|
+
const isSupported = await isPlatformAuthenticatorSupported();
|
|
59
|
+
await startJourney('JOURNEY_ID');
|
|
44
60
|
|
|
45
|
-
// IDO usage
|
|
46
|
-
await ido.startJourney('journey-id');
|
|
47
|
-
await ido.submitClientResponse(
|
|
48
|
-
ClientResponseOptionType.ClientInput,
|
|
49
|
-
{ userEmail: 'user@example.com' }
|
|
50
|
-
);
|
|
51
61
|
```
|
|
52
62
|
|
|
53
63
|
#### TypeScript Support
|
|
54
|
-
Full TypeScript support with individual
|
|
64
|
+
Full TypeScript support with individual imports:
|
|
55
65
|
|
|
56
66
|
```typescript
|
|
57
|
-
import { triggerActionEvent,
|
|
67
|
+
import { triggerActionEvent, setAuthenticatedUser, getSessionToken } from '@transmitsecurity/platform-web-sdk/drs';
|
|
58
68
|
import { isPlatformAuthenticatorSupported } from '@transmitsecurity/platform-web-sdk/webauthn';
|
|
59
69
|
import { start } from '@transmitsecurity/platform-web-sdk/idv';
|
|
60
|
-
import {
|
|
61
|
-
import { initialize } from '@transmitsecurity/platform-web-sdk';
|
|
62
|
-
|
|
63
|
-
// Initialize with TypeScript types
|
|
64
|
-
await initialize({
|
|
65
|
-
clientId: 'your-client-id',
|
|
66
|
-
drs: { serverPath: 'https://api.transmitsecurity.io/risk-collect/' },
|
|
67
|
-
webauthn: { serverPath: 'https://api.transmitsecurity.io' },
|
|
68
|
-
idv: { serverPath: 'https://api.transmitsecurity.io' },
|
|
69
|
-
ido: {
|
|
70
|
-
serverPath: 'https://api.transmitsecurity.io',
|
|
71
|
-
}
|
|
72
|
-
});
|
|
70
|
+
import { submitClientResponse, ClientResponseOptionType } from '@transmitsecurity/platform-web-sdk/ido';
|
|
73
71
|
|
|
74
72
|
// Use with proper TypeScript types
|
|
75
73
|
await triggerActionEvent('login', { correlationId: 'example' });
|
|
74
|
+
await getSessionToken();
|
|
76
75
|
const isSupported: boolean = await isPlatformAuthenticatorSupported();
|
|
77
|
-
await
|
|
76
|
+
await submitClientResponse(
|
|
78
77
|
ClientResponseOptionType.ClientInput,
|
|
79
78
|
{ userEmail: 'user@example.com' }
|
|
80
79
|
);
|
|
81
80
|
```
|
|
82
81
|
|
|
83
|
-
|
|
82
|
+
### Import Individual Modules
|
|
83
|
+
|
|
84
|
+
To leverage namespace calls, import modules from individual subpaths
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
// Individual module imports
|
|
88
|
+
import * as drs from '@transmitsecurity/platform-web-sdk/drs';
|
|
89
|
+
import * as ido from '@transmitsecurity/platform-web-sdk/ido';
|
|
90
|
+
import * as idv from '@transmitsecurity/platform-web-sdk/idv';
|
|
91
|
+
import * as webauthn from '@transmitsecurity/platform-web-sdk/webauthn';
|
|
92
|
+
|
|
93
|
+
// Namespace calls
|
|
94
|
+
await drs.triggerActionEvent('login', { correlationId: 'example' });
|
|
95
|
+
await drs.setAuthenticatedUser('user123');
|
|
96
|
+
await drs.getSessionToken();
|
|
97
|
+
const isSupported = await webauthn.isPlatformAuthenticatorSupported();
|
|
98
|
+
await ido.startJourney('journey-id');
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Import Full SDK (Alternative)
|
|
84
102
|
If you need multiple modules, you can also import the full SDK:
|
|
85
103
|
|
|
86
104
|
```javascript
|
|
87
105
|
import { drs, webauthn, idv, ido, initialize } from '@transmitsecurity/platform-web-sdk';
|
|
88
106
|
|
|
89
|
-
// Single initialize call for all modules
|
|
90
|
-
await initialize({
|
|
91
|
-
clientId: 'your-client-id',
|
|
92
|
-
drs: { serverPath: 'https://api.transmitsecurity.io/risk-collect/' },
|
|
93
|
-
webauthn: { serverPath: 'https://api.transmitsecurity.io' },
|
|
94
|
-
idv: { serverPath: 'https://api.transmitsecurity.io' },
|
|
95
|
-
ido: { serverPath: 'https://api.transmitsecurity.io' }
|
|
96
|
-
});
|
|
97
|
-
|
|
98
107
|
// Use modules through the main object
|
|
99
108
|
await drs.triggerActionEvent('login', { correlationId: 'example' });
|
|
109
|
+
await drs.getSessionToken();
|
|
110
|
+
await ido.startJourney('JOURNEY_ID');
|
|
100
111
|
```
|
package/dist/common.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(i,n){return Object.entries(n).reduce(((n,[a,s])=>({...n,[a]:t.isPrototypeOf(s)?new s(i.slug):"function"==typeof s?s.bind(i):"object"==typeof s&&!Array.isArray(s)&&s?e(i,s):s})),{})}"undefined"==typeof globalThis&&("undefined"!=typeof window?(window.globalThis=window,window.global=window):"undefined"!=typeof self&&(self.globalThis=self,self.global=self)),Object.defineProperty(exports,"__esModule",{value:!0});class t{constructor(e){this.slug=e}static create(i){return class extends t{constructor(t){super(t),Object.assign(this,e(this,i(this)))}}}}var i=Object.freeze({__proto__:null,Agent:t});const n=new Map;function a(e,t){var i,a;null===(i=n.get(e))||void 0===i||i.forEach((a=e=>e(t),(...e)=>{try{return a(...e)}catch(e){console.log(e)}}))}const s=Symbol("MODULE_INITIALIZED");var r=Object.freeze({__proto__:null,MODULE_INITIALIZED:s,emit:a,off:function(e,t){const i=n.get(e);if(!i)return;const a=i.indexOf(t);-1!==a&&i.splice(a,1)},on:function(e,t){var i;n.has(e)?null===(i=n.get(e))||void 0===i||i.push(t):n.set(e,[t])}});let o=null;function c(e){o=e}var d=Object.freeze({__proto__:null,getInitConfig:function(){return o},get initConfig(){return o},setInitConfig:c});function y(e){c(e),a(s,void 0)}var l=Object.freeze({__proto__:null,initialize:y});function u(e,t){const i=!e||"object"!=typeof e||Array.isArray(e)?{}:e;return[t.reduce(((e,t)=>{if(t in e){const i=e[t];if(null!==i&&"object"==typeof i&&!Array.isArray(i))return i}const i={};return e[t]=i,i}),i),i]}const h="tsec",g="general";function f(e){return e?g:o.clientId}function p(e){return function(e){if(!e)return{};try{return JSON.parse(e)}catch(e){return{}}}((e?sessionStorage:localStorage).getItem(h))}function w(e,t){const i=e?sessionStorage:localStorage,n=t(p(e));i.setItem(h,JSON.stringify(n))}var K=Object.freeze({__proto__:null,COMMON_STORAGE_KEY:h,GENERAL_ID_KEY:g,getValue:function(e,t={}){const i=f(!!t.isGeneral),n=p(!!t.sessionOnly),[a]=u(n,[this.slug.toString(),i]);return a[e]},hasValue:function(e,t={}){const i=f(!!t.isGeneral);return function(e,t){let i=e;return t.every((e=>!(!i||"object"!=typeof i||Array.isArray(i)||!(e in i)||(i=i[e],0))),e)}(p(!!t.sessionOnly),[this.slug.toString(),i,e])},removeValue:function(e,t={}){const i=f(!!t.isGeneral);w(!!t.sessionOnly,(t=>{const[n,a]=u(t,[this.slug.toString(),i]);return delete n[e],a}))},setValue:function(e,t,i={}){const n=f(!!i.isGeneral);w(!!i.sessionOnly,(i=>{const[a,s]=u(i,[this.slug.toString(),n]);return a[e]=t,s}))}});const b="RSA-PSS",m=async(e,t)=>await window.crypto.subtle.generateKey({name:e,modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:"SHA-256"},!1,t),v=async()=>await m("RSA-OAEP",["encrypt","decrypt"]),D=async()=>await m(b,["sign"]),R=async(e,t)=>{const i=(new TextEncoder).encode(t);return await window.crypto.subtle.sign({name:b,saltLength:32},e,i)};class S{constructor(e,t,i){this.slug=e,this.dbName=t,this.dbVersion=i}queryObjectStore(e,t,i={}){const{attemptToRecoverDB:n=!0}=i,a=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB||window.shimIndexedDB,s=`${this.slug}:${this.dbName}`,r=a.open(s,this.dbVersion||1);r.onupgradeneeded=()=>{var t;const i=r.result;(null===(t=null==i?void 0:i.objectStoreNames)||void 0===t?void 0:t.contains)&&!i.objectStoreNames.contains(e)&&i.createObjectStore(e,{keyPath:"key"})},r.onsuccess=()=>{const o=r.result;let c;try{c=o.transaction(e,(null==i?void 0:i.operation)||"readwrite")}catch(r){if(n&&r instanceof DOMException&&"NotFoundError"===r.name){o.close();return void(a.deleteDatabase(s).onsuccess=()=>{this.queryObjectStore(e,t,{...i,attemptToRecoverDB:!1})})}throw r}const d=c.objectStore(e);t(d,o),c.oncomplete||(c.oncomplete=()=>{o.close()})}}put(e,t,i){return new Promise(((n,a)=>{this.queryObjectStore(e,(e=>{const s=e.put({key:t,value:i});s.onsuccess=()=>{n(s.result)},s.onerror=e=>{a("Failed adding item to objectStore, err: "+e)}}))}))}add(e,t,i){return new Promise(((n,a)=>{this.queryObjectStore(e,(e=>{const s=e.add({key:t,value:i});s.onsuccess=()=>{n(s.result)},s.onerror=e=>{const t=e.target.error;a(t)}}))}))}get(e,t){return new Promise(((i,n)=>{this.queryObjectStore(e,(e=>{const a=e.get(t);a.onsuccess=()=>{var e;a.result?i(null===(e=a.result)||void 0===e?void 0:e.value):i(void 0)},a.onerror=e=>{n("Failed adding item to objectStore, err: "+e)}}))}))}getAll(e,t){return new Promise(((i,n)=>{this.queryObjectStore(e,(e=>{const a=e.getAll(null,t);a.onsuccess=()=>{if(a.result){const e=a.result;(null==e?void 0:e.length)?i(e.map((e=>null==e?void 0:e.value))):i(e)}else i([])},a.onerror=e=>{n("Failed getting items, err: "+e)}}))}))}delete(e,t){return new Promise(((i,n)=>{this.queryObjectStore(e,(e=>{const a=e.delete(t);a.onsuccess=()=>{i()},a.onerror=e=>{n(`Failed deleting key: '${t}' from objectStore, err: `+e)}}))}))}clear(e){return new Promise(((t,i)=>{this.queryObjectStore(e,(e=>{const n=e.clear();n.onsuccess=()=>{t()},n.onerror=e=>{i("Failed clearing objectStore, err: "+e)}}))}))}executeTransaction(e,t){return new Promise(((i,n)=>{this.queryObjectStore(e,((e,a)=>{const s=e.transaction;s.onerror=()=>{n(`Transaction failed: ${s.error}`)},s.onabort=()=>{n("Transaction aborted")},s.oncomplete=()=>{a.close(),i()};for(const i of t){let t;if("delete"===i.type)t=e.delete(i.key);else{if("put"!==i.type)return s.abort(),void n("Unknown operation type");t=e.put({key:i.key,value:i.value})}t.onerror=()=>{s.abort(),n(`Operation failed: ${t.error}`)}}}))}))}}const k="init",_="completed",x="RSA2048",P=[k,_];class O{constructor(e,t="sign",i){var n,a,s,r,o;this.agent=e,this.keysType=t,this.options=i,this._extractingKeysPromise=null;const c=!(null===(n=this.options)||void 0===n?void 0:n.productScope),d=null===(a=this.options)||void 0===a?void 0:a.fallbackClientId;this.keysDatabaseName=c||!(null===(s=this.options)||void 0===s?void 0:s.indexedDBName)?"ts_crypto_binding":this.options.indexedDBName,this.dbVersion=c?1:(null===(r=this.options)||void 0===r?void 0:r.dbVersion)||1,this.keysStoreName=c||!(null===(o=this.options)||void 0===o?void 0:o.keysStoreName)?"identifiers_store":this.options.keysStoreName;const y=c?"platform":e.slug,l=this.getClientConfiguration(d,y);this.indexedDBClient=new S(l.main,this.keysDatabaseName,this.dbVersion),this.indexedDBClientFallback=new S(l.fallback,this.keysDatabaseName,this.dbVersion)}getClientConfiguration(e,t){return e?{main:t,fallback:`${t}:${e}`}:{main:t,fallback:`${t}:${o.clientId}`}}getKeysRecordKey(){return`${this.keysType}_keys`}getRotatedKeysRecordKey(){return`rotated_${this.keysType}_keys`}getRotatedKeysRecordKeyPending(){return`rotated_pending_${this.keysType}_keys`}arrayBufferToBase64(e){return window.btoa(String.fromCharCode(...new Uint8Array(e)))}async getPKRepresentations(e){const t=await crypto.subtle.exportKey("spki",e);return{arrayBufferKey:t,base64Key:this.arrayBufferToBase64(t)}}async generateKeyPair(){return"sign"==this.keysType?await D():await v()}async calcKeyIdentifier(e){const t=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(t)).map((e=>e.toString(16).padStart(2,"0"))).join("")}async extractKeysData(){if(this._extractingKeysPromise)return this._extractingKeysPromise;this._extractingKeysPromise=(async()=>{var e,t;const i=(null===(t=null===(e=this.options)||void 0===e?void 0:e.keyRotation)||void 0===t?void 0:t.isEnabled)?await this.getRotatedKeysData():await this.getKeysData(),{arrayBufferKey:n,base64Key:a}=await this.getPKRepresentations(i.publicKey);return this.publicKeyBase64=a,this.keyIdentifier=i.keyIdentifier,this.currentKeyId=await this.calcKeyIdentifier(n),i})();try{return await this._extractingKeysPromise}finally{this._extractingKeysPromise=null}}async generateKeyPairData(e){const t=await this.generateKeyPair(),{arrayBufferKey:i}=await this.getPKRepresentations(t.publicKey),n=e||await this.calcKeyIdentifier(i);return{...t,keyIdentifier:n,createdDate:Date.now()}}shouldKeyBeRotated(e){var t;const i=null===(t=this.options)||void 0===t?void 0:t.keyRotation;if(!(null==i?void 0:i.isEnabled)||!i.expiryDays||void 0===i.startedAt)return!1;const n=24*i.expiryDays*60*60*1e3,a=e.createdDate&&e.createdDate>=i.startedAt?e.createdDate:i.startedAt;return Date.now()-a>n-2592e6}async extractMainKeysData(){return await this.indexedDBClient.get(this.keysStoreName,this.getKeysRecordKey())}async extractFallbackMainKeysData(){return await this.indexedDBClientFallback.get(this.keysStoreName,this.getKeysRecordKey())}async extractRotatedKeysData(){return await this.indexedDBClient.get(this.keysStoreName,this.getRotatedKeysRecordKey())}async extractPendingRotatedKeysData(){return await this.indexedDBClient.get(this.keysStoreName,this.getRotatedKeysRecordKeyPending())}async saveKeyData(e,t){try{return await this.indexedDBClient.add(this.keysStoreName,e,t),t}catch(t){if(t instanceof DOMException&&"ConstraintError"===t.name){const t=await this.indexedDBClient.get(this.keysStoreName,e);if(t)return t}throw t}}async getKeysData(){const e=this.getKeysRecordKey();let t=await this.extractMainKeysData();if(t)return t;if(t=await this.extractFallbackMainKeysData(),t)return this.saveKeyData(e,t);const i=await this.generateKeyPairData();return this.saveKeyData(e,i)}async getOrCreateRotatedKeys(){let e=await this.extractRotatedKeysData();if(!e){const t=this.getRotatedKeysRecordKey(),i=await this.getKeysData(),n={...i,createdDate:i.createdDate||Date.now()};e=await this.saveKeyData(t,n)}return e}async getRotatedKeysData(){const e=await this.getOrCreateRotatedKeys();if(this.shouldKeyBeRotated(e)){if(!await this.extractPendingRotatedKeysData()){const t=this.getRotatedKeysRecordKeyPending(),i=await this.generateKeyPairData(e.keyIdentifier);await this.saveKeyData(t,i)}}return e}async getPublicData(){return this.publicKeyBase64&&this.keyIdentifier&&this.currentKeyId||await this.extractKeysData(),{publicKey:this.publicKeyBase64,keyIdentifier:this.keyIdentifier,currentKeyId:this.currentKeyId}}async sign(e){if("sign"==this.keysType){const{privateKey:t}=await this.extractKeysData(),i=await R(t,e);return this.arrayBufferToBase64(i)}throw new Error("keysType must be 'sign' in order to use sign keys")}async clearKeys(){const e=this.getKeysRecordKey();await this.indexedDBClient.delete(this.keysStoreName,e)}getBaseRotationPayload(){return{keyIdentifier:this.keyIdentifier,slot:this.getRotatedKeysRecordKey(),publicKey:this.publicKeyBase64,publicKeyType:x,tenantId:this.options.keyRotation.tenantId}}async getRotationData(){var e,t;if(!(null===(t=null===(e=this.options)||void 0===e?void 0:e.keyRotation)||void 0===t?void 0:t.isEnabled))return;this.publicKeyBase64&&this.keyIdentifier&&this.currentKeyId||await this.extractKeysData();const i=await this.extractPendingRotatedKeysData();if(i){const{base64Key:e}=await this.getPKRepresentations(i.publicKey),{privateKey:t}=await this.extractKeysData(),n={...this.getBaseRotationPayload(),newPublicKey:e,createdDate:i.createdDate,newPublicKeyType:x},a=JSON.stringify(n);return{data:a,signature:await this.signPayload(a,t)}}const n=await this.extractRotatedKeysData();if(n&&!1===n.confirmed){await this.extractKeysData();const e=JSON.stringify(this.getBaseRotationPayload());return{data:e,signature:await this.signPayload(e,n.privateKey)}}}async signPayload(e,t){const i=await R(t,e);return this.arrayBufferToBase64(i)}async handleRotateResponse(e){if(P.includes(e))if(e===k){const e=await this.extractPendingRotatedKeysData();if(e){const t={...e,confirmed:!1};await this.indexedDBClient.executeTransaction(this.keysStoreName,[{type:"delete",key:this.getRotatedKeysRecordKey()},{type:"put",key:this.getRotatedKeysRecordKey(),value:t},{type:"delete",key:this.getRotatedKeysRecordKeyPending()}]);const{arrayBufferKey:i,base64Key:n}=await this.getPKRepresentations(e.publicKey);this.publicKeyBase64=n,this.keyIdentifier=e.keyIdentifier,this.currentKeyId=await this.calcKeyIdentifier(i)}}else if(e===_){const e=await this.extractRotatedKeysData();e&&!1===e.confirmed&&await this.indexedDBClient.put(this.keysStoreName,this.getRotatedKeysRecordKey(),{...e,confirmed:!0})}}}var I=Object.freeze({__proto__:null,COMPLETED_ROTATION_RESPONSE:_,INIT_ROTATION_RESPONSE:k,createCryptoBinding:function(e="sign",t){return new O(this,e,t)},generateRSAKeyPair:v,generateRSASignKeyPair:D,signAssymetric:R,verifyAssymetric:async(e,t,i)=>{const n=(new TextEncoder).encode(t);return await window.crypto.subtle.verify(b,e,i,n)}}),B=Object.freeze({__proto__:null});const T=t.create((e=>{class t extends Error{constructor(t,i){super(`${e.slug}-${t} ${i}`)}}return{TsError:t,TsInternalError:class extends t{constructor(e){super(e,"Internal error")}}}}));var j=t.create((()=>({exceptions:T,...i})));class E{constructor(e,t=[]){this.agent=e,this.middlewares=t,this.logs=[]}info(e,t){this.pushLog(3,e,t)}warn(e,t){this.pushLog(4,e,t)}error(e,t){this.pushLog(5,e,t)}pushLog(e,t,i={}){this.logs.push({timestamp:Date.now(),module:this.agent.slug,severity:e,fields:i,message:t});const n=this.middlewares.map((e=>e(this)));Promise.all(n).catch((()=>{}))}}var N=Object.freeze({__proto__:null,consoleMiddleware:function(e){const t=e.logs[e.logs.length-1];console.log(`${t.severity} ${t.message}`,t.fields)},createSdkLogger:function(e=[]){return new E(this,e)}});function A(e,t){if(!(null==e?void 0:e.trim()))return"";if(function(e){try{return new URL(e),!0}catch(e){return!1}}(e))return e;const i="http://mock.com",n=new URL(i);n.search=(null==t?void 0:t.toString())||"",n.pathname=e;return n.href.replace(i,"")}const C={"Content-Type":"application/json","X-TS-client-time":(new Date).toUTCString(),"X-TS-ua":navigator.userAgent};function $(e,t,i){var n;const a=(s=t||{},encodeURI(JSON.stringify(s)).split(/%..|./).length-1);var s;return{method:e,headers:{...{"X-TS-body-size":String(a)},...C,...i||{}},body:null!==(n=t&&JSON.stringify(t||{}))&&void 0!==n?n:void 0}}function L(e,t,i,n,a){const s=A(e,n),r=$(t,i,a);return fetch(s,r)}async function M(e,t,i,n,a){let s;if(s=await L(e,t,i,n,a),!s.ok)throw new Error("Request failed");return s}var z=Object.freeze({__proto__:null,httpDelete:async function(e,t){const i=await M(e,"DELETE",void 0,void 0,t);return{data:await i.json(),...i,headers:i.headers}},httpGet:async function(e,t,i){const n=await M(e,"GET",void 0,t,i);return{data:await n.json(),...n,headers:n.headers}},httpPost:async function(e,t,i,n){const a=await M(e,"POST",t,i,n);return{data:await a.json(),...a,headers:a.headers}},httpPut:async function(e,t,i,n){const a=await M(e,"PUT",t,i,n);return{data:await a.json(),...a,headers:a.headers}},init:$}),U=t.create((()=>({events:r,moduleMetadata:d,mainEntry:l,utils:j,storage:K,crypto:I,indexedDB:B,logger:N,http:z})));exports.PACKAGE_VERSION="2.0.0",exports.default=U,exports.initialize=y;
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare module './events' {
|
|
2
|
+
interface eventNameToDataParam {
|
|
3
|
+
[MODULE_INITIALIZED]: undefined;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
declare const MODULE_INITIALIZED: unique symbol;
|
|
7
|
+
|
|
8
|
+
declare const PACKAGE_VERSION: string;
|
|
9
|
+
declare function initialize(config: any): void;
|
|
10
|
+
|
|
11
|
+
export { PACKAGE_VERSION, initialize };
|
package/dist/common.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(n,i){return Object.entries(i).reduce(((i,[a,s])=>({...i,[a]:t.isPrototypeOf(s)?new s(n.slug):"function"==typeof s?s.bind(n):"object"==typeof s&&!Array.isArray(s)&&s?e(n,s):s})),{})}"undefined"==typeof globalThis&&("undefined"!=typeof window?(window.globalThis=window,window.global=window):"undefined"!=typeof self&&(self.globalThis=self,self.global=self));class t{constructor(e){this.slug=e}static create(n){return class extends t{constructor(t){super(t),Object.assign(this,e(this,n(this)))}}}}var n=Object.freeze({__proto__:null,Agent:t});const i=new Map;function a(e,t){var n,a;null===(n=i.get(e))||void 0===n||n.forEach((a=e=>e(t),(...e)=>{try{return a(...e)}catch(e){console.log(e)}}))}const s=Symbol("MODULE_INITIALIZED");var r=Object.freeze({__proto__:null,MODULE_INITIALIZED:s,emit:a,off:function(e,t){const n=i.get(e);if(!n)return;const a=n.indexOf(t);-1!==a&&n.splice(a,1)},on:function(e,t){var n;i.has(e)?null===(n=i.get(e))||void 0===n||n.push(t):i.set(e,[t])}});let o=null;function c(e){o=e}var d=Object.freeze({__proto__:null,getInitConfig:function(){return o},get initConfig(){return o},setInitConfig:c});function y(e){c(e),a(s,void 0)}var l=Object.freeze({__proto__:null,initialize:y});function u(e,t){const n=!e||"object"!=typeof e||Array.isArray(e)?{}:e;return[t.reduce(((e,t)=>{if(t in e){const n=e[t];if(null!==n&&"object"==typeof n&&!Array.isArray(n))return n}const n={};return e[t]=n,n}),n),n]}const h="tsec",g="general";function f(e){return e?g:o.clientId}function p(e){return function(e){if(!e)return{};try{return JSON.parse(e)}catch(e){return{}}}((e?sessionStorage:localStorage).getItem(h))}function w(e,t){const n=e?sessionStorage:localStorage,i=t(p(e));n.setItem(h,JSON.stringify(i))}var K=Object.freeze({__proto__:null,COMMON_STORAGE_KEY:h,GENERAL_ID_KEY:g,getValue:function(e,t={}){const n=f(!!t.isGeneral),i=p(!!t.sessionOnly),[a]=u(i,[this.slug.toString(),n]);return a[e]},hasValue:function(e,t={}){const n=f(!!t.isGeneral);return function(e,t){let n=e;return t.every((e=>!(!n||"object"!=typeof n||Array.isArray(n)||!(e in n)||(n=n[e],0))),e)}(p(!!t.sessionOnly),[this.slug.toString(),n,e])},removeValue:function(e,t={}){const n=f(!!t.isGeneral);w(!!t.sessionOnly,(t=>{const[i,a]=u(t,[this.slug.toString(),n]);return delete i[e],a}))},setValue:function(e,t,n={}){const i=f(!!n.isGeneral);w(!!n.sessionOnly,(n=>{const[a,s]=u(n,[this.slug.toString(),i]);return a[e]=t,s}))}});const b="RSA-PSS",m=async(e,t)=>await window.crypto.subtle.generateKey({name:e,modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:"SHA-256"},!1,t),v=async()=>await m("RSA-OAEP",["encrypt","decrypt"]),D=async()=>await m(b,["sign"]),R=async(e,t)=>{const n=(new TextEncoder).encode(t);return await window.crypto.subtle.sign({name:b,saltLength:32},e,n)};class S{constructor(e,t,n){this.slug=e,this.dbName=t,this.dbVersion=n}queryObjectStore(e,t,n={}){const{attemptToRecoverDB:i=!0}=n,a=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB||window.shimIndexedDB,s=`${this.slug}:${this.dbName}`,r=a.open(s,this.dbVersion||1);r.onupgradeneeded=()=>{var t;const n=r.result;(null===(t=null==n?void 0:n.objectStoreNames)||void 0===t?void 0:t.contains)&&!n.objectStoreNames.contains(e)&&n.createObjectStore(e,{keyPath:"key"})},r.onsuccess=()=>{const o=r.result;let c;try{c=o.transaction(e,(null==n?void 0:n.operation)||"readwrite")}catch(r){if(i&&r instanceof DOMException&&"NotFoundError"===r.name){o.close();return void(a.deleteDatabase(s).onsuccess=()=>{this.queryObjectStore(e,t,{...n,attemptToRecoverDB:!1})})}throw r}const d=c.objectStore(e);t(d,o),c.oncomplete||(c.oncomplete=()=>{o.close()})}}put(e,t,n){return new Promise(((i,a)=>{this.queryObjectStore(e,(e=>{const s=e.put({key:t,value:n});s.onsuccess=()=>{i(s.result)},s.onerror=e=>{a("Failed adding item to objectStore, err: "+e)}}))}))}add(e,t,n){return new Promise(((i,a)=>{this.queryObjectStore(e,(e=>{const s=e.add({key:t,value:n});s.onsuccess=()=>{i(s.result)},s.onerror=e=>{const t=e.target.error;a(t)}}))}))}get(e,t){return new Promise(((n,i)=>{this.queryObjectStore(e,(e=>{const a=e.get(t);a.onsuccess=()=>{var e;a.result?n(null===(e=a.result)||void 0===e?void 0:e.value):n(void 0)},a.onerror=e=>{i("Failed adding item to objectStore, err: "+e)}}))}))}getAll(e,t){return new Promise(((n,i)=>{this.queryObjectStore(e,(e=>{const a=e.getAll(null,t);a.onsuccess=()=>{if(a.result){const e=a.result;(null==e?void 0:e.length)?n(e.map((e=>null==e?void 0:e.value))):n(e)}else n([])},a.onerror=e=>{i("Failed getting items, err: "+e)}}))}))}delete(e,t){return new Promise(((n,i)=>{this.queryObjectStore(e,(e=>{const a=e.delete(t);a.onsuccess=()=>{n()},a.onerror=e=>{i(`Failed deleting key: '${t}' from objectStore, err: `+e)}}))}))}clear(e){return new Promise(((t,n)=>{this.queryObjectStore(e,(e=>{const i=e.clear();i.onsuccess=()=>{t()},i.onerror=e=>{n("Failed clearing objectStore, err: "+e)}}))}))}executeTransaction(e,t){return new Promise(((n,i)=>{this.queryObjectStore(e,((e,a)=>{const s=e.transaction;s.onerror=()=>{i(`Transaction failed: ${s.error}`)},s.onabort=()=>{i("Transaction aborted")},s.oncomplete=()=>{a.close(),n()};for(const n of t){let t;if("delete"===n.type)t=e.delete(n.key);else{if("put"!==n.type)return s.abort(),void i("Unknown operation type");t=e.put({key:n.key,value:n.value})}t.onerror=()=>{s.abort(),i(`Operation failed: ${t.error}`)}}}))}))}}const k="init",_="completed",x="RSA2048",P=[k,_];class O{constructor(e,t="sign",n){var i,a,s,r,o;this.agent=e,this.keysType=t,this.options=n,this._extractingKeysPromise=null;const c=!(null===(i=this.options)||void 0===i?void 0:i.productScope),d=null===(a=this.options)||void 0===a?void 0:a.fallbackClientId;this.keysDatabaseName=c||!(null===(s=this.options)||void 0===s?void 0:s.indexedDBName)?"ts_crypto_binding":this.options.indexedDBName,this.dbVersion=c?1:(null===(r=this.options)||void 0===r?void 0:r.dbVersion)||1,this.keysStoreName=c||!(null===(o=this.options)||void 0===o?void 0:o.keysStoreName)?"identifiers_store":this.options.keysStoreName;const y=c?"platform":e.slug,l=this.getClientConfiguration(d,y);this.indexedDBClient=new S(l.main,this.keysDatabaseName,this.dbVersion),this.indexedDBClientFallback=new S(l.fallback,this.keysDatabaseName,this.dbVersion)}getClientConfiguration(e,t){return e?{main:t,fallback:`${t}:${e}`}:{main:t,fallback:`${t}:${o.clientId}`}}getKeysRecordKey(){return`${this.keysType}_keys`}getRotatedKeysRecordKey(){return`rotated_${this.keysType}_keys`}getRotatedKeysRecordKeyPending(){return`rotated_pending_${this.keysType}_keys`}arrayBufferToBase64(e){return window.btoa(String.fromCharCode(...new Uint8Array(e)))}async getPKRepresentations(e){const t=await crypto.subtle.exportKey("spki",e);return{arrayBufferKey:t,base64Key:this.arrayBufferToBase64(t)}}async generateKeyPair(){return"sign"==this.keysType?await D():await v()}async calcKeyIdentifier(e){const t=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(t)).map((e=>e.toString(16).padStart(2,"0"))).join("")}async extractKeysData(){if(this._extractingKeysPromise)return this._extractingKeysPromise;this._extractingKeysPromise=(async()=>{var e,t;const n=(null===(t=null===(e=this.options)||void 0===e?void 0:e.keyRotation)||void 0===t?void 0:t.isEnabled)?await this.getRotatedKeysData():await this.getKeysData(),{arrayBufferKey:i,base64Key:a}=await this.getPKRepresentations(n.publicKey);return this.publicKeyBase64=a,this.keyIdentifier=n.keyIdentifier,this.currentKeyId=await this.calcKeyIdentifier(i),n})();try{return await this._extractingKeysPromise}finally{this._extractingKeysPromise=null}}async generateKeyPairData(e){const t=await this.generateKeyPair(),{arrayBufferKey:n}=await this.getPKRepresentations(t.publicKey),i=e||await this.calcKeyIdentifier(n);return{...t,keyIdentifier:i,createdDate:Date.now()}}shouldKeyBeRotated(e){var t;const n=null===(t=this.options)||void 0===t?void 0:t.keyRotation;if(!(null==n?void 0:n.isEnabled)||!n.expiryDays||void 0===n.startedAt)return!1;const i=24*n.expiryDays*60*60*1e3,a=e.createdDate&&e.createdDate>=n.startedAt?e.createdDate:n.startedAt;return Date.now()-a>i-2592e6}async extractMainKeysData(){return await this.indexedDBClient.get(this.keysStoreName,this.getKeysRecordKey())}async extractFallbackMainKeysData(){return await this.indexedDBClientFallback.get(this.keysStoreName,this.getKeysRecordKey())}async extractRotatedKeysData(){return await this.indexedDBClient.get(this.keysStoreName,this.getRotatedKeysRecordKey())}async extractPendingRotatedKeysData(){return await this.indexedDBClient.get(this.keysStoreName,this.getRotatedKeysRecordKeyPending())}async saveKeyData(e,t){try{return await this.indexedDBClient.add(this.keysStoreName,e,t),t}catch(t){if(t instanceof DOMException&&"ConstraintError"===t.name){const t=await this.indexedDBClient.get(this.keysStoreName,e);if(t)return t}throw t}}async getKeysData(){const e=this.getKeysRecordKey();let t=await this.extractMainKeysData();if(t)return t;if(t=await this.extractFallbackMainKeysData(),t)return this.saveKeyData(e,t);const n=await this.generateKeyPairData();return this.saveKeyData(e,n)}async getOrCreateRotatedKeys(){let e=await this.extractRotatedKeysData();if(!e){const t=this.getRotatedKeysRecordKey(),n=await this.getKeysData(),i={...n,createdDate:n.createdDate||Date.now()};e=await this.saveKeyData(t,i)}return e}async getRotatedKeysData(){const e=await this.getOrCreateRotatedKeys();if(this.shouldKeyBeRotated(e)){if(!await this.extractPendingRotatedKeysData()){const t=this.getRotatedKeysRecordKeyPending(),n=await this.generateKeyPairData(e.keyIdentifier);await this.saveKeyData(t,n)}}return e}async getPublicData(){return this.publicKeyBase64&&this.keyIdentifier&&this.currentKeyId||await this.extractKeysData(),{publicKey:this.publicKeyBase64,keyIdentifier:this.keyIdentifier,currentKeyId:this.currentKeyId}}async sign(e){if("sign"==this.keysType){const{privateKey:t}=await this.extractKeysData(),n=await R(t,e);return this.arrayBufferToBase64(n)}throw new Error("keysType must be 'sign' in order to use sign keys")}async clearKeys(){const e=this.getKeysRecordKey();await this.indexedDBClient.delete(this.keysStoreName,e)}getBaseRotationPayload(){return{keyIdentifier:this.keyIdentifier,slot:this.getRotatedKeysRecordKey(),publicKey:this.publicKeyBase64,publicKeyType:x,tenantId:this.options.keyRotation.tenantId}}async getRotationData(){var e,t;if(!(null===(t=null===(e=this.options)||void 0===e?void 0:e.keyRotation)||void 0===t?void 0:t.isEnabled))return;this.publicKeyBase64&&this.keyIdentifier&&this.currentKeyId||await this.extractKeysData();const n=await this.extractPendingRotatedKeysData();if(n){const{base64Key:e}=await this.getPKRepresentations(n.publicKey),{privateKey:t}=await this.extractKeysData(),i={...this.getBaseRotationPayload(),newPublicKey:e,createdDate:n.createdDate,newPublicKeyType:x},a=JSON.stringify(i);return{data:a,signature:await this.signPayload(a,t)}}const i=await this.extractRotatedKeysData();if(i&&!1===i.confirmed){await this.extractKeysData();const e=JSON.stringify(this.getBaseRotationPayload());return{data:e,signature:await this.signPayload(e,i.privateKey)}}}async signPayload(e,t){const n=await R(t,e);return this.arrayBufferToBase64(n)}async handleRotateResponse(e){if(P.includes(e))if(e===k){const e=await this.extractPendingRotatedKeysData();if(e){const t={...e,confirmed:!1};await this.indexedDBClient.executeTransaction(this.keysStoreName,[{type:"delete",key:this.getRotatedKeysRecordKey()},{type:"put",key:this.getRotatedKeysRecordKey(),value:t},{type:"delete",key:this.getRotatedKeysRecordKeyPending()}]);const{arrayBufferKey:n,base64Key:i}=await this.getPKRepresentations(e.publicKey);this.publicKeyBase64=i,this.keyIdentifier=e.keyIdentifier,this.currentKeyId=await this.calcKeyIdentifier(n)}}else if(e===_){const e=await this.extractRotatedKeysData();e&&!1===e.confirmed&&await this.indexedDBClient.put(this.keysStoreName,this.getRotatedKeysRecordKey(),{...e,confirmed:!0})}}}var I=Object.freeze({__proto__:null,COMPLETED_ROTATION_RESPONSE:_,INIT_ROTATION_RESPONSE:k,createCryptoBinding:function(e="sign",t){return new O(this,e,t)},generateRSAKeyPair:v,generateRSASignKeyPair:D,signAssymetric:R,verifyAssymetric:async(e,t,n)=>{const i=(new TextEncoder).encode(t);return await window.crypto.subtle.verify(b,e,n,i)}}),B=Object.freeze({__proto__:null});const T=t.create((e=>{class t extends Error{constructor(t,n){super(`${e.slug}-${t} ${n}`)}}return{TsError:t,TsInternalError:class extends t{constructor(e){super(e,"Internal error")}}}}));var j=t.create((()=>({exceptions:T,...n})));class E{constructor(e,t=[]){this.agent=e,this.middlewares=t,this.logs=[]}info(e,t){this.pushLog(3,e,t)}warn(e,t){this.pushLog(4,e,t)}error(e,t){this.pushLog(5,e,t)}pushLog(e,t,n={}){this.logs.push({timestamp:Date.now(),module:this.agent.slug,severity:e,fields:n,message:t});const i=this.middlewares.map((e=>e(this)));Promise.all(i).catch((()=>{}))}}var N=Object.freeze({__proto__:null,consoleMiddleware:function(e){const t=e.logs[e.logs.length-1];console.log(`${t.severity} ${t.message}`,t.fields)},createSdkLogger:function(e=[]){return new E(this,e)}});function A(e,t){if(!(null==e?void 0:e.trim()))return"";if(function(e){try{return new URL(e),!0}catch(e){return!1}}(e))return e;const n="http://mock.com",i=new URL(n);i.search=(null==t?void 0:t.toString())||"",i.pathname=e;return i.href.replace(n,"")}const C={"Content-Type":"application/json","X-TS-client-time":(new Date).toUTCString(),"X-TS-ua":navigator.userAgent};function $(e,t,n){var i;const a=(s=t||{},encodeURI(JSON.stringify(s)).split(/%..|./).length-1);var s;return{method:e,headers:{...{"X-TS-body-size":String(a)},...C,...n||{}},body:null!==(i=t&&JSON.stringify(t||{}))&&void 0!==i?i:void 0}}function L(e,t,n,i,a){const s=A(e,i),r=$(t,n,a);return fetch(s,r)}async function M(e,t,n,i,a){let s;if(s=await L(e,t,n,i,a),!s.ok)throw new Error("Request failed");return s}var z=Object.freeze({__proto__:null,httpDelete:async function(e,t){const n=await M(e,"DELETE",void 0,void 0,t);return{data:await n.json(),...n,headers:n.headers}},httpGet:async function(e,t,n){const i=await M(e,"GET",void 0,t,n);return{data:await i.json(),...i,headers:i.headers}},httpPost:async function(e,t,n,i){const a=await M(e,"POST",t,n,i);return{data:await a.json(),...a,headers:a.headers}},httpPut:async function(e,t,n,i){const a=await M(e,"PUT",t,n,i);return{data:await a.json(),...a,headers:a.headers}},init:$}),U=t.create((()=>({events:r,moduleMetadata:d,mainEntry:l,utils:j,storage:K,crypto:I,indexedDB:B,logger:N,http:z})));const q="2.0.0";export{q as PACKAGE_VERSION,U as default,y as initialize};
|