@fantastic.dev/better-stripe 0.42.0 → 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +1 -1
  3. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +1022 -0
  4. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  5. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +511 -0
  6. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
  7. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +1054 -32
  8. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
  9. package/dist/client/connect/payoutSyncTestHelpers.d.ts +527 -16
  10. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  11. package/dist/client/costRecovery-invoices.d.ts +3 -2
  12. package/dist/client/costRecovery-invoices.d.ts.map +1 -1
  13. package/dist/client/costRecovery-invoices.js +10 -5
  14. package/dist/client/costRecovery-invoices.js.map +1 -1
  15. package/dist/client/costRecovery.d.ts +4 -2
  16. package/dist/client/costRecovery.d.ts.map +1 -1
  17. package/dist/client/costRecovery.js +2 -2
  18. package/dist/client/costRecovery.js.map +1 -1
  19. package/dist/client/processingCostReconciliation/client.d.ts +14 -0
  20. package/dist/client/processingCostReconciliation/client.d.ts.map +1 -0
  21. package/dist/client/processingCostReconciliation/client.js +35 -0
  22. package/dist/client/processingCostReconciliation/client.js.map +1 -0
  23. package/dist/client/processingCostReconciliation/contracts.d.ts +172 -0
  24. package/dist/client/processingCostReconciliation/contracts.d.ts.map +1 -0
  25. package/dist/client/processingCostReconciliation/contracts.js +55 -0
  26. package/dist/client/processingCostReconciliation/contracts.js.map +1 -0
  27. package/dist/client/processingCostReconciliation/invoiceFunding.d.ts +15 -0
  28. package/dist/client/processingCostReconciliation/invoiceFunding.d.ts.map +1 -0
  29. package/dist/client/processingCostReconciliation/invoiceFunding.js +195 -0
  30. package/dist/client/processingCostReconciliation/invoiceFunding.js.map +1 -0
  31. package/dist/client/processingCostReconciliation/provider.d.ts +9 -0
  32. package/dist/client/processingCostReconciliation/provider.d.ts.map +1 -0
  33. package/dist/client/processingCostReconciliation/provider.js +148 -0
  34. package/dist/client/processingCostReconciliation/provider.js.map +1 -0
  35. package/dist/client/settlement/processingCostHistory.d.ts +12 -0
  36. package/dist/client/settlement/processingCostHistory.d.ts.map +1 -0
  37. package/dist/client/settlement/processingCostHistory.js +20 -0
  38. package/dist/client/settlement/processingCostHistory.js.map +1 -0
  39. package/dist/client/settlement/processingCosts.d.ts +3 -0
  40. package/dist/client/settlement/processingCosts.d.ts.map +1 -1
  41. package/dist/client/settlement/processingCosts.js +27 -7
  42. package/dist/client/settlement/processingCosts.js.map +1 -1
  43. package/dist/component/_generated/api.d.ts +18 -0
  44. package/dist/component/_generated/api.d.ts.map +1 -1
  45. package/dist/component/_generated/api.js.map +1 -1
  46. package/dist/component/_generated/component.d.ts +515 -0
  47. package/dist/component/_generated/component.d.ts.map +1 -1
  48. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  49. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  50. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  51. package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
  52. package/dist/component/earnings/triggers.d.ts +318 -16
  53. package/dist/component/earnings/triggers.d.ts.map +1 -1
  54. package/dist/component/payoutRelease/queries.d.ts +2 -2
  55. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  56. package/dist/component/processingCostReconciliation/adoption.d.ts +29 -0
  57. package/dist/component/processingCostReconciliation/adoption.d.ts.map +1 -0
  58. package/dist/component/processingCostReconciliation/adoption.js +58 -0
  59. package/dist/component/processingCostReconciliation/adoption.js.map +1 -0
  60. package/dist/component/processingCostReconciliation/bridge.d.ts +45 -0
  61. package/dist/component/processingCostReconciliation/bridge.d.ts.map +1 -0
  62. package/dist/component/processingCostReconciliation/bridge.js +41 -0
  63. package/dist/component/processingCostReconciliation/bridge.js.map +1 -0
  64. package/dist/component/processingCostReconciliation/helpers.d.ts +327 -0
  65. package/dist/component/processingCostReconciliation/helpers.d.ts.map +1 -0
  66. package/dist/component/processingCostReconciliation/helpers.js +39 -0
  67. package/dist/component/processingCostReconciliation/helpers.js.map +1 -0
  68. package/dist/component/processingCostReconciliation/mutations.d.ts +303 -0
  69. package/dist/component/processingCostReconciliation/mutations.d.ts.map +1 -0
  70. package/dist/component/processingCostReconciliation/mutations.js +121 -0
  71. package/dist/component/processingCostReconciliation/mutations.js.map +1 -0
  72. package/dist/component/processingCostReconciliation/queries.d.ts +422 -0
  73. package/dist/component/processingCostReconciliation/queries.d.ts.map +1 -0
  74. package/dist/component/processingCostReconciliation/queries.js +19 -0
  75. package/dist/component/processingCostReconciliation/queries.js.map +1 -0
  76. package/dist/component/processingCostReconciliation/rollback.d.ts +21 -0
  77. package/dist/component/processingCostReconciliation/rollback.d.ts.map +1 -0
  78. package/dist/component/processingCostReconciliation/rollback.js +54 -0
  79. package/dist/component/processingCostReconciliation/rollback.js.map +1 -0
  80. package/dist/component/processingCostReconciliation/schema.d.ts +2460 -0
  81. package/dist/component/processingCostReconciliation/schema.d.ts.map +1 -0
  82. package/dist/component/processingCostReconciliation/schema.js +137 -0
  83. package/dist/component/processingCostReconciliation/schema.js.map +1 -0
  84. package/dist/component/processingCostReconciliation/steps.d.ts +306 -0
  85. package/dist/component/processingCostReconciliation/steps.d.ts.map +1 -0
  86. package/dist/component/processingCostReconciliation/steps.js +149 -0
  87. package/dist/component/processingCostReconciliation/steps.js.map +1 -0
  88. package/dist/component/processingCostReconciliation/validation.d.ts +13 -0
  89. package/dist/component/processingCostReconciliation/validation.d.ts.map +1 -0
  90. package/dist/component/processingCostReconciliation/validation.js +61 -0
  91. package/dist/component/processingCostReconciliation/validation.js.map +1 -0
  92. package/dist/component/processingCostReconciliation/workflow.d.ts +105 -0
  93. package/dist/component/processingCostReconciliation/workflow.d.ts.map +1 -0
  94. package/dist/component/processingCostReconciliation/workflow.js +33 -0
  95. package/dist/component/processingCostReconciliation/workflow.js.map +1 -0
  96. package/dist/component/schema.d.ts +511 -0
  97. package/dist/component/schema.js +2 -0
  98. package/dist/component/schema.js.map +1 -1
  99. package/package.json +1 -1
  100. package/src/client/costRecovery-invoices.ts +19 -4
  101. package/src/client/costRecovery.ts +4 -2
  102. package/src/client/processingCostReconciliation/client.ts +75 -0
  103. package/src/client/processingCostReconciliation/contracts.ts +176 -0
  104. package/src/client/processingCostReconciliation/invoiceFunding.ts +270 -0
  105. package/src/client/processingCostReconciliation/invoiceProvider.test.ts +353 -0
  106. package/src/client/processingCostReconciliation/provider.test.ts +324 -0
  107. package/src/client/processingCostReconciliation/provider.ts +178 -0
  108. package/src/client/settlement/processingCostHistory.ts +31 -0
  109. package/src/client/settlement/processingCosts.ts +50 -15
  110. package/src/component/_generated/api.ts +18 -0
  111. package/src/component/_generated/component.ts +570 -0
  112. package/src/component/processingCostReconciliation/adoption.test.ts +206 -0
  113. package/src/component/processingCostReconciliation/adoption.ts +77 -0
  114. package/src/component/processingCostReconciliation/bridge.ts +50 -0
  115. package/src/component/processingCostReconciliation/helpers.ts +55 -0
  116. package/src/component/processingCostReconciliation/invoice.test.ts +152 -0
  117. package/src/component/processingCostReconciliation/mutations.ts +148 -0
  118. package/src/component/processingCostReconciliation/queries.ts +18 -0
  119. package/src/component/processingCostReconciliation/rollback.ts +72 -0
  120. package/src/component/processingCostReconciliation/schema.ts +191 -0
  121. package/src/component/processingCostReconciliation/state.test.ts +407 -0
  122. package/src/component/processingCostReconciliation/steps.ts +168 -0
  123. package/src/component/processingCostReconciliation/validation.ts +79 -0
  124. package/src/component/processingCostReconciliation/workflow.test.ts +329 -0
  125. package/src/component/processingCostReconciliation/workflow.ts +50 -0
  126. package/src/component/schema.ts +2 -0
