@aglyn/plugins-commerce 1.29.1 → 1.29.3

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.
Files changed (89) hide show
  1. package/package.json +13 -13
  2. package/src/lib/components/console/checkout-tax-blocked-notice.component.d.ts +18 -0
  3. package/src/lib/components/console/checkout-tax-blocked-notice.component.js +67 -0
  4. package/src/lib/components/console/checkout-tax-blocked-notice.component.js.map +1 -0
  5. package/src/lib/components/console/payments-settings-card.component.d.ts +2 -2
  6. package/src/lib/components/console/payments-settings-card.component.js +99 -5
  7. package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
  8. package/src/lib/components/console/product-editor-dialog.component.js +14 -3
  9. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  10. package/src/lib/components/console/products-hub-card.component.js +51 -14
  11. package/src/lib/components/console/products-hub-card.component.js.map +1 -1
  12. package/src/lib/components/console/stripe-tax-readiness.component.d.ts +45 -0
  13. package/src/lib/components/console/stripe-tax-readiness.component.js +276 -0
  14. package/src/lib/components/console/stripe-tax-readiness.component.js.map +1 -0
  15. package/src/lib/components/console/tax-settings-card.component.js +22 -8
  16. package/src/lib/components/console/tax-settings-card.component.js.map +1 -1
  17. package/src/lib/constants/operator-alerts.d.ts +9 -0
  18. package/src/lib/constants/operator-alerts.js +22 -1
  19. package/src/lib/constants/operator-alerts.js.map +1 -1
  20. package/src/lib/declarations.server.js +11 -0
  21. package/src/lib/declarations.server.js.map +1 -1
  22. package/src/lib/model/commerce-record-routes.d.ts +13 -1
  23. package/src/lib/model/commerce-record-routes.js +22 -2
  24. package/src/lib/model/commerce-record-routes.js.map +1 -1
  25. package/src/lib/model/commerce-tax-readiness.d.ts +79 -0
  26. package/src/lib/model/commerce-tax-readiness.js +99 -0
  27. package/src/lib/model/commerce-tax-readiness.js.map +1 -0
  28. package/src/lib/model/commerce.d.ts +7 -0
  29. package/src/lib/model/commerce.js +17 -4
  30. package/src/lib/model/commerce.js.map +1 -1
  31. package/src/lib/model/payments-setup-status.d.ts +68 -0
  32. package/src/lib/model/payments-setup-status.js +103 -0
  33. package/src/lib/model/payments-setup-status.js.map +1 -0
  34. package/src/lib/plan-entitlements.d.ts +2 -2
  35. package/src/lib/plan-entitlements.js +4 -12
  36. package/src/lib/plan-entitlements.js.map +1 -1
  37. package/src/lib/server/cart-checkout.js +3 -0
  38. package/src/lib/server/cart-checkout.js.map +1 -1
  39. package/src/lib/server/checkout-tax-refusal.d.ts +51 -0
  40. package/src/lib/server/checkout-tax-refusal.js +133 -0
  41. package/src/lib/server/checkout-tax-refusal.js.map +1 -0
  42. package/src/lib/server/checkout.d.ts +2 -1
  43. package/src/lib/server/checkout.js +7 -2
  44. package/src/lib/server/checkout.js.map +1 -1
  45. package/src/lib/server/connect-prefill.d.ts +65 -0
  46. package/src/lib/server/connect-prefill.js +85 -0
  47. package/src/lib/server/connect-prefill.js.map +1 -0
  48. package/src/lib/server/connect.d.ts +4 -2
  49. package/src/lib/server/connect.js +117 -37
  50. package/src/lib/server/connect.js.map +1 -1
  51. package/src/lib/server/draft-order.js +4 -2
  52. package/src/lib/server/draft-order.js.map +1 -1
  53. package/src/lib/server/pos-order.js +1 -1
  54. package/src/lib/server/pos-order.js.map +1 -1
  55. package/src/lib/server/product-writer.d.ts +27 -0
  56. package/src/lib/server/product-writer.js +174 -4
  57. package/src/lib/server/product-writer.js.map +1 -1
  58. package/src/lib/server/quote-pay.d.ts +6 -0
  59. package/src/lib/server/quote-pay.js +8 -2
  60. package/src/lib/server/quote-pay.js.map +1 -1
  61. package/src/lib/server/seller-stripe-account.d.ts +19 -0
  62. package/src/lib/server/seller-stripe-account.js +40 -4
  63. package/src/lib/server/seller-stripe-account.js.map +1 -1
  64. package/src/lib/server/site-page-resolver.d.ts +11 -5
  65. package/src/lib/server/site-page-resolver.js +102 -19
  66. package/src/lib/server/site-page-resolver.js.map +1 -1
  67. package/src/lib/server/site-search.d.ts +43 -0
  68. package/src/lib/server/site-search.js +124 -0
  69. package/src/lib/server/site-search.js.map +1 -0
  70. package/src/lib/server/tax-readiness.d.ts +56 -0
  71. package/src/lib/server/tax-readiness.js +169 -0
  72. package/src/lib/server/tax-readiness.js.map +1 -0
  73. package/src/lib/server.js +10 -2
  74. package/src/lib/server.js.map +1 -1
  75. package/src/lib/transfer/product-image-copy.server.d.ts +77 -0
  76. package/src/lib/transfer/product-image-copy.server.js +307 -0
  77. package/src/lib/transfer/product-image-copy.server.js.map +1 -0
  78. package/src/lib/transfer/product-images.d.ts +62 -0
  79. package/src/lib/transfer/product-images.js +143 -0
  80. package/src/lib/transfer/product-images.js.map +1 -0
  81. package/src/lib/transfer/product-sources.d.ts +92 -0
  82. package/src/lib/transfer/product-sources.js +519 -0
  83. package/src/lib/transfer/product-sources.js.map +1 -0
  84. package/src/lib/transfer/product-transfer.d.ts +26 -1
  85. package/src/lib/transfer/product-transfer.js +283 -11
  86. package/src/lib/transfer/product-transfer.js.map +1 -1
  87. package/src/lib/transfer/products.server.d.ts +29 -3
  88. package/src/lib/transfer/products.server.js +289 -13
  89. package/src/lib/transfer/products.server.js.map +1 -1
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { type SellerStripeTaxStatus } from '../model/commerce-tax-readiness';
18
+ /**
19
+ * Whether sales tax lets shoppers check out (AGL-4245):
20
+ * `GET /api/commerce/tax-readiness?hostId=…[&fresh=1]`, served by the console
21
+ * for the Taxes card and the Payments card's notice.
22
+ *
23
+ * Answers a {@link StoreTaxReadiness}: the saved tax mode, whether the store
24
+ * sells on its own Stripe account, that account's Stripe Tax (read with the
25
+ * same `tax/settings` call checkout makes, plus whether any registration is
26
+ * active), and whether checkout is refusing every shopper because of tax.
27
+ *
28
+ * Reading it as not blocked drops the refusal marker
29
+ * (`checkout-tax-refusal.ts`), which is how the owner's alert clears once a
30
+ * mode is chosen or Stripe Tax is on.
31
+ *
32
+ * Who may ask: whoever may read the payment methods card (works the store's
33
+ * orders, or manages its payment methods). A 404 otherwise, so the route
34
+ * never confirms a site exists.
35
+ */
36
+ /** How long one account's Stripe Tax answer is reused, so a card's render does not call Stripe each time. */
37
+ export declare const SELLER_STRIPE_TAX_CACHE_MS = 60000;
38
+ /** The shortest gap between two reads that "Check again" forces. */
39
+ export declare const SELLER_STRIPE_TAX_FRESH_MIN_MS = 5000;
40
+ /** Test seam: forget every cached answer. */
41
+ export declare function resetSellerStripeTaxCacheForTests(): void;
42
+ export interface TaxReadinessReadDeps {
43
+ settings(account: string): Promise<Record<string, unknown> | null>;
44
+ registration(account: string): Promise<boolean | null>;
45
+ now(): number;
46
+ }
47
+ /**
48
+ * The seller's Stripe Tax, cached per account for
49
+ * {@link SELLER_STRIPE_TAX_CACHE_MS}. `fresh` skips the cache unless the
50
+ * cached answer is younger than {@link SELLER_STRIPE_TAX_FRESH_MIN_MS}. An
51
+ * unreadable answer is not cached, so the next paint asks again.
52
+ */
53
+ export declare function cachedSellerStripeTaxStatus(account: string, options?: {
54
+ fresh?: boolean;
55
+ }, deps?: TaxReadinessReadDeps): Promise<SellerStripeTaxStatus>;
56
+ export declare function taxReadinessHandler(request: Request): Promise<Response>;
@@ -0,0 +1,169 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { checkEntitlement, pluginRequestFromWeb } from "@aglyn/aglyn/server";
17
+ import { emailUnverifiedResponse, firebaseAdmin, getOrgForHost, isImpersonationSession, lockdownRefusal } from "@aglyn/tenant-data-admin";
18
+ import { invalidIdTokenResponse } from "@aglyn/tenant-data-admin/server/id-token-refusal";
19
+ import { checkoutTaxBlock, stripeTaxStatusFromSettings } from "../model/commerce-tax-readiness.js";
20
+ import { clearCheckoutTaxRefusal, readCheckoutTaxRefusal } from "./checkout-tax-refusal.js";
21
+ import { holdsCommerceSiteKey } from "./commerce-site-keys.js";
22
+ import { directSellerAccountForHost, fetchSellerStripeTaxSettings, sellerHasActiveTaxRegistration } from "./seller-stripe-account.js";
23
+ /**
24
+ * Whether sales tax lets shoppers check out (AGL-4245):
25
+ * `GET /api/commerce/tax-readiness?hostId=…[&fresh=1]`, served by the console
26
+ * for the Taxes card and the Payments card's notice.
27
+ *
28
+ * Answers a {@link StoreTaxReadiness}: the saved tax mode, whether the store
29
+ * sells on its own Stripe account, that account's Stripe Tax (read with the
30
+ * same `tax/settings` call checkout makes, plus whether any registration is
31
+ * active), and whether checkout is refusing every shopper because of tax.
32
+ *
33
+ * Reading it as not blocked drops the refusal marker
34
+ * (`checkout-tax-refusal.ts`), which is how the owner's alert clears once a
35
+ * mode is chosen or Stripe Tax is on.
36
+ *
37
+ * Who may ask: whoever may read the payment methods card (works the store's
38
+ * orders, or manages its payment methods). A 404 otherwise, so the route
39
+ * never confirms a site exists.
40
+ */ /** How long one account's Stripe Tax answer is reused, so a card's render does not call Stripe each time. */ export const SELLER_STRIPE_TAX_CACHE_MS = 60000;
41
+ /** The shortest gap between two reads that "Check again" forces. */ export const SELLER_STRIPE_TAX_FRESH_MIN_MS = 5000;
42
+ const statusCache = new Map();
43
+ const CACHE_MAX = 500;
44
+ /** Test seam: forget every cached answer. */ export function resetSellerStripeTaxCacheForTests() {
45
+ statusCache.clear();
46
+ }
47
+ const defaultReadDeps = {
48
+ settings: fetchSellerStripeTaxSettings,
49
+ registration: sellerHasActiveTaxRegistration,
50
+ now: ()=>Date.now()
51
+ };
52
+ /**
53
+ * The seller's Stripe Tax, cached per account for
54
+ * {@link SELLER_STRIPE_TAX_CACHE_MS}. `fresh` skips the cache unless the
55
+ * cached answer is younger than {@link SELLER_STRIPE_TAX_FRESH_MIN_MS}. An
56
+ * unreadable answer is not cached, so the next paint asks again.
57
+ */ export async function cachedSellerStripeTaxStatus(account, options = {}, deps = defaultReadDeps) {
58
+ const now = deps.now();
59
+ const cached = statusCache.get(account);
60
+ const maxAge = options.fresh ? SELLER_STRIPE_TAX_FRESH_MIN_MS : SELLER_STRIPE_TAX_CACHE_MS;
61
+ if (cached && now - cached.at < maxAge) return cached.value;
62
+ const [settings, registration] = await Promise.all([
63
+ deps.settings(account),
64
+ deps.registration(account)
65
+ ]);
66
+ const value = stripeTaxStatusFromSettings(settings, registration);
67
+ if (value.readable) {
68
+ if (statusCache.size >= CACHE_MAX) statusCache.clear();
69
+ statusCache.set(account, {
70
+ at: now,
71
+ value
72
+ });
73
+ } else {
74
+ statusCache.delete(account);
75
+ }
76
+ return value;
77
+ }
78
+ const json = (body, status = 200)=>Response.json(body, {
79
+ status
80
+ });
81
+ const savedMode = (tax)=>{
82
+ const mode = tax == null ? void 0 : tax.mode;
83
+ return mode === 'manual' || mode === 'stripe' || mode === 'none' ? mode : null;
84
+ };
85
+ export async function taxReadinessHandler(request) {
86
+ var _headers_authorization, _ref, _ref1;
87
+ const { method, headers: rawHeaders, query } = await pluginRequestFromWeb(request);
88
+ const headers = rawHeaders;
89
+ if (method !== 'GET') return json({
90
+ error: 'Method not allowed'
91
+ }, 405);
92
+ const authorization = (_headers_authorization = headers.authorization) != null ? _headers_authorization : '';
93
+ const idToken = authorization.startsWith('Bearer ') ? authorization.slice('Bearer '.length) : undefined;
94
+ if (!idToken) return json({
95
+ error: 'Unauthenticated'
96
+ }, 401);
97
+ const hostId = String((_ref = query == null ? void 0 : query['hostId']) != null ? _ref : '');
98
+ if (!hostId) return json({
99
+ error: 'Missing hostId'
100
+ }, 400);
101
+ const fresh = String((_ref1 = query == null ? void 0 : query['fresh']) != null ? _ref1 : '') === '1';
102
+ try {
103
+ var _ref2;
104
+ const decoded = await firebaseAdmin.app().auth().verifyIdToken(idToken);
105
+ if (!decoded.email_verified && !isImpersonationSession(decoded)) {
106
+ return emailUnverifiedResponse();
107
+ }
108
+ const firestore = firebaseAdmin.app().firestore();
109
+ const hostRef = firestore.collection('hosts').doc(hostId);
110
+ const hostSnapshot = await hostRef.get();
111
+ if (!hostSnapshot.exists) return json({
112
+ error: 'Not found'
113
+ }, 404);
114
+ const mayRead = holdsCommerceSiteKey(hostSnapshot, decoded.uid, 'commerce.paymentMethods') || holdsCommerceSiteKey(hostSnapshot, decoded.uid, 'commerce.orders');
115
+ if (!mayRead) return json({
116
+ error: 'Not found'
117
+ }, 404);
118
+ const owner = await getOrgForHost(hostId);
119
+ const locked = await lockdownRefusal({
120
+ request,
121
+ staff: decoded['staff'] === true,
122
+ uid: decoded.uid,
123
+ org: owner == null ? void 0 : owner.org,
124
+ host: hostSnapshot.data()
125
+ });
126
+ if (locked) return locked;
127
+ if (!checkEntitlement((_ref2 = owner == null ? void 0 : owner.org) != null ? _ref2 : {}, 'commerce')) {
128
+ return json({
129
+ error: 'Selling is not included on this plan'
130
+ }, 402);
131
+ }
132
+ const store = await hostRef.collection('settings').doc('store').get();
133
+ const mode = savedMode(store.get('tax'));
134
+ const account = await directSellerAccountForHost(hostId);
135
+ const stripeTax = account ? await cachedSellerStripeTaxStatus(account, {
136
+ fresh
137
+ }) : null;
138
+ const blocked = checkoutTaxBlock({
139
+ mode,
140
+ direct: Boolean(account),
141
+ stripeTax
142
+ });
143
+ let refusedAtMs = null;
144
+ if (blocked) {
145
+ const marker = await readCheckoutTaxRefusal(firestore, hostId);
146
+ refusedAtMs = (marker == null ? void 0 : marker.reason) === blocked && Number.isFinite(Number(marker.lastAtMs)) ? Number(marker.lastAtMs) : null;
147
+ } else {
148
+ // Fixed: the next refusal, if the store ever breaks again, tells the owner again.
149
+ await clearCheckoutTaxRefusal(firestore, hostId);
150
+ }
151
+ const answer = {
152
+ mode,
153
+ direct: Boolean(account),
154
+ stripeTax,
155
+ blocked,
156
+ refusedAtMs
157
+ };
158
+ return json(answer);
159
+ } catch (error) {
160
+ const refused = invalidIdTokenResponse(error);
161
+ if (refused) return refused;
162
+ console.error('[commerce] tax readiness failed', hostId, error);
163
+ return json({
164
+ error: 'Could not check sales tax setup'
165
+ }, 500);
166
+ }
167
+ }
168
+
169
+ //# sourceMappingURL=tax-readiness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/tax-readiness.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { checkEntitlement, pluginRequestFromWeb } from '@aglyn/aglyn/server'\nimport {\n emailUnverifiedResponse,\n firebaseAdmin,\n getOrgForHost,\n isImpersonationSession,\n lockdownRefusal,\n} from '@aglyn/tenant-data-admin'\nimport { invalidIdTokenResponse } from '@aglyn/tenant-data-admin/server/id-token-refusal'\nimport {\n checkoutTaxBlock,\n type SellerStripeTaxStatus,\n type StoreTaxReadiness,\n stripeTaxStatusFromSettings,\n} from '../model/commerce-tax-readiness'\nimport { clearCheckoutTaxRefusal, readCheckoutTaxRefusal } from './checkout-tax-refusal'\nimport { holdsCommerceSiteKey } from './commerce-site-keys'\nimport {\n directSellerAccountForHost,\n fetchSellerStripeTaxSettings,\n sellerHasActiveTaxRegistration,\n} from './seller-stripe-account'\n\n/**\n * Whether sales tax lets shoppers check out (AGL-4245):\n * `GET /api/commerce/tax-readiness?hostId=…[&fresh=1]`, served by the console\n * for the Taxes card and the Payments card's notice.\n *\n * Answers a {@link StoreTaxReadiness}: the saved tax mode, whether the store\n * sells on its own Stripe account, that account's Stripe Tax (read with the\n * same `tax/settings` call checkout makes, plus whether any registration is\n * active), and whether checkout is refusing every shopper because of tax.\n *\n * Reading it as not blocked drops the refusal marker\n * (`checkout-tax-refusal.ts`), which is how the owner's alert clears once a\n * mode is chosen or Stripe Tax is on.\n *\n * Who may ask: whoever may read the payment methods card (works the store's\n * orders, or manages its payment methods). A 404 otherwise, so the route\n * never confirms a site exists.\n */\n\n/** How long one account's Stripe Tax answer is reused, so a card's render does not call Stripe each time. */\nexport const SELLER_STRIPE_TAX_CACHE_MS = 60_000\n/** The shortest gap between two reads that \"Check again\" forces. */\nexport const SELLER_STRIPE_TAX_FRESH_MIN_MS = 5_000\n\nconst statusCache = new Map<string, { at: number; value: SellerStripeTaxStatus }>()\nconst CACHE_MAX = 500\n\n/** Test seam: forget every cached answer. */\nexport function resetSellerStripeTaxCacheForTests(): void {\n statusCache.clear()\n}\n\nexport interface TaxReadinessReadDeps {\n settings(account: string): Promise<Record<string, unknown> | null>\n registration(account: string): Promise<boolean | null>\n now(): number\n}\n\nconst defaultReadDeps: TaxReadinessReadDeps = {\n settings: fetchSellerStripeTaxSettings,\n registration: sellerHasActiveTaxRegistration,\n now: () => Date.now(),\n}\n\n/**\n * The seller's Stripe Tax, cached per account for\n * {@link SELLER_STRIPE_TAX_CACHE_MS}. `fresh` skips the cache unless the\n * cached answer is younger than {@link SELLER_STRIPE_TAX_FRESH_MIN_MS}. An\n * unreadable answer is not cached, so the next paint asks again.\n */\nexport async function cachedSellerStripeTaxStatus(\n account: string,\n options: { fresh?: boolean } = {},\n deps: TaxReadinessReadDeps = defaultReadDeps,\n): Promise<SellerStripeTaxStatus> {\n const now = deps.now()\n const cached = statusCache.get(account)\n const maxAge = options.fresh ? SELLER_STRIPE_TAX_FRESH_MIN_MS : SELLER_STRIPE_TAX_CACHE_MS\n if (cached && now - cached.at < maxAge) return cached.value\n const [settings, registration] = await Promise.all([deps.settings(account), deps.registration(account)])\n const value = stripeTaxStatusFromSettings(settings, registration)\n if (value.readable) {\n if (statusCache.size >= CACHE_MAX) statusCache.clear()\n statusCache.set(account, { at: now, value })\n } else {\n statusCache.delete(account)\n }\n return value\n}\n\nconst json = (body: unknown, status = 200) => Response.json(body, { status })\n\nconst savedMode = (tax: unknown): StoreTaxReadiness['mode'] => {\n const mode = (tax as { mode?: unknown } | null | undefined)?.mode\n return mode === 'manual' || mode === 'stripe' || mode === 'none' ? mode : null\n}\n\nexport async function taxReadinessHandler(request: Request): Promise<Response> {\n const { method, headers: rawHeaders, query } = await pluginRequestFromWeb(request)\n const headers = rawHeaders as Partial<Record<string, string>>\n if (method !== 'GET') return json({ error: 'Method not allowed' }, 405)\n const authorization = headers.authorization ?? ''\n const idToken = authorization.startsWith('Bearer ')\n ? authorization.slice('Bearer '.length)\n : undefined\n if (!idToken) return json({ error: 'Unauthenticated' }, 401)\n const hostId = String(query?.['hostId'] ?? '')\n if (!hostId) return json({ error: 'Missing hostId' }, 400)\n const fresh = String(query?.['fresh'] ?? '') === '1'\n\n try {\n const decoded = await firebaseAdmin.app().auth().verifyIdToken(idToken)\n if (!decoded.email_verified && !isImpersonationSession(decoded)) {\n return emailUnverifiedResponse()\n }\n const firestore = firebaseAdmin.app().firestore()\n const hostRef = firestore.collection('hosts').doc(hostId)\n const hostSnapshot = await hostRef.get()\n if (!hostSnapshot.exists) return json({ error: 'Not found' }, 404)\n const mayRead =\n holdsCommerceSiteKey(hostSnapshot, decoded.uid, 'commerce.paymentMethods') ||\n holdsCommerceSiteKey(hostSnapshot, decoded.uid, 'commerce.orders')\n if (!mayRead) return json({ error: 'Not found' }, 404)\n\n const owner = await getOrgForHost(hostId)\n const locked = await lockdownRefusal({\n request,\n staff: decoded['staff'] === true,\n uid: decoded.uid,\n org: owner?.org,\n host: hostSnapshot.data(),\n })\n if (locked) return locked\n if (!checkEntitlement((owner?.org ?? {}) as never, 'commerce')) {\n return json({ error: 'Selling is not included on this plan' }, 402)\n }\n\n const store = await hostRef.collection('settings').doc('store').get()\n const mode = savedMode(store.get('tax'))\n const account = await directSellerAccountForHost(hostId)\n const stripeTax = account ? await cachedSellerStripeTaxStatus(account, { fresh }) : null\n const blocked = checkoutTaxBlock({ mode, direct: Boolean(account), stripeTax })\n let refusedAtMs: number | null = null\n if (blocked) {\n const marker = await readCheckoutTaxRefusal(firestore, hostId)\n refusedAtMs = marker?.reason === blocked && Number.isFinite(Number(marker.lastAtMs))\n ? Number(marker.lastAtMs)\n : null\n } else {\n // Fixed: the next refusal, if the store ever breaks again, tells the owner again.\n await clearCheckoutTaxRefusal(firestore, hostId)\n }\n const answer: StoreTaxReadiness = { mode, direct: Boolean(account), stripeTax, blocked, refusedAtMs }\n return json(answer)\n } catch (error) {\n const refused = invalidIdTokenResponse(error)\n if (refused) return refused\n console.error('[commerce] tax readiness failed', hostId, error)\n return json({ error: 'Could not check sales tax setup' }, 500)\n }\n}\n"],"names":["checkEntitlement","pluginRequestFromWeb","emailUnverifiedResponse","firebaseAdmin","getOrgForHost","isImpersonationSession","lockdownRefusal","invalidIdTokenResponse","checkoutTaxBlock","stripeTaxStatusFromSettings","clearCheckoutTaxRefusal","readCheckoutTaxRefusal","holdsCommerceSiteKey","directSellerAccountForHost","fetchSellerStripeTaxSettings","sellerHasActiveTaxRegistration","SELLER_STRIPE_TAX_CACHE_MS","SELLER_STRIPE_TAX_FRESH_MIN_MS","statusCache","Map","CACHE_MAX","resetSellerStripeTaxCacheForTests","clear","defaultReadDeps","settings","registration","now","Date","cachedSellerStripeTaxStatus","account","options","deps","cached","get","maxAge","fresh","at","value","Promise","all","readable","size","set","delete","json","body","status","Response","savedMode","tax","mode","taxReadinessHandler","request","headers","method","rawHeaders","query","error","authorization","idToken","startsWith","slice","length","undefined","hostId","String","decoded","app","auth","verifyIdToken","email_verified","firestore","hostRef","collection","doc","hostSnapshot","exists","mayRead","uid","owner","locked","staff","org","host","data","store","stripeTax","blocked","direct","Boolean","refusedAtMs","marker","reason","Number","isFinite","lastAtMs","answer","refused","console"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,EAAEC,oBAAoB,QAAQ,sBAAqB;AAC5E,SACEC,uBAAuB,EACvBC,aAAa,EACbC,aAAa,EACbC,sBAAsB,EACtBC,eAAe,QACV,2BAA0B;AACjC,SAASC,sBAAsB,QAAQ,mDAAkD;AACzF,SACEC,gBAAgB,EAGhBC,2BAA2B,QACtB,qCAAiC;AACxC,SAASC,uBAAuB,EAAEC,sBAAsB,QAAQ,4BAAwB;AACxF,SAASC,oBAAoB,QAAQ,0BAAsB;AAC3D,SACEC,0BAA0B,EAC1BC,4BAA4B,EAC5BC,8BAA8B,QACzB,6BAAyB;AAEhC;;;;;;;;;;;;;;;;;CAiBC,GAED,2GAA2G,GAC3G,OAAO,MAAMC,6BAA6B,MAAM;AAChD,kEAAkE,GAClE,OAAO,MAAMC,iCAAiC,KAAK;AAEnD,MAAMC,cAAc,IAAIC;AACxB,MAAMC,YAAY;AAElB,2CAA2C,GAC3C,OAAO,SAASC;IACdH,YAAYI,KAAK;AACnB;AAQA,MAAMC,kBAAwC;IAC5CC,UAAUV;IACVW,cAAcV;IACdW,KAAK,IAAMC,KAAKD,GAAG;AACrB;AAEA;;;;;CAKC,GACD,OAAO,eAAeE,4BACpBC,OAAe,EACfC,UAA+B,CAAC,CAAC,EACjCC,OAA6BR,eAAe;IAE5C,MAAMG,MAAMK,KAAKL,GAAG;IACpB,MAAMM,SAASd,YAAYe,GAAG,CAACJ;IAC/B,MAA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MJ,UAAU,MAAMhB,2BAA2BmD;QACjD,MAAMsB,YAAYzD,UAAU,MAAMD,4BAA4BC,SAAS;YAAEM;QAAM,KAAK;QACpF,MAAMoD,UAAU/E,iBAAiB;YAAE0C;YAAMsC,QAAQC,QAAQ5D;YAAUyD;QAAU;QAC7E,IAAII,cAA6B;QACjC,IAAIH,SAAS;YACX,MAAMI,SAAS,MAAMhF,uBAAuB4D,WAAWP;YACvD0B,cAAcC,CAAAA,0BAAAA,OAAQC,MAAM,MAAKL,WAAWM,OAAOC,QAAQ,CAACD,OAAOF,OAAOI,QAAQ,KAC9EF,OAAOF,OAAOI,QAAQ,IACtB;QACN,OAAO;YACL,kFAAkF;YAClF,MAAMrF,wBAAwB6D,WAAWP;QAC3C;QACA,MAAMgC,SAA4B;YAAE9C;YAAMsC,QAAQC,QAAQ5D;YAAUyD;YAAWC;YAASG;QAAY;QACpG,OAAO9C,KAAKoD;IACd,EAAE,OAAOvC,OAAO;QACd,MAAMwC,UAAU1F,uBAAuBkD;QACvC,IAAIwC,SAAS,OAAOA;QACpBC,QAAQzC,KAAK,CAAC,mCAAmCO,QAAQP;QACzD,OAAOb,KAAK;YAAEa,OAAO;QAAkC,GAAG;IAC5D;AACF"}
package/src/lib/server.js CHANGED
@@ -20,7 +20,7 @@
20
20
  * pulls in firebase-admin + Stripe, so it is NOT re-exported from the client
