@aglyn/plugins-commerce 1.10.0 → 1.12.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 +13 -13
- package/src/lib/components/console/host-quotes-card.component.js +20 -11
- package/src/lib/components/console/host-quotes-card.component.js.map +1 -1
- package/src/lib/components/console/invoice-send.component.d.ts +9 -2
- package/src/lib/components/console/invoice-send.component.js +58 -30
- package/src/lib/components/console/invoice-send.component.js.map +1 -1
- package/src/lib/components/console/pay-link-readiness-notice.component.d.ts +84 -0
- package/src/lib/components/console/pay-link-readiness-notice.component.js +164 -0
- package/src/lib/components/console/pay-link-readiness-notice.component.js.map +1 -0
- package/src/lib/components/console/pos-kiosk/kiosk-menu.d.ts +10 -3
- package/src/lib/components/console/pos-kiosk/kiosk-menu.js +29 -8
- package/src/lib/components/console/pos-kiosk/kiosk-menu.js.map +1 -1
- package/src/lib/components/console/pos-kiosk/pos-kiosk-api.d.ts +2 -0
- package/src/lib/components/console/pos-kiosk/pos-kiosk-api.js +7 -0
- package/src/lib/components/console/pos-kiosk/pos-kiosk-api.js.map +1 -1
- package/src/lib/components/console/pos-kiosk-page.component.d.ts +2 -0
- package/src/lib/components/console/pos-kiosk-page.component.js +54 -3
- package/src/lib/components/console/pos-kiosk-page.component.js.map +1 -1
- package/src/lib/components/console/product-add-ons-fields.component.d.ts +0 -2
- package/src/lib/components/console/product-add-ons-fields.component.js +1 -6
- package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
- package/src/lib/components/console/quote-editor-dialog.component.d.ts +2 -0
- package/src/lib/components/console/quote-editor-dialog.component.js +35 -27
- package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-pay-link.component.d.ts +3 -0
- package/src/lib/components/console/quote-pay-link.component.js +9 -0
- package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
- package/src/lib/components/console/quote-send.component.d.ts +3 -0
- package/src/lib/components/console/quote-send.component.js +9 -0
- package/src/lib/components/console/quote-send.component.js.map +1 -1
- package/src/lib/components/product-detail.js +1 -1
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.js +5 -3
- package/src/lib/components/product-grid.js.map +1 -1
- package/src/lib/components/product-reviews.js +17 -12
- package/src/lib/components/product-reviews.js.map +1 -1
- package/src/lib/components/quote-page-body.js +5 -3
- package/src/lib/components/quote-page-body.js.map +1 -1
- package/src/lib/components/related-products.js +2 -1
- package/src/lib/components/related-products.js.map +1 -1
- package/src/lib/model/commerce-invoices.d.ts +45 -5
- package/src/lib/model/commerce-invoices.js +46 -9
- package/src/lib/model/commerce-invoices.js.map +1 -1
- package/src/lib/model/commerce-kiosk-search.d.ts +22 -0
- package/src/lib/model/commerce-kiosk-search.js +32 -0
- package/src/lib/model/commerce-kiosk-search.js.map +1 -0
- package/src/lib/model/commerce-pos-kiosk.d.ts +7 -1
- package/src/lib/model/commerce-pos-kiosk.js +1 -1
- package/src/lib/model/commerce-pos-kiosk.js.map +1 -1
- package/src/lib/model/commerce-quote-pay.d.ts +110 -6
- package/src/lib/model/commerce-quote-pay.js +182 -23
- package/src/lib/model/commerce-quote-pay.js.map +1 -1
- package/src/lib/model/product-modifiers.d.ts +4 -0
- package/src/lib/model/product-modifiers.js +5 -0
- package/src/lib/model/product-modifiers.js.map +1 -1
- package/src/lib/server/billing-webhook.js +4 -1
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/commerce-pdf.js +2 -1
- package/src/lib/server/commerce-pdf.js.map +1 -1
- package/src/lib/server/invoice-email.js +2 -1
- package/src/lib/server/invoice-email.js.map +1 -1
- package/src/lib/server/order-invoice-send.js +1 -1
- package/src/lib/server/order-invoice-send.js.map +1 -1
- package/src/lib/server/order-status.d.ts +5 -1
- package/src/lib/server/order-status.js +19 -5
- package/src/lib/server/order-status.js.map +1 -1
- package/src/lib/server/pos-kiosk.js +70 -15
- package/src/lib/server/pos-kiosk.js.map +1 -1
- package/src/lib/server/quote-email.js +2 -1
- package/src/lib/server/quote-email.js.map +1 -1
- package/src/lib/server/quote-pay.d.ts +39 -0
- package/src/lib/server/quote-pay.js +103 -43
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/quote-proofs.js +20 -11
- package/src/lib/server/quote-proofs.js.map +1 -1
- package/src/lib/server/site-page-enricher.js +5 -1
- package/src/lib/server/site-page-enricher.js.map +1 -1
- package/src/lib/testing/fake-firestore.js +34 -5
- package/src/lib/testing/fake-firestore.js.map +1 -1
- package/src/lib/transfer/product-register-cells.d.ts +75 -0
- package/src/lib/transfer/product-register-cells.js +487 -0
- package/src/lib/transfer/product-register-cells.js.map +1 -0
- package/src/lib/transfer/product-transfer.d.ts +12 -0
- package/src/lib/transfer/product-transfer.js +174 -10
- package/src/lib/transfer/product-transfer.js.map +1 -1
- package/src/lib/transfer/products.server.js +24 -9
- package/src/lib/transfer/products.server.js.map +1 -1
- package/src/lib/utils/invoice-email-content.d.ts +3 -1
- package/src/lib/utils/invoice-email-content.js +1 -1
- package/src/lib/utils/invoice-email-content.js.map +1 -1
- package/src/lib/utils/quote-email-content.d.ts +3 -1
- package/src/lib/utils/quote-email-content.js +3 -3
- package/src/lib/utils/quote-email-content.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/site-page-enricher.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 type { SitePageEnricher } from '@aglyn/aglyn/server'\nimport {\n createCatalogReadScope,\n queryPublicCatalog,\n type PublicCatalogResult,\n} from './catalog'\n\n/** Component id of the block this enricher seeds; persisted, never renamed. */\nconst PRODUCT_GRID_ID = 'product-grid'\n\n/**\n * Grids seeded per page. A page with a dozen grids would turn one render\n * into a dozen catalog reads, so the walk stops after this many — the rest\n * fetch client-side exactly as they did before, which is a slower first\n * paint rather than a broken page.\n */\nconst MAX_SEEDED_GRIDS = 4\n\ninterface GridProps {\n source?: 'all' | 'collection' | 'category' | 'tag'\n collectionId?: string\n collectionSlug?: string\n categoryId?: string\n categorySlug?: string\n tag?: string\n sort?: string\n maxItems?: number | string\n pageSize?: number | string\n showCategories?: boolean\n showPriceFilter?: boolean\n}\n\ninterface ComposedNode {\n $id?: string\n componentId?: string\n props?: Record<string, unknown>\n resolvedProps?: Record<string, unknown>\n /** Child node IDS — denormalized nodes do not nest (see below). */\n nodes?: string[]\n}\n\n/**\n * Every product-grid node on the page.\n *\n * `composeScreenNodes` returns `Record<string, node>` — a DENORMALIZED FLAT\n * MAP keyed by node id, whose children are id STRINGS in `nodes`. It does not\n * return a tree, and there is no `children` array anywhere in it.\n *\n * The first version of this walked `children` recursively and therefore\n * matched nothing at all, on any page. It shipped green because the unit\n * tests fed it a nested fixture — the fixture encoded the assumption instead\n * of the actual contract, so the tests only ever proved the walker was\n * self-consistent. Iterating the map's values is both correct and simpler;\n * the flat shape means no recursion is needed.\n *\n * Sorted by id so that the MAX_SEEDED_GRIDS cap takes a deterministic subset\n * rather than whichever ones the map happened to enumerate first.\n */\nfunction collectGridNodes(nodes: unknown): ComposedNode[] {\n if (!nodes || typeof nodes !== 'object') return []\n const found: ComposedNode[] = []\n for (const value of Object.values(nodes as Record<string, unknown>)) {\n if (!value || typeof value !== 'object' || Array.isArray(value)) continue\n const shaped = value as ComposedNode\n if (shaped.componentId === PRODUCT_GRID_ID && shaped.$id) {\n found.push(shaped)\n }\n }\n return found.sort((a, b) => String(a.$id).localeCompare(String(b.$id)))\n}\n\n/** Positive integer from a props value that may arrive as a string. */\nfunction positiveInt(value: unknown): number | undefined {\n const parsed = Number(value)\n if (!Number.isFinite(parsed) || parsed <= 0) return undefined\n return Math.floor(parsed)\n}\n\n/**\n * The collection slug a grid on a `/collections/{slug}` page follows when\n * it has no pinned collection — the server-side twin of the grid's\n * `collectionSlugFromLocation()`, which reads `window.location`.\n */\nfunction collectionSlugFromPath(path: string): string {\n const match = path.match(/\\/collections\\/([^/?#]+)/)\n return match ? decodeURIComponent(match[1]) : ''\n}\n\n/**\n * Seeds each product grid's FIRST, UNFILTERED page (AGL-659).\n *\n * `/products` shipped 11KB of HTML with zero words in it: the grid fetches\n * its catalog in a `useEffect`, so the server rendered skeleton cards and\n * crawlers indexed an empty shell. The fix is to run the same query on the\n * server and hand the result down through `pageData`.\n *\n * Three things this deliberately does NOT do:\n *\n * - It does not seed anything the visitor can change. Search text, category\n * chips, type chips and the price slider all start empty on mount, so a\n * props-derived query is exactly what the grid's own first fetch would\n * send. Seed a filtered page and SSR would disagree with hydration.\n * - It does not seed later pages. Load more still goes to the API.\n * - It does not share one slice between grids. Seeds are keyed by node id,\n * because a collection-scoped grid and an all-products grid on the same\n * page must not receive each other's items — wrong products would get\n * indexed and visibly swap on hydrate.\n *\n * Failures are swallowed by the enricher runner, and the grid falls back to\n * fetching. A catalog read that errors must not take a page down.\n */\nexport const commerceSitePageEnricher: SitePageEnricher = async ({\n hostId,\n path,\n nodes,\n}) => {\n const grids = collectGridNodes(nodes).slice(0, MAX_SEEDED_GRIDS)\n if (!grids.length) return undefined\n\n const seeds: Record<string, PublicCatalogResult> = {}\n // One scope for this render, so grids asking the same question share one\n // catalog query, and each different question reads only its own page\n // (AGL-3321) — the seeds stay keyed by node id.\n const reads = createCatalogReadScope()\n await Promise.all(\n grids.map(async (node) => {\n const props = (node.resolvedProps ??\n node.props ??\n {}) as unknown as GridProps\n const source = props.source ?? 'all'\n // Ids first (rename-safe, AGL-343), slugs as the legacy path — the\n // same precedence the grid applies when it builds its own params.\n const collectionSlug =\n source === 'collection'\n ? props.collectionSlug || collectionSlugFromPath(path)\n : props.collectionSlug\n const pageLimit = positiveInt(props.pageSize)\n const limit = pageLimit ?? positiveInt(props.maxItems)\n\n try {\n const result = await queryPublicCatalog({\n hostId,\n ...(source === 'collection'\n ? props.collectionId\n ? { collectionId: props.collectionId }\n : collectionSlug\n ? { collectionSlug }\n : {}\n : {}),\n ...(source === 'category'\n ? props.categoryId\n ? { categoryId: props.categoryId }\n : props.categorySlug\n ? { categorySlug: props.categorySlug }\n : {}\n : {}),\n ...(source === 'tag' && props.tag ? { tag: props.tag } : {}),\n ...(props.sort ? { sort: props.sort } : {}),\n ...(limit ? { limit } : {}),\n // Facets ride along only when a control needs them, matching the\n // grid's `facets=1` condition on its first request.\n facets: Boolean(props.showCategories || props.showPriceFilter),\n reads,\n })\n seeds[node.$id as string] = result\n } catch (error) {\n // One grid failing leaves the others seeded; this one fetches.\n console.error('commerce grid seed failed', node.$id, error)\n }\n }),\n )\n\n if (!Object.keys(seeds).length) return undefined\n\n return {\n // Merged shallowly into the page props, so this key is the whole\n // `pageData` for a screen page. Screens never reach a page resolver\n // (the loader returns a resolver's answer before enrichers run), so\n // there is no resolver-written pageData here to preserve.\n pageData: { commerce: { grids: seeds } },\n }\n}\n\nexport default commerceSitePageEnricher\n"],"names":["createCatalogReadScope","queryPublicCatalog","PRODUCT_GRID_ID","MAX_SEEDED_GRIDS","collectGridNodes","nodes","found","value","Object","values","Array","isArray","shaped","componentId","$id","push","sort","a","b","String","localeCompare","positiveInt","parsed","Number","isFinite","undefined","Math","floor","collectionSlugFromPath","path","match","decodeURIComponent","commerceSitePageEnricher","hostId","grids","slice","length","seeds","reads","Promise","all","map","node","props","resolvedProps","source","collectionSlug","pageLimit","pageSize","limit","maxItems","result","collectionId","categoryId","categorySlug","tag","facets","Boolean","showCategories","showPriceFilter","error","console","keys","pageData","commerce"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SACEA,sBAAsB,EACtBC,kBAAkB,QAEb,eAAW;AAElB,6EA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I,CAACpD,OAAOsD,IAAI,CAACzB,OAAOD,MAAM,EAAE,OAAOX;IAEvC,OAAO;QACL,iEAAiE;QACjE,oEAAoE;QACpE,oEAAoE;QACpE,0DAA0D;QAC1DsC,UAAU;YAAEC,UAAU;gBAAE9B,OAAOG;YAAM;QAAE;IACzC;AACF,EAAC;AAED,eAAeL,yBAAwB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/site-page-enricher.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 type { SitePageEnricher } from '@aglyn/aglyn/server'\nimport {\n createCatalogReadScope,\n queryPublicCatalog,\n type PublicCatalogResult,\n} from './catalog'\n\n/** Component id of the block this enricher seeds; persisted, never renamed. */\nconst PRODUCT_GRID_ID = 'product-grid'\n\n/**\n * Grids seeded per page. A page with a dozen grids would turn one render\n * into a dozen catalog reads, so the walk stops after this many — the rest\n * fetch client-side exactly as they did before, which is a slower first\n * paint rather than a broken page.\n */\nconst MAX_SEEDED_GRIDS = 4\n\ninterface GridProps {\n source?: 'all' | 'collection' | 'category' | 'tag'\n collectionId?: string\n collectionSlug?: string\n categoryId?: string\n categorySlug?: string\n tag?: string\n sort?: string\n maxItems?: number | string\n pageSize?: number | string\n showCategories?: boolean\n showPriceFilter?: boolean\n}\n\ninterface ComposedNode {\n $id?: string\n componentId?: string\n props?: Record<string, unknown>\n resolvedProps?: Record<string, unknown>\n /** Child node IDS — denormalized nodes do not nest (see below). */\n nodes?: string[]\n}\n\n/**\n * Every product-grid node on the page.\n *\n * `composeScreenNodes` returns `Record<string, node>` — a DENORMALIZED FLAT\n * MAP keyed by node id, whose children are id STRINGS in `nodes`. It does not\n * return a tree, and there is no `children` array anywhere in it.\n *\n * The first version of this walked `children` recursively and therefore\n * matched nothing at all, on any page. It shipped green because the unit\n * tests fed it a nested fixture — the fixture encoded the assumption instead\n * of the actual contract, so the tests only ever proved the walker was\n * self-consistent. Iterating the map's values is both correct and simpler;\n * the flat shape means no recursion is needed.\n *\n * Sorted by id so that the MAX_SEEDED_GRIDS cap takes a deterministic subset\n * rather than whichever ones the map happened to enumerate first.\n */\nfunction collectGridNodes(nodes: unknown): ComposedNode[] {\n if (!nodes || typeof nodes !== 'object') return []\n const found: ComposedNode[] = []\n for (const value of Object.values(nodes as Record<string, unknown>)) {\n if (!value || typeof value !== 'object' || Array.isArray(value)) continue\n const shaped = value as ComposedNode\n if (shaped.componentId === PRODUCT_GRID_ID && shaped.$id) {\n found.push(shaped)\n }\n }\n return found.sort((a, b) => String(a.$id).localeCompare(String(b.$id)))\n}\n\n/** Positive integer from a props value that may arrive as a string. */\nfunction positiveInt(value: unknown): number | undefined {\n const parsed = Number(value)\n if (!Number.isFinite(parsed) || parsed <= 0) return undefined\n return Math.floor(parsed)\n}\n\n/**\n * The collection slug a grid on a `/collections/{slug}` page follows when\n * it has no pinned collection — the server-side twin of the grid's\n * `collectionSlugFromLocation()`, which reads `window.location`.\n *\n * The tenant's path has NO leading slash (`collections/bread`, it is the slug\n * segments joined). Requiring one seeded every collection page with the whole\n * catalog, and a seeded grid never refetches (AGL-4177).\n */\nfunction collectionSlugFromPath(path: string): string {\n const match = path.match(/(?:^|\\/)collections\\/([^/?#]+)/)\n return match ? decodeURIComponent(match[1]) : ''\n}\n\n/**\n * Seeds each product grid's FIRST, UNFILTERED page (AGL-659).\n *\n * `/products` shipped 11KB of HTML with zero words in it: the grid fetches\n * its catalog in a `useEffect`, so the server rendered skeleton cards and\n * crawlers indexed an empty shell. The fix is to run the same query on the\n * server and hand the result down through `pageData`.\n *\n * Three things this deliberately does NOT do:\n *\n * - It does not seed anything the visitor can change. Search text, category\n * chips, type chips and the price slider all start empty on mount, so a\n * props-derived query is exactly what the grid's own first fetch would\n * send. Seed a filtered page and SSR would disagree with hydration.\n * - It does not seed later pages. Load more still goes to the API.\n * - It does not share one slice between grids. Seeds are keyed by node id,\n * because a collection-scoped grid and an all-products grid on the same\n * page must not receive each other's items — wrong products would get\n * indexed and visibly swap on hydrate.\n *\n * Failures are swallowed by the enricher runner, and the grid falls back to\n * fetching. A catalog read that errors must not take a page down.\n */\nexport const commerceSitePageEnricher: SitePageEnricher = async ({\n hostId,\n path,\n nodes,\n}) => {\n const grids = collectGridNodes(nodes).slice(0, MAX_SEEDED_GRIDS)\n if (!grids.length) return undefined\n\n const seeds: Record<string, PublicCatalogResult> = {}\n // One scope for this render, so grids asking the same question share one\n // catalog query, and each different question reads only its own page\n // (AGL-3321) — the seeds stay keyed by node id.\n const reads = createCatalogReadScope()\n await Promise.all(\n grids.map(async (node) => {\n const props = (node.resolvedProps ??\n node.props ??\n {}) as unknown as GridProps\n const source = props.source ?? 'all'\n // Ids first (rename-safe, AGL-343), slugs as the legacy path — the\n // same precedence the grid applies when it builds its own params.\n const collectionSlug =\n source === 'collection'\n ? props.collectionSlug || collectionSlugFromPath(path)\n : props.collectionSlug\n const pageLimit = positiveInt(props.pageSize)\n const limit = pageLimit ?? positiveInt(props.maxItems)\n\n try {\n const result = await queryPublicCatalog({\n hostId,\n ...(source === 'collection'\n ? props.collectionId\n ? { collectionId: props.collectionId }\n : collectionSlug\n ? { collectionSlug }\n : {}\n : {}),\n ...(source === 'category'\n ? props.categoryId\n ? { categoryId: props.categoryId }\n : props.categorySlug\n ? { categorySlug: props.categorySlug }\n : {}\n : {}),\n ...(source === 'tag' && props.tag ? { tag: props.tag } : {}),\n ...(props.sort ? { sort: props.sort } : {}),\n ...(limit ? { limit } : {}),\n // Facets ride along only when a control needs them, matching the\n // grid's `facets=1` condition on its first request.\n facets: Boolean(props.showCategories || props.showPriceFilter),\n reads,\n })\n seeds[node.$id as string] = result\n } catch (error) {\n // One grid failing leaves the others seeded; this one fetches.\n console.error('commerce grid seed failed', node.$id, error)\n }\n }),\n )\n\n if (!Object.keys(seeds).length) return undefined\n\n return {\n // Merged shallowly into the page props, so this key is the whole\n // `pageData` for a screen page. Screens never reach a page resolver\n // (the loader returns a resolver's answer before enrichers run), so\n // there is no resolver-written pageData here to preserve.\n pageData: { commerce: { grids: seeds } },\n }\n}\n\nexport default commerceSitePageEnricher\n"],"names":["createCatalogReadScope","queryPublicCatalog","PRODUCT_GRID_ID","MAX_SEEDED_GRIDS","collectGridNodes","nodes","found","value","Object","values","Array","isArray","shaped","componentId","$id","push","sort","a","b","String","localeCompare","positiveInt","parsed","Number","isFinite","undefined","Math","floor","collectionSlugFromPath","path","match","decodeURIComponent","commerceSitePageEnricher","hostId","grids","slice","length","seeds","reads","Promise","all","map","node","props","resolvedProps","source","collectionSlug","pageLimit","pageSize","limit","maxItems","result","collectionId","categoryId","categorySlug","tag","facets","Boolean","showCategories","showPriceFilter","error","console","keys","pageData","commerce"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SACEA,sBAAsB,EACtBC,kBAAkB,QAEb,eAAW;AAElB,6EAA6E,GAC7E,MAAMC,kBAAkB;AAExB;;;;;CAKC,GACD,MAAMC,mBAAmB;AAyBzB;;;;;;;;;;;;;;;;CAgBC,GACD,SAASC,iBAAiBC,KAAc;IACtC,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU,OAAO,EAAE;IAClD,MAAMC,QAAwB,EAAE;IAChC,KAAK,MAAMC,SAASC,OAAOC,MAAM,CAACJ,OAAmC;QACnE,IAAI,CAACE,SAAS,OAAOA,UAAU,YAAYG,MAAMC,OAAO,CAACJ,QAAQ;QACjE,MAAMK,SAASL;QACf,IAAIK,OAAOC,WAAW,KAAKX,mBAAmBU,OAAOE,GAAG,EAAE;YACxDR,MAAMS,IAAI,CAACH;QACb;IACF;I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AAS,MAAMlD,mBAAmB;gBACtCgC;eACIY,WAAW,eACXF,MAAMS,YAAY,GAChB;gBAAEA,cAAcT,MAAMS,YAAY;YAAC,IACnCN,iBACE;gBAAEA;YAAe,IACjB,CAAC,IACL,CAAC,GACDD,WAAW,aACXF,MAAMU,UAAU,GACd;gBAAEA,YAAYV,MAAMU,UAAU;YAAC,IAC/BV,MAAMW,YAAY,GAChB;gBAAEA,cAAcX,MAAMW,YAAY;YAAC,IACnC,CAAC,IACL,CAAC,GACDT,WAAW,SAASF,MAAMY,GAAG,GAAG;gBAAEA,KAAKZ,MAAMY,GAAG;YAAC,IAAI,CAAC,GACtDZ,MAAM3B,IAAI,GAAG;gBAAEA,MAAM2B,MAAM3B,IAAI;YAAC,IAAI,CAAC,GACrCiC,QAAQ;gBAAEA;YAAM,IAAI,CAAC;gBACzB,iEAAiE;gBACjE,oDAAoD;gBACpDO,QAAQC,QAAQd,MAAMe,cAAc,IAAIf,MAAMgB,eAAe;gBAC7DrB;;YAEFD,KAAK,CAACK,KAAK5B,GAAG,CAAW,GAAGqC;QAC9B,EAAE,OAAOS,OAAO;YACd,+DAA+D;YAC/DC,QAAQD,KAAK,CAAC,6BAA6BlB,KAAK5B,GAAG,EAAE8C;QACvD;IACF;IAGF,IAAI,CAACpD,OAAOsD,IAAI,CAACzB,OAAOD,MAAM,EAAE,OAAOX;IAEvC,OAAO;QACL,iEAAiE;QACjE,oEAAoE;QACpE,oEAAoE;QACpE,0DAA0D;QAC1DsC,UAAU;YAAEC,UAAU;gBAAE9B,OAAOG;YAAM;QAAE;IACzC;AACF,EAAC;AAED,eAAeL,yBAAwB"}
|
|
@@ -144,7 +144,7 @@ export function docRef(path) {
|
|
|
144
144
|
if (op === '<') return stored < value;
|
|
145
145
|
return false;
|
|
146
146
|
}
|
|
147
|
-
function collectionRef(path, filters = []) {
|
|
147
|
+
function collectionRef(path, filters = [], paging = {}) {
|
|
148
148
|
const children = ()=>[
|
|
149
149
|
...fakeDocs.keys()
|
|
150
150
|
].filter((key)=>key.startsWith(`${path}/`) && !key.slice(path.length + 1).includes('/'));
|
|
@@ -156,11 +156,40 @@ function collectionRef(path, filters = []) {
|
|
|
156
156
|
op,
|
|
157
157
|
value
|
|
158
158
|
]
|
|
159
|
-
]),
|
|
160
|
-
limit: ()=>
|
|
161
|
-
|
|
159
|
+
], paging),
|
|
160
|
+
limit: (cap)=>collectionRef(path, filters, _extends({}, paging, {
|
|
161
|
+
cap
|
|
162
|
+
})),
|
|
163
|
+
orderBy: (field, direction)=>collectionRef(path, filters, _extends({}, paging, {
|
|
164
|
+
order: {
|
|
165
|
+
field,
|
|
166
|
+
desc: direction === 'desc'
|
|
167
|
+
}
|
|
168
|
+
})),
|
|
169
|
+
startAfter: (snapshot)=>collectionRef(path, filters, _extends({}, paging, {
|
|
170
|
+
after: snapshot.ref.path
|
|
171
|
+
})),
|
|
162
172
|
get: async ()=>{
|
|
163
|
-
|
|
173
|
+
let keys = children().filter((key)=>filters.every(([field, op, value])=>matchesFilter(fieldAt(fakeDocs.get(key), field), op, value)));
|
|
174
|
+
if (paging.order) {
|
|
175
|
+
const { field, desc } = paging.order;
|
|
176
|
+
const sign = desc ? -1 : 1;
|
|
177
|
+
keys = [
|
|
178
|
+
...keys
|
|
179
|
+
].sort((a, b)=>{
|
|
180
|
+
var _fieldAt, _fieldAt1;
|
|
181
|
+
const left = (_fieldAt = fieldAt(fakeDocs.get(a), field)) != null ? _fieldAt : 0;
|
|
182
|
+
const right = (_fieldAt1 = fieldAt(fakeDocs.get(b), field)) != null ? _fieldAt1 : 0;
|
|
183
|
+
if (left !== right) return left < right ? -sign : sign;
|
|
184
|
+
return a < b ? -sign : a > b ? sign : 0;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
if (paging.after) {
|
|
188
|
+
const at = keys.indexOf(paging.after);
|
|
189
|
+
keys = at >= 0 ? keys.slice(at + 1) : keys;
|
|
190
|
+
}
|
|
191
|
+
if (paging.cap !== undefined) keys = keys.slice(0, paging.cap);
|
|
192
|
+
const docs = keys.map(snapshotOf);
|
|
164
193
|
return {
|
|
165
194
|
docs,
|
|
166
195
|
empty: docs.length === 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/testing/fake-firestore.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 * An in-memory stand-in for the Admin SDK's Firestore, for the register's\n * money-path specs (AGL-3607). Faithful where the code under test leans on\n * it: `create()` refuses an existing document, `update()` refuses a missing\n * one, merge-sets merge one level, and the `increment`, `delete` and\n * `arrayUnion` sentinels resolve against the stored value. A transaction\n * buffers its writes and applies them at commit, so a throw inside it writes\n * nothing.\n */\n\nconst INCREMENT = Symbol('increment')\nconst DELETE = Symbol('delete')\nconst UNION = Symbol('arrayUnion')\n\nexport const fakeFieldValue = {\n increment: (value: number) => ({ [INCREMENT]: value }),\n delete: () => ({ [DELETE]: true }),\n arrayUnion: (...values: unknown[]) => ({ [UNION]: values }),\n serverTimestamp: () => '<server-timestamp>',\n}\n\nexport const fakeDocs = new Map<string, Record<string, any>>()\n\nlet autoId = 0\n\nfunction resolveValue(existing: any, value: any): any {\n if (value && typeof value === 'object') {\n if (INCREMENT in value) return (Number(existing) || 0) + value[INCREMENT]\n if (UNION in value) {\n const base = Array.isArray(existing) ? [...existing] : []\n for (const item of value[UNION]) {\n if (!base.some((entry) => JSON.stringify(entry) === JSON.stringify(item))) base.push(item)\n }\n return base\n }\n }\n return value\n}\n\ntype SetOptions = { merge?: boolean; mergeFields?: string[] }\n\nfunction setMode(options?: SetOptions): 'set' | 'merge' | 'fields' {\n if (options?.mergeFields) return 'fields'\n return options?.merge ? 'merge' : 'set'\n}\n\nfunction applyWrite(\n path: string,\n value: Record<string, any>,\n mode: 'set' | 'merge' | 'update' | 'fields',\n) {\n const existing = fakeDocs.get(path)\n if (mode === 'update' && !existing) {\n const error: any = new Error(`NOT_FOUND: ${path}`)\n error.code = 5\n throw error\n }\n // `mergeFields`: each named top-level field is replaced whole, every\n // other stored field stays (the callers name exactly the fields they send).\n const next: Record<string, any> = mode === 'set' ? {} : { ...(existing ?? {}) }\n for (const [key, raw] of Object.entries(value)) {\n if (raw && typeof raw === 'object' && DELETE in raw) {\n delete next[key]\n continue\n }\n if (\n mode === 'merge' &&\n raw &&\n typeof raw === 'object' &&\n !Array.isArray(raw) &&\n !(INCREMENT in raw) &&\n !(UNION in raw) &&\n next[key] &&\n typeof next[key] === 'object' &&\n !Array.isArray(next[key])\n ) {\n const nested = { ...next[key] }\n for (const [inner, innerValue] of Object.entries(raw)) {\n if (innerValue && typeof innerValue === 'object' && DELETE in (innerValue as any)) {\n delete nested[inner]\n } else {\n nested[inner] = resolveValue(nested[inner], innerValue)\n }\n }\n next[key] = nested\n continue\n }\n next[key] = resolveValue(existing?.[key], raw)\n }\n fakeDocs.set(path, next)\n}\n\nfunction snapshotOf(path: string) {\n const data = fakeDocs.get(path)\n return {\n id: path.split('/').pop() as string,\n exists: data !== undefined,\n ref: docRef(path),\n data: () => (data ? JSON.parse(JSON.stringify(data)) : undefined),\n get: (field: string) => data?.[field],\n }\n}\n\nexport function docRef(path: string): any {\n return {\n id: path.split('/').pop() as string,\n path,\n get: async () => snapshotOf(path),\n set: async (value: Record<string, any>, options?: SetOptions) => applyWrite(path, value, setMode(options)),\n update: async (value: Record<string, any>) => applyWrite(path, value, 'update'),\n create: async (value: Record<string, any>) => {\n if (fakeDocs.has(path)) {\n const error: any = new Error(`ALREADY_EXISTS: ${path}`)\n error.code = 6\n throw error\n }\n applyWrite(path, value, 'set')\n },\n delete: async () => {\n fakeDocs.delete(path)\n },\n collection: (name: string) => collectionRef(`${path}/${name}`),\n /** The collection it is in, as a collection-group answer walks up. */\n get parent() {\n return collectionRef(path.split('/').slice(0, -1).join('/'))\n },\n }\n}\n\n/** A field by its dotted path (`attachment.state`), as Firestore reads one. */\nfunction fieldAt(data: Record<string, any> | undefined, field: string): any {\n return field.split('.').reduce((value: any, key) => (value == null ? undefined : value[key]), data)\n}\n\n/**\n * One filter, as Firestore reads it: equality, `array-contains`, `in`, and\n * the four ranges over two numbers or two dates (AGL-4038). A range never\n * matches a missing or null field, which is why a period query cannot see\n * an undated row.\n */\nfunction matchesFilter(stored: any, op: string, value: any): boolean {\n if (op === '==') return stored === value\n if (op === 'array-contains') return Array.isArray(stored) && stored.includes(value)\n if (op === 'in') return Array.isArray(value) && value.includes(stored)\n const numbers = typeof stored === 'number' && typeof value === 'number'\n const dates = stored instanceof Date && value instanceof Date\n if (!numbers && !dates) return false\n if (op === '>=') return stored >= value\n if (op === '>') return stored > value\n if (op === '<=') return stored <= value\n if (op === '<') return stored < value\n return false\n}\n\nfunction collectionRef(path: string, filters: Array<[string, string, any]> = []): any {\n const children = () =>\n [...fakeDocs.keys()].filter(\n (key) => key.startsWith(`${path}/`) && !key.slice(path.length + 1).includes('/'),\n )\n const query = {\n where: (field: string, op: string, value: any) =>\n collectionRef(path, [...filters, [field, op, value]]),\n limit: () => query,\n orderBy: () => query,\n get: async () => {\n const docs = children()\n .filter((key) =>\n filters.every(([field, op, value]) => matchesFilter(fieldAt(fakeDocs.get(key), field), op, value)),\n )\n .map(snapshotOf)\n return { docs, empty: docs.length === 0, size: docs.length }\n },\n /** The aggregate count over the same filters. */\n count: () => ({\n get: async () => {\n const { size } = await query.get()\n return { data: () => ({ count: size }) }\n },\n }),\n }\n return {\n ...query,\n path,\n id: path.split('/').pop() as string,\n /** The document it is under; null for a top-level collection. */\n get parent() {\n const segments = path.split('/')\n return segments.length > 1 ? docRef(segments.slice(0, -1).join('/')) : null\n },\n doc: (id?: string) => docRef(`${path}/${id ?? `auto-${++autoId}`}`),\n add: async (value: Record<string, any>) => {\n const ref = docRef(`${path}/auto-${++autoId}`)\n applyWrite(ref.path, value, 'set')\n return ref\n },\n }\n}\n\n/**\n * Every document in a collection named `name` at any depth, filtered by\n * equality or `array-contains`, on dotted paths too (AGL-4038). `orderBy` sorts on one field, ties broken by path as\n * Firestore does, `startAfter` takes a document snapshot, and `limit` caps\n * the answer, so a cursor-paged staff list can be specced.\n */\ninterface GroupShape {\n filters: Array<[string, any, string?]>\n order?: { field: string; desc: boolean }\n after?: string\n cap?: number\n}\nfunction collectionGroupRef(name: string, shape: GroupShape = { filters: [] }): any {\n const next = (patch: Partial<GroupShape>) => collectionGroupRef(name, { ...shape, ...patch })\n return {\n where: (field: string, op: string, value: any) => next({ filters: [...shape.filters, [field, value, op]] }),\n orderBy: (field: string, direction?: string) => next({ order: { field, desc: direction === 'desc' } }),\n startAfter: (snapshot: { ref: { path: string } }) => next({ after: snapshot.ref.path }),\n limit: (cap: number) => next({ cap }),\n get: async () => {\n let keys = [...fakeDocs.keys()]\n .filter((key) => {\n const parts = key.split('/')\n return parts.length >= 2 && parts.length % 2 === 0 && parts[parts.length - 2] === name\n })\n .filter((key) =>\n shape.filters.every(([field, value, op]) => {\n const stored = fieldAt(fakeDocs.get(key), field)\n if (op === 'array-contains') return Array.isArray(stored) && stored.includes(value)\n if (op === 'in') return Array.isArray(value) && value.includes(stored)\n return stored === value\n }),\n )\n if (shape.order) {\n const { field, desc } = shape.order\n const sign = desc ? -1 : 1\n keys.sort((a, b) => {\n const left = fakeDocs.get(a)?.[field] ?? 0\n const right = fakeDocs.get(b)?.[field] ?? 0\n if (left !== right) return left < right ? -sign : sign\n return a < b ? -sign : a > b ? sign : 0\n })\n }\n if (shape.after) {\n const at = keys.indexOf(shape.after)\n keys = at >= 0 ? keys.slice(at + 1) : keys\n }\n if (shape.cap !== undefined) keys = keys.slice(0, shape.cap)\n const docs = keys.map(snapshotOf)\n return { docs, empty: docs.length === 0, size: docs.length }\n },\n }\n}\n\nexport const fakeFirestore: any = {\n collection: (name: string) => collectionRef(name),\n collectionGroup: (name: string) => collectionGroupRef(name),\n doc: (path: string) => docRef(path),\n runTransaction: async (fn: (transaction: any) => Promise<any>) => {\n const writes: Array<() => void> = []\n const outcome = await fn({\n get: (ref: any) => ref.get(),\n set: (ref: any, value: any, options?: SetOptions) => {\n writes.push(() => applyWrite(ref.path, value, setMode(options)))\n },\n update: (ref: any, value: any) => {\n writes.push(() => applyWrite(ref.path, value, 'update'))\n },\n create: (ref: any, value: any) => {\n if (fakeDocs.has(ref.path)) {\n const error: any = new Error(`ALREADY_EXISTS: ${ref.path}`)\n error.code = 6\n throw error\n }\n writes.push(() => applyWrite(ref.path, value, 'set'))\n },\n delete: (ref: any) => {\n writes.push(() => fakeDocs.delete(ref.path))\n },\n })\n for (const write of writes) write()\n return outcome\n },\n recursiveDelete: async (ref: any) => {\n for (const key of [...fakeDocs.keys()]) {\n if (key === ref.path || key.startsWith(`${ref.path}/`)) fakeDocs.delete(key)\n }\n },\n}\n\nexport function resetFakeFirestore(): void {\n fakeDocs.clear()\n autoId = 0\n}\n"],"names":["INCREMENT","Symbol","DELETE","UNION","fakeFieldValue","increment","value","delete","arrayUnion","values","serverTimestamp","fakeDocs","Map","autoId","resolveValue","existing","Number","base","Array","isArray","item","some","entry","JSON","stringify","push","setMode","options","mergeFields","merge","applyWrite","path","mode","get","error","Error","code","next","key","raw","Object","entries","nested","inner","innerValue","set","snapshotOf","data","id","split","pop","exists","undefined","ref","docRef","parse","field","update","create","has","collection","name","collectionRef","parent","slice","join","fieldAt","reduce","matchesFilter","stored","op","includes","numbers","dates","Date","filters","children","keys","filter","startsWith","length","query","where","limit","orderBy","docs","every","map","empty","size","count","segments","doc","add","collectionGroupRef","shape","patch","direction","order","desc","startAfter","snapshot","after","cap","parts","sign","sort","a","b","left","right","at","indexOf","fakeFirestore","collectionGroup","runTransaction","fn","writes","outcome","write","recursiveDelete","resetFakeFirestore","clear"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;CAQC,GAED,MAAMA,YAAYC,OAAO;AACzB,MAAMC,SAASD,OAAO;AACtB,MAAME,QAAQF,OAAO;AAErB,OAAO,MAAMG,iBAAiB;IAC5BC,WAAW,CAACC,QAAmB,CAAA;YAAE,CAACN,UAAU,EAAEM;QAAM,CAAA;IACpDC,QAAQ,IAAO,CAAA;YAAE,CAACL,OAAO,EAAE;QAAK,CAAA;IAChCM,YAAY,CAAC,GAAGC,SAAuB,CAAA;YAAE,CAACN,MAAM,EAAEM;QAAO,CAAA;IACzDC,iBAAiB,IAAM;AACzB,EAAC;AAED,OAAO,MAAMC,WAAW,IAAIC,MAAkC;AAE9D,IAAIC,SAAS;AAEb,SAASC,aAAaC,QAAa,EAAET,KAAU;IAC7C,IAAIA,SAAS,OAAOA,UAAU,UAAU;QACtC,IAAIN,aAAaM,OAAO,OAAO,AAACU,CAAAA,OAAOD,aAAa,CAAA,IAAKT,KAAK,CAACN,UAAU;QACzE,IAAIG,SAASG,OAAO;YAClB,MAAMW,OAAOC,MAAMC,OAAO,CAACJ,YAAY;mBAAIA;aAAS,GAAG,EAAE;YACzD,KAAK,MAAMK,QAAQd,KAAK,CAACH,MAAM,CAAE;gBAC/B,IAAI,CAACc,KAAKI,IAAI,CAAC,CAACC,QAAUC,KAAKC,SAAS,CAACF,WAAWC,KAAKC,SAAS,CAACJ,QAAQH,KAAKQ,IAAI,CAACL;YACvF;YACA,OAAOH;QACT;IACF;IACA,OAAOX;AACT;AAIA,SAASoB,QAAQC,OAAoB;IACnC,IAAIA,2BAAAA,QAASC,WAAW,EAAE,OAAO;IACjC,OAAOD,CAAAA,2BAAAA,QAASE,KAAK,IAAG,UAAU;AACpC;AAEA,SAASC,WACPC,IAAY,EACZzB,KAA0B,EAC1B0B,IAA2C;IAE3C,MAAMjB,WAAWJ,SAASsB,GAAG,CAAC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AO;YAChD;YACAC,QAAQ,CAAC8C;gBACPgE,OAAO5F,IAAI,CAAC,IAAMd,SAASJ,MAAM,CAAC8C,IAAItB,IAAI;YAC5C;QACF;QACA,KAAK,MAAMwF,SAASF,OAAQE;QAC5B,OAAOD;IACT;IACAE,iBAAiB,OAAOnE;QACtB,KAAK,MAAMf,OAAO;eAAI3B,SAASkE,IAAI;SAAG,CAAE;YACtC,IAAIvC,QAAQe,IAAItB,IAAI,IAAIO,IAAIyC,UAAU,CAAC,GAAG1B,IAAItB,IAAI,CAAC,CAAC,CAAC,GAAGpB,SAASJ,MAAM,CAAC+B;QAC1E;IACF;AACF,EAAC;AAED,OAAO,SAASmF;IACd9G,SAAS+G,KAAK;IACd7G,SAAS;AACX"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/testing/fake-firestore.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 * An in-memory stand-in for the Admin SDK's Firestore, for the register's\n * money-path specs (AGL-3607). Faithful where the code under test leans on\n * it: `create()` refuses an existing document, `update()` refuses a missing\n * one, merge-sets merge one level, and the `increment`, `delete` and\n * `arrayUnion` sentinels resolve against the stored value. A transaction\n * buffers its writes and applies them at commit, so a throw inside it writes\n * nothing.\n */\n\nconst INCREMENT = Symbol('increment')\nconst DELETE = Symbol('delete')\nconst UNION = Symbol('arrayUnion')\n\nexport const fakeFieldValue = {\n increment: (value: number) => ({ [INCREMENT]: value }),\n delete: () => ({ [DELETE]: true }),\n arrayUnion: (...values: unknown[]) => ({ [UNION]: values }),\n serverTimestamp: () => '<server-timestamp>',\n}\n\nexport const fakeDocs = new Map<string, Record<string, any>>()\n\nlet autoId = 0\n\nfunction resolveValue(existing: any, value: any): any {\n if (value && typeof value === 'object') {\n if (INCREMENT in value) return (Number(existing) || 0) + value[INCREMENT]\n if (UNION in value) {\n const base = Array.isArray(existing) ? [...existing] : []\n for (const item of value[UNION]) {\n if (!base.some((entry) => JSON.stringify(entry) === JSON.stringify(item))) base.push(item)\n }\n return base\n }\n }\n return value\n}\n\ntype SetOptions = { merge?: boolean; mergeFields?: string[] }\n\nfunction setMode(options?: SetOptions): 'set' | 'merge' | 'fields' {\n if (options?.mergeFields) return 'fields'\n return options?.merge ? 'merge' : 'set'\n}\n\nfunction applyWrite(\n path: string,\n value: Record<string, any>,\n mode: 'set' | 'merge' | 'update' | 'fields',\n) {\n const existing = fakeDocs.get(path)\n if (mode === 'update' && !existing) {\n const error: any = new Error(`NOT_FOUND: ${path}`)\n error.code = 5\n throw error\n }\n // `mergeFields`: each named top-level field is replaced whole, every\n // other stored field stays (the callers name exactly the fields they send).\n const next: Record<string, any> = mode === 'set' ? {} : { ...(existing ?? {}) }\n for (const [key, raw] of Object.entries(value)) {\n if (raw && typeof raw === 'object' && DELETE in raw) {\n delete next[key]\n continue\n }\n if (\n mode === 'merge' &&\n raw &&\n typeof raw === 'object' &&\n !Array.isArray(raw) &&\n !(INCREMENT in raw) &&\n !(UNION in raw) &&\n next[key] &&\n typeof next[key] === 'object' &&\n !Array.isArray(next[key])\n ) {\n const nested = { ...next[key] }\n for (const [inner, innerValue] of Object.entries(raw)) {\n if (innerValue && typeof innerValue === 'object' && DELETE in (innerValue as any)) {\n delete nested[inner]\n } else {\n nested[inner] = resolveValue(nested[inner], innerValue)\n }\n }\n next[key] = nested\n continue\n }\n next[key] = resolveValue(existing?.[key], raw)\n }\n fakeDocs.set(path, next)\n}\n\nfunction snapshotOf(path: string) {\n const data = fakeDocs.get(path)\n return {\n id: path.split('/').pop() as string,\n exists: data !== undefined,\n ref: docRef(path),\n data: () => (data ? JSON.parse(JSON.stringify(data)) : undefined),\n get: (field: string) => data?.[field],\n }\n}\n\nexport function docRef(path: string): any {\n return {\n id: path.split('/').pop() as string,\n path,\n get: async () => snapshotOf(path),\n set: async (value: Record<string, any>, options?: SetOptions) => applyWrite(path, value, setMode(options)),\n update: async (value: Record<string, any>) => applyWrite(path, value, 'update'),\n create: async (value: Record<string, any>) => {\n if (fakeDocs.has(path)) {\n const error: any = new Error(`ALREADY_EXISTS: ${path}`)\n error.code = 6\n throw error\n }\n applyWrite(path, value, 'set')\n },\n delete: async () => {\n fakeDocs.delete(path)\n },\n collection: (name: string) => collectionRef(`${path}/${name}`),\n /** The collection it is in, as a collection-group answer walks up. */\n get parent() {\n return collectionRef(path.split('/').slice(0, -1).join('/'))\n },\n }\n}\n\n/** A field by its dotted path (`attachment.state`), as Firestore reads one. */\nfunction fieldAt(data: Record<string, any> | undefined, field: string): any {\n return field.split('.').reduce((value: any, key) => (value == null ? undefined : value[key]), data)\n}\n\n/**\n * One filter, as Firestore reads it: equality, `array-contains`, `in`, and\n * the four ranges over two numbers or two dates (AGL-4038). A range never\n * matches a missing or null field, which is why a period query cannot see\n * an undated row.\n */\nfunction matchesFilter(stored: any, op: string, value: any): boolean {\n if (op === '==') return stored === value\n if (op === 'array-contains') return Array.isArray(stored) && stored.includes(value)\n if (op === 'in') return Array.isArray(value) && value.includes(stored)\n const numbers = typeof stored === 'number' && typeof value === 'number'\n const dates = stored instanceof Date && value instanceof Date\n if (!numbers && !dates) return false\n if (op === '>=') return stored >= value\n if (op === '>') return stored > value\n if (op === '<=') return stored <= value\n if (op === '<') return stored < value\n return false\n}\n\n/** A collection query's order, cursor and cap, read as Firestore reads them. */\ninterface CollectionPaging {\n order?: { field: string; desc: boolean }\n after?: string\n cap?: number\n}\n\nfunction collectionRef(\n path: string,\n filters: Array<[string, string, any]> = [],\n paging: CollectionPaging = {},\n): any {\n const children = () =>\n [...fakeDocs.keys()].filter(\n (key) => key.startsWith(`${path}/`) && !key.slice(path.length + 1).includes('/'),\n )\n const query = {\n where: (field: string, op: string, value: any) =>\n collectionRef(path, [...filters, [field, op, value]], paging),\n limit: (cap: number) => collectionRef(path, filters, { ...paging, cap }),\n orderBy: (field: string, direction?: string) =>\n collectionRef(path, filters, { ...paging, order: { field, desc: direction === 'desc' } }),\n startAfter: (snapshot: { ref: { path: string } }) =>\n collectionRef(path, filters, { ...paging, after: snapshot.ref.path }),\n get: async () => {\n let keys = children().filter((key) =>\n filters.every(([field, op, value]) => matchesFilter(fieldAt(fakeDocs.get(key), field), op, value)),\n )\n if (paging.order) {\n const { field, desc } = paging.order\n const sign = desc ? -1 : 1\n keys = [...keys].sort((a, b) => {\n const left = fieldAt(fakeDocs.get(a), field) ?? 0\n const right = fieldAt(fakeDocs.get(b), field) ?? 0\n if (left !== right) return left < right ? -sign : sign\n return a < b ? -sign : a > b ? sign : 0\n })\n }\n if (paging.after) {\n const at = keys.indexOf(paging.after)\n keys = at >= 0 ? keys.slice(at + 1) : keys\n }\n if (paging.cap !== undefined) keys = keys.slice(0, paging.cap)\n const docs = keys.map(snapshotOf)\n return { docs, empty: docs.length === 0, size: docs.length }\n },\n /** The aggregate count over the same filters. */\n count: () => ({\n get: async () => {\n const { size } = await query.get()\n return { data: () => ({ count: size }) }\n },\n }),\n }\n return {\n ...query,\n path,\n id: path.split('/').pop() as string,\n /** The document it is under; null for a top-level collection. */\n get parent() {\n const segments = path.split('/')\n return segments.length > 1 ? docRef(segments.slice(0, -1).join('/')) : null\n },\n doc: (id?: string) => docRef(`${path}/${id ?? `auto-${++autoId}`}`),\n add: async (value: Record<string, any>) => {\n const ref = docRef(`${path}/auto-${++autoId}`)\n applyWrite(ref.path, value, 'set')\n return ref\n },\n }\n}\n\n/**\n * Every document in a collection named `name` at any depth, filtered by\n * equality or `array-contains`, on dotted paths too (AGL-4038). `orderBy` sorts on one field, ties broken by path as\n * Firestore does, `startAfter` takes a document snapshot, and `limit` caps\n * the answer, so a cursor-paged staff list can be specced.\n */\ninterface GroupShape {\n filters: Array<[string, any, string?]>\n order?: { field: string; desc: boolean }\n after?: string\n cap?: number\n}\nfunction collectionGroupRef(name: string, shape: GroupShape = { filters: [] }): any {\n const next = (patch: Partial<GroupShape>) => collectionGroupRef(name, { ...shape, ...patch })\n return {\n where: (field: string, op: string, value: any) => next({ filters: [...shape.filters, [field, value, op]] }),\n orderBy: (field: string, direction?: string) => next({ order: { field, desc: direction === 'desc' } }),\n startAfter: (snapshot: { ref: { path: string } }) => next({ after: snapshot.ref.path }),\n limit: (cap: number) => next({ cap }),\n get: async () => {\n let keys = [...fakeDocs.keys()]\n .filter((key) => {\n const parts = key.split('/')\n return parts.length >= 2 && parts.length % 2 === 0 && parts[parts.length - 2] === name\n })\n .filter((key) =>\n shape.filters.every(([field, value, op]) => {\n const stored = fieldAt(fakeDocs.get(key), field)\n if (op === 'array-contains') return Array.isArray(stored) && stored.includes(value)\n if (op === 'in') return Array.isArray(value) && value.includes(stored)\n return stored === value\n }),\n )\n if (shape.order) {\n const { field, desc } = shape.order\n const sign = desc ? -1 : 1\n keys.sort((a, b) => {\n const left = fakeDocs.get(a)?.[field] ?? 0\n const right = fakeDocs.get(b)?.[field] ?? 0\n if (left !== right) return left < right ? -sign : sign\n return a < b ? -sign : a > b ? sign : 0\n })\n }\n if (shape.after) {\n const at = keys.indexOf(shape.after)\n keys = at >= 0 ? keys.slice(at + 1) : keys\n }\n if (shape.cap !== undefined) keys = keys.slice(0, shape.cap)\n const docs = keys.map(snapshotOf)\n return { docs, empty: docs.length === 0, size: docs.length }\n },\n }\n}\n\nexport const fakeFirestore: any = {\n collection: (name: string) => collectionRef(name),\n collectionGroup: (name: string) => collectionGroupRef(name),\n doc: (path: string) => docRef(path),\n runTransaction: async (fn: (transaction: any) => Promise<any>) => {\n const writes: Array<() => void> = []\n const outcome = await fn({\n get: (ref: any) => ref.get(),\n set: (ref: any, value: any, options?: SetOptions) => {\n writes.push(() => applyWrite(ref.path, value, setMode(options)))\n },\n update: (ref: any, value: any) => {\n writes.push(() => applyWrite(ref.path, value, 'update'))\n },\n create: (ref: any, value: any) => {\n if (fakeDocs.has(ref.path)) {\n const error: any = new Error(`ALREADY_EXISTS: ${ref.path}`)\n error.code = 6\n throw error\n }\n writes.push(() => applyWrite(ref.path, value, 'set'))\n },\n delete: (ref: any) => {\n writes.push(() => fakeDocs.delete(ref.path))\n },\n })\n for (const write of writes) write()\n return outcome\n },\n recursiveDelete: async (ref: any) => {\n for (const key of [...fakeDocs.keys()]) {\n if (key === ref.path || key.startsWith(`${ref.path}/`)) fakeDocs.delete(key)\n }\n },\n}\n\nexport function resetFakeFirestore(): void {\n fakeDocs.clear()\n autoId = 0\n}\n"],"names":["INCREMENT","Symbol","DELETE","UNION","fakeFieldValue","increment","value","delete","arrayUnion","values","serverTimestamp","fakeDocs","Map","autoId","resolveValue","existing","Number","base","Array","isArray","item","some","entry","JSON","stringify","push","setMode","options","mergeFields","merge","applyWrite","path","mode","get","error","Error","code","next","key","raw","Object","entries","nested","inner","innerValue","set","snapshotOf","data","id","split","pop","exists","undefined","ref","docRef","parse","field","update","create","has","collection","name","collectionRef","parent","slice","join","fieldAt","reduce","matchesFilter","stored","op","includes","numbers","dates","Date","filters","paging","children","keys","filter","startsWith","length","query","where","limit","cap","orderBy","direction","order","desc","startAfter","snapshot","after","every","sign","sort","a","b","left","right","at","indexOf","docs","map","empty","size","count","segments","doc","add","collectionGroupRef","shape","patch","parts","fakeFirestore","collectionGroup","runTransaction","fn","writes","outcome","write","recursiveDelete","resetFakeFirestore","clear"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;CAQC,GAED,MAAMA,YAAYC,OAAO;AACzB,MAAMC,SAASD,OAAO;AACtB,MAAME,QAAQF,OAAO;AAErB,OAAO,MAAMG,iBAAiB;IAC5BC,WAAW,CAACC,QAAmB,CAAA;YAAE,CAACN,UAAU,EAAEM;QAAM,CAAA;IACpDC,QAAQ,IA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IACd/G,SAASgH,KAAK;IACd9G,SAAS;AACX"}
|
|
@@ -0,0 +1,75 @@
|
|
|
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 ProductCheckIn } from '../model/commerce-check-in-product';
|
|
18
|
+
import { type ProductModifierGroup } from '../model/product-modifiers';
|
|
19
|
+
/** What a cell read as, or why it could not be. */
|
|
20
|
+
type Read<T> = {
|
|
21
|
+
value: T;
|
|
22
|
+
} | {
|
|
23
|
+
message: string;
|
|
24
|
+
};
|
|
25
|
+
/** One choice as a cell names it. */
|
|
26
|
+
export interface AddOnCellChoice {
|
|
27
|
+
name: string;
|
|
28
|
+
priceCents: number;
|
|
29
|
+
/** What it adds on a variant, by that variant's name. */
|
|
30
|
+
byVariant: Array<{
|
|
31
|
+
label: string;
|
|
32
|
+
priceCents: number;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
/** One group as a cell names it. */
|
|
36
|
+
export interface AddOnCellGroup {
|
|
37
|
+
name: string;
|
|
38
|
+
min: number;
|
|
39
|
+
max: number;
|
|
40
|
+
online: boolean;
|
|
41
|
+
choices: AddOnCellChoice[];
|
|
42
|
+
}
|
|
43
|
+
/** An add-ons cell as its groups, or what is wrong with it for the person to fix. */
|
|
44
|
+
export declare function readAddOnCell(cell: unknown): Read<AddOnCellGroup[]>;
|
|
45
|
+
/** Groups as the one way a cell writes them, so two cells saying the same thing are the same text. */
|
|
46
|
+
export declare function writeAddOnCell(groups: readonly AddOnCellGroup[]): string;
|
|
47
|
+
type LabelledVariant = {
|
|
48
|
+
id: string;
|
|
49
|
+
options?: Record<string, string>;
|
|
50
|
+
};
|
|
51
|
+
/** A stored product's add-ons as a cell; `null` when it has none. */
|
|
52
|
+
export declare function addOnCellOf(stored: unknown, variants: readonly LabelledVariant[]): string | null;
|
|
53
|
+
/** A variant's name in a cell, in any case and whichever order its option values come in. */
|
|
54
|
+
export declare function variantLabelKey(label: string): string;
|
|
55
|
+
/** The ids of a product's variants by the name a cell gives them. */
|
|
56
|
+
export declare function addOnVariantIds(variants: readonly LabelledVariant[]): Record<string, string[]>;
|
|
57
|
+
/**
|
|
58
|
+
* The groups an add-ons cell stores. A group or choice the product already
|
|
59
|
+
* has keeps its id, so a cart holding that choice still finds it; one it does
|
|
60
|
+
* not have gets a new id. `problem` names a variant no price can land on.
|
|
61
|
+
* `groups` is `null` for a cell that cannot be read at all.
|
|
62
|
+
*/
|
|
63
|
+
export declare function modifierGroupsFromAddOnCell(cell: unknown, existing: readonly ProductModifierGroup[] | undefined, variantIds: Readonly<Record<string, string[]>>): {
|
|
64
|
+
groups: ProductModifierGroup[] | null;
|
|
65
|
+
problem: string | null;
|
|
66
|
+
};
|
|
67
|
+
/** A check-in cell as the setting it names, or what is wrong with it. How many people is the model's to refuse. */
|
|
68
|
+
export declare function readCheckInCell(cell: unknown): Read<ProductCheckIn>;
|
|
69
|
+
/** A setting as the one way a cell writes it. */
|
|
70
|
+
export declare function writeCheckInCell(setting: ProductCheckIn): string;
|
|
71
|
+
/** A stored check-in setting as a cell; `null` when it has none. */
|
|
72
|
+
export declare function checkInCellOf(stored: unknown): string | null;
|
|
73
|
+
/** The setting a cell stores; `undefined` for a blank cell. */
|
|
74
|
+
export declare function checkInFromCell(cell: unknown): ProductCheckIn | undefined;
|
|
75
|
+
export {};
|