@scalemule/nextjs 0.1.32 → 0.1.34
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/client.js +16 -150
- package/dist/client.mjs +15 -149
- package/dist/index.js +59 -7845
- package/dist/index.mjs +55 -7841
- package/dist/server/index.js +3 -2460
- package/dist/server/index.mjs +3 -2460
- package/package.json +2 -2
package/dist/client.js
CHANGED
|
@@ -1,142 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var __esm = (fn, res) => function __init() {
|
|
5
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
-
};
|
|
7
|
-
var init_chunk_3FTGBRLU = __esm({
|
|
8
|
-
"node_modules/@scalemule/sdk/dist/chunk-3FTGBRLU.mjs"() {
|
|
9
|
-
}
|
|
10
|
-
});
|
|
3
|
+
var sdk = require('@scalemule/sdk');
|
|
11
4
|
|
|
12
|
-
//
|
|
13
|
-
init_chunk_3FTGBRLU();
|
|
14
|
-
var STORAGE_KEYS = {
|
|
15
|
-
SESSION: "scalemule_session",
|
|
16
|
-
USER_ID: "scalemule_user_id",
|
|
17
|
-
WORKSPACE_ID: "scalemule_workspace_id",
|
|
18
|
-
ANONYMOUS_ID: "scalemule_anonymous_id",
|
|
19
|
-
SESSION_POOL: "scalemule_session_pool",
|
|
20
|
-
ACTIVE_ACCOUNT: "scalemule_active_account",
|
|
21
|
-
KNOWN_ACCOUNTS: "scalemule_known_accounts",
|
|
22
|
-
OFFLINE_QUEUE: "scalemule_offline_queue"
|
|
23
|
-
};
|
|
24
|
-
var LEGACY_ANONYMOUS_ID_KEYS = ["sm_anonymous_id"];
|
|
25
|
-
function generateAnonymousId() {
|
|
26
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
27
|
-
return crypto.randomUUID();
|
|
28
|
-
}
|
|
29
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
30
|
-
const r = Math.random() * 16 | 0;
|
|
31
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
32
|
-
return v.toString(16);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
var inFlight = /* @__PURE__ */ new WeakMap();
|
|
36
|
-
function ensureAnonymousId(storage) {
|
|
37
|
-
const existing = inFlight.get(storage);
|
|
38
|
-
if (existing) return existing;
|
|
39
|
-
const promise = (async () => {
|
|
40
|
-
try {
|
|
41
|
-
return await resolveAnonymousId(storage);
|
|
42
|
-
} finally {
|
|
43
|
-
inFlight.delete(storage);
|
|
44
|
-
}
|
|
45
|
-
})();
|
|
46
|
-
inFlight.set(storage, promise);
|
|
47
|
-
return promise;
|
|
48
|
-
}
|
|
49
|
-
async function resolveAnonymousId(storage) {
|
|
50
|
-
const canonical = await storage.getItem(STORAGE_KEYS.ANONYMOUS_ID);
|
|
51
|
-
if (canonical) {
|
|
52
|
-
for (const legacyKey of LEGACY_ANONYMOUS_ID_KEYS) {
|
|
53
|
-
const legacy = await storage.getItem(legacyKey);
|
|
54
|
-
if (legacy !== canonical) {
|
|
55
|
-
try {
|
|
56
|
-
await storage.setItem(legacyKey, canonical);
|
|
57
|
-
} catch {
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return canonical;
|
|
62
|
-
}
|
|
63
|
-
for (const legacyKey of LEGACY_ANONYMOUS_ID_KEYS) {
|
|
64
|
-
const legacy = await storage.getItem(legacyKey);
|
|
65
|
-
if (legacy) {
|
|
66
|
-
try {
|
|
67
|
-
await storage.setItem(STORAGE_KEYS.ANONYMOUS_ID, legacy);
|
|
68
|
-
} catch {
|
|
69
|
-
}
|
|
70
|
-
return legacy;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const fresh = generateAnonymousId();
|
|
74
|
-
try {
|
|
75
|
-
await storage.setItem(STORAGE_KEYS.ANONYMOUS_ID, fresh);
|
|
76
|
-
} catch {
|
|
77
|
-
}
|
|
78
|
-
for (const legacyKey of LEGACY_ANONYMOUS_ID_KEYS) {
|
|
79
|
-
try {
|
|
80
|
-
await storage.setItem(legacyKey, fresh);
|
|
81
|
-
} catch {
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return fresh;
|
|
85
|
-
}
|
|
86
|
-
var PHONE_COUNTRIES = [
|
|
87
|
-
{ code: "US", name: "United States", dialCode: "+1" },
|
|
88
|
-
{ code: "CA", name: "Canada", dialCode: "+1" },
|
|
89
|
-
{ code: "GB", name: "United Kingdom", dialCode: "+44" },
|
|
90
|
-
{ code: "AU", name: "Australia", dialCode: "+61" },
|
|
91
|
-
{ code: "DE", name: "Germany", dialCode: "+49" },
|
|
92
|
-
{ code: "FR", name: "France", dialCode: "+33" },
|
|
93
|
-
{ code: "IT", name: "Italy", dialCode: "+39" },
|
|
94
|
-
{ code: "ES", name: "Spain", dialCode: "+34" },
|
|
95
|
-
{ code: "NL", name: "Netherlands", dialCode: "+31" },
|
|
96
|
-
{ code: "BE", name: "Belgium", dialCode: "+32" },
|
|
97
|
-
{ code: "CH", name: "Switzerland", dialCode: "+41" },
|
|
98
|
-
{ code: "AT", name: "Austria", dialCode: "+43" },
|
|
99
|
-
{ code: "SE", name: "Sweden", dialCode: "+46" },
|
|
100
|
-
{ code: "NO", name: "Norway", dialCode: "+47" },
|
|
101
|
-
{ code: "DK", name: "Denmark", dialCode: "+45" },
|
|
102
|
-
{ code: "FI", name: "Finland", dialCode: "+358" },
|
|
103
|
-
{ code: "IE", name: "Ireland", dialCode: "+353" },
|
|
104
|
-
{ code: "PT", name: "Portugal", dialCode: "+351" },
|
|
105
|
-
{ code: "PL", name: "Poland", dialCode: "+48" },
|
|
106
|
-
{ code: "CZ", name: "Czech Republic", dialCode: "+420" },
|
|
107
|
-
{ code: "GR", name: "Greece", dialCode: "+30" },
|
|
108
|
-
{ code: "RU", name: "Russia", dialCode: "+7" },
|
|
109
|
-
{ code: "JP", name: "Japan", dialCode: "+81" },
|
|
110
|
-
{ code: "KR", name: "South Korea", dialCode: "+82" },
|
|
111
|
-
{ code: "CN", name: "China", dialCode: "+86" },
|
|
112
|
-
{ code: "HK", name: "Hong Kong", dialCode: "+852" },
|
|
113
|
-
{ code: "TW", name: "Taiwan", dialCode: "+886" },
|
|
114
|
-
{ code: "SG", name: "Singapore", dialCode: "+65" },
|
|
115
|
-
{ code: "MY", name: "Malaysia", dialCode: "+60" },
|
|
116
|
-
{ code: "TH", name: "Thailand", dialCode: "+66" },
|
|
117
|
-
{ code: "VN", name: "Vietnam", dialCode: "+84" },
|
|
118
|
-
{ code: "PH", name: "Philippines", dialCode: "+63" },
|
|
119
|
-
{ code: "ID", name: "Indonesia", dialCode: "+62" },
|
|
120
|
-
{ code: "IN", name: "India", dialCode: "+91" },
|
|
121
|
-
{ code: "PK", name: "Pakistan", dialCode: "+92" },
|
|
122
|
-
{ code: "BD", name: "Bangladesh", dialCode: "+880" },
|
|
123
|
-
{ code: "AE", name: "UAE", dialCode: "+971" },
|
|
124
|
-
{ code: "SA", name: "Saudi Arabia", dialCode: "+966" },
|
|
125
|
-
{ code: "IL", name: "Israel", dialCode: "+972" },
|
|
126
|
-
{ code: "TR", name: "Turkey", dialCode: "+90" },
|
|
127
|
-
{ code: "EG", name: "Egypt", dialCode: "+20" },
|
|
128
|
-
{ code: "ZA", name: "South Africa", dialCode: "+27" },
|
|
129
|
-
{ code: "NG", name: "Nigeria", dialCode: "+234" },
|
|
130
|
-
{ code: "KE", name: "Kenya", dialCode: "+254" },
|
|
131
|
-
{ code: "BR", name: "Brazil", dialCode: "+55" },
|
|
132
|
-
{ code: "MX", name: "Mexico", dialCode: "+52" },
|
|
133
|
-
{ code: "AR", name: "Argentina", dialCode: "+54" },
|
|
134
|
-
{ code: "CL", name: "Chile", dialCode: "+56" },
|
|
135
|
-
{ code: "CO", name: "Colombia", dialCode: "+57" },
|
|
136
|
-
{ code: "PE", name: "Peru", dialCode: "+51" },
|
|
137
|
-
{ code: "NZ", name: "New Zealand", dialCode: "+64" }
|
|
138
|
-
];
|
|
139
|
-
[...PHONE_COUNTRIES].sort((a, b) => b.dialCode.length - a.dialCode.length);
|
|
5
|
+
// src/client.ts
|
|
140
6
|
|
|
141
7
|
// src/types/index.ts
|
|
142
8
|
var ScaleMuleApiError = class extends Error {
|
|
@@ -154,9 +20,9 @@ var GATEWAY_URLS = {
|
|
|
154
20
|
dev: "https://api-dev.scalemule.com",
|
|
155
21
|
prod: "https://api.scalemule.com"
|
|
156
22
|
};
|
|
157
|
-
var
|
|
158
|
-
var
|
|
159
|
-
var
|
|
23
|
+
var SESSION_STORAGE_KEY = sdk.STORAGE_KEYS.SESSION;
|
|
24
|
+
var USER_ID_STORAGE_KEY = sdk.STORAGE_KEYS.USER_ID;
|
|
25
|
+
var WORKSPACE_STORAGE_KEY = sdk.STORAGE_KEYS.WORKSPACE_ID;
|
|
160
26
|
var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
|
|
161
27
|
function sleep(ms) {
|
|
162
28
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -506,9 +372,9 @@ var ScaleMuleClient = class {
|
|
|
506
372
|
setWorkspaceContext(id) {
|
|
507
373
|
this.workspaceId = id;
|
|
508
374
|
if (id) {
|
|
509
|
-
this.storage.setItem(
|
|
375
|
+
this.storage.setItem(WORKSPACE_STORAGE_KEY, id);
|
|
510
376
|
} else {
|
|
511
|
-
this.storage.removeItem(
|
|
377
|
+
this.storage.removeItem(WORKSPACE_STORAGE_KEY);
|
|
512
378
|
}
|
|
513
379
|
}
|
|
514
380
|
/**
|
|
@@ -555,11 +421,11 @@ var ScaleMuleClient = class {
|
|
|
555
421
|
* Initialize client by loading persisted session
|
|
556
422
|
*/
|
|
557
423
|
async initialize() {
|
|
558
|
-
const token = await this.storage.getItem(
|
|
559
|
-
const userId = await this.storage.getItem(
|
|
424
|
+
const token = await this.storage.getItem(SESSION_STORAGE_KEY);
|
|
425
|
+
const userId = await this.storage.getItem(USER_ID_STORAGE_KEY);
|
|
560
426
|
if (token) this.sessionToken = token;
|
|
561
427
|
if (userId) this.userId = userId;
|
|
562
|
-
const wsId = await this.storage.getItem(
|
|
428
|
+
const wsId = await this.storage.getItem(WORKSPACE_STORAGE_KEY);
|
|
563
429
|
if (wsId) this.workspaceId = wsId;
|
|
564
430
|
try {
|
|
565
431
|
await this.ensureAnonymousId();
|
|
@@ -589,7 +455,7 @@ var ScaleMuleClient = class {
|
|
|
589
455
|
async ensureAnonymousId() {
|
|
590
456
|
if (this.anonymousId) return this.anonymousId;
|
|
591
457
|
if (!this.anonymousIdPromise) {
|
|
592
|
-
this.anonymousIdPromise = ensureAnonymousId(this.storage).then((id) => {
|
|
458
|
+
this.anonymousIdPromise = sdk.ensureAnonymousId(this.storage).then((id) => {
|
|
593
459
|
this.anonymousId = id;
|
|
594
460
|
return id;
|
|
595
461
|
}).finally(() => {
|
|
@@ -604,8 +470,8 @@ var ScaleMuleClient = class {
|
|
|
604
470
|
async setSession(token, userId) {
|
|
605
471
|
this.sessionToken = token;
|
|
606
472
|
this.userId = userId;
|
|
607
|
-
await this.storage.setItem(
|
|
608
|
-
await this.storage.setItem(
|
|
473
|
+
await this.storage.setItem(SESSION_STORAGE_KEY, token);
|
|
474
|
+
await this.storage.setItem(USER_ID_STORAGE_KEY, userId);
|
|
609
475
|
if (this.debug) {
|
|
610
476
|
console.log("[ScaleMule] Session set for user:", userId);
|
|
611
477
|
}
|
|
@@ -635,9 +501,9 @@ var ScaleMuleClient = class {
|
|
|
635
501
|
this.sessionToken = null;
|
|
636
502
|
this.userId = null;
|
|
637
503
|
this.workspaceId = null;
|
|
638
|
-
await this.storage.removeItem(
|
|
639
|
-
await this.storage.removeItem(
|
|
640
|
-
await this.storage.removeItem(
|
|
504
|
+
await this.storage.removeItem(SESSION_STORAGE_KEY);
|
|
505
|
+
await this.storage.removeItem(USER_ID_STORAGE_KEY);
|
|
506
|
+
await this.storage.removeItem(WORKSPACE_STORAGE_KEY);
|
|
641
507
|
if (this.debug) {
|
|
642
508
|
console.log("[ScaleMule] Session cleared");
|
|
643
509
|
}
|
package/dist/client.mjs
CHANGED
|
@@ -1,140 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
var __esm = (fn, res) => function __init() {
|
|
3
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
4
|
-
};
|
|
5
|
-
var init_chunk_3FTGBRLU = __esm({
|
|
6
|
-
"node_modules/@scalemule/sdk/dist/chunk-3FTGBRLU.mjs"() {
|
|
7
|
-
}
|
|
8
|
-
});
|
|
1
|
+
import { STORAGE_KEYS, ensureAnonymousId } from '@scalemule/sdk';
|
|
9
2
|
|
|
10
|
-
//
|
|
11
|
-
init_chunk_3FTGBRLU();
|
|
12
|
-
var STORAGE_KEYS = {
|
|
13
|
-
SESSION: "scalemule_session",
|
|
14
|
-
USER_ID: "scalemule_user_id",
|
|
15
|
-
WORKSPACE_ID: "scalemule_workspace_id",
|
|
16
|
-
ANONYMOUS_ID: "scalemule_anonymous_id",
|
|
17
|
-
SESSION_POOL: "scalemule_session_pool",
|
|
18
|
-
ACTIVE_ACCOUNT: "scalemule_active_account",
|
|
19
|
-
KNOWN_ACCOUNTS: "scalemule_known_accounts",
|
|
20
|
-
OFFLINE_QUEUE: "scalemule_offline_queue"
|
|
21
|
-
};
|
|
22
|
-
var LEGACY_ANONYMOUS_ID_KEYS = ["sm_anonymous_id"];
|
|
23
|
-
function generateAnonymousId() {
|
|
24
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
25
|
-
return crypto.randomUUID();
|
|
26
|
-
}
|
|
27
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
28
|
-
const r = Math.random() * 16 | 0;
|
|
29
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
30
|
-
return v.toString(16);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
var inFlight = /* @__PURE__ */ new WeakMap();
|
|
34
|
-
function ensureAnonymousId(storage) {
|
|
35
|
-
const existing = inFlight.get(storage);
|
|
36
|
-
if (existing) return existing;
|
|
37
|
-
const promise = (async () => {
|
|
38
|
-
try {
|
|
39
|
-
return await resolveAnonymousId(storage);
|
|
40
|
-
} finally {
|
|
41
|
-
inFlight.delete(storage);
|
|
42
|
-
}
|
|
43
|
-
})();
|
|
44
|
-
inFlight.set(storage, promise);
|
|
45
|
-
return promise;
|
|
46
|
-
}
|
|
47
|
-
async function resolveAnonymousId(storage) {
|
|
48
|
-
const canonical = await storage.getItem(STORAGE_KEYS.ANONYMOUS_ID);
|
|
49
|
-
if (canonical) {
|
|
50
|
-
for (const legacyKey of LEGACY_ANONYMOUS_ID_KEYS) {
|
|
51
|
-
const legacy = await storage.getItem(legacyKey);
|
|
52
|
-
if (legacy !== canonical) {
|
|
53
|
-
try {
|
|
54
|
-
await storage.setItem(legacyKey, canonical);
|
|
55
|
-
} catch {
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return canonical;
|
|
60
|
-
}
|
|
61
|
-
for (const legacyKey of LEGACY_ANONYMOUS_ID_KEYS) {
|
|
62
|
-
const legacy = await storage.getItem(legacyKey);
|
|
63
|
-
if (legacy) {
|
|
64
|
-
try {
|
|
65
|
-
await storage.setItem(STORAGE_KEYS.ANONYMOUS_ID, legacy);
|
|
66
|
-
} catch {
|
|
67
|
-
}
|
|
68
|
-
return legacy;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const fresh = generateAnonymousId();
|
|
72
|
-
try {
|
|
73
|
-
await storage.setItem(STORAGE_KEYS.ANONYMOUS_ID, fresh);
|
|
74
|
-
} catch {
|
|
75
|
-
}
|
|
76
|
-
for (const legacyKey of LEGACY_ANONYMOUS_ID_KEYS) {
|
|
77
|
-
try {
|
|
78
|
-
await storage.setItem(legacyKey, fresh);
|
|
79
|
-
} catch {
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return fresh;
|
|
83
|
-
}
|
|
84
|
-
var PHONE_COUNTRIES = [
|
|
85
|
-
{ code: "US", name: "United States", dialCode: "+1" },
|
|
86
|
-
{ code: "CA", name: "Canada", dialCode: "+1" },
|
|
87
|
-
{ code: "GB", name: "United Kingdom", dialCode: "+44" },
|
|
88
|
-
{ code: "AU", name: "Australia", dialCode: "+61" },
|
|
89
|
-
{ code: "DE", name: "Germany", dialCode: "+49" },
|
|
90
|
-
{ code: "FR", name: "France", dialCode: "+33" },
|
|
91
|
-
{ code: "IT", name: "Italy", dialCode: "+39" },
|
|
92
|
-
{ code: "ES", name: "Spain", dialCode: "+34" },
|
|
93
|
-
{ code: "NL", name: "Netherlands", dialCode: "+31" },
|
|
94
|
-
{ code: "BE", name: "Belgium", dialCode: "+32" },
|
|
95
|
-
{ code: "CH", name: "Switzerland", dialCode: "+41" },
|
|
96
|
-
{ code: "AT", name: "Austria", dialCode: "+43" },
|
|
97
|
-
{ code: "SE", name: "Sweden", dialCode: "+46" },
|
|
98
|
-
{ code: "NO", name: "Norway", dialCode: "+47" },
|
|
99
|
-
{ code: "DK", name: "Denmark", dialCode: "+45" },
|
|
100
|
-
{ code: "FI", name: "Finland", dialCode: "+358" },
|
|
101
|
-
{ code: "IE", name: "Ireland", dialCode: "+353" },
|
|
102
|
-
{ code: "PT", name: "Portugal", dialCode: "+351" },
|
|
103
|
-
{ code: "PL", name: "Poland", dialCode: "+48" },
|
|
104
|
-
{ code: "CZ", name: "Czech Republic", dialCode: "+420" },
|
|
105
|
-
{ code: "GR", name: "Greece", dialCode: "+30" },
|
|
106
|
-
{ code: "RU", name: "Russia", dialCode: "+7" },
|
|
107
|
-
{ code: "JP", name: "Japan", dialCode: "+81" },
|
|
108
|
-
{ code: "KR", name: "South Korea", dialCode: "+82" },
|
|
109
|
-
{ code: "CN", name: "China", dialCode: "+86" },
|
|
110
|
-
{ code: "HK", name: "Hong Kong", dialCode: "+852" },
|
|
111
|
-
{ code: "TW", name: "Taiwan", dialCode: "+886" },
|
|
112
|
-
{ code: "SG", name: "Singapore", dialCode: "+65" },
|
|
113
|
-
{ code: "MY", name: "Malaysia", dialCode: "+60" },
|
|
114
|
-
{ code: "TH", name: "Thailand", dialCode: "+66" },
|
|
115
|
-
{ code: "VN", name: "Vietnam", dialCode: "+84" },
|
|
116
|
-
{ code: "PH", name: "Philippines", dialCode: "+63" },
|
|
117
|
-
{ code: "ID", name: "Indonesia", dialCode: "+62" },
|
|
118
|
-
{ code: "IN", name: "India", dialCode: "+91" },
|
|
119
|
-
{ code: "PK", name: "Pakistan", dialCode: "+92" },
|
|
120
|
-
{ code: "BD", name: "Bangladesh", dialCode: "+880" },
|
|
121
|
-
{ code: "AE", name: "UAE", dialCode: "+971" },
|
|
122
|
-
{ code: "SA", name: "Saudi Arabia", dialCode: "+966" },
|
|
123
|
-
{ code: "IL", name: "Israel", dialCode: "+972" },
|
|
124
|
-
{ code: "TR", name: "Turkey", dialCode: "+90" },
|
|
125
|
-
{ code: "EG", name: "Egypt", dialCode: "+20" },
|
|
126
|
-
{ code: "ZA", name: "South Africa", dialCode: "+27" },
|
|
127
|
-
{ code: "NG", name: "Nigeria", dialCode: "+234" },
|
|
128
|
-
{ code: "KE", name: "Kenya", dialCode: "+254" },
|
|
129
|
-
{ code: "BR", name: "Brazil", dialCode: "+55" },
|
|
130
|
-
{ code: "MX", name: "Mexico", dialCode: "+52" },
|
|
131
|
-
{ code: "AR", name: "Argentina", dialCode: "+54" },
|
|
132
|
-
{ code: "CL", name: "Chile", dialCode: "+56" },
|
|
133
|
-
{ code: "CO", name: "Colombia", dialCode: "+57" },
|
|
134
|
-
{ code: "PE", name: "Peru", dialCode: "+51" },
|
|
135
|
-
{ code: "NZ", name: "New Zealand", dialCode: "+64" }
|
|
136
|
-
];
|
|
137
|
-
[...PHONE_COUNTRIES].sort((a, b) => b.dialCode.length - a.dialCode.length);
|
|
3
|
+
// src/client.ts
|
|
138
4
|
|
|
139
5
|
// src/types/index.ts
|
|
140
6
|
var ScaleMuleApiError = class extends Error {
|
|
@@ -152,9 +18,9 @@ var GATEWAY_URLS = {
|
|
|
152
18
|
dev: "https://api-dev.scalemule.com",
|
|
153
19
|
prod: "https://api.scalemule.com"
|
|
154
20
|
};
|
|
155
|
-
var
|
|
156
|
-
var
|
|
157
|
-
var
|
|
21
|
+
var SESSION_STORAGE_KEY = STORAGE_KEYS.SESSION;
|
|
22
|
+
var USER_ID_STORAGE_KEY = STORAGE_KEYS.USER_ID;
|
|
23
|
+
var WORKSPACE_STORAGE_KEY = STORAGE_KEYS.WORKSPACE_ID;
|
|
158
24
|
var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
|
|
159
25
|
function sleep(ms) {
|
|
160
26
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -504,9 +370,9 @@ var ScaleMuleClient = class {
|
|
|
504
370
|
setWorkspaceContext(id) {
|
|
505
371
|
this.workspaceId = id;
|
|
506
372
|
if (id) {
|
|
507
|
-
this.storage.setItem(
|
|
373
|
+
this.storage.setItem(WORKSPACE_STORAGE_KEY, id);
|
|
508
374
|
} else {
|
|
509
|
-
this.storage.removeItem(
|
|
375
|
+
this.storage.removeItem(WORKSPACE_STORAGE_KEY);
|
|
510
376
|
}
|
|
511
377
|
}
|
|
512
378
|
/**
|
|
@@ -553,11 +419,11 @@ var ScaleMuleClient = class {
|
|
|
553
419
|
* Initialize client by loading persisted session
|
|
554
420
|
*/
|
|
555
421
|
async initialize() {
|
|
556
|
-
const token = await this.storage.getItem(
|
|
557
|
-
const userId = await this.storage.getItem(
|
|
422
|
+
const token = await this.storage.getItem(SESSION_STORAGE_KEY);
|
|
423
|
+
const userId = await this.storage.getItem(USER_ID_STORAGE_KEY);
|
|
558
424
|
if (token) this.sessionToken = token;
|
|
559
425
|
if (userId) this.userId = userId;
|
|
560
|
-
const wsId = await this.storage.getItem(
|
|
426
|
+
const wsId = await this.storage.getItem(WORKSPACE_STORAGE_KEY);
|
|
561
427
|
if (wsId) this.workspaceId = wsId;
|
|
562
428
|
try {
|
|
563
429
|
await this.ensureAnonymousId();
|
|
@@ -602,8 +468,8 @@ var ScaleMuleClient = class {
|
|
|
602
468
|
async setSession(token, userId) {
|
|
603
469
|
this.sessionToken = token;
|
|
604
470
|
this.userId = userId;
|
|
605
|
-
await this.storage.setItem(
|
|
606
|
-
await this.storage.setItem(
|
|
471
|
+
await this.storage.setItem(SESSION_STORAGE_KEY, token);
|
|
472
|
+
await this.storage.setItem(USER_ID_STORAGE_KEY, userId);
|
|
607
473
|
if (this.debug) {
|
|
608
474
|
console.log("[ScaleMule] Session set for user:", userId);
|
|
609
475
|
}
|
|
@@ -633,9 +499,9 @@ var ScaleMuleClient = class {
|
|
|
633
499
|
this.sessionToken = null;
|
|
634
500
|
this.userId = null;
|
|
635
501
|
this.workspaceId = null;
|
|
636
|
-
await this.storage.removeItem(
|
|
637
|
-
await this.storage.removeItem(
|
|
638
|
-
await this.storage.removeItem(
|
|
502
|
+
await this.storage.removeItem(SESSION_STORAGE_KEY);
|
|
503
|
+
await this.storage.removeItem(USER_ID_STORAGE_KEY);
|
|
504
|
+
await this.storage.removeItem(WORKSPACE_STORAGE_KEY);
|
|
639
505
|
if (this.debug) {
|
|
640
506
|
console.log("[ScaleMule] Session cleared");
|
|
641
507
|
}
|