@oxy-hq/sdk 2.11.0 → 2.13.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/README.md +44 -4
- package/dist/function-context-D8eyZuw_.d.cts +720 -0
- package/dist/function-context-D8eyZuw_.d.cts.map +1 -0
- package/dist/function-context-D8eyZuw_.d.mts +720 -0
- package/dist/function-context-D8eyZuw_.d.mts.map +1 -0
- package/dist/index.cjs +217 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +499 -638
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +499 -638
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +215 -12
- package/dist/index.mjs.map +1 -1
- package/dist/ops.cjs +85 -0
- package/dist/ops.cjs.map +1 -0
- package/dist/ops.d.cts +61 -0
- package/dist/ops.d.cts.map +1 -0
- package/dist/ops.d.mts +61 -0
- package/dist/ops.d.mts.map +1 -0
- package/dist/ops.mjs +79 -0
- package/dist/ops.mjs.map +1 -0
- package/dist/{react-riTxd9ce.cjs → react-CkAQg9wB.cjs} +72 -7
- package/dist/react-CkAQg9wB.cjs.map +1 -0
- package/dist/{react-DqnINwTi.mjs → react-Cq3xULOr.mjs} +72 -7
- package/dist/react-Cq3xULOr.mjs.map +1 -0
- package/dist/{react-CLONxcnA.d.cts → react-D-Sf973d.d.cts} +94 -2
- package/dist/react-D-Sf973d.d.cts.map +1 -0
- package/dist/{react-CLONxcnA.d.mts → react-D-Sf973d.d.mts} +94 -2
- package/dist/react-D-Sf973d.d.mts.map +1 -0
- package/dist/shell.cjs +68 -4
- package/dist/shell.cjs.map +1 -1
- package/dist/shell.d.cts +62 -7
- package/dist/shell.d.cts.map +1 -1
- package/dist/shell.d.mts +62 -7
- package/dist/shell.d.mts.map +1 -1
- package/dist/shell.mjs +66 -5
- package/dist/shell.mjs.map +1 -1
- package/package.json +13 -2
- package/dist/react-CLONxcnA.d.cts.map +0 -1
- package/dist/react-CLONxcnA.d.mts.map +0 -1
- package/dist/react-DqnINwTi.mjs.map +0 -1
- package/dist/react-riTxd9ce.cjs.map +0 -1
|
@@ -364,10 +364,25 @@ function validateFunctions(raw) {
|
|
|
364
364
|
}
|
|
365
365
|
fn.retries = retries;
|
|
366
366
|
}
|
|
367
|
+
if (value.webhook !== void 0) {
|
|
368
|
+
const w = value.webhook;
|
|
369
|
+
if (!isRecord(w)) throw new Error(`oxy-app.json: function "${fnName}" \`webhook\` must be an object`);
|
|
370
|
+
for (const key of ["secretVar", "signatureHeader"]) if (typeof w[key] !== "string" || !w[key].trim()) throw new Error(`oxy-app.json: function "${fnName}" \`webhook.${key}\` must be a non-empty string`);
|
|
371
|
+
const webhook = {
|
|
372
|
+
secretVar: w.secretVar,
|
|
373
|
+
signatureHeader: w.signatureHeader
|
|
374
|
+
};
|
|
375
|
+
if (w.encoding !== void 0) {
|
|
376
|
+
if (w.encoding !== "hex" && w.encoding !== "base64") throw new Error(`oxy-app.json: function "${fnName}" \`webhook.encoding\` must be "hex" or "base64"`);
|
|
377
|
+
webhook.encoding = w.encoding;
|
|
378
|
+
}
|
|
379
|
+
fn.webhook = webhook;
|
|
380
|
+
}
|
|
367
381
|
if (value.inputExample !== void 0) fn.inputExample = value.inputExample;
|
|
368
382
|
const hasSchedule = fn.schedule !== void 0;
|
|
369
383
|
const hasAirway = fn.airwayStep !== void 0;
|
|
370
|
-
|
|
384
|
+
const hasWebhook = fn.webhook !== void 0;
|
|
385
|
+
if (!(fn.route ?? !(hasSchedule || hasAirway || hasWebhook)) && !hasSchedule && !hasAirway && !hasWebhook) throw new Error(`oxy-app.json: function "${fnName}" must enable at least one of route/schedule/airwayStep/webhook`);
|
|
371
386
|
out[fnName] = fn;
|
|
372
387
|
}
|
|
373
388
|
return out;
|
|
@@ -621,6 +636,44 @@ async function sharedQuery(fetcher, projectId, sql, db, opts = {}) {
|
|
|
621
636
|
return p;
|
|
622
637
|
}
|
|
623
638
|
|
|
639
|
+
//#endregion
|
|
640
|
+
//#region src/custom-app/traceparent.ts
|
|
641
|
+
const HEX = "0123456789abcdef";
|
|
642
|
+
function randomHex(bytes) {
|
|
643
|
+
const buf = new Uint8Array(bytes);
|
|
644
|
+
const c = globalThis.crypto;
|
|
645
|
+
if (c && typeof c.getRandomValues === "function") c.getRandomValues(buf);
|
|
646
|
+
else for (let i = 0; i < bytes; i++) buf[i] = Math.floor(Math.random() * 256);
|
|
647
|
+
let out = "";
|
|
648
|
+
for (let i = 0; i < bytes; i++) out += HEX[buf[i] >> 4] + HEX[buf[i] & 15];
|
|
649
|
+
return out;
|
|
650
|
+
}
|
|
651
|
+
/** Mint a fresh, sampled `traceparent`. All-zero ids are invalid per the spec;
|
|
652
|
+
* the loop guards the astronomically unlikely draw. */
|
|
653
|
+
function newTraceparent() {
|
|
654
|
+
let traceId = randomHex(16);
|
|
655
|
+
while (/^0+$/.test(traceId)) traceId = randomHex(16);
|
|
656
|
+
let spanId = randomHex(8);
|
|
657
|
+
while (/^0+$/.test(spanId)) spanId = randomHex(8);
|
|
658
|
+
return {
|
|
659
|
+
header: `00-${traceId}-${spanId}-01`,
|
|
660
|
+
traceId
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Stamp the ids of a failed invoke onto whatever was thrown, so the app (and
|
|
665
|
+
* the platform's error beacon, which reads `traceId`) can name the trace and
|
|
666
|
+
* the server-minted request id. Non-objects are returned untouched.
|
|
667
|
+
*/
|
|
668
|
+
function withInvocationIds(err, traceId, requestId) {
|
|
669
|
+
if (err && typeof err === "object") {
|
|
670
|
+
const target = err;
|
|
671
|
+
if (!target.traceId) target.traceId = traceId;
|
|
672
|
+
if (requestId && !target.requestId) target.requestId = requestId;
|
|
673
|
+
}
|
|
674
|
+
return err;
|
|
675
|
+
}
|
|
676
|
+
|
|
624
677
|
//#endregion
|
|
625
678
|
//#region src/custom-app/react.tsx
|
|
626
679
|
function defaultFetcher(input, init) {
|
|
@@ -893,9 +946,11 @@ function useFunction(name) {
|
|
|
893
946
|
error: null
|
|
894
947
|
}));
|
|
895
948
|
try {
|
|
949
|
+
const trace = newTraceparent();
|
|
896
950
|
const headers = {
|
|
897
951
|
"content-type": "application/json",
|
|
898
|
-
accept: "text/event-stream"
|
|
952
|
+
accept: "text/event-stream",
|
|
953
|
+
traceparent: trace.header
|
|
899
954
|
};
|
|
900
955
|
if (opts?.idempotencyKey) headers["idempotency-key"] = opts.idempotencyKey;
|
|
901
956
|
const result = await sharedFunctionInvoke(functionInvokeKey(name, body), async () => {
|
|
@@ -904,8 +959,13 @@ function useFunction(name) {
|
|
|
904
959
|
headers,
|
|
905
960
|
body: JSON.stringify(body ?? {})
|
|
906
961
|
});
|
|
907
|
-
|
|
908
|
-
|
|
962
|
+
const requestId = resp.headers?.get?.("x-oxy-request-id") ?? null;
|
|
963
|
+
if (!resp.ok && resp.status !== 200) throw withInvocationIds(await apiErrorFromResponse(resp), trace.traceId, requestId);
|
|
964
|
+
try {
|
|
965
|
+
return await readFunctionSseStream(resp);
|
|
966
|
+
} catch (err) {
|
|
967
|
+
throw withInvocationIds(err, trace.traceId, requestId);
|
|
968
|
+
}
|
|
909
969
|
});
|
|
910
970
|
setState({
|
|
911
971
|
data: result.value,
|
|
@@ -947,7 +1007,7 @@ function useFunction(name) {
|
|
|
947
1007
|
* inputs (e.g. a user-picked filter value) are available.
|
|
948
1008
|
*/
|
|
949
1009
|
function useSemanticQuery(input, opts = {}) {
|
|
950
|
-
const { projectId, fetcher } = useOxyApp();
|
|
1010
|
+
const { projectId, appId, fetcher } = useOxyApp();
|
|
951
1011
|
const enabled = opts.enabled !== false;
|
|
952
1012
|
const debug = opts.debug === true;
|
|
953
1013
|
const inputKey = React.useMemo(() => JSON.stringify(input), [input]);
|
|
@@ -982,7 +1042,11 @@ function useSemanticQuery(input, opts = {}) {
|
|
|
982
1042
|
measures: input.measures ?? [],
|
|
983
1043
|
time_dimensions: input.time_dimensions ?? [],
|
|
984
1044
|
filters: input.filters ?? [],
|
|
985
|
-
...input.limit != null ? { limit: input.limit } : {}
|
|
1045
|
+
...input.limit != null ? { limit: input.limit } : {},
|
|
1046
|
+
...input.scope ? {
|
|
1047
|
+
scope: input.scope,
|
|
1048
|
+
...appId ? { app: appId } : {}
|
|
1049
|
+
} : {}
|
|
986
1050
|
});
|
|
987
1051
|
const url = `/api/projects/${projectId}/semantic-query${debug ? "?debug=1" : ""}`;
|
|
988
1052
|
fetcher(url, {
|
|
@@ -1020,6 +1084,7 @@ function useSemanticQuery(input, opts = {}) {
|
|
|
1020
1084
|
}, [
|
|
1021
1085
|
enabled,
|
|
1022
1086
|
projectId,
|
|
1087
|
+
appId,
|
|
1023
1088
|
inputKey,
|
|
1024
1089
|
debug,
|
|
1025
1090
|
nonce,
|
|
@@ -2292,4 +2357,4 @@ const styles = {
|
|
|
2292
2357
|
|
|
2293
2358
|
//#endregion
|
|
2294
2359
|
export { interpretCustomAppError as _, useFunction as a, useQuery as c, useTrackEvent as d, _resetCustomAppManifestCacheForTest as f, apiErrorFromResponse as g, OxyApiError as h, useAgentRun as i, useResolvedManifest as l, readInjectedAppConfig as m, OxyAppProvider as n, useOxyApp as o, loadCustomAppManifest as p, OxyChat as r, useProcedureRun as s, OxyAnswer as t, useSemanticQuery as u, getOxyAppLogger as v, setOxyAppLogger as y };
|
|
2295
|
-
//# sourceMappingURL=react-
|
|
2360
|
+
//# sourceMappingURL=react-Cq3xULOr.mjs.map
|