@fantastic.dev/better-stripe 0.35.0 → 0.37.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 (94) hide show
  1. package/CHANGELOG.md +225 -0
  2. package/README.md +1 -1
  3. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +178 -0
  4. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  5. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +89 -0
  6. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
  7. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +178 -0
  8. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
  9. package/dist/client/connect/payoutSyncTestHelpers.d.ts +89 -0
  10. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  11. package/dist/client/operationEvidence.d.ts +37 -0
  12. package/dist/client/operationEvidence.d.ts.map +1 -0
  13. package/dist/client/operationEvidence.js +44 -0
  14. package/dist/client/operationEvidence.js.map +1 -0
  15. package/dist/client/publicTypes.d.ts +1 -0
  16. package/dist/client/publicTypes.d.ts.map +1 -1
  17. package/dist/client/readContracts.d.ts +2 -0
  18. package/dist/client/readContracts.d.ts.map +1 -1
  19. package/dist/client/readContracts.js +4 -0
  20. package/dist/client/readContracts.js.map +1 -1
  21. package/dist/component/_generated/component.d.ts +181 -0
  22. package/dist/component/_generated/component.d.ts.map +1 -1
  23. package/dist/component/earnings/pairedAdjustment.d.ts +12 -0
  24. package/dist/component/earnings/pairedAdjustment.d.ts.map +1 -0
  25. package/dist/component/earnings/pairedAdjustment.js +46 -0
  26. package/dist/component/earnings/pairedAdjustment.js.map +1 -0
  27. package/dist/component/earnings/triggers.d.ts +120 -0
  28. package/dist/component/earnings/triggers.d.ts.map +1 -1
  29. package/dist/component/earnings/triggers.js +10 -2
  30. package/dist/component/earnings/triggers.js.map +1 -1
  31. package/dist/component/operationEvidence/canonical.d.ts +4 -0
  32. package/dist/component/operationEvidence/canonical.d.ts.map +1 -0
  33. package/dist/component/operationEvidence/canonical.js +8 -0
  34. package/dist/component/operationEvidence/canonical.js.map +1 -0
  35. package/dist/component/operationEvidence/helpers.d.ts +87 -0
  36. package/dist/component/operationEvidence/helpers.d.ts.map +1 -0
  37. package/dist/component/operationEvidence/helpers.js +49 -0
  38. package/dist/component/operationEvidence/helpers.js.map +1 -0
  39. package/dist/component/operationEvidence/maintenance.d.ts +88 -0
  40. package/dist/component/operationEvidence/maintenance.d.ts.map +1 -0
  41. package/dist/component/operationEvidence/maintenance.js +59 -0
  42. package/dist/component/operationEvidence/maintenance.js.map +1 -0
  43. package/dist/component/operationEvidence/mutations.d.ts +97 -0
  44. package/dist/component/operationEvidence/mutations.d.ts.map +1 -0
  45. package/dist/component/operationEvidence/mutations.js +14 -0
  46. package/dist/component/operationEvidence/mutations.js.map +1 -0
  47. package/dist/component/operationEvidence/queries.d.ts +205 -0
  48. package/dist/component/operationEvidence/queries.d.ts.map +1 -0
  49. package/dist/component/operationEvidence/queries.js +75 -0
  50. package/dist/component/operationEvidence/queries.js.map +1 -0
  51. package/dist/component/operationEvidence/schema.d.ts +536 -0
  52. package/dist/component/operationEvidence/schema.d.ts.map +1 -0
  53. package/dist/component/operationEvidence/schema.js +53 -0
  54. package/dist/component/operationEvidence/schema.js.map +1 -0
  55. package/dist/component/payoutRelease/queries.d.ts +2 -2
  56. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  57. package/dist/component/refundHistory/commandEvidence.d.ts +1 -1
  58. package/dist/component/refundHistory/commandEvidence.d.ts.map +1 -1
  59. package/dist/component/refundHistory/commandEvidence.js +6 -2
  60. package/dist/component/refundHistory/commandEvidence.js.map +1 -1
  61. package/dist/component/refundHistory/originalSeller.d.ts +5 -0
  62. package/dist/component/refundHistory/originalSeller.d.ts.map +1 -0
  63. package/dist/component/refundHistory/originalSeller.js +35 -0
  64. package/dist/component/refundHistory/originalSeller.js.map +1 -0
  65. package/dist/component/refundHistory/queries.d.ts +1 -1
  66. package/dist/component/schema.d.ts +89 -0
  67. package/dist/component/schema.js +3 -0
  68. package/dist/component/schema.js.map +1 -1
  69. package/docs/financial-observations.md +85 -0
  70. package/docs/refund-command-evidence.md +6 -0
  71. package/package.json +1 -1
  72. package/src/client/operationEvidence.test.ts +110 -0
  73. package/src/client/operationEvidence.ts +92 -0
  74. package/src/client/publicTypes.ts +8 -0
  75. package/src/client/readContracts.ts +4 -0
  76. package/src/component/_generated/api.ts +10 -0
  77. package/src/component/_generated/component.ts +207 -0
  78. package/src/component/earnings/paired-adjustment.test.ts +258 -0
  79. package/src/component/earnings/pairedAdjustment.ts +77 -0
  80. package/src/component/earnings/triggers.ts +14 -10
  81. package/src/component/operationEvidence/canonical.ts +10 -0
  82. package/src/component/operationEvidence/helpers.ts +65 -0
  83. package/src/component/operationEvidence/integrity.test.ts +257 -0
  84. package/src/component/operationEvidence/maintenance.test.ts +152 -0
  85. package/src/component/operationEvidence/maintenance.ts +89 -0
  86. package/src/component/operationEvidence/mutations.ts +14 -0
  87. package/src/component/operationEvidence/queries.ts +108 -0
  88. package/src/component/operationEvidence/reads.test.ts +140 -0
  89. package/src/component/operationEvidence/schema.ts +62 -0
  90. package/src/component/refundHistory/commandEvidence.ts +7 -2
  91. package/src/component/refundHistory/original-seller-boundaries.test.ts +138 -0
  92. package/src/component/refundHistory/original-seller.test.ts +175 -0
  93. package/src/component/refundHistory/originalSeller.ts +48 -0
  94. package/src/component/schema.ts +6 -0
