@owneraio/finp2p-sdk-js 0.28.41 → 0.29.1

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 (115) hide show
  1. package/README.md +25 -1
  2. package/lib/OwneraAPI/__tests__/utils.test.d.ts +1 -0
  3. package/lib/OwneraAPI/__tests__/utils.test.js +82 -0
  4. package/lib/OwneraAPI/__tests__/utils.test.js.map +1 -0
  5. package/lib/OwneraAPI/finp2p-node-api/__tests__/agreements.test.d.ts +1 -0
  6. package/lib/OwneraAPI/finp2p-node-api/__tests__/agreements.test.js +149 -0
  7. package/lib/OwneraAPI/finp2p-node-api/__tests__/agreements.test.js.map +1 -0
  8. package/lib/OwneraAPI/finp2p-node-api/__tests__/collateral.test.d.ts +1 -0
  9. package/lib/OwneraAPI/finp2p-node-api/__tests__/collateral.test.js +502 -0
  10. package/lib/OwneraAPI/finp2p-node-api/__tests__/collateral.test.js.map +1 -0
  11. package/lib/OwneraAPI/finp2p-node-api/agreements.d.ts +8 -0
  12. package/lib/OwneraAPI/finp2p-node-api/agreements.js +31 -0
  13. package/lib/OwneraAPI/finp2p-node-api/agreements.js.map +1 -0
  14. package/lib/OwneraAPI/finp2p-node-api/collateral.d.ts +16 -0
  15. package/lib/OwneraAPI/finp2p-node-api/collateral.js +131 -0
  16. package/lib/OwneraAPI/finp2p-node-api/collateral.js.map +1 -0
  17. package/lib/OwneraAPI/finp2p-node-api/profiles.js +8 -7
  18. package/lib/OwneraAPI/finp2p-node-api/profiles.js.map +1 -1
  19. package/lib/OwneraAPI/index.js +4 -0
  20. package/lib/OwneraAPI/index.js.map +1 -1
  21. package/lib/OwneraAPI/oss-api/__tests__/buildGraphQLQuery.test.js +73 -0
  22. package/lib/OwneraAPI/oss-api/__tests__/buildGraphQLQuery.test.js.map +1 -1
  23. package/lib/OwneraAPI/oss-api/__tests__/filterUtils.test.d.ts +1 -0
  24. package/lib/OwneraAPI/oss-api/__tests__/filterUtils.test.js +15 -0
  25. package/lib/OwneraAPI/oss-api/__tests__/filterUtils.test.js.map +1 -0
  26. package/lib/OwneraAPI/oss-api/__tests__/getAgreements.test.d.ts +1 -0
  27. package/lib/OwneraAPI/oss-api/__tests__/getAgreements.test.js +175 -0
  28. package/lib/OwneraAPI/oss-api/__tests__/getAgreements.test.js.map +1 -0
  29. package/lib/OwneraAPI/oss-api/__tests__/getCollateralAgreements.test.d.ts +1 -0
  30. package/lib/OwneraAPI/oss-api/__tests__/getCollateralAgreements.test.js +321 -0
  31. package/lib/OwneraAPI/oss-api/__tests__/getCollateralAgreements.test.js.map +1 -0
  32. package/lib/OwneraAPI/oss-api/__tests__/getCollateralReports.test.d.ts +1 -0
  33. package/lib/OwneraAPI/oss-api/__tests__/getCollateralReports.test.js +152 -0
  34. package/lib/OwneraAPI/oss-api/__tests__/getCollateralReports.test.js.map +1 -0
  35. package/lib/OwneraAPI/oss-api/__tests__/getReceiptsByUser.test.d.ts +1 -0
  36. package/lib/OwneraAPI/oss-api/__tests__/getReceiptsByUser.test.js +95 -0
  37. package/lib/OwneraAPI/oss-api/__tests__/getReceiptsByUser.test.js.map +1 -0
  38. package/lib/OwneraAPI/oss-api/oss.js +592 -10
  39. package/lib/OwneraAPI/oss-api/oss.js.map +1 -1
  40. package/lib/OwneraAPI/oss-api/queryUtils.js +15 -8
  41. package/lib/OwneraAPI/oss-api/queryUtils.js.map +1 -1
  42. package/lib/OwneraAPI/utils.js +51 -9
  43. package/lib/OwneraAPI/utils.js.map +1 -1
  44. package/lib/core/__tests__/subscriptionExpiry.test.d.ts +1 -0
  45. package/lib/core/__tests__/subscriptionExpiry.test.js +426 -0
  46. package/lib/core/__tests__/subscriptionExpiry.test.js.map +1 -0
  47. package/lib/core/asset.js +3 -0
  48. package/lib/core/asset.js.map +1 -1
  49. package/lib/core/intents/createIntent/createIntent.js +1 -0
  50. package/lib/core/intents/createIntent/createIntent.js.map +1 -1
  51. package/lib/core/intents/createIntent/createMoveIntentReq.js +1 -1
  52. package/lib/core/intents/createIntent/createMoveIntentReq.js.map +1 -1
  53. package/lib/core/intents/createIntent/createTransferRequestIntent.js +1 -1
  54. package/lib/core/intents/createIntent/createTransferRequestIntent.js.map +1 -1
  55. package/lib/core/intents/createLoanIntent.js +1 -0
  56. package/lib/core/intents/createLoanIntent.js.map +1 -1
  57. package/lib/core/intents/executeIntent.d.ts +1 -0
  58. package/lib/core/intents/executeIntent.js +2 -2
  59. package/lib/core/intents/executeIntent.js.map +1 -1
  60. package/lib/core/intents/executeLoanIntent.d.ts +1 -0
  61. package/lib/core/intents/executeLoanIntent.js +2 -2
  62. package/lib/core/intents/executeLoanIntent.js.map +1 -1
  63. package/lib/core/intents/executeMoveIntent.d.ts +1 -0
  64. package/lib/core/intents/executeMoveIntent.js +2 -2
  65. package/lib/core/intents/executeMoveIntent.js.map +1 -1
  66. package/lib/core/intents/executePrivateIntent.d.ts +1 -0
  67. package/lib/core/intents/executePrivateIntent.js +2 -2
  68. package/lib/core/intents/executePrivateIntent.js.map +1 -1
  69. package/lib/core/intents/executeRedemptionIntent.d.ts +1 -0
  70. package/lib/core/intents/executeRedemptionIntent.js +2 -2
  71. package/lib/core/intents/executeRedemptionIntent.js.map +1 -1
  72. package/lib/core/intents/executeTransferRequest.d.ts +1 -0
  73. package/lib/core/intents/executeTransferRequest.js +2 -2
  74. package/lib/core/intents/executeTransferRequest.js.map +1 -1
  75. package/lib/core/intents/transfer.d.ts +1 -0
  76. package/lib/core/intents/transfer.js +2 -4
  77. package/lib/core/intents/transfer.js.map +1 -1
  78. package/lib/core/intents/updateTransferIntent.d.ts +1 -0
  79. package/lib/core/intents/updateTransferIntent.js +2 -2
  80. package/lib/core/intents/updateTransferIntent.js.map +1 -1
  81. package/lib/core/tokens.js +7 -6
  82. package/lib/core/tokens.js.map +1 -1
  83. package/lib/core/user.js +10 -0
  84. package/lib/core/user.js.map +1 -1
  85. package/lib/core/utils.d.ts +3 -0
  86. package/lib/core/utils.js +7 -1
  87. package/lib/core/utils.js.map +1 -1
  88. package/lib/types/Agreements/Agreements.d.ts +355 -0
  89. package/lib/types/Agreements/Agreements.js +3 -0
  90. package/lib/types/Agreements/Agreements.js.map +1 -0
  91. package/lib/types/Agreements/index.d.ts +1 -0
  92. package/lib/types/Agreements/index.js +18 -0
  93. package/lib/types/Agreements/index.js.map +1 -0
  94. package/lib/types/Collateral/Collateral.d.ts +564 -0
  95. package/lib/types/Collateral/Collateral.js +3 -0
  96. package/lib/types/Collateral/Collateral.js.map +1 -0
  97. package/lib/types/Collateral/index.d.ts +1 -0
  98. package/lib/types/Collateral/index.js +18 -0
  99. package/lib/types/Collateral/index.js.map +1 -0
  100. package/lib/types/Commons/index.d.ts +1 -0
  101. package/lib/types/Core/OwneraAPI.d.ts +4 -0
  102. package/lib/types/Oss/Agreements.d.ts +671 -0
  103. package/lib/types/Oss/Agreements.js +3 -0
  104. package/lib/types/Oss/Agreements.js.map +1 -0
  105. package/lib/types/Oss/Oss.d.ts +63 -0
  106. package/lib/types/Oss/index.d.ts +1 -0
  107. package/lib/types/Oss/index.js +1 -0
  108. package/lib/types/Oss/index.js.map +1 -1
  109. package/lib/types/Oss/utils.d.ts +7 -0
  110. package/lib/types/index.d.ts +2 -0
  111. package/lib/types/index.js +2 -0
  112. package/lib/types/index.js.map +1 -1
  113. package/lib/types/utils.d.ts +5 -0
  114. package/lib/types/utils.js.map +1 -1
  115. package/package.json +3 -8
