@getpara/rest-sdk 3.19.0 → 3.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -135,6 +135,106 @@ methods as the read model: fetch the record immediately after a broadcast, backf
135
135
  reconcile your database against Para's persisted transaction state. See the Para webhook docs for signature
136
136
  verification and `rest.transaction.confirmed` / `rest.transaction.failed` payload examples.
137
137
 
138
+ ## Sponsored Transfers
139
+
140
+ Para enables gas sponsorship per partner through its existing admin-managed `featureFlags.restGasSponsorship` setting.
141
+ For enabled partners, eligible EVM token transfers return HTTP 202 with
142
+ `executionMode: 'sponsored'`, a `transactionId`, and a status. The response has no `signedTransaction`.
143
+ The SDK request is unchanged. Check `executionMode` before reading legacy response fields.
144
+
145
+ ```ts
146
+ // Save this key with your payout before the request. Reuse it if the response is lost.
147
+ const requestKey = crypto.randomUUID();
148
+ const result = await para.transfer(
149
+ wallet.id,
150
+ { to: recipient, value: '1000000', chainId, tokenAddress, kind: 'ERC20' },
151
+ { idempotencyKey: requestKey },
152
+ );
153
+
154
+ if (result.executionMode === 'sponsored') {
155
+ // Save the tracking ID, then poll this lookup from your background job.
156
+ const record = await para.getRestTransaction(wallet.id, result.transactionId);
157
+ console.log(record.status, record.stage, record.hash, record.actualGasCost);
158
+ } else {
159
+ console.log(result.signedTransaction, result.txHash);
160
+ }
161
+ ```
162
+
163
+ Sponsored requests require an idempotency key and a positive integer `value` in token base units. Sponsorship manages
164
+ gas and submission: omit nonce, transaction type and gas/fee overrides; omit `broadcast` or set it to `true`.
165
+ The server applies its configured supported chains and tokens. With the partner flag enabled, pausing global or
166
+ chain sponsorship rejects matching transfers rather than falling back to wallet-paid gas. Turning the partner flag
167
+ off routes new requests through the ordinary transfer path; existing sponsored operations retain their tracking IDs.
168
+
169
+ Poll `getRestTransaction` until the status is `confirmed`, `reverted`, or `failed`; stop polling for policy approval when
170
+ `stage` is `requires_action`. `submitted` with stage `included` is still awaiting receipt verification. `submission_unknown` means
171
+ the provider may have received the operation. `delivery_unverified` means the operation was included but token delivery
172
+ needs reconciliation; neither stage is a reason to send again. Reuse the original request and key to recover a lost
173
+ response, and resume polling the original tracking ID. The SDK does not retry or poll automatically.
174
+
175
+ Conditional approval policies are not supported for sponsored transfers in this pilot.
176
+ After an existing policy review is approved, explicitly continue the same operation:
177
+
178
+ ```ts
179
+ await para.resumeRestTransaction(wallet.id, transactionId, { reviewId });
180
+ ```
181
+
182
+ Resume accepts a review ID, not a new transfer. Repeating `transfer` with the original key only retrieves the existing
183
+ operation and does not resume it. `userOperationHash` identifies the sponsored operation; `txHash` on the transfer
184
+ response and `hash` in transaction history identify its on-chain transaction once included. `actualGasCost` is a decimal
185
+ string in the chain's native-token base units after settlement, including included reverts. Keep it as a string or
186
+ convert it to `bigint`, not `number`. Use `getRestTransaction()` for sponsorship stage, review details, user-operation hash,
187
+ and settled gas cost; `listRestTransactions()` returns transaction summaries. Fetch persisted status to reconcile missed webhooks.
188
+
189
+ ## On-Ramp Purchases
190
+
191
+ `getOnRampPurchase` looks up a fiat on-ramp purchase by the id the SDK reports on the `ONRAMP_LAUNCHED` event — the
192
+ same id that arrives as `purchaseId` on the `onramp.completed` webhook.
193
+
194
+ ```ts
195
+ const purchase = await para.getOnRampPurchase(purchaseId);
196
+
197
+ if (purchase.status === 'FINISHED') {
198
+ console.log(purchase.transactionHash, purchase.asset.symbol, purchase.assetQuantity);
199
+ }
200
+ ```
201
+
202
+ The response is the `onramp.completed` payload plus a lifecycle `status`. A purchase that hasn't settled returns
203
+ partial data — `transactionHash` and `completedAt` are `null` until `status` is `FINISHED` — so branch on `status`
204
+ rather than inferring completion from the hash, and treat an unrecognized status as non-terminal.
205
+
206
+ As with transaction history, webhooks are the preferred way to learn about settlement; use this to backfill a missed
207
+ delivery or to check a purchase still in flight. Check `testMode` before recording a purchase in production
208
+ accounting: test purchases run a real quote but are never charged.
209
+
210
+ ## Webhook Types
211
+
212
+ Webhooks are delivered to your backend, so the types for handling them live here. `ParaWebhookEvent` is a
213
+ discriminated union, so a `switch` on `event.type` narrows `event.data` to that event's payload:
214
+
215
+ ```ts
216
+ import { WebhookEventType, type ParaWebhookEvent } from '@getpara/rest-sdk';
217
+
218
+ export function handleParaWebhook(event: ParaWebhookEvent) {
219
+ switch (event.type) {
220
+ case WebhookEventType.ONRAMP_COMPLETED:
221
+ // event.data is OnrampCompletedPayload
222
+ return credit(event.data.purchaseId, event.data.transactionHash);
223
+ case WebhookEventType.REST_TRANSACTION_CONFIRMED:
224
+ // event.data is RestTransactionConfirmedPayload
225
+ return settle(event.data.transactionId, event.data.hash);
226
+ }
227
+ }
228
+ ```
229
+
230
+ Use `ParaWebhookEvent` rather than the generic `WebhookEvent`, whose `type` and `data` are uncorrelated — `data`
231
+ stays the union of every payload regardless of `type`. Individual payload interfaces (`OnrampCompletedPayload`,
232
+ `WalletCreatedPayload`, …), the `WebhookEventPayloadMap`, and `ParaWebhookPayload<K>` are exported too, for typing a
233
+ single-event handler.
234
+
235
+ These are types only — this package does not receive, verify, or dispatch webhooks. Verify the signature on the raw
236
+ request body before trusting a delivery; see the Para webhook docs for the procedure.
237
+
138
238
  ## Adapters
139
239
 
