@simpleapps-com/augur-server 2.4.0 → 2026.11.1
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/EXPORTS.md +29 -72
- package/README.md +29 -198
- package/dist/actions/agr-info.d.ts +43 -0
- package/dist/actions/agr-info.d.ts.map +1 -0
- package/dist/actions/agr-site.d.ts +37 -0
- package/dist/actions/agr-site.d.ts.map +1 -0
- package/dist/actions/agr-work.d.ts +29 -0
- package/dist/actions/agr-work.d.ts.map +1 -0
- package/dist/actions/avalara.d.ts +38 -0
- package/dist/actions/avalara.d.ts.map +1 -0
- package/dist/actions/basecamp2.d.ts +47 -0
- package/dist/actions/basecamp2.d.ts.map +1 -0
- package/dist/actions/brand-folder.d.ts +38 -0
- package/dist/actions/brand-folder.d.ts.map +1 -0
- package/dist/actions/commerce.d.ts +58 -0
- package/dist/actions/commerce.d.ts.map +1 -0
- package/dist/actions/customers.d.ts +44 -0
- package/dist/actions/customers.d.ts.map +1 -0
- package/dist/actions/favorites.d.ts +20 -0
- package/dist/actions/favorites.d.ts.map +1 -0
- package/dist/actions/gregorovich.d.ts +34 -0
- package/dist/actions/gregorovich.d.ts.map +1 -0
- package/dist/actions/items.d.ts +80 -0
- package/dist/actions/items.d.ts.map +1 -0
- package/dist/actions/joomla.d.ts +59 -0
- package/dist/actions/joomla.d.ts.map +1 -0
- package/dist/actions/legacy.d.ts +45 -0
- package/dist/actions/legacy.d.ts.map +1 -0
- package/dist/actions/logistics.d.ts +40 -0
- package/dist/actions/logistics.d.ts.map +1 -0
- package/dist/actions/orders.d.ts +36 -0
- package/dist/actions/orders.d.ts.map +1 -0
- package/dist/actions/p21-apis.d.ts +33 -0
- package/dist/actions/p21-apis.d.ts.map +1 -0
- package/dist/actions/p21-core.d.ts +46 -0
- package/dist/actions/p21-core.d.ts.map +1 -0
- package/dist/actions/p21-pim.d.ts +36 -0
- package/dist/actions/p21-pim.d.ts.map +1 -0
- package/dist/actions/p21-sism.d.ts +37 -0
- package/dist/actions/p21-sism.d.ts.map +1 -0
- package/dist/actions/payments.d.ts +39 -0
- package/dist/actions/payments.d.ts.map +1 -0
- package/dist/actions/pricing.d.ts +45 -0
- package/dist/actions/pricing.d.ts.map +1 -0
- package/dist/actions/search.d.ts +61 -0
- package/dist/actions/search.d.ts.map +1 -0
- package/dist/actions/shipping.d.ts +56 -0
- package/dist/actions/shipping.d.ts.map +1 -0
- package/dist/actions/site.d.ts +141 -0
- package/dist/actions/site.d.ts.map +1 -0
- package/dist/actions/smarty-streets.d.ts +45 -0
- package/dist/actions/smarty-streets.d.ts.map +1 -0
- package/dist/actions/vmi.d.ts +44 -0
- package/dist/actions/vmi.d.ts.map +1 -0
- package/dist/actions/wishlists.d.ts +28 -0
- package/dist/actions/wishlists.d.ts.map +1 -0
- package/dist/api-handler.d.ts +25 -0
- package/dist/api-handler.d.ts.map +1 -0
- package/dist/api.d.ts +2 -26
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +19 -14
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts +10 -12
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +2 -2
- package/dist/cache/redis-client.d.ts +16 -0
- package/dist/cache/redis-client.d.ts.map +1 -0
- package/dist/cache/with-cache.d.ts +18 -0
- package/dist/cache/with-cache.d.ts.map +1 -0
- package/dist/{chunk-2NL4QKJN.js → chunk-FWO6Q43T.js} +31 -30
- package/dist/chunk-FWO6Q43T.js.map +1 -0
- package/dist/{chunk-ALTIINP6.js → chunk-NTUPTNOI.js} +30 -6
- package/dist/chunk-NTUPTNOI.js.map +1 -0
- package/dist/{chunk-26WZBC4F.js → chunk-PFYEMJTQ.js} +203 -631
- package/dist/chunk-PFYEMJTQ.js.map +1 -0
- package/dist/{chunk-KHFEDL47.js → chunk-SXXWBSTX.js} +18 -12
- package/dist/chunk-SXXWBSTX.js.map +1 -0
- package/dist/chunk-TVH5EONP.js +178 -0
- package/dist/chunk-TVH5EONP.js.map +1 -0
- package/dist/{chunk-PIYHMA6F.js → chunk-U2BKHRJC.js} +10 -13
- package/dist/chunk-U2BKHRJC.js.map +1 -0
- package/dist/environment.d.ts +10 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/hooks.d.ts +8 -10
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +3 -3
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +16 -125
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/pagination.d.ts +32 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/query-action.d.ts +15 -117
- package/dist/query-action.d.ts.map +1 -0
- package/dist/query-action.js +3 -3
- package/dist/{query.d.ts → query-options-helper.d.ts} +5 -7
- package/dist/query-options-helper.d.ts.map +1 -0
- package/dist/query.js +1 -2
- package/dist/recaptcha.d.ts +6 -0
- package/dist/recaptcha.d.ts.map +1 -0
- package/dist/rules.d.ts +221 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/scoped-client-key.d.ts +9 -0
- package/dist/scoped-client-key.d.ts.map +1 -0
- package/dist/sdk-call.d.ts +66 -0
- package/dist/sdk-call.d.ts.map +1 -0
- package/dist/sdk-client-store.d.ts +250 -0
- package/dist/sdk-client-store.d.ts.map +1 -0
- package/dist/server-actions.d.ts +2 -0
- package/dist/server-actions.d.ts.map +1 -0
- package/dist/server-query-client.d.ts +19 -0
- package/dist/server-query-client.d.ts.map +1 -0
- package/dist/{server-site-registry-CdBfczOj.d.ts → server-site-registry.d.ts} +7 -9
- package/dist/server-site-registry.d.ts.map +1 -0
- package/dist/{site.d.ts → server-site.d.ts} +11 -16
- package/dist/server-site.d.ts.map +1 -0
- package/dist/site-actions-store.d.ts +27 -0
- package/dist/site-actions-store.d.ts.map +1 -0
- package/dist/site.js +10 -10
- package/dist/site.js.map +1 -1
- package/dist/testing.d.ts +9 -12
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +7 -27
- package/dist/testing.js.map +1 -1
- package/dist/utils/batch-fetch.d.ts +7 -0
- package/dist/utils/batch-fetch.d.ts.map +1 -0
- package/llms.txt +71 -50
- package/package.json +29 -20
- package/dist/actions.d.ts +0 -2
- package/dist/chunk-26WZBC4F.js.map +0 -1
- package/dist/chunk-2NL4QKJN.js.map +0 -1
- package/dist/chunk-ALTIINP6.js.map +0 -1
- package/dist/chunk-DGUM43GV.js +0 -11
- package/dist/chunk-DGUM43GV.js.map +0 -1
- package/dist/chunk-KHFEDL47.js.map +0 -1
- package/dist/chunk-PIYHMA6F.js.map +0 -1
- package/dist/site-BjSFqufX.d.ts +0 -469
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createQueryOptions,
|
|
3
3
|
createSuspenseQueryOptions
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-U2BKHRJC.js";
|
|
5
5
|
import {
|
|
6
6
|
batchFetch,
|
|
7
7
|
cacheGet,
|
|
@@ -21,9 +21,11 @@ import {
|
|
|
21
21
|
unwrap,
|
|
22
22
|
unwrapOr,
|
|
23
23
|
withServerCache
|
|
24
|
-
} from "./chunk-
|
|
25
|
-
import "./chunk-
|
|
26
|
-
import
|
|
24
|
+
} from "./chunk-PFYEMJTQ.js";
|
|
25
|
+
import "./chunk-NTUPTNOI.js";
|
|
26
|
+
import {
|
|
27
|
+
recaptchaOk
|
|
28
|
+
} from "./chunk-TVH5EONP.js";
|
|
27
29
|
|
|
28
30
|
// src/server-query-client.ts
|
|
29
31
|
import { cache } from "react";
|
|
@@ -51,7 +53,7 @@ var getServerQueryClient = cache(() => createServerQueryClient());
|
|
|
51
53
|
async function verifyRecaptcha(token) {
|
|
52
54
|
try {
|
|
53
55
|
const secretKey = process.env["RECAPTCHA_SECRET_KEY"];
|
|
54
|
-
if (!secretKey) return false;
|
|
56
|
+
if (!secretKey) return recaptchaOk(false, false, void 0);
|
|
55
57
|
const res = await fetch("https://www.google.com/recaptcha/api/siteverify", {
|
|
56
58
|
method: "POST",
|
|
57
59
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
@@ -59,10 +61,10 @@ async function verifyRecaptcha(token) {
|
|
|
59
61
|
});
|
|
60
62
|
if (!res.ok) {
|
|
61
63
|
console.error("reCAPTCHA verify failed:", res.status);
|
|
62
|
-
return false;
|
|
64
|
+
return recaptchaOk(true, false, void 0);
|
|
63
65
|
}
|
|
64
66
|
const result = await res.json();
|
|
65
|
-
return result.success
|
|
67
|
+
return recaptchaOk(true, true, result.success);
|
|
66
68
|
} catch (error) {
|
|
67
69
|
console.error("reCAPTCHA verify error:", error);
|
|
68
70
|
return false;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server-query-client.ts","../src/recaptcha.ts"],"sourcesContent":["import { cache } from \"react\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { CACHE_CONFIG } from \"@simpleapps-com/augur-utils\";\n\n/**\n * Creates a server-side query client optimised for prefetching.\n *\n * - No persistence (server-only)\n * - No GC timers (gcTime: Infinity), so the client is freed with the request\n * - No retries (fail fast on server)\n * - No refetching (server renders are one-shot)\n */\nexport function createServerQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: CACHE_CONFIG.STATIC.staleTime,\n // Infinity = no GC timer. A finite value pins this per-request client\n // (and its whole cache) in memory until the timer fires (#481).\n gcTime: Infinity,\n retry: 0,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n },\n },\n });\n}\n\n/**\n * Returns a per-request singleton QueryClient for React Server Components.\n *\n * React's `cache()` deduplicates calls within a single server request,\n * so each request gets its own QueryClient while avoiding the cross-request\n * state leakage that a module-level singleton would cause.\n */\nexport const getServerQueryClient = cache((): QueryClient => createServerQueryClient());\n","/**\n * Server-side Google reCAPTCHA v3 verification.\n * Used by API routes that accept public form submissions.\n */\nexport async function verifyRecaptcha(token: string): Promise<boolean> {\n try {\n const secretKey = process.env[\"RECAPTCHA_SECRET_KEY\"];\n if (!secretKey) return false;\n\n const res = await fetch(\"https://www.google.com/recaptcha/api/siteverify\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n body: new URLSearchParams({ secret: secretKey, response: token }),\n });\n if (!res.ok) {\n console.error(\"reCAPTCHA verify failed:\", res.status);\n return false;\n }\n const result = (await res.json()) as { success?: boolean };\n return result.success
|
|
1
|
+
{"version":3,"sources":["../src/server-query-client.ts","../src/recaptcha.ts"],"sourcesContent":["import { cache } from \"react\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { CACHE_CONFIG } from \"@simpleapps-com/augur-utils\";\n\n/**\n * Creates a server-side query client optimised for prefetching.\n *\n * - No persistence (server-only)\n * - No GC timers (gcTime: Infinity), so the client is freed with the request\n * - No retries (fail fast on server)\n * - No refetching (server renders are one-shot)\n */\nexport function createServerQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: CACHE_CONFIG.STATIC.staleTime,\n // Infinity = no GC timer. A finite value pins this per-request client\n // (and its whole cache) in memory until the timer fires (#481).\n gcTime: Infinity,\n retry: 0,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n },\n },\n });\n}\n\n/**\n * Returns a per-request singleton QueryClient for React Server Components.\n *\n * React's `cache()` deduplicates calls within a single server request,\n * so each request gets its own QueryClient while avoiding the cross-request\n * state leakage that a module-level singleton would cause.\n */\nexport const getServerQueryClient = cache((): QueryClient => createServerQueryClient());\n","import { recaptchaOk } from \"./rules\";\n\n/**\n * Server-side Google reCAPTCHA v3 verification.\n * Used by API routes that accept public form submissions.\n */\nexport async function verifyRecaptcha(token: string): Promise<boolean> {\n try {\n const secretKey = process.env[\"RECAPTCHA_SECRET_KEY\"];\n if (!secretKey) return recaptchaOk(false, false, undefined);\n\n const res = await fetch(\"https://www.google.com/recaptcha/api/siteverify\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n body: new URLSearchParams({ secret: secretKey, response: token }),\n });\n if (!res.ok) {\n console.error(\"reCAPTCHA verify failed:\", res.status);\n return recaptchaOk(true, false, undefined);\n }\n const result = (await res.json()) as { success?: boolean };\n return recaptchaOk(true, true, result.success);\n } catch (error) {\n console.error(\"reCAPTCHA verify error:\", error);\n return false;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAUtB,SAAS,0BAAuC;AACrD,SAAO,IAAI,YAAY;AAAA,IACrB,gBAAgB;AAAA,MACd,SAAS;AAAA,QACP,WAAW,aAAa,OAAO;AAAA;AAAA;AAAA,QAG/B,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,gBAAgB;AAAA,QAChB,sBAAsB;AAAA,QACtB,oBAAoB;AAAA,MACtB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AASO,IAAM,uBAAuB,MAAM,MAAmB,wBAAwB,CAAC;;;AC9BtF,eAAsB,gBAAgB,OAAiC;AACrE,MAAI;AACF,UAAM,YAAY,QAAQ,IAAI,sBAAsB;AACpD,QAAI,CAAC,UAAW,QAAO,YAAY,OAAO,OAAO,MAAS;AAE1D,UAAM,MAAM,MAAM,MAAM,mDAAmD;AAAA,MACzE,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,oCAAoC;AAAA,MAC/D,MAAM,IAAI,gBAAgB,EAAE,QAAQ,WAAW,UAAU,MAAM,CAAC;AAAA,IAClE,CAAC;AACD,QAAI,CAAC,IAAI,IAAI;AACX,cAAQ,MAAM,4BAA4B,IAAI,MAAM;AACpD,aAAO,YAAY,MAAM,OAAO,MAAS;AAAA,IAC3C;AACA,UAAM,SAAU,MAAM,IAAI,KAAK;AAC/B,WAAO,YAAY,MAAM,MAAM,OAAO,OAAO;AAAA,EAC/C,SAAS,OAAO;AACd,YAAQ,MAAM,2BAA2B,KAAK;AAC9C,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standardized paginated response shape.
|
|
3
|
+
* Works with any factory method — compose with `paginateOffset()`.
|
|
4
|
+
*/
|
|
5
|
+
export interface PaginatedResult<T> {
|
|
6
|
+
data: T[];
|
|
7
|
+
total: number;
|
|
8
|
+
nextCursor?: number;
|
|
9
|
+
hasMore: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a list of items with offset-based pagination metadata.
|
|
13
|
+
*
|
|
14
|
+
* Use this to standardize pagination responses from any factory method.
|
|
15
|
+
* Compatible with React Query's infinite query pattern (`getNextPageParam`).
|
|
16
|
+
*
|
|
17
|
+
* @param items - The items returned from the current page
|
|
18
|
+
* @param pageParam - The current page number (0-based)
|
|
19
|
+
* @param limit - The page size
|
|
20
|
+
* @param total - Optional total count of items (from API response)
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const result = await actions.items.getCategoryItems(uid, {
|
|
25
|
+
* ...filters, offset: page * 24, limit: 24,
|
|
26
|
+
* });
|
|
27
|
+
* return paginateOffset(result.items, page, 24, result.total);
|
|
28
|
+
* // { data: [...], total: 150, nextCursor: 1, hasMore: true }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function paginateOffset<T>(items: T[], pageParam: number, limit: number, total?: number): PaginatedResult<T>;
|
|
32
|
+
//# sourceMappingURL=pagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,KAAK,EAAE,CAAC,EAAE,EACV,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,GACb,eAAe,CAAC,CAAC,CAAC,CASpB"}
|
package/dist/query-action.d.ts
CHANGED
|
@@ -1,78 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare const SessionCredentialsBrand: unique symbol;
|
|
4
|
-
declare const ApprovedMethodPathBrand: unique symbol;
|
|
5
|
-
/**
|
|
6
|
-
* Site identifier extracted from a validated Auth.js session JWT cookie.
|
|
7
|
-
*
|
|
8
|
-
* Intended to be minted only by `getSessionCredentials` in query-action.ts.
|
|
9
|
-
*
|
|
10
|
-
* Brand strength: code-review signal, not type-system enforcement. TypeScript
|
|
11
|
-
* allows `value as SessionSiteId` casts, so audit `as SessionSiteId` usages
|
|
12
|
-
* to catch unintended mints — there should be exactly one, at the JWT mint
|
|
13
|
-
* point.
|
|
14
|
-
*/
|
|
15
|
-
type SessionSiteId = string & {
|
|
16
|
-
readonly [SessionSiteIdBrand]: true;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Bearer token extracted from a validated Auth.js session JWT cookie.
|
|
20
|
-
* Same intended-mint and brand-strength caveat as {@link SessionSiteId}.
|
|
21
|
-
*/
|
|
22
|
-
type SessionBearerToken = string & {
|
|
23
|
-
readonly [SessionBearerTokenBrand]: true;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Paired session credentials. Bundles `siteId` and `token` from the same
|
|
27
|
-
* validated session into one value so downstream functions can accept the
|
|
28
|
-
* pair as a unit, instead of two separate parameters that callers might
|
|
29
|
-
* accidentally mix across sessions.
|
|
30
|
-
*
|
|
31
|
-
* Intended to be minted only by `getSessionCredentials` in query-action.ts,
|
|
32
|
-
* which performs the cross-check that the bearer's `client_id` siteId
|
|
33
|
-
* matches `targetSiteId`. Anything that holds a `SessionCredentials` *was*
|
|
34
|
-
* cross-checked at mint time — provided the value came through that mint
|
|
35
|
-
* and not via a cast.
|
|
36
|
-
*
|
|
37
|
-
* Brand strength: same code-review signal as the field brands. `value as
|
|
38
|
-
* SessionCredentials` compiles. Audit `as SessionCredentials` usages — there
|
|
39
|
-
* should be exactly one, in `getSessionCredentials`.
|
|
40
|
-
*/
|
|
41
|
-
type SessionCredentials = {
|
|
42
|
-
readonly siteId: SessionSiteId;
|
|
43
|
-
readonly token: SessionBearerToken;
|
|
44
|
-
readonly [SessionCredentialsBrand]: true;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* SDK method path validated against the registered allowlist.
|
|
48
|
-
*
|
|
49
|
-
* Intended to be minted only by `parseMethodPath` below. Functions that walk
|
|
50
|
-
* the path into the SDK client (notably `resolveMethod`) demand this type
|
|
51
|
-
* so that an unvalidated string flowing into the walker is a compile error
|
|
52
|
-
* for code that respects the convention.
|
|
53
|
-
*
|
|
54
|
-
* Brand strength: code-review signal. `value as ApprovedMethodPath` compiles.
|
|
55
|
-
* Audit `as ApprovedMethodPath` usages — there should be one, in
|
|
56
|
-
* `parseMethodPath`.
|
|
57
|
-
*
|
|
58
|
-
* Scope of validation: this is a *site-level surface restriction*, not a
|
|
59
|
-
* security boundary. augur-api is the auth authority; the allowlist limits
|
|
60
|
-
* what the application's proxy will forward to the SDK, not what tokens are
|
|
61
|
-
* permitted to do. Useful for narrowing same-origin attack surface (XSS,
|
|
62
|
-
* malicious bundled deps); not a substitute for API-level authorization.
|
|
63
|
-
*/
|
|
64
|
-
type ApprovedMethodPath = string & {
|
|
65
|
-
readonly [ApprovedMethodPathBrand]: true;
|
|
66
|
-
};
|
|
67
|
-
|
|
1
|
+
import { type SessionCredentials, type ApprovedMethodPath } from "./sdk-client-store";
|
|
2
|
+
import { unwrapBaseResponse } from "@simpleapps-com/augur-core";
|
|
68
3
|
/**
|
|
69
4
|
* Resolve session credentials from the Auth.js JWT cookie.
|
|
70
5
|
*
|
|
71
6
|
* Trust-boundary mint point: this is the only function in the package that
|
|
72
7
|
* produces {@link SessionCredentials} values. Bytes from a cookie become
|
|
73
|
-
* typed, paired credentials here and only here.
|
|
74
|
-
*
|
|
75
|
-
*
|
|
8
|
+
* typed, paired credentials here and only here. No other production code
|
|
9
|
+
* constructs the branded pair, so a `SessionCredentials` that came through
|
|
10
|
+
* this mint is JWT-validated and internally consistent. The brand is not
|
|
11
|
+
* enforced by the compiler: an `as SessionCredentials` cast compiles (tests
|
|
12
|
+
* do it), so audit casts (see "Brand strength" below).
|
|
76
13
|
*
|
|
77
14
|
* Returns null when:
|
|
78
15
|
* - no AUTH_SECRET is configured
|
|
@@ -81,6 +18,9 @@ type ApprovedMethodPath = string & {
|
|
|
81
18
|
* - the JWT decode fails or returns null
|
|
82
19
|
* - the decoded payload is missing `targetSiteId` or `token`, or either is
|
|
83
20
|
* not a non-empty string (refuse to mint partial credentials)
|
|
21
|
+
* - `targetSiteId` fails augur-api's `isSiteId` (`[a-z0-9_-]+`): siteIds are
|
|
22
|
+
* lowercase by convention, and the scoped-client key's injectivity proof
|
|
23
|
+
* (`scoped-client-key.ts`) needs a NUL-free siteId
|
|
84
24
|
* - the bearer token's `client_id` siteId portion does not match
|
|
85
25
|
* `targetSiteId` (defense-in-depth: refuses internally inconsistent sessions
|
|
86
26
|
* before they reach the augur-api authority check)
|
|
@@ -90,7 +30,7 @@ type ApprovedMethodPath = string & {
|
|
|
90
30
|
* AUTH_SECRET configured
|
|
91
31
|
* next-auth/jwt, next/headers, jose all loadable
|
|
92
32
|
* session cookie present and decodable with the secret
|
|
93
|
-
* typeof jwt.targetSiteId === "string" ∧ jwt.targetSiteId
|
|
33
|
+
* typeof jwt.targetSiteId === "string" ∧ isSiteId(jwt.targetSiteId) // implies non-empty
|
|
94
34
|
* typeof jwt.token === "string" ∧ jwt.token.length > 0
|
|
95
35
|
* bearerClientSiteId(jwt.token) = some jwt.targetSiteId
|
|
96
36
|
*
|
|
@@ -117,48 +57,6 @@ type ApprovedMethodPath = string & {
|
|
|
117
57
|
* exactly one, in this function), not a hard type-system gate.
|
|
118
58
|
*/
|
|
119
59
|
declare function getSessionCredentials(): Promise<SessionCredentials | null>;
|
|
120
|
-
/**
|
|
121
|
-
* Unwrap SDK BaseResponse if the result matches the standard shape.
|
|
122
|
-
* The SDK wraps all responses in `{ data: T, status: number, message: string }`.
|
|
123
|
-
* SiteActions previously unwrapped this; queryAction now does it automatically
|
|
124
|
-
* so consumers receive `T` directly.
|
|
125
|
-
*
|
|
126
|
-
* ## Property
|
|
127
|
-
*
|
|
128
|
-
* ∀ raw. result(raw) ∈ {raw.data, raw}
|
|
129
|
-
* BaseResponse?(raw) ⟺ raw is non-null object ∧ "data" ∈ keys(raw)
|
|
130
|
-
* ∧ "status" ∈ keys(raw)
|
|
131
|
-
* ∧ "message" ∈ keys(raw)
|
|
132
|
-
*
|
|
133
|
-
* Two possible outcomes; never throws, never reshapes. The structural
|
|
134
|
-
* test checks key presence only — it does NOT validate field types or
|
|
135
|
-
* values. Assumes upstream code does not produce `{data, status, message}`
|
|
136
|
-
* shapes that aren't actually BaseResponses; if it does, those will be
|
|
137
|
-
* incorrectly unwrapped (false positive). In practice the augur-api SDK
|
|
138
|
-
* is the only producer of this shape on the server path.
|
|
139
|
-
*
|
|
140
|
-
* This property is what lets queryAction call this exactly once per
|
|
141
|
-
* request without double-unwrap risk: applying unwrapBaseResponse to
|
|
142
|
-
* an already-unwrapped value is a no-op (the second branch of the
|
|
143
|
-
* property fires).
|
|
144
|
-
*
|
|
145
|
-
* ## SDK envelope coupling — forward-compat additive, brittle to renames
|
|
146
|
-
*
|
|
147
|
-
* The structural test checks for `data ∧ status ∧ message`. Three implications:
|
|
148
|
-
*
|
|
149
|
-
* - Additive SDK changes (envelope grows new fields, e.g. `pagination`,
|
|
150
|
-
* `requestId`) are forward-compatible — the predicate still matches and
|
|
151
|
-
* this function still unwraps correctly.
|
|
152
|
-
* - Renames are brittle: if the augur-api SDK ever changes the envelope
|
|
153
|
-
* to `{ result, status, message }` (or any rename of `data`), this
|
|
154
|
-
* function silently STOPS unwrapping. Consumers receive the envelope
|
|
155
|
-
* as `T` and downstream code breaks far from the cause. The fix is
|
|
156
|
-
* mechanical (update the predicate) but the failure mode is silent —
|
|
157
|
-
* audit this function whenever the SDK envelope contract changes.
|
|
158
|
-
* - This predicate MUST stay in sync with augur-api's BaseResponse type.
|
|
159
|
-
* Treat the envelope shape as a coupled contract, not as inferred behaviour.
|
|
160
|
-
*/
|
|
161
|
-
declare function unwrapBaseResponse(raw: unknown): unknown;
|
|
162
60
|
/**
|
|
163
61
|
* Resolve a dot-separated method path on an object, returning the leaf function.
|
|
164
62
|
*
|
|
@@ -279,8 +177,8 @@ declare function resolveMethod(client: unknown, methodPath: ApprovedMethodPath):
|
|
|
279
177
|
* @param args Arguments to pass to the resolved method
|
|
280
178
|
* @returns The unwrapped result from the SDK method (possibly from Redis cache)
|
|
281
179
|
*/
|
|
282
|
-
declare function queryAction(methodPath: string, ...args: unknown[]): Promise<unknown>;
|
|
180
|
+
export declare function queryAction(methodPath: string, ...args: unknown[]): Promise<unknown>;
|
|
283
181
|
/** Reset lazy-loaded imports. Used in tests only. @internal */
|
|
284
|
-
declare function resetSessionImports(): void;
|
|
285
|
-
|
|
286
|
-
|
|
182
|
+
export declare function resetSessionImports(): void;
|
|
183
|
+
export { unwrapBaseResponse, getSessionCredentials, resolveMethod };
|
|
184
|
+
//# sourceMappingURL=query-action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-action.d.ts","sourceRoot":"","sources":["../src/query-action.ts"],"names":[],"mappings":"AAUA,OAAO,EAOL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EAGxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAGL,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AA+FpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,iBAAe,qBAAqB,IAAI,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAyBzE;AA2DD;;;;;GAKG;AACH,iBAAS,aAAa,CACpB,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,kBAAkB,GAC7B,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAkBvC;AAqCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgHG;AACH,wBAAsB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CA4C1F;AAED,+DAA+D;AAC/D,wBAAgB,mBAAmB,IAAI,IAAI,CAI1C;AAED,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/query-action.js
CHANGED
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
resetSessionImports,
|
|
6
6
|
resolveMethod,
|
|
7
7
|
unwrapBaseResponse
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
8
|
+
} from "./chunk-FWO6Q43T.js";
|
|
9
|
+
import "./chunk-NTUPTNOI.js";
|
|
10
|
+
import "./chunk-TVH5EONP.js";
|
|
11
11
|
export {
|
|
12
12
|
getSessionCredentials,
|
|
13
13
|
queryAction,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { UseQueryOptions, UseSuspenseQueryOptions } from
|
|
2
|
-
|
|
3
|
-
interface QueryOptionsConfig<TParams, TData> {
|
|
1
|
+
import type { UseQueryOptions, UseSuspenseQueryOptions } from "@tanstack/react-query";
|
|
2
|
+
export interface QueryOptionsConfig<TParams, TData> {
|
|
4
3
|
/** Base query key (e.g., "customer-orders") */
|
|
5
4
|
baseKey: string;
|
|
6
5
|
/** Parameters object */
|
|
@@ -24,12 +23,11 @@ interface QueryOptionsConfig<TParams, TData> {
|
|
|
24
23
|
* Creates useQuery options with consistent key generation.
|
|
25
24
|
* Filters out undefined/null/empty params from the query key.
|
|
26
25
|
*/
|
|
27
|
-
declare const createQueryOptions: <TParams extends Record<string, unknown>, TData>({ baseKey, params, queryFn, enabledFn, staleTime, gcTime, excludeFromKey, }: QueryOptionsConfig<TParams, TData>) => UseQueryOptions<TData>;
|
|
26
|
+
export declare const createQueryOptions: <TParams extends Record<string, unknown>, TData>({ baseKey, params, queryFn, enabledFn, staleTime, gcTime, excludeFromKey, }: QueryOptionsConfig<TParams, TData>) => UseQueryOptions<TData>;
|
|
28
27
|
/**
|
|
29
28
|
* Creates useSuspenseQuery options with consistent key generation.
|
|
30
29
|
* Same as createQueryOptions but without enabledFn (suspense queries
|
|
31
30
|
* cannot be disabled).
|
|
32
31
|
*/
|
|
33
|
-
declare const createSuspenseQueryOptions: <TParams extends Record<string, unknown>, TData>({ baseKey, params, queryFn, staleTime, gcTime, excludeFromKey, }: Omit<QueryOptionsConfig<TParams, TData>, "enabledFn">) => UseSuspenseQueryOptions<TData>;
|
|
34
|
-
|
|
35
|
-
export { type QueryOptionsConfig, createQueryOptions, createSuspenseQueryOptions };
|
|
32
|
+
export declare const createSuspenseQueryOptions: <TParams extends Record<string, unknown>, TData>({ baseKey, params, queryFn, staleTime, gcTime, excludeFromKey, }: Omit<QueryOptionsConfig<TParams, TData>, "enabledFn">) => UseSuspenseQueryOptions<TData>;
|
|
33
|
+
//# sourceMappingURL=query-options-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-options-helper.d.ts","sourceRoot":"","sources":["../src/query-options-helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAItF,MAAM,WAAW,kBAAkB,CAAC,OAAO,EAAE,KAAK;IAChD,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,wBAAwB;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,qCAAqC;IACrC,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7C,uDAAuD;IACvD,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC;IACzC,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC;CAChC;AAsBD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,6EAQhF,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,KAAG,eAAe,CAAC,KAAK,CAQ5D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,GAAI,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,kEAOxF,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,WAAW,CAAC,KAAG,uBAAuB,CAAC,KAAK,CAOvF,CAAC"}
|
package/dist/query.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recaptcha.d.ts","sourceRoot":"","sources":["../src/recaptcha.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAoBrE"}
|
package/dist/rules.d.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The siteId of a bearer's client_id claim (`<n>|<siteId>`): the text after the first "|", when
|
|
3
|
+
* there is one and it is non-empty. The prefix is not checked.
|
|
4
|
+
*
|
|
5
|
+
* @ensures exactly the model's ClientIdSiteId on a string claim
|
|
6
|
+
*/
|
|
7
|
+
export declare function clientIdSiteIdOf(clientId: string): string | null;
|
|
8
|
+
/** A session's siteId and bearer token, as minted, or refused. */
|
|
9
|
+
export type Mint = {
|
|
10
|
+
kind: "minted";
|
|
11
|
+
siteId: string;
|
|
12
|
+
token: string;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "refused";
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* getSessionCredentials' mint, once the secret and the decoded session are in hand: a valid
|
|
18
|
+
* siteId (augur-api's `isSiteId`, checked by the caller), a non-empty token, and the bearer's
|
|
19
|
+
* client_id siteId (`""` for none: `clientIdSiteIdOf` never gives `""`) equal to it.
|
|
20
|
+
*
|
|
21
|
+
* @ensures exactly the model's MintCredentials with a secret and a decoded session
|
|
22
|
+
*/
|
|
23
|
+
export declare function mintedCredentials(siteIdOk: boolean, targetSiteId: string, token: string, bearerSiteId: string): Mint;
|
|
24
|
+
/**
|
|
25
|
+
* Whether there is another page: from the total when one is given, else a full page.
|
|
26
|
+
*
|
|
27
|
+
* @ensures exactly the model's HasMore
|
|
28
|
+
*/
|
|
29
|
+
export declare function hasMoreOf(page: number, limit: number, total: number | undefined, itemCount: number): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The next page's cursor: page + 1 while there is more.
|
|
32
|
+
*
|
|
33
|
+
* @ensures exactly the model's NextCursor given HasMore
|
|
34
|
+
*/
|
|
35
|
+
export declare function nextCursorOf(hasMore: boolean, page: number): number | undefined;
|
|
36
|
+
/** The deployment environment. */
|
|
37
|
+
export type Env = "development" | "staging" | "production";
|
|
38
|
+
/**
|
|
39
|
+
* DEPLOYMENT_ENV first; then the server's NODE_ENV; then the browser's host (substring). A missing
|
|
40
|
+
* variable is "".
|
|
41
|
+
*
|
|
42
|
+
* @ensures exactly the model's EnvOf
|
|
43
|
+
*/
|
|
44
|
+
export declare function envOf(deploymentEnv: string, isServer: boolean, nodeEnv: string, host: string): Env;
|
|
45
|
+
/**
|
|
46
|
+
* On the server: development only for NODE_ENV "development".
|
|
47
|
+
*
|
|
48
|
+
* @ensures result = development ⟺ nodeEnv = "development", else production
|
|
49
|
+
*/
|
|
50
|
+
export declare function serverEnvOf(nodeEnv: string): Env;
|
|
51
|
+
/**
|
|
52
|
+
* In the browser: localhost or 127.0.0.1 anywhere in the host is development, agr-hosting.dev
|
|
53
|
+
* staging, anything else production.
|
|
54
|
+
*
|
|
55
|
+
* @ensures exactly the model's host rule
|
|
56
|
+
*/
|
|
57
|
+
export declare function hostEnvOf(host: string): Env;
|
|
58
|
+
/** The API route's outcome for a request. */
|
|
59
|
+
export type ApiOutcome = "forbidden" | "bad-json" | "bad-method-path" | "bad-args" | "run";
|
|
60
|
+
/**
|
|
61
|
+
* A present, non-empty Sec-Fetch-Site other than same-origin is refused (a missing one, `""`
|
|
62
|
+
* from the caller, passes).
|
|
63
|
+
*
|
|
64
|
+
* @ensures result ⟺ fetchSite ∉ {"", "same-origin"}
|
|
65
|
+
*/
|
|
66
|
+
export declare function isCrossOrigin(fetchSite: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* The body's outcome: JSON, then a non-empty methodPath string, then an args array.
|
|
69
|
+
*
|
|
70
|
+
* @ensures exactly the model's ApiOutcomeOf past the origin check
|
|
71
|
+
*/
|
|
72
|
+
export declare function bodyOutcomeOf(jsonOk: boolean, methodPathOk: boolean, argsIsArray: boolean): ApiOutcome;
|
|
73
|
+
/**
|
|
74
|
+
* An outcome's HTTP status: 403, 400 for a bad body, 200 to run.
|
|
75
|
+
*
|
|
76
|
+
* @ensures exactly the model's ApiStatus
|
|
77
|
+
*/
|
|
78
|
+
export declare function apiStatusOf(o: ApiOutcome): number;
|
|
79
|
+
/**
|
|
80
|
+
* A refusal's response text ("" to run).
|
|
81
|
+
*
|
|
82
|
+
* @ensures each refusal has its fixed text
|
|
83
|
+
*/
|
|
84
|
+
export declare function apiMessageOf(o: ApiOutcome): string;
|
|
85
|
+
/**
|
|
86
|
+
* The Redis TTL for a cache tier: none for staleTime 0, the long TTL from an hour up, else the
|
|
87
|
+
* standard one.
|
|
88
|
+
*
|
|
89
|
+
* @ensures exactly the model's TtlFor
|
|
90
|
+
*/
|
|
91
|
+
export declare function ttlFor(staleTimeMs: number, redisTtl: number, longRedisTtl: number): number | null;
|
|
92
|
+
/** The Redis circuit breaker's state: consecutive failures, and when it closes (0 = closed). */
|
|
93
|
+
export interface Circuit {
|
|
94
|
+
failures: number;
|
|
95
|
+
openUntil: number;
|
|
96
|
+
}
|
|
97
|
+
/** The circuit's answer at a time: whether it is open, and its state after the check. */
|
|
98
|
+
export interface CircuitAnswer {
|
|
99
|
+
open: boolean;
|
|
100
|
+
next: Circuit;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* isCircuitOpen at `now`: closed at openUntil 0; past it, reset and closed; else open.
|
|
104
|
+
*
|
|
105
|
+
* @ensures exactly the model's CircuitCheck
|
|
106
|
+
*/
|
|
107
|
+
export declare function circuitCheck(c: Circuit, now: number): CircuitAnswer;
|
|
108
|
+
/**
|
|
109
|
+
* Whether a failure count opens the circuit: five in a row.
|
|
110
|
+
*
|
|
111
|
+
* @ensures result ⟺ failures ≥ 5
|
|
112
|
+
*/
|
|
113
|
+
export declare function opensAt(failures: number): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* A failure counts; from the threshold on the circuit opens for a minute from now.
|
|
116
|
+
*
|
|
117
|
+
* @ensures exactly the model's RecordFailure
|
|
118
|
+
*/
|
|
119
|
+
export declare function recordFailureOf(c: Circuit, now: number): Circuit;
|
|
120
|
+
/**
|
|
121
|
+
* A success clears the failure count and leaves openUntil.
|
|
122
|
+
*
|
|
123
|
+
* @ensures exactly the model's RecordSuccess
|
|
124
|
+
*/
|
|
125
|
+
export declare function recordSuccessOf(c: Circuit): Circuit;
|
|
126
|
+
/**
|
|
127
|
+
* authorize's verified flag: exactly the text "true".
|
|
128
|
+
*
|
|
129
|
+
* @ensures result ⟺ s = "true"
|
|
130
|
+
*/
|
|
131
|
+
export declare function verifiedFlag(s: string): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* reCAPTCHA passes only with a secret, an ok response and the reply's optional `success` exactly
|
|
134
|
+
* true (the score is not read).
|
|
135
|
+
*
|
|
136
|
+
* @ensures exactly the model's RecaptchaOk, success read as `=== true`
|
|
137
|
+
*/
|
|
138
|
+
export declare function recaptchaOk(hasSecret: boolean, httpOk: boolean, success: boolean | undefined): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* A customer id is used only above 0; anything else (NaN included, at the caller) is 0.
|
|
141
|
+
*
|
|
142
|
+
* @ensures result = n when n > 0, else 0
|
|
143
|
+
*/
|
|
144
|
+
export declare function positiveOrZero(n: number): number;
|
|
145
|
+
/**
|
|
146
|
+
* The category page size: 24 when none (or 0) is given.
|
|
147
|
+
*
|
|
148
|
+
* @ensures exactly the model's ItemsLimit, a missing limit as 0
|
|
149
|
+
*/
|
|
150
|
+
export declare function itemsLimitOf(limit: number | undefined): number;
|
|
151
|
+
/** How queryAction resolves its client. */
|
|
152
|
+
export type Resolution = "scoped" | "global" | "uninit";
|
|
153
|
+
/**
|
|
154
|
+
* resolveClient: scoped when credentials minted and a scoped client was made; else the global
|
|
155
|
+
* client when one is registered (also for a valid session without a factory); else none.
|
|
156
|
+
*
|
|
157
|
+
* @ensures exactly the model's ResolveClient
|
|
158
|
+
*/
|
|
159
|
+
export declare function resolutionOf(minted: boolean, scopedMade: boolean, hasGlobal: boolean): Resolution;
|
|
160
|
+
/** The scoped-client slot's decision. */
|
|
161
|
+
export type SlotDecision = "hit" | "mint" | "no-client";
|
|
162
|
+
/**
|
|
163
|
+
* getOrCreateScopedClient's single slot: a hit when it holds this key; else a new client when a
|
|
164
|
+
* factory is registered; else none. An empty slot is "" at the caller, which no key equals (a
|
|
165
|
+
* key holds a NUL).
|
|
166
|
+
*
|
|
167
|
+
* @ensures exactly the model's SlotDecisionOf
|
|
168
|
+
*/
|
|
169
|
+
export declare function slotDecisionOf(slotKey: string, key: string, hasFactory: boolean): SlotDecision;
|
|
170
|
+
/**
|
|
171
|
+
* parseMethodPath: a non-empty path, in the allowlist when one is registered (permissive by
|
|
172
|
+
* default); `listed` is the caller's Set lookup.
|
|
173
|
+
*
|
|
174
|
+
* @ensures exactly the model's ApprovePath
|
|
175
|
+
*/
|
|
176
|
+
export declare function approvePath(path: string, hasAllowlist: boolean, listed: boolean): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* queryAction caches a call only through a wrapper, and only for a read leaf (augur-core's
|
|
179
|
+
* `isReadMethod`, checked by the caller).
|
|
180
|
+
*
|
|
181
|
+
* @ensures exactly the model's UsesCache
|
|
182
|
+
*/
|
|
183
|
+
export declare function usesCache(hasWrapper: boolean, isRead: boolean): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* The scoped cache prefix: the session's siteId and ":".
|
|
186
|
+
*
|
|
187
|
+
* @ensures exactly the model's ScopedPrefix
|
|
188
|
+
*/
|
|
189
|
+
export declare function scopedPrefix(siteId: string): string;
|
|
190
|
+
/**
|
|
191
|
+
* withServerCache caches when the TTL is not 0 (missing or NaN is 0 at the caller; a negative
|
|
192
|
+
* TTL caches too).
|
|
193
|
+
*
|
|
194
|
+
* @ensures exactly the model's ShouldCache
|
|
195
|
+
*/
|
|
196
|
+
export declare function shouldCache(ttl: number): boolean;
|
|
197
|
+
/**
|
|
198
|
+
* getInvMastDoc's positional uid: kept above 0, else none.
|
|
199
|
+
*
|
|
200
|
+
* @ensures result = uid when uid > 0, else undefined
|
|
201
|
+
*/
|
|
202
|
+
export declare function docUidOf(uid: number): number | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* The positional itemId is used only at uid 0 and when non-empty ("" for none, at the caller).
|
|
205
|
+
*
|
|
206
|
+
* @ensures result ⟺ uid = 0 ∧ itemId ≠ ""
|
|
207
|
+
*/
|
|
208
|
+
export declare function takesItemId(uid: number, itemId: string): boolean;
|
|
209
|
+
/**
|
|
210
|
+
* A doc call needs a uid (truthy at the caller) or a non-empty itemId.
|
|
211
|
+
*
|
|
212
|
+
* @ensures result ⟺ uidSet ∨ itemId ≠ ""
|
|
213
|
+
*/
|
|
214
|
+
export declare function hasDocKey(uidSet: boolean, itemId: string): boolean;
|
|
215
|
+
/**
|
|
216
|
+
* The configured payments mode, "live" by default.
|
|
217
|
+
*
|
|
218
|
+
* @ensures result = configured ?? "live"
|
|
219
|
+
*/
|
|
220
|
+
export declare function configuredModeOf(configured: string | undefined): string;
|
|
221
|
+
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The key `siteId + "\0" + token`. Callers MUST pass a siteId with no NUL character
|
|
3
|
+
* (`getSessionCredentials` enforces `isSiteId`); with that, distinct pairs give distinct keys.
|
|
4
|
+
* A siteId with a NUL throws instead of returning a key that could collide.
|
|
5
|
+
*
|
|
6
|
+
* @throws TypeError when `siteId` contains a NUL character
|
|
7
|
+
*/
|
|
8
|
+
export declare function scopedClientKey(siteId: string, token: string): string;
|
|
9
|
+
//# sourceMappingURL=scoped-client-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoped-client-key.d.ts","sourceRoot":"","sources":["../src/scoped-client-key.ts"],"names":[],"mappings":"AAgCA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAMrE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export type { EdgeCacheValue, ActionResult, ApiResult, ListResult, } from "@simpleapps-com/augur-core";
|
|
2
|
+
import type { ApiResult, ListResult } from "@simpleapps-com/augur-core";
|
|
3
|
+
/**
|
|
4
|
+
* Calls an Augur SDK method, forwarding all arguments with full type safety.
|
|
5
|
+
*
|
|
6
|
+
* With augur-api >= 0.9.6, SDK methods properly declare their `CacheParams`
|
|
7
|
+
* option (including `edgeCache`), so this wrapper preserves both parameter
|
|
8
|
+
* and return-type inference end-to-end.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const result = await sdkCall(
|
|
13
|
+
* augurServices.items.invMast.get,
|
|
14
|
+
* invMastUid,
|
|
15
|
+
* { edgeCache: 4 },
|
|
16
|
+
* );
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function sdkCall<TArgs extends unknown[], TResult>(method: (...args: TArgs) => Promise<TResult>, ...args: TArgs): Promise<TResult>;
|
|
20
|
+
/** The SDK response envelope fields the result helpers read. */
|
|
21
|
+
interface SdkEnvelope {
|
|
22
|
+
data?: unknown;
|
|
23
|
+
total?: number;
|
|
24
|
+
count?: number;
|
|
25
|
+
totalResults?: number;
|
|
26
|
+
message?: string;
|
|
27
|
+
status?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extracts an ApiResult from an SDK response, preserving envelope metadata.
|
|
31
|
+
* Use this for single-item endpoints where `data` is a single object.
|
|
32
|
+
*/
|
|
33
|
+
export declare function toApiResult<T>(response: SdkEnvelope): ApiResult<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Extracts a ListResult from an SDK response, preserving envelope metadata.
|
|
36
|
+
* Use this for list endpoints where `data` is an array.
|
|
37
|
+
*/
|
|
38
|
+
export declare function toListResult<T>(response: SdkEnvelope): ListResult<T>;
|
|
39
|
+
export { unwrap, unwrapOr } from "@simpleapps-com/augur-utils";
|
|
40
|
+
export type { SafeActionResult } from "@simpleapps-com/augur-utils";
|
|
41
|
+
import type { SafeActionResult } from "@simpleapps-com/augur-utils";
|
|
42
|
+
/**
|
|
43
|
+
* Wraps an async function call with error handling, returning a
|
|
44
|
+
* `SafeActionResult<T>` instead of throwing.
|
|
45
|
+
*
|
|
46
|
+
* Use this to eliminate try/catch boilerplate in server actions.
|
|
47
|
+
* Reads that go through React Query should NOT use this — let errors
|
|
48
|
+
* propagate so React Query can handle retries and error state.
|
|
49
|
+
*
|
|
50
|
+
* @param fn — The async function to execute
|
|
51
|
+
* @param onError — Optional callback for logging/reporting
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const result = await safeAction(
|
|
56
|
+
* () => actions.commerce.addToCart(cartId, items),
|
|
57
|
+
* );
|
|
58
|
+
* if (result.ok) {
|
|
59
|
+
* // result.data is the response data (undefined for void actions)
|
|
60
|
+
* } else {
|
|
61
|
+
* // result.error is the error message
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function safeAction<T>(fn: () => Promise<T>, onError?: (error: Error) => void): Promise<SafeActionResult<T>>;
|
|
66
|
+
//# sourceMappingURL=sdk-call.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-call.d.ts","sourceRoot":"","sources":["../src/sdk-call.ts"],"names":[],"mappings":"AACA,YAAY,EACV,cAAc,EACd,YAAY,EACZ,SAAS,EACT,UAAU,GACX,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExE;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,OAAO,CAAC,KAAK,SAAS,OAAO,EAAE,EAAE,OAAO,EAC5D,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,EAC5C,GAAG,IAAI,EAAE,KAAK,GACb,OAAO,CAAC,OAAO,CAAC,CAElB;AAED,gEAAgE;AAChE,UAAU,WAAW;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC,CAAC,CASlE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CASpE;AAGD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC/D,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAC/B,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAS9B"}
|