instasign 1.1.9 → 1.1.10

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,11 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [1.1.10] - 2026-03-27
6
+
7
+ ### Changed
8
+ - **Type Safety**: Improved internal type synchronization with compile-time schema validation against the OpenAPI specification.
9
+
5
10
  ## [1.1.9] - 2026-03-27
6
11
 
7
12
  ### Added
package/dist/index.cjs CHANGED
@@ -184,10 +184,58 @@ var Instasign = class {
184
184
  "Content-Type": "application/json"
185
185
  }
186
186
  });
187
+ this.client.interceptors.request.use(
188
+ (requestConfig) => {
189
+ if (requestConfig.data) {
190
+ requestConfig.data = this._serializeDateInputs(requestConfig.data);
191
+ }
192
+ return requestConfig;
193
+ }
194
+ );
195
+ this.client.interceptors.response.use(
196
+ (response) => {
197
+ if (response.data && response.data.result) {
198
+ response.data.result = this._normalizeParseDates(response.data.result);
199
+ }
200
+ return response;
201
+ }
202
+ );
187
203
  this.envelopes = new Envelopes(this.client);
188
204
  this.signRequests = new SignRequests(this.client);
189
205
  this.webhooks = new Webhooks(config.webhookTolerance ?? 300);
190
206
  }
207
+ _serializeDateInputs(data) {
208
+ if (data instanceof Date) {
209
+ return data.toISOString();
210
+ }
211
+ if (!data || typeof data !== "object") return data;
212
+ if (Array.isArray(data)) {
213
+ return data.map((item) => this._serializeDateInputs(item));
214
+ }
215
+ const serialized = {};
216
+ for (const key in data) {
217
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
218
+ serialized[key] = this._serializeDateInputs(data[key]);
219
+ }
220
+ }
221
+ return serialized;
222
+ }
223
+ _normalizeParseDates(data) {
224
+ if (!data || typeof data !== "object") return data;
225
+ if (Array.isArray(data)) {
226
+ return data.map((item) => this._normalizeParseDates(item));
227
+ }
228
+ if (data.__type === "Date" && data.iso) {
229
+ return data.iso;
230
+ }
231
+ const normalized = {};
232
+ for (const key in data) {
233
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
234
+ normalized[key] = this._normalizeParseDates(data[key]);
235
+ }
236
+ }
237
+ return normalized;
238
+ }
191
239
  };
192
240
 
193
241
  // ../types/src/index.ts
