@kittl/sdk 0.0.9 → 1.0.0-alpha.2
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/creativeAgentPanel/sdk.d.ts +8667 -0
- package/dist/{kittl-sdk.esm.js → creativeAgentPanel/sdk.esm.js} +199 -301
- package/dist/{kittl-sdk.js → creativeAgentPanel/sdk.js} +199 -301
- package/dist/dashboardStandalonePage/sdk.d.ts +8656 -0
- package/dist/dashboardStandalonePage/sdk.esm.js +1184 -0
- package/dist/dashboardStandalonePage/sdk.js +1184 -0
- package/dist/editorContentPanel/sdk.d.ts +6318 -103
- package/dist/editorContentPanel/sdk.esm.js +214 -30
- package/dist/editorContentPanel/sdk.js +214 -30
- package/dist/editorScriptRunner/sdk.d.ts +5732 -146
- package/dist/editorScriptRunner/sdk.esm.js +212 -30
- package/dist/editorScriptRunner/sdk.js +212 -30
- package/dist/sharedFileBrowser/sdk.d.ts +188 -2609
- package/dist/sharedFileBrowser/sdk.esm.js +200 -16
- package/dist/sharedFileBrowser/sdk.js +200 -16
- package/package.json +14 -7
- package/dist/sdk.d.ts +0 -2756
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
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",
|
|
15
19
|
/** SDK API call */
|
|
16
20
|
SDK_CALL: "sdk-call",
|
|
17
21
|
/** AI handler registration */
|
|
@@ -60,6 +64,8 @@
|
|
|
60
64
|
LOADED: "loaded"
|
|
61
65
|
};
|
|
62
66
|
var TO_EXTENSION_COMMANDS = {
|
|
67
|
+
/** Callback payload for generator or pending-set subscriptions. */
|
|
68
|
+
AI_GENERATOR_UPDATE: "ai-generator-update",
|
|
63
69
|
/** SDK API response */
|
|
64
70
|
SDK_RESPONSE: "sdk-response",
|
|
65
71
|
/** File browser fetch content request */
|
|
@@ -76,6 +82,10 @@
|
|
|
76
82
|
APP_STATE_UPDATE: "app-state-update"
|
|
77
83
|
};
|
|
78
84
|
|
|
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
|
+
|
|
79
89
|
var isSDKResponseMessage = (data) => {
|
|
80
90
|
return typeof data === "object" && data !== null && "command" in data && data.command === TO_EXTENSION_COMMANDS.SDK_RESPONSE && "messageId" in data && typeof data.messageId === "string";
|
|
81
91
|
};
|
|
@@ -145,7 +155,10 @@
|
|
|
145
155
|
"https://app.stagingdesigner.com",
|
|
146
156
|
"https://*.stagingdesigner.com",
|
|
147
157
|
"http://localhost:3000",
|
|
148
|
-
"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"
|
|
149
162
|
];
|
|
150
163
|
var toOrigin = (value) => {
|
|
151
164
|
if (!value) {
|
|
@@ -200,8 +213,15 @@
|
|
|
200
213
|
};
|
|
201
214
|
|
|
202
215
|
var pendingRequests = /* @__PURE__ */ new Map();
|
|
216
|
+
var sdkVersion;
|
|
217
|
+
function setSDKVersion(version2) {
|
|
218
|
+
sdkVersion = version2;
|
|
219
|
+
}
|
|
203
220
|
var postMessageToParent = (message) => {
|
|
204
|
-
window.parent.postMessage(
|
|
221
|
+
window.parent.postMessage(
|
|
222
|
+
sdkVersion === void 0 ? message : { ...message, sdkVersion },
|
|
223
|
+
getParentDomain()
|
|
224
|
+
);
|
|
205
225
|
};
|
|
206
226
|
var sendMessage = (message) => {
|
|
207
227
|
postMessageToParent(message);
|
|
@@ -224,6 +244,27 @@
|
|
|
224
244
|
};
|
|
225
245
|
|
|
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,
|
|
@@ -259,6 +300,13 @@
|
|
|
259
300
|
messageId,
|
|
260
301
|
apiType: "font"
|
|
261
302
|
}),
|
|
303
|
+
project: (dots, args, messageId) => ({
|
|
304
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
305
|
+
dots,
|
|
306
|
+
args,
|
|
307
|
+
messageId,
|
|
308
|
+
apiType: "project"
|
|
309
|
+
}),
|
|
262
310
|
state: (dots, args, messageId) => ({
|
|
263
311
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
264
312
|
dots,
|
|
@@ -279,6 +327,34 @@
|
|
|
279
327
|
args,
|
|
280
328
|
messageId,
|
|
281
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"
|
|
351
|
+
}),
|
|
352
|
+
agent: (dots, args, messageId) => ({
|
|
353
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
354
|
+
dots,
|
|
355
|
+
args,
|
|
356
|
+
messageId,
|
|
357
|
+
apiType: "agent"
|
|
282
358
|
})
|
|
283
359
|
};
|
|
284
360
|
function createApiProxy(apiType) {
|
|
@@ -295,6 +371,64 @@
|
|
|
295
371
|
});
|
|
296
372
|
}
|
|
297
373
|
|
|
374
|
+
function createAIGeneratorBridgeApi() {
|
|
375
|
+
const callbacks = /* @__PURE__ */ new Map();
|
|
376
|
+
const proxy = createApiProxy("aiGenerator");
|
|
377
|
+
async function subscribe(request, callback) {
|
|
378
|
+
const subscriptionId = generateMessageId();
|
|
379
|
+
callbacks.set(subscriptionId, callback);
|
|
380
|
+
let response;
|
|
381
|
+
try {
|
|
382
|
+
response = await sendMessage({
|
|
383
|
+
command: "ai-generator-subscribe",
|
|
384
|
+
...request,
|
|
385
|
+
subscriptionId,
|
|
386
|
+
messageId: generateMessageId()
|
|
387
|
+
});
|
|
388
|
+
} catch (error) {
|
|
389
|
+
callbacks.delete(subscriptionId);
|
|
390
|
+
throw error;
|
|
391
|
+
}
|
|
392
|
+
if (!response.isOk) {
|
|
393
|
+
callbacks.delete(subscriptionId);
|
|
394
|
+
throw new Error(response.error.message);
|
|
395
|
+
}
|
|
396
|
+
return () => {
|
|
397
|
+
callbacks.delete(subscriptionId);
|
|
398
|
+
postMessageToParent({
|
|
399
|
+
command: "ai-generator-unsubscribe",
|
|
400
|
+
subscriptionId
|
|
401
|
+
});
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
const methods = {
|
|
405
|
+
registerGenerator: (id, callback) => subscribe({ method: "registerGenerator", args: [id] }, (update) => {
|
|
406
|
+
if (update) callback(update);
|
|
407
|
+
}),
|
|
408
|
+
subscribeToGenerationUpdates: (ids, callback) => subscribe(
|
|
409
|
+
{ method: "subscribeToGenerationUpdates", args: [ids] },
|
|
410
|
+
(update) => {
|
|
411
|
+
if (update) callback(update);
|
|
412
|
+
}
|
|
413
|
+
),
|
|
414
|
+
subscribeToPendingGenerations: (callback) => subscribe(
|
|
415
|
+
{ method: "subscribeToPendingGenerations", args: [] },
|
|
416
|
+
() => callback()
|
|
417
|
+
),
|
|
418
|
+
/** Callers may reuse richer internal submission objects; never send their local abort callbacks. */
|
|
419
|
+
cancelGenerations: (submission) => proxy.cancelGenerations({
|
|
420
|
+
generationIds: submission.generationIds,
|
|
421
|
+
until: submission.until
|
|
422
|
+
})
|
|
423
|
+
};
|
|
424
|
+
return {
|
|
425
|
+
api: new Proxy(proxy, {
|
|
426
|
+
get: (target, property, receiver) => property in methods ? methods[property] : Reflect.get(target, property, receiver)
|
|
427
|
+
}),
|
|
428
|
+
dispatch: (message) => callbacks.get(message.subscriptionId)?.(message.update)
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
|
|
298
432
|
var generationHandlers = /* @__PURE__ */ new Map();
|
|
299
433
|
var generationSubscriptions = /* @__PURE__ */ new Map();
|
|
300
434
|
var dispatchAIGenerationUpdate = (subscriptionId, update) => {
|
|
@@ -662,7 +796,7 @@
|
|
|
662
796
|
}
|
|
663
797
|
};
|
|
664
798
|
|
|
665
|
-
var
|
|
799
|
+
var createBatchFor = async (apiType) => {
|
|
666
800
|
const response = await sendMessage({
|
|
667
801
|
command: FROM_EXTENSION_COMMANDS.BATCH_CREATE,
|
|
668
802
|
messageId: generateMessageId()
|
|
@@ -671,14 +805,17 @@
|
|
|
671
805
|
throw response.error;
|
|
672
806
|
}
|
|
673
807
|
const { batchKey } = response.result;
|
|
674
|
-
const sendDesignCall = (dots, args) =>
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
808
|
+
const sendDesignCall = (dots, args) => {
|
|
809
|
+
const message = {
|
|
810
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
811
|
+
dots: apiType === "project" ? ["design", "api", ...dots] : dots,
|
|
812
|
+
args,
|
|
813
|
+
messageId: generateMessageId(),
|
|
814
|
+
apiType,
|
|
815
|
+
batchKey
|
|
816
|
+
};
|
|
817
|
+
return sendMessage(message);
|
|
818
|
+
};
|
|
682
819
|
const commit = async () => {
|
|
683
820
|
const res = await sendMessage({
|
|
684
821
|
command: FROM_EXTENSION_COMMANDS.BATCH_COMMIT,
|
|
@@ -705,6 +842,8 @@
|
|
|
705
842
|
};
|
|
706
843
|
return buildNode([]);
|
|
707
844
|
};
|
|
845
|
+
var createBatch = () => createBatchFor("design");
|
|
846
|
+
var createProjectBatch = () => createBatchFor("project");
|
|
708
847
|
|
|
709
848
|
var createContextBridgeApi = () => {
|
|
710
849
|
const contextProxy = createApiProxy("context");
|
|
@@ -872,6 +1011,7 @@
|
|
|
872
1011
|
var appStateApi = createAppStateBridgeApi();
|
|
873
1012
|
var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
|
|
874
1013
|
var authClient = new SandboxedAuthClient();
|
|
1014
|
+
var aiGeneratorBridge = createAIGeneratorBridgeApi();
|
|
875
1015
|
var handleIncomingMessage = (event) => {
|
|
876
1016
|
const parent = window.parent;
|
|
877
1017
|
if (!parent || parent === window) {
|
|
@@ -894,6 +1034,10 @@
|
|
|
894
1034
|
statelessApi.dispatch(data.type, data.payload);
|
|
895
1035
|
return;
|
|
896
1036
|
}
|
|
1037
|
+
if (isAIGeneratorUpdateMessage(data)) {
|
|
1038
|
+
aiGeneratorBridge.dispatch(data);
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
897
1041
|
if (isAIGenerationUpdatePushMessage(data)) {
|
|
898
1042
|
dispatchAIGenerationUpdate(data.subscriptionId, data.update);
|
|
899
1043
|
return;
|
|
@@ -918,7 +1062,29 @@
|
|
|
918
1062
|
);
|
|
919
1063
|
}
|
|
920
1064
|
};
|
|
1065
|
+
var projectProxy = createApiProxy("project");
|
|
1066
|
+
var projectApi = {
|
|
1067
|
+
design: {
|
|
1068
|
+
state: {
|
|
1069
|
+
getState: projectProxy.design.state.getState,
|
|
1070
|
+
subscribe: designStateApi.subscribe
|
|
1071
|
+
},
|
|
1072
|
+
api: projectProxy.design.api,
|
|
1073
|
+
createBatch: createProjectBatch
|
|
1074
|
+
},
|
|
1075
|
+
app: {
|
|
1076
|
+
state: {
|
|
1077
|
+
getState: projectProxy.app.state.getState,
|
|
1078
|
+
subscribe: appStateApi.subscribe
|
|
1079
|
+
},
|
|
1080
|
+
api: projectProxy.app.api
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
921
1083
|
var bridgeHandlers = {
|
|
1084
|
+
agent: createApiProxy("agent"),
|
|
1085
|
+
aiGenerator: aiGeneratorBridge.api,
|
|
1086
|
+
brandKit: createApiProxy("brandKit"),
|
|
1087
|
+
mockup: createApiProxy("mockup"),
|
|
922
1088
|
ai: createAIApiProxy(),
|
|
923
1089
|
context: contextApi,
|
|
924
1090
|
data: createApiProxy("data"),
|
|
@@ -927,12 +1093,17 @@
|
|
|
927
1093
|
appStore: appStateApi,
|
|
928
1094
|
export: createApiProxy("export"),
|
|
929
1095
|
font: createApiProxy("font"),
|
|
1096
|
+
project: projectApi,
|
|
930
1097
|
state: createApiProxy("state"),
|
|
931
1098
|
upload: createApiProxy("upload"),
|
|
932
|
-
fileBrowser:
|
|
1099
|
+
fileBrowser: { getFiles: createApiProxy("fileBrowser").getFiles },
|
|
1100
|
+
fileBrowserRegistration: createFileBrowserApiProxy(),
|
|
1101
|
+
openMicroEditor: createApiProxy("openMicroEditor"),
|
|
1102
|
+
openMainEditor: createApiProxy("openMainEditor"),
|
|
933
1103
|
auth: authClient,
|
|
934
1104
|
stateless: statelessApi,
|
|
935
|
-
createBatch
|
|
1105
|
+
createBatch,
|
|
1106
|
+
createProjectBatch
|
|
936
1107
|
};
|
|
937
1108
|
|
|
938
1109
|
// src/api/dragAndDrop/DragAndDropApi.ts
|
|
@@ -967,7 +1138,7 @@
|
|
|
967
1138
|
async dropImage(input) {
|
|
968
1139
|
let objectId = null;
|
|
969
1140
|
try {
|
|
970
|
-
const offset = unwrapResult(await this.context.get()).
|
|
1141
|
+
const offset = unwrapResult(await this.context.get()).iframeOffset;
|
|
971
1142
|
const params = this.buildDropImageParams(input, offset);
|
|
972
1143
|
objectId = await this.addDroppedImage(params);
|
|
973
1144
|
if (input.persistImage) {
|
|
@@ -1198,29 +1369,31 @@
|
|
|
1198
1369
|
|
|
1199
1370
|
// src/createEditorSDKAPIs.ts
|
|
1200
1371
|
function createEditorSDKAPIs() {
|
|
1372
|
+
const { project } = bridgeHandlers;
|
|
1373
|
+
const dragAndDrop = new DragAndDropApi({
|
|
1374
|
+
state: project.app.api,
|
|
1375
|
+
context: bridgeHandlers.context,
|
|
1376
|
+
design: project.design.api,
|
|
1377
|
+
upload: bridgeHandlers.upload
|
|
1378
|
+
});
|
|
1201
1379
|
return {
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1380
|
+
aiGenerator: bridgeHandlers.aiGenerator,
|
|
1381
|
+
mockup: bridgeHandlers.mockup,
|
|
1382
|
+
project,
|
|
1205
1383
|
export: bridgeHandlers.export,
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
context: bridgeHandlers.context,
|
|
1209
|
-
dragAndDrop: new DragAndDropApi({
|
|
1210
|
-
state: bridgeHandlers.state,
|
|
1211
|
-
context: bridgeHandlers.context,
|
|
1212
|
-
design: bridgeHandlers.design,
|
|
1213
|
-
upload: bridgeHandlers.upload
|
|
1214
|
-
}),
|
|
1215
|
-
state: bridgeHandlers.state,
|
|
1384
|
+
helpers: { dragAndDrop },
|
|
1385
|
+
dragAndDrop,
|
|
1216
1386
|
auth: bridgeHandlers.auth,
|
|
1217
1387
|
upload: bridgeHandlers.upload,
|
|
1218
1388
|
stateless: bridgeHandlers.stateless,
|
|
1219
1389
|
font: bridgeHandlers.font,
|
|
1220
|
-
|
|
1390
|
+
fileBrowser: bridgeHandlers.fileBrowser
|
|
1221
1391
|
};
|
|
1222
1392
|
}
|
|
1223
1393
|
|
|
1394
|
+
// package.json
|
|
1395
|
+
var version = "1.0.0";
|
|
1396
|
+
|
|
1224
1397
|
// src/utils/syncHtmlDataThemeFromHostContext.ts
|
|
1225
1398
|
async function syncHtmlDataThemeFromHostContext(kittl2) {
|
|
1226
1399
|
if (typeof document === "undefined") {
|
|
@@ -1261,12 +1434,17 @@
|
|
|
1261
1434
|
handleIncomingMessage(event);
|
|
1262
1435
|
}
|
|
1263
1436
|
);
|
|
1264
|
-
|
|
1437
|
+
const { context } = apis;
|
|
1438
|
+
const themeSynced = context?.get && context.subscribe ? syncHtmlDataThemeFromHostContext({
|
|
1439
|
+
context
|
|
1440
|
+
}) : Promise.resolve();
|
|
1441
|
+
void themeSynced.catch(() => void 0).then(() => {
|
|
1265
1442
|
kittl2.onLoadedCallback?.();
|
|
1266
1443
|
sendLoaded();
|
|
1267
1444
|
});
|
|
1268
1445
|
};
|
|
1269
1446
|
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
1447
|
+
setSDKVersion(version);
|
|
1270
1448
|
window.kittl = kittl2;
|
|
1271
1449
|
if (document.readyState === "loading") {
|
|
1272
1450
|
document.addEventListener("DOMContentLoaded", initSdk);
|
|
@@ -1278,5 +1456,9 @@
|
|
|
1278
1456
|
}
|
|
1279
1457
|
|
|
1280
1458
|
// src/editorScriptRunner.ts
|
|
1281
|
-
var kittl = createKittlSDK(
|
|
1459
|
+
var kittl = createKittlSDK({
|
|
1460
|
+
...createEditorSDKAPIs(),
|
|
1461
|
+
// nothing is contextually relevant to a hidden script runner yet
|
|
1462
|
+
context: {}
|
|
1463
|
+
});
|
|
1282
1464
|
})();
|