@owneraio/finp2p-sdk-js 0.28.26 → 0.28.41

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 (199) hide show
  1. package/README.md +71 -1
  2. package/lib/OwneraAPI/__tests__/apiErrorShape.test.d.ts +1 -0
  3. package/lib/OwneraAPI/__tests__/apiErrorShape.test.js +264 -0
  4. package/lib/OwneraAPI/__tests__/apiErrorShape.test.js.map +1 -0
  5. package/lib/OwneraAPI/finp2p-node-api/__tests__/approvalsConfig.test.js +5 -12
  6. package/lib/OwneraAPI/finp2p-node-api/__tests__/approvalsConfig.test.js.map +1 -1
  7. package/lib/OwneraAPI/finp2p-node-api/__tests__/createIntentMetadata.test.d.ts +1 -0
  8. package/lib/OwneraAPI/finp2p-node-api/__tests__/createIntentMetadata.test.js +56 -0
  9. package/lib/OwneraAPI/finp2p-node-api/__tests__/createIntentMetadata.test.js.map +1 -0
  10. package/lib/OwneraAPI/finp2p-node-api/__tests__/dryRunExecute.test.d.ts +1 -0
  11. package/lib/OwneraAPI/finp2p-node-api/__tests__/dryRunExecute.test.js +75 -0
  12. package/lib/OwneraAPI/finp2p-node-api/__tests__/dryRunExecute.test.js.map +1 -0
  13. package/lib/OwneraAPI/finp2p-node-api/__tests__/pathEncoding.test.d.ts +1 -0
  14. package/lib/OwneraAPI/finp2p-node-api/__tests__/pathEncoding.test.js +348 -0
  15. package/lib/OwneraAPI/finp2p-node-api/__tests__/pathEncoding.test.js.map +1 -0
  16. package/lib/OwneraAPI/finp2p-node-api/__tests__/rejectIntent.test.d.ts +1 -0
  17. package/lib/OwneraAPI/finp2p-node-api/__tests__/rejectIntent.test.js +97 -0
  18. package/lib/OwneraAPI/finp2p-node-api/__tests__/rejectIntent.test.js.map +1 -0
  19. package/lib/OwneraAPI/finp2p-node-api/certificates.js +15 -6
  20. package/lib/OwneraAPI/finp2p-node-api/certificates.js.map +1 -1
  21. package/lib/OwneraAPI/finp2p-node-api/custodies.js +13 -2
  22. package/lib/OwneraAPI/finp2p-node-api/custodies.js.map +1 -1
  23. package/lib/OwneraAPI/finp2p-node-api/documents.js +22 -9
  24. package/lib/OwneraAPI/finp2p-node-api/documents.js.map +1 -1
  25. package/lib/OwneraAPI/finp2p-node-api/investorAccounts.d.ts +13 -0
  26. package/lib/OwneraAPI/finp2p-node-api/investorAccounts.js +71 -0
  27. package/lib/OwneraAPI/finp2p-node-api/investorAccounts.js.map +1 -0
  28. package/lib/OwneraAPI/finp2p-node-api/ledgers.js +13 -2
  29. package/lib/OwneraAPI/finp2p-node-api/ledgers.js.map +1 -1
  30. package/lib/OwneraAPI/finp2p-node-api/messages.js +12 -3
  31. package/lib/OwneraAPI/finp2p-node-api/messages.js.map +1 -1
  32. package/lib/OwneraAPI/finp2p-node-api/operations.js +37 -15
  33. package/lib/OwneraAPI/finp2p-node-api/operations.js.map +1 -1
  34. package/lib/OwneraAPI/finp2p-node-api/policies.js +14 -5
  35. package/lib/OwneraAPI/finp2p-node-api/policies.js.map +1 -1
  36. package/lib/OwneraAPI/finp2p-node-api/profiles.js +82 -45
  37. package/lib/OwneraAPI/finp2p-node-api/profiles.js.map +1 -1
  38. package/lib/OwneraAPI/finp2p-node-api/tokens.js +20 -0
  39. package/lib/OwneraAPI/finp2p-node-api/tokens.js.map +1 -1
  40. package/lib/OwneraAPI/index.js +2 -0
  41. package/lib/OwneraAPI/index.js.map +1 -1
  42. package/lib/OwneraAPI/oss-api/__tests__/buildGraphQLQuery.test.d.ts +1 -0
  43. package/lib/OwneraAPI/oss-api/__tests__/buildGraphQLQuery.test.js +253 -0
  44. package/lib/OwneraAPI/oss-api/__tests__/buildGraphQLQuery.test.js.map +1 -0
  45. package/lib/OwneraAPI/oss-api/__tests__/getAllExecutionPlans.test.js +52 -0
  46. package/lib/OwneraAPI/oss-api/__tests__/getAllExecutionPlans.test.js.map +1 -1
  47. package/lib/OwneraAPI/oss-api/__tests__/ossQueryEscaping.test.d.ts +1 -0
  48. package/lib/OwneraAPI/oss-api/__tests__/ossQueryEscaping.test.js +347 -0
  49. package/lib/OwneraAPI/oss-api/__tests__/ossQueryEscaping.test.js.map +1 -0
  50. package/lib/OwneraAPI/oss-api/filterUtils.d.ts +20 -0
  51. package/lib/OwneraAPI/oss-api/filterUtils.js +57 -5
  52. package/lib/OwneraAPI/oss-api/filterUtils.js.map +1 -1
  53. package/lib/OwneraAPI/oss-api/oss.js +155 -75
  54. package/lib/OwneraAPI/oss-api/oss.js.map +1 -1
  55. package/lib/OwneraAPI/oss-api/queryUtils.d.ts +1 -0
  56. package/lib/OwneraAPI/oss-api/queryUtils.js +6 -5
  57. package/lib/OwneraAPI/oss-api/queryUtils.js.map +1 -1
  58. package/lib/OwneraAPI/oss-api/queryValidation.d.ts +3 -1
  59. package/lib/OwneraAPI/oss-api/queryValidation.js +21 -2
  60. package/lib/OwneraAPI/oss-api/queryValidation.js.map +1 -1
  61. package/lib/OwneraAPI/payment-adapter-api/__tests__/updateBalance.test.d.ts +1 -0
  62. package/lib/OwneraAPI/payment-adapter-api/__tests__/updateBalance.test.js +42 -0
  63. package/lib/OwneraAPI/payment-adapter-api/__tests__/updateBalance.test.js.map +1 -0
  64. package/lib/OwneraAPI/payment-adapter-api/vanilla/__tests__/payouts.test.d.ts +1 -0
  65. package/lib/OwneraAPI/payment-adapter-api/vanilla/__tests__/payouts.test.js +73 -0
  66. package/lib/OwneraAPI/payment-adapter-api/vanilla/__tests__/payouts.test.js.map +1 -0
  67. package/lib/OwneraAPI/payment-adapter-api/vanilla/payouts.js +23 -11
  68. package/lib/OwneraAPI/payment-adapter-api/vanilla/payouts.js.map +1 -1
  69. package/lib/OwneraAPI/payment-adapter-api/vanilla/update-balance.d.ts +1 -1
  70. package/lib/OwneraAPI/payment-adapter-api/vanilla/update-balance.js +3 -1
  71. package/lib/OwneraAPI/payment-adapter-api/vanilla/update-balance.js.map +1 -1
  72. package/lib/OwneraAPI/utils.d.ts +39 -0
  73. package/lib/OwneraAPI/utils.js +125 -73
  74. package/lib/OwneraAPI/utils.js.map +1 -1
  75. package/lib/core/__tests__/consoleLogger.test.d.ts +1 -0
  76. package/lib/core/__tests__/consoleLogger.test.js +269 -0
  77. package/lib/core/__tests__/consoleLogger.test.js.map +1 -0
  78. package/lib/core/__tests__/createAssetNameUniqueness.test.d.ts +1 -0
  79. package/lib/core/__tests__/createAssetNameUniqueness.test.js +95 -0
  80. package/lib/core/__tests__/createAssetNameUniqueness.test.js.map +1 -0
  81. package/lib/core/__tests__/custodianPrecedence.test.d.ts +1 -0
  82. package/lib/core/__tests__/custodianPrecedence.test.js +683 -0
  83. package/lib/core/__tests__/custodianPrecedence.test.js.map +1 -0
  84. package/lib/core/__tests__/executeIntentSettlementAssets.test.d.ts +1 -0
  85. package/lib/core/__tests__/executeIntentSettlementAssets.test.js +128 -0
  86. package/lib/core/__tests__/executeIntentSettlementAssets.test.js.map +1 -0
  87. package/lib/core/__tests__/logException.test.d.ts +1 -0
  88. package/lib/core/__tests__/logException.test.js +49 -0
  89. package/lib/core/__tests__/logException.test.js.map +1 -0
  90. package/lib/core/__tests__/multiplyDecimalStrings.test.d.ts +1 -0
  91. package/lib/core/__tests__/multiplyDecimalStrings.test.js +37 -0
  92. package/lib/core/__tests__/multiplyDecimalStrings.test.js.map +1 -0
  93. package/lib/core/__tests__/settlementExecutionAmount.test.d.ts +1 -0
  94. package/lib/core/__tests__/settlementExecutionAmount.test.js +300 -0
  95. package/lib/core/__tests__/settlementExecutionAmount.test.js.map +1 -0
  96. package/lib/core/asset.js +21 -27
  97. package/lib/core/asset.js.map +1 -1
  98. package/lib/core/custodian.d.ts +30 -0
  99. package/lib/core/custodian.js +49 -0
  100. package/lib/core/custodian.js.map +1 -0
  101. package/lib/core/index.d.ts +1 -0
  102. package/lib/core/index.js +3 -1
  103. package/lib/core/index.js.map +1 -1
  104. package/lib/core/intents/__tests__/intentErrorCode.test.d.ts +1 -0
  105. package/lib/core/intents/__tests__/intentErrorCode.test.js +111 -0
  106. package/lib/core/intents/__tests__/intentErrorCode.test.js.map +1 -0
  107. package/lib/core/intents/__tests__/intentHandleReject.test.d.ts +1 -0
  108. package/lib/core/intents/__tests__/intentHandleReject.test.js +50 -0
  109. package/lib/core/intents/__tests__/intentHandleReject.test.js.map +1 -0
  110. package/lib/core/intents/__tests__/loanIntentAdditionalAccounts.test.d.ts +1 -0
  111. package/lib/core/intents/__tests__/loanIntentAdditionalAccounts.test.js +185 -0
  112. package/lib/core/intents/__tests__/loanIntentAdditionalAccounts.test.js.map +1 -0
  113. package/lib/core/intents/__tests__/loanIntentCustodianPrecedence.test.d.ts +1 -0
  114. package/lib/core/intents/__tests__/loanIntentCustodianPrecedence.test.js +85 -0
  115. package/lib/core/intents/__tests__/loanIntentCustodianPrecedence.test.js.map +1 -0
  116. package/lib/core/intents/__tests__/loanIntentMetadata.test.d.ts +1 -0
  117. package/lib/core/intents/__tests__/loanIntentMetadata.test.js +81 -0
  118. package/lib/core/intents/__tests__/loanIntentMetadata.test.js.map +1 -0
  119. package/lib/core/intents/__tests__/moveIntentSegregatedAccounts.test.d.ts +1 -0
  120. package/lib/core/intents/__tests__/moveIntentSegregatedAccounts.test.js +203 -0
  121. package/lib/core/intents/__tests__/moveIntentSegregatedAccounts.test.js.map +1 -0
  122. package/lib/core/intents/createIntent/createIntent.js +4 -3
  123. package/lib/core/intents/createIntent/createIntent.js.map +1 -1
  124. package/lib/core/intents/createIntent/createMoveIntentReq.d.ts +0 -1
  125. package/lib/core/intents/createIntent/createMoveIntentReq.js +15 -8
  126. package/lib/core/intents/createIntent/createMoveIntentReq.js.map +1 -1
  127. package/lib/core/intents/createIntent/helpers.d.ts +6 -2
  128. package/lib/core/intents/createIntent/helpers.js +27 -17
  129. package/lib/core/intents/createIntent/helpers.js.map +1 -1
  130. package/lib/core/intents/createLoanIntent.js +64 -19
  131. package/lib/core/intents/createLoanIntent.js.map +1 -1
  132. package/lib/core/intents/executeIntent.js +102 -41
  133. package/lib/core/intents/executeIntent.js.map +1 -1
  134. package/lib/core/intents/executeLoanIntent.js +48 -23
  135. package/lib/core/intents/executeLoanIntent.js.map +1 -1
  136. package/lib/core/intents/executeMoveIntent.js.map +1 -1
  137. package/lib/core/intents/executePrivateIntent.js +46 -13
  138. package/lib/core/intents/executePrivateIntent.js.map +1 -1
  139. package/lib/core/intents/executeRedemptionIntent.d.ts +1 -0
  140. package/lib/core/intents/executeRedemptionIntent.js +23 -9
  141. package/lib/core/intents/executeRedemptionIntent.js.map +1 -1
  142. package/lib/core/intents/executeTransferRequest.d.ts +5 -0
  143. package/lib/core/intents/executeTransferRequest.js +14 -3
  144. package/lib/core/intents/executeTransferRequest.js.map +1 -1
  145. package/lib/core/intents/getIntent.js +9 -0
  146. package/lib/core/intents/getIntent.js.map +1 -1
  147. package/lib/core/intents/transfer.js +7 -2
  148. package/lib/core/intents/transfer.js.map +1 -1
  149. package/lib/core/intents/updateMoveIntentReq.d.ts +4 -3
  150. package/lib/core/intents/updateMoveIntentReq.js +14 -12
  151. package/lib/core/intents/updateMoveIntentReq.js.map +1 -1
  152. package/lib/core/intents/utils.d.ts +15 -7
  153. package/lib/core/intents/utils.js +35 -26
  154. package/lib/core/intents/utils.js.map +1 -1
  155. package/lib/core/logger.js +128 -22
  156. package/lib/core/logger.js.map +1 -1
  157. package/lib/core/normalizers/__tests__/normalizeOperationResponse.test.d.ts +1 -0
  158. package/lib/core/normalizers/__tests__/normalizeOperationResponse.test.js +60 -0
  159. package/lib/core/normalizers/__tests__/normalizeOperationResponse.test.js.map +1 -0
  160. package/lib/core/normalizers/normalizeOperationResponse.d.ts +6 -0
  161. package/lib/core/normalizers/normalizeOperationResponse.js +4 -5
  162. package/lib/core/normalizers/normalizeOperationResponse.js.map +1 -1
  163. package/lib/core/sdk.d.ts +4 -0
  164. package/lib/core/sdk.js +2 -2
  165. package/lib/core/sdk.js.map +1 -1
  166. package/lib/core/user.d.ts +2 -2
  167. package/lib/core/user.js +6 -3
  168. package/lib/core/user.js.map +1 -1
  169. package/lib/core/utils.d.ts +17 -1
  170. package/lib/core/utils.js +75 -16
  171. package/lib/core/utils.js.map +1 -1
  172. package/lib/index.d.ts +1 -0
  173. package/lib/index.js +3 -1
  174. package/lib/index.js.map +1 -1
  175. package/lib/types/Core/Intents.d.ts +115 -3
  176. package/lib/types/Core/Intents.js +9 -0
  177. package/lib/types/Core/Intents.js.map +1 -1
  178. package/lib/types/Core/OwneraAPI.d.ts +21 -1
  179. package/lib/types/Core/User.d.ts +28 -3
  180. package/lib/types/InvestorAccounts/InvestorAccounts.d.ts +171 -0
  181. package/lib/types/InvestorAccounts/InvestorAccounts.js +35 -0
  182. package/lib/types/InvestorAccounts/InvestorAccounts.js.map +1 -0
  183. package/lib/types/InvestorAccounts/index.d.ts +1 -0
  184. package/lib/types/InvestorAccounts/index.js +18 -0
  185. package/lib/types/InvestorAccounts/index.js.map +1 -0
  186. package/lib/types/Operations/Operations.d.ts +11 -0
  187. package/lib/types/Oss/Oss.d.ts +18 -1
  188. package/lib/types/Oss/OssSchemas.d.ts +50 -0
  189. package/lib/types/Oss/OssSchemas.js.map +1 -1
  190. package/lib/types/Oss/utils.d.ts +32 -0
  191. package/lib/types/PaymentAdapter/PaymentAdapter.d.ts +7 -0
  192. package/lib/types/PaymentAdapter/index.d.ts +33 -1
  193. package/lib/types/Profiles/Intents.d.ts +24 -12
  194. package/lib/types/Profiles/Profiles.d.ts +46 -1
  195. package/lib/types/Tokens/Tokens.d.ts +109 -1
  196. package/lib/types/index.d.ts +1 -0
  197. package/lib/types/index.js +1 -0
  198. package/lib/types/index.js.map +1 -1
  199. package/package.json +1 -1
