@aglyn/plugins-commerce 1.17.0 → 1.19.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.
@@ -0,0 +1,40 @@
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
+ * WHICH PRODUCT A PRODUCT-PAGE TEMPLATE PREVIEWS (AGL-4211), in its own chunk:
18
+ * only Preview of a Product detail block with no product pinned loads it.
19
+ *
20
+ * On a live site such a block takes its product from the `/products/{slug}`
21
+ * address. Preview has none, so the template drew a skeleton that never
22
+ * resolved. It shows the store's first listed product instead.
23
+ */ /**
24
+ * The slug of the store's first listed product, or `''` when it lists none
25
+ * (the block then shows its sample). Reads the same public catalog a product
26
+ * grid does, so a product Preview could not sell is never shown.
27
+ */ export async function firstListedProductSlug(hostId, read = (input)=>fetch(input)) {
28
+ try {
29
+ var _payload_items_, _payload_items;
30
+ const response = await read(`/api/commerce/catalog?hostId=${encodeURIComponent(hostId)}&limit=1`);
31
+ if (!response.ok) return '';
32
+ const payload = await response.json();
33
+ const slug = payload == null ? void 0 : (_payload_items = payload.items) == null ? void 0 : (_payload_items_ = _payload_items[0]) == null ? void 0 : _payload_items_.slug;
34
+ return typeof slug === 'string' ? slug : '';
35
+ } catch (unused) {
36
+ return '';
37
+ }
38
+ }
39
+
40
+ //# sourceMappingURL=product-preview-slug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/product-preview-slug.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\n/*\n * WHICH PRODUCT A PRODUCT-PAGE TEMPLATE PREVIEWS (AGL-4211), in its own chunk:\n * only Preview of a Product detail block with no product pinned loads it.\n *\n * On a live site such a block takes its product from the `/products/{slug}`\n * address. Preview has none, so the template drew a skeleton that never\n * resolved. It shows the store's first listed product instead.\n */\n\n/**\n * The slug of the store's first listed product, or `''` when it lists none\n * (the block then shows its sample). Reads the same public catalog a product\n * grid does, so a product Preview could not sell is never shown.\n */\nexport async function firstListedProductSlug(\n hostId: string,\n read: (input: string) => Promise<Response> = (input) => fetch(input),\n): Promise<string> {\n try {\n const response = await read(`/api/commerce/catalog?hostId=${encodeURIComponent(hostId)}&limit=1`)\n if (!response.ok) return ''\n const payload = (await response.json()) as { items?: Array<{ slug?: unknown }> }\n const slug = payload?.items?.[0]?.slug\n return typeof slug === 'string' ? slug : ''\n } catch {\n return ''\n }\n}\n"],"names":["firstListedProductSlug","hostId","read","input","fetch","payload","response","encodeURIComponent","ok","json","slug","items"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;CAOC,GAED;;;;CAIC,GACD,OAAO,eAAeA,uBACpBC,MAAc,EACdC,OAA6C,CAACC,QAAUC,MAAMD,MAAM;IAEpE,IAAI;YAIWE,iBAAAA;QAHb,MAAMC,WAAW,MAAMJ,KAAK,CAAC,6BAA6B,EAAEK,mBAAmBN,QAAQ,QAAQ,CAAC;QAChG,IAAI,CAACK,SAASE,EAAE,EAAE,OAAO;QACzB,MAAMH,UAAW,MAAMC,SAASG,IAAI;QACpC,MAAMC,OAAOL,4BAAAA,iBAAAA,QAASM,KAAK,sBAAdN,kBAAAA,cAAgB,CAAC,EAAE,qBAAnBA,gBAAqBK,IAAI;QACtC,OAAO,OAAOA,SAAS,WAAWA,OAAO;IAC3C,EAAE,eAAM;QACN,OAAO;IACT;AACF"}
@@ -17,6 +17,7 @@
17
17
  import { type PluginApiHandler, type PluginApiRequest } from '@aglyn/aglyn/server';
18
18
  import { type PluginPersonRecord, type PluginPersonSearchRequest } from '@aglyn/aglyn/plugin-manager/plugin-person-records';
19
19
  import { type PluginRecordFactsRead, type PluginRecordFactsRequest } from '@aglyn/aglyn/plugin-manager/plugin-record-facts';
20
+ import { type PaymentMode } from '@aglyn/tenant-data-admin/server/payment-provider';
20
21
  import { type SaleTaxEngineRequest, type SaleTaxEngineResult } from './tax-engine-quote';
