@assinafy/cli 2.3.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 +3 -2
- package/README.md +2 -2
- package/dist/api.cjs +66 -24
- package/dist/api.cjs.map +1 -1
- package/dist/api.js +63 -23
- package/dist/api.js.map +1 -1
- package/dist/cli.cjs +437 -383
- package/dist/types/api/index.d.ts +1 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/resources/assignments.d.ts.map +1 -1
- package/dist/types/api/resources/authentication.d.ts +1 -1
- package/dist/types/api/resources/authentication.d.ts.map +1 -1
- package/dist/types/api/resources/documents.d.ts.map +1 -1
- package/dist/types/api/resources/oauth.d.ts +4 -1
- package/dist/types/api/resources/oauth.d.ts.map +1 -1
- package/dist/types/api/resources/signers.d.ts.map +1 -1
- package/dist/types/api/resources/workspaces.d.ts.map +1 -1
- package/dist/types/api/types.d.ts +9 -3
- package/dist/types/api/types.d.ts.map +1 -1
- package/dist/types/api/utils.d.ts +4 -0
- package/dist/types/api/utils.d.ts.map +1 -1
- package/docs/api-operations.json +2 -2
- package/docs/api-reference.md +40 -18
- package/docs/assignments.md +10 -7
- package/docs/auth.md +1 -1
- package/docs/documents.md +5 -3
- package/docs/fields.md +2 -2
- package/docs/oauth-guide.md +23 -14
- package/docs/oauth.md +4 -4
- package/docs/sdk-reference.md +6 -6
- package/docs/users.md +2 -1
- package/docs/workspaces.md +6 -3
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -21206,6 +21206,19 @@ function cleanParams(params) {
|
|
|
21206
21206
|
}
|
|
21207
21207
|
return out;
|
|
21208
21208
|
}
|
|
21209
|
+
function stripEmpty(body) {
|
|
21210
|
+
const out = {};
|
|
21211
|
+
for (const [key, value] of Object.entries(body)) {
|
|
21212
|
+
if (value !== void 0 && value !== null) {
|
|
21213
|
+
out[key] = value;
|
|
21214
|
+
}
|
|
21215
|
+
}
|
|
21216
|
+
return out;
|
|
21217
|
+
}
|
|
21218
|
+
function appendFilePart(form, data, contentType, fileName) {
|
|
21219
|
+
const view = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
21220
|
+
form.append("file", new Blob([view], { type: contentType }), fileName);
|
|
21221
|
+
}
|
|
21209
21222
|
function publicRequestConfig(config = {}) {
|
|
21210
21223
|
return {
|
|
21211
21224
|
...config,
|
|
@@ -21446,7 +21459,7 @@ function buildAssignmentPayload(payload, options = {}) {
|
|
|
21446
21459
|
if (!options.skipDigitalCertificateStepValidation) {
|
|
21447
21460
|
validateSigningSteps(normalisedSigners);
|
|
21448
21461
|
}
|
|
21449
|
-
return
|
|
21462
|
+
return stripEmpty({
|
|
21450
21463
|
method: payload.method ?? "virtual",
|
|
21451
21464
|
signers: normalisedSigners,
|
|
21452
21465
|
message: payload.message,
|
|
@@ -21477,7 +21490,7 @@ function normaliseSignerRef(ref, options) {
|
|
|
21477
21490
|
const input = ref;
|
|
21478
21491
|
const id = input.id ?? input.signer_id;
|
|
21479
21492
|
validateSignerOptions(input);
|
|
21480
|
-
const normalised =
|
|
21493
|
+
const normalised = stripEmpty({
|
|
21481
21494
|
id,
|
|
21482
21495
|
verification_method: input.verification_method,
|
|
21483
21496
|
notification_methods: input.notification_methods,
|
|
@@ -21676,6 +21689,7 @@ var AuthenticationResource = class extends BaseResource {
|
|
|
21676
21689
|
var import_node_fs2 = require("fs");
|
|
21677
21690
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
21678
21691
|
var MAX_UPLOAD_BYTES = 25 * 1024 * 1024;
|
|
21692
|
+
var DOCUMENT_SORTS = ["name", "-name", "updated_at", "-updated_at"];
|
|
21679
21693
|
var READY_STATUSES = /* @__PURE__ */ new Set([
|
|
21680
21694
|
"metadata_ready",
|
|
21681
21695
|
"pending_signature",
|
|
@@ -21723,7 +21737,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
21723
21737
|
*/
|
|
21724
21738
|
async list(params = {}, accountId) {
|
|
21725
21739
|
const id = this.accountId(accountId);
|
|
21726
|
-
requireSort(params.sort,
|
|
21740
|
+
requireSort(params.sort, DOCUMENT_SORTS);
|
|
21727
21741
|
return this.callList(
|
|
21728
21742
|
"Failed to list documents",
|
|
21729
21743
|
() => this.http.get(`/accounts/${id}/documents`, {
|
|
@@ -21741,7 +21755,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
21741
21755
|
*/
|
|
21742
21756
|
async search(params = {}, accountId) {
|
|
21743
21757
|
const id = this.accountId(accountId);
|
|
21744
|
-
requireSort(params.sort,
|
|
21758
|
+
requireSort(params.sort, DOCUMENT_SORTS);
|
|
21745
21759
|
return this.callList(
|
|
21746
21760
|
"Failed to search documents",
|
|
21747
21761
|
() => this.http.get(`/accounts/${id}/documents/search`, {
|
|
@@ -22096,8 +22110,7 @@ function validateUpload(buffer, fileName) {
|
|
|
22096
22110
|
}
|
|
22097
22111
|
function buildUploadForm(buffer, fileName, name, metadata) {
|
|
22098
22112
|
const form = new FormData();
|
|
22099
|
-
|
|
22100
|
-
form.append("file", new Blob([view], { type: "application/pdf" }), fileName);
|
|
22113
|
+
appendFilePart(form, buffer, "application/pdf", fileName);
|
|
22101
22114
|
form.append("name", name);
|
|
22102
22115
|
if (metadata) {
|
|
22103
22116
|
form.append("metadata", JSON.stringify(metadata));
|
|
@@ -22212,18 +22225,26 @@ function validationConfig(signerAccessCode) {
|
|
|
22212
22225
|
|
|
22213
22226
|
// src/api/resources/oauth.ts
|
|
22214
22227
|
var import_node_crypto = require("crypto");
|
|
22228
|
+
function formRequestConfig() {
|
|
22229
|
+
return publicRequestConfig({
|
|
22230
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
|
22231
|
+
});
|
|
22232
|
+
}
|
|
22215
22233
|
var OAuthResource = class extends BaseResource {
|
|
22216
22234
|
/** `GET /.well-known/oauth-protected-resource` at the API origin, outside `/v1`. */
|
|
22217
22235
|
async metadata() {
|
|
22218
|
-
return this.call(
|
|
22219
|
-
|
|
22220
|
-
()
|
|
22236
|
+
return this.call("Failed to discover OAuth resource", () => {
|
|
22237
|
+
const baseURL = this.http.defaults.baseURL;
|
|
22238
|
+
if (!baseURL) {
|
|
22239
|
+
throw new ValidationError("A base URL is required to discover OAuth metadata");
|
|
22240
|
+
}
|
|
22241
|
+
return this.http.get(
|
|
22221
22242
|
"/.well-known/oauth-protected-resource",
|
|
22222
22243
|
publicRequestConfig({
|
|
22223
|
-
baseURL: new URL(
|
|
22244
|
+
baseURL: new URL(baseURL).origin
|
|
22224
22245
|
})
|
|
22225
|
-
)
|
|
22226
|
-
);
|
|
22246
|
+
);
|
|
22247
|
+
});
|
|
22227
22248
|
}
|
|
22228
22249
|
/** Read RFC 8414 metadata from an HTTPS issuer and verify its issuer identity. */
|
|
22229
22250
|
async discovery(issuer) {
|
|
@@ -22324,7 +22345,10 @@ var OAuthResource = class extends BaseResource {
|
|
|
22324
22345
|
resource: request.resource
|
|
22325
22346
|
});
|
|
22326
22347
|
}
|
|
22327
|
-
/**
|
|
22348
|
+
/**
|
|
22349
|
+
* `POST /oauth/token` — code exchange or refresh; returns the flat OAuth JSON body.
|
|
22350
|
+
* A refresh must return a new `refresh_token`; otherwise this throws `ValidationError`.
|
|
22351
|
+
*/
|
|
22328
22352
|
async token(payload) {
|
|
22329
22353
|
required(payload.client_id, "client_id");
|
|
22330
22354
|
if (payload.client_secret !== void 0) required(payload.client_secret, "client_secret");
|
|
@@ -22342,10 +22366,18 @@ var OAuthResource = class extends BaseResource {
|
|
|
22342
22366
|
} else {
|
|
22343
22367
|
throw new ValidationError("grant_type must be authorization_code or refresh_token");
|
|
22344
22368
|
}
|
|
22345
|
-
|
|
22369
|
+
const tokens = await this.call(
|
|
22346
22370
|
"OAuth token request failed",
|
|
22347
|
-
() => this.http.post("/oauth/token", payload,
|
|
22371
|
+
() => this.http.post("/oauth/token", payload, formRequestConfig())
|
|
22348
22372
|
);
|
|
22373
|
+
const next = tokens?.refresh_token;
|
|
22374
|
+
if (payload.grant_type === "refresh_token" && (typeof next !== "string" || !next.trim() || next === payload.refresh_token)) {
|
|
22375
|
+
throw new ValidationError(
|
|
22376
|
+
"OAuth refresh response has no new refresh_token; the submitted refresh token may already be retired, so do not reuse it: reconnect instead",
|
|
22377
|
+
{ field: "refresh_token" }
|
|
22378
|
+
);
|
|
22379
|
+
}
|
|
22380
|
+
return tokens;
|
|
22349
22381
|
}
|
|
22350
22382
|
/** `POST /oauth/revoke` — revoke an access/refresh token; success has no required body. */
|
|
22351
22383
|
async revoke(payload) {
|
|
@@ -22357,7 +22389,7 @@ var OAuthResource = class extends BaseResource {
|
|
|
22357
22389
|
}
|
|
22358
22390
|
await this.call(
|
|
22359
22391
|
"OAuth revocation failed",
|
|
22360
|
-
() => this.http.post("/oauth/revoke", payload,
|
|
22392
|
+
() => this.http.post("/oauth/revoke", payload, formRequestConfig())
|
|
22361
22393
|
);
|
|
22362
22394
|
}
|
|
22363
22395
|
/** `GET /oauth/userinfo` — flat OIDC claims; requires a bearer token with `openid`. */
|
|
@@ -22755,12 +22787,18 @@ var SignerResource = class extends BaseResource {
|
|
|
22755
22787
|
requireEmail(email);
|
|
22756
22788
|
try {
|
|
22757
22789
|
const lower = email.toLowerCase();
|
|
22758
|
-
for (let page = 1; ; page++) {
|
|
22790
|
+
for (let page = 1; page <= MAX_SEARCH_PAGES; page++) {
|
|
22759
22791
|
const { data, meta } = await this.list({ search: email, per_page: 100, page }, accountId);
|
|
22760
22792
|
const match = data.find((s) => (s.email ?? "").toLowerCase() === lower);
|
|
22761
22793
|
if (match) return match;
|
|
22762
|
-
if (!data.length
|
|
22794
|
+
if (!data.length) return null;
|
|
22795
|
+
if (meta?.last_page !== void 0) {
|
|
22796
|
+
if (page >= meta.last_page) return null;
|
|
22797
|
+
} else if (data.length < 100) {
|
|
22798
|
+
return null;
|
|
22799
|
+
}
|
|
22763
22800
|
}
|
|
22801
|
+
throw new ValidationError("Signer email search exceeded the maximum page count");
|
|
22764
22802
|
} catch (err) {
|
|
22765
22803
|
if (err instanceof ApiError && err.statusCode === 404) {
|
|
22766
22804
|
return null;
|
|
@@ -22769,6 +22807,7 @@ var SignerResource = class extends BaseResource {
|
|
|
22769
22807
|
}
|
|
22770
22808
|
}
|
|
22771
22809
|
};
|
|
22810
|
+
var MAX_SEARCH_PAGES = 100;
|
|
22772
22811
|
function normaliseSignerPayload(payload, useGovernmentId = false) {
|
|
22773
22812
|
const normalised = {
|
|
22774
22813
|
full_name: payload.full_name,
|
|
@@ -22783,7 +22822,7 @@ function normaliseSignerPayload(payload, useGovernmentId = false) {
|
|
|
22783
22822
|
if ("metadata" in payload && payload.metadata !== void 0) {
|
|
22784
22823
|
normalised.metadata = payload.metadata;
|
|
22785
22824
|
}
|
|
22786
|
-
return
|
|
22825
|
+
return stripEmpty(normalised);
|
|
22787
22826
|
}
|
|
22788
22827
|
|
|
22789
22828
|
// src/api/resources/tags.ts
|
|
@@ -22804,7 +22843,7 @@ var TagResource = class extends BaseResource {
|
|
|
22804
22843
|
const id = this.accountId(accountId);
|
|
22805
22844
|
return this.call(
|
|
22806
22845
|
"Failed to create tag",
|
|
22807
|
-
() => this.http.post(`/accounts/${id}/tags`,
|
|
22846
|
+
() => this.http.post(`/accounts/${id}/tags`, stripEmpty({ ...payload }))
|
|
22808
22847
|
);
|
|
22809
22848
|
}
|
|
22810
22849
|
/**
|
|
@@ -23077,9 +23116,8 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
23077
23116
|
throw new ValidationError("Logo buffer is required");
|
|
23078
23117
|
}
|
|
23079
23118
|
const contentType = options.contentType ?? "image/png";
|
|
23080
|
-
const view = new Uint8Array(logo.buffer, logo.byteOffset, logo.byteLength);
|
|
23081
23119
|
const form = new FormData();
|
|
23082
|
-
form
|
|
23120
|
+
appendFilePart(form, logo, contentType, options.fileName ?? "logo.png");
|
|
23083
23121
|
return this.call(
|
|
23084
23122
|
"Failed to upload workspace logo",
|
|
23085
23123
|
() => this.http.post(`/accounts/${id}/logo`, form, {
|
|
@@ -23543,6 +23581,21 @@ function addSortableListOptions(command, description) {
|
|
|
23543
23581
|
function addListOptions(command, sortDescription = "Sort by field") {
|
|
23544
23582
|
return addSearchListOptions(command).option("--sort <field>", sortDescription);
|
|
23545
23583
|
}
|
|
23584
|
+
function addDownloadOptions(command) {
|
|
23585
|
+
return command.option("-o, --output <path>", "Output file path").option("--force", "Overwrite the output file if it already exists");
|
|
23586
|
+
}
|
|
23587
|
+
function addSignerRefOptions(command) {
|
|
23588
|
+
return command.addOption(
|
|
23589
|
+
new Option("--signer-ids <csv>", "Comma-separated signer IDs (required)").conflicts(
|
|
23590
|
+
"signers"
|
|
23591
|
+
)
|
|
23592
|
+
).addOption(
|
|
23593
|
+
new Option(
|
|
23594
|
+
"--signers <json>",
|
|
23595
|
+
"JSON array of signer refs, with verification_method, step, \u2026 (required)"
|
|
23596
|
+
).conflicts("signerIds")
|
|
23597
|
+
);
|
|
23598
|
+
}
|
|
23546
23599
|
|
|
23547
23600
|
// src/lib/output.ts
|
|
23548
23601
|
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
@@ -23610,6 +23663,13 @@ function printError(err, config) {
|
|
|
23610
23663
|
if (normalized.statusCode) {
|
|
23611
23664
|
writeErr(import_picocolors.default.dim(` (HTTP ${normalized.statusCode})`));
|
|
23612
23665
|
}
|
|
23666
|
+
const challenge = normalized.wwwAuthenticate ?? "";
|
|
23667
|
+
const scope = challenge.includes("insufficient_scope") && /\bscope="([^"]+)"/.exec(challenge)?.[1];
|
|
23668
|
+
if (scope) {
|
|
23669
|
+
writeErr(
|
|
23670
|
+
import_picocolors.default.dim(` (missing OAuth scope: ${sanitizeTerminalText(scope)}; reconnect granting it)`)
|
|
23671
|
+
);
|
|
23672
|
+
}
|
|
23613
23673
|
}
|
|
23614
23674
|
process.exitCode = normalized.exitCode ?? 1;
|
|
23615
23675
|
}
|
|
@@ -23641,6 +23701,11 @@ function paginationFooter(result) {
|
|
|
23641
23701
|
}
|
|
23642
23702
|
return parts.length > 0 ? import_picocolors2.default.dim(parts.join(" \xB7 ")) : "";
|
|
23643
23703
|
}
|
|
23704
|
+
function tableWithFooter(table, result) {
|
|
23705
|
+
const footer = paginationFooter(result);
|
|
23706
|
+
return footer ? `${table}
|
|
23707
|
+
${footer}` : table;
|
|
23708
|
+
}
|
|
23644
23709
|
|
|
23645
23710
|
// src/lib/config.ts
|
|
23646
23711
|
var import_node_crypto3 = require("crypto");
|
|
@@ -24766,7 +24831,7 @@ async function withSpinner(message, config, task) {
|
|
|
24766
24831
|
if (!useSpinner) {
|
|
24767
24832
|
return task();
|
|
24768
24833
|
}
|
|
24769
|
-
const s = spinner();
|
|
24834
|
+
const s = spinner({ output: process.stderr });
|
|
24770
24835
|
s.start(message);
|
|
24771
24836
|
try {
|
|
24772
24837
|
const result = await task();
|
|
@@ -24843,7 +24908,7 @@ function displayWidth(text2) {
|
|
|
24843
24908
|
}
|
|
24844
24909
|
|
|
24845
24910
|
// src/commands/assignments.ts
|
|
24846
|
-
function
|
|
24911
|
+
function resolveAssignmentSignerRefs(signersJson, signerIdsCsv, required2 = true) {
|
|
24847
24912
|
if (signersJson) {
|
|
24848
24913
|
return parseJsonArray(signersJson, "--signers");
|
|
24849
24914
|
}
|
|
@@ -24873,25 +24938,22 @@ var listCommand = addSortableListOptions(
|
|
|
24873
24938
|
{ header: "SIGNERS", value: (r2) => r2.signers?.length },
|
|
24874
24939
|
{ header: "EXPIRES", value: (r2) => r2.expires_at }
|
|
24875
24940
|
]);
|
|
24876
|
-
|
|
24877
|
-
return footer ? `${table}
|
|
24878
|
-
${footer}` : table;
|
|
24941
|
+
return tableWithFooter(table, result);
|
|
24879
24942
|
});
|
|
24880
24943
|
});
|
|
24881
24944
|
});
|
|
24882
|
-
var createCommand =
|
|
24883
|
-
new
|
|
24884
|
-
|
|
24885
|
-
|
|
24886
|
-
|
|
24887
|
-
).option("--method <method>", "virtual or collect", "virtual").option("--message <message>", "Message shown to signers").option("--expires-at <iso8601>", "Expiration timestamp").option("--copy-receivers <csv>", "Comma-separated signer IDs to receive a copy of the document").option(
|
|
24945
|
+
var createCommand = addSignerRefOptions(
|
|
24946
|
+
new Command("create").description("Create a signing assignment for a document").argument("<documentId>", "Document ID")
|
|
24947
|
+
).addOption(
|
|
24948
|
+
new Option("--method <method>", "virtual or collect").choices(["virtual", "collect"]).default("virtual")
|
|
24949
|
+
).option("--message <message>", "Message shown to signers").option("--expires-at <iso8601>", "Expiration timestamp").option("--copy-receivers <csv>", "Comma-separated signer IDs to receive a copy of the document").option(
|
|
24888
24950
|
"--entries <json>",
|
|
24889
24951
|
`JSON array of field placement entries, required for --method collect (e.g. '[{"page_id":"p1","fields":[{"signer_id":"s1","field_id":"f1"}]}]')`
|
|
24890
24952
|
).action(async (documentId, opts, command) => {
|
|
24891
24953
|
await runWithClient(command, async ({ client, config }) => {
|
|
24892
24954
|
const payload = {
|
|
24893
24955
|
method: opts.method,
|
|
24894
|
-
signers:
|
|
24956
|
+
signers: resolveAssignmentSignerRefs(opts.signers, opts.signerIds)
|
|
24895
24957
|
};
|
|
24896
24958
|
if (opts.message) payload.message = opts.message;
|
|
24897
24959
|
if (opts.expiresAt) payload.expires_at = opts.expiresAt;
|
|
@@ -24918,7 +24980,11 @@ var createCommand = new Command("create").description("Create a signing assignme
|
|
|
24918
24980
|
);
|
|
24919
24981
|
});
|
|
24920
24982
|
});
|
|
24921
|
-
var estimateCostCommand =
|
|
24983
|
+
var estimateCostCommand = addSignerRefOptions(
|
|
24984
|
+
new Command("estimate-cost").description("Estimate the credit cost of an assignment").argument("<documentId>", "Document ID")
|
|
24985
|
+
).addOption(
|
|
24986
|
+
new Option("--method <method>", "virtual or collect").choices(["virtual", "collect"]).default("virtual")
|
|
24987
|
+
).option(
|
|
24922
24988
|
"--entries <json>",
|
|
24923
24989
|
"JSON array of field placement entries, required for --method collect"
|
|
24924
24990
|
).action(async (documentId, opts, command) => {
|
|
@@ -24926,7 +24992,7 @@ var estimateCostCommand = new Command("estimate-cost").description("Estimate the
|
|
|
24926
24992
|
const method = opts.method;
|
|
24927
24993
|
const payload = {
|
|
24928
24994
|
method,
|
|
24929
|
-
signers:
|
|
24995
|
+
signers: resolveAssignmentSignerRefs(opts.signers, opts.signerIds, true)
|
|
24930
24996
|
};
|
|
24931
24997
|
if (opts.entries) {
|
|
24932
24998
|
payload.entries = parseJsonArray(opts.entries, "--entries");
|
|
@@ -25002,11 +25068,11 @@ var assignmentsCommand = new Command("assignments").description("Create and mana
|
|
|
25002
25068
|
|
|
25003
25069
|
// src/lib/prompts.ts
|
|
25004
25070
|
async function promptText(message, placeholder) {
|
|
25005
|
-
const value = await text({ message, placeholder });
|
|
25071
|
+
const value = await text({ message, placeholder, output: process.stderr });
|
|
25006
25072
|
return unwrap(value);
|
|
25007
25073
|
}
|
|
25008
25074
|
async function promptSecret(message) {
|
|
25009
|
-
const value = await password({ message });
|
|
25075
|
+
const value = await password({ message, output: process.stderr });
|
|
25010
25076
|
return unwrap(value);
|
|
25011
25077
|
}
|
|
25012
25078
|
async function confirmDestructive(message, force) {
|
|
@@ -25014,13 +25080,13 @@ async function confirmDestructive(message, force) {
|
|
|
25014
25080
|
if (!process.stdin.isTTY) {
|
|
25015
25081
|
throw new CliError("Refusing to proceed without confirmation. Re-run with --yes to confirm.");
|
|
25016
25082
|
}
|
|
25017
|
-
const value = await confirm({ message });
|
|
25083
|
+
const value = await confirm({ message, output: process.stderr });
|
|
25018
25084
|
return unwrap(value);
|
|
25019
25085
|
}
|
|
25020
25086
|
function unwrap(value) {
|
|
25021
25087
|
if (isCancel3(value)) {
|
|
25022
|
-
cancel("Cancelled.");
|
|
25023
|
-
|
|
25088
|
+
cancel("Cancelled.", { output: process.stderr });
|
|
25089
|
+
throw new CliError("Cancelled.", { exitCode: 130 });
|
|
25024
25090
|
}
|
|
25025
25091
|
return value;
|
|
25026
25092
|
}
|
|
@@ -25053,7 +25119,9 @@ var loginCommand = new Command("login").description(
|
|
|
25053
25119
|
);
|
|
25054
25120
|
});
|
|
25055
25121
|
});
|
|
25056
|
-
var socialLoginCommand = new Command("social-login").description("Exchange a provider token for an Assinafy JWT (no existing credentials required)").
|
|
25122
|
+
var socialLoginCommand = new Command("social-login").description("Exchange a provider token for an Assinafy JWT (no existing credentials required)").addOption(
|
|
25123
|
+
new Option("--provider <provider>", "OAuth provider").choices(["google"]).makeOptionMandatory()
|
|
25124
|
+
).addOption(
|
|
25057
25125
|
new Option("--provider-token <token>", "Provider token").env("ASSINAFY_PROVIDER_TOKEN").makeOptionMandatory()
|
|
25058
25126
|
).option("--accept-terms", "Accept the platform terms").action(async (opts, command) => {
|
|
25059
25127
|
await runWithPublicClient(command, async ({ client, config }) => {
|
|
@@ -25302,24 +25370,181 @@ var pathCommand = new Command("path").description("Print the config file path").
|
|
|
25302
25370
|
});
|
|
25303
25371
|
var configCommand = new Command("config").description("Manage credentials, profiles, and settings").addCommand(setCommand).addCommand(getCommand).addCommand(listCommand2).addCommand(useCommand).addCommand(removeCommand).addCommand(pathCommand);
|
|
25304
25372
|
|
|
25305
|
-
// src/
|
|
25373
|
+
// src/lib/oauth-browser.ts
|
|
25306
25374
|
var import_node_child_process2 = require("child_process");
|
|
25375
|
+
var import_node_crypto4 = require("crypto");
|
|
25376
|
+
var import_node_events2 = require("events");
|
|
25377
|
+
var import_node_http = require("http");
|
|
25378
|
+
var CLI_OAUTH_REDIRECT_URI = "https://integrations.assinafy.com.br/assinafy-cli/oauth-callback";
|
|
25379
|
+
var clearHistory = "history.replaceState(null, '', '/');";
|
|
25380
|
+
var brandOrigin = "https://integrations.assinafy.com.br";
|
|
25381
|
+
var callbackCopy = {
|
|
25382
|
+
received: {
|
|
25383
|
+
heading: "Volte ao terminal.",
|
|
25384
|
+
status: "A resposta de autoriza\xE7\xE3o foi recebida. Confira no terminal se a conex\xE3o foi conclu\xEDda."
|
|
25385
|
+
},
|
|
25386
|
+
denied: {
|
|
25387
|
+
heading: "Conex\xE3o n\xE3o autorizada.",
|
|
25388
|
+
status: "A autoriza\xE7\xE3o n\xE3o foi conclu\xEDda. Confira o erro no terminal e inicie uma nova conex\xE3o."
|
|
25389
|
+
},
|
|
25390
|
+
invalid: {
|
|
25391
|
+
heading: "Retorno inv\xE1lido.",
|
|
25392
|
+
status: "Continue na janela original de autoriza\xE7\xE3o. Se ela expirou, inicie uma nova conex\xE3o no terminal."
|
|
25393
|
+
}
|
|
25394
|
+
};
|
|
25395
|
+
function callbackPage(status) {
|
|
25396
|
+
const copy = callbackCopy[status];
|
|
25397
|
+
return `<!doctype html>
|
|
25398
|
+
<html lang="pt-BR">
|
|
25399
|
+
<head>
|
|
25400
|
+
<meta charset="utf-8">
|
|
25401
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
25402
|
+
<meta name="referrer" content="no-referrer">
|
|
25403
|
+
<meta name="robots" content="noindex, nofollow, noarchive">
|
|
25404
|
+
<title>${copy.heading} | Assinafy CLI</title>
|
|
25405
|
+
<script>${clearHistory}</script>
|
|
25406
|
+
<link rel="icon" href="${brandOrigin}/brand/assinafy-icon.png">
|
|
25407
|
+
<link rel="stylesheet" href="${brandOrigin}/brand/colors.css">
|
|
25408
|
+
<link rel="stylesheet" href="${brandOrigin}/brand/site.css">
|
|
25409
|
+
<link rel="stylesheet" href="${brandOrigin}/oauth-callback.css">
|
|
25410
|
+
</head>
|
|
25411
|
+
<body>
|
|
25412
|
+
<a class="skip-link" href="#conteudo">Pular para o conte\xFAdo</a>
|
|
25413
|
+
<header class="site-header wrap">
|
|
25414
|
+
<a class="brand" href="${brandOrigin}" aria-label="Assinafy Integra\xE7\xF5es, in\xEDcio">
|
|
25415
|
+
<img src="${brandOrigin}/brand/assinafy-logotype.svg" width="148" height="32" alt="Assinafy">
|
|
25416
|
+
<span class="brand-section">integra\xE7\xF5es</span>
|
|
25417
|
+
</a>
|
|
25418
|
+
</header>
|
|
25419
|
+
<main id="conteudo" class="hero wrap">
|
|
25420
|
+
<div>
|
|
25421
|
+
<p class="eyebrow"><img src="${brandOrigin}/assinafy-cli/cli-icon.svg" width="24" height="24" alt="">Conex\xE3o com a Assinafy CLI</p>
|
|
25422
|
+
<h1>${copy.heading}</h1>
|
|
25423
|
+
<p class="hero-description" role="status">${copy.status}</p>
|
|
25424
|
+
<a class="button button-primary" href="${brandOrigin}/assinafy-cli">Ajuda para conectar<svg width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 12h16m-7-7 7 7-7 7"/></svg></a>
|
|
25425
|
+
</div>
|
|
25426
|
+
<figure class="connection-art">
|
|
25427
|
+
<div class="connection-map" role="img" aria-label="Retorno de autoriza\xE7\xE3o: Assinafy para Assinafy CLI.">
|
|
25428
|
+
<svg class="connection-lines" viewBox="0 0 480 240" preserveAspectRatio="none" fill="none" aria-hidden="true">
|
|
25429
|
+
<path class="connection-route" d="M120 106H240"/>
|
|
25430
|
+
<path class="connection-complete" d="M240 106H374m-64-5 5 5-5 5"/>
|
|
25431
|
+
</svg>
|
|
25432
|
+
<div class="connection-node connection-assinafy" aria-hidden="true">
|
|
25433
|
+
<span class="connection-tile"><img src="${brandOrigin}/brand/assinafy-icon.png" width="60" height="60" alt=""></span>
|
|
25434
|
+
<span class="connection-label">Assinafy</span>
|
|
25435
|
+
</div>
|
|
25436
|
+
<div class="connection-node connection-application" aria-hidden="true">
|
|
25437
|
+
<span class="connection-tile"><img src="${brandOrigin}/assinafy-cli/cli-icon.svg" width="36" height="36" alt=""></span>
|
|
25438
|
+
<span class="connection-label">Assinafy CLI</span>
|
|
25439
|
+
</div>
|
|
25440
|
+
</div>
|
|
25441
|
+
<figcaption class="connection-caption">Continue no terminal que iniciou a conex\xE3o.</figcaption>
|
|
25442
|
+
</figure>
|
|
25443
|
+
</main>
|
|
25444
|
+
<footer class="site-footer wrap"><span>Assinafy. Assinaturas que conectam.</span></footer>
|
|
25445
|
+
</body>
|
|
25446
|
+
</html>`;
|
|
25447
|
+
}
|
|
25448
|
+
var callbackHeaders = {
|
|
25449
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
25450
|
+
"Cache-Control": "no-store",
|
|
25451
|
+
"Referrer-Policy": "no-referrer",
|
|
25452
|
+
"X-Content-Type-Options": "nosniff",
|
|
25453
|
+
"X-Robots-Tag": "noindex, nofollow, noarchive",
|
|
25454
|
+
"Content-Security-Policy": `default-src 'none'; script-src 'sha256-${(0, import_node_crypto4.createHash)("sha256").update(clearHistory).digest("base64")}'; style-src ${brandOrigin}; img-src ${brandOrigin}; font-src ${brandOrigin}; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`,
|
|
25455
|
+
Connection: "close"
|
|
25456
|
+
};
|
|
25457
|
+
function openBrowser(url2) {
|
|
25458
|
+
const [executable, args] = process.platform === "darwin" ? ["open", [url2]] : process.platform === "win32" ? ["rundll32.exe", ["url.dll,FileProtocolHandler", url2]] : ["xdg-open", [url2]];
|
|
25459
|
+
return new Promise((resolve, reject) => {
|
|
25460
|
+
const child = (0, import_node_child_process2.spawn)(executable, args, {
|
|
25461
|
+
stdio: "ignore",
|
|
25462
|
+
detached: true,
|
|
25463
|
+
windowsHide: true
|
|
25464
|
+
});
|
|
25465
|
+
child.once("error", () => reject(new CliError("Could not open the system browser.")));
|
|
25466
|
+
child.once("spawn", () => {
|
|
25467
|
+
child.unref();
|
|
25468
|
+
resolve();
|
|
25469
|
+
});
|
|
25470
|
+
});
|
|
25471
|
+
}
|
|
25472
|
+
async function connectOAuth(oauth, options, onAuthorize, timeoutMs = 18e4) {
|
|
25473
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 6e5) {
|
|
25474
|
+
throw new CliError("OAuth connection timeout must be between 1 and 600000 milliseconds.");
|
|
25475
|
+
}
|
|
25476
|
+
const request = await oauth.authorize(options);
|
|
25477
|
+
if (new URL(request.redirect_uri).search) {
|
|
25478
|
+
throw new CliError("The browser relay redirect URI must not contain query parameters.");
|
|
25479
|
+
}
|
|
25480
|
+
const server = (0, import_node_http.createServer)({ maxHeaderSize: 8192, requestTimeout: 5e3, headersTimeout: 5e3 });
|
|
25481
|
+
server.maxConnections = 8;
|
|
25482
|
+
server.setTimeout(5e3, (socket) => socket.destroy());
|
|
25483
|
+
let timer;
|
|
25484
|
+
let callbackUrl;
|
|
25485
|
+
try {
|
|
25486
|
+
server.listen(0, "127.0.0.1");
|
|
25487
|
+
await (0, import_node_events2.once)(server, "listening");
|
|
25488
|
+
const address = server.address();
|
|
25489
|
+
if (!address || typeof address === "string") throw new CliError("No OAuth listener address.");
|
|
25490
|
+
const host = `127.0.0.1:${address.port}`;
|
|
25491
|
+
request.state += `.${address.port}`;
|
|
25492
|
+
const expectedState = Buffer.from(request.state);
|
|
25493
|
+
const authorization = new URL(request.authorization_url);
|
|
25494
|
+
authorization.searchParams.set("state", request.state);
|
|
25495
|
+
request.authorization_url = authorization.toString();
|
|
25496
|
+
callbackUrl = await new Promise((resolve, reject) => {
|
|
25497
|
+
let consumed = false;
|
|
25498
|
+
timer = setTimeout(
|
|
25499
|
+
() => reject(new CliError("OAuth connection timed out. Start again.")),
|
|
25500
|
+
timeoutMs
|
|
25501
|
+
);
|
|
25502
|
+
server.once("error", reject);
|
|
25503
|
+
server.on("request", (incoming, response) => {
|
|
25504
|
+
const raw = incoming.url ?? "";
|
|
25505
|
+
const url2 = new URL(raw.startsWith("/callback?") ? raw : "/invalid", `http://${host}`);
|
|
25506
|
+
const query = url2.searchParams;
|
|
25507
|
+
const state = Buffer.from(query.get("state") ?? "");
|
|
25508
|
+
const valid = !consumed && incoming.method === "GET" && incoming.headers.host === host && raw.startsWith("/callback?") && raw.length <= 8192 && url2.origin === `http://${host}` && url2.pathname === "/callback" && !url2.hash && [...query.keys()].every((key) => query.getAll(key).length === 1) && state.length === expectedState.length && (0, import_node_crypto4.timingSafeEqual)(state, expectedState) && query.get("iss") === request.issuer && query.has("code") !== query.has("error") && Boolean((query.get("code") ?? query.get("error"))?.trim());
|
|
25509
|
+
if (!valid) {
|
|
25510
|
+
response.writeHead(400, callbackHeaders);
|
|
25511
|
+
response.end(callbackPage("invalid"));
|
|
25512
|
+
return;
|
|
25513
|
+
}
|
|
25514
|
+
consumed = true;
|
|
25515
|
+
const callback = new URL(request.redirect_uri);
|
|
25516
|
+
for (const key of ["code", "state", "iss", "error"]) {
|
|
25517
|
+
if (query.has(key)) callback.searchParams.set(key, query.get(key));
|
|
25518
|
+
}
|
|
25519
|
+
response.writeHead(200, callbackHeaders);
|
|
25520
|
+
response.end(
|
|
25521
|
+
callbackPage(query.has("error") ? "denied" : "received"),
|
|
25522
|
+
() => resolve(callback.toString())
|
|
25523
|
+
);
|
|
25524
|
+
});
|
|
25525
|
+
void Promise.resolve().then(() => onAuthorize(request.authorization_url)).catch(reject);
|
|
25526
|
+
});
|
|
25527
|
+
} finally {
|
|
25528
|
+
clearTimeout(timer);
|
|
25529
|
+
await new Promise((resolve) => {
|
|
25530
|
+
server.close(() => resolve());
|
|
25531
|
+
server.closeAllConnections();
|
|
25532
|
+
});
|
|
25533
|
+
}
|
|
25534
|
+
return oauth.exchangeCode(callbackUrl, request);
|
|
25535
|
+
}
|
|
25536
|
+
|
|
25537
|
+
// src/commands/docs.ts
|
|
25307
25538
|
var DOCS_URL = "https://api.assinafy.com.br/v1/docs";
|
|
25308
25539
|
var docsCommand = new Command("docs").description("Print (or open) the Assinafy API documentation URL").option("--open", "Open the documentation in your default browser").action(async (opts, command) => {
|
|
25309
25540
|
await runAction(command, async ({ config }) => {
|
|
25310
25541
|
if (opts.open) {
|
|
25311
|
-
|
|
25312
|
-
|
|
25313
|
-
|
|
25314
|
-
|
|
25315
|
-
|
|
25316
|
-
}
|
|
25317
|
-
child.on(
|
|
25318
|
-
"error",
|
|
25319
|
-
() => printWarning(`Could not open a browser. Visit ${DOCS_URL}`, config)
|
|
25320
|
-
);
|
|
25321
|
-
child.unref();
|
|
25322
|
-
printInfo(`Opening ${DOCS_URL}`, config);
|
|
25542
|
+
try {
|
|
25543
|
+
await openBrowser(DOCS_URL);
|
|
25544
|
+
printInfo(`Opening ${DOCS_URL}`, config);
|
|
25545
|
+
} catch {
|
|
25546
|
+
printWarning(`Could not open a browser. Visit ${DOCS_URL}`, config);
|
|
25547
|
+
}
|
|
25323
25548
|
}
|
|
25324
25549
|
printData({ docs: DOCS_URL }, config, (data) => data.docs);
|
|
25325
25550
|
});
|
|
@@ -25355,6 +25580,16 @@ function defaultArtifactFilename(documentId, artifact) {
|
|
|
25355
25580
|
const ext = artifact === "thumbnail" ? "jpg" : artifact === "bundle" ? "zip" : "pdf";
|
|
25356
25581
|
return `${documentId}-${artifact}.${ext}`;
|
|
25357
25582
|
}
|
|
25583
|
+
async function saveDownload(config, options) {
|
|
25584
|
+
const buffer = await withSpinner(options.message, config, options.download);
|
|
25585
|
+
const out = writeBinary(options.output ?? options.defaultName, buffer, { force: options.force });
|
|
25586
|
+
printSuccess(`Saved ${buffer.byteLength} bytes to ${out}`, config);
|
|
25587
|
+
printData(
|
|
25588
|
+
{ path: out, bytes: buffer.byteLength, ...options.data },
|
|
25589
|
+
config,
|
|
25590
|
+
(d) => sanitizeTerminalText(d.path)
|
|
25591
|
+
);
|
|
25592
|
+
}
|
|
25358
25593
|
|
|
25359
25594
|
// src/commands/documents.ts
|
|
25360
25595
|
var uploadCommand = new Command("upload").description("Upload a PDF to the workspace").argument("<file>", "Path to the PDF file").option("--name <name>", "Override the document name (defaults to the file name)").option("--metadata <json>", "JSON object of metadata to attach").option("--wait", "Wait until the document finishes processing").action(async (file, opts, command) => {
|
|
@@ -25400,12 +25635,15 @@ function renderDocumentListTable(result) {
|
|
|
25400
25635
|
{ header: "STATUS", value: (r2) => r2.status },
|
|
25401
25636
|
{ header: "CREATED", value: (r2) => r2.created_at }
|
|
25402
25637
|
]);
|
|
25403
|
-
|
|
25404
|
-
return footer ? `${table}
|
|
25405
|
-
${footer}` : table;
|
|
25638
|
+
return tableWithFooter(table, result);
|
|
25406
25639
|
}
|
|
25407
25640
|
var listCommand3 = addListOptions(
|
|
25408
|
-
new Command("list").description("List workspace documents").option("--status <status>", "Filter by document status").
|
|
25641
|
+
new Command("list").description("List workspace documents").option("--status <status>", "Filter by document status").addOption(
|
|
25642
|
+
new Option("--method <method>", "Filter by signature method (virtual or collect)").choices([
|
|
25643
|
+
"virtual",
|
|
25644
|
+
"collect"
|
|
25645
|
+
])
|
|
25646
|
+
).option("--tags <ids>", "Comma-separated tag IDs (AND semantics)")
|
|
25409
25647
|
).action(async (opts, command) => {
|
|
25410
25648
|
await runWithClient(command, async ({ client, config }) => {
|
|
25411
25649
|
const accountId = requireAccountId(config);
|
|
@@ -25470,63 +25708,49 @@ var renameCommand = new Command("rename").description("Rename a document (only b
|
|
|
25470
25708
|
printData(doc, config, (d) => renderKeyValue({ id: d.id, name: d.name, status: d.status }));
|
|
25471
25709
|
});
|
|
25472
25710
|
});
|
|
25473
|
-
var downloadCommand =
|
|
25474
|
-
"
|
|
25475
|
-
|
|
25476
|
-
|
|
25477
|
-
|
|
25711
|
+
var downloadCommand = addDownloadOptions(
|
|
25712
|
+
new Command("download").description("Download a document artifact").argument("<id>", "Document ID").option(
|
|
25713
|
+
"--artifact <name>",
|
|
25714
|
+
"original | certificated | certificate-page | pades | bundle",
|
|
25715
|
+
"certificated"
|
|
25716
|
+
)
|
|
25717
|
+
).action(async (id, opts, command) => {
|
|
25478
25718
|
await runWithClient(command, async ({ client, config }) => {
|
|
25479
25719
|
const artifact = requireDocumentArtifactName(opts.artifact);
|
|
25480
|
-
|
|
25481
|
-
"Downloading document",
|
|
25482
|
-
|
|
25483
|
-
|
|
25484
|
-
|
|
25485
|
-
|
|
25486
|
-
|
|
25720
|
+
await saveDownload(config, {
|
|
25721
|
+
message: "Downloading document",
|
|
25722
|
+
download: () => client.documents.download(id, artifact),
|
|
25723
|
+
output: opts.output,
|
|
25724
|
+
defaultName: defaultArtifactFilename(id, artifact),
|
|
25725
|
+
force: opts.force,
|
|
25726
|
+
data: { artifact }
|
|
25487
25727
|
});
|
|
25488
|
-
printSuccess(`Saved ${buffer.byteLength} bytes to ${out}`, config);
|
|
25489
|
-
printData(
|
|
25490
|
-
{ path: out, bytes: buffer.byteLength, artifact },
|
|
25491
|
-
config,
|
|
25492
|
-
(d) => sanitizeTerminalText(d.path)
|
|
25493
|
-
);
|
|
25494
25728
|
});
|
|
25495
25729
|
});
|
|
25496
|
-
var thumbnailCommand =
|
|
25730
|
+
var thumbnailCommand = addDownloadOptions(
|
|
25731
|
+
new Command("thumbnail").description("Download the document thumbnail (JPEG)").argument("<id>", "Document ID")
|
|
25732
|
+
).action(async (id, opts, command) => {
|
|
25497
25733
|
await runWithClient(command, async ({ client, config }) => {
|
|
25498
|
-
|
|
25499
|
-
"Downloading thumbnail",
|
|
25500
|
-
|
|
25501
|
-
|
|
25502
|
-
|
|
25503
|
-
const out = writeBinary(opts.output ?? defaultArtifactFilename(id, "thumbnail"), buffer, {
|
|
25734
|
+
await saveDownload(config, {
|
|
25735
|
+
message: "Downloading thumbnail",
|
|
25736
|
+
download: () => client.documents.thumbnail(id),
|
|
25737
|
+
output: opts.output,
|
|
25738
|
+
defaultName: defaultArtifactFilename(id, "thumbnail"),
|
|
25504
25739
|
force: opts.force
|
|
25505
25740
|
});
|
|
25506
|
-
printSuccess(`Saved ${buffer.byteLength} bytes to ${out}`, config);
|
|
25507
|
-
printData(
|
|
25508
|
-
{ path: out, bytes: buffer.byteLength },
|
|
25509
|
-
config,
|
|
25510
|
-
(d) => sanitizeTerminalText(d.path)
|
|
25511
|
-
);
|
|
25512
25741
|
});
|
|
25513
25742
|
});
|
|
25514
|
-
var downloadPageCommand =
|
|
25743
|
+
var downloadPageCommand = addDownloadOptions(
|
|
25744
|
+
new Command("download-page").description("Download a single document page (JPEG)").argument("<id>", "Document ID").argument("<pageId>", "Page ID")
|
|
25745
|
+
).action(async (id, pageId, opts, command) => {
|
|
25515
25746
|
await runWithClient(command, async ({ client, config }) => {
|
|
25516
|
-
|
|
25517
|
-
"Downloading page",
|
|
25518
|
-
|
|
25519
|
-
|
|
25520
|
-
|
|
25521
|
-
const out = writeBinary(opts.output ?? `${id}-page-${pageId}.jpg`, buffer, {
|
|
25747
|
+
await saveDownload(config, {
|
|
25748
|
+
message: "Downloading page",
|
|
25749
|
+
download: () => client.documents.downloadPage(id, pageId),
|
|
25750
|
+
output: opts.output,
|
|
25751
|
+
defaultName: `${id}-page-${pageId}.jpg`,
|
|
25522
25752
|
force: opts.force
|
|
25523
25753
|
});
|
|
25524
|
-
printSuccess(`Saved ${buffer.byteLength} bytes to ${out}`, config);
|
|
25525
|
-
printData(
|
|
25526
|
-
{ path: out, bytes: buffer.byteLength },
|
|
25527
|
-
config,
|
|
25528
|
-
(d) => sanitizeTerminalText(d.path)
|
|
25529
|
-
);
|
|
25530
25754
|
});
|
|
25531
25755
|
});
|
|
25532
25756
|
var activitiesCommand = new Command("activities").description("Show the activity log for a document").argument("<id>", "Document ID").action(async (id, _opts, command) => {
|
|
@@ -25685,14 +25909,14 @@ var publicCommand = new Command("public").description("Public (unauthenticated)
|
|
|
25685
25909
|
});
|
|
25686
25910
|
});
|
|
25687
25911
|
var sendTokenCommand = new Command("send-token").description("Send a 6-digit verification token to a signer").argument("<id>", "Document ID").addOption(
|
|
25688
|
-
new Option(
|
|
25689
|
-
"
|
|
25690
|
-
"
|
|
25691
|
-
])
|
|
25912
|
+
new Option(
|
|
25913
|
+
"--email <email>",
|
|
25914
|
+
"Email address (compatibility overload for older deployments)"
|
|
25915
|
+
).conflicts(["recipient", "channel"])
|
|
25692
25916
|
).addOption(
|
|
25693
25917
|
new Option(
|
|
25694
25918
|
"--recipient <value>",
|
|
25695
|
-
"Email address or phone number (
|
|
25919
|
+
"Email address or phone number (production payload)"
|
|
25696
25920
|
).conflicts("email")
|
|
25697
25921
|
).addOption(
|
|
25698
25922
|
new Option("--channel <channel>", "email or whatsapp").default("email").conflicts("email")
|
|
@@ -25765,6 +25989,9 @@ var fieldColumns = [
|
|
|
25765
25989
|
{ header: "REQUIRED", value: (r2) => r2.is_required },
|
|
25766
25990
|
{ header: "ACTIVE", value: (r2) => r2.is_active }
|
|
25767
25991
|
];
|
|
25992
|
+
var signerAccessCodeOption = () => new Option("--signer-access-code <code>", "Signer access code (for signer-side validation)").env(
|
|
25993
|
+
"ASSINAFY_SIGNER_ACCESS_CODE"
|
|
25994
|
+
);
|
|
25768
25995
|
var createCommand2 = new Command("create").description("Create a custom field definition").requiredOption("--type <type>", "Field type (see `fields types`)").requiredOption("--name <name>", "Field name").option("--regex <regex>", "Validation regex").option("--required", "Mark the field as required").option("--inactive", "Compatibility: create the field inactive").action(async (opts, command) => {
|
|
25769
25996
|
await runWithClient(command, async ({ client, config }) => {
|
|
25770
25997
|
const accountId = requireAccountId(config);
|
|
@@ -25836,12 +26063,7 @@ var deleteCommand2 = new Command("delete").alias("rm").description("Delete a fie
|
|
|
25836
26063
|
printData({ deleted: id }, config);
|
|
25837
26064
|
});
|
|
25838
26065
|
});
|
|
25839
|
-
var validateCommand = new Command("validate").description("Validate a value against a field definition").argument("<id>", "Field ID").argument("<value>", "Value to validate").addOption(
|
|
25840
|
-
new Option(
|
|
25841
|
-
"--signer-access-code <code>",
|
|
25842
|
-
"Signer access code (for signer-side validation)"
|
|
25843
|
-
).env("ASSINAFY_SIGNER_ACCESS_CODE")
|
|
25844
|
-
).action(async (id, value, opts, command) => {
|
|
26066
|
+
var validateCommand = new Command("validate").description("Validate a value against a field definition").argument("<id>", "Field ID").argument("<value>", "Value to validate").addOption(signerAccessCodeOption()).action(async (id, value, opts, command) => {
|
|
25845
26067
|
const run = opts.signerAccessCode ? runWithPublicClient : runWithClient;
|
|
25846
26068
|
await run(command, async ({ client, config }) => {
|
|
25847
26069
|
const accountId = requireAccountId(config);
|
|
@@ -25857,11 +26079,7 @@ var validateCommand = new Command("validate").description("Validate a value agai
|
|
|
25857
26079
|
);
|
|
25858
26080
|
});
|
|
25859
26081
|
});
|
|
25860
|
-
var validateMultipleCommand = new Command("validate-multiple").description("Validate multiple field values at once").requiredOption("--entries <json>", "JSON array of { field_id, value } entries").addOption(
|
|
25861
|
-
new Option("--signer-access-code <code>", "Signer access code").env(
|
|
25862
|
-
"ASSINAFY_SIGNER_ACCESS_CODE"
|
|
25863
|
-
)
|
|
25864
|
-
).action(async (opts, command) => {
|
|
26082
|
+
var validateMultipleCommand = new Command("validate-multiple").description("Validate multiple field values at once").requiredOption("--entries <json>", "JSON array of { field_id, value } entries").addOption(signerAccessCodeOption()).action(async (opts, command) => {
|
|
25865
26083
|
const run = opts.signerAccessCode ? runWithPublicClient : runWithClient;
|
|
25866
26084
|
await run(command, async ({ client, config }) => {
|
|
25867
26085
|
const accountId = requireAccountId(config);
|
|
@@ -25944,178 +26162,6 @@ var logoutCommand = new Command("logout").description("Remove stored credentials
|
|
|
25944
26162
|
});
|
|
25945
26163
|
});
|
|
25946
26164
|
|
|
25947
|
-
// src/lib/oauth-browser.ts
|
|
25948
|
-
var import_node_child_process3 = require("child_process");
|
|
25949
|
-
var import_node_crypto4 = require("crypto");
|
|
25950
|
-
var import_node_events2 = require("events");
|
|
25951
|
-
var import_node_http = require("http");
|
|
25952
|
-
var CLI_OAUTH_REDIRECT_URI = "https://integrations.assinafy.com.br/assinafy-cli/oauth-callback";
|
|
25953
|
-
var clearHistory = "history.replaceState(null, '', '/');";
|
|
25954
|
-
var brandOrigin = "https://integrations.assinafy.com.br";
|
|
25955
|
-
var callbackCopy = {
|
|
25956
|
-
received: {
|
|
25957
|
-
heading: "Volte ao terminal.",
|
|
25958
|
-
status: "A resposta de autoriza\xE7\xE3o foi recebida. Confira no terminal se a conex\xE3o foi conclu\xEDda."
|
|
25959
|
-
},
|
|
25960
|
-
denied: {
|
|
25961
|
-
heading: "Conex\xE3o n\xE3o autorizada.",
|
|
25962
|
-
status: "A autoriza\xE7\xE3o n\xE3o foi conclu\xEDda. Confira o erro no terminal e inicie uma nova conex\xE3o."
|
|
25963
|
-
},
|
|
25964
|
-
invalid: {
|
|
25965
|
-
heading: "Retorno inv\xE1lido.",
|
|
25966
|
-
status: "Continue na janela original de autoriza\xE7\xE3o. Se ela expirou, inicie uma nova conex\xE3o no terminal."
|
|
25967
|
-
}
|
|
25968
|
-
};
|
|
25969
|
-
function callbackPage(status) {
|
|
25970
|
-
const copy = callbackCopy[status];
|
|
25971
|
-
return `<!doctype html>
|
|
25972
|
-
<html lang="pt-BR">
|
|
25973
|
-
<head>
|
|
25974
|
-
<meta charset="utf-8">
|
|
25975
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
25976
|
-
<meta name="referrer" content="no-referrer">
|
|
25977
|
-
<meta name="robots" content="noindex, nofollow, noarchive">
|
|
25978
|
-
<title>${copy.heading} | Assinafy CLI</title>
|
|
25979
|
-
<script>${clearHistory}</script>
|
|
25980
|
-
<link rel="icon" href="${brandOrigin}/brand/assinafy-icon.png">
|
|
25981
|
-
<link rel="stylesheet" href="${brandOrigin}/brand/colors.css">
|
|
25982
|
-
<link rel="stylesheet" href="${brandOrigin}/brand/site.css">
|
|
25983
|
-
<link rel="stylesheet" href="${brandOrigin}/oauth-callback.css">
|
|
25984
|
-
</head>
|
|
25985
|
-
<body>
|
|
25986
|
-
<a class="skip-link" href="#conteudo">Pular para o conte\xFAdo</a>
|
|
25987
|
-
<header class="site-header wrap">
|
|
25988
|
-
<a class="brand" href="${brandOrigin}" aria-label="Assinafy Integra\xE7\xF5es, in\xEDcio">
|
|
25989
|
-
<img src="${brandOrigin}/brand/assinafy-logotype.svg" width="148" height="32" alt="Assinafy">
|
|
25990
|
-
<span class="brand-section">integra\xE7\xF5es</span>
|
|
25991
|
-
</a>
|
|
25992
|
-
</header>
|
|
25993
|
-
<main id="conteudo" class="hero wrap">
|
|
25994
|
-
<div>
|
|
25995
|
-
<p class="eyebrow"><img src="${brandOrigin}/assinafy-cli/cli-icon.svg" width="24" height="24" alt="">Conex\xE3o com a Assinafy CLI</p>
|
|
25996
|
-
<h1>${copy.heading}</h1>
|
|
25997
|
-
<p class="hero-description" role="status">${copy.status}</p>
|
|
25998
|
-
<a class="button button-primary" href="${brandOrigin}/assinafy-cli">Ajuda para conectar<svg width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 12h16m-7-7 7 7-7 7"/></svg></a>
|
|
25999
|
-
</div>
|
|
26000
|
-
<figure class="connection-art">
|
|
26001
|
-
<div class="connection-map" role="img" aria-label="Retorno de autoriza\xE7\xE3o: Assinafy para Assinafy CLI.">
|
|
26002
|
-
<svg class="connection-lines" viewBox="0 0 480 240" preserveAspectRatio="none" fill="none" aria-hidden="true">
|
|
26003
|
-
<path class="connection-route" d="M120 106H240"/>
|
|
26004
|
-
<path class="connection-complete" d="M240 106H374m-64-5 5 5-5 5"/>
|
|
26005
|
-
</svg>
|
|
26006
|
-
<div class="connection-node connection-assinafy" aria-hidden="true">
|
|
26007
|
-
<span class="connection-tile"><img src="${brandOrigin}/brand/assinafy-icon.png" width="60" height="60" alt=""></span>
|
|
26008
|
-
<span class="connection-label">Assinafy</span>
|
|
26009
|
-
</div>
|
|
26010
|
-
<div class="connection-node connection-application" aria-hidden="true">
|
|
26011
|
-
<span class="connection-tile"><img src="${brandOrigin}/assinafy-cli/cli-icon.svg" width="36" height="36" alt=""></span>
|
|
26012
|
-
<span class="connection-label">Assinafy CLI</span>
|
|
26013
|
-
</div>
|
|
26014
|
-
</div>
|
|
26015
|
-
<figcaption class="connection-caption">Continue no terminal que iniciou a conex\xE3o.</figcaption>
|
|
26016
|
-
</figure>
|
|
26017
|
-
</main>
|
|
26018
|
-
<footer class="site-footer wrap"><span>Assinafy. Assinaturas que conectam.</span></footer>
|
|
26019
|
-
</body>
|
|
26020
|
-
</html>`;
|
|
26021
|
-
}
|
|
26022
|
-
var callbackHeaders = {
|
|
26023
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
26024
|
-
"Cache-Control": "no-store",
|
|
26025
|
-
"Referrer-Policy": "no-referrer",
|
|
26026
|
-
"X-Content-Type-Options": "nosniff",
|
|
26027
|
-
"X-Robots-Tag": "noindex, nofollow, noarchive",
|
|
26028
|
-
"Content-Security-Policy": `default-src 'none'; script-src 'sha256-${(0, import_node_crypto4.createHash)("sha256").update(clearHistory).digest("base64")}'; style-src ${brandOrigin}; img-src ${brandOrigin}; font-src ${brandOrigin}; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`,
|
|
26029
|
-
Connection: "close"
|
|
26030
|
-
};
|
|
26031
|
-
function openBrowser(url2) {
|
|
26032
|
-
const [executable, args] = process.platform === "darwin" ? ["open", [url2]] : process.platform === "win32" ? ["rundll32.exe", ["url.dll,FileProtocolHandler", url2]] : ["xdg-open", [url2]];
|
|
26033
|
-
return new Promise((resolve, reject) => {
|
|
26034
|
-
const child = (0, import_node_child_process3.spawn)(executable, args, {
|
|
26035
|
-
stdio: "ignore",
|
|
26036
|
-
detached: true,
|
|
26037
|
-
windowsHide: true
|
|
26038
|
-
});
|
|
26039
|
-
child.once("error", () => reject(new CliError("Could not open the system browser.")));
|
|
26040
|
-
child.once("spawn", () => {
|
|
26041
|
-
child.unref();
|
|
26042
|
-
resolve();
|
|
26043
|
-
});
|
|
26044
|
-
});
|
|
26045
|
-
}
|
|
26046
|
-
async function connectOAuth(oauth, options, onAuthorize, timeoutMs = 18e4) {
|
|
26047
|
-
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 6e5) {
|
|
26048
|
-
throw new CliError("OAuth connection timeout must be between 1 and 600000 milliseconds.");
|
|
26049
|
-
}
|
|
26050
|
-
const request = await oauth.authorize(options);
|
|
26051
|
-
if (new URL(request.redirect_uri).search) {
|
|
26052
|
-
throw new CliError("The browser relay redirect URI must not contain query parameters.");
|
|
26053
|
-
}
|
|
26054
|
-
const server = (0, import_node_http.createServer)({ maxHeaderSize: 8192, requestTimeout: 5e3, headersTimeout: 5e3 });
|
|
26055
|
-
server.maxConnections = 8;
|
|
26056
|
-
server.setTimeout(5e3, (socket) => socket.destroy());
|
|
26057
|
-
let timer;
|
|
26058
|
-
let cancel2;
|
|
26059
|
-
let terminate;
|
|
26060
|
-
let callbackUrl;
|
|
26061
|
-
try {
|
|
26062
|
-
server.listen(0, "127.0.0.1");
|
|
26063
|
-
await (0, import_node_events2.once)(server, "listening");
|
|
26064
|
-
const address = server.address();
|
|
26065
|
-
if (!address || typeof address === "string") throw new CliError("No OAuth listener address.");
|
|
26066
|
-
const host = `127.0.0.1:${address.port}`;
|
|
26067
|
-
request.state += `.${address.port}`;
|
|
26068
|
-
const expectedState = Buffer.from(request.state);
|
|
26069
|
-
const authorization = new URL(request.authorization_url);
|
|
26070
|
-
authorization.searchParams.set("state", request.state);
|
|
26071
|
-
request.authorization_url = authorization.toString();
|
|
26072
|
-
callbackUrl = await new Promise((resolve, reject) => {
|
|
26073
|
-
let consumed = false;
|
|
26074
|
-
timer = setTimeout(
|
|
26075
|
-
() => reject(new CliError("OAuth connection timed out. Start again.")),
|
|
26076
|
-
timeoutMs
|
|
26077
|
-
);
|
|
26078
|
-
cancel2 = () => reject(new CliError("OAuth connection cancelled.", { exitCode: 130 }));
|
|
26079
|
-
terminate = () => reject(new CliError("OAuth connection terminated.", { exitCode: 143 }));
|
|
26080
|
-
process.once("SIGINT", cancel2);
|
|
26081
|
-
process.once("SIGTERM", terminate);
|
|
26082
|
-
server.once("error", reject);
|
|
26083
|
-
server.on("request", (incoming, response) => {
|
|
26084
|
-
const raw = incoming.url ?? "";
|
|
26085
|
-
const url2 = new URL(raw.startsWith("/callback?") ? raw : "/invalid", `http://${host}`);
|
|
26086
|
-
const query = url2.searchParams;
|
|
26087
|
-
const state = Buffer.from(query.get("state") ?? "");
|
|
26088
|
-
const valid = !consumed && incoming.method === "GET" && incoming.headers.host === host && raw.startsWith("/callback?") && raw.length <= 8192 && url2.origin === `http://${host}` && url2.pathname === "/callback" && !url2.hash && [...query.keys()].every((key) => query.getAll(key).length === 1) && state.length === expectedState.length && (0, import_node_crypto4.timingSafeEqual)(state, expectedState) && query.get("iss") === request.issuer && query.has("code") !== query.has("error") && Boolean((query.get("code") ?? query.get("error"))?.trim());
|
|
26089
|
-
if (!valid) {
|
|
26090
|
-
response.writeHead(400, callbackHeaders);
|
|
26091
|
-
response.end(callbackPage("invalid"));
|
|
26092
|
-
return;
|
|
26093
|
-
}
|
|
26094
|
-
consumed = true;
|
|
26095
|
-
const callback = new URL(request.redirect_uri);
|
|
26096
|
-
for (const key of ["code", "state", "iss", "error"]) {
|
|
26097
|
-
if (query.has(key)) callback.searchParams.set(key, query.get(key));
|
|
26098
|
-
}
|
|
26099
|
-
response.writeHead(200, callbackHeaders);
|
|
26100
|
-
response.end(
|
|
26101
|
-
callbackPage(query.has("error") ? "denied" : "received"),
|
|
26102
|
-
() => resolve(callback.toString())
|
|
26103
|
-
);
|
|
26104
|
-
});
|
|
26105
|
-
void Promise.resolve().then(() => onAuthorize(request.authorization_url)).catch(reject);
|
|
26106
|
-
});
|
|
26107
|
-
} finally {
|
|
26108
|
-
clearTimeout(timer);
|
|
26109
|
-
if (cancel2) process.off("SIGINT", cancel2);
|
|
26110
|
-
if (terminate) process.off("SIGTERM", terminate);
|
|
26111
|
-
await new Promise((resolve) => {
|
|
26112
|
-
server.close(() => resolve());
|
|
26113
|
-
server.closeAllConnections();
|
|
26114
|
-
});
|
|
26115
|
-
}
|
|
26116
|
-
return oauth.exchangeCode(callbackUrl, request);
|
|
26117
|
-
}
|
|
26118
|
-
|
|
26119
26165
|
// src/commands/oauth.ts
|
|
26120
26166
|
var clientIdOption = () => new Option("--client-id <id>", "OAuth application client ID").env("ASSINAFY_OAUTH_CLIENT_ID").default("96BZZ0sZTb2NkEXt1GCaIRCTprI2YKHZr8JDHawuXUyCLC88");
|
|
26121
26167
|
var clientSecretOption = () => new Option(
|
|
@@ -26126,8 +26172,8 @@ var connectCommand = new Command("connect").description(
|
|
|
26126
26172
|
"Open browser consent for a public OAuth app, receive its loopback return, and print tokens"
|
|
26127
26173
|
).addOption(clientIdOption()).option("--redirect-uri <uri>", "Exactly registered HTTPS relay URI", CLI_OAUTH_REDIRECT_URI).option(
|
|
26128
26174
|
"--scope <scopes>",
|
|
26129
|
-
"Space-separated scopes;
|
|
26130
|
-
"account:read documents:read documents:write templates:read templates:write openid profile email offline_access"
|
|
26175
|
+
"Space-separated scopes; the default requests every published scope",
|
|
26176
|
+
"account:read documents:read documents:write templates:read templates:write webhooks:write openid profile email offline_access"
|
|
26131
26177
|
).option("--timeout <seconds>", "Wait for browser consent (1\u2013600 seconds)", "180").option("--no-browser", "Print the authorization URL without opening the system browser").action(async (opts, command) => {
|
|
26132
26178
|
await runWithPublicClient(command, async ({ client, config }) => {
|
|
26133
26179
|
const timeout = parseInteger(opts.timeout, "--timeout", { min: 1 });
|
|
@@ -26136,7 +26182,7 @@ var connectCommand = new Command("connect").description(
|
|
|
26136
26182
|
{
|
|
26137
26183
|
clientId: opts.clientId,
|
|
26138
26184
|
redirectUri: opts.redirectUri,
|
|
26139
|
-
scopes: opts.scope.trim().split(/\s+/)
|
|
26185
|
+
scopes: opts.scope.trim().split(/\s+/).filter(Boolean)
|
|
26140
26186
|
},
|
|
26141
26187
|
async (url2) => {
|
|
26142
26188
|
process.stderr.write(
|
|
@@ -26151,10 +26197,20 @@ ${sanitizeTerminalText(url2)}
|
|
|
26151
26197
|
}
|
|
26152
26198
|
},
|
|
26153
26199
|
timeout * 1e3
|
|
26154
|
-
)
|
|
26200
|
+
).catch((error) => {
|
|
26201
|
+
throw withScopeHint(error);
|
|
26202
|
+
});
|
|
26155
26203
|
printData(tokens, config);
|
|
26156
26204
|
});
|
|
26157
26205
|
});
|
|
26206
|
+
function withScopeHint(error) {
|
|
26207
|
+
if (!(error instanceof ValidationError) || error.errors.oauthError !== "invalid_scope")
|
|
26208
|
+
return error;
|
|
26209
|
+
return new ValidationError(
|
|
26210
|
+
`${error.message}. The application is not registered for one of the requested scopes: the default requests all ten published scopes, including webhooks:write. Ask the application owner to register them, or pass --scope with the scopes it permits.`,
|
|
26211
|
+
error.errors
|
|
26212
|
+
);
|
|
26213
|
+
}
|
|
26158
26214
|
var metadataCommand = new Command("metadata").description("Read protected-resource metadata from the API origin").action(async (_opts, command) => {
|
|
26159
26215
|
await runWithPublicClient(command, async ({ client, config }) => {
|
|
26160
26216
|
printData(await client.oauth.metadata(), config);
|
|
@@ -26176,7 +26232,7 @@ var authorizeCommand = new Command("authorize").description(
|
|
|
26176
26232
|
await client.oauth.authorize({
|
|
26177
26233
|
clientId: opts.clientId,
|
|
26178
26234
|
redirectUri: opts.redirectUri,
|
|
26179
|
-
scopes: opts.scope.trim().split(/\s+/)
|
|
26235
|
+
scopes: opts.scope.trim().split(/\s+/).filter(Boolean)
|
|
26180
26236
|
}),
|
|
26181
26237
|
config
|
|
26182
26238
|
);
|
|
@@ -26200,16 +26256,21 @@ var refreshCommand = new Command("refresh").description("Rotate a refresh token
|
|
|
26200
26256
|
new Option("--refresh-token <token>", "Current refresh token").env("ASSINAFY_OAUTH_REFRESH_TOKEN").makeOptionMandatory()
|
|
26201
26257
|
).option("--resource <uri>", "Resource indicator used during authorization").action(async (opts, command) => {
|
|
26202
26258
|
await runWithPublicClient(command, async ({ client, config }) => {
|
|
26203
|
-
|
|
26204
|
-
|
|
26205
|
-
|
|
26206
|
-
|
|
26207
|
-
|
|
26208
|
-
|
|
26209
|
-
|
|
26210
|
-
|
|
26211
|
-
|
|
26212
|
-
|
|
26259
|
+
const tokens = await client.oauth.token({
|
|
26260
|
+
grant_type: "refresh_token",
|
|
26261
|
+
client_id: opts.clientId,
|
|
26262
|
+
client_secret: opts.clientSecret,
|
|
26263
|
+
refresh_token: opts.refreshToken,
|
|
26264
|
+
resource: opts.resource
|
|
26265
|
+
}).catch((error) => {
|
|
26266
|
+
if (!(error instanceof ValidationError) || error.errors.field !== "refresh_token")
|
|
26267
|
+
throw error;
|
|
26268
|
+
throw new ValidationError(
|
|
26269
|
+
`${error.message}. Run \`assinafy oauth connect\` to authorize again.`,
|
|
26270
|
+
error.errors
|
|
26271
|
+
);
|
|
26272
|
+
});
|
|
26273
|
+
printData(tokens, config);
|
|
26213
26274
|
});
|
|
26214
26275
|
});
|
|
26215
26276
|
var revokeCommand = new Command("revoke").description("Revoke an access or refresh token for this application").addOption(clientIdOption()).addOption(clientSecretOption()).addOption(
|
|
@@ -26238,6 +26299,7 @@ var userinfoCommand = new Command("userinfo").description("Read OIDC claims usin
|
|
|
26238
26299
|
var oauthCommand = new Command("oauth").description("OAuth 2.1 authorization, PKCE, token rotation, and OpenID Connect").addCommand(connectCommand).addCommand(metadataCommand).addCommand(discoveryCommand).addCommand(authorizeCommand).addCommand(exchangeCommand).addCommand(refreshCommand).addCommand(revokeCommand).addCommand(userinfoCommand);
|
|
26239
26300
|
|
|
26240
26301
|
// src/commands/send.ts
|
|
26302
|
+
var phonePattern = /^\+?[\d\s().-]*\d[\d\s().-]*$/;
|
|
26241
26303
|
function parseSignerSpec(spec) {
|
|
26242
26304
|
const match = spec.match(/^\s*(.*?)\s*<\s*([^>]*)\s*>\s*$/);
|
|
26243
26305
|
const name = match?.[1]?.trim();
|
|
@@ -26246,12 +26308,17 @@ function parseSignerSpec(spec) {
|
|
|
26246
26308
|
throw new CliError(`Invalid --signer "${spec}". Use "Name <email-or-phone>".`);
|
|
26247
26309
|
}
|
|
26248
26310
|
const isEmail = contact.includes("@");
|
|
26311
|
+
if (!match && !isEmail && !phonePattern.test(contact)) {
|
|
26312
|
+
throw new CliError(
|
|
26313
|
+
`Invalid --signer "${spec}". A bare contact must be an email or a phone number. Use "Name <email-or-phone>".`
|
|
26314
|
+
);
|
|
26315
|
+
}
|
|
26249
26316
|
const signer = { name: name || contact };
|
|
26250
26317
|
if (isEmail) signer.email = contact;
|
|
26251
26318
|
else signer.whatsapp_phone_number = contact;
|
|
26252
26319
|
return signer;
|
|
26253
26320
|
}
|
|
26254
|
-
function
|
|
26321
|
+
function resolveSigners(signerSpecs, signersJson) {
|
|
26255
26322
|
if (signerSpecs.length > 0 && signersJson) {
|
|
26256
26323
|
throw new CliError("Provide either --signer or --signers, not both.");
|
|
26257
26324
|
}
|
|
@@ -26268,7 +26335,7 @@ var sendCommand = new Command("send").description("Upload a PDF, create signers,
|
|
|
26268
26335
|
).addOption(new Option("--signers <json>", "JSON array of signer objects").conflicts("signer")).option("--message <message>", "Message shown to signers").option("--expires-at <iso8601>", "Expiration timestamp").option("--copy-receivers <csv>", "Comma-separated signer IDs to receive a copy of the document").option("--metadata <json>", "JSON object of metadata to attach to the document").option("--no-wait", "Do not wait for the document to finish processing").action(async (file, opts, command) => {
|
|
26269
26336
|
await runWithClient(command, async ({ client, config }) => {
|
|
26270
26337
|
const accountId = requireAccountId(config);
|
|
26271
|
-
const signers =
|
|
26338
|
+
const signers = resolveSigners(opts.signer, opts.signers);
|
|
26272
26339
|
const params = {
|
|
26273
26340
|
source: { filePath: file },
|
|
26274
26341
|
signers,
|
|
@@ -26353,29 +26420,22 @@ var searchCommand2 = new Command("search").description("Search the signer's docu
|
|
|
26353
26420
|
);
|
|
26354
26421
|
});
|
|
26355
26422
|
});
|
|
26356
|
-
var downloadCommand2 =
|
|
26357
|
-
new
|
|
26358
|
-
"
|
|
26423
|
+
var downloadCommand2 = addDownloadOptions(
|
|
26424
|
+
new Command("download").description("Download a signer document artifact").argument("<signerId>", "Signer ID").argument("<documentId>", "Document ID").argument("<artifact>", "original | certificated | certificate-page | pades | bundle").addOption(
|
|
26425
|
+
new Option("--access-code <code>", "Optional signer identity preflight code").env(
|
|
26426
|
+
"ASSINAFY_SIGNER_ACCESS_CODE"
|
|
26427
|
+
)
|
|
26359
26428
|
)
|
|
26360
|
-
).
|
|
26429
|
+
).action(async (signerId, documentId, artifact, opts, command) => {
|
|
26361
26430
|
await runWithPublicClient(command, async ({ client, config }) => {
|
|
26362
26431
|
const artifactName = requireDocumentArtifactName(artifact);
|
|
26363
|
-
|
|
26364
|
-
"Downloading",
|
|
26365
|
-
|
|
26366
|
-
|
|
26367
|
-
|
|
26368
|
-
|
|
26369
|
-
|
|
26370
|
-
buffer,
|
|
26371
|
-
{ force: opts.force }
|
|
26372
|
-
);
|
|
26373
|
-
printSuccess(`Saved ${buffer.byteLength} bytes to ${out}`, config);
|
|
26374
|
-
printData(
|
|
26375
|
-
{ path: out, bytes: buffer.byteLength },
|
|
26376
|
-
config,
|
|
26377
|
-
(d) => sanitizeTerminalText(d.path)
|
|
26378
|
-
);
|
|
26432
|
+
await saveDownload(config, {
|
|
26433
|
+
message: "Downloading",
|
|
26434
|
+
download: () => client.signerDocuments.download(signerId, documentId, artifactName, opts.accessCode),
|
|
26435
|
+
output: opts.output,
|
|
26436
|
+
defaultName: defaultArtifactFilename(documentId, artifactName),
|
|
26437
|
+
force: opts.force
|
|
26438
|
+
});
|
|
26379
26439
|
});
|
|
26380
26440
|
});
|
|
26381
26441
|
var selfCommand = new Command("self").description("Fetch the signer's own profile").addOption(accessCodeOption()).action(async (opts, command) => {
|
|
@@ -26472,23 +26532,18 @@ var uploadSignatureCommand = new Command("upload-signature").description("Upload
|
|
|
26472
26532
|
printData(result, config);
|
|
26473
26533
|
});
|
|
26474
26534
|
});
|
|
26475
|
-
var downloadSignatureCommand =
|
|
26535
|
+
var downloadSignatureCommand = addDownloadOptions(
|
|
26536
|
+
new Command("download-signature").description("Download the signer's signature or initial image").addOption(accessCodeOption()).option("--type <type>", "signature or initial", "signature")
|
|
26537
|
+
).action(async (opts, command) => {
|
|
26476
26538
|
await runWithPublicClient(command, async ({ client, config }) => {
|
|
26477
26539
|
const imageType = requireSignerImageType(opts.type);
|
|
26478
|
-
|
|
26479
|
-
"Downloading signature",
|
|
26480
|
-
|
|
26481
|
-
|
|
26482
|
-
|
|
26483
|
-
const out = writeBinary(opts.output ?? `signer-${imageType}.png`, buffer, {
|
|
26540
|
+
await saveDownload(config, {
|
|
26541
|
+
message: "Downloading signature",
|
|
26542
|
+
download: () => client.signerDocuments.downloadSignature(opts.accessCode, imageType),
|
|
26543
|
+
output: opts.output,
|
|
26544
|
+
defaultName: `signer-${imageType}.png`,
|
|
26484
26545
|
force: opts.force
|
|
26485
26546
|
});
|
|
26486
|
-
printSuccess(`Saved ${buffer.byteLength} bytes to ${out}`, config);
|
|
26487
|
-
printData(
|
|
26488
|
-
{ path: out, bytes: buffer.byteLength },
|
|
26489
|
-
config,
|
|
26490
|
-
(d) => sanitizeTerminalText(d.path)
|
|
26491
|
-
);
|
|
26492
26547
|
});
|
|
26493
26548
|
});
|
|
26494
26549
|
var assignmentCommand = new Command("assignment").description("Fetch the assignment as the signer sees it").addOption(accessCodeOption()).option("--accept-terms", "Pass has_accepted_terms=true").action(async (opts, command) => {
|
|
@@ -26603,9 +26658,7 @@ var listCommand5 = addListOptions(
|
|
|
26603
26658
|
);
|
|
26604
26659
|
printPaginatedData(result, config, (rows) => {
|
|
26605
26660
|
const table = renderTable(rows, signerColumns);
|
|
26606
|
-
|
|
26607
|
-
return footer ? `${table}
|
|
26608
|
-
${footer}` : table;
|
|
26661
|
+
return tableWithFooter(table, result);
|
|
26609
26662
|
});
|
|
26610
26663
|
});
|
|
26611
26664
|
});
|
|
@@ -26751,9 +26804,7 @@ var listCommand7 = addListOptions(
|
|
|
26751
26804
|
{ header: "STATUS", value: (r2) => r2.status },
|
|
26752
26805
|
{ header: "CREATED", value: (r2) => r2.created_at }
|
|
26753
26806
|
]);
|
|
26754
|
-
|
|
26755
|
-
return footer ? `${table}
|
|
26756
|
-
${footer}` : table;
|
|
26807
|
+
return tableWithFooter(table, result);
|
|
26757
26808
|
});
|
|
26758
26809
|
});
|
|
26759
26810
|
});
|
|
@@ -26777,23 +26828,18 @@ var getCommand5 = new Command("get").description("Show a template by ID").argume
|
|
|
26777
26828
|
);
|
|
26778
26829
|
});
|
|
26779
26830
|
});
|
|
26780
|
-
var downloadPageCommand2 =
|
|
26831
|
+
var downloadPageCommand2 = addDownloadOptions(
|
|
26832
|
+
new Command("download-page").description("Download a template page as a JPEG").argument("<templateId>", "Template ID").argument("<pageId>", "Page ID")
|
|
26833
|
+
).action(async (templateId, pageId, opts, command) => {
|
|
26781
26834
|
await runWithClient(command, async ({ client, config }) => {
|
|
26782
26835
|
const accountId = requireAccountId(config);
|
|
26783
|
-
|
|
26784
|
-
"Downloading page",
|
|
26785
|
-
|
|
26786
|
-
|
|
26787
|
-
|
|
26788
|
-
const out = writeBinary(opts.output ?? `${templateId}-page-${pageId}.jpg`, buffer, {
|
|
26836
|
+
await saveDownload(config, {
|
|
26837
|
+
message: "Downloading page",
|
|
26838
|
+
download: () => client.templates.downloadPage(templateId, pageId, accountId),
|
|
26839
|
+
output: opts.output,
|
|
26840
|
+
defaultName: `${templateId}-page-${pageId}.jpg`,
|
|
26789
26841
|
force: opts.force
|
|
26790
26842
|
});
|
|
26791
|
-
printSuccess(`Saved ${buffer.byteLength} bytes to ${out}`, config);
|
|
26792
|
-
printData(
|
|
26793
|
-
{ path: out, bytes: buffer.byteLength },
|
|
26794
|
-
config,
|
|
26795
|
-
(d) => sanitizeTerminalText(d.path)
|
|
26796
|
-
);
|
|
26797
26843
|
});
|
|
26798
26844
|
});
|
|
26799
26845
|
var templatesCommand = new Command("templates").description("List and inspect document templates").addCommand(listCommand7).addCommand(getCommand5).addCommand(downloadPageCommand2);
|
|
@@ -26805,7 +26851,9 @@ var selfCommand2 = new Command("self").description("Show the authenticated user'
|
|
|
26805
26851
|
printData(user, config);
|
|
26806
26852
|
});
|
|
26807
26853
|
});
|
|
26808
|
-
var statsCommand = new Command("stats").description("Show document KPIs across the user's accounts").
|
|
26854
|
+
var statsCommand = new Command("stats").description("Show document KPIs across the user's accounts").addOption(
|
|
26855
|
+
new Option("--granularity <value>", "monthly or daily").choices(["monthly", "daily"]).default("monthly")
|
|
26856
|
+
).option("--month <yyyy-mm>", "Month required for daily granularity").action(async (opts, command) => {
|
|
26809
26857
|
await runWithClient(command, async ({ client, config }) => {
|
|
26810
26858
|
const params = {
|
|
26811
26859
|
granularity: opts.granularity,
|
|
@@ -26955,9 +27003,7 @@ var dispatchesCommand = addSortableListOptions(
|
|
|
26955
27003
|
{ header: "STATUS", value: (r2) => r2.http_status },
|
|
26956
27004
|
{ header: "ENDPOINT", value: (r2) => r2.endpoint }
|
|
26957
27005
|
]);
|
|
26958
|
-
|
|
26959
|
-
return footer ? `${table}
|
|
26960
|
-
${footer}` : table;
|
|
27006
|
+
return tableWithFooter(table, result);
|
|
26961
27007
|
});
|
|
26962
27008
|
});
|
|
26963
27009
|
});
|
|
@@ -27002,7 +27048,12 @@ var whoamiCommand = new Command("whoami").description("Verify credentials and li
|
|
|
27002
27048
|
|
|
27003
27049
|
// src/commands/workspaces.ts
|
|
27004
27050
|
var import_node_path6 = __toESM(require("path"), 1);
|
|
27005
|
-
var createCommand5 = new Command("create").description("Create a workspace (account)").requiredOption("--name <name>", "Workspace name").
|
|
27051
|
+
var createCommand5 = new Command("create").description("Create a workspace (account)").requiredOption("--name <name>", "Workspace name").addOption(
|
|
27052
|
+
new Option("--notification-sender <type>", "Notification sender: User or Account").choices([
|
|
27053
|
+
"User",
|
|
27054
|
+
"Account"
|
|
27055
|
+
])
|
|
27056
|
+
).option("--primary-color <hex>", "Primary brand color").option("--secondary-color <hex>", "Secondary brand color").action(async (opts, command) => {
|
|
27006
27057
|
await runWithClient(command, async ({ client, config }) => {
|
|
27007
27058
|
const workspace = await withSpinner(
|
|
27008
27059
|
"Creating workspace",
|
|
@@ -27047,12 +27098,16 @@ var getCommand7 = new Command("get").description("Show a workspace by ID").argum
|
|
|
27047
27098
|
printData(workspace, config, (w) => renderKeyValue(w));
|
|
27048
27099
|
});
|
|
27049
27100
|
});
|
|
27050
|
-
var updateCommand4 = new Command("update").description("Update a workspace").argument("<id>", "Account/workspace ID").option("--name <name>", "New name").
|
|
27101
|
+
var updateCommand4 = new Command("update").description("Update a workspace").argument("<id>", "Account/workspace ID").option("--name <name>", "New name").addOption(
|
|
27102
|
+
new Option("--notification-sender <type>", "Notification sender: User or Account").choices([
|
|
27103
|
+
"User",
|
|
27104
|
+
"Account"
|
|
27105
|
+
])
|
|
27106
|
+
).option("--primary-color <hex>", "Primary brand color (pass empty to clear)").option("--secondary-color <hex>", "Secondary brand color (pass empty to clear)").action(async (id, opts, command) => {
|
|
27051
27107
|
await runWithClient(command, async ({ client, config }) => {
|
|
27052
27108
|
const payload = {};
|
|
27053
27109
|
if (opts.name) payload.name = opts.name;
|
|
27054
|
-
if (opts.notificationSender)
|
|
27055
|
-
payload.notification_sender_type = opts.notificationSender;
|
|
27110
|
+
if (opts.notificationSender) payload.notification_sender_type = opts.notificationSender;
|
|
27056
27111
|
if (opts.primaryColor !== void 0) payload.primary_color = opts.primaryColor || null;
|
|
27057
27112
|
if (opts.secondaryColor !== void 0) payload.secondary_color = opts.secondaryColor || null;
|
|
27058
27113
|
const workspace = await withSpinner(
|
|
@@ -27078,7 +27133,9 @@ var themeCommand = new Command("theme").description("Show public branding for a
|
|
|
27078
27133
|
);
|
|
27079
27134
|
});
|
|
27080
27135
|
});
|
|
27081
|
-
var statsCommand2 = new Command("stats").description("Show document KPIs for a workspace").argument("<id>", "Account/workspace ID").
|
|
27136
|
+
var statsCommand2 = new Command("stats").description("Show document KPIs for a workspace").argument("<id>", "Account/workspace ID").addOption(
|
|
27137
|
+
new Option("--granularity <value>", "monthly or daily").choices(["monthly", "daily"]).default("monthly")
|
|
27138
|
+
).option("--month <yyyy-mm>", "Month required for daily granularity").action(async (id, opts, command) => {
|
|
27082
27139
|
await runWithClient(command, async ({ client, config }) => {
|
|
27083
27140
|
const params = {
|
|
27084
27141
|
granularity: opts.granularity,
|
|
@@ -27092,20 +27149,17 @@ var statsCommand2 = new Command("stats").description("Show document KPIs for a w
|
|
|
27092
27149
|
printData(rows, config, renderDocumentStats);
|
|
27093
27150
|
});
|
|
27094
27151
|
});
|
|
27095
|
-
var logoDownloadCommand =
|
|
27152
|
+
var logoDownloadCommand = addDownloadOptions(
|
|
27153
|
+
new Command("download").description("Download the workspace logo").argument("<id>", "Account/workspace ID")
|
|
27154
|
+
).action(async (id, opts, command) => {
|
|
27096
27155
|
await runWithClient(command, async ({ client, config }) => {
|
|
27097
|
-
|
|
27098
|
-
"Downloading workspace logo",
|
|
27099
|
-
|
|
27100
|
-
|
|
27101
|
-
|
|
27102
|
-
|
|
27103
|
-
|
|
27104
|
-
printData(
|
|
27105
|
-
{ path: output, bytes: logo.byteLength },
|
|
27106
|
-
config,
|
|
27107
|
-
(value) => sanitizeTerminalText(value.path)
|
|
27108
|
-
);
|
|
27156
|
+
await saveDownload(config, {
|
|
27157
|
+
message: "Downloading workspace logo",
|
|
27158
|
+
download: () => client.workspaces.downloadLogo(id),
|
|
27159
|
+
output: opts.output,
|
|
27160
|
+
defaultName: `${id}-logo.png`,
|
|
27161
|
+
force: opts.force
|
|
27162
|
+
});
|
|
27109
27163
|
});
|
|
27110
27164
|
});
|
|
27111
27165
|
var logoUploadCommand = new Command("upload").description("Upload or replace the workspace logo").argument("<id>", "Account/workspace ID").argument("<file>", "Logo image path").option("--content-type <mime>", "Image MIME type (inferred from extension)").action(async (id, file, opts, command) => {
|
|
@@ -27192,7 +27246,7 @@ function handleStreamError(err, fallback, exit = process.exit) {
|
|
|
27192
27246
|
// package.json
|
|
27193
27247
|
var package_default = {
|
|
27194
27248
|
name: "@assinafy/cli",
|
|
27195
|
-
version: "2.
|
|
27249
|
+
version: "2.4.1",
|
|
27196
27250
|
description: "The official command-line interface for the Assinafy digital-signature API",
|
|
27197
27251
|
license: "MIT",
|
|
27198
27252
|
type: "module",
|