@assinafy/cli 2.0.1 → 2.0.3

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/README.md CHANGED
@@ -59,6 +59,36 @@ assinafy send contract.pdf \
59
59
  --message "Please sign this contract"
60
60
  ```
61
61
 
62
+ ## Document lifecycle
63
+
64
+ `send` is the shortest path: it uploads, waits for processing, creates the signers, and requests signatures. For explicit control, the complete owner-side flow is:
65
+
66
+ ```bash
67
+ # Create or locate each signer.
68
+ SIGNER_ID=$(assinafy signers create \
69
+ --name "Ana Lima" --email ana@example.com --json | jq -r '.id')
70
+
71
+ # Upload, wait for metadata/page processing, then request the signature.
72
+ DOCUMENT_ID=$(assinafy documents upload contract.pdf \
73
+ --name "Service agreement" --wait --json | jq -r '.id')
74
+ assinafy assignments create "$DOCUMENT_ID" \
75
+ --signer-ids "$SIGNER_ID" \
76
+ --message "Please review and sign"
77
+
78
+ # Monitor the audit trail and signing progress.
79
+ assinafy documents get "$DOCUMENT_ID" --json
80
+ assinafy documents progress "$DOCUMENT_ID" --json
81
+ assinafy documents activities "$DOCUMENT_ID" --json
82
+
83
+ # Available after every signer completes and certification finishes.
84
+ assinafy documents download "$DOCUMENT_ID" --artifact certificated \
85
+ --output signed-contract.pdf
86
+ ```
87
+
88
+ The assignment sends each signer the configured email/WhatsApp invitation. Signer-side commands use that invitation's access code and, where configured, the one-time verification code; the published signer artifact download is public and accepts an optional access code for an SDK identity preflight. Owner API credentials are stripped from public and signer-side requests. Poll with `documents wait` when processing is still underway, or register webhooks for `document_ready`, signer completion/rejection, and processing failures. Keep the certified PDF, certificate page, bundle, and `documents activities` output as the final document record. Delete only disposable documents after their retention obligations are satisfied.
89
+
90
+ The [API request/response reference](./docs/api-reference.md) contains the complete published payload and response examples for each HTTP operation. The [SDK reference](./docs/sdk-reference.md) maps every SDK method to those payloads and explains SDK envelope unwrapping, pagination, binary results, errors, and compatibility behavior.
91
+
62
92
  ## Authentication & configuration
63
93
 
64
94
  The CLI resolves every credential with this precedence: **CLI flag → environment variable → config file**.
@@ -129,7 +159,6 @@ assinafy send contract.pdf \
129
159
  --signer "Ana <ana@example.com>" \
130
160
  --signer "Bruno <+5548999990000>" \
131
161
  --message "Please sign" \
132
- --expires-at 2026-12-31T23:59:59Z \
133
162
  --copy-receivers sig_abc123,sig_def456
134
163
  ```
135
164
 
