@aglyn/plugins-commerce 1.33.2 → 1.34.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.
Files changed (104) hide show
  1. package/package.json +13 -13
  2. package/src/lib/components/cart.js +3 -1
  3. package/src/lib/components/cart.js.map +1 -1
  4. package/src/lib/components/console/catalog-organization-card.component.js +82 -69
  5. package/src/lib/components/console/catalog-organization-card.component.js.map +1 -1
  6. package/src/lib/components/console/discounts-card.component.js +46 -25
  7. package/src/lib/components/console/discounts-card.component.js.map +1 -1
  8. package/src/lib/components/console/gift-cards-card.component.js +81 -55
  9. package/src/lib/components/console/gift-cards-card.component.js.map +1 -1
  10. package/src/lib/components/console/host-coupons-card.component.js +36 -25
  11. package/src/lib/components/console/host-coupons-card.component.js.map +1 -1
  12. package/src/lib/components/console/locations-card.component.js +53 -32
  13. package/src/lib/components/console/locations-card.component.js.map +1 -1
  14. package/src/lib/components/console/member-posts-card.component.js +35 -32
  15. package/src/lib/components/console/member-posts-card.component.js.map +1 -1
  16. package/src/lib/components/console/new-store-tax-question.component.d.ts +17 -0
  17. package/src/lib/components/console/new-store-tax-question.component.js +197 -0
  18. package/src/lib/components/console/new-store-tax-question.component.js.map +1 -0
  19. package/src/lib/components/console/payments-settings-card.component.js +132 -5
  20. package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
  21. package/src/lib/components/console/pos/pos-api.d.ts +6 -0
  22. package/src/lib/components/console/pos/pos-api.js.map +1 -1
  23. package/src/lib/components/console/pos/pos-tax-notice.component.d.ts +21 -0
  24. package/src/lib/components/console/pos/pos-tax-notice.component.js +59 -0
  25. package/src/lib/components/console/pos/pos-tax-notice.component.js.map +1 -0
  26. package/src/lib/components/console/pos-page.component.js +65 -17
  27. package/src/lib/components/console/pos-page.component.js.map +1 -1
  28. package/src/lib/components/console/registers-card.component.js +21 -13
  29. package/src/lib/components/console/registers-card.component.js.map +1 -1
  30. package/src/lib/components/console/reviews-moderation-card.component.js +108 -68
  31. package/src/lib/components/console/reviews-moderation-card.component.js.map +1 -1
  32. package/src/lib/components/console/site-member-purchases.component.js +5 -3
  33. package/src/lib/components/console/site-member-purchases.component.js.map +1 -1
  34. package/src/lib/components/console/subscription-detail-dialog.component.d.ts +2 -0
  35. package/src/lib/components/console/subscription-detail-dialog.component.js +1 -1
  36. package/src/lib/components/console/subscription-detail-dialog.component.js.map +1 -1
  37. package/src/lib/components/console/subscriptions-card.component.js +13 -5
  38. package/src/lib/components/console/subscriptions-card.component.js.map +1 -1
  39. package/src/lib/components/console/suppliers-card.component.js +47 -40
  40. package/src/lib/components/console/suppliers-card.component.js.map +1 -1
  41. package/src/lib/components/product-choice-cards.js +2 -1
  42. package/src/lib/components/product-choice-cards.js.map +1 -1
  43. package/src/lib/components/product-detail.js +9 -4
  44. package/src/lib/components/product-detail.js.map +1 -1
  45. package/src/lib/components/product-grid.js +3 -1
  46. package/src/lib/components/product-grid.js.map +1 -1
  47. package/src/lib/components/related-products.js +2 -1
  48. package/src/lib/components/related-products.js.map +1 -1
  49. package/src/lib/components/store-image-sizing.d.ts +46 -0
  50. package/src/lib/components/store-image-sizing.js +53 -0
  51. package/src/lib/components/store-image-sizing.js.map +1 -0
  52. package/src/lib/components/wishlist.js +2 -1
  53. package/src/lib/components/wishlist.js.map +1 -1
  54. package/src/lib/declarations.console-server.js +10 -0
  55. package/src/lib/declarations.console-server.js.map +1 -1
  56. package/src/lib/model/commerce-tax-step.d.ts +123 -0
  57. package/src/lib/model/commerce-tax-step.js +185 -0
  58. package/src/lib/model/commerce-tax-step.js.map +1 -0
  59. package/src/lib/model/index.d.ts +1 -0
  60. package/src/lib/model/index.js +1 -0
  61. package/src/lib/model/index.js.map +1 -1
  62. package/src/lib/model/payments-setup-status.d.ts +40 -0
  63. package/src/lib/model/payments-setup-status.js +63 -0
  64. package/src/lib/model/payments-setup-status.js.map +1 -1
  65. package/src/lib/model/subscription-view.d.ts +19 -0
  66. package/src/lib/model/subscription-view.js +16 -0
  67. package/src/lib/model/subscription-view.js.map +1 -1
  68. package/src/lib/model/tap-to-pay-launch.d.ts +103 -0
  69. package/src/lib/model/tap-to-pay-launch.js +148 -0
  70. package/src/lib/model/tap-to-pay-launch.js.map +1 -0
  71. package/src/lib/plugin.js +12 -0
  72. package/src/lib/plugin.js.map +1 -1
  73. package/src/lib/server/billing-webhook.js +140 -116
  74. package/src/lib/server/billing-webhook.js.map +1 -1
  75. package/src/lib/server/checkout.js +15 -4
  76. package/src/lib/server/checkout.js.map +1 -1
  77. package/src/lib/server/connect-return.d.ts +83 -0
  78. package/src/lib/server/connect-return.js +105 -0
  79. package/src/lib/server/connect-return.js.map +1 -0
  80. package/src/lib/server/connect.d.ts +18 -0
  81. package/src/lib/server/connect.js +60 -6
  82. package/src/lib/server/connect.js.map +1 -1
  83. package/src/lib/server/new-store-tax.d.ts +10 -0
  84. package/src/lib/server/new-store-tax.js +43 -0
  85. package/src/lib/server/new-store-tax.js.map +1 -0
  86. package/src/lib/server/pos-payment.js +3 -2
  87. package/src/lib/server/pos-payment.js.map +1 -1
  88. package/src/lib/server/pos-tax-step.d.ts +43 -0
  89. package/src/lib/server/pos-tax-step.js +55 -0
  90. package/src/lib/server/pos-tax-step.js.map +1 -0
  91. package/src/lib/server/pos-terminal-connection-token.d.ts +10 -1
  92. package/src/lib/server/pos-terminal-connection-token.js +18 -7
  93. package/src/lib/server/pos-terminal-connection-token.js.map +1 -1
  94. package/src/lib/server/pos-terminal.d.ts +9 -0
  95. package/src/lib/server/pos-terminal.js +17 -1
  96. package/src/lib/server/pos-terminal.js.map +1 -1
  97. package/src/lib/server/tap-to-pay-launch-admin.d.ts +18 -0
  98. package/src/lib/server/tap-to-pay-launch-admin.js +204 -0
  99. package/src/lib/server/tap-to-pay-launch-admin.js.map +1 -0
  100. package/src/lib/server/tap-to-pay-launch.d.ts +114 -0
  101. package/src/lib/server/tap-to-pay-launch.js +408 -0
  102. package/src/lib/server/tap-to-pay-launch.js.map +1 -0
  103. package/src/lib/server.js +15 -0
  104. package/src/lib/server.js.map +1 -1
