@c1m-public/channel-client 0.1.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/LICENSE +21 -0
- package/README.md +46 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +167 -0
- package/dist/types.d.ts +224 -0
- package/dist/types.js +1 -0
- package/dist/webhooks.d.ts +130 -0
- package/dist/webhooks.js +158 -0
- package/package.json +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cloud1Media Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# `@c1m-public/channel-client`
|
|
2
|
+
|
|
3
|
+
Server-only TypeScript client for the C1M Channel API. Channel credentials resolve
|
|
4
|
+
the tenant and workspace at the API door, so site URLs never carry either
|
|
5
|
+
identifier.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createChannelClient } from "@c1m-public/channel-client";
|
|
9
|
+
|
|
10
|
+
const channel = createChannelClient({
|
|
11
|
+
baseUrl: process.env.C1M_API_URL!,
|
|
12
|
+
token: process.env.C1M_CHANNEL_TOKEN!,
|
|
13
|
+
cache: { revalidate: 60 },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const document = await channel.site.resolve({ route: "/" });
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The package must only be imported from server modules. Never expose the token in
|
|
20
|
+
`NEXT_PUBLIC_*`, Client Components, browser storage, HTML, source maps, logs, or
|
|
21
|
+
asset requests.
|
|
22
|
+
|
|
23
|
+
## Behavior
|
|
24
|
+
|
|
25
|
+
- Reads may use explicit Next.js revalidation and retry one transient response.
|
|
26
|
+
- Writes are always `no-store`, are never automatically retried, and accept an
|
|
27
|
+
explicit idempotency key.
|
|
28
|
+
- Requests time out after 10 seconds by default.
|
|
29
|
+
- API failures throw `ChannelAPIError` with safe status, code, and request ID.
|
|
30
|
+
- Assets remain tokenless and are normalized with `assetUrl()`.
|
|
31
|
+
|
|
32
|
+
## Private release
|
|
33
|
+
|
|
34
|
+
Build and inspect before publishing:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pnpm --filter @c1m-public/channel-client test:run
|
|
38
|
+
pnpm --filter @c1m-public/channel-client build
|
|
39
|
+
pnpm --filter @c1m-public/channel-client pack
|
|
40
|
+
npm publish --access public
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The first release is published interactively with account 2FA. After the package
|
|
44
|
+
exists, configure npm trusted publishing or staged publishing for GitHub Actions
|
|
45
|
+
instead of storing a long-lived bypass-2FA write token. Increment the package
|
|
46
|
+
version for every release; sites consume exact or controlled semver ranges.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
export * from "./webhooks.js";
|
|
3
|
+
export type { BlogPost, BlogPostResponse, LeadResponse, LightInitResponse, ListResponse, Product, ProductAsset, PublicPage, PublicPageSummary, PublicSubmitReviewInput, PublicWorkspaceInit, Menu, MenuItem, MenuResponse, Review, ReviewSummaryResponse, SiteDocument, SiteGatedDocument, SiteResolvedDocument, ThemeResponse, } from "./types";
|
|
4
|
+
import type { BlogPostResponse, LeadResponse, LightInitResponse, ListResponse, Product, ProductAsset, PublicPage, PublicPageSummary, PublicSubmitReviewInput, PublicWorkspaceInit, MenuResponse, Review, ReviewSummaryResponse, SiteDocument, ThemeResponse } from "./types";
|
|
5
|
+
export type ChannelCachePolicy = "no-store" | {
|
|
6
|
+
revalidate: number;
|
|
7
|
+
tags?: string[];
|
|
8
|
+
};
|
|
9
|
+
export interface ChannelRetryPolicy {
|
|
10
|
+
attempts?: number;
|
|
11
|
+
maxDelayMs?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface CreateChannelClientOptions {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
token: string;
|
|
16
|
+
fetch?: typeof globalThis.fetch;
|
|
17
|
+
cache?: ChannelCachePolicy;
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
retry?: ChannelRetryPolicy | false;
|
|
20
|
+
}
|
|
21
|
+
export interface ChannelListParams {
|
|
22
|
+
cursor?: string;
|
|
23
|
+
limit?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface ChannelProductListParams extends ChannelListParams {
|
|
26
|
+
currency?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ChannelSiteResolveParams {
|
|
29
|
+
route?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ChannelLeadInput {
|
|
32
|
+
name?: string;
|
|
33
|
+
email?: string;
|
|
34
|
+
phone?: string;
|
|
35
|
+
message?: string;
|
|
36
|
+
source?: string;
|
|
37
|
+
meta?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
export interface ChannelMutationOptions {
|
|
40
|
+
idempotencyKey?: string;
|
|
41
|
+
}
|
|
42
|
+
export declare class ChannelAPIError extends Error {
|
|
43
|
+
readonly status: number;
|
|
44
|
+
readonly code: string;
|
|
45
|
+
readonly requestId: string;
|
|
46
|
+
constructor(message: string, status: number, code: string, requestId: string);
|
|
47
|
+
}
|
|
48
|
+
export declare function createChannelClient(options: CreateChannelClientOptions): {
|
|
49
|
+
readonly assetUrl: (pathOrUrl: string) => string;
|
|
50
|
+
readonly site: {
|
|
51
|
+
readonly resolve: (params?: ChannelSiteResolveParams) => Promise<SiteDocument>;
|
|
52
|
+
};
|
|
53
|
+
readonly init: {
|
|
54
|
+
readonly get: () => Promise<PublicWorkspaceInit>;
|
|
55
|
+
readonly light: () => Promise<LightInitResponse>;
|
|
56
|
+
};
|
|
57
|
+
readonly pages: {
|
|
58
|
+
readonly list: (params?: ChannelListParams) => Promise<ListResponse<PublicPageSummary>>;
|
|
59
|
+
readonly get: (slug: string) => Promise<{
|
|
60
|
+
page: PublicPage;
|
|
61
|
+
}>;
|
|
62
|
+
};
|
|
63
|
+
readonly products: {
|
|
64
|
+
readonly list: (params?: ChannelProductListParams) => Promise<ListResponse<Product>>;
|
|
65
|
+
readonly get: (slug: string) => Promise<{
|
|
66
|
+
product: Product;
|
|
67
|
+
}>;
|
|
68
|
+
readonly media: (slug: string) => Promise<ListResponse<ProductAsset>>;
|
|
69
|
+
};
|
|
70
|
+
readonly reviews: {
|
|
71
|
+
readonly list: (params?: ChannelListParams) => Promise<ListResponse<Review>>;
|
|
72
|
+
readonly summary: () => Promise<ReviewSummaryResponse>;
|
|
73
|
+
readonly submit: (input: PublicSubmitReviewInput, mutation?: ChannelMutationOptions) => Promise<{
|
|
74
|
+
message: string;
|
|
75
|
+
}>;
|
|
76
|
+
};
|
|
77
|
+
readonly theme: {
|
|
78
|
+
readonly get: () => Promise<ThemeResponse>;
|
|
79
|
+
};
|
|
80
|
+
readonly menus: {
|
|
81
|
+
readonly get: (handle: string) => Promise<MenuResponse>;
|
|
82
|
+
};
|
|
83
|
+
readonly blog: {
|
|
84
|
+
readonly get: (slug: string) => Promise<BlogPostResponse>;
|
|
85
|
+
};
|
|
86
|
+
readonly leads: {
|
|
87
|
+
readonly create: (input: ChannelLeadInput, mutation?: ChannelMutationOptions) => Promise<{
|
|
88
|
+
lead: LeadResponse;
|
|
89
|
+
}>;
|
|
90
|
+
};
|
|
91
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
export * from "./webhooks.js";
|
|
3
|
+
const CHANNEL_TOKEN_PREFIX = "sk_chan_";
|
|
4
|
+
const RETRYABLE_STATUSES = new Set([429, 502, 503, 504]);
|
|
5
|
+
export class ChannelAPIError extends Error {
|
|
6
|
+
status;
|
|
7
|
+
code;
|
|
8
|
+
requestId;
|
|
9
|
+
constructor(message, status, code, requestId) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.requestId = requestId;
|
|
14
|
+
this.name = "ChannelAPIError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function required(value, label) {
|
|
18
|
+
const normalized = value.trim();
|
|
19
|
+
if (!normalized)
|
|
20
|
+
throw new Error(`${label} is required`);
|
|
21
|
+
return normalized;
|
|
22
|
+
}
|
|
23
|
+
function positiveNumber(value, label) {
|
|
24
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
25
|
+
throw new Error(`${label} must be a positive finite number`);
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
function encodePath(value) {
|
|
29
|
+
return encodeURIComponent(required(value, "path value"));
|
|
30
|
+
}
|
|
31
|
+
function appendQuery(path, values) {
|
|
32
|
+
const query = new URLSearchParams();
|
|
33
|
+
for (const [key, value] of Object.entries(values)) {
|
|
34
|
+
if (value !== undefined && value !== "")
|
|
35
|
+
query.set(key, String(value));
|
|
36
|
+
}
|
|
37
|
+
const encoded = query.toString();
|
|
38
|
+
return encoded ? `${path}?${encoded}` : path;
|
|
39
|
+
}
|
|
40
|
+
function retryDelay(response, maxDelayMs) {
|
|
41
|
+
const value = response.headers.get("Retry-After");
|
|
42
|
+
if (!value)
|
|
43
|
+
return Math.min(250, maxDelayMs);
|
|
44
|
+
const seconds = Number(value);
|
|
45
|
+
if (Number.isFinite(seconds))
|
|
46
|
+
return Math.min(Math.max(seconds * 1_000, 0), maxDelayMs);
|
|
47
|
+
const date = Date.parse(value);
|
|
48
|
+
return Number.isNaN(date) ? Math.min(250, maxDelayMs) : Math.min(Math.max(date - Date.now(), 0), maxDelayMs);
|
|
49
|
+
}
|
|
50
|
+
function wait(ms) {
|
|
51
|
+
return ms <= 0 ? Promise.resolve() : new Promise((resolve) => setTimeout(resolve, ms));
|
|
52
|
+
}
|
|
53
|
+
export function createChannelClient(options) {
|
|
54
|
+
const baseUrl = required(options.baseUrl, "baseUrl").replace(/\/+$/, "");
|
|
55
|
+
const token = required(options.token, "token");
|
|
56
|
+
if (!token.startsWith(CHANNEL_TOKEN_PREFIX))
|
|
57
|
+
throw new Error("token must start with sk_chan_");
|
|
58
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
59
|
+
if (!fetcher)
|
|
60
|
+
throw new Error("fetch implementation is required");
|
|
61
|
+
const cachePolicy = options.cache ?? "no-store";
|
|
62
|
+
if (cachePolicy !== "no-store" && (!Number.isFinite(cachePolicy.revalidate) || cachePolicy.revalidate < 0)) {
|
|
63
|
+
throw new Error("cache.revalidate must be a non-negative finite number");
|
|
64
|
+
}
|
|
65
|
+
const timeoutMs = positiveNumber(options.timeoutMs ?? 10_000, "timeoutMs");
|
|
66
|
+
const configuredRetryAttempts = options.retry === false ? 0 : options.retry?.attempts ?? 1;
|
|
67
|
+
if (!Number.isSafeInteger(configuredRetryAttempts) || configuredRetryAttempts < 0) {
|
|
68
|
+
throw new Error("retry.attempts must be a non-negative safe integer");
|
|
69
|
+
}
|
|
70
|
+
const retryAttempts = configuredRetryAttempts;
|
|
71
|
+
const maxRetryDelayMs = positiveNumber(options.retry === false ? 2_000 : options.retry?.maxDelayMs ?? 2_000, "retry.maxDelayMs");
|
|
72
|
+
async function request(path, init = {}) {
|
|
73
|
+
const method = (init.method ?? "GET").toUpperCase();
|
|
74
|
+
const headers = new Headers(init.headers);
|
|
75
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
76
|
+
if (init.body !== undefined && !headers.has("Content-Type"))
|
|
77
|
+
headers.set("Content-Type", "application/json");
|
|
78
|
+
const requestInit = { ...init, method, headers };
|
|
79
|
+
if (method === "GET" && cachePolicy !== "no-store") {
|
|
80
|
+
requestInit.next = { revalidate: cachePolicy.revalidate, ...(cachePolicy.tags ? { tags: cachePolicy.tags } : {}) };
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
requestInit.cache = "no-store";
|
|
84
|
+
}
|
|
85
|
+
let response;
|
|
86
|
+
for (let attempt = 0; attempt <= retryAttempts; attempt += 1) {
|
|
87
|
+
const controller = new AbortController();
|
|
88
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
89
|
+
const abort = () => controller.abort();
|
|
90
|
+
init.signal?.addEventListener("abort", abort, { once: true });
|
|
91
|
+
if (init.signal?.aborted)
|
|
92
|
+
controller.abort();
|
|
93
|
+
try {
|
|
94
|
+
response = await fetcher(`${baseUrl}/api/v1/channel${path}`, { ...requestInit, signal: controller.signal });
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (controller.signal.aborted) {
|
|
98
|
+
const code = init.signal?.aborted ? "channel_request_aborted" : "channel_request_timeout";
|
|
99
|
+
throw new ChannelAPIError(code === "channel_request_timeout" ? "Channel API request timed out" : "Channel API request aborted", 0, code, "");
|
|
100
|
+
}
|
|
101
|
+
throw new ChannelAPIError("Channel API request failed", 0, "channel_network_error", "");
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
clearTimeout(timeout);
|
|
105
|
+
init.signal?.removeEventListener("abort", abort);
|
|
106
|
+
}
|
|
107
|
+
if (method !== "GET" || !RETRYABLE_STATUSES.has(response.status) || attempt === retryAttempts)
|
|
108
|
+
break;
|
|
109
|
+
await wait(retryDelay(response, maxRetryDelayMs));
|
|
110
|
+
}
|
|
111
|
+
if (!response)
|
|
112
|
+
throw new ChannelAPIError("Channel API request failed", 0, "channel_network_error", "");
|
|
113
|
+
if (!response.ok) {
|
|
114
|
+
const payload = (await response.json().catch(() => ({})));
|
|
115
|
+
throw new ChannelAPIError(typeof payload.message === "string" ? payload.message : "Channel API request failed", response.status, typeof payload.code === "string" ? payload.code : "channel_request_failed", typeof payload.request_id === "string" ? payload.request_id : response.headers.get("X-Request-ID") ?? "");
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
return (await response.json());
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
throw new ChannelAPIError("Channel API response was not valid JSON", response.status, "invalid_channel_response", response.headers.get("X-Request-ID") ?? "");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function mutationHeaders(mutation) {
|
|
125
|
+
return mutation?.idempotencyKey ? { "Idempotency-Key": mutation.idempotencyKey } : undefined;
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
assetUrl: (pathOrUrl) => new URL(required(pathOrUrl, "asset URL"), `${baseUrl}/`).toString(),
|
|
129
|
+
site: {
|
|
130
|
+
resolve: (params = {}) => request(appendQuery("/site/resolve", params)),
|
|
131
|
+
},
|
|
132
|
+
init: {
|
|
133
|
+
get: () => request("/init"),
|
|
134
|
+
light: () => request("/init/light"),
|
|
135
|
+
},
|
|
136
|
+
pages: {
|
|
137
|
+
list: (params = {}) => request(appendQuery("/pages", params)),
|
|
138
|
+
get: (slug) => request(`/pages/${encodePath(slug)}`),
|
|
139
|
+
},
|
|
140
|
+
products: {
|
|
141
|
+
list: (params = {}) => request(appendQuery("/products", params)),
|
|
142
|
+
get: (slug) => request(`/products/${encodePath(slug)}`),
|
|
143
|
+
media: (slug) => request(`/products/${encodePath(slug)}/media`),
|
|
144
|
+
},
|
|
145
|
+
reviews: {
|
|
146
|
+
list: (params = {}) => request(appendQuery("/reviews", params)),
|
|
147
|
+
summary: () => request("/reviews/summary"),
|
|
148
|
+
submit: (input, mutation) => request("/reviews", {
|
|
149
|
+
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
150
|
+
}),
|
|
151
|
+
},
|
|
152
|
+
theme: {
|
|
153
|
+
get: () => request("/theme"),
|
|
154
|
+
},
|
|
155
|
+
menus: {
|
|
156
|
+
get: (handle) => request(`/menus/${encodePath(handle)}`),
|
|
157
|
+
},
|
|
158
|
+
blog: {
|
|
159
|
+
get: (slug) => request(`/blog/posts/${encodePath(slug)}`),
|
|
160
|
+
},
|
|
161
|
+
leads: {
|
|
162
|
+
create: (input, mutation) => request("/leads", {
|
|
163
|
+
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
164
|
+
}),
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
export interface ListResponse<T> {
|
|
2
|
+
items: T[];
|
|
3
|
+
next_cursor?: string;
|
|
4
|
+
has_more?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface WorkspaceInfo {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
slug: string;
|
|
10
|
+
is_active: boolean;
|
|
11
|
+
status?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface PublicWorkspaceInit {
|
|
14
|
+
workspace: WorkspaceInfo;
|
|
15
|
+
branding?: Record<string, unknown>;
|
|
16
|
+
preferences?: Record<string, unknown>;
|
|
17
|
+
profile?: Record<string, unknown>;
|
|
18
|
+
launch?: Record<string, unknown>;
|
|
19
|
+
features?: Array<{
|
|
20
|
+
key: string;
|
|
21
|
+
name: string;
|
|
22
|
+
is_enabled: boolean;
|
|
23
|
+
is_available: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
modules?: unknown[];
|
|
26
|
+
custom?: Record<string, unknown>;
|
|
27
|
+
cache_control?: {
|
|
28
|
+
etag?: string;
|
|
29
|
+
max_age?: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface LightInitResponse {
|
|
33
|
+
workspace_id: string;
|
|
34
|
+
workspace_name: string;
|
|
35
|
+
primary_color: string;
|
|
36
|
+
logo_url?: string;
|
|
37
|
+
logo_light_url?: string;
|
|
38
|
+
logo_dark_url?: string;
|
|
39
|
+
logo_square_url?: string;
|
|
40
|
+
enabled_features: string[];
|
|
41
|
+
etag?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface PublicPageSummary {
|
|
44
|
+
page_key?: string;
|
|
45
|
+
page_type: "system" | "custom";
|
|
46
|
+
is_builder_editable: boolean;
|
|
47
|
+
slug: string;
|
|
48
|
+
title: string;
|
|
49
|
+
visibility: "hidden" | "visible";
|
|
50
|
+
}
|
|
51
|
+
export interface PublicPage extends PublicPageSummary {
|
|
52
|
+
id: string;
|
|
53
|
+
workspace_id: string;
|
|
54
|
+
seo_title?: string;
|
|
55
|
+
seo_description?: string;
|
|
56
|
+
content?: unknown;
|
|
57
|
+
created_at?: string;
|
|
58
|
+
updated_at?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface Product {
|
|
61
|
+
id: string;
|
|
62
|
+
workspace_id: string;
|
|
63
|
+
title: string;
|
|
64
|
+
slug: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
type?: string;
|
|
67
|
+
price_cents: number;
|
|
68
|
+
currency: string;
|
|
69
|
+
inventory_qty: number;
|
|
70
|
+
status: "draft" | "published" | "archived";
|
|
71
|
+
primary_image_url?: string;
|
|
72
|
+
options?: unknown[];
|
|
73
|
+
variants?: unknown[];
|
|
74
|
+
categories?: Array<{
|
|
75
|
+
id: string;
|
|
76
|
+
name: string;
|
|
77
|
+
slug: string;
|
|
78
|
+
}>;
|
|
79
|
+
created_at: string;
|
|
80
|
+
updated_at: string;
|
|
81
|
+
}
|
|
82
|
+
export interface ProductAsset {
|
|
83
|
+
id: string;
|
|
84
|
+
position: number;
|
|
85
|
+
is_featured: boolean;
|
|
86
|
+
asset: {
|
|
87
|
+
id: string;
|
|
88
|
+
source: string;
|
|
89
|
+
name: string;
|
|
90
|
+
alt_text?: string;
|
|
91
|
+
size_bytes: number;
|
|
92
|
+
mime_type?: string;
|
|
93
|
+
url?: string;
|
|
94
|
+
created_at: string;
|
|
95
|
+
};
|
|
96
|
+
created_at: string;
|
|
97
|
+
}
|
|
98
|
+
export interface Review {
|
|
99
|
+
id: string;
|
|
100
|
+
rating: number;
|
|
101
|
+
author_name: string;
|
|
102
|
+
author_email: string;
|
|
103
|
+
title: string;
|
|
104
|
+
body: string;
|
|
105
|
+
status: "pending" | "published" | "rejected";
|
|
106
|
+
source?: string;
|
|
107
|
+
created_at?: string;
|
|
108
|
+
[key: string]: unknown;
|
|
109
|
+
}
|
|
110
|
+
export interface PublicSubmitReviewInput {
|
|
111
|
+
rating: number;
|
|
112
|
+
author_name?: string;
|
|
113
|
+
author_email?: string;
|
|
114
|
+
title?: string;
|
|
115
|
+
body?: string;
|
|
116
|
+
source?: string;
|
|
117
|
+
}
|
|
118
|
+
export interface ReviewSummaryResponse {
|
|
119
|
+
summary: {
|
|
120
|
+
review_count: number;
|
|
121
|
+
average_rating: number;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export interface LeadResponse {
|
|
125
|
+
id: string;
|
|
126
|
+
workspace_id: string;
|
|
127
|
+
name: string;
|
|
128
|
+
email: string;
|
|
129
|
+
phone?: string;
|
|
130
|
+
message?: string;
|
|
131
|
+
source: string;
|
|
132
|
+
status: string;
|
|
133
|
+
meta?: Record<string, unknown>;
|
|
134
|
+
created_at: string;
|
|
135
|
+
updated_at: string;
|
|
136
|
+
}
|
|
137
|
+
export interface SiteSubject {
|
|
138
|
+
kind: "workspace";
|
|
139
|
+
id: string;
|
|
140
|
+
saas_app?: string;
|
|
141
|
+
display_name?: string;
|
|
142
|
+
}
|
|
143
|
+
export interface SiteResolvedDocument {
|
|
144
|
+
state: "resolved";
|
|
145
|
+
subject: SiteSubject;
|
|
146
|
+
page: {
|
|
147
|
+
id: string;
|
|
148
|
+
workspace_id: string;
|
|
149
|
+
slug: string;
|
|
150
|
+
title: string;
|
|
151
|
+
layout_state?: unknown;
|
|
152
|
+
draft_state?: unknown;
|
|
153
|
+
[key: string]: unknown;
|
|
154
|
+
};
|
|
155
|
+
surface?: Record<string, unknown>;
|
|
156
|
+
route_params?: Record<string, string>;
|
|
157
|
+
theme?: Record<string, unknown> | null;
|
|
158
|
+
navigation: {
|
|
159
|
+
main_menu?: Record<string, unknown> | null;
|
|
160
|
+
footer_menu?: Record<string, unknown> | null;
|
|
161
|
+
};
|
|
162
|
+
init: PublicWorkspaceInit;
|
|
163
|
+
seo?: {
|
|
164
|
+
title?: string;
|
|
165
|
+
description?: string;
|
|
166
|
+
};
|
|
167
|
+
revisions?: Record<string, string | undefined>;
|
|
168
|
+
cache_control?: {
|
|
169
|
+
etag?: string;
|
|
170
|
+
max_age?: number;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
export interface SiteGatedDocument {
|
|
174
|
+
state: "gated";
|
|
175
|
+
subject: SiteSubject;
|
|
176
|
+
gate: {
|
|
177
|
+
kind: "password";
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
export type SiteDocument = SiteResolvedDocument | SiteGatedDocument;
|
|
181
|
+
export interface MenuItem {
|
|
182
|
+
id: string;
|
|
183
|
+
parent_id?: string;
|
|
184
|
+
title: string;
|
|
185
|
+
url: string;
|
|
186
|
+
resource_type?: string;
|
|
187
|
+
resource_id?: string;
|
|
188
|
+
position: number;
|
|
189
|
+
target?: Record<string, unknown>;
|
|
190
|
+
[key: string]: unknown;
|
|
191
|
+
}
|
|
192
|
+
export interface Menu {
|
|
193
|
+
id: string;
|
|
194
|
+
workspace_id: string;
|
|
195
|
+
handle: string;
|
|
196
|
+
title: string;
|
|
197
|
+
items?: MenuItem[];
|
|
198
|
+
[key: string]: unknown;
|
|
199
|
+
}
|
|
200
|
+
export interface MenuResponse {
|
|
201
|
+
menu: Menu;
|
|
202
|
+
}
|
|
203
|
+
export interface BlogPost {
|
|
204
|
+
id: string;
|
|
205
|
+
workspace_id: string;
|
|
206
|
+
slug: string;
|
|
207
|
+
title: string;
|
|
208
|
+
status: string;
|
|
209
|
+
excerpt?: string;
|
|
210
|
+
cover_image_url?: string;
|
|
211
|
+
content?: unknown;
|
|
212
|
+
published_at?: string;
|
|
213
|
+
created_at?: string;
|
|
214
|
+
updated_at?: string;
|
|
215
|
+
[key: string]: unknown;
|
|
216
|
+
}
|
|
217
|
+
export interface BlogPostResponse {
|
|
218
|
+
post: BlogPost;
|
|
219
|
+
}
|
|
220
|
+
/** The published theme, as served to a channel that owns its own routing and
|
|
221
|
+
* therefore never calls `site.resolve` (which otherwise bundles it). */
|
|
222
|
+
export interface ThemeResponse {
|
|
223
|
+
theme: Record<string, unknown> | null;
|
|
224
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
/**
|
|
3
|
+
* Channel webhooks — the inbound half of the channel contract.
|
|
4
|
+
*
|
|
5
|
+
* The Channel API lets a headless app read. Webhooks are how it hears back: the
|
|
6
|
+
* `page.published` or `order.paid` event that drives a `revalidatePath` instead
|
|
7
|
+
* of a polling loop.
|
|
8
|
+
*
|
|
9
|
+
* Payloads are deliberately THIN. An event carries identifiers and a few stable,
|
|
10
|
+
* PII-free fields; fetch the detail back through the channel client. Data POSTed
|
|
11
|
+
* to your server can never be reached by a GDPR erasure on ours.
|
|
12
|
+
*/
|
|
13
|
+
export declare const CHANNEL_WEBHOOK_EVENT_TYPES: readonly ["order.created", "order.paid", "lead.created", "review.submitted", "page.published"];
|
|
14
|
+
export type ChannelWebhookEventType = (typeof CHANNEL_WEBHOOK_EVENT_TYPES)[number];
|
|
15
|
+
export interface OrderEventData {
|
|
16
|
+
order_id: string;
|
|
17
|
+
order_number: string;
|
|
18
|
+
status: string;
|
|
19
|
+
payment_status: string;
|
|
20
|
+
currency: string;
|
|
21
|
+
total_cents: number;
|
|
22
|
+
created_at: string;
|
|
23
|
+
}
|
|
24
|
+
export interface LeadCreatedEventData {
|
|
25
|
+
lead_id: string;
|
|
26
|
+
source: string;
|
|
27
|
+
created_at: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Fired at submission, BEFORE moderation — so it carries no review id and says
|
|
31
|
+
* nothing about whether the review was ever published. Useful for intake
|
|
32
|
+
* analytics; do not use it to revalidate a reviews page.
|
|
33
|
+
*/
|
|
34
|
+
export interface ReviewSubmittedEventData {
|
|
35
|
+
rating: number;
|
|
36
|
+
source: string;
|
|
37
|
+
submitted_at: string;
|
|
38
|
+
}
|
|
39
|
+
export interface PagePublishedEventData {
|
|
40
|
+
page_id: string;
|
|
41
|
+
route_pattern: string;
|
|
42
|
+
title: string;
|
|
43
|
+
published_at?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface ChannelWebhookEventDataMap {
|
|
46
|
+
"order.created": OrderEventData;
|
|
47
|
+
"order.paid": OrderEventData;
|
|
48
|
+
"lead.created": LeadCreatedEventData;
|
|
49
|
+
"review.submitted": ReviewSubmittedEventData;
|
|
50
|
+
"page.published": PagePublishedEventData;
|
|
51
|
+
}
|
|
52
|
+
export interface ChannelWebhookEvent<T extends ChannelWebhookEventType = ChannelWebhookEventType> {
|
|
53
|
+
/** The originating event id. Delivery is AT-LEAST-ONCE — use this to dedupe. */
|
|
54
|
+
id: string;
|
|
55
|
+
type: T;
|
|
56
|
+
api_version: string;
|
|
57
|
+
occurred_at: string;
|
|
58
|
+
workspace_id: string;
|
|
59
|
+
/** The channel the event originated from, when it came in through the door. */
|
|
60
|
+
channel_id?: string;
|
|
61
|
+
data: ChannelWebhookEventDataMap[T];
|
|
62
|
+
}
|
|
63
|
+
export type AnyChannelWebhookEvent = {
|
|
64
|
+
[T in ChannelWebhookEventType]: ChannelWebhookEvent<T>;
|
|
65
|
+
}[ChannelWebhookEventType];
|
|
66
|
+
export declare function isChannelWebhookEventType(value: string): value is ChannelWebhookEventType;
|
|
67
|
+
export type ChannelWebhookVerificationCode = "missing_signature" | "missing_timestamp" | "invalid_timestamp" | "timestamp_out_of_tolerance" | "invalid_signature" | "invalid_payload";
|
|
68
|
+
export declare class ChannelWebhookVerificationError extends Error {
|
|
69
|
+
readonly code: ChannelWebhookVerificationCode;
|
|
70
|
+
constructor(message: string, code: ChannelWebhookVerificationCode);
|
|
71
|
+
}
|
|
72
|
+
export declare const CHANNEL_WEBHOOK_SIGNATURE_HEADER = "X-C1M-Signature";
|
|
73
|
+
export declare const CHANNEL_WEBHOOK_TIMESTAMP_HEADER = "X-C1M-Timestamp";
|
|
74
|
+
export declare const CHANNEL_WEBHOOK_EVENT_ID_HEADER = "X-C1M-Event-ID";
|
|
75
|
+
/** Five minutes. Bounds how long a captured request stays replayable. */
|
|
76
|
+
export declare const DEFAULT_TOLERANCE_SECONDS = 300;
|
|
77
|
+
export interface VerifyChannelWebhookSignatureOptions {
|
|
78
|
+
/**
|
|
79
|
+
* The RAW request body, exactly as received. Re-serializing a parsed object
|
|
80
|
+
* (`JSON.stringify(await req.json())`) will not reproduce the signed bytes and
|
|
81
|
+
* verification will fail — read `await req.text()` and parse it AFTER verifying.
|
|
82
|
+
*/
|
|
83
|
+
payload: string | Uint8Array;
|
|
84
|
+
signature: string | null | undefined;
|
|
85
|
+
timestamp: string | null | undefined;
|
|
86
|
+
secret: string;
|
|
87
|
+
toleranceSeconds?: number;
|
|
88
|
+
/** Injectable clock, for tests. Milliseconds since epoch. */
|
|
89
|
+
now?: () => number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Verify a channel webhook signature.
|
|
93
|
+
*
|
|
94
|
+
* The server signs `HMAC-SHA256(secret, "<unix_seconds>.<raw body>")` and sends
|
|
95
|
+
* it as `X-C1M-Signature: sha256=<hex>`. The timestamp is signed too, so it
|
|
96
|
+
* cannot be altered to defeat the replay window.
|
|
97
|
+
*
|
|
98
|
+
* Uses WebCrypto, so it runs unchanged on Node and the edge runtime.
|
|
99
|
+
*
|
|
100
|
+
* @throws {ChannelWebhookVerificationError} if the request is not authentic.
|
|
101
|
+
*/
|
|
102
|
+
export declare function verifyChannelWebhookSignature(options: VerifyChannelWebhookSignatureOptions): Promise<void>;
|
|
103
|
+
export interface ParseChannelWebhookEventOptions {
|
|
104
|
+
secret: string;
|
|
105
|
+
toleranceSeconds?: number;
|
|
106
|
+
now?: () => number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Verify and parse a channel webhook in one step, for an App Router route
|
|
110
|
+
* handler:
|
|
111
|
+
*
|
|
112
|
+
* ```ts
|
|
113
|
+
* export async function POST(request: Request) {
|
|
114
|
+
* let event;
|
|
115
|
+
* try {
|
|
116
|
+
* event = await parseChannelWebhookEvent(request, { secret: process.env.C1M_WEBHOOK_SECRET! });
|
|
117
|
+
* } catch {
|
|
118
|
+
* return new Response("invalid signature", { status: 400 });
|
|
119
|
+
* }
|
|
120
|
+
* if (event.type === "page.published") revalidatePath(event.data.route_pattern);
|
|
121
|
+
* return new Response(null, { status: 204 });
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* Delivery is at-least-once: dedupe on `event.id` before acting on anything
|
|
126
|
+
* that is not idempotent.
|
|
127
|
+
*
|
|
128
|
+
* @throws {ChannelWebhookVerificationError} if the request is not authentic.
|
|
129
|
+
*/
|
|
130
|
+
export declare function parseChannelWebhookEvent(request: Request, options: ParseChannelWebhookEventOptions): Promise<AnyChannelWebhookEvent>;
|
package/dist/webhooks.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
/**
|
|
3
|
+
* Channel webhooks — the inbound half of the channel contract.
|
|
4
|
+
*
|
|
5
|
+
* The Channel API lets a headless app read. Webhooks are how it hears back: the
|
|
6
|
+
* `page.published` or `order.paid` event that drives a `revalidatePath` instead
|
|
7
|
+
* of a polling loop.
|
|
8
|
+
*
|
|
9
|
+
* Payloads are deliberately THIN. An event carries identifiers and a few stable,
|
|
10
|
+
* PII-free fields; fetch the detail back through the channel client. Data POSTed
|
|
11
|
+
* to your server can never be reached by a GDPR erasure on ours.
|
|
12
|
+
*/
|
|
13
|
+
export const CHANNEL_WEBHOOK_EVENT_TYPES = [
|
|
14
|
+
"order.created",
|
|
15
|
+
"order.paid",
|
|
16
|
+
"lead.created",
|
|
17
|
+
"review.submitted",
|
|
18
|
+
"page.published",
|
|
19
|
+
];
|
|
20
|
+
export function isChannelWebhookEventType(value) {
|
|
21
|
+
return CHANNEL_WEBHOOK_EVENT_TYPES.includes(value);
|
|
22
|
+
}
|
|
23
|
+
export class ChannelWebhookVerificationError extends Error {
|
|
24
|
+
code;
|
|
25
|
+
constructor(message, code) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.code = code;
|
|
28
|
+
this.name = "ChannelWebhookVerificationError";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export const CHANNEL_WEBHOOK_SIGNATURE_HEADER = "X-C1M-Signature";
|
|
32
|
+
export const CHANNEL_WEBHOOK_TIMESTAMP_HEADER = "X-C1M-Timestamp";
|
|
33
|
+
export const CHANNEL_WEBHOOK_EVENT_ID_HEADER = "X-C1M-Event-ID";
|
|
34
|
+
/** Five minutes. Bounds how long a captured request stays replayable. */
|
|
35
|
+
export const DEFAULT_TOLERANCE_SECONDS = 300;
|
|
36
|
+
const encoder = new TextEncoder();
|
|
37
|
+
function toBytes(payload) {
|
|
38
|
+
return typeof payload === "string" ? encoder.encode(payload) : payload;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Compare in time independent of how many leading characters match. A plain
|
|
42
|
+
* `===` on the hex digests leaks, through timing, how much of a forged
|
|
43
|
+
* signature was right — which is enough to reconstruct one byte at a time.
|
|
44
|
+
*/
|
|
45
|
+
function timingSafeEqual(a, b) {
|
|
46
|
+
if (a.length !== b.length)
|
|
47
|
+
return false;
|
|
48
|
+
let diff = 0;
|
|
49
|
+
for (let i = 0; i < a.length; i += 1)
|
|
50
|
+
diff |= a[i] ^ b[i];
|
|
51
|
+
return diff === 0;
|
|
52
|
+
}
|
|
53
|
+
function decodeHex(value) {
|
|
54
|
+
if (value.length === 0 || value.length % 2 !== 0)
|
|
55
|
+
return null;
|
|
56
|
+
const out = new Uint8Array(value.length / 2);
|
|
57
|
+
for (let i = 0; i < out.length; i += 1) {
|
|
58
|
+
const byte = Number.parseInt(value.slice(i * 2, i * 2 + 2), 16);
|
|
59
|
+
if (Number.isNaN(byte))
|
|
60
|
+
return null;
|
|
61
|
+
out[i] = byte;
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Verify a channel webhook signature.
|
|
67
|
+
*
|
|
68
|
+
* The server signs `HMAC-SHA256(secret, "<unix_seconds>.<raw body>")` and sends
|
|
69
|
+
* it as `X-C1M-Signature: sha256=<hex>`. The timestamp is signed too, so it
|
|
70
|
+
* cannot be altered to defeat the replay window.
|
|
71
|
+
*
|
|
72
|
+
* Uses WebCrypto, so it runs unchanged on Node and the edge runtime.
|
|
73
|
+
*
|
|
74
|
+
* @throws {ChannelWebhookVerificationError} if the request is not authentic.
|
|
75
|
+
*/
|
|
76
|
+
export async function verifyChannelWebhookSignature(options) {
|
|
77
|
+
const { payload, signature, timestamp, secret } = options;
|
|
78
|
+
const tolerance = options.toleranceSeconds ?? DEFAULT_TOLERANCE_SECONDS;
|
|
79
|
+
const now = options.now ?? Date.now;
|
|
80
|
+
if (!secret)
|
|
81
|
+
throw new Error("secret is required");
|
|
82
|
+
if (!signature) {
|
|
83
|
+
throw new ChannelWebhookVerificationError(`missing ${CHANNEL_WEBHOOK_SIGNATURE_HEADER} header`, "missing_signature");
|
|
84
|
+
}
|
|
85
|
+
if (!timestamp) {
|
|
86
|
+
throw new ChannelWebhookVerificationError(`missing ${CHANNEL_WEBHOOK_TIMESTAMP_HEADER} header`, "missing_timestamp");
|
|
87
|
+
}
|
|
88
|
+
const timestampSeconds = Number(timestamp);
|
|
89
|
+
if (!Number.isFinite(timestampSeconds) || !/^\d+$/.test(timestamp.trim())) {
|
|
90
|
+
throw new ChannelWebhookVerificationError("timestamp is not a unix timestamp", "invalid_timestamp");
|
|
91
|
+
}
|
|
92
|
+
// Replay protection. Skew is checked in BOTH directions: a far-future
|
|
93
|
+
// timestamp is as suspect as a stale one.
|
|
94
|
+
if (tolerance > 0) {
|
|
95
|
+
const ageSeconds = Math.abs(now() / 1_000 - timestampSeconds);
|
|
96
|
+
if (ageSeconds > tolerance) {
|
|
97
|
+
throw new ChannelWebhookVerificationError(`timestamp is outside the ${tolerance}s tolerance`, "timestamp_out_of_tolerance");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const provided = decodeHex(signature.startsWith("sha256=") ? signature.slice(7) : signature);
|
|
101
|
+
if (!provided) {
|
|
102
|
+
throw new ChannelWebhookVerificationError("signature is not sha256=<hex>", "invalid_signature");
|
|
103
|
+
}
|
|
104
|
+
const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
105
|
+
const body = toBytes(payload);
|
|
106
|
+
const signed = new Uint8Array(timestamp.length + 1 + body.length);
|
|
107
|
+
signed.set(encoder.encode(`${timestamp}.`), 0);
|
|
108
|
+
signed.set(body, timestamp.length + 1);
|
|
109
|
+
const expected = new Uint8Array(await crypto.subtle.sign("HMAC", key, signed));
|
|
110
|
+
if (!timingSafeEqual(expected, provided)) {
|
|
111
|
+
throw new ChannelWebhookVerificationError("signature does not match", "invalid_signature");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Verify and parse a channel webhook in one step, for an App Router route
|
|
116
|
+
* handler:
|
|
117
|
+
*
|
|
118
|
+
* ```ts
|
|
119
|
+
* export async function POST(request: Request) {
|
|
120
|
+
* let event;
|
|
121
|
+
* try {
|
|
122
|
+
* event = await parseChannelWebhookEvent(request, { secret: process.env.C1M_WEBHOOK_SECRET! });
|
|
123
|
+
* } catch {
|
|
124
|
+
* return new Response("invalid signature", { status: 400 });
|
|
125
|
+
* }
|
|
126
|
+
* if (event.type === "page.published") revalidatePath(event.data.route_pattern);
|
|
127
|
+
* return new Response(null, { status: 204 });
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* Delivery is at-least-once: dedupe on `event.id` before acting on anything
|
|
132
|
+
* that is not idempotent.
|
|
133
|
+
*
|
|
134
|
+
* @throws {ChannelWebhookVerificationError} if the request is not authentic.
|
|
135
|
+
*/
|
|
136
|
+
export async function parseChannelWebhookEvent(request, options) {
|
|
137
|
+
// Read the raw body BEFORE parsing: the signature covers these exact bytes.
|
|
138
|
+
const payload = await request.text();
|
|
139
|
+
await verifyChannelWebhookSignature({
|
|
140
|
+
payload,
|
|
141
|
+
signature: request.headers.get(CHANNEL_WEBHOOK_SIGNATURE_HEADER),
|
|
142
|
+
timestamp: request.headers.get(CHANNEL_WEBHOOK_TIMESTAMP_HEADER),
|
|
143
|
+
secret: options.secret,
|
|
144
|
+
toleranceSeconds: options.toleranceSeconds,
|
|
145
|
+
now: options.now,
|
|
146
|
+
});
|
|
147
|
+
let event;
|
|
148
|
+
try {
|
|
149
|
+
event = JSON.parse(payload);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
throw new ChannelWebhookVerificationError("body is not valid JSON", "invalid_payload");
|
|
153
|
+
}
|
|
154
|
+
if (!event || typeof event.id !== "string" || typeof event.type !== "string") {
|
|
155
|
+
throw new ChannelWebhookVerificationError("body is not a channel event", "invalid_payload");
|
|
156
|
+
}
|
|
157
|
+
return event;
|
|
158
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@c1m-public/channel-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "Server-only TypeScript client for the MML headless Channel API",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": ["dist", "README.md"],
|
|
16
|
+
"engines": { "node": ">=20" },
|
|
17
|
+
"publishConfig": { "access": "public" },
|
|
18
|
+
"scripts": {
|
|
19
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
20
|
+
"build": "pnpm clean && tsc -p tsconfig.build.json",
|
|
21
|
+
"lint": "tsc -p tsconfig.json --noEmit",
|
|
22
|
+
"test": "vitest",
|
|
23
|
+
"test:run": "vitest run",
|
|
24
|
+
"type-check": "tsc -p tsconfig.json --noEmit"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": { "server-only": "0.0.1" },
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "5.9.3",
|
|
29
|
+
"vitest": "^4.1.4"
|
|
30
|
+
}
|
|
31
|
+
}
|