verdifax 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -2
- package/dist/index.d.mts +209 -4
- package/dist/index.d.ts +209 -4
- package/dist/index.js +259 -55
- package/dist/index.mjs +259 -55
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -674,7 +674,7 @@ var VerdifaxJob = class {
|
|
|
674
674
|
};
|
|
675
675
|
|
|
676
676
|
// src/version.ts
|
|
677
|
-
var SDK_VERSION = "1.
|
|
677
|
+
var SDK_VERSION = "1.3.0";
|
|
678
678
|
|
|
679
679
|
// src/client.ts
|
|
680
680
|
var DEFAULT_BASE_URL = "https://api.verdifax.com";
|
|
@@ -685,6 +685,10 @@ var SDK_USER_AGENT = `verdifax-sdk-node/${SDK_VERSION}`;
|
|
|
685
685
|
var HEADER_API_KEY = "X-Verdifax-Key";
|
|
686
686
|
var REQUEST_KEY_PATH = "/keys/request-key";
|
|
687
687
|
var POLICIES_PATH = "/policies";
|
|
688
|
+
var ACCOUNT_PATH = "/account";
|
|
689
|
+
var ACCOUNT_REQUEST_KEY_PATH = "/account/request-key";
|
|
690
|
+
var ACCOUNT_POLICIES_PATH = "/account/policies";
|
|
691
|
+
var ACCOUNT_CHAIN_ID = /^account-[1-9][0-9]*$/;
|
|
688
692
|
var HEADER_EXPORT_TOTAL = "X-Verdifax-Total";
|
|
689
693
|
var HEADER_EXPORT_TRUNCATED = "X-Verdifax-Truncated";
|
|
690
694
|
var RETRYABLE_STATUSES = /* @__PURE__ */ new Set([429, 502, 503, 504]);
|
|
@@ -870,15 +874,18 @@ var VerdifaxClient = class {
|
|
|
870
874
|
* that the client holds the private key. From then on the server
|
|
871
875
|
* refuses a run on this API key without a request signature. */
|
|
872
876
|
async registerRequestKey() {
|
|
877
|
+
return this.registerRequestKeyAt(REQUEST_KEY_PATH, "registerRequestKey");
|
|
878
|
+
}
|
|
879
|
+
async registerRequestKeyAt(path, method) {
|
|
873
880
|
this.requireAPIKey();
|
|
874
881
|
if (!this.signingKey) {
|
|
875
882
|
throw new VerdifaxError(
|
|
876
|
-
|
|
883
|
+
`verdifax: ${method} needs the signingKey client option`
|
|
877
884
|
);
|
|
878
885
|
}
|
|
879
886
|
return this.request(
|
|
880
887
|
"POST",
|
|
881
|
-
|
|
888
|
+
path,
|
|
882
889
|
requestKeyRegistrationBody(this.signingKey)
|
|
883
890
|
);
|
|
884
891
|
}
|
|
@@ -917,10 +924,13 @@ var VerdifaxClient = class {
|
|
|
917
924
|
* unsigned requests, because the server refuses a signed run on an API
|
|
918
925
|
* key with no registered key. If the call fails it keeps the key. */
|
|
919
926
|
async clearRequestKey() {
|
|
927
|
+
await this.clearRequestKeyAt(REQUEST_KEY_PATH);
|
|
928
|
+
}
|
|
929
|
+
async clearRequestKeyAt(path) {
|
|
920
930
|
this.requireAPIKey();
|
|
921
931
|
await this.request(
|
|
922
932
|
"DELETE",
|
|
923
|
-
|
|
933
|
+
path,
|
|
924
934
|
this.signingKey ? { change: requestKeyChangeApproval(this.signingKey, "") } : void 0
|
|
925
935
|
);
|
|
926
936
|
this.signingKey = void 0;
|
|
@@ -932,13 +942,7 @@ var VerdifaxClient = class {
|
|
|
932
942
|
* not a string: serializing an object here would change the hash.
|
|
933
943
|
* Verdifax does not write, review or approve a customer's policy. */
|
|
934
944
|
async uploadPolicy(document) {
|
|
935
|
-
this.
|
|
936
|
-
if (typeof document !== "string") {
|
|
937
|
-
throw new VerdifaxError(
|
|
938
|
-
"verdifax: document must be the policy's exact text, as a string"
|
|
939
|
-
);
|
|
940
|
-
}
|
|
941
|
-
return this.request("POST", POLICIES_PATH, { document });
|
|
945
|
+
return this.uploadPolicyAt(POLICIES_PATH, document);
|
|
942
946
|
}
|
|
943
947
|
/** This key's stored documents, with the chain its changes belong to,
|
|
944
948
|
* the newest change in it (64 zeros when there is none yet) and the
|
|
@@ -949,44 +953,13 @@ var VerdifaxClient = class {
|
|
|
949
953
|
}
|
|
950
954
|
/** One stored document, with its exact text as `document`. */
|
|
951
955
|
async getPolicy(documentHash) {
|
|
952
|
-
this.
|
|
953
|
-
validateHex64(documentHash, "documentHash");
|
|
954
|
-
return this.request(
|
|
955
|
-
"GET",
|
|
956
|
-
`${POLICIES_PATH}/${documentHash}`
|
|
957
|
-
);
|
|
956
|
+
return this.getPolicyAt(POLICIES_PATH, documentHash);
|
|
958
957
|
}
|
|
959
958
|
/** Shows which rule would fire on sample inputs, for a document given as
|
|
960
959
|
* text or one already stored, named by its hash: exactly one of the two.
|
|
961
960
|
* It seals nothing. */
|
|
962
961
|
async testPolicy(req) {
|
|
963
|
-
this.
|
|
964
|
-
const { inputs, document, documentHash } = req ?? {};
|
|
965
|
-
if (document === void 0 === (documentHash === void 0)) {
|
|
966
|
-
throw new VerdifaxError(
|
|
967
|
-
"verdifax: testPolicy needs exactly one of document or documentHash"
|
|
968
|
-
);
|
|
969
|
-
}
|
|
970
|
-
if (typeof inputs !== "object" || inputs === null || Array.isArray(inputs)) {
|
|
971
|
-
throw new VerdifaxError("verdifax: testPolicy needs inputs as an object");
|
|
972
|
-
}
|
|
973
|
-
const body = { inputs };
|
|
974
|
-
if (document !== void 0) {
|
|
975
|
-
if (typeof document !== "string") {
|
|
976
|
-
throw new VerdifaxError(
|
|
977
|
-
"verdifax: document must be the policy's exact text, as a string"
|
|
978
|
-
);
|
|
979
|
-
}
|
|
980
|
-
body.document = document;
|
|
981
|
-
} else {
|
|
982
|
-
validateHex64(documentHash, "documentHash");
|
|
983
|
-
body.document_hash = documentHash;
|
|
984
|
-
}
|
|
985
|
-
return this.request(
|
|
986
|
-
"POST",
|
|
987
|
-
`${POLICIES_PATH}/test`,
|
|
988
|
-
body
|
|
989
|
-
);
|
|
962
|
+
return this.testPolicyAt(POLICIES_PATH, req, "testPolicy");
|
|
990
963
|
}
|
|
991
964
|
/** This key's policy changes, oldest first, as the list the server sends.
|
|
992
965
|
* Save it as JSON, for example with
|
|
@@ -1012,7 +985,54 @@ var VerdifaxClient = class {
|
|
|
1012
985
|
async activatePolicy(documentHash) {
|
|
1013
986
|
this.requireAPIKey();
|
|
1014
987
|
validateHex64(documentHash, "documentHash");
|
|
1015
|
-
|
|
988
|
+
return this.activatePolicyAt(
|
|
989
|
+
POLICIES_PATH,
|
|
990
|
+
documentHash,
|
|
991
|
+
await this.listPolicies()
|
|
992
|
+
);
|
|
993
|
+
}
|
|
994
|
+
async uploadPolicyAt(base, document) {
|
|
995
|
+
this.requireAPIKey();
|
|
996
|
+
if (typeof document !== "string") {
|
|
997
|
+
throw new VerdifaxError(
|
|
998
|
+
"verdifax: document must be the policy's exact text, as a string"
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
1001
|
+
return this.request("POST", base, { document });
|
|
1002
|
+
}
|
|
1003
|
+
async getPolicyAt(base, documentHash) {
|
|
1004
|
+
this.requireAPIKey();
|
|
1005
|
+
validateHex64(documentHash, "documentHash");
|
|
1006
|
+
return this.request("GET", `${base}/${documentHash}`);
|
|
1007
|
+
}
|
|
1008
|
+
async testPolicyAt(base, req, method) {
|
|
1009
|
+
this.requireAPIKey();
|
|
1010
|
+
const { inputs, document, documentHash } = req ?? {};
|
|
1011
|
+
if (document === void 0 === (documentHash === void 0)) {
|
|
1012
|
+
throw new VerdifaxError(
|
|
1013
|
+
`verdifax: ${method} needs exactly one of document or documentHash`
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
if (typeof inputs !== "object" || inputs === null || Array.isArray(inputs)) {
|
|
1017
|
+
throw new VerdifaxError(`verdifax: ${method} needs inputs as an object`);
|
|
1018
|
+
}
|
|
1019
|
+
const body = { inputs };
|
|
1020
|
+
if (document !== void 0) {
|
|
1021
|
+
if (typeof document !== "string") {
|
|
1022
|
+
throw new VerdifaxError(
|
|
1023
|
+
"verdifax: document must be the policy's exact text, as a string"
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
body.document = document;
|
|
1027
|
+
} else {
|
|
1028
|
+
validateHex64(documentHash, "documentHash");
|
|
1029
|
+
body.document_hash = documentHash;
|
|
1030
|
+
}
|
|
1031
|
+
return this.request("POST", `${base}/test`, body);
|
|
1032
|
+
}
|
|
1033
|
+
/** Posts the change that follows the newest one in `chain`, signed by
|
|
1034
|
+
* the request key when the client has one. */
|
|
1035
|
+
async activatePolicyAt(base, documentHash, chain) {
|
|
1016
1036
|
const previous = chain?.newest_activation_hash;
|
|
1017
1037
|
if (typeof previous !== "string") {
|
|
1018
1038
|
throw new VerdifaxError(
|
|
@@ -1034,11 +1054,147 @@ var VerdifaxClient = class {
|
|
|
1034
1054
|
}
|
|
1035
1055
|
const out = await this.request(
|
|
1036
1056
|
"POST",
|
|
1037
|
-
`${
|
|
1057
|
+
`${base}/${documentHash}/activate`,
|
|
1038
1058
|
body
|
|
1039
1059
|
);
|
|
1040
1060
|
return out.activation;
|
|
1041
1061
|
}
|
|
1062
|
+
// ── Account, with its owner key (auth) ───────────────────────
|
|
1063
|
+
//
|
|
1064
|
+
// An account is a company on Verdifax. Every key belongs to one account
|
|
1065
|
+
// for life. These methods need the account's owner key, which manages the
|
|
1066
|
+
// account and cannot run anything: the server refuses it on every other
|
|
1067
|
+
// route. The account number is a label Verdifax assigned, not a verified
|
|
1068
|
+
// company identity.
|
|
1069
|
+
/** The owner's account: its number, name, tier, key counts and the
|
|
1070
|
+
* chain of its policy changes. */
|
|
1071
|
+
async getAccount() {
|
|
1072
|
+
this.requireAPIKey();
|
|
1073
|
+
return this.request("GET", ACCOUNT_PATH);
|
|
1074
|
+
}
|
|
1075
|
+
/** Creates a member key in the account. It takes the account's tier and
|
|
1076
|
+
* stays in the account for life. The secret is in the result this once.
|
|
1077
|
+
* On a trial account the key needs a request key before it can run. */
|
|
1078
|
+
async createAccountKey(name, options = {}) {
|
|
1079
|
+
this.requireAPIKey();
|
|
1080
|
+
if (typeof name !== "string" || name.trim() === "") {
|
|
1081
|
+
throw new VerdifaxError(
|
|
1082
|
+
"verdifax: name is required for createAccountKey"
|
|
1083
|
+
);
|
|
1084
|
+
}
|
|
1085
|
+
const body = { name };
|
|
1086
|
+
if (options.expiresAt !== void 0) body.expires_at = options.expiresAt;
|
|
1087
|
+
return this.request(
|
|
1088
|
+
"POST",
|
|
1089
|
+
`${ACCOUNT_PATH}/keys`,
|
|
1090
|
+
body
|
|
1091
|
+
);
|
|
1092
|
+
}
|
|
1093
|
+
/** Every key in the account, owner keys included, without secrets. */
|
|
1094
|
+
async listAccountKeys() {
|
|
1095
|
+
this.requireAPIKey();
|
|
1096
|
+
const out = await this.request(
|
|
1097
|
+
"GET",
|
|
1098
|
+
`${ACCOUNT_PATH}/keys`
|
|
1099
|
+
);
|
|
1100
|
+
return { ...out, keys: out?.keys ?? [] };
|
|
1101
|
+
}
|
|
1102
|
+
/** Revokes one of the account's member keys. A key in another account,
|
|
1103
|
+
* or an owner key, throws {@link NotFoundError}. */
|
|
1104
|
+
async revokeAccountKey(keyId) {
|
|
1105
|
+
this.requireAPIKey();
|
|
1106
|
+
requirePositiveId(keyId, "keyId");
|
|
1107
|
+
return this.request(
|
|
1108
|
+
"DELETE",
|
|
1109
|
+
`${ACCOUNT_PATH}/keys/${keyId}`
|
|
1110
|
+
);
|
|
1111
|
+
}
|
|
1112
|
+
/** Registers this client's public key as the owner key's request key,
|
|
1113
|
+
* which must sign every change to the account's policy. It works as
|
|
1114
|
+
* {@link registerRequestKey} does. */
|
|
1115
|
+
async registerAccountRequestKey() {
|
|
1116
|
+
return this.registerRequestKeyAt(
|
|
1117
|
+
ACCOUNT_REQUEST_KEY_PATH,
|
|
1118
|
+
"registerAccountRequestKey"
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
1121
|
+
/** Clears the owner key's request key, as {@link clearRequestKey} does
|
|
1122
|
+
* for a key's own. With none registered the account's policy cannot be
|
|
1123
|
+
* changed. A trial owner key's request key cannot be cleared. */
|
|
1124
|
+
async clearAccountRequestKey() {
|
|
1125
|
+
await this.clearRequestKeyAt(ACCOUNT_REQUEST_KEY_PATH);
|
|
1126
|
+
}
|
|
1127
|
+
/** The runs of every key in the account, paged as {@link listRuns}. */
|
|
1128
|
+
async listAccountRuns(params = {}) {
|
|
1129
|
+
return this.listRunsAt(`${ACCOUNT_PATH}/runs`, params);
|
|
1130
|
+
}
|
|
1131
|
+
/** The runs of every key in the account in a period, as
|
|
1132
|
+
* {@link exportRuns} lists a key's, with the account's number, its
|
|
1133
|
+
* policy documents and its chain of changes. The account's view covers
|
|
1134
|
+
* the runs its keys made through Verdifax, not runs made elsewhere. */
|
|
1135
|
+
async exportAccountRuns(params = {}) {
|
|
1136
|
+
this.requireAPIKey();
|
|
1137
|
+
return this.request(
|
|
1138
|
+
"GET",
|
|
1139
|
+
this.exportPath(`${ACCOUNT_PATH}/runs/export`, params, "json")
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
/** The same rows as {@link exportAccountRuns} as raw CSV text, checked
|
|
1143
|
+
* as {@link exportRunsCSV} checks a key's. */
|
|
1144
|
+
async exportAccountRunsCSV(params = {}) {
|
|
1145
|
+
return this.exportCSVAt(`${ACCOUNT_PATH}/runs/export`, params);
|
|
1146
|
+
}
|
|
1147
|
+
/** Stores an account policy document, as {@link uploadPolicy} stores a
|
|
1148
|
+
* key's. Every key in the account must pass the account's policy on top
|
|
1149
|
+
* of its own. Verdifax does not write, review or approve it. */
|
|
1150
|
+
async uploadAccountPolicy(document) {
|
|
1151
|
+
return this.uploadPolicyAt(ACCOUNT_POLICIES_PATH, document);
|
|
1152
|
+
}
|
|
1153
|
+
/** The account's stored documents, its chain `account-N`, the newest
|
|
1154
|
+
* change in it and the document in force. */
|
|
1155
|
+
async listAccountPolicies() {
|
|
1156
|
+
this.requireAPIKey();
|
|
1157
|
+
return this.request("GET", ACCOUNT_POLICIES_PATH);
|
|
1158
|
+
}
|
|
1159
|
+
/** One of the account's documents, with its exact text. */
|
|
1160
|
+
async getAccountPolicy(documentHash) {
|
|
1161
|
+
return this.getPolicyAt(ACCOUNT_POLICIES_PATH, documentHash);
|
|
1162
|
+
}
|
|
1163
|
+
/** {@link testPolicy} for the account's documents. It seals nothing. */
|
|
1164
|
+
async testAccountPolicy(req) {
|
|
1165
|
+
return this.testPolicyAt(ACCOUNT_POLICIES_PATH, req, "testAccountPolicy");
|
|
1166
|
+
}
|
|
1167
|
+
/** The account's policy changes, oldest first, in the form
|
|
1168
|
+
* `verdifax-verify --policy-history FILE` reads. */
|
|
1169
|
+
async getAccountPolicyHistory() {
|
|
1170
|
+
this.requireAPIKey();
|
|
1171
|
+
return this.request(
|
|
1172
|
+
"GET",
|
|
1173
|
+
`${ACCOUNT_POLICIES_PATH}/history`
|
|
1174
|
+
);
|
|
1175
|
+
}
|
|
1176
|
+
/** Makes a stored document the account's policy in force, as
|
|
1177
|
+
* {@link activatePolicy} does for a key's. It reads
|
|
1178
|
+
* {@link listAccountPolicies} for the chain and its newest change, and
|
|
1179
|
+
* the owner key's request key signs the change over that chain,
|
|
1180
|
+
* `account-N`. The server refuses an unsigned account change, so this
|
|
1181
|
+
* needs the `signingKey` option and refuses to send without it. */
|
|
1182
|
+
async activateAccountPolicy(documentHash) {
|
|
1183
|
+
this.requireAPIKey();
|
|
1184
|
+
validateHex64(documentHash, "documentHash");
|
|
1185
|
+
if (!this.signingKey) {
|
|
1186
|
+
throw new VerdifaxError(
|
|
1187
|
+
"verdifax: activateAccountPolicy needs the owner key's request key in the signingKey client option, because the server refuses an unsigned account policy change"
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
const chain = await this.listAccountPolicies();
|
|
1191
|
+
if (typeof chain?.chain_id !== "string" || !ACCOUNT_CHAIN_ID.test(chain.chain_id)) {
|
|
1192
|
+
throw new VerdifaxError(
|
|
1193
|
+
"verdifax: the server did not report an account chain_id (account-N), so the change cannot be signed"
|
|
1194
|
+
);
|
|
1195
|
+
}
|
|
1196
|
+
return this.activatePolicyAt(ACCOUNT_POLICIES_PATH, documentHash, chain);
|
|
1197
|
+
}
|
|
1042
1198
|
// ── Runs ──────────────────────────────────────────────────────
|
|
1043
1199
|
async getRun(runId) {
|
|
1044
1200
|
this.requireAPIKey();
|
|
@@ -1051,6 +1207,9 @@ var VerdifaxClient = class {
|
|
|
1051
1207
|
return this.request("GET", `/runs/${runId}/verify`);
|
|
1052
1208
|
}
|
|
1053
1209
|
async listRuns(params = {}) {
|
|
1210
|
+
return this.listRunsAt("/runs", params);
|
|
1211
|
+
}
|
|
1212
|
+
async listRunsAt(base, params) {
|
|
1054
1213
|
this.requireAPIKey();
|
|
1055
1214
|
const q = new URLSearchParams();
|
|
1056
1215
|
if (params.limit && params.limit > 0) {
|
|
@@ -1060,7 +1219,7 @@ var VerdifaxClient = class {
|
|
|
1060
1219
|
q.set("offset", String(params.offset));
|
|
1061
1220
|
}
|
|
1062
1221
|
const qs = q.toString();
|
|
1063
|
-
const path = qs ?
|
|
1222
|
+
const path = qs ? `${base}?${qs}` : base;
|
|
1064
1223
|
const out = await this.request("GET", path);
|
|
1065
1224
|
return { runs: out.runs ?? [], total: out.total ?? 0 };
|
|
1066
1225
|
}
|
|
@@ -1098,7 +1257,10 @@ var VerdifaxClient = class {
|
|
|
1098
1257
|
* call that never reached Verdifax cannot appear in it. */
|
|
1099
1258
|
async exportRuns(params = {}) {
|
|
1100
1259
|
this.requireAPIKey();
|
|
1101
|
-
return this.request(
|
|
1260
|
+
return this.request(
|
|
1261
|
+
"GET",
|
|
1262
|
+
this.exportPath("/runs/export", params, "json")
|
|
1263
|
+
);
|
|
1102
1264
|
}
|
|
1103
1265
|
/** The same rows as {@link exportRuns}: the raw CSV text with `total`
|
|
1104
1266
|
* and `truncated` from the response headers. Check `truncated`: when
|
|
@@ -1106,9 +1268,12 @@ var VerdifaxClient = class {
|
|
|
1106
1268
|
* does not send those headers, so that a cut-off export cannot pass
|
|
1107
1269
|
* for a complete one. */
|
|
1108
1270
|
async exportRunsCSV(params = {}) {
|
|
1271
|
+
return this.exportCSVAt("/runs/export", params);
|
|
1272
|
+
}
|
|
1273
|
+
async exportCSVAt(base, params) {
|
|
1109
1274
|
this.requireAPIKey();
|
|
1110
1275
|
const { text, headers } = await this.requestRaw(
|
|
1111
|
-
this.exportPath(params, "csv")
|
|
1276
|
+
this.exportPath(base, params, "csv")
|
|
1112
1277
|
);
|
|
1113
1278
|
const total = Number.parseInt(headers.get(HEADER_EXPORT_TOTAL) ?? "", 10);
|
|
1114
1279
|
const truncated = headers.get(HEADER_EXPORT_TRUNCATED);
|
|
@@ -1119,13 +1284,13 @@ var VerdifaxClient = class {
|
|
|
1119
1284
|
}
|
|
1120
1285
|
return { csv: text, total, truncated: truncated === "true" };
|
|
1121
1286
|
}
|
|
1122
|
-
exportPath(params, format) {
|
|
1287
|
+
exportPath(base, params, format) {
|
|
1123
1288
|
const q = new URLSearchParams();
|
|
1124
1289
|
if (params.from) q.set("from", params.from);
|
|
1125
1290
|
if (params.to) q.set("to", params.to);
|
|
1126
1291
|
if (params.job_id) q.set("job_id", params.job_id);
|
|
1127
1292
|
q.set("format", format);
|
|
1128
|
-
return
|
|
1293
|
+
return `${base}?${q.toString()}`;
|
|
1129
1294
|
}
|
|
1130
1295
|
// ── Attestation receipts (auth) ──────────────────────────────
|
|
1131
1296
|
async listAttestations(params = {}) {
|
|
@@ -1263,14 +1428,48 @@ var VerdifaxClient = class {
|
|
|
1263
1428
|
return this.request("POST", "/dcae/verify", bundle);
|
|
1264
1429
|
}
|
|
1265
1430
|
// ── Admin: API keys (auth) ───────────────────────────────────
|
|
1266
|
-
|
|
1431
|
+
/** Creates a customer key. With `accountId` the key joins that existing
|
|
1432
|
+
* account; without it the key gets an account of its own. A key never
|
|
1433
|
+
* changes account. */
|
|
1434
|
+
async adminCreateKey(name, options = {}) {
|
|
1267
1435
|
this.requireAPIKey();
|
|
1268
1436
|
if (!name) {
|
|
1269
1437
|
throw new VerdifaxError("verdifax: name is required for adminCreateKey");
|
|
1270
1438
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1439
|
+
const body = { name };
|
|
1440
|
+
if (options.accountId !== void 0) {
|
|
1441
|
+
requirePositiveId(options.accountId, "accountId");
|
|
1442
|
+
body.account_id = options.accountId;
|
|
1443
|
+
}
|
|
1444
|
+
return this.request("POST", "/admin/keys", body);
|
|
1445
|
+
}
|
|
1446
|
+
/** Creates an account and its first owner key, whose secret is in the
|
|
1447
|
+
* result this once. The owner key creates the member keys. The account
|
|
1448
|
+
* number is a label Verdifax assigned, not a verified company identity. */
|
|
1449
|
+
async adminCreateAccount(name, options = {}) {
|
|
1450
|
+
this.requireAPIKey();
|
|
1451
|
+
if (typeof name !== "string" || name.trim() === "") {
|
|
1452
|
+
throw new VerdifaxError(
|
|
1453
|
+
"verdifax: name is required for adminCreateAccount"
|
|
1454
|
+
);
|
|
1455
|
+
}
|
|
1456
|
+
const body = { name };
|
|
1457
|
+
if (options.tier !== void 0) body.tier = options.tier;
|
|
1458
|
+
if (options.expiresAt !== void 0) body.expires_at = options.expiresAt;
|
|
1459
|
+
return this.request(
|
|
1460
|
+
"POST",
|
|
1461
|
+
"/admin/accounts",
|
|
1462
|
+
body
|
|
1463
|
+
);
|
|
1464
|
+
}
|
|
1465
|
+
/** Every account, with its key counts. */
|
|
1466
|
+
async adminListAccounts() {
|
|
1467
|
+
this.requireAPIKey();
|
|
1468
|
+
const out = await this.request(
|
|
1469
|
+
"GET",
|
|
1470
|
+
"/admin/accounts"
|
|
1471
|
+
);
|
|
1472
|
+
return out?.accounts ?? [];
|
|
1274
1473
|
}
|
|
1275
1474
|
async adminListKeys() {
|
|
1276
1475
|
this.requireAPIKey();
|
|
@@ -1449,6 +1648,11 @@ var VerdifaxClient = class {
|
|
|
1449
1648
|
return this.signingKey ? signRequestV2(this.signingKey, req) : withExecuteFlags(req);
|
|
1450
1649
|
}
|
|
1451
1650
|
};
|
|
1651
|
+
function requirePositiveId(id, name) {
|
|
1652
|
+
if (!Number.isSafeInteger(id) || id <= 0) {
|
|
1653
|
+
throw new VerdifaxError(`verdifax: ${name} must be a whole number > 0`);
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1452
1656
|
function withSignedText(result, sent) {
|
|
1453
1657
|
return "signed_request" in sent ? { ...result, signed_request: sent.signed_request } : result;
|
|
1454
1658
|
}
|