@caldik/client 0.0.9 → 0.1.1
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 +29 -0
- package/dist/index.d.mts +56 -5
- package/dist/index.mjs +32 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,8 @@ await caldik.cart.applyDiscount("SAVE10")
|
|
|
42
42
|
|
|
43
43
|
const result = await caldik.cart.checkout({
|
|
44
44
|
paymentMethod: "stripe",
|
|
45
|
+
items: [{ productId, productVariantId, quantity: 1 }],
|
|
46
|
+
termsAccepted: acceptedTermsCheckbox,
|
|
45
47
|
successUrl: "https://shop.example/success",
|
|
46
48
|
cancelUrl: "https://shop.example/cart",
|
|
47
49
|
})
|
|
@@ -50,3 +52,30 @@ const result = await caldik.cart.checkout({
|
|
|
50
52
|
Use `caldik.discounts.check({ code, items })` when a cart should be managed by
|
|
51
53
|
the application instead of the SDK.
|
|
52
54
|
|
|
55
|
+
|
|
56
|
+
## Customer Logins
|
|
57
|
+
|
|
58
|
+
Magic Code
|
|
59
|
+
```ts
|
|
60
|
+
await caldik.customer.login("customer@example.com")
|
|
61
|
+
await caldik.customer.login.verify(code) // Six-digit code sent by email.
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Username / Email Password ( if password login is enabled )
|
|
65
|
+
```ts
|
|
66
|
+
await caldik.customer.login({ username: "customer", password })
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
if you are logged in using magic code you can just do
|
|
70
|
+
- this to enroll the customers account into username / email password login ( password login needs to be enabled in the dashboard )
|
|
71
|
+
```ts
|
|
72
|
+
await caldik.customer.setPassword({ username: "customer", password })
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Payment methods and Settings
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const { settings: loginSettings } = await caldik.customer.settings.get()
|
|
79
|
+
const { settings: checkoutSettings } = await caldik.checkout.settings.get()
|
|
80
|
+
const { paymentMethods } = await caldik.checkout.paymentmethods.list()
|
|
81
|
+
```
|
package/dist/index.d.mts
CHANGED
|
@@ -99,6 +99,7 @@ interface Product {
|
|
|
99
99
|
interface ProductVariant {
|
|
100
100
|
id: string;
|
|
101
101
|
name: string;
|
|
102
|
+
position: number;
|
|
102
103
|
price: string;
|
|
103
104
|
compareAtPrice: string | null;
|
|
104
105
|
}
|
|
@@ -146,6 +147,7 @@ type CommerceItem = ManualCommerceItem | ProductCommerceItem;
|
|
|
146
147
|
interface CreateOrderInput {
|
|
147
148
|
customerId?: string;
|
|
148
149
|
email?: string;
|
|
150
|
+
termsAccepted?: boolean;
|
|
149
151
|
paymentMethod: CheckoutPaymentProviderId;
|
|
150
152
|
items: CommerceItem[];
|
|
151
153
|
discountCode?: string;
|
|
@@ -222,6 +224,7 @@ interface StoreWebhookEvent<TObject extends Record<string, unknown> = Record<str
|
|
|
222
224
|
interface CustomerLoginResponse {
|
|
223
225
|
success: boolean;
|
|
224
226
|
message: string;
|
|
227
|
+
loginId: string;
|
|
225
228
|
}
|
|
226
229
|
interface CustomerLoginVerifyResponse {
|
|
227
230
|
success: boolean;
|
|
@@ -229,10 +232,43 @@ interface CustomerLoginVerifyResponse {
|
|
|
229
232
|
id: string;
|
|
230
233
|
shortId: string;
|
|
231
234
|
displayId: string;
|
|
232
|
-
email: string;
|
|
235
|
+
email: string | null;
|
|
233
236
|
status: string;
|
|
234
237
|
};
|
|
235
238
|
}
|
|
239
|
+
interface CustomerPasswordInput {
|
|
240
|
+
username: string;
|
|
241
|
+
password: string;
|
|
242
|
+
}
|
|
243
|
+
interface CustomerLoginSettings {
|
|
244
|
+
passwordEnabled: boolean;
|
|
245
|
+
}
|
|
246
|
+
interface CustomerLoginSettingsResponse {
|
|
247
|
+
success: boolean;
|
|
248
|
+
settings: CustomerLoginSettings;
|
|
249
|
+
}
|
|
250
|
+
interface CheckoutSettings {
|
|
251
|
+
requireEmail: boolean;
|
|
252
|
+
requireTermsAcceptance: boolean;
|
|
253
|
+
}
|
|
254
|
+
interface CheckoutSettingsResponse {
|
|
255
|
+
success: boolean;
|
|
256
|
+
settings: CheckoutSettings;
|
|
257
|
+
}
|
|
258
|
+
interface CheckoutPaymentMethod {
|
|
259
|
+
id: CheckoutPaymentProviderId;
|
|
260
|
+
label: string;
|
|
261
|
+
description: string;
|
|
262
|
+
checkout: {
|
|
263
|
+
kind: "internal" | "redirect";
|
|
264
|
+
requiresCustomerEmail: boolean;
|
|
265
|
+
};
|
|
266
|
+
requiresCustomerLogin: boolean;
|
|
267
|
+
}
|
|
268
|
+
interface CheckoutPaymentMethodsResponse {
|
|
269
|
+
success: boolean;
|
|
270
|
+
paymentMethods: CheckoutPaymentMethod[];
|
|
271
|
+
}
|
|
236
272
|
//#endregion
|
|
237
273
|
//#region src/internal/types.d.ts
|
|
238
274
|
interface RequestOptions {
|
|
@@ -272,7 +308,7 @@ declare class ProductsApi {
|
|
|
272
308
|
private client;
|
|
273
309
|
constructor(client: CaldikHttpClient);
|
|
274
310
|
list(): Promise<ProductsResponse>;
|
|
275
|
-
get(
|
|
311
|
+
get(productIdOrSlug: string): Promise<ProductResponse>;
|
|
276
312
|
}
|
|
277
313
|
//#endregion
|
|
278
314
|
//#region src/reviews.d.ts
|
|
@@ -292,6 +328,12 @@ declare class StoreApi {
|
|
|
292
328
|
//#region src/checkout.d.ts
|
|
293
329
|
declare class CheckoutApi {
|
|
294
330
|
private client;
|
|
331
|
+
readonly paymentmethods: {
|
|
332
|
+
list: () => Promise<CheckoutPaymentMethodsResponse>;
|
|
333
|
+
};
|
|
334
|
+
readonly settings: {
|
|
335
|
+
get: () => Promise<CheckoutSettingsResponse>;
|
|
336
|
+
};
|
|
295
337
|
constructor(client: CaldikHttpClient);
|
|
296
338
|
create(input: CreateOrderInput): Promise<OrderResponse>;
|
|
297
339
|
payWithBalance(orderId: string): Promise<OrderResponse>;
|
|
@@ -300,9 +342,18 @@ declare class CheckoutApi {
|
|
|
300
342
|
//#region src/customer.d.ts
|
|
301
343
|
declare class CustomerApi {
|
|
302
344
|
private client;
|
|
345
|
+
readonly settings: {
|
|
346
|
+
get: () => Promise<CustomerLoginSettingsResponse>;
|
|
347
|
+
};
|
|
348
|
+
readonly login: {
|
|
349
|
+
(email: string): Promise<CustomerLoginResponse>;
|
|
350
|
+
(input: CustomerPasswordInput): Promise<CustomerLoginVerifyResponse>;
|
|
351
|
+
} & {
|
|
352
|
+
/** Pass loginId to resume a code request after reloading the page. */verify: (code: string, loginId?: string | undefined) => Promise<CustomerLoginVerifyResponse>;
|
|
353
|
+
};
|
|
303
354
|
constructor(client: CaldikHttpClient);
|
|
304
|
-
|
|
305
|
-
|
|
355
|
+
/** Set or reset credentials after signing in with an email code. Requires a customer session. */
|
|
356
|
+
setPassword(input: CustomerPasswordInput): Promise<CustomerLoginVerifyResponse>;
|
|
306
357
|
}
|
|
307
358
|
//#endregion
|
|
308
359
|
//#region src/subscriptions.d.ts
|
|
@@ -395,4 +446,4 @@ declare class CaldikClient {
|
|
|
395
446
|
constructor(options?: CaldikClientOptions);
|
|
396
447
|
}
|
|
397
448
|
//#endregion
|
|
398
|
-
export { AppliedDiscount, CaldikClient, CaldikClientOptions, CartApi, CartCheckoutInput, CartDiscount, CartItem, CartSnapshot, CategoriesResponse, Category, CategoryDetails, CategoryMetadata, CategoryProduct, CategoryResponse, CheckDiscountInput, CheckoutPayment, CheckoutPaymentProviderId, CommerceItem, CreateOrderInput, CreateSubscriptionInput, CustomerLoginResponse, CustomerLoginVerifyResponse, DiscountQuoteResponse, DiscountsApi, ManualCommerceItem, OrderResponse, PaymentProviderId, Product, ProductCommerceItem, ProductCustomField, ProductCustomFieldInputType, ProductCustomFieldOption, ProductMetadata, ProductResponse, ProductTag, ProductVariant, ProductsResponse, Review, ReviewsResponse, Store, StoreResponse, StoreWebhookEvent, StoreWebhookEventName, StorefrontMetadata, StorefrontOrder, SubscriptionPaymentProviderId, SubscriptionResponse, checkoutPaymentProviderIds, paymentProviderIds, storeWebhookEventNames, subscriptionPaymentProviderIds };
|
|
449
|
+
export { AppliedDiscount, CaldikClient, CaldikClientOptions, CartApi, CartCheckoutInput, CartDiscount, CartItem, CartSnapshot, CategoriesResponse, Category, CategoryDetails, CategoryMetadata, CategoryProduct, CategoryResponse, CheckDiscountInput, CheckoutPayment, CheckoutPaymentMethod, CheckoutPaymentMethodsResponse, CheckoutPaymentProviderId, CheckoutSettings, CheckoutSettingsResponse, CommerceItem, CreateOrderInput, CreateSubscriptionInput, CustomerLoginResponse, CustomerLoginSettings, CustomerLoginSettingsResponse, CustomerLoginVerifyResponse, CustomerPasswordInput, DiscountQuoteResponse, DiscountsApi, ManualCommerceItem, OrderResponse, PaymentProviderId, Product, ProductCommerceItem, ProductCustomField, ProductCustomFieldInputType, ProductCustomFieldOption, ProductMetadata, ProductResponse, ProductTag, ProductVariant, ProductsResponse, Review, ReviewsResponse, Store, StoreResponse, StoreWebhookEvent, StoreWebhookEventName, StorefrontMetadata, StorefrontOrder, SubscriptionPaymentProviderId, SubscriptionResponse, checkoutPaymentProviderIds, paymentProviderIds, storeWebhookEventNames, subscriptionPaymentProviderIds };
|
package/dist/index.mjs
CHANGED
|
@@ -127,8 +127,8 @@ var ProductsApi = class {
|
|
|
127
127
|
list() {
|
|
128
128
|
return this.client.get("/products", void 0, { access: "public" });
|
|
129
129
|
}
|
|
130
|
-
get(
|
|
131
|
-
return this.client.get(`/products/${
|
|
130
|
+
get(productIdOrSlug) {
|
|
131
|
+
return this.client.get(`/products/${encodeURIComponent(productIdOrSlug)}`, void 0, { access: "public" });
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
134
|
//#endregion
|
|
@@ -157,8 +157,12 @@ var StoreApi = class {
|
|
|
157
157
|
//#region src/checkout.ts
|
|
158
158
|
var CheckoutApi = class {
|
|
159
159
|
client;
|
|
160
|
+
paymentmethods;
|
|
161
|
+
settings;
|
|
160
162
|
constructor(client) {
|
|
161
163
|
this.client = client;
|
|
164
|
+
this.paymentmethods = { list: () => this.client.get("/checkouts/payment-methods", void 0, { access: "public" }) };
|
|
165
|
+
this.settings = { get: () => this.client.get("/checkouts/settings", void 0, { access: "public" }) };
|
|
162
166
|
}
|
|
163
167
|
create(input) {
|
|
164
168
|
return this.client.post("/checkouts", input, { access: "public" });
|
|
@@ -171,14 +175,34 @@ var CheckoutApi = class {
|
|
|
171
175
|
//#region src/customer.ts
|
|
172
176
|
var CustomerApi = class {
|
|
173
177
|
client;
|
|
178
|
+
settings;
|
|
179
|
+
login;
|
|
174
180
|
constructor(client) {
|
|
175
181
|
this.client = client;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
+
this.settings = { get: () => this.client.get("/customers/settings", void 0, { access: "public" }) };
|
|
183
|
+
let pendingLoginId;
|
|
184
|
+
async function login(input) {
|
|
185
|
+
if (typeof input !== "string") return client.post("/customers/login/password", input, { access: "public" });
|
|
186
|
+
const response = await client.post("/customers/login", { email: input }, { access: "public" });
|
|
187
|
+
pendingLoginId = response.loginId;
|
|
188
|
+
return response;
|
|
189
|
+
}
|
|
190
|
+
this.login = Object.assign(login, {
|
|
191
|
+
/** Pass loginId to resume a code request after reloading the page. */
|
|
192
|
+
verify: async (code, loginId = pendingLoginId) => {
|
|
193
|
+
if (!/^\d{6}$/.test(code)) throw new Error("A six-digit login code is required");
|
|
194
|
+
if (!loginId) throw new Error("Request a login code first or provide its loginId");
|
|
195
|
+
const response = await client.post("/customers/login/verify", {
|
|
196
|
+
code,
|
|
197
|
+
loginId
|
|
198
|
+
}, { access: "public" });
|
|
199
|
+
if (pendingLoginId === loginId) pendingLoginId = void 0;
|
|
200
|
+
return response;
|
|
201
|
+
} });
|
|
202
|
+
}
|
|
203
|
+
/** Set or reset credentials after signing in with an email code. Requires a customer session. */
|
|
204
|
+
setPassword(input) {
|
|
205
|
+
return this.client.post("/customers/password", input, { access: "public" });
|
|
182
206
|
}
|
|
183
207
|
};
|
|
184
208
|
//#endregion
|