21
22
  import { type CheckoutSessionExpiry } from './checkout-session-expiry';
22
23
  import type { quotePdfFile } from './commerce-pdf';
@@ -70,6 +71,8 @@ export interface QuoteDeps {
70
71
  }): Promise<{
71
72
  id: string;
72
73
  } | null>;
74
+ /** This deployment's payment mode, from its own credential; absent, the provider's answer. */
75
+ platformMode?(): PaymentMode | undefined;
73
76
  now(): number;
74
77
  }
75
78
  export declare function defaultQuoteDeps(): QuoteDeps;
@@ -23,6 +23,7 @@ import { searchPluginPeople } from "@aglyn/aglyn/plugin-manager/plugin-person-re
23
23
  import { pluginRecordFactsReader } from "@aglyn/aglyn/plugin-manager/plugin-record-facts";
24
24
  import { firebaseAdmin, getOrgForHost } from "@aglyn/tenant-data-admin";
25
25
  import { isRefusedIdToken } from "@aglyn/tenant-data-admin/server/id-token-refusal";
26
+ import { merchantAccountReadiness, paymentProvider } from "@aglyn/tenant-data-admin/server/payment-provider";
26
27
  import * as CommerceModel from "../model/index.js";
27
28
  import { commerceSitePermissionRefusal } from "../model/plugin-permissions.js";
28
29
  import { holdsCommerceSiteKey } from "./commerce-site-keys.js";
@@ -56,6 +57,7 @@ export function defaultQuoteDeps() {
56
57
  return (_ref = await ((_pluginRecordFactsReader = pluginRecordFactsReader(CommerceModel.QUOTE_REQUEST_FACTS_RESOURCE)) == null ? void 0 : _pluginRecordFactsReader.reader.read(request))) != null ? _ref : null;
57
58
  },
58
59
  customerAccount: async (input)=>(await import("./quote-pay.js")).readQuoteCustomerAccount(input),
60
+ platformMode: ()=>paymentProvider().platformMode(),
59
61
  now: ()=>Date.now()
60
62
  };
61
63
  }
@@ -247,6 +249,25 @@ const SEND_ACTIONS = new Set([
247
249
  shipping: input.shipping
248
250
  };
249
251
  }
252
+ /**
253
+ * Whether the site's workspace can take card payments, for an app's "Customers can't pay this quote online yet."
254
+ * notice (AGL-4162). It reads the workspace OWNER's profile, as the console's `useMerchantPayments` and every money
255
+ * route do, and answers with `merchantAccountReadiness`, the check the console's copy has to agree with. The server
256
+ * knows this deployment's payment mode, which an app cannot, so a live deployment's unverified account answers
257
+ * `mode-unverified` here exactly as it does in the console.
258
+ */ async function ownerPaymentsReadiness(deps, hostId) {
259
+ var _owner_org;
260
+ const owner = await deps.orgForHost(hostId);
261
+ const ownerUid = owner == null ? void 0 : (_owner_org = owner.org) == null ? void 0 : _owner_org.ownerUid;
262
+ if (typeof ownerUid !== 'string' || !ownerUid) return 'not-connected';
263
+ const profile = await deps.firestore().collection('profiles').doc(ownerUid).get();
264
+ return merchantAccountReadiness({
265
+ accountId: profile.get('stripeAccountId'),
266
+ chargesEnabled: profile.get('stripeChargesEnabled'),
267
+ accountLivemode: profile.get('stripeAccountLivemode'),
268
+ platformMode: deps.platformMode ? deps.platformMode() : paymentProvider().platformMode()
269
+ });
270
+ }
250
271
  export async function handleQuote(deps, req) {
251
272
  var _body_hostId, _body_action, _body_quoteId, _body_from, _ref;
252
273
  if (req.method !== 'POST') return refuse(405, 'Method not allowed');
@@ -273,6 +294,14 @@ export async function handleQuote(deps, req) {
273
294
  return refuse(403, commerceSitePermissionRefusal(key));
274
295
  }
275
296
  const actor = String(decoded.email || decoded.uid);
297
+ if (action === 'payments-readiness') {
298
+ return {
299
+ status: 200,
300
+ body: {
301
+ state: await ownerPaymentsReadiness(deps, hostId)
302
+ }
303
+ };
304
+ }
276
305
  if (action === 'pay-link' || action === 'replace-link') {
277
306
  var _body_quoteId1, _host_data;
278
307
  const quoteId = String((_body_quoteId1 = body['quoteId']) != null ? _body_quoteId1 : '');