@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.js
CHANGED
|
@@ -308,6 +308,7 @@ __export(index_exports, {
|
|
|
308
308
|
ChatService: () => ChatService,
|
|
309
309
|
CommunicationService: () => CommunicationService,
|
|
310
310
|
ComplianceService: () => ComplianceService,
|
|
311
|
+
CreatorMakerService: () => CreatorMakerService,
|
|
311
312
|
DataService: () => DataService,
|
|
312
313
|
ErrorCodes: () => ErrorCodes,
|
|
313
314
|
EventsService: () => EventsService,
|
|
@@ -474,6 +475,7 @@ var WORKSPACE_STORAGE_KEY = "scalemule_workspace_id";
|
|
|
474
475
|
var ANONYMOUS_ID_STORAGE_KEY = "scalemule_anonymous_id";
|
|
475
476
|
var SESSION_POOL_KEY = "scalemule_session_pool";
|
|
476
477
|
var ACTIVE_ACCOUNT_KEY = "scalemule_active_account";
|
|
478
|
+
var KNOWN_ACCOUNTS_KEY = "scalemule_known_accounts";
|
|
477
479
|
var GATEWAY_URLS = {
|
|
478
480
|
dev: "https://api-dev.scalemule.com",
|
|
479
481
|
prod: "https://api.scalemule.com"
|
|
@@ -523,6 +525,54 @@ function statusToErrorCode(status) {
|
|
|
523
525
|
return status >= 500 ? "internal_error" : `http_${status}`;
|
|
524
526
|
}
|
|
525
527
|
}
|
|
528
|
+
var MAX_KNOWN_ACCOUNTS = 10;
|
|
529
|
+
function maskEmail(email) {
|
|
530
|
+
const parts = email.split("@");
|
|
531
|
+
const local = parts[0] ?? "";
|
|
532
|
+
const domain = parts[1];
|
|
533
|
+
if (!domain) return "***@***.***";
|
|
534
|
+
const tldDot = domain.lastIndexOf(".");
|
|
535
|
+
const tld = tldDot > 0 ? domain.slice(tldDot) : "";
|
|
536
|
+
const domainBase = tldDot > 0 ? domain.slice(0, tldDot) : domain;
|
|
537
|
+
return `${local[0] || "*"}***@${domainBase[0] || "*"}***${tld}`;
|
|
538
|
+
}
|
|
539
|
+
function stableColorIndex(userId) {
|
|
540
|
+
let hash = 0;
|
|
541
|
+
for (let i = 0; i < userId.length; i++) {
|
|
542
|
+
hash = (hash << 5) - hash + userId.charCodeAt(i) | 0;
|
|
543
|
+
}
|
|
544
|
+
return Math.abs(hash) % 8;
|
|
545
|
+
}
|
|
546
|
+
function applyPrivacy(account, privacy) {
|
|
547
|
+
switch (privacy) {
|
|
548
|
+
case "full":
|
|
549
|
+
return {
|
|
550
|
+
userId: account.userId,
|
|
551
|
+
email: account.email,
|
|
552
|
+
fullName: account.fullName,
|
|
553
|
+
avatarUrl: account.avatarUrl,
|
|
554
|
+
provider: account.provider,
|
|
555
|
+
lastActiveAt: account.lastActiveAt
|
|
556
|
+
};
|
|
557
|
+
case "masked":
|
|
558
|
+
return {
|
|
559
|
+
userId: account.userId,
|
|
560
|
+
email: account.email ? maskEmail(account.email) : void 0,
|
|
561
|
+
fullName: account.fullName && account.fullName.length > 0 ? `${account.fullName[0].toUpperCase()}.` : void 0,
|
|
562
|
+
provider: account.provider,
|
|
563
|
+
lastActiveAt: account.lastActiveAt,
|
|
564
|
+
colorIndex: stableColorIndex(account.userId)
|
|
565
|
+
};
|
|
566
|
+
case "minimal":
|
|
567
|
+
return {
|
|
568
|
+
userId: account.userId,
|
|
569
|
+
provider: account.provider,
|
|
570
|
+
lastActiveAt: account.lastActiveAt,
|
|
571
|
+
displayLabel: "Account",
|
|
572
|
+
colorIndex: stableColorIndex(account.userId)
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
}
|
|
526
576
|
function createDefaultStorage() {
|
|
527
577
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
528
578
|
return {
|
|
@@ -669,6 +719,7 @@ var ScaleMuleClient = class {
|
|
|
669
719
|
this.workspaceId = null;
|
|
670
720
|
this.anonymousId = null;
|
|
671
721
|
this.sessionPool = /* @__PURE__ */ new Map();
|
|
722
|
+
this.knownAccounts = /* @__PURE__ */ new Map();
|
|
672
723
|
this.apiKey = config.apiKey;
|
|
673
724
|
this.applicationId = config.applicationId || null;
|
|
674
725
|
this.baseUrl = config.baseUrl || GATEWAY_URLS[config.environment || "prod"];
|
|
@@ -685,6 +736,8 @@ var ScaleMuleClient = class {
|
|
|
685
736
|
this.offlineQueue.setOnlineCallback(() => this.syncOfflineQueue());
|
|
686
737
|
}
|
|
687
738
|
this.multiSessionEnabled = config.enableMultiSession || false;
|
|
739
|
+
this.accountSwitcherEnabled = config.enableAccountSwitcher || false;
|
|
740
|
+
this.accountSwitcherPrivacy = config.accountSwitcherPrivacy || "full";
|
|
688
741
|
}
|
|
689
742
|
// --------------------------------------------------------------------------
|
|
690
743
|
// Session Management
|
|
@@ -727,6 +780,27 @@ var ScaleMuleClient = class {
|
|
|
727
780
|
this.userId = activeId;
|
|
728
781
|
}
|
|
729
782
|
}
|
|
783
|
+
if (this.accountSwitcherEnabled) {
|
|
784
|
+
const knownJson = await this.storage.getItem(KNOWN_ACCOUNTS_KEY);
|
|
785
|
+
if (knownJson) {
|
|
786
|
+
try {
|
|
787
|
+
const entries = JSON.parse(knownJson);
|
|
788
|
+
this.knownAccounts = new Map(Object.entries(entries));
|
|
789
|
+
let changed = false;
|
|
790
|
+
for (const [userId2, entry] of this.knownAccounts) {
|
|
791
|
+
const normalized = applyPrivacy(entry, this.accountSwitcherPrivacy);
|
|
792
|
+
if (JSON.stringify(normalized) !== JSON.stringify(entry)) {
|
|
793
|
+
this.knownAccounts.set(userId2, normalized);
|
|
794
|
+
changed = true;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
if (changed) {
|
|
798
|
+
await this.persistKnownAccounts();
|
|
799
|
+
}
|
|
800
|
+
} catch {
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
730
804
|
if (this.debug)
|
|
731
805
|
console.log(
|
|
732
806
|
"[ScaleMule] Initialized, session:",
|
|
@@ -734,7 +808,9 @@ var ScaleMuleClient = class {
|
|
|
734
808
|
"anonymousId:",
|
|
735
809
|
anonId,
|
|
736
810
|
"poolSize:",
|
|
737
|
-
this.sessionPool.size
|
|
811
|
+
this.sessionPool.size,
|
|
812
|
+
"knownAccounts:",
|
|
813
|
+
this.knownAccounts.size
|
|
738
814
|
);
|
|
739
815
|
}
|
|
740
816
|
async setSession(token, userId) {
|
|
@@ -858,6 +934,57 @@ var ScaleMuleClient = class {
|
|
|
858
934
|
}
|
|
859
935
|
await this.storage.setItem(SESSION_POOL_KEY, JSON.stringify(obj));
|
|
860
936
|
}
|
|
937
|
+
// --------------------------------------------------------------------------
|
|
938
|
+
// Account Switcher (Secure — metadata only, no tokens)
|
|
939
|
+
// --------------------------------------------------------------------------
|
|
940
|
+
isAccountSwitcherEnabled() {
|
|
941
|
+
return this.accountSwitcherEnabled;
|
|
942
|
+
}
|
|
943
|
+
getAccountSwitcherPrivacy() {
|
|
944
|
+
return this.accountSwitcherPrivacy;
|
|
945
|
+
}
|
|
946
|
+
/** Get all known accounts that have logged in on this device (privacy-transformed) */
|
|
947
|
+
getKnownAccounts() {
|
|
948
|
+
return Array.from(this.knownAccounts.values());
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Record an account as "known" on this device.
|
|
952
|
+
* Applies privacy transforms before storing — full email is never persisted
|
|
953
|
+
* in masked/minimal modes. Evicts oldest accounts if over the cap.
|
|
954
|
+
* Called automatically after successful login/register when account switcher is enabled.
|
|
955
|
+
*/
|
|
956
|
+
async addKnownAccount(account) {
|
|
957
|
+
const display = applyPrivacy(account, this.accountSwitcherPrivacy);
|
|
958
|
+
this.knownAccounts.set(account.userId, display);
|
|
959
|
+
if (this.knownAccounts.size > MAX_KNOWN_ACCOUNTS) {
|
|
960
|
+
const sorted = Array.from(this.knownAccounts.entries()).sort(
|
|
961
|
+
(a, b) => (a[1].lastActiveAt || "").localeCompare(b[1].lastActiveAt || "")
|
|
962
|
+
);
|
|
963
|
+
while (this.knownAccounts.size > MAX_KNOWN_ACCOUNTS && sorted.length > 0) {
|
|
964
|
+
const oldest = sorted.shift();
|
|
965
|
+
this.knownAccounts.delete(oldest[0]);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
await this.persistKnownAccounts();
|
|
969
|
+
}
|
|
970
|
+
/** Remove a specific account from the known accounts list ("forget this account") */
|
|
971
|
+
async removeKnownAccount(userId) {
|
|
972
|
+
this.knownAccounts.delete(userId);
|
|
973
|
+
await this.persistKnownAccounts();
|
|
974
|
+
}
|
|
975
|
+
/** Clear all known accounts ("forget all accounts on this device") */
|
|
976
|
+
async clearKnownAccounts() {
|
|
977
|
+
this.knownAccounts.clear();
|
|
978
|
+
await this.storage.removeItem(KNOWN_ACCOUNTS_KEY);
|
|
979
|
+
}
|
|
980
|
+
/** Persist known accounts to storage */
|
|
981
|
+
async persistKnownAccounts() {
|
|
982
|
+
const obj = {};
|
|
983
|
+
for (const [k, v] of this.knownAccounts) {
|
|
984
|
+
obj[k] = v;
|
|
985
|
+
}
|
|
986
|
+
await this.storage.setItem(KNOWN_ACCOUNTS_KEY, JSON.stringify(obj));
|
|
987
|
+
}
|
|
861
988
|
getBaseUrl() {
|
|
862
989
|
return this.baseUrl;
|
|
863
990
|
}
|
|
@@ -1614,6 +1741,16 @@ var AuthService = class extends ServiceModule {
|
|
|
1614
1741
|
addedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1615
1742
|
});
|
|
1616
1743
|
}
|
|
1744
|
+
if (result.data && this.client.isAccountSwitcherEnabled()) {
|
|
1745
|
+
await this.client.addKnownAccount({
|
|
1746
|
+
userId: result.data.user.id,
|
|
1747
|
+
email: result.data.user.email,
|
|
1748
|
+
fullName: result.data.user.full_name,
|
|
1749
|
+
avatarUrl: result.data.user.avatar_url,
|
|
1750
|
+
provider: "email",
|
|
1751
|
+
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1617
1754
|
return result;
|
|
1618
1755
|
}
|
|
1619
1756
|
async login(data, options) {
|
|
@@ -1634,6 +1771,16 @@ var AuthService = class extends ServiceModule {
|
|
|
1634
1771
|
addedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1635
1772
|
});
|
|
1636
1773
|
}
|
|
1774
|
+
if (result.data && this.client.isAccountSwitcherEnabled()) {
|
|
1775
|
+
await this.client.addKnownAccount({
|
|
1776
|
+
userId: result.data.user.id,
|
|
1777
|
+
email: result.data.user.email,
|
|
1778
|
+
fullName: result.data.user.full_name,
|
|
1779
|
+
avatarUrl: result.data.user.avatar_url,
|
|
1780
|
+
provider: "email",
|
|
1781
|
+
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1782
|
+
});
|
|
1783
|
+
}
|
|
1637
1784
|
return result;
|
|
1638
1785
|
}
|
|
1639
1786
|
async logout(options) {
|
|
@@ -1775,7 +1922,18 @@ var AuthService = class extends ServiceModule {
|
|
|
1775
1922
|
}
|
|
1776
1923
|
async handleOAuthCallback(data, options) {
|
|
1777
1924
|
const { provider, ...rest } = data;
|
|
1778
|
-
|
|
1925
|
+
const result = await this._get(this.withQuery(`/oauth/${provider}/callback`, rest), options);
|
|
1926
|
+
if (result.data && this.client.isAccountSwitcherEnabled()) {
|
|
1927
|
+
await this.client.addKnownAccount({
|
|
1928
|
+
userId: result.data.user.id,
|
|
1929
|
+
email: result.data.user.email,
|
|
1930
|
+
fullName: result.data.user.full_name,
|
|
1931
|
+
avatarUrl: result.data.user.avatar_url,
|
|
1932
|
+
provider,
|
|
1933
|
+
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
return result;
|
|
1779
1937
|
}
|
|
1780
1938
|
async listOAuthProviders(options) {
|
|
1781
1939
|
return this._get("/oauth/providers", options);
|
|
@@ -3617,10 +3775,29 @@ var RealtimeService = class extends ServiceModule {
|
|
|
3617
3775
|
// --------------------------------------------------------------------------
|
|
3618
3776
|
connect() {
|
|
3619
3777
|
if (this._status === "connecting" || this._status === "connected") return;
|
|
3620
|
-
const baseUrl = this.client.getBaseUrl();
|
|
3621
|
-
const wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
|
|
3622
3778
|
this.setStatus(this.reconnectAttempt > 0 ? "reconnecting" : "connecting");
|
|
3779
|
+
this.fetchTicketAndConnect();
|
|
3780
|
+
}
|
|
3781
|
+
async fetchTicketAndConnect() {
|
|
3782
|
+
const baseUrl = this.client.getBaseUrl();
|
|
3623
3783
|
try {
|
|
3784
|
+
const headers = { "Content-Type": "application/json" };
|
|
3785
|
+
const apiKey = this.client.getApiKey();
|
|
3786
|
+
if (apiKey) headers["x-api-key"] = apiKey;
|
|
3787
|
+
const token = this.client.getSessionToken();
|
|
3788
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
3789
|
+
const ticketRes = await fetch(`${baseUrl}/v1/realtime/ws/ticket`, {
|
|
3790
|
+
method: "POST",
|
|
3791
|
+
headers
|
|
3792
|
+
});
|
|
3793
|
+
let wsUrl;
|
|
3794
|
+
if (ticketRes.ok) {
|
|
3795
|
+
const ticketData = await ticketRes.json();
|
|
3796
|
+
const ticket = ticketData.ticket;
|
|
3797
|
+
wsUrl = baseUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
|
|
3798
|
+
} else {
|
|
3799
|
+
wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
|
|
3800
|
+
}
|
|
3624
3801
|
this.ws = new WebSocket(wsUrl);
|
|
3625
3802
|
} catch {
|
|
3626
3803
|
this.scheduleReconnect();
|
|
@@ -6018,6 +6195,73 @@ var FlagContentService = class extends ServiceModule {
|
|
|
6018
6195
|
}
|
|
6019
6196
|
};
|
|
6020
6197
|
|
|
6198
|
+
// src/services/creator-maker.ts
|
|
6199
|
+
var CreatorMakerService = class extends ServiceModule {
|
|
6200
|
+
constructor() {
|
|
6201
|
+
super(...arguments);
|
|
6202
|
+
this.basePath = "/v1/creator-maker";
|
|
6203
|
+
}
|
|
6204
|
+
/** Submit a generation job. */
|
|
6205
|
+
async generate(data, options) {
|
|
6206
|
+
return this.post("/jobs", data, options);
|
|
6207
|
+
}
|
|
6208
|
+
/** Get a generation job by ID. */
|
|
6209
|
+
async getJob(jobId, options) {
|
|
6210
|
+
return this._get(`/jobs/${jobId}`, options);
|
|
6211
|
+
}
|
|
6212
|
+
/** Long-poll for job completion (server holds up to 30s). */
|
|
6213
|
+
async pollJob(jobId, options) {
|
|
6214
|
+
return this._get(`/jobs/${jobId}/poll`, {
|
|
6215
|
+
...options,
|
|
6216
|
+
timeout: 35e3
|
|
6217
|
+
});
|
|
6218
|
+
}
|
|
6219
|
+
/** List the current user's generation jobs. */
|
|
6220
|
+
async listJobs(params, options) {
|
|
6221
|
+
return this._list("/jobs", params, options);
|
|
6222
|
+
}
|
|
6223
|
+
/** Cancel a pending or queued job. */
|
|
6224
|
+
async cancelJob(jobId, options) {
|
|
6225
|
+
return this.post(`/jobs/${jobId}/cancel`, void 0, options);
|
|
6226
|
+
}
|
|
6227
|
+
/** Retry a failed job. */
|
|
6228
|
+
async retryJob(jobId, options) {
|
|
6229
|
+
return this.post(`/jobs/${jobId}/retry`, void 0, options);
|
|
6230
|
+
}
|
|
6231
|
+
/** Generate variations of a completed job. */
|
|
6232
|
+
async generateVariations(jobId, options) {
|
|
6233
|
+
return this.post(`/jobs/${jobId}/variations`, void 0, options);
|
|
6234
|
+
}
|
|
6235
|
+
/** List available style presets, optionally filtered by mode. */
|
|
6236
|
+
async listPresets(params, options) {
|
|
6237
|
+
return this._get(this.withQuery("/presets", params), options);
|
|
6238
|
+
}
|
|
6239
|
+
/** Get a style preset by slug. */
|
|
6240
|
+
async getPreset(slug, options) {
|
|
6241
|
+
return this._get(`/presets/${slug}`, options);
|
|
6242
|
+
}
|
|
6243
|
+
/** Create a project. */
|
|
6244
|
+
async createProject(data, options) {
|
|
6245
|
+
return this.post("/projects", data, options);
|
|
6246
|
+
}
|
|
6247
|
+
/** List the current user's projects. */
|
|
6248
|
+
async listProjects(params, options) {
|
|
6249
|
+
return this._list("/projects", params, options);
|
|
6250
|
+
}
|
|
6251
|
+
/** Get generation usage and credit balance. */
|
|
6252
|
+
async getUsage(options) {
|
|
6253
|
+
return this._get("/usage", options);
|
|
6254
|
+
}
|
|
6255
|
+
/** Get a generation output by ID. */
|
|
6256
|
+
async getOutput(outputId, options) {
|
|
6257
|
+
return this._get(`/outputs/${outputId}`, options);
|
|
6258
|
+
}
|
|
6259
|
+
/** Get a download URL for a generation output. */
|
|
6260
|
+
async getDownloadUrl(outputId, options) {
|
|
6261
|
+
return this._get(`/outputs/${outputId}/download`, options);
|
|
6262
|
+
}
|
|
6263
|
+
};
|
|
6264
|
+
|
|
6021
6265
|
// src/services/agent-auth.ts
|
|
6022
6266
|
var AgentAuthService = class extends ServiceModule {
|
|
6023
6267
|
constructor() {
|
|
@@ -6537,6 +6781,7 @@ var ScaleMule = class {
|
|
|
6537
6781
|
this.functions = new FunctionsService(this._client);
|
|
6538
6782
|
this.photo = new PhotoService(this._client);
|
|
6539
6783
|
this.flagContent = new FlagContentService(this._client);
|
|
6784
|
+
this.creatorMaker = new CreatorMakerService(this._client);
|
|
6540
6785
|
this.compliance = new ComplianceService(this._client);
|
|
6541
6786
|
this.orchestrator = new OrchestratorService(this._client);
|
|
6542
6787
|
this.agentAuth = new AgentAuthService(this._client);
|
|
@@ -6616,6 +6861,36 @@ var ScaleMule = class {
|
|
|
6616
6861
|
async clearAllAccounts() {
|
|
6617
6862
|
return this._client.clearAllAccounts();
|
|
6618
6863
|
}
|
|
6864
|
+
// --------------------------------------------------------------------------
|
|
6865
|
+
// Account Switcher (Secure — metadata only, re-auth required)
|
|
6866
|
+
// --------------------------------------------------------------------------
|
|
6867
|
+
/** Whether the account switcher is enabled */
|
|
6868
|
+
isAccountSwitcherEnabled() {
|
|
6869
|
+
return this._client.isAccountSwitcherEnabled();
|
|
6870
|
+
}
|
|
6871
|
+
/** The configured privacy level for the account switcher */
|
|
6872
|
+
getAccountSwitcherPrivacy() {
|
|
6873
|
+
return this._client.getAccountSwitcherPrivacy();
|
|
6874
|
+
}
|
|
6875
|
+
/**
|
|
6876
|
+
* Get all accounts that have previously logged in on this device.
|
|
6877
|
+
* Returns privacy-transformed display data — no raw PII in masked/minimal modes.
|
|
6878
|
+
* Requires `enableAccountSwitcher: true` in config.
|
|
6879
|
+
*/
|
|
6880
|
+
getKnownAccounts() {
|
|
6881
|
+
return this._client.getKnownAccounts();
|
|
6882
|
+
}
|
|
6883
|
+
/**
|
|
6884
|
+
* Forget a specific account — removes it from the known accounts list.
|
|
6885
|
+
* Does NOT affect any active session.
|
|
6886
|
+
*/
|
|
6887
|
+
async removeKnownAccount(userId) {
|
|
6888
|
+
return this._client.removeKnownAccount(userId);
|
|
6889
|
+
}
|
|
6890
|
+
/** Forget all known accounts on this device. */
|
|
6891
|
+
async clearKnownAccounts() {
|
|
6892
|
+
return this._client.clearKnownAccounts();
|
|
6893
|
+
}
|
|
6619
6894
|
/** The base URL being used for API requests. */
|
|
6620
6895
|
getBaseUrl() {
|
|
6621
6896
|
return this._client.getBaseUrl();
|
|
@@ -6655,6 +6930,7 @@ var index_default = ScaleMule;
|
|
|
6655
6930
|
ChatService,
|
|
6656
6931
|
CommunicationService,
|
|
6657
6932
|
ComplianceService,
|
|
6933
|
+
CreatorMakerService,
|
|
6658
6934
|
DataService,
|
|
6659
6935
|
ErrorCodes,
|
|
6660
6936
|
EventsService,
|