@pack/hydrogen 3.1.1-beta.0 → 3.2.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.
package/README.md CHANGED
@@ -1 +1,54 @@
1
- # hydrogen
1
+ # `@pack/hydrogen`
2
+
3
+ Hydrogen runtime integration for Pack content, preview, A/B testing, and server-side error tracking.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @pack/hydrogen
9
+ ```
10
+
11
+ ## Main exports
12
+
13
+ - `createPackClient`
14
+ - `handleRequest`
15
+ - `PackSession`, `PackTestSession`
16
+ - `previewModeAction`, `previewModeLoader`
17
+ - A/B test helpers (`PackTestProvider`, `useAbTest`, etc.)
18
+
19
+ ## Minimal setup
20
+
21
+ ```ts
22
+ import {
23
+ createPackClient,
24
+ handleRequest,
25
+ } from '@pack/hydrogen';
26
+ import { createServerErrorHandler } from '@pack/errors';
27
+
28
+ // Optional if you want route-level error capture in addition to handleRequest wrapping.
29
+ // Duplicate reports for the same Error instance are deduplicated automatically.
30
+ export const handleError = createServerErrorHandler();
31
+
32
+ export default async function fetch(request: Request, env: Env, ctx: ExecutionContext) {
33
+ const pack = createPackClient({
34
+ cache: caches.default,
35
+ waitUntil: ctx.waitUntil.bind(ctx),
36
+ storeId: env.PACK_STORE_ID,
37
+ token: env.PACK_API_TOKEN,
38
+ errorTracking: {
39
+ dsn: env.PUBLIC_PACK_ERROR_TRACKING_DSN,
40
+ },
41
+ session,
42
+ testSession,
43
+ });
44
+
45
+ return handleRequest(pack, request, (req) => storefrontHandler(req));
46
+ }
47
+ ```
48
+
49
+ ## Development
50
+
51
+ ```bash
52
+ yarn
53
+ yarn build
54
+ ```
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { PackClient } from '@pack/client';
2
+ import { ErrorTrackingOptions } from '@pack/errors';
2
3
  import { CacheCustom } from '@shopify/hydrogen';
3
4
  import { SessionStorage, Session, ActionFunctionArgs, LoaderFunctionArgs } from 'react-router';
4
5
  import * as react from 'react';
@@ -26,10 +27,14 @@ interface TestInput {
26
27
  interface Test$1 {
27
28
  id: string;
28
29
  handle: string;
30
+ impressionTrigger?: string;
29
31
  testVariant: {
30
32
  id: string;
31
33
  handle: string;
32
34
  };
35
+ impression?: {
36
+ sectionIds?: string[];
37
+ };
33
38
  }
34
39
 
35
40
  declare class PackTestSession {
@@ -81,6 +86,8 @@ interface CreatePackClientOptions extends EnvironmentOptions {
81
86
  i18n?: I18nOptions;
82
87
  /** Default theme data to use when no token is provided */
83
88
  defaultThemeData?: DefaultThemeData;
89
+ /** Configuration for server-side error tracking */
90
+ errorTracking?: ErrorTrackingOptions;
84
91
  /**
85
92
  * Initial request to extract query parameters from.
86
93
  * If not provided, it will be captured from the first handleRequest call.
@@ -138,12 +145,14 @@ interface Pack {
138
145
  packAbTest: Test$1 | null | undefined;
139
146
  packIsPreviewMode: boolean;
140
147
  packCustomizerMeta: PackCustomizerMeta | null;
148
+ packErrorTracking?: ErrorTrackingOptions;
141
149
  };
142
150
  handleRequest(request: Request): Promise<(response: Response) => void>;
143
151
  isPreviewModeEnabled: () => boolean;
144
152
  isValidEditToken: PackClient["isValidEditToken"];
145
153
  query: <T = any>(query: string, options: QueryOptions) => Promise<QueryResponse<T>>;
146
154
  session: PackSession;
155
+ errorTracking?: ErrorTrackingOptions;
147
156
  testSession: PackTestSession;
148
157
  }
149
158
  interface DefaultThemeData {
@@ -177,15 +186,23 @@ declare function action({ request, context }: ActionFunctionArgs): Promise<Respo
177
186
  */
178
187
  declare function loader({ request, context }: LoaderFunctionArgs): Promise<Response>;
179
188
 
180
- declare const PackTestRoute: () => null;
189
+ type PackTestImpressionSelector = string | string[] | ((packTestInfo: Test$1) => string | string[] | undefined);
190
+ type PackTestRouteProps = {
191
+ impressionSelector?: PackTestImpressionSelector;
192
+ };
193
+ declare const PackTestRoute: ({ impressionSelector, }?: PackTestRouteProps) => null;
181
194
 
182
195
  interface Test {
183
196
  id: string;
184
197
  handle: string;
198
+ impressionTrigger?: string;
185
199
  testVariant: {
186
200
  id: string;
187
201
  handle: string;
188
202
  };
203
+ impression?: {
204
+ sectionIds?: string[];
205
+ };
189
206
  }
190
207
  interface TestExposureCallbackArg extends Test {
191
208
  exposureTime: number;