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 CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [1.1.0] - 2026-02-28
6
+
7
+ ### Added
8
+ - **Envelopes API**: Added `complete(envelopeId)` method to finalize envelopes from the SDK.
9
+
10
+ ### Changed
11
+ - **License**: Changed package license from ISC to Apache-2.0.
12
+ - **Dependency Refactoring**: Moved shared types to a dedicated `@instasign/types` package for better consistency across the project.
13
+ - **Type Safety**: Improved internal type synchronization with compile-time schema validation against the OpenAPI specification.
14
+
5
15
  ## [1.0.1] - 2026-02-27
6
16
 
7
17
  ### Fixed
package/README.md CHANGED
@@ -10,7 +10,7 @@ The **Instasign Node.js SDK** provides convenient access to the **Instasign Serv
10
10
  Install the package with:
11
11
 
12
12
  ```bash
13
- npm install instasign-api-sdk
13
+ npm install instasign
14
14
  ```
15
15
 
16
16
  ## Usage
@@ -18,7 +18,7 @@ npm install instasign-api-sdk
18
18
  The package needs to be configured with your account's API key.
19
19
 
20
20
  ```typescript
21
- import { Instasign } from 'instasign-api-sdk';
21
+ import { Instasign } from 'instasign';
22
22
 
23
23
  const instasign = new Instasign({
24
24
  apiKey: 'your_api_key',
@@ -119,4 +119,4 @@ This library is built with TypeScript and provides industry-standard type defini
119
119
 
120
120
  ## License
121
121
 
122
- ISC
122
+ Apache-2.0
package/dist/index.cjs ADDED
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ Envelopes: () => Envelopes,
34
+ Instasign: () => Instasign,
35
+ SignRequests: () => SignRequests,
36
+ Webhooks: () => Webhooks
37
+ });
38
+ module.exports = __toCommonJS(index_exports);
39
+ var import_axios = __toESM(require("axios"), 1);
40
+
41
+ // src/resources/Envelopes.ts
42
+ var Envelopes = class {
43
+ constructor(client) {
44
+ this.client = client;
45
+ }
46
+ /**
47
+ * Create a new envelope
48
+ */
49
+ async create(params) {
50
+ const response = await this.client.post("/functions/createEnvelope", params);
51
+ return response.data.result;
52
+ }
53
+ /**
54
+ * List envelopes
55
+ */
56
+ async list(params = {}) {
57
+ const response = await this.client.post("/functions/getEnvelopes", params);
58
+ return response.data.result;
59
+ }
60
+ /**
61
+ * Retrieve a single envelope with its sign requests
62
+ */
63
+ async get(envelopeId) {
64
+ const response = await this.client.post("/functions/getEnvelope", { envelopeId });
65
+ return response.data.result;
66
+ }
67
+ /**
68
+ * Complete an envelope
69
+ */
70
+ async complete(envelopeId) {
71
+ const response = await this.client.post("/functions/completeEnvelope", { envelopeId });
72
+ return response.data.result;
73
+ }
74
+ /**
75
+ * Delete an envelope
76
+ */
77
+ async delete(envelopeId) {
78
+ const response = await this.client.post("/functions/deleteEnvelope", { envelopeId });
79
+ return response.data.result;
80
+ }
81
+ /**
82
+ * Update envelope metadata
83
+ */
84
+ async updateMetadata(params) {
85
+ const response = await this.client.post("/functions/updateEnvelopeMetadata", params);
86
+ return response.data.result;
87
+ }
88
+ /**
89
+ * Remove a sign request from an envelope
90
+ */
91
+ async removeSignRequest(params) {
92
+ const response = await this.client.post("/functions/removeSignRequestFromEnvelope", params);
93
+ return response.data.result;
94
+ }
95
+ /**
96
+ * Add a sign request to an envelope
97
+ */
98
+ async addSignRequest(params) {
99
+ const response = await this.client.post("/functions/addSignRequestToEnvelope", params);
100
+ return response.data.result;
101
+ }
102
+ /**
103
+ * Add multiple sign requests to an envelope
104
+ */
105
+ // async addSignRequests(params: AddSignRequestToEnvelopeParams[]): Promise<AddSignRequestToEnvelopeResponse[] | undefined> {
106
+ // // TODO(ciro): must be implemented on back-end
107
+ // const response = await this.client.post('/functions/addMultipleSignRequestsToEnvelope', params);
108
+ // return response.data.result;
109
+ // }
110
+ };
111
+
112
+ // src/resources/SignRequests.ts
113
+ var SignRequests = class {
114
+ constructor(client) {
115
+ this.client = client;
116
+ }
117
+ /**
118
+ * Create a new sign request
119
+ */
120
+ async create(params) {
121
+ const response = await this.client.post("/functions/createSignRequest", params);
122
+ return response.data.result;
123
+ }
124
+ /**
125
+ * Complete a sign request
126
+ */
127
+ async complete(params) {
128
+ const response = await this.client.post("/functions/completeSignRequest", params);
129
+ return response.data.result;
130
+ }
131
+ /**
132
+ * Get the file associated with a sign request
133
+ */
134
+ async getFile(requestId) {
135
+ const response = await this.client.post("/functions/getFileFromRequestId", { requestId });
136
+ return response.data.result;
137
+ }
138
+ };
139
+
140
+ // src/resources/Webhooks.ts
141
+ var crypto = __toESM(require("crypto"), 1);
142
+ var Webhooks = class {
143
+ constructor(tolerance = 300) {
144
+ this.tolerance = tolerance;
145
+ }
146
+ /**
147
+ * Verify and parse a webhook event
148
+ */
149
+ constructEvent(payload, signatureHeader, webhookSecret) {
150
+ const parts = signatureHeader.split(",");
151
+ const timestamp = parts.find((p) => p.startsWith("t="))?.split("=")[1];
152
+ const signature = parts.find((p) => p.startsWith("v1="))?.split("=")[1];
153
+ if (!timestamp || !signature) {
154
+ throw new Error("Invalid signature header");
155
+ }
156
+ const now = Math.floor(Date.now() / 1e3);
157
+ if (Math.abs(now - parseInt(timestamp)) > this.tolerance) {
158
+ throw new Error("Signature too old");
159
+ }
160
+ const signedPayload = `${timestamp}.${payload}`;
161
+ const expectedSignature = crypto.createHmac("sha256", webhookSecret).update(signedPayload).digest("hex");
162
+ const isValid = crypto.timingSafeEqual(
163
+ Buffer.from(signature),
164
+ Buffer.from(expectedSignature)
165
+ );
166
+ if (!isValid) {
167
+ throw new Error("Invalid signature");
168
+ }
169
+ return JSON.parse(payload);
170
+ }
171
+ };
172
+
173
+ // src/index.ts
174
+ var Instasign = class {
175
+ client;
176
+ envelopes;
177
+ signRequests;
178
+ webhooks;
179
+ constructor(config) {
180
+ this.client = import_axios.default.create({
181
+ baseURL: config.serverUrl || "https://parseapi.back4app.com",
182
+ headers: {
183
+ "X-Parse-APPLICATION-ID": config.appId || "jKFo8BFQRdiAUV4F3o3SIDWLpLUb2TVW7bVl7lwH",
184
+ "X-Parse-REST-API-KEY": config.restApiKey || "Gjm9pmxZh0DjXHkcFlf0kGZjHfYEY4ERw71TvLig",
185
+ "x-api-key": config.apiKey,
186
+ "Content-Type": "application/json"
187
+ }
188
+ });
189
+ this.envelopes = new Envelopes(this.client);
190
+ this.signRequests = new SignRequests(this.client);
191
+ this.webhooks = new Webhooks(config.webhookTolerance ?? 300);
192
+ }
193
+ };
194
+ // Annotate the CommonJS export names for ESM import in node:
195
+ 0 && (module.exports = {
196
+ Envelopes,
197
+ Instasign,
198
+ SignRequests,
199
+ Webhooks
200
+ });
201
+ //# sourceMappingURL=index.cjs.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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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