@pack/hydrogen 3.2.5 → 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 +53 -86
- 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());
|
|
@@ -5811,71 +5792,62 @@ async function getTestInfo({
|
|
|
5811
5792
|
);
|
|
5812
5793
|
if (testSessionData?.id && testSessionData?.testVariant) {
|
|
5813
5794
|
debug3("[Pack Test] Found existing test data in session");
|
|
5814
|
-
|
|
5815
|
-
|
|
5816
|
-
|
|
5795
|
+
try {
|
|
5796
|
+
const validationResult = await packClientFetchTestByRules(
|
|
5797
|
+
packClient,
|
|
5798
|
+
testTargetAudienceAttributes,
|
|
5799
|
+
testSession,
|
|
5800
|
+
request,
|
|
5801
|
+
withCache,
|
|
5802
|
+
token,
|
|
5803
|
+
null,
|
|
5804
|
+
true
|
|
5805
|
+
// validateOnly - but will assign new test if current is inactive
|
|
5817
5806
|
);
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
if (validationResult) {
|
|
5831
|
-
if (validationResult.id === testSessionData.id) {
|
|
5832
|
-
debug3(
|
|
5833
|
-
"[Pack Test] Test is still active, using refreshed data",
|
|
5834
|
-
JSON.stringify({
|
|
5835
|
-
testId: validationResult.id,
|
|
5836
|
-
testHandle: validationResult.handle,
|
|
5837
|
-
variantId: validationResult.testVariant.id,
|
|
5838
|
-
variantHandle: validationResult.testVariant.handle
|
|
5839
|
-
})
|
|
5840
|
-
);
|
|
5841
|
-
return validationResult;
|
|
5842
|
-
} else {
|
|
5843
|
-
debug3(
|
|
5844
|
-
"[Pack Test] Original test no longer active, new test assigned",
|
|
5845
|
-
JSON.stringify({
|
|
5846
|
-
oldTestId: testSessionData.id,
|
|
5847
|
-
newTestId: validationResult.id,
|
|
5848
|
-
newTestHandle: validationResult.handle,
|
|
5849
|
-
newVariantId: validationResult.testVariant.id,
|
|
5850
|
-
newVariantHandle: validationResult.testVariant.handle
|
|
5851
|
-
})
|
|
5852
|
-
);
|
|
5853
|
-
return {
|
|
5854
|
-
...validationResult,
|
|
5855
|
-
isFirstExposure: true
|
|
5856
|
-
};
|
|
5857
|
-
}
|
|
5807
|
+
if (validationResult) {
|
|
5808
|
+
if (validationResult.id === testSessionData.id) {
|
|
5809
|
+
debug3(
|
|
5810
|
+
"[Pack Test] Test is still active, using refreshed data",
|
|
5811
|
+
JSON.stringify({
|
|
5812
|
+
testId: validationResult.id,
|
|
5813
|
+
testHandle: validationResult.handle,
|
|
5814
|
+
variantId: validationResult.testVariant.id,
|
|
5815
|
+
variantHandle: validationResult.testVariant.handle
|
|
5816
|
+
})
|
|
5817
|
+
);
|
|
5818
|
+
return validationResult;
|
|
5858
5819
|
} else {
|
|
5859
5820
|
debug3(
|
|
5860
|
-
"[Pack Test]
|
|
5821
|
+
"[Pack Test] Original test no longer active, new test assigned",
|
|
5822
|
+
JSON.stringify({
|
|
5823
|
+
oldTestId: testSessionData.id,
|
|
5824
|
+
newTestId: validationResult.id,
|
|
5825
|
+
newTestHandle: validationResult.handle,
|
|
5826
|
+
newVariantId: validationResult.testVariant.id,
|
|
5827
|
+
newVariantHandle: validationResult.testVariant.handle
|
|
5828
|
+
})
|
|
5861
5829
|
);
|
|
5862
|
-
return
|
|
5830
|
+
return {
|
|
5831
|
+
...validationResult,
|
|
5832
|
+
isFirstExposure: true
|
|
5833
|
+
};
|
|
5863
5834
|
}
|
|
5864
|
-
}
|
|
5835
|
+
} else {
|
|
5865
5836
|
debug3(
|
|
5866
|
-
"[Pack Test]
|
|
5867
|
-
JSON.stringify(error)
|
|
5837
|
+
"[Pack Test] Test is no longer active and no new test was assigned"
|
|
5868
5838
|
);
|
|
5869
|
-
|
|
5870
|
-
"[Pack Test] Error validating test, using cached data:",
|
|
5871
|
-
error
|
|
5872
|
-
);
|
|
5873
|
-
return { ...testSessionData, isFirstExposure: void 0 };
|
|
5839
|
+
return void 0;
|
|
5874
5840
|
}
|
|
5875
|
-
}
|
|
5876
|
-
debug3(
|
|
5877
|
-
|
|
5878
|
-
|
|
5841
|
+
} catch (error) {
|
|
5842
|
+
debug3(
|
|
5843
|
+
"[Pack Test] Error validating test, using cached data:",
|
|
5844
|
+
JSON.stringify(error)
|
|
5845
|
+
);
|
|
5846
|
+
console.error(
|
|
5847
|
+
"[Pack Test] Error validating test, using cached data:",
|
|
5848
|
+
error
|
|
5849
|
+
);
|
|
5850
|
+
return { ...testSessionData, isFirstExposure: void 0 };
|
|
5879
5851
|
}
|
|
5880
5852
|
}
|
|
5881
5853
|
if (exposedTestCookieString) {
|
|
@@ -6220,7 +6192,6 @@ function createPackClient(options) {
|
|
|
6220
6192
|
token,
|
|
6221
6193
|
apiUrl,
|
|
6222
6194
|
defaultThemeData,
|
|
6223
|
-
errorTracking,
|
|
6224
6195
|
i18n,
|
|
6225
6196
|
request
|
|
6226
6197
|
} = options;
|
|
@@ -6290,8 +6261,7 @@ function createPackClient(options) {
|
|
|
6290
6261
|
packSessionId: session.id,
|
|
6291
6262
|
packAbTest: getCurrentAbTest(),
|
|
6292
6263
|
packIsPreviewMode: previewEnabled,
|
|
6293
|
-
packCustomizerMeta: session.get("customizerMeta")
|
|
6294
|
-
packErrorTracking: errorTracking
|
|
6264
|
+
packCustomizerMeta: session.get("customizerMeta")
|
|
6295
6265
|
};
|
|
6296
6266
|
},
|
|
6297
6267
|
isPreviewModeEnabled: () => previewEnabled,
|
|
@@ -6306,7 +6276,6 @@ function createPackClient(options) {
|
|
|
6306
6276
|
return { data, error: null };
|
|
6307
6277
|
},
|
|
6308
6278
|
session,
|
|
6309
|
-
errorTracking,
|
|
6310
6279
|
testSession
|
|
6311
6280
|
};
|
|
6312
6281
|
}
|
|
@@ -6348,8 +6317,7 @@ function createPackClient(options) {
|
|
|
6348
6317
|
packSessionId: session.id,
|
|
6349
6318
|
packAbTest: getCurrentAbTest(),
|
|
6350
6319
|
packIsPreviewMode: previewEnabled,
|
|
6351
|
-
packCustomizerMeta: session.get("customizerMeta")
|
|
6352
|
-
packErrorTracking: errorTracking
|
|
6320
|
+
packCustomizerMeta: session.get("customizerMeta")
|
|
6353
6321
|
};
|
|
6354
6322
|
},
|
|
6355
6323
|
handleRequest: handleRequest2,
|
|
@@ -6477,7 +6445,6 @@ function createPackClient(options) {
|
|
|
6477
6445
|
}
|
|
6478
6446
|
},
|
|
6479
6447
|
session,
|
|
6480
|
-
errorTracking,
|
|
6481
6448
|
testSession
|
|
6482
6449
|
};
|
|
6483
6450
|
}
|