@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.
- package/package.json +13 -13
- package/src/lib/components/cart.js +3 -1
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/console/catalog-organization-card.component.js +82 -69
- package/src/lib/components/console/catalog-organization-card.component.js.map +1 -1
- package/src/lib/components/console/discounts-card.component.js +46 -25
- package/src/lib/components/console/discounts-card.component.js.map +1 -1
- package/src/lib/components/console/gift-cards-card.component.js +81 -55
- package/src/lib/components/console/gift-cards-card.component.js.map +1 -1
- package/src/lib/components/console/host-coupons-card.component.js +36 -25
- package/src/lib/components/console/host-coupons-card.component.js.map +1 -1
- package/src/lib/components/console/locations-card.component.js +53 -32
- package/src/lib/components/console/locations-card.component.js.map +1 -1
- package/src/lib/components/console/member-posts-card.component.js +35 -32
- package/src/lib/components/console/member-posts-card.component.js.map +1 -1
- package/src/lib/components/console/new-store-tax-question.component.d.ts +17 -0
- package/src/lib/components/console/new-store-tax-question.component.js +197 -0
- package/src/lib/components/console/new-store-tax-question.component.js.map +1 -0
- package/src/lib/components/console/payments-settings-card.component.js +132 -5
- package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-api.d.ts +6 -0
- package/src/lib/components/console/pos/pos-api.js.map +1 -1
- package/src/lib/components/console/pos/pos-tax-notice.component.d.ts +21 -0
- package/src/lib/components/console/pos/pos-tax-notice.component.js +59 -0
- package/src/lib/components/console/pos/pos-tax-notice.component.js.map +1 -0
- package/src/lib/components/console/pos-page.component.js +65 -17
- package/src/lib/components/console/pos-page.component.js.map +1 -1
- package/src/lib/components/console/registers-card.component.js +21 -13
- package/src/lib/components/console/registers-card.component.js.map +1 -1
- package/src/lib/components/console/reviews-moderation-card.component.js +108 -68
- package/src/lib/components/console/reviews-moderation-card.component.js.map +1 -1
- package/src/lib/components/console/site-member-purchases.component.js +5 -3
- package/src/lib/components/console/site-member-purchases.component.js.map +1 -1
- package/src/lib/components/console/subscription-detail-dialog.component.d.ts +2 -0
- package/src/lib/components/console/subscription-detail-dialog.component.js +1 -1
- package/src/lib/components/console/subscription-detail-dialog.component.js.map +1 -1
- package/src/lib/components/console/subscriptions-card.component.js +13 -5
- package/src/lib/components/console/subscriptions-card.component.js.map +1 -1
- package/src/lib/components/console/suppliers-card.component.js +47 -40
- package/src/lib/components/console/suppliers-card.component.js.map +1 -1
- package/src/lib/components/product-choice-cards.js +2 -1
- package/src/lib/components/product-choice-cards.js.map +1 -1
- package/src/lib/components/product-detail.js +9 -4
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.js +3 -1
- package/src/lib/components/product-grid.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/components/store-image-sizing.d.ts +46 -0
- package/src/lib/components/store-image-sizing.js +53 -0
- package/src/lib/components/store-image-sizing.js.map +1 -0
- package/src/lib/components/wishlist.js +2 -1
- package/src/lib/components/wishlist.js.map +1 -1
- package/src/lib/declarations.console-server.js +10 -0
- package/src/lib/declarations.console-server.js.map +1 -1
- package/src/lib/model/commerce-tax-step.d.ts +123 -0
- package/src/lib/model/commerce-tax-step.js +185 -0
- package/src/lib/model/commerce-tax-step.js.map +1 -0
- package/src/lib/model/index.d.ts +1 -0
- package/src/lib/model/index.js +1 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/payments-setup-status.d.ts +40 -0
- package/src/lib/model/payments-setup-status.js +63 -0
- package/src/lib/model/payments-setup-status.js.map +1 -1
- package/src/lib/model/subscription-view.d.ts +19 -0
- package/src/lib/model/subscription-view.js +16 -0
- package/src/lib/model/subscription-view.js.map +1 -1
- package/src/lib/model/tap-to-pay-launch.d.ts +103 -0
- package/src/lib/model/tap-to-pay-launch.js +148 -0
- package/src/lib/model/tap-to-pay-launch.js.map +1 -0
- package/src/lib/plugin.js +12 -0
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/server/billing-webhook.js +140 -116
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/checkout.js +15 -4
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/connect-return.d.ts +83 -0
- package/src/lib/server/connect-return.js +105 -0
- package/src/lib/server/connect-return.js.map +1 -0
- package/src/lib/server/connect.d.ts +18 -0
- package/src/lib/server/connect.js +60 -6
- package/src/lib/server/connect.js.map +1 -1
- package/src/lib/server/new-store-tax.d.ts +10 -0
- package/src/lib/server/new-store-tax.js +43 -0
- package/src/lib/server/new-store-tax.js.map +1 -0
- package/src/lib/server/pos-payment.js +3 -2
- package/src/lib/server/pos-payment.js.map +1 -1
- package/src/lib/server/pos-tax-step.d.ts +43 -0
- package/src/lib/server/pos-tax-step.js +55 -0
- package/src/lib/server/pos-tax-step.js.map +1 -0
- package/src/lib/server/pos-terminal-connection-token.d.ts +10 -1
- package/src/lib/server/pos-terminal-connection-token.js +18 -7
- package/src/lib/server/pos-terminal-connection-token.js.map +1 -1
- package/src/lib/server/pos-terminal.d.ts +9 -0
- package/src/lib/server/pos-terminal.js +17 -1
- package/src/lib/server/pos-terminal.js.map +1 -1
- package/src/lib/server/tap-to-pay-launch-admin.d.ts +18 -0
- package/src/lib/server/tap-to-pay-launch-admin.js +204 -0
- package/src/lib/server/tap-to-pay-launch-admin.js.map +1 -0
- package/src/lib/server/tap-to-pay-launch.d.ts +114 -0
- package/src/lib/server/tap-to-pay-launch.js +408 -0
- package/src/lib/server/tap-to-pay-launch.js.map +1 -0
- package/src/lib/server.js +15 -0
- package/src/lib/server.js.map +1 -1
|
@@ -0,0 +1,408 @@
|
|
|
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 { buildRoute, Route } from "@aglyn/aglyn/app-utils/console-routes";
|
|
18
|
+
import { isSignupCanaryEmail, isSignupCanaryOrgSlug } from "@aglyn/aglyn/app-utils/health-report";
|
|
19
|
+
import { isAccountBanLockdownReason, normalizeOrgLockdown } from "@aglyn/aglyn/app-utils/lockdown";
|
|
20
|
+
import { isApnsDeviceToken, MOBILE_APP_BUNDLES, MOBILE_DEVICE_STALE_MS, MOBILE_DEVICES_COLLECTION, MOBILE_DEVICES_PER_USER, mobilePushData } from "@aglyn/aglyn/app-utils/notification-push";
|
|
21
|
+
import { notificationSound } from "@aglyn/aglyn/app-utils/notification-sounds";
|
|
22
|
+
import { readPlatformMarketingConsent } from "@aglyn/aglyn/app-utils/platform-marketing-consent";
|
|
23
|
+
import { isHostPluginEnabled } from "@aglyn/aglyn/server";
|
|
24
|
+
import { TAP_TO_PAY_APPLE_COPY, TAP_TO_PAY_LAUNCH_EMAIL_KEY, TAP_TO_PAY_LAUNCH_IMAGE_URL_ENV, TAP_TO_PAY_LAUNCH_SUBJECT, tapToPayLaunchEmailText, tapToPayLaunchMergeValues } from "@aglyn/shared-util-email";
|
|
25
|
+
import { merchantAccountReadiness } from "@aglyn/tenant-data-admin/server/payment-provider";
|
|
26
|
+
import { BUNDLE_ID } from "../constants/bundle-common.js";
|
|
27
|
+
import { storeBaseCurrency } from "../model/commerce-currency.js";
|
|
28
|
+
import { maskAddress, planTapToPayLaunch, TAP_TO_PAY_LAUNCH_FIELD, TAP_TO_PAY_LAUNCH_PUSH_TYPE, TAP_TO_PAY_LAUNCH_RECORD, TAP_TO_PAY_SET_UP_PATH, tapToPayReleased } from "../model/tap-to-pay-launch.js";
|
|
29
|
+
/*==========================================
|
|
30
|
+
* THE TAP TO PAY ON IPHONE LAUNCH, SENT ONCE (AGL-4061).
|
|
31
|
+
*
|
|
32
|
+
* Reads who can use Tap to Pay on iPhone (`model/tap-to-pay-launch.ts` holds
|
|
33
|
+
* the rules), and either reports who would be told what (the DEFAULT: a dry
|
|
34
|
+
* run sends nothing and writes nothing) or, asked to send and only once the
|
|
35
|
+
* deployment says Tap to Pay on iPhone is released
|
|
36
|
+
* (`TAP_TO_PAY_IPHONE_RELEASED=true`), sends Apple's launch email and push.
|
|
37
|
+
*
|
|
38
|
+
* Once per person, per channel: before a send the person's record on
|
|
39
|
+
* `users/{uid}.launchAnnouncements.tapToPayIPhone` is claimed in a
|
|
40
|
+
* transaction, and the send's time replaces the claim. A second run (or two
|
|
41
|
+
* at once) finds the record and skips them. A failed send releases the claim,
|
|
42
|
+
* so the next run tries again.
|
|
43
|
+
*
|
|
44
|
+
* The push goes straight to each person's Aglyn POS installs on an iPhone or
|
|
45
|
+
* iPad (APNs, the `com.aglyn.pos` topic), never through the notification
|
|
46
|
+
* fan-out: the fan-out would also reach the Aglyn app, and Aglyn POS on
|
|
47
|
+
* Android and the Mac. Tapping it opens Card readers in Aglyn POS, starting
|
|
48
|
+
* Set up Tap to Pay on iPhone (`commerce.tap-to-pay-link`).
|
|
49
|
+
*
|
|
50
|
+
* Never throws for one person: a failure is counted and the run goes on.
|
|
51
|
+
*=========================================*/ /** Workspaces read per run. */ const MAX_ORGS = 5000;
|
|
52
|
+
/** Registers read per store, and shifts per register, for who ran them. */ const MAX_REGISTERS = 50;
|
|
53
|
+
const MAX_SHIFTS = 500;
|
|
54
|
+
/** Sends per channel per run; a larger audience takes another run. */ export const TAP_TO_PAY_LAUNCH_BATCH = 200;
|
|
55
|
+
/** A claim older than this was left by a run that died mid-send: it no longer holds. */ const CLAIM_TTL_MS = 15 * 60 * 1000;
|
|
56
|
+
/** People shown in a report's sample. */ const SAMPLE = 10;
|
|
57
|
+
function ms(value) {
|
|
58
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value;
|
|
59
|
+
const toMillis = value == null ? void 0 : value.toMillis;
|
|
60
|
+
return typeof toMillis === 'function' ? toMillis.call(value) : null;
|
|
61
|
+
}
|
|
62
|
+
const text = (value)=>typeof value === 'string' ? value.trim() : '';
|
|
63
|
+
/** The launch record on a `users/{uid}` document. */ function launchRecord(data) {
|
|
64
|
+
const field = data == null ? void 0 : data[TAP_TO_PAY_LAUNCH_FIELD];
|
|
65
|
+
const record = field == null ? void 0 : field[TAP_TO_PAY_LAUNCH_RECORD];
|
|
66
|
+
return record && typeof record === 'object' ? record : {};
|
|
67
|
+
}
|
|
68
|
+
function defaultChargesReady(profile) {
|
|
69
|
+
return merchantAccountReadiness({
|
|
70
|
+
accountId: profile['stripeAccountId'],
|
|
71
|
+
chargesEnabled: profile['stripeChargesEnabled'],
|
|
72
|
+
accountLivemode: profile['stripeAccountLivemode']
|
|
73
|
+
}) === 'ready';
|
|
74
|
+
}
|
|
75
|
+
/** Every workspace's stores, as the rules read them. */ export async function readTapToPayLaunchStores(deps) {
|
|
76
|
+
var _deps_chargesReady;
|
|
77
|
+
const { db } = deps;
|
|
78
|
+
const chargesReady = (_deps_chargesReady = deps.chargesReady) != null ? _deps_chargesReady : defaultChargesReady;
|
|
79
|
+
const orgs = await db.collection('orgs').limit(MAX_ORGS).get();
|
|
80
|
+
const stores = [];
|
|
81
|
+
for (const orgDoc of orgs.docs){
|
|
82
|
+
var _orgDoc_data, _org_hosts, _profile_data;
|
|
83
|
+
const org = (_orgDoc_data = orgDoc.data()) != null ? _orgDoc_data : {};
|
|
84
|
+
const hostIds = Object.keys((_org_hosts = org['hosts']) != null ? _org_hosts : {});
|
|
85
|
+
if (!hostIds.length) continue;
|
|
86
|
+
const lock = normalizeOrgLockdown(org);
|
|
87
|
+
const banned = Boolean(lock && isAccountBanLockdownReason(lock.reason));
|
|
88
|
+
const orgSlug = text(org['slug']);
|
|
89
|
+
const ownerUid = text(org['ownerUid']);
|
|
90
|
+
const [profile, members] = await Promise.all([
|
|
91
|
+
ownerUid ? db.collection('profiles').doc(ownerUid).get() : Promise.resolve(null),
|
|
92
|
+
db.collection('orgs').doc(orgDoc.id).collection('members').get()
|
|
93
|
+
]);
|
|
94
|
+
const ready = Boolean((profile == null ? void 0 : profile.exists) && chargesReady((_profile_data = profile.data()) != null ? _profile_data : {}));
|
|
95
|
+
const managerUids = new Set(ownerUid ? [
|
|
96
|
+
ownerUid
|
|
97
|
+
] : []);
|
|
98
|
+
for (const member of members.docs){
|
|
99
|
+
const role = member.get('role');
|
|
100
|
+
if (role === 'owner' || role === 'admin') managerUids.add(member.id);
|
|
101
|
+
}
|
|
102
|
+
for (const hostId of hostIds){
|
|
103
|
+
var _host_data;
|
|
104
|
+
const hostRef = db.collection('hosts').doc(hostId);
|
|
105
|
+
const [host, storeSettings, registers] = await Promise.all([
|
|
106
|
+
hostRef.get(),
|
|
107
|
+
hostRef.collection('settings').doc('store').get(),
|
|
108
|
+
hostRef.collection('registers').limit(MAX_REGISTERS).get()
|
|
109
|
+
]);
|
|
110
|
+
if (!host.exists) continue;
|
|
111
|
+
const hostData = (_host_data = host.data()) != null ? _host_data : {};
|
|
112
|
+
const registerUids = new Set();
|
|
113
|
+
for (const register of registers.docs){
|
|
114
|
+
const shifts = await register.ref.collection('shifts').limit(MAX_SHIFTS).get();
|
|
115
|
+
for (const shift of shifts.docs){
|
|
116
|
+
const openedBy = text(shift.get('openedBy'));
|
|
117
|
+
if (openedBy) registerUids.add(openedBy);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
stores.push({
|
|
121
|
+
orgId: orgDoc.id,
|
|
122
|
+
hostId,
|
|
123
|
+
orgName: text(org['name']) || 'your workspace',
|
|
124
|
+
orgSlug,
|
|
125
|
+
hostSlug: text(hostData['subdomain']) || hostId,
|
|
126
|
+
commerceEnabled: isHostPluginEnabled(org, hostData, BUNDLE_ID),
|
|
127
|
+
chargesReady: ready,
|
|
128
|
+
currency: storeBaseCurrency(storeSettings.exists ? storeSettings.data() : undefined).toUpperCase(),
|
|
129
|
+
registers: registers.size,
|
|
130
|
+
banned,
|
|
131
|
+
canary: isSignupCanaryOrgSlug(orgSlug),
|
|
132
|
+
managerUids: [
|
|
133
|
+
...managerUids
|
|
134
|
+
],
|
|
135
|
+
registerUids: [
|
|
136
|
+
...registerUids
|
|
137
|
+
]
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return stores;
|
|
142
|
+
}
|
|
143
|
+
/** Each person's facts, for the uids the eligible stores name. */ export async function readTapToPayLaunchPeople(uids, deps) {
|
|
144
|
+
var _deps_now;
|
|
145
|
+
const { db } = deps;
|
|
146
|
+
const now = ((_deps_now = deps.now) != null ? _deps_now : Date.now)();
|
|
147
|
+
const people = new Map();
|
|
148
|
+
const accounts = new Map((await deps.authUsers(uids)).map((user)=>[
|
|
149
|
+
user.uid,
|
|
150
|
+
user
|
|
151
|
+
]));
|
|
152
|
+
for (const uid of uids){
|
|
153
|
+
const account = accounts.get(uid);
|
|
154
|
+
if (!account) continue;
|
|
155
|
+
const userRef = db.collection('users').doc(uid);
|
|
156
|
+
const [userDoc, devices] = await Promise.all([
|
|
157
|
+
userRef.get(),
|
|
158
|
+
userRef.collection(MOBILE_DEVICES_COLLECTION).where('app', '==', 'aglyn-pos').limit(MOBILE_DEVICES_PER_USER).get()
|
|
159
|
+
]);
|
|
160
|
+
const data = userDoc.exists ? userDoc.data() : undefined;
|
|
161
|
+
const record = launchRecord(data);
|
|
162
|
+
const posIosDevices = devices.docs.filter((device)=>{
|
|
163
|
+
if (device.get('platform') !== 'ios' || device.get('transport') !== 'apns') return false;
|
|
164
|
+
if (!isApnsDeviceToken(device.get('token'))) return false;
|
|
165
|
+
const seen = ms(device.get('lastSeen'));
|
|
166
|
+
return seen === null || now - seen <= MOBILE_DEVICE_STALE_MS;
|
|
167
|
+
}).length;
|
|
168
|
+
const email = account.email;
|
|
169
|
+
people.set(uid, {
|
|
170
|
+
uid,
|
|
171
|
+
email,
|
|
172
|
+
staff: account.staff,
|
|
173
|
+
disabled: account.disabled,
|
|
174
|
+
declinedProductEmail: readPlatformMarketingConsent(data != null ? data : {}).decision === 'declined',
|
|
175
|
+
suppressed: email ? await deps.isSuppressed(email) : false,
|
|
176
|
+
posIosDevices,
|
|
177
|
+
emailedAtMs: ms(record['emailAtMs']),
|
|
178
|
+
pushedAtMs: ms(record['pushAtMs'])
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return people;
|
|
182
|
+
}
|
|
183
|
+
/** Where the button and the push open, for one store. */ export function tapToPayLaunchLink(store, origin) {
|
|
184
|
+
return `${origin}${buildRoute(Route.HOST_DASHBOARD, {
|
|
185
|
+
orgSlug: store.orgSlug,
|
|
186
|
+
host: store.hostSlug
|
|
187
|
+
})}${TAP_TO_PAY_SET_UP_PATH}`;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Claims the person's record for one channel. False when it was already sent,
|
|
191
|
+
* or another run holds a fresh claim.
|
|
192
|
+
*/ async function claim(db, uid, channel, now) {
|
|
193
|
+
const ref = db.collection('users').doc(uid);
|
|
194
|
+
return db.runTransaction(async (transaction)=>{
|
|
195
|
+
const snapshot = await transaction.get(ref);
|
|
196
|
+
const record = launchRecord(snapshot.exists ? snapshot.data() : undefined);
|
|
197
|
+
if (ms(record[`${channel}AtMs`]) !== null) return false;
|
|
198
|
+
const claimed = ms(record[`${channel}ClaimAtMs`]);
|
|
199
|
+
if (claimed !== null && now - claimed < CLAIM_TTL_MS) return false;
|
|
200
|
+
const next = _extends({}, record, {
|
|
201
|
+
[`${channel}ClaimAtMs`]: now
|
|
202
|
+
});
|
|
203
|
+
transaction.set(ref, {
|
|
204
|
+
[TAP_TO_PAY_LAUNCH_FIELD]: {
|
|
205
|
+
[TAP_TO_PAY_LAUNCH_RECORD]: next
|
|
206
|
+
}
|
|
207
|
+
}, {
|
|
208
|
+
merge: true
|
|
209
|
+
});
|
|
210
|
+
return true;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/** Settles a claim: the send's time on success, the claim released otherwise. */ async function settle(db, uid, channel, sentAtMs) {
|
|
214
|
+
const ref = db.collection('users').doc(uid);
|
|
215
|
+
await db.runTransaction(async (transaction)=>{
|
|
216
|
+
const snapshot = await transaction.get(ref);
|
|
217
|
+
const record = _extends({}, launchRecord(snapshot.exists ? snapshot.data() : undefined));
|
|
218
|
+
delete record[`${channel}ClaimAtMs`];
|
|
219
|
+
if (sentAtMs !== null) record[`${channel}AtMs`] = sentAtMs;
|
|
220
|
+
transaction.set(ref, {
|
|
221
|
+
[TAP_TO_PAY_LAUNCH_FIELD]: {
|
|
222
|
+
[TAP_TO_PAY_LAUNCH_RECORD]: record
|
|
223
|
+
}
|
|
224
|
+
}, {
|
|
225
|
+
merge: true
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
/** The push one person is sent. */ export function tapToPayLaunchPushMessage(recipient) {
|
|
230
|
+
return {
|
|
231
|
+
title: TAP_TO_PAY_APPLE_COPY.push.title,
|
|
232
|
+
body: TAP_TO_PAY_APPLE_COPY.push.body,
|
|
233
|
+
data: mobilePushData({
|
|
234
|
+
type: TAP_TO_PAY_LAUNCH_PUSH_TYPE,
|
|
235
|
+
// Stored-link form (`/{hostId}/…`): each app rewrites it onto the store's console address (AGL-3911).
|
|
236
|
+
link: `/${recipient.store.hostId}${TAP_TO_PAY_SET_UP_PATH}`,
|
|
237
|
+
orgId: recipient.store.orgId,
|
|
238
|
+
hostId: recipient.store.hostId,
|
|
239
|
+
uid: recipient.uid
|
|
240
|
+
}),
|
|
241
|
+
urgent: false
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/** The person's live Aglyn POS installs on an iPhone or iPad, as push targets. */ async function posIosTargets(db, uid, now) {
|
|
245
|
+
const devices = await db.collection('users').doc(uid).collection(MOBILE_DEVICES_COLLECTION).where('app', '==', 'aglyn-pos').limit(MOBILE_DEVICES_PER_USER).get();
|
|
246
|
+
const seen = new Set();
|
|
247
|
+
const targets = [];
|
|
248
|
+
for (const device of devices.docs){
|
|
249
|
+
const token = device.get('token');
|
|
250
|
+
if (device.get('platform') !== 'ios' || device.get('transport') !== 'apns' || !isApnsDeviceToken(token)) continue;
|
|
251
|
+
const lastSeen = ms(device.get('lastSeen'));
|
|
252
|
+
if (lastSeen !== null && now - lastSeen > MOBILE_DEVICE_STALE_MS) continue;
|
|
253
|
+
if (seen.has(token)) continue;
|
|
254
|
+
seen.add(token);
|
|
255
|
+
const environment = device.get('apnsEnvironment');
|
|
256
|
+
targets.push({
|
|
257
|
+
ref: device.ref,
|
|
258
|
+
target: _extends({
|
|
259
|
+
token,
|
|
260
|
+
app: 'aglyn-pos',
|
|
261
|
+
topic: MOBILE_APP_BUNDLES['aglyn-pos'],
|
|
262
|
+
sound: notificationSound(undefined)
|
|
263
|
+
}, environment === 'sandbox' || environment === 'production' ? {
|
|
264
|
+
apnsEnvironment: environment
|
|
265
|
+
} : {})
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return targets;
|
|
269
|
+
}
|
|
270
|
+
const sample = (recipients, people)=>recipients.slice(0, SAMPLE).map((recipient)=>{
|
|
271
|
+
var _people_get;
|
|
272
|
+
return {
|
|
273
|
+
address: maskAddress((_people_get = people.get(recipient.uid)) == null ? void 0 : _people_get.email),
|
|
274
|
+
role: recipient.manager ? 'owner or admin' : 'register',
|
|
275
|
+
store: recipient.store.hostId
|
|
276
|
+
};
|
|
277
|
+
});
|
|
278
|
+
/**
|
|
279
|
+
* The launch: a dry run unless `send` is set, and a send refused unless the
|
|
280
|
+
* deployment says Tap to Pay on iPhone is released.
|
|
281
|
+
*/ export async function runTapToPayLaunch(options, deps) {
|
|
282
|
+
var _deps_now, _options_batch;
|
|
283
|
+
var _options_channels;
|
|
284
|
+
const now = (_deps_now = deps.now) != null ? _deps_now : Date.now;
|
|
285
|
+
const released = tapToPayReleased(deps.env);
|
|
286
|
+
const send = options.send === true;
|
|
287
|
+
const channels = new Set(((_options_channels = options.channels) == null ? void 0 : _options_channels.length) ? options.channels : [
|
|
288
|
+
'email',
|
|
289
|
+
'push'
|
|
290
|
+
]);
|
|
291
|
+
const batch = Math.max(1, Math.min((_options_batch = options.batch) != null ? _options_batch : TAP_TO_PAY_LAUNCH_BATCH, TAP_TO_PAY_LAUNCH_BATCH));
|
|
292
|
+
const imageUrl = text(deps.env[TAP_TO_PAY_LAUNCH_IMAGE_URL_ENV]) || null;
|
|
293
|
+
const stores = await readTapToPayLaunchStores(deps);
|
|
294
|
+
const uids = new Set();
|
|
295
|
+
for (const store of stores)for (const uid of [
|
|
296
|
+
...store.managerUids,
|
|
297
|
+
...store.registerUids
|
|
298
|
+
])uids.add(uid);
|
|
299
|
+
const people = await readTapToPayLaunchPeople([
|
|
300
|
+
...uids
|
|
301
|
+
], deps);
|
|
302
|
+
const plan = planTapToPayLaunch(stores, people, isSignupCanaryEmail);
|
|
303
|
+
const report = {
|
|
304
|
+
dryRun: !send,
|
|
305
|
+
released,
|
|
306
|
+
stores: plan.stores,
|
|
307
|
+
audience: plan.audience.length,
|
|
308
|
+
email: {
|
|
309
|
+
due: channels.has('email') ? plan.email.length : 0,
|
|
310
|
+
skipped: plan.emailSkipped,
|
|
311
|
+
sent: 0,
|
|
312
|
+
deferred: 0,
|
|
313
|
+
failed: 0,
|
|
314
|
+
sample: channels.has('email') ? sample(plan.email, people) : []
|
|
315
|
+
},
|
|
316
|
+
push: {
|
|
317
|
+
due: channels.has('push') ? plan.push.length : 0,
|
|
318
|
+
skipped: plan.pushSkipped,
|
|
319
|
+
sent: 0,
|
|
320
|
+
failed: 0,
|
|
321
|
+
pruned: 0,
|
|
322
|
+
unconfigured: false,
|
|
323
|
+
sample: channels.has('push') ? sample(plan.push, people) : []
|
|
324
|
+
},
|
|
325
|
+
remaining: {
|
|
326
|
+
email: 0,
|
|
327
|
+
push: 0
|
|
328
|
+
},
|
|
329
|
+
image: Boolean(imageUrl && tapToPayLaunchMergeValues({
|
|
330
|
+
orgName: '',
|
|
331
|
+
ctaUrl: '',
|
|
332
|
+
preferencesUrl: '',
|
|
333
|
+
imageUrl
|
|
334
|
+
})['ttp.heroHtml'])
|
|
335
|
+
};
|
|
336
|
+
if (!send) return report;
|
|
337
|
+
if (!released) return _extends({}, report, {
|
|
338
|
+
refused: 'not-released'
|
|
339
|
+
});
|
|
340
|
+
const preferencesUrl = `${deps.consoleOrigin}${buildRoute(Route.MANAGE_USER_EMAILS)}`;
|
|
341
|
+
if (channels.has('email') && deps.sendEmail) {
|
|
342
|
+
const due = plan.email.slice(0, batch);
|
|
343
|
+
report.remaining.email = plan.email.length - due.length;
|
|
344
|
+
for (const recipient of due){
|
|
345
|
+
const person = people.get(recipient.uid);
|
|
346
|
+
if (!(person == null ? void 0 : person.email)) continue;
|
|
347
|
+
try {
|
|
348
|
+
if (!await claim(deps.db, recipient.uid, 'email', now())) continue;
|
|
349
|
+
const outcome = await deps.sendEmail({
|
|
350
|
+
to: person.email,
|
|
351
|
+
orgId: recipient.store.orgId,
|
|
352
|
+
values: {
|
|
353
|
+
orgName: recipient.store.orgName,
|
|
354
|
+
ctaUrl: tapToPayLaunchLink(recipient.store, deps.consoleOrigin),
|
|
355
|
+
preferencesUrl,
|
|
356
|
+
imageUrl
|
|
357
|
+
}
|
|
358
|
+
}).catch(()=>'failed');
|
|
359
|
+
await settle(deps.db, recipient.uid, 'email', outcome === 'sent' ? now() : null);
|
|
360
|
+
report.email[outcome] += 1;
|
|
361
|
+
} catch (error) {
|
|
362
|
+
console.error('[tap-to-pay-launch] an email could not be sent', error);
|
|
363
|
+
report.email.failed += 1;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (channels.has('push') && deps.pushTransport && plan.push.length) {
|
|
368
|
+
const transport = await deps.pushTransport().catch(()=>null);
|
|
369
|
+
if (!transport) {
|
|
370
|
+
report.push.unconfigured = true;
|
|
371
|
+
report.remaining.push = plan.push.length;
|
|
372
|
+
} else {
|
|
373
|
+
const due = plan.push.slice(0, batch);
|
|
374
|
+
report.remaining.push = plan.push.length - due.length;
|
|
375
|
+
for (const recipient of due){
|
|
376
|
+
try {
|
|
377
|
+
if (!await claim(deps.db, recipient.uid, 'push', now())) continue;
|
|
378
|
+
const targets = await posIosTargets(deps.db, recipient.uid, now());
|
|
379
|
+
const outcomes = targets.length ? await transport.send(targets.map((entry)=>entry.target), tapToPayLaunchPushMessage(recipient)).catch(()=>targets.map(()=>'failed')) : [];
|
|
380
|
+
for (const [index, outcome] of outcomes.entries()){
|
|
381
|
+
if (outcome === 'prune') {
|
|
382
|
+
var _targets_index;
|
|
383
|
+
await ((_targets_index = targets[index]) == null ? void 0 : _targets_index.ref.delete().catch(()=>undefined));
|
|
384
|
+
report.push.pruned += 1;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
const delivered = outcomes.includes('sent');
|
|
388
|
+
await settle(deps.db, recipient.uid, 'push', delivered ? now() : null);
|
|
389
|
+
if (delivered) report.push.sent += 1;
|
|
390
|
+
else report.push.failed += 1;
|
|
391
|
+
} catch (error) {
|
|
392
|
+
console.error('[tap-to-pay-launch] a push could not be sent', error);
|
|
393
|
+
report.push.failed += 1;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return report;
|
|
399
|
+
}
|
|
400
|
+
/** The plain-text fallback and subject one email is sent with when a render produces nothing. */ export function tapToPayLaunchFallback(values) {
|
|
401
|
+
return {
|
|
402
|
+
subject: TAP_TO_PAY_LAUNCH_SUBJECT,
|
|
403
|
+
text: tapToPayLaunchEmailText(values)
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
export { TAP_TO_PAY_LAUNCH_EMAIL_KEY };
|
|
407
|
+
|
|
408
|
+
//# sourceMappingURL=tap-to-pay-launch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/tap-to-pay-launch.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 { buildRoute, Route } from '@aglyn/aglyn/app-utils/console-routes'\nimport { isSignupCanaryEmail, isSignupCanaryOrgSlug } from '@aglyn/aglyn/app-utils/health-report'\nimport { isAccountBanLockdownReason, normalizeOrgLockdown } from '@aglyn/aglyn/app-utils/lockdown'\nimport {\n isApnsDeviceToken,\n MOBILE_APP_BUNDLES,\n MOBILE_DEVICE_STALE_MS,\n MOBILE_DEVICES_COLLECTION,\n MOBILE_DEVICES_PER_USER,\n mobilePushData,\n} from '@aglyn/aglyn/app-utils/notification-push'\nimport { notificationSound } from '@aglyn/aglyn/app-utils/notification-sounds'\nimport { readPlatformMarketingConsent } from '@aglyn/aglyn/app-utils/platform-marketing-consent'\nimport { isHostPluginEnabled } from '@aglyn/aglyn/server'\nimport {\n TAP_TO_PAY_APPLE_COPY,\n TAP_TO_PAY_LAUNCH_EMAIL_KEY,\n TAP_TO_PAY_LAUNCH_IMAGE_URL_ENV,\n TAP_TO_PAY_LAUNCH_SUBJECT,\n tapToPayLaunchEmailText,\n tapToPayLaunchMergeValues,\n type TapToPayLaunchEmailValues,\n} from '@aglyn/shared-util-email'\nimport { merchantAccountReadiness } from '@aglyn/tenant-data-admin/server/payment-provider'\nimport type { PushMessage, PushTarget, PushTransport } from '@aglyn/tenant-data-admin/server/push-delivery'\nimport { BUNDLE_ID } from '../constants/bundle-common'\nimport { storeBaseCurrency } from '../model/commerce-currency'\nimport {\n maskAddress,\n planTapToPayLaunch,\n TAP_TO_PAY_LAUNCH_FIELD,\n TAP_TO_PAY_LAUNCH_PUSH_TYPE,\n TAP_TO_PAY_LAUNCH_RECORD,\n TAP_TO_PAY_SET_UP_PATH,\n tapToPayReleased,\n type TapToPayLaunchPerson,\n type TapToPayLaunchPlan,\n type TapToPayLaunchRecipient,\n type TapToPayLaunchStore,\n} from '../model/tap-to-pay-launch'\n\n/*==========================================\n * THE TAP TO PAY ON IPHONE LAUNCH, SENT ONCE (AGL-4061).\n *\n * Reads who can use Tap to Pay on iPhone (`model/tap-to-pay-launch.ts` holds\n * the rules), and either reports who would be told what (the DEFAULT: a dry\n * run sends nothing and writes nothing) or, asked to send and only once the\n * deployment says Tap to Pay on iPhone is released\n * (`TAP_TO_PAY_IPHONE_RELEASED=true`), sends Apple's launch email and push.\n *\n * Once per person, per channel: before a send the person's record on\n * `users/{uid}.launchAnnouncements.tapToPayIPhone` is claimed in a\n * transaction, and the send's time replaces the claim. A second run (or two\n * at once) finds the record and skips them. A failed send releases the claim,\n * so the next run tries again.\n *\n * The push goes straight to each person's Aglyn POS installs on an iPhone or\n * iPad (APNs, the `com.aglyn.pos` topic), never through the notification\n * fan-out: the fan-out would also reach the Aglyn app, and Aglyn POS on\n * Android and the Mac. Tapping it opens Card readers in Aglyn POS, starting\n * Set up Tap to Pay on iPhone (`commerce.tap-to-pay-link`).\n *\n * Never throws for one person: a failure is counted and the run goes on.\n *=========================================*/\n\n/** Workspaces read per run. */\nconst MAX_ORGS = 5000\n/** Registers read per store, and shifts per register, for who ran them. */\nconst MAX_REGISTERS = 50\nconst MAX_SHIFTS = 500\n/** Sends per channel per run; a larger audience takes another run. */\nexport const TAP_TO_PAY_LAUNCH_BATCH = 200\n/** A claim older than this was left by a run that died mid-send: it no longer holds. */\nconst CLAIM_TTL_MS = 15 * 60 * 1000\n/** People shown in a report's sample. */\nconst SAMPLE = 10\n\ntype Db = any\n\nexport type TapToPayChannel = 'email' | 'push'\n\n/** What the auth system says about one account. */\nexport interface TapToPayAuthUser {\n uid: string\n email: string | null\n disabled: boolean\n staff: boolean\n}\n\nexport interface TapToPayLaunchDeps {\n db: Db\n /** The accounts, by uid; a uid it leaves out has no account. */\n authUsers: (uids: readonly string[]) => Promise<TapToPayAuthUser[]>\n isSuppressed: (email: string) => Promise<boolean>\n /** Whether a store owner's selling account may be charged now (its profile's fields). */\n chargesReady?: (profile: Record<string, unknown>) => boolean\n /** Renders and sends one email; true once it was accepted. */\n sendEmail?: (input: { to: string; orgId: string; values: TapToPayLaunchEmailValues }) => Promise<'sent' | 'deferred' | 'failed'>\n /** The APNs transport, or null where none is configured. */\n pushTransport?: () => Promise<PushTransport | null>\n consoleOrigin: string\n env: Record<string, string | undefined>\n now?: () => number\n}\n\nexport interface TapToPayLaunchOptions {\n /** Send for real. Absent or false: a dry run. */\n send?: boolean\n channels?: readonly TapToPayChannel[]\n /** Sends per channel this run. */\n batch?: number\n}\n\nexport interface TapToPayLaunchSampleRow {\n address: string\n role: 'owner or admin' | 'register'\n store: string\n}\n\nexport interface TapToPayLaunchReport {\n dryRun: boolean\n released: boolean\n /** A send that was refused, and why; nothing was sent. */\n refused?: 'not-released'\n stores: TapToPayLaunchPlan['stores']\n audience: number\n email: { due: number; skipped: TapToPayLaunchPlan['emailSkipped']; sent: number; deferred: number; failed: number; sample: TapToPayLaunchSampleRow[] }\n push: {\n due: number\n skipped: TapToPayLaunchPlan['pushSkipped']\n sent: number\n failed: number\n /** Devices whose token APNs said is gone, forgotten. */\n pruned: number\n /** No APNs transport configured: nothing could be pushed. */\n unconfigured: boolean\n sample: TapToPayLaunchSampleRow[]\n }\n /** Still due after this run's batch: run again. */\n remaining: { email: number; push: number }\n /** Whether the email carries Apple's image (its hosted address is configured). */\n image: boolean\n}\n\nfunction ms(value: unknown): number | null {\n if (typeof value === 'number' && Number.isFinite(value)) return value\n const toMillis = (value as { toMillis?: () => number } | null)?.toMillis\n return typeof toMillis === 'function' ? toMillis.call(value) : null\n}\n\nconst text = (value: unknown) => (typeof value === 'string' ? value.trim() : '')\n\n/** The launch record on a `users/{uid}` document. */\nfunction launchRecord(data: Record<string, unknown> | undefined): Record<string, unknown> {\n const field = data?.[TAP_TO_PAY_LAUNCH_FIELD] as Record<string, unknown> | undefined\n const record = field?.[TAP_TO_PAY_LAUNCH_RECORD]\n return record && typeof record === 'object' ? (record as Record<string, unknown>) : {}\n}\n\nfunction defaultChargesReady(profile: Record<string, unknown>): boolean {\n return (\n merchantAccountReadiness({\n accountId: profile['stripeAccountId'],\n chargesEnabled: profile['stripeChargesEnabled'],\n accountLivemode: profile['stripeAccountLivemode'],\n } as never) === 'ready'\n )\n}\n\n/** Every workspace's stores, as the rules read them. */\nexport async function readTapToPayLaunchStores(deps: TapToPayLaunchDeps): Promise<TapToPayLaunchStore[]> {\n const { db } = deps\n const chargesReady = deps.chargesReady ?? defaultChargesReady\n const orgs = await db.collection('orgs').limit(MAX_ORGS).get()\n const stores: TapToPayLaunchStore[] = []\n for (const orgDoc of orgs.docs) {\n const org = (orgDoc.data() ?? {}) as Record<string, unknown>\n const hostIds = Object.keys((org['hosts'] as Record<string, unknown>) ?? {})\n if (!hostIds.length) continue\n const lock = normalizeOrgLockdown(org as never)\n const banned = Boolean(lock && isAccountBanLockdownReason(lock.reason))\n const orgSlug = text(org['slug'])\n const ownerUid = text(org['ownerUid'])\n const [profile, members] = await Promise.all([\n ownerUid ? db.collection('profiles').doc(ownerUid).get() : Promise.resolve(null),\n db.collection('orgs').doc(orgDoc.id).collection('members').get(),\n ])\n const ready = Boolean(profile?.exists && chargesReady((profile.data() ?? {}) as Record<string, unknown>))\n const managerUids = new Set<string>(ownerUid ? [ownerUid] : [])\n for (const member of members.docs) {\n const role = member.get('role')\n if (role === 'owner' || role === 'admin') managerUids.add(member.id)\n }\n for (const hostId of hostIds) {\n const hostRef = db.collection('hosts').doc(hostId)\n const [host, storeSettings, registers] = await Promise.all([\n hostRef.get(),\n hostRef.collection('settings').doc('store').get(),\n hostRef.collection('registers').limit(MAX_REGISTERS).get(),\n ])\n if (!host.exists) continue\n const hostData = (host.data() ?? {}) as Record<string, unknown>\n const registerUids = new Set<string>()\n for (const register of registers.docs) {\n const shifts = await register.ref.collection('shifts').limit(MAX_SHIFTS).get()\n for (const shift of shifts.docs) {\n const openedBy = text(shift.get('openedBy'))\n if (openedBy) registerUids.add(openedBy)\n }\n }\n stores.push({\n orgId: orgDoc.id,\n hostId,\n orgName: text(org['name']) || 'your workspace',\n orgSlug,\n hostSlug: text(hostData['subdomain']) || hostId,\n commerceEnabled: isHostPluginEnabled(org as never, hostData as never, BUNDLE_ID),\n chargesReady: ready,\n currency: storeBaseCurrency((storeSettings.exists ? storeSettings.data() : undefined) as never).toUpperCase(),\n registers: registers.size,\n banned,\n canary: isSignupCanaryOrgSlug(orgSlug),\n managerUids: [...managerUids],\n registerUids: [...registerUids],\n })\n }\n }\n return stores\n}\n\n/** Each person's facts, for the uids the eligible stores name. */\nexport async function readTapToPayLaunchPeople(\n uids: readonly string[],\n deps: TapToPayLaunchDeps,\n): Promise<Map<string, TapToPayLaunchPerson>> {\n const { db } = deps\n const now = (deps.now ?? Date.now)()\n const people = new Map<string, TapToPayLaunchPerson>()\n const accounts = new Map((await deps.authUsers(uids)).map((user) => [user.uid, user]))\n for (const uid of uids) {\n const account = accounts.get(uid)\n if (!account) continue\n const userRef = db.collection('users').doc(uid)\n const [userDoc, devices] = await Promise.all([\n userRef.get(),\n userRef.collection(MOBILE_DEVICES_COLLECTION).where('app', '==', 'aglyn-pos').limit(MOBILE_DEVICES_PER_USER).get(),\n ])\n const data = (userDoc.exists ? userDoc.data() : undefined) as Record<string, unknown> | undefined\n const record = launchRecord(data)\n const posIosDevices = devices.docs.filter((device: any) => {\n if (device.get('platform') !== 'ios' || device.get('transport') !== 'apns') return false\n if (!isApnsDeviceToken(device.get('token'))) return false\n const seen = ms(device.get('lastSeen'))\n return seen === null || now - seen <= MOBILE_DEVICE_STALE_MS\n }).length\n const email = account.email\n people.set(uid, {\n uid,\n email,\n staff: account.staff,\n disabled: account.disabled,\n declinedProductEmail: readPlatformMarketingConsent((data ?? {}) as never).decision === 'declined',\n suppressed: email ? await deps.isSuppressed(email) : false,\n posIosDevices,\n emailedAtMs: ms(record['emailAtMs']),\n pushedAtMs: ms(record['pushAtMs']),\n })\n }\n return people\n}\n\n/** Where the button and the push open, for one store. */\nexport function tapToPayLaunchLink(store: TapToPayLaunchStore, origin: string): string {\n return `${origin}${buildRoute(Route.HOST_DASHBOARD, { orgSlug: store.orgSlug, host: store.hostSlug })}${TAP_TO_PAY_SET_UP_PATH}`\n}\n\n/**\n * Claims the person's record for one channel. False when it was already sent,\n * or another run holds a fresh claim.\n */\nasync function claim(db: Db, uid: string, channel: TapToPayChannel, now: number): Promise<boolean> {\n const ref = db.collection('users').doc(uid)\n return db.runTransaction(async (transaction: any) => {\n const snapshot = await transaction.get(ref)\n const record = launchRecord(snapshot.exists ? snapshot.data() : undefined)\n if (ms(record[`${channel}AtMs`]) !== null) return false\n const claimed = ms(record[`${channel}ClaimAtMs`])\n if (claimed !== null && now - claimed < CLAIM_TTL_MS) return false\n const next = { ...record, [`${channel}ClaimAtMs`]: now }\n transaction.set(ref, { [TAP_TO_PAY_LAUNCH_FIELD]: { [TAP_TO_PAY_LAUNCH_RECORD]: next } }, { merge: true })\n return true\n })\n}\n\n/** Settles a claim: the send's time on success, the claim released otherwise. */\nasync function settle(db: Db, uid: string, channel: TapToPayChannel, sentAtMs: number | null): Promise<void> {\n const ref = db.collection('users').doc(uid)\n await db.runTransaction(async (transaction: any) => {\n const snapshot = await transaction.get(ref)\n const record = { ...launchRecord(snapshot.exists ? snapshot.data() : undefined) }\n delete record[`${channel}ClaimAtMs`]\n if (sentAtMs !== null) record[`${channel}AtMs`] = sentAtMs\n transaction.set(ref, { [TAP_TO_PAY_LAUNCH_FIELD]: { [TAP_TO_PAY_LAUNCH_RECORD]: record } }, { merge: true })\n })\n}\n\n/** The push one person is sent. */\nexport function tapToPayLaunchPushMessage(recipient: TapToPayLaunchRecipient): PushMessage {\n return {\n title: TAP_TO_PAY_APPLE_COPY.push.title,\n body: TAP_TO_PAY_APPLE_COPY.push.body,\n data: mobilePushData({\n type: TAP_TO_PAY_LAUNCH_PUSH_TYPE,\n // Stored-link form (`/{hostId}/…`): each app rewrites it onto the store's console address (AGL-3911).\n link: `/${recipient.store.hostId}${TAP_TO_PAY_SET_UP_PATH}`,\n orgId: recipient.store.orgId,\n hostId: recipient.store.hostId,\n uid: recipient.uid,\n }),\n urgent: false,\n }\n}\n\n/** The person's live Aglyn POS installs on an iPhone or iPad, as push targets. */\nasync function posIosTargets(db: Db, uid: string, now: number): Promise<Array<{ target: PushTarget; ref: any }>> {\n const devices = await db\n .collection('users')\n .doc(uid)\n .collection(MOBILE_DEVICES_COLLECTION)\n .where('app', '==', 'aglyn-pos')\n .limit(MOBILE_DEVICES_PER_USER)\n .get()\n const seen = new Set<string>()\n const targets: Array<{ target: PushTarget; ref: any }> = []\n for (const device of devices.docs) {\n const token = device.get('token')\n if (device.get('platform') !== 'ios' || device.get('transport') !== 'apns' || !isApnsDeviceToken(token)) continue\n const lastSeen = ms(device.get('lastSeen'))\n if (lastSeen !== null && now - lastSeen > MOBILE_DEVICE_STALE_MS) continue\n if (seen.has(token)) continue\n seen.add(token)\n const environment = device.get('apnsEnvironment')\n targets.push({\n ref: device.ref,\n target: {\n token,\n app: 'aglyn-pos',\n topic: MOBILE_APP_BUNDLES['aglyn-pos'],\n sound: notificationSound(undefined),\n ...(environment === 'sandbox' || environment === 'production' ? { apnsEnvironment: environment } : {}),\n },\n })\n }\n return targets\n}\n\nconst sample = (recipients: readonly TapToPayLaunchRecipient[], people: ReadonlyMap<string, TapToPayLaunchPerson>) =>\n recipients.slice(0, SAMPLE).map(\n (recipient): TapToPayLaunchSampleRow => ({\n address: maskAddress(people.get(recipient.uid)?.email),\n role: recipient.manager ? 'owner or admin' : 'register',\n store: recipient.store.hostId,\n }),\n )\n\n/**\n * The launch: a dry run unless `send` is set, and a send refused unless the\n * deployment says Tap to Pay on iPhone is released.\n */\nexport async function runTapToPayLaunch(\n options: TapToPayLaunchOptions,\n deps: TapToPayLaunchDeps,\n): Promise<TapToPayLaunchReport> {\n const now = deps.now ?? Date.now\n const released = tapToPayReleased(deps.env)\n const send = options.send === true\n const channels = new Set<TapToPayChannel>(options.channels?.length ? options.channels : ['email', 'push'])\n const batch = Math.max(1, Math.min(options.batch ?? TAP_TO_PAY_LAUNCH_BATCH, TAP_TO_PAY_LAUNCH_BATCH))\n const imageUrl = text(deps.env[TAP_TO_PAY_LAUNCH_IMAGE_URL_ENV]) || null\n\n const stores = await readTapToPayLaunchStores(deps)\n const uids = new Set<string>()\n for (const store of stores) for (const uid of [...store.managerUids, ...store.registerUids]) uids.add(uid)\n const people = await readTapToPayLaunchPeople([...uids], deps)\n const plan = planTapToPayLaunch(stores, people, isSignupCanaryEmail)\n\n const report: TapToPayLaunchReport = {\n dryRun: !send,\n released,\n stores: plan.stores,\n audience: plan.audience.length,\n email: {\n due: channels.has('email') ? plan.email.length : 0,\n skipped: plan.emailSkipped,\n sent: 0,\n deferred: 0,\n failed: 0,\n sample: channels.has('email') ? sample(plan.email, people) : [],\n },\n push: {\n due: channels.has('push') ? plan.push.length : 0,\n skipped: plan.pushSkipped,\n sent: 0,\n failed: 0,\n pruned: 0,\n unconfigured: false,\n sample: channels.has('push') ? sample(plan.push, people) : [],\n },\n remaining: { email: 0, push: 0 },\n image: Boolean(imageUrl && tapToPayLaunchMergeValues({ orgName: '', ctaUrl: '', preferencesUrl: '', imageUrl })['ttp.heroHtml']),\n }\n if (!send) return report\n if (!released) return { ...report, refused: 'not-released' }\n\n const preferencesUrl = `${deps.consoleOrigin}${buildRoute(Route.MANAGE_USER_EMAILS)}`\n\n if (channels.has('email') && deps.sendEmail) {\n const due = plan.email.slice(0, batch)\n report.remaining.email = plan.email.length - due.length\n for (const recipient of due) {\n const person = people.get(recipient.uid)\n if (!person?.email) continue\n try {\n if (!(await claim(deps.db, recipient.uid, 'email', now()))) continue\n const outcome = await deps\n .sendEmail({\n to: person.email,\n orgId: recipient.store.orgId,\n values: {\n orgName: recipient.store.orgName,\n ctaUrl: tapToPayLaunchLink(recipient.store, deps.consoleOrigin),\n preferencesUrl,\n imageUrl,\n },\n })\n .catch(() => 'failed' as const)\n await settle(deps.db, recipient.uid, 'email', outcome === 'sent' ? now() : null)\n report.email[outcome] += 1\n } catch (error) {\n console.error('[tap-to-pay-launch] an email could not be sent', error)\n report.email.failed += 1\n }\n }\n }\n\n if (channels.has('push') && deps.pushTransport && plan.push.length) {\n const transport = await deps.pushTransport().catch(() => null)\n if (!transport) {\n report.push.unconfigured = true\n report.remaining.push = plan.push.length\n } else {\n const due = plan.push.slice(0, batch)\n report.remaining.push = plan.push.length - due.length\n for (const recipient of due) {\n try {\n if (!(await claim(deps.db, recipient.uid, 'push', now()))) continue\n const targets = await posIosTargets(deps.db, recipient.uid, now())\n const outcomes = targets.length\n ? await transport.send(\n targets.map((entry) => entry.target),\n tapToPayLaunchPushMessage(recipient),\n ).catch(() => targets.map(() => 'failed' as const))\n : []\n for (const [index, outcome] of outcomes.entries()) {\n if (outcome === 'prune') {\n await targets[index]?.ref.delete().catch(() => undefined)\n report.push.pruned += 1\n }\n }\n const delivered = outcomes.includes('sent')\n await settle(deps.db, recipient.uid, 'push', delivered ? now() : null)\n if (delivered) report.push.sent += 1\n else report.push.failed += 1\n } catch (error) {\n console.error('[tap-to-pay-launch] a push could not be sent', error)\n report.push.failed += 1\n }\n }\n }\n }\n return report\n}\n\n/** The plain-text fallback and subject one email is sent with when a render produces nothing. */\nexport function tapToPayLaunchFallback(values: TapToPayLaunchEmailValues): { subject: string; text: string } {\n return { subject: TAP_TO_PAY_LAUNCH_SUBJECT, text: tapToPayLaunchEmailText(values) }\n}\n\nexport { TAP_TO_PAY_LAUNCH_EMAIL_KEY }\n"],"names":["buildRoute","Route","isSignupCanaryEmail","isSignupCanaryOrgSlug","isAccountBanLockdownReason","normalizeOrgLockdown","isApnsDeviceToken","MOBILE_APP_BUNDLES","MOBILE_DEVICE_STALE_MS","MOBILE_DEVICES_COLLECTION","MOBILE_DEVICES_PER_USER","mobilePushData","notificationSound","readPlatformMarketingConsent","isHostPluginEnabled","TAP_TO_PAY_APPLE_COPY","TAP_TO_PAY_LAUNCH_EMAIL_KEY","TAP_TO_PAY_LAUNCH_IMAGE_URL_ENV","TAP_TO_PAY_LAUNCH_SUBJECT","tapToPayLaunchEmailText","tapToPayLaunchMergeValues","merchantAccountReadiness","BUNDLE_ID","storeBaseCurrency","maskAddress","planTapToPayLaunch","TAP_TO_PAY_LAUNCH_FIELD","TAP_TO_PAY_LAUNCH_PUSH_TYPE","TAP_TO_PAY_LAUNCH_RECORD","TAP_TO_PAY_SET_UP_PATH","tapToPayReleased","MAX_ORGS","MAX_REGISTERS","MAX_SHIFTS","TAP_TO_PAY_LAUNCH_BATCH","CLAIM_TTL_MS","SAMPLE","ms","value","Number","isFinite","toMillis","call","text","trim","launchRecord","data","field","record","defaultChargesReady","profile","accountId","chargesEnabled","accountLivemode","readTapToPayLaunchStores","deps","db","chargesReady","orgs","collection","limit","get","stores","orgDoc","docs","org","hostIds","Object","keys","length","lock","banned","Boolean","reason","orgSlug","ownerUid","members","Promise","all","doc","resolve","id","ready","exists","managerUids","Set","member","role","add","hostId","host","hostRef","storeSettings","registers","hostData","registerUids","register","shifts","ref","shift","openedBy","push","orgId","orgName","hostSlug","commerceEnabled","currency","undefined","toUpperCase","size","canary","readTapToPayLaunchPeople","uids","now","Date","people","Map","accounts","authUsers","map","user","uid","account","userRef","userDoc","devices","where","posIosDevices","filter","device","seen","email","set","staff","disabled","declinedProductEmail","decision","suppressed","isSuppressed","emailedAtMs","pushedAtMs","tapToPayLaunchLink","store","origin","HOST_DASHBOARD","claim","channel","runTransaction","transaction","snapshot","claimed","next","merge","settle","sentAtMs","tapToPayLaunchPushMessage","recipient","title","body","type","link","urgent","posIosTargets","targets","token","lastSeen","has","environment","target","app","topic","sound","apnsEnvironment","sample","recipients","slice","address","manager","runTapToPayLaunch","options","released","env","send","channels","batch","Math","max","min","imageUrl","plan","report","dryRun","audience","due","skipped","emailSkipped","sent","deferred","failed","pushSkipped","pruned","unconfigured","remaining","image","ctaUrl","preferencesUrl","refused","consoleOrigin","MANAGE_USER_EMAILS","sendEmail","person","outcome","to","values","catch","error","console","pushTransport","transport","outcomes","entry","index","entries","delete","delivered","includes","tapToPayLaunchFallback","subject"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,UAAU,EAAEC,KAAK,QAAQ,wCAAuC;AACzE,SAASC,mBAAmB,EAAEC,qBAAqB,QAAQ,uCAAsC;AACjG,SAASC,0BAA0B,EAAEC,oBAAoB,QAAQ,kCAAiC;AAClG,SACEC,iBAAiB,EACjBC,kBAAkB,EAClBC,sBAAsB,EACtBC,yBAAyB,EACzBC,uBAAuB,EACvBC,cAAc,QACT,2CAA0C;AACjD,SAASC,iBAAiB,QAAQ,6CAA4C;AAC9E,SAASC,4BAA4B,QAAQ,oDAAmD;AAChG,SAASC,mBAAmB,QAAQ,sBAAqB;AACzD,SACEC,qBAAqB,EACrBC,2BAA2B,EAC3BC,+BAA+B,EAC/BC,yBAAyB,EACzBC,uBAAuB,EACvBC,yBAAyB,QAEpB,2BAA0B;AACjC,SAASC,wBAAwB,QAAQ,mDAAkD;AAE3F,SAASC,SAAS,QAAQ,gCAA4B;AACtD,SAASC,iBAAiB,QAAQ,gCAA4B;AAC9D,SACEC,WAAW,EACXC,kBAAkB,EAClBC,uBAAuB,EACvBC,2BAA2B,EAC3BC,wBAAwB,EACxBC,sBAAsB,EACtBC,gBAAgB,QAKX,gCAA4B;AAEnC;;;;;;;;;;;;;;;;;;;;;;2CAsB2C,GAE3C,6BAA6B,GAC7B,MAAMC,WAAW;AACjB,yEAAyE,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AM3G;4BAC/CmF,OAAOzF,IAAI,CAACmG,MAAM,IAAI;wBACxB;oBACF;oBACA,MAAMwB,YAAYL,SAASM,QAAQ,CAAC;oBACpC,MAAMxE,OAAOlG,KAAKC,EAAE,EAAEoG,UAAUnC,GAAG,EAAE,QAAQuG,YAAY/G,QAAQ;oBACjE,IAAI+G,WAAWlC,OAAOzF,IAAI,CAAC+F,IAAI,IAAI;yBAC9BN,OAAOzF,IAAI,CAACiG,MAAM,IAAI;gBAC7B,EAAE,OAAOiB,OAAO;oBACdC,QAAQD,KAAK,CAAC,gDAAgDA;oBAC9DzB,OAAOzF,IAAI,CAACiG,MAAM,IAAI;gBACxB;YACF;QACF;IACF;IACA,OAAOR;AACT;AAEA,+FAA+F,GAC/F,OAAO,SAASoC,uBAAuBb,MAAiC;IACtE,OAAO;QAAEc,SAASjN;QAA2ByB,MAAMxB,wBAAwBkM;IAAQ;AACrF;AAEA,SAASrM,2BAA2B,GAAE"}
|
package/src/lib/server.js
CHANGED
|
@@ -71,6 +71,7 @@ import { streamHandler } from "./server/stream.js";
|
|
|
71
71
|
import { subscriptionPortalHandler } from "./server/subscription-portal.js";
|
|
72
72
|
import { reviewsHandler } from "./server/reviews.js";
|
|
73
73
|
import { connectHandler } from "./server/connect.js";
|
|
74
|
+
import { connectReturnHandler } from "./server/connect-return.js";
|
|
74
75
|
import { cancelOrderHandler } from "./server/cancel-order.js";
|
|
75
76
|
import { carrierRatesAvailabilityHandler } from "./server/carrier-rates-availability.js";
|
|
76
77
|
import { collectionMembershipHandler } from "./server/collection-membership.js";
|
|
@@ -511,6 +512,11 @@ export function registerCommerceConsoleApi() {
|
|
|
511
512
|
registerPluginApiRoute('commerce/product', storefrontReadOnly(productHandler));
|
|
512
513
|
registerPluginApiRoute('commerce/catalog', storefrontReadOnly(catalogHandler));
|
|
513
514
|
registerPluginApiRoute('commerce/related', storefrontReadOnly(relatedHandler));
|
|
515
|
+
// Which currencies a store sells in and the day's rates (AGL-4256). The
|
|
516
|
+
// console's Currencies card and product editor preview prices with it, and
|
|
517
|
+
// Preview's Currency selector reads it; registered for the tenant alone,
|
|
518
|
+
// the card said "no daily rate yet" for every currency.
|
|
519
|
+
registerPluginApiRoute('commerce/currency', storefrontReadOnly(currencyHandler));
|
|
514
520
|
// What a product looks like to a surface that is not this plugin's — a
|
|
515
521
|
// campaign email that features one asks here rather than importing the model.
|
|
516
522
|
registerProductCardReader();
|
|
@@ -566,6 +572,9 @@ export function registerCommerceConsoleApi() {
|
|
|
566
572
|
// Whether live carrier rates can be offered on this site (AGL-3612).
|
|
567
573
|
registerPluginApiRoute('commerce/shipping/carrier-rates', carrierRatesAvailabilityHandler);
|
|
568
574
|
registerPluginApiRoute('commerce/connect', connectHandler);
|
|
575
|
+
// Where Stripe returns an app's onboarding: on to the app's own scheme,
|
|
576
|
+
// which closes its secure browser (AGL-4061).
|
|
577
|
+
registerPluginApiRoute('commerce/connect-return', connectReturnHandler);
|
|
569
578
|
registerPluginApiRoute('commerce/draft-order', draftOrderHandler);
|
|
570
579
|
// Quotes (AGL-4093): create, edit and delete a quote, and find the customer
|
|
571
580
|
// it is for, under "Create and edit quotes". Loaded on first call.
|
|
@@ -704,6 +713,12 @@ export function registerCommerceConsoleApi() {
|
|
|
704
713
|
registerPluginApiRoute('commerce/admin/hardware-orders', {
|
|
705
714
|
web: async (request)=>(await import("./server/pos-hardware-admin.js")).posHardwareAdminOrders(request)
|
|
706
715
|
});
|
|
716
|
+
// Apple's Tap to Pay on iPhone launch email and push (AGL-4061): staff
|
|
717
|
+
// only, a dry run unless asked to send, and a send refused until the
|
|
718
|
+
// deployment says Tap to Pay on iPhone is released.
|
|
719
|
+
registerPluginApiRoute('commerce/admin/tap-to-pay-launch', {
|
|
720
|
+
web: async (request)=>(await import("./server/tap-to-pay-launch-admin.js")).tapToPayLaunchAdmin(request)
|
|
721
|
+
});
|
|
707
722
|
// The self-service kiosk (AGL-3623): a register's paired screen where the
|
|
708
723
|
// customer orders and pays. Its device token, never a staff session; the
|
|
709
724
|
// register's queue of "pay at counter" orders is gated like a sale.
|