@c1m-public/channel-client 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -5
- package/dist/chunk-ATGQYDRM.js +334 -0
- package/dist/chunk-AX6L2XH3.js +599 -0
- package/dist/chunk-JDERR7M5.js +17 -0
- package/dist/chunk-RJQ4YEZV.js +180 -0
- package/dist/dash-next.d.ts +8 -5
- package/dist/dash-next.js +10 -11
- package/dist/dash.d.ts +7 -5
- package/dist/dash.js +3 -16
- package/dist/index.d.ts +1325 -27
- package/dist/index.js +2 -513
- package/dist/moving-lead-model/index.d.ts +417 -3
- package/dist/moving-lead-model/index.js +288 -2
- package/dist/next.d.ts +352 -103
- package/dist/next.js +3 -69
- package/dist/renderer.d.ts +11 -9
- package/dist/renderer.js +75 -95
- package/dist/webhooks.d.ts +28 -26
- package/dist/webhooks.js +1 -228
- package/package.json +5 -3
- package/dist/errors.d.ts +0 -12
- package/dist/errors.js +0 -19
- package/dist/moving-lead-model/address-model.d.ts +0 -12
- package/dist/moving-lead-model/address-model.js +0 -43
- package/dist/moving-lead-model/address-types.d.ts +0 -55
- package/dist/moving-lead-model/address-types.js +0 -12
- package/dist/moving-lead-model/quote-model.d.ts +0 -348
- package/dist/moving-lead-model/quote-model.js +0 -267
- package/dist/next-cart.d.ts +0 -76
- package/dist/next-cart.js +0 -87
- package/dist/next-session.d.ts +0 -121
- package/dist/next-session.js +0 -177
- package/dist/next-webhooks.d.ts +0 -58
- package/dist/next-webhooks.js +0 -109
- package/dist/types.d.ts +0 -1273
- package/dist/types.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1,513 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export * from "./errors.js";
|
|
4
|
-
import { ChannelConfigurationError } from "./errors.js";
|
|
5
|
-
const CHANNEL_TOKEN_PREFIX = "sk_chan_";
|
|
6
|
-
export const DEFAULT_CHANNEL_API_URL = "https://api.saasdash.app";
|
|
7
|
-
const RETRYABLE_STATUSES = new Set([429, 502, 503, 504]);
|
|
8
|
-
export class ChannelAPIError extends Error {
|
|
9
|
-
status;
|
|
10
|
-
code;
|
|
11
|
-
requestId;
|
|
12
|
-
constructor(message, status, code, requestId) {
|
|
13
|
-
super(message);
|
|
14
|
-
this.status = status;
|
|
15
|
-
this.code = code;
|
|
16
|
-
this.requestId = requestId;
|
|
17
|
-
this.name = "ChannelAPIError";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
/** Works across duplicate package instances and transformed test bundles. */
|
|
21
|
-
export function isChannelAPIError(error) {
|
|
22
|
-
return (error instanceof ChannelAPIError ||
|
|
23
|
-
(typeof error === "object" && error !== null &&
|
|
24
|
-
error.name === "ChannelAPIError" &&
|
|
25
|
-
typeof error.status === "number" &&
|
|
26
|
-
typeof error.code === "string" &&
|
|
27
|
-
typeof error.requestId === "string"));
|
|
28
|
-
}
|
|
29
|
-
function required(value, label) {
|
|
30
|
-
const normalized = value.trim();
|
|
31
|
-
if (!normalized)
|
|
32
|
-
throw new ChannelConfigurationError(`${label} is required`);
|
|
33
|
-
return normalized;
|
|
34
|
-
}
|
|
35
|
-
function positiveNumber(value, label) {
|
|
36
|
-
if (!Number.isFinite(value) || value <= 0)
|
|
37
|
-
throw new ChannelConfigurationError(`${label} must be a positive finite number`);
|
|
38
|
-
return value;
|
|
39
|
-
}
|
|
40
|
-
function encodePath(value) {
|
|
41
|
-
return encodeURIComponent(required(value, "path value"));
|
|
42
|
-
}
|
|
43
|
-
function appendQuery(path, values) {
|
|
44
|
-
const query = new URLSearchParams();
|
|
45
|
-
for (const [key, value] of Object.entries(values)) {
|
|
46
|
-
if (value !== undefined && value !== "")
|
|
47
|
-
query.set(key, String(value));
|
|
48
|
-
}
|
|
49
|
-
const encoded = query.toString();
|
|
50
|
-
return encoded ? `${path}?${encoded}` : path;
|
|
51
|
-
}
|
|
52
|
-
// backoffDelay is the no-Retry-After default: exponential from 250 ms with
|
|
53
|
-
// full jitter, capped. A flat 250 ms with no jitter (the previous behaviour)
|
|
54
|
-
// turns `attempts: 5` on a 429 into five requests a quarter-second apart into
|
|
55
|
-
// the very limiter that just refused you — a thundering herd in miniature.
|
|
56
|
-
function backoffDelay(attempt, maxDelayMs) {
|
|
57
|
-
const base = Math.min(250 * 2 ** Math.max(attempt, 0), maxDelayMs);
|
|
58
|
-
return Math.floor(Math.random() * base);
|
|
59
|
-
}
|
|
60
|
-
function retryDelay(response, attempt, maxDelayMs) {
|
|
61
|
-
const value = response.headers.get("Retry-After");
|
|
62
|
-
if (!value)
|
|
63
|
-
return backoffDelay(attempt, maxDelayMs);
|
|
64
|
-
const seconds = Number(value);
|
|
65
|
-
if (Number.isFinite(seconds))
|
|
66
|
-
return Math.min(Math.max(seconds * 1_000, 0), maxDelayMs);
|
|
67
|
-
const date = Date.parse(value);
|
|
68
|
-
return Number.isNaN(date) ? backoffDelay(attempt, maxDelayMs) : Math.min(Math.max(date - Date.now(), 0), maxDelayMs);
|
|
69
|
-
}
|
|
70
|
-
function wait(ms) {
|
|
71
|
-
return ms <= 0 ? Promise.resolve() : new Promise((resolve) => setTimeout(resolve, ms));
|
|
72
|
-
}
|
|
73
|
-
function combineSignals(...signals) {
|
|
74
|
-
const active = signals.filter((signal) => Boolean(signal));
|
|
75
|
-
if (active.length === 0)
|
|
76
|
-
return undefined;
|
|
77
|
-
if (active.length === 1)
|
|
78
|
-
return active[0];
|
|
79
|
-
return AbortSignal.any(active);
|
|
80
|
-
}
|
|
81
|
-
function isFormDataBody(body) {
|
|
82
|
-
return typeof FormData !== "undefined" && body instanceof FormData;
|
|
83
|
-
}
|
|
84
|
-
async function visitorHeaders(token, method, path, visitor) {
|
|
85
|
-
if (!visitor)
|
|
86
|
-
return undefined;
|
|
87
|
-
const ip = visitor.ip?.trim() ?? "";
|
|
88
|
-
const country = visitor.country?.trim().toUpperCase() ?? "";
|
|
89
|
-
const userAgent = visitor.userAgent?.trim() ?? "";
|
|
90
|
-
if (!ip && !country && !userAgent)
|
|
91
|
-
return undefined;
|
|
92
|
-
const timestamp = Math.floor(Date.now() / 1_000).toString();
|
|
93
|
-
const encoder = new TextEncoder();
|
|
94
|
-
const uaHash = await crypto.subtle.digest("SHA-256", encoder.encode(userAgent));
|
|
95
|
-
const hex = (bytes) => Array.from(new Uint8Array(bytes), (value) => value.toString(16).padStart(2, "0")).join("");
|
|
96
|
-
const canonical = ["v1", timestamp, method, `/api/v1/channel${path}`, ip, country, hex(uaHash)].join("\n");
|
|
97
|
-
const key = await crypto.subtle.importKey("raw", encoder.encode(token), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
98
|
-
const signature = hex(await crypto.subtle.sign("HMAC", key, encoder.encode(canonical)));
|
|
99
|
-
return {
|
|
100
|
-
"X-C1M-Visitor-IP": ip,
|
|
101
|
-
"X-C1M-Visitor-Country": country,
|
|
102
|
-
"X-C1M-Visitor-User-Agent": userAgent,
|
|
103
|
-
"X-C1M-Visitor-Timestamp": timestamp,
|
|
104
|
-
"X-C1M-Visitor-Signature": signature,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
export function createChannelClient(options) {
|
|
108
|
-
const baseUrl = (options.baseUrl === undefined
|
|
109
|
-
? DEFAULT_CHANNEL_API_URL
|
|
110
|
-
: required(options.baseUrl, "baseUrl")).replace(/\/+$/, "");
|
|
111
|
-
const token = required(options.token, "token");
|
|
112
|
-
if (!token.startsWith(CHANNEL_TOKEN_PREFIX))
|
|
113
|
-
throw new ChannelConfigurationError("token must start with sk_chan_");
|
|
114
|
-
const fetcher = options.fetch ?? globalThis.fetch;
|
|
115
|
-
if (!fetcher)
|
|
116
|
-
throw new ChannelConfigurationError("fetch implementation is required");
|
|
117
|
-
const timeoutMs = positiveNumber(options.timeoutMs ?? 10_000, "timeoutMs");
|
|
118
|
-
const configuredRetryAttempts = options.retry === false ? 0 : options.retry?.attempts ?? 1;
|
|
119
|
-
if (!Number.isSafeInteger(configuredRetryAttempts) || configuredRetryAttempts < 0) {
|
|
120
|
-
throw new ChannelConfigurationError("retry.attempts must be a non-negative safe integer");
|
|
121
|
-
}
|
|
122
|
-
const retryAttempts = configuredRetryAttempts;
|
|
123
|
-
const maxRetryDelayMs = positiveNumber(options.retry === false ? 2_000 : options.retry?.maxDelayMs ?? 2_000, "retry.maxDelayMs");
|
|
124
|
-
const observe = options.observe;
|
|
125
|
-
async function request(operation, path, init = {}, session) {
|
|
126
|
-
const method = (init.method ?? "GET").toUpperCase();
|
|
127
|
-
const startedAt = Date.now();
|
|
128
|
-
let attempts = 0;
|
|
129
|
-
let status = 0;
|
|
130
|
-
let requestId = "";
|
|
131
|
-
let outcome = "network_error";
|
|
132
|
-
const headers = new Headers(init.headers);
|
|
133
|
-
// The channel token authenticates the APP. A customer is a SECOND,
|
|
134
|
-
// separate credential — Authorization is already spoken for, so the
|
|
135
|
-
// customer's session rides in its own header.
|
|
136
|
-
headers.set("Authorization", `Bearer ${token}`);
|
|
137
|
-
const signedVisitor = await visitorHeaders(token, method, path, options.visitor);
|
|
138
|
-
if (signedVisitor) {
|
|
139
|
-
for (const [key, value] of Object.entries(signedVisitor))
|
|
140
|
-
headers.set(key, value);
|
|
141
|
-
}
|
|
142
|
-
if (session)
|
|
143
|
-
headers.set("X-End-User-Token", session);
|
|
144
|
-
if (init.body !== undefined && !isFormDataBody(init.body) && !headers.has("Content-Type")) {
|
|
145
|
-
headers.set("Content-Type", "application/json");
|
|
146
|
-
}
|
|
147
|
-
const requestInit = { ...init, method, headers };
|
|
148
|
-
// Private reads and every mutation are non-cacheable in every runtime. An
|
|
149
|
-
// adapter may add framework caching only to anonymous GET requests.
|
|
150
|
-
if (method !== "GET" || session) {
|
|
151
|
-
requestInit.cache = "no-store";
|
|
152
|
-
}
|
|
153
|
-
try {
|
|
154
|
-
let response;
|
|
155
|
-
for (let attempt = 0; attempt <= retryAttempts; attempt += 1) {
|
|
156
|
-
attempts = attempt + 1;
|
|
157
|
-
const controller = new AbortController();
|
|
158
|
-
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
159
|
-
try {
|
|
160
|
-
response = await fetcher(`${baseUrl}/api/v1/channel${path}`, {
|
|
161
|
-
...requestInit,
|
|
162
|
-
signal: combineSignals(options.signal, requestInit.signal, controller.signal),
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
catch {
|
|
166
|
-
if (controller.signal.aborted) {
|
|
167
|
-
outcome = "timeout";
|
|
168
|
-
throw new ChannelAPIError("Channel API request timed out", 0, "channel_request_timeout", "");
|
|
169
|
-
}
|
|
170
|
-
if (options.signal?.aborted || requestInit.signal?.aborted) {
|
|
171
|
-
outcome = "cancelled";
|
|
172
|
-
throw new ChannelAPIError("Channel API request was cancelled", 0, "channel_request_cancelled", "");
|
|
173
|
-
}
|
|
174
|
-
outcome = "network_error";
|
|
175
|
-
if (method === "GET" && attempt < retryAttempts) {
|
|
176
|
-
await wait(backoffDelay(attempt, maxRetryDelayMs));
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
throw new ChannelAPIError("Channel API request failed", 0, "channel_network_error", "");
|
|
180
|
-
}
|
|
181
|
-
finally {
|
|
182
|
-
clearTimeout(timeout);
|
|
183
|
-
}
|
|
184
|
-
if (method !== "GET" || !RETRYABLE_STATUSES.has(response.status) || attempt === retryAttempts)
|
|
185
|
-
break;
|
|
186
|
-
await wait(retryDelay(response, attempt, maxRetryDelayMs));
|
|
187
|
-
}
|
|
188
|
-
if (!response)
|
|
189
|
-
throw new ChannelAPIError("Channel API request failed", 0, "channel_network_error", "");
|
|
190
|
-
status = response.status;
|
|
191
|
-
requestId = response.headers.get("X-Request-ID") ?? "";
|
|
192
|
-
if (!response.ok) {
|
|
193
|
-
const payload = (await response.json().catch(() => ({})));
|
|
194
|
-
requestId = typeof payload.request_id === "string" ? payload.request_id : requestId;
|
|
195
|
-
outcome = "api_error";
|
|
196
|
-
throw new ChannelAPIError(typeof payload.message === "string" ? payload.message : "Channel API request failed", response.status, typeof payload.code === "string" ? payload.code : "channel_request_failed", requestId);
|
|
197
|
-
}
|
|
198
|
-
try {
|
|
199
|
-
outcome = "success";
|
|
200
|
-
if (response.status === 204)
|
|
201
|
-
return undefined;
|
|
202
|
-
const text = await response.text();
|
|
203
|
-
if (!text)
|
|
204
|
-
return undefined;
|
|
205
|
-
const payload = JSON.parse(text);
|
|
206
|
-
return payload;
|
|
207
|
-
}
|
|
208
|
-
catch {
|
|
209
|
-
outcome = "invalid_response";
|
|
210
|
-
throw new ChannelAPIError("Channel API response was not valid JSON", response.status, "invalid_channel_response", requestId);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
finally {
|
|
214
|
-
if (observe) {
|
|
215
|
-
try {
|
|
216
|
-
observe({ operation, method, outcome, status, requestId, durationMs: Math.max(0, Date.now() - startedAt), attempts });
|
|
217
|
-
}
|
|
218
|
-
catch {
|
|
219
|
-
// Telemetry must never become part of the request's availability path.
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
function mutationHeaders(mutation) {
|
|
225
|
-
return mutation?.idempotencyKey ? { "Idempotency-Key": mutation.idempotencyKey } : undefined;
|
|
226
|
-
}
|
|
227
|
-
return {
|
|
228
|
-
/**
|
|
229
|
-
* Verify the channel token and see what it points at.
|
|
230
|
-
*
|
|
231
|
-
* The cheapest call on the door — it does no database work server-side. Use
|
|
232
|
-
* it as a deployment health check: a 200 means C1M_CHANNEL_TOKEN is right and
|
|
233
|
-
* aimed at the scope you expect. A ChannelAPIError with status 401 means
|
|
234
|
-
* the token is bad, revoked, or the channel is disabled (the door will not
|
|
235
|
-
* say which). A 503 means C1M is unavailable — NOT that your token is wrong.
|
|
236
|
-
*/
|
|
237
|
-
ping: (challenge) => request("channel.ping", appendQuery("/ping", { challenge })),
|
|
238
|
-
/** Return a request-scoped client that signs trusted edge visitor metadata. */
|
|
239
|
-
withVisitor: (visitor) => createChannelClient({ ...options, visitor }),
|
|
240
|
-
geo: {
|
|
241
|
-
detect: () => request("channel.geo.detect", "/geo/detect"),
|
|
242
|
-
},
|
|
243
|
-
/** Tenant-level data exposed only to a dash-scoped channel token. */
|
|
244
|
-
dash: {
|
|
245
|
-
profile: () => request("channel.dash.profile", "/dash/profile"),
|
|
246
|
-
init: () => request("channel.dash.init", "/dash/init"),
|
|
247
|
-
plans: () => request("channel.dash.plans", "/dash/plans"),
|
|
248
|
-
directory: {
|
|
249
|
-
regions: () => request("channel.dash.directory.regions", "/dash/directory/regions"),
|
|
250
|
-
list: (params = {}) => request("channel.dash.directory.browse", appendQuery("/dash/directory", params)),
|
|
251
|
-
get: (idOrSlug) => request("channel.dash.directory.get", `/dash/directory/${encodePath(idOrSlug)}`),
|
|
252
|
-
},
|
|
253
|
-
leads: {
|
|
254
|
-
create: (input, mutation) => request("channel.dash.leads.capture", "/dash/leads", {
|
|
255
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
256
|
-
}),
|
|
257
|
-
},
|
|
258
|
-
// The Lead Match Portal. A requester asks for a signed link by email,
|
|
259
|
-
// then views their quote requests with the token that link carries. Not
|
|
260
|
-
// a customer session: the token is the only credential, and view() takes
|
|
261
|
-
// it explicitly so a site never has to hold it in a cookie.
|
|
262
|
-
leadPortal: {
|
|
263
|
-
requestLink: (input) => request("channel.dash.lead_portal.request_link", "/dash/lead-portal/request-link", { method: "POST", body: JSON.stringify(input) }),
|
|
264
|
-
view: (token) => request("channel.dash.lead_portal.my_quotes", appendQuery("/dash/lead-portal/my-quotes", { token })),
|
|
265
|
-
},
|
|
266
|
-
},
|
|
267
|
-
assetUrl: (pathOrUrl) => new URL(required(pathOrUrl, "asset URL"), `${baseUrl}/`).toString(),
|
|
268
|
-
site: {
|
|
269
|
-
resolve: (params = {}) => request("channel.site.resolve", appendQuery("/site/resolve", params)),
|
|
270
|
-
},
|
|
271
|
-
init: {
|
|
272
|
-
get: () => request("channel.init.get", "/init"),
|
|
273
|
-
light: () => request("channel.init.light", "/init/light"),
|
|
274
|
-
},
|
|
275
|
-
pages: {
|
|
276
|
-
list: (params = {}) => request("content.pages.public.list.channel", appendQuery("/pages", params)),
|
|
277
|
-
get: (slug) => request("content.pages.public.get.channel", `/pages/${encodePath(slug)}`),
|
|
278
|
-
},
|
|
279
|
-
products: {
|
|
280
|
-
list: (params = {}) => request("shop.public.products.list.channel", appendQuery("/products", params)),
|
|
281
|
-
get: (slug) => request("shop.public.products.get.channel", `/products/${encodePath(slug)}`),
|
|
282
|
-
media: (slug) => request("shop.public.products.media.channel", `/products/${encodePath(slug)}/media`),
|
|
283
|
-
},
|
|
284
|
-
categories: {
|
|
285
|
-
list: (params = {}) => request("channel.catalog.categories.list", appendQuery("/categories", params)),
|
|
286
|
-
products: (slug) => request("channel.catalog.categories.products", `/categories/by-slug/${encodePath(slug)}/products`),
|
|
287
|
-
},
|
|
288
|
-
collections: {
|
|
289
|
-
list: (params = {}) => request("channel.catalog.collections.list", appendQuery("/collections", params)),
|
|
290
|
-
products: (slug) => request("channel.catalog.collections.products", `/collections/by-slug/${encodePath(slug)}/products`),
|
|
291
|
-
},
|
|
292
|
-
brands: {
|
|
293
|
-
list: (params = {}) => request("channel.catalog.brands.list", appendQuery("/brands", params)),
|
|
294
|
-
},
|
|
295
|
-
cart: {
|
|
296
|
-
get: (cartToken) => request("channel.cart.get", appendQuery("/cart", { cart_token: required(cartToken, "cartToken") })),
|
|
297
|
-
addItem: (input, mutation) => request("channel.cart.items.add", "/cart/items", {
|
|
298
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
299
|
-
}),
|
|
300
|
-
updateItem: (itemId, input, mutation) => request("channel.cart.items.update", `/cart/items/${encodePath(itemId)}`, {
|
|
301
|
-
method: "PATCH", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
302
|
-
}),
|
|
303
|
-
removeItem: (itemId, cartToken, mutation) => request("channel.cart.items.remove", appendQuery(`/cart/items/${encodePath(itemId)}`, {
|
|
304
|
-
cart_token: required(cartToken, "cartToken"),
|
|
305
|
-
}), {
|
|
306
|
-
method: "DELETE", headers: mutationHeaders(mutation),
|
|
307
|
-
}),
|
|
308
|
-
clear: (cartToken, mutation) => request("channel.cart.clear", appendQuery("/cart", { cart_token: required(cartToken, "cartToken") }), {
|
|
309
|
-
method: "DELETE", headers: mutationHeaders(mutation),
|
|
310
|
-
}),
|
|
311
|
-
merge: (input, mutation) => request("channel.cart.merge", "/cart/merge", {
|
|
312
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
313
|
-
}),
|
|
314
|
-
},
|
|
315
|
-
// Checkout is addressed by the ORDER the cart became: the server mounts
|
|
316
|
-
// /checkout/{order_id}/... (the cart is an orders row, and every cart call
|
|
317
|
-
// returns its order.id). 0.5.0 shipped these without the order_id segment,
|
|
318
|
-
// so every checkout call 404'd — the signature change is safe because the
|
|
319
|
-
// old shape never worked.
|
|
320
|
-
checkout: {
|
|
321
|
-
options: (orderId, cartToken) => request("channel.checkout.options", appendQuery(`/checkout/${encodePath(orderId)}/options`, {
|
|
322
|
-
cart_token: required(cartToken, "cartToken"),
|
|
323
|
-
})),
|
|
324
|
-
status: (orderId, params = {}) => request("channel.checkout.status", appendQuery(`/checkout/${encodePath(orderId)}/status`, {
|
|
325
|
-
cart_token: params.cartToken,
|
|
326
|
-
checkout_session_id: params.checkoutSessionId,
|
|
327
|
-
})),
|
|
328
|
-
setCustomer: (orderId, input, mutation) => request("channel.checkout.customer.set", `/checkout/${encodePath(orderId)}/customer`, {
|
|
329
|
-
method: "PUT", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
330
|
-
}),
|
|
331
|
-
setAddresses: (orderId, input, mutation) => request("channel.checkout.addresses.set", `/checkout/${encodePath(orderId)}/addresses`, {
|
|
332
|
-
method: "PUT", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
333
|
-
}),
|
|
334
|
-
setFulfillment: (orderId, input, mutation) => request("channel.checkout.fulfillment.set", `/checkout/${encodePath(orderId)}/fulfillment`, {
|
|
335
|
-
method: "PUT", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
336
|
-
}),
|
|
337
|
-
pay: (orderId, input, mutation) => request("channel.checkout.pay", `/checkout/${encodePath(orderId)}/pay`, {
|
|
338
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
339
|
-
}),
|
|
340
|
-
},
|
|
341
|
-
reviews: {
|
|
342
|
-
list: (params = {}) => request("reviews.public.list.channel", appendQuery("/reviews", params)),
|
|
343
|
-
summary: () => request("reviews.public.summary.channel", "/reviews/summary"),
|
|
344
|
-
submit: (input, mutation) => request("reviews.public.submit.channel", "/reviews", {
|
|
345
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
346
|
-
}),
|
|
347
|
-
},
|
|
348
|
-
theme: {
|
|
349
|
-
get: () => request("channel.theme.get", "/theme"),
|
|
350
|
-
},
|
|
351
|
-
menus: {
|
|
352
|
-
get: (handle) => request("channel.menus.get", `/menus/${encodePath(handle)}`),
|
|
353
|
-
},
|
|
354
|
-
blog: {
|
|
355
|
-
list: (params = {}) => request("channel.blog.list", appendQuery("/blog/posts", params)),
|
|
356
|
-
get: (slug) => request("channel.blog.get", `/blog/posts/${encodePath(slug)}`),
|
|
357
|
-
},
|
|
358
|
-
giving: {
|
|
359
|
-
entries: {
|
|
360
|
-
list: () => request("channel.giving.entries.list", "/giving/entries"),
|
|
361
|
-
get: (slug) => request("channel.giving.entries.get", `/giving/entries/${encodePath(slug)}`),
|
|
362
|
-
},
|
|
363
|
-
start: (input, mutation) => request("channel.giving.start", "/give/start", {
|
|
364
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
365
|
-
}),
|
|
366
|
-
},
|
|
367
|
-
subscriptions: {
|
|
368
|
-
// Plan catalogue for rendering a membership picker. Managing an agreement
|
|
369
|
-
// a customer already holds lives under withCustomer(...).subscriptions.
|
|
370
|
-
plans: {
|
|
371
|
-
list: () => request("channel.subscriptions.plans.list", "/subscriptions/plans"),
|
|
372
|
-
get: (planId) => request("channel.subscriptions.plans.get", `/subscriptions/plans/${encodePath(planId)}`),
|
|
373
|
-
},
|
|
374
|
-
},
|
|
375
|
-
paymentLinks: {
|
|
376
|
-
get: (linkId) => request("monetization.payment_links.public_get.channel", `/payment-links/${encodePath(linkId)}`),
|
|
377
|
-
checkout: (linkId, input, mutation) => request("monetization.payment_links.public_checkout.channel", `/payment-links/${encodePath(linkId)}/checkout`, { method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input) }),
|
|
378
|
-
redemptions: {
|
|
379
|
-
get: (linkId, redemptionId) => request("monetization.payment_links.public_redemption_get.channel", `/payment-links/${encodePath(linkId)}/redemptions/${encodePath(redemptionId)}`),
|
|
380
|
-
},
|
|
381
|
-
},
|
|
382
|
-
print: {
|
|
383
|
-
settings: () => request("channel.print.settings", "/print/settings"),
|
|
384
|
-
quote: (input, mutation) => request("channel.print.quote", "/print/quote", {
|
|
385
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
386
|
-
}),
|
|
387
|
-
intake: (input, mutation) => {
|
|
388
|
-
const form = new FormData();
|
|
389
|
-
form.set("name", input.name);
|
|
390
|
-
if (input.email)
|
|
391
|
-
form.set("email", input.email);
|
|
392
|
-
if (input.phone)
|
|
393
|
-
form.set("phone", input.phone);
|
|
394
|
-
if (input.notes)
|
|
395
|
-
form.set("notes", input.notes);
|
|
396
|
-
form.set("options", JSON.stringify(input.options));
|
|
397
|
-
for (const file of input.files)
|
|
398
|
-
form.append("files", file.blob, file.filename);
|
|
399
|
-
return request("channel.print.intake", "/print/intake", {
|
|
400
|
-
method: "POST", headers: mutationHeaders(mutation), body: form,
|
|
401
|
-
});
|
|
402
|
-
},
|
|
403
|
-
},
|
|
404
|
-
dining: {
|
|
405
|
-
menu: (boardSlug) => request("dining.public.board_menu.channel", `/dining/boards/${encodePath(boardSlug)}/menu`),
|
|
406
|
-
},
|
|
407
|
-
// Customer sign-in. These are anonymous calls — they CREATE a session.
|
|
408
|
-
auth: {
|
|
409
|
-
check: (email) => request("channel.auth.check", "/auth/check", { method: "POST", body: JSON.stringify({ email }) }),
|
|
410
|
-
signup: (input) => request("channel.auth.signup", "/auth/signup", { method: "POST", body: JSON.stringify(input) }),
|
|
411
|
-
sendCode: (email) => request("channel.auth.send_code", "/auth/send-code", { method: "POST", body: JSON.stringify({ email }) }),
|
|
412
|
-
verifyCode: (input) => request("channel.auth.verify_code", "/auth/verify-code", { method: "POST", body: JSON.stringify(input) }),
|
|
413
|
-
refresh: (refreshToken) => request("channel.auth.refresh", "/auth/refresh", { method: "POST", body: JSON.stringify({ refresh_token: refreshToken }) }),
|
|
414
|
-
},
|
|
415
|
-
/**
|
|
416
|
-
* Scope calls to a signed-in customer.
|
|
417
|
-
*
|
|
418
|
-
* The session is passed here rather than stored on the client, so it cannot
|
|
419
|
-
* leak between requests: on a server rendering for many visitors at once, a
|
|
420
|
-
* mutable "current customer" is a cross-customer data leak waiting to
|
|
421
|
-
* happen. Each request carries the session it was given, or none.
|
|
422
|
-
*
|
|
423
|
-
* Orders are scoped server-side to this customer's own email within the
|
|
424
|
-
* channel's workspace — another customer's order id returns 404.
|
|
425
|
-
*/
|
|
426
|
-
withCustomer(session) {
|
|
427
|
-
const customerSession = required(session, "session");
|
|
428
|
-
return {
|
|
429
|
-
me: () => request("channel.auth.me", "/auth/me", {}, customerSession),
|
|
430
|
-
updateProfile: (input) => request("channel.auth.me.update", "/auth/me", { method: "PUT", body: JSON.stringify(input) }, customerSession),
|
|
431
|
-
logout: () => request("channel.auth.logout", "/auth/logout", { method: "POST" }, customerSession),
|
|
432
|
-
sessions: {
|
|
433
|
-
list: () => request("channel.auth.sessions.list", "/auth/me/sessions", {}, customerSession),
|
|
434
|
-
revoke: (sessionId) => request("channel.auth.sessions.revoke", `/auth/me/sessions/${encodePath(sessionId)}`, { method: "DELETE" }, customerSession),
|
|
435
|
-
revokeOthers: () => request("channel.auth.sessions.revoke_others", "/auth/me/sessions/revoke-others", { method: "POST" }, customerSession),
|
|
436
|
-
revokeAll: () => request("channel.auth.sessions.revoke_all", "/auth/me/sessions/revoke-all", { method: "POST" }, customerSession),
|
|
437
|
-
},
|
|
438
|
-
securityActivity: (params = {}) => request("channel.auth.security_activity.list", appendQuery("/auth/me/security-activity", params), {}, customerSession),
|
|
439
|
-
orders: {
|
|
440
|
-
list: (params = {}) => request("channel.account.orders.list", appendQuery("/account/orders", params), {}, customerSession),
|
|
441
|
-
summary: () => request("channel.account.orders.summary", "/account/orders/summary", {}, customerSession),
|
|
442
|
-
get: (orderId) => request("channel.account.orders.get", `/account/orders/${encodePath(orderId)}`, {}, customerSession),
|
|
443
|
-
},
|
|
444
|
-
addresses: {
|
|
445
|
-
list: () => request("channel.account.addresses.list", "/account/addresses", {}, customerSession),
|
|
446
|
-
get: (addressId) => request("channel.account.addresses.get", `/account/addresses/${encodePath(addressId)}`, {}, customerSession),
|
|
447
|
-
create: (input, mutation) => request("channel.account.addresses.create", "/account/addresses", {
|
|
448
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
449
|
-
}, customerSession),
|
|
450
|
-
update: (addressId, input, mutation) => request("channel.account.addresses.update", `/account/addresses/${encodePath(addressId)}`, {
|
|
451
|
-
method: "PUT", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
452
|
-
}, customerSession),
|
|
453
|
-
delete: (addressId, mutation) => request("channel.account.addresses.delete", `/account/addresses/${encodePath(addressId)}`, {
|
|
454
|
-
method: "DELETE", headers: mutationHeaders(mutation),
|
|
455
|
-
}, customerSession),
|
|
456
|
-
setDefault: (addressId, kind, mutation) => request("channel.account.addresses.set_default", `/account/addresses/${encodePath(addressId)}/default`, {
|
|
457
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify({ kind }),
|
|
458
|
-
}, customerSession),
|
|
459
|
-
},
|
|
460
|
-
paymentMethods: {
|
|
461
|
-
list: () => request("channel.account.payment_methods.list", "/account/payment-methods", {}, customerSession),
|
|
462
|
-
setup: (input, mutation) => request("channel.account.payment_methods.setup", "/account/payment-methods/setup", {
|
|
463
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
464
|
-
}, customerSession),
|
|
465
|
-
confirm: (input, mutation) => request("channel.account.payment_methods.confirm", "/account/payment-methods/confirm", {
|
|
466
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
467
|
-
}, customerSession),
|
|
468
|
-
setDefault: (methodId, mutation) => request("channel.account.payment_methods.default", `/account/payment-methods/${encodePath(methodId)}/default`, {
|
|
469
|
-
method: "POST", headers: mutationHeaders(mutation),
|
|
470
|
-
}, customerSession),
|
|
471
|
-
delete: (methodId, mutation) => request("channel.account.payment_methods.delete", `/account/payment-methods/${encodePath(methodId)}`, {
|
|
472
|
-
method: "DELETE", headers: mutationHeaders(mutation),
|
|
473
|
-
}, customerSession),
|
|
474
|
-
},
|
|
475
|
-
subscriptions: {
|
|
476
|
-
start: (input, mutation) => request("channel.subscriptions.start", "/subscriptions/start", {
|
|
477
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
478
|
-
}, customerSession),
|
|
479
|
-
list: (params = {}) => request("channel.account.subscriptions.list", appendQuery("/account/subscriptions", params), {}, customerSession),
|
|
480
|
-
get: (agreementId) => request("channel.account.subscriptions.get", `/account/subscriptions/${encodePath(agreementId)}`, {}, customerSession),
|
|
481
|
-
source: (agreementId) => request("channel.account.subscriptions.source", `/account/subscriptions/${encodePath(agreementId)}/source`, {}, customerSession),
|
|
482
|
-
cancel: (agreementId, params = {}, mutation) => request("channel.account.subscriptions.cancel", appendQuery(`/account/subscriptions/${encodePath(agreementId)}/cancel`, params), {
|
|
483
|
-
method: "POST", headers: mutationHeaders(mutation),
|
|
484
|
-
}, customerSession),
|
|
485
|
-
pause: (agreementId, mutation) => request("channel.account.subscriptions.pause", `/account/subscriptions/${encodePath(agreementId)}/pause`, {
|
|
486
|
-
method: "POST", headers: mutationHeaders(mutation),
|
|
487
|
-
}, customerSession),
|
|
488
|
-
resume: (agreementId, mutation) => request("channel.account.subscriptions.resume", `/account/subscriptions/${encodePath(agreementId)}/resume`, {
|
|
489
|
-
method: "POST", headers: mutationHeaders(mutation),
|
|
490
|
-
}, customerSession),
|
|
491
|
-
invoices: {
|
|
492
|
-
list: (agreementId, params = {}) => request("channel.account.subscriptions.invoices.list", appendQuery(`/account/subscriptions/${encodePath(agreementId)}/invoices`, params), {}, customerSession),
|
|
493
|
-
get: (invoiceId) => request("channel.account.subscriptions.invoices.get", `/account/subscriptions/invoices/${encodePath(invoiceId)}`, {}, customerSession),
|
|
494
|
-
payNow: (invoiceId, mutation) => request("channel.account.subscriptions.invoices.pay_now", `/account/subscriptions/invoices/${encodePath(invoiceId)}/pay-now`, {
|
|
495
|
-
method: "POST", headers: mutationHeaders(mutation),
|
|
496
|
-
}, customerSession),
|
|
497
|
-
},
|
|
498
|
-
},
|
|
499
|
-
giving: {
|
|
500
|
-
list: () => request("channel.account.giving.list", "/account/giving", {}, customerSession),
|
|
501
|
-
start: (input, mutation) => request("channel.giving.start", "/give/start", {
|
|
502
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
503
|
-
}, customerSession),
|
|
504
|
-
},
|
|
505
|
-
};
|
|
506
|
-
},
|
|
507
|
-
leads: {
|
|
508
|
-
create: (input, mutation) => request("growth.public_workspace.leads.capture.channel", "/leads", {
|
|
509
|
-
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
510
|
-
}),
|
|
511
|
-
},
|
|
512
|
-
};
|
|
513
|
-
}
|
|
1
|
+
export { ChannelAPIError, DEFAULT_CHANNEL_API_URL, createChannelClient, isChannelAPIError } from './chunk-AX6L2XH3.js';
|
|
2
|
+
export { CHANNEL_WEBHOOK_EVENT_ID_HEADER, CHANNEL_WEBHOOK_EVENT_TYPES, CHANNEL_WEBHOOK_SIGNATURE_HEADER, CHANNEL_WEBHOOK_TIMESTAMP_HEADER, ChannelConfigurationError, ChannelWebhookVerificationError, DEFAULT_TOLERANCE_SECONDS, isChannelConfigurationError, isChannelWebhookEventType, isChannelWebhookVerificationError, isKnownChannelWebhookEvent, parseChannelWebhookEvent, verifyChannelWebhookSignature } from './chunk-RJQ4YEZV.js';
|