@@ -1 +1 @@
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 AddSignRequestsToEnvelopeParams,\n type AddSignRequestsToEnvelopeResponse,\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 remove(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 sign requests to an envelope\n */\n async addAll(params: AddSignRequestsToEnvelopeParams): Promise<AddSignRequestsToEnvelopeResponse | undefined> {\n const response = await this.client.post('/functions/envelope:add-sign-requests', 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 'envelope_all_requests_signed',\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 'envelope_all_requests_signed': { 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 'expired',\n] as const;\n\nexport type SignRequestStatus = typeof VALID_SIGN_REQUEST_STATUSES[number];\n\nexport const VALID_SIGN_REQUEST_SIGNATURE_TYPES = ['otp', 'advanced', 'qualified'] as const;\n\nexport type SignatureType = typeof VALID_SIGN_REQUEST_SIGNATURE_TYPES[number];\n\nexport const VALID_ENVELOPE_STATUSES = [\n 'pending',\n 'in-progress',\n 'completed',\n 'canceled',\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;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,MAA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N,MAAgB;AAAA,EACX;AAAA,EAEQ;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,QAA0B;AAClC,SAAK,SAAS,aAAAA,QAAM,OAAO;AAAA,MACvB,SAAS,OAAO;AAAA,MAChB,SAAS;AAAA,QACL,0BAA0B,OAAO;AAAA,QACjC,wBAAwB,OAAO;AAAA,QAC/B,aAAa,OAAO;AAAA,QACpB,gBAAgB;AAAA,MACpB;AAAA,IACJ,CAAC;AAED,SAAK,YAAY,IAAI,UAAU,KAAK,MAAM;AAC1C,SAAK,eAAe,IAAI,aAAa,KAAK,MAAM;AAChD,SAAK,WAAW,IAAI,SAAS,OAAO,oBAAoB,GAAG;AAAA,EAC/D;AACJ;;;ACvCO,IAAM,4BAA4B;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAeO,IAAM,8BAA8B;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAIO,IAAM,qCAAqC,CAAC,OAAO,YAAY,WAAW;AAI1E,IAAM,0BAA0B;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAOO,IAAM,iBAAiB,CAAC,aAAa,WAAW;AAGhD,IAAM,wBAAwB,CAAC,OAAO,MAAM;","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 AddSignRequestsToEnvelopeParams,\n type AddSignRequestsToEnvelopeResponse,\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 remove(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 sign requests to an envelope\n */\n async addAll(params: AddSignRequestsToEnvelopeParams): Promise<AddSignRequestsToEnvelopeResponse | undefined> {\n const response = await this.client.post('/functions/envelope:add-sign-requests', 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 this.client.interceptors.request.use(\n (requestConfig) => {\n if (requestConfig.data) {\n requestConfig.data = this._serializeDateInputs(requestConfig.data);\n }\n return requestConfig;\n },\n );\n this.client.interceptors.response.use(\n (response) => {\n if (response.data && response.data.result) {\n response.data.result = this._normalizeParseDates(response.data.result);\n }\n return response;\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 private _serializeDateInputs(data: any): any { // eslint-disable-line @typescript-eslint/no-explicit-any\n if (data instanceof Date) {\n return data.toISOString();\n }\n\n if (!data || typeof data !== 'object') return data;\n\n if (Array.isArray(data)) {\n return data.map(item => this._serializeDateInputs(item));\n }\n\n const serialized: any = {}; // eslint-disable-line @typescript-eslint/no-explicit-any\n for (const key in data) {\n if (Object.prototype.hasOwnProperty.call(data, key)) {\n serialized[key] = this._serializeDateInputs(data[key]);\n }\n }\n return serialized;\n }\n\n private _normalizeParseDates(data: any): any { // eslint-disable-line @typescript-eslint/no-explicit-any\n if (!data || typeof data !== 'object') return data;\n\n if (Array.isArray(data)) {\n return data.map(item => this._normalizeParseDates(item));\n }\n\n if (data.__type === 'Date' && data.iso) {\n return data.iso;\n }\n\n const normalized: any = {}; // eslint-disable-line @typescript-eslint/no-explicit-any\n for (const key in data) {\n if (Object.prototype.hasOwnProperty.call(data, key)) {\n normalized[key] = this._normalizeParseDates(data[key]);\n }\n }\n return normalized;\n }\n}\n","export const VALID_WEBHOOK_EVENT_TYPES = [\n 'envelope_created',\n 'envelope_expired',\n 'envelope_all_requests_signed',\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 'envelope_all_requests_signed': { 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 'expired',\n] as const;\n\nexport type SignRequestStatus = typeof VALID_SIGN_REQUEST_STATUSES[number];\n\nexport const VALID_SIGN_REQUEST_SIGNATURE_TYPES = ['otp', 'advanced', 'qualified'] as const;\n\nexport type SignatureType = typeof VALID_SIGN_REQUEST_SIGNATURE_TYPES[number];\n\nexport const VALID_ENVELOPE_STATUSES = [\n 'pending',\n 'in-progress',\n 'completed',\n 'canceled',\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;AAAA;;;ACcO,IAAM,YAAN,MAAgB;AAAA,EACnB,YAAoB,QAAuB;AAAvB;AAAA,EAAyB;AAAA;AAAA;AAAA;AAAA,EAK7C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O,KAAK,IAAI,UAAQ,KAAK,qBAAqB,IAAI,CAAC;AAAA,IAC3D;AAEA,UAAM,aAAkB,CAAC;AACzB,eAAW,OAAO,MAAM;AACpB,UAAI,OAAO,UAAU,eAAe,KAAK,MAAM,GAAG,GAAG;AACjD,mBAAW,GAAG,IAAI,KAAK,qBAAqB,KAAK,GAAG,CAAC;AAAA,MACzD;AAAA,IACJ;AACA,WAAO;AAAA,EACX;AAAA,EAEQ,qBAAqB,MAAgB;AACzC,QAAI,CAAC,QAAQ,OAAO,SAAS,SAAU,QAAO;AAE9C,QAAI,MAAM,QAAQ,IAAI,GAAG;AACrB,aAAO,KAAK,IAAI,UAAQ,KAAK,qBAAqB,IAAI,CAAC;AAAA,IAC3D;AAEA,QAAI,KAAK,WAAW,UAAU,KAAK,KAAK;AACpC,aAAO,KAAK;AAAA,IAChB;AAEA,UAAM,aAAkB,CAAC;AACzB,eAAW,OAAO,MAAM;AACpB,UAAI,OAAO,UAAU,eAAe,KAAK,MAAM,GAAG,GAAG;AACjD,mBAAW,GAAG,IAAI,KAAK,qBAAqB,KAAK,GAAG,CAAC;AAAA,MACzD;AAAA,IACJ;AACA,WAAO;AAAA,EACX;AACJ;;;AC/FO,IAAM,4BAA4B;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAeO,IAAM,8BAA8B;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAIO,IAAM,qCAAqC,CAAC,OAAO,YAAY,WAAW;AAI1E,IAAM,0BAA0B;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAOO,IAAM,iBAAiB,CAAC,aAAa,WAAW;AAGhD,IAAM,wBAAwB,CAAC,OAAO,MAAM;","names":["axios"]}
package/dist/index.d.cts CHANGED
@@ -771,22 +771,24 @@ interface OperationResponse {
771
771
  type ResponseResult<P extends keyof paths> = NonNullable<NonNullable<paths[P]['post']['responses']>[200]['content']>['application/json']['result'];
772
772
  /** Extract the request body type from a Cloud Function */
773
773
  type RequestBody<P extends keyof paths> = NonNullable<NonNullable<paths[P]['post']['requestBody']>['content']>['application/json'];
774
+ type DateInput = string | Date;
775
+ type WithDateInputFields<T, K extends keyof T> = Omit<T, K> & {
776
+ [P in K]?: DateInput;
777
+ };
774
778
  /** A full envelope with its sign requests */
775
779
  interface Envelope extends SchemaResult<'EnvelopeGetResult'> {
776
780
  }
777
781
  /** Envelope as returned in a list */
778
782
  interface EnvelopeListItem extends SchemaResult<'EnvelopeListResult'> {
779
783
  }
780
- interface CreateEnvelopeParams extends RequestBody<'/functions/envelope:create'> {
781
- }
782
- interface GetEnvelopesParams extends RequestBody<'/functions/envelope:list'> {
783
- }
784
- interface UpdateEnvelopeMetadataParams extends RequestBody<'/functions/envelope:update-metadata'> {
785
- }
786
- interface RemoveSignRequestFromEnvelopeParams extends RequestBody<'/functions/envelope:remove-sign-request'> {
787
- }
788
- interface AddSignRequestsToEnvelopeParams extends RequestBody<'/functions/envelope:add-sign-requests'> {
789
- }
784
+ type CreateEnvelopeParams = WithDateInputFields<RequestBody<'/functions/envelope:create'>, 'expirationDate'>;
785
+ type GetEnvelopesParams = WithDateInputFields<RequestBody<'/functions/envelope:list'>, 'expirationDateStart' | 'expirationDateEnd'>;
786
+ type UpdateEnvelopeMetadataParams = RequestBody<'/functions/envelope:update-metadata'>;
787
+ type RemoveSignRequestFromEnvelopeParams = RequestBody<'/functions/envelope:remove-sign-request'>;
788
+ type AddSignRequestInput = WithDateInputFields<RequestBody<'/functions/envelope:add-sign-requests'>['signRequests'][number], 'expirationDate'>;
789
+ type AddSignRequestsToEnvelopeParams = Omit<RequestBody<'/functions/envelope:add-sign-requests'>, 'signRequests'> & {
790
+ signRequests: AddSignRequestInput[];
791
+ };
790
792
  interface CreateEnvelopeResponse extends ResponseResult<'/functions/envelope:create'> {
791
793
  }
792
794
  interface UpdateEnvelopeMetadataResponse extends ResponseResult<'/functions/envelope:update-metadata'> {
@@ -796,14 +798,10 @@ interface AddSignRequestsToEnvelopeResponse extends ResponseResult<'/functions/e
796
798
  /** A single sign request */
797
799
  interface SignRequest extends SchemaResult<'SignRequestGetResult'> {
798
800
  }
799
- interface CreateSignRequestParams extends RequestBody<'/functions/sign-request:create'> {
800
- }
801
- interface CompleteSignRequestParams extends RequestBody<'/functions/sign-request:complete'> {
802
- }
803
- interface GetFileFromRequestIdParams extends RequestBody<'/functions/sign-request:get'> {
804
- }
805
- interface UpdateSignRequestMetadataParams extends RequestBody<'/functions/sign-request:update-metadata'> {
806
- }
801
+ type CreateSignRequestParams = WithDateInputFields<RequestBody<'/functions/sign-request:create'>, 'expirationDate'>;
802
+ type CompleteSignRequestParams = RequestBody<'/functions/sign-request:complete'>;
803
+ type GetFileFromRequestIdParams = RequestBody<'/functions/sign-request:get'>;
804
+ type UpdateSignRequestMetadataParams = RequestBody<'/functions/sign-request:update-metadata'>;
807
805
  interface CreateSignRequestResponse extends ResponseResult<'/functions/sign-request:create'> {
808
806
  }
809
807
  interface CompleteSignRequestResponse extends ResponseResult<'/functions/sign-request:complete'> {
@@ -907,6 +905,8 @@ declare class Instasign {
907
905
  readonly signRequests: SignRequests;
908
906
  readonly webhooks: Webhooks;
909
907
  constructor(config: IInstasignConfig);
908
+ private _serializeDateInputs;
909
+ private _normalizeParseDates;
910
910
  }
911
911
 
912
- export { type $defs, type AddSignRequestsToEnvelopeParams, type AddSignRequestsToEnvelopeResponse, type CompleteSignRequestParams, type CompleteSignRequestResponse, type CreateEnvelopeParams, type CreateEnvelopeResponse, type CreateSignRequestParams, type CreateSignRequestResponse, type Envelope, type EnvelopeCreatedEvent, type EnvelopeExpiredEvent, type EnvelopeListItem, type EnvelopeMetadata, type EnvelopeStatus, Envelopes, type GetEnvelopesParams, type GetFileFromRequestIdParams, type IInstasignConfig, Instasign, type OperationResponse, type OrderBy, type OrderDirection, type RemoveSignRequestFromEnvelopeParams, type RequestBody, type ResponseResult, type SchemaResult, type SignRequest, type SignRequestCreatedEvent, type SignRequestExpiredEvent, type SignRequestMetadata, type SignRequestSignedEvent, type SignRequestStatus, SignRequests, type SignatureType, type UpdateEnvelopeMetadataParams, type UpdateEnvelopeMetadataResponse, type UpdateSignRequestMetadataParams, type UpdateSignRequestMetadataResponse, VALID_ENVELOPE_STATUSES, VALID_ORDER_BY, VALID_ORDER_DIRECTION, VALID_SIGN_REQUEST_SIGNATURE_TYPES, VALID_SIGN_REQUEST_STATUSES, VALID_WEBHOOK_EVENT_TYPES, type WebhookEvent, type WebhookEventType, type WebhookPayloadMap, type WebhookStatus, Webhooks, type components, type operations, type paths, type webhooks };
912
+ export { type $defs, type AddSignRequestInput, type AddSignRequestsToEnvelopeParams, type AddSignRequestsToEnvelopeResponse, type CompleteSignRequestParams, type CompleteSignRequestResponse, type CreateEnvelopeParams, type CreateEnvelopeResponse, type CreateSignRequestParams, type CreateSignRequestResponse, type DateInput, type Envelope, type EnvelopeCreatedEvent, type EnvelopeExpiredEvent, type EnvelopeListItem, type EnvelopeMetadata, type EnvelopeStatus, Envelopes, type GetEnvelopesParams, type GetFileFromRequestIdParams, type IInstasignConfig, Instasign, type OperationResponse, type OrderBy, type OrderDirection, type RemoveSignRequestFromEnvelopeParams, type RequestBody, type ResponseResult, type SchemaResult, type SignRequest, type SignRequestCreatedEvent, type SignRequestExpiredEvent, type SignRequestMetadata, type SignRequestSignedEvent, type SignRequestStatus, SignRequests, type SignatureType, type UpdateEnvelopeMetadataParams, type UpdateEnvelopeMetadataResponse, type UpdateSignRequestMetadataParams, type UpdateSignRequestMetadataResponse, VALID_ENVELOPE_STATUSES, VALID_ORDER_BY, VALID_ORDER_DIRECTION, VALID_SIGN_REQUEST_SIGNATURE_TYPES, VALID_SIGN_REQUEST_STATUSES, VALID_WEBHOOK_EVENT_TYPES, type WebhookEvent, type WebhookEventType, type WebhookPayloadMap, type WebhookStatus, Webhooks, type components, type operations, type paths, type webhooks };
package/dist/index.d.ts CHANGED
@@ -771,22 +771,24 @@ interface OperationResponse {
771
771
  type ResponseResult<P extends keyof paths> = NonNullable<NonNullable<paths[P]['post']['responses']>[200]['content']>['application/json']['result'];
772
772
  /** Extract the request body type from a Cloud Function */
773
773
  type RequestBody<P extends keyof paths> = NonNullable<NonNullable<paths[P]['post']['requestBody']>['content']>['application/json'];
774
+ type DateInput = string | Date;
775
+ type WithDateInputFields<T, K extends keyof T> = Omit<T, K> & {
776
+ [P in K]?: DateInput;
777
+ };
774
778
  /** A full envelope with its sign requests */
775
779
  interface Envelope extends SchemaResult<'EnvelopeGetResult'> {
776
780
  }
777
781
  /** Envelope as returned in a list */
778
782
  interface EnvelopeListItem extends SchemaResult<'EnvelopeListResult'> {
779
783
  }
780
- interface CreateEnvelopeParams extends RequestBody<'/functions/envelope:create'> {
781
- }
782
- interface GetEnvelopesParams extends RequestBody<'/functions/envelope:list'> {
783
- }
784
- interface UpdateEnvelopeMetadataParams extends RequestBody<'/functions/envelope:update-metadata'> {
785
- }
786
- interface RemoveSignRequestFromEnvelopeParams extends RequestBody<'/functions/envelope:remove-sign-request'> {
787
- }
788
- interface AddSignRequestsToEnvelopeParams extends RequestBody<'/functions/envelope:add-sign-requests'> {
789
- }
784
+ type CreateEnvelopeParams = WithDateInputFields<RequestBody<'/functions/envelope:create'>, 'expirationDate'>;
785
+ type GetEnvelopesParams = WithDateInputFields<RequestBody<'/functions/envelope:list'>, 'expirationDateStart' | 'expirationDateEnd'>;
786
+ type UpdateEnvelopeMetadataParams = RequestBody<'/functions/envelope:update-metadata'>;
787
+ type RemoveSignRequestFromEnvelopeParams = RequestBody<'/functions/envelope:remove-sign-request'>;
788
+ type AddSignRequestInput = WithDateInputFields<RequestBody<'/functions/envelope:add-sign-requests'>['signRequests'][number], 'expirationDate'>;
789
+ type AddSignRequestsToEnvelopeParams = Omit<RequestBody<'/functions/envelope:add-sign-requests'>, 'signRequests'> & {
790
+ signRequests: AddSignRequestInput[];
791
+ };
790
792
  interface CreateEnvelopeResponse extends ResponseResult<'/functions/envelope:create'> {
791
793
  }
792
794
  interface UpdateEnvelopeMetadataResponse extends ResponseResult<'/functions/envelope:update-metadata'> {
@@ -796,14 +798,10 @@ interface AddSignRequestsToEnvelopeResponse extends ResponseResult<'/functions/e
796
798
  /** A single sign request */
797
799
  interface SignRequest extends SchemaResult<'SignRequestGetResult'> {
798
800
  }
799
- interface CreateSignRequestParams extends RequestBody<'/functions/sign-request:create'> {
800
- }
801
- interface CompleteSignRequestParams extends RequestBody<'/functions/sign-request:complete'> {
802
- }
803
- interface GetFileFromRequestIdParams extends RequestBody<'/functions/sign-request:get'> {
804
- }
805
- interface UpdateSignRequestMetadataParams extends RequestBody<'/functions/sign-request:update-metadata'> {
806
- }
801
+ type CreateSignRequestParams = WithDateInputFields<RequestBody<'/functions/sign-request:create'>, 'expirationDate'>;
802
+ type CompleteSignRequestParams = RequestBody<'/functions/sign-request:complete'>;
803
+ type GetFileFromRequestIdParams = RequestBody<'/functions/sign-request:get'>;
804
+ type UpdateSignRequestMetadataParams = RequestBody<'/functions/sign-request:update-metadata'>;
807
805
  interface CreateSignRequestResponse extends ResponseResult<'/functions/sign-request:create'> {
808
806
  }
809
807
  interface CompleteSignRequestResponse extends ResponseResult<'/functions/sign-request:complete'> {
@@ -907,6 +905,8 @@ declare class Instasign {
907
905
  readonly signRequests: SignRequests;
908
906
  readonly webhooks: Webhooks;
909
907
  constructor(config: IInstasignConfig);
908
+ private _serializeDateInputs;
909
+ private _normalizeParseDates;
910
910
  }
911
911
 
912
- export { type $defs, type AddSignRequestsToEnvelopeParams, type AddSignRequestsToEnvelopeResponse, type CompleteSignRequestParams, type CompleteSignRequestResponse, type CreateEnvelopeParams, type CreateEnvelopeResponse, type CreateSignRequestParams, type CreateSignRequestResponse, type Envelope, type EnvelopeCreatedEvent, type EnvelopeExpiredEvent, type EnvelopeListItem, type EnvelopeMetadata, type EnvelopeStatus, Envelopes, type GetEnvelopesParams, type GetFileFromRequestIdParams, type IInstasignConfig, Instasign, type OperationResponse, type OrderBy, type OrderDirection, type RemoveSignRequestFromEnvelopeParams, type RequestBody, type ResponseResult, type SchemaResult, type SignRequest, type SignRequestCreatedEvent, type SignRequestExpiredEvent, type SignRequestMetadata, type SignRequestSignedEvent, type SignRequestStatus, SignRequests, type SignatureType, type UpdateEnvelopeMetadataParams, type UpdateEnvelopeMetadataResponse, type UpdateSignRequestMetadataParams, type UpdateSignRequestMetadataResponse, VALID_ENVELOPE_STATUSES, VALID_ORDER_BY, VALID_ORDER_DIRECTION, VALID_SIGN_REQUEST_SIGNATURE_TYPES, VALID_SIGN_REQUEST_STATUSES, VALID_WEBHOOK_EVENT_TYPES, type WebhookEvent, type WebhookEventType, type WebhookPayloadMap, type WebhookStatus, Webhooks, type components, type operations, type paths, type webhooks };
912
+ export { type $defs, type AddSignRequestInput, type AddSignRequestsToEnvelopeParams, type AddSignRequestsToEnvelopeResponse, type CompleteSignRequestParams, type CompleteSignRequestResponse, type CreateEnvelopeParams, type CreateEnvelopeResponse, type CreateSignRequestParams, type CreateSignRequestResponse, type DateInput, type Envelope, type EnvelopeCreatedEvent, type EnvelopeExpiredEvent, type EnvelopeListItem, type EnvelopeMetadata, type EnvelopeStatus, Envelopes, type GetEnvelopesParams, type GetFileFromRequestIdParams, type IInstasignConfig, Instasign, type OperationResponse, type OrderBy, type OrderDirection, type RemoveSignRequestFromEnvelopeParams, type RequestBody, type ResponseResult, type SchemaResult, type SignRequest, type SignRequestCreatedEvent, type SignRequestExpiredEvent, type SignRequestMetadata, type SignRequestSignedEvent, type SignRequestStatus, SignRequests, type SignatureType, type UpdateEnvelopeMetadataParams, type UpdateEnvelopeMetadataResponse, type UpdateSignRequestMetadataParams, type UpdateSignRequestMetadataResponse, VALID_ENVELOPE_STATUSES, VALID_ORDER_BY, VALID_ORDER_DIRECTION, VALID_SIGN_REQUEST_SIGNATURE_TYPES, VALID_SIGN_REQUEST_STATUSES, VALID_WEBHOOK_EVENT_TYPES, type WebhookEvent, type WebhookEventType, type WebhookPayloadMap, type WebhookStatus, Webhooks, type components, type operations, type paths, type webhooks };
package/dist/index.js CHANGED
@@ -139,10 +139,58 @@ var Instasign = class {
139
139
  "Content-Type": "application/json"
140
140
  }
141
141
  });
142
+ this.client.interceptors.request.use(
143
+ (requestConfig) => {
144
+ if (requestConfig.data) {
145
+ requestConfig.data = this._serializeDateInputs(requestConfig.data);
146
+ }
147
+ return requestConfig;
148
+ }
149
+ );
150
+ this.client.interceptors.response.use(
151
+ (response) => {
152
+ if (response.data && response.data.result) {
153
+ response.data.result = this._normalizeParseDates(response.data.result);
154
+ }
155
+ return response;
156
+ }
157
+ );
142
158
  this.envelopes = new Envelopes(this.client);
143
159
  this.signRequests = new SignRequests(this.client);
144
160
  this.webhooks = new Webhooks(config.webhookTolerance ?? 300);
145
161
  }
162
+ _serializeDateInputs(data) {
163
+ if (data instanceof Date) {
164
+ return data.toISOString();
165
+ }
166
+ if (!data || typeof data !== "object") return data;
167
+ if (Array.isArray(data)) {
168
+ return data.map((item) => this._serializeDateInputs(item));
169
+ }
170
+ const serialized = {};
171
+ for (const key in data) {
172
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
173
+ serialized[key] = this._serializeDateInputs(data[key]);
174
+ }
175
+ }
176
+ return serialized;
177
+ }
178
+ _normalizeParseDates(data) {
179
+ if (!data || typeof data !== "object") return data;
180
+ if (Array.isArray(data)) {
181
+ return data.map((item) => this._normalizeParseDates(item));
182
+ }
183
+ if (data.__type === "Date" && data.iso) {
184
+ return data.iso;
185
+ }
186
+ const normalized = {};
187
+ for (const key in data) {
188
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
189
+ normalized[key] = this._normalizeParseDates(data[key]);
190
+ }
191
+ }
192
+ return normalized;
193
+ }
146
194
  };
147
195
 
148
196
  // ../types/src/index.ts
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/resources/Envelopes.ts","../src/resources/SignRequests.ts","../src/resources/Webhooks.ts","../src/instasign.ts","../../types/src/index.ts"],"sourcesContent":["import { AxiosInstance } from 'axios';\nimport {\n Envelope,\n type AddSignRequestsToEnvelopeParams,\n type AddSignRequestsToEnvelopeResponse,\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 remove(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 sign requests to an envelope\n */\n async addAll(params: AddSignRequestsToEnvelopeParams): Promise<AddSignRequestsToEnvelopeResponse | undefined> {\n const response = await this.client.post('/functions/envelope:add-sign-requests', 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 'envelope_all_requests_signed',\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 'envelope_all_requests_signed': { 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 'expired',\n] as const;\n\nexport type SignRequestStatus = typeof VALID_SIGN_REQUEST_STATUSES[number];\n\nexport const VALID_SIGN_REQUEST_SIGNATURE_TYPES = ['otp', 'advanced', 'qualified'] as const;\n\nexport type SignatureType = typeof VALID_SIGN_REQUEST_SIGNATURE_TYPES[number];\n\nexport const VALID_ENVELOPE_STATUSES = [\n 'pending',\n 'in-progress',\n 'completed',\n 'canceled',\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":";AAcO,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;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,YAA4D;AACrE,UAAM,WAAW,MAAM,KAAK,OAAO,KAAK,8BAA8B,EAAE,WAAW,CAAC;AACpF,WAAO,SAAS,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKA,MA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;AACJ;AAeO,IAAM,8BAA8B;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAIO,IAAM,qCAAqC,CAAC,OAAO,YAAY,WAAW;AAI1E,IAAM,0BAA0B;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAOO,IAAM,iBAAiB,CAAC,aAAa,WAAW;AAGhD,IAAM,wBAAwB,CAAC,OAAO,MAAM;","names":[]}
1
+ {"version":3,"sources":["../src/resources/Envelopes.ts","../src/resources/SignRequests.ts","../src/resources/Webhooks.ts","../src/instasign.ts","../../types/src/index.ts"],"sourcesContent":["import { AxiosInstance } from 'axios';\nimport {\n Envelope,\n type AddSignRequestsToEnvelopeParams,\n type AddSignRequestsToEnvelopeResponse,\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 remove(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 sign requests to an envelope\n */\n async addAll(params: AddSignRequestsToEnvelopeParams): Promise<AddSignRequestsToEnvelopeResponse | undefined> {\n const response = await this.client.post('/functions/envelope:add-sign-requests', 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 this.client.interceptors.request.use(\n (requestConfig) => {\n if (requestConfig.data) {\n requestConfig.data = this._serializeDateInputs(requestConfig.data);\n }\n return requestConfig;\n },\n );\n this.client.interceptors.response.use(\n (response) => {\n if (response.data && response.data.result) {\n response.data.result = this._normalizeParseDates(response.data.result);\n }\n return response;\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 private _serializeDateInputs(data: any): any { // eslint-disable-line @typescript-eslint/no-explicit-any\n if (data instanceof Date) {\n return data.toISOString();\n }\n\n if (!data || typeof data !== 'object') return data;\n\n if (Array.isArray(data)) {\n return data.map(item => this._serializeDateInputs(item));\n }\n\n const serialized: any = {}; // eslint-disable-line @typescript-eslint/no-explicit-any\n for (const key in data) {\n if (Object.prototype.hasOwnProperty.call(data, key)) {\n serialized[key] = this._serializeDateInputs(data[key]);\n }\n }\n return serialized;\n }\n\n private _normalizeParseDates(data: any): any { // eslint-disable-line @typescript-eslint/no-explicit-any\n if (!data || typeof data !== 'object') return data;\n\n if (Array.isArray(data)) {\n return data.map(item => this._normalizeParseDates(item));\n }\n\n if (data.__type === 'Date' && data.iso) {\n return data.iso;\n }\n\n const normalized: any = {}; // eslint-disable-line @typescript-eslint/no-explicit-any\n for (const key in data) {\n if (Object.prototype.hasOwnProperty.call(data, key)) {\n normalized[key] = this._normalizeParseDates(data[key]);\n }\n }\n return normalized;\n }\n}\n","export const VALID_WEBHOOK_EVENT_TYPES = [\n 'envelope_created',\n 'envelope_expired',\n 'envelope_all_requests_signed',\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 'envelope_all_requests_signed': { 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 'expired',\n] as const;\n\nexport type SignRequestStatus = typeof VALID_SIGN_REQUEST_STATUSES[number];\n\nexport const VALID_SIGN_REQUEST_SIGNATURE_TYPES = ['otp', 'advanced', 'qualified'] as const;\n\nexport type SignatureType = typeof VALID_SIGN_REQUEST_SIGNATURE_TYPES[number];\n\nexport const VALID_ENVELOPE_STATUSES = [\n 'pending',\n 'in-progress',\n 'completed',\n 'canceled',\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":";AAcO,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;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,YAA4D;AACrE,UAAM,WAAW,MAAM,KAAK,OAAO,KAAK,8BAA8B,EAAE,WAAW,CAAC;AACpF,WAAO,SAAS,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,eAAe,QAA2F;AAC5G,UAAM,W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EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAeO,IAAM,8BAA8B;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAIO,IAAM,qCAAqC,CAAC,OAAO,YAAY,WAAW;AAI1E,IAAM,0BAA0B;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAOO,IAAM,iBAAiB,CAAC,aAAa,WAAW;AAGhD,IAAM,wBAAwB,CAAC,OAAO,MAAM;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instasign",
3
- "version": "1.1.9",
3
+ "version": "1.1.10",
4
4
  "description": "Instasign API wrapper",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",