@scalemule/sdk 0.0.28 → 0.0.30
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.d.mts +228 -1
- package/dist/index.d.ts +228 -1
- package/dist/index.js +280 -4
- package/dist/index.mjs +279 -4
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -107,6 +107,7 @@ var WORKSPACE_STORAGE_KEY = "scalemule_workspace_id";
|
|
|
107
107
|
var ANONYMOUS_ID_STORAGE_KEY = "scalemule_anonymous_id";
|
|
108
108
|
var SESSION_POOL_KEY = "scalemule_session_pool";
|
|
109
109
|
var ACTIVE_ACCOUNT_KEY = "scalemule_active_account";
|
|
110
|
+
var KNOWN_ACCOUNTS_KEY = "scalemule_known_accounts";
|
|
110
111
|
var GATEWAY_URLS = {
|
|
111
112
|
dev: "https://api-dev.scalemule.com",
|
|
112
113
|
prod: "https://api.scalemule.com"
|
|
@@ -156,6 +157,54 @@ function statusToErrorCode(status) {
|
|
|
156
157
|
return status >= 500 ? "internal_error" : `http_${status}`;
|
|
157
158
|
}
|
|
158
159
|
}
|
|
160
|
+
var MAX_KNOWN_ACCOUNTS = 10;
|
|
161
|
+
function maskEmail(email) {
|
|
162
|
+
const parts = email.split("@");
|
|
163
|
+
const local = parts[0] ?? "";
|
|
164
|
+
const domain = parts[1];
|
|
165
|
+
if (!domain) return "***@***.***";
|
|
166
|
+
const tldDot = domain.lastIndexOf(".");
|
|
167
|
+
const tld = tldDot > 0 ? domain.slice(tldDot) : "";
|
|
168
|
+
const domainBase = tldDot > 0 ? domain.slice(0, tldDot) : domain;
|
|
169
|
+
return `${local[0] || "*"}***@${domainBase[0] || "*"}***${tld}`;
|
|
170
|
+
}
|
|
171
|
+
function stableColorIndex(userId) {
|
|
172
|
+
let hash = 0;
|
|
173
|
+
for (let i = 0; i < userId.length; i++) {
|
|
174
|
+
hash = (hash << 5) - hash + userId.charCodeAt(i) | 0;
|
|
175
|
+
}
|
|
176
|
+
return Math.abs(hash) % 8;
|
|
177
|
+
}
|
|
178
|
+
function applyPrivacy(account, privacy) {
|
|
179
|
+
switch (privacy) {
|
|
180
|
+
case "full":
|
|
181
|
+
return {
|
|
182
|
+
userId: account.userId,
|
|
183
|
+
email: account.email,
|
|
184
|
+
fullName: account.fullName,
|
|
185
|
+
avatarUrl: account.avatarUrl,
|
|
186
|
+
provider: account.provider,
|
|
187
|
+
lastActiveAt: account.lastActiveAt
|
|
188
|
+
};
|
|
189
|
+
case "masked":
|
|
190
|
+
return {
|
|
191
|
+
userId: account.userId,
|
|
192
|
+
email: account.email ? maskEmail(account.email) : void 0,
|
|
193
|
+
fullName: account.fullName && account.fullName.length > 0 ? `${account.fullName[0].toUpperCase()}.` : void 0,
|
|
194
|
+
provider: account.provider,
|
|
195
|
+
lastActiveAt: account.lastActiveAt,
|
|
196
|
+
colorIndex: stableColorIndex(account.userId)
|
|
197
|
+
};
|
|
198
|
+
case "minimal":
|
|
199
|
+
return {
|
|
200
|
+
userId: account.userId,
|
|
201
|
+
provider: account.provider,
|
|
202
|
+
lastActiveAt: account.lastActiveAt,
|
|
203
|
+
displayLabel: "Account",
|
|
204
|
+
colorIndex: stableColorIndex(account.userId)
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
159
208
|
function createDefaultStorage() {
|
|
160
209
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
161
210
|
return {
|
|
@@ -302,6 +351,7 @@ var ScaleMuleClient = class {
|
|
|
302
351
|
this.workspaceId = null;
|
|
303
352
|
this.anonymousId = null;
|
|
304
353
|
this.sessionPool = /* @__PURE__ */ new Map();
|
|
354
|
+
this.knownAccounts = /* @__PURE__ */ new Map();
|
|
305
355
|
this.apiKey = config.apiKey;
|
|
306
356
|
this.applicationId = config.applicationId || null;
|
|
307
357
|
this.baseUrl = config.baseUrl || GATEWAY_URLS[config.environment || "prod"];
|
|
@@ -318,6 +368,8 @@ var ScaleMuleClient = class {
|
|
|
318
368
|
this.offlineQueue.setOnlineCallback(() => this.syncOfflineQueue());
|
|
319
369
|
}
|
|
320
370
|
this.multiSessionEnabled = config.enableMultiSession || false;
|
|
371
|
+
this.accountSwitcherEnabled = config.enableAccountSwitcher || false;
|
|
372
|
+
this.accountSwitcherPrivacy = config.accountSwitcherPrivacy || "full";
|
|
321
373
|
}
|
|
322
374
|
// --------------------------------------------------------------------------
|
|
323
375
|
// Session Management
|
|
@@ -360,6 +412,27 @@ var ScaleMuleClient = class {
|
|
|
360
412
|
this.userId = activeId;
|
|
361
413
|
}
|
|
362
414
|
}
|
|
415
|
+
if (this.accountSwitcherEnabled) {
|
|
416
|
+
const knownJson = await this.storage.getItem(KNOWN_ACCOUNTS_KEY);
|
|
417
|
+
if (knownJson) {
|
|
418
|
+
try {
|
|
419
|
+
const entries = JSON.parse(knownJson);
|
|
420
|
+
this.knownAccounts = new Map(Object.entries(entries));
|
|
421
|
+
let changed = false;
|
|
422
|
+
for (const [userId2, entry] of this.knownAccounts) {
|
|
423
|
+
const normalized = applyPrivacy(entry, this.accountSwitcherPrivacy);
|
|
424
|
+
if (JSON.stringify(normalized) !== JSON.stringify(entry)) {
|
|
425
|
+
this.knownAccounts.set(userId2, normalized);
|
|
426
|
+
changed = true;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (changed) {
|
|
430
|
+
await this.persistKnownAccounts();
|
|
431
|
+
}
|
|
432
|
+
} catch {
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
363
436
|
if (this.debug)
|
|
364
437
|
console.log(
|
|
365
438
|
"[ScaleMule] Initialized, session:",
|
|
@@ -367,7 +440,9 @@ var ScaleMuleClient = class {
|
|
|
367
440
|
"anonymousId:",
|
|
368
441
|
anonId,
|
|
369
442
|
"poolSize:",
|
|
370
|
-
this.sessionPool.size
|
|
443
|
+
this.sessionPool.size,
|
|
444
|
+
"knownAccounts:",
|
|
445
|
+
this.knownAccounts.size
|
|
371
446
|
);
|
|
372
447
|
}
|
|
373
448
|
async setSession(token, userId) {
|
|
@@ -491,6 +566,57 @@ var ScaleMuleClient = class {
|
|
|
491
566
|
}
|
|
492
567
|
await this.storage.setItem(SESSION_POOL_KEY, JSON.stringify(obj));
|
|
493
568
|
}
|
|
569
|
+
// --------------------------------------------------------------------------
|
|
570
|
+
// Account Switcher (Secure — metadata only, no tokens)
|
|
571
|
+
// --------------------------------------------------------------------------
|
|
572
|
+
isAccountSwitcherEnabled() {
|
|
573
|
+
return this.accountSwitcherEnabled;
|
|
574
|
+
}
|
|
575
|
+
getAccountSwitcherPrivacy() {
|
|
576
|
+
return this.accountSwitcherPrivacy;
|
|
577
|
+
}
|
|
578
|
+
/** Get all known accounts that have logged in on this device (privacy-transformed) */
|
|
579
|
+
getKnownAccounts() {
|
|
580
|
+
return Array.from(this.knownAccounts.values());
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Record an account as "known" on this device.
|
|
584
|
+
* Applies privacy transforms before storing — full email is never persisted
|
|
585
|
+
* in masked/minimal modes. Evicts oldest accounts if over the cap.
|
|
586
|
+
* Called automatically after successful login/register when account switcher is enabled.
|
|
587
|
+
*/
|
|
588
|
+
async addKnownAccount(account) {
|
|
589
|
+
const display = applyPrivacy(account, this.accountSwitcherPrivacy);
|
|
590
|
+
this.knownAccounts.set(account.userId, display);
|
|
591
|
+
if (this.knownAccounts.size > MAX_KNOWN_ACCOUNTS) {
|
|
592
|
+
const sorted = Array.from(this.knownAccounts.entries()).sort(
|
|
593
|
+
(a, b) => (a[1].lastActiveAt || "").localeCompare(b[1].lastActiveAt || "")
|
|
594
|
+
);
|
|
595
|
+
while (this.knownAccounts.size > MAX_KNOWN_ACCOUNTS && sorted.length > 0) {
|
|
596
|
+
const oldest = sorted.shift();
|
|
597
|
+
this.knownAccounts.delete(oldest[0]);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
await this.persistKnownAccounts();
|
|
601
|
+
}
|
|
602
|
+
/** Remove a specific account from the known accounts list ("forget this account") */
|
|
603
|
+
async removeKnownAccount(userId) {
|
|
604
|
+
this.knownAccounts.delete(userId);
|
|
605
|
+
await this.persistKnownAccounts();
|
|
606
|
+
}
|
|
607
|
+
/** Clear all known accounts ("forget all accounts on this device") */
|
|
608
|
+
async clearKnownAccounts() {
|
|
609
|
+
this.knownAccounts.clear();
|
|
610
|
+
await this.storage.removeItem(KNOWN_ACCOUNTS_KEY);
|
|
611
|
+
}
|
|
612
|
+
/** Persist known accounts to storage */
|
|
613
|
+
async persistKnownAccounts() {
|
|
614
|
+
const obj = {};
|
|
615
|
+
for (const [k, v] of this.knownAccounts) {
|
|
616
|
+
obj[k] = v;
|
|
617
|
+
}
|
|
618
|
+
await this.storage.setItem(KNOWN_ACCOUNTS_KEY, JSON.stringify(obj));
|
|
619
|
+
}
|
|
494
620
|
getBaseUrl() {
|
|
495
621
|
return this.baseUrl;
|
|
496
622
|
}
|
|
@@ -1247,6 +1373,16 @@ var AuthService = class extends ServiceModule {
|
|
|
1247
1373
|
addedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1248
1374
|
});
|
|
1249
1375
|
}
|
|
1376
|
+
if (result.data && this.client.isAccountSwitcherEnabled()) {
|
|
1377
|
+
await this.client.addKnownAccount({
|
|
1378
|
+
userId: result.data.user.id,
|
|
1379
|
+
email: result.data.user.email,
|
|
1380
|
+
fullName: result.data.user.full_name,
|
|
1381
|
+
avatarUrl: result.data.user.avatar_url,
|
|
1382
|
+
provider: "email",
|
|
1383
|
+
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1250
1386
|
return result;
|
|
1251
1387
|
}
|
|
1252
1388
|
async login(data, options) {
|
|
@@ -1267,6 +1403,16 @@ var AuthService = class extends ServiceModule {
|
|
|
1267
1403
|
addedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1268
1404
|
});
|
|
1269
1405
|
}
|
|
1406
|
+
if (result.data && this.client.isAccountSwitcherEnabled()) {
|
|
1407
|
+
await this.client.addKnownAccount({
|
|
1408
|
+
userId: result.data.user.id,
|
|
1409
|
+
email: result.data.user.email,
|
|
1410
|
+
fullName: result.data.user.full_name,
|
|
1411
|
+
avatarUrl: result.data.user.avatar_url,
|
|
1412
|
+
provider: "email",
|
|
1413
|
+
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1270
1416
|
return result;
|
|
1271
1417
|
}
|
|
1272
1418
|
async logout(options) {
|
|
@@ -1408,7 +1554,18 @@ var AuthService = class extends ServiceModule {
|
|
|
1408
1554
|
}
|
|
1409
1555
|
async handleOAuthCallback(data, options) {
|
|
1410
1556
|
const { provider, ...rest } = data;
|
|
1411
|
-
|
|
1557
|
+
const result = await this._get(this.withQuery(`/oauth/${provider}/callback`, rest), options);
|
|
1558
|
+
if (result.data && this.client.isAccountSwitcherEnabled()) {
|
|
1559
|
+
await this.client.addKnownAccount({
|
|
1560
|
+
userId: result.data.user.id,
|
|
1561
|
+
email: result.data.user.email,
|
|
1562
|
+
fullName: result.data.user.full_name,
|
|
1563
|
+
avatarUrl: result.data.user.avatar_url,
|
|
1564
|
+
provider,
|
|
1565
|
+
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1566
|
+
});
|
|
1567
|
+
}
|
|
1568
|
+
return result;
|
|
1412
1569
|
}
|
|
1413
1570
|
async listOAuthProviders(options) {
|
|
1414
1571
|
return this._get("/oauth/providers", options);
|
|
@@ -3247,10 +3404,29 @@ var RealtimeService = class extends ServiceModule {
|
|
|
3247
3404
|
// --------------------------------------------------------------------------
|
|
3248
3405
|
connect() {
|
|
3249
3406
|
if (this._status === "connecting" || this._status === "connected") return;
|
|
3250
|
-
const baseUrl = this.client.getBaseUrl();
|
|
3251
|
-
const wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
|
|
3252
3407
|
this.setStatus(this.reconnectAttempt > 0 ? "reconnecting" : "connecting");
|
|
3408
|
+
this.fetchTicketAndConnect();
|
|
3409
|
+
}
|
|
3410
|
+
async fetchTicketAndConnect() {
|
|
3411
|
+
const baseUrl = this.client.getBaseUrl();
|
|
3253
3412
|
try {
|
|
3413
|
+
const headers = { "Content-Type": "application/json" };
|
|
3414
|
+
const apiKey = this.client.getApiKey();
|
|
3415
|
+
if (apiKey) headers["x-api-key"] = apiKey;
|
|
3416
|
+
const token = this.client.getSessionToken();
|
|
3417
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
3418
|
+
const ticketRes = await fetch(`${baseUrl}/v1/realtime/ws/ticket`, {
|
|
3419
|
+
method: "POST",
|
|
3420
|
+
headers
|
|
3421
|
+
});
|
|
3422
|
+
let wsUrl;
|
|
3423
|
+
if (ticketRes.ok) {
|
|
3424
|
+
const ticketData = await ticketRes.json();
|
|
3425
|
+
const ticket = ticketData.ticket;
|
|
3426
|
+
wsUrl = baseUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
|
|
3427
|
+
} else {
|
|
3428
|
+
wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
|
|
3429
|
+
}
|
|
3254
3430
|
this.ws = new WebSocket(wsUrl);
|
|
3255
3431
|
} catch {
|
|
3256
3432
|
this.scheduleReconnect();
|
|
@@ -5648,6 +5824,73 @@ var FlagContentService = class extends ServiceModule {
|
|
|
5648
5824
|
}
|
|
5649
5825
|
};
|
|
5650
5826
|
|
|
5827
|
+
// src/services/creator-maker.ts
|
|
5828
|
+
var CreatorMakerService = class extends ServiceModule {
|
|
5829
|
+
constructor() {
|
|
5830
|
+
super(...arguments);
|
|
5831
|
+
this.basePath = "/v1/creator-maker";
|
|
5832
|
+
}
|
|
5833
|
+
/** Submit a generation job. */
|
|
5834
|
+
async generate(data, options) {
|
|
5835
|
+
return this.post("/jobs", data, options);
|
|
5836
|
+
}
|
|
5837
|
+
/** Get a generation job by ID. */
|
|
5838
|
+
async getJob(jobId, options) {
|
|
5839
|
+
return this._get(`/jobs/${jobId}`, options);
|
|
5840
|
+
}
|
|
5841
|
+
/** Long-poll for job completion (server holds up to 30s). */
|
|
5842
|
+
async pollJob(jobId, options) {
|
|
5843
|
+
return this._get(`/jobs/${jobId}/poll`, {
|
|
5844
|
+
...options,
|
|
5845
|
+
timeout: 35e3
|
|
5846
|
+
});
|
|
5847
|
+
}
|
|
5848
|
+
/** List the current user's generation jobs. */
|
|
5849
|
+
async listJobs(params, options) {
|
|
5850
|
+
return this._list("/jobs", params, options);
|
|
5851
|
+
}
|
|
5852
|
+
/** Cancel a pending or queued job. */
|
|
5853
|
+
async cancelJob(jobId, options) {
|
|
5854
|
+
return this.post(`/jobs/${jobId}/cancel`, void 0, options);
|
|
5855
|
+
}
|
|
5856
|
+
/** Retry a failed job. */
|
|
5857
|
+
async retryJob(jobId, options) {
|
|
5858
|
+
return this.post(`/jobs/${jobId}/retry`, void 0, options);
|
|
5859
|
+
}
|
|
5860
|
+
/** Generate variations of a completed job. */
|
|
5861
|
+
async generateVariations(jobId, options) {
|
|
5862
|
+
return this.post(`/jobs/${jobId}/variations`, void 0, options);
|
|
5863
|
+
}
|
|
5864
|
+
/** List available style presets, optionally filtered by mode. */
|
|
5865
|
+
async listPresets(params, options) {
|
|
5866
|
+
return this._get(this.withQuery("/presets", params), options);
|
|
5867
|
+
}
|
|
5868
|
+
/** Get a style preset by slug. */
|
|
5869
|
+
async getPreset(slug, options) {
|
|
5870
|
+
return this._get(`/presets/${slug}`, options);
|
|
5871
|
+
}
|
|
5872
|
+
/** Create a project. */
|
|
5873
|
+
async createProject(data, options) {
|
|
5874
|
+
return this.post("/projects", data, options);
|
|
5875
|
+
}
|
|
5876
|
+
/** List the current user's projects. */
|
|
5877
|
+
async listProjects(params, options) {
|
|
5878
|
+
return this._list("/projects", params, options);
|
|
5879
|
+
}
|
|
5880
|
+
/** Get generation usage and credit balance. */
|
|
5881
|
+
async getUsage(options) {
|
|
5882
|
+
return this._get("/usage", options);
|
|
5883
|
+
}
|
|
5884
|
+
/** Get a generation output by ID. */
|
|
5885
|
+
async getOutput(outputId, options) {
|
|
5886
|
+
return this._get(`/outputs/${outputId}`, options);
|
|
5887
|
+
}
|
|
5888
|
+
/** Get a download URL for a generation output. */
|
|
5889
|
+
async getDownloadUrl(outputId, options) {
|
|
5890
|
+
return this._get(`/outputs/${outputId}/download`, options);
|
|
5891
|
+
}
|
|
5892
|
+
};
|
|
5893
|
+
|
|
5651
5894
|
// src/services/agent-auth.ts
|
|
5652
5895
|
var AgentAuthService = class extends ServiceModule {
|
|
5653
5896
|
constructor() {
|
|
@@ -6167,6 +6410,7 @@ var ScaleMule = class {
|
|
|
6167
6410
|
this.functions = new FunctionsService(this._client);
|
|
6168
6411
|
this.photo = new PhotoService(this._client);
|
|
6169
6412
|
this.flagContent = new FlagContentService(this._client);
|
|
6413
|
+
this.creatorMaker = new CreatorMakerService(this._client);
|
|
6170
6414
|
this.compliance = new ComplianceService(this._client);
|
|
6171
6415
|
this.orchestrator = new OrchestratorService(this._client);
|
|
6172
6416
|
this.agentAuth = new AgentAuthService(this._client);
|
|
@@ -6246,6 +6490,36 @@ var ScaleMule = class {
|
|
|
6246
6490
|
async clearAllAccounts() {
|
|
6247
6491
|
return this._client.clearAllAccounts();
|
|
6248
6492
|
}
|
|
6493
|
+
// --------------------------------------------------------------------------
|
|
6494
|
+
// Account Switcher (Secure — metadata only, re-auth required)
|
|
6495
|
+
// --------------------------------------------------------------------------
|
|
6496
|
+
/** Whether the account switcher is enabled */
|
|
6497
|
+
isAccountSwitcherEnabled() {
|
|
6498
|
+
return this._client.isAccountSwitcherEnabled();
|
|
6499
|
+
}
|
|
6500
|
+
/** The configured privacy level for the account switcher */
|
|
6501
|
+
getAccountSwitcherPrivacy() {
|
|
6502
|
+
return this._client.getAccountSwitcherPrivacy();
|
|
6503
|
+
}
|
|
6504
|
+
/**
|
|
6505
|
+
* Get all accounts that have previously logged in on this device.
|
|
6506
|
+
* Returns privacy-transformed display data — no raw PII in masked/minimal modes.
|
|
6507
|
+
* Requires `enableAccountSwitcher: true` in config.
|
|
6508
|
+
*/
|
|
6509
|
+
getKnownAccounts() {
|
|
6510
|
+
return this._client.getKnownAccounts();
|
|
6511
|
+
}
|
|
6512
|
+
/**
|
|
6513
|
+
* Forget a specific account — removes it from the known accounts list.
|
|
6514
|
+
* Does NOT affect any active session.
|
|
6515
|
+
*/
|
|
6516
|
+
async removeKnownAccount(userId) {
|
|
6517
|
+
return this._client.removeKnownAccount(userId);
|
|
6518
|
+
}
|
|
6519
|
+
/** Forget all known accounts on this device. */
|
|
6520
|
+
async clearKnownAccounts() {
|
|
6521
|
+
return this._client.clearKnownAccounts();
|
|
6522
|
+
}
|
|
6249
6523
|
/** The base URL being used for API requests. */
|
|
6250
6524
|
getBaseUrl() {
|
|
6251
6525
|
return this._client.getBaseUrl();
|
|
@@ -6284,6 +6558,7 @@ export {
|
|
|
6284
6558
|
ChatService,
|
|
6285
6559
|
CommunicationService,
|
|
6286
6560
|
ComplianceService,
|
|
6561
|
+
CreatorMakerService,
|
|
6287
6562
|
DataService,
|
|
6288
6563
|
ErrorCodes,
|
|
6289
6564
|
EventsService,
|