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/dist/index.js CHANGED
@@ -1,6 +1,3 @@
1
- // src/index.ts
2
- import axios from "axios";
3
-
4
1
  // src/resources/Envelopes.ts
5
2
  var Envelopes = class {
6
3
  constructor(client) {
@@ -10,56 +7,56 @@ var Envelopes = class {
10
7
  * Create a new envelope
11
8
  */
12
9
  async create(params) {
13
- const response = await this.client.post("/functions/createEnvelope", params);
10
+ const response = await this.client.post("/functions/envelope:create", params);
14
11
  return response.data.result;
15
12
  }
16
13
  /**
17
14
  * List envelopes
18
15
  */
19
16
  async list(params = {}) {
20
- const response = await this.client.post("/functions/getEnvelopes", params);
17
+ const response = await this.client.post("/functions/envelope:list", params);
21
18
  return response.data.result;
22
19
  }
23
20
  /**
24
21
  * Retrieve a single envelope with its sign requests
25
22
  */
26
23
  async get(envelopeId) {
27
- const response = await this.client.post("/functions/getEnvelope", { envelopeId });
24
+ const response = await this.client.post("/functions/envelope:get", { envelopeId });
28
25
  return response.data.result;
29
26
  }
30
27
  /**
31
28
  * Complete an envelope
32
29
  */
33
30
  async complete(envelopeId) {
34
- const response = await this.client.post("/functions/completeEnvelope", { envelopeId });
31
+ const response = await this.client.post("/functions/envelope:complete", { envelopeId });
35
32
  return response.data.result;
36
33
  }
37
34
  /**
38
35
  * Delete an envelope
39
36
  */
40
37
  async delete(envelopeId) {
41
- const response = await this.client.post("/functions/deleteEnvelope", { envelopeId });
38
+ const response = await this.client.post("/functions/envelope:delete", { envelopeId });
42
39
  return response.data.result;
43
40
  }
44
41
  /**
45
42
  * Update envelope metadata
46
43
  */
47
44
  async updateMetadata(params) {
48
- const response = await this.client.post("/functions/updateEnvelopeMetadata", params);
45
+ const response = await this.client.post("/functions/envelope:update-metadata", params);
49
46
  return response.data.result;
50
47
  }
51
48
  /**
52
49
  * Remove a sign request from an envelope
53
50
  */
54
51
  async removeSignRequest(params) {
55
- const response = await this.client.post("/functions/removeSignRequestFromEnvelope", params);
52
+ const response = await this.client.post("/functions/envelope:remove-sign-request", params);
56
53
  return response.data.result;
57
54
  }
58
55
  /**
59
56
  * Add a sign request to an envelope
60
57
  */
61
58
  async addSignRequest(params) {
62
- const response = await this.client.post("/functions/addSignRequestToEnvelope", params);
59
+ const response = await this.client.post("/functions/envelope:add-sign-request", params);
63
60
  return response.data.result;
64
61
  }
65
62
  /**
@@ -81,21 +78,21 @@ var SignRequests = class {
81
78
  * Create a new sign request
82
79
  */
83
80
  async create(params) {
84
- const response = await this.client.post("/functions/createSignRequest", params);
81
+ const response = await this.client.post("/functions/sign-request:create", params);
85
82
  return response.data.result;
86
83
  }
87
84
  /**
88
85
  * Complete a sign request
89
86
  */
90
87
  async complete(params) {
91
- const response = await this.client.post("/functions/completeSignRequest", params);
88
+ const response = await this.client.post("/functions/sign-request:complete", params);
92
89
  return response.data.result;
93
90
  }
94
91
  /**
95
92
  * Get the file associated with a sign request
96
93
  */
97
- async getFile(requestId) {
98
- const response = await this.client.post("/functions/getFileFromRequestId", { requestId });
94
+ async get(requestId) {
95
+ const response = await this.client.post("/functions/sign-request:get", { requestId });
99
96
  return response.data.result;
100
97
  }
101
98
  };
@@ -133,7 +130,8 @@ var Webhooks = class {
133
130
  }
134
131
  };
135
132
 
136
- // src/index.ts
133
+ // src/instasign.ts
134
+ import axios from "axios";
137
135
  var Instasign = class {
138
136
  client;
139
137
  envelopes;
@@ -141,10 +139,10 @@ var Instasign = class {
141
139
  webhooks;
142
140
  constructor(config) {
143
141
  this.client = axios.create({
144
- baseURL: config.serverUrl || "https://parseapi.back4app.com",
142
+ baseURL: config.serverUrl,
145
143
  headers: {
146
- "X-Parse-APPLICATION-ID": config.appId || "jKFo8BFQRdiAUV4F3o3SIDWLpLUb2TVW7bVl7lwH",
147
- "X-Parse-REST-API-KEY": config.restApiKey || "Gjm9pmxZh0DjXHkcFlf0kGZjHfYEY4ERw71TvLig",
144
+ "X-Parse-APPLICATION-ID": config.appId,
145
+ "X-Parse-REST-API-KEY": config.restApiKey,
148
146
  "x-api-key": config.apiKey,
149
147
  "Content-Type": "application/json"
150
148
  }
@@ -154,10 +152,38 @@ var Instasign = class {
154
152
  this.webhooks = new Webhooks(config.webhookTolerance ?? 300);
155
153
  }
156
154
  };
155
+
156
+ // ../types/src/index.ts
157
+ var VALID_WEBHOOK_EVENT_TYPES = [
158
+ "envelope_created",
159
+ "envelope_expired",
160
+ "sign_request_created",
161
+ "sign_request_signed",
162
+ "sign_request_expired"
163
+ ];
164
+ var VALID_SIGN_REQUEST_STATUSES = [
165
+ "pending",
166
+ "completed",
167
+ "canceled",
168
+ "queued"
169
+ ];
170
+ var VALID_ENVELOPE_STATUSES = [
171
+ "pending",
172
+ "in-progress",
173
+ "completed",
174
+ "cancelled"
175
+ ];
176
+ var VALID_ORDER_BY = ["updatedAt", "createdAt"];
177
+ var VALID_ORDER_DIRECTION = ["asc", "desc"];
157
178
  export {
158
179
  Envelopes,
159
180
  Instasign,
160
181
  SignRequests,
182
+ VALID_ENVELOPE_STATUSES,
183
+ VALID_ORDER_BY,
184
+ VALID_ORDER_DIRECTION,
185
+ VALID_SIGN_REQUEST_STATUSES,
186
+ VALID_WEBHOOK_EVENT_TYPES,
161
187
  Webhooks
162
188
  };
163
189
  //# sourceMappingURL=index.js.map
package/dist/index.js.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 Buffer.from(expectedSignature)\n );\n\n if (!isValid) {\n throw new Error('Invalid signature');\n }\n\n return JSON.parse(payload) as WebhookEvent;\n }\n}\n"],"mappings":";AAAA,OAAO,WAA8B;;;ACe9B,IAAM,YAAN,MAAgB;AAAA,EACnB,YAAoB,QAAuB;AAAvB;AAAA,EAAyB;AAAA;AAAA;AAAA;AAAA,EAK7C,MAAM,OAAO,QAA2E;AACpF,UAAM,WAAW,MAAM,KAAK,OAAO,KAAK,6BAA6B,MAAM;AAC3E,WAAO,SAAS,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,SAA6B,CAAC,GAA4C;AACjF,UAAM,WAAW,MAAM,KAAK,OAAO,KAAK,2BAA2B,MAAM;AACzE,WAAO,SAAS,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,IAAI,YAAmD;AACzD,UAAM,WAAW,MAAM,KAAK,OAAO,KAAK,0BAA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MAAM,OAAO;AAAA,MACzB,SAAS,OAAO,aAAa;AAAA,MAC7B,SAAS;AAAA,QACP,0BAA0B,OAAO,SAAS;AAAA,QAC1C,wBAAwB,OAAO,cAAc;AAAA,QAC7C,aAAa,OAAO;AAAA,QACpB,gBAAgB;AAAA,MAClB;AAAA,IACF,CAAC;AAED,SAAK,YAAY,IAAI,UAAU,KAAK,MAAM;AAC1C,SAAK,eAAe,IAAI,aAAa,KAAK,MAAM;AAChD,SAAK,WAAW,IAAI,SAAS,OAAO,oBAAoB,GAAG;AAAA,EAC7D;AACF;","names":[]}
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 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":";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;A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,MAAgB;AAAA,EACX;AAAA,EAEQ;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,QAA0B;AAClC,SAAK,SAAS,MAAM,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;AACJ;AAcO,IAAM,8BAA8B;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAIO,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.2",
3
+ "version": "1.1.4",
4
4
  "description": "Instasign API wrapper",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",