@c1m-public/channel-client 0.6.0 → 0.9.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 +40 -6
- package/dist/index.d.ts +88 -4
- package/dist/index.js +148 -7
- package/dist/next-cart.d.ts +3 -1
- package/dist/next-cart.js +6 -4
- package/dist/next-session.js +5 -24
- package/dist/next-webhooks.d.ts +6 -0
- package/dist/next-webhooks.js +32 -12
- package/dist/next.d.ts +67 -0
- package/dist/types.d.ts +526 -0
- package/dist/webhooks.d.ts +42 -2
- package/dist/webhooks.js +61 -2
- package/package.json +1 -1
package/dist/next-webhooks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "server-only";
|
|
2
|
-
import { ChannelWebhookVerificationError, parseChannelWebhookEvent, } from "./webhooks.js";
|
|
2
|
+
import { ChannelWebhookVerificationError, isChannelWebhookEventType, parseChannelWebhookEvent, } from "./webhooks.js";
|
|
3
3
|
/**
|
|
4
4
|
* Webhook route factory: the whole app/api/webhooks/c1m/route.ts in one call.
|
|
5
5
|
*
|
|
@@ -16,6 +16,12 @@ import { ChannelWebhookVerificationError, parseChannelWebhookEvent, } from "./we
|
|
|
16
16
|
*/
|
|
17
17
|
/** The cache tag every anonymous site read is filed under. */
|
|
18
18
|
export const CHANNEL_SITE_CACHE_TAG = "channel:site";
|
|
19
|
+
/**
|
|
20
|
+
* The cache tag catalog reads (product list, product detail) are filed under.
|
|
21
|
+
* `product.*` events bust this tag by default, so a merchant's price edit
|
|
22
|
+
* reaches the storefront on the next request instead of at the end of a TTL.
|
|
23
|
+
*/
|
|
24
|
+
export const CHANNEL_CATALOG_CACHE_TAG = "channel:catalog";
|
|
19
25
|
/**
|
|
20
26
|
* A route_pattern arrives from the network; it is input, not truth. Reject
|
|
21
27
|
* anything that is not a plain absolute path before handing it to the cache.
|
|
@@ -36,14 +42,23 @@ function isVerificationError(error) {
|
|
|
36
42
|
typeof error.code === "string");
|
|
37
43
|
}
|
|
38
44
|
function defaultBehavior(event, invalidate) {
|
|
39
|
-
if (event.type
|
|
45
|
+
if (event.type === "page.published") {
|
|
46
|
+
const path = safePublishedPath(event.data.route_pattern);
|
|
47
|
+
if (!path)
|
|
48
|
+
throw new Error("page.published contains an invalid route_pattern");
|
|
49
|
+
invalidate.revalidateTag(CHANNEL_SITE_CACHE_TAG);
|
|
50
|
+
invalidate.revalidatePath(path);
|
|
51
|
+
return path;
|
|
52
|
+
}
|
|
53
|
+
// A catalog edit with no cache bust means the site serves the old price
|
|
54
|
+
// until its TTL expires — so product.* busts the catalog tag by default,
|
|
55
|
+
// with no configuration. Tag your product reads with
|
|
56
|
+
// CHANNEL_CATALOG_CACHE_TAG and a price change lands on the next request.
|
|
57
|
+
if (event.type === "product.created" || event.type === "product.updated" || event.type === "product.deleted") {
|
|
58
|
+
invalidate.revalidateTag(CHANNEL_CATALOG_CACHE_TAG);
|
|
40
59
|
return undefined;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
throw new Error("page.published contains an invalid route_pattern");
|
|
44
|
-
invalidate.revalidateTag(CHANNEL_SITE_CACHE_TAG);
|
|
45
|
-
invalidate.revalidatePath(path);
|
|
46
|
-
return path;
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
47
62
|
}
|
|
48
63
|
/** Build the POST handler for the channel webhook endpoint. */
|
|
49
64
|
export function createChannelWebhookRoute(options) {
|
|
@@ -65,17 +80,22 @@ export function createChannelWebhookRoute(options) {
|
|
|
65
80
|
return Response.json({ code: "channel_webhook_failed" }, { status: 500 });
|
|
66
81
|
}
|
|
67
82
|
try {
|
|
68
|
-
|
|
83
|
+
if (!isChannelWebhookEventType(event.type)) {
|
|
84
|
+
logger.info("channel_webhook_ignored", { eventId: event.id, eventType: event.type });
|
|
85
|
+
return new Response(null, { status: 204 });
|
|
86
|
+
}
|
|
87
|
+
const knownEvent = event;
|
|
88
|
+
const handler = options.onEvent?.[knownEvent.type];
|
|
69
89
|
let revalidatedPath;
|
|
70
90
|
if (handler) {
|
|
71
|
-
await handler(
|
|
91
|
+
await handler(knownEvent, options.invalidate);
|
|
72
92
|
}
|
|
73
93
|
else {
|
|
74
|
-
revalidatedPath = defaultBehavior(
|
|
94
|
+
revalidatedPath = defaultBehavior(knownEvent, options.invalidate);
|
|
75
95
|
}
|
|
76
96
|
logger.info("channel_webhook_processed", {
|
|
77
97
|
eventId: event.id,
|
|
78
|
-
eventType:
|
|
98
|
+
eventType: knownEvent.type,
|
|
79
99
|
...(revalidatedPath ? { revalidatedPath } : {}),
|
|
80
100
|
});
|
|
81
101
|
return new Response(null, { status: 204 });
|
package/dist/next.d.ts
CHANGED
|
@@ -37,6 +37,17 @@ export declare function createNextChannelClient(options: CreateNextChannelClient
|
|
|
37
37
|
}>;
|
|
38
38
|
readonly media: (slug: string) => Promise<import("./types.js").ListResponse<import("./types.js").ProductAsset>>;
|
|
39
39
|
};
|
|
40
|
+
readonly categories: {
|
|
41
|
+
readonly list: (params?: import("./index.js").ChannelListParams) => Promise<import("./types.js").ListResponse<import("./types.js").CatalogCategory>>;
|
|
42
|
+
readonly products: (slug: string) => Promise<import("./types.js").CatalogProductsResponse>;
|
|
43
|
+
};
|
|
44
|
+
readonly collections: {
|
|
45
|
+
readonly list: (params?: import("./index.js").ChannelListParams) => Promise<import("./types.js").ListResponse<import("./types.js").CatalogCollection>>;
|
|
46
|
+
readonly products: (slug: string) => Promise<import("./types.js").CatalogProductsResponse>;
|
|
47
|
+
};
|
|
48
|
+
readonly brands: {
|
|
49
|
+
readonly list: (params?: import("./index.js").ChannelListParams) => Promise<import("./types.js").ListResponse<import("./types.js").CatalogBrand>>;
|
|
50
|
+
};
|
|
40
51
|
readonly cart: {
|
|
41
52
|
readonly get: (cartToken: string) => Promise<import("./types.js").CartResponse>;
|
|
42
53
|
readonly addItem: (input: import("./types.js").AddCartItemInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").CartResponse>;
|
|
@@ -67,8 +78,30 @@ export declare function createNextChannelClient(options: CreateNextChannelClient
|
|
|
67
78
|
readonly get: (handle: string) => Promise<import("./types.js").MenuResponse>;
|
|
68
79
|
};
|
|
69
80
|
readonly blog: {
|
|
81
|
+
readonly list: (params?: import("./index.js").ChannelListParams) => Promise<import("./types.js").ListResponse<import("./types.js").BlogPost>>;
|
|
70
82
|
readonly get: (slug: string) => Promise<import("./types.js").BlogPostResponse>;
|
|
71
83
|
};
|
|
84
|
+
readonly giving: {
|
|
85
|
+
readonly entries: {
|
|
86
|
+
readonly list: () => Promise<{
|
|
87
|
+
items: import("./types.js").GivingEntry[];
|
|
88
|
+
}>;
|
|
89
|
+
readonly get: (slug: string) => Promise<{
|
|
90
|
+
entry: import("./types.js").GivingEntry;
|
|
91
|
+
}>;
|
|
92
|
+
};
|
|
93
|
+
readonly start: (input: import("./types.js").StartGivingInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").StartGivingResponse>;
|
|
94
|
+
};
|
|
95
|
+
readonly print: {
|
|
96
|
+
readonly settings: () => Promise<import("./types.js").PrintSettingsResponse>;
|
|
97
|
+
readonly quote: (input: import("./types.js").PrintOptionsSelection) => Promise<import("./types.js").PrintQuoteResponse>;
|
|
98
|
+
readonly intake: (input: import("./types.js").PrintIntakeInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<{
|
|
99
|
+
job: import("./types.js").PrintJob;
|
|
100
|
+
}>;
|
|
101
|
+
};
|
|
102
|
+
readonly dining: {
|
|
103
|
+
readonly menu: (boardSlug: string) => Promise<import("./types.js").DiningMenu>;
|
|
104
|
+
};
|
|
72
105
|
readonly auth: {
|
|
73
106
|
readonly check: (email: string) => Promise<{
|
|
74
107
|
exists: boolean;
|
|
@@ -103,6 +136,40 @@ export declare function createNextChannelClient(options: CreateNextChannelClient
|
|
|
103
136
|
order: import("./types.js").Order;
|
|
104
137
|
}>;
|
|
105
138
|
};
|
|
139
|
+
readonly addresses: {
|
|
140
|
+
readonly list: () => Promise<import("./types.js").ListResponse<import("./types.js").SavedAddress>>;
|
|
141
|
+
readonly get: (addressId: string) => Promise<import("./types.js").SavedAddressResponse>;
|
|
142
|
+
readonly create: (input: import("./types.js").SavedAddressInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").SavedAddressResponse>;
|
|
143
|
+
readonly update: (addressId: string, input: import("./types.js").SavedAddressUpdateInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").SavedAddressResponse>;
|
|
144
|
+
readonly delete: (addressId: string, mutation?: import("./index.js").ChannelMutationOptions) => Promise<{
|
|
145
|
+
status?: string;
|
|
146
|
+
}>;
|
|
147
|
+
readonly setDefault: (addressId: string, kind: import("./types.js").SavedAddressDefaultKind, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").SavedAddressResponse>;
|
|
148
|
+
};
|
|
149
|
+
readonly paymentMethods: {
|
|
150
|
+
readonly list: () => Promise<import("./types.js").ListResponse<import("./types.js").SavedPaymentMethod>>;
|
|
151
|
+
readonly setup: (input: import("./types.js").PaymentMethodSetupInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").PaymentMethodSetupResult>;
|
|
152
|
+
readonly confirm: (input: import("./types.js").PaymentMethodConfirmInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").SavedPaymentMethod>;
|
|
153
|
+
readonly setDefault: (methodId: string, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").PaymentMethodMutationResponse>;
|
|
154
|
+
readonly delete: (methodId: string, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").PaymentMethodMutationResponse>;
|
|
155
|
+
};
|
|
156
|
+
readonly subscriptions: {
|
|
157
|
+
readonly list: (params?: import("./index.js").ChannelSubscriptionListParams) => Promise<import("./types.js").SubscriptionListResponse>;
|
|
158
|
+
readonly get: (agreementId: string) => Promise<import("./types.js").SubscriptionAgreementResponse>;
|
|
159
|
+
readonly source: (agreementId: string) => Promise<import("./types.js").SubscriptionSourceResponse>;
|
|
160
|
+
readonly cancel: (agreementId: string, params?: import("./index.js").ChannelSubscriptionCancelParams, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").SubscriptionAgreementResponse>;
|
|
161
|
+
readonly pause: (agreementId: string, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").SubscriptionAgreementResponse>;
|
|
162
|
+
readonly resume: (agreementId: string, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").SubscriptionAgreementResponse>;
|
|
163
|
+
readonly invoices: {
|
|
164
|
+
readonly list: (agreementId: string, params?: import("./index.js").ChannelInvoiceListParams) => Promise<import("./types.js").SubscriptionInvoiceListResponse>;
|
|
165
|
+
readonly get: (invoiceId: string) => Promise<import("./types.js").SubscriptionInvoiceResponse>;
|
|
166
|
+
readonly payNow: (invoiceId: string, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").SubscriptionInvoiceResponse>;
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
readonly giving: {
|
|
170
|
+
readonly list: () => Promise<import("./types.js").GivingIntentListResponse>;
|
|
171
|
+
readonly start: (input: import("./types.js").StartGivingInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").StartGivingResponse>;
|
|
172
|
+
};
|
|
106
173
|
};
|
|
107
174
|
readonly leads: {
|
|
108
175
|
readonly create: (input: import("./index.js").ChannelLeadInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<{
|