@kittl/sdk 0.0.8 → 1.0.0-alpha.1
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/dashboardStandalonePage/sdk.d.ts +8261 -0
- package/dist/dashboardStandalonePage/sdk.esm.js +1176 -0
- package/dist/dashboardStandalonePage/sdk.js +1176 -0
- package/dist/editorContentPanel/sdk.d.ts +8613 -0
- package/dist/editorContentPanel/sdk.esm.js +1462 -0
- package/dist/editorContentPanel/sdk.js +1462 -0
- package/dist/editorScriptRunner/sdk.d.ts +7977 -0
- package/dist/{kittl-sdk.esm.js → editorScriptRunner/sdk.esm.js} +400 -180
- package/dist/{kittl-sdk.js → editorScriptRunner/sdk.js} +400 -180
- package/dist/sharedFileBrowser/sdk.d.ts +328 -0
- package/dist/sharedFileBrowser/sdk.esm.js +1177 -0
- package/dist/sharedFileBrowser/sdk.js +1177 -0
- package/package.json +25 -6
- package/dist/sdk.d.ts +0 -2424
|
@@ -3,8 +3,19 @@
|
|
|
3
3
|
|
|
4
4
|
"use strict";
|
|
5
5
|
(() => {
|
|
6
|
-
//
|
|
6
|
+
// src/api/utils.ts
|
|
7
|
+
function unwrapResult(result) {
|
|
8
|
+
if (result.isOk) {
|
|
9
|
+
return result.result;
|
|
10
|
+
}
|
|
11
|
+
throw result.error;
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
var FROM_EXTENSION_COMMANDS = {
|
|
15
|
+
/** Capability-owned AI callback registration. */
|
|
16
|
+
AI_GENERATOR_SUBSCRIBE: "ai-generator-subscribe",
|
|
17
|
+
/** Capability-owned AI callback teardown. */
|
|
18
|
+
AI_GENERATOR_UNSUBSCRIBE: "ai-generator-unsubscribe",
|
|
8
19
|
/** SDK API call */
|
|
9
20
|
SDK_CALL: "sdk-call",
|
|
10
21
|
/** AI handler registration */
|
|
@@ -53,6 +64,8 @@
|
|
|
53
64
|
LOADED: "loaded"
|
|
54
65
|
};
|
|
55
66
|
var TO_EXTENSION_COMMANDS = {
|
|
67
|
+
/** Callback payload for generator or pending-set subscriptions. */
|
|
68
|
+
AI_GENERATOR_UPDATE: "ai-generator-update",
|
|
56
69
|
/** SDK API response */
|
|
57
70
|
SDK_RESPONSE: "sdk-response",
|
|
58
71
|
/** File browser fetch content request */
|
|
@@ -69,7 +82,10 @@
|
|
|
69
82
|
APP_STATE_UPDATE: "app-state-update"
|
|
70
83
|
};
|
|
71
84
|
|
|
72
|
-
|
|
85
|
+
function isAIGeneratorUpdateMessage(data) {
|
|
86
|
+
return !!data && typeof data === "object" && "command" in data && data.command === "ai-generator-update" && "subscriptionId" in data && typeof data.subscriptionId === "string";
|
|
87
|
+
}
|
|
88
|
+
|
|
73
89
|
var isSDKResponseMessage = (data) => {
|
|
74
90
|
return typeof data === "object" && data !== null && "command" in data && data.command === TO_EXTENSION_COMMANDS.SDK_RESPONSE && "messageId" in data && typeof data.messageId === "string";
|
|
75
91
|
};
|
|
@@ -92,7 +108,13 @@
|
|
|
92
108
|
return typeof data === "object" && data !== null && "command" in data && data.command === TO_EXTENSION_COMMANDS.FILE_BROWSER_FETCH_CONTENT_REQUEST && "requestId" in data && typeof data.requestId === "string" && "subscriptionId" in data && typeof data.subscriptionId === "string";
|
|
93
109
|
};
|
|
94
110
|
|
|
95
|
-
|
|
111
|
+
var generateMessageId = () => {
|
|
112
|
+
if (crypto?.randomUUID && typeof crypto.randomUUID === "function") {
|
|
113
|
+
return crypto.randomUUID();
|
|
114
|
+
}
|
|
115
|
+
return Math.random().toString(36).substring(7);
|
|
116
|
+
};
|
|
117
|
+
|
|
96
118
|
var buildMethodPath = (rootPrefix, pathSegments) => {
|
|
97
119
|
if (!rootPrefix) {
|
|
98
120
|
return pathSegments.join(".");
|
|
@@ -128,16 +150,15 @@
|
|
|
128
150
|
return createNode([]);
|
|
129
151
|
};
|
|
130
152
|
|
|
131
|
-
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/shared/index.js
|
|
132
|
-
var EDITOR_URL = typeof window !== "undefined" ? window.location?.origin : "";
|
|
133
|
-
|
|
134
|
-
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/utils/approvedDomain/approvedDomain.js
|
|
135
153
|
var parentDomain;
|
|
136
154
|
var APPROVED_EXTENSION_COMMUNICATION_DOMAINS = [
|
|
137
155
|
"https://app.stagingdesigner.com",
|
|
138
156
|
"https://*.stagingdesigner.com",
|
|
139
157
|
"http://localhost:3000",
|
|
140
|
-
"https://app.kittl.com"
|
|
158
|
+
"https://app.kittl.com",
|
|
159
|
+
// website, for sandboxed standalone dashboard pages
|
|
160
|
+
"http://localhost:3003",
|
|
161
|
+
"https://www.kittl.com"
|
|
141
162
|
];
|
|
142
163
|
var toOrigin = (value) => {
|
|
143
164
|
if (!value) {
|
|
@@ -191,16 +212,16 @@
|
|
|
191
212
|
return parentDomain;
|
|
192
213
|
};
|
|
193
214
|
|
|
194
|
-
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/messageSender.js
|
|
195
215
|
var pendingRequests = /* @__PURE__ */ new Map();
|
|
196
|
-
var
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return Math.random().toString(36).substring(7);
|
|
201
|
-
};
|
|
216
|
+
var sdkVersion;
|
|
217
|
+
function setSDKVersion(version2) {
|
|
218
|
+
sdkVersion = version2;
|
|
219
|
+
}
|
|
202
220
|
var postMessageToParent = (message) => {
|
|
203
|
-
window.parent.postMessage(
|
|
221
|
+
window.parent.postMessage(
|
|
222
|
+
sdkVersion === void 0 ? message : { ...message, sdkVersion },
|
|
223
|
+
getParentDomain()
|
|
224
|
+
);
|
|
204
225
|
};
|
|
205
226
|
var sendMessage = (message) => {
|
|
206
227
|
postMessageToParent(message);
|
|
@@ -222,8 +243,28 @@
|
|
|
222
243
|
postMessageToParent(message);
|
|
223
244
|
};
|
|
224
245
|
|
|
225
|
-
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/apiProxy/index.js
|
|
226
246
|
var createSDKCallMessage = {
|
|
247
|
+
aiGenerator: (dots, args, messageId) => ({
|
|
248
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
249
|
+
dots,
|
|
250
|
+
args,
|
|
251
|
+
messageId,
|
|
252
|
+
apiType: "aiGenerator"
|
|
253
|
+
}),
|
|
254
|
+
mockup: (dots, args, messageId) => ({
|
|
255
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
256
|
+
dots,
|
|
257
|
+
args,
|
|
258
|
+
messageId,
|
|
259
|
+
apiType: "mockup"
|
|
260
|
+
}),
|
|
261
|
+
fileBrowser: (dots, args, messageId) => ({
|
|
262
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
263
|
+
dots,
|
|
264
|
+
args,
|
|
265
|
+
messageId,
|
|
266
|
+
apiType: "fileBrowser"
|
|
267
|
+
}),
|
|
227
268
|
ai: (dots, args, messageId) => ({
|
|
228
269
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
229
270
|
dots,
|
|
@@ -245,6 +286,13 @@
|
|
|
245
286
|
messageId,
|
|
246
287
|
apiType: "design"
|
|
247
288
|
}),
|
|
289
|
+
export: (dots, args, messageId) => ({
|
|
290
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
291
|
+
dots,
|
|
292
|
+
args,
|
|
293
|
+
messageId,
|
|
294
|
+
apiType: "export"
|
|
295
|
+
}),
|
|
248
296
|
font: (dots, args, messageId) => ({
|
|
249
297
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
250
298
|
dots,
|
|
@@ -252,6 +300,13 @@
|
|
|
252
300
|
messageId,
|
|
253
301
|
apiType: "font"
|
|
254
302
|
}),
|
|
303
|
+
project: (dots, args, messageId) => ({
|
|
304
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
305
|
+
dots,
|
|
306
|
+
args,
|
|
307
|
+
messageId,
|
|
308
|
+
apiType: "project"
|
|
309
|
+
}),
|
|
255
310
|
state: (dots, args, messageId) => ({
|
|
256
311
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
257
312
|
dots,
|
|
@@ -272,6 +327,27 @@
|
|
|
272
327
|
args,
|
|
273
328
|
messageId,
|
|
274
329
|
apiType: "data"
|
|
330
|
+
}),
|
|
331
|
+
brandKit: (dots, args, messageId) => ({
|
|
332
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
333
|
+
dots,
|
|
334
|
+
args,
|
|
335
|
+
messageId,
|
|
336
|
+
apiType: "brandKit"
|
|
337
|
+
}),
|
|
338
|
+
openMicroEditor: (dots, args, messageId) => ({
|
|
339
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
340
|
+
dots,
|
|
341
|
+
args,
|
|
342
|
+
messageId,
|
|
343
|
+
apiType: "openMicroEditor"
|
|
344
|
+
}),
|
|
345
|
+
openMainEditor: (dots, args, messageId) => ({
|
|
346
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
347
|
+
dots,
|
|
348
|
+
args,
|
|
349
|
+
messageId,
|
|
350
|
+
apiType: "openMainEditor"
|
|
275
351
|
})
|
|
276
352
|
};
|
|
277
353
|
function createApiProxy(apiType) {
|
|
@@ -288,7 +364,64 @@
|
|
|
288
364
|
});
|
|
289
365
|
}
|
|
290
366
|
|
|
291
|
-
|
|
367
|
+
function createAIGeneratorBridgeApi() {
|
|
368
|
+
const callbacks = /* @__PURE__ */ new Map();
|
|
369
|
+
const proxy = createApiProxy("aiGenerator");
|
|
370
|
+
async function subscribe(request, callback) {
|
|
371
|
+
const subscriptionId = generateMessageId();
|
|
372
|
+
callbacks.set(subscriptionId, callback);
|
|
373
|
+
let response;
|
|
374
|
+
try {
|
|
375
|
+
response = await sendMessage({
|
|
376
|
+
command: "ai-generator-subscribe",
|
|
377
|
+
...request,
|
|
378
|
+
subscriptionId,
|
|
379
|
+
messageId: generateMessageId()
|
|
380
|
+
});
|
|
381
|
+
} catch (error) {
|
|
382
|
+
callbacks.delete(subscriptionId);
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
if (!response.isOk) {
|
|
386
|
+
callbacks.delete(subscriptionId);
|
|
387
|
+
throw new Error(response.error.message);
|
|
388
|
+
}
|
|
389
|
+
return () => {
|
|
390
|
+
callbacks.delete(subscriptionId);
|
|
391
|
+
postMessageToParent({
|
|
392
|
+
command: "ai-generator-unsubscribe",
|
|
393
|
+
subscriptionId
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
const methods = {
|
|
398
|
+
registerGenerator: (id, callback) => subscribe({ method: "registerGenerator", args: [id] }, (update) => {
|
|
399
|
+
if (update) callback(update);
|
|
400
|
+
}),
|
|
401
|
+
subscribeToGenerationUpdates: (ids, callback) => subscribe(
|
|
402
|
+
{ method: "subscribeToGenerationUpdates", args: [ids] },
|
|
403
|
+
(update) => {
|
|
404
|
+
if (update) callback(update);
|
|
405
|
+
}
|
|
406
|
+
),
|
|
407
|
+
subscribeToPendingGenerations: (callback) => subscribe(
|
|
408
|
+
{ method: "subscribeToPendingGenerations", args: [] },
|
|
409
|
+
() => callback()
|
|
410
|
+
),
|
|
411
|
+
/** Callers may reuse richer internal submission objects; never send their local abort callbacks. */
|
|
412
|
+
cancelGenerations: (submission) => proxy.cancelGenerations({
|
|
413
|
+
generationIds: submission.generationIds,
|
|
414
|
+
until: submission.until
|
|
415
|
+
})
|
|
416
|
+
};
|
|
417
|
+
return {
|
|
418
|
+
api: new Proxy(proxy, {
|
|
419
|
+
get: (target, property, receiver) => property in methods ? methods[property] : Reflect.get(target, property, receiver)
|
|
420
|
+
}),
|
|
421
|
+
dispatch: (message) => callbacks.get(message.subscriptionId)?.(message.update)
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
292
425
|
var generationHandlers = /* @__PURE__ */ new Map();
|
|
293
426
|
var generationSubscriptions = /* @__PURE__ */ new Map();
|
|
294
427
|
var dispatchAIGenerationUpdate = (subscriptionId, update) => {
|
|
@@ -390,9 +523,11 @@
|
|
|
390
523
|
};
|
|
391
524
|
}
|
|
392
525
|
|
|
393
|
-
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/apiProxy/fileBrowserApiProxy.js
|
|
394
526
|
var fetchContentHandlers = /* @__PURE__ */ new Map();
|
|
395
527
|
var tabIdToSubscriptionId = /* @__PURE__ */ new Map();
|
|
528
|
+
var removeSubscriptionHandlers = (subscriptionId) => {
|
|
529
|
+
fetchContentHandlers.delete(subscriptionId);
|
|
530
|
+
};
|
|
396
531
|
var dispatchFileBrowserFetchContentRequest = (requestId, subscriptionId, params) => {
|
|
397
532
|
const handler = fetchContentHandlers.get(subscriptionId);
|
|
398
533
|
if (!handler) {
|
|
@@ -412,12 +547,12 @@
|
|
|
412
547
|
next: result.next
|
|
413
548
|
};
|
|
414
549
|
postMessageToParent(responseMessage);
|
|
415
|
-
}).catch((
|
|
550
|
+
}).catch((error) => {
|
|
416
551
|
const responseMessage = {
|
|
417
552
|
command: FROM_EXTENSION_COMMANDS.FILE_BROWSER_FETCH_CONTENT_RESPONSE,
|
|
418
553
|
requestId,
|
|
419
554
|
content: [],
|
|
420
|
-
error:
|
|
555
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
421
556
|
};
|
|
422
557
|
postMessageToParent(responseMessage);
|
|
423
558
|
});
|
|
@@ -428,7 +563,7 @@
|
|
|
428
563
|
const subscriptionId = generateMessageId();
|
|
429
564
|
const existingSubscriptionId = tabIdToSubscriptionId.get(tab.id);
|
|
430
565
|
if (existingSubscriptionId) {
|
|
431
|
-
|
|
566
|
+
removeSubscriptionHandlers(existingSubscriptionId);
|
|
432
567
|
}
|
|
433
568
|
fetchContentHandlers.set(subscriptionId, tab.fetchContent);
|
|
434
569
|
tabIdToSubscriptionId.set(tab.id, subscriptionId);
|
|
@@ -437,12 +572,14 @@
|
|
|
437
572
|
messageId: generateMessageId(),
|
|
438
573
|
tabId: tab.id,
|
|
439
574
|
label: tab.label,
|
|
575
|
+
order: tab.order,
|
|
576
|
+
emptyState: tab.emptyState,
|
|
440
577
|
subscriptionId
|
|
441
578
|
};
|
|
442
579
|
try {
|
|
443
580
|
const response = await sendMessage(registerMessage);
|
|
444
581
|
if (!response.isOk) {
|
|
445
|
-
|
|
582
|
+
removeSubscriptionHandlers(subscriptionId);
|
|
446
583
|
tabIdToSubscriptionId.delete(tab.id);
|
|
447
584
|
return {
|
|
448
585
|
isOk: false,
|
|
@@ -454,7 +591,8 @@
|
|
|
454
591
|
result: void 0
|
|
455
592
|
};
|
|
456
593
|
} catch {
|
|
457
|
-
|
|
594
|
+
removeSubscriptionHandlers(subscriptionId);
|
|
595
|
+
tabIdToSubscriptionId.delete(tab.id);
|
|
458
596
|
return {
|
|
459
597
|
isOk: false,
|
|
460
598
|
error: {
|
|
@@ -467,7 +605,6 @@
|
|
|
467
605
|
};
|
|
468
606
|
}
|
|
469
607
|
|
|
470
|
-
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/appState/index.js
|
|
471
608
|
var sendUnsubscribe = (selectorIds) => {
|
|
472
609
|
const message = {
|
|
473
610
|
command: FROM_EXTENSION_COMMANDS.APP_STATE_UNSUBSCRIBE,
|
|
@@ -532,106 +669,127 @@
|
|
|
532
669
|
return { subscribe, dispatch };
|
|
533
670
|
};
|
|
534
671
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
543
|
-
};
|
|
544
|
-
var generatePKCECode = () => {
|
|
545
|
-
if (!window.crypto) {
|
|
546
|
-
throw new Error("Crypto API not available");
|
|
672
|
+
var SandboxedAuthClient = class {
|
|
673
|
+
/**
|
|
674
|
+
* Binds the public start method because the exported SDK API may pass it
|
|
675
|
+
* around without its client object as the receiver.
|
|
676
|
+
*/
|
|
677
|
+
constructor() {
|
|
678
|
+
this.startAuth = this.startAuth.bind(this);
|
|
547
679
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
680
|
+
/**
|
|
681
|
+
* Starts provider authentication and optionally adds an RFC 7636 PKCE
|
|
682
|
+
* challenge to the request. Successful responses include the verifier that
|
|
683
|
+
* the caller must pass to {@link exchangeCode}.
|
|
684
|
+
*/
|
|
685
|
+
async startAuth(request) {
|
|
686
|
+
const state = generateMessageId();
|
|
687
|
+
let pkceCode = "";
|
|
688
|
+
let code_verifier = "";
|
|
689
|
+
if (request.generatePKCE) {
|
|
690
|
+
code_verifier = this.generatePKCECode();
|
|
691
|
+
pkceCode = await this.hashPKCECode(code_verifier);
|
|
692
|
+
}
|
|
693
|
+
const message = {
|
|
694
|
+
command: FROM_EXTENSION_COMMANDS.AUTH_START,
|
|
695
|
+
messageId: generateMessageId(),
|
|
696
|
+
state,
|
|
697
|
+
provider: request.provider,
|
|
698
|
+
params: {
|
|
699
|
+
...request.params,
|
|
700
|
+
...pkceCode ? {
|
|
701
|
+
code_challenge: pkceCode,
|
|
702
|
+
code_challenge_method: "S256"
|
|
703
|
+
} : {}
|
|
561
704
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
} : {}
|
|
573
|
-
}
|
|
574
|
-
};
|
|
575
|
-
const response = await sendMessage(message);
|
|
576
|
-
if (!response.isOk) {
|
|
577
|
-
return response;
|
|
705
|
+
};
|
|
706
|
+
const response = await sendMessage(message);
|
|
707
|
+
if (!response.isOk) {
|
|
708
|
+
return response;
|
|
709
|
+
}
|
|
710
|
+
return {
|
|
711
|
+
...response,
|
|
712
|
+
result: {
|
|
713
|
+
...response.result,
|
|
714
|
+
code_verifier
|
|
578
715
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
/** Exchanges the provider authorization code for an auth token. */
|
|
719
|
+
exchangeCode(request) {
|
|
720
|
+
const message = {
|
|
721
|
+
command: FROM_EXTENSION_COMMANDS.AUTH_EXCHANGE,
|
|
722
|
+
messageId: generateMessageId(),
|
|
723
|
+
code: request.code,
|
|
724
|
+
code_verifier: request.code_verifier,
|
|
725
|
+
provider: request.provider,
|
|
726
|
+
params: request.params,
|
|
727
|
+
headers: request.headers
|
|
728
|
+
};
|
|
729
|
+
return sendMessage(message);
|
|
730
|
+
}
|
|
731
|
+
/** Requests the current auth token for a provider. */
|
|
732
|
+
getAuthToken(request) {
|
|
733
|
+
const message = {
|
|
734
|
+
command: FROM_EXTENSION_COMMANDS.AUTH_GET_TOKEN,
|
|
735
|
+
messageId: generateMessageId(),
|
|
736
|
+
provider: request.provider
|
|
737
|
+
};
|
|
738
|
+
return sendMessage(message);
|
|
739
|
+
}
|
|
740
|
+
/** Refreshes the auth token for a provider. */
|
|
741
|
+
refreshToken(request) {
|
|
742
|
+
const message = {
|
|
743
|
+
command: FROM_EXTENSION_COMMANDS.AUTH_REFRESH,
|
|
744
|
+
messageId: generateMessageId(),
|
|
745
|
+
provider: request.provider
|
|
746
|
+
};
|
|
747
|
+
return sendMessage(message);
|
|
748
|
+
}
|
|
749
|
+
/** Logs the current user out of a provider. */
|
|
750
|
+
logout(request) {
|
|
751
|
+
const message = {
|
|
752
|
+
command: FROM_EXTENSION_COMMANDS.AUTH_LOGOUT,
|
|
753
|
+
messageId: generateMessageId(),
|
|
754
|
+
provider: request.provider
|
|
755
|
+
};
|
|
756
|
+
return sendMessage(message);
|
|
757
|
+
}
|
|
758
|
+
/** Requests the authenticated user's user token from the parent window. */
|
|
759
|
+
getUserToken() {
|
|
760
|
+
const message = {
|
|
761
|
+
command: FROM_EXTENSION_COMMANDS.AUTH_GET_USER_TOKEN,
|
|
762
|
+
messageId: generateMessageId()
|
|
763
|
+
};
|
|
764
|
+
return sendMessage(message);
|
|
765
|
+
}
|
|
766
|
+
/** Hashes a PKCE verifier and encodes the SHA-256 digest as Base64URL. */
|
|
767
|
+
async hashPKCECode(input) {
|
|
768
|
+
const subtle = window.crypto?.subtle;
|
|
769
|
+
if (!subtle) {
|
|
770
|
+
throw new Error("Web Crypto SubtleCrypto API not available");
|
|
629
771
|
}
|
|
630
|
-
|
|
772
|
+
const textAsBuffer = new TextEncoder().encode(input);
|
|
773
|
+
const hashBuffer = await subtle.digest("SHA-256", textAsBuffer);
|
|
774
|
+
const hashArray = new Uint8Array(hashBuffer);
|
|
775
|
+
const binaryString = String.fromCharCode(...hashArray);
|
|
776
|
+
const base64 = btoa(binaryString);
|
|
777
|
+
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
778
|
+
}
|
|
779
|
+
/** Generates a high-entropy RFC 7636-compatible PKCE verifier. */
|
|
780
|
+
generatePKCECode() {
|
|
781
|
+
if (!window.crypto) {
|
|
782
|
+
throw new Error("Crypto API not available");
|
|
783
|
+
}
|
|
784
|
+
const array = new Uint32Array(56);
|
|
785
|
+
window.crypto.getRandomValues(array);
|
|
786
|
+
return Array.from(array, (dec) => `0${dec.toString(16)}`.slice(-2)).join(
|
|
787
|
+
""
|
|
788
|
+
);
|
|
789
|
+
}
|
|
631
790
|
};
|
|
632
791
|
|
|
633
|
-
|
|
634
|
-
var createBatch = async () => {
|
|
792
|
+
var createBatchFor = async (apiType) => {
|
|
635
793
|
const response = await sendMessage({
|
|
636
794
|
command: FROM_EXTENSION_COMMANDS.BATCH_CREATE,
|
|
637
795
|
messageId: generateMessageId()
|
|
@@ -640,14 +798,17 @@
|
|
|
640
798
|
throw response.error;
|
|
641
799
|
}
|
|
642
800
|
const { batchKey } = response.result;
|
|
643
|
-
const sendDesignCall = (dots, args) =>
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
801
|
+
const sendDesignCall = (dots, args) => {
|
|
802
|
+
const message = {
|
|
803
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
804
|
+
dots: apiType === "project" ? ["design", "api", ...dots] : dots,
|
|
805
|
+
args,
|
|
806
|
+
messageId: generateMessageId(),
|
|
807
|
+
apiType,
|
|
808
|
+
batchKey
|
|
809
|
+
};
|
|
810
|
+
return sendMessage(message);
|
|
811
|
+
};
|
|
651
812
|
const commit = async () => {
|
|
652
813
|
const res = await sendMessage({
|
|
653
814
|
command: FROM_EXTENSION_COMMANDS.BATCH_COMMIT,
|
|
@@ -674,8 +835,9 @@
|
|
|
674
835
|
};
|
|
675
836
|
return buildNode([]);
|
|
676
837
|
};
|
|
838
|
+
var createBatch = () => createBatchFor("design");
|
|
839
|
+
var createProjectBatch = () => createBatchFor("project");
|
|
677
840
|
|
|
678
|
-
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/context/contextBridge.js
|
|
679
841
|
var createContextBridgeApi = () => {
|
|
680
842
|
const contextProxy = createApiProxy("context");
|
|
681
843
|
const subscriptionCallbacks = /* @__PURE__ */ new Map();
|
|
@@ -722,7 +884,6 @@
|
|
|
722
884
|
return { api, dispatch };
|
|
723
885
|
};
|
|
724
886
|
|
|
725
|
-
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/designState/index.js
|
|
726
887
|
var sendUnsubscribe2 = (selectorIds) => {
|
|
727
888
|
const message = {
|
|
728
889
|
command: FROM_EXTENSION_COMMANDS.DESIGN_STATE_UNSUBSCRIBE,
|
|
@@ -789,7 +950,6 @@
|
|
|
789
950
|
return { subscribe, dispatch };
|
|
790
951
|
};
|
|
791
952
|
|
|
792
|
-
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/stateless/index.js
|
|
793
953
|
var createStatelessBridgeApi = () => {
|
|
794
954
|
const subscribers = /* @__PURE__ */ new Map();
|
|
795
955
|
return {
|
|
@@ -839,11 +999,12 @@
|
|
|
839
999
|
};
|
|
840
1000
|
};
|
|
841
1001
|
|
|
842
|
-
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers.js
|
|
843
1002
|
var statelessApi = createStatelessBridgeApi();
|
|
844
1003
|
var designStateApi = createDesignStateBridgeApi();
|
|
845
1004
|
var appStateApi = createAppStateBridgeApi();
|
|
846
1005
|
var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
|
|
1006
|
+
var authClient = new SandboxedAuthClient();
|
|
1007
|
+
var aiGeneratorBridge = createAIGeneratorBridgeApi();
|
|
847
1008
|
var handleIncomingMessage = (event) => {
|
|
848
1009
|
const parent = window.parent;
|
|
849
1010
|
if (!parent || parent === window) {
|
|
@@ -866,6 +1027,10 @@
|
|
|
866
1027
|
statelessApi.dispatch(data.type, data.payload);
|
|
867
1028
|
return;
|
|
868
1029
|
}
|
|
1030
|
+
if (isAIGeneratorUpdateMessage(data)) {
|
|
1031
|
+
aiGeneratorBridge.dispatch(data);
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
869
1034
|
if (isAIGenerationUpdatePushMessage(data)) {
|
|
870
1035
|
dispatchAIGenerationUpdate(data.subscriptionId, data.update);
|
|
871
1036
|
return;
|
|
@@ -890,30 +1055,49 @@
|
|
|
890
1055
|
);
|
|
891
1056
|
}
|
|
892
1057
|
};
|
|
1058
|
+
var projectProxy = createApiProxy("project");
|
|
1059
|
+
var projectApi = {
|
|
1060
|
+
design: {
|
|
1061
|
+
state: {
|
|
1062
|
+
getState: projectProxy.design.state.getState,
|
|
1063
|
+
subscribe: designStateApi.subscribe
|
|
1064
|
+
},
|
|
1065
|
+
api: projectProxy.design.api,
|
|
1066
|
+
createBatch: createProjectBatch
|
|
1067
|
+
},
|
|
1068
|
+
app: {
|
|
1069
|
+
state: {
|
|
1070
|
+
getState: projectProxy.app.state.getState,
|
|
1071
|
+
subscribe: appStateApi.subscribe
|
|
1072
|
+
},
|
|
1073
|
+
api: projectProxy.app.api
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
893
1076
|
var bridgeHandlers = {
|
|
1077
|
+
aiGenerator: aiGeneratorBridge.api,
|
|
1078
|
+
brandKit: createApiProxy("brandKit"),
|
|
1079
|
+
mockup: createApiProxy("mockup"),
|
|
894
1080
|
ai: createAIApiProxy(),
|
|
895
1081
|
context: contextApi,
|
|
896
1082
|
data: createApiProxy("data"),
|
|
897
1083
|
design: createApiProxy("design"),
|
|
898
1084
|
designStore: designStateApi,
|
|
899
1085
|
appStore: appStateApi,
|
|
1086
|
+
export: createApiProxy("export"),
|
|
900
1087
|
font: createApiProxy("font"),
|
|
1088
|
+
project: projectApi,
|
|
901
1089
|
state: createApiProxy("state"),
|
|
902
1090
|
upload: createApiProxy("upload"),
|
|
903
|
-
fileBrowser:
|
|
904
|
-
|
|
1091
|
+
fileBrowser: { getFiles: createApiProxy("fileBrowser").getFiles },
|
|
1092
|
+
fileBrowserRegistration: createFileBrowserApiProxy(),
|
|
1093
|
+
openMicroEditor: createApiProxy("openMicroEditor"),
|
|
1094
|
+
openMainEditor: createApiProxy("openMainEditor"),
|
|
1095
|
+
auth: authClient,
|
|
905
1096
|
stateless: statelessApi,
|
|
906
|
-
createBatch
|
|
1097
|
+
createBatch,
|
|
1098
|
+
createProjectBatch
|
|
907
1099
|
};
|
|
908
1100
|
|
|
909
|
-
// src/api/utils.ts
|
|
910
|
-
function unwrapResult(result) {
|
|
911
|
-
if (result.isOk) {
|
|
912
|
-
return result.result;
|
|
913
|
-
}
|
|
914
|
-
throw result.error;
|
|
915
|
-
}
|
|
916
|
-
|
|
917
1101
|
// src/api/dragAndDrop/DragAndDropApi.ts
|
|
918
1102
|
var HIDDEN_DRAG_PREVIEW_OFFSET_PX = "-9999px";
|
|
919
1103
|
var DragAndDropApi = class {
|
|
@@ -946,7 +1130,7 @@
|
|
|
946
1130
|
async dropImage(input) {
|
|
947
1131
|
let objectId = null;
|
|
948
1132
|
try {
|
|
949
|
-
const offset = unwrapResult(await this.context.get()).
|
|
1133
|
+
const offset = unwrapResult(await this.context.get()).iframeOffset;
|
|
950
1134
|
const params = this.buildDropImageParams(input, offset);
|
|
951
1135
|
objectId = await this.addDroppedImage(params);
|
|
952
1136
|
if (input.persistImage) {
|
|
@@ -1175,6 +1359,33 @@
|
|
|
1175
1359
|
}
|
|
1176
1360
|
};
|
|
1177
1361
|
|
|
1362
|
+
// src/createEditorSDKAPIs.ts
|
|
1363
|
+
function createEditorSDKAPIs() {
|
|
1364
|
+
const { project } = bridgeHandlers;
|
|
1365
|
+
const dragAndDrop = new DragAndDropApi({
|
|
1366
|
+
state: project.app.api,
|
|
1367
|
+
context: bridgeHandlers.context,
|
|
1368
|
+
design: project.design.api,
|
|
1369
|
+
upload: bridgeHandlers.upload
|
|
1370
|
+
});
|
|
1371
|
+
return {
|
|
1372
|
+
aiGenerator: bridgeHandlers.aiGenerator,
|
|
1373
|
+
mockup: bridgeHandlers.mockup,
|
|
1374
|
+
project,
|
|
1375
|
+
export: bridgeHandlers.export,
|
|
1376
|
+
helpers: { dragAndDrop },
|
|
1377
|
+
dragAndDrop,
|
|
1378
|
+
auth: bridgeHandlers.auth,
|
|
1379
|
+
upload: bridgeHandlers.upload,
|
|
1380
|
+
stateless: bridgeHandlers.stateless,
|
|
1381
|
+
font: bridgeHandlers.font,
|
|
1382
|
+
fileBrowser: bridgeHandlers.fileBrowser
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
// package.json
|
|
1387
|
+
var version = "1.0.0";
|
|
1388
|
+
|
|
1178
1389
|
// src/utils/syncHtmlDataThemeFromHostContext.ts
|
|
1179
1390
|
async function syncHtmlDataThemeFromHostContext(kittl2) {
|
|
1180
1391
|
if (typeof document === "undefined") {
|
|
@@ -1193,44 +1404,53 @@
|
|
|
1193
1404
|
});
|
|
1194
1405
|
}
|
|
1195
1406
|
|
|
1196
|
-
// src/
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1407
|
+
// src/createKittlSDK.ts
|
|
1408
|
+
function createKittlSDK(apis) {
|
|
1409
|
+
const kittl2 = {
|
|
1410
|
+
onLoadedCallback: null,
|
|
1411
|
+
loaded: false,
|
|
1412
|
+
onReady: (callback) => {
|
|
1413
|
+
if (kittl2.loaded) {
|
|
1414
|
+
callback();
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
kittl2.onLoadedCallback = callback;
|
|
1418
|
+
},
|
|
1419
|
+
...apis
|
|
1420
|
+
};
|
|
1421
|
+
const initSdk = () => {
|
|
1422
|
+
kittl2.loaded = true;
|
|
1423
|
+
window.addEventListener(
|
|
1424
|
+
"message",
|
|
1425
|
+
(event) => {
|
|
1426
|
+
handleIncomingMessage(event);
|
|
1427
|
+
}
|
|
1428
|
+
);
|
|
1429
|
+
const { context } = apis;
|
|
1430
|
+
const themeSynced = context?.get && context.subscribe ? syncHtmlDataThemeFromHostContext({
|
|
1431
|
+
context
|
|
1432
|
+
}) : Promise.resolve();
|
|
1433
|
+
void themeSynced.catch(() => void 0).then(() => {
|
|
1434
|
+
kittl2.onLoadedCallback?.();
|
|
1435
|
+
sendLoaded();
|
|
1436
|
+
});
|
|
1437
|
+
};
|
|
1438
|
+
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
1439
|
+
setSDKVersion(version);
|
|
1440
|
+
window.kittl = kittl2;
|
|
1441
|
+
if (document.readyState === "loading") {
|
|
1442
|
+
document.addEventListener("DOMContentLoaded", initSdk);
|
|
1443
|
+
} else {
|
|
1444
|
+
initSdk();
|
|
1221
1445
|
}
|
|
1222
|
-
);
|
|
1223
|
-
void syncHtmlDataThemeFromHostContext(kittl).then(() => {
|
|
1224
|
-
kittl.onLoadedCallback?.();
|
|
1225
|
-
sendLoaded();
|
|
1226
|
-
});
|
|
1227
|
-
};
|
|
1228
|
-
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
1229
|
-
window.kittl = kittl;
|
|
1230
|
-
if (document.readyState === "loading") {
|
|
1231
|
-
document.addEventListener("DOMContentLoaded", initSdk);
|
|
1232
|
-
} else {
|
|
1233
|
-
initSdk();
|
|
1234
1446
|
}
|
|
1447
|
+
return kittl2;
|
|
1235
1448
|
}
|
|
1449
|
+
|
|
1450
|
+
// src/editorScriptRunner.ts
|
|
1451
|
+
var kittl = createKittlSDK({
|
|
1452
|
+
...createEditorSDKAPIs(),
|
|
1453
|
+
// nothing is contextually relevant to a hidden script runner yet
|
|
1454
|
+
context: {}
|
|
1455
|
+
});
|
|
1236
1456
|
})();
|