@pack/hydrogen 2.1.0 → 3.0.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/dist/index.d.ts +3 -4
- package/dist/index.js +67 -51
- 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
|
|
|
@@ -172,11 +171,11 @@ declare function usePackCookies(options?: UsePackCookiesOptions): void;
|
|
|
172
171
|
* A `POST` request to this route will exit preview mode
|
|
173
172
|
* POST /api/edit Content-Type: application/x-www-form-urlencoded
|
|
174
173
|
*/
|
|
175
|
-
declare
|
|
174
|
+
declare function action({ request, context }: ActionFunctionArgs): Promise<Response>;
|
|
176
175
|
/**
|
|
177
176
|
* A `GET` request to this route will enter preview mode
|
|
178
177
|
*/
|
|
179
|
-
declare
|
|
178
|
+
declare function loader({ request, context }: LoaderFunctionArgs): Promise<Response>;
|
|
180
179
|
|
|
181
180
|
declare const PackTestRoute: () => null;
|
|
182
181
|
|
package/dist/index.js
CHANGED
|
@@ -1322,70 +1322,94 @@ 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
|
-
var
|
|
1328
|
-
|
|
1327
|
+
var __hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1328
|
+
var cookieNameRegExp = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
1329
|
+
var cookieValueRegExp = /^("?)[\u0021\u0023-\u002B\u002D-\u003A\u003C-\u005B\u005D-\u007E]*\1$/;
|
|
1330
|
+
var domainValueRegExp = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
|
|
1331
|
+
var pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
|
|
1332
|
+
function parse2(str, opt) {
|
|
1329
1333
|
if (typeof str !== "string") {
|
|
1330
1334
|
throw new TypeError("argument str must be a string");
|
|
1331
1335
|
}
|
|
1332
1336
|
var obj = {};
|
|
1333
|
-
var
|
|
1334
|
-
|
|
1337
|
+
var len = str.length;
|
|
1338
|
+
if (len < 2) return obj;
|
|
1339
|
+
var dec = opt && opt.decode || decode;
|
|
1335
1340
|
var index = 0;
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1341
|
+
var eqIdx = 0;
|
|
1342
|
+
var endIdx = 0;
|
|
1343
|
+
do {
|
|
1344
|
+
eqIdx = str.indexOf("=", index);
|
|
1345
|
+
if (eqIdx === -1) break;
|
|
1346
|
+
endIdx = str.indexOf(";", index);
|
|
1342
1347
|
if (endIdx === -1) {
|
|
1343
|
-
endIdx =
|
|
1344
|
-
} else if (
|
|
1348
|
+
endIdx = len;
|
|
1349
|
+
} else if (eqIdx > endIdx) {
|
|
1345
1350
|
index = str.lastIndexOf(";", eqIdx - 1) + 1;
|
|
1346
1351
|
continue;
|
|
1347
1352
|
}
|
|
1348
|
-
var
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
+
var keyStartIdx = startIndex(str, index, eqIdx);
|
|
1354
|
+
var keyEndIdx = endIndex(str, eqIdx, keyStartIdx);
|
|
1355
|
+
var key = str.slice(keyStartIdx, keyEndIdx);
|
|
1356
|
+
if (!__hasOwnProperty.call(obj, key)) {
|
|
1357
|
+
var valStartIdx = startIndex(str, eqIdx + 1, endIdx);
|
|
1358
|
+
var valEndIdx = endIndex(str, endIdx, valStartIdx);
|
|
1359
|
+
if (str.charCodeAt(valStartIdx) === 34 && str.charCodeAt(valEndIdx - 1) === 34) {
|
|
1360
|
+
valStartIdx++;
|
|
1361
|
+
valEndIdx--;
|
|
1353
1362
|
}
|
|
1363
|
+
var val = str.slice(valStartIdx, valEndIdx);
|
|
1354
1364
|
obj[key] = tryDecode(val, dec);
|
|
1355
1365
|
}
|
|
1356
1366
|
index = endIdx + 1;
|
|
1357
|
-
}
|
|
1367
|
+
} while (index < len);
|
|
1358
1368
|
return obj;
|
|
1359
1369
|
}
|
|
1360
|
-
function
|
|
1361
|
-
|
|
1362
|
-
|
|
1370
|
+
function startIndex(str, index, max) {
|
|
1371
|
+
do {
|
|
1372
|
+
var code = str.charCodeAt(index);
|
|
1373
|
+
if (code !== 32 && code !== 9) return index;
|
|
1374
|
+
} while (++index < max);
|
|
1375
|
+
return max;
|
|
1376
|
+
}
|
|
1377
|
+
function endIndex(str, index, min) {
|
|
1378
|
+
while (index > min) {
|
|
1379
|
+
var code = str.charCodeAt(--index);
|
|
1380
|
+
if (code !== 32 && code !== 9) return index + 1;
|
|
1381
|
+
}
|
|
1382
|
+
return min;
|
|
1383
|
+
}
|
|
1384
|
+
function serialize3(name, val, opt) {
|
|
1385
|
+
var enc = opt && opt.encode || encodeURIComponent;
|
|
1363
1386
|
if (typeof enc !== "function") {
|
|
1364
1387
|
throw new TypeError("option encode is invalid");
|
|
1365
1388
|
}
|
|
1366
|
-
if (!
|
|
1389
|
+
if (!cookieNameRegExp.test(name)) {
|
|
1367
1390
|
throw new TypeError("argument name is invalid");
|
|
1368
1391
|
}
|
|
1369
1392
|
var value = enc(val);
|
|
1370
|
-
if (
|
|
1393
|
+
if (!cookieValueRegExp.test(value)) {
|
|
1371
1394
|
throw new TypeError("argument val is invalid");
|
|
1372
1395
|
}
|
|
1373
1396
|
var str = name + "=" + value;
|
|
1397
|
+
if (!opt) return str;
|
|
1374
1398
|
if (null != opt.maxAge) {
|
|
1375
|
-
var maxAge = opt.maxAge
|
|
1376
|
-
if (
|
|
1399
|
+
var maxAge = Math.floor(opt.maxAge);
|
|
1400
|
+
if (!isFinite(maxAge)) {
|
|
1377
1401
|
throw new TypeError("option maxAge is invalid");
|
|
1378
1402
|
}
|
|
1379
|
-
str += "; Max-Age=" +
|
|
1403
|
+
str += "; Max-Age=" + maxAge;
|
|
1380
1404
|
}
|
|
1381
1405
|
if (opt.domain) {
|
|
1382
|
-
if (!
|
|
1406
|
+
if (!domainValueRegExp.test(opt.domain)) {
|
|
1383
1407
|
throw new TypeError("option domain is invalid");
|
|
1384
1408
|
}
|
|
1385
1409
|
str += "; Domain=" + opt.domain;
|
|
1386
1410
|
}
|
|
1387
1411
|
if (opt.path) {
|
|
1388
|
-
if (!
|
|
1412
|
+
if (!pathValueRegExp.test(opt.path)) {
|
|
1389
1413
|
throw new TypeError("option path is invalid");
|
|
1390
1414
|
}
|
|
1391
1415
|
str += "; Path=" + opt.path;
|
|
@@ -1446,11 +1470,8 @@ var require_cookie = __commonJS({
|
|
|
1446
1470
|
function decode(str) {
|
|
1447
1471
|
return str.indexOf("%") !== -1 ? decodeURIComponent(str) : str;
|
|
1448
1472
|
}
|
|
1449
|
-
function encode(val) {
|
|
1450
|
-
return encodeURIComponent(val);
|
|
1451
|
-
}
|
|
1452
1473
|
function isDate(val) {
|
|
1453
|
-
return __toString.call(val) === "[object Date]"
|
|
1474
|
+
return __toString.call(val) === "[object Date]";
|
|
1454
1475
|
}
|
|
1455
1476
|
function tryDecode(str, decode2) {
|
|
1456
1477
|
try {
|
|
@@ -4588,7 +4609,7 @@ function getDevice(userAgent) {
|
|
|
4588
4609
|
}
|
|
4589
4610
|
|
|
4590
4611
|
// ../packlytics/dist/packlytics.js
|
|
4591
|
-
import { getStorefrontHeaders } from "@shopify/
|
|
4612
|
+
import { getStorefrontHeaders } from "@shopify/hydrogen/oxygen";
|
|
4592
4613
|
|
|
4593
4614
|
// ../packlytics/dist/utils/get-client-location.js
|
|
4594
4615
|
function getClientLocation(locale) {
|
|
@@ -4662,14 +4683,9 @@ async function handleRequest(pack, request, handleRequest2) {
|
|
|
4662
4683
|
}
|
|
4663
4684
|
|
|
4664
4685
|
// src/session/usePackCookies.ts
|
|
4686
|
+
var import_cookie = __toESM(require_cookie(), 1);
|
|
4665
4687
|
import { useEffect } from "react";
|
|
4666
4688
|
|
|
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
4689
|
// src/constants.ts
|
|
4674
4690
|
var PACK_COOKIE_ID = "__pack";
|
|
4675
4691
|
var PACK_USER_CONSENT_COOKIE_ID = "__pack_user_consent";
|
|
@@ -4689,10 +4705,10 @@ function usePackCookies(options) {
|
|
|
4689
4705
|
}, [hasUserConsent2]);
|
|
4690
4706
|
}
|
|
4691
4707
|
function setCookie(name, value, maxage, domain) {
|
|
4692
|
-
document.cookie =
|
|
4693
|
-
maxage,
|
|
4708
|
+
document.cookie = (0, import_cookie.serialize)(name, value, {
|
|
4709
|
+
maxAge: maxage,
|
|
4694
4710
|
domain,
|
|
4695
|
-
|
|
4711
|
+
sameSite: "lax",
|
|
4696
4712
|
path: "/"
|
|
4697
4713
|
});
|
|
4698
4714
|
}
|
|
@@ -4701,7 +4717,7 @@ function setCookie(name, value, maxage, domain) {
|
|
|
4701
4717
|
import {
|
|
4702
4718
|
createCookie,
|
|
4703
4719
|
createCookieSessionStorage
|
|
4704
|
-
} from "
|
|
4720
|
+
} from "react-router";
|
|
4705
4721
|
|
|
4706
4722
|
// src/session/cookies-utils.tsx
|
|
4707
4723
|
var import_cookie2 = __toESM(require_cookie(), 1);
|
|
@@ -4803,7 +4819,7 @@ var PackSession = class {
|
|
|
4803
4819
|
import {
|
|
4804
4820
|
createCookie as createCookie2,
|
|
4805
4821
|
createCookieSessionStorage as createCookieSessionStorage2
|
|
4806
|
-
} from "
|
|
4822
|
+
} from "react-router";
|
|
4807
4823
|
var import_debug = __toESM(require_browser(), 1);
|
|
4808
4824
|
var debug = (0, import_debug.default)("pack:ab-testing:test-session");
|
|
4809
4825
|
function isSafari2(userAgent) {
|
|
@@ -6376,7 +6392,7 @@ function isLocalPath(request, url) {
|
|
|
6376
6392
|
const urlToCheck = new URL(url, currentUrl.origin);
|
|
6377
6393
|
return currentUrl.origin === urlToCheck.origin;
|
|
6378
6394
|
}
|
|
6379
|
-
|
|
6395
|
+
async function action({ request, context }) {
|
|
6380
6396
|
const { session } = context.pack;
|
|
6381
6397
|
if (!(request.method === "POST" && session)) {
|
|
6382
6398
|
return json({ message: "Method not allowed" }, 405);
|
|
@@ -6386,8 +6402,8 @@ var action = async ({ request, context }) => {
|
|
|
6386
6402
|
const redirectTo = isLocalPath(request, slug) ? slug : ROOT_PATH;
|
|
6387
6403
|
await session.destroy();
|
|
6388
6404
|
return redirect(redirectTo);
|
|
6389
|
-
}
|
|
6390
|
-
|
|
6405
|
+
}
|
|
6406
|
+
async function loader({ request, context }) {
|
|
6391
6407
|
const { pack } = context;
|
|
6392
6408
|
if (!pack.session) return notFound();
|
|
6393
6409
|
const { searchParams } = new URL(request.url);
|
|
@@ -6434,7 +6450,7 @@ var loader = async function({ request, context }) {
|
|
|
6434
6450
|
return redirect(redirectTo, {
|
|
6435
6451
|
status: 307
|
|
6436
6452
|
});
|
|
6437
|
-
}
|
|
6453
|
+
}
|
|
6438
6454
|
var MissingTokenError = class extends Response {
|
|
6439
6455
|
constructor() {
|
|
6440
6456
|
super("Missing token", { status: 401, statusText: "Unauthorized" });
|
|
@@ -6447,7 +6463,7 @@ var InvalidTokenError = class extends Response {
|
|
|
6447
6463
|
};
|
|
6448
6464
|
|
|
6449
6465
|
// src/tests/pack-test-route.ts
|
|
6450
|
-
import { useLoaderData, useMatches, useRevalidator } from "
|
|
6466
|
+
import { useLoaderData, useMatches, useRevalidator } from "react-router";
|
|
6451
6467
|
|
|
6452
6468
|
// ../../node_modules/js-cookie/dist/js.cookie.mjs
|
|
6453
6469
|
function assign(target) {
|
|
@@ -6666,7 +6682,7 @@ function PackTestProvider({
|
|
|
6666
6682
|
}
|
|
6667
6683
|
|
|
6668
6684
|
// src/tests/hooks.ts
|
|
6669
|
-
import { useRouteLoaderData } from "
|
|
6685
|
+
import { useRouteLoaderData } from "react-router";
|
|
6670
6686
|
function useAbTest() {
|
|
6671
6687
|
const { abTest, packAbTest } = useRouteLoaderData("root");
|
|
6672
6688
|
if (abTest === void 0 && packAbTest === void 0) {
|