@caldik/client 0.1.0 → 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 CHANGED
@@ -57,8 +57,8 @@ the application instead of the SDK.
57
57
 
58
58
  Magic Code
59
59
  ```ts
60
- await caldik.customer.requestLogin("customer@example.com")
61
- await caldik.customer.verifyLogin(code)
60
+ await caldik.customer.login("customer@example.com")
61
+ await caldik.customer.login.verify(code) // Six-digit code sent by email.
62
62
  ```
63
63
 
64
64
  Username / Email Password ( if password login is enabled )
@@ -78,4 +78,4 @@ await caldik.customer.setPassword({ username: "customer", password })
78
78
  const { settings: loginSettings } = await caldik.customer.settings.get()
79
79
  const { settings: checkoutSettings } = await caldik.checkout.settings.get()
80
80
  const { paymentMethods } = await caldik.checkout.paymentmethods.list()
81
- ```
81
+ ```
package/dist/index.d.mts CHANGED
@@ -224,6 +224,7 @@ interface StoreWebhookEvent<TObject extends Record<string, unknown> = Record<str
224
224
  interface CustomerLoginResponse {
225
225
  success: boolean;
226
226
  message: string;
227
+ loginId: string;
227
228
  }
228
229
  interface CustomerLoginVerifyResponse {
229
230
  success: boolean;
@@ -344,12 +345,15 @@ declare class CustomerApi {
344
345
  readonly settings: {
345
346
  get: () => Promise<CustomerLoginSettingsResponse>;
346
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
+ };
347
354
  constructor(client: CaldikHttpClient);
348
- login(input: CustomerPasswordInput): Promise<CustomerLoginVerifyResponse>;
349
355
  /** Set or reset credentials after signing in with an email code. Requires a customer session. */
350
356
  setPassword(input: CustomerPasswordInput): Promise<CustomerLoginVerifyResponse>;
351
- requestLogin(email: string): Promise<CustomerLoginResponse>;
352
- verifyLogin(code: string): Promise<CustomerLoginVerifyResponse>;
353
357
  }
354
358
  //#endregion
355
359
  //#region src/subscriptions.d.ts
package/dist/index.mjs CHANGED
@@ -176,23 +176,34 @@ var CheckoutApi = class {
176
176
  var CustomerApi = class {
177
177
  client;
178
178
  settings;
179
+ login;
179
180
  constructor(client) {
180
181
  this.client = client;
181
182
  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" });
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
+ } });
185
202
  }
186
203
  /** Set or reset credentials after signing in with an email code. Requires a customer session. */
187
204
  setPassword(input) {
188
205
  return this.client.post("/customers/password", input, { access: "public" });
189
206
  }
190
- requestLogin(email) {
191
- return this.client.post("/customers/login", { email }, { access: "public" });
192
- }
193
- verifyLogin(code) {
194
- return this.client.post("/customers/login/verify", { code }, { access: "public" });
195
- }
196
207
  };
197
208
  //#endregion
198
209
  //#region src/subscriptions.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caldik/client",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.mts",