@aglyn/tenant-data-admin 1.0.0-beta.200 → 1.0.0-beta.202
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 +8 -7
- package/src/lib/server/card-payment-velocity.d.ts +85 -0
- package/src/lib/server/card-payment-velocity.js +202 -0
- package/src/lib/server/card-payment-velocity.js.map +1 -0
- package/src/lib/server/configured-url-fetch.d.ts +42 -0
- package/src/lib/server/configured-url-fetch.js +118 -0
- package/src/lib/server/configured-url-fetch.js.map +1 -0
- package/src/lib/server/dns-probe.d.ts +7 -0
- package/src/lib/server/dns-probe.js +52 -0
- package/src/lib/server/dns-probe.js.map +1 -1
- package/src/lib/server/email-deliverability.d.ts +150 -0
- package/src/lib/server/email-deliverability.js +538 -0
- package/src/lib/server/email-deliverability.js.map +1 -0
- package/src/lib/server/email-sender-reputation.d.ts +2 -11
- package/src/lib/server/email-sender-reputation.js +8 -25
- package/src/lib/server/email-sender-reputation.js.map +1 -1
- package/src/lib/server/email-suppression.d.ts +10 -1
- package/src/lib/server/email-suppression.js +4 -3
- package/src/lib/server/email-suppression.js.map +1 -1
- package/src/lib/server/erase-person.js +31 -3
- package/src/lib/server/erase-person.js.map +1 -1
- package/src/lib/server/host-visitor-records.d.ts +16 -2
- package/src/lib/server/host-visitor-records.js +31 -6
- package/src/lib/server/host-visitor-records.js.map +1 -1
- package/src/lib/server/hosted-page-review.d.ts +112 -0
- package/src/lib/server/hosted-page-review.js +378 -0
- package/src/lib/server/hosted-page-review.js.map +1 -0
- package/src/lib/server/member-email-aliases.js +18 -7
- package/src/lib/server/member-email-aliases.js.map +1 -1
- package/src/lib/server/notifications.d.ts +8 -0
- package/src/lib/server/notifications.js +92 -17
- package/src/lib/server/notifications.js.map +1 -1
- package/src/lib/server/org-age.d.ts +27 -0
- package/src/lib/server/org-age.js +44 -0
- package/src/lib/server/org-age.js.map +1 -0
- package/src/lib/server/org-member-notice.js +20 -5
- package/src/lib/server/org-member-notice.js.map +1 -1
- package/src/lib/server/organizations.d.ts +10 -1
- package/src/lib/server/organizations.js +12 -4
- package/src/lib/server/organizations.js.map +1 -1
- package/src/lib/server/outbound-send-review.d.ts +224 -0
- package/src/lib/server/outbound-send-review.js +479 -0
- package/src/lib/server/outbound-send-review.js.map +1 -0
- package/src/lib/server/payment-fraud-signal.d.ts +156 -0
- package/src/lib/server/payment-fraud-signal.js +368 -0
- package/src/lib/server/payment-fraud-signal.js.map +1 -0
- package/src/lib/server/payment-risk-record.d.ts +59 -0
- package/src/lib/server/payment-risk-record.js +76 -0
- package/src/lib/server/payment-risk-record.js.map +1 -0
- package/src/lib/server/render-system-email.d.ts +176 -0
- package/src/lib/server/render-system-email.js +315 -0
- package/src/lib/server/render-system-email.js.map +1 -0
- package/src/lib/server/sending-domains.d.ts +6 -0
- package/src/lib/server/sending-domains.js +98 -6
- package/src/lib/server/sending-domains.js.map +1 -1
- package/src/lib/server/staff-alert-email.d.ts +2 -1
- package/src/lib/server/staff-alert-email.js +16 -5
- package/src/lib/server/staff-alert-email.js.map +1 -1
- package/src/lib/server/stripe-card-authentication.d.ts +35 -0
- package/src/lib/server/stripe-card-authentication.js +63 -0
- package/src/lib/server/stripe-card-authentication.js.map +1 -0
- package/src/lib/server/tenant-write-lockdown.d.ts +32 -2
- package/src/lib/server/tenant-write-lockdown.js +33 -3
- package/src/lib/server/tenant-write-lockdown.js.map +1 -1
- package/src/tenancy.d.ts +5 -0
- package/src/tenancy.js +10 -0
- package/src/tenancy.js.map +1 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/** Which Stripe signal this is. */
|
|
18
|
+
export type PaymentFraudSignalKind = 'early-fraud-warning' | 'radar-review' | 'dispute';
|
|
19
|
+
/** The Stripe object type each signal arrives as, for the queue's text. */
|
|
20
|
+
export declare const PAYMENT_FRAUD_SIGNAL_LABELS: Record<PaymentFraudSignalKind, string>;
|
|
21
|
+
/** What the card's own checks said, when the charge could be read. */
|
|
22
|
+
export interface PaymentFraudCardChecks {
|
|
23
|
+
cvcCheck: string | null;
|
|
24
|
+
addressPostalCodeCheck: string | null;
|
|
25
|
+
cardCountry: string | null;
|
|
26
|
+
riskLevel: string | null;
|
|
27
|
+
threeDSecure: string | null;
|
|
28
|
+
}
|
|
29
|
+
export interface PaymentFraudSignal {
|
|
30
|
+
kind: PaymentFraudSignalKind;
|
|
31
|
+
/** The EFW, review or dispute id: one row per signal, whatever redelivers. */
|
|
32
|
+
stripeObjectId: string;
|
|
33
|
+
chargeId: string | null;
|
|
34
|
+
paymentIntentId: string | null;
|
|
35
|
+
/** The workspace the charge billed, or null when it resolved to none. */
|
|
36
|
+
orgId: string | null;
|
|
37
|
+
/** Smallest currency unit, or null when nothing recorded the amount. */
|
|
38
|
+
amountCents: number | null;
|
|
39
|
+
currency: string;
|
|
40
|
+
/** `fraud_type`, the review's `reason`, the dispute's `reason`. */
|
|
41
|
+
detail: string;
|
|
42
|
+
checks: PaymentFraudCardChecks | null;
|
|
43
|
+
livemode: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** The row id: hex, so the admin route's id pattern addresses it. */
|
|
46
|
+
export declare function paymentFraudSignalReviewId(kind: PaymentFraudSignalKind, stripeObjectId: string): string;
|
|
47
|
+
/** The staff-facing reference, beside the intake's `AR-` and the screen's `HS-`. */
|
|
48
|
+
export declare function paymentFraudSignalReference(reviewId: string): string;
|
|
49
|
+
/** Where staff act on the workspace's billing: its Subscription card. */
|
|
50
|
+
export declare function staffSubscriptionCardPath(orgId: string): string;
|
|
51
|
+
/** `$56.00 USD`, or a sentence saying the amount is not known. */
|
|
52
|
+
export declare function formatSignalAmount(amountCents: number | null, currency: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* The one-line summary of a charge Stripe gives back, for a signal whose
|
|
55
|
+
* charge is not on a platform revenue row. A READ — the only Stripe call
|
|
56
|
+
* this module makes — and it answers null rather than throwing, because a
|
|
57
|
+
* fraud alert that fails for want of an amount is worse than one that says
|
|
58
|
+
* the amount is unknown.
|
|
59
|
+
*/
|
|
60
|
+
export declare function readStripeChargeForSignal(chargeId: string, options: {
|
|
61
|
+
secretKey: string | undefined;
|
|
62
|
+
fetchImpl?: typeof fetch;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
amountCents: number | null;
|
|
65
|
+
currency: string;
|
|
66
|
+
customerId: string | null;
|
|
67
|
+
checks: PaymentFraudCardChecks;
|
|
68
|
+
/**
|
|
69
|
+
* The connected account the charge paid (AGL-3360): a destination
|
|
70
|
+
* charge's `transfer_data.destination`. Every sale Aglyn takes for a site
|
|
71
|
+
* is a destination charge on the platform account — the facilitator
|
|
72
|
+
* model (AGL-1956) — so this is the seller. Null for a charge that paid
|
|
73
|
+
* only the platform, a workspace's own subscription.
|
|
74
|
+
*/
|
|
75
|
+
sellerAccountId: string | null;
|
|
76
|
+
} | null>;
|
|
77
|
+
/** The row's prose: what arrived, about which workspace, and what to do. */
|
|
78
|
+
export declare function describePaymentFraudSignal(signal: PaymentFraudSignal): string;
|
|
79
|
+
/**
|
|
80
|
+
* File one signal and tell staff, once per signal.
|
|
81
|
+
*
|
|
82
|
+
* Idempotent on the Stripe object id: a redelivery bumps `reportCount` and
|
|
83
|
+
* leaves the row's status — which staff own from the moment they touch it —
|
|
84
|
+
* where it was. Throws only if the row write throws, which is the webhook's
|
|
85
|
+
* to answer; the notification never throws.
|
|
86
|
+
*/
|
|
87
|
+
export declare function recordPaymentFraudSignal(signal: PaymentFraudSignal, deps: {
|
|
88
|
+
firestore: FirebaseFirestore.Firestore;
|
|
89
|
+
notify: (payload: {
|
|
90
|
+
type: 'system.abuseReportUrgent';
|
|
91
|
+
title: string;
|
|
92
|
+
body: string;
|
|
93
|
+
link: string;
|
|
94
|
+
}) => Promise<void>;
|
|
95
|
+
}): Promise<{
|
|
96
|
+
reviewId: string;
|
|
97
|
+
reference: string;
|
|
98
|
+
first: boolean;
|
|
99
|
+
}>;
|
|
100
|
+
export declare const SELLER_FRAUD_PATTERN: {
|
|
101
|
+
/** Distinct charges with an early fraud warning or a dispute. */
|
|
102
|
+
readonly minDistinctCharges: 3;
|
|
103
|
+
/** …within this window. */
|
|
104
|
+
readonly windowMs: number;
|
|
105
|
+
/** How long the ledger keeps an entry at all. */
|
|
106
|
+
readonly retainMs: number;
|
|
107
|
+
};
|
|
108
|
+
/** Admin-SDK only; no client rule opens it (default deny). */
|
|
109
|
+
export declare const SELLER_FRAUD_LEDGER_COLLECTION = "paymentFraudLedger";
|
|
110
|
+
export interface SellerFraudLedgerEntry {
|
|
111
|
+
kind: PaymentFraudSignalKind;
|
|
112
|
+
stripeObjectId: string;
|
|
113
|
+
chargeId: string | null;
|
|
114
|
+
amountCents: number | null;
|
|
115
|
+
currency: string;
|
|
116
|
+
detail: string;
|
|
117
|
+
/** The sites a plugin recognised the charge as belonging to. */
|
|
118
|
+
hostIds: string[];
|
|
119
|
+
atMs: number;
|
|
120
|
+
}
|
|
121
|
+
/** Whether a seller's ledger shows the pattern at `nowMs`. Pure. */
|
|
122
|
+
export declare function sellerFraudPattern(entries: readonly SellerFraudLedgerEntry[], nowMs: number): {
|
|
123
|
+
matched: boolean;
|
|
124
|
+
chargeIds: string[];
|
|
125
|
+
};
|
|
126
|
+
/** The connected account's page in the Stripe Dashboard. */
|
|
127
|
+
export declare function stripeConnectedAccountUrl(accountId: string, livemode: boolean): string;
|
|
128
|
+
/**
|
|
129
|
+
* Keep one signal on a seller's charge, and file the pattern row when the
|
|
130
|
+
* ledger crosses the threshold. Idempotent on the Stripe object id: a
|
|
131
|
+
* redelivery changes nothing and files nothing.
|
|
132
|
+
*/
|
|
133
|
+
export declare function recordSellerFraudSignal(input: {
|
|
134
|
+
signal: PaymentFraudSignal;
|
|
135
|
+
sellerAccountId: string;
|
|
136
|
+
/** The sites a plugin recognised the charge as belonging to. */
|
|
137
|
+
hostIds: string[];
|
|
138
|
+
/** Workspaces owning those sites, for the row. */
|
|
139
|
+
orgIds: string[];
|
|
140
|
+
}, deps: {
|
|
141
|
+
firestore: FirebaseFirestore.Firestore;
|
|
142
|
+
notify: (payload: {
|
|
143
|
+
type: 'system.abuseReportUrgent';
|
|
144
|
+
title: string;
|
|
145
|
+
body: string;
|
|
146
|
+
link: string;
|
|
147
|
+
}) => Promise<void>;
|
|
148
|
+
nowMs?: number;
|
|
149
|
+
}): Promise<{
|
|
150
|
+
first: boolean;
|
|
151
|
+
matched: boolean;
|
|
152
|
+
filed: {
|
|
153
|
+
reviewId: string;
|
|
154
|
+
reference: string;
|
|
155
|
+
} | null;
|
|
156
|
+
}>;
|
|
@@ -0,0 +1,368 @@
|
|
|
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
|
+
*/ /*==========================================
|
|
18
|
+
* STRIPE'S FRAUD SIGNALS, INTO THE ABUSE QUEUE (AGL-3356).
|
|
19
|
+
*
|
|
20
|
+
* The 9/26 incident paid for Pro with a card whose CVC check came back
|
|
21
|
+
* unavailable and which never met 3-D Secure. Stripe had three ways to tell
|
|
22
|
+
* us about a card like that — an early fraud warning from the issuer, a
|
|
23
|
+
* Radar review, a dispute — and the platform webhook either did not
|
|
24
|
+
* subscribe to them or filed them where nobody triages abuse.
|
|
25
|
+
*
|
|
26
|
+
* Each signal now files an urgent row in the abuse queue that names the
|
|
27
|
+
* workspace, the charge and the amount, links the staff Subscription card
|
|
28
|
+
* on the org page (AGL-3359, where billing is canceled), and notifies staff
|
|
29
|
+
* once. NOTHING IS DONE TO THE MONEY OR THE SUBSCRIPTION: no refund, no
|
|
30
|
+
* cancel. An early fraud warning is not a chargeback, a review may clear, and
|
|
31
|
+
* a refund issued before staff look can be the wrong half of a dispute. The
|
|
32
|
+
* row is the prompt; staff decide.
|
|
33
|
+
*
|
|
34
|
+
* Dependencies are passed in rather than imported — the Firestore handle the
|
|
35
|
+
* webhook observes its writes through, and its staff notifier — so the
|
|
36
|
+
* webhook's "did this delivery do anything" ledger sees the write, and a spec
|
|
37
|
+
* substituting the admin barrel substitutes these too.
|
|
38
|
+
*=========================================*/ import { createHash } from "crypto";
|
|
39
|
+
import { ABUSE_REPORT_COLLECTION } from "@aglyn/aglyn/app-utils/abuse-report";
|
|
40
|
+
import { FieldValue } from "firebase-admin/firestore";
|
|
41
|
+
const KIND_LABEL = {
|
|
42
|
+
'early-fraud-warning': 'Early fraud warning',
|
|
43
|
+
'radar-review': 'Radar review opened',
|
|
44
|
+
dispute: 'Card dispute opened'
|
|
45
|
+
};
|
|
46
|
+
/** The Stripe object type each signal arrives as, for the queue's text. */ export const PAYMENT_FRAUD_SIGNAL_LABELS = KIND_LABEL;
|
|
47
|
+
/** The row id: hex, so the admin route's id pattern addresses it. */ export function paymentFraudSignalReviewId(kind, stripeObjectId) {
|
|
48
|
+
return createHash('sha256').update(`stripe-fraud:${kind}:${stripeObjectId}`).digest('hex').slice(0, 40);
|
|
49
|
+
}
|
|
50
|
+
/** The staff-facing reference, beside the intake's `AR-` and the screen's `HS-`. */ export function paymentFraudSignalReference(reviewId) {
|
|
51
|
+
return `PF-${reviewId.slice(0, 10).toUpperCase()}`;
|
|
52
|
+
}
|
|
53
|
+
/** Where staff act on the workspace's billing: its Subscription card. */ export function staffSubscriptionCardPath(orgId) {
|
|
54
|
+
return `/admin/orgs/${encodeURIComponent(orgId)}#subscription`;
|
|
55
|
+
}
|
|
56
|
+
/** `$56.00 USD`, or a sentence saying the amount is not known. */ export function formatSignalAmount(amountCents, currency) {
|
|
57
|
+
if (amountCents === null || !Number.isFinite(amountCents)) {
|
|
58
|
+
return 'amount not recorded';
|
|
59
|
+
}
|
|
60
|
+
return `${(amountCents / 100).toFixed(2)} ${String(currency || 'usd').toUpperCase()}`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The one-line summary of a charge Stripe gives back, for a signal whose
|
|
64
|
+
* charge is not on a platform revenue row. A READ — the only Stripe call
|
|
65
|
+
* this module makes — and it answers null rather than throwing, because a
|
|
66
|
+
* fraud alert that fails for want of an amount is worse than one that says
|
|
67
|
+
* the amount is unknown.
|
|
68
|
+
*/ export async function readStripeChargeForSignal(chargeId, options) {
|
|
69
|
+
if (!chargeId || !options.secretKey) return null;
|
|
70
|
+
try {
|
|
71
|
+
var _options_fetchImpl, _ref, _ref1;
|
|
72
|
+
var _charge_payment_method_details, _card_checks, _card_checks1, _charge_outcome, _card_three_d_secure, _charge_transfer_data;
|
|
73
|
+
const response = await ((_options_fetchImpl = options.fetchImpl) != null ? _options_fetchImpl : fetch)(`https://api.stripe.com/v1/charges/${encodeURIComponent(chargeId)}`, {
|
|
74
|
+
headers: {
|
|
75
|
+
Authorization: `Bearer ${options.secretKey}`
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
if (!response.ok) return null;
|
|
79
|
+
const charge = await response.json();
|
|
80
|
+
const card = (_ref = charge == null ? void 0 : (_charge_payment_method_details = charge['payment_method_details']) == null ? void 0 : _charge_payment_method_details['card']) != null ? _ref : {};
|
|
81
|
+
const text = (value)=>typeof value === 'string' && value ? value : null;
|
|
82
|
+
return {
|
|
83
|
+
amountCents: Number.isFinite(Number(charge == null ? void 0 : charge['amount'])) ? Number(charge['amount']) : null,
|
|
84
|
+
currency: String((_ref1 = charge == null ? void 0 : charge['currency']) != null ? _ref1 : 'usd'),
|
|
85
|
+
customerId: text(charge == null ? void 0 : charge['customer']),
|
|
86
|
+
checks: {
|
|
87
|
+
cvcCheck: text(card == null ? void 0 : (_card_checks = card['checks']) == null ? void 0 : _card_checks['cvc_check']),
|
|
88
|
+
addressPostalCodeCheck: text(card == null ? void 0 : (_card_checks1 = card['checks']) == null ? void 0 : _card_checks1['address_postal_code_check']),
|
|
89
|
+
cardCountry: text(card == null ? void 0 : card['country']),
|
|
90
|
+
riskLevel: text(charge == null ? void 0 : (_charge_outcome = charge['outcome']) == null ? void 0 : _charge_outcome['risk_level']),
|
|
91
|
+
threeDSecure: text(card == null ? void 0 : (_card_three_d_secure = card['three_d_secure']) == null ? void 0 : _card_three_d_secure['result'])
|
|
92
|
+
},
|
|
93
|
+
sellerAccountId: accountRef(charge == null ? void 0 : (_charge_transfer_data = charge['transfer_data']) == null ? void 0 : _charge_transfer_data['destination'])
|
|
94
|
+
};
|
|
95
|
+
} catch (unused) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** A Stripe account reference, expanded or not, as an id or null. */ function accountRef(value) {
|
|
100
|
+
var _ref;
|
|
101
|
+
const id = typeof value === 'string' ? value : String((_ref = value == null ? void 0 : value.id) != null ? _ref : '');
|
|
102
|
+
return id.startsWith('acct_') ? id : null;
|
|
103
|
+
}
|
|
104
|
+
/** The row's prose: what arrived, about which workspace, and what to do. */ export function describePaymentFraudSignal(signal) {
|
|
105
|
+
var _signal_orgId, _ref, _signal_chargeId;
|
|
106
|
+
const lines = [
|
|
107
|
+
`${KIND_LABEL[signal.kind]} from Stripe (${signal.stripeObjectId})` + (signal.livemode ? '' : ' — TEST MODE') + '.',
|
|
108
|
+
`Workspace: ${(_signal_orgId = signal.orgId) != null ? _signal_orgId : 'none — the charge did not resolve to a workspace subscription'}.`,
|
|
109
|
+
`Charge: ${(_ref = (_signal_chargeId = signal.chargeId) != null ? _signal_chargeId : signal.paymentIntentId) != null ? _ref : 'not named'} · ${formatSignalAmount(signal.amountCents, signal.currency)}.`
|
|
110
|
+
];
|
|
111
|
+
if (signal.detail) lines.push(`Stripe says: ${signal.detail}.`);
|
|
112
|
+
const checks = signal.checks;
|
|
113
|
+
if (checks) {
|
|
114
|
+
var _checks_cvcCheck, _checks_addressPostalCodeCheck, _checks_cardCountry, _checks_threeDSecure, _checks_riskLevel;
|
|
115
|
+
lines.push(`Card: CVC ${(_checks_cvcCheck = checks.cvcCheck) != null ? _checks_cvcCheck : 'unknown'}, postal code ${(_checks_addressPostalCodeCheck = checks.addressPostalCodeCheck) != null ? _checks_addressPostalCodeCheck : 'unknown'}, ` + `issued in ${(_checks_cardCountry = checks.cardCountry) != null ? _checks_cardCountry : 'unknown'}, 3DS ${(_checks_threeDSecure = checks.threeDSecure) != null ? _checks_threeDSecure : 'not used'}, ` + `Radar risk ${(_checks_riskLevel = checks.riskLevel) != null ? _checks_riskLevel : 'unknown'}.`);
|
|
116
|
+
}
|
|
117
|
+
lines.push(signal.kind === 'radar-review' ? 'The payment waits in Stripe until the review is closed there.' : signal.kind === 'dispute' ? 'Answer the dispute in Stripe before its evidence deadline.' : 'An early fraud warning is not yet a chargeback; refunding now can avoid one.', 'Nothing has been refunded or canceled. Decide on the org’s Subscription card, lock the workspace if it is fraud, and close this row with what you did.');
|
|
118
|
+
return lines.join('\n').slice(0, 5000);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* File one signal and tell staff, once per signal.
|
|
122
|
+
*
|
|
123
|
+
* Idempotent on the Stripe object id: a redelivery bumps `reportCount` and
|
|
124
|
+
* leaves the row's status — which staff own from the moment they touch it —
|
|
125
|
+
* where it was. Throws only if the row write throws, which is the webhook's
|
|
126
|
+
* to answer; the notification never throws.
|
|
127
|
+
*/ export async function recordPaymentFraudSignal(signal, deps) {
|
|
128
|
+
const reviewId = paymentFraudSignalReviewId(signal.kind, signal.stripeObjectId);
|
|
129
|
+
const reference = paymentFraudSignalReference(reviewId);
|
|
130
|
+
const ref = deps.firestore.collection(ABUSE_REPORT_COLLECTION).doc(reviewId);
|
|
131
|
+
const first = !(await ref.get()).exists;
|
|
132
|
+
const subscriptionCard = signal.orgId ? staffSubscriptionCardPath(signal.orgId) : null;
|
|
133
|
+
await ref.set(_extends({
|
|
134
|
+
reference,
|
|
135
|
+
// "Phishing or fraud" — the queue's urgent fraud category.
|
|
136
|
+
category: 'phishing',
|
|
137
|
+
severity: 'urgent',
|
|
138
|
+
source: 'stripe-fraud-signal',
|
|
139
|
+
url: null,
|
|
140
|
+
reportedHostname: null,
|
|
141
|
+
hostId: null,
|
|
142
|
+
orgId: signal.orgId,
|
|
143
|
+
details: describePaymentFraudSignal(signal),
|
|
144
|
+
reporterEmail: null,
|
|
145
|
+
reporterName: null,
|
|
146
|
+
dmca: null,
|
|
147
|
+
reportCount: FieldValue.increment(1),
|
|
148
|
+
paymentSignal: {
|
|
149
|
+
kind: signal.kind,
|
|
150
|
+
stripeObjectId: signal.stripeObjectId,
|
|
151
|
+
chargeId: signal.chargeId,
|
|
152
|
+
paymentIntentId: signal.paymentIntentId,
|
|
153
|
+
amountCents: signal.amountCents,
|
|
154
|
+
currency: signal.currency,
|
|
155
|
+
detail: signal.detail,
|
|
156
|
+
checks: signal.checks,
|
|
157
|
+
livemode: signal.livemode,
|
|
158
|
+
subscriptionCard
|
|
159
|
+
},
|
|
160
|
+
updatedAt: FieldValue.serverTimestamp()
|
|
161
|
+
}, first ? {
|
|
162
|
+
status: 'open',
|
|
163
|
+
createdAt: FieldValue.serverTimestamp()
|
|
164
|
+
} : {}), {
|
|
165
|
+
merge: true
|
|
166
|
+
});
|
|
167
|
+
if (first) {
|
|
168
|
+
var _ref, _signal_chargeId;
|
|
169
|
+
await deps.notify({
|
|
170
|
+
type: 'system.abuseReportUrgent',
|
|
171
|
+
title: `${KIND_LABEL[signal.kind]} — ${formatSignalAmount(signal.amountCents, signal.currency)}`,
|
|
172
|
+
body: `${signal.orgId ? `Workspace ${signal.orgId}` : 'A charge that is not a workspace subscription'}, ` + `charge ${(_ref = (_signal_chargeId = signal.chargeId) != null ? _signal_chargeId : signal.paymentIntentId) != null ? _ref : 'not named'}. ` + `Nothing has been refunded or canceled. Reference ${reference}.`,
|
|
173
|
+
link: '/admin/abuse-reports'
|
|
174
|
+
}).catch(()=>undefined);
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
reviewId,
|
|
178
|
+
reference,
|
|
179
|
+
first
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/*==========================================
|
|
183
|
+
* THE SELLER PATTERN: WHEN THE MERCHANT MAY BE THE FRAUDSTER (AGL-3360).
|
|
184
|
+
*
|
|
185
|
+
* A site's own sales are destination charges on the platform account, so
|
|
186
|
+
* Stripe's fraud signals about a shopper's card arrive here too. One of them
|
|
187
|
+
* is the merchant's business — their customer, their order, their decision
|
|
188
|
+
* (`payment-risk-record.ts` puts it on the record and tells them). Staff are
|
|
189
|
+
* not paged for it.
|
|
190
|
+
*
|
|
191
|
+
* What IS staff's business is the shape a phishing actor leaves when they
|
|
192
|
+
* run stolen cards through a storefront of their own: several different
|
|
193
|
+
* charges on ONE connected account drawing issuer fraud reports or
|
|
194
|
+
* chargebacks in a short time. So every signal on a seller's charge is kept
|
|
195
|
+
* in a small per-account ledger, and one urgent abuse-queue row is filed when
|
|
196
|
+
*
|
|
197
|
+
* ≥ 3 DISTINCT charges carry an early fraud warning or a dispute
|
|
198
|
+
* within 7 days.
|
|
199
|
+
*
|
|
200
|
+
* Why those numbers. An early fraud warning is an issuer's report that the
|
|
201
|
+
* cardholder did not make the payment, and a dispute is a formal
|
|
202
|
+
* chargeback; a legitimate small merchant sees either rarely — card-network
|
|
203
|
+
* dispute monitoring starts near 0.9% of a month's transactions, single
|
|
204
|
+
* digits a MONTH for a shop doing hundreds of sales. One or two in a week is
|
|
205
|
+
* ordinary friendly fraud and must never page staff. Three separate charges
|
|
206
|
+
* in one week is a rate a real small shop does not produce, and is what a
|
|
207
|
+
* card tester or a stolen-card storefront produces within days. Counted by
|
|
208
|
+
* CHARGE, because a warning is routinely followed by a dispute on the same
|
|
209
|
+
* payment, and that is one bad payment, not two. Radar reviews are kept in
|
|
210
|
+
* the ledger for the row's prose but never counted: a review is Stripe's
|
|
211
|
+
* suspicion, not an issuer's report, and a busy shop can collect several
|
|
212
|
+
* that clear.
|
|
213
|
+
*
|
|
214
|
+
* One row per window: once filed, the account is not filed again until 7
|
|
215
|
+
* days have passed, so a burst is one row with everything in it rather than
|
|
216
|
+
* a row per signal. NOTHING IS DONE TO THE ACCOUNT OR THE MONEY: staff
|
|
217
|
+
* decide (lock the workspace, pause the account's payouts in Stripe).
|
|
218
|
+
*=========================================*/ export const SELLER_FRAUD_PATTERN = {
|
|
219
|
+
/** Distinct charges with an early fraud warning or a dispute. */ minDistinctCharges: 3,
|
|
220
|
+
/** …within this window. */ windowMs: 7 * 24 * 60 * 60 * 1000,
|
|
221
|
+
/** How long the ledger keeps an entry at all. */ retainMs: 30 * 24 * 60 * 60 * 1000
|
|
222
|
+
};
|
|
223
|
+
const WINDOW_DAYS = SELLER_FRAUD_PATTERN.windowMs / 86400000;
|
|
224
|
+
/** Admin-SDK only; no client rule opens it (default deny). */ export const SELLER_FRAUD_LEDGER_COLLECTION = 'paymentFraudLedger';
|
|
225
|
+
/** Whether a seller's ledger shows the pattern at `nowMs`. Pure. */ export function sellerFraudPattern(entries, nowMs) {
|
|
226
|
+
const since = nowMs - SELLER_FRAUD_PATTERN.windowMs;
|
|
227
|
+
const chargeIds = [
|
|
228
|
+
...new Set(entries.filter((entry)=>(entry.kind === 'early-fraud-warning' || entry.kind === 'dispute') && entry.atMs >= since).map((entry)=>entry.chargeId || entry.stripeObjectId))
|
|
229
|
+
];
|
|
230
|
+
return {
|
|
231
|
+
matched: chargeIds.length >= SELLER_FRAUD_PATTERN.minDistinctCharges,
|
|
232
|
+
chargeIds
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/** The connected account's page in the Stripe Dashboard. */ export function stripeConnectedAccountUrl(accountId, livemode) {
|
|
236
|
+
return `https://dashboard.stripe.com/${livemode ? '' : 'test/'}connect/accounts/${encodeURIComponent(accountId)}`;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Keep one signal on a seller's charge, and file the pattern row when the
|
|
240
|
+
* ledger crosses the threshold. Idempotent on the Stripe object id: a
|
|
241
|
+
* redelivery changes nothing and files nothing.
|
|
242
|
+
*/ export async function recordSellerFraudSignal(input, deps) {
|
|
243
|
+
var _deps_nowMs, _input_orgIds_, _hostIds_;
|
|
244
|
+
const nowMs = (_deps_nowMs = deps.nowMs) != null ? _deps_nowMs : Date.now();
|
|
245
|
+
const { signal, sellerAccountId } = input;
|
|
246
|
+
const ledgerRef = deps.firestore.collection(SELLER_FRAUD_LEDGER_COLLECTION).doc(sellerAccountId);
|
|
247
|
+
const outcome = await deps.firestore.runTransaction(async (transaction)=>{
|
|
248
|
+
var _fresh_get;
|
|
249
|
+
const fresh = await transaction.get(ledgerRef);
|
|
250
|
+
const stored = Array.isArray(fresh.get('entries')) ? fresh.get('entries') : [];
|
|
251
|
+
if (stored.some((entry)=>entry.stripeObjectId === signal.stripeObjectId)) {
|
|
252
|
+
return {
|
|
253
|
+
first: false,
|
|
254
|
+
matched: false,
|
|
255
|
+
fileAtMs: 0,
|
|
256
|
+
entries: stored
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
const entries = [
|
|
260
|
+
...stored.filter((entry)=>entry.atMs >= nowMs - SELLER_FRAUD_PATTERN.retainMs),
|
|
261
|
+
{
|
|
262
|
+
kind: signal.kind,
|
|
263
|
+
stripeObjectId: signal.stripeObjectId,
|
|
264
|
+
chargeId: signal.chargeId,
|
|
265
|
+
amountCents: signal.amountCents,
|
|
266
|
+
currency: signal.currency,
|
|
267
|
+
detail: signal.detail,
|
|
268
|
+
hostIds: input.hostIds,
|
|
269
|
+
atMs: nowMs
|
|
270
|
+
}
|
|
271
|
+
];
|
|
272
|
+
const { matched } = sellerFraudPattern(entries, nowMs);
|
|
273
|
+
const lastFiledAtMs = Number((_fresh_get = fresh.get('lastFiledAtMs')) != null ? _fresh_get : 0);
|
|
274
|
+
const fileAtMs = matched && !(lastFiledAtMs && nowMs - lastFiledAtMs < SELLER_FRAUD_PATTERN.windowMs) ? nowMs : 0;
|
|
275
|
+
transaction.set(ledgerRef, _extends({
|
|
276
|
+
sellerAccountId,
|
|
277
|
+
entries,
|
|
278
|
+
livemode: signal.livemode,
|
|
279
|
+
updatedAtMs: nowMs
|
|
280
|
+
}, fileAtMs ? {
|
|
281
|
+
lastFiledAtMs: fileAtMs
|
|
282
|
+
} : {}), {
|
|
283
|
+
merge: true
|
|
284
|
+
});
|
|
285
|
+
return {
|
|
286
|
+
first: true,
|
|
287
|
+
matched,
|
|
288
|
+
fileAtMs,
|
|
289
|
+
entries
|
|
290
|
+
};
|
|
291
|
+
});
|
|
292
|
+
if (!outcome.fileAtMs) {
|
|
293
|
+
return {
|
|
294
|
+
first: outcome.first,
|
|
295
|
+
matched: outcome.matched,
|
|
296
|
+
filed: null
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
const { chargeIds } = sellerFraudPattern(outcome.entries, nowMs);
|
|
300
|
+
const inWindow = outcome.entries.filter((entry)=>entry.atMs >= nowMs - SELLER_FRAUD_PATTERN.windowMs);
|
|
301
|
+
const reviewId = createHash('sha256').update(`stripe-seller-pattern:${sellerAccountId}:${outcome.fileAtMs}`).digest('hex').slice(0, 40);
|
|
302
|
+
const reference = paymentFraudSignalReference(reviewId);
|
|
303
|
+
const orgId = (_input_orgIds_ = input.orgIds[0]) != null ? _input_orgIds_ : null;
|
|
304
|
+
const hostIds = [
|
|
305
|
+
...new Set(inWindow.flatMap((entry)=>{
|
|
306
|
+
var _entry_hostIds;
|
|
307
|
+
return (_entry_hostIds = entry.hostIds) != null ? _entry_hostIds : [];
|
|
308
|
+
}))
|
|
309
|
+
];
|
|
310
|
+
const stripeUrl = stripeConnectedAccountUrl(sellerAccountId, signal.livemode);
|
|
311
|
+
const details = [
|
|
312
|
+
`${chargeIds.length} different charges paid to connected account ${sellerAccountId} drew an issuer fraud warning or a dispute within ${WINDOW_DAYS} days` + (signal.livemode ? '' : ' — TEST MODE') + '.',
|
|
313
|
+
`Workspace(s): ${input.orgIds.length ? input.orgIds.join(', ') : 'not resolved'}. Site(s): ${hostIds.length ? hostIds.join(', ') : 'not resolved'}.`,
|
|
314
|
+
...inWindow.map((entry)=>{
|
|
315
|
+
var _entry_chargeId;
|
|
316
|
+
return `• ${KIND_LABEL[entry.kind]} ${entry.stripeObjectId} on ${(_entry_chargeId = entry.chargeId) != null ? _entry_chargeId : 'an unnamed charge'} · ${formatSignalAmount(entry.amountCents, entry.currency)}` + (entry.detail ? ` · ${entry.detail}` : '');
|
|
317
|
+
}),
|
|
318
|
+
'A shop taking stolen cards through its own storefront leaves this shape. Each merchant has already been shown the signal on its own order or booking.',
|
|
319
|
+
`Nothing has been refunded, canceled or paused. If this is the seller's fraud, lock the workspace and pause the account's payouts in Stripe (${stripeUrl}), then close this row with what you did.`
|
|
320
|
+
].join('\n').slice(0, 5000);
|
|
321
|
+
await deps.firestore.collection(ABUSE_REPORT_COLLECTION).doc(reviewId).set({
|
|
322
|
+
reference,
|
|
323
|
+
// "Phishing or fraud" — the queue's urgent fraud category.
|
|
324
|
+
category: 'phishing',
|
|
325
|
+
severity: 'urgent',
|
|
326
|
+
source: 'stripe-seller-fraud-pattern',
|
|
327
|
+
url: null,
|
|
328
|
+
reportedHostname: null,
|
|
329
|
+
hostId: (_hostIds_ = hostIds[0]) != null ? _hostIds_ : null,
|
|
330
|
+
orgId,
|
|
331
|
+
details,
|
|
332
|
+
reporterEmail: null,
|
|
333
|
+
reporterName: null,
|
|
334
|
+
dmca: null,
|
|
335
|
+
reportCount: 1,
|
|
336
|
+
sellerPattern: {
|
|
337
|
+
sellerAccountId,
|
|
338
|
+
stripeAccountUrl: stripeUrl,
|
|
339
|
+
chargeIds,
|
|
340
|
+
orgIds: input.orgIds,
|
|
341
|
+
hostIds,
|
|
342
|
+
threshold: SELLER_FRAUD_PATTERN.minDistinctCharges,
|
|
343
|
+
windowDays: WINDOW_DAYS,
|
|
344
|
+
livemode: signal.livemode
|
|
345
|
+
},
|
|
346
|
+
status: 'open',
|
|
347
|
+
createdAt: FieldValue.serverTimestamp(),
|
|
348
|
+
updatedAt: FieldValue.serverTimestamp()
|
|
349
|
+
}, {
|
|
350
|
+
merge: true
|
|
351
|
+
});
|
|
352
|
+
await deps.notify({
|
|
353
|
+
type: 'system.abuseReportUrgent',
|
|
354
|
+
title: `Seller fraud pattern — ${chargeIds.length} charges on one account`,
|
|
355
|
+
body: `Connected account ${sellerAccountId}` + (orgId ? ` (workspace ${orgId})` : '') + ` drew fraud warnings or disputes on ${chargeIds.length} different charges in ${WINDOW_DAYS} days. ` + `Nothing has been refunded, canceled or paused. Reference ${reference}.`,
|
|
356
|
+
link: '/admin/abuse-reports'
|
|
357
|
+
}).catch(()=>undefined);
|
|
358
|
+
return {
|
|
359
|
+
first: true,
|
|
360
|
+
matched: true,
|
|
361
|
+
filed: {
|
|
362
|
+
reviewId,
|
|
363
|
+
reference
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
//# sourceMappingURL=payment-fraud-signal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/payment-fraud-signal.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 * STRIPE'S FRAUD SIGNALS, INTO THE ABUSE QUEUE (AGL-3356).\n *\n * The 9/26 incident paid for Pro with a card whose CVC check came back\n * unavailable and which never met 3-D Secure. Stripe had three ways to tell\n * us about a card like that — an early fraud warning from the issuer, a\n * Radar review, a dispute — and the platform webhook either did not\n * subscribe to them or filed them where nobody triages abuse.\n *\n * Each signal now files an urgent row in the abuse queue that names the\n * workspace, the charge and the amount, links the staff Subscription card\n * on the org page (AGL-3359, where billing is canceled), and notifies staff\n * once. NOTHING IS DONE TO THE MONEY OR THE SUBSCRIPTION: no refund, no\n * cancel. An early fraud warning is not a chargeback, a review may clear, and\n * a refund issued before staff look can be the wrong half of a dispute. The\n * row is the prompt; staff decide.\n *\n * Dependencies are passed in rather than imported — the Firestore handle the\n * webhook observes its writes through, and its staff notifier — so the\n * webhook's \"did this delivery do anything\" ledger sees the write, and a spec\n * substituting the admin barrel substitutes these too.\n *=========================================*/\n\nimport { createHash } from 'crypto'\nimport { ABUSE_REPORT_COLLECTION } from '@aglyn/aglyn/app-utils/abuse-report'\nimport { FieldValue } from 'firebase-admin/firestore'\n\n/** Which Stripe signal this is. */\nexport type PaymentFraudSignalKind =\n | 'early-fraud-warning'\n | 'radar-review'\n | 'dispute'\n\nconst KIND_LABEL: Record<PaymentFraudSignalKind, string> = {\n 'early-fraud-warning': 'Early fraud warning',\n 'radar-review': 'Radar review opened',\n dispute: 'Card dispute opened',\n}\n\n/** The Stripe object type each signal arrives as, for the queue's text. */\nexport const PAYMENT_FRAUD_SIGNAL_LABELS = KIND_LABEL\n\n/** What the card's own checks said, when the charge could be read. */\nexport interface PaymentFraudCardChecks {\n cvcCheck: string | null\n addressPostalCodeCheck: string | null\n cardCountry: string | null\n riskLevel: string | null\n threeDSecure: string | null\n}\n\nexport interface PaymentFraudSignal {\n kind: PaymentFraudSignalKind\n /** The EFW, review or dispute id: one row per signal, whatever redelivers. */\n stripeObjectId: string\n chargeId: string | null\n paymentIntentId: string | null\n /** The workspace the charge billed, or null when it resolved to none. */\n orgId: string | null\n /** Smallest currency unit, or null when nothing recorded the amount. */\n amountCents: number | null\n currency: string\n /** `fraud_type`, the review's `reason`, the dispute's `reason`. */\n detail: string\n checks: PaymentFraudCardChecks | null\n livemode: boolean\n}\n\n/** The row id: hex, so the admin route's id pattern addresses it. */\nexport function paymentFraudSignalReviewId(\n kind: PaymentFraudSignalKind,\n stripeObjectId: string,\n): string {\n return createHash('sha256')\n .update(`stripe-fraud:${kind}:${stripeObjectId}`)\n .digest('hex')\n .slice(0, 40)\n}\n\n/** The staff-facing reference, beside the intake's `AR-` and the screen's `HS-`. */\nexport function paymentFraudSignalReference(reviewId: string): string {\n return `PF-${reviewId.slice(0, 10).toUpperCase()}`\n}\n\n/** Where staff act on the workspace's billing: its Subscription card. */\nexport function staffSubscriptionCardPath(orgId: string): string {\n return `/admin/orgs/${encodeURIComponent(orgId)}#subscription`\n}\n\n/** `$56.00 USD`, or a sentence saying the amount is not known. */\nexport function formatSignalAmount(\n amountCents: number | null,\n currency: string,\n): string {\n if (amountCents === null || !Number.isFinite(amountCents)) {\n return 'amount not recorded'\n }\n return `${(amountCents / 100).toFixed(2)} ${String(currency || 'usd').toUpperCase()}`\n}\n\n/**\n * The one-line summary of a charge Stripe gives back, for a signal whose\n * charge is not on a platform revenue row. A READ — the only Stripe call\n * this module makes — and it answers null rather than throwing, because a\n * fraud alert that fails for want of an amount is worse than one that says\n * the amount is unknown.\n */\nexport async function readStripeChargeForSignal(\n chargeId: string,\n options: { secretKey: string | undefined; fetchImpl?: typeof fetch },\n): Promise<{\n amountCents: number | null\n currency: string\n customerId: string | null\n checks: PaymentFraudCardChecks\n /**\n * The connected account the charge paid (AGL-3360): a destination\n * charge's `transfer_data.destination`. Every sale Aglyn takes for a site\n * is a destination charge on the platform account — the facilitator\n * model (AGL-1956) — so this is the seller. Null for a charge that paid\n * only the platform, a workspace's own subscription.\n */\n sellerAccountId: string | null\n} | null> {\n if (!chargeId || !options.secretKey) return null\n try {\n const response = await (options.fetchImpl ?? fetch)(\n `https://api.stripe.com/v1/charges/${encodeURIComponent(chargeId)}`,\n { headers: { Authorization: `Bearer ${options.secretKey}` } },\n )\n if (!response.ok) return null\n const charge = (await response.json()) as Record<string, any>\n const card = charge?.['payment_method_details']?.['card'] ?? {}\n const text = (value: unknown) =>\n typeof value === 'string' && value ? value : null\n return {\n amountCents: Number.isFinite(Number(charge?.['amount']))\n ? Number(charge['amount'])\n : null,\n currency: String(charge?.['currency'] ?? 'usd'),\n customerId: text(charge?.['customer']),\n checks: {\n cvcCheck: text(card?.['checks']?.['cvc_check']),\n addressPostalCodeCheck: text(card?.['checks']?.['address_postal_code_check']),\n cardCountry: text(card?.['country']),\n riskLevel: text(charge?.['outcome']?.['risk_level']),\n threeDSecure: text(card?.['three_d_secure']?.['result']),\n },\n sellerAccountId: accountRef(charge?.['transfer_data']?.['destination']),\n }\n } catch {\n return null\n }\n}\n\n/** A Stripe account reference, expanded or not, as an id or null. */\nfunction accountRef(value: unknown): string | null {\n const id =\n typeof value === 'string'\n ? value\n : String((value as { id?: unknown } | null)?.id ?? '')\n return id.startsWith('acct_') ? id : null\n}\n\n/** The row's prose: what arrived, about which workspace, and what to do. */\nexport function describePaymentFraudSignal(signal: PaymentFraudSignal): string {\n const lines = [\n `${KIND_LABEL[signal.kind]} from Stripe (${signal.stripeObjectId})` +\n (signal.livemode ? '' : ' — TEST MODE') +\n '.',\n `Workspace: ${signal.orgId ?? 'none — the charge did not resolve to a workspace subscription'}.`,\n `Charge: ${signal.chargeId ?? signal.paymentIntentId ?? 'not named'} · ${formatSignalAmount(signal.amountCents, signal.currency)}.`,\n ]\n if (signal.detail) lines.push(`Stripe says: ${signal.detail}.`)\n const checks = signal.checks\n if (checks) {\n lines.push(\n `Card: CVC ${checks.cvcCheck ?? 'unknown'}, postal code ${checks.addressPostalCodeCheck ?? 'unknown'}, ` +\n `issued in ${checks.cardCountry ?? 'unknown'}, 3DS ${checks.threeDSecure ?? 'not used'}, ` +\n `Radar risk ${checks.riskLevel ?? 'unknown'}.`,\n )\n }\n lines.push(\n signal.kind === 'radar-review'\n ? 'The payment waits in Stripe until the review is closed there.'\n : signal.kind === 'dispute'\n ? 'Answer the dispute in Stripe before its evidence deadline.'\n : 'An early fraud warning is not yet a chargeback; refunding now can avoid one.',\n 'Nothing has been refunded or canceled. Decide on the org’s Subscription card, lock the workspace if it is fraud, and close this row with what you did.',\n )\n return lines.join('\\n').slice(0, 5000)\n}\n\n/**\n * File one signal and tell staff, once per signal.\n *\n * Idempotent on the Stripe object id: a redelivery bumps `reportCount` and\n * leaves the row's status — which staff own from the moment they touch it —\n * where it was. Throws only if the row write throws, which is the webhook's\n * to answer; the notification never throws.\n */\nexport async function recordPaymentFraudSignal(\n signal: PaymentFraudSignal,\n deps: {\n firestore: FirebaseFirestore.Firestore\n notify: (payload: {\n type: 'system.abuseReportUrgent'\n title: string\n body: string\n link: string\n }) => Promise<void>\n },\n): Promise<{ reviewId: string; reference: string; first: boolean }> {\n const reviewId = paymentFraudSignalReviewId(signal.kind, signal.stripeObjectId)\n const reference = paymentFraudSignalReference(reviewId)\n const ref = deps.firestore.collection(ABUSE_REPORT_COLLECTION).doc(reviewId)\n const first = !(await ref.get()).exists\n const subscriptionCard = signal.orgId\n ? staffSubscriptionCardPath(signal.orgId)\n : null\n await ref.set(\n {\n reference,\n // \"Phishing or fraud\" — the queue's urgent fraud category.\n category: 'phishing',\n severity: 'urgent',\n source: 'stripe-fraud-signal',\n url: null,\n reportedHostname: null,\n hostId: null,\n orgId: signal.orgId,\n details: describePaymentFraudSignal(signal),\n reporterEmail: null,\n reporterName: null,\n dmca: null,\n reportCount: FieldValue.increment(1),\n paymentSignal: {\n kind: signal.kind,\n stripeObjectId: signal.stripeObjectId,\n chargeId: signal.chargeId,\n paymentIntentId: signal.paymentIntentId,\n amountCents: signal.amountCents,\n currency: signal.currency,\n detail: signal.detail,\n checks: signal.checks,\n livemode: signal.livemode,\n subscriptionCard,\n },\n updatedAt: FieldValue.serverTimestamp(),\n ...(first\n ? { status: 'open', createdAt: FieldValue.serverTimestamp() }\n : {}),\n },\n { merge: true },\n )\n if (first) {\n await deps\n .notify({\n type: 'system.abuseReportUrgent',\n title: `${KIND_LABEL[signal.kind]} — ${formatSignalAmount(signal.amountCents, signal.currency)}`,\n body:\n `${signal.orgId ? `Workspace ${signal.orgId}` : 'A charge that is not a workspace subscription'}, ` +\n `charge ${signal.chargeId ?? signal.paymentIntentId ?? 'not named'}. ` +\n `Nothing has been refunded or canceled. Reference ${reference}.`,\n link: '/admin/abuse-reports',\n })\n .catch(() => undefined)\n }\n return { reviewId, reference, first }\n}\n\n/*==========================================\n * THE SELLER PATTERN: WHEN THE MERCHANT MAY BE THE FRAUDSTER (AGL-3360).\n *\n * A site's own sales are destination charges on the platform account, so\n * Stripe's fraud signals about a shopper's card arrive here too. One of them\n * is the merchant's business — their customer, their order, their decision\n * (`payment-risk-record.ts` puts it on the record and tells them). Staff are\n * not paged for it.\n *\n * What IS staff's business is the shape a phishing actor leaves when they\n * run stolen cards through a storefront of their own: several different\n * charges on ONE connected account drawing issuer fraud reports or\n * chargebacks in a short time. So every signal on a seller's charge is kept\n * in a small per-account ledger, and one urgent abuse-queue row is filed when\n *\n * ≥ 3 DISTINCT charges carry an early fraud warning or a dispute\n * within 7 days.\n *\n * Why those numbers. An early fraud warning is an issuer's report that the\n * cardholder did not make the payment, and a dispute is a formal\n * chargeback; a legitimate small merchant sees either rarely — card-network\n * dispute monitoring starts near 0.9% of a month's transactions, single\n * digits a MONTH for a shop doing hundreds of sales. One or two in a week is\n * ordinary friendly fraud and must never page staff. Three separate charges\n * in one week is a rate a real small shop does not produce, and is what a\n * card tester or a stolen-card storefront produces within days. Counted by\n * CHARGE, because a warning is routinely followed by a dispute on the same\n * payment, and that is one bad payment, not two. Radar reviews are kept in\n * the ledger for the row's prose but never counted: a review is Stripe's\n * suspicion, not an issuer's report, and a busy shop can collect several\n * that clear.\n *\n * One row per window: once filed, the account is not filed again until 7\n * days have passed, so a burst is one row with everything in it rather than\n * a row per signal. NOTHING IS DONE TO THE ACCOUNT OR THE MONEY: staff\n * decide (lock the workspace, pause the account's payouts in Stripe).\n *=========================================*/\n\nexport const SELLER_FRAUD_PATTERN = {\n /** Distinct charges with an early fraud warning or a dispute. */\n minDistinctCharges: 3,\n /** …within this window. */\n windowMs: 7 * 24 * 60 * 60 * 1000,\n /** How long the ledger keeps an entry at all. */\n retainMs: 30 * 24 * 60 * 60 * 1000,\n} as const\n\nconst WINDOW_DAYS = SELLER_FRAUD_PATTERN.windowMs / 86_400_000\n\n/** Admin-SDK only; no client rule opens it (default deny). */\nexport const SELLER_FRAUD_LEDGER_COLLECTION = 'paymentFraudLedger'\n\nexport interface SellerFraudLedgerEntry {\n kind: PaymentFraudSignalKind\n stripeObjectId: string\n chargeId: string | null\n amountCents: number | null\n currency: string\n detail: string\n /** The sites a plugin recognised the charge as belonging to. */\n hostIds: string[]\n atMs: number\n}\n\n/** Whether a seller's ledger shows the pattern at `nowMs`. Pure. */\nexport function sellerFraudPattern(\n entries: readonly SellerFraudLedgerEntry[],\n nowMs: number,\n): { matched: boolean; chargeIds: string[] } {\n const since = nowMs - SELLER_FRAUD_PATTERN.windowMs\n const chargeIds = [\n ...new Set(\n entries\n .filter(\n (entry) =>\n (entry.kind === 'early-fraud-warning' || entry.kind === 'dispute') &&\n entry.atMs >= since,\n )\n .map((entry) => entry.chargeId || entry.stripeObjectId),\n ),\n ]\n return {\n matched: chargeIds.length >= SELLER_FRAUD_PATTERN.minDistinctCharges,\n chargeIds,\n }\n}\n\n/** The connected account's page in the Stripe Dashboard. */\nexport function stripeConnectedAccountUrl(\n accountId: string,\n livemode: boolean,\n): string {\n return `https://dashboard.stripe.com/${livemode ? '' : 'test/'}connect/accounts/${encodeURIComponent(accountId)}`\n}\n\n/**\n * Keep one signal on a seller's charge, and file the pattern row when the\n * ledger crosses the threshold. Idempotent on the Stripe object id: a\n * redelivery changes nothing and files nothing.\n */\nexport async function recordSellerFraudSignal(\n input: {\n signal: PaymentFraudSignal\n sellerAccountId: string\n /** The sites a plugin recognised the charge as belonging to. */\n hostIds: string[]\n /** Workspaces owning those sites, for the row. */\n orgIds: string[]\n },\n deps: {\n firestore: FirebaseFirestore.Firestore\n notify: (payload: {\n type: 'system.abuseReportUrgent'\n title: string\n body: string\n link: string\n }) => Promise<void>\n nowMs?: number\n },\n): Promise<{\n first: boolean\n matched: boolean\n filed: { reviewId: string; reference: string } | null\n}> {\n const nowMs = deps.nowMs ?? Date.now()\n const { signal, sellerAccountId } = input\n const ledgerRef = deps.firestore\n .collection(SELLER_FRAUD_LEDGER_COLLECTION)\n .doc(sellerAccountId)\n const outcome = await deps.firestore.runTransaction(async (transaction) => {\n const fresh = await transaction.get(ledgerRef)\n const stored = (\n Array.isArray(fresh.get('entries')) ? fresh.get('entries') : []\n ) as SellerFraudLedgerEntry[]\n if (stored.some((entry) => entry.stripeObjectId === signal.stripeObjectId)) {\n return { first: false, matched: false, fileAtMs: 0, entries: stored }\n }\n const entries: SellerFraudLedgerEntry[] = [\n ...stored.filter(\n (entry) => entry.atMs >= nowMs - SELLER_FRAUD_PATTERN.retainMs,\n ),\n {\n kind: signal.kind,\n stripeObjectId: signal.stripeObjectId,\n chargeId: signal.chargeId,\n amountCents: signal.amountCents,\n currency: signal.currency,\n detail: signal.detail,\n hostIds: input.hostIds,\n atMs: nowMs,\n },\n ]\n const { matched } = sellerFraudPattern(entries, nowMs)\n const lastFiledAtMs = Number(fresh.get('lastFiledAtMs') ?? 0)\n const fileAtMs =\n matched &&\n !(lastFiledAtMs && nowMs - lastFiledAtMs < SELLER_FRAUD_PATTERN.windowMs)\n ? nowMs\n : 0\n transaction.set(\n ledgerRef,\n {\n sellerAccountId,\n entries,\n livemode: signal.livemode,\n updatedAtMs: nowMs,\n ...(fileAtMs ? { lastFiledAtMs: fileAtMs } : {}),\n },\n { merge: true },\n )\n return { first: true, matched, fileAtMs, entries }\n })\n if (!outcome.fileAtMs) {\n return { first: outcome.first, matched: outcome.matched, filed: null }\n }\n\n const { chargeIds } = sellerFraudPattern(outcome.entries, nowMs)\n const inWindow = outcome.entries.filter(\n (entry) => entry.atMs >= nowMs - SELLER_FRAUD_PATTERN.windowMs,\n )\n const reviewId = createHash('sha256')\n .update(`stripe-seller-pattern:${sellerAccountId}:${outcome.fileAtMs}`)\n .digest('hex')\n .slice(0, 40)\n const reference = paymentFraudSignalReference(reviewId)\n const orgId = input.orgIds[0] ?? null\n const hostIds = [...new Set(inWindow.flatMap((entry) => entry.hostIds ?? []))]\n const stripeUrl = stripeConnectedAccountUrl(sellerAccountId, signal.livemode)\n const details = [\n `${chargeIds.length} different charges paid to connected account ${sellerAccountId} drew an issuer fraud warning or a dispute within ${WINDOW_DAYS} days` +\n (signal.livemode ? '' : ' — TEST MODE') +\n '.',\n `Workspace(s): ${input.orgIds.length ? input.orgIds.join(', ') : 'not resolved'}. Site(s): ${hostIds.length ? hostIds.join(', ') : 'not resolved'}.`,\n ...inWindow.map(\n (entry) =>\n `• ${KIND_LABEL[entry.kind]} ${entry.stripeObjectId} on ${entry.chargeId ?? 'an unnamed charge'} · ${formatSignalAmount(entry.amountCents, entry.currency)}` +\n (entry.detail ? ` · ${entry.detail}` : ''),\n ),\n 'A shop taking stolen cards through its own storefront leaves this shape. Each merchant has already been shown the signal on its own order or booking.',\n `Nothing has been refunded, canceled or paused. If this is the seller's fraud, lock the workspace and pause the account's payouts in Stripe (${stripeUrl}), then close this row with what you did.`,\n ]\n .join('\\n')\n .slice(0, 5000)\n await deps.firestore\n .collection(ABUSE_REPORT_COLLECTION)\n .doc(reviewId)\n .set(\n {\n reference,\n // \"Phishing or fraud\" — the queue's urgent fraud category.\n category: 'phishing',\n severity: 'urgent',\n source: 'stripe-seller-fraud-pattern',\n url: null,\n reportedHostname: null,\n hostId: hostIds[0] ?? null,\n orgId,\n details,\n reporterEmail: null,\n reporterName: null,\n dmca: null,\n reportCount: 1,\n sellerPattern: {\n sellerAccountId,\n stripeAccountUrl: stripeUrl,\n chargeIds,\n orgIds: input.orgIds,\n hostIds,\n threshold: SELLER_FRAUD_PATTERN.minDistinctCharges,\n windowDays: WINDOW_DAYS,\n livemode: signal.livemode,\n },\n status: 'open',\n createdAt: FieldValue.serverTimestamp(),\n updatedAt: FieldValue.serverTimestamp(),\n },\n { merge: true },\n )\n await deps\n .notify({\n type: 'system.abuseReportUrgent',\n title: `Seller fraud pattern — ${chargeIds.length} charges on one account`,\n body:\n `Connected account ${sellerAccountId}` +\n (orgId ? ` (workspace ${orgId})` : '') +\n ` drew fraud warnings or disputes on ${chargeIds.length} different charges in ${WINDOW_DAYS} days. ` +\n `Nothing has been refunded, canceled or paused. Reference ${reference}.`,\n link: '/admin/abuse-reports',\n })\n .catch(() => undefined)\n return { first: true, matched: true, filed: { reviewId, reference } }\n}\n"],"names":["createHash","ABUSE_REPORT_COLLECTION","FieldValue","KIND_LABEL","dispute","PAYMENT_FRAUD_SIGNAL_LABELS","paymentFraudSignalReviewId","kind","stripeObjectId","update","digest","slice","paymentFraudSignalReference","reviewId","toUpperCase","staffSubscriptionCardPath","orgId","encodeURIComponent","formatSignalAmount","amountCents","currency","Number","isFinite","toFixed","String","readStripeChargeForSignal","chargeId","options","secretKey","charge","card","response","fetchImpl","fetch","headers","Authorization","ok","json","text","value","customerId","checks","cvcCheck","addressPostalCodeCheck","cardCountry","riskLevel","threeDSecure","sellerAccountId","accountRef","id","startsWith","describePaymentFraudSignal","signal","lines","livemode","paymentIntentId","detail","push","join","recordPaymentFraudSignal","deps","reference","ref","firestore","collection","doc","first","get","exists","subscriptionCard","set","category","severity","source","url","reportedHostname","hostId","details","reporterEmail","reporterName","dmca","reportCount","increment","paymentSignal","updatedAt","serverTimestamp","status","createdAt","merge","notify","type","title","body","link","catch","undefined","SELLER_FRAUD_PATTERN","minDistinctCharges","windowMs","retainMs","WINDOW_DAYS","SELLER_FRAUD_LEDGER_COLLECTION","sellerFraudPattern","entries","nowMs","since","chargeIds","Set","filter","entry","atMs","map","matched","length","stripeConnectedAccountUrl","accountId","recordSellerFraudSignal","input","hostIds","Date","now","ledgerRef","outcome","runTransaction","transaction","fresh","stored","Array","isArray","some","fileAtMs","lastFiledAtMs","updatedAtMs","filed","inWindow","orgIds","flatMap","stripeUrl","sellerPattern","stripeAccountUrl","threshold","windowDays"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;2CAqB2C,GAE3C,SAASA,UAAU,QAAQ,SAAQ;AACnC,SAASC,uBAAuB,QAAQ,sCAAqC;AAC7E,SAASC,UAAU,QAAQ,2BAA0B;AAQrD,MAAMC,aAAqD;IACzD,uBAAuB;IACvB,gBAAgB;IAChBC,SAAS;AACX;AAEA,yEAAyE,GACzE,OAAO,MAAMC,8BAA8BF,WAAU;AA4BrD,mEAAmE,GACnE,OAAO,SAASG,2BACdC,IAA4B,EAC5BC,cAAsB;IAEtB,OAAOR,WAAW,UACfS,MAAM,CAAC,CAAC,aAAa,EAAEF,KAAK,CAAC,EAAEC,gBAAgB,EAC/CE,MAAM,CAAC,OACPC,KAAK,CAAC,GAAG;AACd;AAEA,kFAAkF,GAClF,OAAO,SAASC,4BAA4BC,QAAgB;IAC1D,OAAO,CAAC,GAAG,EAAEA,SAASF,KAAK,CAAC,GAAG,IAAIG,WAAW,IAAI;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