@@ -527,6 +527,251 @@ pageInfo {
527
527
  totalCount
528
528
  totalLeft
529
529
  }`;
530
+ const emptyPageInfo = { hasNextPage: false, totalCount: 0, totalLeft: 0 };
531
+ // agreement (resource type 107) fragments — selections validated against the
532
+ // oss feature/collateral-mobility schema on local6 (ownership.graphql).
533
+ const accountPolicyFragment = `
534
+ policyId
535
+ version
536
+ direction
537
+ eligibility { assetTypes assetNameRegexp assetCodes ledgerNames }
538
+ constraints { allowedCounterOrganizations allowedCounterAssetTypes allowedCounterFinIds allowedCounterRoles }
539
+ authorization { requiredRoles requiredSigners threshold }
540
+ conditions {
541
+ name
542
+ trigger { type asserterRole }
543
+ authorization { requiredRoles requiredSigners threshold }
544
+ constraints { allowedCounterOrganizations allowedCounterAssetTypes allowedCounterFinIds allowedCounterRoles }
545
+ }
546
+ allowedInitiatorRoles
547
+ agreementRef
548
+ beneficialOwnerRole
549
+ boundParty
550
+ signers { signerParty }
551
+ `;
552
+ const containerSpecFragment = `
553
+ key
554
+ servesRoles
555
+ boundParty
556
+ provisionerRole
557
+ provisionerParty
558
+ eligibleAssets { network standard tokenId }
559
+ policyTemplate { ${accountPolicyFragment} }
560
+ `;
561
+ // AgreementSchemaReference is a union: the url arm carries `url`, the document arm `key`.
562
+ const agreementSchemaFragment = `
563
+ name
564
+ version
565
+ reference {
566
+ ... on AgreementSchemaUrlReference { url format hash { hash hashAlgorithm } }
567
+ ... on AgreementSchemaDocumentReference { key path format hash { hash hashAlgorithm } }
568
+ }
569
+ `;
570
+ const agreementAccountFragment = `
571
+ agreementId
572
+ finId
573
+ orgId
574
+ custodianOrgId
575
+ policyId
576
+ policyVersion
577
+ servesRoles
578
+ provisionerRole
579
+ status
580
+ footprints { network standard tokenId networkAccount }
581
+ spec { ${containerSpecFragment} }
582
+ `;
583
+ const agreementFragment = `
584
+ id
585
+ organizationId
586
+ status
587
+ version
588
+ consentRoles
589
+ participants { organizationId roles }
590
+ roles { role parties }
591
+ eligibleAssets { network standard tokenId }
592
+ termsType
593
+ terms
594
+ validFrom
595
+ validUntil
596
+ signatures { role signerParty }
597
+ events {
598
+ id
599
+ eventType
600
+ emitterRole
601
+ sequence
602
+ occurredAt
603
+ payloadType
604
+ payload
605
+ referencedEventIds
606
+ after { changeStateTo }
607
+ }
608
+ accounts { ${agreementAccountFragment} }
609
+ setup {
610
+ ... on AgreementProvisioningSpec {
611
+ provisionerRole
612
+ policyTemplate { ${accountPolicyFragment} }
613
+ containers { ${containerSpecFragment} }
614
+ }
615
+ }
616
+ definition {
617
+ name
618
+ version
619
+ emitterRoles
620
+ guard
621
+ states { onCreation onApproval allowedStates finalStates }
622
+ schema { ${agreementSchemaFragment} }
623
+ allowedEvents { type guard schema { ${agreementSchemaFragment} } }
624
+ transitions { event toState fromStates guard targetSelectableByEvent selectableStates }
625
+ }
626
+ `;
627
+ // collateral facade module fragments (collateral.graphql) — folded entities,
628
+ // decoded terms, no base64, no raw events.
629
+ const collateralAgreementFragment = `
630
+ agreementId
631
+ orgId
632
+ status
633
+ version
634
+ termsType
635
+ consentRoles
636
+ eligibleAssets { network standard tokenId }
637
+ definitionSchemaKey
638
+ terms {
639
+ baseCurrency
640
+ haircutApplyMethod
641
+ eligibleAssets { assetId haircut caip19 }
642
+ }
643
+ roles { role parties }
644
+ participants { orgId role }
645
+ containers { key finId orgId status boundParty }
646
+ validFrom
647
+ validUntil
648
+ createdAt
649
+ `;
650
+ // The asset an execution plan moved, with the attribution line's valuation overlaid.
651
+ const collateralReportActionAssetFragment = `
652
+ assetIdType
653
+ assetId
654
+ name
655
+ ticker
656
+ assetIdentifierType
657
+ assetIdentifierValue
658
+ metadata { appliedHaircut baseUnitPrice baseValue baseUnits finalUnitPrice finalValue finalUnits }
659
+ `;
660
+ const collateralReportFragment = `
661
+ reportId
662
+ agreementId
663
+ type
664
+ currency
665
+ senderOrgId
666
+ senderProfileId
667
+ receiverOrgId
668
+ receiverProfileId
669
+ reportCreatorId
670
+ nominalMarginAmount
671
+ deadline
672
+ eventId
673
+ containerKey
674
+ calledParty
675
+ overlayStatus
676
+ sequence
677
+ fulfillmentMode
678
+ createdAt
679
+ statusHistory { status sequence emitterRole emitterOrgId note timestamp }
680
+ resolutions { resolvedBy sequence timestamp note }
681
+ rejections { rejectedBy sequence timestamp note }
682
+ actions {
683
+ action
684
+ nominalAmount
685
+ recoveredAsset { assetId quantity }
686
+ }
687
+ settlement { assetId }
688
+ negotiations {
689
+ negotiationId
690
+ kind
691
+ status
692
+ openedBy
693
+ standingRound
694
+ standingBy
695
+ agreedLines { assetId quantity }
696
+ intentId
697
+ rounds { round action by lines { assetId quantity } intentId reason sequence timestamp }
698
+ }
699
+ exceptions {
700
+ exceptionId
701
+ status
702
+ blame
703
+ reason
704
+ raisedBy
705
+ details { executionPlanId assetId quantity }
706
+ eventId
707
+ sequence
708
+ timestamp
709
+ }
710
+ manualResolves {
711
+ manualResolveId
712
+ exceptionIds
713
+ requestedBy
714
+ reason
715
+ eventId
716
+ sequence
717
+ timestamp
718
+ decisions { status decidedBy reason sequence timestamp }
719
+ }
720
+ coverageRechecks { requestedBy reason eventId sequence timestamp }
721
+ executionPlans {
722
+ planId
723
+ status
724
+ asset { ${collateralReportActionAssetFragment} }
725
+ quantity
726
+ failureReason
727
+ instructions { sequence status errorCode errorMessage }
728
+ createdAt
729
+ lastModified
730
+ }
731
+ attributionProposals {
732
+ proposalId
733
+ round
734
+ status
735
+ lines {
736
+ assetId
737
+ quantity
738
+ metadata { appliedHaircut baseUnitPrice baseValue baseUnits finalUnitPrice finalValue finalUnits }
739
+ }
740
+ proposedBy
741
+ decidedBy
742
+ completed
743
+ eventId
744
+ decisionEventId
745
+ sequence
746
+ timestamp
747
+ }
748
+ `;
749
+ const collateralContainerBookFragment = `
750
+ agreementId
751
+ containerKey
752
+ finId
753
+ boundParty
754
+ booksAvailable
755
+ holdings { assetId quantity }
756
+ activity { assetId quantity direction reportId timestampMs transactionId operationType }
757
+ earmarks { reportId holdings { assetId quantity } }
758
+ unattributed { assetId quantity }
759
+ `;
760
+ // A connection page is complete when its root resolved and no node is null. `nodes: null` is a valid
761
+ // empty page; a field error that nulls anything is caught earlier, because these reads are `strict`.
762
+ const isCompletePage = (page) => { var _a; return !!page && ((_a = page.nodes) !== null && _a !== void 0 ? _a : []).every((node) => node !== null && node !== undefined); };
763
+ // OSS `CollateralAgreementOrderField` values: the only order literals `getCollateralAgreements` sends.
764
+ const COLLATERAL_AGREEMENT_ORDER_FIELDS = ['CREATED_AT', 'AGREEMENT_ID'];
765
+ // OSS `CollateralReportOrderField` values: the only order literals `getCollateralReports` sends.
766
+ const COLLATERAL_REPORT_ORDER_FIELDS = ['CREATED_AT'];
767
+ const COLLATERAL_REPORT_CHANGE_KINDS = [
768
+ 'CREATED',
769
+ 'STATUS_CHANGED',
770
+ 'RESOLVED',
771
+ 'NEGOTIATION',
772
+ 'REJECTED',
773
+ 'EXCEPTION',
774
+ ];
530
775
  // execution plan fragments
531
776
  const termFragment = `
