@scalemule/nextjs 0.0.36 → 0.0.38
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/index.js +351 -76
- package/dist/index.mjs +351 -76
- package/package.json +2 -2
- package/dist/index-BIIUrnPr.d.mts +0 -898
- package/dist/index-BIIUrnPr.d.ts +0 -898
- package/dist/webhook-handler-BobYTuNP.d.ts +0 -779
- package/dist/webhook-handler-CNKQ1k2a.d.mts +0 -779
package/dist/index.mjs
CHANGED
|
@@ -288,78 +288,6 @@ var init_upload_compression_VOUJRAIM = __esm({
|
|
|
288
288
|
|
|
289
289
|
// node_modules/@scalemule/sdk/dist/index.mjs
|
|
290
290
|
init_chunk_3FTGBRLU();
|
|
291
|
-
|
|
292
|
-
// node_modules/@scalemule/ui/dist/phone/index.mjs
|
|
293
|
-
var PHONE_COUNTRIES = [
|
|
294
|
-
{ code: "US", name: "United States", dialCode: "+1" },
|
|
295
|
-
{ code: "CA", name: "Canada", dialCode: "+1" },
|
|
296
|
-
{ code: "GB", name: "United Kingdom", dialCode: "+44" },
|
|
297
|
-
{ code: "AU", name: "Australia", dialCode: "+61" },
|
|
298
|
-
{ code: "DE", name: "Germany", dialCode: "+49" },
|
|
299
|
-
{ code: "FR", name: "France", dialCode: "+33" },
|
|
300
|
-
{ code: "IT", name: "Italy", dialCode: "+39" },
|
|
301
|
-
{ code: "ES", name: "Spain", dialCode: "+34" },
|
|
302
|
-
{ code: "NL", name: "Netherlands", dialCode: "+31" },
|
|
303
|
-
{ code: "BE", name: "Belgium", dialCode: "+32" },
|
|
304
|
-
{ code: "CH", name: "Switzerland", dialCode: "+41" },
|
|
305
|
-
{ code: "AT", name: "Austria", dialCode: "+43" },
|
|
306
|
-
{ code: "SE", name: "Sweden", dialCode: "+46" },
|
|
307
|
-
{ code: "NO", name: "Norway", dialCode: "+47" },
|
|
308
|
-
{ code: "DK", name: "Denmark", dialCode: "+45" },
|
|
309
|
-
{ code: "FI", name: "Finland", dialCode: "+358" },
|
|
310
|
-
{ code: "IE", name: "Ireland", dialCode: "+353" },
|
|
311
|
-
{ code: "PT", name: "Portugal", dialCode: "+351" },
|
|
312
|
-
{ code: "PL", name: "Poland", dialCode: "+48" },
|
|
313
|
-
{ code: "CZ", name: "Czech Republic", dialCode: "+420" },
|
|
314
|
-
{ code: "GR", name: "Greece", dialCode: "+30" },
|
|
315
|
-
{ code: "RU", name: "Russia", dialCode: "+7" },
|
|
316
|
-
{ code: "JP", name: "Japan", dialCode: "+81" },
|
|
317
|
-
{ code: "KR", name: "South Korea", dialCode: "+82" },
|
|
318
|
-
{ code: "CN", name: "China", dialCode: "+86" },
|
|
319
|
-
{ code: "HK", name: "Hong Kong", dialCode: "+852" },
|
|
320
|
-
{ code: "TW", name: "Taiwan", dialCode: "+886" },
|
|
321
|
-
{ code: "SG", name: "Singapore", dialCode: "+65" },
|
|
322
|
-
{ code: "MY", name: "Malaysia", dialCode: "+60" },
|
|
323
|
-
{ code: "TH", name: "Thailand", dialCode: "+66" },
|
|
324
|
-
{ code: "VN", name: "Vietnam", dialCode: "+84" },
|
|
325
|
-
{ code: "PH", name: "Philippines", dialCode: "+63" },
|
|
326
|
-
{ code: "ID", name: "Indonesia", dialCode: "+62" },
|
|
327
|
-
{ code: "IN", name: "India", dialCode: "+91" },
|
|
328
|
-
{ code: "PK", name: "Pakistan", dialCode: "+92" },
|
|
329
|
-
{ code: "BD", name: "Bangladesh", dialCode: "+880" },
|
|
330
|
-
{ code: "AE", name: "UAE", dialCode: "+971" },
|
|
331
|
-
{ code: "SA", name: "Saudi Arabia", dialCode: "+966" },
|
|
332
|
-
{ code: "IL", name: "Israel", dialCode: "+972" },
|
|
333
|
-
{ code: "TR", name: "Turkey", dialCode: "+90" },
|
|
334
|
-
{ code: "EG", name: "Egypt", dialCode: "+20" },
|
|
335
|
-
{ code: "ZA", name: "South Africa", dialCode: "+27" },
|
|
336
|
-
{ code: "NG", name: "Nigeria", dialCode: "+234" },
|
|
337
|
-
{ code: "KE", name: "Kenya", dialCode: "+254" },
|
|
338
|
-
{ code: "BR", name: "Brazil", dialCode: "+55" },
|
|
339
|
-
{ code: "MX", name: "Mexico", dialCode: "+52" },
|
|
340
|
-
{ code: "AR", name: "Argentina", dialCode: "+54" },
|
|
341
|
-
{ code: "CL", name: "Chile", dialCode: "+56" },
|
|
342
|
-
{ code: "CO", name: "Colombia", dialCode: "+57" },
|
|
343
|
-
{ code: "PE", name: "Peru", dialCode: "+51" },
|
|
344
|
-
{ code: "NZ", name: "New Zealand", dialCode: "+64" }
|
|
345
|
-
];
|
|
346
|
-
function normalizePhoneNumber(input) {
|
|
347
|
-
if (typeof input !== "string") return "";
|
|
348
|
-
const trimmed = input.trim();
|
|
349
|
-
if (!trimmed) return "";
|
|
350
|
-
const digitsOnly = trimmed.replace(/\D/g, "");
|
|
351
|
-
if (!digitsOnly) return "";
|
|
352
|
-
if (trimmed.startsWith("+")) {
|
|
353
|
-
return `+${digitsOnly}`;
|
|
354
|
-
}
|
|
355
|
-
if (trimmed.startsWith("00") && digitsOnly.length > 2) {
|
|
356
|
-
return `+${digitsOnly.slice(2)}`;
|
|
357
|
-
}
|
|
358
|
-
return `+${digitsOnly}`;
|
|
359
|
-
}
|
|
360
|
-
[...PHONE_COUNTRIES].sort((a, b) => b.dialCode.length - a.dialCode.length);
|
|
361
|
-
|
|
362
|
-
// node_modules/@scalemule/sdk/dist/index.mjs
|
|
363
291
|
function buildClientContextHeaders(context) {
|
|
364
292
|
if (!context) return {};
|
|
365
293
|
const headers = {};
|
|
@@ -384,6 +312,7 @@ var WORKSPACE_STORAGE_KEY = "scalemule_workspace_id";
|
|
|
384
312
|
var ANONYMOUS_ID_STORAGE_KEY = "scalemule_anonymous_id";
|
|
385
313
|
var SESSION_POOL_KEY = "scalemule_session_pool";
|
|
386
314
|
var ACTIVE_ACCOUNT_KEY = "scalemule_active_account";
|
|
315
|
+
var KNOWN_ACCOUNTS_KEY = "scalemule_known_accounts";
|
|
387
316
|
var GATEWAY_URLS = {
|
|
388
317
|
dev: "https://api-dev.scalemule.com",
|
|
389
318
|
prod: "https://api.scalemule.com"
|
|
@@ -433,6 +362,54 @@ function statusToErrorCode(status) {
|
|
|
433
362
|
return status >= 500 ? "internal_error" : `http_${status}`;
|
|
434
363
|
}
|
|
435
364
|
}
|
|
365
|
+
var MAX_KNOWN_ACCOUNTS = 10;
|
|
366
|
+
function maskEmail(email) {
|
|
367
|
+
const parts = email.split("@");
|
|
368
|
+
const local = parts[0] ?? "";
|
|
369
|
+
const domain = parts[1];
|
|
370
|
+
if (!domain) return "***@***.***";
|
|
371
|
+
const tldDot = domain.lastIndexOf(".");
|
|
372
|
+
const tld = tldDot > 0 ? domain.slice(tldDot) : "";
|
|
373
|
+
const domainBase = tldDot > 0 ? domain.slice(0, tldDot) : domain;
|
|
374
|
+
return `${local[0] || "*"}***@${domainBase[0] || "*"}***${tld}`;
|
|
375
|
+
}
|
|
376
|
+
function stableColorIndex(userId) {
|
|
377
|
+
let hash = 0;
|
|
378
|
+
for (let i = 0; i < userId.length; i++) {
|
|
379
|
+
hash = (hash << 5) - hash + userId.charCodeAt(i) | 0;
|
|
380
|
+
}
|
|
381
|
+
return Math.abs(hash) % 8;
|
|
382
|
+
}
|
|
383
|
+
function applyPrivacy(account, privacy) {
|
|
384
|
+
switch (privacy) {
|
|
385
|
+
case "full":
|
|
386
|
+
return {
|
|
387
|
+
userId: account.userId,
|
|
388
|
+
email: account.email,
|
|
389
|
+
fullName: account.fullName,
|
|
390
|
+
avatarUrl: account.avatarUrl,
|
|
391
|
+
provider: account.provider,
|
|
392
|
+
lastActiveAt: account.lastActiveAt
|
|
393
|
+
};
|
|
394
|
+
case "masked":
|
|
395
|
+
return {
|
|
396
|
+
userId: account.userId,
|
|
397
|
+
email: account.email ? maskEmail(account.email) : void 0,
|
|
398
|
+
fullName: account.fullName && account.fullName.length > 0 ? `${account.fullName[0].toUpperCase()}.` : void 0,
|
|
399
|
+
provider: account.provider,
|
|
400
|
+
lastActiveAt: account.lastActiveAt,
|
|
401
|
+
colorIndex: stableColorIndex(account.userId)
|
|
402
|
+
};
|
|
403
|
+
case "minimal":
|
|
404
|
+
return {
|
|
405
|
+
userId: account.userId,
|
|
406
|
+
provider: account.provider,
|
|
407
|
+
lastActiveAt: account.lastActiveAt,
|
|
408
|
+
displayLabel: "Account",
|
|
409
|
+
colorIndex: stableColorIndex(account.userId)
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
}
|
|
436
413
|
function createDefaultStorage() {
|
|
437
414
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
438
415
|
return {
|
|
@@ -579,6 +556,7 @@ var ScaleMuleClient = class {
|
|
|
579
556
|
this.workspaceId = null;
|
|
580
557
|
this.anonymousId = null;
|
|
581
558
|
this.sessionPool = /* @__PURE__ */ new Map();
|
|
559
|
+
this.knownAccounts = /* @__PURE__ */ new Map();
|
|
582
560
|
this.apiKey = config.apiKey;
|
|
583
561
|
this.applicationId = config.applicationId || null;
|
|
584
562
|
this.baseUrl = config.baseUrl || GATEWAY_URLS[config.environment || "prod"];
|
|
@@ -595,6 +573,8 @@ var ScaleMuleClient = class {
|
|
|
595
573
|
this.offlineQueue.setOnlineCallback(() => this.syncOfflineQueue());
|
|
596
574
|
}
|
|
597
575
|
this.multiSessionEnabled = config.enableMultiSession || false;
|
|
576
|
+
this.accountSwitcherEnabled = config.enableAccountSwitcher || false;
|
|
577
|
+
this.accountSwitcherPrivacy = config.accountSwitcherPrivacy || "full";
|
|
598
578
|
}
|
|
599
579
|
// --------------------------------------------------------------------------
|
|
600
580
|
// Session Management
|
|
@@ -637,6 +617,27 @@ var ScaleMuleClient = class {
|
|
|
637
617
|
this.userId = activeId;
|
|
638
618
|
}
|
|
639
619
|
}
|
|
620
|
+
if (this.accountSwitcherEnabled) {
|
|
621
|
+
const knownJson = await this.storage.getItem(KNOWN_ACCOUNTS_KEY);
|
|
622
|
+
if (knownJson) {
|
|
623
|
+
try {
|
|
624
|
+
const entries = JSON.parse(knownJson);
|
|
625
|
+
this.knownAccounts = new Map(Object.entries(entries));
|
|
626
|
+
let changed = false;
|
|
627
|
+
for (const [userId2, entry] of this.knownAccounts) {
|
|
628
|
+
const normalized = applyPrivacy(entry, this.accountSwitcherPrivacy);
|
|
629
|
+
if (JSON.stringify(normalized) !== JSON.stringify(entry)) {
|
|
630
|
+
this.knownAccounts.set(userId2, normalized);
|
|
631
|
+
changed = true;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
if (changed) {
|
|
635
|
+
await this.persistKnownAccounts();
|
|
636
|
+
}
|
|
637
|
+
} catch {
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
640
641
|
if (this.debug)
|
|
641
642
|
console.log(
|
|
642
643
|
"[ScaleMule] Initialized, session:",
|
|
@@ -644,7 +645,9 @@ var ScaleMuleClient = class {
|
|
|
644
645
|
"anonymousId:",
|
|
645
646
|
anonId,
|
|
646
647
|
"poolSize:",
|
|
647
|
-
this.sessionPool.size
|
|
648
|
+
this.sessionPool.size,
|
|
649
|
+
"knownAccounts:",
|
|
650
|
+
this.knownAccounts.size
|
|
648
651
|
);
|
|
649
652
|
}
|
|
650
653
|
async setSession(token, userId) {
|
|
@@ -768,6 +771,57 @@ var ScaleMuleClient = class {
|
|
|
768
771
|
}
|
|
769
772
|
await this.storage.setItem(SESSION_POOL_KEY, JSON.stringify(obj));
|
|
770
773
|
}
|
|
774
|
+
// --------------------------------------------------------------------------
|
|
775
|
+
// Account Switcher (Secure — metadata only, no tokens)
|
|
776
|
+
// --------------------------------------------------------------------------
|
|
777
|
+
isAccountSwitcherEnabled() {
|
|
778
|
+
return this.accountSwitcherEnabled;
|
|
779
|
+
}
|
|
780
|
+
getAccountSwitcherPrivacy() {
|
|
781
|
+
return this.accountSwitcherPrivacy;
|
|
782
|
+
}
|
|
783
|
+
/** Get all known accounts that have logged in on this device (privacy-transformed) */
|
|
784
|
+
getKnownAccounts() {
|
|
785
|
+
return Array.from(this.knownAccounts.values());
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Record an account as "known" on this device.
|
|
789
|
+
* Applies privacy transforms before storing — full email is never persisted
|
|
790
|
+
* in masked/minimal modes. Evicts oldest accounts if over the cap.
|
|
791
|
+
* Called automatically after successful login/register when account switcher is enabled.
|
|
792
|
+
*/
|
|
793
|
+
async addKnownAccount(account) {
|
|
794
|
+
const display = applyPrivacy(account, this.accountSwitcherPrivacy);
|
|
795
|
+
this.knownAccounts.set(account.userId, display);
|
|
796
|
+
if (this.knownAccounts.size > MAX_KNOWN_ACCOUNTS) {
|
|
797
|
+
const sorted = Array.from(this.knownAccounts.entries()).sort(
|
|
798
|
+
(a, b) => (a[1].lastActiveAt || "").localeCompare(b[1].lastActiveAt || "")
|
|
799
|
+
);
|
|
800
|
+
while (this.knownAccounts.size > MAX_KNOWN_ACCOUNTS && sorted.length > 0) {
|
|
801
|
+
const oldest = sorted.shift();
|
|
802
|
+
this.knownAccounts.delete(oldest[0]);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
await this.persistKnownAccounts();
|
|
806
|
+
}
|
|
807
|
+
/** Remove a specific account from the known accounts list ("forget this account") */
|
|
808
|
+
async removeKnownAccount(userId) {
|
|
809
|
+
this.knownAccounts.delete(userId);
|
|
810
|
+
await this.persistKnownAccounts();
|
|
811
|
+
}
|
|
812
|
+
/** Clear all known accounts ("forget all accounts on this device") */
|
|
813
|
+
async clearKnownAccounts() {
|
|
814
|
+
this.knownAccounts.clear();
|
|
815
|
+
await this.storage.removeItem(KNOWN_ACCOUNTS_KEY);
|
|
816
|
+
}
|
|
817
|
+
/** Persist known accounts to storage */
|
|
818
|
+
async persistKnownAccounts() {
|
|
819
|
+
const obj = {};
|
|
820
|
+
for (const [k, v] of this.knownAccounts) {
|
|
821
|
+
obj[k] = v;
|
|
822
|
+
}
|
|
823
|
+
await this.storage.setItem(KNOWN_ACCOUNTS_KEY, JSON.stringify(obj));
|
|
824
|
+
}
|
|
771
825
|
getBaseUrl() {
|
|
772
826
|
return this.baseUrl;
|
|
773
827
|
}
|
|
@@ -1259,6 +1313,74 @@ function asString(parent, key) {
|
|
|
1259
1313
|
const value = parent[key];
|
|
1260
1314
|
return typeof value === "string" ? value : void 0;
|
|
1261
1315
|
}
|
|
1316
|
+
var PHONE_COUNTRIES = [
|
|
1317
|
+
{ code: "US", name: "United States", dialCode: "+1" },
|
|
1318
|
+
{ code: "CA", name: "Canada", dialCode: "+1" },
|
|
1319
|
+
{ code: "GB", name: "United Kingdom", dialCode: "+44" },
|
|
1320
|
+
{ code: "AU", name: "Australia", dialCode: "+61" },
|
|
1321
|
+
{ code: "DE", name: "Germany", dialCode: "+49" },
|
|
1322
|
+
{ code: "FR", name: "France", dialCode: "+33" },
|
|
1323
|
+
{ code: "IT", name: "Italy", dialCode: "+39" },
|
|
1324
|
+
{ code: "ES", name: "Spain", dialCode: "+34" },
|
|
1325
|
+
{ code: "NL", name: "Netherlands", dialCode: "+31" },
|
|
1326
|
+
{ code: "BE", name: "Belgium", dialCode: "+32" },
|
|
1327
|
+
{ code: "CH", name: "Switzerland", dialCode: "+41" },
|
|
1328
|
+
{ code: "AT", name: "Austria", dialCode: "+43" },
|
|
1329
|
+
{ code: "SE", name: "Sweden", dialCode: "+46" },
|
|
1330
|
+
{ code: "NO", name: "Norway", dialCode: "+47" },
|
|
1331
|
+
{ code: "DK", name: "Denmark", dialCode: "+45" },
|
|
1332
|
+
{ code: "FI", name: "Finland", dialCode: "+358" },
|
|
1333
|
+
{ code: "IE", name: "Ireland", dialCode: "+353" },
|
|
1334
|
+
{ code: "PT", name: "Portugal", dialCode: "+351" },
|
|
1335
|
+
{ code: "PL", name: "Poland", dialCode: "+48" },
|
|
1336
|
+
{ code: "CZ", name: "Czech Republic", dialCode: "+420" },
|
|
1337
|
+
{ code: "GR", name: "Greece", dialCode: "+30" },
|
|
1338
|
+
{ code: "RU", name: "Russia", dialCode: "+7" },
|
|
1339
|
+
{ code: "JP", name: "Japan", dialCode: "+81" },
|
|
1340
|
+
{ code: "KR", name: "South Korea", dialCode: "+82" },
|
|
1341
|
+
{ code: "CN", name: "China", dialCode: "+86" },
|
|
1342
|
+
{ code: "HK", name: "Hong Kong", dialCode: "+852" },
|
|
1343
|
+
{ code: "TW", name: "Taiwan", dialCode: "+886" },
|
|
1344
|
+
{ code: "SG", name: "Singapore", dialCode: "+65" },
|
|
1345
|
+
{ code: "MY", name: "Malaysia", dialCode: "+60" },
|
|
1346
|
+
{ code: "TH", name: "Thailand", dialCode: "+66" },
|
|
1347
|
+
{ code: "VN", name: "Vietnam", dialCode: "+84" },
|
|
1348
|
+
{ code: "PH", name: "Philippines", dialCode: "+63" },
|
|
1349
|
+
{ code: "ID", name: "Indonesia", dialCode: "+62" },
|
|
1350
|
+
{ code: "IN", name: "India", dialCode: "+91" },
|
|
1351
|
+
{ code: "PK", name: "Pakistan", dialCode: "+92" },
|
|
1352
|
+
{ code: "BD", name: "Bangladesh", dialCode: "+880" },
|
|
1353
|
+
{ code: "AE", name: "UAE", dialCode: "+971" },
|
|
1354
|
+
{ code: "SA", name: "Saudi Arabia", dialCode: "+966" },
|
|
1355
|
+
{ code: "IL", name: "Israel", dialCode: "+972" },
|
|
1356
|
+
{ code: "TR", name: "Turkey", dialCode: "+90" },
|
|
1357
|
+
{ code: "EG", name: "Egypt", dialCode: "+20" },
|
|
1358
|
+
{ code: "ZA", name: "South Africa", dialCode: "+27" },
|
|
1359
|
+
{ code: "NG", name: "Nigeria", dialCode: "+234" },
|
|
1360
|
+
{ code: "KE", name: "Kenya", dialCode: "+254" },
|
|
1361
|
+
{ code: "BR", name: "Brazil", dialCode: "+55" },
|
|
1362
|
+
{ code: "MX", name: "Mexico", dialCode: "+52" },
|
|
1363
|
+
{ code: "AR", name: "Argentina", dialCode: "+54" },
|
|
1364
|
+
{ code: "CL", name: "Chile", dialCode: "+56" },
|
|
1365
|
+
{ code: "CO", name: "Colombia", dialCode: "+57" },
|
|
1366
|
+
{ code: "PE", name: "Peru", dialCode: "+51" },
|
|
1367
|
+
{ code: "NZ", name: "New Zealand", dialCode: "+64" }
|
|
1368
|
+
];
|
|
1369
|
+
function normalizePhoneNumber(input) {
|
|
1370
|
+
if (typeof input !== "string") return "";
|
|
1371
|
+
const trimmed = input.trim();
|
|
1372
|
+
if (!trimmed) return "";
|
|
1373
|
+
const digitsOnly = trimmed.replace(/\D/g, "");
|
|
1374
|
+
if (!digitsOnly) return "";
|
|
1375
|
+
if (trimmed.startsWith("+")) {
|
|
1376
|
+
return `+${digitsOnly}`;
|
|
1377
|
+
}
|
|
1378
|
+
if (trimmed.startsWith("00") && digitsOnly.length > 2) {
|
|
1379
|
+
return `+${digitsOnly.slice(2)}`;
|
|
1380
|
+
}
|
|
1381
|
+
return `+${digitsOnly}`;
|
|
1382
|
+
}
|
|
1383
|
+
[...PHONE_COUNTRIES].sort((a, b) => b.dialCode.length - a.dialCode.length);
|
|
1262
1384
|
function collectDeviceFingerprint() {
|
|
1263
1385
|
if (typeof window === "undefined" || typeof navigator === "undefined") return void 0;
|
|
1264
1386
|
try {
|
|
@@ -1387,6 +1509,16 @@ var AuthService = class extends ServiceModule {
|
|
|
1387
1509
|
addedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1388
1510
|
});
|
|
1389
1511
|
}
|
|
1512
|
+
if (result.data && this.client.isAccountSwitcherEnabled()) {
|
|
1513
|
+
await this.client.addKnownAccount({
|
|
1514
|
+
userId: result.data.user.id,
|
|
1515
|
+
email: result.data.user.email,
|
|
1516
|
+
fullName: result.data.user.full_name,
|
|
1517
|
+
avatarUrl: result.data.user.avatar_url,
|
|
1518
|
+
provider: "email",
|
|
1519
|
+
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1390
1522
|
return result;
|
|
1391
1523
|
}
|
|
1392
1524
|
async login(data, options) {
|
|
@@ -1407,6 +1539,16 @@ var AuthService = class extends ServiceModule {
|
|
|
1407
1539
|
addedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1408
1540
|
});
|
|
1409
1541
|
}
|
|
1542
|
+
if (result.data && this.client.isAccountSwitcherEnabled()) {
|
|
1543
|
+
await this.client.addKnownAccount({
|
|
1544
|
+
userId: result.data.user.id,
|
|
1545
|
+
email: result.data.user.email,
|
|
1546
|
+
fullName: result.data.user.full_name,
|
|
1547
|
+
avatarUrl: result.data.user.avatar_url,
|
|
1548
|
+
provider: "email",
|
|
1549
|
+
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1410
1552
|
return result;
|
|
1411
1553
|
}
|
|
1412
1554
|
async logout(options) {
|
|
@@ -1548,7 +1690,18 @@ var AuthService = class extends ServiceModule {
|
|
|
1548
1690
|
}
|
|
1549
1691
|
async handleOAuthCallback(data, options) {
|
|
1550
1692
|
const { provider, ...rest } = data;
|
|
1551
|
-
|
|
1693
|
+
const result = await this._get(this.withQuery(`/oauth/${provider}/callback`, rest), options);
|
|
1694
|
+
if (result.data && this.client.isAccountSwitcherEnabled()) {
|
|
1695
|
+
await this.client.addKnownAccount({
|
|
1696
|
+
userId: result.data.user.id,
|
|
1697
|
+
email: result.data.user.email,
|
|
1698
|
+
fullName: result.data.user.full_name,
|
|
1699
|
+
avatarUrl: result.data.user.avatar_url,
|
|
1700
|
+
provider,
|
|
1701
|
+
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
return result;
|
|
1552
1705
|
}
|
|
1553
1706
|
async listOAuthProviders(options) {
|
|
1554
1707
|
return this._get("/oauth/providers", options);
|
|
@@ -3062,10 +3215,29 @@ var RealtimeService = class extends ServiceModule {
|
|
|
3062
3215
|
// --------------------------------------------------------------------------
|
|
3063
3216
|
connect() {
|
|
3064
3217
|
if (this._status === "connecting" || this._status === "connected") return;
|
|
3065
|
-
const baseUrl = this.client.getBaseUrl();
|
|
3066
|
-
const wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
|
|
3067
3218
|
this.setStatus(this.reconnectAttempt > 0 ? "reconnecting" : "connecting");
|
|
3219
|
+
this.fetchTicketAndConnect();
|
|
3220
|
+
}
|
|
3221
|
+
async fetchTicketAndConnect() {
|
|
3222
|
+
const baseUrl = this.client.getBaseUrl();
|
|
3068
3223
|
try {
|
|
3224
|
+
const headers = { "Content-Type": "application/json" };
|
|
3225
|
+
const apiKey = this.client.getApiKey();
|
|
3226
|
+
if (apiKey) headers["x-api-key"] = apiKey;
|
|
3227
|
+
const token = this.client.getSessionToken();
|
|
3228
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
3229
|
+
const ticketRes = await fetch(`${baseUrl}/v1/realtime/ws/ticket`, {
|
|
3230
|
+
method: "POST",
|
|
3231
|
+
headers
|
|
3232
|
+
});
|
|
3233
|
+
let wsUrl;
|
|
3234
|
+
if (ticketRes.ok) {
|
|
3235
|
+
const ticketData = await ticketRes.json();
|
|
3236
|
+
const ticket = ticketData.ticket;
|
|
3237
|
+
wsUrl = baseUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
|
|
3238
|
+
} else {
|
|
3239
|
+
wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
|
|
3240
|
+
}
|
|
3069
3241
|
this.ws = new WebSocket(wsUrl);
|
|
3070
3242
|
} catch {
|
|
3071
3243
|
this.scheduleReconnect();
|
|
@@ -5249,6 +5421,71 @@ var FlagContentService = class extends ServiceModule {
|
|
|
5249
5421
|
return this._get(`/appeals/${id}`, options);
|
|
5250
5422
|
}
|
|
5251
5423
|
};
|
|
5424
|
+
var CreatorMakerService = class extends ServiceModule {
|
|
5425
|
+
constructor() {
|
|
5426
|
+
super(...arguments);
|
|
5427
|
+
this.basePath = "/v1/creator-maker";
|
|
5428
|
+
}
|
|
5429
|
+
/** Submit a generation job. */
|
|
5430
|
+
async generate(data, options) {
|
|
5431
|
+
return this.post("/jobs", data, options);
|
|
5432
|
+
}
|
|
5433
|
+
/** Get a generation job by ID. */
|
|
5434
|
+
async getJob(jobId, options) {
|
|
5435
|
+
return this._get(`/jobs/${jobId}`, options);
|
|
5436
|
+
}
|
|
5437
|
+
/** Long-poll for job completion (server holds up to 30s). */
|
|
5438
|
+
async pollJob(jobId, options) {
|
|
5439
|
+
return this._get(`/jobs/${jobId}/poll`, {
|
|
5440
|
+
...options,
|
|
5441
|
+
timeout: 35e3
|
|
5442
|
+
});
|
|
5443
|
+
}
|
|
5444
|
+
/** List the current user's generation jobs. */
|
|
5445
|
+
async listJobs(params, options) {
|
|
5446
|
+
return this._list("/jobs", params, options);
|
|
5447
|
+
}
|
|
5448
|
+
/** Cancel a pending or queued job. */
|
|
5449
|
+
async cancelJob(jobId, options) {
|
|
5450
|
+
return this.post(`/jobs/${jobId}/cancel`, void 0, options);
|
|
5451
|
+
}
|
|
5452
|
+
/** Retry a failed job. */
|
|
5453
|
+
async retryJob(jobId, options) {
|
|
5454
|
+
return this.post(`/jobs/${jobId}/retry`, void 0, options);
|
|
5455
|
+
}
|
|
5456
|
+
/** Generate variations of a completed job. */
|
|
5457
|
+
async generateVariations(jobId, options) {
|
|
5458
|
+
return this.post(`/jobs/${jobId}/variations`, void 0, options);
|
|
5459
|
+
}
|
|
5460
|
+
/** List available style presets, optionally filtered by mode. */
|
|
5461
|
+
async listPresets(params, options) {
|
|
5462
|
+
return this._get(this.withQuery("/presets", params), options);
|
|
5463
|
+
}
|
|
5464
|
+
/** Get a style preset by slug. */
|
|
5465
|
+
async getPreset(slug, options) {
|
|
5466
|
+
return this._get(`/presets/${slug}`, options);
|
|
5467
|
+
}
|
|
5468
|
+
/** Create a project. */
|
|
5469
|
+
async createProject(data, options) {
|
|
5470
|
+
return this.post("/projects", data, options);
|
|
5471
|
+
}
|
|
5472
|
+
/** List the current user's projects. */
|
|
5473
|
+
async listProjects(params, options) {
|
|
5474
|
+
return this._list("/projects", params, options);
|
|
5475
|
+
}
|
|
5476
|
+
/** Get generation usage and credit balance. */
|
|
5477
|
+
async getUsage(options) {
|
|
5478
|
+
return this._get("/usage", options);
|
|
5479
|
+
}
|
|
5480
|
+
/** Get a generation output by ID. */
|
|
5481
|
+
async getOutput(outputId, options) {
|
|
5482
|
+
return this._get(`/outputs/${outputId}`, options);
|
|
5483
|
+
}
|
|
5484
|
+
/** Get a download URL for a generation output. */
|
|
5485
|
+
async getDownloadUrl(outputId, options) {
|
|
5486
|
+
return this._get(`/outputs/${outputId}/download`, options);
|
|
5487
|
+
}
|
|
5488
|
+
};
|
|
5252
5489
|
var AgentAuthService = class extends ServiceModule {
|
|
5253
5490
|
constructor() {
|
|
5254
5491
|
super(...arguments);
|
|
@@ -5450,6 +5687,13 @@ var AgentProjectsService = class extends ServiceModule {
|
|
|
5450
5687
|
options
|
|
5451
5688
|
);
|
|
5452
5689
|
}
|
|
5690
|
+
async startTask(taskId, agentId, applicationId, options) {
|
|
5691
|
+
return this.post(
|
|
5692
|
+
this.withAppId(`/tasks/${taskId}/start`, applicationId),
|
|
5693
|
+
{ agent_id: agentId },
|
|
5694
|
+
options
|
|
5695
|
+
);
|
|
5696
|
+
}
|
|
5453
5697
|
async submit(taskId, data, applicationId, options) {
|
|
5454
5698
|
return this.post(this.withAppId(`/tasks/${taskId}/submit`, applicationId), data, options);
|
|
5455
5699
|
}
|
|
@@ -5748,6 +5992,7 @@ var ScaleMule = class {
|
|
|
5748
5992
|
this.functions = new FunctionsService(this._client);
|
|
5749
5993
|
this.photo = new PhotoService(this._client);
|
|
5750
5994
|
this.flagContent = new FlagContentService(this._client);
|
|
5995
|
+
this.creatorMaker = new CreatorMakerService(this._client);
|
|
5751
5996
|
this.compliance = new ComplianceService(this._client);
|
|
5752
5997
|
this.orchestrator = new OrchestratorService(this._client);
|
|
5753
5998
|
this.agentAuth = new AgentAuthService(this._client);
|
|
@@ -5827,6 +6072,36 @@ var ScaleMule = class {
|
|
|
5827
6072
|
async clearAllAccounts() {
|
|
5828
6073
|
return this._client.clearAllAccounts();
|
|
5829
6074
|
}
|
|
6075
|
+
// --------------------------------------------------------------------------
|
|
6076
|
+
// Account Switcher (Secure — metadata only, re-auth required)
|
|
6077
|
+
// --------------------------------------------------------------------------
|
|
6078
|
+
/** Whether the account switcher is enabled */
|
|
6079
|
+
isAccountSwitcherEnabled() {
|
|
6080
|
+
return this._client.isAccountSwitcherEnabled();
|
|
6081
|
+
}
|
|
6082
|
+
/** The configured privacy level for the account switcher */
|
|
6083
|
+
getAccountSwitcherPrivacy() {
|
|
6084
|
+
return this._client.getAccountSwitcherPrivacy();
|
|
6085
|
+
}
|
|
6086
|
+
/**
|
|
6087
|
+
* Get all accounts that have previously logged in on this device.
|
|
6088
|
+
* Returns privacy-transformed display data — no raw PII in masked/minimal modes.
|
|
6089
|
+
* Requires `enableAccountSwitcher: true` in config.
|
|
6090
|
+
*/
|
|
6091
|
+
getKnownAccounts() {
|
|
6092
|
+
return this._client.getKnownAccounts();
|
|
6093
|
+
}
|
|
6094
|
+
/**
|
|
6095
|
+
* Forget a specific account — removes it from the known accounts list.
|
|
6096
|
+
* Does NOT affect any active session.
|
|
6097
|
+
*/
|
|
6098
|
+
async removeKnownAccount(userId) {
|
|
6099
|
+
return this._client.removeKnownAccount(userId);
|
|
6100
|
+
}
|
|
6101
|
+
/** Forget all known accounts on this device. */
|
|
6102
|
+
async clearKnownAccounts() {
|
|
6103
|
+
return this._client.clearKnownAccounts();
|
|
6104
|
+
}
|
|
5830
6105
|
/** The base URL being used for API requests. */
|
|
5831
6106
|
getBaseUrl() {
|
|
5832
6107
|
return this._client.getBaseUrl();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalemule/nextjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"description": "ScaleMule SDK for Next.js applications - authentication, storage, and user management",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"clean": "rm -rf dist"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@scalemule/sdk": "^0.0.
|
|
55
|
+
"@scalemule/sdk": "^0.0.30"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"next": ">=14.0.0",
|