instasign 1.1.2 → 1.1.4
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 +16 -0
- package/README.md +16 -9
- package/dist/index.cjs +50 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +321 -855
- package/dist/index.d.ts +321 -855
- package/dist/index.js +45 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/types/schema.d.ts +149 -637
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.1.4] - 2026-03-01
|
|
6
|
+
- **Type Safety**: Improved internal type synchronization with compile-time schema validation against the OpenAPI specification.
|
|
7
|
+
|
|
8
|
+
## [1.1.3] - 2026-03-01
|
|
9
|
+
- **Improved Type Precision**: Refactored resource types (Envelopes, SignRequests) to be derived directly from the OpenAPI schema using new utility types (`ResponseResult`, `RequestBody`).
|
|
10
|
+
- **Read-only Resources**: The `envelopes`, `signRequests`, and `webhooks` properties on the `Instasign` class are now `readonly`.
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- **Swagger Enum Serialization**: Fixed an issue where string union types (like `status`) were serialized as generic objects in Swagger.
|
|
14
|
+
- **Swagger Param Enums**: Enhanced parameter extraction to correctly map cloud function parameters (like `orderBy`, `orderDirection`) to OpenAPI enums.
|
|
15
|
+
- **Swagger Nested Objects**: Increased recursion depth and refined mapping to ensure nested arrays and objects (like `signRequests` inside `envelope:list`) are fully typed.
|
|
16
|
+
- **Swagger Date Serialization**: Fixed `Date` objects being expanded into generic objects; they are now correctly mapped to `string` with `format: date-time`.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- **Type Safety**: Improved internal type synchronization with compile-time schema validation against the OpenAPI specification.
|
|
20
|
+
|
|
5
21
|
## [1.1.2] - 2026-03-01
|
|
6
22
|
|
|
7
23
|
### Added
|
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ npm install instasign
|
|
|
15
15
|
|
|
16
16
|
## Usage
|
|
17
17
|
|
|
18
|
-
The package needs to be configured with your account's API key.
|
|
18
|
+
The package needs to be configured with your account's API key. You can also provide Parse Server configuration if you are using a custom instance.
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
21
|
import { Instasign } from 'instasign';
|
|
@@ -23,9 +23,9 @@ import { Instasign } from 'instasign';
|
|
|
23
23
|
const instasign = new Instasign({
|
|
24
24
|
apiKey: 'your_api_key',
|
|
25
25
|
restApiKey: 'your_parse_rest_api_key', // Optional
|
|
26
|
-
serverUrl: 'https://
|
|
27
|
-
appId: 'your_app_id', // Optional
|
|
28
|
-
webhookTolerance: 300 // default is 300 seconds
|
|
26
|
+
serverUrl: 'https://api.instasign.io', // Optional: Your server URL
|
|
27
|
+
appId: 'your_app_id', // Optional: Your Parse App ID
|
|
28
|
+
webhookTolerance: 300 // default is 300 seconds
|
|
29
29
|
});
|
|
30
30
|
```
|
|
31
31
|
|
|
@@ -40,8 +40,12 @@ const envelope = await instasign.envelopes.create({
|
|
|
40
40
|
description: 'Please sign the attached document',
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
// List envelopes
|
|
44
|
-
const envelopes = await instasign.envelopes.list(
|
|
43
|
+
// List envelopes with full type support for nested objects
|
|
44
|
+
const envelopes = await instasign.envelopes.list({
|
|
45
|
+
status: 'pending',
|
|
46
|
+
orderBy: 'createdAt',
|
|
47
|
+
orderDirection: 'desc'
|
|
48
|
+
});
|
|
45
49
|
|
|
46
50
|
// Retrieve an envelope by ID
|
|
47
51
|
const envelope = await instasign.envelopes.get('envelope_id_here');
|
|
@@ -95,8 +99,8 @@ const endpointSecret = 'secret_key';
|
|
|
95
99
|
|
|
96
100
|
try {
|
|
97
101
|
const event = instasign.webhooks.constructEvent(payload, sig, endpointSecret);
|
|
98
|
-
// Handle the event
|
|
99
|
-
console.log(event.type);
|
|
102
|
+
// Handle the event (fully typed)
|
|
103
|
+
console.log(event.type); // e.g., 'envelope.completed'
|
|
100
104
|
} catch (err) {
|
|
101
105
|
console.error(`Webhook Error: ${err.message}`);
|
|
102
106
|
res.status(400).send(`Webhook Error: ${err.message}`);
|
|
@@ -105,7 +109,10 @@ try {
|
|
|
105
109
|
|
|
106
110
|
## TypeScript Support
|
|
107
111
|
|
|
108
|
-
This library is built with TypeScript and provides industry-standard type definitions auto-generated from the Instasign OpenAPI schema. Every method in the SDK is strictly typed,
|
|
112
|
+
This library is built with TypeScript and provides industry-standard type definitions auto-generated from the Instasign OpenAPI schema. Every method in the SDK is strictly typed, including:
|
|
113
|
+
- **Enums**: Fields like `status`, `orderBy`, and `orderDirection` use string union types.
|
|
114
|
+
- **Nested Objects**: Complex structures like the `signRequests` array inside an envelope are fully typed.
|
|
115
|
+
- **Dates**: Automatic mapping of ISO date strings for `createdAt`, `updatedAt`, and `expirationDate`.
|
|
109
116
|
|
|
110
117
|
## Configuration Options
|
|
111
118
|
|
package/dist/index.cjs
CHANGED
|
@@ -33,10 +33,14 @@ __export(index_exports, {
|
|
|
33
33
|
Envelopes: () => Envelopes,
|
|
34
34
|
Instasign: () => Instasign,
|
|
35
35
|
SignRequests: () => SignRequests,
|
|
36
|
+
VALID_ENVELOPE_STATUSES: () => VALID_ENVELOPE_STATUSES,
|
|
37
|
+
VALID_ORDER_BY: () => VALID_ORDER_BY,
|
|
38
|
+
VALID_ORDER_DIRECTION: () => VALID_ORDER_DIRECTION,
|
|
39
|
+
VALID_SIGN_REQUEST_STATUSES: () => VALID_SIGN_REQUEST_STATUSES,
|
|
40
|
+
VALID_WEBHOOK_EVENT_TYPES: () => VALID_WEBHOOK_EVENT_TYPES,
|
|
36
41
|
Webhooks: () => Webhooks
|
|
37
42
|
});
|
|
38
43
|
module.exports = __toCommonJS(index_exports);
|
|
39
|
-
var import_axios = __toESM(require("axios"), 1);
|
|
40
44
|
|
|
41
45
|
// src/resources/Envelopes.ts
|
|
42
46
|
var Envelopes = class {
|
|
@@ -47,56 +51,56 @@ var Envelopes = class {
|
|
|
47
51
|
* Create a new envelope
|
|
48
52
|
*/
|
|
49
53
|
async create(params) {
|
|
50
|
-
const response = await this.client.post("/functions/
|
|
54
|
+
const response = await this.client.post("/functions/envelope:create", params);
|
|
51
55
|
return response.data.result;
|
|
52
56
|
}
|
|
53
57
|
/**
|
|
54
58
|
* List envelopes
|
|
55
59
|
*/
|
|
56
60
|
async list(params = {}) {
|
|
57
|
-
const response = await this.client.post("/functions/
|
|
61
|
+
const response = await this.client.post("/functions/envelope:list", params);
|
|
58
62
|
return response.data.result;
|
|
59
63
|
}
|
|
60
64
|
/**
|
|
61
65
|
* Retrieve a single envelope with its sign requests
|
|
62
66
|
*/
|
|
63
67
|
async get(envelopeId) {
|
|
64
|
-
const response = await this.client.post("/functions/
|
|
68
|
+
const response = await this.client.post("/functions/envelope:get", { envelopeId });
|
|
65
69
|
return response.data.result;
|
|
66
70
|
}
|
|
67
71
|
/**
|
|
68
72
|
* Complete an envelope
|
|
69
73
|
*/
|
|
70
74
|
async complete(envelopeId) {
|
|
71
|
-
const response = await this.client.post("/functions/
|
|
75
|
+
const response = await this.client.post("/functions/envelope:complete", { envelopeId });
|
|
72
76
|
return response.data.result;
|
|
73
77
|
}
|
|
74
78
|
/**
|
|
75
79
|
* Delete an envelope
|
|
76
80
|
*/
|
|
77
81
|
async delete(envelopeId) {
|
|
78
|
-
const response = await this.client.post("/functions/
|
|
82
|
+
const response = await this.client.post("/functions/envelope:delete", { envelopeId });
|
|
79
83
|
return response.data.result;
|
|
80
84
|
}
|
|
81
85
|
/**
|
|
82
86
|
* Update envelope metadata
|
|
83
87
|
*/
|
|
84
88
|
async updateMetadata(params) {
|
|
85
|
-
const response = await this.client.post("/functions/
|
|
89
|
+
const response = await this.client.post("/functions/envelope:update-metadata", params);
|
|
86
90
|
return response.data.result;
|
|
87
91
|
}
|
|
88
92
|
/**
|
|
89
93
|
* Remove a sign request from an envelope
|
|
90
94
|
*/
|
|
91
95
|
async removeSignRequest(params) {
|
|
92
|
-
const response = await this.client.post("/functions/
|
|
96
|
+
const response = await this.client.post("/functions/envelope:remove-sign-request", params);
|
|
93
97
|
return response.data.result;
|
|
94
98
|
}
|
|
95
99
|
/**
|
|
96
100
|
* Add a sign request to an envelope
|
|
97
101
|
*/
|
|
98
102
|
async addSignRequest(params) {
|
|
99
|
-
const response = await this.client.post("/functions/
|
|
103
|
+
const response = await this.client.post("/functions/envelope:add-sign-request", params);
|
|
100
104
|
return response.data.result;
|
|
101
105
|
}
|
|
102
106
|
/**
|
|
@@ -118,21 +122,21 @@ var SignRequests = class {
|
|
|
118
122
|
* Create a new sign request
|
|
119
123
|
*/
|
|
120
124
|
async create(params) {
|
|
121
|
-
const response = await this.client.post("/functions/
|
|
125
|
+
const response = await this.client.post("/functions/sign-request:create", params);
|
|
122
126
|
return response.data.result;
|
|
123
127
|
}
|
|
124
128
|
/**
|
|
125
129
|
* Complete a sign request
|
|
126
130
|
*/
|
|
127
131
|
async complete(params) {
|
|
128
|
-
const response = await this.client.post("/functions/
|
|
132
|
+
const response = await this.client.post("/functions/sign-request:complete", params);
|
|
129
133
|
return response.data.result;
|
|
130
134
|
}
|
|
131
135
|
/**
|
|
132
136
|
* Get the file associated with a sign request
|
|
133
137
|
*/
|
|
134
|
-
async
|
|
135
|
-
const response = await this.client.post("/functions/
|
|
138
|
+
async get(requestId) {
|
|
139
|
+
const response = await this.client.post("/functions/sign-request:get", { requestId });
|
|
136
140
|
return response.data.result;
|
|
137
141
|
}
|
|
138
142
|
};
|
|
@@ -170,7 +174,8 @@ var Webhooks = class {
|
|
|
170
174
|
}
|
|
171
175
|
};
|
|
172
176
|
|
|
173
|
-
// src/
|
|
177
|
+
// src/instasign.ts
|
|
178
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
174
179
|
var Instasign = class {
|
|
175
180
|
client;
|
|
176
181
|
envelopes;
|
|
@@ -178,10 +183,10 @@ var Instasign = class {
|
|
|
178
183
|
webhooks;
|
|
179
184
|
constructor(config) {
|
|
180
185
|
this.client = import_axios.default.create({
|
|
181
|
-
baseURL: config.serverUrl
|
|
186
|
+
baseURL: config.serverUrl,
|
|
182
187
|
headers: {
|
|
183
|
-
"X-Parse-APPLICATION-ID": config.appId
|
|
184
|
-
"X-Parse-REST-API-KEY": config.restApiKey
|
|
188
|
+
"X-Parse-APPLICATION-ID": config.appId,
|
|
189
|
+
"X-Parse-REST-API-KEY": config.restApiKey,
|
|
185
190
|
"x-api-key": config.apiKey,
|
|
186
191
|
"Content-Type": "application/json"
|
|
187
192
|
}
|
|
@@ -191,11 +196,39 @@ var Instasign = class {
|
|
|
191
196
|
this.webhooks = new Webhooks(config.webhookTolerance ?? 300);
|
|
192
197
|
}
|
|
193
198
|
};
|
|
199
|
+
|
|
200
|
+
// ../types/src/index.ts
|
|
201
|
+
var VALID_WEBHOOK_EVENT_TYPES = [
|
|
202
|
+
"envelope_created",
|
|
203
|
+
"envelope_expired",
|
|
204
|
+
"sign_request_created",
|
|
205
|
+
"sign_request_signed",
|
|
206
|
+
"sign_request_expired"
|
|
207
|
+
];
|
|
208
|
+
var VALID_SIGN_REQUEST_STATUSES = [
|
|
209
|
+
"pending",
|
|
210
|
+
"completed",
|
|
211
|
+
"canceled",
|
|
212
|
+
"queued"
|
|
213
|
+
];
|
|
214
|
+
var VALID_ENVELOPE_STATUSES = [
|
|
215
|
+
"pending",
|
|
216
|
+
"in-progress",
|
|
217
|
+
"completed",
|
|
218
|
+
"cancelled"
|
|
219
|
+
];
|
|
220
|
+
var VALID_ORDER_BY = ["updatedAt", "createdAt"];
|
|
221
|
+
var VALID_ORDER_DIRECTION = ["asc", "desc"];
|
|
194
222
|
// Annotate the CommonJS export names for ESM import in node:
|
|
195
223
|
0 && (module.exports = {
|
|
196
224
|
Envelopes,
|
|
197
225
|
Instasign,
|
|
198
226
|
SignRequests,
|
|
227
|
+
VALID_ENVELOPE_STATUSES,
|
|
228
|
+
VALID_ORDER_BY,
|
|
229
|
+
VALID_ORDER_DIRECTION,
|
|
230
|
+
VALID_SIGN_REQUEST_STATUSES,
|
|
231
|
+
VALID_WEBHOOK_EVENT_TYPES,
|
|
199
232
|
Webhooks
|
|
200
233
|
});
|
|
201
234
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +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';\nexport * from './types.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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AAC,WAAW;AAC1B,YAAM,IAAI,MAAM,0BAA0B;AAAA,IAC9C;AAEA,UAAM,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AACxC,QAAI,KAAK,IAAI,MAAM,SAAS,SAAS,CAAC,IAAI,KAAK,WAAW;AACtD,YAAM,IAAI,MAAM,mBAAmB;AAAA,IACvC;AAEA,UAAM,gBAAgB,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;;;AHhBO,IAAM,YAAN,MAAgB;AAAA,EACb;AAAA,EAED;AAAA,EACA;AAAA,EACA;AAAA,EAEP,YAAY,QAA0B;AACpC,SAAK,SAAS,aAAAA,QAAM,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":["axios"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/resources/Envelopes.ts","../src/resources/SignRequests.ts","../src/resources/Webhooks.ts","../src/instasign.ts","../../types/src/index.ts"],"sourcesContent":["export * from './resources/Envelopes.js';\nexport * from './resources/SignRequests.js';\nexport * from './resources/Webhooks.js';\nexport * from './instasign.js';\nexport * from './types.js';\nexport * from '@instasign/types';\n\nexport type * from '../types/schema.js';","import { AxiosInstance } from 'axios';\nimport {\n Envelope,\n type AddSignRequestToEnvelopeParams,\n type AddSignRequestToEnvelopeResponse,\n type CreateEnvelopeParams,\n type CreateEnvelopeResponse,\n type GetEnvelopesParams,\n type OperationResponse,\n type RemoveSignRequestFromEnvelopeParams,\n type UpdateEnvelopeMetadataParams,\n type UpdateEnvelopeMetadataResponse\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/envelope:create', params);\n return response.data.result;\n }\n\n /**\n * List envelopes\n */\n async list(params: GetEnvelopesParams = {}): Promise<Envelope[] | undefined> {\n const response = await this.client.post('/functions/envelope:list', 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/envelope:get', { 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/envelope:complete', { 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/envelope:delete', { 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/envelope:update-metadata', 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/envelope:remove-sign-request', 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/envelope:add-sign-request', 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 SignRequest,\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/sign-request:create', 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/sign-request:complete', params);\n return response.data.result;\n }\n\n /**\n * Get the file associated with a sign request\n */\n async get(requestId: string): Promise<SignRequest | undefined> {\n const response = await this.client.post('/functions/sign-request:get', { requestId });\n return response.data.result;\n }\n}","import * as crypto from 'node:crypto';\nimport { WebhookEvent } from '../types.js';\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","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 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 readonly envelopes: Envelopes;\n public readonly signRequests: SignRequests;\n public readonly webhooks: Webhooks;\n\n constructor(config: IInstasignConfig) {\n this.client = axios.create({\n baseURL: config.serverUrl,\n headers: {\n 'X-Parse-APPLICATION-ID': config.appId,\n 'X-Parse-REST-API-KEY': config.restApiKey,\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","export const VALID_WEBHOOK_EVENT_TYPES = [\n 'envelope_created',\n 'envelope_expired',\n 'sign_request_created',\n 'sign_request_signed',\n 'sign_request_expired',\n] as const;\n\nexport type WebhookEventType = typeof VALID_WEBHOOK_EVENT_TYPES[number];\n\nexport type WebhookStatus = 'pending' | 'success' | 'error';\n\nexport type WebhookPayloadMap = {\n 'envelope_created': { envelopeId: string };\n 'envelope_expired': { envelopeId: string };\n 'sign_request_created': { requestId: string; status: string; envelopeId?: string };\n 'sign_request_signed': { requestId: string; status: string; envelopeId?: string };\n 'sign_request_expired': { requestId: string };\n};\n\nexport const VALID_SIGN_REQUEST_STATUSES = [\n 'pending',\n 'completed',\n 'canceled',\n 'queued',\n] as const;\n\nexport type SignRequestStatus = typeof VALID_SIGN_REQUEST_STATUSES[number];\n\nexport const VALID_ENVELOPE_STATUSES = [\n 'pending',\n 'in-progress',\n 'completed',\n 'cancelled',\n] as const;\n\nexport type EnvelopeStatus = typeof VALID_ENVELOPE_STATUSES[number];\n\nexport type SignRequestMetadata = Record<string, unknown>;\nexport type EnvelopeMetadata = Record<string, unknown>;\n\nexport const VALID_ORDER_BY = ['updatedAt', 'createdAt'] as const;\nexport type OrderBy = (typeof VALID_ORDER_BY)[number];\n\nexport const VALID_ORDER_DIRECTION = ['asc', 'desc'] as const;\nexport type OrderDirection = (typeof VALID_ORDER_DIRECTION)[number];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACcO,IAAM,YAAN,MAAgB;AAAA,EACnB,YAAoB,QAAuB;AAAvB;AAAA,EAAyB;AAAA;AAAA;AAAA;AAAA,EAK7C,MAAM,OAAO,QAA2E;AACpF,UAAM,WAAW,MAAM,KAAK,OAAO,KAAK,8BAA8B,MAAM;AAC5E,WAAO,SAAS,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,SAA6B,CAAC,GAAoC;AACzE,UAAM,WAAW,MAAM,KAAK,OAAO,KAAK,4BAA4B,MAAM;AAC1E,WAAO,SAAS,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,IAAI,YAAmD;AACzD,UAAM,WAAW,MAAM,KAAK,OAAO,KAAK,2BAA2B,EAAE,WAAW,CAAC;AACjF,WAAO,SAAS,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,SAAS,YAA4D;AACvE,UAAM,WAAW,MAAM,KAAK,OAAO,KAAK,gCAAgC,EAAE,WAAW,CAAC;AACtF,WAAO,SAAS,KAAK;AAAA,EACzB;A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