@caldik/client 0.0.9 → 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/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.requestLogin("customer@example.com")
61
+ await caldik.customer.verifyLogin(code)
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;
@@ -229,10 +231,43 @@ interface CustomerLoginVerifyResponse {
229
231
  id: string;
230
232
  shortId: string;
231
233
  displayId: string;
232
- email: string;
234
+ email: string | null;
233
235
  status: string;
234
236
  };
235
237
  }
238
+ interface CustomerPasswordInput {
239
+ username: string;
240
+ password: string;
241
+ }
242
+ interface CustomerLoginSettings {
243
+ passwordEnabled: boolean;
244
+ }
245
+ interface CustomerLoginSettingsResponse {
246
+ success: boolean;
247
+ settings: CustomerLoginSettings;
248
+ }
249
+ interface CheckoutSettings {
250
+ requireEmail: boolean;
251
+ requireTermsAcceptance: boolean;
252
+ }
253
+ interface CheckoutSettingsResponse {
254
+ success: boolean;
255
+ settings: CheckoutSettings;
256
+ }
257
+ interface CheckoutPaymentMethod {
258
+ id: CheckoutPaymentProviderId;
259
+ label: string;
260
+ description: string;
261
+ checkout: {
262
+ kind: "internal" | "redirect";
263
+ requiresCustomerEmail: boolean;
264
+ };
265
+ requiresCustomerLogin: boolean;
266
+ }
267
+ interface CheckoutPaymentMethodsResponse {
268
+ success: boolean;
269
+ paymentMethods: CheckoutPaymentMethod[];
270
+ }
236
271
  //#endregion
237
272
  //#region src/internal/types.d.ts
238
273
  interface RequestOptions {
@@ -272,7 +307,7 @@ declare class ProductsApi {
272
307
  private client;
273
308
  constructor(client: CaldikHttpClient);
274
309
  list(): Promise<ProductsResponse>;
275
- get(productId: string): Promise<ProductResponse>;
310
+ get(productIdOrSlug: string): Promise<ProductResponse>;
276
311
  }
277
312
  //#endregion
278
313
  //#region src/reviews.d.ts
@@ -292,6 +327,12 @@ declare class StoreApi {
292
327
  //#region src/checkout.d.ts
293
328
  declare class CheckoutApi {
294
329
  private client;
330
+ readonly paymentmethods: {
331
+ list: () => Promise<CheckoutPaymentMethodsResponse>;
332
+ };
333
+ readonly settings: {
334
+ get: () => Promise<CheckoutSettingsResponse>;
335
+ };
295
336
  constructor(client: CaldikHttpClient);
296
337
  create(input: CreateOrderInput): Promise<OrderResponse>;
297
338
  payWithBalance(orderId: string): Promise<OrderResponse>;
@@ -300,7 +341,13 @@ declare class CheckoutApi {
300
341
  //#region src/customer.d.ts
301
342
  declare class CustomerApi {
302
343
  private client;
344
+ readonly settings: {
345
+ get: () => Promise<CustomerLoginSettingsResponse>;
346
+ };
303
347
  constructor(client: CaldikHttpClient);
348
+ login(input: CustomerPasswordInput): Promise<CustomerLoginVerifyResponse>;
349
+ /** Set or reset credentials after signing in with an email code. Requires a customer session. */
350
+ setPassword(input: CustomerPasswordInput): Promise<CustomerLoginVerifyResponse>;
304
351
  requestLogin(email: string): Promise<CustomerLoginResponse>;
305
352
  verifyLogin(code: string): Promise<CustomerLoginVerifyResponse>;
306
353
  }
@@ -395,4 +442,4 @@ declare class CaldikClient {
395
442
  constructor(options?: CaldikClientOptions);
396
443
  }
397
444
  //#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 };
445
+ 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(productId) {
131
- return this.client.get(`/products/${productId}`, void 0, { access: "public" });
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,8 +175,17 @@ var CheckoutApi = class {
171
175
  //#region src/customer.ts
172
176
  var CustomerApi = class {
173
177
  client;
178
+ settings;
174
179
  constructor(client) {
175
180
  this.client = client;
181
+ this.settings = { get: () => this.client.get("/customers/settings", void 0, { access: "public" }) };
182
+ }
183
+ login(input) {
184
+ return this.client.post("/customers/login/password", input, { access: "public" });
185
+ }
186
+ /** Set or reset credentials after signing in with an email code. Requires a customer session. */
187
+ setPassword(input) {
188
+ return this.client.post("/customers/password", input, { access: "public" });
176
189
  }
177
190
  requestLogin(email) {
178
191
  return this.client.post("/customers/login", { email }, { access: "public" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caldik/client",
3
- "version": "0.0.9",
3
+ "version": "0.1.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.mts",