@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/README.en.md CHANGED
@@ -571,7 +571,7 @@ The [release runbook](./docs/releasing.md) covers tags, trusted publishing, and
571
571
 
572
572
  - The production OpenAPI publishes 93 operations and the SDK implements all of them. Sandbox deployments can lag individual routes — account/user statistics and user notification preferences may return route-level 404s there despite being documented in production.
573
573
  - The SDK keeps two platform-compatible template routes (`GET /accounts/{id}/templates/{id}` and its page download) that are absent from the published OpenAPI paths.
574
- - The API's digital-certificate prose mentions certificate start/complete routes that are not defined as OpenAPI paths. The SDK does not invent contracts for them.
574
+ - Certificate start/complete are deployed production extensions of the public signing frontend, exposed as `signerDocuments.startCertificate(accessCode)` and `signerDocuments.completeCertificate(accessCode, token)`. Start posts `{ "signer-access-code": code }` and returns `{ token }`; complete posts `{ "signer-access-code": code, token }` and returns `{ signerName }`. Both also carry the access code in the query string and strip owner credentials. They supplement, but are not part of, the 93 OpenAPI operations.
575
575
  - Both the published and legacy `send-token` payloads are supported for compatible deployments.
576
576
  - `WebhookVerifier` is **experimental**. Assinafy does not publish the signature header, algorithm, encoding, timestamp, or replay-protection scheme, so it is not a production trust boundary until the exact scheme is published or independently verified against real deliveries.
577
577
 
package/dist/api.cjs CHANGED
@@ -51,7 +51,9 @@ __export(api_exports, {
51
51
  WebhookVerifier: () => WebhookVerifier,
52
52
  WorkspaceResource: () => WorkspaceResource,
53
53
  buildAssignmentPayload: () => buildAssignmentPayload,
54
- normalizeBaseUrl: () => normalizeBaseUrl
54
+ normalizeBaseUrl: () => normalizeBaseUrl,
55
+ requireDocumentArtifactName: () => requireDocumentArtifactName,
56
+ requireSignerImageType: () => requireSignerImageType
55
57
  });
56
58
  module.exports = __toCommonJS(api_exports);
57
59
 
@@ -188,6 +190,19 @@ function cleanParams(params) {
188
190
  }
189
191
  return out;
190
192
  }