@@ -0,0 +1,12 @@
1
+ import type { MutationCtx } from "../_generated/server.js";
2
+ export type Contribution = {
3
+ accountId: string;
4
+ currency: string;
5
+ gross: number;
6
+ reversed: number;
7
+ paidOut: number;
8
+ count: number;
9
+ };
10
+ /** Same bucket only: preserve subtract/reset/reapply validation with one read. */
11
+ export declare function replaceContribution(ctx: MutationCtx, previous: Contribution, next: Contribution): Promise<void>;
12
+ //# sourceMappingURL=pairedAdjustment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pairedAdjustment.d.ts","sourceRoot":"","sources":["../../../src/component/earnings/pairedAdjustment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAG3D,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAuBF,kFAAkF;AAClF,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,YAAY,iBAuCnB"}
@@ -0,0 +1,46 @@
1
+ import { addSummaryAmounts } from "./arithmetic.js";
2
+ function apply(row, contribution, sign) {
3
+ const totals = {
4
+ gross: addSummaryAmounts(row?.gross ?? 0, sign * contribution.gross),
5
+ reversed: addSummaryAmounts(row?.reversed ?? 0, sign * contribution.reversed),
6
+ paidOut: addSummaryAmounts(row?.paidOut ?? 0, sign * contribution.paidOut),
7
+ count: addSummaryAmounts(row?.count ?? 0, sign * contribution.count),
8
+ };
9
+ addSummaryAmounts(totals.gross, -totals.reversed);
10
+ return totals;
11
+ }
12
+ /** Same bucket only: preserve subtract/reset/reapply validation with one read. */
13
+ export async function replaceContribution(ctx, previous, next) {
14
+ if (previous.accountId !== next.accountId ||
15
+ previous.currency !== next.currency)
16
+ throw new Error("Paired contributions require the same currency bucket");
17
+ const row = await ctx.db
18
+ .query("currencyTotals")
19
+ .withIndex("by_account_kind_currency", (q) => q
20
+ .eq("accountId", previous.accountId)
21
+ .eq("kind", "earnings")
22
+ .eq("currency", previous.currency))
23
+ .unique();
24
+ const removed = apply(row, previous, -1);
25
+ // The existing subtract path deletes a zero-count stored row before reapply.
26
+ const hasIntermediateRow = !row || removed.count !== 0;
27
+ const totals = apply(hasIntermediateRow ? removed : null, next, 1);
28
+ if (hasIntermediateRow && totals.count === 0) {
29
+ if (row)
30
+ await ctx.db.delete("currencyTotals", row._id);
31
+ return;
32
+ }
33
+ if (row &&
34
+ ["gross", "reversed", "paidOut", "count"].every((field) => Object.is(row[field], totals[field])))
35
+ return;
36
+ if (row)
37
+ await ctx.db.patch("currencyTotals", row._id, totals);
38
+ else
39
+ await ctx.db.insert("currencyTotals", {
40
+ accountId: next.accountId,
41
+ currency: next.currency,
42
+ kind: "earnings",
43
+ ...totals,
44
+ });
45
+ }
46
+ //# sourceMappingURL=pairedAdjustment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pairedAdjustment.js","sourceRoot":"","sources":["../../../src/component/earnings/pairedAdjustment.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAUpD,SAAS,KAAK,CACZ,GAKQ,EACR,YAA0B,EAC1B,IAAY;IAEZ,MAAM,MAAM,GAAG;QACb,KAAK,EAAE,iBAAiB,CAAC,GAAG,EAAE,KAAK,IAAI,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC;QACpE,QAAQ,EAAE,iBAAiB,CACzB,GAAG,EAAE,QAAQ,IAAI,CAAC,EAClB,IAAI,GAAG,YAAY,CAAC,QAAQ,CAC7B;QACD,OAAO,EAAE,iBAAiB,CAAC,GAAG,EAAE,OAAO,IAAI,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC,OAAO,CAAC;QAC1E,KAAK,EAAE,iBAAiB,CAAC,GAAG,EAAE,KAAK,IAAI,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC;KACrE,CAAC;IACF,iBAAiB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClD,OAAO,MAAM,CAAC;AAChB,CAAC;AACD,kFAAkF;AAClF,MAAM,CAAC,KAAK,UA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,MAAM,CAAC,KAAK,CAAC,CAAC,CACrC;QAED,OAAO;IACT,IAAI,GAAG;QAAE,MAAM,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;;QAE7D,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,gBAAgB,EAAE;YACpC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,UAAU;YAChB,GAAG,MAAM;SACV,CAAC,CAAC;AACP,CAAC"}
@@ -630,6 +630,66 @@ export declare const mutation: import("convex-helpers/server/customFunctions").C
630
630
  searchIndexes: {};