@@ -0,0 +1,204 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2026 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ import { platformConsoleOrigin } from "@aglyn/aglyn/app-utils/platform-brand";
18
+ import { pluginRequestFromWeb } from "@aglyn/aglyn/server";
19
+ import { sendEmail, TAP_TO_PAY_LAUNCH_EMAIL_KEY, tapToPayLaunchMergeValues } from "@aglyn/shared-util-email";
20
+ import { emailUnverifiedResponse, firebaseAdmin, isEmailSuppressed, isImpersonationSession, meterPlatformEmail } from "@aglyn/tenant-data-admin";
21
+ import { addAdminAudit } from "@aglyn/tenant-data-admin/server/admin-audit-write";
22
+ import { invalidIdTokenResponse } from "@aglyn/tenant-data-admin/server/id-token-refusal";
23
+ import { orgSystemEmailBrand, renderSystemEmailContent } from "@aglyn/tenant-data-admin/server/render-system-email";
24
+ import { runTapToPayLaunch, tapToPayLaunchFallback } from "./tap-to-pay-launch.js";
25
+ /*==========================================
26
+ * `/api/commerce/admin/tap-to-pay-launch` (AGL-4061): the staff door for
27
+ * Apple's Tap to Pay on iPhone launch email and push.
28
+ *
29
+ * GET the dry run: who would be told what (counts, and a sample with
30
+ * each address masked), sending and writing nothing. Any staff role.
31
+ * POST `{ "send": false }` or no body: the same dry run.
32
+ * `{ "send": true, "reason": "…", "channels": ["email","push"] }`:
33
+ * sends, `super` staff only, and only once the deployment says Tap
34
+ * to Pay on iPhone is released (`TAP_TO_PAY_IPHONE_RELEASED=true`;
35
+ * 409 otherwise). Each person once per channel; a run sends up to
36
+ * 200 per channel and reports what remains, so it is run again until
37
+ * `remaining` is zero. Every send is an `adminAudit` row.
38
+ *
39
+ * The rules and the sending are `tap-to-pay-launch.ts`; this file is the
40
+ * door. The operator's note is `docs/TAP_TO_PAY_LAUNCH.md`.
41
+ *=========================================*/ const json = (body, status = 200)=>Response.json(body, {
42
+ status,
43
+ headers: {
44
+ 'Cache-Control': 'no-store'
45
+ }
46
+ });
47
+ const CHANNELS = [
48
+ 'email',
49
+ 'push'
50
+ ];
51
+ /** The auth system's answer for each uid, 100 at a time. */ async function authUsers(uids) {
52
+ const auth = firebaseAdmin.app().auth();
53
+ const users = [];
54
+ for(let index = 0; index < uids.length; index += 100){
55
+ const result = await auth.getUsers(uids.slice(index, index + 100).map((uid)=>({
56
+ uid
57
+ })));
58
+ for (const user of result.users){
59
+ var _user_email;
60
+ var _user_customClaims;
61
+ users.push({
62
+ uid: user.uid,
63
+ email: (_user_email = user.email) != null ? _user_email : null,
64
+ disabled: user.disabled,
65
+ staff: Boolean((_user_customClaims = user.customClaims) == null ? void 0 : _user_customClaims['staff'])
66
+ });
67
+ }
68
+ }
69
+ return users;
70
+ }
71
+ /** The deployment's dependencies; the send halves only for a send. */ function launchDeps(send) {
72
+ const firestore = firebaseAdmin.app().firestore();
73
+ const brands = new Map();
74
+ const brandFor = (orgId)=>{
75
+ if (!brands.has(orgId)) brands.set(orgId, orgSystemEmailBrand(orgId));
76
+ return brands.get(orgId);
77
+ };
78
+ return _extends({
79
+ db: firestore,
80
+ authUsers,
81
+ isSuppressed: (email)=>isEmailSuppressed(email),
82
+ consoleOrigin: platformConsoleOrigin(),
83
+ env: process.env
84
+ }, send ? {
85
+ sendEmail: async ({ to, orgId, values })=>{
86
+ const brand = await brandFor(orgId);
87
+ const content = await renderSystemEmailContent(TAP_TO_PAY_LAUNCH_EMAIL_KEY, tapToPayLaunchMergeValues(values), brand, tapToPayLaunchFallback(values));
88
+ const result = await sendEmail(_extends({
89
+ to
90
+ }, content, brand.fromName ? {
91
+ fromName: brand.fromName
92
+ } : {}, {
93
+ context: TAP_TO_PAY_LAUNCH_EMAIL_KEY,
94
+ priority: 'bulk',
95
+ headers: {
96
+ 'List-Unsubscribe': `<${values.preferencesUrl}>`
97
+ }
98
+ }));
99
+ if (result.sent) {
100
+ await meterPlatformEmail().catch(()=>undefined);
101
+ return 'sent';
102
+ }
103
+ const reason = result.reason;
104
+ return reason === 'rate-limited' || reason === 'frequency-capped' ? 'deferred' : 'failed';
105
+ },
106
+ pushTransport: async ()=>(await import("@aglyn/tenant-data-admin/server/push-apns")).apnsTransport()
107
+ } : {});
108
+ }
109
+ async function handler(request) {
110
+ var _headers_authorization;
111
+ const { method, body, headers: rawHeaders } = await pluginRequestFromWeb(request);
112
+ const headers = rawHeaders;
113
+ const authorization = (_headers_authorization = headers.authorization) != null ? _headers_authorization : '';
114
+ const idToken = authorization.startsWith('Bearer ') ? authorization.slice('Bearer '.length) : undefined;
115
+ if (!idToken) return json({
116
+ error: 'Unauthenticated'
117
+ }, 401);
118
+ if (method !== 'GET' && method !== 'POST') return json({
119
+ error: 'Method not allowed'
120
+ }, 405);
121
+ try {
122
+ var _decoded_staffRole;
123
+ const decoded = await firebaseAdmin.app().auth().verifyIdToken(idToken);
124
+ if (!decoded.email_verified && !isImpersonationSession(decoded)) return emailUnverifiedResponse();
125
+ if (!decoded['staff']) return json({
126
+ error: 'Staff only'
127
+ }, 403);
128
+ // A missing role claim reads as the least one, never as super.
129
+ const role = String((_decoded_staffRole = decoded['staffRole']) != null ? _decoded_staffRole : 'support');
130
+ const input = method === 'POST' ? body != null ? body : {} : {};
131
+ if (input['send'] !== undefined && typeof input['send'] !== 'boolean') {
132
+ return json({
133
+ error: 'send must be true or false'
134
+ }, 400);
135
+ }
136
+ const send = input['send'] === true;
137
+ const requested = input['channels'];
138
+ if (requested !== undefined && (!Array.isArray(requested) || requested.some((c)=>!CHANNELS.includes(c)))) {
139
+ return json({
140
+ error: 'channels must list "email", "push" or both'
141
+ }, 400);
142
+ }
143
+ const channels = requested != null ? requested : [
144
+ ...CHANNELS
145
+ ];
146
+ if (send) {
147
+ var _input_reason;
148
+ if (role !== 'super') return json({
149
+ error: 'Sending the launch requires the super staff role.'
150
+ }, 403);
151
+ // Validated before anything goes out: a send cannot be recalled.
152
+ const reason = String((_input_reason = input['reason']) != null ? _input_reason : '').trim().slice(0, 500);
153
+ if (reason.length < 8) {
154
+ return json({
155
+ error: 'A send needs a reason of at least 8 characters; it reaches every eligible merchant.'
156
+ }, 400);
157
+ }
158
+ const report = await runTapToPayLaunch({
159
+ send: true,
160
+ channels
161
+ }, launchDeps(true));
162
+ if (report.refused) {
163
+ return json({
164
+ error: 'Tap to Pay on iPhone is not released on this deployment (TAP_TO_PAY_IPHONE_RELEASED is not true). Nothing was sent.',
165
+ report
166
+ }, 409);
167
+ }
168
+ await addAdminAudit(firebaseAdmin.app().firestore(), {
169
+ action: 'tap-to-pay-launch.send',
170
+ actorUid: decoded.uid,
171
+ actorEmail: decoded.email ? String(decoded.email) : null,
172
+ target: 'tap-to-pay-iphone-launch',
173
+ reason,
174
+ before: null,
175
+ after: {
176
+ channels,
177
+ emailSent: report.email.sent,
178
+ emailDeferred: report.email.deferred,
179
+ emailFailed: report.email.failed,
180
+ pushSent: report.push.sent,
181
+ pushFailed: report.push.failed,
182
+ remaining: report.remaining,
183
+ image: report.image
184
+ },
185
+ at: firebaseAdmin.firestore.FieldValue.serverTimestamp()
186
+ });
187
+ return json(report);
188
+ }
189
+ return json(await runTapToPayLaunch({
190
+ send: false,
191
+ channels
192
+ }, launchDeps(false)));
193
+ } catch (error) {
194
+ const unauthenticated = invalidIdTokenResponse(error);
195
+ if (unauthenticated) return unauthenticated;
196
+ console.error('[tap-to-pay-launch] failed', error);
197
+ return json({
198
+ error: 'The launch could not be read'
199
+ }, 500);
200
+ }
201
+ }
202
+ export { handler as tapToPayLaunchAdmin };
203
+
204
+ //# sourceMappingURL=tap-to-pay-launch-admin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/tap-to-pay-launch-admin.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 { platformConsoleOrigin } from '@aglyn/aglyn/app-utils/platform-brand'\nimport { pluginRequestFromWeb } from '@aglyn/aglyn/server'\nimport { sendEmail, TAP_TO_PAY_LAUNCH_EMAIL_KEY, tapToPayLaunchMergeValues } from '@aglyn/shared-util-email'\nimport {\n emailUnverifiedResponse,\n firebaseAdmin,\n isEmailSuppressed,\n isImpersonationSession,\n meterPlatformEmail,\n} from '@aglyn/tenant-data-admin'\nimport { addAdminAudit } from '@aglyn/tenant-data-admin/server/admin-audit-write'\nimport { invalidIdTokenResponse } from '@aglyn/tenant-data-admin/server/id-token-refusal'\nimport {\n orgSystemEmailBrand,\n renderSystemEmailContent,\n type SystemEmailBrand,\n} from '@aglyn/tenant-data-admin/server/render-system-email'\nimport {\n runTapToPayLaunch,\n tapToPayLaunchFallback,\n type TapToPayAuthUser,\n type TapToPayChannel,\n type TapToPayLaunchDeps,\n} from './tap-to-pay-launch'\n\n/*==========================================\n * `/api/commerce/admin/tap-to-pay-launch` (AGL-4061): the staff door for\n * Apple's Tap to Pay on iPhone launch email and push.\n *\n * GET the dry run: who would be told what (counts, and a sample with\n * each address masked), sending and writing nothing. Any staff role.\n * POST `{ \"send\": false }` or no body: the same dry run.\n * `{ \"send\": true, \"reason\": \"…\", \"channels\": [\"email\",\"push\"] }`:\n * sends, `super` staff only, and only once the deployment says Tap\n * to Pay on iPhone is released (`TAP_TO_PAY_IPHONE_RELEASED=true`;\n * 409 otherwise). Each person once per channel; a run sends up to\n * 200 per channel and reports what remains, so it is run again until\n * `remaining` is zero. Every send is an `adminAudit` row.\n *\n * The rules and the sending are `tap-to-pay-launch.ts`; this file is the\n * door. The operator's note is `docs/TAP_TO_PAY_LAUNCH.md`.\n *=========================================*/\n\nconst json = (body: unknown, status = 200) =>\n Response.json(body, { status, headers: { 'Cache-Control': 'no-store' } })\n\nconst CHANNELS: readonly TapToPayChannel[] = ['email', 'push']\n\n/** The auth system's answer for each uid, 100 at a time. */\nasync function authUsers(uids: readonly string[]): Promise<TapToPayAuthUser[]> {\n const auth = firebaseAdmin.app().auth()\n const users: TapToPayAuthUser[] = []\n for (let index = 0; index < uids.length; index += 100) {\n const result = await auth.getUsers(uids.slice(index, index + 100).map((uid) => ({ uid })))\n for (const user of result.users) {\n users.push({\n uid: user.uid,\n email: user.email ?? null,\n disabled: user.disabled,\n staff: Boolean(user.customClaims?.['staff']),\n })\n }\n }\n return users\n}\n\n/** The deployment's dependencies; the send halves only for a send. */\nfunction launchDeps(send: boolean): TapToPayLaunchDeps {\n const firestore = firebaseAdmin.app().firestore()\n const brands = new Map<string, Promise<SystemEmailBrand>>()\n const brandFor = (orgId: string) => {\n if (!brands.has(orgId)) brands.set(orgId, orgSystemEmailBrand(orgId))\n return brands.get(orgId) as Promise<SystemEmailBrand>\n }\n return {\n db: firestore,\n authUsers,\n isSuppressed: (email) => isEmailSuppressed(email),\n consoleOrigin: platformConsoleOrigin(),\n env: process.env,\n ...(send\n ? {\n sendEmail: async ({ to, orgId, values }) => {\n const brand = await brandFor(orgId)\n const content = await renderSystemEmailContent(\n TAP_TO_PAY_LAUNCH_EMAIL_KEY,\n tapToPayLaunchMergeValues(values),\n brand,\n tapToPayLaunchFallback(values),\n )\n const result = await sendEmail({\n to,\n ...content,\n ...(brand.fromName ? { fromName: brand.fromName } : {}),\n context: TAP_TO_PAY_LAUNCH_EMAIL_KEY,\n priority: 'bulk',\n headers: { 'List-Unsubscribe': `<${values.preferencesUrl}>` },\n })\n if (result.sent) {\n await meterPlatformEmail().catch(() => undefined)\n return 'sent'\n }\n const reason = (result as { reason?: string }).reason\n return reason === 'rate-limited' || reason === 'frequency-capped' ? 'deferred' : 'failed'\n },\n pushTransport: async () =>\n (await import('@aglyn/tenant-data-admin/server/push-apns')).apnsTransport(),\n }\n : {}),\n }\n}\n\nasync function handler(request: Request): Promise<Response> {\n const { method, body, headers: rawHeaders } = await pluginRequestFromWeb(request)\n const headers = rawHeaders as Partial<Record<string, string>>\n const authorization = headers.authorization ?? ''\n const idToken = authorization.startsWith('Bearer ') ? authorization.slice('Bearer '.length) : undefined\n if (!idToken) return json({ error: 'Unauthenticated' }, 401)\n if (method !== 'GET' && method !== 'POST') return json({ error: 'Method not allowed' }, 405)\n\n try {\n const decoded = await firebaseAdmin.app().auth().verifyIdToken(idToken)\n if (!decoded.email_verified && !isImpersonationSession(decoded)) return emailUnverifiedResponse()\n if (!decoded['staff']) return json({ error: 'Staff only' }, 403)\n // A missing role claim reads as the least one, never as super.\n const role = String(decoded['staffRole'] ?? 'support')\n\n const input = (method === 'POST' ? (body ?? {}) : {}) as Record<string, unknown>\n if (input['send'] !== undefined && typeof input['send'] !== 'boolean') {\n return json({ error: 'send must be true or false' }, 400)\n }\n const send = input['send'] === true\n const requested = input['channels']\n if (requested !== undefined && (!Array.isArray(requested) || requested.some((c) => !CHANNELS.includes(c)))) {\n return json({ error: 'channels must list \"email\", \"push\" or both' }, 400)\n }\n const channels = (requested as TapToPayChannel[] | undefined) ?? [...CHANNELS]\n\n if (send) {\n if (role !== 'super') return json({ error: 'Sending the launch requires the super staff role.' }, 403)\n // Validated before anything goes out: a send cannot be recalled.\n const reason = String(input['reason'] ?? '').trim().slice(0, 500)\n if (reason.length < 8) {\n return json({ error: 'A send needs a reason of at least 8 characters; it reaches every eligible merchant.' }, 400)\n }\n const report = await runTapToPayLaunch({ send: true, channels }, launchDeps(true))\n if (report.refused) {\n return json(\n {\n error:\n 'Tap to Pay on iPhone is not released on this deployment (TAP_TO_PAY_IPHONE_RELEASED is not true). Nothing was sent.',\n report,\n },\n 409,\n )\n }\n await addAdminAudit(firebaseAdmin.app().firestore(), {\n action: 'tap-to-pay-launch.send',\n actorUid: decoded.uid,\n actorEmail: decoded.email ? String(decoded.email) : null,\n target: 'tap-to-pay-iphone-launch',\n reason,\n before: null,\n after: {\n channels,\n emailSent: report.email.sent,\n emailDeferred: report.email.deferred,\n emailFailed: report.email.failed,\n pushSent: report.push.sent,\n pushFailed: report.push.failed,\n remaining: report.remaining,\n image: report.image,\n },\n at: firebaseAdmin.firestore.FieldValue.serverTimestamp(),\n })\n return json(report)\n }\n\n return json(await runTapToPayLaunch({ send: false, channels }, launchDeps(false)))\n } catch (error) {\n const unauthenticated = invalidIdTokenResponse(error)\n if (unauthenticated) return unauthenticated\n console.error('[tap-to-pay-launch] failed', error)\n return json({ error: 'The launch could not be read' }, 500)\n }\n}\n\nexport { handler as tapToPayLaunchAdmin }\n"],"names":["platformConsoleOrigin","pluginRequestFromWeb","sendEmail","TAP_TO_PAY_LAUNCH_EMAIL_KEY","tapToPayLaunchMergeValues","emailUnverifiedResponse","firebaseAdmin","isEmailSuppressed","isImpersonationSession","meterPlatformEmail","addAdminAudit","invalidIdTokenResponse","orgSystemEmailBrand","renderSystemEmailContent","runTapToPayLaunch","tapToPayLaunchFallback","json","body","status","Response","headers","CHANNELS","authUsers","uids","auth","app","users","index","length","result","getUsers","slice","map","uid","user","push","email","disabled","staff","Boolean","customClaims","launchDeps","send","firestore","brands","Map","brandFor","orgId","has","set","get","db","isSuppressed","consoleOrigin","env","process","to","values","brand","content","fromName","context","priority","preferencesUrl","sent","catch","undefined","reason","pushTransport","apnsTransport","handler","request","method","rawHeaders","authorization","idToken","startsWith","error","decoded","verifyIdToken","email_verified","role","String","input","requested","Array","isArray","some","c","includes","channels","trim","report","refused","action","actorUid","actorEmail","target","before","after","emailSent","emailDeferred","deferred","emailFailed","failed","pushSent","pushFailed","remaining","image","at","FieldValue","serverTimestamp","unauthenticated","console","tapToPayLaunchAdmin"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,qBAAqB,QAAQ,wCAAuC;AAC7E,SAASC,oBAAoB,QAAQ,sBAAqB;AAC1D,SAASC,SAAS,EAAEC,2BAA2B,EAAEC,yBAAyB,QAAQ,2BAA0B;AAC5G,SACEC,uBAAuB,EACvBC,aAAa,EACbC,iBAAiB,EACjBC,sBAAsB,EACtBC,kBAAkB,QACb,2BAA0B;AACjC,SAASC,aAAa,QAAQ,oDAAmD;AACjF,SAASC,sBAAsB,QAAQ,mDAAkD;AACzF,SACEC,mBAAmB,EACnBC,wBAAwB,QAEnB,sDAAqD;AAC5D,SACEC,iBAAiB,EACjBC,sBAAsB,QAIjB,yBAAqB;AAE5B;;;;;;;;;;;;;;;;2CAgB2C,GAE3C,MAAMC,OAAO,CAACC,MAAeC,SAAS,GAAG,GACvCC,SAASH,IAAI,CAACC,MAAM;QAAEC;QAAQE,SAAS;YAAE,iBAAiB;QAAW;IAAE;AAEzE,MAAMC,WAAuC;IAAC;IAAS;CAAO;AAE9D,0DAA0D,GAC1D,eAAeC,UAAUC,IAAuB;IAC9C,MAAMC,OAAOlB,cAAcmB,GAAG,GAAGD,IAAI;IACrC,MAAME,QAA4B,EAAE;IACpC,IAAK,IAAIC,QAAQ,GAAGA,QAAQJ,KAAKK,MAAM,EAAED,SAAS,IAAK;QACrD,MAAME,SAAS,MAAML,KAAKM,QAAQ,CAACP,KAAKQ,KAAK,CAACJ,OAAOA,QAAQ,KAAKK,GAAG,CAAC,CAACC,MAAS,CAAA;gBAAEA;YAAI,CAAA;QACtF,KAAK,MAAMC,QAAQL,OAAOH,KAAK,CAAE;gBAGtBQ;gBAEQA;YAJjBR,MAAMS,IAAI,CAAC;gBACTF,KAAKC,KAAKD,GAAG;gBACbG,KAAK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U,CAACC,eAAe;YACxD;YACA,OAAO/F,KAAK4E;QACd;QAEA,OAAO5E,KAAK,MAAMF,kBAAkB;YAAE4B,MAAM;YAAOgD;QAAS,GAAGjD,WAAW;IAC5E,EAAE,OAAOoC,OAAO;QACd,MAAMmC,kBAAkBrG,uBAAuBkE;QAC/C,IAAImC,iBAAiB,OAAOA;QAC5BC,QAAQpC,KAAK,CAAC,8BAA8BA;QAC5C,OAAO7D,KAAK;YAAE6D,OAAO;QAA+B,GAAG;IACzD;AACF;AAEA,SAASP,WAAW4C,mBAAmB,GAAE"}
@@ -0,0 +1,114 @@
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 { TAP_TO_PAY_LAUNCH_EMAIL_KEY, type TapToPayLaunchEmailValues } from '@aglyn/shared-util-email';
18
+ import type { PushMessage, PushTransport } from '@aglyn/tenant-data-admin/server/push-delivery';
19
+ import { type TapToPayLaunchPerson, type TapToPayLaunchPlan, type TapToPayLaunchRecipient, type TapToPayLaunchStore } from '../model/tap-to-pay-launch';
20
+ /** Sends per channel per run; a larger audience takes another run. */
21
+ export declare const TAP_TO_PAY_LAUNCH_BATCH = 200;
22
+ type Db = any;
23
+ export type TapToPayChannel = 'email' | 'push';
24
+ /** What the auth system says about one account. */
25
+ export interface TapToPayAuthUser {
26
+ uid: string;
27
+ email: string | null;
28
+ disabled: boolean;
29
+ staff: boolean;
30
+ }
31
+ export interface TapToPayLaunchDeps {
32
+ db: Db;
33
+ /** The accounts, by uid; a uid it leaves out has no account. */
34
+ authUsers: (uids: readonly string[]) => Promise<TapToPayAuthUser[]>;
35
+ isSuppressed: (email: string) => Promise<boolean>;
36
+ /** Whether a store owner's selling account may be charged now (its profile's fields). */
37
+ chargesReady?: (profile: Record<string, unknown>) => boolean;
38
+ /** Renders and sends one email; true once it was accepted. */
39
+ sendEmail?: (input: {
40
+ to: string;
41
+ orgId: string;
42
+ values: TapToPayLaunchEmailValues;
43
+ }) => Promise<'sent' | 'deferred' | 'failed'>;
44
+ /** The APNs transport, or null where none is configured. */
45
+ pushTransport?: () => Promise<PushTransport | null>;
46
+ consoleOrigin: string;
47
+ env: Record<string, string | undefined>;
48
+ now?: () => number;
49
+ }
50
+ export interface TapToPayLaunchOptions {
51
+ /** Send for real. Absent or false: a dry run. */
52
+ send?: boolean;
53
+ channels?: readonly TapToPayChannel[];
54
+ /** Sends per channel this run. */
55
+ batch?: number;
56
+ }
57
+ export interface TapToPayLaunchSampleRow {
58
+ address: string;
59
+ role: 'owner or admin' | 'register';
60
+ store: string;
61
+ }
62
+ export interface TapToPayLaunchReport {
63
+ dryRun: boolean;
64
+ released: boolean;
65
+ /** A send that was refused, and why; nothing was sent. */
66
+ refused?: 'not-released';
67
+ stores: TapToPayLaunchPlan['stores'];
68
+ audience: number;
69
+ email: {
70
+ due: number;
71
+ skipped: TapToPayLaunchPlan['emailSkipped'];
72
+ sent: number;
73
+ deferred: number;
74
+ failed: number;
75
+ sample: TapToPayLaunchSampleRow[];
76
+ };
77
+ push: {
78
+ due: number;
79
+ skipped: TapToPayLaunchPlan['pushSkipped'];
80
+ sent: number;
81
+ failed: number;
82
+ /** Devices whose token APNs said is gone, forgotten. */
83
+ pruned: number;
84
+ /** No APNs transport configured: nothing could be pushed. */
85
+ unconfigured: boolean;
86
+ sample: TapToPayLaunchSampleRow[];
87
+ };
88
+ /** Still due after this run's batch: run again. */
89
+ remaining: {
90
+ email: number;
91
+ push: number;
92
+ };
93
+ /** Whether the email carries Apple's image (its hosted address is configured). */
94
+ image: boolean;
95
+ }
96
+ /** Every workspace's stores, as the rules read them. */
97
+ export declare function readTapToPayLaunchStores(deps: TapToPayLaunchDeps): Promise<TapToPayLaunchStore[]>;
98
+ /** Each person's facts, for the uids the eligible stores name. */
99
+ export declare function readTapToPayLaunchPeople(uids: readonly string[], deps: TapToPayLaunchDeps): Promise<Map<string, TapToPayLaunchPerson>>;
100
+ /** Where the button and the push open, for one store. */
101
+ export declare function tapToPayLaunchLink(store: TapToPayLaunchStore, origin: string): string;
102
+ /** The push one person is sent. */
103
+ export declare function tapToPayLaunchPushMessage(recipient: TapToPayLaunchRecipient): PushMessage;
104
+ /**
105
+ * The launch: a dry run unless `send` is set, and a send refused unless the
106
+ * deployment says Tap to Pay on iPhone is released.
107
+ */
108
+ export declare function runTapToPayLaunch(options: TapToPayLaunchOptions, deps: TapToPayLaunchDeps): Promise<TapToPayLaunchReport>;
109
+ /** The plain-text fallback and subject one email is sent with when a render produces nothing. */
110
+ export declare function tapToPayLaunchFallback(values: TapToPayLaunchEmailValues): {
111
+ subject: string;
112
+ text: string;
113
+ };
114
+ export { TAP_TO_PAY_LAUNCH_EMAIL_KEY };