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