@superblocksteam/library 2.0.99 → 2.0.100-next.0
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/jsx-dev-runtime/index.js +1 -1
- package/dist/{jsx-wrapper-esyZ2hyZ.js → jsx-wrapper-BD9Xq9Y2.js} +152 -44
- package/dist/jsx-wrapper-BD9Xq9Y2.js.map +1 -0
- package/dist/lib/index.d.ts +64 -7
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +64 -10
- package/dist/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/jsx-wrapper-esyZ2hyZ.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as root_store_default, t as makeWrappedComponent, x as api_hmr_tracker_default } from "../jsx-wrapper-
|
|
1
|
+
import { _ as root_store_default, t as makeWrappedComponent, x as api_hmr_tracker_default } from "../jsx-wrapper-BD9Xq9Y2.js";
|
|
2
2
|
import { SOURCE_ID_ATTRIBUTE } from "@superblocksteam/library-shared";
|
|
3
3
|
import * as ReactJsxDevRuntime from "react/jsx-dev-runtime";
|
|
4
4
|
|
|
@@ -2081,6 +2081,25 @@ const decodeBytestringsInV2ExecutionResponse = (response) => {
|
|
|
2081
2081
|
|
|
2082
2082
|
//#endregion
|
|
2083
2083
|
//#region src/lib/internal-details/lib/features/file-utils.ts
|
|
2084
|
+
function isNativeFile(value) {
|
|
2085
|
+
return typeof File !== "undefined" && value instanceof File;
|
|
2086
|
+
}
|
|
2087
|
+
function isFileLike(value) {
|
|
2088
|
+
if (isNativeFile(value)) return true;
|
|
2089
|
+
if (typeof value !== "object" || value == null) return false;
|
|
2090
|
+
return typeof value.name === "string" && typeof value.size === "number" && typeof value.type === "string" && typeof value.lastModified === "number" && typeof value.arrayBuffer === "function";
|
|
2091
|
+
}
|
|
2092
|
+
function isPathOnlyFileDescriptor(value) {
|
|
2093
|
+
if (typeof value !== "object" || value == null) return false;
|
|
2094
|
+
return typeof value.path === "string" && typeof value.arrayBuffer !== "function";
|
|
2095
|
+
}
|
|
2096
|
+
function bytesToBase64(bytes) {
|
|
2097
|
+
if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
|
|
2098
|
+
let binary = "";
|
|
2099
|
+
const chunkSize = 32768;
|
|
2100
|
+
for (let i = 0; i < bytes.length; i += chunkSize) binary += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
|
|
2101
|
+
return btoa(binary);
|
|
2102
|
+
}
|
|
2084
2103
|
function getFileUploadId(file) {
|
|
2085
2104
|
return `${file.name.replace(/[^a-zA-Z0-9.-]/g, "_")}-${file.size}-${file.lastModified}`;
|
|
2086
2105
|
}
|
|
@@ -2100,25 +2119,28 @@ function getFileInputData(f) {
|
|
|
2100
2119
|
async function formatFileForRequest(file, fileId) {
|
|
2101
2120
|
return {
|
|
2102
2121
|
originalName: fileId,
|
|
2103
|
-
buffer: await new Promise((resolve, reject) => {
|
|
2122
|
+
buffer: typeof file.arrayBuffer === "function" ? bytesToBase64(new Uint8Array(await file.arrayBuffer())) : await new Promise((resolve, reject) => {
|
|
2104
2123
|
const reader = new FileReader();
|
|
2105
2124
|
reader.onload = () => resolve(reader.result.split(",")[1]);
|
|
2106
2125
|
reader.onerror = () => reject(new Error(reader.error?.message || "Unknown error reading file"));
|
|
2107
2126
|
reader.readAsDataURL(file);
|
|
2108
2127
|
}),
|
|
2109
2128
|
encoding: "base64",
|
|
2110
|
-
|
|
2129
|
+
mimeType: file.type || "application/octet-stream",
|
|
2130
|
+
size: String(file.size)
|
|
2111
2131
|
};
|
|
2112
2132
|
}
|
|
2113
2133
|
async function getInputsWithFileMetadata(inputs) {
|
|
2114
2134
|
const filesForRequest = {};
|
|
2115
2135
|
const processValue = async (value) => {
|
|
2116
2136
|
if (value === void 0) return null;
|
|
2117
|
-
if (value
|
|
2137
|
+
if (isFileLike(value)) {
|
|
2118
2138
|
const inputData = getFileInputData(value);
|
|
2119
2139
|
if (!filesForRequest[inputData.$superblocksId]) filesForRequest[inputData.$superblocksId] = await formatFileForRequest(value, inputData.$superblocksId);
|
|
2120
2140
|
return inputData;
|
|
2121
|
-
}
|
|
2141
|
+
}
|
|
2142
|
+
if (isPathOnlyFileDescriptor(value)) throw new Error("File upload inputs must be browser File objects (or compatible file-like objects with arrayBuffer()). Received a path-only file descriptor instead.");
|
|
2143
|
+
else if (Array.isArray(value)) return await Promise.all(value.map((item) => processValue(item)));
|
|
2122
2144
|
else if (typeof value === "object" && value != null && value.constructor === Object) return await processObject(value);
|
|
2123
2145
|
return value;
|
|
2124
2146
|
};
|
|
@@ -2178,6 +2200,11 @@ var ApiManager = class {
|
|
|
2178
2200
|
* round-trip. Empty for cloud orgs.
|
|
2179
2201
|
*/
|
|
2180
2202
|
_agents = [];
|
|
2203
|
+
/**
|
|
2204
|
+
* DP routing config mapping profile keys to DP URLs, sent by the parent.
|
|
2205
|
+
* Only populated when dataPlaneGatewayEnabled is true.
|
|
2206
|
+
*/
|
|
2207
|
+
_dpRoutingConfig = {};
|
|
2181
2208
|
token;
|
|
2182
2209
|
accessToken;
|
|
2183
2210
|
runningApiControllers = {};
|
|
@@ -2197,6 +2224,9 @@ var ApiManager = class {
|
|
|
2197
2224
|
set agents(agents) {
|
|
2198
2225
|
this._agents = agents;
|
|
2199
2226
|
}
|
|
2227
|
+
set dpRoutingConfig(config) {
|
|
2228
|
+
this._dpRoutingConfig = config;
|
|
2229
|
+
}
|
|
2200
2230
|
setTokens(token, accessToken) {
|
|
2201
2231
|
this.token = token;
|
|
2202
2232
|
this.accessToken = accessToken;
|
|
@@ -2360,7 +2390,14 @@ var ApiManager = class {
|
|
|
2360
2390
|
};
|
|
2361
2391
|
}
|
|
2362
2392
|
const profileKey = context$1.profiles?.selected?.key ?? "staging";
|
|
2363
|
-
const agentBaseUrl =
|
|
2393
|
+
const agentBaseUrl = (() => {
|
|
2394
|
+
if (this.rootStore.dataPlaneGatewayEnabled) {
|
|
2395
|
+
const dpUrl = this._dpRoutingConfig[profileKey];
|
|
2396
|
+
if (dpUrl) return withTrailingSlash(dpUrl);
|
|
2397
|
+
return this._agentUrls[0] ? withTrailingSlash(this._agentUrls[0]) : this.getRandomAgentBaseUrl(profileKey);
|
|
2398
|
+
}
|
|
2399
|
+
return this.getRandomAgentBaseUrl(profileKey);
|
|
2400
|
+
})();
|
|
2364
2401
|
if (!agentBaseUrl) {
|
|
2365
2402
|
sendNotification({
|
|
2366
2403
|
message: "No active agent found",
|
|
@@ -2545,7 +2582,7 @@ var ApiManager = class {
|
|
|
2545
2582
|
* Reads execution context (profile, branch, tokens) from rootStore so the
|
|
2546
2583
|
* caller doesn't need to resolve them through the parent frame.
|
|
2547
2584
|
*/
|
|
2548
|
-
async executeSdkApiV3(apiName, inputs) {
|
|
2585
|
+
async executeSdkApiV3(apiName, inputs, options) {
|
|
2549
2586
|
const applicationId = this.rootStore.applicationId;
|
|
2550
2587
|
if (!applicationId) return {
|
|
2551
2588
|
success: false,
|
|
@@ -2554,43 +2591,77 @@ var ApiManager = class {
|
|
|
2554
2591
|
message: "No application ID found"
|
|
2555
2592
|
}
|
|
2556
2593
|
};
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2594
|
+
const abortController = new AbortController();
|
|
2595
|
+
this.runningApiControllers[apiName]?.abort();
|
|
2596
|
+
this.runningApiControllers[apiName] = abortController;
|
|
2597
|
+
const forwardAbort = () => abortController.abort();
|
|
2598
|
+
if (options?.signal) if (options.signal.aborted) abortController.abort();
|
|
2599
|
+
else options.signal.addEventListener("abort", forwardAbort, { once: true });
|
|
2600
|
+
try {
|
|
2601
|
+
let entryPoint = this.rootStore.getApiEntryPoint(apiName);
|
|
2602
|
+
if (!entryPoint) {
|
|
2603
|
+
await this.rootStore.awaitDiscovery();
|
|
2604
|
+
entryPoint = this.rootStore.getApiEntryPoint(apiName);
|
|
2564
2605
|
}
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2606
|
+
if (!entryPoint) return {
|
|
2607
|
+
success: false,
|
|
2608
|
+
error: {
|
|
2609
|
+
code: "UNKNOWN_API",
|
|
2610
|
+
message: `No entryPoint registered for API "${apiName}". Was it discovered?`
|
|
2611
|
+
}
|
|
2612
|
+
};
|
|
2613
|
+
await this.rootStore.editStore?.operationManager.ensureFilesSynced();
|
|
2614
|
+
const profile = this.rootStore.profile;
|
|
2615
|
+
const branchName = this.rootStore.branchName;
|
|
2616
|
+
const commitId = this.rootStore.commitId;
|
|
2617
|
+
const editMode$1 = isEditMode();
|
|
2618
|
+
const appMode$1 = getAppMode();
|
|
2619
|
+
const viewMode = editMode$1 ? ViewMode.EDITOR : appMode$1 === AppMode.PREVIEW ? ViewMode.PREVIEW : ViewMode.DEPLOYED;
|
|
2620
|
+
const profileKey = profile?.key ?? "default";
|
|
2621
|
+
const agentBaseUrl = (() => {
|
|
2622
|
+
if (this.rootStore.dataPlaneGatewayEnabled) {
|
|
2623
|
+
const dpUrl = this._dpRoutingConfig[profileKey];
|
|
2624
|
+
if (dpUrl) return withTrailingSlash(dpUrl);
|
|
2625
|
+
return this._agentUrls[0] ? withTrailingSlash(this._agentUrls[0]) : this.getRandomAgentBaseUrl(profileKey);
|
|
2626
|
+
}
|
|
2627
|
+
return this.getRandomAgentBaseUrl(profileKey);
|
|
2628
|
+
})();
|
|
2629
|
+
if (!agentBaseUrl) return {
|
|
2630
|
+
success: false,
|
|
2631
|
+
error: {
|
|
2632
|
+
code: "NO_AGENT",
|
|
2633
|
+
message: "Unable to resolve agent for API execution"
|
|
2634
|
+
}
|
|
2635
|
+
};
|
|
2636
|
+
const { inputs: finalInputs, files } = await getInputsWithFileMetadata(inputs);
|
|
2637
|
+
const body = {
|
|
2638
|
+
applicationId,
|
|
2639
|
+
inputs: finalInputs,
|
|
2640
|
+
viewMode,
|
|
2641
|
+
entryPoint
|
|
2642
|
+
};
|
|
2643
|
+
if (files.length > 0) body.files = files;
|
|
2644
|
+
if (profile) body.profile = profile;
|
|
2645
|
+
if (editMode$1) {
|
|
2646
|
+
if (branchName) body.branchName = branchName;
|
|
2647
|
+
body.includeDiagnostics = true;
|
|
2648
|
+
}
|
|
2649
|
+
if (!editMode$1 && commitId) body.commitId = commitId;
|
|
2650
|
+
const integrationIds = (this.rootStore.getApiIntegrations(apiName) ?? []).map((integration) => integration.id);
|
|
2651
|
+
if (integrationIds.length > 0) {
|
|
2652
|
+
const authResult = await new Promise((resolve) => {
|
|
2653
|
+
const callbackId = addNewPromise(resolve);
|
|
2654
|
+
window.parent.postMessage({
|
|
2655
|
+
type: "authenticate-api-request",
|
|
2656
|
+
payload: {
|
|
2657
|
+
apiId: apiName,
|
|
2658
|
+
callbackId,
|
|
2659
|
+
integrationIds
|
|
2660
|
+
}
|
|
2661
|
+
}, "*");
|
|
2662
|
+
});
|
|
2663
|
+
if (authResult?.errors?.length > 0) console.error("SDK API authentication returned with errors", authResult.errors);
|
|
2579
2664
|
}
|
|
2580
|
-
};
|
|
2581
|
-
const body = {
|
|
2582
|
-
applicationId,
|
|
2583
|
-
inputs,
|
|
2584
|
-
viewMode,
|
|
2585
|
-
entryPoint
|
|
2586
|
-
};
|
|
2587
|
-
if (profile) body.profile = profile;
|
|
2588
|
-
if (editMode$1) {
|
|
2589
|
-
if (branchName) body.branchName = branchName;
|
|
2590
|
-
body.includeDiagnostics = true;
|
|
2591
|
-
}
|
|
2592
|
-
if (!editMode$1 && commitId) body.commitId = commitId;
|
|
2593
|
-
try {
|
|
2594
2665
|
const response = await fetch(`${agentBaseUrl}v3/execute`, {
|
|
2595
2666
|
method: "POST",
|
|
2596
2667
|
headers: {
|
|
@@ -2599,7 +2670,8 @@ var ApiManager = class {
|
|
|
2599
2670
|
Authorization: `Bearer ${this.token}`,
|
|
2600
2671
|
[SUPERBLOCKS_REQUEST_ID_HEADER]: generateId()
|
|
2601
2672
|
},
|
|
2602
|
-
body: JSON.stringify(body)
|
|
2673
|
+
body: JSON.stringify(body),
|
|
2674
|
+
signal: abortController.signal
|
|
2603
2675
|
});
|
|
2604
2676
|
if (!response.ok) {
|
|
2605
2677
|
const text = await response.text();
|
|
@@ -2633,6 +2705,14 @@ var ApiManager = class {
|
|
|
2633
2705
|
diagnostics: result.diagnostics
|
|
2634
2706
|
};
|
|
2635
2707
|
} catch (error) {
|
|
2708
|
+
if (error instanceof Error && error.name === "AbortError") return {
|
|
2709
|
+
success: false,
|
|
2710
|
+
error: {
|
|
2711
|
+
code: "ABORTED",
|
|
2712
|
+
message: `API "${apiName}" execution was aborted`
|
|
2713
|
+
}
|
|
2714
|
+
};
|
|
2715
|
+
console.error(`[api-store] executeSdkApiV3 failed for "${apiName}":`, error);
|
|
2636
2716
|
return {
|
|
2637
2717
|
success: false,
|
|
2638
2718
|
error: {
|
|
@@ -2640,6 +2720,9 @@ var ApiManager = class {
|
|
|
2640
2720
|
message: error instanceof Error ? error.message : "Network error occurred"
|
|
2641
2721
|
}
|
|
2642
2722
|
};
|
|
2723
|
+
} finally {
|
|
2724
|
+
options?.signal?.removeEventListener("abort", forwardAbort);
|
|
2725
|
+
if (this.runningApiControllers[apiName] === abortController) delete this.runningApiControllers[apiName];
|
|
2643
2726
|
}
|
|
2644
2727
|
}
|
|
2645
2728
|
@action async cancelApi(apiName, _scopeId) {
|
|
@@ -2650,7 +2733,7 @@ var ApiManager = class {
|
|
|
2650
2733
|
}
|
|
2651
2734
|
abortController.abort();
|
|
2652
2735
|
delete this.runningApiControllers[apiName];
|
|
2653
|
-
editorBridge.setApiResponse(apiName, {
|
|
2736
|
+
if (!(this.rootStore.sdkApiEnabled || !!this.rootStore.getApiEntryPoint(apiName))) editorBridge.setApiResponse(apiName, {
|
|
2654
2737
|
status: "STATUS_CANCELLED",
|
|
2655
2738
|
execution: null,
|
|
2656
2739
|
events: [],
|
|
@@ -3189,6 +3272,12 @@ var RootStore = class {
|
|
|
3189
3272
|
* When false, the YAML-based API system is used instead.
|
|
3190
3273
|
*/
|
|
3191
3274
|
sdkApiEnabled = false;
|
|
3275
|
+
/**
|
|
3276
|
+
* Whether execute requests should be routed through the data plane gateway
|
|
3277
|
+
* endpoint instead of direct agent URLs.
|
|
3278
|
+
* Passed to the library via the ui.data-plane-gateway.enabled bootstrap flag.
|
|
3279
|
+
*/
|
|
3280
|
+
dataPlaneGatewayEnabled = false;
|
|
3192
3281
|
/** Selected integration profile for orchestrator API calls */
|
|
3193
3282
|
profile;
|
|
3194
3283
|
/** Current git branch name for editor-mode API execution */
|
|
@@ -3202,6 +3291,11 @@ var RootStore = class {
|
|
|
3202
3291
|
*/
|
|
3203
3292
|
apiEntryPoints = /* @__PURE__ */ new Map();
|
|
3204
3293
|
/**
|
|
3294
|
+
* Maps API name → statically declared integrations.
|
|
3295
|
+
* Populated during edit-mode discovery and from the deployed build manifest.
|
|
3296
|
+
*/
|
|
3297
|
+
apiIntegrations = /* @__PURE__ */ new Map();
|
|
3298
|
+
/**
|
|
3205
3299
|
* Resolves when the initial SDK API discovery pass completes.
|
|
3206
3300
|
* executeSdkApiV3 awaits this so callers don't race against discovery.
|
|
3207
3301
|
*/
|
|
@@ -3221,6 +3315,8 @@ var RootStore = class {
|
|
|
3221
3315
|
setSdkUser: action,
|
|
3222
3316
|
sdkApiEnabled: observable,
|
|
3223
3317
|
setSdkApiEnabled: action,
|
|
3318
|
+
dataPlaneGatewayEnabled: observable,
|
|
3319
|
+
setDataPlaneGatewayEnabled: action,
|
|
3224
3320
|
profile: observable.ref,
|
|
3225
3321
|
setProfile: action,
|
|
3226
3322
|
branchName: observable,
|
|
@@ -3254,6 +3350,9 @@ var RootStore = class {
|
|
|
3254
3350
|
this.sdkApiEnabled = enabled;
|
|
3255
3351
|
if (enabled && !this._resolveDiscovery) this.initDiscoveryGate();
|
|
3256
3352
|
}
|
|
3353
|
+
setDataPlaneGatewayEnabled(enabled) {
|
|
3354
|
+
this.dataPlaneGatewayEnabled = enabled;
|
|
3355
|
+
}
|
|
3257
3356
|
setProfile(profile) {
|
|
3258
3357
|
this.profile = profile;
|
|
3259
3358
|
}
|
|
@@ -3272,6 +3371,15 @@ var RootStore = class {
|
|
|
3272
3371
|
clearApiEntryPoints() {
|
|
3273
3372
|
this.apiEntryPoints.clear();
|
|
3274
3373
|
}
|
|
3374
|
+
setApiIntegrations(apiName, integrations) {
|
|
3375
|
+
this.apiIntegrations.set(apiName, integrations);
|
|
3376
|
+
}
|
|
3377
|
+
getApiIntegrations(apiName) {
|
|
3378
|
+
return this.apiIntegrations.get(apiName);
|
|
3379
|
+
}
|
|
3380
|
+
clearApiIntegrations() {
|
|
3381
|
+
this.apiIntegrations.clear();
|
|
3382
|
+
}
|
|
3275
3383
|
/**
|
|
3276
3384
|
* Initialise (or re-initialise) the discovery gate. Called when discovery
|
|
3277
3385
|
* starts so that executeSdkApiV3 awaits before checking entry points.
|
|
@@ -3963,4 +4071,4 @@ const useJSXContext = () => {
|
|
|
3963
4071
|
|
|
3964
4072
|
//#endregion
|
|
3965
4073
|
export { useSuperblocksProfiles as A, createManagedPropsList as B, rejectById as C, useSuperblocksContext as D, getAppMode as E, editorBridge as F, getEditStore as G, PropsCategory as H, iframeMessageHandler as I, isEmbeddedBySuperblocksFirstParty as L, generateId as M, sendNotification as N, useSuperblocksDataTags as O, colors as P, sendMessageImmediately as R, addNewPromise as S, SuperblocksContextProvider as T, Section as U, Prop as V, createPropertiesPanelDefinition as W, root_store_default as _, FixWithClarkButton as a, getContextFromTraceHeaders as b, ErrorContent as c, ErrorMessage as d, ErrorStack as f, StyledClarkIcon as g, SecondaryButton as h, getWidgetRectAnchorName as i, useSuperblocksUser as j, useSuperblocksGroups as k, ErrorDetails as l, ErrorTitle as m, useJSXContext as n, ActionsContainer as o, ErrorSummary as p, getWidgetAnchorName as r, ErrorContainer as s, makeWrappedComponent as t, ErrorIconContainer as u, startEditorSync as v, resolveById as w, api_hmr_tracker_default as x, createIframeSpan as y, isEditMode as z };
|
|
3966
|
-
//# sourceMappingURL=jsx-wrapper-
|
|
4074
|
+
//# sourceMappingURL=jsx-wrapper-BD9Xq9Y2.js.map
|