@epcc-sdk/sdks-shopper 0.0.37 → 0.0.38

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.
Files changed (2) hide show
  1. package/README.md +79 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -3,6 +3,85 @@
3
3
  Below you'll find instructions on how to install, set up, and use the client, along with a list of available operations.
4
4
 
5
5
 
6
+ ## Authentication (Browser)
7
+
8
+ The SDK includes built-in authentication support for browser environments using Elastic Path's implicit authentication flow. It handles token management, automatic refresh, and storage.
9
+
10
+ ### Quick Start
11
+
12
+ > **Note**: This authentication mechanism is designed for browser environments where state persistence (localStorage, cookies) is available. The built-in storage adapters and cross-tab synchronization features require browser APIs.
13
+
14
+ ```typescript
15
+ import { configureClient } from "@epcc-sdk/sdks-shopper/auth/configure-client";
16
+
17
+ // Configure the singleton client with authentication
18
+ configureClient(
19
+ {
20
+ baseUrl: "https://useast.api.elasticpath.com"
21
+ },
22
+ {
23
+ clientId: "your-client-id",
24
+ storage: "localStorage" // or "cookie" or custom adapter
25
+ }
26
+ );
27
+ ```
28
+
29
+ ### Storage Options
30
+
31
+ - **localStorage** (default): Tokens stored in browser localStorage with cross-tab synchronization
32
+ - **cookie**: Tokens stored in JavaScript-readable cookies
33
+ - **Custom adapter**: Implement your own storage mechanism
34
+
35
+ ```typescript
36
+ // Cookie storage with options
37
+ configureClient(config, {
38
+ clientId: "your-client-id",
39
+ storage: "cookie",
40
+ cookie: {
41
+ sameSite: "Strict",
42
+ secure: true,
43
+ maxAge: 3600 // 1 hour
44
+ }
45
+ });
46
+ ```
47
+
48
+ ### Creating Standalone Clients
49
+
50
+ For multiple stores or isolated instances:
51
+
52
+ ```typescript
53
+ import { createShopperClient } from "@epcc-sdk/sdks-shopper/auth/configure-client";
54
+
55
+ const { client, auth } = createShopperClient(
56
+ { baseUrl: "https://useast.api.elasticpath.com" },
57
+ { clientId: "your-client-id" }
58
+ );
59
+ ```
60
+
61
+ ### Manual Auth Control
62
+
63
+ Access the underlying auth instance for manual control:
64
+
65
+ ```typescript
66
+ const { client, auth } = configureClient(config, authOptions);
67
+
68
+ // Check authentication status
69
+ if (auth.isAuthenticated()) {
70
+ console.log("Authenticated!");
71
+ }
72
+
73
+ // Manually clear tokens
74
+ auth.clearToken();
75
+ ```
76
+
77
+ ### Features
78
+
79
+ - **Automatic token refresh**: Refreshes expired tokens automatically
80
+ - **Request retry**: Retries failed requests once after refreshing token
81
+ - **Cross-tab sync**: localStorage adapter syncs auth state across browser tabs
82
+ - **Type-safe**: Full TypeScript support with proper types
83
+ - **Flexible storage**: Built-in adapters or bring your own
84
+
6
85
  ## React Query Support
7
86
 
8
87
  This SDK provides optional React Query hooks for React applications. To use them, you need to:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epcc-sdk/sdks-shopper",
3
- "version": "0.0.37",
3
+ "version": "0.0.38",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",