@commercengine/storefront-sdk-nextjs 0.1.0-alpha.0 → 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.
@@ -0,0 +1,136 @@
1
+ "use client";
2
+
3
+
4
+ const require_sdk_manager = require('./sdk-manager-NWADjRFW.cjs');
5
+ const react = require_sdk_manager.__toESM(require("react"));
6
+ const __commercengine_storefront_sdk = require_sdk_manager.__toESM(require("@commercengine/storefront-sdk"));
7
+
8
+ //#region src/init-client.ts
9
+ /**
10
+ * Client-side initialization component
11
+ * Use this in your root layout to initialize the SDK once
12
+ *
13
+ * Configuration is handled via environment variables:
14
+ * - NEXT_PUBLIC_STORE_ID
15
+ * - NEXT_PUBLIC_API_KEY
16
+ * - NEXT_PUBLIC_ENVIRONMENT (optional, defaults to staging)
17
+ *
18
+ * The core SDK middleware automatically handles everything:
19
+ * - Creates anonymous tokens automatically on first API request (if no tokens exist)
20
+ * - Token state assessment and cleanup on first request per page load
21
+ * - Expired token refresh with automatic anonymous fallback
22
+ * - Graceful handling of partial token states
23
+ *
24
+ * No manual token creation needed - just make API calls and everything works!
25
+ */
26
+ /**
27
+ * Bootstrap tokens by checking if access token exists and creating anonymous token if needed
28
+ */
29
+ async function bootstrapTokens() {
30
+ const sdk = require_sdk_manager.getStorefrontSDK();
31
+ const accessToken = await sdk.getAccessToken();
32
+ if (!accessToken) await sdk.auth.getAnonymousToken();
33
+ }
34
+ function StorefrontSDKInitializer({ runtimeConfig } = {}) {
35
+ (0, react.useEffect)(() => {
36
+ require_sdk_manager.initializeStorefrontSDK();
37
+ bootstrapTokens().catch(console.error);
38
+ }, [runtimeConfig]);
39
+ return null;
40
+ }
41
+
42
+ //#endregion
43
+ Object.defineProperty(exports, 'AuthClient', {
44
+ enumerable: true,
45
+ get: function () {
46
+ return __commercengine_storefront_sdk.AuthClient;
47
+ }
48
+ });
49
+ Object.defineProperty(exports, 'BrowserTokenStorage', {
50
+ enumerable: true,
51
+ get: function () {
52
+ return __commercengine_storefront_sdk.BrowserTokenStorage;
53
+ }
54
+ });
55
+ Object.defineProperty(exports, 'CartClient', {
56
+ enumerable: true,
57
+ get: function () {
58
+ return __commercengine_storefront_sdk.CartClient;
59
+ }
60
+ });
61
+ Object.defineProperty(exports, 'CatalogClient', {
62
+ enumerable: true,
63
+ get: function () {
64
+ return __commercengine_storefront_sdk.CatalogClient;
65
+ }
66
+ });
67
+ exports.ClientTokenStorage = require_sdk_manager.ClientTokenStorage;
68
+ Object.defineProperty(exports, 'CookieTokenStorage', {
69
+ enumerable: true,
70
+ get: function () {
71
+ return __commercengine_storefront_sdk.CookieTokenStorage;
72
+ }
73
+ });
74
+ Object.defineProperty(exports, 'CustomerClient', {
75
+ enumerable: true,
76
+ get: function () {
77
+ return __commercengine_storefront_sdk.CustomerClient;
78
+ }
79
+ });
80
+ Object.defineProperty(exports, 'Environment', {
81
+ enumerable: true,
82
+ get: function () {
83
+ return __commercengine_storefront_sdk.Environment;
84
+ }
85
+ });
86
+ Object.defineProperty(exports, 'HelpersClient', {
87
+ enumerable: true,
88
+ get: function () {
89
+ return __commercengine_storefront_sdk.HelpersClient;
90
+ }
91
+ });
92
+ Object.defineProperty(exports, 'MemoryTokenStorage', {
93
+ enumerable: true,
94
+ get: function () {
95
+ return __commercengine_storefront_sdk.MemoryTokenStorage;
96
+ }
97
+ });
98
+ Object.defineProperty(exports, 'OrderClient', {
99
+ enumerable: true,
100
+ get: function () {
101
+ return __commercengine_storefront_sdk.OrderClient;
102
+ }
103
+ });
104
+ Object.defineProperty(exports, 'ResponseUtils', {
105
+ enumerable: true,
106
+ get: function () {
107
+ return __commercengine_storefront_sdk.ResponseUtils;
108
+ }
109
+ });
110
+ Object.defineProperty(exports, 'ShippingClient', {
111
+ enumerable: true,
112
+ get: function () {
113
+ return __commercengine_storefront_sdk.ShippingClient;
114
+ }
115
+ });
116
+ Object.defineProperty(exports, 'StoreConfigClient', {
117
+ enumerable: true,
118
+ get: function () {
119
+ return __commercengine_storefront_sdk.StoreConfigClient;
120
+ }
121
+ });
122
+ Object.defineProperty(exports, 'StorefrontAPIClient', {
123
+ enumerable: true,
124
+ get: function () {
125
+ return __commercengine_storefront_sdk.StorefrontAPIClient;
126
+ }
127
+ });
128
+ Object.defineProperty(exports, 'StorefrontSDK', {
129
+ enumerable: true,
130
+ get: function () {
131
+ return __commercengine_storefront_sdk.StorefrontSDK;
132
+ }
133
+ });
134
+ exports.StorefrontSDKInitializer = StorefrontSDKInitializer;
135
+ exports.getStorefrontSDK = require_sdk_manager.getStorefrontSDK;
136
+ exports.initializeStorefrontSDK = require_sdk_manager.initializeStorefrontSDK;
@@ -0,0 +1,17 @@
1
+ import { ClientTokenStorage, NextJSSDKConfig, NextJSTokenStorageOptions, StorefrontRuntimeConfig, getStorefrontSDK, initializeStorefrontSDK } from "./sdk-manager-D2ktqPrp.cjs";
2
+ import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDKOptions, TokenStorage } from "@commercengine/storefront-sdk";
3
+
4
+ //#region src/init-client.d.ts
5
+ interface StorefrontSDKInitializerProps {
6
+ /**
7
+ * Optional runtime configuration overrides for client-side API calls
8
+ * These settings will apply to all client-side storefront() calls
9
+ */
10
+ runtimeConfig?: StorefrontRuntimeConfig;
11
+ }
12
+ declare function StorefrontSDKInitializer({
13
+ runtimeConfig
14
+ }?: StorefrontSDKInitializerProps): null;
15
+ //#endregion
16
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, ClientTokenStorage, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, type NextJSSDKConfig, type NextJSTokenStorageOptions, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDKInitializer, type StorefrontSDKOptions, type TokenStorage, getStorefrontSDK, initializeStorefrontSDK };
17
+ //# sourceMappingURL=client.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.cts","names":[],"sources":["../src/init-client.ts"],"sourcesContent":[],"mappings":";;;;UAuCU,6BAAA;;;AAhCa;AAwCvB;EAAwC,aAAA,CAAA,EAHtB,uBAGsB;;AAAoB,iBAA5C,wBAAA,CAA4C;EAAA;AAAA,CAAA,CAAA,EAAA,6BAAA,CAAA,EAAA,IAAA"}
@@ -0,0 +1,17 @@
1
+ import { ClientTokenStorage, NextJSSDKConfig, NextJSTokenStorageOptions, StorefrontRuntimeConfig, getStorefrontSDK, initializeStorefrontSDK } from "./sdk-manager-B9xDQQuv.js";
2
+ import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDKOptions, TokenStorage } from "@commercengine/storefront-sdk";
3
+
4
+ //#region src/init-client.d.ts
5
+ interface StorefrontSDKInitializerProps {
6
+ /**
7
+ * Optional runtime configuration overrides for client-side API calls
8
+ * These settings will apply to all client-side storefront() calls
9
+ */
10
+ runtimeConfig?: StorefrontRuntimeConfig;
11
+ }
12
+ declare function StorefrontSDKInitializer({
13
+ runtimeConfig
14
+ }?: StorefrontSDKInitializerProps): null;
15
+ //#endregion
16
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, ClientTokenStorage, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, type NextJSSDKConfig, type NextJSTokenStorageOptions, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDKInitializer, type StorefrontSDKOptions, type TokenStorage, getStorefrontSDK, initializeStorefrontSDK };
17
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../src/init-client.ts"],"sourcesContent":[],"mappings":";;;;UAuCU,6BAAA;;;AAhCa;AAwCvB;EAAwC,aAAA,CAAA,EAHtB,uBAGsB;;AAAoB,iBAA5C,wBAAA,CAA4C;EAAA;AAAA,CAAA,CAAA,EAAA,6BAAA,CAAA,EAAA,IAAA"}
package/dist/client.js ADDED
@@ -0,0 +1,44 @@
1
+ "use client";
2
+
3
+
4
+ import { ClientTokenStorage, getStorefrontSDK, initializeStorefrontSDK } from "./sdk-manager-CdgrfSVp.js";
5
+ import { useEffect } from "react";
6
+ import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK } from "@commercengine/storefront-sdk";
7
+
8
+ //#region src/init-client.ts
9
+ /**
10
+ * Client-side initialization component
11
+ * Use this in your root layout to initialize the SDK once
12
+ *
13
+ * Configuration is handled via environment variables:
14
+ * - NEXT_PUBLIC_STORE_ID
15
+ * - NEXT_PUBLIC_API_KEY
16
+ * - NEXT_PUBLIC_ENVIRONMENT (optional, defaults to staging)
17
+ *
18
+ * The core SDK middleware automatically handles everything:
19
+ * - Creates anonymous tokens automatically on first API request (if no tokens exist)
20
+ * - Token state assessment and cleanup on first request per page load
21
+ * - Expired token refresh with automatic anonymous fallback
22
+ * - Graceful handling of partial token states
23
+ *
24
+ * No manual token creation needed - just make API calls and everything works!
25
+ */
26
+ /**
27
+ * Bootstrap tokens by checking if access token exists and creating anonymous token if needed
28
+ */
29
+ async function bootstrapTokens() {
30
+ const sdk = getStorefrontSDK();
31
+ const accessToken = await sdk.getAccessToken();
32
+ if (!accessToken) await sdk.auth.getAnonymousToken();
33
+ }
34
+ function StorefrontSDKInitializer({ runtimeConfig } = {}) {
35
+ useEffect(() => {
36
+ initializeStorefrontSDK();
37
+ bootstrapTokens().catch(console.error);
38
+ }, [runtimeConfig]);
39
+ return null;
40
+ }
41
+
42
+ //#endregion
43
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, ClientTokenStorage, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDKInitializer, getStorefrontSDK, initializeStorefrontSDK };
44
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":[],"sources":["../src/init-client.ts"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { \n initializeStorefrontSDK, \n getStorefrontSDK,\n type StorefrontRuntimeConfig \n} from \"./sdk-manager\";\n\n/**\n * Client-side initialization component\n * Use this in your root layout to initialize the SDK once\n *\n * Configuration is handled via environment variables:\n * - NEXT_PUBLIC_STORE_ID\n * - NEXT_PUBLIC_API_KEY\n * - NEXT_PUBLIC_ENVIRONMENT (optional, defaults to staging)\n *\n * The core SDK middleware automatically handles everything:\n * - Creates anonymous tokens automatically on first API request (if no tokens exist)\n * - Token state assessment and cleanup on first request per page load\n * - Expired token refresh with automatic anonymous fallback\n * - Graceful handling of partial token states\n *\n * No manual token creation needed - just make API calls and everything works!\n */\n\n/**\n * Bootstrap tokens by checking if access token exists and creating anonymous token if needed\n */\nasync function bootstrapTokens() {\n const sdk = getStorefrontSDK();\n const accessToken = await sdk.getAccessToken();\n\n if (!accessToken) {\n await sdk.auth.getAnonymousToken();\n }\n}\n\ninterface StorefrontSDKInitializerProps {\n /**\n * Optional runtime configuration overrides for client-side API calls\n * These settings will apply to all client-side storefront() calls\n */\n runtimeConfig?: StorefrontRuntimeConfig;\n}\n\nexport function StorefrontSDKInitializer({ runtimeConfig }: StorefrontSDKInitializerProps = {}) {\n useEffect(() => {\n // Initialize SDK - configuration comes from environment variables\n // Middleware handles all token management automatically\n initializeStorefrontSDK();\n\n // Bootstrap tokens if they don't exist\n // Note: per-request config will be handled through storefront() function calls\n bootstrapTokens().catch(console.error);\n }, [runtimeConfig]);\n\n return null; // No UI needed\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,eAAe,kBAAkB;CAC/B,MAAM,MAAM;CACZ,MAAM,cAAc,MAAM,IAAI;AAE9B,KAAI,CAAC,YACH,OAAM,IAAI,KAAK;;AAYnB,SAAgB,yBAAyB,EAAE,kBAAiD,IAAI;AAC9F,iBAAgB;AAGd;AAIA,oBAAkB,MAAM,QAAQ;IAC/B,CAAC;AAEJ,QAAO"}