@pack/hydrogen 2.0.6 → 2.1.0-rr7-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.ts +15 -4
- package/dist/index.js +53 -22
- package/dist/index.js.map +1 -1
- package/package.json +10 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { PackClient } from '@pack/client';
|
|
2
2
|
import { CacheCustom } from '@shopify/hydrogen';
|
|
3
|
-
import { SessionStorage, Session } from '
|
|
4
|
-
import { ActionFunction, LoaderFunction } from '@remix-run/server-runtime';
|
|
3
|
+
import { SessionStorage, Session, ActionFunctionArgs, LoaderFunctionArgs } from 'react-router';
|
|
5
4
|
import * as react from 'react';
|
|
6
5
|
import react__default, { Dispatch, SetStateAction, PropsWithChildren } from 'react';
|
|
7
6
|
|
|
@@ -68,6 +67,10 @@ interface EnvironmentOptions {
|
|
|
68
67
|
*/
|
|
69
68
|
waitUntil: ExecutionContext["waitUntil"];
|
|
70
69
|
}
|
|
70
|
+
interface I18nOptions {
|
|
71
|
+
language: string;
|
|
72
|
+
country: string;
|
|
73
|
+
}
|
|
71
74
|
interface CreatePackClientOptions extends EnvironmentOptions {
|
|
72
75
|
apiUrl?: string;
|
|
73
76
|
token?: string;
|
|
@@ -75,6 +78,7 @@ interface CreatePackClientOptions extends EnvironmentOptions {
|
|
|
75
78
|
session: PackSession;
|
|
76
79
|
testSession: PackTestSession;
|
|
77
80
|
contentEnvironment?: string;
|
|
81
|
+
i18n?: I18nOptions;
|
|
78
82
|
/** Default theme data to use when no token is provided */
|
|
79
83
|
defaultThemeData?: DefaultThemeData;
|
|
80
84
|
/**
|
|
@@ -107,6 +111,13 @@ interface PackCustomizerMeta {
|
|
|
107
111
|
src?: string;
|
|
108
112
|
version?: string;
|
|
109
113
|
};
|
|
114
|
+
previewContext?: {
|
|
115
|
+
locale?: string;
|
|
116
|
+
pageDraft?: string;
|
|
117
|
+
siteSettingsDraft?: string;
|
|
118
|
+
testHandle?: string;
|
|
119
|
+
testVariantHandle?: string;
|
|
120
|
+
};
|
|
110
121
|
[key: string]: any;
|
|
111
122
|
}
|
|
112
123
|
interface Pack {
|
|
@@ -160,11 +171,11 @@ declare function usePackCookies(options?: UsePackCookiesOptions): void;
|
|
|
160
171
|
* A `POST` request to this route will exit preview mode
|
|
161
172
|
* POST /api/edit Content-Type: application/x-www-form-urlencoded
|
|
162
173
|
*/
|
|
163
|
-
declare
|
|
174
|
+
declare function action({ request, context }: ActionFunctionArgs): Promise<Response>;
|
|
164
175
|
/**
|
|
165
176
|
* A `GET` request to this route will enter preview mode
|
|
166
177
|
*/
|
|
167
|
-
declare
|
|
178
|
+
declare function loader({ request, context }: LoaderFunctionArgs): Promise<Response>;
|
|
168
179
|
|
|
169
180
|
declare const PackTestRoute: () => null;
|
|
170
181
|
|
package/dist/index.js
CHANGED
|
@@ -1322,7 +1322,7 @@ var require_cookie = __commonJS({
|
|
|
1322
1322
|
"node_modules/cookie/index.js"(exports) {
|
|
1323
1323
|
"use strict";
|
|
1324
1324
|
exports.parse = parse2;
|
|
1325
|
-
exports.serialize =
|
|
1325
|
+
exports.serialize = serialize3;
|
|
1326
1326
|
var __toString = Object.prototype.toString;
|
|
1327
1327
|
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
1328
1328
|
function parse2(str, options) {
|
|
@@ -1357,7 +1357,7 @@ var require_cookie = __commonJS({
|
|
|
1357
1357
|
}
|
|
1358
1358
|
return obj;
|
|
1359
1359
|
}
|
|
1360
|
-
function
|
|
1360
|
+
function serialize3(name, val, options) {
|
|
1361
1361
|
var opt = options || {};
|
|
1362
1362
|
var enc = opt.encode || encode;
|
|
1363
1363
|
if (typeof enc !== "function") {
|
|
@@ -4588,7 +4588,7 @@ function getDevice(userAgent) {
|
|
|
4588
4588
|
}
|
|
4589
4589
|
|
|
4590
4590
|
// ../packlytics/dist/packlytics.js
|
|
4591
|
-
import { getStorefrontHeaders } from "@shopify/
|
|
4591
|
+
import { getStorefrontHeaders } from "@shopify/hydrogen/oxygen";
|
|
4592
4592
|
|
|
4593
4593
|
// ../packlytics/dist/utils/get-client-location.js
|
|
4594
4594
|
function getClientLocation(locale) {
|
|
@@ -4655,21 +4655,16 @@ async function handleRequest(pack, request, handleRequest2) {
|
|
|
4655
4655
|
packHandleResponse(response);
|
|
4656
4656
|
response.headers.append("powered-by", "Shopify, Hydrogen + Pack Digital");
|
|
4657
4657
|
response.headers.append("Set-Cookie", await pack.session.commit());
|
|
4658
|
-
if (pack.testSession.hasChanges()) {
|
|
4658
|
+
if (pack.testSession && pack.testSession.hasChanges()) {
|
|
4659
4659
|
response.headers.append("Set-Cookie", await pack.testSession.commit());
|
|
4660
4660
|
}
|
|
4661
4661
|
return response;
|
|
4662
4662
|
}
|
|
4663
4663
|
|
|
4664
4664
|
// src/session/usePackCookies.ts
|
|
4665
|
+
var import_cookie = __toESM(require_cookie(), 1);
|
|
4665
4666
|
import { useEffect } from "react";
|
|
4666
4667
|
|
|
4667
|
-
// ../../node_modules/worktop/cookie/index.mjs
|
|
4668
|
-
function l(a, r, e = {}) {
|
|
4669
|
-
let t = a + "=" + encodeURIComponent(r);
|
|
4670
|
-
return e.expires && (t += "; Expires=" + new Date(e.expires).toUTCString()), e.maxage != null && e.maxage >= 0 && (t += "; Max-Age=" + (e.maxage | 0)), e.domain && (t += "; Domain=" + e.domain), e.path && (t += "; Path=" + e.path), e.samesite && (t += "; SameSite=" + e.samesite), (e.secure || e.samesite === "None") && (t += "; Secure"), e.httponly && (t += "; HttpOnly"), t;
|
|
4671
|
-
}
|
|
4672
|
-
|
|
4673
4668
|
// src/constants.ts
|
|
4674
4669
|
var PACK_COOKIE_ID = "__pack";
|
|
4675
4670
|
var PACK_USER_CONSENT_COOKIE_ID = "__pack_user_consent";
|
|
@@ -4689,10 +4684,10 @@ function usePackCookies(options) {
|
|
|
4689
4684
|
}, [hasUserConsent2]);
|
|
4690
4685
|
}
|
|
4691
4686
|
function setCookie(name, value, maxage, domain) {
|
|
4692
|
-
document.cookie =
|
|
4693
|
-
maxage,
|
|
4687
|
+
document.cookie = (0, import_cookie.serialize)(name, value, {
|
|
4688
|
+
maxAge: maxage,
|
|
4694
4689
|
domain,
|
|
4695
|
-
|
|
4690
|
+
sameSite: "lax",
|
|
4696
4691
|
path: "/"
|
|
4697
4692
|
});
|
|
4698
4693
|
}
|
|
@@ -4701,7 +4696,7 @@ function setCookie(name, value, maxage, domain) {
|
|
|
4701
4696
|
import {
|
|
4702
4697
|
createCookie,
|
|
4703
4698
|
createCookieSessionStorage
|
|
4704
|
-
} from "
|
|
4699
|
+
} from "react-router";
|
|
4705
4700
|
|
|
4706
4701
|
// src/session/cookies-utils.tsx
|
|
4707
4702
|
var import_cookie2 = __toESM(require_cookie(), 1);
|
|
@@ -4803,7 +4798,7 @@ var PackSession = class {
|
|
|
4803
4798
|
import {
|
|
4804
4799
|
createCookie as createCookie2,
|
|
4805
4800
|
createCookieSessionStorage as createCookieSessionStorage2
|
|
4806
|
-
} from "
|
|
4801
|
+
} from "react-router";
|
|
4807
4802
|
var import_debug = __toESM(require_browser(), 1);
|
|
4808
4803
|
var debug = (0, import_debug.default)("pack:ab-testing:test-session");
|
|
4809
4804
|
function isSafari2(userAgent) {
|
|
@@ -6072,10 +6067,16 @@ function createPackClient(options) {
|
|
|
6072
6067
|
token,
|
|
6073
6068
|
apiUrl,
|
|
6074
6069
|
defaultThemeData,
|
|
6070
|
+
i18n,
|
|
6075
6071
|
request
|
|
6076
6072
|
} = options;
|
|
6077
6073
|
const previewEnabled = !!session.get("previewEnabled");
|
|
6078
6074
|
const previewEnvironment = session.get("environment");
|
|
6075
|
+
const locale = session.get("locale");
|
|
6076
|
+
const pageDraft = session.get("pageDraft");
|
|
6077
|
+
const siteSettingsDraft = session.get("siteSettingsDraft");
|
|
6078
|
+
const testHandle = session.get("testHandle");
|
|
6079
|
+
const testVariantHandle = session.get("testVariantHandle");
|
|
6079
6080
|
const clientContentEnvironment = previewEnvironment || contentEnvironment;
|
|
6080
6081
|
let packClient;
|
|
6081
6082
|
let testInfoForRequest = void 0;
|
|
@@ -6168,7 +6169,14 @@ function createPackClient(options) {
|
|
|
6168
6169
|
token,
|
|
6169
6170
|
contentEnvironment: clientContentEnvironment,
|
|
6170
6171
|
sessionId: session.id,
|
|
6171
|
-
clientName: "HydrogenClient"
|
|
6172
|
+
clientName: "HydrogenClient",
|
|
6173
|
+
locale,
|
|
6174
|
+
pageDraft,
|
|
6175
|
+
siteSettingsDraft,
|
|
6176
|
+
testHandle,
|
|
6177
|
+
testVariantHandle,
|
|
6178
|
+
// When in preview mode, ignore test status to allow previewing draft tests
|
|
6179
|
+
ignoreTestStatus: previewEnabled
|
|
6172
6180
|
});
|
|
6173
6181
|
return {
|
|
6174
6182
|
get abTest() {
|
|
@@ -6218,6 +6226,10 @@ function createPackClient(options) {
|
|
|
6218
6226
|
} else {
|
|
6219
6227
|
queryVariables.version = "PUBLISHED";
|
|
6220
6228
|
}
|
|
6229
|
+
if (i18n) {
|
|
6230
|
+
queryVariables.language = i18n.language;
|
|
6231
|
+
queryVariables.country = i18n.country;
|
|
6232
|
+
}
|
|
6221
6233
|
if (packClient && token && !testInfoForRequest && currentRequest) {
|
|
6222
6234
|
try {
|
|
6223
6235
|
if (!testInfoPromise) {
|
|
@@ -6359,7 +6371,7 @@ function isLocalPath(request, url) {
|
|
|
6359
6371
|
const urlToCheck = new URL(url, currentUrl.origin);
|
|
6360
6372
|
return currentUrl.origin === urlToCheck.origin;
|
|
6361
6373
|
}
|
|
6362
|
-
|
|
6374
|
+
async function action({ request, context }) {
|
|
6363
6375
|
const { session } = context.pack;
|
|
6364
6376
|
if (!(request.method === "POST" && session)) {
|
|
6365
6377
|
return json({ message: "Method not allowed" }, 405);
|
|
@@ -6369,8 +6381,8 @@ var action = async ({ request, context }) => {
|
|
|
6369
6381
|
const redirectTo = isLocalPath(request, slug) ? slug : ROOT_PATH;
|
|
6370
6382
|
await session.destroy();
|
|
6371
6383
|
return redirect(redirectTo);
|
|
6372
|
-
}
|
|
6373
|
-
|
|
6384
|
+
}
|
|
6385
|
+
async function loader({ request, context }) {
|
|
6374
6386
|
const { pack } = context;
|
|
6375
6387
|
if (!pack.session) return notFound();
|
|
6376
6388
|
const { searchParams } = new URL(request.url);
|
|
@@ -6387,18 +6399,37 @@ var loader = async function({ request, context }) {
|
|
|
6387
6399
|
throw new InvalidTokenError();
|
|
6388
6400
|
}
|
|
6389
6401
|
let customizerMetaJson;
|
|
6402
|
+
let previewContext = null;
|
|
6390
6403
|
try {
|
|
6391
6404
|
customizerMetaJson = customizerMeta ? JSON.parse(customizerMeta) : null;
|
|
6405
|
+
previewContext = customizerMetaJson?.previewContext || null;
|
|
6392
6406
|
} catch (_error) {
|
|
6393
6407
|
customizerMetaJson = null;
|
|
6394
6408
|
}
|
|
6395
6409
|
pack.session.set("previewEnabled", true);
|
|
6396
6410
|
pack.session.set("environment", environment);
|
|
6397
6411
|
pack.session.set("customizerMeta", customizerMetaJson);
|
|
6412
|
+
if (previewContext) {
|
|
6413
|
+
if (previewContext.locale) {
|
|
6414
|
+
pack.session.set("locale", previewContext.locale);
|
|
6415
|
+
}
|
|
6416
|
+
if (previewContext.pageDraft) {
|
|
6417
|
+
pack.session.set("pageDraft", previewContext.pageDraft);
|
|
6418
|
+
}
|
|
6419
|
+
if (previewContext.siteSettingsDraft) {
|
|
6420
|
+
pack.session.set("siteSettingsDraft", previewContext.siteSettingsDraft);
|
|
6421
|
+
}
|
|
6422
|
+
if (previewContext.testHandle) {
|
|
6423
|
+
pack.session.set("testHandle", previewContext.testHandle);
|
|
6424
|
+
}
|
|
6425
|
+
if (previewContext.testVariantHandle) {
|
|
6426
|
+
pack.session.set("testVariantHandle", previewContext.testVariantHandle);
|
|
6427
|
+
}
|
|
6428
|
+
}
|
|
6398
6429
|
return redirect(redirectTo, {
|
|
6399
6430
|
status: 307
|
|
6400
6431
|
});
|
|
6401
|
-
}
|
|
6432
|
+
}
|
|
6402
6433
|
var MissingTokenError = class extends Response {
|
|
6403
6434
|
constructor() {
|
|
6404
6435
|
super("Missing token", { status: 401, statusText: "Unauthorized" });
|
|
@@ -6411,7 +6442,7 @@ var InvalidTokenError = class extends Response {
|
|
|
6411
6442
|
};
|
|
6412
6443
|
|
|
6413
6444
|
// src/tests/pack-test-route.ts
|
|
6414
|
-
import { useLoaderData, useMatches, useRevalidator } from "
|
|
6445
|
+
import { useLoaderData, useMatches, useRevalidator } from "react-router";
|
|
6415
6446
|
|
|
6416
6447
|
// ../../node_modules/js-cookie/dist/js.cookie.mjs
|
|
6417
6448
|
function assign(target) {
|
|
@@ -6630,7 +6661,7 @@ function PackTestProvider({
|
|
|
6630
6661
|
}
|
|
6631
6662
|
|
|
6632
6663
|
// src/tests/hooks.ts
|
|
6633
|
-
import { useRouteLoaderData } from "
|
|
6664
|
+
import { useRouteLoaderData } from "react-router";
|
|
6634
6665
|
function useAbTest() {
|
|
6635
6666
|
const { abTest, packAbTest } = useRouteLoaderData("root");
|
|
6636
6667
|
if (abTest === void 0 && packAbTest === void 0) {
|