@c1m-public/channel-client 0.1.0 → 0.3.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 +34 -2
- package/dist/index.d.ts +75 -2
- package/dist/index.js +123 -49
- package/dist/types.d.ts +73 -8
- package/package.json +23 -5
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ const channel = createChannelClient({
|
|
|
13
13
|
cache: { revalidate: 60 },
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const { page } = await channel.pages.get("home");
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
The package must only be imported from server modules. Never expose the token in
|
|
@@ -28,8 +28,40 @@ asset requests.
|
|
|
28
28
|
- Requests time out after 10 seconds by default.
|
|
29
29
|
- API failures throw `ChannelAPIError` with safe status, code, and request ID.
|
|
30
30
|
- Assets remain tokenless and are normalized with `assetUrl()`.
|
|
31
|
+
- `observe` can receive one bounded telemetry event per logical request. Events
|
|
32
|
+
contain operation, outcome, status, request ID, duration and attempt count;
|
|
33
|
+
they never contain URLs, credentials, headers, bodies or customer data.
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
```ts
|
|
36
|
+
const channel = createChannelClient({
|
|
37
|
+
baseUrl: process.env.C1M_API_URL!,
|
|
38
|
+
token: process.env.C1M_CHANNEL_TOKEN!,
|
|
39
|
+
observe(event) {
|
|
40
|
+
console.info("c1m.channel", event);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Webhooks
|
|
46
|
+
|
|
47
|
+
Verify webhook requests before parsing or acting on their payload:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { parseChannelWebhookEvent } from "@c1m-public/channel-client";
|
|
51
|
+
|
|
52
|
+
const event = await parseChannelWebhookEvent(request, {
|
|
53
|
+
secret: process.env.C1M_CHANNEL_WEBHOOK_SECRET!,
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The verifier authenticates the raw body and `X-C1M-Timestamp` with the
|
|
58
|
+
`X-C1M-Signature` HMAC using a timing-safe comparison. It rejects timestamps
|
|
59
|
+
outside a five-minute window by default, including future timestamps. Keep the
|
|
60
|
+
raw request body intact, return a non-success response on verification failure,
|
|
61
|
+
and make event handling idempotent: the timestamp window limits replay exposure
|
|
62
|
+
but does not provide single-delivery semantics.
|
|
63
|
+
|
|
64
|
+
## Release
|
|
33
65
|
|
|
34
66
|
Build and inspect before publishing:
|
|
35
67
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "server-only";
|
|
2
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";
|
|
3
|
+
export type { BlogPost, BlogPostResponse, ChannelPing, Customer, CustomerResponse, CustomerSession, CustomerSignupResponse, LeadResponse, Order, OrderSummary, SendCodeResponse, LightInitResponse, ListResponse, Product, ProductAsset, PublicPage, PublicPageSummary, PublicSubmitReviewInput, PublicWorkspaceInit, Menu, MenuItem, MenuResponse, Review, ReviewSummaryResponse, SiteDocument, SiteGatedDocument, SiteResolvedDocument, ThemeResponse, } from "./types";
|
|
4
|
+
import type { BlogPostResponse, ChannelPing, CustomerResponse, CustomerSession, CustomerSignupResponse, LeadResponse, LightInitResponse, ListResponse, Order, OrderSummary, SendCodeResponse, Product, ProductAsset, PublicPage, PublicPageSummary, PublicSubmitReviewInput, PublicWorkspaceInit, MenuResponse, Review, ReviewSummaryResponse, SiteDocument, ThemeResponse } from "./types";
|
|
5
5
|
export type ChannelCachePolicy = "no-store" | {
|
|
6
6
|
revalidate: number;
|
|
7
7
|
tags?: string[];
|
|
@@ -17,7 +17,24 @@ export interface CreateChannelClientOptions {
|
|
|
17
17
|
cache?: ChannelCachePolicy;
|
|
18
18
|
timeoutMs?: number;
|
|
19
19
|
retry?: ChannelRetryPolicy | false;
|
|
20
|
+
observe?: ChannelRequestObserver;
|
|
20
21
|
}
|
|
22
|
+
export type ChannelRequestOutcome = "success" | "api_error" | "network_error" | "timeout" | "invalid_response";
|
|
23
|
+
export type ChannelOperation = "channel.ping" | "channel.site.resolve" | "channel.init.get" | "channel.init.light" | "content.pages.public.list.channel" | "content.pages.public.get.channel" | "shop.public.products.list.channel" | "shop.public.products.get.channel" | "shop.public.products.media.channel" | "reviews.public.list.channel" | "reviews.public.summary.channel" | "reviews.public.submit.channel" | "channel.theme.get" | "channel.menus.get" | "channel.blog.get" | "channel.auth.check" | "channel.auth.signup" | "channel.auth.send_code" | "channel.auth.verify_code" | "channel.auth.refresh" | "channel.auth.me" | "channel.auth.me.update" | "channel.auth.logout" | "channel.account.orders.list" | "channel.account.orders.summary" | "channel.account.orders.get" | "growth.public_workspace.leads.capture.channel";
|
|
24
|
+
export interface ChannelRequestObservation {
|
|
25
|
+
operation: ChannelOperation;
|
|
26
|
+
method: string;
|
|
27
|
+
outcome: ChannelRequestOutcome;
|
|
28
|
+
status: number;
|
|
29
|
+
requestId: string;
|
|
30
|
+
durationMs: number;
|
|
31
|
+
attempts: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Receives bounded request telemetry. Observations deliberately exclude URLs,
|
|
35
|
+
* headers, credentials, request bodies, response bodies and customer data.
|
|
36
|
+
*/
|
|
37
|
+
export type ChannelRequestObserver = (observation: ChannelRequestObservation) => void;
|
|
21
38
|
export interface ChannelListParams {
|
|
22
39
|
cursor?: string;
|
|
23
40
|
limit?: number;
|
|
@@ -46,6 +63,16 @@ export declare class ChannelAPIError extends Error {
|
|
|
46
63
|
constructor(message: string, status: number, code: string, requestId: string);
|
|
47
64
|
}
|
|
48
65
|
export declare function createChannelClient(options: CreateChannelClientOptions): {
|
|
66
|
+
/**
|
|
67
|
+
* Verify the channel token and see what it points at.
|
|
68
|
+
*
|
|
69
|
+
* The cheapest call on the door — it does no database work server-side. Use
|
|
70
|
+
* it as a deployment health check: a 200 means C1M_CHANNEL_TOKEN is right and
|
|
71
|
+
* aimed at the workspace you expect. A ChannelAPIError with status 401 means
|
|
72
|
+
* the token is bad, revoked, or the channel is disabled (the door will not
|
|
73
|
+
* say which). A 503 means C1M is unavailable — NOT that your token is wrong.
|
|
74
|
+
*/
|
|
75
|
+
readonly ping: () => Promise<ChannelPing>;
|
|
49
76
|
readonly assetUrl: (pathOrUrl: string) => string;
|
|
50
77
|
readonly site: {
|
|
51
78
|
readonly resolve: (params?: ChannelSiteResolveParams) => Promise<SiteDocument>;
|
|
@@ -83,6 +110,52 @@ export declare function createChannelClient(options: CreateChannelClientOptions)
|
|
|
83
110
|
readonly blog: {
|
|
84
111
|
readonly get: (slug: string) => Promise<BlogPostResponse>;
|
|
85
112
|
};
|
|
113
|
+
readonly auth: {
|
|
114
|
+
readonly check: (email: string) => Promise<{
|
|
115
|
+
exists: boolean;
|
|
116
|
+
}>;
|
|
117
|
+
readonly signup: (input: {
|
|
118
|
+
email: string;
|
|
119
|
+
name: string;
|
|
120
|
+
phone?: string;
|
|
121
|
+
}) => Promise<CustomerSignupResponse>;
|
|
122
|
+
readonly sendCode: (email: string) => Promise<SendCodeResponse>;
|
|
123
|
+
readonly verifyCode: (input: {
|
|
124
|
+
email: string;
|
|
125
|
+
code: string;
|
|
126
|
+
}) => Promise<CustomerSession>;
|
|
127
|
+
readonly refresh: (refreshToken: string) => Promise<CustomerSession>;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Scope calls to a signed-in customer.
|
|
131
|
+
*
|
|
132
|
+
* The session is passed here rather than stored on the client, so it cannot
|
|
133
|
+
* leak between requests: on a server rendering for many visitors at once, a
|
|
134
|
+
* mutable "current customer" is a cross-customer data leak waiting to
|
|
135
|
+
* happen. Each request carries the session it was given, or none.
|
|
136
|
+
*
|
|
137
|
+
* Orders are scoped server-side to this customer's own email within the
|
|
138
|
+
* channel's workspace — another customer's order id returns 404.
|
|
139
|
+
*/
|
|
140
|
+
readonly withCustomer: (session: string) => {
|
|
141
|
+
readonly me: () => Promise<CustomerResponse>;
|
|
142
|
+
readonly updateProfile: (input: {
|
|
143
|
+
name?: string;
|
|
144
|
+
phone?: string;
|
|
145
|
+
}) => Promise<CustomerResponse>;
|
|
146
|
+
readonly logout: () => Promise<{
|
|
147
|
+
status?: string;
|
|
148
|
+
}>;
|
|
149
|
+
readonly orders: {
|
|
150
|
+
readonly list: (params?: ChannelListParams) => Promise<ListResponse<Order>>;
|
|
151
|
+
readonly summary: () => Promise<{
|
|
152
|
+
summary: OrderSummary;
|
|
153
|
+
}>;
|
|
154
|
+
readonly get: (orderId: string) => Promise<{
|
|
155
|
+
order: Order;
|
|
156
|
+
}>;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
86
159
|
readonly leads: {
|
|
87
160
|
readonly create: (input: ChannelLeadInput, mutation?: ChannelMutationOptions) => Promise<{
|
|
88
161
|
lead: LeadResponse;
|
package/dist/index.js
CHANGED
|
@@ -69,97 +69,171 @@ export function createChannelClient(options) {
|
|
|
69
69
|
}
|
|
70
70
|
const retryAttempts = configuredRetryAttempts;
|
|
71
71
|
const maxRetryDelayMs = positiveNumber(options.retry === false ? 2_000 : options.retry?.maxDelayMs ?? 2_000, "retry.maxDelayMs");
|
|
72
|
-
|
|
72
|
+
const observe = options.observe;
|
|
73
|
+
async function request(operation, path, init = {}, session) {
|
|
73
74
|
const method = (init.method ?? "GET").toUpperCase();
|
|
75
|
+
const startedAt = Date.now();
|
|
76
|
+
let attempts = 0;
|
|
77
|
+
let status = 0;
|
|
78
|
+
let requestId = "";
|
|
79
|
+
let outcome = "network_error";
|
|
74
80
|
const headers = new Headers(init.headers);
|
|
81
|
+
// The channel token authenticates the APP. A customer is a SECOND,
|
|
82
|
+
// separate credential — Authorization is already spoken for, so the
|
|
83
|
+
// customer's session rides in its own header.
|
|
75
84
|
headers.set("Authorization", `Bearer ${token}`);
|
|
85
|
+
if (session)
|
|
86
|
+
headers.set("X-End-User-Token", session);
|
|
76
87
|
if (init.body !== undefined && !headers.has("Content-Type"))
|
|
77
88
|
headers.set("Content-Type", "application/json");
|
|
78
89
|
const requestInit = { ...init, method, headers };
|
|
79
|
-
|
|
90
|
+
// A customer-scoped read is NEVER cached, whatever cache policy the client
|
|
91
|
+
// was built with. These responses belong to one signed-in person: caching
|
|
92
|
+
// `/account/orders` under a shared revalidate+tag would serve one customer's
|
|
93
|
+
// orders from another's render. The guarantee lives here, in the library, so
|
|
94
|
+
// an app cannot lose it by constructing the client the obvious way.
|
|
95
|
+
if (method === "GET" && !session && cachePolicy !== "no-store") {
|
|
80
96
|
requestInit.next = { revalidate: cachePolicy.revalidate, ...(cachePolicy.tags ? { tags: cachePolicy.tags } : {}) };
|
|
81
97
|
}
|
|
82
98
|
else {
|
|
83
99
|
requestInit.cache = "no-store";
|
|
84
100
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
try {
|
|
102
|
+
let response;
|
|
103
|
+
for (let attempt = 0; attempt <= retryAttempts; attempt += 1) {
|
|
104
|
+
attempts = attempt + 1;
|
|
105
|
+
const controller = new AbortController();
|
|
106
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
107
|
+
try {
|
|
108
|
+
response = await fetcher(`${baseUrl}/api/v1/channel${path}`, { ...requestInit, signal: controller.signal });
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (controller.signal.aborted) {
|
|
112
|
+
outcome = "timeout";
|
|
113
|
+
throw new ChannelAPIError("Channel API request timed out", 0, "channel_request_timeout", "");
|
|
114
|
+
}
|
|
115
|
+
outcome = "network_error";
|
|
116
|
+
throw new ChannelAPIError("Channel API request failed", 0, "channel_network_error", "");
|
|
100
117
|
}
|
|
118
|
+
finally {
|
|
119
|
+
clearTimeout(timeout);
|
|
120
|
+
}
|
|
121
|
+
if (method !== "GET" || !RETRYABLE_STATUSES.has(response.status) || attempt === retryAttempts)
|
|
122
|
+
break;
|
|
123
|
+
await wait(retryDelay(response, maxRetryDelayMs));
|
|
124
|
+
}
|
|
125
|
+
if (!response)
|
|
101
126
|
throw new ChannelAPIError("Channel API request failed", 0, "channel_network_error", "");
|
|
127
|
+
status = response.status;
|
|
128
|
+
requestId = response.headers.get("X-Request-ID") ?? "";
|
|
129
|
+
if (!response.ok) {
|
|
130
|
+
const payload = (await response.json().catch(() => ({})));
|
|
131
|
+
requestId = typeof payload.request_id === "string" ? payload.request_id : requestId;
|
|
132
|
+
outcome = "api_error";
|
|
133
|
+
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);
|
|
102
134
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
135
|
+
try {
|
|
136
|
+
const payload = (await response.json());
|
|
137
|
+
outcome = "success";
|
|
138
|
+
return payload;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
outcome = "invalid_response";
|
|
142
|
+
throw new ChannelAPIError("Channel API response was not valid JSON", response.status, "invalid_channel_response", requestId);
|
|
106
143
|
}
|
|
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
144
|
}
|
|
120
|
-
|
|
121
|
-
|
|
145
|
+
finally {
|
|
146
|
+
if (observe) {
|
|
147
|
+
try {
|
|
148
|
+
observe({ operation, method, outcome, status, requestId, durationMs: Math.max(0, Date.now() - startedAt), attempts });
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// Telemetry must never become part of the request's availability path.
|
|
152
|
+
}
|
|
153
|
+
}
|
|
122
154
|
}
|
|
123
155
|
}
|
|
124
156
|
function mutationHeaders(mutation) {
|
|
125
157
|
return mutation?.idempotencyKey ? { "Idempotency-Key": mutation.idempotencyKey } : undefined;
|
|
126
158
|
}
|
|
127
159
|
return {
|
|
160
|
+
/**
|
|
161
|
+
* Verify the channel token and see what it points at.
|
|
162
|
+
*
|
|
163
|
+
* The cheapest call on the door — it does no database work server-side. Use
|
|
164
|
+
* it as a deployment health check: a 200 means C1M_CHANNEL_TOKEN is right and
|
|
165
|
+
* aimed at the workspace you expect. A ChannelAPIError with status 401 means
|
|
166
|
+
* the token is bad, revoked, or the channel is disabled (the door will not
|
|
167
|
+
* say which). A 503 means C1M is unavailable — NOT that your token is wrong.
|
|
168
|
+
*/
|
|
169
|
+
ping: () => request("channel.ping", "/ping"),
|
|
128
170
|
assetUrl: (pathOrUrl) => new URL(required(pathOrUrl, "asset URL"), `${baseUrl}/`).toString(),
|
|
129
171
|
site: {
|
|
130
|
-
resolve: (params = {}) => request(appendQuery("/site/resolve", params)),
|
|
172
|
+
resolve: (params = {}) => request("channel.site.resolve", appendQuery("/site/resolve", params)),
|
|
131
173
|
},
|
|
132
174
|
init: {
|
|
133
|
-
get: () => request("/init"),
|
|
134
|
-
light: () => request("/init/light"),
|
|
175
|
+
get: () => request("channel.init.get", "/init"),
|
|
176
|
+
light: () => request("channel.init.light", "/init/light"),
|
|
135
177
|
},
|
|
136
178
|
pages: {
|
|
137
|
-
list: (params = {}) => request(appendQuery("/pages", params)),
|
|
138
|
-
get: (slug) => request(`/pages/${encodePath(slug)}`),
|
|
179
|
+
list: (params = {}) => request("content.pages.public.list.channel", appendQuery("/pages", params)),
|
|
180
|
+
get: (slug) => request("content.pages.public.get.channel", `/pages/${encodePath(slug)}`),
|
|
139
181
|
},
|
|
140
182
|
products: {
|
|
141
|
-
list: (params = {}) => request(appendQuery("/products", params)),
|
|
142
|
-
get: (slug) => request(`/products/${encodePath(slug)}`),
|
|
143
|
-
media: (slug) => request(`/products/${encodePath(slug)}/media`),
|
|
183
|
+
list: (params = {}) => request("shop.public.products.list.channel", appendQuery("/products", params)),
|
|
184
|
+
get: (slug) => request("shop.public.products.get.channel", `/products/${encodePath(slug)}`),
|
|
185
|
+
media: (slug) => request("shop.public.products.media.channel", `/products/${encodePath(slug)}/media`),
|
|
144
186
|
},
|
|
145
187
|
reviews: {
|
|
146
|
-
list: (params = {}) => request(appendQuery("/reviews", params)),
|
|
147
|
-
summary: () => request("/reviews/summary"),
|
|
148
|
-
submit: (input, mutation) => request("/reviews", {
|
|
188
|
+
list: (params = {}) => request("reviews.public.list.channel", appendQuery("/reviews", params)),
|
|
189
|
+
summary: () => request("reviews.public.summary.channel", "/reviews/summary"),
|
|
190
|
+
submit: (input, mutation) => request("reviews.public.submit.channel", "/reviews", {
|
|
149
191
|
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
150
192
|
}),
|
|
151
193
|
},
|
|
152
194
|
theme: {
|
|
153
|
-
get: () => request("/theme"),
|
|
195
|
+
get: () => request("channel.theme.get", "/theme"),
|
|
154
196
|
},
|
|
155
197
|
menus: {
|
|
156
|
-
get: (handle) => request(`/menus/${encodePath(handle)}`),
|
|
198
|
+
get: (handle) => request("channel.menus.get", `/menus/${encodePath(handle)}`),
|
|
157
199
|
},
|
|
158
200
|
blog: {
|
|
159
|
-
get: (slug) => request(`/blog/posts/${encodePath(slug)}`),
|
|
201
|
+
get: (slug) => request("channel.blog.get", `/blog/posts/${encodePath(slug)}`),
|
|
202
|
+
},
|
|
203
|
+
// Customer sign-in. These are anonymous calls — they CREATE a session.
|
|
204
|
+
auth: {
|
|
205
|
+
check: (email) => request("channel.auth.check", "/auth/check", { method: "POST", body: JSON.stringify({ email }) }),
|
|
206
|
+
signup: (input) => request("channel.auth.signup", "/auth/signup", { method: "POST", body: JSON.stringify(input) }),
|
|
207
|
+
sendCode: (email) => request("channel.auth.send_code", "/auth/send-code", { method: "POST", body: JSON.stringify({ email }) }),
|
|
208
|
+
verifyCode: (input) => request("channel.auth.verify_code", "/auth/verify-code", { method: "POST", body: JSON.stringify(input) }),
|
|
209
|
+
refresh: (refreshToken) => request("channel.auth.refresh", "/auth/refresh", { method: "POST", body: JSON.stringify({ refresh_token: refreshToken }) }),
|
|
210
|
+
},
|
|
211
|
+
/**
|
|
212
|
+
* Scope calls to a signed-in customer.
|
|
213
|
+
*
|
|
214
|
+
* The session is passed here rather than stored on the client, so it cannot
|
|
215
|
+
* leak between requests: on a server rendering for many visitors at once, a
|
|
216
|
+
* mutable "current customer" is a cross-customer data leak waiting to
|
|
217
|
+
* happen. Each request carries the session it was given, or none.
|
|
218
|
+
*
|
|
219
|
+
* Orders are scoped server-side to this customer's own email within the
|
|
220
|
+
* channel's workspace — another customer's order id returns 404.
|
|
221
|
+
*/
|
|
222
|
+
withCustomer(session) {
|
|
223
|
+
const customerSession = required(session, "session");
|
|
224
|
+
return {
|
|
225
|
+
me: () => request("channel.auth.me", "/auth/me", {}, customerSession),
|
|
226
|
+
updateProfile: (input) => request("channel.auth.me.update", "/auth/me", { method: "PUT", body: JSON.stringify(input) }, customerSession),
|
|
227
|
+
logout: () => request("channel.auth.logout", "/auth/logout", { method: "POST" }, customerSession),
|
|
228
|
+
orders: {
|
|
229
|
+
list: (params = {}) => request("channel.account.orders.list", appendQuery("/account/orders", params), {}, customerSession),
|
|
230
|
+
summary: () => request("channel.account.orders.summary", "/account/orders/summary", {}, customerSession),
|
|
231
|
+
get: (orderId) => request("channel.account.orders.get", `/account/orders/${encodePath(orderId)}`, {}, customerSession),
|
|
232
|
+
},
|
|
233
|
+
};
|
|
160
234
|
},
|
|
161
235
|
leads: {
|
|
162
|
-
create: (input, mutation) => request("/leads", {
|
|
236
|
+
create: (input, mutation) => request("growth.public_workspace.leads.capture.channel", "/leads", {
|
|
163
237
|
method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
|
|
164
238
|
}),
|
|
165
239
|
},
|
package/dist/types.d.ts
CHANGED
|
@@ -41,21 +41,36 @@ export interface LightInitResponse {
|
|
|
41
41
|
etag?: string;
|
|
42
42
|
}
|
|
43
43
|
export interface PublicPageSummary {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
id: string;
|
|
45
|
+
saas_app: string;
|
|
46
|
+
workspace_id: string;
|
|
47
|
+
source: string;
|
|
48
|
+
route_kind: string;
|
|
49
|
+
route_pattern: string;
|
|
47
50
|
slug: string;
|
|
48
51
|
title: string;
|
|
52
|
+
status: string;
|
|
53
|
+
status_reason: string;
|
|
49
54
|
visibility: "hidden" | "visible";
|
|
55
|
+
edit_mode: string;
|
|
56
|
+
draft_revision: number;
|
|
57
|
+
created_at: string;
|
|
58
|
+
updated_at: string;
|
|
50
59
|
}
|
|
51
60
|
export interface PublicPage extends PublicPageSummary {
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
owner_app?: string;
|
|
62
|
+
required_apps?: string[];
|
|
63
|
+
required_features?: string[];
|
|
54
64
|
seo_title?: string;
|
|
55
65
|
seo_description?: string;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
draft_state?: unknown;
|
|
67
|
+
layout_state?: unknown;
|
|
68
|
+
published_at?: string;
|
|
69
|
+
manifest_key?: string;
|
|
70
|
+
manifest_version?: number;
|
|
71
|
+
template_key?: string;
|
|
72
|
+
theme_id?: string;
|
|
73
|
+
default_shell_template_id?: string;
|
|
59
74
|
}
|
|
60
75
|
export interface Product {
|
|
61
76
|
id: string;
|
|
@@ -222,3 +237,53 @@ export interface BlogPostResponse {
|
|
|
222
237
|
export interface ThemeResponse {
|
|
223
238
|
theme: Record<string, unknown> | null;
|
|
224
239
|
}
|
|
240
|
+
export interface Customer {
|
|
241
|
+
id: string;
|
|
242
|
+
email: string;
|
|
243
|
+
name: string;
|
|
244
|
+
email_verified?: boolean;
|
|
245
|
+
is_active?: boolean;
|
|
246
|
+
[key: string]: unknown;
|
|
247
|
+
}
|
|
248
|
+
/** Returned by verify-code and refresh. `access_token` is the session. */
|
|
249
|
+
export interface CustomerSession {
|
|
250
|
+
access_token: string;
|
|
251
|
+
refresh_token: string;
|
|
252
|
+
token_type: string;
|
|
253
|
+
expires_at: string;
|
|
254
|
+
end_user: Customer;
|
|
255
|
+
}
|
|
256
|
+
export interface CustomerSignupResponse {
|
|
257
|
+
end_user: Customer;
|
|
258
|
+
created: boolean;
|
|
259
|
+
requires_email_verification: boolean;
|
|
260
|
+
}
|
|
261
|
+
export interface SendCodeResponse {
|
|
262
|
+
status: string;
|
|
263
|
+
purpose: string;
|
|
264
|
+
}
|
|
265
|
+
export interface CustomerResponse {
|
|
266
|
+
end_user: Customer;
|
|
267
|
+
}
|
|
268
|
+
export interface Order {
|
|
269
|
+
id: string;
|
|
270
|
+
order_number: string;
|
|
271
|
+
status: string;
|
|
272
|
+
payment_status: string;
|
|
273
|
+
currency: string;
|
|
274
|
+
total_cents: number;
|
|
275
|
+
created_at: string;
|
|
276
|
+
[key: string]: unknown;
|
|
277
|
+
}
|
|
278
|
+
export interface OrderSummary {
|
|
279
|
+
base_currency: string;
|
|
280
|
+
total_orders: number;
|
|
281
|
+
[key: string]: unknown;
|
|
282
|
+
}
|
|
283
|
+
/** What the door reports about the token you just used. */
|
|
284
|
+
export interface ChannelPing {
|
|
285
|
+
channel_id: string;
|
|
286
|
+
workspace_id: string;
|
|
287
|
+
saas_app: string;
|
|
288
|
+
api_version: string;
|
|
289
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c1m-public/channel-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Server-only TypeScript client for the MML headless Channel API",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/cloud1mediaLtd/mml-js.git",
|
|
10
|
+
"directory": "packages/channel-client"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/cloud1mediaLtd/mml-js/tree/main/packages/channel-client",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/cloud1mediaLtd/mml-js/issues"
|
|
15
|
+
},
|
|
7
16
|
"main": "./dist/index.js",
|
|
8
17
|
"types": "./dist/index.d.ts",
|
|
9
18
|
"exports": {
|
|
@@ -12,9 +21,16 @@
|
|
|
12
21
|
"default": "./dist/index.js"
|
|
13
22
|
}
|
|
14
23
|
},
|
|
15
|
-
"files": [
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
18
34
|
"scripts": {
|
|
19
35
|
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
20
36
|
"build": "pnpm clean && tsc -p tsconfig.build.json",
|
|
@@ -23,7 +39,9 @@
|
|
|
23
39
|
"test:run": "vitest run",
|
|
24
40
|
"type-check": "tsc -p tsconfig.json --noEmit"
|
|
25
41
|
},
|
|
26
|
-
"dependencies": {
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"server-only": "0.0.1"
|
|
44
|
+
},
|
|
27
45
|
"devDependencies": {
|
|
28
46
|
"typescript": "5.9.3",
|
|
29
47
|
"vitest": "^4.1.4"
|