@pack/hydrogen 2.1.0-rr7-beta.3 → 2.1.1

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  import { PackClient } from '@pack/client';
2
2
  import { CacheCustom } from '@shopify/hydrogen';
3
- import { SessionStorage, Session, ActionFunctionArgs, LoaderFunctionArgs } from 'react-router';
3
+ import { SessionStorage, Session } from '@shopify/remix-oxygen';
4
+ import { ActionFunction, LoaderFunction } from '@remix-run/server-runtime';
4
5
  import * as react from 'react';
5
6
  import react__default, { Dispatch, SetStateAction, PropsWithChildren } from 'react';
6
7
 
@@ -171,11 +172,11 @@ declare function usePackCookies(options?: UsePackCookiesOptions): void;
171
172
  * A `POST` request to this route will exit preview mode
172
173
  * POST /api/edit Content-Type: application/x-www-form-urlencoded
173
174
  */
174
- declare function action({ request, context }: ActionFunctionArgs): Promise<Response>;
175
+ declare const action: ActionFunction;
175
176
  /**
176
177
  * A `GET` request to this route will enter preview mode
177
178
  */
178
- declare function loader({ request, context }: LoaderFunctionArgs): Promise<Response>;
179
+ declare const loader: LoaderFunction;
179
180
 
180
181
  declare const PackTestRoute: () => null;
181
182
 
package/dist/index.js CHANGED
@@ -1317,75 +1317,99 @@ var require_ua_parser = __commonJS({
1317
1317
  }
1318
1318
  });
1319
1319
 