package/lib/core/utils.js CHANGED
@@ -3,39 +3,57 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generateIdempotencyKey = exports.getOrgFromResourceId = exports.generateNonce = exports.logException = void 0;
6
+ exports.multiplyDecimalStrings = exports.generateIdempotencyKey = exports.getOrgFromResourceId = exports.generateNonce = exports.logException = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const crypto_1 = require("crypto");
9
+ const describeBody = (data) => {
10
+ if (data && typeof data.pipe === 'function')
11
+ return '<stream>';
12
+ try {
13
+ return JSON.stringify(data);
14
+ }
15
+ catch (_a) {
16
+ return '<unserializable>';
17
+ }
18
+ };
9
19
  /**
10
20
  * Logs Exception
11
21
  *
12
22
  * @param error object that we want to print.
13
- * @param log function for logging
23
+ * @param log function for logging. Called as a plain function, so pass `(...input) => logger.error(...input)`
24
+ * rather than `logger.error`: a class-based logger's method loses its `this` otherwise.
14
25
  * @returns
15
26
  */
16
27
  const logException = (error, log) => {
17
- var _a;
18
- if (axios_1.default.isAxiosError(error) && error.response) {
19
- const config = error.config;
20
- const res = error.response;
21
- if (config) {
22
- log(`🔴 Axios Exception: ${config.method} ${config.url} ${res.status}:`);
23
- if (Array.isArray(res.data['errors'])) {
24
- for (const { code, message } of res.data['errors']) {
25
- log(`🔴 Code: ${code}`);
26
- log(`🔴 Message: ${message}`);
28
+ var _a, _b;
29
+ // Never throws: callers log from inside a request's catch before rejecting, so a throw here
30
+ // (a stream body's circular references, a null body) would leave their promise unsettled.
31
+ try {
32
+ if (axios_1.default.isAxiosError(error) && error.response) {
33
+ const config = error.config;
34
+ const res = error.response;
35
+ if (config) {
36
+ log(`🔴 Axios Exception: ${config.method} ${config.url} ${res.status}:`);
37
+ if (Array.isArray((_a = res.data) === null || _a === void 0 ? void 0 : _a.errors)) {
38
+ for (const { code, message } of res.data.errors) {
39
+ log(`🔴 Code: ${code}`);
40
+ log(`🔴 Message: ${message}`);
41
+ }
42
+ }
43
+ else {
44
+ log(`🔴 Details: ${describeBody(res.data)}`);
27
45
  }
28
46
  }
29
47
  else {
30
- log(`🔴 Details: ${JSON.stringify(res.data)}`);
48
+ log(`🔴 Axios Exception: ${res.status} - ${describeBody(res.data)}`);
31
49
  }
32
50
  }
33
51
  else {
34
- log(`🔴 Axios Exception: ${res.status} - ${JSON.stringify(res.data)}`);
52
+ log(`🔴 Exception: ${error === null || error === void 0 ? void 0 : error.message}, stack: ${(_b = error === null || error === void 0 ? void 0 : error.stack) === null || _b === void 0 ? void 0 : _b.slice(0, 200)}`);
35
53
  }
36
54
  }
37
- else {
38
- log(`🔴 Exception: ${error.message}, stack: ${(_a = error.stack) === null || _a === void 0 ? void 0 : _a.slice(0, 200)}`);
55
+ catch (_c) {
56
+ // logging is best-effort
39
57
  }
40
58
  };
41
59
  exports.logException = logException;
@@ -72,4 +90,45 @@ exports.getOrgFromResourceId = getOrgFromResourceId;
72
90
  */
73
91
  const generateIdempotencyKey = () => (0, exports.generateNonce)().toString('hex');
74
92
  exports.generateIdempotencyKey = generateIdempotencyKey;
93
+ /**
94
+ * Exact multiplication of two decimal strings, as decimal arithmetic — no floats anywhere.
95
+ *
96
+ * The router compares settlement amounts as DECIMAL STRINGS, exactly, so the SDK must never
97
+ * hand it a float-derived string: `Number('3') * Number('0.1')` is `"0.30000000000000004"`,
98
+ * which a stored `"0.3"` rejects (7305). Scaling both operands to integers, multiplying with
99
+ * BigInt and re-placing the point gives the true product with no rounding at any step.
100
+ *
101
+ * Output is canonical — no exponent, no trailing fractional zeros, no trailing point — so
102
+ * `"1050.00" x "1"` is `"1050"`, matching the router's own normalisation of the stored total.
103
+ * Note this makes the ARITHMETIC exact; it cannot make an inexact per-unit value divide a
104
+ * total evenly (quantity 11 of total 100 has no finite decimal unit). Callers who hold the
105
+ * total should send it directly rather than reconstructing it from a unit.
106
+ */
107
+ const multiplyDecimalStrings = (a, b) => {
108
+ const parse = (s) => {
109
+ const trimmed = s.trim();
110
+ // Unambiguous by construction: the digit run before the point is a single greedy
111
+ // `\d+` and the fraction only starts at a literal `.`, so there is exactly one way
112
+ // to match — no polynomial backtracking on long digit strings (CodeQL js/polynomial-redos).
113
+ if (!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(trimmed)) {
114
+ throw new Error(`multiplyDecimalStrings: not a plain decimal string: "${s}"`);
115
+ }
116
+ const negative = trimmed.startsWith('-');
117
+ const unsigned = trimmed.replace(/^[+-]/, '');
118
+ const [whole = '', frac = ''] = unsigned.split('.');
119
+ return { digits: BigInt((whole || '0') + frac), scale: frac.length, negative };
120
+ };
121
+ const x = parse(a);
122
+ const y = parse(b);
123
+ const product = x.digits * y.digits;
124
+ const scale = x.scale + y.scale;
125
+ let text = product.toString().padStart(scale + 1, '0');
126
+ if (scale > 0) {
127
+ // Re-place the point, then drop trailing fractional zeros and a bare trailing point.
128
+ text = `${text.slice(0, -scale)}.${text.slice(-scale)}`.replace(/0+$/, '').replace(/\.$/, '');
129
+ }
130
+ const negative = x.negative !== y.negative && product !== BigInt(0);
131
+ return `${negative ? '-' : ''}${text}`;
132
+ };
133
+ exports.multiplyDecimalStrings = multiplyDecimalStrings;
75
134
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/core/utils.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,mCAAqC;AAErC;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAAC,KAAU,EAAE,GAA8B,EAAE,EAAE;;IACzE,IAAI,eAAK,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QAChD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,MAAM,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC3B,IAAI,MAAM,EAAE,CAAC;YACX,GAAG,CAAC,uBAAuB,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;YACzE,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;gBACtC,KAAK,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAA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AC,CAAC,CAAC,CAAC;IACnB,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;IAChC,IAAI,IAAI,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IACvD,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACd,qFAAqF;QACrF,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChG,CAAC;IACD,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ,IAAI,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC;IACpE,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC;AACzC,CAAC,CAAC;AAzBW,QAAA,sBAAsB,0BAyBjC"}
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './core';
2
2
  export { default as OwneraAPI } from './OwneraAPI';
3
+ export { TRANSPORT_ERROR_CODE } from './OwneraAPI/utils';
3
4
  export * from './types';
4
5
  export * from './validators';
package/lib/index.js CHANGED
@@ -17,10 +17,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.OwneraAPI = void 0;
20
+ exports.TRANSPORT_ERROR_CODE = exports.OwneraAPI = void 0;
21
21
  __exportStar(require("./core"), exports);
22
22
  var OwneraAPI_1 = require("./OwneraAPI");
23
23
  Object.defineProperty(exports, "OwneraAPI", { enumerable: true, get: function () { return __importDefault(OwneraAPI_1).default; } });
24
+ var utils_1 = require("./OwneraAPI/utils");
25
+ Object.defineProperty(exports, "TRANSPORT_ERROR_CODE", { enumerable: true, get: function () { return utils_1.TRANSPORT_ERROR_CODE; } });
24
26
  __exportStar(require("./types"), exports);
25
27
  __exportStar(require("./validators"), exports);
26
28
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,yCAAmD;AAA1C,uHAAA,OAAO,OAAa;AAC7B,0CAAwB;AACxB,+CAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,yCAAmD;AAA1C,uHAAA,OAAO,OAAa;AAC7B,2CAAyD;AAAhD,6GAAA,oBAAoB,OAAA;AAC7B,0CAAwB;AACxB,+CAA6B"}
@@ -1,4 +1,5 @@
1
1
  import { FinIdAccount, FinP2PAsset, ManualSignaturePolicy, MovePresignedSignaturePolicy, SettlementAssetTerm, SettlementInstructionDestinationAccount, SettlementInstructionSourceAccount, FullSettlementTerm, TransferRequestIntent, IntentCreationSettlementTerm } from '../Profiles';
2
+ import { NetworkAccount } from '../InvestorAccounts';
2
3
  /**
3
4
  * Intent Interface allow to manage intent state (enable/disable/cancel)
4
5
  */
@@ -15,10 +16,20 @@ export interface IntentInterface {
15
16
  */
16
17
  disable: () => Promise<void>;
17
18
  /**
18
- * Cancel intent
19
+ * Cancel intent — the CREATOR withdrawing it.
19
20
  *
20
21
  */
21
22
  cancel: () => Promise<void>;
23
+ /**
24
+ * Reject intent — the RECEIVER refusing it, optionally saying why.
25
+ *
26
+ * Terminal. Only the intent's receiver may reject, and only while the intent is
27
+ * active; the router enforces both. A non-blank `reason` is persisted on the intent
28
+ * and readable by the counterparty as `rejectReason`. Requires a router with the
29
+ * explicit reject endpoint (finp2p-core#2649); older routers answer 404.
30
+ *
31
+ */
32
+ reject: (reason?: string) => Promise<void>;
22
33
  }
23
34
  export type SellingSettlementInstructionRequest = {
24
35
  destinationAccount: SettlementInstructionDestinationAccount[];
@@ -62,7 +73,60 @@ export interface CreateIntent {
62
73
  export interface LoanIntentSettlementAccountOverride {
63
74
  orgId: string;
64
75
  asset?: SettlementAssetTerm;
76
+ /**
77
+ * Custodian for THIS settlement account.
78
+ *
79
+ * Without it the settlement custodians are taken from `sourceCustodianOrgId` /
80
+ * `destinationCustodianOrgId`, which also drive the asset accounts — and they map
81
+ * to opposite sides in the two instructions (source → asset borrower but settlement
82
+ * LENDER). A cross-org loan whose two parties have different custodians is
83
+ * therefore inexpressible with those two fields alone: satisfying the asset legs
84
+ * necessarily inverts the settlement legs.
85
+ *
86
+ * Honoured on BOTH create and execute with the same precedence — this override,
87
+ * then `sourceCustodianOrgId` / `destinationCustodianOrgId`, then the SDK default —
88
+ * so the two calls cannot disagree about the stored custodian (a mismatch is the
89
+ * router's 7301). Optional and defaulted to today's behaviour, so existing callers
90
+ * are unaffected.
91
+ */
92
+ custodian?: {
93
+ orgId: string;
94
+ };
65
95
  }
96
+ /** An account on the loan's collateral that a loan policy may route the collateral through. */
97
+ export interface LoanIntentAdditionalAccount {
98
+ /** Profile id of the account owner. */
99
+ owner: string;
100
+ finId: string;
101
+ /** Empty falls back to the Sdk's default custodian. */
102
+ custodianOrgId: string;
103
+ /**
104
+ * Organization holding the account; it executes every hop sourced at the account.
105
+ * Absent or empty defaults to the organization of the collateral asset.
106
+ *
107
+ * An organization other than the collateral's has not been run end to end against an
108
+ * adapter: its hops execute at this organization with the collateral profile's ledger
109
+ * binding, so they only work if this organization's adapter reaches the same ledger
110
+ * state the collateral was credited in.
111
+ */
112
+ orgId?: string;
113
+ /** Wallet an on-chain leg needs, e.g. `{ type: 'walletAccount', address }`. */
114
+ networkAccount?: NetworkAccount;
115
+ }
116
+ export interface LoanIntentAdditionalAccounts {
117
+ /** Holds the borrower's collateral until the principal arrives. Router alias `lender_escrow`. */
118
+ openingLeg?: LoanIntentAdditionalAccount;
119
+ /** Holds the returning collateral until the repayment arrives. Router alias `borrower_escrow`. */
120
+ closingLeg?: LoanIntentAdditionalAccount;
121
+ }
122
+ /**
123
+ * The alias each leg is sent under: the name a loan policy references as
124
+ * contract_details.loan.additional_accounts.<alias> (finp2p-core #2708).
125
+ */
126
+ export declare const LOAN_ADDITIONAL_ACCOUNT_ALIASES: {
127
+ readonly openingLeg: "lender_escrow";
128
+ readonly closingLeg: "borrower_escrow";
129
+ };
66
130
  export interface CreateLoanIntent {
67
131
  amount: string;
68
132
  assetId: string;
@@ -90,6 +154,21 @@ export interface CreateLoanIntent {
90
154
  */
91
155
  settlementBorrowerAccount?: LoanIntentSettlementAccountOverride;
92
156
  settlementLenderAccount?: LoanIntentSettlementAccountOverride;
157
+ /** Optional custom metadata forwarded to the node (map of non-empty strings). */
158
+ metadata?: Record<string, string>;
159
+ /**
160
+ * The legs sent must match the aliases the loan policy uses: the router rejects
161
+ * creation (7332) when the matched policy routes through a leg that was not sent,
162
+ * or ignores a leg that was.
163
+ *
164
+ * Empty or absent sends none. Sending any needs a router on release v0.29 or later
165
+ * (finp2p-core #2709). Older routers do not reject the field: they accept the request
166
+ * and silently book a plain loan without the escrows, so check the router version
167
+ * before sending.
168
+ *
169
+ * A leg may not be the borrower's or the lender's own collateral account.
170
+ */
171
+ additionalAccounts?: LoanIntentAdditionalAccounts;
93
172
  }
94
173
  export interface IntentExecution {
95
174
  assetId: string;
@@ -112,6 +191,19 @@ export interface Transfer {
112
191
  destinationAccount: SettlementInstructionDestinationAccount;
113
192
  sourceAccount: SettlementInstructionSourceAccount;
114
193
  idempotency?: string;
194
+ /**
195
+ * FALLBACK custodian for the SOURCE side: used only when the account carries no
196
+ * `custodian.orgId` of its own — it does NOT override one that is present, unlike the
197
+ * identically-suffixed override fields on {@link IntentExecution}, hence the `Fallback` in the
198
+ * name. It takes precedence over the Sdk default {@link SdkOptions.custodianOrgId}. The two
199
+ * sides of a transfer are different investors, so each side has its own field — a single shared
200
+ * fallback would custody one of them at the wrong organization.
201
+ *
202
+ * Note the accounts are read at `account.custodian.orgId` — a `custody` key is ignored.
203
+ */
204
+ sourceFallbackCustodianOrgId?: string;
205
+ /** Same as {@link Transfer.sourceFallbackCustodianOrgId}, for the DESTINATION side. */
206
+ destinationFallbackCustodianOrgId?: string;
115
207
  }
116
208
  export interface LoanIntentExecutionData {
117
209
  assetId: string;
@@ -122,7 +214,25 @@ export interface LoanIntentExecutionData {
122
214
  sourceCustodianOrgId?: string;
123
215
  destinationCustodianOrgId?: string;
124
216
  settlementAssetId?: string;
217
+ /**
218
+ * Per-unit settlement value. When set (and `settlementTotalAmount` is not), the SDK sends
219
+ * `assetTerm.amount x settlementTermAmount`, computed with exact decimal arithmetic; a zero
220
+ * or non-decimal product is rejected. It takes precedence over the stored settlement term.
221
+ */
125
222
  settlementTermAmount?: string;
223
+ /**
224
+ * The settlement TOTAL for the execute payload, sent verbatim. Takes precedence over
225
+ * `settlementTermAmount` and the stored settlement term.
226
+ *
227
+ * When both overrides are omitted the SDK derives the amount from the intent's stored
228
+ * settlement term: a fullSettlement total as is, a partialSettlement unitValue x
229
+ * `assetTerm.amount` with exact decimal arithmetic. A caller that already holds the
230
+ * intent's stored total (an approving counterparty reading the intent back) should pass it
231
+ * here rather than `settlementTermAmount`: the router compares the execute amount against
232
+ * the stored total as an exact decimal value, and a total reconstructed from a rounded
233
+ * per-unit value can only match when the division was exact in the first place.
234
+ */
235
+ settlementTotalAmount?: string;
126
236
  observers?: string[];
127
237
  /**
128
238
  * Optional per-side overrides for the settlement instruction's borrower
@@ -235,8 +345,10 @@ export interface CreateMoveIntent {
235
345
  * each to its CAIP-19 wire shape, mirroring {@link CreateMoveIntent}. When
236
346
  * destinations are provided, the node requires at least one.
237
347
  * - `start` / `end` are optional epoch-millisecond window bounds.
238
- * - `status: 'Rejected'` rejects the intent (the only status the node accepts).
239
- * May be sent on its own, without destinations.
348
+ * - `status: 'Rejected'` rejects the intent (the only status the PATCH accepts).
349
+ * May be sent on its own, without destinations. To reject WITH a reason, or on a
350
+ * router that gates rejection on the receiver, use `profiles.rejectIntent` /
351
+ * {@link IntentInterface.reject} — the explicit reject endpoint.
240
352
  * - Custody-offered seg/pool fields are updatable, with **omit = keep, not
241
353
  * clear** semantics: the SDK never sends a clearing value for
242
354
  * `sourceToSegregatedAccount` when you omit it, so the intent's existing
@@ -1,3 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LOAN_ADDITIONAL_ACCOUNT_ALIASES = void 0;
4
+ /**
5
+ * The alias each leg is sent under: the name a loan policy references as
6
+ * contract_details.loan.additional_accounts.<alias> (finp2p-core #2708).
7
+ */
8
+ exports.LOAN_ADDITIONAL_ACCOUNT_ALIASES = {
9
+ openingLeg: 'lender_escrow',
10
+ closingLeg: 'borrower_escrow',
11
+ };
3
12
  //# sourceMappingURL=Intents.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Intents.js","sourceRoot":"","sources":["../../../src/types/Core/Intents.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"Intents.js","sourceRoot":"","sources":["../../../src/types/Core/Intents.ts"],"names":[],"mappings":";;;AAsJA;;;GAGG;AACU,QAAA,+BAA+B,GAAG;IAC7C,UAAU,EAAE,eAAe;IAC3B,UAAU,EAAE,iBAAiB;CACwC,CAAC"}
@@ -13,6 +13,7 @@ import { Operations } from '../Operations';
13
13
  import { Logger, LogLevel } from './Logger';
14
14
  import { Messages } from '../Messages';
15
15
  import { Ledgers, Custodies } from '../Ledgers';
16
+ import { InvestorAccounts } from '../InvestorAccounts';
16
17
  import { Policies } from '../Policies';
17
18
  import { PinningConfigData, CreatePinningConfigRequest, UpdatePinningConfigRequest, DeletePinningConfigRequest } from '../PinningConfig';
18
19
  import { RequestOptions } from '../Commons';
@@ -29,6 +30,7 @@ export interface OwneraAPIInterface {
29
30
  messages: Messages;
30
31
  ledgers: Ledgers;
31
32
  custodies: Custodies;
33
+ investorAccounts: InvestorAccounts;
32
34
  policies: Policies;
33
35
  approvalsConfig: ApprovalsConfig;
34
36
  data: DataApi;
@@ -39,7 +41,25 @@ export interface OwneraAPIInterface {
39
41
  }
40
42
  export interface OwneraAPICommonOptions {
41
43
  orgId: string;
42
- custodianOrgId: string;
44
+ /**
45
+ * Default custodian for this client — used whenever a call does not determine a custodian of
46
+ * its own.
47
+ *
48
+ * A custodian is decided per investor account. Each stamping site resolves it from two
49
+ * preferred inputs — the custodian already on the account (from the intent, or the account
50
+ * passed with the call) and a custodian passed with the call — with this default always the
51
+ * terminal step. Which preferred input wins depends on whose account is being stamped: when it
52
+ * is the executor's own account the per-call value wins, and when it is the counterparty's the
53
+ * intent's value is authoritative (see the README "Custodian org id" section for the per-flow
54
+ * order). Per-call fields: `user.addAccount({ custodianOrgId })`,
55
+ * `Transfer.source/destinationFallbackCustodianOrgId`, `IntentExecution.source/destinationCustodianOrgId`,
56
+ * `CreatePrimarySale.custodianOrgId`, `LoanIntent*.source/destinationCustodianOrgId`.
57
+ *
58
+ * Optional: omit it if every call supplies its own custodian. If a call falls through to this
59
+ * default and none is configured, it fails with a `CustodianOrgIdError` naming the flow — a
60
+ * custodian is required, and an empty value is rejected by the Router.
61
+ */
62
+ custodianOrgId?: string;
43
63
  owneraAPIAddress: string;
44
64
  owneraOssURL?: string;
45
65
  owneraFinp2pURL?: string;
@@ -11,16 +11,36 @@ import { MessageOperation } from '../Messages';
11
11
  import { IncomingMessage, OutgoingMessage } from '../Oss/utils';
12
12
  import { CoreRequestOptions } from './Options';
13
13
  import { AddAccountOperation, DataAccessPermission, FinP2PAsset, UpdateTransferRequestIntentRequest } from '../Profiles';
14
+ /**
15
+ * Options for {@link UserInterface.addAccount}.
16
+ */
17
+ export interface AddAccountOptions extends CoreRequestOptions {
18
+ /**
19
+ * Organization that custodies the new account. Defaults to the Sdk's
20
+ * {@link SdkOptions.custodianOrgId}.
21
+ *
22
+ * One of the two must be set: with neither, the call fails with a `CustodianOrgIdError`.
23
+ */
24
+ custodianOrgId?: string;
25
+ }
14
26
  /**
15
27
  * User Interface allow to interact with system user data, create certificates, intents, share the user, etc.
16
28
  */
17
29
  export interface UserInterface extends IdResponse {
18
30
  /**
19
- * Get user data
20
- * @param options Options. See {@link CoreRequestOptions}
31
+ * Create a finId account for this user, custodied at a given organization.
32
+ *
33
+ * The custodian is fixed at creation and cannot be changed afterwards, so prefer passing
34
+ * `custodianOrgId` explicitly. When omitted, the Sdk's default
35
+ * {@link SdkOptions.custodianOrgId} is used.
36
+ *
37
+ * The resolved custodian is echoed back as `response.custodyOrgId` — verify it matches
38
+ * what was requested.
39
+ *
40
+ * @param options Options. See {@link AddAccountOptions}
21
41
  * @returns Promise with object. See {@link AddAccountOperation}
22
42
  */
23
- addAccount: (options?: CoreRequestOptions) => Promise<AddAccountOperation>;
43
+ addAccount: (options?: AddAccountOptions) => Promise<AddAccountOperation>;
24
44
  /**
25
45
  * Get user data
26
46
  * @returns Promise with object. See {@link MappedUser}
@@ -175,8 +195,13 @@ export interface UserInterface extends IdResponse {
175
195
  executeTransferRequest: (data: {
176
196
  intentId: string;
177
197
  assetId: string;
198
+ destinationAssetId?: string;
178
199
  executionId?: string;
179
200
  observers?: string[];
201
+ /** Custodian of the SENDER's account — sender and receiver are two different owners. */
202
+ sourceCustodianOrgId?: string;
203
+ /** Custodian of the RECEIVER's account. */
204
+ destinationCustodianOrgId?: string;
180
205
  }, options?: CoreRequestOptions) => Promise<any>;
181
206
  /**
182
207
  * Update transfer request
@@ -0,0 +1,171 @@
1
+ import { Operation, RequestOptions } from '../Commons';
2
+ /**
3
+ * REST wire shape of the network-account union
4
+ * (`common-external-components.yaml#/components/schemas/networkAccount`).
5
+ * Discriminated by the literal `type` field. Distinct from the OSS read-model
6
+ * union, which discriminates by `__typename` and whose WalletAccount `type`
7
+ * carries the ledger discriminator (e.g. "ethereum"), not a literal.
8
+ */
9
+ export interface WalletNetworkAccount {
10
+ type: 'walletAccount';
11
+ /** Address of the wallet. */
12
+ address: string;
13
+ }
14
+ export interface Caip10NetworkAccount {
15
+ type: 'caip10Account';
16
+ /** CAIP-2 chain id, e.g. "eip155:1" — the same token used by CAIP-19 asset identifiers. */
17
+ network: string;
18
+ /** CAIP-10 account address on that chain. */
19
+ address: string;
20
+ }
21
+ export interface CustodialNetworkAccount {
22
+ type: 'custodialAccount';
23
+ /** Custody provider discriminator, e.g. "fireblocks". */
24
+ provider: string;
25
+ /** Provider-internal vault/account id (spans chains; not an on-chain address). */
26
+ vaultAccountId: string;
27
+ /** Optional narrowing to a chain/asset within the provider. */
28
+ assetId?: string;
29
+ }
30
+ export type NetworkAccount = WalletNetworkAccount | Caip10NetworkAccount | CustodialNetworkAccount;
31
+ /**
32
+ * Ledger-adapter-issued challenge for an investor network-account operation,
33
+ * surfaced on `GET /operations/status/{cid}` while the workflow is parked
34
+ * (`isCompleted: false`). Discriminated by `type`
35
+ * (`application-api.base.yaml#/components/schemas/networkAccountChallenge`).
36
+ * New variants may be added by the platform without breaking existing clients —
37
+ * render unknown types as an opaque blob rather than failing.
38
+ */
39
+ export interface SignatureTemplateChallenge {
40
+ type: 'signatureTemplate';
41
+ /** Hex-encoded payload the wallet must sign; submit via submitProof. */
42
+ payload: string;
43
+ }
44
+ export interface WalletConnectChallenge {
45
+ type: 'walletConnect';
46
+ /** WalletConnect URI to approve (fulfilled out-of-band). */
47
+ uri: string;
48
+ }
49
+ export interface DepositChallenge {
50
+ type: 'deposit';
51
+ fromAddress: string;
52
+ toAddress: string;
53
+ amount: string;
54
+ }
55
+ export interface FireblocksApprovalChallenge {
56
+ type: 'fireblocksApproval';
57
+ /** Fireblocks request id awaiting approval in the Fireblocks app. */
58
+ requestId: string;
59
+ }
60
+ export type NetworkAccountChallenge = SignatureTemplateChallenge | WalletConnectChallenge | DepositChallenge | FireblocksApprovalChallenge;
61
+ /**
62
+ * `GET /operations/status/{cid}` shape for investor-account workflows — they
63
+ * ride the `workflow` operation variant. `challenge` is present only while the
64
+ * operation is parked on a ledger-adapter challenge. The success result carries
65
+ * no payload (the bound account is read back from the OSS read model —
66
+ * `getUserNetworkAccounts`).
67
+ */
68
+ export interface InvestorAccountOperation extends Operation {
69
+ type?: 'workflow';
70
+ metadata?: Record<string, unknown>;
71
+ challenge?: NetworkAccountChallenge;
72
+ response?: {
73
+ type: 'error';
74
+ errors: {
75
+ code: number;
76
+ message: string;
77
+ }[];
78
+ } | {
79
+ type: 'success';
80
+ };
81
+ }
82
+ /** Request for `POST /profiles/investor/{investorId}/account/create` — the LA generates a wallet on the asset's network. */
83
+ export interface CreateInvestorAccountRequest {
84
+ investorId: string;
85
+ organizationId: string;
86
+ assetId: string;
87
+ }
88
+ /** Request for `POST /profiles/investor/{investorId}/account/bind` — caller supplies an external account they own. */
89
+ export interface BindInvestorAccountRequest extends CreateInvestorAccountRequest {
90
+ networkAccount: NetworkAccount;
91
+ /**
92
+ * Optional hex-encoded proof-of-ownership signature over the network
93
+ * account. The canonical flow is challenge-first — the vanilla LA always
94
+ * answers a bind with a signatureTemplate challenge (regular and proxy
95
+ * adapter alike) and ownership is proven via `submitProof` — so callers
96
+ * normally omit this. Supply it only for adapters that accept an upfront
97
+ * hint; final verification is via the LA challenge either way.
98
+ */
99
+ ownershipSignature?: string;
100
+ }
101
+ /** Request for `POST /profiles/investor/{investorId}/account/proof` — signatureTemplate challenges only. */
102
+ export interface SubmitInvestorAccountProofRequest {
103
+ investorId: string;
104
+ /** Correlation id of the account workflow awaiting the proof. */
105
+ cid: string;
106
+ /** Hex-encoded signature over the LA-issued signatureTemplate payload. */
107
+ ownershipSignature: string;
108
+ }
109
+ /** Request for `DELETE /profiles/investor/{investorId}/account/{accountId}` — unbind. */
110
+ export interface RemoveInvestorAccountRequest {
111
+ investorId: string;
112
+ /** LA-assigned account identifier (from the OSS read model). */
113
+ accountId: string;
114
+ }
115
+ /**
116
+ * Platform error codes for investor-account operations
117
+ * (`owneraio/pkg/errorcodes`, Account*Err). Surfaced on the operation's error
118
+ * response and on synchronous rejections.
119
+ */
120
+ export declare const INVESTOR_ACCOUNT_ERROR_CODES: {
121
+ /** 404 — investor resource not found for an account operation. */
122
+ readonly INVESTOR_NOT_FOUND: 7340;
123
+ /** 404 — asset not found or not accessible to the calling organization. */
124
+ readonly ASSET_NOT_FOUND: 7341;
125
+ /** 400 — the supplied network account payload failed validation. */
126
+ readonly INVALID_SHAPE: 7342;
127
+ /** 502 — the ledger adapter failed the account create/bind operation. */
128
+ readonly LA_FAILED: 7343;
129
+ /** 409 — the network account is already bound for this investor/asset/org. */
130
+ readonly ALREADY_BOUND: 7344;
131
+ /** 401 — ownership signature verification failed. */
132
+ readonly BAD_SIGNATURE: 7345;
133
+ /** 408 — the challenge was not fulfilled within the ledger-supplied expiry. */
134
+ readonly CHALLENGE_TIMEOUT: 7346;
135
+ /** 502 — the ledger adapter failed the unbind operation. */
136
+ readonly UNBIND_LA_FAILED: 7347;
137
+ /** 404 — the referenced account id or operation cid was not found. */
138
+ readonly ACCOUNT_NOT_FOUND: 7348;
139
+ /** 409 — the operation is not valid for the current workflow state. */
140
+ readonly INVALID_STATE: 7349;
141
+ /** 502 — the LA issued a challenge type the router cannot represent. */
142
+ readonly UNSUPPORTED_CHALLENGE: 7350;
143
+ /** 400 — an explicitly supplied account is not whitelisted for the investor on this org/asset. */
144
+ readonly NOT_WHITELISTED: 7351;
145
+ };
146
+ /**
147
+ * Investor network-account onboarding API
148
+ * (`/profiles/investor/{investorId}/account/*`, platform release-v0.28+).
149
+ *
150
+ * All four calls are asynchronous: they return `202 { cid, isCompleted: false }`
151
+ * and the workflow is tracked via `operations.investorAccountOperationStatus`.
152
+ * There is no list endpoint and no cancel (removed platform-wide — an unwanted
153
+ * operation can only expire); bound accounts are read from the OSS read model
154
+ * via `query.getUserNetworkAccounts`.
155
+ *
156
+ * `options.idempotency` (the `Idempotency-Key` header) is REQUIRED by the
157
+ * platform on every call — hence the non-optional `options` parameter — and
158
+ * MUST be a hex-encoded nonce: the router hex-decodes it and rejects anything
159
+ * else with 422 ("invalid idempotency key format"). Use
160
+ * `sdk.utils.generateIdempotencyKey()`, which produces exactly that.
161
+ */
162
+ export interface InvestorAccounts {
163
+ /** Create a new LA-generated account for the investor on (organizationId, assetId). */
164
+ createAccount(request: CreateInvestorAccountRequest, options: RequestOptions): Promise<Operation>;
165
+ /** Bind an existing caller-supplied account (challenge-first: ownership is proven via submitProof). */
166
+ bindAccount(request: BindInvestorAccountRequest, options: RequestOptions): Promise<Operation>;
167
+ /** Submit the signature for a pending signatureTemplate challenge. */
168
+ submitProof(request: SubmitInvestorAccountProofRequest, options: RequestOptions): Promise<Operation>;
169
+ /** Unbind a previously bound account. */
170
+ removeAccount(request: RemoveInvestorAccountRequest, options: RequestOptions): Promise<Operation>;
171
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.INVESTOR_ACCOUNT_ERROR_CODES = void 0;
4
+ /**
5
+ * Platform error codes for investor-account operations
6
+ * (`owneraio/pkg/errorcodes`, Account*Err). Surfaced on the operation's error
7
+ * response and on synchronous rejections.
8
+ */
9
+ exports.INVESTOR_ACCOUNT_ERROR_CODES = {
10
+ /** 404 — investor resource not found for an account operation. */
11
+ INVESTOR_NOT_FOUND: 7340,
12
+ /** 404 — asset not found or not accessible to the calling organization. */
13
+ ASSET_NOT_FOUND: 7341,
14
+ /** 400 — the supplied network account payload failed validation. */
15
+ INVALID_SHAPE: 7342,
16
+ /** 502 — the ledger adapter failed the account create/bind operation. */
17
+ LA_FAILED: 7343,
18
+ /** 409 — the network account is already bound for this investor/asset/org. */
19
+ ALREADY_BOUND: 7344,
20
+ /** 401 — ownership signature verification failed. */
21
+ BAD_SIGNATURE: 7345,
22
+ /** 408 — the challenge was not fulfilled within the ledger-supplied expiry. */
23
+ CHALLENGE_TIMEOUT: 7346,
24
+ /** 502 — the ledger adapter failed the unbind operation. */
25
+ UNBIND_LA_FAILED: 7347,
26
+ /** 404 — the referenced account id or operation cid was not found. */
27
+ ACCOUNT_NOT_FOUND: 7348,
28
+ /** 409 — the operation is not valid for the current workflow state. */
29
+ INVALID_STATE: 7349,
30
+ /** 502 — the LA issued a challenge type the router cannot represent. */
31
+ UNSUPPORTED_CHALLENGE: 7350,
32
+ /** 400 — an explicitly supplied account is not whitelisted for the investor on this org/asset. */
33
+ NOT_WHITELISTED: 7351,
34
+ };
35
+ //# sourceMappingURL=InvestorAccounts.js.map