21
21
  * barrel — apps import `@aglyn/plugins-commerce/server` only from their
22
22
  * (server-only) API dispatcher registration.
23
- */ import { registerBillingWebhookHandler, registerPluginApiRoute, registerPluginJob, registerSitePageEnricher, registerSitePageResolver, registerPluginPermissions, registerPluginConfigSchema } from "@aglyn/aglyn/server";
23
+ */ import { registerBillingWebhookHandler, registerPluginApiRoute, registerPluginJob, registerSitePageEnricher, registerSiteEditContextResolver, registerSitePageResolver, registerPluginPermissions, registerPluginConfigSchema } from "@aglyn/aglyn/server";
24
24
  import { isEmailConfigured } from "@aglyn/shared-util-email";
25
25
  import { firebaseAdmin } from "@aglyn/tenant-data-admin";
26
26
  import { BUNDLE_ID } from "./constants/bundle-common.js";
@@ -42,7 +42,7 @@ import { registerOrderFigureReaders } from "./server/order-figures.js";
42
42
  import { COMMERCE_PERMISSIONS } from "./model/plugin-permissions.js";
43
43
  import { COMMERCE_CONFIG_SCHEMA } from "./plugin-config.js";
44
44
  import { commerceSitePageEnricher } from "./server/site-page-enricher.js";