@@ -0,0 +1,58 @@
1
+ import { importOpeningClaim } from "../costRecovery/imports.js";
2
+ import { reference } from "./helpers.js";
3
+ function opening(value) {
4
+ if (value === null)
5
+ return null;
6
+ if (!value || typeof value !== "object" || Array.isArray(value))
7
+ throw new Error("Invalid opening snapshot.");
8
+ const r = value;
9
+ if (Object.keys(r).some((k) => !["operationKey", "amountDue", "collectedAmount", "revision"].includes(k)) ||
10
+ typeof r.operationKey !== "string" ||
11
+ !r.operationKey.trim() ||
12
+ ![r.amountDue, r.collectedAmount, r.revision].every((n) => typeof n === "number" && Number.isSafeInteger(n)) ||
13
+ r.revision < 0)
14
+ throw new Error("Invalid opening snapshot.");
15
+ return r;
16
+ }
17
+ /** Host verifies its historical record. Adoption and host marker share this transaction. */
18
+ export async function adopt(ctx, op, o) {
19
+ try {
20
+ const snapshot = opening(await ctx.runMutation(op.importHook, {
21
+ ...reference(op),
22
+ claimKey: op.claimKey,
23
+ expectedRevision: op.expectedRevision,
24
+ sourceChargeId: o.sourceChargeId,
25
+ sourceGross: o.gross,
26
+ sourceProcessingFee: o.originalProcessingFee,
27
+ }));
28
+ if (!snapshot) {
29
+ const current = await ctx.db
30
+ .query("recoveryClaims")
31
+ .withIndex("by_key", (q) => q.eq("claimKey", op.claimKey))
32
+ .unique();
33
+ if (current)
34
+ throw new Error("Opening hook changed the live claim.");
35
+ return null;
36
+ }
37
+ const imported = await importOpeningClaim(ctx, {
38
+ accountId: op.accountId,
39
+ scopeKey: op.scopeKey,
40
+ currency: op.currency,
41
+ claimKey: op.claimKey,
42
+ sourceChargeId: o.sourceChargeId,
43
+ sourceGross: o.gross,
44
+ sourceProcessingFee: o.originalProcessingFee,
45
+ ...snapshot,
46
+ });
47
+ if (imported.revision !== snapshot.revision ||
48
+ imported.amountDue !== snapshot.amountDue ||
49
+ imported.collectedAmount !== snapshot.collectedAmount ||
50
+ imported.reservedAmount !== 0)
51
+ throw new Error("Opening claim changed during adoption.");
52
+ return imported;
53
+ }
54
+ catch {
55
+ throw new Error("Processing-cost import failed.");
56
+ }
57
+ }
58
+ //# sourceMappingURL=adoption.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adoption.js","sourceRoot":"","sources":["../../../src/component/processingCostReconciliation/adoption.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,SAAS,OAAO,CAAC,KAAc;IAC7B,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAC7D,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,MAAM,CAAC,GAAG,KAAgC,CAAC;IAC3C,IACE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CACjB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,cAAc,EAAE,WAAW,EAAE,iBAAiB,EAAE,UAAU,CAAC,CAAC,QAAQ,CACpE,CAAC,CACF,CACJ;QACD,OAAO,CAAC,CAAC,YAAY,KAAK,QAAQ;QAClC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE;QACtB,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,CACjD,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CACxD;QACA,CAAC,CAAC,QAAmB,GAAG,CAAC;QAE1B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,OAAO,CAAY,CAAC;AACtB,CAAC;AACD,4FAA4F;AAC5F,MAAM,CAAC,KAAK,UAAU,KAAK,CACzB,GAAgB,EAChB,EAAiD,EACjD,CAA4B;IAE5B,IAAI,CAAC;QACH,MAAM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rD,QAAQ,CAAC,cAAc,KAAK,CAAC;YAE7B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC5D,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;AACH,CAAC"}
@@ -0,0 +1,45 @@
1
+ export declare const invoke: import("convex/server").RegisteredAction<"internal", {
2
+ accountId: string;
3
+ currency: string;
4
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
5
+ scopeKey: string;
6
+ version: number;
7
+ }, Promise<{
8
+ reason: "fee_pending" | "history_incomplete" | "provider_pending";
9
+ retryable: true;
10
+ status: "not_ready";
11
+ } | {
12
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
13
+ retryable: false;
14
+ status: "conflict";
15
+ } | {
16
+ reason: "currency_mismatch" | "invalid_scope" | "payment_not_payable" | "policy_invalid" | "unsupported_source";
17
+ retryable: false;
18
+ status: "rejected";
19
+ } | {
20
+ reason: "history_incomplete" | "provider_outcome_unknown";
21
+ retryable: false;
22
+ status: "unknown";
23
+ } | {
24
+ status: "ready";
25
+ value: {
26
+ currency: string;
27
+ disputeFees: number;
28
+ gross: number;
29
+ originalProcessingFee: number;
30
+ paymentIntentId: string;
31
+ principalReturned: number;
32
+ processingFee: number;
33
+ provenance: {
34
+ customerAccountId: string;
35
+ invoiceId: string;
36
+ invoicePaymentId: string;
37
+ recoveryInvoiceItemId?: string | undefined;
38
+ stripePriceId?: string | undefined;
39
+ stripeProductId?: string | undefined;
40
+ subscriptionId?: string | undefined;
41
+ };
42
+ sourceChargeId: string;
43
+ };
44
+ }>>;
45
+ //# sourceMappingURL=bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../../src/component/processingCostReconciliation/bridge.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCjB,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { anyApi } from "convex/server";
2
+ import { v } from "convex/values";
3
+ import { internalAction } from "../_generated/server.js";
4
+ import { refFields, observation, failure } from "./schema.js";
5
+ import { providerReceiptSchema } from "../../client/processingCostReconciliation/contracts.js";
6
+ import { same } from "../recoveryWorkflow/helpers.js";
7
+ const outcome = v.union(v.object({ status: v.literal("ready"), value: observation }), failure);
8
+ const unknown = {
9
+ status: "unknown",
10
+ reason: "provider_outcome_unknown",
11
+ retryable: false,
12
+ };
13
+ export const invoke = internalAction({
14
+ args: refFields,
15
+ returns: outcome,
16
+ handler: async (ctx, args) => {
17
+ try {
18
+ const op = await ctx.runQuery(anyApi.processingCostReconciliation.queries.saved, args);
19
+ if (op.result)
20
+ return { status: "ready", value: op.result.observation };
21
+ if (op.failure && ["conflict", "rejected"].includes(op.failure.status))
22
+ return op.failure;
23
+ await ctx.runMutation(anyApi.processingCostReconciliation.steps.begin, args);
24
+ const request = {
25
+ ...args,
26
+ providerApiVersion: op.providerApiVersion,
27
+ definitionVersion: op.definitionVersion,
28
+ };
29
+ const raw = await ctx.runAction(op.provider, request);
30
+ const parsed = providerReceiptSchema.safeParse(raw);
31
+ if (!parsed.success)
32
+ return unknown;
33
+ const { outcome, ...echo } = parsed.data;
34
+ return same(request, echo) ? outcome : unknown;
35
+ }
36
+ catch {
37
+ return unknown;
38
+ }
39
+ },
40
+ });
41
+ //# sourceMappingURL=bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../src/component/processingCostReconciliation/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAuB,MAAM,eAAe,CAAC;AAE5D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO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iB;aACxC,CAAC;YACF,MAAM,GAAG,GAAY,MAAM,GAAG,CAAC,SAAS,CACtC,EAAE,CAAC,QAAoC,EACvC,OAAO,CACR,CAAC;YACF,MAAM,MAAM,GAAG,qBAAqB,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACpD,IAAI,CAAC,MAAM,CAAC,OAAO;gBAAE,OAAO,OAAO,CAAC;YACpC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC;YACzC,OAAO,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;QACjD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,327 @@
1
+ import { type Infer } from "convex/values";
2
+ import type { Doc } from "../_generated/dataModel.js";
3
+ import type { MutationCtx, QueryCtx } from "../_generated/server.js";
4
+ import { failure } from "./schema.js";
5
+ declare const _ref: import("convex/values").VObject<{
6
+ accountId: string;
7
+ currency: string;
8
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
9
+ scopeKey: string;
10
+ version: number;
11
+ }, {
12
+ accountId: import("convex/values").VString<string, "required">;
13
+ scopeKey: import("convex/values").VString<string, "required">;
14
+ currency: import("convex/values").VString<string, "required">;
15
+ operationId: import("convex/values").VId<import("convex/values").GenericId<"processingCostReconciliationOperations">, "required">;
16
+ version: import("convex/values").VFloat64<number, "required">;
17
+ }, "required", "accountId" | "currency" | "operationId" | "scopeKey" | "version">;
18
+ export type OperationRef = Infer<typeof _ref>;
19
+ export declare const conflict: (reason: "identity_changed" | "revision_changed") => {
20
+ readonly status: "conflict";
21
+ readonly reason: "identity_changed" | "revision_changed";
22
+ readonly retryable: false;
23
+ };
24
+ export declare function reference(op: Doc<"processingCostReconciliationOperations">): OperationRef;
25
+ export declare function status(op: Doc<"processingCostReconciliationOperations">): {
26
+ status: "completed";
27
+ result: {
28
+ claim: {
29
+ _creationTime: number;
30
+ _id: import("convex/values").GenericId<"recoveryClaims">;
31
+ accountId: string;
32
+ amountDue: number;
33
+ claimKey: string;
34
+ collectedAmount: number;
35
+ currency: string;
36
+ openingCollection?: {
37
+ amountDue: number;
38
+ collectedAmount: number;
39
+ operationKey: string;
40
+ revision: number;
41
+ } | undefined;
42
+ outstanding: number;
43
+ reservedAmount: number;
44
+ revision: number;
45
+ scopeKey: string;
46
+ sign: "negative" | "positive" | "zero";
47
+ sourceChargeId: string;
48
+ sourceGross: number;
49
+ sourceProcessingFee: number;
50
+ };
51
+ deficit: {
52
+ amountDue: number;
53
+ currency: string;
54
+ disputeLiability: number;
55
+ processingLiability: number;
56
+ retainedFee: number;
57
+ };
58
+ observation: {
59
+ currency: string;
60
+ disputeFees: number;
61
+ gross: number;
62
+ originalProcessingFee: number;
63
+ paymentIntentId: string;
64
+ principalReturned: number;
65
+ processingFee: number;
66
+ provenance: {
67
+ customerAccountId: string;
68
+ invoiceId: string;
69
+ invoicePaymentId: string;
70
+ recoveryInvoiceItemId?: string | undefined;
71
+ stripePriceId?: string | undefined;
72
+ stripeProductId?: string | undefined;
73
+ subscriptionId?: string | undefined;
74
+ };
75
+ sourceChargeId: string;
76
+ };
77
+ rollbackClaim?: {
78
+ _creationTime: number;
79
+ _id: import("convex/values").GenericId<"recoveryClaims">;
80
+ accountId: string;
81
+ amountDue: number;
82
+ claimKey: string;
83
+ collectedAmount: number;
84
+ currency: string;
85
+ openingCollection?: {
86
+ amountDue: number;
87
+ collectedAmount: number;
88
+ operationKey: string;
89
+ revision: number;
90
+ } | undefined;
91
+ outstanding: number;
92
+ reservedAmount: number;
93
+ revision: number;
94
+ scopeKey: string;
95
+ sign: "negative" | "positive" | "zero";
96
+ sourceChargeId: string;
97
+ sourceGross: number;
98
+ sourceProcessingFee: number;
99
+ } | undefined;
100
+ };
101
+ accountId: string;
102
+ currency: string;
103
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
104
+ scopeKey: string;
105
+ version: number;
106
+ } | {
107
+ accountId: string;
108
+ currency: string;
109
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
110
+ reason: "fee_pending" | "history_incomplete" | "provider_pending";
111
+ retryable: true;
112
+ scopeKey: string;
113
+ status: "not_ready";
114
+ version: number;
115
+ } | {
116
+ accountId: string;
117
+ currency: string;
118
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
119
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
120
+ retryable: false;
121
+ scopeKey: string;
122
+ status: "conflict";
123
+ version: number;
124
+ } | {
125
+ accountId: string;
126
+ currency: string;
127
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
128
+ reason: "currency_mismatch" | "invalid_scope" | "payment_not_payable" | "policy_invalid" | "unsupported_source";
129
+ retryable: false;
130
+ scopeKey: string;
131
+ status: "rejected";
132
+ version: number;
133
+ } | {
134
+ accountId: string;
135
+ currency: string;
136
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
137
+ reason: "history_incomplete" | "provider_outcome_unknown";
138
+ retryable: false;
139
+ scopeKey: string;
140
+ status: "unknown";
141
+ version: number;
142
+ } | {
143
+ status: "queued" | "running";
144
+ accountId: string;
145
+ currency: string;
146
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
147
+ scopeKey: string;
148
+ version: number;
149
+ };
150
+ export declare function read(ctx: QueryCtx | MutationCtx, args: OperationRef): Promise<{
151
+ _creationTime: number;
152
+ _id: import("convex/values").GenericId<"processingCostReconciliationOperations">;
153
+ accountId: string;
154
+ claimKey: string;
155
+ currency: string;
156
+ definitionVersion: number;
157
+ expectedRevision: number;
158
+ failure?: {
159
+ reason: "fee_pending" | "history_incomplete" | "provider_pending";
160
+ retryable: true;
161
+ status: "not_ready";
162
+ } | {
163
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
164
+ retryable: false;
165
+ status: "conflict";
166
+ } | {
167
+ reason: "currency_mismatch" | "invalid_scope" | "payment_not_payable" | "policy_invalid" | "unsupported_source";
168
+ retryable: false;
169
+ status: "rejected";
170
+ } | {
171
+ reason: "history_incomplete" | "provider_outcome_unknown";
172
+ retryable: false;
173
+ status: "unknown";
174
+ } | undefined;
175
+ importHook?: string | undefined;
176
+ maxAttempts: number;
177
+ policy: {
178
+ liability: {
179
+ disputeCosts: "all" | "none";
180
+ processingCosts: "all" | "none" | "uncovered";
181
+ };
182
+ rounding: "ceil" | "floor" | "nearest";
183
+ sellingFee: number;
184
+ };
185
+ projection?: string | undefined;
186
+ provider: string;
187
+ providerApiVersion: string;
188
+ requestKey: string;
189
+ result?: {
190
+ claim: {
191
+ _creationTime: number;
192
+ _id: import("convex/values").GenericId<"recoveryClaims">;
193
+ accountId: string;
194
+ amountDue: number;
195
+ claimKey: string;
196
+ collectedAmount: number;
197
+ currency: string;
198
+ openingCollection?: {
199
+ amountDue: number;
200
+ collectedAmount: number;
201
+ operationKey: string;
202
+ revision: number;
203
+ } | undefined;
204
+ outstanding: number;
205
+ reservedAmount: number;
206
+ revision: number;
207
+ scopeKey: string;
208
+ sign: "negative" | "positive" | "zero";
209
+ sourceChargeId: string;
210
+ sourceGross: number;
211
+ sourceProcessingFee: number;
212
+ };
213
+ deficit: {
214
+ amountDue: number;
215
+ currency: string;
216
+ disputeLiability: number;
217
+ processingLiability: number;
218
+ retainedFee: number;
219
+ };
220
+ observation: {
221
+ currency: string;
222
+ disputeFees: number;
223
+ gross: number;
224
+ originalProcessingFee: number;
225
+ paymentIntentId: string;
226
+ principalReturned: number;
227
+ processingFee: number;
228
+ provenance: {
229
+ customerAccountId: string;
230
+ invoiceId: string;
231
+ invoicePaymentId: string;
232
+ recoveryInvoiceItemId?: string | undefined;
233
+ stripePriceId?: string | undefined;
234
+ stripeProductId?: string | undefined;
235
+ subscriptionId?: string | undefined;
236
+ };
237
+ sourceChargeId: string;
238
+ };
239
+ rollbackClaim?: {
240
+ _creationTime: number;
241
+ _id: import("convex/values").GenericId<"recoveryClaims">;
242
+ accountId: string;
243
+ amountDue: number;
244
+ claimKey: string;
245
+ collectedAmount: number;
246
+ currency: string;
247
+ openingCollection?: {
248
+ amountDue: number;
249
+ collectedAmount: number;
250
+ operationKey: string;
251
+ revision: number;
252
+ } | undefined;
253
+ outstanding: number;
254
+ reservedAmount: number;
255
+ revision: number;
256
+ scopeKey: string;
257
+ sign: "negative" | "positive" | "zero";
258
+ sourceChargeId: string;
259
+ sourceGross: number;
260
+ sourceProcessingFee: number;
261
+ } | undefined;
262
+ } | undefined;
263
+ retryDelayMs: number;
264
+ rollback?: {
265
+ expectedRevision: number;
266
+ groupKey: string;
267
+ } | undefined;
268
+ scopeKey: string;
269
+ source: {
270
+ customerAccountId: string;
271
+ gross: number;
272
+ invoiceId?: string | undefined;
273
+ kind: "sale";
274
+ paymentIntentId: string;
275
+ stripeAccountId?: string | undefined;
276
+ stripePriceId?: string | undefined;
277
+ stripeProductId?: string | undefined;
278
+ subscriptionId?: string | undefined;
279
+ } | {
280
+ gross: number;
281
+ groupKey: string;
282
+ kind: "invoice_recovery";
283
+ paymentIntentId: string;
284
+ };
285
+ status: "completed" | "conflict" | "queued" | "rejected" | "running" | "unknown" | "waiting";
286
+ version: number;
287
+ workflowId?: string | undefined;
288
+ }>;
289
+ export declare function setFailure(ctx: MutationCtx, op: Doc<"processingCostReconciliationOperations">, value: Infer<typeof failure>): Promise<{
290
+ accountId: string;
291
+ currency: string;
292
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
293
+ reason: "fee_pending" | "history_incomplete" | "provider_pending";
294
+ retryable: true;
295
+ scopeKey: string;
296
+ status: "not_ready";
297
+ version: number;
298
+ } | {
299
+ accountId: string;
300
+ currency: string;
301
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
302
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
303
+ retryable: false;
304
+ scopeKey: string;
305
+ status: "conflict";
306
+ version: number;
307
+ } | {
308
+ accountId: string;
309
+ currency: string;
310
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
311
+ reason: "currency_mismatch" | "invalid_scope" | "payment_not_payable" | "policy_invalid" | "unsupported_source";
312
+ retryable: false;
313
+ scopeKey: string;
314
+ status: "rejected";
315
+ version: number;
316
+ } | {
317
+ accountId: string;
318
+ currency: string;
319
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
320
+ reason: "history_incomplete" | "provider_outcome_unknown";
321
+ retryable: false;
322
+ scopeKey: string;
323
+ status: "unknown";
324
+ version: number;
325
+ }>;
326
+ export {};
327
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/component/processingCostReconciliation/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAa,OAAO,EAAE,MAAM,aAAa,CAAC;AACjD,QAAA,MAAM,IAAI;;;;;;;;;;;;iFAAsB,CAAC;AACjC,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAC9C,eAAO,MAAM,QAAQ,WAAY,kBAAkB,GAAG,kBAAkB;qBAC3D,UAAU;;;CAAsC,CAAC;AAC9D,wBAAgB,SAAS,CACvB,EAAE,EAAE,GAAG,CAAC,wCAAwC,CAAC,GAChD,YAAY,CAQd;AACD,wBAAgB,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,wCAAwC,CAAC;YAG3C,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMvC;AACD,wBAAsB,IAAI,CAAC,GAAG,EAAE,QAAQ,GAAG,WAAW,EAAE,IAAI,EAAE,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAazE;AAED,wBAAsB,UAAU,CAC9B,GAAG,EAAE,WAAW,EAChB,EAAE,EAAE,GAAG,CAAC,wCAAwC,CAAC,EACjD,KAAK,EAAE,KAAK,CAAC,OAAO,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAO7B"}
@@ -0,0 +1,39 @@
1
+ import { v } from "convex/values";
2
+ import { refFields } from "./schema.js";
3
+ const _ref = v.object(refFields);
4
+ export const conflict = (reason) => ({ status: "conflict", reason, retryable: false });
5
+ export function reference(op) {
6
+ return {
7
+ accountId: op.accountId,
8
+ scopeKey: op.scopeKey,
9
+ currency: op.currency,
10
+ operationId: op._id,
11
+ version: op.version,
12
+ };
13
+ }
14
+ export function status(op) {
15
+ const ref = reference(op);
16
+ if (op.result)
17
+ return { ...ref, status: "completed", result: op.result };
18
+ if (op.failure)
19
+ return { ...ref, ...op.failure };
20
+ return {
21
+ ...ref,
22
+ status: op.status === "queued" ? "queued" : "running",
23
+ };
24
+ }
25
+ export async function read(ctx, args) {
26
+ const op = await ctx.db.get("processingCostReconciliationOperations", args.operationId);
27
+ if (!op ||
28
+ Object.entries(reference(op)).some(([k, value]) => value !== args[k]))
29
+ throw new Error("Processing-cost operation identity does not match.");
30
+ return op;
31
+ }
32
+ export async function setFailure(ctx, op, value) {
33
+ await ctx.db.patch("processingCostReconciliationOperations", op._id, {
34
+ status: value.status === "not_ready" ? "waiting" : value.status,
35
+ failure: value,
36
+ });
37
+ return { ...reference(op), ...value };
38
+ }
39
+ //# sourceMappingURL=helpers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