@caldik/client 0.1.9 → 0.1.10
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 +10 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +22 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -384,6 +384,16 @@ await caldik.customer.session()
|
|
|
384
384
|
|
|
385
385
|
### Current Customer
|
|
386
386
|
|
|
387
|
+
**Sign out the current customer**
|
|
388
|
+
|
|
389
|
+
```ts
|
|
390
|
+
await caldik.customer.logout()
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
This revokes the current session, expires its cookies and clears the local cart
|
|
394
|
+
cache. The customer's saved cart remains available after their next sign-in.
|
|
395
|
+
Logout resolves to `undefined` and is safe to repeat.
|
|
396
|
+
|
|
387
397
|
**Get the signed-in customer**
|
|
388
398
|
|
|
389
399
|
```ts
|
package/dist/index.d.mts
CHANGED
|
@@ -478,11 +478,14 @@ declare class CaldikHttpClient {
|
|
|
478
478
|
private readonly onSetCookie?;
|
|
479
479
|
private readonly storefrontOrigin?;
|
|
480
480
|
private readonly authenticationListeners;
|
|
481
|
+
private readonly logoutListeners;
|
|
481
482
|
constructor(options?: HttpClientOptions);
|
|
482
483
|
storeContextId(): string | null;
|
|
483
484
|
hasCartSession(): boolean;
|
|
484
485
|
onCustomerAuthentication(listener: () => Promise<unknown>): void;
|
|
485
486
|
customerAuthenticated(): Promise<void>;
|
|
487
|
+
onCustomerLogout(listener: () => Promise<unknown>): void;
|
|
488
|
+
customerLoggedOut(): Promise<void>;
|
|
486
489
|
private captureCookies;
|
|
487
490
|
private baseUrl;
|
|
488
491
|
private response;
|
|
@@ -586,6 +589,7 @@ declare class CustomerApi {
|
|
|
586
589
|
currency?: string;
|
|
587
590
|
}) => CaldikRequest<CustomerBalanceResponse>;
|
|
588
591
|
};
|
|
592
|
+
readonly logout: () => Promise<void>;
|
|
589
593
|
constructor(client: CaldikHttpClient);
|
|
590
594
|
/** Resolves without a body on HTTP 200; rejects with status 401 when signed out. */
|
|
591
595
|
session(): CaldikRequest<void>;
|
package/dist/index.mjs
CHANGED
|
@@ -105,6 +105,7 @@ var CaldikHttpClient = class {
|
|
|
105
105
|
onSetCookie;
|
|
106
106
|
storefrontOrigin;
|
|
107
107
|
authenticationListeners = /* @__PURE__ */ new Set();
|
|
108
|
+
logoutListeners = /* @__PURE__ */ new Set();
|
|
108
109
|
constructor(options = {}) {
|
|
109
110
|
this.apiKey = options.apiKey?.trim() || void 0;
|
|
110
111
|
this.apiUrl = options.apiUrl || defaultApiUrl(isBrowserRuntime());
|
|
@@ -134,6 +135,12 @@ var CaldikHttpClient = class {
|
|
|
134
135
|
async customerAuthenticated() {
|
|
135
136
|
await Promise.allSettled([...this.authenticationListeners].map((listener) => listener()));
|
|
136
137
|
}
|
|
138
|
+
onCustomerLogout(listener) {
|
|
139
|
+
this.logoutListeners.add(listener);
|
|
140
|
+
}
|
|
141
|
+
async customerLoggedOut() {
|
|
142
|
+
await Promise.all([...this.logoutListeners].map((listener) => listener()));
|
|
143
|
+
}
|
|
137
144
|
async captureCookies(response) {
|
|
138
145
|
for (const cookie of response.headers.getSetCookie()) {
|
|
139
146
|
const [pair = "", ...attributes] = cookie.split(";");
|
|
@@ -302,8 +309,19 @@ var CustomerApi = class {
|
|
|
302
309
|
password;
|
|
303
310
|
orders;
|
|
304
311
|
balance;
|
|
312
|
+
logout;
|
|
305
313
|
constructor(client) {
|
|
306
314
|
this.client = client;
|
|
315
|
+
this.logout = async () => {
|
|
316
|
+
await client.post("/customers/logout", void 0, {
|
|
317
|
+
access: "public",
|
|
318
|
+
empty: true
|
|
319
|
+
});
|
|
320
|
+
pendingChallengeId = void 0;
|
|
321
|
+
pendingRegistrationId = void 0;
|
|
322
|
+
pendingResetId = void 0;
|
|
323
|
+
await client.customerLoggedOut();
|
|
324
|
+
};
|
|
307
325
|
this.orders = {
|
|
308
326
|
list: (options = {}) => client.get("/customers/orders", { ...options }, { access: "public" }),
|
|
309
327
|
get: (id) => client.get(`/customers/orders/${encodeURIComponent(id)}`, void 0, { access: "public" })
|
|
@@ -474,6 +492,10 @@ var CartApi = class {
|
|
|
474
492
|
initialized = false;
|
|
475
493
|
constructor(client) {
|
|
476
494
|
this.client = client;
|
|
495
|
+
client.onCustomerLogout(() => this.enqueue(async () => {
|
|
496
|
+
this.reset();
|
|
497
|
+
this.initialized = false;
|
|
498
|
+
}));
|
|
477
499
|
client.onCustomerAuthentication(() => {
|
|
478
500
|
this.readCache();
|
|
479
501
|
return this.initialized || this.cache.reference || this.cache.snapshot.items.length || client.hasCartSession() ? this.enqueue(async () => {
|