@pack/hydrogen 3.2.6 → 3.2.7
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 +7 -14
- package/dist/index.d.ts +0 -5
- package/dist/index.js +5 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@pack/hydrogen`
|
|
2
2
|
|
|
3
|
-
Hydrogen runtime integration for Pack content, preview, A/B testing
|
|
3
|
+
Hydrogen runtime integration for Pack content, preview, and A/B testing.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -19,25 +19,18 @@ npm install @pack/hydrogen
|
|
|
19
19
|
## Minimal setup
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
|
-
import {
|
|
23
|
-
createPackClient,
|
|
24
|
-
handleRequest,
|
|
25
|
-
} from '@pack/hydrogen';
|
|
26
|
-
import { createServerErrorHandler } from '@pack/errors';
|
|
22
|
+
import { createPackClient, handleRequest } from "@pack/hydrogen";
|
|
27
23
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
export default async function fetch(
|
|
25
|
+
request: Request,
|
|
26
|
+
env: Env,
|
|
27
|
+
ctx: ExecutionContext,
|
|
28
|
+
) {
|
|
33
29
|
const pack = createPackClient({
|
|
34
30
|
cache: caches.default,
|
|
35
31
|
waitUntil: ctx.waitUntil.bind(ctx),
|
|
36
32
|
storeId: env.PACK_STORE_ID,
|
|
37
33
|
token: env.PACK_API_TOKEN,
|
|
38
|
-
errorTracking: {
|
|
39
|
-
dsn: env.PUBLIC_PACK_ERROR_TRACKING_DSN,
|
|
40
|
-
},
|
|
41
34
|
session,
|
|
42
35
|
testSession,
|
|
43
36
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { PackClient } from '@pack/client';
|
|
2
|
-
import { ErrorTrackingOptions } from '@pack/errors';
|
|
3
2
|
import { CacheCustom } from '@shopify/hydrogen';
|
|
4
3
|
import { SessionStorage, Session, ActionFunctionArgs, LoaderFunctionArgs } from 'react-router';
|
|
5
4
|
import * as react from 'react';
|
|
@@ -86,8 +85,6 @@ interface CreatePackClientOptions extends EnvironmentOptions {
|
|
|
86
85
|
i18n?: I18nOptions;
|
|
87
86
|
/** Default theme data to use when no token is provided */
|
|
88
87
|
defaultThemeData?: DefaultThemeData;
|
|
89
|
-
/** Configuration for server-side error tracking */
|
|
90
|
-
errorTracking?: ErrorTrackingOptions;
|
|
91
88
|
/**
|
|
92
89
|
* Initial request to extract query parameters from.
|
|
93
90
|
* If not provided, it will be captured from the first handleRequest call.
|
|
@@ -145,14 +142,12 @@ interface Pack {
|
|
|
145
142
|
packAbTest: Test$1 | null | undefined;
|
|
146
143
|
packIsPreviewMode: boolean;
|
|
147
144
|
packCustomizerMeta: PackCustomizerMeta | null;
|
|
148
|
-
packErrorTracking?: ErrorTrackingOptions;
|
|
149
145
|
};
|
|
150
146
|
handleRequest(request: Request): Promise<(response: Response) => void>;
|
|
151
147
|
isPreviewModeEnabled: () => boolean;
|
|
152
148
|
isValidEditToken: PackClient["isValidEditToken"];
|
|
153
149
|
query: <T = any>(query: string, options: QueryOptions) => Promise<QueryResponse<T>>;
|
|
154
150
|
session: PackSession;
|
|
155
|
-
errorTracking?: ErrorTrackingOptions;
|
|
156
151
|
testSession: PackTestSession;
|
|
157
152
|
}
|
|
158
153
|
interface DefaultThemeData {
|
package/dist/index.js
CHANGED
|
@@ -4356,9 +4356,6 @@ var require_dist = __commonJS({
|
|
|
4356
4356
|
}
|
|
4357
4357
|
});
|
|
4358
4358
|
|
|
4359
|
-
// src/handle-request.ts
|
|
4360
|
-
import { sendServerErrorEvent } from "@pack/errors";
|
|
4361
|
-
|
|
4362
4359
|
// ../packlytics/dist/utils/get-packlytics-id.js
|
|
4363
4360
|
function sha256(ascii) {
|
|
4364
4361
|
function rightRotate(value, amount) {
|
|
@@ -4671,28 +4668,12 @@ async function packlytics(pack, request, next) {
|
|
|
4671
4668
|
}
|
|
4672
4669
|
|
|
4673
4670
|
// src/handle-request.ts
|
|
4674
|
-
function getServerStatusError(request, status) {
|
|
4675
|
-
let pathname = request.url;
|
|
4676
|
-
try {
|
|
4677
|
-
pathname = new URL(request.url).pathname;
|
|
4678
|
-
} catch {
|
|
4679
|
-
}
|
|
4680
|
-
return new Error(`HTTP ${status} response for ${request.method} ${pathname}`);
|
|
4681
|
-
}
|
|
4682
4671
|
async function handleRequest(pack, request, handleRequest2) {
|
|
4683
4672
|
const packHandleResponse = await pack.handleRequest(request);
|
|
4684
4673
|
let response;
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
});
|
|
4689
|
-
} catch (error) {
|
|
4690
|
-
sendServerErrorEvent(error, request, pack);
|
|
4691
|
-
throw error;
|
|
4692
|
-
}
|
|
4693
|
-
if (response.status >= 500 && !request.signal.aborted) {
|
|
4694
|
-
sendServerErrorEvent(getServerStatusError(request, response.status), request, pack);
|
|
4695
|
-
}
|
|
4674
|
+
response = await packlytics(pack, request, () => {
|
|
4675
|
+
return handleRequest2(request);
|
|
4676
|
+
});
|
|
4696
4677
|
packHandleResponse(response);
|
|
4697
4678
|
response.headers.append("powered-by", "Shopify, Hydrogen + Pack Digital");
|
|
4698
4679
|
response.headers.append("Set-Cookie", await pack.session.commit());
|
|
@@ -6211,7 +6192,6 @@ function createPackClient(options) {
|
|
|
6211
6192
|
token,
|
|
6212
6193
|
apiUrl,
|
|
6213
6194
|
defaultThemeData,
|
|
6214
|
-
errorTracking,
|
|
6215
6195
|
i18n,
|
|
6216
6196
|
request
|
|
6217
6197
|
} = options;
|
|
@@ -6281,8 +6261,7 @@ function createPackClient(options) {
|
|
|
6281
6261
|
packSessionId: session.id,
|
|
6282
6262
|
packAbTest: getCurrentAbTest(),
|
|
6283
6263
|
packIsPreviewMode: previewEnabled,
|
|
6284
|
-
packCustomizerMeta: session.get("customizerMeta")
|
|
6285
|
-
packErrorTracking: errorTracking
|
|
6264
|
+
packCustomizerMeta: session.get("customizerMeta")
|
|
6286
6265
|
};
|
|
6287
6266
|
},
|
|
6288
6267
|
isPreviewModeEnabled: () => previewEnabled,
|
|
@@ -6297,7 +6276,6 @@ function createPackClient(options) {
|
|
|
6297
6276
|
return { data, error: null };
|
|
6298
6277
|
},
|
|
6299
6278
|
session,
|
|
6300
|
-
errorTracking,
|
|
6301
6279
|
testSession
|
|
6302
6280
|
};
|
|
6303
6281
|
}
|
|
@@ -6339,8 +6317,7 @@ function createPackClient(options) {
|
|
|
6339
6317
|
packSessionId: session.id,
|
|
6340
6318
|
packAbTest: getCurrentAbTest(),
|
|
6341
6319
|
packIsPreviewMode: previewEnabled,
|
|
6342
|
-
packCustomizerMeta: session.get("customizerMeta")
|
|
6343
|
-
packErrorTracking: errorTracking
|
|
6320
|
+
packCustomizerMeta: session.get("customizerMeta")
|
|
6344
6321
|
};
|
|
6345
6322
|
},
|
|
6346
6323
|
handleRequest: handleRequest2,
|
|
@@ -6468,7 +6445,6 @@ function createPackClient(options) {
|
|
|
6468
6445
|
}
|
|
6469
6446
|
},
|
|
6470
6447
|
session,
|
|
6471
|
-
errorTracking,
|
|
6472
6448
|
testSession
|
|
6473
6449
|
};
|
|
6474
6450
|
}
|