1320
- // node_modules/cookie/index.js
1320
+ // ../../node_modules/cookie/index.js
1321
1321
  var require_cookie = __commonJS({
1322
- "node_modules/cookie/index.js"(exports) {
1322
+ "../../node_modules/cookie/index.js"(exports) {
1323
1323
  "use strict";
1324
1324
  exports.parse = parse2;
1325
- exports.serialize = serialize3;
1325
+ exports.serialize = serialize2;
1326
1326
  var __toString = Object.prototype.toString;
1327
- var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
1328
- function parse2(str, options) {
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 opt = options || {};
1334
- var dec = opt.decode || decode;
1337
+ var len = str.length;
1338
+ if (len < 2) return obj;
1339
+ var dec = opt && opt.decode || decode;
1335
1340
  var index = 0;
1336
- while (index < str.length) {
1337
- var eqIdx = str.indexOf("=", index);
1338
- if (eqIdx === -1) {
1339
- break;
1340
- }
1341
- var endIdx = str.indexOf(";", index);
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 = str.length;
1344
- } else if (endIdx < eqIdx) {
1348
+ endIdx = len;
1349
+ } else if (eqIdx > endIdx) {
1345
1350
  index = str.lastIndexOf(";", eqIdx - 1) + 1;
1346
1351
  continue;
1347
1352
  }
1348
- var key = str.slice(index, eqIdx).trim();
1349
- if (void 0 === obj[key]) {
1350
- var val = str.slice(eqIdx + 1, endIdx).trim();
1351
- if (val.charCodeAt(0) === 34) {
1352
- val = val.slice(1, -1);
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 serialize3(name, val, options) {
1361
- var opt = options || {};
1362
- var enc = opt.encode || encode;
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 serialize2(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 (!fieldContentRegExp.test(name)) {
1389
+ if (!cookieNameRegExp.test(name)) {
1367
1390
  throw new TypeError("argument name is invalid");
1368
1391
  }
1369
1392
  var value = enc(val);
1370
- if (value && !fieldContentRegExp.test(value)) {
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 - 0;
1376
- if (isNaN(maxAge) || !isFinite(maxAge)) {
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=" + Math.floor(maxAge);
1403
+ str += "; Max-Age=" + maxAge;
1380
1404
  }
1381
1405
  if (opt.domain) {
1382
- if (!fieldContentRegExp.test(opt.domain)) {
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 (!fieldContentRegExp.test(opt.path)) {
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]" || val instanceof 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/hydrogen/oxygen";
4612
+ import { getStorefrontHeaders } from "@shopify/remix-oxygen";
4592
4613
 
4593
4614
  // ../packlytics/dist/utils/get-client-location.js
4594
4615
  function getClientLocation(locale) {
@@ -4662,9 +4683,14 @@ async function handleRequest(pack, request, handleRequest2) {
4662
4683
  }
4663
4684
 
4664
4685
  // src/session/usePackCookies.ts
4665
- var import_cookie = __toESM(require_cookie(), 1);
4666
4686
  import { useEffect } from "react";
4667
4687
 
4688
+ // ../../node_modules/worktop/cookie/index.mjs
4689
+ function l(a, r, e = {}) {
4690
+ let t = a + "=" + encodeURIComponent(r);
4691
+ 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;
4692
+ }
4693
+
4668
4694
  // src/constants.ts
4669
4695
  var PACK_COOKIE_ID = "__pack";
4670
4696
  var PACK_USER_CONSENT_COOKIE_ID = "__pack_user_consent";
@@ -4684,10 +4710,10 @@ function usePackCookies(options) {
4684
4710
  }, [hasUserConsent2]);
4685
4711
  }
4686
4712
  function setCookie(name, value, maxage, domain) {
4687
- document.cookie = (0, import_cookie.serialize)(name, value, {
4688
- maxAge: maxage,
4713
+ document.cookie = l(name, value, {
4714
+ maxage,
4689
4715
  domain,
4690
- sameSite: "lax",
4716
+ samesite: "Lax",
4691
4717
  path: "/"
4692
4718
  });
4693
4719
  }
@@ -4696,7 +4722,7 @@ function setCookie(name, value, maxage, domain) {
4696
4722
  import {
4697
4723
  createCookie,
4698
4724
  createCookieSessionStorage
4699
- } from "react-router";
4725
+ } from "@shopify/remix-oxygen";
4700
4726
 
4701
4727
  // src/session/cookies-utils.tsx
4702
4728
  var import_cookie2 = __toESM(require_cookie(), 1);
@@ -4798,7 +4824,7 @@ var PackSession = class {
4798
4824
  import {
4799
4825
  createCookie as createCookie2,
4800
4826
  createCookieSessionStorage as createCookieSessionStorage2
4801
- } from "react-router";
4827
+ } from "@shopify/remix-oxygen";
4802
4828
  var import_debug = __toESM(require_browser(), 1);
4803
4829
  var debug = (0, import_debug.default)("pack:ab-testing:test-session");
4804
4830
  function isSafari2(userAgent) {
@@ -6371,7 +6397,7 @@ function isLocalPath(request, url) {
6371
6397
  const urlToCheck = new URL(url, currentUrl.origin);
6372
6398
  return currentUrl.origin === urlToCheck.origin;
6373
6399
  }
6374
- async function action({ request, context }) {
6400
+ var action = async ({ request, context }) => {
6375
6401
  const { session } = context.pack;
6376
6402
  if (!(request.method === "POST" && session)) {
6377
6403
  return json({ message: "Method not allowed" }, 405);
@@ -6381,8 +6407,8 @@ async function action({ request, context }) {
6381
6407
  const redirectTo = isLocalPath(request, slug) ? slug : ROOT_PATH;
6382
6408
  await session.destroy();
6383
6409
  return redirect(redirectTo);
6384
- }
6385
- async function loader({ request, context }) {
6410
+ };
6411
+ var loader = async function({ request, context }) {
6386
6412
  const { pack } = context;
6387
6413
  if (!pack.session) return notFound();
6388
6414
  const { searchParams } = new URL(request.url);
@@ -6429,7 +6455,7 @@ async function loader({ request, context }) {
6429
6455
  return redirect(redirectTo, {
6430
6456
  status: 307
6431
6457
  });
6432
- }
6458
+ };
6433
6459
  var MissingTokenError = class extends Response {
6434
6460
  constructor() {
6435
6461
  super("Missing token", { status: 401, statusText: "Unauthorized" });
@@ -6442,7 +6468,7 @@ var InvalidTokenError = class extends Response {
6442
6468
  };
6443
6469
 
6444
6470
  // src/tests/pack-test-route.ts
6445
- import { useLoaderData, useMatches, useRevalidator } from "react-router";
6471
+ import { useLoaderData, useMatches, useRevalidator } from "@remix-run/react";
6446
6472
 
6447
6473
  // ../../node_modules/js-cookie/dist/js.cookie.mjs
6448
6474
  function assign(target) {
@@ -6661,7 +6687,7 @@ function PackTestProvider({
6661
6687
  }
6662
6688
 
6663
6689
  // src/tests/hooks.ts
6664
- import { useRouteLoaderData } from "react-router";
6690
+ import { useRouteLoaderData } from "@remix-run/react";
6665
6691
  function useAbTest() {
6666
6692
  const { abTest, packAbTest } = useRouteLoaderData("root");
6667
6693
  if (abTest === void 0 && packAbTest === void 0) {