@@ -150,8 +179,8 @@ Use `--signers '<json>'` for full control (verification methods, signing order/`
150
179
  | `documents activities <id>` | Activity log |
151
180
  | `documents delete <id> [-y]` | Delete a document |
152
181
  | `documents tags <id>` | List attached tags |
153
- | `documents tags-set <id> [names...]` | Replace the tag set |
154
- | `documents tags-add <id> <names...>` | Attach tags by name |
182
+ | `documents tags-set <id> [tagIds...]` | Replace the tag set by ID |
183
+ | `documents tags-add <id> <tagIds...>` | Attach tags by ID |
155
184
  | `documents tags-remove <id> <tagId>` | Detach one tag |
156
185
  | `documents create-from-template <templateId> --signers <json> [...]` | Create from a template |
157
186
  | `documents estimate-template-cost <templateId> --signers <json>` | Estimate template cost |
@@ -167,7 +196,7 @@ Use `--signers '<json>'` for full control (verification methods, signing order/`
167
196
  `create` · `list` · `get <id>` · `update <id>` · `delete <id>` · `find-by-email <email>`
168
197
 
169
198
  ```bash
170
- assinafy signers create --name "Ana Lima" --email ana@example.com --cpf 123.456.789-00
199
+ assinafy signers create --name "Ana Lima" --email ana@example.com
171
200
  ```
172
201
 
173
202
  ### `assignments`
@@ -204,11 +233,11 @@ assinafy assignments create doc_123 --signer-ids sig_1,sig_2 --message "Please s
204
233
 
205
234
  `self` · `stats [--granularity] [--month]` · `notification-preferences get|update`
206
235
 
207
- ### `signer` — signer-side flows (authenticated by a signer access code)
236
+ ### `signer` — signer-side flows
208
237
 
209
238
  `document <signerId>` · `documents <signerId>` · `download <signerId> <documentId> <artifact>` · `self` · `accept-terms` · `verify-email` · `confirm-data <documentId>` · `upload-signature` · `download-signature` · `assignment` · `sign <documentId> <assignmentId>` · `decline <documentId> <assignmentId>` · `sign-multiple` · `decline-multiple`
210
239
 
211
- Every signer command takes `--access-code <code>` (the one-time link emailed/WhatsApped to the signer); use `ASSINAFY_SIGNER_ACCESS_CODE` to keep it out of process arguments.
240
+ Every signer command except the public artifact `download` requires `--access-code <code>` (the one-time link emailed/WhatsApped to the signer). `download` accepts the code optionally for an identity preflight. Use `ASSINAFY_SIGNER_ACCESS_CODE` to keep it out of process arguments.
212
241
 
213
242
  ### `auth`
214
243
 
@@ -249,14 +278,15 @@ assinafy documents list --status pending_signature --json | jq -r '.data[].id'
249
278
  # Upload and capture the new document ID
250
279
  DOC=$(assinafy documents upload contract.pdf --json | jq -r '.id')
251
280
 
252
- # Bulk-tag every template-created document
253
- assinafy documents tags-add "$DOC" legal q4-2026
281
+ # Attach an existing tag by its documented ID
282
+ TAG_ID=$(assinafy tags list --search legal --json | jq -r '.[0].id')
283
+ assinafy documents tags-add "$DOC" "$TAG_ID"
254
284
  ```
255
285
 
256
286
  ## Development
257
287
 
258
288
  ```bash
259
- npm install # install dependencies
289
+ npm ci # install exactly from package-lock.json
260
290
  npm run dev -- --help # run from source with tsx
261
291
  npm run dev:watch # run from source and restart on changes
262
292
  npm run typecheck # tsc --noEmit
@@ -273,6 +303,8 @@ npm run pack:release # create release archives in dist/release/
273
303
  The opt-in `npm run test:sandbox` matrix requires the sandbox variables shown in
274
304
  `.env.example`. It creates and cleans up disposable API resources and sends one
275
305
  signing-token email to `ASSINAFY_TEST_EMAIL`; do not run it against production.
306
+ The current sandbox requires the legacy `--recipient` form for that token request,
307
+ while `--email` follows the production OpenAPI payload.
276
308
 
277
309
  ## Release
278
310
 
@@ -124,7 +124,7 @@ Source: git+https://github.com/alexindigo/asynckit.git
124
124
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
125
125
  SOFTWARE.
126
126
 
127
- ## axios 1.19.0
127
+ ## axios 1.20.0
128
128
 
129
129
  License: MIT
130
130
 
package/dist/api.cjs CHANGED
@@ -106,6 +106,13 @@ var DOCUMENT_ARTIFACT_NAMES = [
106
106
  "pades",
107
107
  "bundle"
108
108
  ];
109
+ var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
110
+ var VERIFICATION_METHODS = [
111
+ "Email",
112
+ "Whatsapp",
113
+ "DigitalCertificate"
114
+ ];
115
+ var NOTIFICATION_METHODS = ["Email", "Whatsapp"];
109
116
  function handleAssinafyResponse(response) {
110
117
  const resp = response;
111
118
  if (resp && typeof resp === "object" && resp.status !== void 0 && "data" in resp) {
@@ -183,6 +190,51 @@ function requireIso8601(value, name = "timestamp") {
183
190
  }
184
191
  return value;
185
192
  }
193
+ function requireEmail(value) {
194
+ if (!value || !EMAIL_RE.test(value)) {
195
+ throw new ValidationError("Invalid email address", { email: value });
196
+ }
197
+ return value;
198
+ }
199
+ function validateSignerOptions(input) {
200
+ if (input.verification_method !== void 0 && !VERIFICATION_METHODS.includes(input.verification_method)) {
201
+ throw new ValidationError(
202
+ `verification_method must be one of: ${VERIFICATION_METHODS.join(", ")}`
203
+ );
204
+ }
205
+ if (input.notification_methods !== void 0 && (!Array.isArray(input.notification_methods) || input.notification_methods.some(
206
+ (method) => !NOTIFICATION_METHODS.includes(method)
207
+ ))) {
208
+ throw new ValidationError(
209
+ `notification_methods must contain only: ${NOTIFICATION_METHODS.join(", ")}`
210
+ );
211
+ }
212
+ if (input.step !== void 0 && !Number.isInteger(input.step)) {
213
+ throw new ValidationError("step must be an integer");
214
+ }
215
+ }
216
+ function validateSigningSteps(signers) {
217
+ const withSteps = signers.filter((signer) => signer.step !== void 0);
218
+ if (withSteps.length > 0) {
219
+ if (withSteps.length !== signers.length) {
220
+ throw new ValidationError("step must be supplied for every signer when used");
221
+ }
222
+ const steps = [...new Set(withSteps.map((signer) => signer.step))].sort(
223
+ (a, b) => a - b
224
+ );
225
+ if (steps.some((step, index) => step !== index + 1)) {
226
+ throw new ValidationError("steps must form a contiguous sequence starting at 1");
227
+ }
228
+ }
229
+ validateDigitalCertificateSteps(signers);
230
+ }
231
+ function validateDigitalCertificateSteps(signers) {
232
+ for (const signer of signers) {
233
+ if (signer.verification_method === "DigitalCertificate" && signers.some((other) => other !== signer && (other.step ?? 1) === (signer.step ?? 1))) {
234
+ throw new ValidationError("a DigitalCertificate signer must be alone in its signing step");
235
+ }
236
+ }
237
+ }
186
238
  function documentStatsParams(params = {}) {
187
239
  if (params.granularity !== void 0 && !["monthly", "daily"].includes(params.granularity)) {
188
240
  throw new ValidationError("granularity must be monthly or daily");
@@ -328,15 +380,25 @@ function toInt(value) {
328
380
 
329
381
  // src/api/resources/assignments.ts
330
382
  function buildAssignmentPayload(payload, options = {}) {
383
+ if (payload.method !== void 0 && payload.method !== "virtual" && payload.method !== "collect") {
384
+ throw new ValidationError("method must be virtual or collect");
385
+ }
331
386
  const signers = extractSignerRefs(payload);
332
- if (signers.length === 0 && !options.allowEmptySigners) {
387
+ if (signers.length === 0 && (!options.allowEmptySigners || (payload.method ?? "virtual") !== "collect")) {
333
388
  throw new ValidationError("At least one signer is required", {
334
389
  signers: payload.signers ?? payload.signer_ids ?? payload.signerIds
335
390
  });
336
391
  }
392
+ if (payload.method === "collect" && !Array.isArray(payload.entries)) {
393
+ throw new ValidationError("entries are required for collect assignments");
394
+ }
395
+ const normalisedSigners = signers.map((ref) => normaliseSignerRef(ref, options));
396
+ if (!options.skipDigitalCertificateStepValidation) {
397
+ validateDigitalCertificateSteps(normalisedSigners);
398
+ }
337
399
  return cleanParams({
338
400
  method: payload.method ?? "virtual",
339
- signers: signers.map((ref) => normaliseSignerRef(ref, options)),
401
+ signers: normalisedSigners,
340
402
  message: payload.message,
341
403
  expires_at: payload.expires_at === void 0 ? void 0 : requireIso8601(payload.expires_at, "expires_at"),
342
404
  copy_receivers: payload.copy_receivers,
@@ -364,6 +426,7 @@ function normaliseSignerRef(ref, options) {
364
426
  if (ref && typeof ref === "object") {
365
427
  const input = ref;
366
428
  const id = input.id ?? input.signer_id;
429
+ validateSignerOptions(input);
367
430
  const normalised = cleanParams({
368
431
  id,
369
432
  verification_method: input.verification_method,
@@ -421,14 +484,16 @@ var AssignmentResource = class extends BaseResource {
421
484
  `/documents/${docId}/assignments/estimate-cost`,
422
485
  buildAssignmentPayload(payload, {
423
486
  allowSignersWithoutId: true,
424
- allowEmptySigners: true
487
+ allowEmptySigners: true,
488
+ skipDigitalCertificateStepValidation: true
425
489
  })
426
490
  )
427
491
  );
428
492
  }
429
493
  /**
430
494
  * Update the expiration date of an existing assignment.
431
- * Pass `null` to remove the expiration entirely.
495
+ * The published API accepts an ISO 8601 timestamp. Deployments that support
496
+ * clearing an expiration also accept `null`.
432
497
  */
433
498
  async resetExpiration(documentId, assignmentId, expiresAt) {
434
499
  const docId = this.requireId(documentId, "Document ID");
@@ -763,24 +828,24 @@ var DocumentResource = class extends BaseResource {
763
828
  );
764
829
  }
765
830
  /**
766
- * Replace the document's tag set with `tags` (an array of tag names).
767
- * Unknown names are auto-created; an empty array detaches all tags.
831
+ * Replace the document's tag set with tag IDs. An empty array detaches all tags.
832
+ * Values are forwarded unchanged for compatibility with deployments that also accept names.
768
833
  */
769
834
  async replaceTags(documentId, tags, accountId) {
770
835
  const accId = this.accountId(accountId);
771
836
  const docId = this.requireId(documentId, "Document ID");
772
- if (!Array.isArray(tags)) throw new ValidationError("tags must be an array of tag names");
837
+ if (!Array.isArray(tags)) throw new ValidationError("tags must be an array of tag IDs");
773
838
  return this.call(
774
839
  "Failed to replace document tags",
775
840
  () => this.http.put(`/accounts/${accId}/documents/${docId}/tags`, { tags })
776
841
  );
777
842
  }
778
- /** Attach additional tags (by name) without removing existing ones. Idempotent. */
843
+ /** Attach additional tag IDs without removing existing ones. */
779
844
  async addTags(documentId, tags, accountId) {
780
845
  const accId = this.accountId(accountId);
781
846
  const docId = this.requireId(documentId, "Document ID");
782
847
  if (!Array.isArray(tags) || tags.length === 0) {
783
- throw new ValidationError("tags must be a non-empty array of tag names");
848
+ throw new ValidationError("tags must be a non-empty array of tag IDs");
784
849
  }
785
850
  return this.call(
786
851
  "Failed to add document tags",
@@ -810,7 +875,14 @@ var DocumentResource = class extends BaseResource {
810
875
  async createFromTemplate(templateId, signers, options = {}, accountId) {
811
876
  const tmplId = this.requireId(templateId, "Template ID");
812
877
  const accId = this.accountId(accountId);
878
+ validateTemplateSigners(signers, { requireId: true, singleNotification: true });
813
879
  if (options.expires_at !== void 0) requireIso8601(options.expires_at, "expires_at");
880
+ if (options.editor_fields !== void 0 && (!Array.isArray(options.editor_fields) || options.editor_fields.some((field) => !field?.field_id || typeof field.value !== "string"))) {
881
+ throw new ValidationError("editor_fields must contain field_id and value");
882
+ }
883
+ if (options.tags !== void 0 && (!Array.isArray(options.tags) || options.tags.some((tag) => typeof tag !== "string" || !tag))) {
884
+ throw new ValidationError("tags must contain non-empty tag names");
885
+ }
814
886
  const body = { ...options, signers };
815
887
  this.logger.info("Creating document from template", { templateId: tmplId, accountId: accId });
816
888
  return this.call(
@@ -822,6 +894,7 @@ var DocumentResource = class extends BaseResource {
822
894
  async estimateCostFromTemplate(templateId, signers, accountId) {
823
895
  const tmplId = this.requireId(templateId, "Template ID");
824
896
  const accId = this.accountId(accountId);
897
+ validateTemplateSigners(signers, { requireId: false, singleNotification: false });
825
898
  return this.call(
826
899
  "Failed to estimate cost from template",
827
900
  () => this.http.post(`/accounts/${accId}/templates/${tmplId}/documents/estimate-cost`, { signers })
@@ -868,7 +941,7 @@ var DocumentResource = class extends BaseResource {
868
941
  async sendToken(documentId, recipient, channel = "email") {
869
942
  const id = this.requireId(documentId, "Document ID");
870
943
  if (typeof recipient === "object") {
871
- if (!recipient?.email) throw new ValidationError("email is required");
944
+ requireEmail(recipient?.email);
872
945
  return this.call(
873
946
  "Failed to send signing token",
874
947
  () => this.http.put(
@@ -879,6 +952,10 @@ var DocumentResource = class extends BaseResource {
879
952
  );
880
953
  }
881
954
  if (!recipient) throw new ValidationError("recipient is required");
955
+ if (channel !== "email" && channel !== "whatsapp") {
956
+ throw new ValidationError("channel must be email or whatsapp");
957
+ }
958
+ if (channel === "email") requireEmail(recipient);
882
959
  return this.call(
883
960
  "Failed to send signing token",
884
961
  () => this.http.put(
@@ -909,6 +986,31 @@ var DocumentResource = class extends BaseResource {
909
986
  return { signed, total, pending, percentage };
910
987
  }
911
988
  };
989
+ function validateTemplateSigners(signers, options) {
990
+ if (!Array.isArray(signers)) throw new ValidationError("signers must be an array");
991
+ for (const value of signers) {
992
+ if (!value || typeof value !== "object") {
993
+ throw new ValidationError("each template signer must be an object");
994
+ }
995
+ const signer = value;
996
+ if (typeof signer.role_id !== "string" || !signer.role_id) {
997
+ throw new ValidationError("each template signer requires role_id");
998
+ }
999
+ if ((options.requireId || signer.id !== void 0) && (typeof signer.id !== "string" || !signer.id)) {
1000
+ throw new ValidationError("each template signer requires a valid id");
1001
+ }
1002
+ validateSignerOptions(signer);
1003
+ if (options.requireId && signer.step !== void 0 && Number(signer.step) < 1) {
1004
+ throw new ValidationError("template signer step must be a positive integer");
1005
+ }
1006
+ if (options.singleNotification && Array.isArray(signer.notification_methods) && signer.notification_methods.length > 1) {
1007
+ throw new ValidationError("template signers accept at most one notification method");
1008
+ }
1009
+ }
1010
+ if (options.requireId) {
1011
+ validateSigningSteps(signers);
1012
+ }
1013
+ }
912
1014
  async function loadSource(source) {
913
1015
  if ("buffer" in source) {
914
1016
  if (!source.fileName) {
@@ -1020,6 +1122,7 @@ var FieldsResource = class extends BaseResource {
1020
1122
  async validate(fieldId, value, options = {}) {
1021
1123
  const id = this.accountId(options.accountId);
1022
1124
  const fid = this.requireId(fieldId, "Field ID");
1125
+ if (value === void 0) throw new ValidationError("value is required");
1023
1126
  return this.call(
1024
1127
  "Failed to validate field value",
1025
1128
  () => this.http.post(
@@ -1034,6 +1137,11 @@ var FieldsResource = class extends BaseResource {
1034
1137
  if (!Array.isArray(entries) || entries.length === 0) {
1035
1138
  throw new ValidationError("entries must be a non-empty array");
1036
1139
  }
1140
+ if (entries.some(
1141
+ (entry) => !entry || typeof entry !== "object" || typeof entry.field_id !== "string" || !entry.field_id || entry.value === void 0
1142
+ )) {
1143
+ throw new ValidationError("each entry must contain field_id and value");
1144
+ }
1037
1145
  const id = this.accountId(options.accountId);
1038
1146
  return this.call(
1039
1147
  "Failed to validate field values",
@@ -1085,20 +1193,28 @@ var SignerDocumentsResource = class extends BaseResource {
1085
1193
  () => this.http.get(`/signers/${sid}/documents/search`, signerAccessConfig(code, { search }))
1086
1194
  );
1087
1195
  }
1088
- /** `GET /signers/{signer_id}/documents/{document_id}/download/{artifact}?signer-access-code=…` */
1196
+ /**
1197
+ * Public `GET /signers/{signer_id}/documents/{document_id}/download/{artifact}`.
1198
+ * When an access code is supplied, the SDK first verifies that it belongs to
1199
+ * the requested signer for callers that want that additional check.
1200
+ */
1089
1201
  async download(signerId, documentId, artifactName, signerAccessCode) {
1090
1202
  const sid = this.requireId(signerId, "Signer ID");
1091
1203
  const did = this.requireId(documentId, "Document ID");
1092
1204
  const artifact = requireDocumentArtifactName(artifactName);
1093
- const code = this.requireId(signerAccessCode, "signer-access-code");
1094
- const signer = await this.self(code);
1095
- if (signer.id !== sid) {
1096
- throw new ValidationError("Signer access code does not match the signer ID");
1205
+ let config = publicRequestConfig();
1206
+ if (signerAccessCode !== void 0) {
1207
+ const code = this.requireId(signerAccessCode, "signer-access-code");
1208
+ const signer = await this.self(code);
1209
+ if (signer.id !== sid) {
1210
+ throw new ValidationError("Signer access code does not match the signer ID");
1211
+ }
1212
+ config = signerAccessConfig(code);
1097
1213
  }
1098
1214
  return this.callBinary(
1099
1215
  "Failed to download signer document",
1100
1216
  () => this.http.get(`/signers/${sid}/documents/${did}/download/${artifact}`, {
1101
- ...signerAccessConfig(code),
1217
+ ...config,
1102
1218
  responseType: "arraybuffer"
1103
1219
  })
1104
1220
  );
@@ -1266,15 +1382,9 @@ var SignerDocumentsResource = class extends BaseResource {
1266
1382
  };
1267
1383
 
1268
1384
  // src/api/resources/signers.ts
1269
- var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
1270
1385
  function validateCreateSignerPayload(payload) {
1271
1386
  if (!payload.full_name?.trim()) throw new ValidationError("Signer full name is required");
1272
- if (payload.email) assertEmail(payload.email);
1273
- }
1274
- function assertEmail(email) {
1275
- if (!email || !EMAIL_RE.test(email)) {
1276
- throw new ValidationError("Invalid email address", { email });
1277
- }
1387
+ if (payload.email !== void 0) requireEmail(payload.email);
1278
1388
  }
1279
1389
  var SignerResource = class extends BaseResource {
1280
1390
  /**
@@ -1337,6 +1447,10 @@ var SignerResource = class extends BaseResource {
1337
1447
  async update(signerId, payload, accountId) {
1338
1448
  const id = this.accountId(accountId);
1339
1449
  const sid = this.requireId(signerId, "Signer ID");
1450
+ if (payload.full_name !== void 0 && !payload.full_name.trim()) {
1451
+ throw new ValidationError("Signer full name cannot be blank");
1452
+ }
1453
+ if (payload.email !== void 0) requireEmail(payload.email);
1340
1454
  return this.call(
1341
1455
  "Failed to update signer",
1342
1456
  () => this.http.put(`/accounts/${id}/signers/${sid}`, normaliseSignerPayload(payload, true))
@@ -1353,7 +1467,7 @@ var SignerResource = class extends BaseResource {
1353
1467
  }
1354
1468
  /** Find a signer by email via the API's `search` parameter. Returns `null` if none match. */
1355
1469
  async findByEmail(email, accountId) {
1356
- assertEmail(email);
1470
+ requireEmail(email);
1357
1471
  try {
1358
1472
  const { data } = await this.list({ search: email, per_page: 100 }, accountId);
1359
1473
  const lower = email.toLowerCase();
@@ -1551,7 +1665,22 @@ var WebhookResource = class extends BaseResource {
1551
1665
  /** Register (or replace) the webhook subscription for the workspace. */
1552
1666
  async register(payload, accountId) {
1553
1667
  if (!payload.url) throw new ValidationError("Webhook URL is required");
1554
- if (!payload.email) throw new ValidationError("Webhook email is required");
1668
+ let webhookUrl;
1669
+ try {
1670
+ webhookUrl = new URL(payload.url);
1671
+ } catch {
1672
+ throw new ValidationError("Webhook URL must be a valid HTTP(S) URL");
1673
+ }
1674
+ if (webhookUrl.protocol !== "http:" && webhookUrl.protocol !== "https:") {
1675
+ throw new ValidationError("Webhook URL must be a valid HTTP(S) URL");
1676
+ }
1677
+ requireEmail(payload.email);
1678
+ if (payload.events !== void 0 && (!Array.isArray(payload.events) || payload.events.some((event) => typeof event !== "string" || !event))) {
1679
+ throw new ValidationError("Webhook events must contain non-empty strings");
1680
+ }
1681
+ if (payload.is_active !== void 0 && typeof payload.is_active !== "boolean") {
1682
+ throw new ValidationError("Webhook is_active must be a boolean");
1683
+ }
1555
1684
  const id = this.accountId(accountId);
1556
1685
  const body = {
1557
1686
  url: payload.url,
@@ -1725,13 +1854,13 @@ var WebhookVerifier = class {
1725
1854
  /** Returns `true` if `signature` is a valid HMAC of `payload` under the configured scheme. */
1726
1855
  verify(payload, signature) {
1727
1856
  if (!this.webhookSecret || !signature) return false;
1728
- const buf = typeof payload === "string" ? Buffer.from(payload, "utf8") : payload;
1729
- const expected = (0, import_node_crypto.createHmac)(this.algorithm, this.webhookSecret).update(buf).digest(this.encoding);
1730
- const provided = signature.trim();
1731
- const a = Buffer.from(expected, "utf8");
1732
- const b = Buffer.from(provided, "utf8");
1733
- if (a.length !== b.length) return false;
1734
1857
  try {
1858
+ const buf = typeof payload === "string" ? Buffer.from(payload, "utf8") : payload;
1859
+ const expected = (0, import_node_crypto.createHmac)(this.algorithm, this.webhookSecret).update(buf).digest(this.encoding);
1860
+ const provided = signature.trim();
1861
+ const a = Buffer.from(expected, "utf8");
1862
+ const b = Buffer.from(provided, "utf8");
1863
+ if (a.length !== b.length) return false;
1735
1864
  return (0, import_node_crypto.timingSafeEqual)(a, b);
1736
1865
  } catch {
1737
1866
  return false;
@@ -1751,7 +1880,8 @@ var WebhookVerifier = class {
1751
1880
  getEventType(event) {
1752
1881
  if (!event || typeof event !== "object") return null;
1753
1882
  const e = event;
1754
- return e.event ?? e.type ?? null;
1883
+ if (typeof e.event === "string") return e.event;
1884
+ return typeof e.type === "string" ? e.type : null;
1755
1885
  }
1756
1886
  /**
1757
1887
  * Extract the event data from an event envelope.
@@ -1796,6 +1926,9 @@ var AssinafyClient = class _AssinafyClient {
1796
1926
  "An API key (options.apiKey) or legacy access token (options.token) is required."
1797
1927
  );
1798
1928
  }
1929
+ if (options.timeout !== void 0 && (!Number.isFinite(options.timeout) || options.timeout <= 0)) {
1930
+ throw new ValidationError("timeout must be a finite positive number");
1931
+ }
1799
1932
  this.defaultAccountId = options.accountId;
1800
1933
  this.logger = options.logger ?? createNoopLogger();
1801
1934
  this.webhookSecret = options.webhookSecret;