@caldik/client 0.0.4 → 0.0.6
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 +6 -0
- package/dist/index.d.mts +80 -4
- package/dist/index.mjs +76 -4
- package/package.json +3 -1
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
+
//#region src/payment-providers.generated.d.ts
|
|
2
|
+
declare const paymentProviderIds: readonly ["customer_balance", "stripe", "ovgc"];
|
|
3
|
+
declare const checkoutPaymentProviderIds: readonly ["customer_balance", "stripe", "ovgc"];
|
|
4
|
+
declare const subscriptionPaymentProviderIds: readonly ["stripe"];
|
|
5
|
+
type PaymentProviderId = typeof paymentProviderIds[number];
|
|
6
|
+
type CheckoutPaymentProviderId = typeof checkoutPaymentProviderIds[number];
|
|
7
|
+
type SubscriptionPaymentProviderId = typeof subscriptionPaymentProviderIds[number];
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/store-events.generated.d.ts
|
|
10
|
+
declare const storeWebhookEventNames: readonly ["store.updated", "store.suspended", "store.restored", "domain.created", "domain.updated", "domain.deleted", "member.invited", "member.updated", "member.removed", "member.invite_revoked", "product.created", "product.updated", "product.deleted", "category.created", "category.updated", "category.deleted", "discount.created", "discount.updated", "discount.deleted", "customer.created", "customer.updated", "order.created", "order.updated", "subscription.created", "subscription.updated"];
|
|
11
|
+
type StoreWebhookEventName = typeof storeWebhookEventNames[number];
|
|
12
|
+
//#endregion
|
|
1
13
|
//#region src/types.d.ts
|
|
14
|
+
interface StorefrontMetadata {
|
|
15
|
+
id: string;
|
|
16
|
+
title: string;
|
|
17
|
+
description: string;
|
|
18
|
+
json: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
type ProductMetadata = StorefrontMetadata;
|
|
21
|
+
type CategoryMetadata = StorefrontMetadata;
|
|
2
22
|
interface Category {
|
|
3
23
|
id: string;
|
|
4
24
|
name: string;
|
|
@@ -7,6 +27,7 @@ interface Category {
|
|
|
7
27
|
price: string;
|
|
8
28
|
logo: string | null;
|
|
9
29
|
banner: string | null;
|
|
30
|
+
metadata: CategoryMetadata[];
|
|
10
31
|
}
|
|
11
32
|
interface CategoriesResponse {
|
|
12
33
|
success: boolean;
|
|
@@ -27,7 +48,11 @@ interface CategoryProduct {
|
|
|
27
48
|
interface CategoryDetails {
|
|
28
49
|
id: string;
|
|
29
50
|
name: string;
|
|
51
|
+
slug: string;
|
|
30
52
|
description: string;
|
|
53
|
+
logo: string | null;
|
|
54
|
+
banner: string | null;
|
|
55
|
+
metadata: CategoryMetadata[];
|
|
31
56
|
products: CategoryProduct[];
|
|
32
57
|
}
|
|
33
58
|
interface CategoryResponse {
|
|
@@ -68,6 +93,8 @@ interface Product {
|
|
|
68
93
|
maximumQuantity: number | null;
|
|
69
94
|
variants: ProductVariant[];
|
|
70
95
|
tags: ProductTag[];
|
|
96
|
+
customFields: ProductCustomField[];
|
|
97
|
+
metadata: ProductMetadata[];
|
|
71
98
|
}
|
|
72
99
|
interface ProductVariant {
|
|
73
100
|
id: string;
|
|
@@ -79,6 +106,23 @@ interface ProductTag {
|
|
|
79
106
|
label: string;
|
|
80
107
|
color: string;
|
|
81
108
|
}
|
|
109
|
+
type ProductCustomFieldInputType = "text" | "textarea" | "number" | "dropdown" | "checkbox";
|
|
110
|
+
interface ProductCustomFieldOption {
|
|
111
|
+
id: string;
|
|
112
|
+
label: string;
|
|
113
|
+
value: string;
|
|
114
|
+
position: number;
|
|
115
|
+
}
|
|
116
|
+
interface ProductCustomField {
|
|
117
|
+
id: string;
|
|
118
|
+
name: string;
|
|
119
|
+
inputType: ProductCustomFieldInputType;
|
|
120
|
+
placeholder: string | null;
|
|
121
|
+
position: number;
|
|
122
|
+
defaultValue: string | null;
|
|
123
|
+
requiredEnabled: boolean;
|
|
124
|
+
options: ProductCustomFieldOption[];
|
|
125
|
+
}
|
|
82
126
|
interface ProductsResponse {
|
|
83
127
|
success: boolean;
|
|
84
128
|
products: Product[];
|
|
@@ -102,7 +146,7 @@ type CommerceItem = ManualCommerceItem | ProductCommerceItem;
|
|
|
102
146
|
interface CreateOrderInput {
|
|
103
147
|
customerId?: string;
|
|
104
148
|
email?: string;
|
|
105
|
-
paymentMethod:
|
|
149
|
+
paymentMethod: CheckoutPaymentProviderId;
|
|
106
150
|
items: CommerceItem[];
|
|
107
151
|
successUrl?: string;
|
|
108
152
|
cancelUrl?: string;
|
|
@@ -118,7 +162,7 @@ interface StorefrontOrder {
|
|
|
118
162
|
currency: string;
|
|
119
163
|
}
|
|
120
164
|
interface CheckoutPayment {
|
|
121
|
-
type:
|
|
165
|
+
type: CheckoutPaymentProviderId;
|
|
122
166
|
checkoutUrl?: string | null;
|
|
123
167
|
checkoutSessionId?: string | null;
|
|
124
168
|
balanceAfter?: string;
|
|
@@ -131,6 +175,7 @@ interface OrderResponse {
|
|
|
131
175
|
interface CreateSubscriptionInput {
|
|
132
176
|
customerId?: string;
|
|
133
177
|
email?: string;
|
|
178
|
+
paymentMethod?: SubscriptionPaymentProviderId;
|
|
134
179
|
items: CommerceItem[];
|
|
135
180
|
billingInterval: "day" | "week" | "month" | "year";
|
|
136
181
|
billingIntervalCount?: number;
|
|
@@ -152,11 +197,33 @@ interface SubscriptionResponse {
|
|
|
152
197
|
currency: string;
|
|
153
198
|
};
|
|
154
199
|
payment: {
|
|
155
|
-
type:
|
|
200
|
+
type: SubscriptionPaymentProviderId;
|
|
156
201
|
checkoutUrl: string;
|
|
157
202
|
checkoutSessionId: string;
|
|
158
203
|
};
|
|
159
204
|
}
|
|
205
|
+
interface StoreWebhookEventDefinition {
|
|
206
|
+
name: StoreWebhookEventName;
|
|
207
|
+
resource: string;
|
|
208
|
+
action: string;
|
|
209
|
+
description: string;
|
|
210
|
+
}
|
|
211
|
+
interface StoreWebhookEventsResponse {
|
|
212
|
+
success: boolean;
|
|
213
|
+
apiVersion: "v1";
|
|
214
|
+
catalogVersion: string;
|
|
215
|
+
events: StoreWebhookEventDefinition[];
|
|
216
|
+
}
|
|
217
|
+
interface StoreWebhookEvent<TObject extends Record<string, unknown> = Record<string, unknown>> {
|
|
218
|
+
id: string;
|
|
219
|
+
type: StoreWebhookEventName;
|
|
220
|
+
createdAt: number;
|
|
221
|
+
storeId: string;
|
|
222
|
+
data: {
|
|
223
|
+
object: TObject;
|
|
224
|
+
previousAttributes?: Record<string, unknown>;
|
|
225
|
+
};
|
|
226
|
+
}
|
|
160
227
|
interface CustomerLoginResponse {
|
|
161
228
|
success: boolean;
|
|
162
229
|
message: string;
|
|
@@ -249,6 +316,14 @@ declare class SubscriptionsApi {
|
|
|
249
316
|
create(input: CreateSubscriptionInput): Promise<SubscriptionResponse>;
|
|
250
317
|
}
|
|
251
318
|
//#endregion
|
|
319
|
+
//#region src/webhooks.d.ts
|
|
320
|
+
declare class WebhooksApi {
|
|
321
|
+
private client;
|
|
322
|
+
constructor(client: CaldikHttpClient);
|
|
323
|
+
/** Lists the canonical events accepted by store webhook subscriptions. */
|
|
324
|
+
events(): Promise<StoreWebhookEventsResponse>;
|
|
325
|
+
}
|
|
326
|
+
//#endregion
|
|
252
327
|
//#region src/index.d.ts
|
|
253
328
|
interface CaldikClientOptions {
|
|
254
329
|
/** Store ID for external servers. Hosted Workers receive it automatically. */
|
|
@@ -265,7 +340,8 @@ declare class CaldikClient {
|
|
|
265
340
|
readonly checkout: CheckoutApi;
|
|
266
341
|
readonly customer: CustomerApi;
|
|
267
342
|
readonly subscriptions: SubscriptionsApi;
|
|
343
|
+
readonly webhooks: WebhooksApi;
|
|
268
344
|
constructor(options?: CaldikClientOptions);
|
|
269
345
|
}
|
|
270
346
|
//#endregion
|
|
271
|
-
export { CaldikClient, CaldikClientOptions, CategoriesResponse, Category, CategoryDetails, CategoryProduct, CategoryResponse, CheckoutPayment, CommerceItem, CreateOrderInput, CreateSubscriptionInput, CustomerLoginResponse, CustomerLoginVerifyResponse, ManualCommerceItem, OrderResponse, Product, ProductCommerceItem, ProductResponse, ProductTag, ProductVariant, ProductsResponse, Review, ReviewsResponse, Store, StoreResponse, StorefrontOrder, SubscriptionResponse };
|
|
347
|
+
export { CaldikClient, CaldikClientOptions, CategoriesResponse, Category, CategoryDetails, CategoryMetadata, CategoryProduct, CategoryResponse, CheckoutPayment, CheckoutPaymentProviderId, CommerceItem, CreateOrderInput, CreateSubscriptionInput, CustomerLoginResponse, CustomerLoginVerifyResponse, ManualCommerceItem, OrderResponse, PaymentProviderId, Product, ProductCommerceItem, ProductCustomField, ProductCustomFieldInputType, ProductCustomFieldOption, ProductMetadata, ProductResponse, ProductTag, ProductVariant, ProductsResponse, Review, ReviewsResponse, Store, StoreResponse, StoreWebhookEvent, StoreWebhookEventDefinition, StoreWebhookEventName, StoreWebhookEventsResponse, StorefrontMetadata, StorefrontOrder, SubscriptionPaymentProviderId, SubscriptionResponse, checkoutPaymentProviderIds, paymentProviderIds, storeWebhookEventNames, subscriptionPaymentProviderIds };
|
package/dist/index.mjs
CHANGED
|
@@ -10,6 +10,21 @@ function boundRuntimeStoreId() {
|
|
|
10
10
|
const storeId = globalThis.process?.env?.CALDIK_STORE_ID?.trim();
|
|
11
11
|
return storeId && STORE_ID_PATTERN.test(storeId) ? storeId : null;
|
|
12
12
|
}
|
|
13
|
+
function browserRuntimeStoreId() {
|
|
14
|
+
const cookies = typeof document.cookie === "string" ? document.cookie : "";
|
|
15
|
+
for (const item of cookies.split(";")) {
|
|
16
|
+
const separator = item.indexOf("=");
|
|
17
|
+
if (separator < 1) continue;
|
|
18
|
+
if (item.slice(0, separator).trim() !== "__Host-caldik-store-id") continue;
|
|
19
|
+
try {
|
|
20
|
+
const value = decodeURIComponent(item.slice(separator + 1).trim());
|
|
21
|
+
return STORE_ID_PATTERN.test(value) ? value : null;
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
13
28
|
var CaldikHttpClient = class {
|
|
14
29
|
apiKey;
|
|
15
30
|
apiUrl;
|
|
@@ -24,8 +39,9 @@ var CaldikHttpClient = class {
|
|
|
24
39
|
}
|
|
25
40
|
baseUrl() {
|
|
26
41
|
if (isBrowserRuntime()) {
|
|
27
|
-
|
|
28
|
-
|
|
42
|
+
const storeId = this.storeId || browserRuntimeStoreId();
|
|
43
|
+
if (!storeId) throw new Error("Caldik storefront context is unavailable. Hosted storefronts receive it automatically; local or externally hosted browsers must provide storeId.");
|
|
44
|
+
return `${this.apiUrl.replace(/\/+$/, "")}/v1/stores/${encodeURIComponent(storeId)}`;
|
|
29
45
|
}
|
|
30
46
|
const boundStoreId = boundRuntimeStoreId();
|
|
31
47
|
if (boundStoreId && this.storeId && boundStoreId !== this.storeId) throw new Error("Caldik storeId does not match the hosted runtime");
|
|
@@ -40,7 +56,7 @@ var CaldikHttpClient = class {
|
|
|
40
56
|
const headers = {};
|
|
41
57
|
if (!isBrowserRuntime()) headers["User-Agent"] = "CaldikClient/0.0.2";
|
|
42
58
|
if (this.apiKey) headers.Authorization = `Bearer ${this.apiKey}`;
|
|
43
|
-
else if (options?.access === "public") headers["X-Caldik-Public-Request"] = "1";
|
|
59
|
+
else if (options?.access === "public" && !isBrowserRuntime()) headers["X-Caldik-Public-Request"] = "1";
|
|
44
60
|
if (input !== void 0) headers["Content-Type"] = "application/json";
|
|
45
61
|
if (options?.edgeCache) headers["X-Cache-Policy"] = "public";
|
|
46
62
|
const response = await fetch(url, {
|
|
@@ -154,6 +170,60 @@ var SubscriptionsApi = class {
|
|
|
154
170
|
}
|
|
155
171
|
};
|
|
156
172
|
//#endregion
|
|
173
|
+
//#region src/webhooks.ts
|
|
174
|
+
var WebhooksApi = class {
|
|
175
|
+
client;
|
|
176
|
+
constructor(client) {
|
|
177
|
+
this.client = client;
|
|
178
|
+
}
|
|
179
|
+
/** Lists the canonical events accepted by store webhook subscriptions. */
|
|
180
|
+
events() {
|
|
181
|
+
return this.client.get("/webhooks/events");
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/payment-providers.generated.ts
|
|
186
|
+
const paymentProviderIds = [
|
|
187
|
+
"customer_balance",
|
|
188
|
+
"stripe",
|
|
189
|
+
"ovgc"
|
|
190
|
+
];
|
|
191
|
+
const checkoutPaymentProviderIds = [
|
|
192
|
+
"customer_balance",
|
|
193
|
+
"stripe",
|
|
194
|
+
"ovgc"
|
|
195
|
+
];
|
|
196
|
+
const subscriptionPaymentProviderIds = ["stripe"];
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/store-events.generated.ts
|
|
199
|
+
const storeWebhookEventNames = [
|
|
200
|
+
"store.updated",
|
|
201
|
+
"store.suspended",
|
|
202
|
+
"store.restored",
|
|
203
|
+
"domain.created",
|
|
204
|
+
"domain.updated",
|
|
205
|
+
"domain.deleted",
|
|
206
|
+
"member.invited",
|
|
207
|
+
"member.updated",
|
|
208
|
+
"member.removed",
|
|
209
|
+
"member.invite_revoked",
|
|
210
|
+
"product.created",
|
|
211
|
+
"product.updated",
|
|
212
|
+
"product.deleted",
|
|
213
|
+
"category.created",
|
|
214
|
+
"category.updated",
|
|
215
|
+
"category.deleted",
|
|
216
|
+
"discount.created",
|
|
217
|
+
"discount.updated",
|
|
218
|
+
"discount.deleted",
|
|
219
|
+
"customer.created",
|
|
220
|
+
"customer.updated",
|
|
221
|
+
"order.created",
|
|
222
|
+
"order.updated",
|
|
223
|
+
"subscription.created",
|
|
224
|
+
"subscription.updated"
|
|
225
|
+
];
|
|
226
|
+
//#endregion
|
|
157
227
|
//#region src/index.ts
|
|
158
228
|
var CaldikClient = class {
|
|
159
229
|
categories;
|
|
@@ -163,6 +233,7 @@ var CaldikClient = class {
|
|
|
163
233
|
checkout;
|
|
164
234
|
customer;
|
|
165
235
|
subscriptions;
|
|
236
|
+
webhooks;
|
|
166
237
|
constructor(options = {}) {
|
|
167
238
|
const client = new CaldikHttpClient({
|
|
168
239
|
apiKey: options.apiKey,
|
|
@@ -176,7 +247,8 @@ var CaldikClient = class {
|
|
|
176
247
|
this.checkout = new CheckoutApi(client);
|
|
177
248
|
this.customer = new CustomerApi(client);
|
|
178
249
|
this.subscriptions = new SubscriptionsApi(client);
|
|
250
|
+
this.webhooks = new WebhooksApi(client);
|
|
179
251
|
}
|
|
180
252
|
};
|
|
181
253
|
//#endregion
|
|
182
|
-
export { CaldikClient };
|
|
254
|
+
export { CaldikClient, checkoutPaymentProviderIds, paymentProviderIds, storeWebhookEventNames, subscriptionPaymentProviderIds };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caldik/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.mts",
|
|
@@ -18,9 +18,11 @@
|
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "tsdown",
|
|
21
|
+
"sync:api-contracts": "bun scripts/sync-api-contracts.ts",
|
|
21
22
|
"test": "bun test"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
25
|
+
"@types/bun": "latest",
|
|
24
26
|
"tsdown": "^0.22.3",
|
|
25
27
|
"typescript": "^6.0.3"
|
|
26
28
|
}
|