@tokenoftrust/storefront-runner 4.11.13 → 4.11.14

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.
@@ -25,6 +25,8 @@ import type {
25
25
  ProviderOutcome,
26
26
  PublicCommerceEvent,
27
27
  StockState,
28
+ CustomizationEnv,
29
+ TenantConfig,
28
30
  } from "@tot/public-runtime";
29
31
  import {
30
32
  actorMayCommand,
@@ -53,11 +55,29 @@ import type {
53
55
  OrdersViewModel,
54
56
  } from "../viewmodels/orders";
55
57
  import type { CheckoutOrderClient } from "../orderClient";
56
- import { DEFAULT_TIMEZONE } from "@tot/public-runtime/declared-tenant-config";
58
+ import { DEFAULT_TIMEZONE, resolveStoreTimeZone } from "@tot/public-runtime/declared-tenant-config";
59
+ import { DeclaredTenantConfigUnreadError, withDeclaredTenantConfig } from "@/config/declaredTenantConfig";
57
60
 
58
61
  const EVIDENCE_STATES: readonly EvidenceState[] = ["fresh", "not-required", "UNKNOWN", "stale", "unreadable", "absent"];
59
62
  const REFUND_PAYMENTS: ReadonlySet<PaymentState> = new Set(["refunded", "refund_requested", "refund_unknown"]);
60
63
 
64
+ /** Read the selected store's declared clock from the same channel as its Orders data. */
65
+ export async function readOrdersTimeZone(
66
+ target: TenantConfig | null,
67
+ kvGet: (key: string) => Promise<string | null>,
68
+ env: CustomizationEnv,
69
+ ): Promise<string> {
70
+ if (!target) return DEFAULT_TIMEZONE;
71
+ try {
72
+ const declared = await withDeclaredTenantConfig(target, kvGet, { env });
73
+ return resolveStoreTimeZone(declared.timezone);
74
+ } catch (error) {
75
+ // An unreadable declaration cannot establish the store's clock. The formatter labels UTC.
76
+ if (error instanceof DeclaredTenantConfigUnreadError) return DEFAULT_TIMEZONE;
77
+ throw error;
78
+ }
79
+ }
80
+
61
81
  /** `YYYY-MM-DD` of an instant on the store's calendar. `null` when the instant does not parse. */
62
82
  export function storeDay(instant: string | Date, timeZone: string): string | null {
63
83
  const at = typeof instant === "string" ? new Date(instant) : instant;
@@ -67,18 +87,18 @@ export function storeDay(instant: string | Date, timeZone: string): string | nul
67
87
  return `${part("year")}-${part("month")}-${part("day")}`;
68
88
  }
69
89
 
70
- /** An instant's clock time on the store's clock, e.g. `12:03 PM`. */
90
+ /** An instant's clock time and zone on the store's clock, e.g. `12:03 PM PDT`. */
71
91
  export function formatStoreTime(instant: string, timeZone: string): string {
72
92
  const at = new Date(instant);
73
93
  if (Number.isNaN(at.getTime())) return "";
74
- return new Intl.DateTimeFormat("en-US", { timeZone, hour: "numeric", minute: "2-digit" }).format(at);
94
+ return new Intl.DateTimeFormat("en-US", { timeZone, hour: "numeric", minute: "2-digit", timeZoneName: "short" }).format(at);
75
95
  }
76
96
 
77
- /** An instant's date and clock time on the store's clock, e.g. `Oct 27, 12:03 PM`. */
97
+ /** An instant's date, clock time and zone on the store's clock, e.g. `Oct 27, 12:03 PM PDT`. */
78
98
  export function formatStoreDateTime(instant: string, timeZone: string): string {
79
99
  const at = new Date(instant);
80
100
  if (Number.isNaN(at.getTime())) return "";
81
- return new Intl.DateTimeFormat("en-US", { timeZone, month: "short", day: "numeric", hour: "numeric", minute: "2-digit" }).format(at);
101
+ return new Intl.DateTimeFormat("en-US", { timeZone, month: "short", day: "numeric", hour: "numeric", minute: "2-digit", timeZoneName: "short" }).format(at);
82
102
  }
83
103
 
84
104
  /** An instant's date on the store's calendar, e.g. `Oct 27`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "4.11.13",
3
+ "version": "4.11.14",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
6
6
  "packageManager": "pnpm@11.9.0",