@tokenoftrust/cli 7.6.6 → 7.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/cli",
3
- "version": "7.6.6",
3
+ "version": "7.8.0",
4
4
  "description": "Token of Trust developer CLI — clone a tenant store, run it locally with save→reload, and submit it for preview. Installs the `tot` command.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Token of Trust",
@@ -19,7 +19,7 @@
19
19
 
20
20
  export const TOT_CONFIG_KEYS = [
21
21
  "$schema", "tenant", "scope", "mappings", "hostPlatform", "sample", "seed",
22
- "displayName", "siteType", "compliance", "capabilities", "features", "embeds", "seo", "currency", "timezone", "shipping", "catalog",
22
+ "displayName", "siteType", "compliance", "capabilities", "features", "embeds", "seo", "currency", "timezone", "shipping", "catalog", "accessPolicy", "verification",
23
23
  ];
24
24
  // Keys other tooling has written that the platform does NOT read, with the key it does.
25
25
  const RENAMED_CONFIG_KEYS = { appDomain: "scope", tenantId: "tenant" };
@@ -32,6 +32,41 @@ export const FEATURE_KEYS = [
32
32
  ];
33
33
  export const SITE_TYPES = ["commerce", "marketing"];
34
34
 
35
+ const ACCESS_MODES = ["open", "checkout_gated", "closed_store"];
36
+ const REGISTRATION_MODES = ["self_serve", "approval_required"];
37
+ const ACCESS_POLICY_KEYS = ["mode", "hidePricesForGuests", "registrationMode", "b2bKybOrgVerification"];
38
+
39
+ /** @param {unknown} value */
40
+ export function accessPolicyDeclarationProblems(value) {
41
+ if (!isObject(value)) return ["accessPolicy must be an object"];
42
+ /** @type {Record<string, unknown>} */
43
+ const policy = value;
44
+ const problems = [];
45
+ if (Object.keys(policy).some(key => !ACCESS_POLICY_KEYS.includes(key))) problems.push("accessPolicy has an unknown field");
46
+ if (typeof policy.mode !== "string" || !ACCESS_MODES.includes(policy.mode)) problems.push("accessPolicy.mode is invalid");
47
+ if (policy.registrationMode !== undefined &&
48
+ (typeof policy.registrationMode !== "string" || !REGISTRATION_MODES.includes(policy.registrationMode))) {
49
+ problems.push("accessPolicy.registrationMode is invalid");
50
+ }
51
+ for (const field of ["hidePricesForGuests", "b2bKybOrgVerification"]) {
52
+ if (policy[field] !== undefined && typeof policy[field] !== "boolean") problems.push(`accessPolicy.${field} must be boolean`);
53
+ }
54
+ return problems;
55
+ }
56
+
57
+ /** @param {unknown} value */
58
+ export function verificationDeclarationProblems(value) {
59
+ if (!isObject(value)) return ["verification must be an object"];
60
+ /** @type {Record<string, unknown>} */
61
+ const policy = value;
62
+ const problems = [];
63
+ if (Object.keys(policy).some(key => key !== "allowCrossStoreReuse")) problems.push("verification has an unknown field");
64
+ if (policy.allowCrossStoreReuse !== undefined && typeof policy.allowCrossStoreReuse !== "boolean") {
65
+ problems.push("verification.allowCrossStoreReuse must be boolean");
66
+ }
67
+ return problems;
68
+ }
69
+
35
70
  /** The currency a store sells in when `.tot/config.json` declares none. */
36
71
  export const DEFAULT_CURRENCY = "USD";
37
72
 
@@ -844,6 +879,16 @@ export function validateDeclaredConfig(config, file = ".tot/config.json") {
844
879
  'declare e.g. `"shipping": { "tiers": [ { "rate": 5.99 }, { "atOrAbove": 100, "rate": 0, "label": "Free shipping" } ] }`, or remove `shipping` to charge none'));
845
880
  }
846
881
  }
882
+ if (config.accessPolicy !== undefined) {
883
+ for (const problem of accessPolicyDeclarationProblems(config.accessPolicy)) {
884
+ out.push(mk(ERROR, "config-access-policy", file, problem));
885
+ }
886
+ }
887
+ if (config.verification !== undefined) {
888
+ for (const problem of verificationDeclarationProblems(config.verification)) {
889
+ out.push(mk(ERROR, "config-shopper-verification", file, problem));
890
+ }
891
+ }
847
892
  if (config.catalog !== undefined) {
848
893
  const problems = catalogDeclarationProblems(config.catalog);
849
894
  if (problems.length > 0) {