631
631
  vectorIndexes: {};
632
632
  };
633
+ operationEvidenceHeaders: {
634
+ document: {
635
+ _creationTime: number;
636
+ _id: import("convex/values").GenericId<"operationEvidenceHeaders">;
637
+ firstObservedAt: number;
638
+ generation: number;
639
+ isContradictory: boolean;
640
+ latestFingerprint: string;
641
+ latestPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
642
+ operationDigest: string;
643
+ originalFingerprint: string;
644
+ originalIdentityFingerprint: string;
645
+ originalPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
646
+ producer: "trusted_host_maintenance";
647
+ producerVersion: 1;
648
+ sourceChargeDigest: string;
649
+ sourceCreatedAt: number;
650
+ sourceId: import("convex/values").GenericId<"transferReversalOps">;
651
+ };
652
+ fieldPaths: "_id" | ("_creationTime" | "firstObservedAt" | "generation" | "isContradictory" | "latestFingerprint" | "latestPayloadId" | "operationDigest" | "originalFingerprint" | "originalIdentityFingerprint" | "originalPayloadId" | "producer" | "producerVersion" | "sourceChargeDigest" | "sourceCreatedAt" | "sourceId");
653
+ indexes: {
654
+ by_id: ["_id"];
655
+ by_creation_time: ["_creationTime"];
656
+ by_operation_digest: ["operationDigest", "_creationTime"];
657
+ by_source_charge_digest: ["sourceChargeDigest", "_creationTime"];
658
+ by_source_id: ["sourceId", "_creationTime"];
659
+ };
660
+ searchIndexes: {};
661
+ vectorIndexes: {};
662
+ };
663
+ operationEvidencePayloads: {
664
+ document: {
665
+ _creationTime: number;
666
+ _id: import("convex/values").GenericId<"operationEvidencePayloads">;
667
+ commissionExposure?: {
668
+ chargeAmount: number;
669
+ disputeId?: string | undefined;
670
+ disputeState?: "lost" | "open" | "won" | undefined;
671
+ finalized: boolean;
672
+ kind: "dispute" | "refund";
673
+ principal: number;
674
+ refundId?: string | undefined;
675
+ refundedPrincipal?: number | undefined;
676
+ } | undefined;
677
+ operationId: string;
678
+ slices: {
679
+ from: number;
680
+ stripeTransferId: string;
681
+ to: number;
682
+ }[];
683
+ sourceChargeId: string;
684
+ };
685
+ fieldPaths: "_id" | ("_creationTime" | "commissionExposure" | "commissionExposure.chargeAmount" | "commissionExposure.disputeId" | "commissionExposure.disputeState" | "commissionExposure.finalized" | "commissionExposure.kind" | "commissionExposure.principal" | "commissionExposure.refundId" | "commissionExposure.refundedPrincipal" | "operationId" | "slices" | "sourceChargeId");
686
+ indexes: {
687
+ by_id: ["_id"];
688
+ by_creation_time: ["_creationTime"];
689
+ };
690
+ searchIndexes: {};
691
+ vectorIndexes: {};
692
+ };
633
693
  payments: {
634
694
  document: {
635
695
  _creationTime: number;
@@ -2148,6 +2208,66 @@ export declare const mutation: import("convex-helpers/server/customFunctions").C
2148
2208
  searchIndexes: {};
2149
2209
  vectorIndexes: {};
2150
2210
  };
2211
+ operationEvidenceHeaders: {
2212
+ document: {
2213
+ _creationTime: number;
2214
+ _id: import("convex/values").GenericId<"operationEvidenceHeaders">;
2215
+ firstObservedAt: number;
2216
+ generation: number;
2217
+ isContradictory: boolean;
2218
+ latestFingerprint: string;
2219
+ latestPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
2220
+ operationDigest: string;
2221
+ originalFingerprint: string;
2222
+ originalIdentityFingerprint: string;
2223
+ originalPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
2224
+ producer: "trusted_host_maintenance";
2225
+ producerVersion: 1;
2226
+ sourceChargeDigest: string;
2227
+ sourceCreatedAt: number;
2228
+ sourceId: import("convex/values").GenericId<"transferReversalOps">;
2229
+ };
2230
+ fieldPaths: "_id" | ("_creationTime" | "firstObservedAt" | "generation" | "isContradictory" | "latestFingerprint" | "latestPayloadId" | "operationDigest" | "originalFingerprint" | "originalIdentityFingerprint" | "originalPayloadId" | "producer" | "producerVersion" | "sourceChargeDigest" | "sourceCreatedAt" | "sourceId");
2231
+ indexes: {
2232
+ by_id: ["_id"];
2233
+ by_creation_time: ["_creationTime"];
2234
+ by_operation_digest: ["operationDigest", "_creationTime"];
2235
+ by_source_charge_digest: ["sourceChargeDigest", "_creationTime"];
2236
+ by_source_id: ["sourceId", "_creationTime"];
2237
+ };
2238
+ searchIndexes: {};
2239
+ vectorIndexes: {};
2240
+ };
2241
+ operationEvidencePayloads: {
2242
+ document: {
2243
+ _creationTime: number;
2244
+ _id: import("convex/values").GenericId<"operationEvidencePayloads">;
2245
+ commissionExposure?: {
2246
+ chargeAmount: number;
2247
+ disputeId?: string | undefined;
2248
+ disputeState?: "lost" | "open" | "won" | undefined;
2249
+ finalized: boolean;
2250
+ kind: "dispute" | "refund";
2251
+ principal: number;
2252
+ refundId?: string | undefined;
2253
+ refundedPrincipal?: number | undefined;
2254
+ } | undefined;
2255
+ operationId: string;
2256
+ slices: {
2257
+ from: number;
2258
+ stripeTransferId: string;
2259
+ to: number;
2260
+ }[];
2261
+ sourceChargeId: string;
2262
+ };
2263
+ fieldPaths: "_id" | ("_creationTime" | "commissionExposure" | "commissionExposure.chargeAmount" | "commissionExposure.disputeId" | "commissionExposure.disputeState" | "commissionExposure.finalized" | "commissionExposure.kind" | "commissionExposure.principal" | "commissionExposure.refundId" | "commissionExposure.refundedPrincipal" | "operationId" | "slices" | "sourceChargeId");
2264
+ indexes: {
2265
+ by_id: ["_id"];
2266
+ by_creation_time: ["_creationTime"];
2267
+ };
2268
+ searchIndexes: {};
2269
+ vectorIndexes: {};
2270
+ };
2151
2271
  payments: {
2152
2272
  document: {
2153
2273
  _creationTime: number;
@@ -1 +1 @@
1
- {"version":3,"file":"triggers.d.ts","sourceRoot":"","sources":["../../../src/component/earnings/triggers.ts"],"names":[],"mappings":"AAyGA,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAA0D,CAAC"}
@@ -3,6 +3,7 @@ import { registerPayoutRevisions } from "../payoutSnapshots/revisions.js";
3
3
  import { Triggers } from "convex-helpers/server/triggers";
4
4
  import { customCtx, customMutation, } from "convex-helpers/server/customFunctions";
5
5
  import { addSummaryAmounts } from "./arithmetic.js";
6
+ import { replaceContribution } from "./pairedAdjustment.js";
6
7
  import { mutation as rawMutation, } from "../_generated/server.js";
7
8
  async function adjust(ctx, kind, value, sign) {
8
9
  const row = await ctx.db
@@ -43,10 +44,17 @@ triggers.register("transfers", async (ctx, change) => {
43
44
  paidOut: 0,
44
45
  count: 1,
45
46
  });
46
- if (change.oldDoc?.totalsRecorded)
47
+ const canPair = change.oldDoc?.totalsRecorded &&
48
+ change.newDoc &&
49
+ change.oldDoc.destinationAccountId === change.newDoc.destinationAccountId &&
50
+ change.oldDoc.currency === change.newDoc.currency;
51
+ if (canPair)
52
+ await replaceContribution(ctx, contribution(change.oldDoc), contribution(change.newDoc));
53
+ else if (change.oldDoc?.totalsRecorded)
47
54
  await adjust(ctx, "earnings", contribution(change.oldDoc), -1);
48
55
  if (change.newDoc) {
49
- await adjust(ctx, "earnings", contribution(change.newDoc), 1);
56
+ if (!canPair)
57
+ await adjust(ctx, "earnings", contribution(change.newDoc), 1);
50
58
  if (!change.newDoc.totalsRecorded) {
51
59
  await ctx.innerDb.patch("transfers", change.id, { totalsRecorded: true });
52
60
  // Frontier producers own bounded batch observation, including oversized release deferral.
@@ -1 +1 @@
1
- {"version":3,"file":"triggers.js","sourceRoot":"","sources":["../../../src/component/earnings/triggers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EACL,SAAS,EACT,cAAc,GACf,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EACL,QAAQ,IAAI,WAAW,GAExB,MAAM,yBAAyB,CAAC;AAUjC,KAAK,UAAU,MAAM,CACnB,GAAgB,EAChB,IAA4B,EAC5B,KAAmB,EACnB,IAAY;IAEZ,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE;SACrB,KAAK,CAAC,gBAAgB,CAAC;SACvB,SAAS,CAAC,0BAA0B,EAAE,CAAC,CAAC,EAAE,EAAE,CAC3C,CAAC;SACE,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC;SAChC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC;SAChB,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,CAClC;SACA,MAAM,EAAE,CAAC;IACZ,MAAM,MAAM,GAAG;QACb,KAAK,EAAE,iBAAiB,CAAC,GAAG,EAAE,KAAK,IAAI,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC;QAC7D,QAAQ,EAAE,iBAAiB,CAAC,GAAG,EAAE,QAAQ,IAAI,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC;QACtE,OAAO,EAAE,iBAAiB,CAAC,GAAG,EAAE,OAAO,IAAI,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC;QACnE,KAAK,EAAE,iBA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AM,CAAC,EAAE,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC,CAAC,CAAC;AACH,uBAAuB,CAAC,QAAQ,CAAC,CAAC;AAClC,MAAM,CAAC,MAAM,QAAQ,GAAG,cAAc,CAAC,WAAW,EAAE,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type Value } from "convex/values";
2
+ /** Convex encoding preserves special floats and recursively sorts object keys. */
3
+ export declare function canonicalFingerprint(value: Value): Promise<string>;
4
+ //# sourceMappingURL=canonical.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../../../src/component/operationEvidence/canonical.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AAEzD,kFAAkF;AAClF,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,KAAK,mBAMtD"}
@@ -0,0 +1,8 @@
1
+ import { convexToJson } from "convex/values";
2
+ /** Convex encoding preserves special floats and recursively sorts object keys. */
3
+ export async function canonicalFingerprint(value) {
4
+ const bytes = new TextEncoder().encode(JSON.stringify(convexToJson(value)));
5
+ const hash = await crypto.subtle.digest("SHA-256", bytes);
6
+ return Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join("");
7
+ }
8
+ //# sourceMappingURL=canonical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.js","sourceRoot":"","sources":["../../../src/component/operationEvidence/canonical.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAc,MAAM,eAAe,CAAC;AAEzD,kFAAkF;AAClF,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,KAAY;IACrD,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5E,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC1D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAC/C,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CACnC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,87 @@
1
+ import type { Doc, Id } from "../_generated/dataModel.js";
2
+ import type { QueryCtx } from "../_generated/server.js";
3
+ export declare const operationEvidenceScope = "operation-evidence-maintenance-v1";
4
+ export declare function readState(ctx: QueryCtx): Promise<{
5
+ coverage: "unknown";
6
+ evidenceGeneration: number | null;
7
+ }>;
8
+ export declare function bodyOf(row: Doc<"transferReversalOps"> | Doc<"operationEvidencePayloads">): {
9
+ commissionExposure?: {
10
+ chargeAmount: number;
11
+ disputeId?: string | undefined;
12
+ disputeState?: "lost" | "open" | "won" | undefined;
13
+ finalized: boolean;
14
+ kind: "dispute" | "refund";
15
+ principal: number;
16
+ refundId?: string | undefined;
17
+ refundedPrincipal?: number | undefined;
18
+ } | undefined;
19
+ operationId: string;
20
+ slices: {
21
+ from: number;
22
+ stripeTransferId: string;
23
+ to: number;
24
+ }[];
25
+ sourceChargeId: string;
26
+ } | {
27
+ commissionExposure?: {
28
+ chargeAmount: number;
29
+ disputeId?: string | undefined;
30
+ disputeState?: "lost" | "open" | "won" | undefined;
31
+ finalized: boolean;
32
+ kind: "dispute" | "refund";
33
+ principal: number;
34
+ refundId?: string | undefined;
35
+ refundedPrincipal?: number | undefined;
36
+ } | undefined;
37
+ operationId: string;
38
+ slices: {
39
+ from: number;
40
+ stripeTransferId: string;
41
+ to: number;
42
+ }[];
43
+ sourceChargeId: string;
44
+ };
45
+ export declare function sourceFingerprint(body: ReturnType<typeof bodyOf>): Promise<string>;
46
+ export declare function identityFingerprint(body: ReturnType<typeof bodyOf>): Promise<string>;
47
+ export declare function selectorDigest(selector: "operationId" | "sourceChargeId", value: string): Promise<string>;
48
+ export declare function isValidHeader(header: Doc<"operationEvidenceHeaders">): boolean;
49
+ export declare function uniqueSourceHeader(ctx: QueryCtx, sourceId: Id<"transferReversalOps">): Promise<{
50
+ headers: {
51
+ _creationTime: number;
52
+ _id: import("convex/values").GenericId<"operationEvidenceHeaders">;
53
+ firstObservedAt: number;
54
+ generation: number;
55
+ isContradictory: boolean;
56
+ latestFingerprint: string;
57
+ latestPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
58
+ operationDigest: string;
59
+ originalFingerprint: string;
60
+ originalIdentityFingerprint: string;
61
+ originalPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
62
+ producer: "trusted_host_maintenance";
63
+ producerVersion: 1;
64
+ sourceChargeDigest: string;
65
+ sourceCreatedAt: number;
66
+ sourceId: import("convex/values").GenericId<"transferReversalOps">;
67
+ }[];
68
+ header: {
69
+ _creationTime: number;
70
+ _id: import("convex/values").GenericId<"operationEvidenceHeaders">;
71
+ firstObservedAt: number;
72
+ generation: number;
73
+ isContradictory: boolean;
74
+ latestFingerprint: string;
75
+ latestPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
76
+ operationDigest: string;
77
+ originalFingerprint: string;
78
+ originalIdentityFingerprint: string;
79
+ originalPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
80
+ producer: "trusted_host_maintenance";
81
+ producerVersion: 1;
82
+ sourceChargeDigest: string;
83
+ sourceCreatedAt: number;
84
+ sourceId: import("convex/values").GenericId<"transferReversalOps">;
85
+ } | null;
86
+ }>;
87
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/component/operationEvidence/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAIxD,eAAO,MAAM,sBAAsB,sCAAsC,CAAC;AAC1E,wBAAsB,SAAS,CAAC,GAAG,EAAE,QAAQ;cAE/B,SAAS;;GAMtB;AACD,wBAAgB,MAAM,CACpB,GAAG,EAAE,GAAG,CAAC,qBAAqB,CAAC,GAAG,GAAG,CAAC,2BAA2B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMnE;AACD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,mBAEhE;AACD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,mBAOlE;AACD,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,aAAa,GAAG,gBAAgB,EAC1C,KAAK,EAAE,MAAM,mBAOd;AACD,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,0BAA0B,CAAC,WAMpE;AACD,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,QAAQ,EACb,QAAQ,EAAE,EAAE,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAWpC"}
@@ -0,0 +1,49 @@
1
+ import { observationGeneration } from "../financialObservations/generations.js";
2
+ import { canonicalFingerprint } from "./canonical.js";
3
+ export const operationEvidenceScope = "operation-evidence-maintenance-v1";
4
+ export async function readState(ctx) {
5
+ return {
6
+ coverage: "unknown",
7
+ evidenceGeneration: await observationGeneration(ctx, operationEvidenceScope),
8
+ };
9
+ }
10
+ export function bodyOf(row) {
11
+ const { _id, _creationTime, ...fields } = row;
12
+ void _id;
13
+ void _creationTime;
14
+ return fields;
15
+ }
16
+ export function sourceFingerprint(body) {
17
+ return canonicalFingerprint({ domain: "operation-evidence-source-v1", body });
18
+ }
19
+ export function identityFingerprint(body) {
20
+ return canonicalFingerprint({
21
+ domain: "operation-evidence-identity-v1",
22
+ operationId: body.operationId,
23
+ sourceChargeId: body.sourceChargeId,
24
+ slices: body.slices,
25
+ });
26
+ }
27
+ export function selectorDigest(selector, value) {
28
+ return canonicalFingerprint({
29
+ domain: "operation-evidence-selector-v1",
30
+ selector,
31
+ value,
32
+ });
33
+ }
34
+ export function isValidHeader(header) {
35
+ return (Number.isSafeInteger(header.generation) &&
36
+ header.generation >= 1 &&
37
+ header.originalPayloadId !== header.latestPayloadId);
38
+ }
39
+ export async function uniqueSourceHeader(ctx, sourceId) {
40
+ const headers = await ctx.db
41
+ .query("operationEvidenceHeaders")
42
+ .withIndex("by_source_id", (q) => q.eq("sourceId", sourceId))
43
+ .take(2);
44
+ return {
45
+ headers,
46
+ header: headers.length === 1 && isValidHeader(headers[0]) ? headers[0] : null,
47
+ };
48
+ }
49
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/component/operationEvidence/helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,mCAAmC,CAAC;AAC1E,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAa;IAC3C,OAAO;QACL,QAAQ,EAAE,SAAkB;QAC5B,kBAAkB,EAAE,MAAM,qBAAqB,CAC7C,GAAG,EACH,sBAAsB,CACvB;KACF,CAAC;AACJ,CAAC;AACD,MAAM,UAAU,MAAM,CACpB,GAAkE;IAElE,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,MAAM,EAAE,GAAG,GAAG,CAAC;IAC9C,KAAK,GAAG,CAAC;IACT,KAAK,aAAa,CAAC;IACnB,OAAO,MAAM,CAAC;AAChB,CAAC;AACD,MAAM,UAAU,iB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1,88 @@
1
+ import type { Id } from "../_generated/dataModel.js";
2
+ import type { MutationCtx } from "../_generated/server.js";
3
+ /** Explicit evidence maintenance only. Never called from a financial writer here. */
4
+ export declare function captureSource(ctx: MutationCtx, sourceId: Id<"transferReversalOps">): Promise<{
5
+ status: "unavailable";
6
+ header: null;
7
+ } | {
8
+ status: "source_unavailable";
9
+ header: {
10
+ _creationTime: number;
11
+ _id: import("convex/values").GenericId<"operationEvidenceHeaders">;
12
+ firstObservedAt: number;
13
+ generation: number;
14
+ isContradictory: boolean;
15
+ latestFingerprint: string;
16
+ latestPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
17
+ operationDigest: string;
18
+ originalFingerprint: string;
19
+ originalIdentityFingerprint: string;
20
+ originalPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
21
+ producer: "trusted_host_maintenance";
22
+ producerVersion: 1;
23
+ sourceChargeDigest: string;
24
+ sourceCreatedAt: number;
25
+ sourceId: import("convex/values").GenericId<"transferReversalOps">;
26
+ } | null;
27
+ } | {
28
+ status: "unchanged";
29
+ header: {
30
+ _creationTime: number;
31
+ _id: import("convex/values").GenericId<"operationEvidenceHeaders">;
32
+ firstObservedAt: number;
33
+ generation: number;
34
+ isContradictory: boolean;
35
+ latestFingerprint: string;
36
+ latestPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
37
+ operationDigest: string;
38
+ originalFingerprint: string;
39
+ originalIdentityFingerprint: string;
40
+ originalPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
41
+ producer: "trusted_host_maintenance";
42
+ producerVersion: 1;
43
+ sourceChargeDigest: string;
44
+ sourceCreatedAt: number;
45
+ sourceId: import("convex/values").GenericId<"transferReversalOps">;
46
+ };
47
+ } | {
48
+ status: "updated";
49
+ header: {
50
+ _creationTime: number;
51
+ _id: import("convex/values").GenericId<"operationEvidenceHeaders">;
52
+ firstObservedAt: number;
53
+ generation: number;
54
+ isContradictory: boolean;
55
+ latestFingerprint: string;
56
+ latestPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
57
+ operationDigest: string;
58
+ originalFingerprint: string;
59
+ originalIdentityFingerprint: string;
60
+ originalPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
61
+ producer: "trusted_host_maintenance";
62
+ producerVersion: 1;
63
+ sourceChargeDigest: string;
64
+ sourceCreatedAt: number;
65
+ sourceId: import("convex/values").GenericId<"transferReversalOps">;
66
+ };
67
+ } | {
68
+ status: "captured";
69
+ header: {
70
+ _creationTime: number;
71
+ _id: import("convex/values").GenericId<"operationEvidenceHeaders">;
72
+ firstObservedAt: number;
73
+ generation: number;
74
+ isContradictory: boolean;
75
+ latestFingerprint: string;
76
+ latestPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
77
+ operationDigest: string;
78
+ originalFingerprint: string;
79
+ originalIdentityFingerprint: string;
80
+ originalPayloadId: import("convex/values").GenericId<"operationEvidencePayloads">;
81
+ producer: "trusted_host_maintenance";
82
+ producerVersion: 1;
83
+ sourceChargeDigest: string;
84
+ sourceCreatedAt: number;
85
+ sourceId: import("convex/values").GenericId<"transferReversalOps">;
86
+ };
87
+ }>;
88
+ //# sourceMappingURL=maintenance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maintenance.d.ts","sourceRoot":"","sources":["../../../src/component/operationEvidence/maintenance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAc3D,qFAAqF;AACrF,wBAAsB,aAAa,CACjC,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,EAAE,CAAC,qBAAqB,CAAC;YAIhB,aAAa;;;YAEF,oBAAoB;;;;;;;;;;;;;;;;;;;;YAI/B,WAAW;;;;;;;;;;;;;;;;;;;;YAwBlB,SAAS;;;;;;;;;;;;;;;;;;;;YAiCX,UAAU;;;;;;;;;;;;;;;;;;;GAGrB"}
@@ -0,0 +1,59 @@
1
+ import { advanceObservationGeneration, observationGeneration, } from "../financialObservations/generations.js";
2
+ import { bodyOf, identityFingerprint, operationEvidenceScope, selectorDigest, sourceFingerprint, uniqueSourceHeader, } from "./helpers.js";
3
+ /** Explicit evidence maintenance only. Never called from a financial writer here. */
4
+ export async function captureSource(ctx, sourceId) {
5
+ const { headers, header } = await uniqueSourceHeader(ctx, sourceId);
6
+ if (headers.length > 1 || (headers.length === 1 && !header))
7
+ return { status: "unavailable", header: null };
8
+ const source = await ctx.db.get("transferReversalOps", sourceId);
9
+ if (!source)
10
+ return { status: "source_unavailable", header };
11
+ const body = bodyOf(source);
12
+ const fingerprint = await sourceFingerprint(body);
13
+ if (header?.latestFingerprint === fingerprint)
14
+ return { status: "unchanged", header };
15
+ const generation = await observationGeneration(ctx, operationEvidenceScope);
16
+ if (generation === null ||
17
+ generation >= Number.MAX_SAFE_INTEGER ||
18
+ (header && header.generation >= Number.MAX_SAFE_INTEGER))
19
+ throw new Error("Operation evidence generation unavailable");
20
+ const identity = await identityFingerprint(body);
21
+ if (header) {
22
+ await ctx.db.replace("operationEvidencePayloads", header.latestPayloadId, body);
23
+ await ctx.db.patch("operationEvidenceHeaders", header._id, {
24
+ latestFingerprint: fingerprint,
25
+ generation: header.generation + 1,
26
+ isContradictory: header.isContradictory ||
27
+ header.originalIdentityFingerprint !== identity,
28
+ });
29
+ await advanceObservationGeneration(ctx, operationEvidenceScope);
30
+ return {
31
+ status: "updated",
32
+ header: (await ctx.db.get("operationEvidenceHeaders", header._id)),
33
+ };
34
+ }
35
+ const originalPayloadId = await ctx.db.insert("operationEvidencePayloads", body);
36
+ const latestPayloadId = await ctx.db.insert("operationEvidencePayloads", body);
37
+ const id = await ctx.db.insert("operationEvidenceHeaders", {
38
+ sourceId,
39
+ originalPayloadId,
40
+ latestPayloadId,
41
+ producer: "trusted_host_maintenance",
42
+ producerVersion: 1,
43
+ firstObservedAt: Date.now(),
44
+ sourceCreatedAt: source._creationTime,
45
+ originalFingerprint: fingerprint,
46
+ latestFingerprint: fingerprint,
47
+ originalIdentityFingerprint: identity,
48
+ operationDigest: await selectorDigest("operationId", body.operationId),
49
+ sourceChargeDigest: await selectorDigest("sourceChargeId", body.sourceChargeId),
50
+ generation: 1,
51
+ isContradictory: false,
52
+ });
53
+ await advanceObservationGeneration(ctx, operationEvidenceScope);
54
+ return {
55
+ status: "captured",
56
+ header: (await ctx.db.get("operationEvidenceHeaders", id)),
57
+ };
58
+ }
59
+ //# sourceMappingURL=maintenance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maintenance.js","sourceRoot":"","sources":["../../../src/component/operationEvidence/maintenance.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,4BAA4B,EAC5B,qBAAqB,GACtB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACL,MAAM,EACN,mBAAmB,EACnB,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAEtB,qFAAqF;AACrF,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAAgB,EAChB,QAAmC;IAEnC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACpE,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;QACzD,OAAO,EAAE,MAAM,EAAE,aAAsB,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC1D,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC;IACjE,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,MAAM,EAAE,oBAA6B,EAAE,MAAM,EAAE,CAAC;IACtE,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5B,MAAM,WAAW,GA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