45
- import { commerceSitePageResolver } from "./server/site-page-resolver.js";
45
+ import { commerceEditContextResolver, commerceSitePageResolver } from "./server/site-page-resolver.js";
46
46
  import { cartCheckoutHandler } from "./server/cart-checkout.js";
47
47
  import { cartHandler } from "./server/cart.js";
48
48
  import { cartExtrasHandler } from "./server/checkout-extras.js";
@@ -366,6 +366,8 @@ registerPluginJob({
366
366
  registerPluginConfigSchema(COMMERCE_CONFIG_SCHEMA);
367
367
  // PDP/PLP template pages (AGL-418): /products/* + /collections/*.
368
368
  registerSitePageResolver(commerceSitePageResolver);
369
+ // What the admin edit bar names those pages, and where it edits them.
370
+ registerSiteEditContextResolver(commerceEditContextResolver);
369
371
  // Seeds product grids on ordinary screens (AGL-659) — the resolver above
370
372
  // only covers /products/* and /collections/*, so /products itself, and any
371
373
  // designed page with a grid on it, needed this to render server-side.
@@ -611,6 +613,12 @@ export function registerCommerceConsoleApi() {
611
613
  registerPluginApiRoute('commerce/payment-methods', {
612
614
  web: async (request)=>(await import("./server/payment-methods.js")).paymentMethodsHandler(request)
613
615
  });
616
+ // Whether sales tax lets shoppers check out (AGL-4245): the store's own
617
+ // Stripe Tax and the tax choice, for the Taxes and Payments cards. Loaded
618
+ // with the first request.
619
+ registerPluginApiRoute('commerce/tax-readiness', {
620
+ web: async (request)=>(await import("./server/tax-readiness.js")).taxReadinessHandler(request)
621
+ });
614
622
  // A smart collection's rules changed or it was deleted: re-stamp which
615
623
  // products it holds (AGL-3321), the membership the storefront queries.
616
624
  registerPluginApiRoute('commerce/collection-membership', collectionMembershipHandler);