@pack/hydrogen 1.0.8 → 2.0.0-beta.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/dist/index.d.mts +195 -0
- package/dist/index.js +2903 -6
- package/dist/index.js.map +1 -0
- package/package.json +15 -6
- package/dist/constants.d.ts +0 -4
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -3
- package/dist/create-pack-client.d.ts +0 -60
- package/dist/create-pack-client.d.ts.map +0 -1
- package/dist/create-pack-client.js +0 -214
- package/dist/handle-request.d.ts +0 -3
- package/dist/handle-request.d.ts.map +0 -1
- package/dist/handle-request.js +0 -9
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/preview/preview-mode.d.ts +0 -27
- package/dist/preview/preview-mode.d.ts.map +0 -1
- package/dist/preview/preview-mode.js +0 -108
- package/dist/session/cookies-utils.d.ts +0 -13
- package/dist/session/cookies-utils.d.ts.map +0 -1
- package/dist/session/cookies-utils.js +0 -62
- package/dist/session/session.d.ts +0 -14
- package/dist/session/session.d.ts.map +0 -1
- package/dist/session/session.js +0 -50
- package/dist/session/usePackCookies.d.ts +0 -15
- package/dist/session/usePackCookies.d.ts.map +0 -1
- package/dist/session/usePackCookies.js +0 -17
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { PackClient } from '@pack/client';
|
|
2
|
+
import { CacheCustom } from '@shopify/hydrogen';
|
|
3
|
+
import { SessionStorage, Session } from '@shopify/remix-oxygen';
|
|
4
|
+
import { ActionFunction, LoaderFunction } from '@remix-run/server-runtime';
|
|
5
|
+
import * as react from 'react';
|
|
6
|
+
import react__default, { Dispatch, SetStateAction, PropsWithChildren } from 'react';
|
|
7
|
+
|
|
8
|
+
declare class PackSession {
|
|
9
|
+
#private;
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly secret: string;
|
|
12
|
+
constructor(id: string, secret: string, sessionStorage: SessionStorage, session: Session);
|
|
13
|
+
static init(request: Request, secrets: string[]): Promise<PackSession>;
|
|
14
|
+
has(key: string): boolean;
|
|
15
|
+
get(key: string): any;
|
|
16
|
+
destroy(): Promise<string>;
|
|
17
|
+
set(key: string, value: any): void;
|
|
18
|
+
commit(): Promise<string>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface TestInput {
|
|
22
|
+
testId?: string;
|
|
23
|
+
testHandle?: string;
|
|
24
|
+
testVariantId?: string;
|
|
25
|
+
testVariantHandle?: string;
|
|
26
|
+
}
|
|
27
|
+
interface Test$1 {
|
|
28
|
+
id: string;
|
|
29
|
+
handle: string;
|
|
30
|
+
testVariant: {
|
|
31
|
+
id: string;
|
|
32
|
+
handle: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare class PackTestSession {
|
|
37
|
+
#private;
|
|
38
|
+
readonly id: string;
|
|
39
|
+
constructor(id: string, sessionStorage: SessionStorage, session: Session);
|
|
40
|
+
static init(request: Request, secrets: string[]): Promise<PackTestSession>;
|
|
41
|
+
getTestData(): Test$1 | undefined;
|
|
42
|
+
getExpireAt(): string | undefined;
|
|
43
|
+
setTestData(testData: Test$1 | undefined): void;
|
|
44
|
+
setExpireAt(expireAt: string | undefined): void;
|
|
45
|
+
clearTestData(): void;
|
|
46
|
+
hasTestData(): boolean;
|
|
47
|
+
hasChanges(): boolean;
|
|
48
|
+
commit(): Promise<string>;
|
|
49
|
+
destroy(): Promise<string>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @see https://shopify.dev/docs/custom-storefronts/hydrogen/data-fetching/cache#caching-strategies */
|
|
53
|
+
type CachingStrategy = ReturnType<typeof CacheCustom>;
|
|
54
|
+
interface EnvironmentOptions {
|
|
55
|
+
/**
|
|
56
|
+
* A Cache API instance.
|
|
57
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Cache
|
|
58
|
+
*/
|
|
59
|
+
cache: Cache;
|
|
60
|
+
/**
|
|
61
|
+
* A runtime utility for serverless environments
|
|
62
|
+
* @see https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#waituntil
|
|
63
|
+
*/
|
|
64
|
+
waitUntil: ExecutionContext["waitUntil"];
|
|
65
|
+
}
|
|
66
|
+
interface CreatePackClientOptions extends EnvironmentOptions {
|
|
67
|
+
apiUrl?: string;
|
|
68
|
+
token?: string;
|
|
69
|
+
storeId?: string;
|
|
70
|
+
session: PackSession;
|
|
71
|
+
testSession: PackTestSession;
|
|
72
|
+
contentEnvironment?: string;
|
|
73
|
+
/** Default theme data to use when no token is provided */
|
|
74
|
+
defaultThemeData?: DefaultThemeData;
|
|
75
|
+
}
|
|
76
|
+
type Variables = Record<string, any>;
|
|
77
|
+
interface QueryOptions {
|
|
78
|
+
variables?: Variables;
|
|
79
|
+
cache?: CachingStrategy;
|
|
80
|
+
test?: TestInput;
|
|
81
|
+
request: Request;
|
|
82
|
+
}
|
|
83
|
+
interface QueryError {
|
|
84
|
+
message: string;
|
|
85
|
+
param?: string;
|
|
86
|
+
code?: string;
|
|
87
|
+
type: string;
|
|
88
|
+
}
|
|
89
|
+
interface QueryResponse<T> {
|
|
90
|
+
data: T | null;
|
|
91
|
+
error: QueryError | null;
|
|
92
|
+
packTestInfo?: Test$1;
|
|
93
|
+
}
|
|
94
|
+
interface PackCustomizerMeta {
|
|
95
|
+
environment?: string;
|
|
96
|
+
overlay?: {
|
|
97
|
+
src?: string;
|
|
98
|
+
version?: string;
|
|
99
|
+
};
|
|
100
|
+
[key: string]: any;
|
|
101
|
+
}
|
|
102
|
+
interface Pack {
|
|
103
|
+
abTest: Test$1 | null | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* @deprecated The method should not be used
|
|
106
|
+
*/
|
|
107
|
+
getPackSessionData(): {
|
|
108
|
+
storeId: string;
|
|
109
|
+
sessionId: string;
|
|
110
|
+
abTest: Test$1 | null | undefined;
|
|
111
|
+
isPreviewModeEnabled: boolean;
|
|
112
|
+
customizerMeta: any;
|
|
113
|
+
};
|
|
114
|
+
getPackContextData(): {
|
|
115
|
+
packStoreId: string;
|
|
116
|
+
packSessionId: string;
|
|
117
|
+
packAbTest: Test$1 | null | undefined;
|
|
118
|
+
packIsPreviewMode: boolean;
|
|
119
|
+
packCustomizerMeta: PackCustomizerMeta | null;
|
|
120
|
+
};
|
|
121
|
+
handleRequest(request: Request): Promise<(response: Response) => void>;
|
|
122
|
+
isPreviewModeEnabled: () => boolean;
|
|
123
|
+
isValidEditToken: PackClient["isValidEditToken"];
|
|
124
|
+
query: <T = any>(query: string, options: QueryOptions) => Promise<QueryResponse<T>>;
|
|
125
|
+
session: PackSession;
|
|
126
|
+
testSession: PackTestSession;
|
|
127
|
+
}
|
|
128
|
+
interface DefaultThemeData {
|
|
129
|
+
data: Record<string, any>;
|
|
130
|
+
}
|
|
131
|
+
declare function createPackClient(options: CreatePackClientOptions): Pack;
|
|
132
|
+
|
|
133
|
+
declare function handleRequest(pack: Pack, request: Request, handleRequest: (request: Request) => Promise<Response>): Promise<Response>;
|
|
134
|
+
|
|
135
|
+
type UsePackCookiesOptions = {
|
|
136
|
+
/**
|
|
137
|
+
* If set to `false`, Shopify cookies will be removed.
|
|
138
|
+
* If set to `true`, Shopify unique user token cookie will have cookie expiry of 1 year.
|
|
139
|
+
* Defaults to false.
|
|
140
|
+
**/
|
|
141
|
+
hasUserConsent?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* The domain scope of the cookie. Defaults to empty string.
|
|
144
|
+
**/
|
|
145
|
+
domain?: string;
|
|
146
|
+
};
|
|
147
|
+
declare function usePackCookies(options?: UsePackCookiesOptions): void;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* A `POST` request to this route will exit preview mode
|
|
151
|
+
* POST /api/edit Content-Type: application/x-www-form-urlencoded
|
|
152
|
+
*/
|
|
153
|
+
declare const action: ActionFunction;
|
|
154
|
+
/**
|
|
155
|
+
* A `GET` request to this route will enter preview mode
|
|
156
|
+
*/
|
|
157
|
+
declare const loader: LoaderFunction;
|
|
158
|
+
|
|
159
|
+
declare const PackTestRoute: () => null;
|
|
160
|
+
|
|
161
|
+
interface Test {
|
|
162
|
+
id: string;
|
|
163
|
+
handle: string;
|
|
164
|
+
testVariant: {
|
|
165
|
+
id: string;
|
|
166
|
+
handle: string;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
interface TestExposureCallbackArg extends Test {
|
|
170
|
+
exposureTime: number;
|
|
171
|
+
}
|
|
172
|
+
type PackTestContextValue = {
|
|
173
|
+
testExposureCallback?: (test: TestExposureCallbackArg) => void;
|
|
174
|
+
hasUserConsent?: boolean | undefined;
|
|
175
|
+
pendingExposureQueue?: Map<any, any>;
|
|
176
|
+
setPendingExposureQueue?: Dispatch<SetStateAction<Map<any, any>>>;
|
|
177
|
+
exposedExperiments?: Set<unknown>;
|
|
178
|
+
};
|
|
179
|
+
declare const PackTestContext: react.Context<PackTestContextValue>;
|
|
180
|
+
declare const usePackTestContext: () => PackTestContextValue;
|
|
181
|
+
|
|
182
|
+
interface PackContentProps {
|
|
183
|
+
testExposureCallback?: (test: Test) => void;
|
|
184
|
+
hasUserConsent?: boolean;
|
|
185
|
+
}
|
|
186
|
+
declare function PackTestProvider({ children, testExposureCallback, hasUserConsent, }: PropsWithChildren<PackContentProps>): react__default.JSX.Element;
|
|
187
|
+
|
|
188
|
+
declare function useAbTest(): Test$1 | null;
|
|
189
|
+
declare function useAbTestSessionId(): string;
|
|
190
|
+
declare function useAbTestId(): string | undefined;
|
|
191
|
+
declare function useAbTestHandle(): string | undefined;
|
|
192
|
+
declare function useAbTestVariantId(): string | undefined;
|
|
193
|
+
declare function useAbTestVariantHandle(): string | undefined;
|
|
194
|
+
|
|
195
|
+
export { type Pack, PackSession, PackTestContext, PackTestProvider, PackTestRoute, PackTestSession, createPackClient, handleRequest, action as previewModeAction, loader as previewModeLoader, useAbTest, useAbTestHandle, useAbTestId, useAbTestSessionId, useAbTestVariantHandle, useAbTestVariantId, usePackCookies, usePackTestContext };
|