140
240
  ```ts
package/dist/cjs/index.js CHANGED
@@ -14,6 +14,7 @@ var __copyProps = (to, from, except, desc) => {
14
14
  }
15
15
  return to;
16
16
  };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
  var __async = (__this, __arguments, generator) => {
19
20
  return new Promise((resolve, reject) => {
@@ -40,10 +41,15 @@ __export(index_exports, {
40
41
  ParaRestClient: () => ParaRestClient,
41
42
  ParaRestError: () => ParaRestError,
42
43
  ParaRestSerializationError: () => ParaRestSerializationError,
43
- ParaRestValidationError: () => ParaRestValidationError,
44
+ ParaRestValidationError: () => import_validation2.ParaRestValidationError,
44
45
  toRestJson: () => toRestJson
45
46
  });
46
47
  module.exports = __toCommonJS(index_exports);
48
+ var import_permissions = require("./permissions.js");
49
+ var import_validation = require("./validation.js");
50
+ __reExport(index_exports, require("./permissions.js"), module.exports);
51
+ __reExport(index_exports, require("./webhooks.js"), module.exports);
52
+ var import_validation2 = require("./validation.js");
47
53
  class ParaRestError extends Error {
48
54
  constructor({
49
55
  status,
@@ -67,12 +73,6 @@ class ParaRestSerializationError extends Error {
67
73
  this.name = "ParaRestSerializationError";
68
74
  }
69
75
  }
70
- class ParaRestValidationError extends Error {
71
- constructor(message) {
72
- super(message);
73
- this.name = "ParaRestValidationError";
74
- }
75
- }
76
76
  const BASE_URLS = {
77
77
  PROD: "https://api.getpara.com",
78
78
  BETA: "https://api.beta.getpara.com",
@@ -103,11 +103,12 @@ function toRestJson(body) {
103
103
  }
104
104
  return json;
105
105
  }
106
- class ParaRestClient {
106
+ class ParaRestClient extends import_permissions.RestPermissionsClient {
107
107
  constructor(options) {
108
108
  var _a, _b, _c;
109
+ super();
109
110
  if (!options.apiKey) {
110
- throw new ParaRestValidationError("apiKey is required");
111
+ throw new import_validation.ParaRestValidationError("apiKey is required");
111
112
  }
112
113
  this.apiKey = options.apiKey;
113
114
  this.baseUrl = resolveBaseUrl((_a = options.env) != null ? _a : "PROD");
@@ -115,10 +116,10 @@ class ParaRestClient {
115
116
  this.requestIdGenerator = (_c = options.requestIdGenerator) != null ? _c : defaultRequestId;
116
117
  }
117
118
  createWallet(body, options) {
118
- requireBody(body, "body");
119
- requireNonEmpty(body.type, "type");
120
- requireNonEmpty(body.userIdentifier, "userIdentifier");
121
- requireNonEmpty(body.userIdentifierType, "userIdentifierType");
119
+ (0, import_validation.requireBody)(body, "body");
120
+ (0, import_validation.requireNonEmpty)(body.type, "type");
121
+ (0, import_validation.requireNonEmpty)(body.userIdentifier, "userIdentifier");
122
+ (0, import_validation.requireNonEmpty)(body.userIdentifierType, "userIdentifierType");
122
123
  return this.request("POST", "/v1/wallets", { body, options, expectedStatus: 201 });
123
124
  }
124
125
  listWallets(query, options) {
@@ -128,16 +129,16 @@ class ParaRestClient {
128
129
  return this.request("GET", `/v1/wallets/${walletPath(walletId)}`, { options });
129
130
  }
130
131
  updateWalletIdentifier(walletId, body, options) {
131
- requireNonEmpty(walletId, "walletId");
132
- requireBody(body, "body");
133
- requireNonEmpty(body.userIdentifier, "userIdentifier");
134
- requireNonEmpty(body.userIdentifierType, "userIdentifierType");
132
+ (0, import_validation.requireNonEmpty)(walletId, "walletId");
133
+ (0, import_validation.requireBody)(body, "body");
134
+ (0, import_validation.requireNonEmpty)(body.userIdentifier, "userIdentifier");
135
+ (0, import_validation.requireNonEmpty)(body.userIdentifierType, "userIdentifierType");
135
136
  return this.request("PATCH", `/v1/wallets/${walletPath(walletId)}`, { body, options });
136
137
  }
137
138
  migrateShare(walletId, body, options) {
138
- requireNonEmpty(walletId, "walletId");
139
- requireBody(body, "body");
140
- requireNonEmpty(body.encryptedPayload, "encryptedPayload");
139
+ (0, import_validation.requireNonEmpty)(walletId, "walletId");
140
+ (0, import_validation.requireBody)(body, "body");
141
+ (0, import_validation.requireNonEmpty)(body.encryptedPayload, "encryptedPayload");
141
142
  return this.request("POST", `/v1/wallets/${walletPath(walletId)}/migrate-share`, { body, options });
142
143
  }
143
144
  getEnclavePublicKey(options) {
@@ -147,67 +148,67 @@ class ParaRestClient {
147
148
  return this.request("GET", `/v1/wallets/${walletPath(walletId)}/balance${queryString(query)}`, { options });
148
149
  }
149
150
  signRaw(walletId, body, options) {
150
- requireNonEmpty(walletId, "walletId");
151
- requireBody(body, "body");
152
- requireNonEmpty(body.data, "data");
151
+ (0, import_validation.requireNonEmpty)(walletId, "walletId");
152
+ (0, import_validation.requireBody)(body, "body");
153
+ (0, import_validation.requireNonEmpty)(body.data, "data");
153
154
  return this.request("POST", `/v1/wallets/${walletPath(walletId)}/sign-raw`, { body, options });
154
155
  }
155
156
  signMessage(walletId, body, options) {
156
- requireNonEmpty(walletId, "walletId");
157
- requireBody(body, "body");
158
- requireNonEmpty(body.message, "message");
157
+ (0, import_validation.requireNonEmpty)(walletId, "walletId");
158
+ (0, import_validation.requireBody)(body, "body");
159
+ (0, import_validation.requireNonEmpty)(body.message, "message");
159
160
  return this.request("POST", `/v1/wallets/${walletPath(walletId)}/sign-message`, { body, options });
160
161
  }
161
162
  signTransaction(walletId, body, options) {
162
- requireNonEmpty(walletId, "walletId");
163
- requireBody(body, "body");
163
+ (0, import_validation.requireNonEmpty)(walletId, "walletId");
164
+ (0, import_validation.requireBody)(body, "body");
164
165
  if (body.transaction == null || body.transaction === "") {
165
- throw new ParaRestValidationError("transaction is required");
166
+ throw new import_validation.ParaRestValidationError("transaction is required");
166
167
  }
167
168
  return this.request("POST", `/v1/wallets/${walletPath(walletId)}/sign-transaction`, { body, options });
168
169
  }
169
170
  signTypedData(walletId, body, options) {
170
- requireNonEmpty(walletId, "walletId");
171
- requireBody(body, "body");
172
- requireBody(body.typedData, "typedData");
173
- requireBody(body.typedData.domain, "typedData.domain");
174
- requireBody(body.typedData.types, "typedData.types");
175
- requireNonEmpty(body.typedData.primaryType, "typedData.primaryType");
176
- requireBody(body.typedData.message, "typedData.message");
171
+ (0, import_validation.requireNonEmpty)(walletId, "walletId");
172
+ (0, import_validation.requireBody)(body, "body");
173
+ (0, import_validation.requireBody)(body.typedData, "typedData");
174
+ (0, import_validation.requireBody)(body.typedData.domain, "typedData.domain");
175
+ (0, import_validation.requireBody)(body.typedData.types, "typedData.types");
176
+ (0, import_validation.requireNonEmpty)(body.typedData.primaryType, "typedData.primaryType");
177
+ (0, import_validation.requireBody)(body.typedData.message, "typedData.message");
177
178
  return this.request("POST", `/v1/wallets/${walletPath(walletId)}/sign-typed-data`, { body, options });
178
179
  }
179
180
  signAuthorization(walletId, body, options) {
180
- requireNonEmpty(walletId, "walletId");
181
- requireBody(body, "body");
182
- requireBody(body.authorization, "authorization");
181
+ (0, import_validation.requireNonEmpty)(walletId, "walletId");
182
+ (0, import_validation.requireBody)(body, "body");
183
+ (0, import_validation.requireBody)(body.authorization, "authorization");
183
184
  if (!body.authorization.address && !body.authorization.contractAddress) {
184
- throw new ParaRestValidationError("authorization.address is required");
185
+ throw new import_validation.ParaRestValidationError("authorization.address is required");
185
186
  }
186
187
  if (body.authorization.chainId == null) {
187
- throw new ParaRestValidationError("authorization.chainId is required");
188
+ throw new import_validation.ParaRestValidationError("authorization.chainId is required");
188
189
  }
189
190
  if (body.authorization.nonce == null) {
190
- throw new ParaRestValidationError("authorization.nonce is required");
191
+ throw new import_validation.ParaRestValidationError("authorization.nonce is required");
191
192
  }
192
193
  return this.request("POST", `/v1/wallets/${walletPath(walletId)}/sign-authorization`, { body, options });
193
194
  }
194
195
  transfer(walletId, body, options) {
195
- requireNonEmpty(walletId, "walletId");
196
- requireBody(body, "body");
197
- requireNonEmpty(body.to, "to");
198
- requireNonEmpty(body.value, "value");
196
+ (0, import_validation.requireNonEmpty)(walletId, "walletId");
197
+ (0, import_validation.requireBody)(body, "body");
198
+ (0, import_validation.requireNonEmpty)(body.to, "to");
199
+ (0, import_validation.requireNonEmpty)(body.value, "value");
199
200
  return this.request("POST", `/v1/wallets/${walletPath(walletId)}/transfer`, { body, options });
200
201
  }
201
202
  estimateFee(walletId, body, options) {
202
- requireNonEmpty(walletId, "walletId");
203
- requireBody(body, "body");
204
- requireNonEmpty(body.to, "to");
205
- requireNonEmpty(body.value, "value");
203
+ (0, import_validation.requireNonEmpty)(walletId, "walletId");
204
+ (0, import_validation.requireBody)(body, "body");
205
+ (0, import_validation.requireNonEmpty)(body.to, "to");
206
+ (0, import_validation.requireNonEmpty)(body.value, "value");
206
207
  return this.request("POST", `/v1/wallets/${walletPath(walletId)}/estimate-fee`, { body, options });
207
208
  }
208
209
  requestFaucet(body, options) {
209
- requireBody(body, "body");
210
- requireNonEmpty(body.walletId, "walletId");
210
+ (0, import_validation.requireBody)(body, "body");
211
+ (0, import_validation.requireNonEmpty)(body.walletId, "walletId");
211
212
  return this.request("POST", "/faucet", { body, options });
212
213
  }
213
214
  listRestTransactions(walletId, query, options) {
@@ -216,12 +217,32 @@ class ParaRestClient {
216
217
  getRestTransaction(walletId, transactionId, options) {
217
218
  return this.request(
218
219
  "GET",
219
- `/v1/wallets/${walletPath(walletId)}/transactions/${pathSegment("transactionId", transactionId)}`,
220
+ `/v1/wallets/${walletPath(walletId)}/transactions/${(0, import_validation.pathSegment)("transactionId", transactionId)}`,
220
221
  {
221
222
  options
222
223
  }
223
224
  );
224
225
  }
226
+ resumeRestTransaction(walletId, transactionId, body, options) {
227
+ (0, import_validation.requireBody)(body, "body");
228
+ (0, import_validation.requireNonEmpty)(body.reviewId, "reviewId");
229
+ return this.request(
230
+ "POST",
231
+ `/v1/wallets/${walletPath(walletId)}/transactions/${(0, import_validation.pathSegment)("transactionId", transactionId)}/resume`,
232
+ { body, options }
233
+ );
234
+ }
235
+ /**
236
+ * Look up a fiat on-ramp purchase by id — the id the SDK reports on the `ONRAMP_LAUNCHED` event, and the
237
+ * `purchaseId` on the `onramp.completed` webhook. Use it to reconcile a delivery you missed, or to check one still in flight.
238
+ *
239
+ * Scoped to the calling partner: a purchase that doesn't exist, is malformed, or belongs to another partner all
240
+ * raise an identical `ParaRestError` with status 404, so a 404 never confirms that some other partner's purchase
241
+ * id exists.
242
+ */
243
+ getOnRampPurchase(purchaseId, options) {
244
+ return this.request("GET", `/v1/onramp/purchases/${(0, import_validation.pathSegment)("purchaseId", purchaseId)}`, { options });
245
+ }
225
246
  request(_0, _1) {
226
247
  return __async(this, arguments, function* (method, path, {
227
248
  body,
@@ -267,14 +288,14 @@ class ParaRestClient {
267
288
  function resolveBaseUrl(env) {
268
289
  const baseUrl = typeof env === "string" ? BASE_URLS[env] : env.baseUrl;
269
290
  if (!baseUrl) {
270
- throw new ParaRestValidationError("baseUrl is required");
291
+ throw new import_validation.ParaRestValidationError("baseUrl is required");
271
292
  }
272
293
  return baseUrl.replace(/\/+$/, "");
273
294
  }
274
295
  function getGlobalFetch() {
275
296
  const fetchImpl = globalThis.fetch;
276
297
  if (!fetchImpl) {
277
- throw new ParaRestValidationError("fetch is required in this runtime; pass options.fetch");
298
+ throw new import_validation.ParaRestValidationError("fetch is required in this runtime; pass options.fetch");
278
299
  }
279
300
  return fetchImpl;
280
301
  }
@@ -286,21 +307,7 @@ function defaultRequestId() {
286
307
  return `req_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;
