@getpara/rest-sdk 3.23.0 → 3.25.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 +198 -10
- package/dist/cjs/index.js +87 -1
- package/dist/cjs/permissions.js +13 -7
- package/dist/cjs/webhookVerification.js +156 -0
- package/dist/esm/index.js +83 -0
- package/dist/esm/permissions.js +13 -7
- package/dist/esm/webhookVerification.js +132 -0
- package/dist/types/index.d.ts +228 -9
- package/dist/types/permissions.d.ts +23 -9
- package/dist/types/webhookVerification.d.ts +42 -0
- package/dist/types/webhooks.d.ts +38 -15
- package/package.json +3 -3
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { PermissionsV2AuthoritySetHistory, PermissionsV2AuthoritySetView, PermissionsV2AuthoritySetWrite, PermissionsV2AuthorizationConfigurationHistory, PermissionsV2AuthorizationConfigurationView, PermissionsV2AuthorizationConfigurationWrite, PermissionsV2AuthorizationScopeBindingHistory, PermissionsV2AuthorizationScopeBindingView, PermissionsV2AuthorizationScopeBindingWrite, PermissionsV2AuthorizationScopeMembers, PermissionsV2ConditionalApprovalCaseSummary, PermissionsV2ConditionalApprovalCaseView, PermissionsV2ConditionalApprovalPartnerCaseList, PermissionsV2ConditionalRequirementList, PermissionsV2ConditionalRequirementView, PermissionsV2DelegationConsentDiscoveryResponse, PermissionsV2DelegationConsentView, PermissionsV2EffectiveAuthorizationConfiguration, PermissionsV2PolicyListResponse, PermissionsV2PolicyResponse, PermissionsV2PolicyUsage, PermissionsV2PolicyVersionsResponse, PermissionsV2PolicyView, PermissionsV2UserParameterHistory, PermissionsV2UserParameterView } from '@getpara/shared';
|
|
2
2
|
import type { ParaRestCallOptions } from './index.js';
|
|
3
|
-
export type { PermissionsV2AuthoritySetHistory, PermissionsV2AuthoritySetWrite, PermissionsV2AuthorizationConfigurationHistory, PermissionsV2AuthorizationConfigurationWrite, PermissionsV2AuthorizationScopeBindingHistory, PermissionsV2AuthorizationScopeBindingWrite, PermissionsV2AuthorizationScopeMembers, PermissionsV2ConditionalApprovalCaseSummary,
|
|
3
|
+
export type { PermissionsV2AuthoritySetHistory, PermissionsV2AuthoritySetWrite, PermissionsV2AuthorizationConfigurationHistory, PermissionsV2AuthorizationConfigurationWrite, PermissionsV2AuthorizationScopeBindingHistory, PermissionsV2AuthorizationScopeBindingWrite, PermissionsV2AuthorizationScopeMembers, PermissionsV2ConditionalApprovalCaseSummary, PermissionsV2ConditionalRequirementList, PermissionsV2ConditionalRequirementView, PermissionsV2EffectiveAuthorizationConfiguration, PermissionsV2PolicyListResponse, PermissionsV2PolicyResponse, PermissionsV2PolicyUsage, PermissionsV2PolicyUsageMeter, PermissionsV2PolicyVersionsResponse, PermissionsV2PolicyView, } from '@getpara/shared';
|
|
4
4
|
type PermissionsRequestOptions = {
|
|
5
5
|
body?: unknown;
|
|
6
6
|
options?: ParaRestCallOptions;
|
|
7
7
|
expectedStatus?: number;
|
|
8
8
|
};
|
|
9
9
|
export type PermissionsV2PolicyLifecycle = PermissionsV2PolicyView['lifecycle'];
|
|
10
|
+
export type PermissionsV2ConditionalApprovalCaseSummaryList = PermissionsV2ConditionalApprovalPartnerCaseList;
|
|
10
11
|
export interface PermissionsV2ApprovalRequirementReference {
|
|
11
12
|
authorizationScopeId: string;
|
|
12
13
|
policyId: string;
|
|
@@ -31,7 +32,7 @@ export interface PermissionsV2AuthorizationScopeMemberListOptions {
|
|
|
31
32
|
limit?: number;
|
|
32
33
|
afterUserId?: string;
|
|
33
34
|
}
|
|
34
|
-
export interface
|
|
35
|
+
export interface PermissionsV2PolicyUsageContext extends PermissionsV2WalletContext {
|
|
35
36
|
userId?: string;
|
|
36
37
|
chainId?: string;
|
|
37
38
|
tokenAddress?: string;
|
|
@@ -40,12 +41,23 @@ export interface PermissionsV2PartnerUsageContext extends PermissionsV2WalletCon
|
|
|
40
41
|
export interface PermissionsV2UserAdjustablePolicyListResponse {
|
|
41
42
|
policies: PermissionsV2UserParameterView[];
|
|
42
43
|
}
|
|
44
|
+
export type PermissionsV2ReviewStatus = 'pending' | 'approved' | 'rejected' | 'expired' | 'consumed';
|
|
45
|
+
export interface PermissionsV2ReviewApproval {
|
|
46
|
+
reviewId: string;
|
|
47
|
+
status: PermissionsV2ReviewStatus;
|
|
48
|
+
approvedAt?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface PermissionsV2ReviewRejection {
|
|
51
|
+
reviewId: string;
|
|
52
|
+
status: PermissionsV2ReviewStatus;
|
|
53
|
+
rejectedAt?: string;
|
|
54
|
+
}
|
|
43
55
|
/** Partner-secret permissions methods inherited by {@link ParaRestClient}. */
|
|
44
56
|
export declare abstract class RestPermissionsClient {
|
|
45
57
|
protected abstract request<T>(method: string, path: string, options?: PermissionsRequestOptions): Promise<T>;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
listPolicies(options?: ParaRestCallOptions): Promise<PermissionsV2PolicyListResponse>;
|
|
59
|
+
getPolicy(policyId: string, options?: ParaRestCallOptions): Promise<PermissionsV2PolicyResponse>;
|
|
60
|
+
listPolicyVersions(policyId: string, options?: ParaRestCallOptions): Promise<PermissionsV2PolicyVersionsResponse>;
|
|
49
61
|
listUserPolicyConsents(userId: string, context: PermissionsV2ConsentListContext, options?: ParaRestCallOptions): Promise<PermissionsV2DelegationConsentDiscoveryResponse>;
|
|
50
62
|
getUserPolicyConsent(userId: string, policyId: string, context: PermissionsV2WalletContext, options?: ParaRestCallOptions): Promise<PermissionsV2DelegationConsentView>;
|
|
51
63
|
listUserAdjustablePolicies(userId: string, options?: ParaRestCallOptions): Promise<PermissionsV2UserAdjustablePolicyListResponse>;
|
|
@@ -65,8 +77,10 @@ export declare abstract class RestPermissionsClient {
|
|
|
65
77
|
getWalletAuthorizationScope(walletId: string, options?: ParaRestCallOptions): Promise<PermissionsV2AuthorizationScopeBindingView>;
|
|
66
78
|
setWalletAuthorizationScope(walletId: string, body: PermissionsV2AuthorizationScopeBindingWrite, options?: ParaRestCallOptions): Promise<PermissionsV2AuthorizationScopeBindingView>;
|
|
67
79
|
listWalletAuthorizationScopeHistory(walletId: string, query?: PermissionsV2HistoryOptions, options?: ParaRestCallOptions): Promise<PermissionsV2AuthorizationScopeBindingHistory>;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
80
|
+
listApprovalCases(query?: PermissionsV2CaseListOptions, options?: ParaRestCallOptions): Promise<PermissionsV2ConditionalApprovalCaseSummaryList>;
|
|
81
|
+
getApprovalCase(caseId: string, options?: ParaRestCallOptions): Promise<Omit<PermissionsV2ConditionalApprovalCaseView, 'decision'>>;
|
|
82
|
+
cancelApprovalCase(caseId: string, options?: ParaRestCallOptions): Promise<PermissionsV2ConditionalApprovalCaseSummary>;
|
|
83
|
+
approveReview(reviewId: string, options?: ParaRestCallOptions): Promise<PermissionsV2ReviewApproval>;
|
|
84
|
+
rejectReview(reviewId: string, options?: ParaRestCallOptions): Promise<PermissionsV2ReviewRejection>;
|
|
85
|
+
getPolicyUsage(policyId: string, context: PermissionsV2PolicyUsageContext, options?: ParaRestCallOptions): Promise<PermissionsV2PolicyUsage>;
|
|
72
86
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { WebhookPayloadVersion } from '@getpara/shared';
|
|
2
|
+
import type { RestHeaders } from './index.js';
|
|
3
|
+
import type { ParaWebhookEvent } from './webhooks.js';
|
|
4
|
+
export declare class ParaWebhookVerificationError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
/** A Fetch `Headers` object, or a header record such as Node's `IncomingHttpHeaders`. */
|
|
8
|
+
export type ParaWebhookHeaders = RestHeaders | Record<string, string | string[] | undefined>;
|
|
9
|
+
export interface VerifyParaWebhookOptions {
|
|
10
|
+
/** The request body exactly as received, before any JSON parsing. */
|
|
11
|
+
body: string | Uint8Array;
|
|
12
|
+
headers: ParaWebhookHeaders;
|
|
13
|
+
/** The endpoint's signing secret, starting with `whsec_`. */
|
|
14
|
+
secret: string;
|
|
15
|
+
/** How far `webhook-timestamp` may be from the current time, in either direction. Defaults to 300. */
|
|
16
|
+
toleranceInSeconds?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Verifies a webhook delivery from Para and returns its event.
|
|
20
|
+
*
|
|
21
|
+
* Accepts Para's original signature and the Standard Webhooks signature. After a secret rotation, deliveries are
|
|
22
|
+
* signed with both the new and the previous secret for 24 hours, so either secret verifies them.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { verifyParaWebhook } from '@getpara/rest-sdk';
|
|
26
|
+
*
|
|
27
|
+
* const event = await verifyParaWebhook({
|
|
28
|
+
* body: await request.text(),
|
|
29
|
+
* headers: request.headers,
|
|
30
|
+
* secret: process.env.PARA_WEBHOOK_SECRET!,
|
|
31
|
+
* });
|
|
32
|
+
* if (event.version === 2) {
|
|
33
|
+
* // event.data is a version 2 payload
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @throws {ParaWebhookVerificationError} when a `webhook-*` header is missing or malformed, the timestamp is outside
|
|
38
|
+
* the tolerance, or no signature matches the secret.
|
|
39
|
+
* @throws {ParaRestValidationError} when the secret is empty, `toleranceInSeconds` is not a finite, non-negative
|
|
40
|
+
* number, or the runtime has no Web Crypto.
|
|
41
|
+
*/
|
|
42
|
+
export declare function verifyParaWebhook(options: VerifyParaWebhookOptions): Promise<ParaWebhookEvent<WebhookPayloadVersion>>;
|
package/dist/types/webhooks.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { WebhookEventType } from '@getpara/shared';
|
|
2
|
-
export type { WebhookEvent, WebhookEventPayload, WebhookEventPayloadMap, UserCreatedPayload, WalletCreatedPayload, TransactionSignedPayload, SendBroadcastedPayload, SendConfirmedPayload, SendFailedPayload, RestTransactionConfirmedPayload, RestTransactionFailedPayload, WalletPregenClaimedPayload, UserExternalWalletVerifiedPayload, OnrampCompletedPayload, UserTwoFactorResetPayload, FundsReceivedPayload, TestPingPayload, } from '@getpara/shared';
|
|
3
|
-
import type { WebhookEventPayloadMap } from '@getpara/shared';
|
|
2
|
+
export type { WebhookEvent, WebhookEventPayload, WebhookEventPayloadMap, WebhookPayloadVersion, WebhookEventPayloadV2, WebhookEventPayloadMapV2, WebhookError, CaipNetwork, UserCreatedPayload, WalletCreatedPayload, TransactionSignedPayload, SendBroadcastedPayload, SendConfirmedPayload, SendFailedPayload, RestTransactionConfirmedPayload, RestTransactionFailedPayload, WalletPregenClaimedPayload, UserExternalWalletVerifiedPayload, OnrampCompletedPayload, UserTwoFactorResetPayload, FundsReceivedPayload, TestPingPayload, UserCreatedPayloadV2, WalletCreatedPayloadV2, TransactionSignedPayloadV2, SendBroadcastedPayloadV2, SendConfirmedPayloadV2, SendFailedPayloadV2, RestTransactionConfirmedPayloadV2, RestTransactionFailedPayloadV2, WalletPregenClaimedPayloadV2, UserExternalWalletVerifiedPayloadV2, OnrampCompletedPayloadV2, UserTwoFactorResetPayloadV2, FundsReceivedPayloadV2, TestPingPayloadV2, } from '@getpara/shared';
|
|
3
|
+
import type { WebhookEventPayloadMap, WebhookEventPayloadMapV2, WebhookPayloadVersion } from '@getpara/shared';
|
|
4
4
|
/**
|
|
5
5
|
* A received webhook, as a discriminated union over the event type.
|
|
6
6
|
*
|
|
@@ -8,7 +8,9 @@ import type { WebhookEventPayloadMap } from '@getpara/shared';
|
|
|
8
8
|
* uncorrelated, so `data` stays the union of every payload no matter what `type` says. This maps each event type to
|
|
9
9
|
* its own payload, so a `switch` on `event.type` narrows `event.data` to the matching shape.
|
|
10
10
|
*
|
|
11
|
-
* Derived from `WebhookEventPayloadMap`, so it picks up new event types automatically.
|
|
11
|
+
* Derived from `WebhookEventPayloadMap` and `WebhookEventPayloadMapV2`, so it picks up new event types automatically.
|
|
12
|
+
* It describes version 1 payloads by default. Use `ParaWebhookEvent<2>` for an endpoint set to payload version 2, or
|
|
13
|
+
* `ParaWebhookEvent<1 | 2>` and check `event.version` when either can arrive.
|
|
12
14
|
*
|
|
13
15
|
* ```ts
|
|
14
16
|
* import { WebhookEventType, type ParaWebhookEvent } from '@getpara/rest-sdk';
|
|
@@ -25,18 +27,39 @@ import type { WebhookEventPayloadMap } from '@getpara/shared';
|
|
|
25
27
|
* }
|
|
26
28
|
* ```
|
|
27
29
|
*/
|
|
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];
|
|
30
|
+
export type ParaWebhookEvent<Version extends WebhookPayloadVersion = 1> = ParaWebhookEventsByVersion[Version];
|
|
38
31
|
/**
|
|
39
32
|
* 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.
|
|
33
|
+
* typing a per-event handler without restating the payload interface's name. Pass `2` as the second argument for an
|
|
34
|
+
* endpoint that receives version 2 payloads.
|
|
41
35
|
*/
|
|
42
|
-
export type ParaWebhookPayload<K extends keyof WebhookEventPayloadMap> =
|
|
36
|
+
export type ParaWebhookPayload<K extends keyof WebhookEventPayloadMap, Version extends WebhookPayloadVersion = 1> = WebhookPayloadMapsByVersion[Version][K];
|
|
37
|
+
interface WebhookPayloadMapsByVersion {
|
|
38
|
+
1: WebhookEventPayloadMap;
|
|
39
|
+
2: WebhookEventPayloadMapV2;
|
|
40
|
+
}
|
|
41
|
+
interface ParaWebhookEventsByVersion {
|
|
42
|
+
1: {
|
|
43
|
+
[K in keyof WebhookEventPayloadMap]: {
|
|
44
|
+
/** Unique event id, prefixed with `evt_`. */
|
|
45
|
+
id: string;
|
|
46
|
+
type: K;
|
|
47
|
+
/** ISO 8601 timestamp of when the event was created. */
|
|
48
|
+
createdAt: string;
|
|
49
|
+
/** Absent on deliveries sent before payload versions existed. */
|
|
50
|
+
version?: 1;
|
|
51
|
+
data: WebhookEventPayloadMap[K];
|
|
52
|
+
};
|
|
53
|
+
}[keyof WebhookEventPayloadMap];
|
|
54
|
+
2: {
|
|
55
|
+
[K in keyof WebhookEventPayloadMapV2]: {
|
|
56
|
+
/** Unique event id, prefixed with `evt_`. */
|
|
57
|
+
id: string;
|
|
58
|
+
type: K;
|
|
59
|
+
/** ISO 8601 timestamp of when the event was created. */
|
|
60
|
+
createdAt: string;
|
|
61
|
+
version: 2;
|
|
62
|
+
data: WebhookEventPayloadMapV2[K];
|
|
63
|
+
};
|
|
64
|
+
}[keyof WebhookEventPayloadMapV2];
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/rest-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.25.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
6
|
"homepage": "https://docs.getpara.com/v3/rest/sdk",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"vitest": "^3.2.4"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@getpara/shared": "^1.
|
|
30
|
+
"@getpara/shared": "^1.40.0"
|
|
31
31
|
},
|
|
32
32
|
"exports": {
|
|
33
33
|
".": {
|
|
@@ -111,5 +111,5 @@
|
|
|
111
111
|
}
|
|
112
112
|
},
|
|
113
113
|
"typings": "dist/types/index.d.ts",
|
|
114
|
-
"gitHead": "
|
|
114
|
+
"gitHead": "757f086d7e0ff8adcc488ad0fc0801ec56366ee2"
|
|
115
115
|
}
|