@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
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
/*! Kittl SDK - https://kittl.com - see license for terms */
|
|
3
3
|
|
|
4
4
|
var FROM_EXTENSION_COMMANDS = {
|
|
5
|
+
/** Capability-owned AI callback registration. */
|
|
6
|
+
AI_GENERATOR_SUBSCRIBE: "ai-generator-subscribe",
|
|
7
|
+
/** Capability-owned AI callback teardown. */
|
|
8
|
+
AI_GENERATOR_UNSUBSCRIBE: "ai-generator-unsubscribe",
|
|
5
9
|
/** SDK API call */
|
|
6
10
|
SDK_CALL: "sdk-call",
|
|
7
11
|
/** AI handler registration */
|
|
@@ -50,6 +54,8 @@ var FROM_EXTENSION_COMMANDS = {
|
|
|
50
54
|
LOADED: "loaded"
|
|
51
55
|
};
|
|
52
56
|
var TO_EXTENSION_COMMANDS = {
|
|
57
|
+
/** Callback payload for generator or pending-set subscriptions. */
|
|
58
|
+
AI_GENERATOR_UPDATE: "ai-generator-update",
|
|
53
59
|
/** SDK API response */
|
|
54
60
|
SDK_RESPONSE: "sdk-response",
|
|
55
61
|
/** File browser fetch content request */
|
|
@@ -66,6 +72,10 @@ var TO_EXTENSION_COMMANDS = {
|
|
|
66
72
|
APP_STATE_UPDATE: "app-state-update"
|
|
67
73
|
};
|
|
68
74
|
|
|
75
|
+
function isAIGeneratorUpdateMessage(data) {
|
|
76
|
+
return !!data && typeof data === "object" && "command" in data && data.command === "ai-generator-update" && "subscriptionId" in data && typeof data.subscriptionId === "string";
|
|
77
|
+
}
|
|
78
|
+
|
|
69
79
|
var isSDKResponseMessage = (data) => {
|
|
70
80
|
return typeof data === "object" && data !== null && "command" in data && data.command === TO_EXTENSION_COMMANDS.SDK_RESPONSE && "messageId" in data && typeof data.messageId === "string";
|
|
71
81
|
};
|
|
@@ -135,7 +145,10 @@ var APPROVED_EXTENSION_COMMUNICATION_DOMAINS = [
|
|
|
135
145
|
"https://app.stagingdesigner.com",
|
|
136
146
|
"https://*.stagingdesigner.com",
|
|
137
147
|
"http://localhost:3000",
|
|
138
|
-
"https://app.kittl.com"
|
|
148
|
+
"https://app.kittl.com",
|
|
149
|
+
// website, for sandboxed standalone dashboard pages
|
|
150
|
+
"http://localhost:3003",
|
|
151
|
+
"https://www.kittl.com"
|
|
139
152
|
];
|
|
140
153
|
var toOrigin = (value) => {
|
|
141
154
|
if (!value) {
|
|
@@ -190,8 +203,15 @@ var getParentDomain = () => {
|
|
|
190
203
|
};
|
|
191
204
|
|
|
192
205
|
var pendingRequests = /* @__PURE__ */ new Map();
|
|
206
|
+
var sdkVersion;
|
|
207
|
+
function setSDKVersion(version2) {
|
|
208
|
+
sdkVersion = version2;
|
|
209
|
+
}
|
|
193
210
|
var postMessageToParent = (message) => {
|
|
194
|
-
window.parent.postMessage(
|
|
211
|
+
window.parent.postMessage(
|
|
212
|
+
sdkVersion === void 0 ? message : { ...message, sdkVersion },
|
|
213
|
+
getParentDomain()
|
|
214
|
+
);
|
|
195
215
|
};
|
|
196
216
|
var sendMessage = (message) => {
|
|
197
217
|
postMessageToParent(message);
|
|
@@ -214,6 +234,27 @@ var sendLoaded = () => {
|
|
|
214
234
|
};
|
|
215
235
|
|
|
216
236
|
var createSDKCallMessage = {
|
|
237
|
+
aiGenerator: (dots, args, messageId) => ({
|
|
238
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
239
|
+
dots,
|
|
240
|
+
args,
|
|
241
|
+
messageId,
|
|
242
|
+
apiType: "aiGenerator"
|
|
243
|
+
}),
|
|
244
|
+
mockup: (dots, args, messageId) => ({
|
|
245
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
246
|
+
dots,
|
|
247
|
+
args,
|
|
248
|
+
messageId,
|
|
249
|
+
apiType: "mockup"
|
|
250
|
+
}),
|
|
251
|
+
fileBrowser: (dots, args, messageId) => ({
|
|
252
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
253
|
+
dots,
|
|
254
|
+
args,
|
|
255
|
+
messageId,
|
|
256
|
+
apiType: "fileBrowser"
|
|
257
|
+
}),
|
|
217
258
|
ai: (dots, args, messageId) => ({
|
|
218
259
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
219
260
|
dots,
|
|
@@ -249,6 +290,13 @@ var createSDKCallMessage = {
|
|
|
249
290
|
messageId,
|
|
250
291
|
apiType: "font"
|
|
251
292
|
}),
|
|
293
|
+
project: (dots, args, messageId) => ({
|
|
294
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
295
|
+
dots,
|
|
296
|
+
args,
|
|
297
|
+
messageId,
|
|
298
|
+
apiType: "project"
|
|
299
|
+
}),
|
|
252
300
|
state: (dots, args, messageId) => ({
|
|
253
301
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
254
302
|
dots,
|
|
@@ -269,6 +317,34 @@ var createSDKCallMessage = {
|
|
|
269
317
|
args,
|
|
270
318
|
messageId,
|
|
271
319
|
apiType: "data"
|
|
320
|
+
}),
|
|
321
|
+
brandKit: (dots, args, messageId) => ({
|
|
322
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
323
|
+
dots,
|
|
324
|
+
args,
|
|
325
|
+
messageId,
|
|
326
|
+
apiType: "brandKit"
|
|
327
|
+
}),
|
|
328
|
+
openMicroEditor: (dots, args, messageId) => ({
|
|
329
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
330
|
+
dots,
|
|
331
|
+
args,
|
|
332
|
+
messageId,
|
|
333
|
+
apiType: "openMicroEditor"
|
|
334
|
+
}),
|
|
335
|
+
openMainEditor: (dots, args, messageId) => ({
|
|
336
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
337
|
+
dots,
|
|
338
|
+
args,
|
|
339
|
+
messageId,
|
|
340
|
+
apiType: "openMainEditor"
|
|
341
|
+
}),
|
|
342
|
+
agent: (dots, args, messageId) => ({
|
|
343
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
344
|
+
dots,
|
|
345
|
+
args,
|
|
346
|
+
messageId,
|
|
347
|
+
apiType: "agent"
|
|
272
348
|
})
|
|
273
349
|
};
|
|
274
350
|
function createApiProxy(apiType) {
|
|
@@ -285,6 +361,64 @@ function createApiProxy(apiType) {
|
|
|
285
361
|
});
|
|
286
362
|
}
|
|
287
363
|
|
|
364
|
+
function createAIGeneratorBridgeApi() {
|
|
365
|
+
const callbacks = /* @__PURE__ */ new Map();
|
|
366
|
+
const proxy = createApiProxy("aiGenerator");
|
|
367
|
+
async function subscribe(request, callback) {
|
|
368
|
+
const subscriptionId = generateMessageId();
|
|
369
|
+
callbacks.set(subscriptionId, callback);
|
|
370
|
+
let response;
|
|
371
|
+
try {
|
|
372
|
+
response = await sendMessage({
|
|
373
|
+
command: "ai-generator-subscribe",
|
|
374
|
+
...request,
|
|
375
|
+
subscriptionId,
|
|
376
|
+
messageId: generateMessageId()
|
|
377
|
+
});
|
|
378
|
+
} catch (error) {
|
|
379
|
+
callbacks.delete(subscriptionId);
|
|
380
|
+
throw error;
|
|
381
|
+
}
|
|
382
|
+
if (!response.isOk) {
|
|
383
|
+
callbacks.delete(subscriptionId);
|
|
384
|
+
throw new Error(response.error.message);
|
|
385
|
+
}
|
|
386
|
+
return () => {
|
|
387
|
+
callbacks.delete(subscriptionId);
|
|
388
|
+
postMessageToParent({
|
|
389
|
+
command: "ai-generator-unsubscribe",
|
|
390
|
+
subscriptionId
|
|
391
|
+
});
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
const methods = {
|
|
395
|
+
registerGenerator: (id, callback) => subscribe({ method: "registerGenerator", args: [id] }, (update) => {
|
|
396
|
+
if (update) callback(update);
|
|
397
|
+
}),
|
|
398
|
+
subscribeToGenerationUpdates: (ids, callback) => subscribe(
|
|
399
|
+
{ method: "subscribeToGenerationUpdates", args: [ids] },
|
|
400
|
+
(update) => {
|
|
401
|
+
if (update) callback(update);
|
|
402
|
+
}
|
|
403
|
+
),
|
|
404
|
+
subscribeToPendingGenerations: (callback) => subscribe(
|
|
405
|
+
{ method: "subscribeToPendingGenerations", args: [] },
|
|
406
|
+
() => callback()
|
|
407
|
+
),
|
|
408
|
+
/** Callers may reuse richer internal submission objects; never send their local abort callbacks. */
|
|
409
|
+
cancelGenerations: (submission) => proxy.cancelGenerations({
|
|
410
|
+
generationIds: submission.generationIds,
|
|
411
|
+
until: submission.until
|
|
412
|
+
})
|
|
413
|
+
};
|
|
414
|
+
return {
|
|
415
|
+
api: new Proxy(proxy, {
|
|
416
|
+
get: (target, property, receiver) => property in methods ? methods[property] : Reflect.get(target, property, receiver)
|
|
417
|
+
}),
|
|
418
|
+
dispatch: (message) => callbacks.get(message.subscriptionId)?.(message.update)
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
288
422
|
var generationHandlers = /* @__PURE__ */ new Map();
|
|
289
423
|
var generationSubscriptions = /* @__PURE__ */ new Map();
|
|
290
424
|
var dispatchAIGenerationUpdate = (subscriptionId, update) => {
|
|
@@ -652,7 +786,7 @@ var SandboxedAuthClient = class {
|
|
|
652
786
|
}
|
|
653
787
|
};
|
|
654
788
|
|
|
655
|
-
var
|
|
789
|
+
var createBatchFor = async (apiType) => {
|
|
656
790
|
const response = await sendMessage({
|
|
657
791
|
command: FROM_EXTENSION_COMMANDS.BATCH_CREATE,
|
|
658
792
|
messageId: generateMessageId()
|
|
@@ -661,14 +795,17 @@ var createBatch = async () => {
|
|
|
661
795
|
throw response.error;
|
|
662
796
|
}
|
|
663
797
|
const { batchKey } = response.result;
|
|
664
|
-
const sendDesignCall = (dots, args) =>
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
798
|
+
const sendDesignCall = (dots, args) => {
|
|
799
|
+
const message = {
|
|
800
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
801
|
+
dots: apiType === "project" ? ["design", "api", ...dots] : dots,
|
|
802
|
+
args,
|
|
803
|
+
messageId: generateMessageId(),
|
|
804
|
+
apiType,
|
|
805
|
+
batchKey
|
|
806
|
+
};
|
|
807
|
+
return sendMessage(message);
|
|
808
|
+
};
|
|
672
809
|
const commit = async () => {
|
|
673
810
|
const res = await sendMessage({
|
|
674
811
|
command: FROM_EXTENSION_COMMANDS.BATCH_COMMIT,
|
|
@@ -695,6 +832,8 @@ var createBatch = async () => {
|
|
|
695
832
|
};
|
|
696
833
|
return buildNode([]);
|
|
697
834
|
};
|
|
835
|
+
var createBatch = () => createBatchFor("design");
|
|
836
|
+
var createProjectBatch = () => createBatchFor("project");
|
|
698
837
|
|
|
699
838
|
var createContextBridgeApi = () => {
|
|
700
839
|
const contextProxy = createApiProxy("context");
|
|
@@ -862,6 +1001,7 @@ var designStateApi = createDesignStateBridgeApi();
|
|
|
862
1001
|
var appStateApi = createAppStateBridgeApi();
|
|
863
1002
|
var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
|
|
864
1003
|
var authClient = new SandboxedAuthClient();
|
|
1004
|
+
var aiGeneratorBridge = createAIGeneratorBridgeApi();
|
|
865
1005
|
var handleIncomingMessage = (event) => {
|
|
866
1006
|
const parent = window.parent;
|
|
867
1007
|
if (!parent || parent === window) {
|
|
@@ -884,6 +1024,10 @@ var handleIncomingMessage = (event) => {
|
|
|
884
1024
|
statelessApi.dispatch(data.type, data.payload);
|
|
885
1025
|
return;
|
|
886
1026
|
}
|
|
1027
|
+
if (isAIGeneratorUpdateMessage(data)) {
|
|
1028
|
+
aiGeneratorBridge.dispatch(data);
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
887
1031
|
if (isAIGenerationUpdatePushMessage(data)) {
|
|
888
1032
|
dispatchAIGenerationUpdate(data.subscriptionId, data.update);
|
|
889
1033
|
return;
|
|
@@ -908,7 +1052,29 @@ var handleIncomingMessage = (event) => {
|
|
|
908
1052
|
);
|
|
909
1053
|
}
|
|
910
1054
|
};
|
|
1055
|
+
var projectProxy = createApiProxy("project");
|
|
1056
|
+
var projectApi = {
|
|
1057
|
+
design: {
|
|
1058
|
+
state: {
|
|
1059
|
+
getState: projectProxy.design.state.getState,
|
|
1060
|
+
subscribe: designStateApi.subscribe
|
|
1061
|
+
},
|
|
1062
|
+
api: projectProxy.design.api,
|
|
1063
|
+
createBatch: createProjectBatch
|
|
1064
|
+
},
|
|
1065
|
+
app: {
|
|
1066
|
+
state: {
|
|
1067
|
+
getState: projectProxy.app.state.getState,
|
|
1068
|
+
subscribe: appStateApi.subscribe
|
|
1069
|
+
},
|
|
1070
|
+
api: projectProxy.app.api
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
911
1073
|
var bridgeHandlers = {
|
|
1074
|
+
agent: createApiProxy("agent"),
|
|
1075
|
+
aiGenerator: aiGeneratorBridge.api,
|
|
1076
|
+
brandKit: createApiProxy("brandKit"),
|
|
1077
|
+
mockup: createApiProxy("mockup"),
|
|
912
1078
|
ai: createAIApiProxy(),
|
|
913
1079
|
context: contextApi,
|
|
914
1080
|
data: createApiProxy("data"),
|
|
@@ -917,12 +1083,17 @@ var bridgeHandlers = {
|
|
|
917
1083
|
appStore: appStateApi,
|
|
918
1084
|
export: createApiProxy("export"),
|
|
919
1085
|
font: createApiProxy("font"),
|
|
1086
|
+
project: projectApi,
|
|
920
1087
|
state: createApiProxy("state"),
|
|
921
1088
|
upload: createApiProxy("upload"),
|
|
922
|
-
fileBrowser:
|
|
1089
|
+
fileBrowser: { getFiles: createApiProxy("fileBrowser").getFiles },
|
|
1090
|
+
fileBrowserRegistration: createFileBrowserApiProxy(),
|
|
1091
|
+
openMicroEditor: createApiProxy("openMicroEditor"),
|
|
1092
|
+
openMainEditor: createApiProxy("openMainEditor"),
|
|
923
1093
|
auth: authClient,
|
|
924
1094
|
stateless: statelessApi,
|
|
925
|
-
createBatch
|
|
1095
|
+
createBatch,
|
|
1096
|
+
createProjectBatch
|
|
926
1097
|
};
|
|
927
1098
|
|
|
928
1099
|
// src/api/utils.ts
|
|
@@ -965,7 +1136,7 @@ var DragAndDropApi = class {
|
|
|
965
1136
|
async dropImage(input) {
|
|
966
1137
|
let objectId = null;
|
|
967
1138
|
try {
|
|
968
|
-
const offset = unwrapResult(await this.context.get()).
|
|
1139
|
+
const offset = unwrapResult(await this.context.get()).iframeOffset;
|
|
969
1140
|
const params = this.buildDropImageParams(input, offset);
|
|
970
1141
|
objectId = await this.addDroppedImage(params);
|
|
971
1142
|
if (input.persistImage) {
|
|
@@ -1196,29 +1367,31 @@ var DragAndDropApi = class {
|
|
|
1196
1367
|
|
|
1197
1368
|
// src/createEditorSDKAPIs.ts
|
|
1198
1369
|
function createEditorSDKAPIs() {
|
|
1370
|
+
const { project } = bridgeHandlers;
|
|
1371
|
+
const dragAndDrop = new DragAndDropApi({
|
|
1372
|
+
state: project.app.api,
|
|
1373
|
+
context: bridgeHandlers.context,
|
|
1374
|
+
design: project.design.api,
|
|
1375
|
+
upload: bridgeHandlers.upload
|
|
1376
|
+
});
|
|
1199
1377
|
return {
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1378
|
+
aiGenerator: bridgeHandlers.aiGenerator,
|
|
1379
|
+
mockup: bridgeHandlers.mockup,
|
|
1380
|
+
project,
|
|
1203
1381
|
export: bridgeHandlers.export,
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
context: bridgeHandlers.context,
|
|
1207
|
-
dragAndDrop: new DragAndDropApi({
|
|
1208
|
-
state: bridgeHandlers.state,
|
|
1209
|
-
context: bridgeHandlers.context,
|
|
1210
|
-
design: bridgeHandlers.design,
|
|
1211
|
-
upload: bridgeHandlers.upload
|
|
1212
|
-
}),
|
|
1213
|
-
state: bridgeHandlers.state,
|
|
1382
|
+
helpers: { dragAndDrop },
|
|
1383
|
+
dragAndDrop,
|
|
1214
1384
|
auth: bridgeHandlers.auth,
|
|
1215
1385
|
upload: bridgeHandlers.upload,
|
|
1216
1386
|
stateless: bridgeHandlers.stateless,
|
|
1217
1387
|
font: bridgeHandlers.font,
|
|
1218
|
-
|
|
1388
|
+
fileBrowser: bridgeHandlers.fileBrowser
|
|
1219
1389
|
};
|
|
1220
1390
|
}
|
|
1221
1391
|
|
|
1392
|
+
// package.json
|
|
1393
|
+
var version = "1.0.0";
|
|
1394
|
+
|
|
1222
1395
|
// src/utils/syncHtmlDataThemeFromHostContext.ts
|
|
1223
1396
|
async function syncHtmlDataThemeFromHostContext(kittl2) {
|
|
1224
1397
|
if (typeof document === "undefined") {
|
|
@@ -1259,12 +1432,17 @@ function createKittlSDK(apis) {
|
|
|
1259
1432
|
handleIncomingMessage(event);
|
|
1260
1433
|
}
|
|
1261
1434
|
);
|
|
1262
|
-
|
|
1435
|
+
const { context } = apis;
|
|
1436
|
+
const themeSynced = context?.get && context.subscribe ? syncHtmlDataThemeFromHostContext({
|
|
1437
|
+
context
|
|
1438
|
+
}) : Promise.resolve();
|
|
1439
|
+
void themeSynced.catch(() => void 0).then(() => {
|
|
1263
1440
|
kittl2.onLoadedCallback?.();
|
|
1264
1441
|
sendLoaded();
|
|
1265
1442
|
});
|
|
1266
1443
|
};
|
|
1267
1444
|
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
1445
|
+
setSDKVersion(version);
|
|
1268
1446
|
window.kittl = kittl2;
|
|
1269
1447
|
if (document.readyState === "loading") {
|
|
1270
1448
|
document.addEventListener("DOMContentLoaded", initSdk);
|
|
@@ -1278,7 +1456,13 @@ function createKittlSDK(apis) {
|
|
|
1278
1456
|
// src/editorContentPanel.ts
|
|
1279
1457
|
var kittl = createKittlSDK({
|
|
1280
1458
|
...createEditorSDKAPIs(),
|
|
1281
|
-
|
|
1459
|
+
context: bridgeHandlers.context,
|
|
1460
|
+
brandKit: bridgeHandlers.brandKit,
|
|
1461
|
+
fileBrowser: {
|
|
1462
|
+
getFiles: bridgeHandlers.fileBrowser.getFiles,
|
|
1463
|
+
// Keep existing content-panel extensions working while registration moves to sharedFileBrowser context.
|
|
1464
|
+
registerUploadBrowser: bridgeHandlers.fileBrowserRegistration.registerUploadBrowser
|
|
1465
|
+
}
|
|
1282
1466
|
});
|
|
1283
1467
|
export {
|
|
1284
1468
|
kittl,
|