@oxy-hq/sdk 2.10.0 → 2.12.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 +156 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +338 -595
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +338 -595
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +155 -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-B7zt-0RH.mjs → react-BXGyzgz0.mjs} +19 -6
- package/dist/react-BXGyzgz0.mjs.map +1 -0
- package/dist/{react-BGUzRMxq.d.mts → react-DW7Z96sD.d.cts} +52 -1
- package/dist/react-DW7Z96sD.d.cts.map +1 -0
- package/dist/{react-BGUzRMxq.d.cts → react-DW7Z96sD.d.mts} +52 -1
- package/dist/react-DW7Z96sD.d.mts.map +1 -0
- package/dist/{react-Cas_DVKe.cjs → react-DcT-mUPj.cjs} +19 -6
- package/dist/react-DcT-mUPj.cjs.map +1 -0
- package/dist/shell.cjs +34 -4
- package/dist/shell.cjs.map +1 -1
- package/dist/shell.d.cts +39 -7
- package/dist/shell.d.cts.map +1 -1
- package/dist/shell.d.mts +39 -7
- package/dist/shell.d.mts.map +1 -1
- package/dist/shell.mjs +34 -5
- package/dist/shell.mjs.map +1 -1
- package/package.json +12 -1
- package/dist/react-B7zt-0RH.mjs.map +0 -1
- package/dist/react-BGUzRMxq.d.cts.map +0 -1
- package/dist/react-BGUzRMxq.d.mts.map +0 -1
- package/dist/react-Cas_DVKe.cjs.map +0 -1
package/dist/ops.d.cts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
import { _ as OxyReach } from "./function-context-D8eyZuw_.cjs";
|
|
3
|
+
//#region src/ops/index.d.ts
|
|
4
|
+
/** What `ctx.user.reach` carries — one shape, declared once on the context type. */
|
|
5
|
+
type Reach = OxyReach;
|
|
6
|
+
/** The slice of `ctx` this module reads — a test hands in exactly this. */
|
|
7
|
+
interface ReachCtx {
|
|
8
|
+
user: {
|
|
9
|
+
/**
|
|
10
|
+
* Present on every invocation since SDK 2.12 / the operating graph. Typed
|
|
11
|
+
* optional here so a function can be written before its server is
|
|
12
|
+
* upgraded: an absent reach is the fail-closed answer, never the office.
|
|
13
|
+
*/
|
|
14
|
+
reach?: Reach | null;
|
|
15
|
+
appRole?: string;
|
|
16
|
+
kind?: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The caller's reach. Synchronous — the platform decided it before the
|
|
21
|
+
* function ran — but `await reachOf(ctx)` still works, so code written against
|
|
22
|
+
* the app-side version keeps compiling.
|
|
23
|
+
*
|
|
24
|
+
* Absent reach (an older server) lands on nowhere. Not "system reaches
|
|
25
|
+
* everywhere, everyone else nowhere": a system invocation on an older server
|
|
26
|
+
* carries no reach either, and the one thing this module must never do is
|
|
27
|
+
* invent a wider answer than the platform gave.
|
|
28
|
+
*/
|
|
29
|
+
declare function reachOf(ctx: ReachCtx): Reach;
|
|
30
|
+
declare function reaches(reach: Reach, locationId: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* For a writer naming a location: the 403 to return, or null to proceed.
|
|
33
|
+
*
|
|
34
|
+
* The message names the location and not the roster, and the code is stable:
|
|
35
|
+
* the client tells "you are not rostered here" from "no such location" (a 404
|
|
36
|
+
* the writers answer BEFORE this) and from "admin only" (a 403 with another
|
|
37
|
+
* code) without parsing English.
|
|
38
|
+
*/
|
|
39
|
+
declare function requireReach(ctx: ReachCtx, locationId: string): Response | null;
|
|
40
|
+
/**
|
|
41
|
+
* For a reader: a SQL expression that is true for rows in reach, over the
|
|
42
|
+
* given location column, binding through `params`.
|
|
43
|
+
*
|
|
44
|
+
* `TRUE` for a caller who reaches everywhere, so the statement reads the same
|
|
45
|
+
* either way. Otherwise the locations go in as ONE comma-joined text parameter
|
|
46
|
+
* unpacked by `string_to_array` — a location id is a uuid or a slug and can
|
|
47
|
+
* never contain the separator. An empty list becomes an empty array, so a
|
|
48
|
+
* caller assigned nowhere matches nothing rather than everything: the two
|
|
49
|
+
* states are different values, not one sentinel doing double duty.
|
|
50
|
+
*/
|
|
51
|
+
declare function predicate(reach: Reach, column: string, params: unknown[]): string;
|
|
52
|
+
/**
|
|
53
|
+
* The app-admin gate, decided in one place. `appRole` is derived by the
|
|
54
|
+
* platform (`Ring::AppAdmin`) and is the ONE field on `ctx.user` a function
|
|
55
|
+
* may gate on; `orgRole` and `teams` are there to explain, not to decide.
|
|
56
|
+
*/
|
|
57
|
+
declare function isAdmin(ctx: Pick<ReachCtx, "user">): boolean;
|
|
58
|
+
declare function adminOnly(what: string): Response;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { Reach, ReachCtx, adminOnly, isAdmin, predicate, reachOf, reaches, requireReach };
|
|
61
|
+
//# sourceMappingURL=ops.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ops.d.cts","names":[],"sources":["../src/ops/index.ts"],"mappings":";;;;KAsBY,QAAQ;;UAGH;EACf;;;;;;IAME,QAAQ;IACR;IACA;;;;;;;;;;;;;iBAgBY,QAAQ,KAAK,WAAW;iBAMxB,QAAQ,OAAO,OAAO;;;;;;;;;iBAYtB,aAAa,KAAK,UAAU,qBAAqB;;;;;;;;;;;;iBAmBjD,UAAU,OAAO,OAAO,gBAAgB;;;;;;iBAgBxC,QAAQ,KAAK,KAAK;iBAIlB,UAAU,eAAe"}
|
package/dist/ops.d.mts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
import { _ as OxyReach } from "./function-context-D8eyZuw_.mjs";
|
|
3
|
+
//#region src/ops/index.d.ts
|
|
4
|
+
/** What `ctx.user.reach` carries — one shape, declared once on the context type. */
|
|
5
|
+
type Reach = OxyReach;
|
|
6
|
+
/** The slice of `ctx` this module reads — a test hands in exactly this. */
|
|
7
|
+
interface ReachCtx {
|
|
8
|
+
user: {
|
|
9
|
+
/**
|
|
10
|
+
* Present on every invocation since SDK 2.12 / the operating graph. Typed
|
|
11
|
+
* optional here so a function can be written before its server is
|
|
12
|
+
* upgraded: an absent reach is the fail-closed answer, never the office.
|
|
13
|
+
*/
|
|
14
|
+
reach?: Reach | null;
|
|
15
|
+
appRole?: string;
|
|
16
|
+
kind?: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The caller's reach. Synchronous — the platform decided it before the
|
|
21
|
+
* function ran — but `await reachOf(ctx)` still works, so code written against
|
|
22
|
+
* the app-side version keeps compiling.
|
|
23
|
+
*
|
|
24
|
+
* Absent reach (an older server) lands on nowhere. Not "system reaches
|
|
25
|
+
* everywhere, everyone else nowhere": a system invocation on an older server
|
|
26
|
+
* carries no reach either, and the one thing this module must never do is
|
|
27
|
+
* invent a wider answer than the platform gave.
|
|
28
|
+
*/
|
|
29
|
+
declare function reachOf(ctx: ReachCtx): Reach;
|
|
30
|
+
declare function reaches(reach: Reach, locationId: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* For a writer naming a location: the 403 to return, or null to proceed.
|
|
33
|
+
*
|
|
34
|
+
* The message names the location and not the roster, and the code is stable:
|
|
35
|
+
* the client tells "you are not rostered here" from "no such location" (a 404
|
|
36
|
+
* the writers answer BEFORE this) and from "admin only" (a 403 with another
|
|
37
|
+
* code) without parsing English.
|
|
38
|
+
*/
|
|
39
|
+
declare function requireReach(ctx: ReachCtx, locationId: string): Response | null;
|
|
40
|
+
/**
|
|
41
|
+
* For a reader: a SQL expression that is true for rows in reach, over the
|
|
42
|
+
* given location column, binding through `params`.
|
|
43
|
+
*
|
|
44
|
+
* `TRUE` for a caller who reaches everywhere, so the statement reads the same
|
|
45
|
+
* either way. Otherwise the locations go in as ONE comma-joined text parameter
|
|
46
|
+
* unpacked by `string_to_array` — a location id is a uuid or a slug and can
|
|
47
|
+
* never contain the separator. An empty list becomes an empty array, so a
|
|
48
|
+
* caller assigned nowhere matches nothing rather than everything: the two
|
|
49
|
+
* states are different values, not one sentinel doing double duty.
|
|
50
|
+
*/
|
|
51
|
+
declare function predicate(reach: Reach, column: string, params: unknown[]): string;
|
|
52
|
+
/**
|
|
53
|
+
* The app-admin gate, decided in one place. `appRole` is derived by the
|
|
54
|
+
* platform (`Ring::AppAdmin`) and is the ONE field on `ctx.user` a function
|
|
55
|
+
* may gate on; `orgRole` and `teams` are there to explain, not to decide.
|
|
56
|
+
*/
|
|
57
|
+
declare function isAdmin(ctx: Pick<ReachCtx, "user">): boolean;
|
|
58
|
+
declare function adminOnly(what: string): Response;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { Reach, ReachCtx, adminOnly, isAdmin, predicate, reachOf, reaches, requireReach };
|
|
61
|
+
//# sourceMappingURL=ops.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ops.d.mts","names":[],"sources":["../src/ops/index.ts"],"mappings":";;;;KAsBY,QAAQ;;UAGH;EACf;;;;;;IAME,QAAQ;IACR;IACA;;;;;;;;;;;;;iBAgBY,QAAQ,KAAK,WAAW;iBAMxB,QAAQ,OAAO,OAAO;;;;;;;;;iBAYtB,aAAa,KAAK,UAAU,qBAAqB;;;;;;;;;;;;iBAmBjD,UAAU,OAAO,OAAO,gBAAgB;;;;;;iBAgBxC,QAAQ,KAAK,KAAK;iBAIlB,UAAU,eAAe"}
|
package/dist/ops.mjs
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// @oxy/sdk - TypeScript SDK for Oxy data platform
|
|
2
|
+
//#region src/ops/index.ts
|
|
3
|
+
const NOWHERE = {
|
|
4
|
+
everywhere: false,
|
|
5
|
+
via: null,
|
|
6
|
+
locations: []
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The caller's reach. Synchronous — the platform decided it before the
|
|
10
|
+
* function ran — but `await reachOf(ctx)` still works, so code written against
|
|
11
|
+
* the app-side version keeps compiling.
|
|
12
|
+
*
|
|
13
|
+
* Absent reach (an older server) lands on nowhere. Not "system reaches
|
|
14
|
+
* everywhere, everyone else nowhere": a system invocation on an older server
|
|
15
|
+
* carries no reach either, and the one thing this module must never do is
|
|
16
|
+
* invent a wider answer than the platform gave.
|
|
17
|
+
*/
|
|
18
|
+
function reachOf(ctx) {
|
|
19
|
+
const r = ctx.user.reach;
|
|
20
|
+
if (!r || typeof r !== "object" || !Array.isArray(r.locations)) return NOWHERE;
|
|
21
|
+
return {
|
|
22
|
+
everywhere: r.everywhere === true,
|
|
23
|
+
via: r.via ?? null,
|
|
24
|
+
locations: [...r.locations]
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function reaches(reach, locationId) {
|
|
28
|
+
return reach.everywhere || reach.locations.includes(locationId);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* For a writer naming a location: the 403 to return, or null to proceed.
|
|
32
|
+
*
|
|
33
|
+
* The message names the location and not the roster, and the code is stable:
|
|
34
|
+
* the client tells "you are not rostered here" from "no such location" (a 404
|
|
35
|
+
* the writers answer BEFORE this) and from "admin only" (a 403 with another
|
|
36
|
+
* code) without parsing English.
|
|
37
|
+
*/
|
|
38
|
+
function requireReach(ctx, locationId) {
|
|
39
|
+
if (reaches(reachOf(ctx), locationId)) return null;
|
|
40
|
+
return Response.json({
|
|
41
|
+
error: `you are not rostered at ${locationId}`,
|
|
42
|
+
code: "OutOfReach",
|
|
43
|
+
locationId
|
|
44
|
+
}, { status: 403 });
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* For a reader: a SQL expression that is true for rows in reach, over the
|
|
48
|
+
* given location column, binding through `params`.
|
|
49
|
+
*
|
|
50
|
+
* `TRUE` for a caller who reaches everywhere, so the statement reads the same
|
|
51
|
+
* either way. Otherwise the locations go in as ONE comma-joined text parameter
|
|
52
|
+
* unpacked by `string_to_array` — a location id is a uuid or a slug and can
|
|
53
|
+
* never contain the separator. An empty list becomes an empty array, so a
|
|
54
|
+
* caller assigned nowhere matches nothing rather than everything: the two
|
|
55
|
+
* states are different values, not one sentinel doing double duty.
|
|
56
|
+
*/
|
|
57
|
+
function predicate(reach, column, params) {
|
|
58
|
+
if (reach.everywhere) return "TRUE";
|
|
59
|
+
params.push(reach.locations.join(","));
|
|
60
|
+
return `${column}::text = ANY(string_to_array($${params.length}::text, ','))`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The app-admin gate, decided in one place. `appRole` is derived by the
|
|
64
|
+
* platform (`Ring::AppAdmin`) and is the ONE field on `ctx.user` a function
|
|
65
|
+
* may gate on; `orgRole` and `teams` are there to explain, not to decide.
|
|
66
|
+
*/
|
|
67
|
+
function isAdmin(ctx) {
|
|
68
|
+
return (ctx.user.appRole ?? "") === "admin";
|
|
69
|
+
}
|
|
70
|
+
function adminOnly(what) {
|
|
71
|
+
return Response.json({
|
|
72
|
+
error: `${what} needs app-admin standing`,
|
|
73
|
+
code: "AdminOnly"
|
|
74
|
+
}, { status: 403 });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
export { adminOnly, isAdmin, predicate, reachOf, reaches, requireReach };
|
|
79
|
+
//# sourceMappingURL=ops.mjs.map
|
package/dist/ops.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ops.mjs","names":[],"sources":["../src/ops/index.ts"],"sourcesContent":["// `@oxy-hq/sdk/ops` — the operating graph, applied inside an Oxy Function.\n//\n// The platform states where a caller may act (`ctx.user.reach`, derived from\n// their assignments — see `internal-docs/operating-graph.md` §3.3); this is\n// how a function applies it. Library code, versioned with the SDK, and\n// replaceable: an app that needs a tighter rule wraps `reachOf` and keeps the\n// rest. It may tighten, never widen — the reach the platform hands in is the\n// ceiling.\n//\n// Lifted from Store Ops's `functions/access.ts` (customer-apps #138) minus its\n// roster SQL: the roster is the platform's now, so the decision arrives on\n// `ctx.user` and nothing here reads a table.\n//\n// Two entry points. `requireReach` for a writer that names a location: the\n// 403 to return, or null. `predicate` for a reader: a SQL expression over the\n// statement's own location column, bound through the statement's parameter\n// list, so the scope lives in the WHERE — before the LIMIT, so a page is a\n// page of the right set.\n\nimport type { OxyReach } from \"../custom-app/function-context\";\n\n/** What `ctx.user.reach` carries — one shape, declared once on the context type. */\nexport type Reach = OxyReach;\n\n/** The slice of `ctx` this module reads — a test hands in exactly this. */\nexport interface ReachCtx {\n user: {\n /**\n * Present on every invocation since SDK 2.12 / the operating graph. Typed\n * optional here so a function can be written before its server is\n * upgraded: an absent reach is the fail-closed answer, never the office.\n */\n reach?: Reach | null;\n appRole?: string;\n kind?: string;\n };\n}\n\nconst NOWHERE: Reach = { everywhere: false, via: null, locations: [] };\n\n/**\n * The caller's reach. Synchronous — the platform decided it before the\n * function ran — but `await reachOf(ctx)` still works, so code written against\n * the app-side version keeps compiling.\n *\n * Absent reach (an older server) lands on nowhere. Not \"system reaches\n * everywhere, everyone else nowhere\": a system invocation on an older server\n * carries no reach either, and the one thing this module must never do is\n * invent a wider answer than the platform gave.\n */\nexport function reachOf(ctx: ReachCtx): Reach {\n const r = ctx.user.reach;\n if (!r || typeof r !== \"object\" || !Array.isArray(r.locations)) return NOWHERE;\n return { everywhere: r.everywhere === true, via: r.via ?? null, locations: [...r.locations] };\n}\n\nexport function reaches(reach: Reach, locationId: string): boolean {\n return reach.everywhere || reach.locations.includes(locationId);\n}\n\n/**\n * For a writer naming a location: the 403 to return, or null to proceed.\n *\n * The message names the location and not the roster, and the code is stable:\n * the client tells \"you are not rostered here\" from \"no such location\" (a 404\n * the writers answer BEFORE this) and from \"admin only\" (a 403 with another\n * code) without parsing English.\n */\nexport function requireReach(ctx: ReachCtx, locationId: string): Response | null {\n if (reaches(reachOf(ctx), locationId)) return null;\n return Response.json(\n { error: `you are not rostered at ${locationId}`, code: \"OutOfReach\", locationId },\n { status: 403 }\n );\n}\n\n/**\n * For a reader: a SQL expression that is true for rows in reach, over the\n * given location column, binding through `params`.\n *\n * `TRUE` for a caller who reaches everywhere, so the statement reads the same\n * either way. Otherwise the locations go in as ONE comma-joined text parameter\n * unpacked by `string_to_array` — a location id is a uuid or a slug and can\n * never contain the separator. An empty list becomes an empty array, so a\n * caller assigned nowhere matches nothing rather than everything: the two\n * states are different values, not one sentinel doing double duty.\n */\nexport function predicate(reach: Reach, column: string, params: unknown[]): string {\n if (reach.everywhere) return \"TRUE\";\n params.push(reach.locations.join(\",\"));\n // `::text` on the column: `string_to_array` yields `text[]`, and Postgres\n // will not compare a `uuid` column to it on its own (`uuid = text` has no\n // operator). The platform's location ids ARE uuids, so a tenant storing\n // them in the natural column type would otherwise get a reader that never\n // runs. A text column is unaffected.\n return `${column}::text = ANY(string_to_array($${params.length}::text, ','))`;\n}\n\n/**\n * The app-admin gate, decided in one place. `appRole` is derived by the\n * platform (`Ring::AppAdmin`) and is the ONE field on `ctx.user` a function\n * may gate on; `orgRole` and `teams` are there to explain, not to decide.\n */\nexport function isAdmin(ctx: Pick<ReachCtx, \"user\">): boolean {\n return (ctx.user.appRole ?? \"\") === \"admin\";\n}\n\nexport function adminOnly(what: string): Response {\n return Response.json(\n { error: `${what} needs app-admin standing`, code: \"AdminOnly\" },\n { status: 403 }\n );\n}\n"],"mappings":";;AAsCA,MAAM,UAAiB;CAAE,YAAY;CAAO,KAAK;CAAM,WAAW,CAAC;AAAE;;;;;;;;;;;AAYrE,SAAgB,QAAQ,KAAsB;CAC5C,MAAM,IAAI,IAAI,KAAK;CACnB,IAAI,CAAC,KAAK,OAAO,MAAM,YAAY,CAAC,MAAM,QAAQ,EAAE,SAAS,GAAG,OAAO;CACvE,OAAO;EAAE,YAAY,EAAE,eAAe;EAAM,KAAK,EAAE,OAAO;EAAM,WAAW,CAAC,GAAG,EAAE,SAAS;CAAE;AAC9F;AAEA,SAAgB,QAAQ,OAAc,YAA6B;CACjE,OAAO,MAAM,cAAc,MAAM,UAAU,SAAS,UAAU;AAChE;;;;;;;;;AAUA,SAAgB,aAAa,KAAe,YAAqC;CAC/E,IAAI,QAAQ,QAAQ,GAAG,GAAG,UAAU,GAAG,OAAO;CAC9C,OAAO,SAAS,KACd;EAAE,OAAO,2BAA2B;EAAc,MAAM;EAAc;CAAW,GACjF,EAAE,QAAQ,IAAI,CAChB;AACF;;;;;;;;;;;;AAaA,SAAgB,UAAU,OAAc,QAAgB,QAA2B;CACjF,IAAI,MAAM,YAAY,OAAO;CAC7B,OAAO,KAAK,MAAM,UAAU,KAAK,GAAG,CAAC;CAMrC,OAAO,GAAG,OAAO,gCAAgC,OAAO,OAAO;AACjE;;;;;;AAOA,SAAgB,QAAQ,KAAsC;CAC5D,QAAQ,IAAI,KAAK,WAAW,QAAQ;AACtC;AAEA,SAAgB,UAAU,MAAwB;CAChD,OAAO,SAAS,KACd;EAAE,OAAO,GAAG,KAAK;EAA4B,MAAM;CAAY,GAC/D,EAAE,QAAQ,IAAI,CAChB;AACF"}
|
|
@@ -772,6 +772,7 @@ function useOxyApp() {
|
|
|
772
772
|
if (!ctx) throw new Error("useOxyApp must be called inside <OxyAppProvider>");
|
|
773
773
|
return {
|
|
774
774
|
projectId: ctx.resolved?.projectId,
|
|
775
|
+
appId: ctx.resolved?.appId,
|
|
775
776
|
appSlug: ctx.resolved?.appSlug,
|
|
776
777
|
orgSlug: ctx.resolved?.orgSlug,
|
|
777
778
|
fetcher: ctx.fetcher
|
|
@@ -946,7 +947,7 @@ function useFunction(name) {
|
|
|
946
947
|
* inputs (e.g. a user-picked filter value) are available.
|
|
947
948
|
*/
|
|
948
949
|
function useSemanticQuery(input, opts = {}) {
|
|
949
|
-
const { projectId, fetcher } = useOxyApp();
|
|
950
|
+
const { projectId, appId, fetcher } = useOxyApp();
|
|
950
951
|
const enabled = opts.enabled !== false;
|
|
951
952
|
const debug = opts.debug === true;
|
|
952
953
|
const inputKey = React.useMemo(() => JSON.stringify(input), [input]);
|
|
@@ -981,7 +982,11 @@ function useSemanticQuery(input, opts = {}) {
|
|
|
981
982
|
measures: input.measures ?? [],
|
|
982
983
|
time_dimensions: input.time_dimensions ?? [],
|
|
983
984
|
filters: input.filters ?? [],
|
|
984
|
-
...input.limit != null ? { limit: input.limit } : {}
|
|
985
|
+
...input.limit != null ? { limit: input.limit } : {},
|
|
986
|
+
...input.scope ? {
|
|
987
|
+
scope: input.scope,
|
|
988
|
+
...appId ? { app: appId } : {}
|
|
989
|
+
} : {}
|
|
985
990
|
});
|
|
986
991
|
const url = `/api/projects/${projectId}/semantic-query${debug ? "?debug=1" : ""}`;
|
|
987
992
|
fetcher(url, {
|
|
@@ -1019,6 +1024,7 @@ function useSemanticQuery(input, opts = {}) {
|
|
|
1019
1024
|
}, [
|
|
1020
1025
|
enabled,
|
|
1021
1026
|
projectId,
|
|
1027
|
+
appId,
|
|
1022
1028
|
inputKey,
|
|
1023
1029
|
debug,
|
|
1024
1030
|
nonce,
|
|
@@ -1558,7 +1564,7 @@ function sleep(ms, signal) {
|
|
|
1558
1564
|
* within-limit events are unaffected.
|
|
1559
1565
|
*/
|
|
1560
1566
|
function useTrackEvent() {
|
|
1561
|
-
const { projectId, fetcher } = useOxyApp();
|
|
1567
|
+
const { projectId, appId, fetcher } = useOxyApp();
|
|
1562
1568
|
const queueRef = React.useRef([]);
|
|
1563
1569
|
const flushTimerRef = React.useRef(null);
|
|
1564
1570
|
const flush = React.useCallback(() => {
|
|
@@ -1569,7 +1575,10 @@ function useTrackEvent() {
|
|
|
1569
1575
|
queueRef.current = [];
|
|
1570
1576
|
for (const evt of batch) {
|
|
1571
1577
|
const url = `/api/customer-apps/${projectId}/events`;
|
|
1572
|
-
const body = JSON.stringify(
|
|
1578
|
+
const body = JSON.stringify(appId ? {
|
|
1579
|
+
...evt,
|
|
1580
|
+
app_id: appId
|
|
1581
|
+
} : evt);
|
|
1573
1582
|
try {
|
|
1574
1583
|
if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function" && document.visibilityState === "hidden") navigator.sendBeacon(url, new Blob([body], { type: "application/json" }));
|
|
1575
1584
|
else fetcher(url, {
|
|
@@ -1583,7 +1592,11 @@ function useTrackEvent() {
|
|
|
1583
1592
|
console.warn("[oxy] useTrackEvent enqueue failed:", e);
|
|
1584
1593
|
}
|
|
1585
1594
|
}
|
|
1586
|
-
}, [
|
|
1595
|
+
}, [
|
|
1596
|
+
projectId,
|
|
1597
|
+
fetcher,
|
|
1598
|
+
appId
|
|
1599
|
+
]);
|
|
1587
1600
|
React.useEffect(() => {
|
|
1588
1601
|
if (typeof window === "undefined") return;
|
|
1589
1602
|
const onHide = () => flush();
|
|
@@ -2284,4 +2297,4 @@ const styles = {
|
|
|
2284
2297
|
|
|
2285
2298
|
//#endregion
|
|
2286
2299
|
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 };
|
|
2287
|
-
//# sourceMappingURL=react-
|
|
2300
|
+
//# sourceMappingURL=react-BXGyzgz0.mjs.map
|