287
308
  }
288
309
  function walletPath(walletId) {
289
- return pathSegment("walletId", walletId);
290
- }
291
- function pathSegment(name, value) {
292
- requireNonEmpty(value, name);
293
- return encodeURIComponent(value);
294
- }
295
- function requireBody(value, name) {
296
- if (!isRecord(value)) {
297
- throw new ParaRestValidationError(`${name} is required`);
298
- }
299
- }
300
- function requireNonEmpty(value, name) {
301
- if (value == null || value === "") {
302
- throw new ParaRestValidationError(`${name} is required`);
303
- }
310
+ return (0, import_validation.pathSegment)("walletId", walletId);
304
311
  }
305
312
  function queryString(query) {
306
313
  if (!query) return "";
@@ -335,5 +342,7 @@ function stringField(value) {
335
342
  ParaRestError,
336
343
  ParaRestSerializationError,
337
344
  ParaRestValidationError,
338
- toRestJson
345
+ toRestJson,
346
+ ...require("./permissions.js"),
347
+ ...require("./webhooks.js")
339
348
  });
@@ -0,0 +1,219 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __objRest = (source, exclude) => {
20
+ var target = {};
21
+ for (var prop in source)
22
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
23
+ target[prop] = source[prop];
24
+ if (source != null && __getOwnPropSymbols)
25
+ for (var prop of __getOwnPropSymbols(source)) {
26
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
27
+ target[prop] = source[prop];
28
+ }
29
+ return target;
30
+ };
31
+ var __export = (target, all) => {
32
+ for (var name in all)
33
+ __defProp(target, name, { get: all[name], enumerable: true });
34
+ };
35
+ var __copyProps = (to, from, except, desc) => {
36
+ if (from && typeof from === "object" || typeof from === "function") {
37
+ for (let key of __getOwnPropNames(from))
38
+ if (!__hasOwnProp.call(to, key) && key !== except)
39
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
40
+ }
41
+ return to;
42
+ };
43
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
44
+ var permissions_exports = {};
45
+ __export(permissions_exports, {
46
+ RestPermissionsClient: () => RestPermissionsClient
47
+ });
48
+ module.exports = __toCommonJS(permissions_exports);
49
+ var import_validation = require("./validation.js");
50
+ const basePath = "/v1/permissions-v2";
51
+ function queryString(query) {
52
+ if (!query) return "";
53
+ const params = new URLSearchParams();
54
+ for (const [key, value] of Object.entries(query)) {
55
+ if (value != null) params.set(key, String(value));
56
+ }
57
+ const serialized = params.toString();
58
+ return serialized ? `?${serialized}` : "";
59
+ }
60
+ function requirementPath(reference) {
61
+ return `${basePath}/authorization-scopes/${(0, import_validation.pathSegment)(
62
+ "authorizationScopeId",
63
+ reference.authorizationScopeId
64
+ )}/policies/${(0, import_validation.pathSegment)(
65
+ "policyId",
66
+ reference.policyId
67
+ )}/versions/${(0, import_validation.pathSegment)("policyVersion", reference.policyVersion)}/requirements/${(0, import_validation.pathSegment)(
68
+ "requirementId",
69
+ reference.requirementId
70
+ )}`;
71
+ }
72
+ class RestPermissionsClient {
73
+ listPartnerPolicies(options) {
74
+ return this.request("GET", `${basePath}/policies`, { options });
75
+ }
76
+ getPartnerPolicy(policyId, options) {
77
+ return this.request("GET", `${basePath}/policies/${(0, import_validation.pathSegment)("policyId", policyId)}`, { options });
78
+ }
79
+ listPartnerPolicyVersions(policyId, options) {
80
+ return this.request("GET", `${basePath}/policies/${(0, import_validation.pathSegment)("policyId", policyId)}/versions`, { options });
81
+ }
82
+ listUserPolicyConsents(userId, context, options) {
83
+ return this.request(
84
+ "GET",
85
+ `${basePath}/users/${(0, import_validation.pathSegment)("userId", userId)}/delegation-consents${queryString(context)}`,
86
+ { options }
87
+ );
88
+ }
89
+ getUserPolicyConsent(userId, policyId, context, options) {
90
+ return this.request(
91
+ "GET",
92
+ `${basePath}/users/${(0, import_validation.pathSegment)("userId", userId)}/delegation-consents/${(0, import_validation.pathSegment)(
93
+ "policyId",
94
+ policyId
95
+ )}${queryString(context)}`,
96
+ { options }
97
+ );
98
+ }
99
+ listUserAdjustablePolicies(userId, options) {
100
+ return this.request("GET", `${basePath}/users/${(0, import_validation.pathSegment)("userId", userId)}/user-parameters`, { options });
101
+ }
102
+ getUserPolicyParameters(userId, policyId, options) {
103
+ return this.request(
104
+ "GET",
105
+ `${basePath}/users/${(0, import_validation.pathSegment)("userId", userId)}/user-parameters/${(0, import_validation.pathSegment)("policyId", policyId)}`,
106
+ { options }
107
+ );
108
+ }
109
+ listUserPolicyParameterHistory(userId, policyId, query, options) {
110
+ return this.request(
111
+ "GET",
112
+ `${basePath}/users/${(0, import_validation.pathSegment)("userId", userId)}/user-parameters/${(0, import_validation.pathSegment)(
113
+ "policyId",
114
+ policyId
115
+ )}/history${queryString(query)}`,
116
+ { options }
117
+ );
118
+ }
119
+ listConfigurableApprovalRequirements(authorizationScopeId, options) {
120
+ return this.request(
121
+ "GET",
122
+ `${basePath}/authorization-scopes/${(0, import_validation.pathSegment)("authorizationScopeId", authorizationScopeId)}/requirements`,
123
+ { options }
124
+ );
125
+ }
126
+ getConfigurableApprovalRequirement(reference, options) {
127
+ return this.request("GET", requirementPath(reference), { options });
128
+ }
129
+ getApprovalConfiguration(reference, options) {
130
+ return this.request("GET", `${requirementPath(reference)}/configuration`, { options });
131
+ }
132
+ getEffectiveApprovalConfiguration(reference, options) {
133
+ return this.request("GET", `${requirementPath(reference)}/configuration/effective`, { options });
134
+ }
135
+ updateApprovalConfiguration(reference, body, options) {
136
+ return this.request("PUT", `${requirementPath(reference)}/configuration`, { body, options });
137
+ }
138
+ resetApprovalConfiguration(reference, expectedRevision, options) {
139
+ return this.updateApprovalConfiguration(reference, { expectedRevision, values: {} }, options);
140
+ }
141
+ listApprovalConfigurationHistory(reference, options) {
142
+ return this.request("GET", `${requirementPath(reference)}/configuration/history`, { options });
143
+ }
144
+ getUserApprovalAssignments(authorizationScopeId, userId, options) {
145
+ return this.request(
146
+ "GET",
147
+ `${basePath}/authorization-scopes/${(0, import_validation.pathSegment)("authorizationScopeId", authorizationScopeId)}/users/${(0, import_validation.pathSegment)(
148
+ "userId",
149
+ userId
150
+ )}/assignments`,
151
+ { options }
152
+ );
153
+ }
154
+ listAuthorizationScopeMembers(authorizationScopeId, query, options) {
155
+ return this.request(
156
+ "GET",
157
+ `${basePath}/authorization-scopes/${(0, import_validation.pathSegment)("authorizationScopeId", authorizationScopeId)}/members${queryString(
158
+ query
159
+ )}`,
160
+ { options }
161
+ );
162
+ }
163
+ replaceUserApprovalAssignments(authorizationScopeId, userId, body, options) {
164
+ return this.request(
165
+ "PUT",
166
+ `${basePath}/authorization-scopes/${(0, import_validation.pathSegment)("authorizationScopeId", authorizationScopeId)}/users/${(0, import_validation.pathSegment)(
167
+ "userId",
168
+ userId
169
+ )}/assignments`,
170
+ { body, options }
171
+ );
172
+ }
173
+ listUserApprovalAssignmentHistory(authorizationScopeId, userId, options) {
174
+ return this.request(
175
+ "GET",
176
+ `${basePath}/authorization-scopes/${(0, import_validation.pathSegment)("authorizationScopeId", authorizationScopeId)}/users/${(0, import_validation.pathSegment)(
177
+ "userId",
178
+ userId
179
+ )}/assignments/history`,
180
+ { options }
181
+ );
182
+ }
183
+ getWalletAuthorizationScope(walletId, options) {
184
+ return this.request("GET", `${basePath}/wallets/${(0, import_validation.pathSegment)("walletId", walletId)}/authorization-scope`, { options });
185
+ }
186
+ setWalletAuthorizationScope(walletId, body, options) {
187
+ return this.request("PUT", `${basePath}/wallets/${(0, import_validation.pathSegment)("walletId", walletId)}/authorization-scope`, {
188
+ body,
189
+ options
190
+ });
191
+ }
192
+ listWalletAuthorizationScopeHistory(walletId, query, options) {
193
+ return this.request(
194
+ "GET",
195
+ `${basePath}/wallets/${(0, import_validation.pathSegment)("walletId", walletId)}/authorization-scope/history${queryString(query)}`,
196
+ { options }
197
+ );
198
+ }
199
+ listPartnerApprovalCases(query, options) {
200
+ return this.request("GET", `${basePath}/approval-cases${queryString(query)}`, { options });
201
+ }
202
+ getPartnerApprovalCase(caseId, options) {
203
+ return this.request("GET", `${basePath}/approval-cases/${(0, import_validation.pathSegment)("caseId", caseId)}`, { options });
204
+ }
205
+ getPartnerPolicyUsage(policyId, context, options) {
206
+ const _a = context, { userId, walletId } = _a, query = __objRest(_a, ["userId", "walletId"]);
207
+ const subjectPath = userId ? `users/${(0, import_validation.pathSegment)("userId", userId)}` : `wallets/${(0, import_validation.pathSegment)("walletId", walletId)}`;
208
+ const usageQuery = userId ? __spreadValues({ walletId }, query) : query;
209
+ return this.request(
210
+ "GET",
211
+ `${basePath}/${subjectPath}/policies/${(0, import_validation.pathSegment)("policyId", policyId)}/usage${queryString(usageQuery)}`,
212
+ { options }
213
+ );
214
+ }
215
+ }
216
+ // Annotate the CommonJS export names for ESM import in node:
217
+ 0 && (module.exports = {
218
+ RestPermissionsClient
219
+ });
@@ -0,0 +1,52 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var validation_exports = {};
19
+ __export(validation_exports, {
20
+ ParaRestValidationError: () => ParaRestValidationError,
21
+ pathSegment: () => pathSegment,
22
+ requireBody: () => requireBody,
23
+ requireNonEmpty: () => requireNonEmpty
24
+ });
25
+ module.exports = __toCommonJS(validation_exports);
26
+ class ParaRestValidationError extends Error {
27
+ constructor(message) {
28
+ super(message);
29
+ this.name = "ParaRestValidationError";
30
+ }
31
+ }
32
+ function requireBody(value, name) {
33
+ if (value == null || typeof value !== "object" || Array.isArray(value)) {
34
+ throw new ParaRestValidationError(`${name} is required`);
35
+ }
36
+ }
37
+ function requireNonEmpty(value, name) {
38
+ if (value == null || value === "") {
39
+ throw new ParaRestValidationError(`${name} is required`);
40
+ }
41
+ }
42
+ function pathSegment(name, value) {
43
+ requireNonEmpty(value, name);
44
+ return encodeURIComponent(value);
45
+ }
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ ParaRestValidationError,
49
+ pathSegment,
50
+ requireBody,
51
+ requireNonEmpty
52
+ });
@@ -0,0 +1,27 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var webhooks_exports = {};
19
+ __export(webhooks_exports, {
20
+ WebhookEventType: () => import_shared.WebhookEventType
21
+ });
22
+ module.exports = __toCommonJS(webhooks_exports);
23
+ var import_shared = require("@getpara/shared");
24
+ // Annotate the CommonJS export names for ESM import in node:
25
+ 0 && (module.exports = {
26
+ WebhookEventType
27
+ });
package/dist/esm/index.js CHANGED
@@ -18,6 +18,11 @@ var __async = (__this, __arguments, generator) => {
18
18
  step((generator = generator.apply(__this, __arguments)).next());
19
19
  });