193
+ function stripEmpty(body) {
194
+ const out = {};
195
+ for (const [key, value] of Object.entries(body)) {
196
+ if (value !== void 0 && value !== null) {
197
+ out[key] = value;
198
+ }
199
+ }
200
+ return out;
201
+ }
202
+ function appendFilePart(form, data, contentType, fileName) {
203
+ const view = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
204
+ form.append("file", new Blob([view], { type: contentType }), fileName);
205
+ }
191
206
  function publicRequestConfig(config = {}) {
192
207
  return {
193
208
  ...config,
@@ -428,7 +443,7 @@ function buildAssignmentPayload(payload, options = {}) {
428
443
  if (!options.skipDigitalCertificateStepValidation) {
429
444
  validateSigningSteps(normalisedSigners);
430
445
  }
431
- return cleanParams({
446
+ return stripEmpty({
432
447
  method: payload.method ?? "virtual",
433
448
  signers: normalisedSigners,
434
449
  message: payload.message,
@@ -459,7 +474,7 @@ function normaliseSignerRef(ref, options) {
459
474
  const input = ref;
460
475
  const id = input.id ?? input.signer_id;
461
476
  validateSignerOptions(input);
462
- const normalised = cleanParams({
477
+ const normalised = stripEmpty({
463
478
  id,
464
479
  verification_method: input.verification_method,
465
480
  notification_methods: input.notification_methods,
@@ -658,6 +673,7 @@ var AuthenticationResource = class extends BaseResource {
658
673
  var import_node_fs = require("fs");
659
674
  var import_node_path = __toESM(require("path"), 1);
660
675
  var MAX_UPLOAD_BYTES = 25 * 1024 * 1024;
676
+ var DOCUMENT_SORTS = ["name", "-name", "updated_at", "-updated_at"];
661
677
  var READY_STATUSES = /* @__PURE__ */ new Set([
662
678
  "metadata_ready",
663
679
  "pending_signature",
@@ -705,7 +721,7 @@ var DocumentResource = class extends BaseResource {
705
721
  */
706
722
  async list(params = {}, accountId) {
707
723
  const id = this.accountId(accountId);
708
- requireSort(params.sort, ["name", "-name", "updated_at", "-updated_at"]);
724
+ requireSort(params.sort, DOCUMENT_SORTS);
709
725
  return this.callList(
710
726
  "Failed to list documents",
711
727
  () => this.http.get(`/accounts/${id}/documents`, {
@@ -723,7 +739,7 @@ var DocumentResource = class extends BaseResource {
723
739
  */
724
740
  async search(params = {}, accountId) {
725
741
  const id = this.accountId(accountId);
726
- requireSort(params.sort, ["name", "-name", "updated_at", "-updated_at"]);
742
+ requireSort(params.sort, DOCUMENT_SORTS);
727
743
  return this.callList(
728
744
  "Failed to search documents",
729
745
  () => this.http.get(`/accounts/${id}/documents/search`, {
@@ -1078,8 +1094,7 @@ function validateUpload(buffer, fileName) {
1078
1094
  }
1079
1095
  function buildUploadForm(buffer, fileName, name, metadata) {
1080
1096
  const form = new FormData();
1081
- const view = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1082
- form.append("file", new Blob([view], { type: "application/pdf" }), fileName);
1097
+ appendFilePart(form, buffer, "application/pdf", fileName);
1083
1098
  form.append("name", name);
1084
1099
  if (metadata) {
1085
1100
  form.append("metadata", JSON.stringify(metadata));
@@ -1194,21 +1209,26 @@ function validationConfig(signerAccessCode) {
1194
1209
 
1195
1210
  // src/api/resources/oauth.ts
1196
1211
  var import_node_crypto = require("crypto");
1197
- var formRequestConfig = publicRequestConfig({
1198
- headers: { "Content-Type": "application/x-www-form-urlencoded" }
1199
- });
1212
+ function formRequestConfig() {
1213
+ return publicRequestConfig({
1214
+ headers: { "Content-Type": "application/x-www-form-urlencoded" }
1215
+ });
1216
+ }
1200
1217
  var OAuthResource = class extends BaseResource {
1201
1218
  /** `GET /.well-known/oauth-protected-resource` at the API origin, outside `/v1`. */
1202
1219
  async metadata() {
1203
- return this.call(
1204
- "Failed to discover OAuth resource",
1205
- () => this.http.get(
1220
+ return this.call("Failed to discover OAuth resource", () => {
1221
+ const baseURL = this.http.defaults.baseURL;
1222
+ if (!baseURL) {
1223
+ throw new ValidationError("A base URL is required to discover OAuth metadata");
1224
+ }
1225
+ return this.http.get(
1206
1226
  "/.well-known/oauth-protected-resource",
1207
1227
  publicRequestConfig({
1208
- baseURL: new URL(this.http.defaults.baseURL).origin
1228
+ baseURL: new URL(baseURL).origin
1209
1229
  })
1210
- )
1211
- );
1230
+ );
1231
+ });
1212
1232
  }
1213
1233
  /** Read RFC 8414 metadata from an HTTPS issuer and verify its issuer identity. */
1214
1234
  async discovery(issuer) {
@@ -1332,7 +1352,7 @@ var OAuthResource = class extends BaseResource {
1332
1352
  }
1333
1353
  const tokens = await this.call(
1334
1354
  "OAuth token request failed",
1335
- () => this.http.post("/oauth/token", payload, formRequestConfig)
1355
+ () => this.http.post("/oauth/token", payload, formRequestConfig())
1336
1356
  );
1337
1357
  const next = tokens?.refresh_token;
1338
1358
  if (payload.grant_type === "refresh_token" && (typeof next !== "string" || !next.trim() || next === payload.refresh_token)) {
@@ -1353,7 +1373,7 @@ var OAuthResource = class extends BaseResource {
1353
1373
  }
1354
1374
  await this.call(
1355
1375
  "OAuth revocation failed",
1356
- () => this.http.post("/oauth/revoke", payload, formRequestConfig)
1376
+ () => this.http.post("/oauth/revoke", payload, formRequestConfig())
1357
1377
  );
1358
1378
  }
1359
1379
  /** `GET /oauth/userinfo` — flat OIDC claims; requires a bearer token with `openid`. */
@@ -1751,12 +1771,18 @@ var SignerResource = class extends BaseResource {
1751
1771
  requireEmail(email);
1752
1772
  try {
1753
1773
  const lower = email.toLowerCase();
1754
- for (let page = 1; ; page++) {
1774
+ for (let page = 1; page <= MAX_SEARCH_PAGES; page++) {
1755
1775
  const { data, meta } = await this.list({ search: email, per_page: 100, page }, accountId);
1756
1776
  const match = data.find((s) => (s.email ?? "").toLowerCase() === lower);
1757
1777
  if (match) return match;
1758
- if (!data.length || !meta?.last_page || page >= meta.last_page) return null;
1778
+ if (!data.length) return null;
1779
+ if (meta?.last_page !== void 0) {
1780
+ if (page >= meta.last_page) return null;
1781
+ } else if (data.length < 100) {
1782
+ return null;
1783
+ }
1759
1784
  }
1785
+ throw new ValidationError("Signer email search exceeded the maximum page count");
1760
1786
  } catch (err) {
1761
1787
  if (err instanceof ApiError && err.statusCode === 404) {
1762
1788
  return null;
@@ -1765,6 +1791,7 @@ var SignerResource = class extends BaseResource {
1765
1791
  }
1766
1792
  }
1767
1793
  };
1794
+ var MAX_SEARCH_PAGES = 100;
1768
1795
  function normaliseSignerPayload(payload, useGovernmentId = false) {
1769
1796
  const normalised = {
1770
1797
  full_name: payload.full_name,
@@ -1779,7 +1806,7 @@ function normaliseSignerPayload(payload, useGovernmentId = false) {
1779
1806
  if ("metadata" in payload && payload.metadata !== void 0) {
1780
1807
  normalised.metadata = payload.metadata;
1781
1808
  }
1782
- return cleanParams(normalised);
1809
+ return stripEmpty(normalised);
1783
1810
  }
1784
1811
 
1785
1812
  // src/api/resources/tags.ts
@@ -1800,7 +1827,7 @@ var TagResource = class extends BaseResource {
1800
1827
  const id = this.accountId(accountId);
1801
1828
  return this.call(
1802
1829
  "Failed to create tag",
1803
- () => this.http.post(`/accounts/${id}/tags`, cleanParams({ ...payload }))
1830
+ () => this.http.post(`/accounts/${id}/tags`, stripEmpty({ ...payload }))
1804
1831
  );
1805
1832
  }
1806
1833
  /**
@@ -2073,9 +2100,8 @@ var WorkspaceResource = class extends BaseResource {
2073
2100
  throw new ValidationError("Logo buffer is required");
2074
2101
  }
2075
2102
  const contentType = options.contentType ?? "image/png";
2076
- const view = new Uint8Array(logo.buffer, logo.byteOffset, logo.byteLength);
2077
2103
  const form = new FormData();
2078
- form.append("file", new Blob([view], { type: contentType }), options.fileName ?? "logo.png");
2104
+ appendFilePart(form, logo, contentType, options.fileName ?? "logo.png");
2079
2105
  return this.call(
2080
2106
  "Failed to upload workspace logo",
2081
2107
  () => this.http.post(`/accounts/${id}/logo`, form, {
@@ -2412,6 +2438,8 @@ var AssinafyClient = class _AssinafyClient {
2412
2438
  WebhookVerifier,
2413
2439
  WorkspaceResource,
2414
2440
  buildAssignmentPayload,
2415
- normalizeBaseUrl
2441
+ normalizeBaseUrl,
2442
+ requireDocumentArtifactName,
2443
+ requireSignerImageType
2416
2444
  });
2417
2445
  //# sourceMappingURL=api.cjs.map