532
777
  term {
@@ -2142,8 +2387,18 @@ query getReceiptsByAsset {
2142
2387
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2143
2388
  let dstCursor = '';
2144
2389
  let srcCursor = '';
2390
+ // An empty list is a valid answer; a side or receipt nulled by a GraphQL error (partial data)
2391
+ // is not, nor a next page without the cursor to fetch it
2392
+ const answered = (side) => {
2393
+ var _a;
2394
+ return Array.isArray(side === null || side === void 0 ? void 0 : side.nodes) &&
2395
+ side.nodes.every((receipt) => receipt != null) &&
2396
+ typeof ((_a = side === null || side === void 0 ? void 0 : side.pageInfo) === null || _a === void 0 ? void 0 : _a.hasNextPage) === 'boolean' &&
2397
+ (!side.pageInfo.hasNextPage || !!side.pageInfo.endCursor);
2398
+ };
2145
2399
  const readyConditions = {
2146
- match: (res) => { var _a, _b, _c, _d; return ((_b = (_a = res.destination) === null || _a === void 0 ? void 0 : _a.nodes) === null || _b === void 0 ? void 0 : _b.length) || ((_d = (_c = res.source) === null || _c === void 0 ? void 0 : _c.nodes) === null || _d === void 0 ? void 0 : _d.length); },
2400
+ // Every side in this page's query must answer
2401
+ match: (res) => (!fetchDst || answered(res.destination)) && (!fetchSrc || answered(res.source)),
2147
2402
  name: 'getReceiptsByUser',
2148
2403
  data: request,
2149
2404
  };
@@ -2198,15 +2453,11 @@ query getReceiptsByUser {
2198
2453
  fetchDst = !!dstCursor && !!((_j = response.destination) === null || _j === void 0 ? void 0 : _j.pageInfo.hasNextPage);
2199
2454
  fetchSrc = !!srcCursor && !!((_k = response.source) === null || _k === void 0 ? void 0 : _k.pageInfo.hasNextPage);
2200
2455
  }
2201
- if (!allReceipts) {
2202
- throw {
2203
- code: 404,
2204
- name: 'Not found',
2205
- message: `No receipts found for user ${request.userId}`,
2206
- };
2207
- }
2208
- allReceipts.forEach(normalizeReceiptIntents);
2209
- return allReceipts;
2456
+ // A receipt where the user is both source and destination comes back on both sides
2457
+ const seen = new Set();
2458
+ const receipts = allReceipts.filter((receipt) => !receipt.id || (!seen.has(receipt.id) && !!seen.add(receipt.id)));
2459
+ receipts.forEach(normalizeReceiptIntents);
2460
+ return receipts;
2210
2461
  }),
