@assinafy/cli 2.4.0 → 2.4.1

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));
@@ -1137,21 +1150,26 @@ function validationConfig(signerAccessCode) {
1137
1150
 
1138
1151
  // src/api/resources/oauth.ts
1139
1152
  import { createHash, randomBytes, timingSafeEqual } from "crypto";
1140
- var formRequestConfig = publicRequestConfig({
1141
- headers: { "Content-Type": "application/x-www-form-urlencoded" }
1142
- });
1153
+ function formRequestConfig() {
1154
+ return publicRequestConfig({
1155
+ headers: { "Content-Type": "application/x-www-form-urlencoded" }
1156
+ });
1157
+ }
1143
1158
  var OAuthResource = class extends BaseResource {
1144
1159
  /** `GET /.well-known/oauth-protected-resource` at the API origin, outside `/v1`. */
1145
1160
  async metadata() {
1146
- return this.call(
1147
- "Failed to discover OAuth resource",
1148
- () => this.http.get(
1161
+ return this.call("Failed to discover OAuth resource", () => {
1162
+ const baseURL = this.http.defaults.baseURL;
1163
+ if (!baseURL) {
1164
+ throw new ValidationError("A base URL is required to discover OAuth metadata");
1165
+ }
1166
+ return this.http.get(
1149
1167
  "/.well-known/oauth-protected-resource",
1150
1168
  publicRequestConfig({
1151
- baseURL: new URL(this.http.defaults.baseURL).origin
1169
+ baseURL: new URL(baseURL).origin
1152
1170
  })
1153
- )
1154
- );
1171
+ );
1172
+ });
1155
1173
  }
1156
1174
  /** Read RFC 8414 metadata from an HTTPS issuer and verify its issuer identity. */
1157
1175
  async discovery(issuer) {
@@ -1275,7 +1293,7 @@ var OAuthResource = class extends BaseResource {
1275
1293
  }
1276
1294
  const tokens = await this.call(
1277
1295
  "OAuth token request failed",
1278
- () => this.http.post("/oauth/token", payload, formRequestConfig)
1296
+ () => this.http.post("/oauth/token", payload, formRequestConfig())
1279
1297
  );
1280
1298
  const next = tokens?.refresh_token;
1281
1299
  if (payload.grant_type === "refresh_token" && (typeof next !== "string" || !next.trim() || next === payload.refresh_token)) {
@@ -1296,7 +1314,7 @@ var OAuthResource = class extends BaseResource {
1296
1314
  }
1297
1315
  await this.call(
1298
1316
  "OAuth revocation failed",
1299
- () => this.http.post("/oauth/revoke", payload, formRequestConfig)
1317
+ () => this.http.post("/oauth/revoke", payload, formRequestConfig())
1300
1318
  );
1301
1319
  }
1302
1320
  /** `GET /oauth/userinfo` — flat OIDC claims; requires a bearer token with `openid`. */
@@ -1694,12 +1712,18 @@ var SignerResource = class extends BaseResource {
1694
1712
  requireEmail(email);
1695
1713
  try {
1696
1714
  const lower = email.toLowerCase();
1697
- for (let page = 1; ; page++) {
1715
+ for (let page = 1; page <= MAX_SEARCH_PAGES; page++) {
1698
1716
  const { data, meta } = await this.list({ search: email, per_page: 100, page }, accountId);
1699
1717
  const match = data.find((s) => (s.email ?? "").toLowerCase() === lower);
1700
1718
  if (match) return match;
1701
- if (!data.length || !meta?.last_page || page >= meta.last_page) return null;
1719
+ if (!data.length) return null;
1720
+ if (meta?.last_page !== void 0) {
1721
+ if (page >= meta.last_page) return null;
1722
+ } else if (data.length < 100) {
1723
+ return null;
1724
+ }
1702
1725
  }
1726
+ throw new ValidationError("Signer email search exceeded the maximum page count");
1703
1727
  } catch (err) {
1704
1728
  if (err instanceof ApiError && err.statusCode === 404) {
1705
1729
  return null;
@@ -1708,6 +1732,7 @@ var SignerResource = class extends BaseResource {
1708
1732
  }
1709
1733
  }
1710
1734
  };
1735
+ var MAX_SEARCH_PAGES = 100;
1711
1736
  function normaliseSignerPayload(payload, useGovernmentId = false) {
1712
1737
  const normalised = {
1713
1738
  full_name: payload.full_name,
@@ -1722,7 +1747,7 @@ function normaliseSignerPayload(payload, useGovernmentId = false) {
1722
1747
  if ("metadata" in payload && payload.metadata !== void 0) {
1723
1748
  normalised.metadata = payload.metadata;
1724
1749
  }
1725
- return cleanParams(normalised);
1750
+ return stripEmpty(normalised);
1726
1751
  }
1727
1752
 
1728
1753
  // src/api/resources/tags.ts
@@ -1743,7 +1768,7 @@ var TagResource = class extends BaseResource {
1743
1768
  const id = this.accountId(accountId);
1744
1769
  return this.call(
1745
1770
  "Failed to create tag",
1746
- () => this.http.post(`/accounts/${id}/tags`, cleanParams({ ...payload }))
1771
+ () => this.http.post(`/accounts/${id}/tags`, stripEmpty({ ...payload }))
1747
1772
  );
1748
1773
  }
1749
1774
  /**
@@ -2016,9 +2041,8 @@ var WorkspaceResource = class extends BaseResource {
2016
2041
  throw new ValidationError("Logo buffer is required");
2017
2042
  }
2018
2043
  const contentType = options.contentType ?? "image/png";
2019
- const view = new Uint8Array(logo.buffer, logo.byteOffset, logo.byteLength);
2020
2044
  const form = new FormData();
2021
- form.append("file", new Blob([view], { type: contentType }), options.fileName ?? "logo.png");
2045
+ appendFilePart(form, logo, contentType, options.fileName ?? "logo.png");
2022
2046
  return this.call(
2023
2047
  "Failed to upload workspace logo",
2024
2048
  () => this.http.post(`/accounts/${id}/logo`, form, {
@@ -2354,6 +2378,8 @@ export {
2354
2378
  WebhookVerifier,
2355
2379
  WorkspaceResource,
2356
2380
  buildAssignmentPayload,
2357
- normalizeBaseUrl
2381
+ normalizeBaseUrl,
2382
+ requireDocumentArtifactName,
2383
+ requireSignerImageType
2358
2384
  };
2359
2385
  //# sourceMappingURL=api.js.map