@assinafy/cli 2.4.0 → 2.4.2

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/api.js CHANGED
@@ -131,6 +131,19 @@ function cleanParams(params) {
131
131
  }
132
132
  return out;
133
133
  }
134
+ function stripEmpty(body) {
135
+ const out = {};
136
+ for (const [key, value] of Object.entries(body)) {
137
+ if (value !== void 0 && value !== null) {
138
+ out[key] = value;
139
+ }
140
+ }
141
+ return out;
142
+ }
143
+ function appendFilePart(form, data, contentType, fileName) {
144
+ const view = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
145
+ form.append("file", new Blob([view], { type: contentType }), fileName);
146
+ }
134
147
  function publicRequestConfig(config = {}) {
135
148
  return {
136
149
  ...config,
@@ -371,7 +384,7 @@ function buildAssignmentPayload(payload, options = {}) {
371
384
  if (!options.skipDigitalCertificateStepValidation) {
372
385
  validateSigningSteps(normalisedSigners);
373
386
  }
374
- return cleanParams({
387
+ return stripEmpty({
375
388
  method: payload.method ?? "virtual",
376
389
  signers: normalisedSigners,
377
390
  message: payload.message,
@@ -402,7 +415,7 @@ function normaliseSignerRef(ref, options) {
402
415
  const input = ref;
403
416
  const id = input.id ?? input.signer_id;
404
417
  validateSignerOptions(input);
405
- const normalised = cleanParams({
418
+ const normalised = stripEmpty({
406
419
  id,
407
420
  verification_method: input.verification_method,
408
421
  notification_methods: input.notification_methods,
@@ -601,6 +614,7 @@ var AuthenticationResource = class extends BaseResource {
601
614
  import { promises as fs } from "fs";
602
615
  import path from "path";
603
616
  var MAX_UPLOAD_BYTES = 25 * 1024 * 1024;
617
+ var DOCUMENT_SORTS = ["name", "-name", "updated_at", "-updated_at"];
604
618
  var READY_STATUSES = /* @__PURE__ */ new Set([
605
619
  "metadata_ready",
606
620
  "pending_signature",
@@ -648,7 +662,7 @@ var DocumentResource = class extends BaseResource {
648
662
  */
649
663
  async list(params = {}, accountId) {
650
664
  const id = this.accountId(accountId);
651
- requireSort(params.sort, ["name", "-name", "updated_at", "-updated_at"]);
665
+ requireSort(params.sort, DOCUMENT_SORTS);
652
666
  return this.callList(
653
667
  "Failed to list documents",
654
668
  () => this.http.get(`/accounts/${id}/documents`, {
@@ -666,7 +680,7 @@ var DocumentResource = class extends BaseResource {
666
680
  */
667
681
  async search(params = {}, accountId) {
668
682
  const id = this.accountId(accountId);
669
- requireSort(params.sort, ["name", "-name", "updated_at", "-updated_at"]);
683
+ requireSort(params.sort, DOCUMENT_SORTS);
670
684
  return this.callList(
671
685
  "Failed to search documents",
672
686
  () => this.http.get(`/accounts/${id}/documents/search`, {
@@ -1021,8 +1035,7 @@ function validateUpload(buffer, fileName) {
1021
1035
  }
1022
1036
  function buildUploadForm(buffer, fileName, name, metadata) {
1023
1037
  const form = new FormData();
1024
- const view = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1025
- form.append("file", new Blob([view], { type: "application/pdf" }), fileName);
1038
+ appendFilePart(form, buffer, "application/pdf", fileName);
1026
1039
  form.append("name", name);
1027
1040
  if (metadata) {
1028
1041
  form.append("metadata", JSON.stringify(metadata));
@@ -1132,26 +1145,35 @@ var FieldsResource = class extends BaseResource {
1132
1145
  }
1133
1146
  };
1134
1147
  function validationConfig(signerAccessCode) {
1135
- return signerAccessCode ? signerAccessConfig(signerAccessCode) : void 0;
1148
+ if (signerAccessCode === void 0) return void 0;
1149
+ if (typeof signerAccessCode !== "string" || !signerAccessCode.trim()) {
1150
+ throw new ValidationError("signerAccessCode is required when supplied");
1151
+ }
1152
+ return signerAccessConfig(signerAccessCode);
1136
1153
  }
1137
1154
 
1138
1155
  // src/api/resources/oauth.ts
1139
1156
  import { createHash, randomBytes, timingSafeEqual } from "crypto";
1140
- var formRequestConfig = publicRequestConfig({
1141
- headers: { "Content-Type": "application/x-www-form-urlencoded" }
1142
- });
1157
+ function formRequestConfig() {
1158
+ return publicRequestConfig({
1159
+ headers: { "Content-Type": "application/x-www-form-urlencoded" }
1160
+ });
1161
+ }
1143
1162
  var OAuthResource = class extends BaseResource {
1144
1163
  /** `GET /.well-known/oauth-protected-resource` at the API origin, outside `/v1`. */
1145
1164
  async metadata() {
1146
- return this.call(
1147
- "Failed to discover OAuth resource",
1148
- () => this.http.get(
1165
+ return this.call("Failed to discover OAuth resource", () => {
1166
+ const baseURL = this.http.defaults.baseURL;
1167
+ if (!baseURL) {
1168
+ throw new ValidationError("A base URL is required to discover OAuth metadata");
1169
+ }
1170
+ return this.http.get(
1149
1171
  "/.well-known/oauth-protected-resource",
1150
1172
  publicRequestConfig({
1151
- baseURL: new URL(this.http.defaults.baseURL).origin
1173
+ baseURL: new URL(baseURL).origin
1152
1174
  })
1153
- )
1154
- );
1175
+ );
1176
+ });
1155
1177
  }
1156
1178
  /** Read RFC 8414 metadata from an HTTPS issuer and verify its issuer identity. */
1157
1179
  async discovery(issuer) {
@@ -1235,6 +1257,9 @@ var OAuthResource = class extends BaseResource {
1235
1257
  if (callback.searchParams.get("iss") !== request.issuer) {
1236
1258
  throw new ValidationError("OAuth issuer mismatch");
1237
1259
  }
1260
+ if (callback.searchParams.has("code") === callback.searchParams.has("error")) {
1261
+ throw new ValidationError("OAuth callback must contain exactly one of code or error");
1262
+ }
1238
1263
  if (callback.searchParams.has("error")) {
1239
1264
  const error = callback.searchParams.get("error");
1240
1265
  const oauthError = error.length > 0 && error.length <= 64 && !/[^a-z_]/.test(error) ? error : "unknown_error";
@@ -1275,7 +1300,7 @@ var OAuthResource = class extends BaseResource {
1275
1300
  }
1276
1301
  const tokens = await this.call(
1277
1302
  "OAuth token request failed",
1278
- () => this.http.post("/oauth/token", payload, formRequestConfig)
1303
+ () => this.http.post("/oauth/token", payload, formRequestConfig())
1279
1304
  );
1280
1305
  const next = tokens?.refresh_token;
1281
1306
  if (payload.grant_type === "refresh_token" && (typeof next !== "string" || !next.trim() || next === payload.refresh_token)) {
@@ -1296,7 +1321,7 @@ var OAuthResource = class extends BaseResource {
1296
1321
  }
1297
1322
  await this.call(
1298
1323
  "OAuth revocation failed",
1299
- () => this.http.post("/oauth/revoke", payload, formRequestConfig)
1324
+ () => this.http.post("/oauth/revoke", payload, formRequestConfig())
1300
1325
  );
1301
1326
  }
1302
1327
  /** `GET /oauth/userinfo` — flat OIDC claims; requires a bearer token with `openid`. */
@@ -1694,12 +1719,18 @@ var SignerResource = class extends BaseResource {
1694
1719
  requireEmail(email);
1695
1720
  try {
1696
1721
  const lower = email.toLowerCase();
1697
- for (let page = 1; ; page++) {
1722
+ for (let page = 1; page <= MAX_SEARCH_PAGES; page++) {
1698
1723
  const { data, meta } = await this.list({ search: email, per_page: 100, page }, accountId);
1699
1724
  const match = data.find((s) => (s.email ?? "").toLowerCase() === lower);
1700
1725
  if (match) return match;
1701
- if (!data.length || !meta?.last_page || page >= meta.last_page) return null;
1726
+ if (!data.length) return null;
1727
+ if (meta?.last_page !== void 0) {
1728
+ if (page >= meta.last_page) return null;
1729
+ } else if (data.length < 100) {
1730
+ return null;
1731
+ }
1702
1732
  }
1733
+ throw new ValidationError("Signer email search exceeded the maximum page count");
1703
1734
  } catch (err) {
1704
1735
  if (err instanceof ApiError && err.statusCode === 404) {
1705
1736
  return null;
@@ -1708,6 +1739,7 @@ var SignerResource = class extends BaseResource {
1708
1739
  }
1709
1740
  }
1710
1741
  };
1742
+ var MAX_SEARCH_PAGES = 100;
1711
1743
  function normaliseSignerPayload(payload, useGovernmentId = false) {
1712
1744
  const normalised = {
1713
1745
  full_name: payload.full_name,
@@ -1722,7 +1754,7 @@ function normaliseSignerPayload(payload, useGovernmentId = false) {
1722
1754
  if ("metadata" in payload && payload.metadata !== void 0) {
1723
1755
  normalised.metadata = payload.metadata;
1724
1756
  }
1725
- return cleanParams(normalised);
1757
+ return stripEmpty(normalised);
1726
1758
  }
1727
1759
 
1728
1760
  // src/api/resources/tags.ts
@@ -1743,7 +1775,7 @@ var TagResource = class extends BaseResource {
1743
1775
  const id = this.accountId(accountId);
1744
1776
  return this.call(
1745
1777
  "Failed to create tag",
1746
- () => this.http.post(`/accounts/${id}/tags`, cleanParams({ ...payload }))
1778
+ () => this.http.post(`/accounts/${id}/tags`, stripEmpty({ ...payload }))
1747
1779
  );
1748
1780
  }
1749
1781
  /**
@@ -2016,9 +2048,8 @@ var WorkspaceResource = class extends BaseResource {
2016
2048
  throw new ValidationError("Logo buffer is required");
2017
2049
  }
2018
2050
  const contentType = options.contentType ?? "image/png";
2019
- const view = new Uint8Array(logo.buffer, logo.byteOffset, logo.byteLength);
2020
2051
  const form = new FormData();
2021
- form.append("file", new Blob([view], { type: contentType }), options.fileName ?? "logo.png");
2052
+ appendFilePart(form, logo, contentType, options.fileName ?? "logo.png");
2022
2053
  return this.call(
2023
2054
  "Failed to upload workspace logo",
2024
2055
  () => this.http.post(`/accounts/${id}/logo`, form, {
@@ -2354,6 +2385,8 @@ export {
2354
2385
  WebhookVerifier,
2355
2386
  WorkspaceResource,
2356
2387
  buildAssignmentPayload,
2357
- normalizeBaseUrl
2388
+ normalizeBaseUrl,
2389
+ requireDocumentArtifactName,
2390
+ requireSignerImageType
2358
2391
  };
2359
2392
  //# sourceMappingURL=api.js.map