@riverbankcms/sdk 0.6.1 → 0.7.2
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 +175 -0
- package/dist/cli/index.js +42 -95
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init-docs/content/agents-section.md +50 -0
- package/dist/cli/init-docs/content/cli-reference.md +574 -0
- package/dist/cli/init-docs/content/content-management.md +384 -0
- package/dist/cli/init-docs/content/context-brand.md +125 -0
- package/dist/cli/init-docs/content/context-brief.md +77 -0
- package/dist/cli/init-docs/content/context-knowledge.md +111 -0
- package/dist/cli/init-docs/content/getting-started.md +130 -0
- package/dist/cli/init-docs/content/site-workflows-readme.md +96 -0
- package/dist/cli/init-docs/content/workflow-add-block.md +228 -0
- package/dist/cli/init-docs/content/workflow-create-page.md +193 -0
- package/dist/cli/init-docs/content/workflow-publish.md +280 -0
- package/dist/client/client.d.mts +2 -2
- package/dist/client/client.d.ts +2 -2
- package/dist/client/client.js +536 -71
- package/dist/client/client.js.map +1 -1
- package/dist/client/client.mjs +536 -78
- package/dist/client/client.mjs.map +1 -1
- package/dist/client/hooks.d.mts +2 -2
- package/dist/client/hooks.d.ts +2 -2
- package/dist/client/usePage-C9tJpuKa.d.mts +6813 -0
- package/dist/client/usePage-Db9kzA41.d.ts +6813 -0
- package/dist/server/{Layout-wBtJLTVX.d.ts → Layout-Ce7PU9I5.d.ts} +1 -1
- package/dist/server/{Layout-B7cvis7r.d.mts → Layout-WllR8Zug.d.mts} +1 -1
- package/dist/server/{chunk-I7ZR2WO3.mjs → chunk-5JT452F2.mjs} +537 -76
- package/dist/server/chunk-5JT452F2.mjs.map +1 -0
- package/dist/server/{chunk-Z5ZA6Q4D.mjs → chunk-74XUVNOO.mjs} +5 -3
- package/dist/server/chunk-74XUVNOO.mjs.map +1 -0
- package/dist/server/{chunk-3B364WO2.js → chunk-7BVRA5MY.js} +4 -49
- package/dist/server/chunk-7BVRA5MY.js.map +1 -0
- package/dist/server/chunk-AET56TQX.mjs +45 -0
- package/dist/server/chunk-AET56TQX.mjs.map +1 -0
- package/dist/server/chunk-ARNCLSQT.mjs +52 -0
- package/dist/server/chunk-ARNCLSQT.mjs.map +1 -0
- package/dist/server/chunk-BNQV3PXP.js +69 -0
- package/dist/server/chunk-BNQV3PXP.js.map +1 -0
- package/dist/server/{chunk-IVHIQFJH.js → chunk-HMENX4Y7.js} +543 -82
- package/dist/server/chunk-HMENX4Y7.js.map +1 -0
- package/dist/server/{chunk-I2D7KOEA.js → chunk-JWRNMNWI.js} +5 -3
- package/dist/server/chunk-JWRNMNWI.js.map +1 -0
- package/dist/server/chunk-LQUKXIW7.mjs +13 -0
- package/dist/server/chunk-LQUKXIW7.mjs.map +1 -0
- package/dist/server/{chunk-XXFF4RVR.mjs → chunk-RBJFXNDM.mjs} +1 -46
- package/dist/server/chunk-RBJFXNDM.mjs.map +1 -0
- package/dist/server/chunk-SWYWZT3L.mjs +69 -0
- package/dist/server/chunk-SWYWZT3L.mjs.map +1 -0
- package/dist/server/chunk-T26N3P26.js +52 -0
- package/dist/server/chunk-T26N3P26.js.map +1 -0
- package/dist/server/chunk-VODFQMUW.js +45 -0
- package/dist/server/chunk-VODFQMUW.js.map +1 -0
- package/dist/server/chunk-WYNEYDXO.js +13 -0
- package/dist/server/chunk-WYNEYDXO.js.map +1 -0
- package/dist/server/{components-CICSJyp_.d.ts → components--LT61IKp.d.ts} +2 -2
- package/dist/server/{components-CMMwDXTW.d.mts → components-RPzRQve6.d.mts} +2 -2
- package/dist/server/components.d.mts +4 -4
- package/dist/server/components.d.ts +4 -4
- package/dist/server/components.js +5 -4
- package/dist/server/components.js.map +1 -1
- package/dist/server/components.mjs +5 -4
- package/dist/server/config-validation.js +0 -1
- package/dist/server/config-validation.js.map +1 -1
- package/dist/server/config-validation.mjs +0 -1
- package/dist/server/config.js +0 -1
- package/dist/server/config.js.map +1 -1
- package/dist/server/config.mjs +0 -1
- package/dist/server/config.mjs.map +1 -1
- package/dist/server/data.d.mts +1 -1
- package/dist/server/data.d.ts +1 -1
- package/dist/server/data.js +0 -1
- package/dist/server/data.js.map +1 -1
- package/dist/server/data.mjs +0 -1
- package/dist/server/env.d.mts +23 -0
- package/dist/server/env.d.ts +23 -0
- package/dist/server/env.js +7 -0
- package/dist/server/env.js.map +1 -0
- package/dist/server/env.mjs +7 -0
- package/dist/server/index-BL66CU6d.d.mts +130 -0
- package/dist/server/{index-Bucs6UqG.d.mts → index-Bkva0WAj.d.mts} +1 -1
- package/dist/server/index-CJk9iQQW.d.ts +130 -0
- package/dist/server/{index-Cp7tJuRt.d.ts → index-CSBWKA3r.d.ts} +1 -1
- package/dist/server/index.d.mts +3 -3
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.js +2 -3
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +1 -2
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/{loadContent-Buvmudee.d.ts → loadContent-CXUWMuzY.d.ts} +11 -3
- package/dist/server/{loadContent-BS-3wesN.d.mts → loadContent-F_tAS0Nl.d.mts} +11 -3
- package/dist/server/{loadPage-IDGVDFBB.js → loadPage-6I7F6GRF.js} +1 -2
- package/dist/server/loadPage-6I7F6GRF.js.map +1 -0
- package/dist/server/{loadPage-B8mQUUSo.d.mts → loadPage-CxlYLe5K.d.mts} +1 -1
- package/dist/server/{loadPage-DNQTTRHL.mjs → loadPage-JI2SML4M.mjs} +1 -2
- package/dist/server/{loadPage-DP3nrHBi.d.ts → loadPage-i2r-X5b9.d.ts} +1 -1
- package/dist/server/metadata.d.mts +8 -135
- package/dist/server/metadata.d.ts +8 -135
- package/dist/server/metadata.js +4 -65
- package/dist/server/metadata.js.map +1 -1
- package/dist/server/metadata.mjs +4 -65
- package/dist/server/metadata.mjs.map +1 -1
- package/dist/server/navigation.js +0 -1
- package/dist/server/navigation.js.map +1 -1
- package/dist/server/navigation.mjs +0 -1
- package/dist/server/next/revalidate.d.mts +66 -0
- package/dist/server/next/revalidate.d.ts +66 -0
- package/dist/server/next/revalidate.js +59 -0
- package/dist/server/next/revalidate.js.map +1 -0
- package/dist/server/next/revalidate.mjs +59 -0
- package/dist/server/next/revalidate.mjs.map +1 -0
- package/dist/server/next/tags.d.mts +78 -0
- package/dist/server/next/tags.d.ts +78 -0
- package/dist/server/next/tags.js +34 -0
- package/dist/server/next/tags.js.map +1 -0
- package/dist/server/next/tags.mjs +34 -0
- package/dist/server/next/tags.mjs.map +1 -0
- package/dist/server/next.d.mts +432 -0
- package/dist/server/next.d.ts +432 -0
- package/dist/server/next.js +217 -0
- package/dist/server/next.js.map +1 -0
- package/dist/server/next.mjs +217 -0
- package/dist/server/next.mjs.map +1 -0
- package/dist/server/rendering/server.d.mts +3 -3
- package/dist/server/rendering/server.d.ts +3 -3
- package/dist/server/rendering/server.js +5 -4
- package/dist/server/rendering/server.js.map +1 -1
- package/dist/server/rendering/server.mjs +5 -4
- package/dist/server/rendering.d.mts +6 -6
- package/dist/server/rendering.d.ts +6 -6
- package/dist/server/rendering.js +7 -6
- package/dist/server/rendering.js.map +1 -1
- package/dist/server/rendering.mjs +9 -8
- package/dist/server/routing.d.mts +2 -2
- package/dist/server/routing.d.ts +2 -2
- package/dist/server/routing.js +2 -4
- package/dist/server/routing.js.map +1 -1
- package/dist/server/routing.mjs +1 -3
- package/dist/server/routing.mjs.map +1 -1
- package/dist/server/server.d.mts +4 -4
- package/dist/server/server.d.ts +4 -4
- package/dist/server/server.js +4 -5
- package/dist/server/server.js.map +1 -1
- package/dist/server/server.mjs +5 -6
- package/dist/server/theme-bridge.js +0 -1
- package/dist/server/theme-bridge.js.map +1 -1
- package/dist/server/theme-bridge.mjs +0 -1
- package/dist/server/theme-bridge.mjs.map +1 -1
- package/dist/server/theme.js +1 -3
- package/dist/server/theme.js.map +1 -1
- package/dist/server/theme.mjs +0 -2
- package/dist/server/theme.mjs.map +1 -1
- package/dist/server/{types-BvcJU7zk.d.ts → types-DnkRh0UL.d.ts} +118 -9
- package/dist/server/{types-1cLz0vnq.d.mts → types-MF2AWoKv.d.mts} +118 -9
- package/dist/server/webhooks.d.mts +75 -0
- package/dist/server/webhooks.d.ts +75 -0
- package/dist/server/webhooks.js +11 -0
- package/dist/server/webhooks.js.map +1 -0
- package/dist/server/webhooks.mjs +11 -0
- package/dist/server/webhooks.mjs.map +1 -0
- package/package.json +33 -1
- package/dist/server/chunk-3B364WO2.js.map +0 -1
- package/dist/server/chunk-BJTO5JO5.mjs +0 -11
- package/dist/server/chunk-DGUM43GV.js +0 -11
- package/dist/server/chunk-DGUM43GV.js.map +0 -1
- package/dist/server/chunk-I2D7KOEA.js.map +0 -1
- package/dist/server/chunk-I7ZR2WO3.mjs.map +0 -1
- package/dist/server/chunk-IVHIQFJH.js.map +0 -1
- package/dist/server/chunk-XXFF4RVR.mjs.map +0 -1
- package/dist/server/chunk-Z5ZA6Q4D.mjs.map +0 -1
- package/dist/server/loadPage-IDGVDFBB.js.map +0 -1
- /package/dist/server/{chunk-BJTO5JO5.mjs.map → env.mjs.map} +0 -0
- /package/dist/server/{loadPage-DNQTTRHL.mjs.map → loadPage-JI2SML4M.mjs.map} +0 -0
package/dist/server/theme.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
-
|
|
3
|
-
// src/theme/index.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/theme/index.ts
|
|
4
2
|
function applyTheme(theme, element) {
|
|
5
3
|
const targetElement = _nullishCoalesce(element, () => ( (typeof document !== "undefined" ? document.documentElement : null)));
|
|
6
4
|
if (!targetElement) {
|
package/dist/server/theme.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/will/Projects/Business/cms/builder/packages/sdk/dist/server/theme.js","../../src/theme/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"sources":["/Users/will/Projects/Business/cms/builder/packages/sdk/dist/server/theme.js","../../src/theme/index.ts"],"names":[],"mappings":"AAAA;ACkBO,SAAS,UAAA,CAAW,KAAA,EAAgC,OAAA,EAA6B;AACtF,EAAA,MAAM,cAAA,mBAAgB,OAAA,UAAA,CAAY,OAAO,SAAA,IAAa,YAAA,EAAc,QAAA,CAAS,gBAAA,EAAkB,IAAA,GAAA;AAE/F,EAAA,GAAA,CAAI,CAAC,aAAA,EAAe;AAClB,IAAA,OAAA,CAAQ,IAAA,CAAK,yDAAyD,CAAA;AACtE,IAAA,MAAA;AAAA,EACF;AAIA,EAAA,aAAA,CAAc,YAAA,CAAa,oBAAA,EAAsB,IAAA,CAAK,SAAA,CAAU,KAAK,CAAC,CAAA;AAIxE;AAiBO,SAAS,WAAA,CAAY,QAAA,EAAmC,CAAC,CAAA,EAA4B;AAI1F,EAAA,OAAO,EAAE,GAAG,QAAQ,CAAA;AACtB;AD1CA;AACE;AACA;AACF,mEAAC","file":"/Users/will/Projects/Business/cms/builder/packages/sdk/dist/server/theme.js","sourcesContent":[null,"/**\n * Theme utilities for Riverbank CMS\n *\n * These utilities help you work with Builder themes in your application.\n */\n\n/**\n * Apply a Builder theme to the DOM by injecting CSS variables\n *\n * @param theme - The theme object from Riverbank CMS\n * @param element - The element to apply the theme to (default: document.documentElement)\n *\n * @example\n * ```ts\n * const site = await client.getSite({ slug: 'my-site' });\n * applyTheme(site.theme);\n * ```\n */\nexport function applyTheme(theme: Record<string, unknown>, element?: HTMLElement): void {\n const targetElement = element ?? (typeof document !== 'undefined' ? document.documentElement : null);\n\n if (!targetElement) {\n console.warn('[Builder SDK] Cannot apply theme: no document available');\n return;\n }\n\n // Theme application will use the theme runtime from @riverbankcms/blocks\n // For now, we'll set a data attribute that the theme runtime can pick up\n targetElement.setAttribute('data-builder-theme', JSON.stringify(theme));\n\n // Note: Full CSS variable injection will be implemented once we\n // finalize the theme transformation API from @riverbankcms/blocks\n}\n\n/**\n * Create a theme object with type-safe defaults\n *\n * @param partial - Partial theme configuration\n * @returns Complete theme object\n *\n * @example\n * ```ts\n * const customTheme = createTheme({\n * colors: {\n * primary: '#007bff',\n * },\n * });\n * ```\n */\nexport function createTheme(partial: Record<string, unknown> = {}): Record<string, unknown> {\n // For now, return the partial as-is\n // Full theme creation with defaults will be implemented once we\n // finalize the theme structure from @riverbankcms/blocks\n return { ...partial };\n}\n\n/**\n * Re-export theme types from @riverbankcms/blocks when available\n */\nexport type Theme = Record<string, unknown>;\n"]}
|
package/dist/server/theme.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/theme/index.ts"],"sourcesContent":["/**\n * Theme utilities for Riverbank CMS\n *\n * These utilities help you work with Builder themes in your application.\n */\n\n/**\n * Apply a Builder theme to the DOM by injecting CSS variables\n *\n * @param theme - The theme object from Riverbank CMS\n * @param element - The element to apply the theme to (default: document.documentElement)\n *\n * @example\n * ```ts\n * const site = await client.getSite({ slug: 'my-site' });\n * applyTheme(site.theme);\n * ```\n */\nexport function applyTheme(theme: Record<string, unknown>, element?: HTMLElement): void {\n const targetElement = element ?? (typeof document !== 'undefined' ? document.documentElement : null);\n\n if (!targetElement) {\n console.warn('[Builder SDK] Cannot apply theme: no document available');\n return;\n }\n\n // Theme application will use the theme runtime from @riverbankcms/blocks\n // For now, we'll set a data attribute that the theme runtime can pick up\n targetElement.setAttribute('data-builder-theme', JSON.stringify(theme));\n\n // Note: Full CSS variable injection will be implemented once we\n // finalize the theme transformation API from @riverbankcms/blocks\n}\n\n/**\n * Create a theme object with type-safe defaults\n *\n * @param partial - Partial theme configuration\n * @returns Complete theme object\n *\n * @example\n * ```ts\n * const customTheme = createTheme({\n * colors: {\n * primary: '#007bff',\n * },\n * });\n * ```\n */\nexport function createTheme(partial: Record<string, unknown> = {}): Record<string, unknown> {\n // For now, return the partial as-is\n // Full theme creation with defaults will be implemented once we\n // finalize the theme structure from @riverbankcms/blocks\n return { ...partial };\n}\n\n/**\n * Re-export theme types from @riverbankcms/blocks when available\n */\nexport type Theme = Record<string, unknown>;\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/theme/index.ts"],"sourcesContent":["/**\n * Theme utilities for Riverbank CMS\n *\n * These utilities help you work with Builder themes in your application.\n */\n\n/**\n * Apply a Builder theme to the DOM by injecting CSS variables\n *\n * @param theme - The theme object from Riverbank CMS\n * @param element - The element to apply the theme to (default: document.documentElement)\n *\n * @example\n * ```ts\n * const site = await client.getSite({ slug: 'my-site' });\n * applyTheme(site.theme);\n * ```\n */\nexport function applyTheme(theme: Record<string, unknown>, element?: HTMLElement): void {\n const targetElement = element ?? (typeof document !== 'undefined' ? document.documentElement : null);\n\n if (!targetElement) {\n console.warn('[Builder SDK] Cannot apply theme: no document available');\n return;\n }\n\n // Theme application will use the theme runtime from @riverbankcms/blocks\n // For now, we'll set a data attribute that the theme runtime can pick up\n targetElement.setAttribute('data-builder-theme', JSON.stringify(theme));\n\n // Note: Full CSS variable injection will be implemented once we\n // finalize the theme transformation API from @riverbankcms/blocks\n}\n\n/**\n * Create a theme object with type-safe defaults\n *\n * @param partial - Partial theme configuration\n * @returns Complete theme object\n *\n * @example\n * ```ts\n * const customTheme = createTheme({\n * colors: {\n * primary: '#007bff',\n * },\n * });\n * ```\n */\nexport function createTheme(partial: Record<string, unknown> = {}): Record<string, unknown> {\n // For now, return the partial as-is\n // Full theme creation with defaults will be implemented once we\n // finalize the theme structure from @riverbankcms/blocks\n return { ...partial };\n}\n\n/**\n * Re-export theme types from @riverbankcms/blocks when available\n */\nexport type Theme = Record<string, unknown>;\n"],"mappings":";AAkBO,SAAS,WAAW,OAAgC,SAA6B;AACtF,QAAM,gBAAgB,YAAY,OAAO,aAAa,cAAc,SAAS,kBAAkB;AAE/F,MAAI,CAAC,eAAe;AAClB,YAAQ,KAAK,yDAAyD;AACtE;AAAA,EACF;AAIA,gBAAc,aAAa,sBAAsB,KAAK,UAAU,KAAK,CAAC;AAIxE;AAiBO,SAAS,YAAY,UAAmC,CAAC,GAA4B;AAI1F,SAAO,EAAE,GAAG,QAAQ;AACtB;","names":[]}
|
|
@@ -33,10 +33,17 @@ interface PaginationMeta {
|
|
|
33
33
|
type EntriesResponseWithMeta = {
|
|
34
34
|
entries: EntriesResponse['entries'];
|
|
35
35
|
} & PaginationMeta;
|
|
36
|
+
/**
|
|
37
|
+
* Common options for all SDK methods
|
|
38
|
+
*/
|
|
39
|
+
interface SdkMethodOptions {
|
|
40
|
+
/** AbortSignal for cancelling the request */
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}
|
|
36
43
|
/**
|
|
37
44
|
* Base parameters for getEntries - shared across all overloads
|
|
38
45
|
*/
|
|
39
|
-
interface GetEntriesBaseParams {
|
|
46
|
+
interface GetEntriesBaseParams extends SdkMethodOptions {
|
|
40
47
|
/** The site ID */
|
|
41
48
|
siteId: string;
|
|
42
49
|
/** The content type key (e.g., 'blog-post', 'product') */
|
|
@@ -54,6 +61,92 @@ interface GetEntriesBaseParams {
|
|
|
54
61
|
/** Entry IDs to fetch when mode is 'manual' */
|
|
55
62
|
entryIds?: string[];
|
|
56
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Source of the data returned by a resilient fetch
|
|
66
|
+
*/
|
|
67
|
+
type ResilienceSource = 'live' | 'cache' | 'stale' | 'prebuild' | 'error';
|
|
68
|
+
/**
|
|
69
|
+
* Status information from a resilient fetch operation
|
|
70
|
+
*/
|
|
71
|
+
interface ResilienceStatus {
|
|
72
|
+
/** Where the data came from */
|
|
73
|
+
source: ResilienceSource;
|
|
74
|
+
/** Whether this was a preview request */
|
|
75
|
+
isPreview: boolean;
|
|
76
|
+
/** Cache key used for this request */
|
|
77
|
+
cacheKey?: string;
|
|
78
|
+
/** Error details if fetch failed */
|
|
79
|
+
error?: {
|
|
80
|
+
code?: string;
|
|
81
|
+
message: string;
|
|
82
|
+
};
|
|
83
|
+
/** Seconds since cache TTL expired (when source='stale') */
|
|
84
|
+
staleAgeSec?: number;
|
|
85
|
+
/** Seconds since prebuild was generated (when source='prebuild') */
|
|
86
|
+
prebuildAgeSec?: number;
|
|
87
|
+
/** Circuit breaker state at time of request */
|
|
88
|
+
circuit: CircuitState;
|
|
89
|
+
/** Correlation ID for debugging */
|
|
90
|
+
requestId?: string;
|
|
91
|
+
/** Total request duration including retries (ms) */
|
|
92
|
+
durationMs?: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Circuit breaker state information
|
|
96
|
+
*/
|
|
97
|
+
interface CircuitState {
|
|
98
|
+
state: 'closed' | 'open' | 'half-open';
|
|
99
|
+
failureCount: number;
|
|
100
|
+
/** Timestamp when circuit will transition from open to half-open */
|
|
101
|
+
openUntil?: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Retry configuration
|
|
105
|
+
*/
|
|
106
|
+
interface RetryConfig {
|
|
107
|
+
/** Maximum number of attempts (including initial) */
|
|
108
|
+
maxAttempts?: number;
|
|
109
|
+
/** Base delay between retries in ms */
|
|
110
|
+
baseDelayMs?: number;
|
|
111
|
+
/** Maximum delay between retries in ms */
|
|
112
|
+
maxDelayMs?: number;
|
|
113
|
+
/** Jitter strategy: 'full' adds randomization, 'none' uses exact delays */
|
|
114
|
+
jitter?: 'full' | 'none';
|
|
115
|
+
/** Custom function to determine if an error should be retried */
|
|
116
|
+
retryOn?: (error: Error, statusCode?: number) => boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Circuit breaker configuration
|
|
120
|
+
*/
|
|
121
|
+
interface CircuitBreakerConfig {
|
|
122
|
+
/** Number of failures before opening circuit */
|
|
123
|
+
failureThreshold?: number;
|
|
124
|
+
/** Time in ms before attempting to close circuit */
|
|
125
|
+
resetTimeoutMs?: number;
|
|
126
|
+
/** Number of successful requests needed to close from half-open */
|
|
127
|
+
halfOpenMaxRequests?: number;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Resilience configuration for the SDK client
|
|
131
|
+
*/
|
|
132
|
+
interface ResilienceConfig {
|
|
133
|
+
/** Enable resilience features (default: true) */
|
|
134
|
+
enabled?: boolean;
|
|
135
|
+
/** Serve stale data on fetch failure (default: true) */
|
|
136
|
+
staleIfError?: boolean;
|
|
137
|
+
/** Seconds AFTER cache TTL expires that stale data remains valid (default: 300) */
|
|
138
|
+
staleTtlSec?: number;
|
|
139
|
+
/** Request timeout in ms (default: 8000 server, 5000 browser) */
|
|
140
|
+
requestTimeoutMs?: number;
|
|
141
|
+
/** Retry configuration */
|
|
142
|
+
retry?: RetryConfig;
|
|
143
|
+
/** Circuit breaker configuration */
|
|
144
|
+
circuitBreaker?: CircuitBreakerConfig;
|
|
145
|
+
/** Callback fired on every request with status information */
|
|
146
|
+
onStatusChange?: (status: ResilienceStatus) => void;
|
|
147
|
+
/** Callback fired only when transitioning into/out of degraded mode */
|
|
148
|
+
onDegradedMode?: (degraded: boolean, status: ResilienceStatus) => void;
|
|
149
|
+
}
|
|
57
150
|
/**
|
|
58
151
|
* Configuration for creating a Riverbank CMS client
|
|
59
152
|
*/
|
|
@@ -85,6 +178,10 @@ interface RiverbankClientConfig {
|
|
|
85
178
|
*/
|
|
86
179
|
maxSize?: number;
|
|
87
180
|
};
|
|
181
|
+
/**
|
|
182
|
+
* Resilience configuration for error handling, retries, and fallbacks
|
|
183
|
+
*/
|
|
184
|
+
resilience?: ResilienceConfig;
|
|
88
185
|
}
|
|
89
186
|
/**
|
|
90
187
|
* Riverbank CMS client interface
|
|
@@ -97,7 +194,7 @@ interface RiverbankClient {
|
|
|
97
194
|
slug?: string;
|
|
98
195
|
domain?: string;
|
|
99
196
|
id?: string;
|
|
100
|
-
}): Promise<SiteResponse>;
|
|
197
|
+
} & SdkMethodOptions): Promise<SiteResponse>;
|
|
101
198
|
/**
|
|
102
199
|
* Fetch a specific page by path
|
|
103
200
|
*
|
|
@@ -107,7 +204,7 @@ interface RiverbankClient {
|
|
|
107
204
|
siteId: string;
|
|
108
205
|
path: string;
|
|
109
206
|
preview?: boolean;
|
|
110
|
-
}): Promise<PageResponse>;
|
|
207
|
+
} & SdkMethodOptions): Promise<PageResponse>;
|
|
111
208
|
/**
|
|
112
209
|
* Fetch published content entries with optional pagination, sorting, and preview mode
|
|
113
210
|
*
|
|
@@ -168,20 +265,20 @@ interface RiverbankClient {
|
|
|
168
265
|
siteId: string;
|
|
169
266
|
contentType: string;
|
|
170
267
|
slug: string;
|
|
171
|
-
}): Promise<EntryResponse>;
|
|
268
|
+
} & SdkMethodOptions): Promise<EntryResponse>;
|
|
172
269
|
/**
|
|
173
270
|
* Fetch a public form definition by ID
|
|
174
271
|
*/
|
|
175
272
|
getPublicFormById(params: {
|
|
176
273
|
formId: string;
|
|
177
|
-
}): Promise<PublicFormResponse>;
|
|
274
|
+
} & SdkMethodOptions): Promise<PublicFormResponse>;
|
|
178
275
|
/**
|
|
179
276
|
* Fetch public booking services for a site
|
|
180
277
|
*/
|
|
181
278
|
getPublicBookingServices(params: {
|
|
182
279
|
siteId: string;
|
|
183
280
|
ids?: string;
|
|
184
|
-
}): Promise<PublicBookingServicesResponse>;
|
|
281
|
+
} & SdkMethodOptions): Promise<PublicBookingServicesResponse>;
|
|
185
282
|
/**
|
|
186
283
|
* List public events for a site (optionally time-filtered)
|
|
187
284
|
*/
|
|
@@ -191,7 +288,7 @@ interface RiverbankClient {
|
|
|
191
288
|
from?: string;
|
|
192
289
|
to?: string;
|
|
193
290
|
stage?: string;
|
|
194
|
-
}): Promise<PublicEventsResponse>;
|
|
291
|
+
} & SdkMethodOptions): Promise<PublicEventsResponse>;
|
|
195
292
|
/**
|
|
196
293
|
* Resolve an event occurrence by URL segment (date or UUID)
|
|
197
294
|
*
|
|
@@ -220,7 +317,7 @@ interface RiverbankClient {
|
|
|
220
317
|
siteId: string;
|
|
221
318
|
entryId: string;
|
|
222
319
|
segment: string;
|
|
223
|
-
}): Promise<ResolveEventOccurrenceResponse>;
|
|
320
|
+
} & SdkMethodOptions): Promise<ResolveEventOccurrenceResponse>;
|
|
224
321
|
/**
|
|
225
322
|
* Check if a path has a configured redirect rule
|
|
226
323
|
*
|
|
@@ -241,11 +338,23 @@ interface RiverbankClient {
|
|
|
241
338
|
checkRedirect(params: {
|
|
242
339
|
siteId: string;
|
|
243
340
|
path: string;
|
|
244
|
-
}): Promise<CheckRedirectResponse>;
|
|
341
|
+
} & SdkMethodOptions): Promise<CheckRedirectResponse>;
|
|
245
342
|
/**
|
|
246
343
|
* Force clear the cache
|
|
247
344
|
*/
|
|
248
345
|
clearCache(): void;
|
|
346
|
+
/**
|
|
347
|
+
* Get the status from the most recently emitted request
|
|
348
|
+
*
|
|
349
|
+
* Note: With concurrent requests, this returns the last status emitted,
|
|
350
|
+
* which may not be from the request you're interested in. For reliable
|
|
351
|
+
* per-request status, use the onStatusChange callback instead.
|
|
352
|
+
*/
|
|
353
|
+
getLastEmittedStatus(): ResilienceStatus | null;
|
|
354
|
+
/**
|
|
355
|
+
* Get the current circuit breaker state
|
|
356
|
+
*/
|
|
357
|
+
getCircuitState(): CircuitState;
|
|
249
358
|
}
|
|
250
359
|
|
|
251
360
|
export type { EntriesResponse as E, PageResponse as P, RiverbankClient as R, SiteResponse as S, RiverbankClientConfig as a, EntryResponse as b, EntriesResponseWithMeta as c, PaginationMeta as d, ResolveEventOccurrenceResponse as e };
|
|
@@ -33,10 +33,17 @@ interface PaginationMeta {
|
|
|
33
33
|
type EntriesResponseWithMeta = {
|
|
34
34
|
entries: EntriesResponse['entries'];
|
|
35
35
|
} & PaginationMeta;
|
|
36
|
+
/**
|
|
37
|
+
* Common options for all SDK methods
|
|
38
|
+
*/
|
|
39
|
+
interface SdkMethodOptions {
|
|
40
|
+
/** AbortSignal for cancelling the request */
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}
|
|
36
43
|
/**
|
|
37
44
|
* Base parameters for getEntries - shared across all overloads
|
|
38
45
|
*/
|
|
39
|
-
interface GetEntriesBaseParams {
|
|
46
|
+
interface GetEntriesBaseParams extends SdkMethodOptions {
|
|
40
47
|
/** The site ID */
|
|
41
48
|
siteId: string;
|
|
42
49
|
/** The content type key (e.g., 'blog-post', 'product') */
|
|
@@ -54,6 +61,92 @@ interface GetEntriesBaseParams {
|
|
|
54
61
|
/** Entry IDs to fetch when mode is 'manual' */
|
|
55
62
|
entryIds?: string[];
|
|
56
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Source of the data returned by a resilient fetch
|
|
66
|
+
*/
|
|
67
|
+
type ResilienceSource = 'live' | 'cache' | 'stale' | 'prebuild' | 'error';
|
|
68
|
+
/**
|
|
69
|
+
* Status information from a resilient fetch operation
|
|
70
|
+
*/
|
|
71
|
+
interface ResilienceStatus {
|
|
72
|
+
/** Where the data came from */
|
|
73
|
+
source: ResilienceSource;
|
|
74
|
+
/** Whether this was a preview request */
|
|
75
|
+
isPreview: boolean;
|
|
76
|
+
/** Cache key used for this request */
|
|
77
|
+
cacheKey?: string;
|
|
78
|
+
/** Error details if fetch failed */
|
|
79
|
+
error?: {
|
|
80
|
+
code?: string;
|
|
81
|
+
message: string;
|
|
82
|
+
};
|
|
83
|
+
/** Seconds since cache TTL expired (when source='stale') */
|
|
84
|
+
staleAgeSec?: number;
|
|
85
|
+
/** Seconds since prebuild was generated (when source='prebuild') */
|
|
86
|
+
prebuildAgeSec?: number;
|
|
87
|
+
/** Circuit breaker state at time of request */
|
|
88
|
+
circuit: CircuitState;
|
|
89
|
+
/** Correlation ID for debugging */
|
|
90
|
+
requestId?: string;
|
|
91
|
+
/** Total request duration including retries (ms) */
|
|
92
|
+
durationMs?: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Circuit breaker state information
|
|
96
|
+
*/
|
|
97
|
+
interface CircuitState {
|
|
98
|
+
state: 'closed' | 'open' | 'half-open';
|
|
99
|
+
failureCount: number;
|
|
100
|
+
/** Timestamp when circuit will transition from open to half-open */
|
|
101
|
+
openUntil?: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Retry configuration
|
|
105
|
+
*/
|
|
106
|
+
interface RetryConfig {
|
|
107
|
+
/** Maximum number of attempts (including initial) */
|
|
108
|
+
maxAttempts?: number;
|
|
109
|
+
/** Base delay between retries in ms */
|
|
110
|
+
baseDelayMs?: number;
|
|
111
|
+
/** Maximum delay between retries in ms */
|
|
112
|
+
maxDelayMs?: number;
|
|
113
|
+
/** Jitter strategy: 'full' adds randomization, 'none' uses exact delays */
|
|
114
|
+
jitter?: 'full' | 'none';
|
|
115
|
+
/** Custom function to determine if an error should be retried */
|
|
116
|
+
retryOn?: (error: Error, statusCode?: number) => boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Circuit breaker configuration
|
|
120
|
+
*/
|
|
121
|
+
interface CircuitBreakerConfig {
|
|
122
|
+
/** Number of failures before opening circuit */
|
|
123
|
+
failureThreshold?: number;
|
|
124
|
+
/** Time in ms before attempting to close circuit */
|
|
125
|
+
resetTimeoutMs?: number;
|
|
126
|
+
/** Number of successful requests needed to close from half-open */
|
|
127
|
+
halfOpenMaxRequests?: number;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Resilience configuration for the SDK client
|
|
131
|
+
*/
|
|
132
|
+
interface ResilienceConfig {
|
|
133
|
+
/** Enable resilience features (default: true) */
|
|
134
|
+
enabled?: boolean;
|
|
135
|
+
/** Serve stale data on fetch failure (default: true) */
|
|
136
|
+
staleIfError?: boolean;
|
|
137
|
+
/** Seconds AFTER cache TTL expires that stale data remains valid (default: 300) */
|
|
138
|
+
staleTtlSec?: number;
|
|
139
|
+
/** Request timeout in ms (default: 8000 server, 5000 browser) */
|
|
140
|
+
requestTimeoutMs?: number;
|
|
141
|
+
/** Retry configuration */
|
|
142
|
+
retry?: RetryConfig;
|
|
143
|
+
/** Circuit breaker configuration */
|
|
144
|
+
circuitBreaker?: CircuitBreakerConfig;
|
|
145
|
+
/** Callback fired on every request with status information */
|
|
146
|
+
onStatusChange?: (status: ResilienceStatus) => void;
|
|
147
|
+
/** Callback fired only when transitioning into/out of degraded mode */
|
|
148
|
+
onDegradedMode?: (degraded: boolean, status: ResilienceStatus) => void;
|
|
149
|
+
}
|
|
57
150
|
/**
|
|
58
151
|
* Configuration for creating a Riverbank CMS client
|
|
59
152
|
*/
|
|
@@ -85,6 +178,10 @@ interface RiverbankClientConfig {
|
|
|
85
178
|
*/
|
|
86
179
|
maxSize?: number;
|
|
87
180
|
};
|
|
181
|
+
/**
|
|
182
|
+
* Resilience configuration for error handling, retries, and fallbacks
|
|
183
|
+
*/
|
|
184
|
+
resilience?: ResilienceConfig;
|
|
88
185
|
}
|
|
89
186
|
/**
|
|
90
187
|
* Riverbank CMS client interface
|
|
@@ -97,7 +194,7 @@ interface RiverbankClient {
|
|
|
97
194
|
slug?: string;
|
|
98
195
|
domain?: string;
|
|
99
196
|
id?: string;
|
|
100
|
-
}): Promise<SiteResponse>;
|
|
197
|
+
} & SdkMethodOptions): Promise<SiteResponse>;
|
|
101
198
|
/**
|
|
102
199
|
* Fetch a specific page by path
|
|
103
200
|
*
|
|
@@ -107,7 +204,7 @@ interface RiverbankClient {
|
|
|
107
204
|
siteId: string;
|
|
108
205
|
path: string;
|
|
109
206
|
preview?: boolean;
|
|
110
|
-
}): Promise<PageResponse>;
|
|
207
|
+
} & SdkMethodOptions): Promise<PageResponse>;
|
|
111
208
|
/**
|
|
112
209
|
* Fetch published content entries with optional pagination, sorting, and preview mode
|
|
113
210
|
*
|
|
@@ -168,20 +265,20 @@ interface RiverbankClient {
|
|
|
168
265
|
siteId: string;
|
|
169
266
|
contentType: string;
|
|
170
267
|
slug: string;
|
|
171
|
-
}): Promise<EntryResponse>;
|
|
268
|
+
} & SdkMethodOptions): Promise<EntryResponse>;
|
|
172
269
|
/**
|
|
173
270
|
* Fetch a public form definition by ID
|
|
174
271
|
*/
|
|
175
272
|
getPublicFormById(params: {
|
|
176
273
|
formId: string;
|
|
177
|
-
}): Promise<PublicFormResponse>;
|
|
274
|
+
} & SdkMethodOptions): Promise<PublicFormResponse>;
|
|
178
275
|
/**
|
|
179
276
|
* Fetch public booking services for a site
|
|
180
277
|
*/
|
|
181
278
|
getPublicBookingServices(params: {
|
|
182
279
|
siteId: string;
|
|
183
280
|
ids?: string;
|
|
184
|
-
}): Promise<PublicBookingServicesResponse>;
|
|
281
|
+
} & SdkMethodOptions): Promise<PublicBookingServicesResponse>;
|
|
185
282
|
/**
|
|
186
283
|
* List public events for a site (optionally time-filtered)
|
|
187
284
|
*/
|
|
@@ -191,7 +288,7 @@ interface RiverbankClient {
|
|
|
191
288
|
from?: string;
|
|
192
289
|
to?: string;
|
|
193
290
|
stage?: string;
|
|
194
|
-
}): Promise<PublicEventsResponse>;
|
|
291
|
+
} & SdkMethodOptions): Promise<PublicEventsResponse>;
|
|
195
292
|
/**
|
|
196
293
|
* Resolve an event occurrence by URL segment (date or UUID)
|
|
197
294
|
*
|
|
@@ -220,7 +317,7 @@ interface RiverbankClient {
|
|
|
220
317
|
siteId: string;
|
|
221
318
|
entryId: string;
|
|
222
319
|
segment: string;
|
|
223
|
-
}): Promise<ResolveEventOccurrenceResponse>;
|
|
320
|
+
} & SdkMethodOptions): Promise<ResolveEventOccurrenceResponse>;
|
|
224
321
|
/**
|
|
225
322
|
* Check if a path has a configured redirect rule
|
|
226
323
|
*
|
|
@@ -241,11 +338,23 @@ interface RiverbankClient {
|
|
|
241
338
|
checkRedirect(params: {
|
|
242
339
|
siteId: string;
|
|
243
340
|
path: string;
|
|
244
|
-
}): Promise<CheckRedirectResponse>;
|
|
341
|
+
} & SdkMethodOptions): Promise<CheckRedirectResponse>;
|
|
245
342
|
/**
|
|
246
343
|
* Force clear the cache
|
|
247
344
|
*/
|
|
248
345
|
clearCache(): void;
|
|
346
|
+
/**
|
|
347
|
+
* Get the status from the most recently emitted request
|
|
348
|
+
*
|
|
349
|
+
* Note: With concurrent requests, this returns the last status emitted,
|
|
350
|
+
* which may not be from the request you're interested in. For reliable
|
|
351
|
+
* per-request status, use the onStatusChange callback instead.
|
|
352
|
+
*/
|
|
353
|
+
getLastEmittedStatus(): ResilienceStatus | null;
|
|
354
|
+
/**
|
|
355
|
+
* Get the current circuit breaker state
|
|
356
|
+
*/
|
|
357
|
+
getCircuitState(): CircuitState;
|
|
249
358
|
}
|
|
250
359
|
|
|
251
360
|
export type { EntriesResponse as E, PageResponse as P, RiverbankClient as R, SiteResponse as S, RiverbankClientConfig as a, EntryResponse as b, EntriesResponseWithMeta as c, PaginationMeta as d, ResolveEventOccurrenceResponse as e };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Webhook verification utilities for Riverbank SDK
|
|
5
|
+
*
|
|
6
|
+
* Provides framework-agnostic webhook signature verification and payload parsing.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Zod schema for webhook payload validation.
|
|
11
|
+
*/
|
|
12
|
+
declare const WebhookPayloadSchema: z.ZodObject<{
|
|
13
|
+
event: z.ZodString;
|
|
14
|
+
timestamp: z.ZodString;
|
|
15
|
+
siteId: z.ZodString;
|
|
16
|
+
data: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
17
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
/**
|
|
20
|
+
* Webhook payload structure sent by the CMS.
|
|
21
|
+
*/
|
|
22
|
+
type WebhookPayload = z.infer<typeof WebhookPayloadSchema>;
|
|
23
|
+
/**
|
|
24
|
+
* Verify a webhook signature using HMAC-SHA256.
|
|
25
|
+
*
|
|
26
|
+
* Uses timing-safe comparison to prevent timing attacks.
|
|
27
|
+
*
|
|
28
|
+
* @param payload - The raw request body as a string
|
|
29
|
+
* @param signature - The X-Riverbank-Signature header value
|
|
30
|
+
* @param secret - The webhook signing secret (RIVERBANK_WEBHOOK_SECRET)
|
|
31
|
+
* @returns true if signature is valid, false otherwise
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const body = await request.text();
|
|
36
|
+
* const signature = request.headers.get('x-riverbank-signature');
|
|
37
|
+
* const secret = process.env.RIVERBANK_WEBHOOK_SECRET;
|
|
38
|
+
*
|
|
39
|
+
* if (!verifyWebhookSignature(body, signature, secret)) {
|
|
40
|
+
* return new Response('Invalid signature', { status: 401 });
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function verifyWebhookSignature(payload: string, signature: string, secret: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Result type for webhook payload parsing.
|
|
47
|
+
*/
|
|
48
|
+
type ParseWebhookResult = {
|
|
49
|
+
success: true;
|
|
50
|
+
payload: WebhookPayload;
|
|
51
|
+
} | {
|
|
52
|
+
success: false;
|
|
53
|
+
error: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Parse and validate a webhook payload from the request body.
|
|
57
|
+
*
|
|
58
|
+
* Uses Zod schema validation to ensure the payload has the expected structure.
|
|
59
|
+
*
|
|
60
|
+
* @param body - The raw request body as a string
|
|
61
|
+
* @returns A result object with either the validated payload or an error message
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const body = await request.text();
|
|
66
|
+
* const result = parseWebhookPayload(body);
|
|
67
|
+
* if (!result.success) {
|
|
68
|
+
* return new Response(result.error, { status: 400 });
|
|
69
|
+
* }
|
|
70
|
+
* console.log(`Received ${result.payload.event} for site ${result.payload.siteId}`);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
declare function parseWebhookPayload(body: string): ParseWebhookResult;
|
|
74
|
+
|
|
75
|
+
export { type ParseWebhookResult, type WebhookPayload, WebhookPayloadSchema, parseWebhookPayload, verifyWebhookSignature };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Webhook verification utilities for Riverbank SDK
|
|
5
|
+
*
|
|
6
|
+
* Provides framework-agnostic webhook signature verification and payload parsing.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Zod schema for webhook payload validation.
|
|
11
|
+
*/
|
|
12
|
+
declare const WebhookPayloadSchema: z.ZodObject<{
|
|
13
|
+
event: z.ZodString;
|
|
14
|
+
timestamp: z.ZodString;
|
|
15
|
+
siteId: z.ZodString;
|
|
16
|
+
data: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
17
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
/**
|
|
20
|
+
* Webhook payload structure sent by the CMS.
|
|
21
|
+
*/
|
|
22
|
+
type WebhookPayload = z.infer<typeof WebhookPayloadSchema>;
|
|
23
|
+
/**
|
|
24
|
+
* Verify a webhook signature using HMAC-SHA256.
|
|
25
|
+
*
|
|
26
|
+
* Uses timing-safe comparison to prevent timing attacks.
|
|
27
|
+
*
|
|
28
|
+
* @param payload - The raw request body as a string
|
|
29
|
+
* @param signature - The X-Riverbank-Signature header value
|
|
30
|
+
* @param secret - The webhook signing secret (RIVERBANK_WEBHOOK_SECRET)
|
|
31
|
+
* @returns true if signature is valid, false otherwise
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const body = await request.text();
|
|
36
|
+
* const signature = request.headers.get('x-riverbank-signature');
|
|
37
|
+
* const secret = process.env.RIVERBANK_WEBHOOK_SECRET;
|
|
38
|
+
*
|
|
39
|
+
* if (!verifyWebhookSignature(body, signature, secret)) {
|
|
40
|
+
* return new Response('Invalid signature', { status: 401 });
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function verifyWebhookSignature(payload: string, signature: string, secret: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Result type for webhook payload parsing.
|
|
47
|
+
*/
|
|
48
|
+
type ParseWebhookResult = {
|
|
49
|
+
success: true;
|
|
50
|
+
payload: WebhookPayload;
|
|
51
|
+
} | {
|
|
52
|
+
success: false;
|
|
53
|
+
error: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Parse and validate a webhook payload from the request body.
|
|
57
|
+
*
|
|
58
|
+
* Uses Zod schema validation to ensure the payload has the expected structure.
|
|
59
|
+
*
|
|
60
|
+
* @param body - The raw request body as a string
|
|
61
|
+
* @returns A result object with either the validated payload or an error message
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const body = await request.text();
|
|
66
|
+
* const result = parseWebhookPayload(body);
|
|
67
|
+
* if (!result.success) {
|
|
68
|
+
* return new Response(result.error, { status: 400 });
|
|
69
|
+
* }
|
|
70
|
+
* console.log(`Received ${result.payload.event} for site ${result.payload.siteId}`);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
declare function parseWebhookPayload(body: string): ParseWebhookResult;
|
|
74
|
+
|
|
75
|
+
export { type ParseWebhookResult, type WebhookPayload, WebhookPayloadSchema, parseWebhookPayload, verifyWebhookSignature };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkVODFQMUWjs = require('./chunk-VODFQMUW.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.WebhookPayloadSchema = _chunkVODFQMUWjs.WebhookPayloadSchema; exports.parseWebhookPayload = _chunkVODFQMUWjs.parseWebhookPayload; exports.verifyWebhookSignature = _chunkVODFQMUWjs.verifyWebhookSignature;
|
|
11
|
+
//# sourceMappingURL=webhooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/will/Projects/Business/cms/builder/packages/sdk/dist/server/webhooks.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACF,mNAAC","file":"/Users/will/Projects/Business/cms/builder/packages/sdk/dist/server/webhooks.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|