@cmssy/core 19.38.0 → 19.39.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/{csp-C-aqRQ1T.d.ts → csp-9c8JYkS0.d.ts} +18 -1
- package/dist/{csp-CyEN5oH8.d.cts → csp-NaRDpreT.d.cts} +18 -1
- package/dist/index.cjs +91 -75
- package/dist/index.d.cts +3 -16
- package/dist/index.d.ts +3 -16
- package/dist/index.js +89 -76
- package/dist/internal/locale.cjs +1 -1
- package/dist/internal/locale.js +1 -1
- package/dist/internal.cjs +75 -1
- package/dist/internal.d.cts +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +75 -2
- package/dist/preflight.cjs +88 -1
- package/dist/preflight.js +88 -1
- package/dist/testing.cjs +55 -1
- package/dist/testing.js +55 -1
- package/package.json +1 -1
|
@@ -257,6 +257,23 @@ declare function postToEditor(target: PostTarget, editorOrigin: string, message:
|
|
|
257
257
|
declare function resolveInitialTarget(editorOrigin: string | string[]): string;
|
|
258
258
|
declare function parseEditorMessage(data: unknown, origin: string, expectedOrigin: string | string[]): EditorToAppMessage | null;
|
|
259
259
|
|
|
260
|
+
declare const CMSSY_EDIT_HEADER = "x-cmssy-edit";
|
|
261
|
+
declare const CMSSY_EDIT_QUERY_PARAM = "cmssyEdit";
|
|
262
|
+
declare const CMSSY_SECRET_QUERY_PARAM = "cmssySecret";
|
|
263
|
+
declare const CMSSY_EDIT_URL_TOKEN_PAGE = "cmssy:edit-url";
|
|
264
|
+
declare const CMSSY_EDIT_TOKEN_CAPABILITY = "edit-token";
|
|
265
|
+
declare const CMSSY_DRAFT_TOKEN_CAPABILITY = "draft-token";
|
|
266
|
+
interface EditSearchParams {
|
|
267
|
+
getAll: (name: string) => string[];
|
|
268
|
+
get: (name: string) => string | null;
|
|
269
|
+
}
|
|
270
|
+
declare function cmssyEditCredentialMatches(provided: string, draftSecret: string): Promise<boolean>;
|
|
271
|
+
declare function isVerifiedEditUrl(url: {
|
|
272
|
+
searchParams: EditSearchParams;
|
|
273
|
+
}, config: {
|
|
274
|
+
draftSecret: string;
|
|
275
|
+
}): Promise<boolean>;
|
|
276
|
+
|
|
260
277
|
interface CmssyCspOptions {
|
|
261
278
|
editorOrigin?: string | string[];
|
|
262
279
|
}
|
|
@@ -271,4 +288,4 @@ declare function toCspOrigin(origin: string): string;
|
|
|
271
288
|
declare function cmssyCspHeaders(options: CmssyCspOptions): Record<string, string>;
|
|
272
289
|
declare function applyCmssyCsp<T extends MutableHeaders>(response: T, options: CmssyCspOptions): T;
|
|
273
290
|
|
|
274
|
-
export { type AppToEditorMessage as A, type BoundsMessage as B, type CmssyRecordSort as C, DEFAULT_CMSSY_EDITOR_ORIGINS as D, type EditorToAppMessage as E, FORM_QUERY as F, type
|
|
291
|
+
export { isVerifiedEditUrl as $, type AppToEditorMessage as A, type BoundsMessage as B, type CmssyRecordSort as C, DEFAULT_CMSSY_EDITOR_ORIGINS as D, type EditorToAppMessage as E, FORM_QUERY as F, type ParentReadyMessage as G, type PatchMessage as H, type InvisibleBlock as I, type PostTarget as J, SHORTCUT_ACTIONS as K, type ScopedVariables as L, MODEL_DEFINITIONS_QUERY as M, type SelectMessage as N, type ShortcutAction as O, PROTOCOL_VERSION as P, type QueryScopedOptions as Q, type ReadyMessage as R, SITE_CONFIG_QUERY as S, type ShortcutMessage as T, type ViewportMessage as U, type VariablesParameter as V, applyCmssyCsp as W, createCmssyClient as X, defineCmssyConfig as Y, defineCmssyLayout as Z, isProtocolCompatible as _, MODEL_RECORDS_QUERY as a, normalizeOrigin as a0, parseEditorMessage as a1, postToEditor as a2, resolveEditorOrigin as a3, SUBMIT_FORM_MUTATION as b, cmssyCspHeaders as c, cmssyEditCredentialMatches as d, CMSSY_DRAFT_TOKEN_CAPABILITY as e, CMSSY_EDIT_HEADER as f, CMSSY_EDIT_QUERY_PARAM as g, CMSSY_EDIT_TOKEN_CAPABILITY as h, isDevelopment as i, CMSSY_EDIT_URL_TOKEN_PAGE as j, CMSSY_SECRET_QUERY_PARAM as k, layoutRegionIds as l, type ClickMessage as m, type CmssyClient as n, type CmssyConfig as o, type CmssyCspOptions as p, type CmssyEnvConfig as q, resolveInitialTarget as r, type CmssyLayout as s, toCspOrigin as t, type CmssyRegion as u, type CmssyRegionOf as v, type CmssyRegionSettings as w, type CmssyRegionSettingsOf as x, type InvisibleBlocksMessage as y, type InvisibleReason as z };
|
|
@@ -257,6 +257,23 @@ declare function postToEditor(target: PostTarget, editorOrigin: string, message:
|
|
|
257
257
|
declare function resolveInitialTarget(editorOrigin: string | string[]): string;
|
|
258
258
|
declare function parseEditorMessage(data: unknown, origin: string, expectedOrigin: string | string[]): EditorToAppMessage | null;
|
|
259
259
|
|
|
260
|
+
declare const CMSSY_EDIT_HEADER = "x-cmssy-edit";
|
|
261
|
+
declare const CMSSY_EDIT_QUERY_PARAM = "cmssyEdit";
|
|
262
|
+
declare const CMSSY_SECRET_QUERY_PARAM = "cmssySecret";
|
|
263
|
+
declare const CMSSY_EDIT_URL_TOKEN_PAGE = "cmssy:edit-url";
|
|
264
|
+
declare const CMSSY_EDIT_TOKEN_CAPABILITY = "edit-token";
|
|
265
|
+
declare const CMSSY_DRAFT_TOKEN_CAPABILITY = "draft-token";
|
|
266
|
+
interface EditSearchParams {
|
|
267
|
+
getAll: (name: string) => string[];
|
|
268
|
+
get: (name: string) => string | null;
|
|
269
|
+
}
|
|
270
|
+
declare function cmssyEditCredentialMatches(provided: string, draftSecret: string): Promise<boolean>;
|
|
271
|
+
declare function isVerifiedEditUrl(url: {
|
|
272
|
+
searchParams: EditSearchParams;
|
|
273
|
+
}, config: {
|
|
274
|
+
draftSecret: string;
|
|
275
|
+
}): Promise<boolean>;
|
|
276
|
+
|
|
260
277
|
interface CmssyCspOptions {
|
|
261
278
|
editorOrigin?: string | string[];
|
|
262
279
|
}
|
|
@@ -271,4 +288,4 @@ declare function toCspOrigin(origin: string): string;
|
|
|
271
288
|
declare function cmssyCspHeaders(options: CmssyCspOptions): Record<string, string>;
|
|
272
289
|
declare function applyCmssyCsp<T extends MutableHeaders>(response: T, options: CmssyCspOptions): T;
|
|
273
290
|
|
|
274
|
-
export { type AppToEditorMessage as A, type BoundsMessage as B, type CmssyRecordSort as C, DEFAULT_CMSSY_EDITOR_ORIGINS as D, type EditorToAppMessage as E, FORM_QUERY as F, type
|
|
291
|
+
export { isVerifiedEditUrl as $, type AppToEditorMessage as A, type BoundsMessage as B, type CmssyRecordSort as C, DEFAULT_CMSSY_EDITOR_ORIGINS as D, type EditorToAppMessage as E, FORM_QUERY as F, type ParentReadyMessage as G, type PatchMessage as H, type InvisibleBlock as I, type PostTarget as J, SHORTCUT_ACTIONS as K, type ScopedVariables as L, MODEL_DEFINITIONS_QUERY as M, type SelectMessage as N, type ShortcutAction as O, PROTOCOL_VERSION as P, type QueryScopedOptions as Q, type ReadyMessage as R, SITE_CONFIG_QUERY as S, type ShortcutMessage as T, type ViewportMessage as U, type VariablesParameter as V, applyCmssyCsp as W, createCmssyClient as X, defineCmssyConfig as Y, defineCmssyLayout as Z, isProtocolCompatible as _, MODEL_RECORDS_QUERY as a, normalizeOrigin as a0, parseEditorMessage as a1, postToEditor as a2, resolveEditorOrigin as a3, SUBMIT_FORM_MUTATION as b, cmssyCspHeaders as c, cmssyEditCredentialMatches as d, CMSSY_DRAFT_TOKEN_CAPABILITY as e, CMSSY_EDIT_HEADER as f, CMSSY_EDIT_QUERY_PARAM as g, CMSSY_EDIT_TOKEN_CAPABILITY as h, isDevelopment as i, CMSSY_EDIT_URL_TOKEN_PAGE as j, CMSSY_SECRET_QUERY_PARAM as k, layoutRegionIds as l, type ClickMessage as m, type CmssyClient as n, type CmssyConfig as o, type CmssyCspOptions as p, type CmssyEnvConfig as q, resolveInitialTarget as r, type CmssyLayout as s, toCspOrigin as t, type CmssyRegion as u, type CmssyRegionOf as v, type CmssyRegionSettings as w, type CmssyRegionSettingsOf as x, type InvisibleBlocksMessage as y, type InvisibleReason as z };
|
package/dist/index.cjs
CHANGED
|
@@ -225,7 +225,7 @@ function documentText(document2) {
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
// src/version.ts
|
|
228
|
-
var CMSSY_CORE_VERSION = "19.
|
|
228
|
+
var CMSSY_CORE_VERSION = "19.39.0" ;
|
|
229
229
|
var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
|
|
230
230
|
|
|
231
231
|
// src/data/http.ts
|
|
@@ -1574,80 +1574,6 @@ function parseEditorMessage(data, origin, expectedOrigin) {
|
|
|
1574
1574
|
}
|
|
1575
1575
|
}
|
|
1576
1576
|
|
|
1577
|
-
// src/secret-match.ts
|
|
1578
|
-
var MAX_SECRET_LENGTH = 256;
|
|
1579
|
-
async function cmssySecretsMatch(a, b) {
|
|
1580
|
-
if (a.length > MAX_SECRET_LENGTH || b.length > MAX_SECRET_LENGTH) {
|
|
1581
|
-
return false;
|
|
1582
|
-
}
|
|
1583
|
-
const encoder = new TextEncoder();
|
|
1584
|
-
const [ha, hb] = await Promise.all([
|
|
1585
|
-
crypto.subtle.digest("SHA-256", encoder.encode(a)),
|
|
1586
|
-
crypto.subtle.digest("SHA-256", encoder.encode(b))
|
|
1587
|
-
]);
|
|
1588
|
-
const va = new Uint8Array(ha);
|
|
1589
|
-
const vb = new Uint8Array(hb);
|
|
1590
|
-
let diff = 0;
|
|
1591
|
-
for (let i = 0; i < va.length; i += 1) {
|
|
1592
|
-
diff |= (va[i] ?? 0) ^ (vb[i] ?? 0);
|
|
1593
|
-
}
|
|
1594
|
-
return diff === 0;
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
// src/edit-request.ts
|
|
1598
|
-
var CMSSY_EDIT_HEADER = "x-cmssy-edit";
|
|
1599
|
-
var CMSSY_EDIT_QUERY_PARAM = "cmssyEdit";
|
|
1600
|
-
var CMSSY_SECRET_QUERY_PARAM = "cmssySecret";
|
|
1601
|
-
async function isVerifiedEditUrl(url, config) {
|
|
1602
|
-
if (!url.searchParams.getAll(CMSSY_EDIT_QUERY_PARAM).includes("1")) {
|
|
1603
|
-
return false;
|
|
1604
|
-
}
|
|
1605
|
-
const provided = url.searchParams.get(CMSSY_SECRET_QUERY_PARAM);
|
|
1606
|
-
if (!provided || !config.draftSecret) return false;
|
|
1607
|
-
return cmssySecretsMatch(provided, config.draftSecret);
|
|
1608
|
-
}
|
|
1609
|
-
|
|
1610
|
-
// src/csp.ts
|
|
1611
|
-
function toCspOrigin(origin) {
|
|
1612
|
-
if (origin === "*") return "*";
|
|
1613
|
-
let parsed;
|
|
1614
|
-
try {
|
|
1615
|
-
parsed = new URL(origin);
|
|
1616
|
-
} catch {
|
|
1617
|
-
throw new Error(`cmssy: invalid editorOrigin "${origin}"`);
|
|
1618
|
-
}
|
|
1619
|
-
if (parsed.origin === "null") {
|
|
1620
|
-
throw new Error(`cmssy: editorOrigin "${origin}" has no usable origin`);
|
|
1621
|
-
}
|
|
1622
|
-
return parsed.origin;
|
|
1623
|
-
}
|
|
1624
|
-
function frameAncestors(editorOrigin) {
|
|
1625
|
-
const resolved = resolveEditorOrigin(editorOrigin);
|
|
1626
|
-
const origins = Array.isArray(resolved) ? resolved : [resolved];
|
|
1627
|
-
if (origins.length === 0) {
|
|
1628
|
-
throw new Error(
|
|
1629
|
-
"cmssy: editorOrigin must contain at least one valid origin"
|
|
1630
|
-
);
|
|
1631
|
-
}
|
|
1632
|
-
const normalized = origins.map((origin) => toCspOrigin(origin.trim()));
|
|
1633
|
-
return `frame-ancestors ${normalized.join(" ")}`;
|
|
1634
|
-
}
|
|
1635
|
-
function mergeFrameAncestors(existing, directive) {
|
|
1636
|
-
if (!existing) return directive;
|
|
1637
|
-
const kept = existing.split(";").map((part) => part.trim()).filter((part) => part.length > 0 && !/^frame-ancestors\b/i.test(part));
|
|
1638
|
-
kept.push(directive);
|
|
1639
|
-
return kept.join("; ");
|
|
1640
|
-
}
|
|
1641
|
-
function applyCmssyCsp(response, options) {
|
|
1642
|
-
const merged = mergeFrameAncestors(
|
|
1643
|
-
response.headers.get("Content-Security-Policy"),
|
|
1644
|
-
frameAncestors(options.editorOrigin)
|
|
1645
|
-
);
|
|
1646
|
-
response.headers.set("Content-Security-Policy", merged);
|
|
1647
|
-
response.headers.delete("X-Frame-Options");
|
|
1648
|
-
return response;
|
|
1649
|
-
}
|
|
1650
|
-
|
|
1651
1577
|
// src/internal/hmac.ts
|
|
1652
1578
|
function hexToBytes(hex) {
|
|
1653
1579
|
if (hex.length % 2 !== 0 || /[^0-9a-fA-F]/.test(hex)) return null;
|
|
@@ -1725,6 +1651,93 @@ async function verifyCmssyEditToken(token, secret, options = {}) {
|
|
|
1725
1651
|
return timingSafeHexEqual(expected, provided);
|
|
1726
1652
|
}
|
|
1727
1653
|
|
|
1654
|
+
// src/secret-match.ts
|
|
1655
|
+
var MAX_SECRET_LENGTH = 256;
|
|
1656
|
+
async function cmssySecretsMatch(a, b) {
|
|
1657
|
+
if (a.length > MAX_SECRET_LENGTH || b.length > MAX_SECRET_LENGTH) {
|
|
1658
|
+
return false;
|
|
1659
|
+
}
|
|
1660
|
+
const encoder = new TextEncoder();
|
|
1661
|
+
const [ha, hb] = await Promise.all([
|
|
1662
|
+
crypto.subtle.digest("SHA-256", encoder.encode(a)),
|
|
1663
|
+
crypto.subtle.digest("SHA-256", encoder.encode(b))
|
|
1664
|
+
]);
|
|
1665
|
+
const va = new Uint8Array(ha);
|
|
1666
|
+
const vb = new Uint8Array(hb);
|
|
1667
|
+
let diff = 0;
|
|
1668
|
+
for (let i = 0; i < va.length; i += 1) {
|
|
1669
|
+
diff |= (va[i] ?? 0) ^ (vb[i] ?? 0);
|
|
1670
|
+
}
|
|
1671
|
+
return diff === 0;
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
// src/edit-request.ts
|
|
1675
|
+
var CMSSY_EDIT_HEADER = "x-cmssy-edit";
|
|
1676
|
+
var CMSSY_EDIT_QUERY_PARAM = "cmssyEdit";
|
|
1677
|
+
var CMSSY_SECRET_QUERY_PARAM = "cmssySecret";
|
|
1678
|
+
var CMSSY_EDIT_URL_TOKEN_PAGE = "cmssy:edit-url";
|
|
1679
|
+
var CMSSY_EDIT_TOKEN_CAPABILITY = "edit-token";
|
|
1680
|
+
var CMSSY_DRAFT_TOKEN_CAPABILITY = "draft-token";
|
|
1681
|
+
var MAX_EDIT_URL_TOKEN_LIFETIME_MS = 24 * 60 * 60 * 1e3;
|
|
1682
|
+
async function cmssyEditCredentialMatches(provided, draftSecret) {
|
|
1683
|
+
if (!provided || !draftSecret) return false;
|
|
1684
|
+
if (await cmssySecretsMatch(provided, draftSecret)) return true;
|
|
1685
|
+
const expiresAt = Number(provided.slice(0, provided.indexOf(".")));
|
|
1686
|
+
if (expiresAt - Date.now() > MAX_EDIT_URL_TOKEN_LIFETIME_MS) return false;
|
|
1687
|
+
return verifyCmssyEditToken(provided, draftSecret, {
|
|
1688
|
+
page: CMSSY_EDIT_URL_TOKEN_PAGE
|
|
1689
|
+
});
|
|
1690
|
+
}
|
|
1691
|
+
async function isVerifiedEditUrl(url, config) {
|
|
1692
|
+
if (!url.searchParams.getAll(CMSSY_EDIT_QUERY_PARAM).includes("1")) {
|
|
1693
|
+
return false;
|
|
1694
|
+
}
|
|
1695
|
+
const provided = url.searchParams.get(CMSSY_SECRET_QUERY_PARAM);
|
|
1696
|
+
if (!provided || !config.draftSecret) return false;
|
|
1697
|
+
return cmssyEditCredentialMatches(provided, config.draftSecret);
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
// src/csp.ts
|
|
1701
|
+
function toCspOrigin(origin) {
|
|
1702
|
+
if (origin === "*") return "*";
|
|
1703
|
+
let parsed;
|
|
1704
|
+
try {
|
|
1705
|
+
parsed = new URL(origin);
|
|
1706
|
+
} catch {
|
|
1707
|
+
throw new Error(`cmssy: invalid editorOrigin "${origin}"`);
|
|
1708
|
+
}
|
|
1709
|
+
if (parsed.origin === "null") {
|
|
1710
|
+
throw new Error(`cmssy: editorOrigin "${origin}" has no usable origin`);
|
|
1711
|
+
}
|
|
1712
|
+
return parsed.origin;
|
|
1713
|
+
}
|
|
1714
|
+
function frameAncestors(editorOrigin) {
|
|
1715
|
+
const resolved = resolveEditorOrigin(editorOrigin);
|
|
1716
|
+
const origins = Array.isArray(resolved) ? resolved : [resolved];
|
|
1717
|
+
if (origins.length === 0) {
|
|
1718
|
+
throw new Error(
|
|
1719
|
+
"cmssy: editorOrigin must contain at least one valid origin"
|
|
1720
|
+
);
|
|
1721
|
+
}
|
|
1722
|
+
const normalized = origins.map((origin) => toCspOrigin(origin.trim()));
|
|
1723
|
+
return `frame-ancestors ${normalized.join(" ")}`;
|
|
1724
|
+
}
|
|
1725
|
+
function mergeFrameAncestors(existing, directive) {
|
|
1726
|
+
if (!existing) return directive;
|
|
1727
|
+
const kept = existing.split(";").map((part) => part.trim()).filter((part) => part.length > 0 && !/^frame-ancestors\b/i.test(part));
|
|
1728
|
+
kept.push(directive);
|
|
1729
|
+
return kept.join("; ");
|
|
1730
|
+
}
|
|
1731
|
+
function applyCmssyCsp(response, options) {
|
|
1732
|
+
const merged = mergeFrameAncestors(
|
|
1733
|
+
response.headers.get("Content-Security-Policy"),
|
|
1734
|
+
frameAncestors(options.editorOrigin)
|
|
1735
|
+
);
|
|
1736
|
+
response.headers.set("Content-Security-Policy", merged);
|
|
1737
|
+
response.headers.delete("X-Frame-Options");
|
|
1738
|
+
return response;
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1728
1741
|
// src/order-progress.ts
|
|
1729
1742
|
var orderProgressValues = [
|
|
1730
1743
|
"placed",
|
|
@@ -1854,9 +1867,12 @@ Object.defineProperty(exports, "taxTreatmentKindValues", {
|
|
|
1854
1867
|
exports.BUYER_CATALOG_PRICES_QUERY = BUYER_CATALOG_PRICES_QUERY;
|
|
1855
1868
|
exports.BUYER_PRICES_QUERY = BUYER_PRICES_QUERY;
|
|
1856
1869
|
exports.CMSSY_BUYER_PRICES_MAX_ITEMS = CMSSY_BUYER_PRICES_MAX_ITEMS;
|
|
1870
|
+
exports.CMSSY_DRAFT_TOKEN_CAPABILITY = CMSSY_DRAFT_TOKEN_CAPABILITY;
|
|
1857
1871
|
exports.CMSSY_EDIT_HEADER = CMSSY_EDIT_HEADER;
|
|
1858
1872
|
exports.CMSSY_EDIT_QUERY_PARAM = CMSSY_EDIT_QUERY_PARAM;
|
|
1873
|
+
exports.CMSSY_EDIT_TOKEN_CAPABILITY = CMSSY_EDIT_TOKEN_CAPABILITY;
|
|
1859
1874
|
exports.CMSSY_EDIT_TOKEN_HEADER = CMSSY_EDIT_TOKEN_HEADER;
|
|
1875
|
+
exports.CMSSY_EDIT_URL_TOKEN_PAGE = CMSSY_EDIT_URL_TOKEN_PAGE;
|
|
1860
1876
|
exports.CMSSY_LOCALE_HEADER = CMSSY_LOCALE_HEADER;
|
|
1861
1877
|
exports.CMSSY_PUBLIC_PRICES_MAX_ITEMS = CMSSY_PUBLIC_PRICES_MAX_ITEMS;
|
|
1862
1878
|
exports.CMSSY_RATE_LIMIT_WINDOW_MS = CMSSY_RATE_LIMIT_WINDOW_MS;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CmssyRecordSort } from './csp-
|
|
2
|
-
export { A as AppToEditorMessage, B as BoundsMessage,
|
|
1
|
+
import { C as CmssyRecordSort } from './csp-NaRDpreT.cjs';
|
|
2
|
+
export { A as AppToEditorMessage, B as BoundsMessage, e as CMSSY_DRAFT_TOKEN_CAPABILITY, f as CMSSY_EDIT_HEADER, g as CMSSY_EDIT_QUERY_PARAM, h as CMSSY_EDIT_TOKEN_CAPABILITY, j as CMSSY_EDIT_URL_TOKEN_PAGE, k as CMSSY_SECRET_QUERY_PARAM, m as ClickMessage, n as CmssyClient, o as CmssyConfig, p as CmssyCspOptions, q as CmssyEnvConfig, s as CmssyLayout, u as CmssyRegion, v as CmssyRegionOf, w as CmssyRegionSettings, x as CmssyRegionSettingsOf, D as DEFAULT_CMSSY_EDITOR_ORIGINS, E as EditorToAppMessage, I as InvisibleBlock, y as InvisibleBlocksMessage, z as InvisibleReason, P as PROTOCOL_VERSION, G as ParentReadyMessage, H as PatchMessage, J as PostTarget, Q as QueryScopedOptions, R as ReadyMessage, K as SHORTCUT_ACTIONS, L as ScopedVariables, N as SelectMessage, O as ShortcutAction, T as ShortcutMessage, V as VariablesParameter, U as ViewportMessage, W as applyCmssyCsp, X as createCmssyClient, Y as defineCmssyConfig, Z as defineCmssyLayout, _ as isProtocolCompatible, $ as isVerifiedEditUrl, a0 as normalizeOrigin, a1 as parseEditorMessage, a2 as postToEditor, a3 as resolveEditorOrigin } from './csp-NaRDpreT.cjs';
|
|
3
3
|
import { a as CmssyOperation, G as GraphqlRequestOptions } from './locale-DgWB2_Zb.cjs';
|
|
4
4
|
export { b as CMSSY_LOCALE_HEADER, C as CmssyOperationInput, f as CmssyTypedDocument, g as graphqlRequest, d as localizeHref, h as resolveCmssyLocale, t as typedOperation } from './locale-DgWB2_Zb.cjs';
|
|
5
5
|
import { F as FetchLike, R as RetryOption, C as CmssyClientConfig } from './content-client-nqEVPiBe.cjs';
|
|
@@ -392,19 +392,6 @@ declare function isFormFieldVisible(field: Pick<ConditionalFormField, "showWhen"
|
|
|
392
392
|
declare function visibleFormFields<F extends Pick<ConditionalFormField, "showWhen">>(fields: readonly F[], values: Record<string, unknown>): F[];
|
|
393
393
|
declare function isFormFieldRequired(field: ConditionalFormField, values: Record<string, unknown>): boolean;
|
|
394
394
|
|
|
395
|
-
declare const CMSSY_EDIT_HEADER = "x-cmssy-edit";
|
|
396
|
-
declare const CMSSY_EDIT_QUERY_PARAM = "cmssyEdit";
|
|
397
|
-
declare const CMSSY_SECRET_QUERY_PARAM = "cmssySecret";
|
|
398
|
-
interface EditSearchParams {
|
|
399
|
-
getAll: (name: string) => string[];
|
|
400
|
-
get: (name: string) => string | null;
|
|
401
|
-
}
|
|
402
|
-
declare function isVerifiedEditUrl(url: {
|
|
403
|
-
searchParams: EditSearchParams;
|
|
404
|
-
}, config: {
|
|
405
|
-
draftSecret: string;
|
|
406
|
-
}): Promise<boolean>;
|
|
407
|
-
|
|
408
395
|
declare const CMSSY_EDIT_TOKEN_HEADER = "x-cmssy-edit-token";
|
|
409
396
|
interface MintCmssyEditTokenOptions {
|
|
410
397
|
page?: string;
|
|
@@ -436,4 +423,4 @@ declare class CmssyWebhookError extends Error {
|
|
|
436
423
|
}
|
|
437
424
|
declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): Promise<CmssyWebhookEvent>;
|
|
438
425
|
|
|
439
|
-
export { BUYER_CATALOG_PRICES_QUERY, BUYER_PRICES_QUERY, type BlockManifest, type BlockManifestBlock, type BlockManifestSource, type BuyerCatalogPricesResult, type BuyerCatalogPricesVariables, type BuyerPricesResult, type BuyerPricesVariables, CMSSY_BUYER_PRICES_MAX_ITEMS,
|
|
426
|
+
export { BUYER_CATALOG_PRICES_QUERY, BUYER_PRICES_QUERY, type BlockManifest, type BlockManifestBlock, type BlockManifestSource, type BuyerCatalogPricesResult, type BuyerCatalogPricesVariables, type BuyerPricesResult, type BuyerPricesVariables, CMSSY_BUYER_PRICES_MAX_ITEMS, CMSSY_EDIT_TOKEN_HEADER, CMSSY_PUBLIC_PRICES_MAX_ITEMS, type CmssyBuyerCatalogPage, type CmssyBuyerCatalogPrice, type CmssyBuyerCatalogSort, type CmssyBuyerPrice, type CmssyChannelRefusal, type CmssyChannelRefusalReason, type CmssyCheckoutErrorReason, CmssyClientConfig, type CmssyMaintenance, type CmssyMaintenanceRefusal, type CmssyMemberPriceList, CmssyOperation, type CmssyOrderProgress, type CmssyOrderProgressInput, type CmssyPriceDisplayMode, type CmssyPriceListSource, type CmssyPriceQueryItem, type CmssyPriceTier, type CmssyPriceWithheldReason, type CmssyPublicCatalogPage, type CmssyPublicPriceResult, type CmssyPublicPricedRecord, type CmssyPublicPricedRecordData, type CmssyQuantityRuleReason, type CmssyQuantityRuleViolation, CmssyRecordSort, type CmssyTaxTreatment, type CmssyTaxedAmount, CmssyWebhookError, type ConditionalFormField, FetchLike, type GetBuyerCatalogPricesQuery, type GetBuyerPricesOptions, type GetPublicCatalogPricesQuery, type GetPublicPricesOptions, GraphqlRequestOptions, MAINTENANCE_QUERY, type MediaLike, type MintCmssyEditTokenOptions, PUBLIC_CATALOG_PRICES_QUERY, PUBLIC_PRICES_QUERY, type PublicCatalogPricesResult, type PublicCatalogPricesVariables, type PublicPricesResult, type PublicPricesVariables, RetryOption, type VerifyCmssyEditTokenOptions, blocksToMeta, blocksToSchemas, buildBlockManifest, channelRefusal, channelRefusalReasonValues, checkoutErrorItemId, checkoutErrorReason, checkoutErrorReasonValues, fields, getBuyerCatalogPrices, getBuyerPrices, getMaintenance, getPublicCatalogPrices, getPublicPrices, isFormFieldRequired, isFormFieldVisible, layoutRegionsToBridge, maintenanceRefusal, mediaAlt, mediaDuration, mediaType, mediaUrl, mediaUrls, mintCmssyEditToken, orderProgress, orderProgressValues, priceDisplayModeValues, priceListSourceValues, priceWithheldReasonValues, propsToSchema, quantityRuleReasonValues, quantityRuleViolation, registryToManifestBlocks, verifyCmssyEditToken, verifyCmssyWebhook, visibleFormFields };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CmssyRecordSort } from './csp-
|
|
2
|
-
export { A as AppToEditorMessage, B as BoundsMessage,
|
|
1
|
+
import { C as CmssyRecordSort } from './csp-9c8JYkS0.js';
|
|
2
|
+
export { A as AppToEditorMessage, B as BoundsMessage, e as CMSSY_DRAFT_TOKEN_CAPABILITY, f as CMSSY_EDIT_HEADER, g as CMSSY_EDIT_QUERY_PARAM, h as CMSSY_EDIT_TOKEN_CAPABILITY, j as CMSSY_EDIT_URL_TOKEN_PAGE, k as CMSSY_SECRET_QUERY_PARAM, m as ClickMessage, n as CmssyClient, o as CmssyConfig, p as CmssyCspOptions, q as CmssyEnvConfig, s as CmssyLayout, u as CmssyRegion, v as CmssyRegionOf, w as CmssyRegionSettings, x as CmssyRegionSettingsOf, D as DEFAULT_CMSSY_EDITOR_ORIGINS, E as EditorToAppMessage, I as InvisibleBlock, y as InvisibleBlocksMessage, z as InvisibleReason, P as PROTOCOL_VERSION, G as ParentReadyMessage, H as PatchMessage, J as PostTarget, Q as QueryScopedOptions, R as ReadyMessage, K as SHORTCUT_ACTIONS, L as ScopedVariables, N as SelectMessage, O as ShortcutAction, T as ShortcutMessage, V as VariablesParameter, U as ViewportMessage, W as applyCmssyCsp, X as createCmssyClient, Y as defineCmssyConfig, Z as defineCmssyLayout, _ as isProtocolCompatible, $ as isVerifiedEditUrl, a0 as normalizeOrigin, a1 as parseEditorMessage, a2 as postToEditor, a3 as resolveEditorOrigin } from './csp-9c8JYkS0.js';
|
|
3
3
|
import { a as CmssyOperation, G as GraphqlRequestOptions } from './locale-Br9RRVb_.js';
|
|
4
4
|
export { b as CMSSY_LOCALE_HEADER, C as CmssyOperationInput, f as CmssyTypedDocument, g as graphqlRequest, d as localizeHref, h as resolveCmssyLocale, t as typedOperation } from './locale-Br9RRVb_.js';
|
|
5
5
|
import { F as FetchLike, R as RetryOption, C as CmssyClientConfig } from './content-client-nqEVPiBe.js';
|
|
@@ -392,19 +392,6 @@ declare function isFormFieldVisible(field: Pick<ConditionalFormField, "showWhen"
|
|
|
392
392
|
declare function visibleFormFields<F extends Pick<ConditionalFormField, "showWhen">>(fields: readonly F[], values: Record<string, unknown>): F[];
|
|
393
393
|
declare function isFormFieldRequired(field: ConditionalFormField, values: Record<string, unknown>): boolean;
|
|
394
394
|
|
|
395
|
-
declare const CMSSY_EDIT_HEADER = "x-cmssy-edit";
|
|
396
|
-
declare const CMSSY_EDIT_QUERY_PARAM = "cmssyEdit";
|
|
397
|
-
declare const CMSSY_SECRET_QUERY_PARAM = "cmssySecret";
|
|
398
|
-
interface EditSearchParams {
|
|
399
|
-
getAll: (name: string) => string[];
|
|
400
|
-
get: (name: string) => string | null;
|
|
401
|
-
}
|
|
402
|
-
declare function isVerifiedEditUrl(url: {
|
|
403
|
-
searchParams: EditSearchParams;
|
|
404
|
-
}, config: {
|
|
405
|
-
draftSecret: string;
|
|
406
|
-
}): Promise<boolean>;
|
|
407
|
-
|
|
408
395
|
declare const CMSSY_EDIT_TOKEN_HEADER = "x-cmssy-edit-token";
|
|
409
396
|
interface MintCmssyEditTokenOptions {
|
|
410
397
|
page?: string;
|
|
@@ -436,4 +423,4 @@ declare class CmssyWebhookError extends Error {
|
|
|
436
423
|
}
|
|
437
424
|
declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): Promise<CmssyWebhookEvent>;
|
|
438
425
|
|
|
439
|
-
export { BUYER_CATALOG_PRICES_QUERY, BUYER_PRICES_QUERY, type BlockManifest, type BlockManifestBlock, type BlockManifestSource, type BuyerCatalogPricesResult, type BuyerCatalogPricesVariables, type BuyerPricesResult, type BuyerPricesVariables, CMSSY_BUYER_PRICES_MAX_ITEMS,
|
|
426
|
+
export { BUYER_CATALOG_PRICES_QUERY, BUYER_PRICES_QUERY, type BlockManifest, type BlockManifestBlock, type BlockManifestSource, type BuyerCatalogPricesResult, type BuyerCatalogPricesVariables, type BuyerPricesResult, type BuyerPricesVariables, CMSSY_BUYER_PRICES_MAX_ITEMS, CMSSY_EDIT_TOKEN_HEADER, CMSSY_PUBLIC_PRICES_MAX_ITEMS, type CmssyBuyerCatalogPage, type CmssyBuyerCatalogPrice, type CmssyBuyerCatalogSort, type CmssyBuyerPrice, type CmssyChannelRefusal, type CmssyChannelRefusalReason, type CmssyCheckoutErrorReason, CmssyClientConfig, type CmssyMaintenance, type CmssyMaintenanceRefusal, type CmssyMemberPriceList, CmssyOperation, type CmssyOrderProgress, type CmssyOrderProgressInput, type CmssyPriceDisplayMode, type CmssyPriceListSource, type CmssyPriceQueryItem, type CmssyPriceTier, type CmssyPriceWithheldReason, type CmssyPublicCatalogPage, type CmssyPublicPriceResult, type CmssyPublicPricedRecord, type CmssyPublicPricedRecordData, type CmssyQuantityRuleReason, type CmssyQuantityRuleViolation, CmssyRecordSort, type CmssyTaxTreatment, type CmssyTaxedAmount, CmssyWebhookError, type ConditionalFormField, FetchLike, type GetBuyerCatalogPricesQuery, type GetBuyerPricesOptions, type GetPublicCatalogPricesQuery, type GetPublicPricesOptions, GraphqlRequestOptions, MAINTENANCE_QUERY, type MediaLike, type MintCmssyEditTokenOptions, PUBLIC_CATALOG_PRICES_QUERY, PUBLIC_PRICES_QUERY, type PublicCatalogPricesResult, type PublicCatalogPricesVariables, type PublicPricesResult, type PublicPricesVariables, RetryOption, type VerifyCmssyEditTokenOptions, blocksToMeta, blocksToSchemas, buildBlockManifest, channelRefusal, channelRefusalReasonValues, checkoutErrorItemId, checkoutErrorReason, checkoutErrorReasonValues, fields, getBuyerCatalogPrices, getBuyerPrices, getMaintenance, getPublicCatalogPrices, getPublicPrices, isFormFieldRequired, isFormFieldVisible, layoutRegionsToBridge, maintenanceRefusal, mediaAlt, mediaDuration, mediaType, mediaUrl, mediaUrls, mintCmssyEditToken, orderProgress, orderProgressValues, priceDisplayModeValues, priceListSourceValues, priceWithheldReasonValues, propsToSchema, quantityRuleReasonValues, quantityRuleViolation, registryToManifestBlocks, verifyCmssyEditToken, verifyCmssyWebhook, visibleFormFields };
|
package/dist/index.js
CHANGED
|
@@ -224,7 +224,7 @@ function documentText(document2) {
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
// src/version.ts
|
|
227
|
-
var CMSSY_CORE_VERSION = "19.
|
|
227
|
+
var CMSSY_CORE_VERSION = "19.39.0" ;
|
|
228
228
|
var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
|
|
229
229
|
|
|
230
230
|
// src/data/http.ts
|
|
@@ -1573,80 +1573,6 @@ function parseEditorMessage(data, origin, expectedOrigin) {
|
|
|
1573
1573
|
}
|
|
1574
1574
|
}
|
|
1575
1575
|
|
|
1576
|
-
// src/secret-match.ts
|
|
1577
|
-
var MAX_SECRET_LENGTH = 256;
|
|
1578
|
-
async function cmssySecretsMatch(a, b) {
|
|
1579
|
-
if (a.length > MAX_SECRET_LENGTH || b.length > MAX_SECRET_LENGTH) {
|
|
1580
|
-
return false;
|
|
1581
|
-
}
|
|
1582
|
-
const encoder = new TextEncoder();
|
|
1583
|
-
const [ha, hb] = await Promise.all([
|
|
1584
|
-
crypto.subtle.digest("SHA-256", encoder.encode(a)),
|
|
1585
|
-
crypto.subtle.digest("SHA-256", encoder.encode(b))
|
|
1586
|
-
]);
|
|
1587
|
-
const va = new Uint8Array(ha);
|
|
1588
|
-
const vb = new Uint8Array(hb);
|
|
1589
|
-
let diff = 0;
|
|
1590
|
-
for (let i = 0; i < va.length; i += 1) {
|
|
1591
|
-
diff |= (va[i] ?? 0) ^ (vb[i] ?? 0);
|
|
1592
|
-
}
|
|
1593
|
-
return diff === 0;
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
// src/edit-request.ts
|
|
1597
|
-
var CMSSY_EDIT_HEADER = "x-cmssy-edit";
|
|
1598
|
-
var CMSSY_EDIT_QUERY_PARAM = "cmssyEdit";
|
|
1599
|
-
var CMSSY_SECRET_QUERY_PARAM = "cmssySecret";
|
|
1600
|
-
async function isVerifiedEditUrl(url, config) {
|
|
1601
|
-
if (!url.searchParams.getAll(CMSSY_EDIT_QUERY_PARAM).includes("1")) {
|
|
1602
|
-
return false;
|
|
1603
|
-
}
|
|
1604
|
-
const provided = url.searchParams.get(CMSSY_SECRET_QUERY_PARAM);
|
|
1605
|
-
if (!provided || !config.draftSecret) return false;
|
|
1606
|
-
return cmssySecretsMatch(provided, config.draftSecret);
|
|
1607
|
-
}
|
|
1608
|
-
|
|
1609
|
-
// src/csp.ts
|
|
1610
|
-
function toCspOrigin(origin) {
|
|
1611
|
-
if (origin === "*") return "*";
|
|
1612
|
-
let parsed;
|
|
1613
|
-
try {
|
|
1614
|
-
parsed = new URL(origin);
|
|
1615
|
-
} catch {
|
|
1616
|
-
throw new Error(`cmssy: invalid editorOrigin "${origin}"`);
|
|
1617
|
-
}
|
|
1618
|
-
if (parsed.origin === "null") {
|
|
1619
|
-
throw new Error(`cmssy: editorOrigin "${origin}" has no usable origin`);
|
|
1620
|
-
}
|
|
1621
|
-
return parsed.origin;
|
|
1622
|
-
}
|
|
1623
|
-
function frameAncestors(editorOrigin) {
|
|
1624
|
-
const resolved = resolveEditorOrigin(editorOrigin);
|
|
1625
|
-
const origins = Array.isArray(resolved) ? resolved : [resolved];
|
|
1626
|
-
if (origins.length === 0) {
|
|
1627
|
-
throw new Error(
|
|
1628
|
-
"cmssy: editorOrigin must contain at least one valid origin"
|
|
1629
|
-
);
|
|
1630
|
-
}
|
|
1631
|
-
const normalized = origins.map((origin) => toCspOrigin(origin.trim()));
|
|
1632
|
-
return `frame-ancestors ${normalized.join(" ")}`;
|
|
1633
|
-
}
|
|
1634
|
-
function mergeFrameAncestors(existing, directive) {
|
|
1635
|
-
if (!existing) return directive;
|
|
1636
|
-
const kept = existing.split(";").map((part) => part.trim()).filter((part) => part.length > 0 && !/^frame-ancestors\b/i.test(part));
|
|
1637
|
-
kept.push(directive);
|
|
1638
|
-
return kept.join("; ");
|
|
1639
|
-
}
|
|
1640
|
-
function applyCmssyCsp(response, options) {
|
|
1641
|
-
const merged = mergeFrameAncestors(
|
|
1642
|
-
response.headers.get("Content-Security-Policy"),
|
|
1643
|
-
frameAncestors(options.editorOrigin)
|
|
1644
|
-
);
|
|
1645
|
-
response.headers.set("Content-Security-Policy", merged);
|
|
1646
|
-
response.headers.delete("X-Frame-Options");
|
|
1647
|
-
return response;
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
1576
|
// src/internal/hmac.ts
|
|
1651
1577
|
function hexToBytes(hex) {
|
|
1652
1578
|
if (hex.length % 2 !== 0 || /[^0-9a-fA-F]/.test(hex)) return null;
|
|
@@ -1724,6 +1650,93 @@ async function verifyCmssyEditToken(token, secret, options = {}) {
|
|
|
1724
1650
|
return timingSafeHexEqual(expected, provided);
|
|
1725
1651
|
}
|
|
1726
1652
|
|
|
1653
|
+
// src/secret-match.ts
|
|
1654
|
+
var MAX_SECRET_LENGTH = 256;
|
|
1655
|
+
async function cmssySecretsMatch(a, b) {
|
|
1656
|
+
if (a.length > MAX_SECRET_LENGTH || b.length > MAX_SECRET_LENGTH) {
|
|
1657
|
+
return false;
|
|
1658
|
+
}
|
|
1659
|
+
const encoder = new TextEncoder();
|
|
1660
|
+
const [ha, hb] = await Promise.all([
|
|
1661
|
+
crypto.subtle.digest("SHA-256", encoder.encode(a)),
|
|
1662
|
+
crypto.subtle.digest("SHA-256", encoder.encode(b))
|
|
1663
|
+
]);
|
|
1664
|
+
const va = new Uint8Array(ha);
|
|
1665
|
+
const vb = new Uint8Array(hb);
|
|
1666
|
+
let diff = 0;
|
|
1667
|
+
for (let i = 0; i < va.length; i += 1) {
|
|
1668
|
+
diff |= (va[i] ?? 0) ^ (vb[i] ?? 0);
|
|
1669
|
+
}
|
|
1670
|
+
return diff === 0;
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
// src/edit-request.ts
|
|
1674
|
+
var CMSSY_EDIT_HEADER = "x-cmssy-edit";
|
|
1675
|
+
var CMSSY_EDIT_QUERY_PARAM = "cmssyEdit";
|
|
1676
|
+
var CMSSY_SECRET_QUERY_PARAM = "cmssySecret";
|
|
1677
|
+
var CMSSY_EDIT_URL_TOKEN_PAGE = "cmssy:edit-url";
|
|
1678
|
+
var CMSSY_EDIT_TOKEN_CAPABILITY = "edit-token";
|
|
1679
|
+
var CMSSY_DRAFT_TOKEN_CAPABILITY = "draft-token";
|
|
1680
|
+
var MAX_EDIT_URL_TOKEN_LIFETIME_MS = 24 * 60 * 60 * 1e3;
|
|
1681
|
+
async function cmssyEditCredentialMatches(provided, draftSecret) {
|
|
1682
|
+
if (!provided || !draftSecret) return false;
|
|
1683
|
+
if (await cmssySecretsMatch(provided, draftSecret)) return true;
|
|
1684
|
+
const expiresAt = Number(provided.slice(0, provided.indexOf(".")));
|
|
1685
|
+
if (expiresAt - Date.now() > MAX_EDIT_URL_TOKEN_LIFETIME_MS) return false;
|
|
1686
|
+
return verifyCmssyEditToken(provided, draftSecret, {
|
|
1687
|
+
page: CMSSY_EDIT_URL_TOKEN_PAGE
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
async function isVerifiedEditUrl(url, config) {
|
|
1691
|
+
if (!url.searchParams.getAll(CMSSY_EDIT_QUERY_PARAM).includes("1")) {
|
|
1692
|
+
return false;
|
|
1693
|
+
}
|
|
1694
|
+
const provided = url.searchParams.get(CMSSY_SECRET_QUERY_PARAM);
|
|
1695
|
+
if (!provided || !config.draftSecret) return false;
|
|
1696
|
+
return cmssyEditCredentialMatches(provided, config.draftSecret);
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
// src/csp.ts
|
|
1700
|
+
function toCspOrigin(origin) {
|
|
1701
|
+
if (origin === "*") return "*";
|
|
1702
|
+
let parsed;
|
|
1703
|
+
try {
|
|
1704
|
+
parsed = new URL(origin);
|
|
1705
|
+
} catch {
|
|
1706
|
+
throw new Error(`cmssy: invalid editorOrigin "${origin}"`);
|
|
1707
|
+
}
|
|
1708
|
+
if (parsed.origin === "null") {
|
|
1709
|
+
throw new Error(`cmssy: editorOrigin "${origin}" has no usable origin`);
|
|
1710
|
+
}
|
|
1711
|
+
return parsed.origin;
|
|
1712
|
+
}
|
|
1713
|
+
function frameAncestors(editorOrigin) {
|
|
1714
|
+
const resolved = resolveEditorOrigin(editorOrigin);
|
|
1715
|
+
const origins = Array.isArray(resolved) ? resolved : [resolved];
|
|
1716
|
+
if (origins.length === 0) {
|
|
1717
|
+
throw new Error(
|
|
1718
|
+
"cmssy: editorOrigin must contain at least one valid origin"
|
|
1719
|
+
);
|
|
1720
|
+
}
|
|
1721
|
+
const normalized = origins.map((origin) => toCspOrigin(origin.trim()));
|
|
1722
|
+
return `frame-ancestors ${normalized.join(" ")}`;
|
|
1723
|
+
}
|
|
1724
|
+
function mergeFrameAncestors(existing, directive) {
|
|
1725
|
+
if (!existing) return directive;
|
|
1726
|
+
const kept = existing.split(";").map((part) => part.trim()).filter((part) => part.length > 0 && !/^frame-ancestors\b/i.test(part));
|
|
1727
|
+
kept.push(directive);
|
|
1728
|
+
return kept.join("; ");
|
|
1729
|
+
}
|
|
1730
|
+
function applyCmssyCsp(response, options) {
|
|
1731
|
+
const merged = mergeFrameAncestors(
|
|
1732
|
+
response.headers.get("Content-Security-Policy"),
|
|
1733
|
+
frameAncestors(options.editorOrigin)
|
|
1734
|
+
);
|
|
1735
|
+
response.headers.set("Content-Security-Policy", merged);
|
|
1736
|
+
response.headers.delete("X-Frame-Options");
|
|
1737
|
+
return response;
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1727
1740
|
// src/order-progress.ts
|
|
1728
1741
|
var orderProgressValues = [
|
|
1729
1742
|
"placed",
|
|
@@ -1822,4 +1835,4 @@ async function verifyCmssyWebhook(options) {
|
|
|
1822
1835
|
return parsed;
|
|
1823
1836
|
}
|
|
1824
1837
|
|
|
1825
|
-
export { BUYER_CATALOG_PRICES_QUERY, BUYER_PRICES_QUERY, CMSSY_BUYER_PRICES_MAX_ITEMS, CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_EDIT_TOKEN_HEADER, CMSSY_LOCALE_HEADER, CMSSY_PUBLIC_PRICES_MAX_ITEMS, CMSSY_RATE_LIMIT_WINDOW_MS, CMSSY_RETRY_MODES, CMSSY_SECRET_QUERY_PARAM, CmssyGraphqlError, CmssyRequestError, CmssyWebhookError, DEFAULT_CMSSY_API_URL, DEFAULT_CMSSY_EDITOR_ORIGINS, MAINTENANCE_QUERY, PROTOCOL_VERSION, PUBLIC_CATALOG_PRICES_QUERY, PUBLIC_PRICES_QUERY, SHORTCUT_ACTIONS, applyCmssyCsp, blocksToMeta, blocksToSchemas, buildBlockManifest, channelRefusal, channelRefusalReasonValues, checkoutErrorItemId, checkoutErrorReason, checkoutErrorReasonValues, createCmssyClient, createRetryingFetch, defineCmssyConfig, defineCmssyLayout, fields, getBuyerCatalogPrices, getBuyerPrices, getMaintenance, getPublicCatalogPrices, getPublicPrices, graphqlRequest, isFormFieldRequired, isFormFieldVisible, isProtocolCompatible, isTransientRequestError, isVerifiedEditUrl, layoutRegionsToBridge, localizeHref, maintenanceRefusal, mediaAlt, mediaDuration, mediaType, mediaUrl, mediaUrls, mintCmssyEditToken, normalizeOrigin, orderProgress, orderProgressValues, parseEditorMessage, postToEditor, priceDisplayModeValues, priceListSourceValues, priceWithheldReasonValues, propsToSchema, quantityRuleReasonValues, quantityRuleViolation, registryToManifestBlocks, resolveCmssyLocale, resolveEditorOrigin, typedOperation, verifyCmssyEditToken, verifyCmssyWebhook, visibleFormFields };
|
|
1838
|
+
export { BUYER_CATALOG_PRICES_QUERY, BUYER_PRICES_QUERY, CMSSY_BUYER_PRICES_MAX_ITEMS, CMSSY_DRAFT_TOKEN_CAPABILITY, CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_EDIT_TOKEN_CAPABILITY, CMSSY_EDIT_TOKEN_HEADER, CMSSY_EDIT_URL_TOKEN_PAGE, CMSSY_LOCALE_HEADER, CMSSY_PUBLIC_PRICES_MAX_ITEMS, CMSSY_RATE_LIMIT_WINDOW_MS, CMSSY_RETRY_MODES, CMSSY_SECRET_QUERY_PARAM, CmssyGraphqlError, CmssyRequestError, CmssyWebhookError, DEFAULT_CMSSY_API_URL, DEFAULT_CMSSY_EDITOR_ORIGINS, MAINTENANCE_QUERY, PROTOCOL_VERSION, PUBLIC_CATALOG_PRICES_QUERY, PUBLIC_PRICES_QUERY, SHORTCUT_ACTIONS, applyCmssyCsp, blocksToMeta, blocksToSchemas, buildBlockManifest, channelRefusal, channelRefusalReasonValues, checkoutErrorItemId, checkoutErrorReason, checkoutErrorReasonValues, createCmssyClient, createRetryingFetch, defineCmssyConfig, defineCmssyLayout, fields, getBuyerCatalogPrices, getBuyerPrices, getMaintenance, getPublicCatalogPrices, getPublicPrices, graphqlRequest, isFormFieldRequired, isFormFieldVisible, isProtocolCompatible, isTransientRequestError, isVerifiedEditUrl, layoutRegionsToBridge, localizeHref, maintenanceRefusal, mediaAlt, mediaDuration, mediaType, mediaUrl, mediaUrls, mintCmssyEditToken, normalizeOrigin, orderProgress, orderProgressValues, parseEditorMessage, postToEditor, priceDisplayModeValues, priceListSourceValues, priceWithheldReasonValues, propsToSchema, quantityRuleReasonValues, quantityRuleViolation, registryToManifestBlocks, resolveCmssyLocale, resolveEditorOrigin, typedOperation, verifyCmssyEditToken, verifyCmssyWebhook, visibleFormFields };
|
package/dist/internal/locale.cjs
CHANGED
package/dist/internal/locale.js
CHANGED
package/dist/internal.cjs
CHANGED
|
@@ -156,7 +156,7 @@ function documentText(document2) {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
// src/version.ts
|
|
159
|
-
var CMSSY_CORE_VERSION = "19.
|
|
159
|
+
var CMSSY_CORE_VERSION = "19.39.0" ;
|
|
160
160
|
var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
|
|
161
161
|
|
|
162
162
|
// src/data/http.ts
|
|
@@ -1477,6 +1477,79 @@ async function cmssySecretsMatch(a, b) {
|
|
|
1477
1477
|
return diff === 0;
|
|
1478
1478
|
}
|
|
1479
1479
|
|
|
1480
|
+
// src/internal/hmac.ts
|
|
1481
|
+
function hexToBytes(hex) {
|
|
1482
|
+
if (hex.length % 2 !== 0 || /[^0-9a-fA-F]/.test(hex)) return null;
|
|
1483
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
1484
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
1485
|
+
bytes[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
1486
|
+
}
|
|
1487
|
+
return bytes;
|
|
1488
|
+
}
|
|
1489
|
+
function bytesToHex(bytes) {
|
|
1490
|
+
return [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1491
|
+
}
|
|
1492
|
+
function timingSafeHexEqual(expectedHex, providedHex) {
|
|
1493
|
+
if (expectedHex.length !== providedHex.length) return false;
|
|
1494
|
+
const expected = hexToBytes(expectedHex);
|
|
1495
|
+
const provided = hexToBytes(providedHex);
|
|
1496
|
+
if (!expected || !provided) return false;
|
|
1497
|
+
let diff = 0;
|
|
1498
|
+
for (let i = 0; i < expected.length; i += 1) {
|
|
1499
|
+
diff |= (expected[i] ?? 0) ^ (provided[i] ?? 0);
|
|
1500
|
+
}
|
|
1501
|
+
return diff === 0;
|
|
1502
|
+
}
|
|
1503
|
+
async function hmacSha256Hex(secret, message) {
|
|
1504
|
+
const encoder = new TextEncoder();
|
|
1505
|
+
const key = await crypto.subtle.importKey(
|
|
1506
|
+
"raw",
|
|
1507
|
+
encoder.encode(secret),
|
|
1508
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
1509
|
+
false,
|
|
1510
|
+
["sign"]
|
|
1511
|
+
);
|
|
1512
|
+
const signature = await crypto.subtle.sign(
|
|
1513
|
+
"HMAC",
|
|
1514
|
+
key,
|
|
1515
|
+
encoder.encode(message)
|
|
1516
|
+
);
|
|
1517
|
+
return bytesToHex(new Uint8Array(signature));
|
|
1518
|
+
}
|
|
1519
|
+
var MAX_TOKEN_LENGTH = 256;
|
|
1520
|
+
function payload(expiresAt, page) {
|
|
1521
|
+
return `${expiresAt}.${page}`;
|
|
1522
|
+
}
|
|
1523
|
+
async function verifyCmssyEditToken(token, secret, options = {}) {
|
|
1524
|
+
if (!token || !secret) return false;
|
|
1525
|
+
if (token.length > MAX_TOKEN_LENGTH) return false;
|
|
1526
|
+
const separator = token.indexOf(".");
|
|
1527
|
+
if (separator === -1) return false;
|
|
1528
|
+
const expiresAt = Number(token.slice(0, separator));
|
|
1529
|
+
const provided = token.slice(separator + 1);
|
|
1530
|
+
if (!Number.isSafeInteger(expiresAt) || !provided) return false;
|
|
1531
|
+
const now = options.now ?? Date.now();
|
|
1532
|
+
if (expiresAt <= now) return false;
|
|
1533
|
+
const expected = await hmacSha256Hex(
|
|
1534
|
+
secret,
|
|
1535
|
+
payload(expiresAt, options.page ?? "")
|
|
1536
|
+
);
|
|
1537
|
+
return timingSafeHexEqual(expected, provided);
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
// src/edit-request.ts
|
|
1541
|
+
var CMSSY_EDIT_URL_TOKEN_PAGE = "cmssy:edit-url";
|
|
1542
|
+
var MAX_EDIT_URL_TOKEN_LIFETIME_MS = 24 * 60 * 60 * 1e3;
|
|
1543
|
+
async function cmssyEditCredentialMatches(provided, draftSecret) {
|
|
1544
|
+
if (!provided || !draftSecret) return false;
|
|
1545
|
+
if (await cmssySecretsMatch(provided, draftSecret)) return true;
|
|
1546
|
+
const expiresAt = Number(provided.slice(0, provided.indexOf(".")));
|
|
1547
|
+
if (expiresAt - Date.now() > MAX_EDIT_URL_TOKEN_LIFETIME_MS) return false;
|
|
1548
|
+
return verifyCmssyEditToken(provided, draftSecret, {
|
|
1549
|
+
page: CMSSY_EDIT_URL_TOKEN_PAGE
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1480
1553
|
// src/config.ts
|
|
1481
1554
|
var DEFAULT_CMSSY_EDITOR_ORIGINS = [
|
|
1482
1555
|
"https://cmssy.io",
|
|
@@ -1666,6 +1739,7 @@ exports.asBucket = asBucket;
|
|
|
1666
1739
|
exports.buildBlockContext = buildBlockContext;
|
|
1667
1740
|
exports.clearWorkspaceIdCache = clearWorkspaceIdCache;
|
|
1668
1741
|
exports.cmssyCspHeaders = cmssyCspHeaders;
|
|
1742
|
+
exports.cmssyEditCredentialMatches = cmssyEditCredentialMatches;
|
|
1669
1743
|
exports.cmssySecretsMatch = cmssySecretsMatch;
|
|
1670
1744
|
exports.collectFormIds = collectFormIds;
|
|
1671
1745
|
exports.createCmssyLayoutStore = createCmssyLayoutStore;
|
package/dist/internal.d.cts
CHANGED
|
@@ -4,8 +4,8 @@ import { G as GraphqlRequestOptions } from './locale-DgWB2_Zb.cjs';
|
|
|
4
4
|
export { b as CMSSY_LOCALE_HEADER, l as localeForPath, c as localeForPathname, d as localizeHref, r as resolveSiteLocales, s as splitCmssyLocale, e as splitLocaleFromPath } from './locale-DgWB2_Zb.cjs';
|
|
5
5
|
import { CmssyFormDefinition, BuildBlockContextExtra, CmssyBlockContext, CmssySiteConfig, FieldDefinition, RawBlock, CmssyLayoutGroup } from '@cmssy/types';
|
|
6
6
|
export { CmssySiteLocales } from '@cmssy/types';
|
|
7
|
-
import { Q as QueryScopedOptions } from './csp-
|
|
8
|
-
export { F as FORM_QUERY, M as MODEL_DEFINITIONS_QUERY, a as MODEL_RECORDS_QUERY, S as SITE_CONFIG_QUERY, b as SUBMIT_FORM_MUTATION, c as cmssyCspHeaders, i as isDevelopment, l as layoutRegionIds, r as resolveInitialTarget, t as toCspOrigin } from './csp-
|
|
7
|
+
import { Q as QueryScopedOptions } from './csp-NaRDpreT.cjs';
|
|
8
|
+
export { F as FORM_QUERY, M as MODEL_DEFINITIONS_QUERY, a as MODEL_RECORDS_QUERY, S as SITE_CONFIG_QUERY, b as SUBMIT_FORM_MUTATION, c as cmssyCspHeaders, d as cmssyEditCredentialMatches, i as isDevelopment, l as layoutRegionIds, r as resolveInitialTarget, t as toCspOrigin } from './csp-NaRDpreT.cjs';
|
|
9
9
|
export { localizedPath } from './internal/locale.cjs';
|
|
10
10
|
|
|
11
11
|
declare function buildBlockContext(locale: string, defaultLocale: string, enabledLocales?: string[], isPreview?: boolean, forms?: Record<string, CmssyFormDefinition>, extra?: BuildBlockContextExtra): CmssyBlockContext;
|
package/dist/internal.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { G as GraphqlRequestOptions } from './locale-Br9RRVb_.js';
|
|
|
4
4
|
export { b as CMSSY_LOCALE_HEADER, l as localeForPath, c as localeForPathname, d as localizeHref, r as resolveSiteLocales, s as splitCmssyLocale, e as splitLocaleFromPath } from './locale-Br9RRVb_.js';
|
|
5
5
|
import { CmssyFormDefinition, BuildBlockContextExtra, CmssyBlockContext, CmssySiteConfig, FieldDefinition, RawBlock, CmssyLayoutGroup } from '@cmssy/types';
|
|
6
6
|
export { CmssySiteLocales } from '@cmssy/types';
|
|
7
|
-
import { Q as QueryScopedOptions } from './csp-
|
|
8
|
-
export { F as FORM_QUERY, M as MODEL_DEFINITIONS_QUERY, a as MODEL_RECORDS_QUERY, S as SITE_CONFIG_QUERY, b as SUBMIT_FORM_MUTATION, c as cmssyCspHeaders, i as isDevelopment, l as layoutRegionIds, r as resolveInitialTarget, t as toCspOrigin } from './csp-
|
|
7
|
+
import { Q as QueryScopedOptions } from './csp-9c8JYkS0.js';
|
|
8
|
+
export { F as FORM_QUERY, M as MODEL_DEFINITIONS_QUERY, a as MODEL_RECORDS_QUERY, S as SITE_CONFIG_QUERY, b as SUBMIT_FORM_MUTATION, c as cmssyCspHeaders, d as cmssyEditCredentialMatches, i as isDevelopment, l as layoutRegionIds, r as resolveInitialTarget, t as toCspOrigin } from './csp-9c8JYkS0.js';
|
|
9
9
|
export { localizedPath } from './internal/locale.js';
|
|
10
10
|
|
|
11
11
|
declare function buildBlockContext(locale: string, defaultLocale: string, enabledLocales?: string[], isPreview?: boolean, forms?: Record<string, CmssyFormDefinition>, extra?: BuildBlockContextExtra): CmssyBlockContext;
|
package/dist/internal.js
CHANGED
|
@@ -154,7 +154,7 @@ function documentText(document2) {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
// src/version.ts
|
|
157
|
-
var CMSSY_CORE_VERSION = "19.
|
|
157
|
+
var CMSSY_CORE_VERSION = "19.39.0" ;
|
|
158
158
|
var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
|
|
159
159
|
|
|
160
160
|
// src/data/http.ts
|
|
@@ -1475,6 +1475,79 @@ async function cmssySecretsMatch(a, b) {
|
|
|
1475
1475
|
return diff === 0;
|
|
1476
1476
|
}
|
|
1477
1477
|
|
|
1478
|
+
// src/internal/hmac.ts
|
|
1479
|
+
function hexToBytes(hex) {
|
|
1480
|
+
if (hex.length % 2 !== 0 || /[^0-9a-fA-F]/.test(hex)) return null;
|
|
1481
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
1482
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
1483
|
+
bytes[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
1484
|
+
}
|
|
1485
|
+
return bytes;
|
|
1486
|
+
}
|
|
1487
|
+
function bytesToHex(bytes) {
|
|
1488
|
+
return [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1489
|
+
}
|
|
1490
|
+
function timingSafeHexEqual(expectedHex, providedHex) {
|
|
1491
|
+
if (expectedHex.length !== providedHex.length) return false;
|
|
1492
|
+
const expected = hexToBytes(expectedHex);
|
|
1493
|
+
const provided = hexToBytes(providedHex);
|
|
1494
|
+
if (!expected || !provided) return false;
|
|
1495
|
+
let diff = 0;
|
|
1496
|
+
for (let i = 0; i < expected.length; i += 1) {
|
|
1497
|
+
diff |= (expected[i] ?? 0) ^ (provided[i] ?? 0);
|
|
1498
|
+
}
|
|
1499
|
+
return diff === 0;
|
|
1500
|
+
}
|
|
1501
|
+
async function hmacSha256Hex(secret, message) {
|
|
1502
|
+
const encoder = new TextEncoder();
|
|
1503
|
+
const key = await crypto.subtle.importKey(
|
|
1504
|
+
"raw",
|
|
1505
|
+
encoder.encode(secret),
|
|
1506
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
1507
|
+
false,
|
|
1508
|
+
["sign"]
|
|
1509
|
+
);
|
|
1510
|
+
const signature = await crypto.subtle.sign(
|
|
1511
|
+
"HMAC",
|
|
1512
|
+
key,
|
|
1513
|
+
encoder.encode(message)
|
|
1514
|
+
);
|
|
1515
|
+
return bytesToHex(new Uint8Array(signature));
|
|
1516
|
+
}
|
|
1517
|
+
var MAX_TOKEN_LENGTH = 256;
|
|
1518
|
+
function payload(expiresAt, page) {
|
|
1519
|
+
return `${expiresAt}.${page}`;
|
|
1520
|
+
}
|
|
1521
|
+
async function verifyCmssyEditToken(token, secret, options = {}) {
|
|
1522
|
+
if (!token || !secret) return false;
|
|
1523
|
+
if (token.length > MAX_TOKEN_LENGTH) return false;
|
|
1524
|
+
const separator = token.indexOf(".");
|
|
1525
|
+
if (separator === -1) return false;
|
|
1526
|
+
const expiresAt = Number(token.slice(0, separator));
|
|
1527
|
+
const provided = token.slice(separator + 1);
|
|
1528
|
+
if (!Number.isSafeInteger(expiresAt) || !provided) return false;
|
|
1529
|
+
const now = options.now ?? Date.now();
|
|
1530
|
+
if (expiresAt <= now) return false;
|
|
1531
|
+
const expected = await hmacSha256Hex(
|
|
1532
|
+
secret,
|
|
1533
|
+
payload(expiresAt, options.page ?? "")
|
|
1534
|
+
);
|
|
1535
|
+
return timingSafeHexEqual(expected, provided);
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
// src/edit-request.ts
|
|
1539
|
+
var CMSSY_EDIT_URL_TOKEN_PAGE = "cmssy:edit-url";
|
|
1540
|
+
var MAX_EDIT_URL_TOKEN_LIFETIME_MS = 24 * 60 * 60 * 1e3;
|
|
1541
|
+
async function cmssyEditCredentialMatches(provided, draftSecret) {
|
|
1542
|
+
if (!provided || !draftSecret) return false;
|
|
1543
|
+
if (await cmssySecretsMatch(provided, draftSecret)) return true;
|
|
1544
|
+
const expiresAt = Number(provided.slice(0, provided.indexOf(".")));
|
|
1545
|
+
if (expiresAt - Date.now() > MAX_EDIT_URL_TOKEN_LIFETIME_MS) return false;
|
|
1546
|
+
return verifyCmssyEditToken(provided, draftSecret, {
|
|
1547
|
+
page: CMSSY_EDIT_URL_TOKEN_PAGE
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1478
1551
|
// src/config.ts
|
|
1479
1552
|
var DEFAULT_CMSSY_EDITOR_ORIGINS = [
|
|
1480
1553
|
"https://cmssy.io",
|
|
@@ -1653,4 +1726,4 @@ function layoutRegionIds(layout) {
|
|
|
1653
1726
|
return (layout?.regions ?? DEFAULT_LAYOUT_REGIONS).map((region) => region.id);
|
|
1654
1727
|
}
|
|
1655
1728
|
|
|
1656
|
-
export { CMSSY_DELIVERY_OPERATIONS, CMSSY_LOCALE_HEADER, FORM_QUERY, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, asBucket, buildBlockContext, clearWorkspaceIdCache, cmssyCspHeaders, cmssySecretsMatch, collectFormIds, createCmssyLayoutStore, fetchLayoutKey, fetchLayouts, fetchLayoutsByKey, fetchPage, fetchPageById, fetchPageMeta, fetchPages, fetchSiteConfig, getBlockContentForLanguage, isDevelopment, layoutRegionIds, layoutStoreKey, localeForPath, localeForPathname, localizeHref, localizedPath, normalizeBlockContent, readThroughLayoutStore, resolveApiUrl, resolveForms, resolveInitialTarget, resolveRelationContent, resolveSiteLocales, resolveWorkspaceId, splitCmssyLocale, splitLocaleFromPath, toCspOrigin, unreachableShowWhenTargets };
|
|
1729
|
+
export { CMSSY_DELIVERY_OPERATIONS, CMSSY_LOCALE_HEADER, FORM_QUERY, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, asBucket, buildBlockContext, clearWorkspaceIdCache, cmssyCspHeaders, cmssyEditCredentialMatches, cmssySecretsMatch, collectFormIds, createCmssyLayoutStore, fetchLayoutKey, fetchLayouts, fetchLayoutsByKey, fetchPage, fetchPageById, fetchPageMeta, fetchPages, fetchSiteConfig, getBlockContentForLanguage, isDevelopment, layoutRegionIds, layoutStoreKey, localeForPath, localeForPathname, localizeHref, localizedPath, normalizeBlockContent, readThroughLayoutStore, resolveApiUrl, resolveForms, resolveInitialTarget, resolveRelationContent, resolveSiteLocales, resolveWorkspaceId, splitCmssyLocale, splitLocaleFromPath, toCspOrigin, unreachableShowWhenTargets };
|
package/dist/preflight.cjs
CHANGED
|
@@ -156,7 +156,7 @@ function documentText(document) {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
// src/version.ts
|
|
159
|
-
var CMSSY_CORE_VERSION = "19.
|
|
159
|
+
var CMSSY_CORE_VERSION = "19.39.0" ;
|
|
160
160
|
var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
|
|
161
161
|
|
|
162
162
|
// src/content/content-client.ts
|
|
@@ -184,6 +184,69 @@ var DEFAULT_CMSSY_EDITOR_ORIGINS = [
|
|
|
184
184
|
"https://www.cmssy.io"
|
|
185
185
|
];
|
|
186
186
|
|
|
187
|
+
// src/internal/hmac.ts
|
|
188
|
+
function hexToBytes(hex) {
|
|
189
|
+
if (hex.length % 2 !== 0 || /[^0-9a-fA-F]/.test(hex)) return null;
|
|
190
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
191
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
192
|
+
bytes[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
193
|
+
}
|
|
194
|
+
return bytes;
|
|
195
|
+
}
|
|
196
|
+
function bytesToHex(bytes) {
|
|
197
|
+
return [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
198
|
+
}
|
|
199
|
+
function timingSafeHexEqual(expectedHex, providedHex) {
|
|
200
|
+
if (expectedHex.length !== providedHex.length) return false;
|
|
201
|
+
const expected = hexToBytes(expectedHex);
|
|
202
|
+
const provided = hexToBytes(providedHex);
|
|
203
|
+
if (!expected || !provided) return false;
|
|
204
|
+
let diff = 0;
|
|
205
|
+
for (let i = 0; i < expected.length; i += 1) {
|
|
206
|
+
diff |= (expected[i] ?? 0) ^ (provided[i] ?? 0);
|
|
207
|
+
}
|
|
208
|
+
return diff === 0;
|
|
209
|
+
}
|
|
210
|
+
async function hmacSha256Hex(secret, message) {
|
|
211
|
+
const encoder = new TextEncoder();
|
|
212
|
+
const key = await crypto.subtle.importKey(
|
|
213
|
+
"raw",
|
|
214
|
+
encoder.encode(secret),
|
|
215
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
216
|
+
false,
|
|
217
|
+
["sign"]
|
|
218
|
+
);
|
|
219
|
+
const signature = await crypto.subtle.sign(
|
|
220
|
+
"HMAC",
|
|
221
|
+
key,
|
|
222
|
+
encoder.encode(message)
|
|
223
|
+
);
|
|
224
|
+
return bytesToHex(new Uint8Array(signature));
|
|
225
|
+
}
|
|
226
|
+
var MAX_TOKEN_LENGTH = 256;
|
|
227
|
+
function payload(expiresAt, page) {
|
|
228
|
+
return `${expiresAt}.${page}`;
|
|
229
|
+
}
|
|
230
|
+
async function verifyCmssyEditToken(token, secret, options = {}) {
|
|
231
|
+
if (!token || !secret) return false;
|
|
232
|
+
if (token.length > MAX_TOKEN_LENGTH) return false;
|
|
233
|
+
const separator = token.indexOf(".");
|
|
234
|
+
if (separator === -1) return false;
|
|
235
|
+
const expiresAt = Number(token.slice(0, separator));
|
|
236
|
+
const provided = token.slice(separator + 1);
|
|
237
|
+
if (!Number.isSafeInteger(expiresAt) || !provided) return false;
|
|
238
|
+
const now = options.now ?? Date.now();
|
|
239
|
+
if (expiresAt <= now) return false;
|
|
240
|
+
const expected = await hmacSha256Hex(
|
|
241
|
+
secret,
|
|
242
|
+
payload(expiresAt, options.page ?? "")
|
|
243
|
+
);
|
|
244
|
+
return timingSafeHexEqual(expected, provided);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/edit-request.ts
|
|
248
|
+
var CMSSY_EDIT_URL_TOKEN_PAGE = "cmssy:edit-url";
|
|
249
|
+
|
|
187
250
|
// src/edit-diagnostics.ts
|
|
188
251
|
var REQUIRED_ENV = [
|
|
189
252
|
["org", "CMSSY_ORG_SLUG"],
|
|
@@ -259,6 +322,18 @@ async function collectEditDiagnostics(input) {
|
|
|
259
322
|
});
|
|
260
323
|
return { workspace, checks };
|
|
261
324
|
}
|
|
325
|
+
var EDIT_TOKEN_SHAPE = /^(\d+)\.[0-9a-f]{64}$/;
|
|
326
|
+
async function expiredEditTokenTime(provided, draftSecret) {
|
|
327
|
+
const match = EDIT_TOKEN_SHAPE.exec(provided);
|
|
328
|
+
if (!match) return null;
|
|
329
|
+
const expiresAt = Number(match[1]);
|
|
330
|
+
if (expiresAt > Date.now()) return null;
|
|
331
|
+
const signedBySecret = await verifyCmssyEditToken(provided, draftSecret, {
|
|
332
|
+
page: CMSSY_EDIT_URL_TOKEN_PAGE,
|
|
333
|
+
now: expiresAt - 1
|
|
334
|
+
});
|
|
335
|
+
return signedBySecret ? expiresAt : null;
|
|
336
|
+
}
|
|
262
337
|
async function diagnoseSecret(preflight, providedSecret) {
|
|
263
338
|
const name2 = "draft secret";
|
|
264
339
|
if (!providedSecret?.trim()) {
|
|
@@ -269,6 +344,18 @@ async function diagnoseSecret(preflight, providedSecret) {
|
|
|
269
344
|
fix: "open the page from the cmssy editor, which appends the cmssySecret itself"
|
|
270
345
|
};
|
|
271
346
|
}
|
|
347
|
+
const expiresAt = await expiredEditTokenTime(
|
|
348
|
+
providedSecret,
|
|
349
|
+
preflight.draftSecret
|
|
350
|
+
);
|
|
351
|
+
if (expiresAt !== null) {
|
|
352
|
+
return {
|
|
353
|
+
name: name2,
|
|
354
|
+
status: "fail",
|
|
355
|
+
message: `the cmssySecret is an edit token that expired at ${new Date(expiresAt).toISOString()}`,
|
|
356
|
+
fix: "reload the editor, which mints a fresh token - if it keeps expiring at once, check this machine's clock"
|
|
357
|
+
};
|
|
358
|
+
}
|
|
272
359
|
const platform = await checkDraftSecret(preflight);
|
|
273
360
|
if (platform.status === "fail") {
|
|
274
361
|
return {
|
package/dist/preflight.js
CHANGED
|
@@ -154,7 +154,7 @@ function documentText(document) {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
// src/version.ts
|
|
157
|
-
var CMSSY_CORE_VERSION = "19.
|
|
157
|
+
var CMSSY_CORE_VERSION = "19.39.0" ;
|
|
158
158
|
var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
|
|
159
159
|
|
|
160
160
|
// src/content/content-client.ts
|
|
@@ -182,6 +182,69 @@ var DEFAULT_CMSSY_EDITOR_ORIGINS = [
|
|
|
182
182
|
"https://www.cmssy.io"
|
|
183
183
|
];
|
|
184
184
|
|
|
185
|
+
// src/internal/hmac.ts
|
|
186
|
+
function hexToBytes(hex) {
|
|
187
|
+
if (hex.length % 2 !== 0 || /[^0-9a-fA-F]/.test(hex)) return null;
|
|
188
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
189
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
190
|
+
bytes[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
191
|
+
}
|
|
192
|
+
return bytes;
|
|
193
|
+
}
|
|
194
|
+
function bytesToHex(bytes) {
|
|
195
|
+
return [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
196
|
+
}
|
|
197
|
+
function timingSafeHexEqual(expectedHex, providedHex) {
|
|
198
|
+
if (expectedHex.length !== providedHex.length) return false;
|
|
199
|
+
const expected = hexToBytes(expectedHex);
|
|
200
|
+
const provided = hexToBytes(providedHex);
|
|
201
|
+
if (!expected || !provided) return false;
|
|
202
|
+
let diff = 0;
|
|
203
|
+
for (let i = 0; i < expected.length; i += 1) {
|
|
204
|
+
diff |= (expected[i] ?? 0) ^ (provided[i] ?? 0);
|
|
205
|
+
}
|
|
206
|
+
return diff === 0;
|
|
207
|
+
}
|
|
208
|
+
async function hmacSha256Hex(secret, message) {
|
|
209
|
+
const encoder = new TextEncoder();
|
|
210
|
+
const key = await crypto.subtle.importKey(
|
|
211
|
+
"raw",
|
|
212
|
+
encoder.encode(secret),
|
|
213
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
214
|
+
false,
|
|
215
|
+
["sign"]
|
|
216
|
+
);
|
|
217
|
+
const signature = await crypto.subtle.sign(
|
|
218
|
+
"HMAC",
|
|
219
|
+
key,
|
|
220
|
+
encoder.encode(message)
|
|
221
|
+
);
|
|
222
|
+
return bytesToHex(new Uint8Array(signature));
|
|
223
|
+
}
|
|
224
|
+
var MAX_TOKEN_LENGTH = 256;
|
|
225
|
+
function payload(expiresAt, page) {
|
|
226
|
+
return `${expiresAt}.${page}`;
|
|
227
|
+
}
|
|
228
|
+
async function verifyCmssyEditToken(token, secret, options = {}) {
|
|
229
|
+
if (!token || !secret) return false;
|
|
230
|
+
if (token.length > MAX_TOKEN_LENGTH) return false;
|
|
231
|
+
const separator = token.indexOf(".");
|
|
232
|
+
if (separator === -1) return false;
|
|
233
|
+
const expiresAt = Number(token.slice(0, separator));
|
|
234
|
+
const provided = token.slice(separator + 1);
|
|
235
|
+
if (!Number.isSafeInteger(expiresAt) || !provided) return false;
|
|
236
|
+
const now = options.now ?? Date.now();
|
|
237
|
+
if (expiresAt <= now) return false;
|
|
238
|
+
const expected = await hmacSha256Hex(
|
|
239
|
+
secret,
|
|
240
|
+
payload(expiresAt, options.page ?? "")
|
|
241
|
+
);
|
|
242
|
+
return timingSafeHexEqual(expected, provided);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/edit-request.ts
|
|
246
|
+
var CMSSY_EDIT_URL_TOKEN_PAGE = "cmssy:edit-url";
|
|
247
|
+
|
|
185
248
|
// src/edit-diagnostics.ts
|
|
186
249
|
var REQUIRED_ENV = [
|
|
187
250
|
["org", "CMSSY_ORG_SLUG"],
|
|
@@ -257,6 +320,18 @@ async function collectEditDiagnostics(input) {
|
|
|
257
320
|
});
|
|
258
321
|
return { workspace, checks };
|
|
259
322
|
}
|
|
323
|
+
var EDIT_TOKEN_SHAPE = /^(\d+)\.[0-9a-f]{64}$/;
|
|
324
|
+
async function expiredEditTokenTime(provided, draftSecret) {
|
|
325
|
+
const match = EDIT_TOKEN_SHAPE.exec(provided);
|
|
326
|
+
if (!match) return null;
|
|
327
|
+
const expiresAt = Number(match[1]);
|
|
328
|
+
if (expiresAt > Date.now()) return null;
|
|
329
|
+
const signedBySecret = await verifyCmssyEditToken(provided, draftSecret, {
|
|
330
|
+
page: CMSSY_EDIT_URL_TOKEN_PAGE,
|
|
331
|
+
now: expiresAt - 1
|
|
332
|
+
});
|
|
333
|
+
return signedBySecret ? expiresAt : null;
|
|
334
|
+
}
|
|
260
335
|
async function diagnoseSecret(preflight, providedSecret) {
|
|
261
336
|
const name2 = "draft secret";
|
|
262
337
|
if (!providedSecret?.trim()) {
|
|
@@ -267,6 +342,18 @@ async function diagnoseSecret(preflight, providedSecret) {
|
|
|
267
342
|
fix: "open the page from the cmssy editor, which appends the cmssySecret itself"
|
|
268
343
|
};
|
|
269
344
|
}
|
|
345
|
+
const expiresAt = await expiredEditTokenTime(
|
|
346
|
+
providedSecret,
|
|
347
|
+
preflight.draftSecret
|
|
348
|
+
);
|
|
349
|
+
if (expiresAt !== null) {
|
|
350
|
+
return {
|
|
351
|
+
name: name2,
|
|
352
|
+
status: "fail",
|
|
353
|
+
message: `the cmssySecret is an edit token that expired at ${new Date(expiresAt).toISOString()}`,
|
|
354
|
+
fix: "reload the editor, which mints a fresh token - if it keeps expiring at once, check this machine's clock"
|
|
355
|
+
};
|
|
356
|
+
}
|
|
270
357
|
const platform = await checkDraftSecret(preflight);
|
|
271
358
|
if (platform.status === "fail") {
|
|
272
359
|
return {
|
package/dist/testing.cjs
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// src/
|
|
3
|
+
// src/internal/hmac.ts
|
|
4
|
+
function bytesToHex(bytes) {
|
|
5
|
+
return [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
6
|
+
}
|
|
7
|
+
async function hmacSha256Hex(secret, message) {
|
|
8
|
+
const encoder = new TextEncoder();
|
|
9
|
+
const key = await crypto.subtle.importKey(
|
|
10
|
+
"raw",
|
|
11
|
+
encoder.encode(secret),
|
|
12
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
13
|
+
false,
|
|
14
|
+
["sign"]
|
|
15
|
+
);
|
|
16
|
+
const signature = await crypto.subtle.sign(
|
|
17
|
+
"HMAC",
|
|
18
|
+
key,
|
|
19
|
+
encoder.encode(message)
|
|
20
|
+
);
|
|
21
|
+
return bytesToHex(new Uint8Array(signature));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/edit-token.ts
|
|
25
|
+
var DEFAULT_TTL_SECONDS = 12 * 60 * 60;
|
|
26
|
+
function payload(expiresAt, page) {
|
|
27
|
+
return `${expiresAt}.${page}`;
|
|
28
|
+
}
|
|
29
|
+
async function mintCmssyEditToken(secret, options = {}) {
|
|
30
|
+
if (!secret) {
|
|
31
|
+
throw new Error("cmssy: minting an edit token needs a draftSecret");
|
|
32
|
+
}
|
|
33
|
+
const now = options.now ?? Date.now();
|
|
34
|
+
const ttl = options.ttlSeconds ?? DEFAULT_TTL_SECONDS;
|
|
35
|
+
const expiresAt = now + ttl * 1e3;
|
|
36
|
+
const signature = await hmacSha256Hex(
|
|
37
|
+
secret,
|
|
38
|
+
payload(expiresAt, options.page ?? "")
|
|
39
|
+
);
|
|
40
|
+
return `${expiresAt}.${signature}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/edit-request.ts
|
|
44
|
+
var CMSSY_EDIT_URL_TOKEN_PAGE = "cmssy:edit-url";
|
|
4
45
|
|
|
5
46
|
// src/preflight.ts
|
|
6
47
|
var ALLOWED_FRAME_HOSTS = ["cmssy.io", "www.cmssy.io"];
|
|
@@ -133,6 +174,19 @@ async function checkCmssyEditMode(options) {
|
|
|
133
174
|
);
|
|
134
175
|
}
|
|
135
176
|
}
|
|
177
|
+
if (secret) {
|
|
178
|
+
const editToken = await mintCmssyEditToken(secret, {
|
|
179
|
+
page: CMSSY_EDIT_URL_TOKEN_PAGE
|
|
180
|
+
});
|
|
181
|
+
const tokenEdit = await html(
|
|
182
|
+
url(`${path}?cmssyEdit=1&cmssySecret=${encodeURIComponent(editToken)}`)
|
|
183
|
+
);
|
|
184
|
+
if (!EDITOR_MARKER.test(tokenEdit.body)) {
|
|
185
|
+
failures.push(
|
|
186
|
+
`edit ${path}: no editor for an edit token - the cmssy editor sends a token instead of the secret to sites that announce it, so every check of cmssySecret must accept one (use isVerifiedEditUrl)`
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
136
190
|
const query = `cmssyEdit=1&cmssySecret=${encodeURIComponent(secret)}`;
|
|
137
191
|
const { localizedPath } = options;
|
|
138
192
|
if (!localizedPath) {
|
package/dist/testing.js
CHANGED
|
@@ -1,4 +1,45 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/internal/hmac.ts
|
|
2
|
+
function bytesToHex(bytes) {
|
|
3
|
+
return [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
4
|
+
}
|
|
5
|
+
async function hmacSha256Hex(secret, message) {
|
|
6
|
+
const encoder = new TextEncoder();
|
|
7
|
+
const key = await crypto.subtle.importKey(
|
|
8
|
+
"raw",
|
|
9
|
+
encoder.encode(secret),
|
|
10
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
11
|
+
false,
|
|
12
|
+
["sign"]
|
|
13
|
+
);
|
|
14
|
+
const signature = await crypto.subtle.sign(
|
|
15
|
+
"HMAC",
|
|
16
|
+
key,
|
|
17
|
+
encoder.encode(message)
|
|
18
|
+
);
|
|
19
|
+
return bytesToHex(new Uint8Array(signature));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/edit-token.ts
|
|
23
|
+
var DEFAULT_TTL_SECONDS = 12 * 60 * 60;
|
|
24
|
+
function payload(expiresAt, page) {
|
|
25
|
+
return `${expiresAt}.${page}`;
|
|
26
|
+
}
|
|
27
|
+
async function mintCmssyEditToken(secret, options = {}) {
|
|
28
|
+
if (!secret) {
|
|
29
|
+
throw new Error("cmssy: minting an edit token needs a draftSecret");
|
|
30
|
+
}
|
|
31
|
+
const now = options.now ?? Date.now();
|
|
32
|
+
const ttl = options.ttlSeconds ?? DEFAULT_TTL_SECONDS;
|
|
33
|
+
const expiresAt = now + ttl * 1e3;
|
|
34
|
+
const signature = await hmacSha256Hex(
|
|
35
|
+
secret,
|
|
36
|
+
payload(expiresAt, options.page ?? "")
|
|
37
|
+
);
|
|
38
|
+
return `${expiresAt}.${signature}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/edit-request.ts
|
|
42
|
+
var CMSSY_EDIT_URL_TOKEN_PAGE = "cmssy:edit-url";
|
|
2
43
|
|
|
3
44
|
// src/preflight.ts
|
|
4
45
|
var ALLOWED_FRAME_HOSTS = ["cmssy.io", "www.cmssy.io"];
|
|
@@ -131,6 +172,19 @@ async function checkCmssyEditMode(options) {
|
|
|
131
172
|
);
|
|
132
173
|
}
|
|
133
174
|
}
|
|
175
|
+
if (secret) {
|
|
176
|
+
const editToken = await mintCmssyEditToken(secret, {
|
|
177
|
+
page: CMSSY_EDIT_URL_TOKEN_PAGE
|
|
178
|
+
});
|
|
179
|
+
const tokenEdit = await html(
|
|
180
|
+
url(`${path}?cmssyEdit=1&cmssySecret=${encodeURIComponent(editToken)}`)
|
|
181
|
+
);
|
|
182
|
+
if (!EDITOR_MARKER.test(tokenEdit.body)) {
|
|
183
|
+
failures.push(
|
|
184
|
+
`edit ${path}: no editor for an edit token - the cmssy editor sends a token instead of the secret to sites that announce it, so every check of cmssySecret must accept one (use isVerifiedEditUrl)`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
134
188
|
const query = `cmssyEdit=1&cmssySecret=${encodeURIComponent(secret)}`;
|
|
135
189
|
const { localizedPath } = options;
|
|
136
190
|
if (!localizedPath) {
|