@explorins/pers-sdk 2.0.6 → 2.0.7
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/dist/campaign/api/campaign-api.d.ts +19 -8
- package/dist/campaign/api/campaign-api.d.ts.map +1 -1
- package/dist/campaign/services/campaign-service.d.ts +10 -2
- package/dist/campaign/services/campaign-service.d.ts.map +1 -1
- package/dist/campaign.cjs +1 -1
- package/dist/campaign.js +1 -1
- package/dist/chunks/{campaign-service-Ae164xl8.cjs → campaign-service-CdEz0jpP.cjs} +29 -16
- package/dist/chunks/{campaign-service-Ae164xl8.cjs.map → campaign-service-CdEz0jpP.cjs.map} +1 -1
- package/dist/chunks/{campaign-service-rlK4WeSY.js → campaign-service-DrTAqFZM.js} +29 -16
- package/dist/chunks/{campaign-service-rlK4WeSY.js.map → campaign-service-DrTAqFZM.js.map} +1 -1
- package/dist/chunks/environment-C73snhIJ.cjs +145 -0
- package/dist/chunks/environment-C73snhIJ.cjs.map +1 -0
- package/dist/chunks/environment-CKVwRAEL.js +140 -0
- package/dist/chunks/environment-CKVwRAEL.js.map +1 -0
- package/dist/chunks/node-http-client-D_avaa5F.cjs +88 -0
- package/dist/chunks/node-http-client-D_avaa5F.cjs.map +1 -0
- package/dist/chunks/node-http-client-DloDLfm9.js +86 -0
- package/dist/chunks/node-http-client-DloDLfm9.js.map +1 -0
- package/dist/chunks/{pers-sdk-DLTY5heK.js → pers-sdk-JIExM712.js} +51 -157
- package/dist/chunks/pers-sdk-JIExM712.js.map +1 -0
- package/dist/chunks/{pers-sdk-Bm6y6cX4.cjs → pers-sdk-h-uoLpBx.cjs} +50 -160
- package/dist/chunks/pers-sdk-h-uoLpBx.cjs.map +1 -0
- package/dist/chunks/{web3-chain-service-6vsVHPjl.cjs → web3-chain-service-BeBjALg2.cjs} +82 -163
- package/dist/chunks/web3-chain-service-BeBjALg2.cjs.map +1 -0
- package/dist/chunks/{web3-chain-service-BcUeeujC.js → web3-chain-service-DKHCnHQX.js} +83 -163
- package/dist/chunks/web3-chain-service-DKHCnHQX.js.map +1 -0
- package/dist/core/auth/static-jwt-auth-provider.d.ts +5 -0
- package/dist/core/auth/static-jwt-auth-provider.d.ts.map +1 -1
- package/dist/core/errors/index.d.ts +30 -83
- package/dist/core/errors/index.d.ts.map +1 -1
- package/dist/core/pers-api-client.d.ts.map +1 -1
- package/dist/core/version.d.ts +3 -3
- package/dist/core/version.d.ts.map +1 -1
- package/dist/core.cjs +8 -8
- package/dist/core.js +4 -3
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +10 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/managers/campaign-manager.d.ts +36 -1
- package/dist/managers/campaign-manager.d.ts.map +1 -1
- package/dist/node.cjs +100 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.ts +70 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +94 -0
- package/dist/node.js.map +1 -0
- package/dist/package.json +9 -2
- package/dist/pers-sdk.d.ts.map +1 -1
- package/dist/platform-adapters/node-http-client.d.ts.map +1 -1
- package/dist/platform-adapters.cjs +3 -66
- package/dist/platform-adapters.cjs.map +1 -1
- package/dist/platform-adapters.js +3 -66
- package/dist/platform-adapters.js.map +1 -1
- package/dist/web3-chain.cjs +1 -1
- package/dist/web3-chain.js +1 -1
- package/package.json +9 -2
- package/dist/chunks/pers-sdk-Bm6y6cX4.cjs.map +0 -1
- package/dist/chunks/pers-sdk-DLTY5heK.js.map +0 -1
- package/dist/chunks/web3-chain-service-6vsVHPjl.cjs.map +0 -1
- package/dist/chunks/web3-chain-service-BcUeeujC.js.map +0 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
class IndexedDBTokenStorage {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.supportsObjects = true;
|
|
4
|
+
this.dbPromise = null;
|
|
5
|
+
if (typeof indexedDB === 'undefined') {
|
|
6
|
+
console.warn('IndexedDB is not available in this environment');
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
getDB() {
|
|
10
|
+
if (this.dbPromise)
|
|
11
|
+
return this.dbPromise;
|
|
12
|
+
this.dbPromise = new Promise((resolve, reject) => {
|
|
13
|
+
if (typeof indexedDB === 'undefined') {
|
|
14
|
+
return reject(new Error('IndexedDB not supported'));
|
|
15
|
+
}
|
|
16
|
+
const request = indexedDB.open(IndexedDBTokenStorage.DB_NAME, IndexedDBTokenStorage.DB_VERSION);
|
|
17
|
+
request.onupgradeneeded = (event) => {
|
|
18
|
+
const db = event.target.result;
|
|
19
|
+
if (!db.objectStoreNames.contains(IndexedDBTokenStorage.STORE_NAME)) {
|
|
20
|
+
db.createObjectStore(IndexedDBTokenStorage.STORE_NAME);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
request.onsuccess = (event) => {
|
|
24
|
+
resolve(event.target.result);
|
|
25
|
+
};
|
|
26
|
+
request.onerror = (event) => {
|
|
27
|
+
reject(event.target.error);
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
return this.dbPromise;
|
|
31
|
+
}
|
|
32
|
+
async get(key) {
|
|
33
|
+
try {
|
|
34
|
+
const db = await this.getDB();
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const transaction = db.transaction(IndexedDBTokenStorage.STORE_NAME, 'readonly');
|
|
37
|
+
const store = transaction.objectStore(IndexedDBTokenStorage.STORE_NAME);
|
|
38
|
+
const request = store.get(key);
|
|
39
|
+
request.onsuccess = () => resolve(request.result || null);
|
|
40
|
+
request.onerror = () => reject(request.error);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
console.warn('[IndexedDBTokenStorage] Failed to get key', key, e);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async set(key, value) {
|
|
49
|
+
try {
|
|
50
|
+
const db = await this.getDB();
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
const transaction = db.transaction(IndexedDBTokenStorage.STORE_NAME, 'readwrite');
|
|
53
|
+
const store = transaction.objectStore(IndexedDBTokenStorage.STORE_NAME);
|
|
54
|
+
const request = store.put(value, key);
|
|
55
|
+
request.onsuccess = () => resolve();
|
|
56
|
+
request.onerror = () => reject(request.error);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
console.error('[IndexedDBTokenStorage] Failed to set key', key, e);
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async remove(key) {
|
|
65
|
+
try {
|
|
66
|
+
const db = await this.getDB();
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
const transaction = db.transaction(IndexedDBTokenStorage.STORE_NAME, 'readwrite');
|
|
69
|
+
const store = transaction.objectStore(IndexedDBTokenStorage.STORE_NAME);
|
|
70
|
+
const request = store.delete(key);
|
|
71
|
+
request.onsuccess = () => resolve();
|
|
72
|
+
request.onerror = () => reject(request.error);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
console.warn('[IndexedDBTokenStorage] Failed to remove key', key, e);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async clear() {
|
|
80
|
+
try {
|
|
81
|
+
const db = await this.getDB();
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
const transaction = db.transaction(IndexedDBTokenStorage.STORE_NAME, 'readwrite');
|
|
84
|
+
const store = transaction.objectStore(IndexedDBTokenStorage.STORE_NAME);
|
|
85
|
+
const request = store.clear();
|
|
86
|
+
request.onsuccess = () => resolve();
|
|
87
|
+
request.onerror = () => reject(request.error);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
console.warn('[IndexedDBTokenStorage] Failed to clear storage', e);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
IndexedDBTokenStorage.DB_NAME = 'pers-sdk-storage';
|
|
96
|
+
IndexedDBTokenStorage.STORE_NAME = 'auth-tokens';
|
|
97
|
+
IndexedDBTokenStorage.DB_VERSION = 1;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Environment Detection Utility
|
|
101
|
+
* Detects runtime environment for platform-specific behaviors
|
|
102
|
+
*/
|
|
103
|
+
/**
|
|
104
|
+
* Detects the current runtime environment
|
|
105
|
+
*/
|
|
106
|
+
function detectEnvironment() {
|
|
107
|
+
const global = globalThis;
|
|
108
|
+
const isNode = typeof process !== 'undefined' &&
|
|
109
|
+
process.versions?.node != null &&
|
|
110
|
+
typeof global.window === 'undefined';
|
|
111
|
+
const isBrowser = typeof global.window !== 'undefined' &&
|
|
112
|
+
typeof global.document !== 'undefined';
|
|
113
|
+
const isReactNative = typeof global.navigator?.product === 'string' &&
|
|
114
|
+
global.navigator.product.toLowerCase() === 'reactnative';
|
|
115
|
+
const isWeb = isBrowser || isReactNative;
|
|
116
|
+
const needsNodeStreamPolyfills = isWeb;
|
|
117
|
+
return {
|
|
118
|
+
isNode,
|
|
119
|
+
isBrowser,
|
|
120
|
+
isReactNative,
|
|
121
|
+
isWeb,
|
|
122
|
+
needsNodeStreamPolyfills
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Global environment info (cached)
|
|
127
|
+
*/
|
|
128
|
+
const environment = detectEnvironment();
|
|
129
|
+
/**
|
|
130
|
+
* Warns if environment might have bundling issues
|
|
131
|
+
*/
|
|
132
|
+
function warnIfProblematicEnvironment(feature) {
|
|
133
|
+
if (environment.needsNodeStreamPolyfills) {
|
|
134
|
+
console.warn(`[PERS SDK] ${feature} may require additional polyfills in web environments. ` +
|
|
135
|
+
`If you encounter 'readable-stream' errors, ensure proper polyfills are configured.`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { IndexedDBTokenStorage as I, detectEnvironment as d, environment as e, warnIfProblematicEnvironment as w };
|
|
140
|
+
//# sourceMappingURL=environment-CKVwRAEL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment-CKVwRAEL.js","sources":["../../src/core/auth/indexed-db-storage.ts","../../src/core/environment.ts"],"sourcesContent":[null,null],"names":[],"mappings":"MAWa,qBAAqB,CAAA;AAOhC,IAAA,WAAA,GAAA;QANS,IAAA,CAAA,eAAe,GAAG,IAAI;QAIvB,IAAA,CAAA,SAAS,GAAgC,IAAI;AAGnD,QAAA,IAAI,OAAO,SAAS,KAAK,WAAW,EAAE;AACpC,YAAA,OAAO,CAAC,IAAI,CAAC,gDAAgD,CAAC;QAChE;IACF;IAEQ,KAAK,GAAA;QACX,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO,IAAI,CAAC,SAAS;QAEzC,IAAI,CAAC,SAAS,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;AAC/C,YAAA,IAAI,OAAO,SAAS,KAAK,WAAW,EAAE;gBACpC,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;YACrD;AAEA,YAAA,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,qBAAqB,CAAC,UAAU,CAAC;AAE/F,YAAA,OAAO,CAAC,eAAe,GAAG,CAAC,KAAK,KAAI;AAClC,gBAAA,MAAM,EAAE,GAAI,KAAK,CAAC,MAA2B,CAAC,MAAM;AACpD,gBAAA,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,qBAAqB,CAAC,UAAU,CAAC,EAAE;AACnE,oBAAA,EAAE,CAAC,iBAAiB,CAAC,qBAAqB,CAAC,UAAU,CAAC;gBACxD;AACF,YAAA,CAAC;AAED,YAAA,OAAO,CAAC,SAAS,GAAG,CAAC,KAAK,KAAI;AAC5B,gBAAA,OAAO,CAAE,KAAK,CAAC,MAA2B,CAAC,MAAM,CAAC;AACpD,YAAA,CAA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AAS;QACT,aAAa;QACb,KAAK;QACL;KACD;AACH;AAEA;;AAEG;AACI,MAAM,WAAW,GAAG,iBAAiB;AAE5C;;AAEG;AACG,SAAU,4BAA4B,CAAC,OAAe,EAAA;AAC1D,IAAA,IAAI,WAAW,CAAC,wBAAwB,EAAE;AACxC,QAAA,OAAO,CAAC,IAAI,CACV,CAAA,WAAA,EAAc,OAAO,CAAA,uDAAA,CAAyD;AAC9E,YAAA,CAAA,kFAAA,CAAoF,CACrF;IACH;AACF;;;;"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Node.js HTTP Client adapter for PERS SDK
|
|
5
|
+
*
|
|
6
|
+
* Simple HTTP client for Node.js environments using native fetch (Node 18+) or a polyfill.
|
|
7
|
+
* Works with Express, Next.js API routes, or any Node.js-based backend.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createPersSDK } from '@explorins/pers-sdk';
|
|
12
|
+
* import { NodeHttpClientAdapter } from '@explorins/pers-sdk/platform-adapters';
|
|
13
|
+
*
|
|
14
|
+
* const sdk = createPersSDK(
|
|
15
|
+
* new NodeHttpClientAdapter(),
|
|
16
|
+
* { environment: 'production', apiProjectKey: 'your-key' }
|
|
17
|
+
* );
|
|
18
|
+
*
|
|
19
|
+
* // Use managers directly
|
|
20
|
+
* await sdk.user.getCurrentUser();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
class NodeHttpClientAdapter {
|
|
24
|
+
async get(url, options = {}) {
|
|
25
|
+
return this.request(url, 'GET', undefined, options);
|
|
26
|
+
}
|
|
27
|
+
async post(url, data = null, options = {}) {
|
|
28
|
+
return this.request(url, 'POST', data, options);
|
|
29
|
+
}
|
|
30
|
+
async put(url, data = null, options = {}) {
|
|
31
|
+
return this.request(url, 'PUT', data, options);
|
|
32
|
+
}
|
|
33
|
+
async delete(url, options = {}) {
|
|
34
|
+
return this.request(url, 'DELETE', undefined, options);
|
|
35
|
+
}
|
|
36
|
+
async patch(url, data = null, options = {}) {
|
|
37
|
+
return this.request(url, 'PATCH', data, options);
|
|
38
|
+
}
|
|
39
|
+
async request(url, method, data, options = {}) {
|
|
40
|
+
// Use native fetch in Node 18+ or require a polyfill for older versions
|
|
41
|
+
const fetchImpl = globalThis.fetch || require('node-fetch');
|
|
42
|
+
const headers = {
|
|
43
|
+
'Content-Type': 'application/json',
|
|
44
|
+
'User-Agent': 'PERS-SDK-Node/1.0',
|
|
45
|
+
...options.headers
|
|
46
|
+
};
|
|
47
|
+
const fetchOptions = {
|
|
48
|
+
method,
|
|
49
|
+
headers,
|
|
50
|
+
...options
|
|
51
|
+
};
|
|
52
|
+
if (data !== undefined && method !== 'GET') {
|
|
53
|
+
fetchOptions.body = JSON.stringify(data);
|
|
54
|
+
}
|
|
55
|
+
const response = await fetchImpl(url, fetchOptions);
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
// Extract backend error response if available
|
|
58
|
+
let errorData;
|
|
59
|
+
try {
|
|
60
|
+
const contentType = response.headers.get('content-type');
|
|
61
|
+
if (contentType?.includes('application/json')) {
|
|
62
|
+
errorData = await response.json();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// If parsing fails, continue with basic error
|
|
67
|
+
}
|
|
68
|
+
// Create error with backend data attached
|
|
69
|
+
const error = new Error(errorData?.message || `HTTP ${response.status}: ${response.statusText}`);
|
|
70
|
+
error.status = response.status;
|
|
71
|
+
error.statusText = response.statusText;
|
|
72
|
+
// Attach backend error response for extraction
|
|
73
|
+
if (errorData) {
|
|
74
|
+
Object.assign(error, errorData);
|
|
75
|
+
}
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
// Handle different response types
|
|
79
|
+
const contentType = response.headers.get('content-type');
|
|
80
|
+
if (contentType?.includes('application/json')) {
|
|
81
|
+
return response.json();
|
|
82
|
+
}
|
|
83
|
+
return response.text();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
exports.NodeHttpClientAdapter = NodeHttpClientAdapter;
|
|
88
|
+
//# sourceMappingURL=node-http-client-D_avaa5F.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-http-client-D_avaa5F.cjs","sources":["../../src/platform-adapters/node-http-client.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;AAmBG;MACU,qBAAqB,CAAA;AAChC,IAAA,MAAM,GAAG,CAAI,GAAW,EAAE,UAA0B,EAAE,EAAA;AACpD,QAAA,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC;IACxD;IAEA,MAAM,IAAI,CAAI,GAAW,EAAE,IAAA,GAAgB,IAAI,EAAE,OAAA,GAA0B,EAAE,EAAA;AAC3E,QAAA,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC;IACpD;IAEA,MAAM,GAAG,CAAI,GAAW,EAAE,IAAA,GAAgB,IAAI,EAAE,OAAA,GAA0B,EAAE,EAAA;AAC1E,QAAA,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC;IACnD;AAEA,IAAA,MAAM,MAAM,CAAI,GAAW,EAAE,UAA0B,EAAE,EAAA;AACvD,QAAA,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;IAC3D;IAEA,MAAM,KAAK,CAAI,GAAW,EAAE,IAAA,GAAgB,IAAI,EAAE,OAAA,GAA0B,EAAE,EAAA;AAC5E,QAAA,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC;IACrD;IAEQ,MAAM,OAAO,CACnB,GAAW,EACX,MA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K;QACb;;QAGA,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;AAExD,QAAA,IAAI,WAAW,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE;AAC7C,YAAA,OAAO,QAAQ,CAAC,IAAI,EAAO;QAC7B;AAEA,QAAA,OAAO,QAAQ,CAAC,IAAI,EAAO;IAC7B;AACD;;;;"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js HTTP Client adapter for PERS SDK
|
|
3
|
+
*
|
|
4
|
+
* Simple HTTP client for Node.js environments using native fetch (Node 18+) or a polyfill.
|
|
5
|
+
* Works with Express, Next.js API routes, or any Node.js-based backend.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createPersSDK } from '@explorins/pers-sdk';
|
|
10
|
+
* import { NodeHttpClientAdapter } from '@explorins/pers-sdk/platform-adapters';
|
|
11
|
+
*
|
|
12
|
+
* const sdk = createPersSDK(
|
|
13
|
+
* new NodeHttpClientAdapter(),
|
|
14
|
+
* { environment: 'production', apiProjectKey: 'your-key' }
|
|
15
|
+
* );
|
|
16
|
+
*
|
|
17
|
+
* // Use managers directly
|
|
18
|
+
* await sdk.user.getCurrentUser();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
class NodeHttpClientAdapter {
|
|
22
|
+
async get(url, options = {}) {
|
|
23
|
+
return this.request(url, 'GET', undefined, options);
|
|
24
|
+
}
|
|
25
|
+
async post(url, data = null, options = {}) {
|
|
26
|
+
return this.request(url, 'POST', data, options);
|
|
27
|
+
}
|
|
28
|
+
async put(url, data = null, options = {}) {
|
|
29
|
+
return this.request(url, 'PUT', data, options);
|
|
30
|
+
}
|
|
31
|
+
async delete(url, options = {}) {
|
|
32
|
+
return this.request(url, 'DELETE', undefined, options);
|
|
33
|
+
}
|
|
34
|
+
async patch(url, data = null, options = {}) {
|
|
35
|
+
return this.request(url, 'PATCH', data, options);
|
|
36
|
+
}
|
|
37
|
+
async request(url, method, data, options = {}) {
|
|
38
|
+
// Use native fetch in Node 18+ or require a polyfill for older versions
|
|
39
|
+
const fetchImpl = globalThis.fetch || require('node-fetch');
|
|
40
|
+
const headers = {
|
|
41
|
+
'Content-Type': 'application/json',
|
|
42
|
+
'User-Agent': 'PERS-SDK-Node/1.0',
|
|
43
|
+
...options.headers
|
|
44
|
+
};
|
|
45
|
+
const fetchOptions = {
|
|
46
|
+
method,
|
|
47
|
+
headers,
|
|
48
|
+
...options
|
|
49
|
+
};
|
|
50
|
+
if (data !== undefined && method !== 'GET') {
|
|
51
|
+
fetchOptions.body = JSON.stringify(data);
|
|
52
|
+
}
|
|
53
|
+
const response = await fetchImpl(url, fetchOptions);
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
// Extract backend error response if available
|
|
56
|
+
let errorData;
|
|
57
|
+
try {
|
|
58
|
+
const contentType = response.headers.get('content-type');
|
|
59
|
+
if (contentType?.includes('application/json')) {
|
|
60
|
+
errorData = await response.json();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// If parsing fails, continue with basic error
|
|
65
|
+
}
|
|
66
|
+
// Create error with backend data attached
|
|
67
|
+
const error = new Error(errorData?.message || `HTTP ${response.status}: ${response.statusText}`);
|
|
68
|
+
error.status = response.status;
|
|
69
|
+
error.statusText = response.statusText;
|
|
70
|
+
// Attach backend error response for extraction
|
|
71
|
+
if (errorData) {
|
|
72
|
+
Object.assign(error, errorData);
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
// Handle different response types
|
|
77
|
+
const contentType = response.headers.get('content-type');
|
|
78
|
+
if (contentType?.includes('application/json')) {
|
|
79
|
+
return response.json();
|
|
80
|
+
}
|
|
81
|
+
return response.text();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { NodeHttpClientAdapter as N };
|
|
86
|
+
//# sourceMappingURL=node-http-client-DloDLfm9.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-http-client-DloDLfm9.js","sources":["../../src/platform-adapters/node-http-client.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;AAmBG;MACU,qBAAqB,CAAA;AAChC,IAAA,MAAM,GAAG,CAAI,GAAW,EAAE,UAA0B,EAAE,EAAA;AACpD,QAAA,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC;IACxD;IAEA,MAAM,IAAI,CAAI,GAAW,EAAE,IAAA,GAAgB,IAAI,EAAE,OAAA,GAA0B,EAAE,EAAA;AAC3E,QAAA,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC;IACpD;IAEA,MAAM,GAAG,CAAI,GAAW,EAAE,IAAA,GAAgB,IAAI,EAAE,OAAA,GAA0B,EAAE,EAAA;AAC1E,QAAA,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC;IACnD;AAEA,IAAA,MAAM,MAAM,CAAI,GAAW,EAAE,UAA0B,EAAE,EAAA;AACvD,QAAA,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;IAC3D;IAEA,MAAM,KAAK,CAAI,GAAW,EAAE,IAAA,GAAgB,IAAI,EAAE,OAAA,GAA0B,EAAE,EAAA;AAC5E,QAAA,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC;IACrD;IAEQ,MAAM,OAAO,CACnB,GAAW,EACX,MAAc,EACd,IAAc,EACd,OAAA,GAA0B,EAAE,EAAA;;QAG5B,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,IAAI,OAAO,CAAC,YAA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,QAAQ,CAAC,kBAAkB,CAAC,EAAE;AAC7C,YAAA,OAAO,QAAQ,CAAC,IAAI,EAAO;QAC7B;AAEA,QAAA,OAAO,QAAQ,CAAC,IAAI,EAAO;IAC7B;AACD;;;;"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AccountOwnerType, MembershipRole, NativeTokenTypes } from '@explorins/pers-shared';
|
|
2
|
-
import { i as isTokenExpired, E as ErrorUtils, A as AuthenticationError, a as PersApiError, c as Web3ChainService, W as Web3ChainApi } from './web3-chain-service-
|
|
2
|
+
import { i as isTokenExpired, E as ErrorUtils, A as AuthenticationError, a as PersApiError, c as Web3ChainService, W as Web3ChainApi } from './web3-chain-service-DKHCnHQX.js';
|
|
3
3
|
import { a as UserService, U as UserApi } from './user-service-BGP3SZpk.js';
|
|
4
4
|
import { createUserStatusSDK } from '../user-status.js';
|
|
5
5
|
import { a as TokenService, T as TokenApi } from './token-service-Bfj6C0yz.js';
|
|
6
6
|
import { BusinessApi, BusinessService, BusinessMembershipApi, BusinessMembershipService } from '../business.js';
|
|
7
|
-
import { a as CampaignService, C as CampaignApi } from './campaign-service-
|
|
7
|
+
import { a as CampaignService, C as CampaignApi } from './campaign-service-DrTAqFZM.js';
|
|
8
8
|
import { RedemptionService, RedemptionApi } from '../redemption.js';
|
|
9
9
|
import { a as TransactionService, T as TransactionApi } from './transaction-service-CnOD3scu.js';
|
|
10
10
|
import { PaymentService, PaymentApi as PurchaseApi } from '../payment.js';
|
|
@@ -818,8 +818,8 @@ class DefaultAuthProvider {
|
|
|
818
818
|
*/
|
|
819
819
|
/** SDK package name */
|
|
820
820
|
const SDK_NAME = '@explorins/pers-sdk';
|
|
821
|
-
/** SDK version -
|
|
822
|
-
const SDK_VERSION = '
|
|
821
|
+
/** SDK version - TODO: Load dynamically from package.json */
|
|
822
|
+
const SDK_VERSION = '2.0.6';
|
|
823
823
|
/** Full SDK identifier for headers */
|
|
824
824
|
const SDK_USER_AGENT = `${SDK_NAME}/${SDK_VERSION}`;
|
|
825
825
|
|
|
@@ -967,35 +967,32 @@ class PersApiClient {
|
|
|
967
967
|
const errorMessage = ErrorUtils.getMessage(error);
|
|
968
968
|
// Handle 401 errors centrally through AuthService
|
|
969
969
|
if (status === 401) {
|
|
970
|
-
// Extract backend error details for better error reporting
|
|
971
970
|
const backendError = ErrorUtils.extractBackendErrorDetails(error);
|
|
972
971
|
// If this IS a refresh request that failed with 401, don't retry to avoid infinite loop
|
|
973
972
|
if (options?.isRefreshRequest) {
|
|
974
973
|
this.emitErrorEvent(backendError, errorMessage, endpoint, method, status, error);
|
|
975
|
-
throw new AuthenticationError(
|
|
974
|
+
throw new AuthenticationError(errorMessage, endpoint, method, backendError);
|
|
976
975
|
}
|
|
977
976
|
// For regular requests: try refresh once, then fail
|
|
978
977
|
if (retryCount === 0 && this.mergedConfig.authProvider) {
|
|
979
978
|
try {
|
|
980
979
|
const refreshSuccessful = await this.refreshManager.attemptInternalRefresh();
|
|
981
980
|
if (refreshSuccessful) {
|
|
982
|
-
// Retry the request with retryCount = 1 to prevent further retries
|
|
983
981
|
return await this.request(method, endpoint, body, { ...options, retryCount: 1 });
|
|
984
982
|
}
|
|
985
983
|
}
|
|
986
984
|
catch (refreshError) {
|
|
987
|
-
//
|
|
985
|
+
// Silent refresh failure
|
|
988
986
|
}
|
|
989
987
|
}
|
|
990
|
-
// Auth failure - let AuthService handle cleanup and notify app
|
|
991
988
|
await this.authService.handleAuthFailure();
|
|
992
989
|
this.emitErrorEvent(backendError, errorMessage, endpoint, method, status, error);
|
|
993
|
-
throw new AuthenticationError(
|
|
990
|
+
throw new AuthenticationError(errorMessage, endpoint, method, backendError);
|
|
994
991
|
}
|
|
995
992
|
// Extract backend error details for non-401 errors
|
|
996
|
-
const
|
|
997
|
-
this.emitErrorEvent(
|
|
998
|
-
throw new PersApiError(errorMessage, endpoint, method, status || undefined,
|
|
993
|
+
const backendError = ErrorUtils.extractBackendErrorDetails(error);
|
|
994
|
+
this.emitErrorEvent(backendError, errorMessage, endpoint, method, status, error);
|
|
995
|
+
throw new PersApiError(errorMessage, endpoint, method, status || undefined, backendError);
|
|
999
996
|
}
|
|
1000
997
|
}
|
|
1001
998
|
/**
|
|
@@ -1008,12 +1005,12 @@ class PersApiClient {
|
|
|
1008
1005
|
instanceId: this._events?.instanceId ?? 'none',
|
|
1009
1006
|
subscriberCount: this._events?.subscriberCount ?? 0,
|
|
1010
1007
|
domain: errorDetails.domain,
|
|
1011
|
-
|
|
1008
|
+
message: errorDetails.message || errorMessage
|
|
1012
1009
|
});
|
|
1013
1010
|
this._events?.emitError({
|
|
1014
1011
|
domain: errorDetails.domain || 'external',
|
|
1015
1012
|
type: errorDetails.code || 'API_ERROR',
|
|
1016
|
-
userMessage: errorDetails.
|
|
1013
|
+
userMessage: errorDetails.message || errorMessage, // Event system uses userMessage for display
|
|
1017
1014
|
code: errorDetails.code,
|
|
1018
1015
|
details: {
|
|
1019
1016
|
endpoint,
|
|
@@ -1144,144 +1141,6 @@ class PersApiClient {
|
|
|
1144
1141
|
}
|
|
1145
1142
|
}
|
|
1146
1143
|
|
|
1147
|
-
class IndexedDBTokenStorage {
|
|
1148
|
-
constructor() {
|
|
1149
|
-
this.supportsObjects = true;
|
|
1150
|
-
this.dbPromise = null;
|
|
1151
|
-
if (typeof indexedDB === 'undefined') {
|
|
1152
|
-
console.warn('IndexedDB is not available in this environment');
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
getDB() {
|
|
1156
|
-
if (this.dbPromise)
|
|
1157
|
-
return this.dbPromise;
|
|
1158
|
-
this.dbPromise = new Promise((resolve, reject) => {
|
|
1159
|
-
if (typeof indexedDB === 'undefined') {
|
|
1160
|
-
return reject(new Error('IndexedDB not supported'));
|
|
1161
|
-
}
|
|
1162
|
-
const request = indexedDB.open(IndexedDBTokenStorage.DB_NAME, IndexedDBTokenStorage.DB_VERSION);
|
|
1163
|
-
request.onupgradeneeded = (event) => {
|
|
1164
|
-
const db = event.target.result;
|
|
1165
|
-
if (!db.objectStoreNames.contains(IndexedDBTokenStorage.STORE_NAME)) {
|
|
1166
|
-
db.createObjectStore(IndexedDBTokenStorage.STORE_NAME);
|
|
1167
|
-
}
|
|
1168
|
-
};
|
|
1169
|
-
request.onsuccess = (event) => {
|
|
1170
|
-
resolve(event.target.result);
|
|
1171
|
-
};
|
|
1172
|
-
request.onerror = (event) => {
|
|
1173
|
-
reject(event.target.error);
|
|
1174
|
-
};
|
|
1175
|
-
});
|
|
1176
|
-
return this.dbPromise;
|
|
1177
|
-
}
|
|
1178
|
-
async get(key) {
|
|
1179
|
-
try {
|
|
1180
|
-
const db = await this.getDB();
|
|
1181
|
-
return new Promise((resolve, reject) => {
|
|
1182
|
-
const transaction = db.transaction(IndexedDBTokenStorage.STORE_NAME, 'readonly');
|
|
1183
|
-
const store = transaction.objectStore(IndexedDBTokenStorage.STORE_NAME);
|
|
1184
|
-
const request = store.get(key);
|
|
1185
|
-
request.onsuccess = () => resolve(request.result || null);
|
|
1186
|
-
request.onerror = () => reject(request.error);
|
|
1187
|
-
});
|
|
1188
|
-
}
|
|
1189
|
-
catch (e) {
|
|
1190
|
-
console.warn('[IndexedDBTokenStorage] Failed to get key', key, e);
|
|
1191
|
-
return null;
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
async set(key, value) {
|
|
1195
|
-
try {
|
|
1196
|
-
const db = await this.getDB();
|
|
1197
|
-
return new Promise((resolve, reject) => {
|
|
1198
|
-
const transaction = db.transaction(IndexedDBTokenStorage.STORE_NAME, 'readwrite');
|
|
1199
|
-
const store = transaction.objectStore(IndexedDBTokenStorage.STORE_NAME);
|
|
1200
|
-
const request = store.put(value, key);
|
|
1201
|
-
request.onsuccess = () => resolve();
|
|
1202
|
-
request.onerror = () => reject(request.error);
|
|
1203
|
-
});
|
|
1204
|
-
}
|
|
1205
|
-
catch (e) {
|
|
1206
|
-
console.error('[IndexedDBTokenStorage] Failed to set key', key, e);
|
|
1207
|
-
throw e;
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
async remove(key) {
|
|
1211
|
-
try {
|
|
1212
|
-
const db = await this.getDB();
|
|
1213
|
-
return new Promise((resolve, reject) => {
|
|
1214
|
-
const transaction = db.transaction(IndexedDBTokenStorage.STORE_NAME, 'readwrite');
|
|
1215
|
-
const store = transaction.objectStore(IndexedDBTokenStorage.STORE_NAME);
|
|
1216
|
-
const request = store.delete(key);
|
|
1217
|
-
request.onsuccess = () => resolve();
|
|
1218
|
-
request.onerror = () => reject(request.error);
|
|
1219
|
-
});
|
|
1220
|
-
}
|
|
1221
|
-
catch (e) {
|
|
1222
|
-
console.warn('[IndexedDBTokenStorage] Failed to remove key', key, e);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
async clear() {
|
|
1226
|
-
try {
|
|
1227
|
-
const db = await this.getDB();
|
|
1228
|
-
return new Promise((resolve, reject) => {
|
|
1229
|
-
const transaction = db.transaction(IndexedDBTokenStorage.STORE_NAME, 'readwrite');
|
|
1230
|
-
const store = transaction.objectStore(IndexedDBTokenStorage.STORE_NAME);
|
|
1231
|
-
const request = store.clear();
|
|
1232
|
-
request.onsuccess = () => resolve();
|
|
1233
|
-
request.onerror = () => reject(request.error);
|
|
1234
|
-
});
|
|
1235
|
-
}
|
|
1236
|
-
catch (e) {
|
|
1237
|
-
console.warn('[IndexedDBTokenStorage] Failed to clear storage', e);
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
IndexedDBTokenStorage.DB_NAME = 'pers-sdk-storage';
|
|
1242
|
-
IndexedDBTokenStorage.STORE_NAME = 'auth-tokens';
|
|
1243
|
-
IndexedDBTokenStorage.DB_VERSION = 1;
|
|
1244
|
-
|
|
1245
|
-
/**
|
|
1246
|
-
* Environment Detection Utility
|
|
1247
|
-
* Detects runtime environment for platform-specific behaviors
|
|
1248
|
-
*/
|
|
1249
|
-
/**
|
|
1250
|
-
* Detects the current runtime environment
|
|
1251
|
-
*/
|
|
1252
|
-
function detectEnvironment() {
|
|
1253
|
-
const global = globalThis;
|
|
1254
|
-
const isNode = typeof process !== 'undefined' &&
|
|
1255
|
-
process.versions?.node != null &&
|
|
1256
|
-
typeof global.window === 'undefined';
|
|
1257
|
-
const isBrowser = typeof global.window !== 'undefined' &&
|
|
1258
|
-
typeof global.document !== 'undefined';
|
|
1259
|
-
const isReactNative = typeof global.navigator?.product === 'string' &&
|
|
1260
|
-
global.navigator.product.toLowerCase() === 'reactnative';
|
|
1261
|
-
const isWeb = isBrowser || isReactNative;
|
|
1262
|
-
const needsNodeStreamPolyfills = isWeb;
|
|
1263
|
-
return {
|
|
1264
|
-
isNode,
|
|
1265
|
-
isBrowser,
|
|
1266
|
-
isReactNative,
|
|
1267
|
-
isWeb,
|
|
1268
|
-
needsNodeStreamPolyfills
|
|
1269
|
-
};
|
|
1270
|
-
}
|
|
1271
|
-
/**
|
|
1272
|
-
* Global environment info (cached)
|
|
1273
|
-
*/
|
|
1274
|
-
const environment = detectEnvironment();
|
|
1275
|
-
/**
|
|
1276
|
-
* Warns if environment might have bundling issues
|
|
1277
|
-
*/
|
|
1278
|
-
function warnIfProblematicEnvironment(feature) {
|
|
1279
|
-
if (environment.needsNodeStreamPolyfills) {
|
|
1280
|
-
console.warn(`[PERS SDK] ${feature} may require additional polyfills in web environments. ` +
|
|
1281
|
-
`If you encounter 'readable-stream' errors, ensure proper polyfills are configured.`);
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
1144
|
/**
|
|
1286
1145
|
* Static JWT Authentication Provider
|
|
1287
1146
|
* For server-side integrations with long-lived JWT tokens
|
|
@@ -1374,6 +1233,14 @@ class StaticJwtAuthProvider {
|
|
|
1374
1233
|
await this.statusChangeCallback(status);
|
|
1375
1234
|
}
|
|
1376
1235
|
}
|
|
1236
|
+
/**
|
|
1237
|
+
* Clear tokens (no-op for static provider)
|
|
1238
|
+
* Static JWTs are immutable and managed externally
|
|
1239
|
+
*/
|
|
1240
|
+
async clearTokens() {
|
|
1241
|
+
// No-op: Static JWTs cannot be cleared, they must be rotated externally
|
|
1242
|
+
console.warn('[StaticJwtAuthProvider] clearTokens() called but static JWTs cannot be cleared. Rotate JWT externally.');
|
|
1243
|
+
}
|
|
1377
1244
|
}
|
|
1378
1245
|
|
|
1379
1246
|
/**
|
|
@@ -3810,8 +3677,35 @@ class CampaignManager {
|
|
|
3810
3677
|
* });
|
|
3811
3678
|
* ```
|
|
3812
3679
|
*/
|
|
3813
|
-
|
|
3814
|
-
|
|
3680
|
+
/**
|
|
3681
|
+
* Admin: Get campaign claims with optional filters
|
|
3682
|
+
*
|
|
3683
|
+
* Retrieves campaign claims with optional filtering by campaign, user, or business.
|
|
3684
|
+
* This operation requires administrator privileges and provides system-wide
|
|
3685
|
+
* visibility into campaign performance and user engagement.
|
|
3686
|
+
*
|
|
3687
|
+
* @param filters - Optional filters and pagination options
|
|
3688
|
+
* @returns Promise resolving to paginated campaign claims
|
|
3689
|
+
* @throws {PersApiError} When not authenticated as administrator
|
|
3690
|
+
*
|
|
3691
|
+
* @example
|
|
3692
|
+
* ```typescript
|
|
3693
|
+
* // Get all claims
|
|
3694
|
+
* const allClaims = await sdk.campaigns.getCampaignClaims();
|
|
3695
|
+
*
|
|
3696
|
+
* // Get claims for specific user
|
|
3697
|
+
* const userClaims = await sdk.campaigns.getCampaignClaims({ userId: 'user-123' });
|
|
3698
|
+
*
|
|
3699
|
+
* // Get claims for specific campaign with pagination
|
|
3700
|
+
* const page1 = await sdk.campaigns.getCampaignClaims({
|
|
3701
|
+
* campaignId: 'campaign-456',
|
|
3702
|
+
* page: 1,
|
|
3703
|
+
* limit: 50
|
|
3704
|
+
* });
|
|
3705
|
+
* ```
|
|
3706
|
+
*/
|
|
3707
|
+
async getCampaignClaims(filters) {
|
|
3708
|
+
return this.campaignService.getCampaignClaims(filters);
|
|
3815
3709
|
}
|
|
3816
3710
|
/**
|
|
3817
3711
|
* Admin: Get campaign claims by user ID
|
|
@@ -7362,5 +7256,5 @@ function createPersSDK(httpClient, config) {
|
|
|
7362
7256
|
return new PersSDK(httpClient, config);
|
|
7363
7257
|
}
|
|
7364
7258
|
|
|
7365
|
-
export { AuthStatus as A, BusinessManager as B, CampaignManager as C, DefaultAuthProvider as D,
|
|
7366
|
-
//# sourceMappingURL=pers-sdk-
|
|
7259
|
+
export { AuthStatus as A, BusinessManager as B, CampaignManager as C, DefaultAuthProvider as D, ApiKeyApi as E, FileManager as F, LocalStorageTokenStorage as L, MemoryTokenStorage as M, PersSDK as P, RedemptionManager as R, SDK_NAME as S, TokenManager as T, UserManager as U, WebDPoPCryptoProvider as W, AuthTokenManager as a, AUTH_STORAGE_KEYS as b, createPersSDK as c, DPOP_STORAGE_KEYS as d, SDK_VERSION as e, SDK_USER_AGENT as f, PersApiClient as g, DEFAULT_PERS_CONFIG as h, buildApiRoot as i, StaticJwtAuthProvider as j, AuthApi as k, AuthService as l, mergeWithDefaults as m, DPoPManager as n, PersEventEmitter as o, AuthManager as p, UserStatusManager as q, TransactionManager as r, PurchaseManager as s, TenantManager as t, ApiKeyManager as u, AnalyticsManager as v, DonationManager as w, Web3Manager as x, FileApi as y, FileService as z };
|
|
7260
|
+
//# sourceMappingURL=pers-sdk-JIExM712.js.map
|