2211
2462
  getReceiptsByOperation: (request) => __awaiter(void 0, void 0, void 0, function* () {
2212
2463
  var _a;
@@ -2474,6 +2725,112 @@ subscription getReceipts {
2474
2725
  r.onNext(data);
2475
2726
  } }));
2476
2727
  },
2728
+ // -- agreements (resource type 107): raw read-model pushes (ownership.graphql)
2729
+ getAgreementAddedSubscription: (r) => {
2730
+ var _a;
2731
+ const args = ((_a = r.orgIds) === null || _a === void 0 ? void 0 : _a.length) ? `(orgIds: ${JSON.stringify(r.orgIds)})` : '';
2732
+ const query = `
2733
+ subscription agreementAddedSubscription {
2734
+ agreementAdded${args} {
2735
+ ${agreementFragment}
2736
+ }
2737
+ }
2738
+ `;
2739
+ return client.subscribe(Object.assign(Object.assign({}, r), { query }));
2740
+ },
2741
+ getAgreementChangedSubscription: (r) => {
2742
+ var _a, _b;
2743
+ const filters = [];
2744
+ if ((_a = r.agreementIds) === null || _a === void 0 ? void 0 : _a.length)
2745
+ filters.push(`agreementIds: ${JSON.stringify(r.agreementIds)}`);
2746
+ if ((_b = r.orgIds) === null || _b === void 0 ? void 0 : _b.length)
2747
+ filters.push(`orgIds: ${JSON.stringify(r.orgIds)}`);
2748
+ const args = filters.length ? `(${filters.join(', ')})` : '';
2749
+ const query = `
2750
+ subscription agreementChangedSubscription {
2751
+ agreementChanged${args} {
2752
+ ${agreementFragment}
2753
+ }
2754
+ }
2755
+ `;
2756
+ return client.subscribe(Object.assign(Object.assign({}, r), { query }));
2757
+ },
2758
+ // -- collateral facade subscriptions (collateral.graphql): the fully folded
2759
+ // entities; gated per org by the OSS `enabled_features` config (`collateral`).
2760
+ getCollateralAgreementAddedSubscription: (r) => {
2761
+ var _a;
2762
+ const args = ((_a = r.orgIds) === null || _a === void 0 ? void 0 : _a.length) ? `(orgIds: ${JSON.stringify(r.orgIds)})` : '';
2763
+ const query = `
2764
+ subscription collateralAgreementAddedSubscription {
2765
+ collateralAgreementAdded${args} {
2766
+ ${collateralAgreementFragment}
2767
+ }
2768
+ }
2769
+ `;
2770
+ return client.subscribe(Object.assign(Object.assign({}, r), { query }));
2771
+ },
2772
+ getCollateralAgreementChangedSubscription: (r) => {
2773
+ var _a, _b;
2774
+ const filters = [];
2775
+ if ((_a = r.agreementIds) === null || _a === void 0 ? void 0 : _a.length)
2776
+ filters.push(`agreementIds: ${JSON.stringify(r.agreementIds)}`);
2777
+ if ((_b = r.orgIds) === null || _b === void 0 ? void 0 : _b.length)
2778
+ filters.push(`orgIds: ${JSON.stringify(r.orgIds)}`);
2779
+ const args = filters.length ? `(${filters.join(', ')})` : '';
2780
+ const query = `
2781
+ subscription collateralAgreementChangedSubscription {
2782
+ collateralAgreementChanged${args} {
2783
+ ${collateralAgreementFragment}
2784
+ }
2785
+ }
2786
+ `;
2787
+ return client.subscribe(Object.assign(Object.assign({}, r), { query }));
2788
+ },
2789
+ getCollateralReportChangedSubscription: (r) => {
2790
+ var _a, _b, _c;
2791
+ const filters = [];
2792
+ if ((_a = r.agreementIds) === null || _a === void 0 ? void 0 : _a.length)
2793
+ filters.push(`agreementIds: ${JSON.stringify(r.agreementIds)}`);
2794
+ if ((_b = r.reportIds) === null || _b === void 0 ? void 0 : _b.length)
2795
+ filters.push(`reportIds: ${JSON.stringify(r.reportIds)}`);
2796
+ // Kinds are interpolated as raw enum literals, so only known ones may pass. An unknown kind is
2797
+ // refused rather than dropped: dropping the last one would silently widen the stream to every change.
2798
+ const changeKinds = (_c = r.changeKinds) !== null && _c !== void 0 ? _c : [];
2799
+ const unknownKinds = changeKinds.filter((kind) => !COLLATERAL_REPORT_CHANGE_KINDS.includes(kind));
2800
+ if (unknownKinds.length) {
2801
+ throw {
2802
+ code: 400,
2803
+ name: 'UnknownChangeKind',
2804
+ message: `Unknown collateral report change kind(s): ${unknownKinds.join(', ')}`,
2805
+ };
2806
+ }
2807
+ if (changeKinds.length)
2808
+ filters.push(`changeKinds: [${changeKinds.join(', ')}]`);
2809
+ const args = filters.length ? `(${filters.join(', ')})` : '';
2810
+ const query = `
2811
+ subscription collateralReportChangedSubscription {
2812
+ collateralReportChanged${args} {
2813
+ kind
2814
+ report {
2815
+ ${collateralReportFragment}
2816
+ }
2817
+ }
2818
+ }
2819
+ `;
2820
+ return client.subscribe(Object.assign(Object.assign({}, r), { query }));
2821
+ },
2822
+ getCollateralContainerBookChangedSubscription: (r) => {
2823
+ var _a;
2824
+ const args = ((_a = r.agreementIds) === null || _a === void 0 ? void 0 : _a.length) ? `(agreementIds: ${JSON.stringify(r.agreementIds)})` : '';
2825
+ const query = `
2826
+ subscription collateralContainerBookChangedSubscription {
2827
+ collateralContainerBookChanged${args} {
2828
+ ${collateralContainerBookFragment}
2829
+ }
2830
+ }
2831
+ `;
2832
+ return client.subscribe(Object.assign(Object.assign({}, r), { query }));
2833
+ },
2477
2834
  getUserHoldingChangedSubscription: (r) => {
2478
2835
  const query = `
2479
2836
  subscription userHoldingChangedSubscription {
@@ -2921,6 +3278,231 @@ query getWorkflowById {
2921
3278
  }
2922
3279
  return node;
2923
3280
  }),
3281
+ // models - agreements (resource type 107)
3282
+ getAgreements: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (request = {}) {
3283
+ var _a;
3284
+ const { filter } = request;
3285
+ const { id, idContains, organizationId, status } = filter || {};
3286
+ const filters = `
3287
+ filter: [
3288
+ ${id ? `{key:"id",operator:EQ,value:${gqlString(id)}},` : ''}
3289
+ ${idContains ? `{key:"id",operator:CONTAINS,value:${gqlString(idContains)}},` : ''}
3290
+ ${organizationId ? `{key:"organizationId",operator:EQ,value:${gqlString(organizationId)}},` : ''}
3291
+ ${(status === null || status === void 0 ? void 0 : status.length) ? `{key:"status",operator:IN,value:${gqlStringList(status)}},` : ''}
3292
+ ]
3293
+ `;
3294
+ const query = `
3295
+ query getAgreements {
3296
+ agreements
3297
+ (${filters},
3298
+ ${(0, queryUtils_1.paginateFragment)({ after: filter === null || filter === void 0 ? void 0 : filter.after, limit: filter === null || filter === void 0 ? void 0 : filter.limit, skip: filter === null || filter === void 0 ? void 0 : filter.skip })})
3299
+ {
3300
+ nodes {
3301
+ ${agreementFragment}
3302
+ }
3303
+ ${pageInfoFragment}
3304
+ }
3305
+ }
3306
+ `;
3307
+ const readyCondition = {
3308
+ match: (response) => isCompletePage(response === null || response === void 0 ? void 0 : response.agreements),
3309
+ name: 'getAgreements',
3310
+ strict: true,
3311
+ data: request,
3312
+ };
3313
+ const response = yield (0, utils_2.ossQuery)(client, logger, query, readyCondition);
3314
+ return { data: (_a = response.agreements.nodes) !== null && _a !== void 0 ? _a : [], pageInfo: response.agreements.pageInfo };
3315
+ }),
3316
+ getAgreementAccounts: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (request = {}) {
3317
+ var _a;
3318
+ const { filter } = request;
3319
+ const { agreementId, finId, orgId, status } = filter || {};
3320
+ const filters = `
3321
+ filter: [
3322
+ ${agreementId ? `{key:"agreementId",operator:EQ,value:${gqlString(agreementId)}},` : ''}
3323
+ ${finId ? `{key:"finId",operator:EQ,value:${gqlString(finId)}},` : ''}
3324
+ ${orgId ? `{key:"orgId",operator:EQ,value:${gqlString(orgId)}},` : ''}
3325
+ ${(status === null || status === void 0 ? void 0 : status.length) ? `{key:"status",operator:IN,value:${gqlStringList(status)}},` : ''}
3326
+ ]
3327
+ `;
3328
+ const query = `
3329
+ query getAgreementAccounts {
3330
+ agreementAccounts
3331
+ (${filters},
3332
+ ${(0, queryUtils_1.paginateFragment)({ after: filter === null || filter === void 0 ? void 0 : filter.after, limit: filter === null || filter === void 0 ? void 0 : filter.limit, skip: filter === null || filter === void 0 ? void 0 : filter.skip })})
3333
+ {
3334
+ nodes {
3335
+ ${agreementAccountFragment}
3336
+ }
3337
+ ${pageInfoFragment}
3338
+ }
3339
+ }
3340
+ `;
3341
+ const readyCondition = {
3342
+ match: (response) => isCompletePage(response === null || response === void 0 ? void 0 : response.agreementAccounts),
3343
+ name: 'getAgreementAccounts',
3344
+ strict: true,
3345
+ data: request,
3346
+ };
3347
+ const response = yield (0, utils_2.ossQuery)(client, logger, query, readyCondition);
3348
+ return { data: (_a = response.agreementAccounts.nodes) !== null && _a !== void 0 ? _a : [], pageInfo: response.agreementAccounts.pageInfo };
3349
+ }),
3350
+ // models - collateral facade (collateral.graphql, `collateral` namespace root;
3351
+ // gated by the OSS `enabled_features` config — unlicensed orgs get a GraphQL error)
3352
+ getCollateralAgreements: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (request = {}) {
3353
+ var _a, _b;
3354
+ const { filter } = request;
3355
+ const { agreementId, agreementIdContains, orgId, status, createdAtFrom, createdAtTo, sortField, sortOrder } = filter || {};
3356
+ // 0 is a valid bound, so presence is checked rather than truthiness (as for reports).
3357
+ const hasFrom = createdAtFrom !== undefined && createdAtFrom !== null;
3358
+ const hasTo = createdAtTo !== undefined && createdAtTo !== null;
3359
+ // Interpolated raw into the document as enum literals, so only the schema's values get through.
3360
+ // A given but unknown value is refused, not replaced: a silent default would page in the wrong order.
3361
+ if (sortField !== undefined && !COLLATERAL_AGREEMENT_ORDER_FIELDS.includes(sortField)) {
3362
+ throw {
3363
+ code: 400,
3364
+ name: 'InvalidSortField',
3365
+ message: `Unknown collateral agreement sort field: ${sortField}`,
3366
+ };
3367
+ }
3368
+ if (sortOrder !== undefined && sortOrder !== 'ASC' && sortOrder !== 'DESC') {
3369
+ throw { code: 400, name: 'InvalidSortOrder', message: `Unknown sort order: ${sortOrder}` };
3370
+ }
3371
+ const orderField = sortField !== null && sortField !== void 0 ? sortField : 'CREATED_AT';
3372
+ const orderDirection = sortOrder !== null && sortOrder !== void 0 ? sortOrder : 'DESC';
3373
+ const filters = `
3374
+ filter: [
3375
+ ${agreementId ? `{key:"agreementId",operator:EQ,value:${gqlString(agreementId)}},` : ''}
3376
+ ${agreementIdContains ? `{key:"agreementId",operator:CONTAINS,value:${gqlString(agreementIdContains)}},` : ''}
3377
+ ${orgId ? `{key:"orgId",operator:EQ,value:${gqlString(orgId)}},` : ''}
3378
+ ${(status === null || status === void 0 ? void 0 : status.length) ? `{key:"status",operator:IN,value:${gqlStringList(status)}},` : ''}
3379
+ ${hasFrom ? `{key:"createdAt",operator:GTE,value:${gqlString(createdAtFrom)}},` : ''}
3380
+ ${hasTo ? `{key:"createdAt",operator:LTE,value:${gqlString(createdAtTo)}},` : ''}
3381
+ ]
3382
+ `;
3383
+ const query = `
3384
+ query getCollateralAgreements {
3385
+ collateral {
3386
+ agreements
3387
+ (${filters},
3388
+ ${(0, queryUtils_1.paginateFragment)({ after: filter === null || filter === void 0 ? void 0 : filter.after, limit: filter === null || filter === void 0 ? void 0 : filter.limit, skip: filter === null || filter === void 0 ? void 0 : filter.skip })}
3389
+ orderBy: {field: ${orderField}, direction: ${orderDirection}})
3390
+ {
3391
+ nodes {
3392
+ ${collateralAgreementFragment}
3393
+ }
3394
+ ${pageInfoFragment}
3395
+ }
3396
+ }
3397
+ }
3398
+ `;
3399
+ const readyCondition = {
3400
+ match: (response) => {
3401
+ var _a;
3402
+ return isCompletePage((_a = response === null || response === void 0 ? void 0 : response.collateral) === null || _a === void 0 ? void 0 : _a.agreements);
3403
+ },
3404
+ name: 'getCollateralAgreements',
3405
+ strict: true,
3406
+ data: request,
3407
+ };
3408
+ const response = yield (0, utils_2.ossQuery)(client, logger, query, readyCondition);
3409
+ const page = response.collateral.agreements;
3410
+ return { data: (_a = page.nodes) !== null && _a !== void 0 ? _a : [], pageInfo: (_b = page.pageInfo) !== null && _b !== void 0 ? _b : emptyPageInfo };
3411
+ }),
3412
+ getCollateralReports: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (request = {}) {
3413
+ var _a, _b;
3414
+ const { filter } = request;
3415
+ const { agreementId, reportId, reportIdContains, overlayStatus, type, createdAtFrom, createdAtTo, sortField, sortOrder, } = filter || {};
3416
+ // createdAt is epoch SECONDS on a report, and the bounds are inclusive: GTE/LTE, not GT/LT.
3417
+ // A bound of 0 is a real instant, so these test for undefined rather than truthiness.
3418
+ const hasFrom = createdAtFrom !== undefined && createdAtFrom !== null;
3419
+ const hasTo = createdAtTo !== undefined && createdAtTo !== null;
3420
+ // Interpolated raw into the document as enum literals, so only the schema's values get through.
3421
+ // A given but unknown value is refused, not replaced: a silent default would page in the wrong order.
3422
+ if (sortField !== undefined && !COLLATERAL_REPORT_ORDER_FIELDS.includes(sortField)) {
3423
+ throw {
3424
+ code: 400,
3425
+ name: 'InvalidSortField',
3426
+ message: `Unknown collateral report sort field: ${sortField}`,
3427
+ };
3428
+ }
3429
+ if (sortOrder !== undefined && sortOrder !== 'ASC' && sortOrder !== 'DESC') {
3430
+ throw { code: 400, name: 'InvalidSortOrder', message: `Unknown sort order: ${sortOrder}` };
3431
+ }
3432
+ const orderField = sortField !== null && sortField !== void 0 ? sortField : 'CREATED_AT';
3433
+ const orderDirection = sortOrder !== null && sortOrder !== void 0 ? sortOrder : 'DESC';
3434
+ const filters = `
3435
+ filter: [
3436
+ ${agreementId ? `{key:"agreementId",operator:EQ,value:${gqlString(agreementId)}},` : ''}
3437
+ ${reportId ? `{key:"reportId",operator:EQ,value:${gqlString(reportId)}},` : ''}
3438
+ ${reportIdContains ? `{key:"reportId",operator:CONTAINS,value:${gqlString(reportIdContains)}},` : ''}
3439
+ ${(overlayStatus === null || overlayStatus === void 0 ? void 0 : overlayStatus.length) ? `{key:"overlayStatus",operator:IN,value:${gqlStringList(overlayStatus)}},` : ''}
3440
+ ${(type === null || type === void 0 ? void 0 : type.length) ? `{key:"type",operator:IN,value:${gqlStringList(type)}},` : ''}
3441
+ ${hasFrom ? `{key:"createdAt",operator:GTE,value:${gqlString(createdAtFrom)}},` : ''}
3442
+ ${hasTo ? `{key:"createdAt",operator:LTE,value:${gqlString(createdAtTo)}},` : ''}
3443
+ ]
3444
+ `;
3445
+ const query = `
3446
+ query getCollateralReports {
3447
+ collateral {
3448
+ reports
3449
+ (${filters},
3450
+ ${(0, queryUtils_1.paginateFragment)({ after: filter === null || filter === void 0 ? void 0 : filter.after, limit: filter === null || filter === void 0 ? void 0 : filter.limit, skip: filter === null || filter === void 0 ? void 0 : filter.skip })}
3451
+ orderBy: {field: ${orderField}, direction: ${orderDirection}})
3452
+ {
3453
+ nodes {
3454
+ ${collateralReportFragment}
3455
+ }
3456
+ ${pageInfoFragment}
3457
+ }
3458
+ }
3459
+ }
3460
+ `;
3461
+ const readyCondition = {
3462
+ match: (response) => { var _a; return isCompletePage((_a = response === null || response === void 0 ? void 0 : response.collateral) === null || _a === void 0 ? void 0 : _a.reports); },
3463
+ name: 'getCollateralReports',
3464
+ strict: true,
3465
+ data: request,
3466
+ };
3467
+ const response = yield (0, utils_2.ossQuery)(client, logger, query, readyCondition);
3468
+ const page = response.collateral.reports;
3469
+ return { data: (_a = page.nodes) !== null && _a !== void 0 ? _a : [], pageInfo: (_b = page.pageInfo) !== null && _b !== void 0 ? _b : emptyPageInfo };
3470
+ }),
3471
+ getCollateralContainerBooks: (request) => __awaiter(void 0, void 0, void 0, function* () {
3472
+ var _a;
3473
+ const { agreementId } = request;
3474
+ if (!agreementId) {
3475
+ throw {
3476
+ code: 400,
3477
+ name: 'AgreementIdIsRequired',
3478
+ message: 'agreementId is required to get the container books!',
3479
+ };
3480
+ }
3481
+ const query = `
3482
+ query getCollateralContainerBooks {
3483
+ collateral {
3484
+ containerBooks(agreementId: ${gqlString(agreementId)}) {
3485
+ agreementId
3486
+ containers {
3487
+ ${collateralContainerBookFragment}
3488
+ }
3489
+ }
3490
+ }
3491
+ }
3492
+ `;
3493
+ const readyCondition = {
3494
+ match: (response) => {
3495
+ var _a;
3496
+ const books = (_a = response === null || response === void 0 ? void 0 : response.collateral) === null || _a === void 0 ? void 0 : _a.containerBooks;
3497
+ return isCompletePage(books && { nodes: books.containers });
3498
+ },
3499
+ name: 'getCollateralContainerBooks',
3500
+ strict: true,
3501
+ data: request,
3502
+ };
3503
+ const response = yield (0, utils_2.ossQuery)(client, logger, query, readyCondition);
3504
+ return (_a = response.collateral.containerBooks.containers) !== null && _a !== void 0 ? _a : [];
3505
+ }),
2924
3506
  };
2925
3507
  return ossInterface;
2926
3508
  };