@fantastic.dev/better-stripe 0.33.0 → 0.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/CHANGELOG.md +7 -0
- package/README.md +30 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +36 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +18 -0
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +36 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +18 -0
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/core/accountClosures.d.ts +15 -0
- package/dist/client/core/accountClosures.d.ts.map +1 -0
- package/dist/client/core/accountClosures.js +10 -0
- package/dist/client/core/accountClosures.js.map +1 -0
- package/dist/client/core/accounts.d.ts.map +1 -1
- package/dist/client/core/accounts.js +15 -23
- package/dist/client/core/accounts.js.map +1 -1
- package/dist/client/core/personalAccountMapping.d.ts +8 -0
- package/dist/client/core/personalAccountMapping.d.ts.map +1 -0
- package/dist/client/core/personalAccountMapping.js +11 -0
- package/dist/client/core/personalAccountMapping.js.map +1 -0
- package/dist/client/index.d.ts +55 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +13 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/publicTypes.d.ts +5 -0
- package/dist/client/publicTypes.d.ts.map +1 -0
- package/dist/client/publicTypes.js +2 -0
- package/dist/client/publicTypes.js.map +1 -0
- package/dist/component/_generated/component.d.ts +88 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/accountClosure/helpers.d.ts +18 -0
- package/dist/component/accountClosure/helpers.d.ts.map +1 -0
- package/dist/component/accountClosure/helpers.js +18 -0
- package/dist/component/accountClosure/helpers.js.map +1 -0
- package/dist/component/accountClosure/mutations.d.ts +20 -0
- package/dist/component/accountClosure/mutations.d.ts.map +1 -0
- package/dist/component/accountClosure/mutations.js +55 -0
- package/dist/component/accountClosure/mutations.js.map +1 -0
- package/dist/component/accountClosure/queries.d.ts +34 -0
- package/dist/component/accountClosure/queries.d.ts.map +1 -0
- package/dist/component/accountClosure/queries.js +36 -0
- package/dist/component/accountClosure/queries.js.map +1 -0
- package/dist/component/accountClosure/schema.d.ts +46 -0
- package/dist/component/accountClosure/schema.d.ts.map +1 -0
- package/dist/component/accountClosure/schema.js +20 -0
- package/dist/component/accountClosure/schema.js.map +1 -0
- package/dist/component/core/mutations.d.ts.map +1 -1
- package/dist/component/core/mutations.js +5 -0
- package/dist/component/core/mutations.js.map +1 -1
- package/dist/component/core/personalAccountMapping.d.ts +95 -0
- package/dist/component/core/personalAccountMapping.d.ts.map +1 -0
- package/dist/component/core/personalAccountMapping.js +54 -0
- package/dist/component/core/personalAccountMapping.js.map +1 -0
- package/dist/component/core/queries.d.ts +27 -0
- package/dist/component/core/queries.d.ts.map +1 -1
- package/dist/component/core/queries.js +7 -0
- package/dist/component/core/queries.js.map +1 -1
- package/dist/component/earnings/triggers.d.ts +42 -0
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/schema.d.ts +18 -0
- package/dist/component/schema.js +2 -0
- package/dist/component/schema.js.map +1 -1
- package/docs/personal-account-mapping.md +54 -0
- package/package.json +3 -2
- package/src/client/core/account-close-orchestration.test.ts +131 -0
- package/src/client/core/account-closure.test.ts +317 -0
- package/src/client/core/accountClosures.ts +37 -0
- package/src/client/core/accounts.test.ts +0 -111
- package/src/client/core/accounts.ts +24 -29
- package/src/client/core/personal-account-mapping.test.ts +71 -0
- package/src/client/core/personalAccountMapping.ts +23 -0
- package/src/client/index.ts +36 -33
- package/src/client/publicTypes.ts +35 -0
- package/src/component/_generated/api.ts +8 -0
- package/src/component/_generated/component.ts +126 -0
- package/src/component/accountClosure/helpers.ts +21 -0
- package/src/component/accountClosure/mutations.ts +56 -0
- package/src/component/accountClosure/queries.ts +43 -0
- package/src/component/accountClosure/schema.ts +20 -0
- package/src/component/core/mutations.ts +3 -0
- package/src/component/core/personal-account-mapping.test.ts +173 -0
- package/src/component/core/personalAccountMapping.ts +81 -0
- package/src/component/core/queries.ts +11 -0
- package/src/component/schema.ts +2 -0
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
export declare const mutation: import("convex-helpers/server/customFunctions").CustomBuilder<"mutation", Record<string, never>, import("convex/server").GenericMutationCtx<{
|
|
2
|
+
accountClosures: {
|
|
3
|
+
document: {
|
|
4
|
+
_creationTime: number;
|
|
5
|
+
_id: import("convex/values").GenericId<"accountClosures">;
|
|
6
|
+
appliedConfigurations?: ("customer" | "merchant" | "recipient")[] | undefined;
|
|
7
|
+
closedAt?: number | undefined;
|
|
8
|
+
orgId?: string | undefined;
|
|
9
|
+
state: "closed" | "pending";
|
|
10
|
+
stripeAccountId: string;
|
|
11
|
+
userId?: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
fieldPaths: "_id" | ("_creationTime" | "appliedConfigurations" | "closedAt" | "orgId" | "state" | "stripeAccountId" | "userId");
|
|
14
|
+
indexes: {
|
|
15
|
+
by_id: ["_id"];
|
|
16
|
+
by_creation_time: ["_creationTime"];
|
|
17
|
+
by_stripe_account_id: ["stripeAccountId", "_creationTime"];
|
|
18
|
+
by_user_state: ["userId", "orgId", "state", "_creationTime"];
|
|
19
|
+
};
|
|
20
|
+
searchIndexes: {};
|
|
21
|
+
vectorIndexes: {};
|
|
22
|
+
};
|
|
2
23
|
accounts: {
|
|
3
24
|
document: {
|
|
4
25
|
_creationTime: number;
|
|
@@ -1284,6 +1305,27 @@ export declare const mutation: import("convex-helpers/server/customFunctions").C
|
|
|
1284
1305
|
vectorIndexes: {};
|
|
1285
1306
|
};
|
|
1286
1307
|
}>, Record<string, never>, import("convex/server").GenericMutationCtx<{
|
|
1308
|
+
accountClosures: {
|
|
1309
|
+
document: {
|
|
1310
|
+
_creationTime: number;
|
|
1311
|
+
_id: import("convex/values").GenericId<"accountClosures">;
|
|
1312
|
+
appliedConfigurations?: ("customer" | "merchant" | "recipient")[] | undefined;
|
|
1313
|
+
closedAt?: number | undefined;
|
|
1314
|
+
orgId?: string | undefined;
|
|
1315
|
+
state: "closed" | "pending";
|
|
1316
|
+
stripeAccountId: string;
|
|
1317
|
+
userId?: string | undefined;
|
|
1318
|
+
};
|
|
1319
|
+
fieldPaths: "_id" | ("_creationTime" | "appliedConfigurations" | "closedAt" | "orgId" | "state" | "stripeAccountId" | "userId");
|
|
1320
|
+
indexes: {
|
|
1321
|
+
by_id: ["_id"];
|
|
1322
|
+
by_creation_time: ["_creationTime"];
|
|
1323
|
+
by_stripe_account_id: ["stripeAccountId", "_creationTime"];
|
|
1324
|
+
by_user_state: ["userId", "orgId", "state", "_creationTime"];
|
|
1325
|
+
};
|
|
1326
|
+
searchIndexes: {};
|
|
1327
|
+
vectorIndexes: {};
|
|
1328
|
+
};
|
|
1287
1329
|
accounts: {
|
|
1288
1330
|
document: {
|
|
1289
1331
|
_creationTime: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"triggers.d.ts","sourceRoot":"","sources":["../../../src/component/earnings/triggers.ts"],"names":[],"mappings":"AAiGA,eAAO,MAAM,QAAQ
|
|
1
|
+
{"version":3,"file":"triggers.d.ts","sourceRoot":"","sources":["../../../src/component/earnings/triggers.ts"],"names":[],"mappings":"AAiGA,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAA0D,CAAC"}
|
|
@@ -1140,6 +1140,24 @@ declare const _default: import("convex/server").SchemaDefinition<{
|
|
|
1140
1140
|
by_stripe_account_id: ["stripeAccountId", "_creationTime"];
|
|
1141
1141
|
by_user_id: ["userId", "_creationTime"];
|
|
1142
1142
|
}, {}, {}>;
|
|
1143
|
+
accountClosures: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
1144
|
+
appliedConfigurations?: ("customer" | "merchant" | "recipient")[] | undefined;
|
|
1145
|
+
closedAt?: number | undefined;
|
|
1146
|
+
orgId?: string | undefined;
|
|
1147
|
+
state: "closed" | "pending";
|
|
1148
|
+
stripeAccountId: string;
|
|
1149
|
+
userId?: string | undefined;
|
|
1150
|
+
}, {
|
|
1151
|
+
stripeAccountId: import("convex/values").VString<string, "required">;
|
|
1152
|
+
userId: import("convex/values").VString<string | undefined, "optional">;
|
|
1153
|
+
orgId: import("convex/values").VString<string | undefined, "optional">;
|
|
1154
|
+
appliedConfigurations: import("convex/values").VArray<("customer" | "merchant" | "recipient")[] | undefined, import("convex/values").VUnion<"customer" | "merchant" | "recipient", [import("convex/values").VLiteral<"customer", "required">, import("convex/values").VLiteral<"merchant", "required">, import("convex/values").VLiteral<"recipient", "required">], "required", never>, "optional">;
|
|
1155
|
+
state: import("convex/values").VUnion<"closed" | "pending", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"closed", "required">], "required", never>;
|
|
1156
|
+
closedAt: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
1157
|
+
}, "required", "appliedConfigurations" | "closedAt" | "orgId" | "state" | "stripeAccountId" | "userId">, {
|
|
1158
|
+
by_stripe_account_id: ["stripeAccountId", "_creationTime"];
|
|
1159
|
+
by_user_state: ["userId", "orgId", "state", "_creationTime"];
|
|
1160
|
+
}, {}, {}>;
|
|
1143
1161
|
products: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
1144
1162
|
accountId?: string | undefined;
|
|
1145
1163
|
active: boolean;
|
package/dist/component/schema.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { accountClosuresTable } from "./accountClosure/schema.js";
|
|
1
2
|
import { jobsTable as payoutWorkerJobsTable } from "./payoutWorker/schema.js";
|
|
2
3
|
import { financialRevisionsTable, riskEventsTable, riskRevisionsTable, snapshotsTable, snapshotSourcesTable, snapshotClaimsTable, snapshotFeesTable, } from "./payoutSnapshots/schema.js";
|
|
3
4
|
import { claimsTable as payoutSyncClaimsTable } from "./payoutSync/schema.js";
|
|
@@ -46,6 +47,7 @@ export default defineSchema({
|
|
|
46
47
|
commissionDecisions: commissionDecisionsTable,
|
|
47
48
|
// Core
|
|
48
49
|
accounts: accountsTable,
|
|
50
|
+
accountClosures: accountClosuresTable,
|
|
49
51
|
// Products
|
|
50
52
|
products: productsTable,
|
|
51
53
|
prices: pricesTable,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAA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C,2BAA2B,EAAE,mBAAmB;IAChD,uBAAuB;IACvB,iBAAiB;IACjB,gBAAgB;IAChB,yBAAyB,EAAE,iBAAiB;IAC5C,yBAAyB,EAAE,8BAA8B;IACzD,gBAAgB,EAAE,qBAAqB;IACvC,iBAAiB,EAAE,sBAAsB;IACzC,mBAAmB,EAAE,wBAAwB;IAC7C,uBAAuB,EAAE,4BAA4B;IACrD,cAAc,EAAE,aAAa;IAC7B,sBAAsB,EAAE,eAAe;IACvC,cAAc,EAAE,mBAAmB;IACnC,cAAc,EAAE,WAAW;IAC3B,gBAAgB,EAAE,aAAa;IAC/B,cAAc,EAAE,WAAW;IAC3B,oBAAoB,EAAE,iBAAiB;IACvC,qBAAqB,EAAE,gBAAgB;IACvC,eAAe,EAAE,oBAAoB;IACrC,mBAAmB,EAAE,wBAAwB;IAC7C,OAAO;IACP,QAAQ,EAAE,aAAa;IACvB,eAAe,EAAE,oBAAoB;IAErC,WAAW;IACX,QAAQ,EAAE,aAAa;IACvB,MAAM,EAAE,WAAW;IAEnB,UAAU;IACV,aAAa,EAAE,kBAAkB;IACjC,gBAAgB,EAAE,qBAAqB;IACvC,QAAQ,EAAE,aAAa;IAEvB,UAAU;IACV,QAAQ,EAAE,aAAa;IACvB,OAAO,EAAE,YAAY;IACrB,iBAAiB,EAAE,sBAAsB;IACzC,OAAO,EAAE,YAAY;IACrB,QAAQ,EAAE,aAAa;IACvB,SAAS,EAAE,cAAc;IACzB,mBAAmB,EAAE,wBAAwB;IAE7C,WAAW;IACX,aAAa,EAAE,kBAAkB;CAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Unambiguous personal account mappings
|
|
2
|
+
|
|
3
|
+
`stripe.getPersonalAccountMapping(ctx, { userId })` reads component identity
|
|
4
|
+
mappings without contacting Stripe. It returns the exported
|
|
5
|
+
`PersonalAccountMapping` discriminated union:
|
|
6
|
+
|
|
7
|
+
- `status: "unique"` includes the original account document.
|
|
8
|
+
- `status: "unavailable"` includes `missing`, `ambiguous`, `organization`,
|
|
9
|
+
`invalid_account`, `closure_unresolved` or `closed` as its reason.
|
|
10
|
+
|
|
11
|
+
The required user selector is exact, nonempty, at most 256 characters and free of
|
|
12
|
+
ASCII control characters. Extra SDK options are rejected before component reads.
|
|
13
|
+
A successful result requires exactly one user-index match, no organization field
|
|
14
|
+
(including an empty organization ID), a canonical `acct_` identifier of at most
|
|
15
|
+
128 characters and exactly one reciprocal Stripe-account-index match pointing
|
|
16
|
+
to the same document. Each index read takes at most two rows. A candidate's
|
|
17
|
+
closure index also takes at most two rows: duplicate closure provenance, pending
|
|
18
|
+
closure or terminal closure makes that candidate unavailable. At most six rows
|
|
19
|
+
are read; there is no whole-table scan, provider read or financial write.
|
|
20
|
+
|
|
21
|
+
Two records for one user are ambiguous even when the older record was inserted
|
|
22
|
+
first, or one record belongs to an organization. The reader neither selects the
|
|
23
|
+
newest account nor migrates ownership or funds. It preserves the existing
|
|
24
|
+
`getAccountByUserId`, `getAccountByStripeId` and organization getters for consumers
|
|
25
|
+
that depend on their legacy behavior. Do not use those first-match getters as
|
|
26
|
+
proof of unique personal ownership.
|
|
27
|
+
|
|
28
|
+
Authenticate and authorize the enabled host actor before deriving `userId` on
|
|
29
|
+
the server. User IDs supplied by the browser or a Vite demo persona do not prove
|
|
30
|
+
authentication. For a refund, derive the original merchant from verified payment
|
|
31
|
+
routing first, then compare that original identifier to the unique mapping for
|
|
32
|
+
the authorized owner. A community ownership transfer cannot remap an old
|
|
33
|
+
merchant's payment to its new owner. Unknown or ambiguous mappings must remain
|
|
34
|
+
unavailable.
|
|
35
|
+
|
|
36
|
+
The matching Vite server binding is
|
|
37
|
+
[`requireOriginalPersonalAccount`](../example/convex/billing/personalAccountMapping.ts).
|
|
38
|
+
It takes an already-authenticated server identity and the server-verified original
|
|
39
|
+
account identifier, rejects a different owner, organization or replacement
|
|
40
|
+
account, and forwards component errors. It is a reference adapter, not a session
|
|
41
|
+
authentication implementation. A production host supplies its real session,
|
|
42
|
+
tenant authorization and immutable payment provenance.
|
|
43
|
+
|
|
44
|
+
Component mutations can reuse `resolvePersonalAccountMapping` from
|
|
45
|
+
`src/component/core/personalAccountMapping.ts` in their transaction; mutation
|
|
46
|
+
contexts satisfy its query-context database interface. This avoids duplicating
|
|
47
|
+
the reciprocal and closure checks when admitting an ownership binding.
|
|
48
|
+
|
|
49
|
+
A unique component mapping is identity evidence at the time of the read. It does
|
|
50
|
+
not prove provider freshness, merchant capabilities, settlement eligibility,
|
|
51
|
+
available balance or permission to create a refund. Original invoice allocation,
|
|
52
|
+
buyer, currency, charge, refund history and creation-time revalidation remain
|
|
53
|
+
separate requirements. Closed-account history uses the dedicated historical
|
|
54
|
+
provenance APIs; this reader never revives a closed account.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fantastic.dev/better-stripe",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "A Convex component for Stripe V2 Accounts API integration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"stripe",
|
|
@@ -67,7 +67,8 @@
|
|
|
67
67
|
"docs/read-contracts.md",
|
|
68
68
|
"docs/invoice-payment-pages.md",
|
|
69
69
|
"docs/checkout-session-pages.md",
|
|
70
|
-
"docs/refund-context.md"
|
|
70
|
+
"docs/refund-context.md",
|
|
71
|
+
"docs/personal-account-mapping.md"
|
|
71
72
|
],
|
|
72
73
|
"scripts": {
|
|
73
74
|
"build": "tsc --project ./tsconfig.build.json",
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// @vitest-environment edge-runtime
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import type Stripe from "stripe";
|
|
4
|
+
import type { Component, RunCtx } from "../helpers.js";
|
|
5
|
+
import { closeAccount, restartAccountOnboarding } from "./accounts.js";
|
|
6
|
+
|
|
7
|
+
function makeStripe() {
|
|
8
|
+
return { v2: { core: { accounts: { close: vi.fn(), retrieve: vi.fn() } } } };
|
|
9
|
+
}
|
|
10
|
+
function asStripe(stripe: ReturnType<typeof makeStripe>) {
|
|
11
|
+
return stripe as unknown as Stripe;
|
|
12
|
+
}
|
|
13
|
+
function makeComponent() {
|
|
14
|
+
return {
|
|
15
|
+
accountClosure: {
|
|
16
|
+
mutations: {
|
|
17
|
+
prepare: refFor("accountClosure/mutations/prepare"),
|
|
18
|
+
complete: refFor("accountClosure/mutations/complete"),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
} as unknown as Component;
|
|
22
|
+
}
|
|
23
|
+
function refFor(path: string) {
|
|
24
|
+
return { [Symbol.for("toReferencePath")]: `betterStripe/${path}` };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("closeAccount / restartAccountOnboarding", () => {
|
|
28
|
+
function context(appliedConfigurations?: string[], state = "pending") {
|
|
29
|
+
const runMutation = vi
|
|
30
|
+
.fn()
|
|
31
|
+
.mockResolvedValueOnce({
|
|
32
|
+
closure: { appliedConfigurations, state },
|
|
33
|
+
isRetry: false,
|
|
34
|
+
})
|
|
35
|
+
.mockResolvedValue(null);
|
|
36
|
+
return { ctx: { runMutation } as unknown as RunCtx, runMutation };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
it("pins stored configurations before close and completes without deleting provenance", async () => {
|
|
40
|
+
const stripe = makeStripe();
|
|
41
|
+
const { ctx, runMutation } = context(["merchant", "recipient"]);
|
|
42
|
+
expect(
|
|
43
|
+
await closeAccount(asStripe(stripe), makeComponent(), ctx, {
|
|
44
|
+
stripeAccountId: "acct_close",
|
|
45
|
+
}),
|
|
46
|
+
).toEqual({ closed: true });
|
|
47
|
+
expect(stripe.v2.core.accounts.retrieve).not.toHaveBeenCalled();
|
|
48
|
+
expect(stripe.v2.core.accounts.close).toHaveBeenCalledWith(
|
|
49
|
+
"acct_close",
|
|
50
|
+
{ applied_configurations: ["merchant", "recipient"] },
|
|
51
|
+
{ idempotencyKey: "betterstripe-close:acct_close" },
|
|
52
|
+
);
|
|
53
|
+
expect(runMutation.mock.calls.map((call) => call[0])).toEqual([
|
|
54
|
+
refFor("accountClosure/mutations/prepare"),
|
|
55
|
+
refFor("accountClosure/mutations/complete"),
|
|
56
|
+
]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("retrieves configurations when none were stored", async () => {
|
|
60
|
+
const stripe = makeStripe();
|
|
61
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({
|
|
62
|
+
applied_configurations: ["merchant"],
|
|
63
|
+
});
|
|
64
|
+
const { ctx } = context();
|
|
65
|
+
await closeAccount(asStripe(stripe), makeComponent(), ctx, {
|
|
66
|
+
stripeAccountId: "acct_fallback",
|
|
67
|
+
});
|
|
68
|
+
expect(stripe.v2.core.accounts.close).toHaveBeenCalledWith(
|
|
69
|
+
"acct_fallback",
|
|
70
|
+
{ applied_configurations: ["merchant"] },
|
|
71
|
+
{ idempotencyKey: "betterstripe-close:acct_fallback" },
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("preserves pending provenance and refuses close when required provider lookup fails", async () => {
|
|
76
|
+
const stripe = makeStripe();
|
|
77
|
+
stripe.v2.core.accounts.retrieve.mockRejectedValue(
|
|
78
|
+
new Error("retrieve unavailable"),
|
|
79
|
+
);
|
|
80
|
+
const { ctx, runMutation } = context();
|
|
81
|
+
await expect(
|
|
82
|
+
closeAccount(asStripe(stripe), makeComponent(), ctx, {
|
|
83
|
+
stripeAccountId: "acct_missing",
|
|
84
|
+
}),
|
|
85
|
+
).rejects.toThrow("retrieve unavailable");
|
|
86
|
+
expect(stripe.v2.core.accounts.close).not.toHaveBeenCalled();
|
|
87
|
+
expect(runMutation).toHaveBeenCalledTimes(1);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("does not complete local closure after provider refusal", async () => {
|
|
91
|
+
const stripe = makeStripe();
|
|
92
|
+
stripe.v2.core.accounts.close.mockRejectedValue(new Error("close boom"));
|
|
93
|
+
const { ctx, runMutation } = context(["merchant"]);
|
|
94
|
+
await expect(
|
|
95
|
+
closeAccount(asStripe(stripe), makeComponent(), ctx, {
|
|
96
|
+
stripeAccountId: "acct_err",
|
|
97
|
+
}),
|
|
98
|
+
).rejects.toThrow("close boom");
|
|
99
|
+
expect(runMutation).toHaveBeenCalledTimes(1);
|
|
100
|
+
expect(runMutation).toHaveBeenCalledWith(
|
|
101
|
+
refFor("accountClosure/mutations/prepare"),
|
|
102
|
+
{ stripeAccountId: "acct_err" },
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("returns an already closed account without another provider operation", async () => {
|
|
107
|
+
const stripe = makeStripe();
|
|
108
|
+
const { ctx } = context([], "closed");
|
|
109
|
+
expect(
|
|
110
|
+
await closeAccount(asStripe(stripe), makeComponent(), ctx, {
|
|
111
|
+
stripeAccountId: "acct_done",
|
|
112
|
+
}),
|
|
113
|
+
).toEqual({ closed: true });
|
|
114
|
+
expect(stripe.v2.core.accounts.close).not.toHaveBeenCalled();
|
|
115
|
+
expect(stripe.v2.core.accounts.retrieve).not.toHaveBeenCalled();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("restartAccountOnboarding retains the same closure provenance contract", async () => {
|
|
119
|
+
const stripe = makeStripe();
|
|
120
|
+
const { ctx, runMutation } = context([]);
|
|
121
|
+
expect(
|
|
122
|
+
await restartAccountOnboarding(asStripe(stripe), makeComponent(), ctx, {
|
|
123
|
+
stripeAccountId: "acct_restart",
|
|
124
|
+
}),
|
|
125
|
+
).toEqual({ closed: true });
|
|
126
|
+
expect(runMutation.mock.calls.map((call) => call[0])).toEqual([
|
|
127
|
+
refFor("accountClosure/mutations/prepare"),
|
|
128
|
+
refFor("accountClosure/mutations/complete"),
|
|
129
|
+
]);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
// @vitest-environment edge-runtime
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import type Stripe from "stripe";
|
|
4
|
+
import type { RunCtx } from "../helpers.js";
|
|
5
|
+
import { components, initConvexTest } from "../setup.test.js";
|
|
6
|
+
import schema from "../../component/schema.js";
|
|
7
|
+
import { closeAccount } from "./accounts.js";
|
|
8
|
+
import { BetterStripe } from "../index.js";
|
|
9
|
+
|
|
10
|
+
const modules = import.meta.glob("../../component/**/*.ts");
|
|
11
|
+
function fixture() {
|
|
12
|
+
const t = initConvexTest();
|
|
13
|
+
t.registerComponent("betterStripe", schema, modules);
|
|
14
|
+
const ctx = { runQuery: t.query, runMutation: t.mutation } as RunCtx;
|
|
15
|
+
const close = vi.fn().mockResolvedValue({ closed: true });
|
|
16
|
+
const retrieve = vi.fn().mockResolvedValue({ closed: true });
|
|
17
|
+
const stripe = {
|
|
18
|
+
v2: { core: { accounts: { close, retrieve } } },
|
|
19
|
+
} as unknown as Stripe;
|
|
20
|
+
const client = new BetterStripe(components.betterStripe, {
|
|
21
|
+
STRIPE_SECRET_KEY: "sk_test_bts202_dummy",
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
client,
|
|
25
|
+
t,
|
|
26
|
+
ctx,
|
|
27
|
+
stripe,
|
|
28
|
+
close,
|
|
29
|
+
retrieve,
|
|
30
|
+
component: components.betterStripe,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe("account closure provenance", () => {
|
|
35
|
+
it("does not resurrect a closed recipient on a late account upsert", async () => {
|
|
36
|
+
const f = fixture();
|
|
37
|
+
const account = {
|
|
38
|
+
stripeAccountId: "acct_closed",
|
|
39
|
+
userId: "original",
|
|
40
|
+
appliedConfigurations: ["recipient" as const],
|
|
41
|
+
};
|
|
42
|
+
await f.t.mutation(f.component.core.mutations.upsertAccount, account);
|
|
43
|
+
await closeAccount(f.stripe, f.component, f.ctx, {
|
|
44
|
+
stripeAccountId: account.stripeAccountId,
|
|
45
|
+
});
|
|
46
|
+
await f.t.mutation(f.component.core.mutations.upsertAccountInternal, {
|
|
47
|
+
...account,
|
|
48
|
+
userId: "replacement",
|
|
49
|
+
onboardingStatus: "complete",
|
|
50
|
+
});
|
|
51
|
+
await f.t.mutation(f.component.core.mutations.upsertAccount, account);
|
|
52
|
+
expect(
|
|
53
|
+
await f.t.query(f.component.core.queries.getAccountByUserId, {
|
|
54
|
+
userId: "original",
|
|
55
|
+
}),
|
|
56
|
+
).toBeNull();
|
|
57
|
+
expect(
|
|
58
|
+
await f.t.query(f.component.core.queries.getAccountByUserId, {
|
|
59
|
+
userId: "replacement",
|
|
60
|
+
}),
|
|
61
|
+
).toBeNull();
|
|
62
|
+
expect(
|
|
63
|
+
await f.t.query(f.component.core.queries.getAccountByStripeId, {
|
|
64
|
+
stripeAccountId: account.stripeAccountId,
|
|
65
|
+
}),
|
|
66
|
+
).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
it("retains original owner history while active lookups move to another account", async () => {
|
|
69
|
+
const f = fixture();
|
|
70
|
+
await f.t.mutation(f.component.core.mutations.upsertAccount, {
|
|
71
|
+
stripeAccountId: "acct_old",
|
|
72
|
+
userId: "original",
|
|
73
|
+
appliedConfigurations: ["recipient"],
|
|
74
|
+
});
|
|
75
|
+
await closeAccount(f.stripe, f.component, f.ctx, {
|
|
76
|
+
stripeAccountId: "acct_old",
|
|
77
|
+
});
|
|
78
|
+
await f.t.mutation(f.component.core.mutations.upsertAccount, {
|
|
79
|
+
stripeAccountId: "acct_new",
|
|
80
|
+
userId: "original",
|
|
81
|
+
});
|
|
82
|
+
const history = await f.client.listClosedAccountsByUserId(f.ctx, {
|
|
83
|
+
userId: "original",
|
|
84
|
+
paginationOpts: { numItems: 1, cursor: null },
|
|
85
|
+
});
|
|
86
|
+
expect(history.page.map((row) => row.stripeAccountId)).toEqual([
|
|
87
|
+
"acct_old",
|
|
88
|
+
]);
|
|
89
|
+
expect(history.page[0].userId).toBe("original");
|
|
90
|
+
expect(history.page[0].closedAt).toBeTypeOf("number");
|
|
91
|
+
expect(
|
|
92
|
+
(
|
|
93
|
+
await f.t.query(f.component.core.queries.getAccountByUserId, {
|
|
94
|
+
userId: "original",
|
|
95
|
+
})
|
|
96
|
+
)?.stripeAccountId,
|
|
97
|
+
).toBe("acct_new");
|
|
98
|
+
expect(
|
|
99
|
+
(
|
|
100
|
+
await f.t.query(
|
|
101
|
+
f.component.accountClosure.queries.listClosedAccountsByUserId,
|
|
102
|
+
{
|
|
103
|
+
userId: "replacement",
|
|
104
|
+
paginationOpts: { numItems: 1, cursor: null },
|
|
105
|
+
},
|
|
106
|
+
)
|
|
107
|
+
).page,
|
|
108
|
+
).toEqual([]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("keeps the live mapping after provider failure and pins its owner during retry", async () => {
|
|
112
|
+
const f = fixture();
|
|
113
|
+
await f.t.mutation(f.component.core.mutations.upsertAccount, {
|
|
114
|
+
stripeAccountId: "acct_fail",
|
|
115
|
+
userId: "original",
|
|
116
|
+
appliedConfigurations: [],
|
|
117
|
+
});
|
|
118
|
+
f.close.mockRejectedValueOnce(new Error("provider refused"));
|
|
119
|
+
await expect(
|
|
120
|
+
closeAccount(f.stripe, f.component, f.ctx, {
|
|
121
|
+
stripeAccountId: "acct_fail",
|
|
122
|
+
}),
|
|
123
|
+
).rejects.toThrow("provider refused");
|
|
124
|
+
expect(
|
|
125
|
+
(
|
|
126
|
+
await f.t.query(f.component.core.queries.getAccountByUserId, {
|
|
127
|
+
userId: "original",
|
|
128
|
+
})
|
|
129
|
+
)?.stripeAccountId,
|
|
130
|
+
).toBe("acct_fail");
|
|
131
|
+
expect(
|
|
132
|
+
await f.t.query(
|
|
133
|
+
f.component.accountClosure.queries.getClosedAccountByStripeId,
|
|
134
|
+
{ stripeAccountId: "acct_fail" },
|
|
135
|
+
),
|
|
136
|
+
).toBeNull();
|
|
137
|
+
await expect(
|
|
138
|
+
f.t.mutation(f.component.core.mutations.upsertAccount, {
|
|
139
|
+
stripeAccountId: "acct_fail",
|
|
140
|
+
userId: "replacement",
|
|
141
|
+
}),
|
|
142
|
+
).rejects.toThrow("ownership is pinned");
|
|
143
|
+
f.retrieve.mockResolvedValueOnce({
|
|
144
|
+
closed: false,
|
|
145
|
+
applied_configurations: [],
|
|
146
|
+
});
|
|
147
|
+
await closeAccount(f.stripe, f.component, f.ctx, {
|
|
148
|
+
stripeAccountId: "acct_fail",
|
|
149
|
+
});
|
|
150
|
+
expect(f.close).toHaveBeenCalledTimes(2);
|
|
151
|
+
expect(f.close.mock.calls[0][2]).toEqual(f.close.mock.calls[1][2]);
|
|
152
|
+
expect(
|
|
153
|
+
(
|
|
154
|
+
await f.t.query(
|
|
155
|
+
f.component.accountClosure.queries.getClosedAccountByStripeId,
|
|
156
|
+
{ stripeAccountId: "acct_fail" },
|
|
157
|
+
)
|
|
158
|
+
)?.userId,
|
|
159
|
+
).toBe("original");
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("recovers provider success followed by local completion failure without another close", async () => {
|
|
163
|
+
const f = fixture();
|
|
164
|
+
await f.t.mutation(f.component.core.mutations.upsertAccount, {
|
|
165
|
+
stripeAccountId: "acct_retry",
|
|
166
|
+
userId: "original",
|
|
167
|
+
appliedConfigurations: [],
|
|
168
|
+
});
|
|
169
|
+
const runMutation = vi
|
|
170
|
+
.fn(f.t.mutation)
|
|
171
|
+
.mockImplementationOnce(f.t.mutation)
|
|
172
|
+
.mockRejectedValueOnce(new Error("local completion unavailable"));
|
|
173
|
+
const ctx = { ...f.ctx, runMutation } as RunCtx;
|
|
174
|
+
await expect(
|
|
175
|
+
closeAccount(f.stripe, f.component, ctx, {
|
|
176
|
+
stripeAccountId: "acct_retry",
|
|
177
|
+
}),
|
|
178
|
+
).rejects.toThrow("local completion unavailable");
|
|
179
|
+
await closeAccount(f.stripe, f.component, f.ctx, {
|
|
180
|
+
stripeAccountId: "acct_retry",
|
|
181
|
+
});
|
|
182
|
+
await closeAccount(f.stripe, f.component, f.ctx, {
|
|
183
|
+
stripeAccountId: "acct_retry",
|
|
184
|
+
});
|
|
185
|
+
expect(f.close).toHaveBeenCalledTimes(1);
|
|
186
|
+
expect(f.close.mock.calls[0][2]).toEqual({
|
|
187
|
+
idempotencyKey: "betterstripe-close:acct_retry",
|
|
188
|
+
});
|
|
189
|
+
expect(
|
|
190
|
+
(
|
|
191
|
+
await f.t.query(
|
|
192
|
+
f.component.accountClosure.queries.getClosedAccountByStripeId,
|
|
193
|
+
{ stripeAccountId: "acct_retry" },
|
|
194
|
+
)
|
|
195
|
+
)?.userId,
|
|
196
|
+
).toBe("original");
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("does not disclose organization history through personal owner discovery", async () => {
|
|
200
|
+
const f = fixture();
|
|
201
|
+
await f.t.mutation(f.component.core.mutations.upsertAccount, {
|
|
202
|
+
stripeAccountId: "acct_org",
|
|
203
|
+
userId: "original",
|
|
204
|
+
orgId: "org_private",
|
|
205
|
+
appliedConfigurations: [],
|
|
206
|
+
});
|
|
207
|
+
await closeAccount(f.stripe, f.component, f.ctx, {
|
|
208
|
+
stripeAccountId: "acct_org",
|
|
209
|
+
});
|
|
210
|
+
expect(
|
|
211
|
+
(
|
|
212
|
+
await f.t.query(
|
|
213
|
+
f.component.accountClosure.queries.listClosedAccountsByUserId,
|
|
214
|
+
{
|
|
215
|
+
userId: "original",
|
|
216
|
+
paginationOpts: { numItems: 10, cursor: null },
|
|
217
|
+
},
|
|
218
|
+
)
|
|
219
|
+
).page,
|
|
220
|
+
).toEqual([]);
|
|
221
|
+
expect(
|
|
222
|
+
(
|
|
223
|
+
await f.t.query(
|
|
224
|
+
f.component.accountClosure.queries.getClosedAccountByStripeId,
|
|
225
|
+
{ stripeAccountId: "acct_org" },
|
|
226
|
+
)
|
|
227
|
+
)?.orgId,
|
|
228
|
+
).toBe("org_private");
|
|
229
|
+
});
|
|
230
|
+
it("preserves payout rows and original account references for historical reads", async () => {
|
|
231
|
+
const f = fixture();
|
|
232
|
+
const accountId = "acct_financial_history";
|
|
233
|
+
await f.t.mutation(f.component.core.mutations.upsertAccount, {
|
|
234
|
+
stripeAccountId: accountId,
|
|
235
|
+
userId: "original",
|
|
236
|
+
appliedConfigurations: [],
|
|
237
|
+
});
|
|
238
|
+
await f.t.mutation(f.component.connect.mutations.upsertPayout, {
|
|
239
|
+
stripePayoutId: "po_retained",
|
|
240
|
+
accountId,
|
|
241
|
+
amount: 1200,
|
|
242
|
+
currency: "usd",
|
|
243
|
+
status: "paid",
|
|
244
|
+
});
|
|
245
|
+
const original = await f.t.query(
|
|
246
|
+
f.component.connect.queries.getPayoutByStripeId,
|
|
247
|
+
{ stripePayoutId: "po_retained" },
|
|
248
|
+
);
|
|
249
|
+
await closeAccount(f.stripe, f.component, f.ctx, {
|
|
250
|
+
stripeAccountId: accountId,
|
|
251
|
+
});
|
|
252
|
+
const owner = await f.client.getClosedAccountByStripeId(f.ctx, {
|
|
253
|
+
stripeAccountId: accountId,
|
|
254
|
+
});
|
|
255
|
+
expect(owner?.userId).toBe("original");
|
|
256
|
+
expect(owner?.orgId).toBeUndefined();
|
|
257
|
+
expect(
|
|
258
|
+
await f.t.query(f.component.connect.queries.listPayouts, {
|
|
259
|
+
accountId: owner!.stripeAccountId,
|
|
260
|
+
}),
|
|
261
|
+
).toEqual([original]);
|
|
262
|
+
expect(
|
|
263
|
+
await f.t.query(f.component.connect.queries.getPayoutByStripeId, {
|
|
264
|
+
stripePayoutId: "po_retained",
|
|
265
|
+
}),
|
|
266
|
+
).toEqual(original);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("paginates personal closed history without unrelated users or organization rows", async () => {
|
|
270
|
+
const f = fixture();
|
|
271
|
+
for (const [stripeAccountId, userId, orgId] of [
|
|
272
|
+
["acct_p1", "original", undefined],
|
|
273
|
+
["acct_org_private", "original", "org_private"],
|
|
274
|
+
["acct_p2", "original", undefined],
|
|
275
|
+
["acct_other", "other", undefined],
|
|
276
|
+
]) {
|
|
277
|
+
await f.t.mutation(f.component.core.mutations.upsertAccount, {
|
|
278
|
+
stripeAccountId: stripeAccountId!,
|
|
279
|
+
userId: userId!,
|
|
280
|
+
orgId,
|
|
281
|
+
appliedConfigurations: [],
|
|
282
|
+
});
|
|
283
|
+
await closeAccount(f.stripe, f.component, f.ctx, {
|
|
284
|
+
stripeAccountId: stripeAccountId!,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
const first = await f.t.query(
|
|
288
|
+
f.component.accountClosure.queries.listClosedAccountsByUserId,
|
|
289
|
+
{ userId: "original", paginationOpts: { numItems: 1, cursor: null } },
|
|
290
|
+
);
|
|
291
|
+
const second = await f.t.query(
|
|
292
|
+
f.component.accountClosure.queries.listClosedAccountsByUserId,
|
|
293
|
+
{
|
|
294
|
+
userId: "original",
|
|
295
|
+
paginationOpts: { numItems: 1, cursor: first.continueCursor },
|
|
296
|
+
},
|
|
297
|
+
);
|
|
298
|
+
expect(
|
|
299
|
+
[...first.page, ...second.page].map((row) => row.stripeAccountId).sort(),
|
|
300
|
+
).toEqual(["acct_p1", "acct_p2"]);
|
|
301
|
+
expect(first.isDone).toBe(false);
|
|
302
|
+
const end = await f.client.listClosedAccountsByUserId(f.ctx, {
|
|
303
|
+
userId: "original",
|
|
304
|
+
paginationOpts: { numItems: 1, cursor: second.continueCursor },
|
|
305
|
+
});
|
|
306
|
+
expect(end.page).toEqual([]);
|
|
307
|
+
expect(end.isDone).toBe(true);
|
|
308
|
+
for (const numItems of [0, 101, 1.5]) {
|
|
309
|
+
await expect(
|
|
310
|
+
f.client.listClosedAccountsByUserId(f.ctx, {
|
|
311
|
+
userId: "original",
|
|
312
|
+
paginationOpts: { numItems, cursor: null },
|
|
313
|
+
}),
|
|
314
|
+
).rejects.toThrow("between 1 and 100");
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|