@oxy-hq/sdk 2.11.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.
Files changed (40) hide show
  1. package/README.md +44 -4
  2. package/dist/function-context-D8eyZuw_.d.cts +720 -0
  3. package/dist/function-context-D8eyZuw_.d.cts.map +1 -0
  4. package/dist/function-context-D8eyZuw_.d.mts +720 -0
  5. package/dist/function-context-D8eyZuw_.d.mts.map +1 -0
  6. package/dist/index.cjs +156 -11
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +338 -638
  9. package/dist/index.d.cts.map +1 -1
  10. package/dist/index.d.mts +338 -638
  11. package/dist/index.d.mts.map +1 -1
  12. package/dist/index.mjs +155 -12
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/ops.cjs +85 -0
  15. package/dist/ops.cjs.map +1 -0
  16. package/dist/ops.d.cts +61 -0
  17. package/dist/ops.d.cts.map +1 -0
  18. package/dist/ops.d.mts +61 -0
  19. package/dist/ops.d.mts.map +1 -0
  20. package/dist/ops.mjs +79 -0
  21. package/dist/ops.mjs.map +1 -0
  22. package/dist/{react-DqnINwTi.mjs → react-BXGyzgz0.mjs} +8 -3
  23. package/dist/react-BXGyzgz0.mjs.map +1 -0
  24. package/dist/{react-CLONxcnA.d.cts → react-DW7Z96sD.d.cts} +8 -1
  25. package/dist/{react-CLONxcnA.d.cts.map → react-DW7Z96sD.d.cts.map} +1 -1
  26. package/dist/{react-CLONxcnA.d.mts → react-DW7Z96sD.d.mts} +8 -1
  27. package/dist/{react-CLONxcnA.d.mts.map → react-DW7Z96sD.d.mts.map} +1 -1
  28. package/dist/{react-riTxd9ce.cjs → react-DcT-mUPj.cjs} +8 -3
  29. package/dist/react-DcT-mUPj.cjs.map +1 -0
  30. package/dist/shell.cjs +34 -4
  31. package/dist/shell.cjs.map +1 -1
  32. package/dist/shell.d.cts +39 -7
  33. package/dist/shell.d.cts.map +1 -1
  34. package/dist/shell.d.mts +39 -7
  35. package/dist/shell.d.mts.map +1 -1
  36. package/dist/shell.mjs +34 -5
  37. package/dist/shell.mjs.map +1 -1
  38. package/package.json +12 -1
  39. package/dist/react-DqnINwTi.mjs.map +0 -1
  40. package/dist/react-riTxd9ce.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
@@ -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"}
@@ -947,7 +947,7 @@ function useFunction(name) {
947
947
  * inputs (e.g. a user-picked filter value) are available.
948
948
  */
949
949
  function useSemanticQuery(input, opts = {}) {
950
- const { projectId, fetcher } = useOxyApp();
950
+ const { projectId, appId, fetcher } = useOxyApp();
951
951
  const enabled = opts.enabled !== false;
952
952
  const debug = opts.debug === true;
953
953
  const inputKey = React.useMemo(() => JSON.stringify(input), [input]);
@@ -982,7 +982,11 @@ function useSemanticQuery(input, opts = {}) {
982
982
  measures: input.measures ?? [],
983
983
  time_dimensions: input.time_dimensions ?? [],
984
984
  filters: input.filters ?? [],
985
- ...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
+ } : {}
986
990
  });
987
991
  const url = `/api/projects/${projectId}/semantic-query${debug ? "?debug=1" : ""}`;
988
992
  fetcher(url, {
@@ -1020,6 +1024,7 @@ function useSemanticQuery(input, opts = {}) {
1020
1024
  }, [
1021
1025
  enabled,
1022
1026
  projectId,
1027
+ appId,
1023
1028
  inputKey,
1024
1029
  debug,
1025
1030
  nonce,
@@ -2292,4 +2297,4 @@ const styles = {
2292
2297
 
2293
2298
  //#endregion
2294
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 };
2295
- //# sourceMappingURL=react-DqnINwTi.mjs.map
2300
+ //# sourceMappingURL=react-BXGyzgz0.mjs.map