@commercengine/storefront-sdk-nextjs 0.1.0-alpha.0 → 1.0.0-alpha.2
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 +515 -139
- package/dist/client.cjs +405 -0
- package/dist/client.d.cts +121 -0
- package/dist/client.d.ts +121 -0
- package/dist/client.js +378 -0
- package/dist/index.cjs +229 -140
- package/dist/index.d.cts +27 -102
- package/dist/index.d.ts +27 -102
- package/dist/index.js +230 -132
- package/dist/middleware.cjs +66 -0
- package/dist/middleware.d.cts +38 -0
- package/dist/middleware.d.ts +38 -0
- package/dist/middleware.js +39 -0
- package/dist/server-ByBPoXJG.d.cts +182 -0
- package/dist/server-ByBPoXJG.d.ts +182 -0
- package/dist/server-CwxgXezP.d.cts +115 -0
- package/dist/server-CwxgXezP.d.ts +115 -0
- package/dist/server-D-pFrx8J.d.cts +105 -0
- package/dist/server-DaDfTjsO.d.cts +103 -0
- package/dist/server-DaDfTjsO.d.ts +103 -0
- package/dist/server-DjlQVC11.d.ts +105 -0
- package/dist/server.cjs +385 -0
- package/dist/server.d.cts +3 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +358 -0
- package/dist/storefront.cjs +474 -0
- package/dist/storefront.d.cts +2 -0
- package/dist/storefront.d.ts +2 -0
- package/dist/storefront.js +448 -0
- package/package.json +18 -8
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { TokenStorage, StorefrontSDK, StorefrontSDKOptions } from '@commercengine/storefront-sdk';
|
|
2
|
+
import './storefront.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for NextJSTokenStorage
|
|
6
|
+
*/
|
|
7
|
+
interface NextJSTokenStorageOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Prefix for cookie names (default: "ce_")
|
|
10
|
+
*/
|
|
11
|
+
prefix?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Maximum age of cookies in seconds (default: 30 days)
|
|
14
|
+
*/
|
|
15
|
+
maxAge?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Cookie path (default: "/")
|
|
18
|
+
*/
|
|
19
|
+
path?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Cookie domain (default: current domain)
|
|
22
|
+
*/
|
|
23
|
+
domain?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Whether cookies should be secure (default: auto-detect based on environment)
|
|
26
|
+
*/
|
|
27
|
+
secure?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* SameSite cookie attribute (default: "Lax")
|
|
30
|
+
*/
|
|
31
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Client-side token storage that uses document.cookie
|
|
35
|
+
*/
|
|
36
|
+
declare class ClientTokenStorage implements TokenStorage {
|
|
37
|
+
private accessTokenKey;
|
|
38
|
+
private refreshTokenKey;
|
|
39
|
+
private options;
|
|
40
|
+
constructor(options?: NextJSTokenStorageOptions);
|
|
41
|
+
getAccessToken(): Promise<string | null>;
|
|
42
|
+
setAccessToken(token: string): Promise<void>;
|
|
43
|
+
getRefreshToken(): Promise<string | null>;
|
|
44
|
+
setRefreshToken(token: string): Promise<void>;
|
|
45
|
+
clearTokens(): Promise<void>;
|
|
46
|
+
private getCookie;
|
|
47
|
+
private setCookie;
|
|
48
|
+
private deleteCookie;
|
|
49
|
+
}
|
|
50
|
+
type NextCookieStore$1 = {
|
|
51
|
+
get: (name: string) => {
|
|
52
|
+
value: string;
|
|
53
|
+
} | undefined;
|
|
54
|
+
set: (name: string, value: string, options?: any) => void;
|
|
55
|
+
delete: (name: string) => void;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Server-side token storage that uses Next.js cookies API
|
|
59
|
+
*/
|
|
60
|
+
declare class ServerTokenStorage implements TokenStorage {
|
|
61
|
+
private accessTokenKey;
|
|
62
|
+
private refreshTokenKey;
|
|
63
|
+
private options;
|
|
64
|
+
private cookieStore;
|
|
65
|
+
constructor(cookieStore: NextCookieStore$1, options?: NextJSTokenStorageOptions);
|
|
66
|
+
getAccessToken(): Promise<string | null>;
|
|
67
|
+
setAccessToken(token: string): Promise<void>;
|
|
68
|
+
getRefreshToken(): Promise<string | null>;
|
|
69
|
+
setRefreshToken(token: string): Promise<void>;
|
|
70
|
+
clearTokens(): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Configuration for the NextJS SDK wrapper
|
|
75
|
+
*/
|
|
76
|
+
interface NextJSSDKConfig extends Omit<StorefrontSDKOptions, "tokenStorage"> {
|
|
77
|
+
/**
|
|
78
|
+
* Token storage configuration options
|
|
79
|
+
*/
|
|
80
|
+
tokenStorageOptions?: NextJSTokenStorageOptions;
|
|
81
|
+
}
|
|
82
|
+
type NextCookieStore = {
|
|
83
|
+
get: (name: string) => {
|
|
84
|
+
value: string;
|
|
85
|
+
} | undefined;
|
|
86
|
+
set: (name: string, value: string, options?: any) => void;
|
|
87
|
+
delete: (name: string) => void;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Smart SDK getter that automatically detects environment
|
|
91
|
+
*
|
|
92
|
+
* Usage:
|
|
93
|
+
* - Client-side: getStorefrontSDK()
|
|
94
|
+
* - Server-side with request context: getStorefrontSDK(await cookies())
|
|
95
|
+
* - SSG/ISR (no request context): getStorefrontSDK() (uses memory storage)
|
|
96
|
+
*/
|
|
97
|
+
declare function getStorefrontSDK(): StorefrontSDK;
|
|
98
|
+
declare function getStorefrontSDK(cookieStore: NextCookieStore): StorefrontSDK;
|
|
99
|
+
/**
|
|
100
|
+
* Initialize the SDK with configuration (internal use)
|
|
101
|
+
* This should be called once in your app via StorefrontSDKInitializer
|
|
102
|
+
*/
|
|
103
|
+
declare function initializeStorefrontSDK(config: NextJSSDKConfig): void;
|
|
104
|
+
|
|
105
|
+
export { ClientTokenStorage as C, type NextJSSDKConfig as N, ServerTokenStorage as S, type NextJSTokenStorageOptions as a, getStorefrontSDK as g, initializeStorefrontSDK as i };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { TokenStorage, StorefrontSDK, StorefrontSDKOptions } from '@commercengine/storefront-sdk';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for NextJSTokenStorage
|
|
5
|
+
*/
|
|
6
|
+
interface NextJSTokenStorageOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Prefix for cookie names (default: "ce_")
|
|
9
|
+
*/
|
|
10
|
+
prefix?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Maximum age of cookies in seconds (default: 30 days)
|
|
13
|
+
*/
|
|
14
|
+
maxAge?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Cookie path (default: "/")
|
|
17
|
+
*/
|
|
18
|
+
path?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Cookie domain (default: current domain)
|
|
21
|
+
*/
|
|
22
|
+
domain?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Whether cookies should be secure (default: auto-detect based on environment)
|
|
25
|
+
*/
|
|
26
|
+
secure?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* SameSite cookie attribute (default: "Lax")
|
|
29
|
+
*/
|
|
30
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Client-side token storage that uses document.cookie
|
|
34
|
+
*/
|
|
35
|
+
declare class ClientTokenStorage implements TokenStorage {
|
|
36
|
+
private accessTokenKey;
|
|
37
|
+
private refreshTokenKey;
|
|
38
|
+
private options;
|
|
39
|
+
constructor(options?: NextJSTokenStorageOptions);
|
|
40
|
+
getAccessToken(): Promise<string | null>;
|
|
41
|
+
setAccessToken(token: string): Promise<void>;
|
|
42
|
+
getRefreshToken(): Promise<string | null>;
|
|
43
|
+
setRefreshToken(token: string): Promise<void>;
|
|
44
|
+
clearTokens(): Promise<void>;
|
|
45
|
+
private getCookie;
|
|
46
|
+
private setCookie;
|
|
47
|
+
private deleteCookie;
|
|
48
|
+
}
|
|
49
|
+
type NextCookieStore$1 = {
|
|
50
|
+
get: (name: string) => {
|
|
51
|
+
value: string;
|
|
52
|
+
} | undefined;
|
|
53
|
+
set: (name: string, value: string, options?: any) => void;
|
|
54
|
+
delete: (name: string) => void;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Server-side token storage that uses Next.js cookies API
|
|
58
|
+
*/
|
|
59
|
+
declare class ServerTokenStorage implements TokenStorage {
|
|
60
|
+
private accessTokenKey;
|
|
61
|
+
private refreshTokenKey;
|
|
62
|
+
private options;
|
|
63
|
+
private cookieStore;
|
|
64
|
+
constructor(cookieStore: NextCookieStore$1, options?: NextJSTokenStorageOptions);
|
|
65
|
+
getAccessToken(): Promise<string | null>;
|
|
66
|
+
setAccessToken(token: string): Promise<void>;
|
|
67
|
+
getRefreshToken(): Promise<string | null>;
|
|
68
|
+
setRefreshToken(token: string): Promise<void>;
|
|
69
|
+
clearTokens(): Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Configuration for the NextJS SDK wrapper
|
|
74
|
+
*/
|
|
75
|
+
interface NextJSSDKConfig extends Omit<StorefrontSDKOptions, "tokenStorage"> {
|
|
76
|
+
/**
|
|
77
|
+
* Token storage configuration options
|
|
78
|
+
*/
|
|
79
|
+
tokenStorageOptions?: NextJSTokenStorageOptions;
|
|
80
|
+
}
|
|
81
|
+
type NextCookieStore = {
|
|
82
|
+
get: (name: string) => {
|
|
83
|
+
value: string;
|
|
84
|
+
} | undefined;
|
|
85
|
+
set: (name: string, value: string, options?: any) => void;
|
|
86
|
+
delete: (name: string) => void;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Smart SDK getter that automatically detects environment
|
|
90
|
+
*
|
|
91
|
+
* Usage:
|
|
92
|
+
* - Client-side: getStorefrontSDK()
|
|
93
|
+
* - Server-side: getStorefrontSDK(await cookies())
|
|
94
|
+
*/
|
|
95
|
+
declare function getStorefrontSDK(): StorefrontSDK;
|
|
96
|
+
declare function getStorefrontSDK(cookieStore: NextCookieStore): StorefrontSDK;
|
|
97
|
+
/**
|
|
98
|
+
* Initialize the SDK with configuration (internal use)
|
|
99
|
+
* This should be called once in your app via StorefrontSDKInitializer
|
|
100
|
+
*/
|
|
101
|
+
declare function initializeStorefrontSDK(config: NextJSSDKConfig): void;
|
|
102
|
+
|
|
103
|
+
export { ClientTokenStorage as C, type NextJSSDKConfig as N, ServerTokenStorage as S, type NextJSTokenStorageOptions as a, getStorefrontSDK as g, initializeStorefrontSDK as i };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { TokenStorage, StorefrontSDK, StorefrontSDKOptions } from '@commercengine/storefront-sdk';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for NextJSTokenStorage
|
|
5
|
+
*/
|
|
6
|
+
interface NextJSTokenStorageOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Prefix for cookie names (default: "ce_")
|
|
9
|
+
*/
|
|
10
|
+
prefix?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Maximum age of cookies in seconds (default: 30 days)
|
|
13
|
+
*/
|
|
14
|
+
maxAge?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Cookie path (default: "/")
|
|
17
|
+
*/
|
|
18
|
+
path?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Cookie domain (default: current domain)
|
|
21
|
+
*/
|
|
22
|
+
domain?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Whether cookies should be secure (default: auto-detect based on environment)
|
|
25
|
+
*/
|
|
26
|
+
secure?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* SameSite cookie attribute (default: "Lax")
|
|
29
|
+
*/
|
|
30
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Client-side token storage that uses document.cookie
|
|
34
|
+
*/
|
|
35
|
+
declare class ClientTokenStorage implements TokenStorage {
|
|
36
|
+
private accessTokenKey;
|
|
37
|
+
private refreshTokenKey;
|
|
38
|
+
private options;
|
|
39
|
+
constructor(options?: NextJSTokenStorageOptions);
|
|
40
|
+
getAccessToken(): Promise<string | null>;
|
|
41
|
+
setAccessToken(token: string): Promise<void>;
|
|
42
|
+
getRefreshToken(): Promise<string | null>;
|
|
43
|
+
setRefreshToken(token: string): Promise<void>;
|
|
44
|
+
clearTokens(): Promise<void>;
|
|
45
|
+
private getCookie;
|
|
46
|
+
private setCookie;
|
|
47
|
+
private deleteCookie;
|
|
48
|
+
}
|
|
49
|
+
type NextCookieStore$1 = {
|
|
50
|
+
get: (name: string) => {
|
|
51
|
+
value: string;
|
|
52
|
+
} | undefined;
|
|
53
|
+
set: (name: string, value: string, options?: any) => void;
|
|
54
|
+
delete: (name: string) => void;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Server-side token storage that uses Next.js cookies API
|
|
58
|
+
*/
|
|
59
|
+
declare class ServerTokenStorage implements TokenStorage {
|
|
60
|
+
private accessTokenKey;
|
|
61
|
+
private refreshTokenKey;
|
|
62
|
+
private options;
|
|
63
|
+
private cookieStore;
|
|
64
|
+
constructor(cookieStore: NextCookieStore$1, options?: NextJSTokenStorageOptions);
|
|
65
|
+
getAccessToken(): Promise<string | null>;
|
|
66
|
+
setAccessToken(token: string): Promise<void>;
|
|
67
|
+
getRefreshToken(): Promise<string | null>;
|
|
68
|
+
setRefreshToken(token: string): Promise<void>;
|
|
69
|
+
clearTokens(): Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Configuration for the NextJS SDK wrapper
|
|
74
|
+
*/
|
|
75
|
+
interface NextJSSDKConfig extends Omit<StorefrontSDKOptions, "tokenStorage"> {
|
|
76
|
+
/**
|
|
77
|
+
* Token storage configuration options
|
|
78
|
+
*/
|
|
79
|
+
tokenStorageOptions?: NextJSTokenStorageOptions;
|
|
80
|
+
}
|
|
81
|
+
type NextCookieStore = {
|
|
82
|
+
get: (name: string) => {
|
|
83
|
+
value: string;
|
|
84
|
+
} | undefined;
|
|
85
|
+
set: (name: string, value: string, options?: any) => void;
|
|
86
|
+
delete: (name: string) => void;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Smart SDK getter that automatically detects environment
|
|
90
|
+
*
|
|
91
|
+
* Usage:
|
|
92
|
+
* - Client-side: getStorefrontSDK()
|
|
93
|
+
* - Server-side: getStorefrontSDK(await cookies())
|
|
94
|
+
*/
|
|
95
|
+
declare function getStorefrontSDK(): StorefrontSDK;
|
|
96
|
+
declare function getStorefrontSDK(cookieStore: NextCookieStore): StorefrontSDK;
|
|
97
|
+
/**
|
|
98
|
+
* Initialize the SDK with configuration (internal use)
|
|
99
|
+
* This should be called once in your app via StorefrontSDKInitializer
|
|
100
|
+
*/
|
|
101
|
+
declare function initializeStorefrontSDK(config: NextJSSDKConfig): void;
|
|
102
|
+
|
|
103
|
+
export { ClientTokenStorage as C, type NextJSSDKConfig as N, ServerTokenStorage as S, type NextJSTokenStorageOptions as a, getStorefrontSDK as g, initializeStorefrontSDK as i };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { TokenStorage, StorefrontSDK, StorefrontSDKOptions } from '@commercengine/storefront-sdk';
|
|
2
|
+
import './storefront.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for NextJSTokenStorage
|
|
6
|
+
*/
|
|
7
|
+
interface NextJSTokenStorageOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Prefix for cookie names (default: "ce_")
|
|
10
|
+
*/
|
|
11
|
+
prefix?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Maximum age of cookies in seconds (default: 30 days)
|
|
14
|
+
*/
|
|
15
|
+
maxAge?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Cookie path (default: "/")
|
|
18
|
+
*/
|
|
19
|
+
path?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Cookie domain (default: current domain)
|
|
22
|
+
*/
|
|
23
|
+
domain?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Whether cookies should be secure (default: auto-detect based on environment)
|
|
26
|
+
*/
|
|
27
|
+
secure?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* SameSite cookie attribute (default: "Lax")
|
|
30
|
+
*/
|
|
31
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Client-side token storage that uses document.cookie
|
|
35
|
+
*/
|
|
36
|
+
declare class ClientTokenStorage implements TokenStorage {
|
|
37
|
+
private accessTokenKey;
|
|
38
|
+
private refreshTokenKey;
|
|
39
|
+
private options;
|
|
40
|
+
constructor(options?: NextJSTokenStorageOptions);
|
|
41
|
+
getAccessToken(): Promise<string | null>;
|
|
42
|
+
setAccessToken(token: string): Promise<void>;
|
|
43
|
+
getRefreshToken(): Promise<string | null>;
|
|
44
|
+
setRefreshToken(token: string): Promise<void>;
|
|
45
|
+
clearTokens(): Promise<void>;
|
|
46
|
+
private getCookie;
|
|
47
|
+
private setCookie;
|
|
48
|
+
private deleteCookie;
|
|
49
|
+
}
|
|
50
|
+
type NextCookieStore$1 = {
|
|
51
|
+
get: (name: string) => {
|
|
52
|
+
value: string;
|
|
53
|
+
} | undefined;
|
|
54
|
+
set: (name: string, value: string, options?: any) => void;
|
|
55
|
+
delete: (name: string) => void;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Server-side token storage that uses Next.js cookies API
|
|
59
|
+
*/
|
|
60
|
+
declare class ServerTokenStorage implements TokenStorage {
|
|
61
|
+
private accessTokenKey;
|
|
62
|
+
private refreshTokenKey;
|
|
63
|
+
private options;
|
|
64
|
+
private cookieStore;
|
|
65
|
+
constructor(cookieStore: NextCookieStore$1, options?: NextJSTokenStorageOptions);
|
|
66
|
+
getAccessToken(): Promise<string | null>;
|
|
67
|
+
setAccessToken(token: string): Promise<void>;
|
|
68
|
+
getRefreshToken(): Promise<string | null>;
|
|
69
|
+
setRefreshToken(token: string): Promise<void>;
|
|
70
|
+
clearTokens(): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Configuration for the NextJS SDK wrapper
|
|
75
|
+
*/
|
|
76
|
+
interface NextJSSDKConfig extends Omit<StorefrontSDKOptions, "tokenStorage"> {
|
|
77
|
+
/**
|
|
78
|
+
* Token storage configuration options
|
|
79
|
+
*/
|
|
80
|
+
tokenStorageOptions?: NextJSTokenStorageOptions;
|
|
81
|
+
}
|
|
82
|
+
type NextCookieStore = {
|
|
83
|
+
get: (name: string) => {
|
|
84
|
+
value: string;
|
|
85
|
+
} | undefined;
|
|
86
|
+
set: (name: string, value: string, options?: any) => void;
|
|
87
|
+
delete: (name: string) => void;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Smart SDK getter that automatically detects environment
|
|
91
|
+
*
|
|
92
|
+
* Usage:
|
|
93
|
+
* - Client-side: getStorefrontSDK()
|
|
94
|
+
* - Server-side with request context: getStorefrontSDK(await cookies())
|
|
95
|
+
* - SSG/ISR (no request context): getStorefrontSDK() (uses memory storage)
|
|
96
|
+
*/
|
|
97
|
+
declare function getStorefrontSDK(): StorefrontSDK;
|
|
98
|
+
declare function getStorefrontSDK(cookieStore: NextCookieStore): StorefrontSDK;
|
|
99
|
+
/**
|
|
100
|
+
* Initialize the SDK with configuration (internal use)
|
|
101
|
+
* This should be called once in your app via StorefrontSDKInitializer
|
|
102
|
+
*/
|
|
103
|
+
declare function initializeStorefrontSDK(config: NextJSSDKConfig): void;
|
|
104
|
+
|
|
105
|
+
export { ClientTokenStorage as C, type NextJSSDKConfig as N, ServerTokenStorage as S, type NextJSTokenStorageOptions as a, getStorefrontSDK as g, initializeStorefrontSDK as i };
|