20
20
  };
21
+ import { RestPermissionsClient } from "./permissions.js";
22
+ import { ParaRestValidationError, pathSegment, requireBody, requireNonEmpty } from "./validation.js";
23
+ export * from "./permissions.js";
24
+ export * from "./webhooks.js";
25
+ import { ParaRestValidationError as ParaRestValidationError2 } from "./validation.js";
21
26
  class ParaRestError extends Error {
22
27
  constructor({
23
28
  status,
@@ -41,12 +46,6 @@ class ParaRestSerializationError extends Error {
41
46
  this.name = "ParaRestSerializationError";
42
47
  }
43
48
  }
44
- class ParaRestValidationError extends Error {
45
- constructor(message) {
46
- super(message);
47
- this.name = "ParaRestValidationError";
48
- }
49
- }
50
49
  const BASE_URLS = {
51
50
  PROD: "https://api.getpara.com",
52
51
  BETA: "https://api.beta.getpara.com",
@@ -77,9 +76,10 @@ function toRestJson(body) {
77
76
  }
78
77
  return json;
79
78
  }
80
- class ParaRestClient {
79
+ class ParaRestClient extends RestPermissionsClient {
81
80
  constructor(options) {
82
81
  var _a, _b, _c;
82
+ super();
83
83
  if (!options.apiKey) {
84
84
  throw new ParaRestValidationError("apiKey is required");
85
85
  }
@@ -196,6 +196,26 @@ class ParaRestClient {
196
196
  }
197
197
  );
198
198
  }
199
+ resumeRestTransaction(walletId, transactionId, body, options) {
200
+ requireBody(body, "body");
201
+ requireNonEmpty(body.reviewId, "reviewId");
202
+ return this.request(
203
+ "POST",
204
+ `/v1/wallets/${walletPath(walletId)}/transactions/${pathSegment("transactionId", transactionId)}/resume`,
205
+ { body, options }
206
+ );
207
+ }
208
+ /**
209
+ * Look up a fiat on-ramp purchase by id — the id the SDK reports on the `ONRAMP_LAUNCHED` event, and the
210
+ * `purchaseId` on the `onramp.completed` webhook. Use it to reconcile a delivery you missed, or to check one still in flight.
211
+ *
212
+ * Scoped to the calling partner: a purchase that doesn't exist, is malformed, or belongs to another partner all
213
+ * raise an identical `ParaRestError` with status 404, so a 404 never confirms that some other partner's purchase
214
+ * id exists.
215
+ */
216
+ getOnRampPurchase(purchaseId, options) {
217
+ return this.request("GET", `/v1/onramp/purchases/${pathSegment("purchaseId", purchaseId)}`, { options });
218
+ }
199
219
  request(_0, _1) {
200
220
  return __async(this, arguments, function* (method, path, {
201
221
  body,
@@ -262,20 +282,6 @@ function defaultRequestId() {
262
282
  function walletPath(walletId) {
263
283
  return pathSegment("walletId", walletId);
264
284
  }
265
- function pathSegment(name, value) {
266
- requireNonEmpty(value, name);
267
- return encodeURIComponent(value);
268
- }
269
- function requireBody(value, name) {
270
- if (!isRecord(value)) {
271
- throw new ParaRestValidationError(`${name} is required`);
272
- }
273
- }
274
- function requireNonEmpty(value, name) {
275
- if (value == null || value === "") {
276
- throw new ParaRestValidationError(`${name} is required`);
277
- }
278
- }
279
285
  function queryString(query) {
280
286
  if (!query) return "";
281
287
  const params = new URLSearchParams();
@@ -307,6 +313,6 @@ export {
307
313
  ParaRestClient,
308
314
  ParaRestError,
309
315
  ParaRestSerializationError,
310
- ParaRestValidationError,
316
+ ParaRestValidationError2 as ParaRestValidationError,
311
317
  toRestJson
312
318
  };
@@ -0,0 +1,198 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __objRest = (source, exclude) => {
18
+ var target = {};
19
+ for (var prop in source)
20
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
21
+ target[prop] = source[prop];
22
+ if (source != null && __getOwnPropSymbols)
23
+ for (var prop of __getOwnPropSymbols(source)) {
24
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
25
+ target[prop] = source[prop];
26
+ }
27
+ return target;
28
+ };
29
+ import { pathSegment } from "./validation.js";
30
+ const basePath = "/v1/permissions-v2";
31
+ function queryString(query) {
32
+ if (!query) return "";
33
+ const params = new URLSearchParams();
34
+ for (const [key, value] of Object.entries(query)) {
35
+ if (value != null) params.set(key, String(value));
36
+ }
37
+ const serialized = params.toString();
38
+ return serialized ? `?${serialized}` : "";
39
+ }
40
+ function requirementPath(reference) {
41
+ return `${basePath}/authorization-scopes/${pathSegment(
42
+ "authorizationScopeId",
43
+ reference.authorizationScopeId
44
+ )}/policies/${pathSegment(
45
+ "policyId",
46
+ reference.policyId
47
+ )}/versions/${pathSegment("policyVersion", reference.policyVersion)}/requirements/${pathSegment(
48
+ "requirementId",
49
+ reference.requirementId
50
+ )}`;
51
+ }
52
+ class RestPermissionsClient {
53
+ listPartnerPolicies(options) {
54
+ return this.request("GET", `${basePath}/policies`, { options });
55
+ }
56
+ getPartnerPolicy(policyId, options) {
57
+ return this.request("GET", `${basePath}/policies/${pathSegment("policyId", policyId)}`, { options });
58
+ }
59
+ listPartnerPolicyVersions(policyId, options) {
60
+ return this.request("GET", `${basePath}/policies/${pathSegment("policyId", policyId)}/versions`, { options });
61
+ }
62
+ listUserPolicyConsents(userId, context, options) {
63
+ return this.request(
64
+ "GET",
65
+ `${basePath}/users/${pathSegment("userId", userId)}/delegation-consents${queryString(context)}`,
66
+ { options }
67
+ );
68
+ }
69
+ getUserPolicyConsent(userId, policyId, context, options) {
70
+ return this.request(
71
+ "GET",
72
+ `${basePath}/users/${pathSegment("userId", userId)}/delegation-consents/${pathSegment(
73
+ "policyId",
74
+ policyId
75
+ )}${queryString(context)}`,
76
+ { options }
77
+ );
78
+ }
79
+ listUserAdjustablePolicies(userId, options) {
80
+ return this.request("GET", `${basePath}/users/${pathSegment("userId", userId)}/user-parameters`, { options });
81
+ }
82
+ getUserPolicyParameters(userId, policyId, options) {
83
+ return this.request(
84
+ "GET",
85
+ `${basePath}/users/${pathSegment("userId", userId)}/user-parameters/${pathSegment("policyId", policyId)}`,
86
+ { options }
87
+ );
88
+ }
89
+ listUserPolicyParameterHistory(userId, policyId, query, options) {
90
+ return this.request(
91
+ "GET",
92
+ `${basePath}/users/${pathSegment("userId", userId)}/user-parameters/${pathSegment(
93
+ "policyId",
94
+ policyId
95
+ )}/history${queryString(query)}`,
96
+ { options }
97
+ );
98
+ }
99
+ listConfigurableApprovalRequirements(authorizationScopeId, options) {
100
+ return this.request(
101
+ "GET",
102
+ `${basePath}/authorization-scopes/${pathSegment("authorizationScopeId", authorizationScopeId)}/requirements`,
103
+ { options }
104
+ );
105
+ }
106
+ getConfigurableApprovalRequirement(reference, options) {
107
+ return this.request("GET", requirementPath(reference), { options });
108
+ }
109
+ getApprovalConfiguration(reference, options) {
110
+ return this.request("GET", `${requirementPath(reference)}/configuration`, { options });
111
+ }
112
+ getEffectiveApprovalConfiguration(reference, options) {
113
+ return this.request("GET", `${requirementPath(reference)}/configuration/effective`, { options });
114
+ }
115
+ updateApprovalConfiguration(reference, body, options) {
116
+ return this.request("PUT", `${requirementPath(reference)}/configuration`, { body, options });
117
+ }
118
+ resetApprovalConfiguration(reference, expectedRevision, options) {
119
+ return this.updateApprovalConfiguration(reference, { expectedRevision, values: {} }, options);
120
+ }
121
+ listApprovalConfigurationHistory(reference, options) {
122
+ return this.request("GET", `${requirementPath(reference)}/configuration/history`, { options });
123
+ }
124
+ getUserApprovalAssignments(authorizationScopeId, userId, options) {
125
+ return this.request(
126
+ "GET",
127
+ `${basePath}/authorization-scopes/${pathSegment("authorizationScopeId", authorizationScopeId)}/users/${pathSegment(
128
+ "userId",
129
+ userId
130
+ )}/assignments`,
131
+ { options }
132
+ );
133
+ }
134
+ listAuthorizationScopeMembers(authorizationScopeId, query, options) {
135
+ return this.request(
136
+ "GET",
137
+ `${basePath}/authorization-scopes/${pathSegment("authorizationScopeId", authorizationScopeId)}/members${queryString(
138
+ query
139
+ )}`,
140
+ { options }
141
+ );
142
+ }
143
+ replaceUserApprovalAssignments(authorizationScopeId, userId, body, options) {
144
+ return this.request(
145
+ "PUT",
146
+ `${basePath}/authorization-scopes/${pathSegment("authorizationScopeId", authorizationScopeId)}/users/${pathSegment(
147
+ "userId",
148
+ userId
149
+ )}/assignments`,
150
+ { body, options }
151
+ );
152
+ }
153
+ listUserApprovalAssignmentHistory(authorizationScopeId, userId, options) {
154
+ return this.request(
155
+ "GET",
156
+ `${basePath}/authorization-scopes/${pathSegment("authorizationScopeId", authorizationScopeId)}/users/${pathSegment(
157
+ "userId",
158
+ userId
159
+ )}/assignments/history`,
160
+ { options }
161
+ );
162
+ }
163
+ getWalletAuthorizationScope(walletId, options) {
164
+ return this.request("GET", `${basePath}/wallets/${pathSegment("walletId", walletId)}/authorization-scope`, { options });
165
+ }
166
+ setWalletAuthorizationScope(walletId, body, options) {
167
+ return this.request("PUT", `${basePath}/wallets/${pathSegment("walletId", walletId)}/authorization-scope`, {
168
+ body,
169
+ options
170
+ });
171
+ }
172
+ listWalletAuthorizationScopeHistory(walletId, query, options) {
173
+ return this.request(
174
+ "GET",
175
+ `${basePath}/wallets/${pathSegment("walletId", walletId)}/authorization-scope/history${queryString(query)}`,
176
+ { options }
177
+ );
178
+ }
179
+ listPartnerApprovalCases(query, options) {
180
+ return this.request("GET", `${basePath}/approval-cases${queryString(query)}`, { options });
181
+ }
182
+ getPartnerApprovalCase(caseId, options) {
183
+ return this.request("GET", `${basePath}/approval-cases/${pathSegment("caseId", caseId)}`, { options });
184
+ }
185
+ getPartnerPolicyUsage(policyId, context, options) {
186
+ const _a = context, { userId, walletId } = _a, query = __objRest(_a, ["userId", "walletId"]);
187
+ const subjectPath = userId ? `users/${pathSegment("userId", userId)}` : `wallets/${pathSegment("walletId", walletId)}`;
188
+ const usageQuery = userId ? __spreadValues({ walletId }, query) : query;
189
+ return this.request(
190
+ "GET",
191
+ `${basePath}/${subjectPath}/policies/${pathSegment("policyId", policyId)}/usage${queryString(usageQuery)}`,
192
+ { options }
193
+ );
194
+ }
195
+ }
196
+ export {
197
+ RestPermissionsClient
198
+ };
@@ -0,0 +1,26 @@
1
+ class ParaRestValidationError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = "ParaRestValidationError";
5
+ }
6
+ }
7
+ function requireBody(value, name) {
8
+ if (value == null || typeof value !== "object" || Array.isArray(value)) {
9
+ throw new ParaRestValidationError(`${name} is required`);
10
+ }
11
+ }
12
+ function requireNonEmpty(value, name) {
13
+ if (value == null || value === "") {
14
+ throw new ParaRestValidationError(`${name} is required`);
15
+ }
16
+ }
17
+ function pathSegment(name, value) {
18
+ requireNonEmpty(value, name);
19
+ return encodeURIComponent(value);
20
+ }
21
+ export {
22
+ ParaRestValidationError,
23
+ pathSegment,
24
+ requireBody,
25
+ requireNonEmpty
26
+ };
@@ -0,0 +1,4 @@
1
+ import { WebhookEventType } from "@getpara/shared";
2
+ export {
3
+ WebhookEventType
4
+ };
@@ -1,4 +1,8 @@
1
- import type { TPregenIdentifierType, TWalletScheme, TWalletType } from '@getpara/shared';
1
+ import type { OnrampCompletedPayload, TPregenIdentifierType, TWalletScheme, TWalletType } from '@getpara/shared';
2
+ import { RestPermissionsClient } from './permissions.js';
3
+ export * from './permissions.js';
4
+ export * from './webhooks.js';
5
+ export { ParaRestValidationError } from './validation.js';
2
6
  export type ParaRestEnvironment = 'PROD' | 'BETA' | 'SANDBOX' | {
3
7
  baseUrl: string;
4
8
  };
@@ -54,6 +58,7 @@ export interface EnclavePublicKeyResponse {
54
58
  generatedAt: string;
55
59
  }
56
60
  export type SolanaNetwork = 'SOLANA' | 'SOLANA_DEVNET';
61
+ export type SuiNetwork = 'SUI' | 'SUI_TESTNET' | 'SUI_DEVNET';
57
62
  export interface GetWalletBalanceRequest {
58
63
  chainId?: string | number;
59
64
  tokenAddress?: string;
@@ -81,7 +86,7 @@ export interface SignMessageResponse {
81
86
  export interface SignTransactionRequest {
82
87
  transaction: EvmSignTransactionRequest | string;
83
88
  broadcast?: boolean;
84
- network?: SolanaNetwork;
89
+ network?: SolanaNetwork | SuiNetwork;
85
90
  networkPassphrase?: string;
86
91
  }
87
92
  export interface EvmSignTransactionRequest {
@@ -153,11 +158,20 @@ export interface TransferRequest {
153
158
  broadcast?: boolean;
154
159
  network?: SolanaNetwork;
155
160
  }
156
- export interface TransferResponse {
161
+ export interface LegacyTransferResponse {
162
+ executionMode?: 'legacy';
157
163
  signedTransaction: string;
158
164
  txHash?: string;
159
165
  transactionId?: string;
160
166
  }
167
+ export interface SponsoredTransferResponse extends RestSponsorshipDetails {
168
+ executionMode: 'sponsored';
169
+ transactionId: string;
170
+ status: RestTransactionKnownStatus;
171
+ txHash?: string;
172
+ signedTransaction?: never;
173
+ }
174
+ export type TransferResponse = LegacyTransferResponse | SponsoredTransferResponse;
161
175
  export interface EstimateFeeRequest {
162
176
  to: string;
163
177
  value: string;
@@ -191,18 +205,30 @@ export type RestTransactionStatus = RestTransactionKnownStatus | (string & {});
191
205
  export type RestTransactionIntentKind = 'transfer' | 'sign_transaction';
192
206
  export type RestTransactionFailureStage = 'mpc_sign' | 'signature_apply' | 'signer_verify' | 'broadcast' | 'monitor_timeout';
193
207
  export type RestTransactionWalletType = 'EVM' | 'SOLANA';
208
+ export type RestSponsoredTransactionStage = 'requires_action' | 'preparing' | 'signed' | 'submission_unknown' | 'included' | 'delivery_unverified';
209
+ export interface RestSponsorshipDetails {
210
+ userOperationHash?: string;
211
+ stage?: RestSponsoredTransactionStage;
212
+ reviewId?: string;
213
+ /** Actual gas cost in native-token base units, available after settlement. */
214
+ actualGasCost?: string;
215
+ }
216
+ export interface ResumeRestTransactionRequest {
217
+ reviewId: string;
218
+ }
194
219
  export interface ListRestTransactionsRequest {
195
220
  limit?: number;
196
221
  cursor?: string;
197
222
  status?: RestTransactionKnownStatus;
198
223
  intentKind?: RestTransactionIntentKind;
199
224
  }
200
- export interface RestTransaction {
225
+ export interface RestTransaction extends RestSponsorshipDetails {
201
226
  transactionId: string;
202
227
  walletId: string;
203
228
  walletType: RestTransactionWalletType;
204
229
  intentKind: RestTransactionIntentKind;
205
230
  status: RestTransactionStatus;
231
+ executionMode?: 'legacy' | 'sponsored';
206
232
  chainId?: string;
207
233
  network?: SolanaNetwork;
208
234
  to?: string;
@@ -218,6 +244,24 @@ export interface RestTransaction {
218
244
  submittedAt?: string;
219
245
  resolvedAt?: string;
220
246
  }
247
+ export type RestOnRampPurchaseKnownStatus = 'INITIATED' | 'FINISHED' | 'CANCELLED';
248
+ /**
249
+ * Lifecycle state of an on-ramp purchase. Treat an unrecognized value as NON-TERMINAL — new states may be added,
250
+ * and settling your own records on one you don't know is worse than waiting for a state you do.
251
+ */
252
+ export type RestOnRampPurchaseStatus = RestOnRampPurchaseKnownStatus | (string & {});
253
+ /**
254
+ * A fiat on-ramp purchase, as returned by `getOnRampPurchase`.
255
+ *
256
+ * Extends the `onramp.completed` webhook payload — the server builds both from one definition, so the two shapes
257
+ * can't diverge — with the row's lifecycle `status`. A purchase that hasn't settled yet returns partial data:
258
+ * `transactionHash` and `completedAt` are `null` until `status` is `FINISHED`, so read `status` rather than
259
+ * inferring completion from the hash.
260
+ */
261
+ export interface RestOnRampPurchase extends Omit<OnrampCompletedPayload, 'completedAt'> {
262
+ status: RestOnRampPurchaseStatus;
263
+ completedAt: string | null;
264
+ }
221
265
  export interface ParaRestCallOptions {
222
266
  idempotencyKey?: string;
223
267
  signal?: AbortSignal;
@@ -261,11 +305,8 @@ export declare class ParaRestError extends Error {
261
305
  export declare class ParaRestSerializationError extends Error {
262
306
  constructor(message: string);
263
307
  }
264
- export declare class ParaRestValidationError extends Error {
265
- constructor(message: string);
266
- }
267
308
  export declare function toRestJson(body: unknown): string;
268
- export declare class ParaRestClient {
309
+ export declare class ParaRestClient extends RestPermissionsClient {
269
310
  private readonly apiKey;
270
311
  private readonly baseUrl;
271
312
  private readonly fetchImpl;
@@ -288,5 +329,19 @@ export declare class ParaRestClient {
288
329
  requestFaucet(body: FaucetRequest, options?: ParaRestCallOptions): Promise<FaucetResponse>;
289
330
  listRestTransactions(walletId: string, query?: ListRestTransactionsRequest, options?: ParaRestCallOptions): Promise<RestListResponse<RestTransaction>>;
290
331
  getRestTransaction(walletId: string, transactionId: string, options?: ParaRestCallOptions): Promise<RestTransaction>;
291
- private request;
332
+ resumeRestTransaction(walletId: string, transactionId: string, body: ResumeRestTransactionRequest, options?: ParaRestCallOptions): Promise<SponsoredTransferResponse>;
333
+ /**
334
+ * Look up a fiat on-ramp purchase by id — the id the SDK reports on the `ONRAMP_LAUNCHED` event, and the
335
+ * `purchaseId` on the `onramp.completed` webhook. Use it to reconcile a delivery you missed, or to check one still in flight.
336
+ *
337
+ * Scoped to the calling partner: a purchase that doesn't exist, is malformed, or belongs to another partner all
338
+ * raise an identical `ParaRestError` with status 404, so a 404 never confirms that some other partner's purchase
339
+ * id exists.
340
+ */
341
+ getOnRampPurchase(purchaseId: string, options?: ParaRestCallOptions): Promise<RestOnRampPurchase>;
342
+ protected request<T>(method: string, path: string, { body, options, expectedStatus, }?: {
343
+ body?: unknown;
344
+ options?: ParaRestCallOptions;
345
+ expectedStatus?: number;
346
+ }): Promise<T>;
292
347
  }
@@ -0,0 +1,69 @@
1
+ import type { PermissionsV2AuthoritySetHistory, PermissionsV2AuthoritySetView, PermissionsV2AuthoritySetWrite, PermissionsV2AuthorizationConfigurationHistory, PermissionsV2AuthorizationConfigurationView, PermissionsV2AuthorizationConfigurationWrite, PermissionsV2AuthorizationScopeBindingHistory, PermissionsV2AuthorizationScopeBindingView, PermissionsV2AuthorizationScopeBindingWrite, PermissionsV2AuthorizationScopeMembers, PermissionsV2ConditionalApprovalCaseView, PermissionsV2ConditionalApprovalPartnerCaseList, PermissionsV2ConditionalRequirementList, PermissionsV2ConditionalRequirementView, PermissionsV2DelegationConsentDiscoveryResponse, PermissionsV2DelegationConsentView, PermissionsV2EffectiveAuthorizationConfiguration, PermissionsV2PolicyListResponse, PermissionsV2PolicyResponse, PermissionsV2PolicyUsage, PermissionsV2PolicyVersionsResponse, PermissionsV2PolicyView, PermissionsV2UserParameterHistory, PermissionsV2UserParameterView } from '@getpara/shared';
2
+ import type { ParaRestCallOptions } from './index.js';
3
+ export type { PermissionsV2AuthoritySetHistory, PermissionsV2AuthoritySetWrite, PermissionsV2AuthorizationConfigurationHistory, PermissionsV2AuthorizationConfigurationWrite, PermissionsV2AuthorizationScopeBindingHistory, PermissionsV2AuthorizationScopeBindingWrite, PermissionsV2AuthorizationScopeMembers, PermissionsV2ConditionalApprovalPartnerCaseList, PermissionsV2ConditionalRequirementList, PermissionsV2ConditionalRequirementView, PermissionsV2EffectiveAuthorizationConfiguration, PermissionsV2PolicyListResponse, PermissionsV2PolicyResponse, PermissionsV2PolicyUsage, PermissionsV2PolicyUsageMeter, PermissionsV2PolicyVersionsResponse, PermissionsV2PolicyView, } from '@getpara/shared';
4
+ type PermissionsRequestOptions = {
5
+ body?: unknown;
6
+ options?: ParaRestCallOptions;
7
+ expectedStatus?: number;
8
+ };
9
+ export type PermissionsV2PolicyLifecycle = PermissionsV2PolicyView['lifecycle'];
10
+ export interface PermissionsV2ApprovalRequirementReference {
11
+ authorizationScopeId: string;
12
+ policyId: string;
13
+ policyVersion: string;
14
+ requirementId: string;
15
+ }
16
+ export interface PermissionsV2WalletContext {
17
+ walletId: string;
18
+ }
19
+ export interface PermissionsV2ConsentListContext extends PermissionsV2WalletContext {
20
+ pendingTransactionId?: string;
21
+ }
22
+ export interface PermissionsV2HistoryOptions {
23
+ beforeRevision?: number;
24
+ }
25
+ export interface PermissionsV2CaseListOptions {
26
+ limit?: number;
27
+ beforeCaseId?: string;
28
+ }
29
+ export interface PermissionsV2AuthorizationScopeMemberListOptions {
30
+ limit?: number;
31
+ afterUserId?: string;
32
+ }
33
+ export interface PermissionsV2PartnerUsageContext extends PermissionsV2WalletContext {
34
+ userId?: string;
35
+ chainId?: string;
36
+ tokenAddress?: string;
37
+ }
38
+ export interface PermissionsV2UserAdjustablePolicyListResponse {
39
+ policies: PermissionsV2UserParameterView[];
40
+ }
41
+ /** Partner-secret permissions methods inherited by {@link ParaRestClient}. */
42
+ export declare abstract class RestPermissionsClient {
43
+ protected abstract request<T>(method: string, path: string, options?: PermissionsRequestOptions): Promise<T>;
44
+ listPartnerPolicies(options?: ParaRestCallOptions): Promise<PermissionsV2PolicyListResponse>;
45
+ getPartnerPolicy(policyId: string, options?: ParaRestCallOptions): Promise<PermissionsV2PolicyResponse>;
46
+ listPartnerPolicyVersions(policyId: string, options?: ParaRestCallOptions): Promise<PermissionsV2PolicyVersionsResponse>;
47
+ listUserPolicyConsents(userId: string, context: PermissionsV2ConsentListContext, options?: ParaRestCallOptions): Promise<PermissionsV2DelegationConsentDiscoveryResponse>;
48
+ getUserPolicyConsent(userId: string, policyId: string, context: PermissionsV2WalletContext, options?: ParaRestCallOptions): Promise<PermissionsV2DelegationConsentView>;
49
+ listUserAdjustablePolicies(userId: string, options?: ParaRestCallOptions): Promise<PermissionsV2UserAdjustablePolicyListResponse>;
50
+ getUserPolicyParameters(userId: string, policyId: string, options?: ParaRestCallOptions): Promise<PermissionsV2UserParameterView>;
51
+ listUserPolicyParameterHistory(userId: string, policyId: string, query?: PermissionsV2HistoryOptions, options?: ParaRestCallOptions): Promise<PermissionsV2UserParameterHistory>;
52
+ listConfigurableApprovalRequirements(authorizationScopeId: string, options?: ParaRestCallOptions): Promise<PermissionsV2ConditionalRequirementList>;
53
+ getConfigurableApprovalRequirement(reference: PermissionsV2ApprovalRequirementReference, options?: ParaRestCallOptions): Promise<PermissionsV2ConditionalRequirementView>;
54
+ getApprovalConfiguration(reference: PermissionsV2ApprovalRequirementReference, options?: ParaRestCallOptions): Promise<PermissionsV2AuthorizationConfigurationView>;
55
+ getEffectiveApprovalConfiguration(reference: PermissionsV2ApprovalRequirementReference, options?: ParaRestCallOptions): Promise<PermissionsV2EffectiveAuthorizationConfiguration>;
56
+ updateApprovalConfiguration(reference: PermissionsV2ApprovalRequirementReference, body: PermissionsV2AuthorizationConfigurationWrite, options?: ParaRestCallOptions): Promise<PermissionsV2AuthorizationConfigurationView>;
57
+ resetApprovalConfiguration(reference: PermissionsV2ApprovalRequirementReference, expectedRevision: number, options?: ParaRestCallOptions): Promise<PermissionsV2AuthorizationConfigurationView>;
58
+ listApprovalConfigurationHistory(reference: PermissionsV2ApprovalRequirementReference, options?: ParaRestCallOptions): Promise<PermissionsV2AuthorizationConfigurationHistory>;
59
+ getUserApprovalAssignments(authorizationScopeId: string, userId: string, options?: ParaRestCallOptions): Promise<PermissionsV2AuthoritySetView>;
60
+ listAuthorizationScopeMembers(authorizationScopeId: string, query?: PermissionsV2AuthorizationScopeMemberListOptions, options?: ParaRestCallOptions): Promise<PermissionsV2AuthorizationScopeMembers>;
61
+ replaceUserApprovalAssignments(authorizationScopeId: string, userId: string, body: PermissionsV2AuthoritySetWrite, options?: ParaRestCallOptions): Promise<PermissionsV2AuthoritySetView>;
62
+ listUserApprovalAssignmentHistory(authorizationScopeId: string, userId: string, options?: ParaRestCallOptions): Promise<PermissionsV2AuthoritySetHistory>;
63
+ getWalletAuthorizationScope(walletId: string, options?: ParaRestCallOptions): Promise<PermissionsV2AuthorizationScopeBindingView>;
64
+ setWalletAuthorizationScope(walletId: string, body: PermissionsV2AuthorizationScopeBindingWrite, options?: ParaRestCallOptions): Promise<PermissionsV2AuthorizationScopeBindingView>;
65
+ listWalletAuthorizationScopeHistory(walletId: string, query?: PermissionsV2HistoryOptions, options?: ParaRestCallOptions): Promise<PermissionsV2AuthorizationScopeBindingHistory>;
66
+ listPartnerApprovalCases(query?: PermissionsV2CaseListOptions, options?: ParaRestCallOptions): Promise<PermissionsV2ConditionalApprovalPartnerCaseList>;
67
+ getPartnerApprovalCase(caseId: string, options?: ParaRestCallOptions): Promise<Omit<PermissionsV2ConditionalApprovalCaseView, 'decision'>>;
68
+ getPartnerPolicyUsage(policyId: string, context: PermissionsV2PartnerUsageContext, options?: ParaRestCallOptions): Promise<PermissionsV2PolicyUsage>;
69
+ }
@@ -0,0 +1,6 @@
1
+ export declare class ParaRestValidationError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare function requireBody(value: unknown, name: string): asserts value is Record<string, unknown>;
5
+ export declare function requireNonEmpty(value: unknown, name: string): asserts value is string;
6
+ export declare function pathSegment(name: string, value: string): string;
@@ -0,0 +1,42 @@
1
+ export { WebhookEventType } from '@getpara/shared';
2
+ export type { WebhookEvent, WebhookEventPayload, WebhookEventPayloadMap, UserCreatedPayload, WalletCreatedPayload, TransactionSignedPayload, SendBroadcastedPayload, SendConfirmedPayload, SendFailedPayload, RestTransactionConfirmedPayload, RestTransactionFailedPayload, WalletPregenClaimedPayload, UserExternalWalletVerifiedPayload, OnrampCompletedPayload, TestPingPayload, } from '@getpara/shared';
3
+ import type { WebhookEventPayloadMap } from '@getpara/shared';
4
+ /**
5
+ * A received webhook, as a discriminated union over the event type.
6
+ *
7
+ * Prefer this to the generic `WebhookEvent` when handling deliveries: `WebhookEvent<T>` leaves `type` and `data`
8
+ * uncorrelated, so `data` stays the union of every payload no matter what `type` says. This maps each event type to
9
+ * its own payload, so a `switch` on `event.type` narrows `event.data` to the matching shape.
10
+ *
11
+ * Derived from `WebhookEventPayloadMap`, so it picks up new event types automatically.
12
+ *
13
+ * ```ts
14
+ * import { WebhookEventType, type ParaWebhookEvent } from '@getpara/rest-sdk';
15
+ *
16
+ * function handle(event: ParaWebhookEvent) {
17
+ * switch (event.type) {
18
+ * case WebhookEventType.ONRAMP_COMPLETED:
19
+ * // event.data is OnrampCompletedPayload
20
+ * return credit(event.data.purchaseId, event.data.transactionHash);
21
+ * case WebhookEventType.WALLET_CREATED:
22
+ * // event.data is WalletCreatedPayload
23
+ * return index(event.data.walletAddress);
24
+ * }
25
+ * }
26
+ * ```
27
+ */
28
+ export type ParaWebhookEvent = {
29
+ [K in keyof WebhookEventPayloadMap]: {
30
+ /** Unique event id, prefixed with `evt_`. */
31
+ id: string;
32
+ type: K;
33
+ /** ISO 8601 timestamp of when the event was created. */
34
+ createdAt: string;
35
+ data: WebhookEventPayloadMap[K];
36
+ };
37
+ }[keyof WebhookEventPayloadMap];
38
+ /**
39
+ * The payload for a given event type — e.g. `ParaWebhookPayload<WebhookEventType.ONRAMP_COMPLETED>`. Useful for
40
+ * typing a per-event handler without restating the payload interface's name.
41
+ */
42
+ export type ParaWebhookPayload<K extends keyof WebhookEventPayloadMap> = WebhookEventPayloadMap[K];
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@getpara/rest-sdk",
3
- "version": "3.19.0",
3
+ "version": "3.21.0",
4
4
  "description": "Typed server-side SDK for Para REST wallet management and signing",
5
5
  "author": "Para Team <hello@getpara.com> (https://getpara.com)",
6
- "homepage": "https://docs.getpara.com/v2/rest/sdk",
6
+ "homepage": "https://docs.getpara.com/v3/rest/sdk",
7
7
  "keywords": [
8
8
  "para",
9
9
  "rest",
@@ -27,7 +27,7 @@
27
27
  "vitest": "^3.2.4"
28
28
  },
29
29
  "dependencies": {
30
- "@getpara/shared": "^1.30.0"
30
+ "@getpara/shared": "^1.34.0"
31
31
  },
32
32
  "exports": {
33
33
  ".": {
@@ -64,7 +64,7 @@
64
64
  "@solana/signers": "^2.2.1",
65
65
  "@solana/transactions": "^2.2.1",
66
66
  "ethers": "^6.13.4",
67
- "viem": "^2.39.0"
67
+ "viem": "^2.10.0"
68
68
  },
69
69
  "peerDependenciesMeta": {
70
70
  "@solana/addresses": {
@@ -88,8 +88,9 @@
88
88
  },
89
89
  "scripts": {
90
90
  "build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
91
- "build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration",
92
- "test": "vitest run"
91
+ "build:types": "tsc --emitDeclarationOnly",
92
+ "test": "vitest run --coverage",
93
+ "typecheck": "tsc --noEmit"
93
94
  },
94
95
  "publishConfig": {
95
96
  "access": "public"
@@ -110,5 +111,5 @@
110
111
  }
111
112
  },
112
113
  "typings": "dist/types/index.d.ts",
113
- "gitHead": "6bc9e2483d62220b6c6920560358c80b188c2c31"
114
+ "gitHead": "e1ca81fb06f6337aaa7cc1860584b7ba5d1d9ca8"
114
115
  }