instasign 1.0.2 → 1.1.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/CHANGELOG.md +10 -0
- package/README.md +3 -3
- package/dist/index.cjs +201 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1406 -0
- package/dist/index.d.ts +1394 -9
- package/dist/index.js +162 -26
- package/dist/index.js.map +1 -0
- package/package.json +25 -8
- package/{dist → types}/schema.d.ts +1 -0
- package/dist/resources/Envelopes.d.ts +0 -57
- package/dist/resources/Envelopes.js +0 -69
- package/dist/resources/SignRequests.d.ts +0 -23
- package/dist/resources/SignRequests.js +0 -27
- package/dist/resources/Webhooks.d.ts +0 -9
- package/dist/resources/Webhooks.js +0 -32
- package/dist/schema.js +0 -5
package/dist/index.js
CHANGED
|
@@ -1,27 +1,163 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
|
|
4
|
+
// src/resources/Envelopes.ts
|
|
5
|
+
var Envelopes = class {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create a new envelope
|
|
11
|
+
*/
|
|
12
|
+
async create(params) {
|
|
13
|
+
const response = await this.client.post("/functions/createEnvelope", params);
|
|
14
|
+
return response.data.result;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* List envelopes
|
|
18
|
+
*/
|
|
19
|
+
async list(params = {}) {
|
|
20
|
+
const response = await this.client.post("/functions/getEnvelopes", params);
|
|
21
|
+
return response.data.result;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Retrieve a single envelope with its sign requests
|
|
25
|
+
*/
|
|
26
|
+
async get(envelopeId) {
|
|
27
|
+
const response = await this.client.post("/functions/getEnvelope", { envelopeId });
|
|
28
|
+
return response.data.result;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Complete an envelope
|
|
32
|
+
*/
|
|
33
|
+
async complete(envelopeId) {
|
|
34
|
+
const response = await this.client.post("/functions/completeEnvelope", { envelopeId });
|
|
35
|
+
return response.data.result;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Delete an envelope
|
|
39
|
+
*/
|
|
40
|
+
async delete(envelopeId) {
|
|
41
|
+
const response = await this.client.post("/functions/deleteEnvelope", { envelopeId });
|
|
42
|
+
return response.data.result;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Update envelope metadata
|
|
46
|
+
*/
|
|
47
|
+
async updateMetadata(params) {
|
|
48
|
+
const response = await this.client.post("/functions/updateEnvelopeMetadata", params);
|
|
49
|
+
return response.data.result;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Remove a sign request from an envelope
|
|
53
|
+
*/
|
|
54
|
+
async removeSignRequest(params) {
|
|
55
|
+
const response = await this.client.post("/functions/removeSignRequestFromEnvelope", params);
|
|
56
|
+
return response.data.result;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Add a sign request to an envelope
|
|
60
|
+
*/
|
|
61
|
+
async addSignRequest(params) {
|
|
62
|
+
const response = await this.client.post("/functions/addSignRequestToEnvelope", params);
|
|
63
|
+
return response.data.result;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Add multiple sign requests to an envelope
|
|
67
|
+
*/
|
|
68
|
+
// async addSignRequests(params: AddSignRequestToEnvelopeParams[]): Promise<AddSignRequestToEnvelopeResponse[] | undefined> {
|
|
69
|
+
// // TODO(ciro): must be implemented on back-end
|
|
70
|
+
// const response = await this.client.post('/functions/addMultipleSignRequestsToEnvelope', params);
|
|
71
|
+
// return response.data.result;
|
|
72
|
+
// }
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/resources/SignRequests.ts
|
|
76
|
+
var SignRequests = class {
|
|
77
|
+
constructor(client) {
|
|
78
|
+
this.client = client;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a new sign request
|
|
82
|
+
*/
|
|
83
|
+
async create(params) {
|
|
84
|
+
const response = await this.client.post("/functions/createSignRequest", params);
|
|
85
|
+
return response.data.result;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Complete a sign request
|
|
89
|
+
*/
|
|
90
|
+
async complete(params) {
|
|
91
|
+
const response = await this.client.post("/functions/completeSignRequest", params);
|
|
92
|
+
return response.data.result;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get the file associated with a sign request
|
|
96
|
+
*/
|
|
97
|
+
async getFile(requestId) {
|
|
98
|
+
const response = await this.client.post("/functions/getFileFromRequestId", { requestId });
|
|
99
|
+
return response.data.result;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/resources/Webhooks.ts
|
|
104
|
+
import * as crypto from "crypto";
|
|
105
|
+
var Webhooks = class {
|
|
106
|
+
constructor(tolerance = 300) {
|
|
107
|
+
this.tolerance = tolerance;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Verify and parse a webhook event
|
|
111
|
+
*/
|
|
112
|
+
constructEvent(payload, signatureHeader, webhookSecret) {
|
|
113
|
+
const parts = signatureHeader.split(",");
|
|
114
|
+
const timestamp = parts.find((p) => p.startsWith("t="))?.split("=")[1];
|
|
115
|
+
const signature = parts.find((p) => p.startsWith("v1="))?.split("=")[1];
|
|
116
|
+
if (!timestamp || !signature) {
|
|
117
|
+
throw new Error("Invalid signature header");
|
|
26
118
|
}
|
|
27
|
-
|
|
119
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
120
|
+
if (Math.abs(now - parseInt(timestamp)) > this.tolerance) {
|
|
121
|
+
throw new Error("Signature too old");
|
|
122
|
+
}
|
|
123
|
+
const signedPayload = `${timestamp}.${payload}`;
|
|
124
|
+
const expectedSignature = crypto.createHmac("sha256", webhookSecret).update(signedPayload).digest("hex");
|
|
125
|
+
const isValid = crypto.timingSafeEqual(
|
|
126
|
+
Buffer.from(signature),
|
|
127
|
+
Buffer.from(expectedSignature)
|
|
128
|
+
);
|
|
129
|
+
if (!isValid) {
|
|
130
|
+
throw new Error("Invalid signature");
|
|
131
|
+
}
|
|
132
|
+
return JSON.parse(payload);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/index.ts
|
|
137
|
+
var Instasign = class {
|
|
138
|
+
client;
|
|
139
|
+
envelopes;
|
|
140
|
+
signRequests;
|
|
141
|
+
webhooks;
|
|
142
|
+
constructor(config) {
|
|
143
|
+
this.client = axios.create({
|
|
144
|
+
baseURL: config.serverUrl || "https://parseapi.back4app.com",
|
|
145
|
+
headers: {
|
|
146
|
+
"X-Parse-APPLICATION-ID": config.appId || "jKFo8BFQRdiAUV4F3o3SIDWLpLUb2TVW7bVl7lwH",
|
|
147
|
+
"X-Parse-REST-API-KEY": config.restApiKey || "Gjm9pmxZh0DjXHkcFlf0kGZjHfYEY4ERw71TvLig",
|
|
148
|
+
"x-api-key": config.apiKey,
|
|
149
|
+
"Content-Type": "application/json"
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
this.envelopes = new Envelopes(this.client);
|
|
153
|
+
this.signRequests = new SignRequests(this.client);
|
|
154
|
+
this.webhooks = new Webhooks(config.webhookTolerance ?? 300);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
export {
|
|
158
|
+
Envelopes,
|
|
159
|
+
Instasign,
|
|
160
|
+
SignRequests,
|
|
161
|
+
Webhooks
|
|
162
|
+
};
|
|
163
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/resources/Envelopes.ts","../src/resources/SignRequests.ts","../src/resources/Webhooks.ts"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\nimport { Envelopes } from './resources/Envelopes.js';\nimport { SignRequests } from './resources/SignRequests.js';\nimport { Webhooks } from './resources/Webhooks.js';\n\nexport * from './resources/Envelopes.js';\nexport * from './resources/SignRequests.js';\nexport * from './resources/Webhooks.js';\n\nexport type * from '../types/schema.js';\n\nexport interface IInstasignConfig {\n /// Required Instasign API key\n apiKey: string;\n\n /// Optional Parse Server config\n appId?: string;\n restApiKey?: string;\n serverUrl?: string;\n /// Optional webhook signature tolerance in seconds (default 300)\n webhookTolerance?: number;\n}\n\nexport class Instasign {\n private client: AxiosInstance;\n\n public envelopes: Envelopes;\n public signRequests: SignRequests;\n public webhooks: Webhooks;\n\n constructor(config: IInstasignConfig) {\n this.client = axios.create({\n baseURL: config.serverUrl || 'https://parseapi.back4app.com',\n headers: {\n 'X-Parse-APPLICATION-ID': config.appId || 'jKFo8BFQRdiAUV4F3o3SIDWLpLUb2TVW7bVl7lwH',\n 'X-Parse-REST-API-KEY': config.restApiKey || 'Gjm9pmxZh0DjXHkcFlf0kGZjHfYEY4ERw71TvLig',\n 'x-api-key': config.apiKey,\n 'Content-Type': 'application/json',\n },\n });\n\n this.envelopes = new Envelopes(this.client);\n this.signRequests = new SignRequests(this.client);\n this.webhooks = new Webhooks(config.webhookTolerance ?? 300);\n }\n}\n\n","import { AxiosInstance } from 'axios';\nimport {\n type CreateEnvelopeParams,\n type CreateEnvelopeResponse,\n type GetEnvelopesParams,\n type EnvelopeListItem,\n type Envelope,\n type OperationResponse,\n type UpdateEnvelopeMetadataParams,\n type UpdateEnvelopeMetadataResponse,\n type RemoveSignRequestFromEnvelopeParams,\n type AddSignRequestToEnvelopeParams,\n type AddSignRequestToEnvelopeResponse,\n} from '../types.js';\n\nexport class Envelopes {\n constructor(private client: AxiosInstance) { }\n\n /**\n * Create a new envelope\n */\n async create(params: CreateEnvelopeParams): Promise<CreateEnvelopeResponse | undefined> {\n const response = await this.client.post('/functions/createEnvelope', params);\n return response.data.result;\n }\n\n /**\n * List envelopes\n */\n async list(params: GetEnvelopesParams = {}): Promise<EnvelopeListItem[] | undefined> {\n const response = await this.client.post('/functions/getEnvelopes', params);\n return response.data.result;\n }\n\n /**\n * Retrieve a single envelope with its sign requests\n */\n async get(envelopeId: string): Promise<Envelope | undefined> {\n const response = await this.client.post('/functions/getEnvelope', { envelopeId });\n return response.data.result;\n }\n\n /**\n * Complete an envelope\n */\n async complete(envelopeId: string): Promise<OperationResponse | undefined> {\n const response = await this.client.post('/functions/completeEnvelope', { envelopeId });\n return response.data.result;\n }\n\n /**\n * Delete an envelope\n */\n async delete(envelopeId: string): Promise<OperationResponse | undefined> {\n const response = await this.client.post('/functions/deleteEnvelope', { envelopeId });\n return response.data.result;\n }\n\n /**\n * Update envelope metadata\n */\n async updateMetadata(params: UpdateEnvelopeMetadataParams): Promise<UpdateEnvelopeMetadataResponse | undefined> {\n const response = await this.client.post('/functions/updateEnvelopeMetadata', params);\n return response.data.result;\n }\n\n /**\n * Remove a sign request from an envelope\n */\n async removeSignRequest(params: RemoveSignRequestFromEnvelopeParams): Promise<OperationResponse | undefined> {\n const response = await this.client.post('/functions/removeSignRequestFromEnvelope', params);\n return response.data.result;\n }\n\n /**\n * Add a sign request to an envelope\n */\n async addSignRequest(params: AddSignRequestToEnvelopeParams): Promise<AddSignRequestToEnvelopeResponse | undefined> {\n const response = await this.client.post('/functions/addSignRequestToEnvelope', params);\n return response.data.result;\n }\n\n /**\n * Add multiple sign requests to an envelope\n */\n // async addSignRequests(params: AddSignRequestToEnvelopeParams[]): Promise<AddSignRequestToEnvelopeResponse[] | undefined> {\n // // TODO(ciro): must be implemented on back-end\n // const response = await this.client.post('/functions/addMultipleSignRequestsToEnvelope', params);\n // return response.data.result;\n // }\n}","import { AxiosInstance } from 'axios';\nimport {\n type CreateSignRequestParams,\n type CreateSignRequestResponse,\n type CompleteSignRequestParams,\n type CompleteSignRequestResponse,\n type SignRequestFile,\n} from '../types.js';\n\nexport class SignRequests {\n constructor(private client: AxiosInstance) { }\n\n /**\n * Create a new sign request\n */\n async create(params: CreateSignRequestParams): Promise<CreateSignRequestResponse | undefined> {\n const response = await this.client.post('/functions/createSignRequest', params);\n return response.data.result;\n }\n\n /**\n * Complete a sign request\n */\n async complete(params: CompleteSignRequestParams): Promise<CompleteSignRequestResponse | undefined> {\n const response = await this.client.post('/functions/completeSignRequest', params);\n return response.data.result;\n }\n\n /**\n * Get the file associated with a sign request\n */\n async getFile(requestId: string): Promise<SignRequestFile | undefined> {\n const response = await this.client.post('/functions/getFileFromRequestId', { requestId });\n return response.data.result;\n }\n}","import * as crypto from 'node:crypto';\nimport { WebhookEvent } from '../types';\n\nexport class Webhooks {\n constructor(private tolerance: number = 300) { }\n\n /**\n * Verify and parse a webhook event\n */\n public constructEvent(payload: string, signatureHeader: string, webhookSecret: string): WebhookEvent {\n const parts = signatureHeader.split(',');\n const timestamp = parts.find((p) => p.startsWith('t='))?.split('=')[1];\n const signature = parts.find((p) => p.startsWith('v1='))?.split('=')[1];\n\n if (!timestamp || !signature) {\n throw new Error('Invalid signature header');\n }\n\n const now = Math.floor(Date.now() / 1000);\n if (Math.abs(now - parseInt(timestamp)) > this.tolerance) {\n throw new Error('Signature too old');\n }\n\n const signedPayload = `${timestamp}.${payload}`;\n const expectedSignature = crypto\n .createHmac('sha256', webhookSecret)\n .update(signedPayload)\n .digest('hex');\n\n const isValid = crypto.timingSafeEqual(\n Buffer.from(signature),\n Buffer.from(expectedSignature)\n );\n\n if (!isValid) {\n throw new Error('Invalid signature');\n }\n\n return JSON.parse(payload) as WebhookEvent;\n }\n}\n"],"mappings":";AAAA,OAAO,WAA8B;;;ACe9B,IAAM,YAAN,MAAgB;AAAA,EACnB,YA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B,GAAG,SAAS,IAAI,OAAO;AAC7C,UAAM,oBACD,kBAAW,UAAU,aAAa,EAClC,OAAO,aAAa,EACpB,OAAO,KAAK;AAEjB,UAAM,UAAiB;AAAA,MACnB,OAAO,KAAK,SAAS;AAAA,MACrB,OAAO,KAAK,iBAAiB;AAAA,IACjC;AAEA,QAAI,CAAC,SAAS;AACV,YAAM,IAAI,MAAM,mBAAmB;AAAA,IACvC;AAEA,WAAO,KAAK,MAAM,OAAO;AAAA,EAC7B;AACJ;;;AHjBO,IAAM,YAAN,MAAgB;AAAA,EACb;AAAA,EAED;AAAA,EACA;AAAA,EACA;AAAA,EAEP,YAAY,QAA0B;AACpC,SAAK,SAAS,MAAM,OAAO;AAAA,MACzB,SAAS,OAAO,aAAa;AAAA,MAC7B,SAAS;AAAA,QACP,0BAA0B,OAAO,SAAS;AAAA,QAC1C,wBAAwB,OAAO,cAAc;AAAA,QAC7C,aAAa,OAAO;AAAA,QACpB,gBAAgB;AAAA,MAClB;AAAA,IACF,CAAC;AAED,SAAK,YAAY,IAAI,UAAU,KAAK,MAAM;AAC1C,SAAK,eAAe,IAAI,aAAa,KAAK,MAAM;AAChD,SAAK,WAAW,IAAI,SAAS,OAAO,oBAAoB,GAAG;AAAA,EAC7D;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instasign",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Instasign API wrapper",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
7
21
|
"files": [
|
|
8
22
|
"dist",
|
|
23
|
+
"types",
|
|
9
24
|
"README.md",
|
|
10
25
|
"CHANGELOG.md"
|
|
11
26
|
],
|
|
12
27
|
"scripts": {
|
|
13
|
-
"build": "
|
|
28
|
+
"build": "tsup",
|
|
29
|
+
"dev": "tsup --watch",
|
|
14
30
|
"prepublishOnly": "npm run build"
|
|
15
31
|
},
|
|
16
32
|
"keywords": [
|
|
@@ -28,12 +44,13 @@
|
|
|
28
44
|
"Ciro Carandente"
|
|
29
45
|
],
|
|
30
46
|
"license": "Apache-2.0",
|
|
31
|
-
"type": "module",
|
|
32
47
|
"dependencies": {
|
|
33
|
-
"axios": "^1.12.2"
|
|
48
|
+
"axios": "^1.12.2",
|
|
49
|
+
"@instasign/types": "*"
|
|
34
50
|
},
|
|
35
51
|
"devDependencies": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
52
|
+
"tsup": "^8.0.0",
|
|
53
|
+
"typescript": "^5.8.0",
|
|
54
|
+
"@types/node": "^22.0.0"
|
|
38
55
|
}
|
|
39
56
|
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
2
|
-
import type { paths } from '../schema.js';
|
|
3
|
-
export type CreateEnvelopeParams = NonNullable<paths["/functions/createEnvelope"]["post"]["requestBody"]>["content"]["application/json"];
|
|
4
|
-
export type CreateEnvelopeResponse = NonNullable<NonNullable<paths["/functions/createEnvelope"]["post"]["responses"]>["200"]["content"]>["application/json"]["result"];
|
|
5
|
-
export type GetEnvelopesParams = NonNullable<paths["/functions/getEnvelopes"]["post"]["requestBody"]>["content"]["application/json"];
|
|
6
|
-
export type GetEnvelopesResponse = NonNullable<NonNullable<paths["/functions/getEnvelopes"]["post"]["responses"]>["200"]["content"]>["application/json"]["result"];
|
|
7
|
-
export type GetEnvelopeResponse = NonNullable<NonNullable<paths["/functions/getEnvelope"]["post"]["responses"]>["200"]["content"]>["application/json"]["result"];
|
|
8
|
-
export type CompleteEnvelopeResponse = NonNullable<NonNullable<paths["/functions/completeEnvelope"]["post"]["responses"]>["200"]["content"]>["application/json"]["result"];
|
|
9
|
-
export type DeleteEnvelopeResponse = NonNullable<NonNullable<paths["/functions/deleteEnvelope"]["post"]["responses"]>["200"]["content"]>["application/json"]["result"];
|
|
10
|
-
export type UpdateEnvelopeMetadataParams = NonNullable<paths["/functions/updateEnvelopeMetadata"]["post"]["requestBody"]>["content"]["application/json"];
|
|
11
|
-
export type UpdateEnvelopeMetadataResponse = NonNullable<NonNullable<paths["/functions/updateEnvelopeMetadata"]["post"]["responses"]>["200"]["content"]>["application/json"]["result"];
|
|
12
|
-
export type RemoveSignRequestFromEnvelopeParams = NonNullable<paths["/functions/removeSignRequestFromEnvelope"]["post"]["requestBody"]>["content"]["application/json"];
|
|
13
|
-
export type RemoveSignRequestFromEnvelopeResponse = NonNullable<NonNullable<paths["/functions/removeSignRequestFromEnvelope"]["post"]["responses"]>["200"]["content"]>["application/json"]["result"];
|
|
14
|
-
export type AddSignRequestToEnvelopeParams = NonNullable<paths["/functions/addSignRequestToEnvelope"]["post"]["requestBody"]>["content"]["application/json"];
|
|
15
|
-
export type AddSignRequestToEnvelopeResponse = NonNullable<NonNullable<paths["/functions/addSignRequestToEnvelope"]["post"]["responses"]>["200"]["content"]>["application/json"]["result"];
|
|
16
|
-
export type AddSignRequestsToEnvelopeParams = AddSignRequestToEnvelopeParams[];
|
|
17
|
-
export type AddSignRequestsToEnvelopeResponse = AddSignRequestToEnvelopeResponse[];
|
|
18
|
-
export declare class Envelopes {
|
|
19
|
-
private client;
|
|
20
|
-
constructor(client: AxiosInstance);
|
|
21
|
-
/**
|
|
22
|
-
* Create a new envelope
|
|
23
|
-
*/
|
|
24
|
-
create(params: CreateEnvelopeParams): Promise<CreateEnvelopeResponse>;
|
|
25
|
-
/**
|
|
26
|
-
* List envelopes
|
|
27
|
-
*/
|
|
28
|
-
list(params?: GetEnvelopesParams): Promise<GetEnvelopesResponse>;
|
|
29
|
-
/**
|
|
30
|
-
* Retrieve envelope status
|
|
31
|
-
*/
|
|
32
|
-
get(envelopeId: string): Promise<GetEnvelopeResponse>;
|
|
33
|
-
/**
|
|
34
|
-
* Complete an envelope
|
|
35
|
-
*/
|
|
36
|
-
complete(envelopeId: string): Promise<CompleteEnvelopeResponse>;
|
|
37
|
-
/**
|
|
38
|
-
* Delete an envelope
|
|
39
|
-
*/
|
|
40
|
-
delete(envelopeId: string): Promise<DeleteEnvelopeResponse>;
|
|
41
|
-
/**
|
|
42
|
-
* Update envelope metadata
|
|
43
|
-
*/
|
|
44
|
-
updateMetadata(params: UpdateEnvelopeMetadataParams): Promise<UpdateEnvelopeMetadataResponse>;
|
|
45
|
-
/**
|
|
46
|
-
* Remove sign request from envelope
|
|
47
|
-
*/
|
|
48
|
-
removeSignRequest(params: RemoveSignRequestFromEnvelopeParams): Promise<RemoveSignRequestFromEnvelopeResponse>;
|
|
49
|
-
/**
|
|
50
|
-
* Add sign request to envelope
|
|
51
|
-
*/
|
|
52
|
-
addSignRequest(params: AddSignRequestToEnvelopeParams): Promise<AddSignRequestToEnvelopeResponse>;
|
|
53
|
-
/**
|
|
54
|
-
* Add multiple sign request to envelope
|
|
55
|
-
*/
|
|
56
|
-
addSignRequests(params: AddSignRequestsToEnvelopeParams): Promise<AddSignRequestsToEnvelopeResponse>;
|
|
57
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
export class Envelopes {
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Create a new envelope
|
|
8
|
-
*/
|
|
9
|
-
async create(params) {
|
|
10
|
-
const response = await this.client.post('/functions/createEnvelope', params);
|
|
11
|
-
return response.data.result;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* List envelopes
|
|
15
|
-
*/
|
|
16
|
-
async list(params = {}) {
|
|
17
|
-
const response = await this.client.post('/functions/getEnvelopes', params);
|
|
18
|
-
return response.data.result;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Retrieve envelope status
|
|
22
|
-
*/
|
|
23
|
-
async get(envelopeId) {
|
|
24
|
-
const response = await this.client.post('/functions/getEnvelope', { envelopeId });
|
|
25
|
-
return response.data.result;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Complete an envelope
|
|
29
|
-
*/
|
|
30
|
-
async complete(envelopeId) {
|
|
31
|
-
const response = await this.client.post('/functions/completeEnvelope', { envelopeId });
|
|
32
|
-
return response.data.result;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Delete an envelope
|
|
36
|
-
*/
|
|
37
|
-
async delete(envelopeId) {
|
|
38
|
-
const response = await this.client.post('/functions/deleteEnvelope', { envelopeId });
|
|
39
|
-
return response.data.result;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Update envelope metadata
|
|
43
|
-
*/
|
|
44
|
-
async updateMetadata(params) {
|
|
45
|
-
const response = await this.client.post('/functions/updateEnvelopeMetadata', params);
|
|
46
|
-
return response.data.result;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Remove sign request from envelope
|
|
50
|
-
*/
|
|
51
|
-
async removeSignRequest(params) {
|
|
52
|
-
const response = await this.client.post('/functions/removeSignRequestFromEnvelope', params);
|
|
53
|
-
return response.data.result;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Add sign request to envelope
|
|
57
|
-
*/
|
|
58
|
-
async addSignRequest(params) {
|
|
59
|
-
const response = await this.client.post('/functions/addSignRequestToEnvelope', params);
|
|
60
|
-
return response.data.result;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Add multiple sign request to envelope
|
|
64
|
-
*/
|
|
65
|
-
async addSignRequests(params) {
|
|
66
|
-
const response = await this.client.post('/functions/addMultipleSignRequestsToEnvelope', params);
|
|
67
|
-
return response.data.result;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
2
|
-
import type { paths } from '../schema.js';
|
|
3
|
-
export type CreateSignRequestParams = NonNullable<paths["/functions/createSignRequest"]["post"]["requestBody"]>["content"]["application/json"];
|
|
4
|
-
export type CreateSignRequestResponse = NonNullable<NonNullable<paths["/functions/createSignRequest"]["post"]["responses"]>["200"]["content"]>["application/json"]["result"];
|
|
5
|
-
export type CompleteSignRequestParams = NonNullable<paths["/functions/completeSignRequest"]["post"]["requestBody"]>["content"]["application/json"];
|
|
6
|
-
export type CompleteSignRequestResponse = NonNullable<NonNullable<paths["/functions/completeSignRequest"]["post"]["responses"]>["200"]["content"]>["application/json"]["result"];
|
|
7
|
-
export type GetFileFromRequestIdResponse = NonNullable<NonNullable<paths["/functions/getFileFromRequestId"]["post"]["responses"]>["200"]["content"]>["application/json"]["result"];
|
|
8
|
-
export declare class SignRequests {
|
|
9
|
-
private client;
|
|
10
|
-
constructor(client: AxiosInstance);
|
|
11
|
-
/**
|
|
12
|
-
* Create a new sign request
|
|
13
|
-
*/
|
|
14
|
-
create(params: CreateSignRequestParams): Promise<CreateSignRequestResponse>;
|
|
15
|
-
/**
|
|
16
|
-
* Complete a sign request
|
|
17
|
-
*/
|
|
18
|
-
complete(params: CompleteSignRequestParams): Promise<CompleteSignRequestResponse>;
|
|
19
|
-
/**
|
|
20
|
-
* Get file from request id
|
|
21
|
-
*/
|
|
22
|
-
getFile(requestId: string): Promise<GetFileFromRequestIdResponse>;
|
|
23
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export class SignRequests {
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Create a new sign request
|
|
8
|
-
*/
|
|
9
|
-
async create(params) {
|
|
10
|
-
const response = await this.client.post('/functions/createSignRequest', params);
|
|
11
|
-
return response.data.result;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Complete a sign request
|
|
15
|
-
*/
|
|
16
|
-
async complete(params) {
|
|
17
|
-
const response = await this.client.post('/functions/completeSignRequest', params);
|
|
18
|
-
return response.data.result;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Get file from request id
|
|
22
|
-
*/
|
|
23
|
-
async getFile(requestId) {
|
|
24
|
-
const response = await this.client.post('/functions/getFileFromRequestId', { requestId });
|
|
25
|
-
return response.data.result;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type WebhookEvent = any;
|
|
2
|
-
export declare class Webhooks {
|
|
3
|
-
private tolerance;
|
|
4
|
-
constructor(tolerance?: number);
|
|
5
|
-
/**
|
|
6
|
-
* Verify and parse a webhook event
|
|
7
|
-
*/
|
|
8
|
-
constructEvent(payload: string, signatureHeader: string, webhookSecret: string): WebhookEvent;
|
|
9
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
export class Webhooks {
|
|
3
|
-
tolerance;
|
|
4
|
-
constructor(tolerance = 300) {
|
|
5
|
-
this.tolerance = tolerance;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Verify and parse a webhook event
|
|
9
|
-
*/
|
|
10
|
-
constructEvent(payload, signatureHeader, webhookSecret) {
|
|
11
|
-
const parts = signatureHeader.split(',');
|
|
12
|
-
const timestamp = parts.find((p) => p.startsWith('t='))?.split('=')[1];
|
|
13
|
-
const signature = parts.find((p) => p.startsWith('v1='))?.split('=')[1];
|
|
14
|
-
if (!timestamp || !signature) {
|
|
15
|
-
throw new Error('Invalid signature header');
|
|
16
|
-
}
|
|
17
|
-
const now = Math.floor(Date.now() / 1000);
|
|
18
|
-
if (Math.abs(now - parseInt(timestamp)) > this.tolerance) {
|
|
19
|
-
throw new Error('Signature too old');
|
|
20
|
-
}
|
|
21
|
-
const signedPayload = `${timestamp}.${payload}`;
|
|
22
|
-
const expectedSignature = crypto
|
|
23
|
-
.createHmac('sha256', webhookSecret)
|
|
24
|
-
.update(signedPayload)
|
|
25
|
-
.digest('hex');
|
|
26
|
-
const isValid = crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expectedSignature));
|
|
27
|
-
if (!isValid) {
|
|
28
|
-
throw new Error('Invalid signature');
|
|
29
|
-
}
|
|
30
|
-
return JSON.parse(payload);
|
|
31
|
-
}
|
|
32
|
-
}
|