@limitry/cli 1.0.0-rc.17 → 1.0.0-rc.19
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/CHANGELOG.md +56 -0
- package/README.md +7 -3
- package/dist/limitry.mjs +1130 -574
- package/package.json +2 -2
package/dist/limitry.mjs
CHANGED
|
@@ -239,21 +239,21 @@ var signInOptions = {
|
|
|
239
239
|
emailSignUp: optional.signIn?.emailSignUp ?? "form"
|
|
240
240
|
};
|
|
241
241
|
function resolveProductEnvironments(environments, defaultEnvironment, docs) {
|
|
242
|
-
const
|
|
242
|
+
const list2 = (environments ?? []).map((env) => ({
|
|
243
243
|
name: env.name,
|
|
244
244
|
keyPrefix: env.keyPrefix,
|
|
245
245
|
readOnlyWorkspace: env.readOnlyWorkspace ?? false,
|
|
246
246
|
description: env.description ?? "",
|
|
247
247
|
agentLabel: env.agentLabel ?? env.description ?? ""
|
|
248
248
|
}));
|
|
249
|
-
const names = new Set(
|
|
250
|
-
const prefixes = new Set(
|
|
251
|
-
if (names.size !==
|
|
249
|
+
const names = new Set(list2.map((env) => env.name));
|
|
250
|
+
const prefixes = new Set(list2.map((env) => env.keyPrefix));
|
|
251
|
+
if (names.size !== list2.length || prefixes.size !== list2.length) {
|
|
252
252
|
throw new Error(
|
|
253
253
|
"brand.json environments: each needs its own name and keyPrefix"
|
|
254
254
|
);
|
|
255
255
|
}
|
|
256
|
-
for (const env of
|
|
256
|
+
for (const env of list2) {
|
|
257
257
|
if (!/^[a-z][a-z0-9-]*$/.test(env.name)) {
|
|
258
258
|
throw new Error(`brand.json environment name "${env.name}" is invalid`);
|
|
259
259
|
}
|
|
@@ -274,9 +274,9 @@ function resolveProductEnvironments(environments, defaultEnvironment, docs) {
|
|
|
274
274
|
);
|
|
275
275
|
}
|
|
276
276
|
return {
|
|
277
|
-
list,
|
|
278
|
-
default: defaultEnvironment ??
|
|
279
|
-
docs:
|
|
277
|
+
list: list2,
|
|
278
|
+
default: defaultEnvironment ?? list2[0]?.name ?? null,
|
|
279
|
+
docs: list2.length > 0 ? docs ?? null : null
|
|
280
280
|
};
|
|
281
281
|
}
|
|
282
282
|
var productEnvironments = resolveProductEnvironments(
|
|
@@ -770,42 +770,269 @@ function removeTrailingSlash(url) {
|
|
|
770
770
|
}
|
|
771
771
|
|
|
772
772
|
// node_modules/@limitry/sdk/dist/errors.js
|
|
773
|
-
var
|
|
773
|
+
var BASE_ERROR_NAME = `${brand2.name.split(/[-_]/).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("")}Error`;
|
|
774
|
+
var SdkError = class _SdkError extends Error {
|
|
775
|
+
constructor(message, options) {
|
|
776
|
+
super(message, options);
|
|
777
|
+
this.name = new.target === _SdkError ? BASE_ERROR_NAME : new.target.name;
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
var APIConnectionError = class extends SdkError {
|
|
781
|
+
constructor(options = {}) {
|
|
782
|
+
super(options.message ?? "Could not connect to the API", {
|
|
783
|
+
cause: options.cause
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
var APITimeoutError = class extends APIConnectionError {
|
|
788
|
+
constructor(options = {}) {
|
|
789
|
+
super({ message: "The request timed out", cause: options.cause });
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
var APIError = class extends SdkError {
|
|
793
|
+
/** The HTTP status code. */
|
|
774
794
|
status;
|
|
795
|
+
/** The error's code, to branch on (`not_found`, `rate_limited`, …). */
|
|
775
796
|
code;
|
|
797
|
+
/** The request's id: quote it to support. */
|
|
776
798
|
requestId;
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
799
|
+
/**
|
|
800
|
+
* The response's headers (Retry-After, Server-Timing, the rate-limit
|
|
801
|
+
* ones): empty when the error was not built from a response.
|
|
802
|
+
*/
|
|
803
|
+
headers;
|
|
804
|
+
/** What is wrong with each field, when the API refused the input. */
|
|
805
|
+
details;
|
|
806
|
+
/** A link to the error's entry in the docs. */
|
|
807
|
+
docs;
|
|
808
|
+
constructor(init) {
|
|
809
|
+
super(init.message);
|
|
810
|
+
this.status = init.status;
|
|
811
|
+
this.code = init.code;
|
|
812
|
+
this.requestId = init.requestId;
|
|
813
|
+
this.headers = init.headers ?? new Headers();
|
|
814
|
+
this.details = init.details;
|
|
815
|
+
this.docs = init.docs;
|
|
783
816
|
}
|
|
784
817
|
};
|
|
818
|
+
var BadRequestError = class extends APIError {
|
|
819
|
+
};
|
|
820
|
+
var AuthenticationError = class extends APIError {
|
|
821
|
+
};
|
|
822
|
+
var PlanLimitError = class extends APIError {
|
|
823
|
+
};
|
|
824
|
+
var PermissionDeniedError = class extends APIError {
|
|
825
|
+
};
|
|
826
|
+
var NotFoundError = class extends APIError {
|
|
827
|
+
};
|
|
828
|
+
var ConflictError = class extends APIError {
|
|
829
|
+
};
|
|
830
|
+
var UnprocessableEntityError = class extends APIError {
|
|
831
|
+
};
|
|
832
|
+
var RateLimitError = class extends APIError {
|
|
833
|
+
};
|
|
834
|
+
var InternalServerError = class extends APIError {
|
|
835
|
+
};
|
|
836
|
+
var BY_STATUS = {
|
|
837
|
+
400: BadRequestError,
|
|
838
|
+
401: AuthenticationError,
|
|
839
|
+
402: PlanLimitError,
|
|
840
|
+
403: PermissionDeniedError,
|
|
841
|
+
404: NotFoundError,
|
|
842
|
+
409: ConflictError,
|
|
843
|
+
422: UnprocessableEntityError,
|
|
844
|
+
429: RateLimitError
|
|
845
|
+
};
|
|
846
|
+
function errorClassFor(status) {
|
|
847
|
+
return BY_STATUS[status] ?? (status >= 500 ? InternalServerError : APIError);
|
|
848
|
+
}
|
|
785
849
|
function apiErrorFrom(error, response) {
|
|
786
|
-
const envelope = error
|
|
787
|
-
|
|
850
|
+
const envelope = error !== null && typeof error === "object" ? error : {};
|
|
851
|
+
const body = envelope.error ?? {};
|
|
852
|
+
const ErrorClass = errorClassFor(response.status);
|
|
853
|
+
return new ErrorClass({
|
|
854
|
+
status: response.status,
|
|
855
|
+
code: body.code ?? "http_error",
|
|
856
|
+
message: body.message ?? `HTTP ${response.status}`,
|
|
857
|
+
requestId: body.requestId ?? response.headers.get("x-request-id") ?? void 0,
|
|
858
|
+
headers: response.headers,
|
|
859
|
+
...Array.isArray(body.details) ? { details: body.details } : {},
|
|
860
|
+
...typeof body.docs === "string" ? { docs: body.docs } : {}
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
function connectionErrorFrom(error, signal) {
|
|
864
|
+
if (signal?.aborted)
|
|
865
|
+
return signal.reason;
|
|
866
|
+
if (error instanceof SdkError)
|
|
867
|
+
return error;
|
|
868
|
+
if (error instanceof Error && error.name === "TimeoutError") {
|
|
869
|
+
return new APITimeoutError({ cause: error });
|
|
870
|
+
}
|
|
871
|
+
return new APIConnectionError({ cause: error });
|
|
872
|
+
}
|
|
873
|
+
function withConnectionErrors(fetch2) {
|
|
874
|
+
return async (request) => {
|
|
875
|
+
try {
|
|
876
|
+
return await fetch2(request);
|
|
877
|
+
} catch (error) {
|
|
878
|
+
throw connectionErrorFrom(error, request.signal);
|
|
879
|
+
}
|
|
880
|
+
};
|
|
788
881
|
}
|
|
789
882
|
|
|
790
883
|
// node_modules/@limitry/sdk/dist/product/index.js
|
|
791
884
|
var product_exports = {};
|
|
792
885
|
__export(product_exports, {
|
|
793
|
-
|
|
794
|
-
|
|
886
|
+
LimitReachedError: () => LimitReachedError,
|
|
887
|
+
UnavailableError: () => UnavailableError,
|
|
795
888
|
createLimits: () => createLimits,
|
|
796
889
|
productMethods: () => productMethods,
|
|
797
890
|
productRetry: () => productRetry2
|
|
798
891
|
});
|
|
799
892
|
|
|
893
|
+
// node_modules/@limitry/sdk/dist/pagination.js
|
|
894
|
+
var Page = class {
|
|
895
|
+
/** This page's items. */
|
|
896
|
+
items;
|
|
897
|
+
/** The cursor for the next page; null on the last one. */
|
|
898
|
+
nextCursor;
|
|
899
|
+
#next;
|
|
900
|
+
constructor(body, next) {
|
|
901
|
+
Object.assign(this, body);
|
|
902
|
+
this.items = body.items;
|
|
903
|
+
this.nextCursor = body.nextCursor ?? null;
|
|
904
|
+
this.#next = next;
|
|
905
|
+
}
|
|
906
|
+
/** Whether another page follows this one. */
|
|
907
|
+
hasNextPage() {
|
|
908
|
+
return this.#next !== null && typeof this.nextCursor === "string";
|
|
909
|
+
}
|
|
910
|
+
/** The next page; throws when this is the last one (see hasNextPage). */
|
|
911
|
+
getNextPage() {
|
|
912
|
+
if (!this.hasNextPage()) {
|
|
913
|
+
return Promise.reject(new Error("No next page: check hasNextPage() first"));
|
|
914
|
+
}
|
|
915
|
+
return this.#next(this.nextCursor);
|
|
916
|
+
}
|
|
917
|
+
/** This page and every page after it. */
|
|
918
|
+
async *iterPages() {
|
|
919
|
+
yield this;
|
|
920
|
+
let page = this.hasNextPage() ? await this.getNextPage() : null;
|
|
921
|
+
while (page) {
|
|
922
|
+
yield page;
|
|
923
|
+
page = page.hasNextPage() ? await page.getNextPage() : null;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
/** Every item, from this page on, fetching each next page as it goes. */
|
|
927
|
+
async *[Symbol.asyncIterator]() {
|
|
928
|
+
for await (const page of this.iterPages())
|
|
929
|
+
yield* page.items;
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
var PagePromise = class {
|
|
933
|
+
#page;
|
|
934
|
+
[Symbol.toStringTag] = "PagePromise";
|
|
935
|
+
constructor(page) {
|
|
936
|
+
this.#page = page;
|
|
937
|
+
}
|
|
938
|
+
then(onFulfilled, onRejected) {
|
|
939
|
+
return this.#page.then(onFulfilled, onRejected);
|
|
940
|
+
}
|
|
941
|
+
catch(onRejected) {
|
|
942
|
+
return this.#page.catch(onRejected);
|
|
943
|
+
}
|
|
944
|
+
finally(onFinally) {
|
|
945
|
+
return this.#page.finally(onFinally);
|
|
946
|
+
}
|
|
947
|
+
async *[Symbol.asyncIterator]() {
|
|
948
|
+
yield* await this.#page;
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
function pages(fetch2, paged) {
|
|
952
|
+
const load = (cursor) => new PagePromise(fetch2(cursor).then((body) => new Page(body, paged ? load : null)));
|
|
953
|
+
return load(void 0);
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
// node_modules/@limitry/sdk/dist/resources.js
|
|
957
|
+
var TIMEOUT_HEADER = "x-sdk-timeout";
|
|
958
|
+
async function call(client, op, pathParams, input, options = {}, content) {
|
|
959
|
+
const query = {};
|
|
960
|
+
const body = {};
|
|
961
|
+
for (const [name, value] of Object.entries(input ?? {})) {
|
|
962
|
+
if (value === void 0)
|
|
963
|
+
continue;
|
|
964
|
+
(op.query.includes(name) ? query : body)[name] = value;
|
|
965
|
+
}
|
|
966
|
+
const headers = {
|
|
967
|
+
...options.headers,
|
|
968
|
+
...options.idempotencyKey ? { "idempotency-key": options.idempotencyKey } : {},
|
|
969
|
+
...options.timeout === void 0 ? {} : { [TIMEOUT_HEADER]: String(options.timeout) }
|
|
970
|
+
};
|
|
971
|
+
const request = client.request;
|
|
972
|
+
const raw = op.rawBody ? content instanceof Blob ? content : new Blob([content]) : void 0;
|
|
973
|
+
const { data, error, response } = await request(op.method, op.path, {
|
|
974
|
+
params: { path: pathParams, query },
|
|
975
|
+
...op.hasBody ? { body } : {},
|
|
976
|
+
...raw ? {
|
|
977
|
+
body: raw,
|
|
978
|
+
bodySerializer: (value) => value,
|
|
979
|
+
headers: { "content-type": raw.type || op.rawBody, ...headers }
|
|
980
|
+
} : { headers },
|
|
981
|
+
...op.rawResponse ? { parseAs: "blob" } : {},
|
|
982
|
+
signal: options.signal
|
|
983
|
+
});
|
|
984
|
+
if (error !== void 0 || !response.ok) {
|
|
985
|
+
throw apiErrorFrom(error, response);
|
|
986
|
+
}
|
|
987
|
+
return data;
|
|
988
|
+
}
|
|
989
|
+
function list(client, op, pathParams, input, options = {}, paged = true) {
|
|
990
|
+
return pages((cursor) => call(client, op, pathParams, cursor === void 0 ? input : { ...input, cursor }, options), paged);
|
|
991
|
+
}
|
|
992
|
+
|
|
800
993
|
// node_modules/@limitry/sdk/dist/retry.js
|
|
801
994
|
var WRITES = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
802
995
|
var RETRY_STATUSES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
|
|
803
996
|
var DEFAULT_MAX_RETRIES = 2;
|
|
804
|
-
var MAX_WAIT_MS =
|
|
997
|
+
var MAX_WAIT_MS = 6e4;
|
|
805
998
|
var MAX_BASE_KEY = 200;
|
|
806
999
|
var PRODUCT_RETRY_HEADER = "x-sdk-product-retry";
|
|
1000
|
+
var DEFAULT_TIMEOUT_MS = 6e4;
|
|
1001
|
+
function withAttemptTimeout(fetch2, ms) {
|
|
1002
|
+
return (request) => {
|
|
1003
|
+
const asked = Number(request.headers.get(TIMEOUT_HEADER));
|
|
1004
|
+
const limit = asked > 0 ? asked : ms;
|
|
1005
|
+
const headers = new Headers(request.headers);
|
|
1006
|
+
headers.delete(TIMEOUT_HEADER);
|
|
1007
|
+
return fetch2(new Request(request, {
|
|
1008
|
+
headers,
|
|
1009
|
+
signal: AbortSignal.any([
|
|
1010
|
+
request.signal,
|
|
1011
|
+
AbortSignal.timeout(Math.max(1, Math.round(limit)))
|
|
1012
|
+
])
|
|
1013
|
+
}));
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
807
1016
|
var productRetry = () => "productRetry" in product_exports ? Reflect.get(product_exports, "productRetry") ?? null : null;
|
|
808
1017
|
var wait = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
1018
|
+
function pause(sleep, ms, signal) {
|
|
1019
|
+
if (signal.aborted)
|
|
1020
|
+
return Promise.reject(signal.reason);
|
|
1021
|
+
return new Promise((done, fail) => {
|
|
1022
|
+
const abort = () => fail(signal.reason);
|
|
1023
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
1024
|
+
sleep(ms).then(() => {
|
|
1025
|
+
signal.removeEventListener("abort", abort);
|
|
1026
|
+
if (signal.aborted)
|
|
1027
|
+
fail(signal.reason);
|
|
1028
|
+
else
|
|
1029
|
+
done();
|
|
1030
|
+
}, (error) => {
|
|
1031
|
+
signal.removeEventListener("abort", abort);
|
|
1032
|
+
fail(error);
|
|
1033
|
+
});
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
809
1036
|
function backoff(attempt) {
|
|
810
1037
|
const base = Math.min(500 * 2 ** attempt, 8e3);
|
|
811
1038
|
return base * (0.75 + Math.random() * 0.25);
|
|
@@ -868,7 +1095,7 @@ function withRetries(fetch2, options = {}) {
|
|
|
868
1095
|
} catch (error) {
|
|
869
1096
|
if (last || request.signal.aborted)
|
|
870
1097
|
throw error;
|
|
871
|
-
await sleep
|
|
1098
|
+
await pause(sleep, backoff(attempt), request.signal);
|
|
872
1099
|
continue;
|
|
873
1100
|
}
|
|
874
1101
|
const laterMs = later ? await later.wait(response, laterTries) : null;
|
|
@@ -879,7 +1106,7 @@ function withRetries(fetch2, options = {}) {
|
|
|
879
1106
|
laterTries++;
|
|
880
1107
|
laterWaited += laterMs;
|
|
881
1108
|
await response.body?.cancel();
|
|
882
|
-
await sleep
|
|
1109
|
+
await pause(sleep, laterMs, request.signal);
|
|
883
1110
|
attempt--;
|
|
884
1111
|
continue;
|
|
885
1112
|
}
|
|
@@ -889,7 +1116,7 @@ function withRetries(fetch2, options = {}) {
|
|
|
889
1116
|
if (delay > MAX_WAIT_MS)
|
|
890
1117
|
return response;
|
|
891
1118
|
await response.body?.cancel();
|
|
892
|
-
await sleep
|
|
1119
|
+
await pause(sleep, delay, request.signal);
|
|
893
1120
|
}
|
|
894
1121
|
};
|
|
895
1122
|
}
|
|
@@ -958,43 +1185,76 @@ function checkedCost(units) {
|
|
|
958
1185
|
}
|
|
959
1186
|
return units;
|
|
960
1187
|
}
|
|
961
|
-
var
|
|
1188
|
+
var LimitReachedError = class extends SdkError {
|
|
962
1189
|
reason;
|
|
963
1190
|
/** The limit that refused; null for too many open reservations. */
|
|
964
1191
|
limitId;
|
|
1192
|
+
limitName;
|
|
965
1193
|
retryAfterSeconds;
|
|
966
1194
|
decision;
|
|
967
1195
|
constructor(decision) {
|
|
968
1196
|
super(decision.reason?.message ?? "Refused");
|
|
969
|
-
this.name = "
|
|
1197
|
+
this.name = "LimitReachedError";
|
|
970
1198
|
this.reason = decision.reason?.code ?? "limit_reached";
|
|
971
1199
|
this.limitId = decision.reason?.limitId ?? null;
|
|
1200
|
+
this.limitName = decision.reason?.limitName ?? null;
|
|
972
1201
|
this.retryAfterSeconds = decision.retryAfterSeconds ?? null;
|
|
973
1202
|
this.decision = decision;
|
|
974
1203
|
}
|
|
975
1204
|
};
|
|
976
|
-
var
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1205
|
+
var UnavailableError = class extends SdkError {
|
|
1206
|
+
reason;
|
|
1207
|
+
constructor(reason, options) {
|
|
1208
|
+
super(`Limitry gave no decision (${reason}) and a limit refuses when unreachable`, options);
|
|
1209
|
+
this.name = "UnavailableError";
|
|
1210
|
+
this.reason = reason;
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
var NoDecision = class {
|
|
1214
|
+
// Plain fields, not parameter properties: Node's type stripping (the
|
|
1215
|
+
// docs build and the Python parity check import this file) refuses them.
|
|
1216
|
+
reason;
|
|
1217
|
+
cause;
|
|
1218
|
+
constructor(reason, cause) {
|
|
1219
|
+
this.reason = reason;
|
|
1220
|
+
this.cause = cause;
|
|
1221
|
+
}
|
|
1222
|
+
/** No answer in time: unlike an error, the check may have been decided. */
|
|
1223
|
+
get timedOut() {
|
|
1224
|
+
return this.reason === "timeout";
|
|
980
1225
|
}
|
|
981
1226
|
};
|
|
982
|
-
var UNREACHABLE = /* @__PURE__ */ Symbol("unreachable");
|
|
983
|
-
var TIMED_OUT = /* @__PURE__ */ Symbol("timed out");
|
|
984
1227
|
var FINISH_TIMEOUT_MS = 5e3;
|
|
985
1228
|
var wait2 = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
1229
|
+
function abortable(work, signal) {
|
|
1230
|
+
if (!signal)
|
|
1231
|
+
return work;
|
|
1232
|
+
if (signal.aborted)
|
|
1233
|
+
return Promise.reject(signal.reason);
|
|
1234
|
+
return new Promise((resolve2, reject) => {
|
|
1235
|
+
const stop = () => reject(signal.reason);
|
|
1236
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
1237
|
+
work.then((value) => {
|
|
1238
|
+
signal.removeEventListener("abort", stop);
|
|
1239
|
+
resolve2(value);
|
|
1240
|
+
}, (error) => {
|
|
1241
|
+
signal.removeEventListener("abort", stop);
|
|
1242
|
+
reject(error);
|
|
1243
|
+
});
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
986
1246
|
function retryAfterMs(response) {
|
|
987
1247
|
const value = response.headers.get("retry-after");
|
|
988
1248
|
const seconds = value === null ? NaN : Number(value);
|
|
989
1249
|
return Number.isFinite(seconds) ? seconds * 1e3 : void 0;
|
|
990
1250
|
}
|
|
991
1251
|
function createLimits(client, options = {}, internals = {}) {
|
|
992
|
-
const
|
|
1252
|
+
const defaultTimeout = options.timeout ?? 1500;
|
|
993
1253
|
const sleep = internals.sleep ?? wait2;
|
|
994
1254
|
const random = internals.random ?? Math.random;
|
|
995
1255
|
const remembered = /* @__PURE__ */ new Map();
|
|
996
1256
|
const key = (s, action) => `${s.kind}\0${s.id}\0${action}`;
|
|
997
|
-
const failMode = (
|
|
1257
|
+
const failMode = (r) => r.failMode ?? options.failMode ?? remembered.get(key(r.subject, r.action)) ?? "open";
|
|
998
1258
|
const concurrentAmounts = /* @__PURE__ */ new Map();
|
|
999
1259
|
const running = /* @__PURE__ */ new Map();
|
|
1000
1260
|
const remember = (s, action, decision) => {
|
|
@@ -1007,15 +1267,13 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1007
1267
|
} else {
|
|
1008
1268
|
concurrentAmounts.delete(key(s, action));
|
|
1009
1269
|
}
|
|
1010
|
-
if (options.failMode)
|
|
1011
|
-
return;
|
|
1012
1270
|
const closed = decision.limits.some((r) => r.failMode === "closed");
|
|
1013
1271
|
remembered.set(key(s, action), closed ? "closed" : "open");
|
|
1014
1272
|
if (remembered.size > 1e4) {
|
|
1015
1273
|
remembered.delete(remembered.keys().next().value);
|
|
1016
1274
|
}
|
|
1017
1275
|
};
|
|
1018
|
-
function budget(budgetMs) {
|
|
1276
|
+
function budget(budgetMs, signal) {
|
|
1019
1277
|
const started = Date.now();
|
|
1020
1278
|
let slept = 0;
|
|
1021
1279
|
return {
|
|
@@ -1023,27 +1281,29 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1023
1281
|
left: () => Math.ceil(budgetMs - Math.max(Date.now() - started, slept)),
|
|
1024
1282
|
async sleep(ms) {
|
|
1025
1283
|
slept += ms;
|
|
1026
|
-
await sleep(ms);
|
|
1284
|
+
await abortable(sleep(ms), signal);
|
|
1027
1285
|
}
|
|
1028
1286
|
};
|
|
1029
1287
|
}
|
|
1030
|
-
async function check(body, idempotencyKey, budgetMs
|
|
1031
|
-
const time = budget(budgetMs);
|
|
1288
|
+
async function check(body, idempotencyKey, budgetMs, finishOnly = false, signal) {
|
|
1289
|
+
const time = budget(budgetMs, signal);
|
|
1032
1290
|
for (let tries = 0; ; tries++) {
|
|
1033
|
-
const answer2 = await checkOnce(body, idempotencyKey, Math.max(1, time.left()), finishOnly);
|
|
1291
|
+
const answer2 = await checkOnce(body, idempotencyKey, Math.max(1, time.left()), finishOnly, signal);
|
|
1034
1292
|
if (answer2.kind !== "later")
|
|
1035
1293
|
return answer2.value;
|
|
1036
|
-
const
|
|
1037
|
-
if (
|
|
1038
|
-
return
|
|
1039
|
-
await time.sleep(
|
|
1294
|
+
const pause2 = retryWaitMs(answer2.retryAfterMs, tries, random);
|
|
1295
|
+
if (pause2 >= time.left())
|
|
1296
|
+
return new NoDecision("unreachable");
|
|
1297
|
+
await time.sleep(pause2);
|
|
1040
1298
|
}
|
|
1041
1299
|
}
|
|
1042
|
-
async function checkOnce(body, idempotencyKey, wait3, finishOnly) {
|
|
1300
|
+
async function checkOnce(body, idempotencyKey, wait3, finishOnly, signal) {
|
|
1301
|
+
signal?.throwIfAborted();
|
|
1043
1302
|
let timer;
|
|
1044
1303
|
const late = new Promise((resolve2) => {
|
|
1045
|
-
timer = setTimeout(() => resolve2(
|
|
1304
|
+
timer = setTimeout(() => resolve2(new NoDecision("timeout")), wait3);
|
|
1046
1305
|
});
|
|
1306
|
+
const deadline = AbortSignal.timeout(wait3);
|
|
1047
1307
|
const asked = (async () => {
|
|
1048
1308
|
try {
|
|
1049
1309
|
const { data, error, response } = await client.POST("/checks", {
|
|
@@ -1055,25 +1315,27 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1055
1315
|
[PRODUCT_RETRY_HEADER]: "return",
|
|
1056
1316
|
...finishOnly ? { "limitry-finish-only": "1" } : {}
|
|
1057
1317
|
},
|
|
1058
|
-
signal: AbortSignal.
|
|
1318
|
+
signal: signal ? AbortSignal.any([deadline, signal]) : deadline
|
|
1059
1319
|
});
|
|
1060
1320
|
if (data)
|
|
1061
1321
|
return data;
|
|
1062
1322
|
if (isRetryLater(response, error))
|
|
1063
1323
|
return { later: retryAfterMs(response) };
|
|
1064
|
-
if (response.status === 402
|
|
1065
|
-
return
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
return
|
|
1324
|
+
if (response.status === 402)
|
|
1325
|
+
return new NoDecision("plan_limit_reached", apiErrorFrom(error, response));
|
|
1326
|
+
if (response.status === 429)
|
|
1327
|
+
return new NoDecision("rate_limited", apiErrorFrom(error, response));
|
|
1328
|
+
if (response.status < 500)
|
|
1329
|
+
return apiErrorFrom(error, response);
|
|
1330
|
+
return new NoDecision("unreachable", apiErrorFrom(error, response));
|
|
1071
1331
|
} catch (error) {
|
|
1072
|
-
|
|
1332
|
+
if (signal?.aborted)
|
|
1333
|
+
throw signal.reason;
|
|
1334
|
+
return error?.name === "TimeoutError" || error instanceof APITimeoutError ? new NoDecision("timeout", error) : new NoDecision("unreachable", error);
|
|
1073
1335
|
}
|
|
1074
1336
|
})();
|
|
1075
1337
|
try {
|
|
1076
|
-
const answer2 = await Promise.race([asked, late]);
|
|
1338
|
+
const answer2 = await abortable(Promise.race([asked, late]), signal);
|
|
1077
1339
|
if (answer2 instanceof Error)
|
|
1078
1340
|
throw answer2;
|
|
1079
1341
|
if (typeof answer2 === "object" && "later" in answer2)
|
|
@@ -1083,7 +1345,7 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1083
1345
|
clearTimeout(timer);
|
|
1084
1346
|
}
|
|
1085
1347
|
}
|
|
1086
|
-
async function settle(id, action, cost) {
|
|
1348
|
+
async function settle(id, action, timeoutMs, cost) {
|
|
1087
1349
|
const idempotencyKey = crypto.randomUUID();
|
|
1088
1350
|
const time = budget(timeoutMs);
|
|
1089
1351
|
for (let tries = 0; ; tries++) {
|
|
@@ -1112,10 +1374,10 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1112
1374
|
await time.sleep(retryMs);
|
|
1113
1375
|
}
|
|
1114
1376
|
}
|
|
1115
|
-
async function releaseUnheard(body, idempotencyKey) {
|
|
1116
|
-
const replay = await check(body, idempotencyKey);
|
|
1117
|
-
if (
|
|
1118
|
-
await settle(replay.reservation.id, "release");
|
|
1377
|
+
async function releaseUnheard(body, idempotencyKey, timeoutMs) {
|
|
1378
|
+
const replay = await check(body, idempotencyKey, timeoutMs);
|
|
1379
|
+
if (!(replay instanceof NoDecision) && replay.reservation) {
|
|
1380
|
+
await settle(replay.reservation.id, "release", timeoutMs);
|
|
1119
1381
|
}
|
|
1120
1382
|
}
|
|
1121
1383
|
return {
|
|
@@ -1124,38 +1386,45 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1124
1386
|
* subjects): used, remaining, resetsAt — for showing an end user. Call
|
|
1125
1387
|
* it from your server; a key never belongs in a browser. Not a check:
|
|
1126
1388
|
* nothing is counted; a subject with no limit gets an empty `limits`.
|
|
1127
|
-
* Throws on an error answer.
|
|
1389
|
+
* Throws the API's error (APIError) on an error answer.
|
|
1128
1390
|
*/
|
|
1129
1391
|
async standing(request) {
|
|
1130
|
-
const { data, error, response } = await client.GET("/
|
|
1392
|
+
const { data, error, response } = await client.GET("/subjects/{subjectKind}/{subjectId}/standing", {
|
|
1131
1393
|
params: {
|
|
1394
|
+
path: {
|
|
1395
|
+
subjectKind: request.subject.kind,
|
|
1396
|
+
subjectId: request.subject.id
|
|
1397
|
+
},
|
|
1132
1398
|
query: {
|
|
1133
|
-
subject: `${request.subject.kind}:${request.subject.id}`,
|
|
1134
1399
|
...request.shared?.length ? {
|
|
1135
1400
|
shared: request.shared.map((s) => `${s.kind}:${s.id}`).join(",")
|
|
1136
1401
|
} : {}
|
|
1137
1402
|
}
|
|
1138
|
-
}
|
|
1403
|
+
},
|
|
1404
|
+
...request.signal ? { signal: request.signal } : {}
|
|
1139
1405
|
});
|
|
1140
1406
|
if (data)
|
|
1141
1407
|
return data;
|
|
1142
|
-
throw
|
|
1408
|
+
throw apiErrorFrom(error, response);
|
|
1143
1409
|
},
|
|
1144
1410
|
/** Checks `cost`, runs `fn` only if allowed, and returns its result. */
|
|
1145
1411
|
async guard(request, fn) {
|
|
1412
|
+
request.signal?.throwIfAborted();
|
|
1146
1413
|
const body = {
|
|
1147
1414
|
subject: request.subject,
|
|
1148
1415
|
shared: request.shared,
|
|
1149
1416
|
action: request.action,
|
|
1150
1417
|
cost: request.cost ?? 1
|
|
1151
1418
|
};
|
|
1152
|
-
const idempotencyKey = crypto.randomUUID();
|
|
1153
|
-
const decision = await check(body, idempotencyKey);
|
|
1154
|
-
if (decision
|
|
1155
|
-
if (failMode(request
|
|
1156
|
-
throw new
|
|
1419
|
+
const idempotencyKey = request.idempotencyKey ?? crypto.randomUUID();
|
|
1420
|
+
const decision = await check(body, idempotencyKey, request.timeout ?? defaultTimeout, false, request.signal);
|
|
1421
|
+
if (decision instanceof NoDecision) {
|
|
1422
|
+
if (failMode(request) === "closed") {
|
|
1423
|
+
throw new UnavailableError(decision.reason, {
|
|
1424
|
+
cause: decision.cause
|
|
1425
|
+
});
|
|
1157
1426
|
}
|
|
1158
|
-
if (decision
|
|
1427
|
+
if (decision.timedOut) {
|
|
1159
1428
|
void check(body, idempotencyKey, FINISH_TIMEOUT_MS, true).catch(() => {
|
|
1160
1429
|
});
|
|
1161
1430
|
}
|
|
@@ -1163,7 +1432,7 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1163
1432
|
}
|
|
1164
1433
|
remember(request.subject, request.action, decision);
|
|
1165
1434
|
if (!decision.allowed)
|
|
1166
|
-
throw new
|
|
1435
|
+
throw new LimitReachedError(decision);
|
|
1167
1436
|
return fn();
|
|
1168
1437
|
},
|
|
1169
1438
|
/**
|
|
@@ -1173,6 +1442,7 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1173
1442
|
* is taken for exactly as long as `fn` runs.
|
|
1174
1443
|
*/
|
|
1175
1444
|
async reserve(request, fn) {
|
|
1445
|
+
request.signal?.throwIfAborted();
|
|
1176
1446
|
const reserved = request.cost ?? 1;
|
|
1177
1447
|
const body = {
|
|
1178
1448
|
subject: request.subject,
|
|
@@ -1182,7 +1452,7 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1182
1452
|
mode: "reserve",
|
|
1183
1453
|
ttlSeconds: request.ttlSeconds
|
|
1184
1454
|
};
|
|
1185
|
-
const idempotencyKey = crypto.randomUUID();
|
|
1455
|
+
const idempotencyKey = request.idempotencyKey ?? crypto.randomUUID();
|
|
1186
1456
|
const slot = key(request.subject, request.action);
|
|
1187
1457
|
const before = running.get(slot) ?? 0;
|
|
1188
1458
|
running.set(slot, before + 1);
|
|
@@ -1199,7 +1469,16 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1199
1469
|
};
|
|
1200
1470
|
async function reserveOnce(request, fn, body, idempotencyKey, before) {
|
|
1201
1471
|
const reserved = request.cost ?? 1;
|
|
1202
|
-
const
|
|
1472
|
+
const timeoutMs = request.timeout ?? defaultTimeout;
|
|
1473
|
+
let decision;
|
|
1474
|
+
try {
|
|
1475
|
+
decision = await check(body, idempotencyKey, timeoutMs, false, request.signal);
|
|
1476
|
+
} catch (error) {
|
|
1477
|
+
if (request.signal?.aborted)
|
|
1478
|
+
void releaseUnheard(body, idempotencyKey, timeoutMs).catch(() => {
|
|
1479
|
+
});
|
|
1480
|
+
throw error;
|
|
1481
|
+
}
|
|
1203
1482
|
const uncounted = {
|
|
1204
1483
|
// Checked even uncounted: the mistake shows whether or not
|
|
1205
1484
|
// Limitry answered.
|
|
@@ -1207,13 +1486,14 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1207
1486
|
extend: async () => {
|
|
1208
1487
|
}
|
|
1209
1488
|
};
|
|
1210
|
-
if (decision
|
|
1211
|
-
const
|
|
1489
|
+
if (decision instanceof NoDecision) {
|
|
1490
|
+
const none = decision;
|
|
1491
|
+
const unheard = () => none.timedOut ? releaseUnheard(body, idempotencyKey, timeoutMs) : Promise.resolve();
|
|
1212
1492
|
const amount = concurrentAmounts.get(key(request.subject, request.action));
|
|
1213
|
-
if (failMode(request
|
|
1493
|
+
if (failMode(request) === "closed" || // Open, but never past a concurrent limit's amount here.
|
|
1214
1494
|
amount !== void 0 && before >= amount) {
|
|
1215
1495
|
await unheard();
|
|
1216
|
-
throw new
|
|
1496
|
+
throw new UnavailableError(none.reason, { cause: none.cause });
|
|
1217
1497
|
}
|
|
1218
1498
|
try {
|
|
1219
1499
|
return await fn(uncounted);
|
|
@@ -1223,7 +1503,7 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1223
1503
|
}
|
|
1224
1504
|
remember(request.subject, request.action, decision);
|
|
1225
1505
|
if (!decision.allowed || !decision.reservation) {
|
|
1226
|
-
throw new
|
|
1506
|
+
throw new LimitReachedError(decision);
|
|
1227
1507
|
}
|
|
1228
1508
|
const id = decision.reservation.id;
|
|
1229
1509
|
let used = reserved;
|
|
@@ -1245,10 +1525,10 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1245
1525
|
try {
|
|
1246
1526
|
result = await fn(reservation);
|
|
1247
1527
|
} catch (error) {
|
|
1248
|
-
await settle(id, "release");
|
|
1528
|
+
await settle(id, "release", timeoutMs);
|
|
1249
1529
|
throw error;
|
|
1250
1530
|
}
|
|
1251
|
-
await settle(id, "commit", used);
|
|
1531
|
+
await settle(id, "commit", timeoutMs, used);
|
|
1252
1532
|
return result;
|
|
1253
1533
|
}
|
|
1254
1534
|
}
|
|
@@ -1268,37 +1548,6 @@ var productMethods = (client) => {
|
|
|
1268
1548
|
};
|
|
1269
1549
|
var productRetry2 = movingRetry();
|
|
1270
1550
|
|
|
1271
|
-
// node_modules/@limitry/sdk/dist/resources.js
|
|
1272
|
-
async function call(client, op, pathParams, input, options = {}, content) {
|
|
1273
|
-
const query = {};
|
|
1274
|
-
const body = {};
|
|
1275
|
-
for (const [name, value] of Object.entries(input ?? {})) {
|
|
1276
|
-
if (value === void 0)
|
|
1277
|
-
continue;
|
|
1278
|
-
(op.query.includes(name) ? query : body)[name] = value;
|
|
1279
|
-
}
|
|
1280
|
-
const headers = {
|
|
1281
|
-
...options.headers,
|
|
1282
|
-
...options.idempotencyKey ? { "idempotency-key": options.idempotencyKey } : {}
|
|
1283
|
-
};
|
|
1284
|
-
const request = client.request;
|
|
1285
|
-
const raw = op.rawBody ? content instanceof Blob ? content : new Blob([content]) : void 0;
|
|
1286
|
-
const { data, error, response } = await request(op.method, op.path, {
|
|
1287
|
-
params: { path: pathParams, query },
|
|
1288
|
-
...op.hasBody ? { body } : {},
|
|
1289
|
-
...raw ? {
|
|
1290
|
-
body: raw,
|
|
1291
|
-
bodySerializer: (value) => value,
|
|
1292
|
-
headers: { "content-type": raw.type || op.rawBody, ...headers }
|
|
1293
|
-
} : { headers },
|
|
1294
|
-
...op.rawResponse ? { parseAs: "blob" } : {}
|
|
1295
|
-
});
|
|
1296
|
-
if (error !== void 0 || !response.ok) {
|
|
1297
|
-
throw apiErrorFrom(error, response);
|
|
1298
|
-
}
|
|
1299
|
-
return data;
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
1551
|
// node_modules/@limitry/sdk/dist/resources.gen.js
|
|
1303
1552
|
function resources(client) {
|
|
1304
1553
|
return {
|
|
@@ -1306,6 +1555,10 @@ function resources(client) {
|
|
|
1306
1555
|
create: (
|
|
1307
1556
|
/** Check whether a subject may act */
|
|
1308
1557
|
(input, options) => call(client, { "method": "post", "path": "/checks", "query": [], "hasBody": true }, {}, input, options)
|
|
1558
|
+
),
|
|
1559
|
+
list: (
|
|
1560
|
+
/** List checks */
|
|
1561
|
+
(input, options) => list(client, { "method": "get", "path": "/checks", "query": ["limit", "cursor", "before", "subject", "refused"], "hasBody": false }, {}, input, options, true)
|
|
1309
1562
|
)
|
|
1310
1563
|
},
|
|
1311
1564
|
limits: {
|
|
@@ -1322,9 +1575,13 @@ function resources(client) {
|
|
|
1322
1575
|
/** Add credits to a balance */
|
|
1323
1576
|
(limitId, input, options) => call(client, { "method": "post", "path": "/limits/{limitId}/credits", "query": [], "hasBody": true }, { "limitId": limitId }, input, options)
|
|
1324
1577
|
),
|
|
1578
|
+
get: (
|
|
1579
|
+
/** Get a credit */
|
|
1580
|
+
(limitId, creditId, options) => call(client, { "method": "get", "path": "/limits/{limitId}/credits/{creditId}", "query": [], "hasBody": false }, { "limitId": limitId, "creditId": creditId }, void 0, options)
|
|
1581
|
+
),
|
|
1325
1582
|
list: (
|
|
1326
1583
|
/** List a balance's credits */
|
|
1327
|
-
(limitId, input, options) =>
|
|
1584
|
+
(limitId, input, options) => list(client, { "method": "get", "path": "/limits/{limitId}/credits", "query": ["limit", "cursor", "before", "subjectId"], "hasBody": false }, { "limitId": limitId }, input, options, true)
|
|
1328
1585
|
)
|
|
1329
1586
|
},
|
|
1330
1587
|
get: (
|
|
@@ -1333,7 +1590,7 @@ function resources(client) {
|
|
|
1333
1590
|
),
|
|
1334
1591
|
list: (
|
|
1335
1592
|
/** List limits */
|
|
1336
|
-
(input, options) =>
|
|
1593
|
+
(input, options) => list(client, { "method": "get", "path": "/limits", "query": ["limit", "cursor", "subjectKind", "action", "archived"], "hasBody": false }, {}, input, options, true)
|
|
1337
1594
|
),
|
|
1338
1595
|
restore: (
|
|
1339
1596
|
/** Restore an archived limit */
|
|
@@ -1357,6 +1614,10 @@ function resources(client) {
|
|
|
1357
1614
|
/** Extend a reservation */
|
|
1358
1615
|
(reservationId, input, options) => call(client, { "method": "post", "path": "/reservations/{reservationId}/extend", "query": [], "hasBody": true }, { "reservationId": reservationId }, input, options)
|
|
1359
1616
|
),
|
|
1617
|
+
get: (
|
|
1618
|
+
/** Get a reservation */
|
|
1619
|
+
(reservationId, options) => call(client, { "method": "get", "path": "/reservations/{reservationId}", "query": [], "hasBody": false }, { "reservationId": reservationId }, void 0, options)
|
|
1620
|
+
),
|
|
1360
1621
|
release: (
|
|
1361
1622
|
/** Release a reservation */
|
|
1362
1623
|
(reservationId, options) => call(client, { "method": "post", "path": "/reservations/{reservationId}/release", "query": [], "hasBody": false }, { "reservationId": reservationId }, void 0, options)
|
|
@@ -1367,12 +1628,30 @@ function resources(client) {
|
|
|
1367
1628
|
/** Get a subject */
|
|
1368
1629
|
(subjectKind, subjectId, options) => call(client, { "method": "get", "path": "/subjects/{subjectKind}/{subjectId}", "query": [], "hasBody": false }, { "subjectKind": subjectKind, "subjectId": subjectId }, void 0, options)
|
|
1369
1630
|
),
|
|
1631
|
+
import: (
|
|
1632
|
+
/** Name many subjects */
|
|
1633
|
+
(input, options) => call(client, { "method": "post", "path": "/subjects/import", "query": [], "hasBody": true }, {}, input, options)
|
|
1634
|
+
),
|
|
1635
|
+
list: (
|
|
1636
|
+
/** List subjects */
|
|
1637
|
+
(input, options) => list(client, { "method": "get", "path": "/subjects", "query": ["limit", "cursor", "kind", "label", "q"], "hasBody": false }, {}, input, options, true)
|
|
1638
|
+
),
|
|
1639
|
+
names: {
|
|
1640
|
+
delete: (
|
|
1641
|
+
/** Erase a subject's name and labels */
|
|
1642
|
+
(subjectKind, subjectId, options) => call(client, { "method": "delete", "path": "/subjects/{subjectKind}/{subjectId}/names", "query": [], "hasBody": false }, { "subjectKind": subjectKind, "subjectId": subjectId }, void 0, options)
|
|
1643
|
+
)
|
|
1644
|
+
},
|
|
1370
1645
|
reset: (
|
|
1371
1646
|
/** Reset a subject's limits */
|
|
1372
1647
|
(subjectKind, subjectId, input, options) => call(client, { "method": "post", "path": "/subjects/{subjectKind}/{subjectId}/reset", "query": [], "hasBody": true }, { "subjectKind": subjectKind, "subjectId": subjectId }, input, options)
|
|
1373
1648
|
),
|
|
1649
|
+
standing: (
|
|
1650
|
+
/** Get where a subject stands */
|
|
1651
|
+
(subjectKind, subjectId, input, options) => call(client, { "method": "get", "path": "/subjects/{subjectKind}/{subjectId}/standing", "query": ["shared"], "hasBody": false }, { "subjectKind": subjectKind, "subjectId": subjectId }, input, options)
|
|
1652
|
+
),
|
|
1374
1653
|
update: (
|
|
1375
|
-
/**
|
|
1654
|
+
/** Update a subject */
|
|
1376
1655
|
(subjectKind, subjectId, input, options) => call(client, { "method": "patch", "path": "/subjects/{subjectKind}/{subjectId}", "query": [], "hasBody": true }, { "subjectKind": subjectKind, "subjectId": subjectId }, input, options)
|
|
1377
1656
|
)
|
|
1378
1657
|
},
|
|
@@ -1385,13 +1664,9 @@ function resources(client) {
|
|
|
1385
1664
|
/** Get a limit's usage over time */
|
|
1386
1665
|
(input, options) => call(client, { "method": "get", "path": "/usage", "query": ["limitId", "limitName", "subject", "period", "from", "to", "granularity"], "hasBody": false }, {}, input, options)
|
|
1387
1666
|
),
|
|
1388
|
-
standing: (
|
|
1389
|
-
/** Get where a subject stands */
|
|
1390
|
-
(input, options) => call(client, { "method": "get", "path": "/usage/standing", "query": ["subject", "shared"], "hasBody": false }, {}, input, options)
|
|
1391
|
-
),
|
|
1392
1667
|
subjects: (
|
|
1393
1668
|
/** List who is using a limit */
|
|
1394
|
-
(input, options) => call(client, { "method": "get", "path": "/usage/subjects", "query": ["limitId", "limitName", "period", "from", "to", "sort", "
|
|
1669
|
+
(input, options) => call(client, { "method": "get", "path": "/usage/subjects", "query": ["limitId", "limitName", "period", "from", "to", "sort", "top"], "hasBody": false }, {}, input, options)
|
|
1395
1670
|
)
|
|
1396
1671
|
},
|
|
1397
1672
|
user: {
|
|
@@ -1408,7 +1683,7 @@ function resources(client) {
|
|
|
1408
1683
|
approvalActions: {
|
|
1409
1684
|
list: (
|
|
1410
1685
|
/** List the actions you can ask approval for */
|
|
1411
|
-
(options) =>
|
|
1686
|
+
(options) => list(client, { "method": "get", "path": "/workspace/approval-actions", "query": [], "hasBody": false }, {}, void 0, options, false)
|
|
1412
1687
|
)
|
|
1413
1688
|
},
|
|
1414
1689
|
approvalRequests: {
|
|
@@ -1418,23 +1693,23 @@ function resources(client) {
|
|
|
1418
1693
|
),
|
|
1419
1694
|
get: (
|
|
1420
1695
|
/** Check an approval request */
|
|
1421
|
-
(
|
|
1696
|
+
(approvalRequestId, options) => call(client, { "method": "get", "path": "/workspace/approval-requests/{approvalRequestId}", "query": [], "hasBody": false }, { "approvalRequestId": approvalRequestId }, void 0, options)
|
|
1422
1697
|
),
|
|
1423
1698
|
redeem: (
|
|
1424
1699
|
/** Redeem an approved request */
|
|
1425
|
-
(
|
|
1700
|
+
(approvalRequestId, options) => call(client, { "method": "post", "path": "/workspace/approval-requests/{approvalRequestId}/redeem", "query": [], "hasBody": false }, { "approvalRequestId": approvalRequestId }, void 0, options)
|
|
1426
1701
|
)
|
|
1427
1702
|
},
|
|
1428
1703
|
auditEvents: {
|
|
1429
1704
|
list: (
|
|
1430
1705
|
/** List workspace audit events */
|
|
1431
|
-
(input, options) =>
|
|
1706
|
+
(input, options) => list(client, { "method": "get", "path": "/workspace/audit-events", "query": ["limit", "cursor", "before", "action", "actor"], "hasBody": false }, {}, input, options, true)
|
|
1432
1707
|
)
|
|
1433
1708
|
},
|
|
1434
1709
|
eventTypes: {
|
|
1435
1710
|
list: (
|
|
1436
1711
|
/** List event types */
|
|
1437
|
-
(options) =>
|
|
1712
|
+
(options) => list(client, { "method": "get", "path": "/workspace/event-types", "query": [], "hasBody": false }, {}, void 0, options, false)
|
|
1438
1713
|
)
|
|
1439
1714
|
},
|
|
1440
1715
|
get: (
|
|
@@ -1444,29 +1719,31 @@ function resources(client) {
|
|
|
1444
1719
|
invitations: {
|
|
1445
1720
|
list: (
|
|
1446
1721
|
/** List pending invitations */
|
|
1447
|
-
(input, options) =>
|
|
1722
|
+
(input, options) => list(client, { "method": "get", "path": "/workspace/invitations", "query": ["limit", "cursor"], "hasBody": false }, {}, input, options, true)
|
|
1448
1723
|
)
|
|
1449
1724
|
},
|
|
1450
1725
|
members: {
|
|
1451
1726
|
list: (
|
|
1452
1727
|
/** List workspace members */
|
|
1453
|
-
(input, options) =>
|
|
1728
|
+
(input, options) => list(client, { "method": "get", "path": "/workspace/members", "query": ["limit", "cursor"], "hasBody": false }, {}, input, options, true)
|
|
1729
|
+
)
|
|
1730
|
+
},
|
|
1731
|
+
planUsage: {
|
|
1732
|
+
get: (
|
|
1733
|
+
/** Get your plan's usage this period */
|
|
1734
|
+
(options) => call(client, { "method": "get", "path": "/workspace/plan-usage", "query": [], "hasBody": false }, {}, void 0, options)
|
|
1454
1735
|
)
|
|
1455
1736
|
},
|
|
1456
1737
|
teams: {
|
|
1457
1738
|
list: (
|
|
1458
1739
|
/** List teams */
|
|
1459
|
-
(input, options) =>
|
|
1740
|
+
(input, options) => list(client, { "method": "get", "path": "/workspace/teams", "query": ["limit", "cursor"], "hasBody": false }, {}, input, options, true)
|
|
1460
1741
|
)
|
|
1461
1742
|
},
|
|
1462
|
-
usage: (
|
|
1463
|
-
/** Get your plan's usage this period */
|
|
1464
|
-
(options) => call(client, { "method": "get", "path": "/workspace/usage", "query": [], "hasBody": false }, {}, void 0, options)
|
|
1465
|
-
),
|
|
1466
1743
|
webhookDeliveries: {
|
|
1467
1744
|
list: (
|
|
1468
1745
|
/** List an endpoint's deliveries */
|
|
1469
|
-
(endpointId, input, options) =>
|
|
1746
|
+
(endpointId, input, options) => list(client, { "method": "get", "path": "/workspace/webhook-endpoints/{endpointId}/deliveries", "query": ["limit", "cursor", "before", "status"], "hasBody": false }, { "endpointId": endpointId }, input, options, true)
|
|
1470
1747
|
),
|
|
1471
1748
|
redeliver: (
|
|
1472
1749
|
/** Redeliver an event */
|
|
@@ -1492,7 +1769,7 @@ function resources(client) {
|
|
|
1492
1769
|
),
|
|
1493
1770
|
list: (
|
|
1494
1771
|
/** List webhook endpoints */
|
|
1495
|
-
(options) =>
|
|
1772
|
+
(options) => list(client, { "method": "get", "path": "/workspace/webhook-endpoints", "query": [], "hasBody": false }, {}, void 0, options, false)
|
|
1496
1773
|
),
|
|
1497
1774
|
test: (
|
|
1498
1775
|
/** Send a test event */
|
|
@@ -1507,11 +1784,13 @@ function resources(client) {
|
|
|
1507
1784
|
};
|
|
1508
1785
|
}
|
|
1509
1786
|
|
|
1787
|
+
// node_modules/@limitry/sdk/dist/version.js
|
|
1788
|
+
var VERSION = "1.0.0-rc.18";
|
|
1789
|
+
|
|
1510
1790
|
// node_modules/@limitry/sdk/dist/webhooks.js
|
|
1511
|
-
var WebhookVerificationError = class extends
|
|
1791
|
+
var WebhookVerificationError = class extends SdkError {
|
|
1512
1792
|
constructor(message) {
|
|
1513
1793
|
super(message);
|
|
1514
|
-
this.name = "WebhookVerificationError";
|
|
1515
1794
|
}
|
|
1516
1795
|
};
|
|
1517
1796
|
function header(headers, name) {
|
|
@@ -1579,7 +1858,8 @@ async function verifyWebhook(body, headers, secret, options = {}) {
|
|
|
1579
1858
|
// node_modules/@limitry/sdk/dist/index.js
|
|
1580
1859
|
var API_KEY_ENV = `${brand2.identifier.toUpperCase()}_API_KEY`;
|
|
1581
1860
|
var TOKEN_ENV = `${brand2.identifier.toUpperCase()}_TOKEN`;
|
|
1582
|
-
var
|
|
1861
|
+
var BASE_URL_ENV = `${brand2.identifier.toUpperCase()}_BASE_URL`;
|
|
1862
|
+
var DEFAULT_BASE_URL = `https://api.${brand2.domain}`;
|
|
1583
1863
|
function createClient2(options = {}) {
|
|
1584
1864
|
const client = createBaseClient(options);
|
|
1585
1865
|
const extend = Reflect.get(product_exports, "productMethods");
|
|
@@ -1601,14 +1881,22 @@ function createBaseClient(options) {
|
|
|
1601
1881
|
if (!token) {
|
|
1602
1882
|
throw new Error(`${brand2.productName}: no API key. Pass { apiKey } or set ${API_KEY_ENV}.`);
|
|
1603
1883
|
}
|
|
1604
|
-
const origin = withoutTrailingSlashes(options.
|
|
1605
|
-
const
|
|
1884
|
+
const origin = withoutTrailingSlashes(options.baseURL || environment()?.[BASE_URL_ENV] || DEFAULT_BASE_URL);
|
|
1885
|
+
const send2 = withAttemptTimeout(options.fetch ?? ((request) => fetch(request)), options.timeout ?? DEFAULT_TIMEOUT_MS);
|
|
1886
|
+
const sending = options.maxRetries === 0 ? withoutProductRetryHeader(send2) : withRetries(send2, { maxRetries: options.maxRetries });
|
|
1606
1887
|
const client = createClient({
|
|
1607
1888
|
baseUrl: `${origin}/v1`,
|
|
1608
|
-
fetch:
|
|
1889
|
+
fetch: withConnectionErrors(sending)
|
|
1609
1890
|
});
|
|
1610
1891
|
client.use({
|
|
1611
1892
|
onRequest({ request }) {
|
|
1893
|
+
for (const [name, value] of Object.entries(options.defaultHeaders ?? {})) {
|
|
1894
|
+
if (!request.headers.has(name))
|
|
1895
|
+
request.headers.set(name, value);
|
|
1896
|
+
}
|
|
1897
|
+
if (!("document" in globalThis) && !request.headers.has("user-agent")) {
|
|
1898
|
+
request.headers.set("user-agent", USER_AGENT);
|
|
1899
|
+
}
|
|
1612
1900
|
request.headers.set("authorization", `Bearer ${token}`);
|
|
1613
1901
|
if (options.workspace && !request.headers.has("x-workspace")) {
|
|
1614
1902
|
request.headers.set("x-workspace", options.workspace);
|
|
@@ -1623,9 +1911,13 @@ function createBaseClient(options) {
|
|
|
1623
1911
|
webhooks: { verify: verifyWebhook }
|
|
1624
1912
|
});
|
|
1625
1913
|
}
|
|
1626
|
-
|
|
1914
|
+
var USER_AGENT = `${brand2.name}-node/${VERSION}`;
|
|
1915
|
+
function environment() {
|
|
1627
1916
|
const runtime = globalThis;
|
|
1628
|
-
|
|
1917
|
+
return runtime.process?.env;
|
|
1918
|
+
}
|
|
1919
|
+
function credentialFromEnvironment() {
|
|
1920
|
+
const env = environment();
|
|
1629
1921
|
return env?.[API_KEY_ENV] || env?.[TOKEN_ENV] || void 0;
|
|
1630
1922
|
}
|
|
1631
1923
|
function unwrap(result) {
|
|
@@ -1649,12 +1941,12 @@ var CommanderError = class extends Error {
|
|
|
1649
1941
|
* @param {string} code an id string representing the error
|
|
1650
1942
|
* @param {string} message human-readable description of the error
|
|
1651
1943
|
*/
|
|
1652
|
-
constructor(
|
|
1944
|
+
constructor(exitCode2, code2, message) {
|
|
1653
1945
|
super(message);
|
|
1654
1946
|
Error.captureStackTrace(this, this.constructor);
|
|
1655
1947
|
this.name = this.constructor.name;
|
|
1656
1948
|
this.code = code2;
|
|
1657
|
-
this.exitCode =
|
|
1949
|
+
this.exitCode = exitCode2;
|
|
1658
1950
|
this.nestedError = void 0;
|
|
1659
1951
|
}
|
|
1660
1952
|
};
|
|
@@ -3210,11 +3502,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3210
3502
|
* @return never
|
|
3211
3503
|
* @private
|
|
3212
3504
|
*/
|
|
3213
|
-
_exit(
|
|
3505
|
+
_exit(exitCode2, code2, message) {
|
|
3214
3506
|
if (this._exitCallback) {
|
|
3215
|
-
this._exitCallback(new CommanderError(
|
|
3507
|
+
this._exitCallback(new CommanderError(exitCode2, code2, message));
|
|
3216
3508
|
}
|
|
3217
|
-
process2.exit(
|
|
3509
|
+
process2.exit(exitCode2);
|
|
3218
3510
|
}
|
|
3219
3511
|
/**
|
|
3220
3512
|
* Register callback `fn` for the command.
|
|
@@ -4365,9 +4657,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
4365
4657
|
this.outputHelp({ error: true });
|
|
4366
4658
|
}
|
|
4367
4659
|
const config2 = errorOptions || {};
|
|
4368
|
-
const
|
|
4660
|
+
const exitCode2 = config2.exitCode || 1;
|
|
4369
4661
|
const code2 = config2.code || "commander.error";
|
|
4370
|
-
this._exit(
|
|
4662
|
+
this._exit(exitCode2, code2, message);
|
|
4371
4663
|
}
|
|
4372
4664
|
/**
|
|
4373
4665
|
* Apply any option related environment variables, if option does
|
|
@@ -4486,10 +4778,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
4486
4778
|
* @param {string} flag
|
|
4487
4779
|
* @private
|
|
4488
4780
|
*/
|
|
4489
|
-
unknownOption(
|
|
4781
|
+
unknownOption(flag) {
|
|
4490
4782
|
if (this._allowUnknownOption) return;
|
|
4491
4783
|
let suggestion = "";
|
|
4492
|
-
if (
|
|
4784
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
4493
4785
|
let candidateFlags = [];
|
|
4494
4786
|
let command = this;
|
|
4495
4787
|
do {
|
|
@@ -4497,9 +4789,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
4497
4789
|
candidateFlags = candidateFlags.concat(moreFlags);
|
|
4498
4790
|
command = command.parent;
|
|
4499
4791
|
} while (command && !command._enablePositionalOptions);
|
|
4500
|
-
suggestion = suggestSimilar(
|
|
4792
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
4501
4793
|
}
|
|
4502
|
-
const message = `error: unknown option '${
|
|
4794
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
4503
4795
|
this.error(message, { code: "commander.unknownOption" });
|
|
4504
4796
|
}
|
|
4505
4797
|
/**
|
|
@@ -4909,11 +5201,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
4909
5201
|
*/
|
|
4910
5202
|
help(contextOptions) {
|
|
4911
5203
|
this.outputHelp(contextOptions);
|
|
4912
|
-
let
|
|
4913
|
-
if (
|
|
4914
|
-
|
|
5204
|
+
let exitCode2 = Number(process2.exitCode ?? 0);
|
|
5205
|
+
if (exitCode2 === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
5206
|
+
exitCode2 = 1;
|
|
4915
5207
|
}
|
|
4916
|
-
this._exit(
|
|
5208
|
+
this._exit(exitCode2, "commander.help", "(outputHelp)");
|
|
4917
5209
|
}
|
|
4918
5210
|
/**
|
|
4919
5211
|
* // Do a little typing to coordinate emit and listener for the help text events.
|
|
@@ -5059,13 +5351,13 @@ function browserLogin(options) {
|
|
|
5059
5351
|
return;
|
|
5060
5352
|
}
|
|
5061
5353
|
const fields = url.searchParams;
|
|
5062
|
-
const
|
|
5354
|
+
const send2 = (status, title, text) => res.writeHead(status, {
|
|
5063
5355
|
"content-type": "text/html; charset=utf-8",
|
|
5064
5356
|
"cache-control": "no-store",
|
|
5065
5357
|
"referrer-policy": "no-referrer"
|
|
5066
5358
|
}).end(PAGE(title, text));
|
|
5067
5359
|
if (fields.get("state") !== state) {
|
|
5068
|
-
|
|
5360
|
+
send2(
|
|
5069
5361
|
400,
|
|
5070
5362
|
"Not this login",
|
|
5071
5363
|
"This sign-in did not come from the terminal that is waiting. Run login again."
|
|
@@ -5073,16 +5365,16 @@ function browserLogin(options) {
|
|
|
5073
5365
|
return;
|
|
5074
5366
|
}
|
|
5075
5367
|
if (fields.get("error")) {
|
|
5076
|
-
|
|
5368
|
+
send2(200, "Sign-in cancelled", "You can close this tab.");
|
|
5077
5369
|
finish(() => reject(new Error("sign-in was denied in the browser")));
|
|
5078
5370
|
return;
|
|
5079
5371
|
}
|
|
5080
5372
|
const token = decrypt(fields.get("token") ?? "");
|
|
5081
5373
|
if (!token) {
|
|
5082
|
-
|
|
5374
|
+
send2(400, "Something went wrong", "Run login again.");
|
|
5083
5375
|
return;
|
|
5084
5376
|
}
|
|
5085
|
-
|
|
5377
|
+
send2(
|
|
5086
5378
|
200,
|
|
5087
5379
|
"You are signed in",
|
|
5088
5380
|
"Return to your terminal. You can close this tab."
|
|
@@ -5134,6 +5426,9 @@ import {
|
|
|
5134
5426
|
writeFileSync
|
|
5135
5427
|
} from "node:fs";
|
|
5136
5428
|
import { join } from "node:path";
|
|
5429
|
+
function baseURLEnvVar() {
|
|
5430
|
+
return BASE_URL_ENV;
|
|
5431
|
+
}
|
|
5137
5432
|
function environmentEnvVar() {
|
|
5138
5433
|
return `${brand.identifier.toUpperCase()}_ENVIRONMENT`;
|
|
5139
5434
|
}
|
|
@@ -5161,12 +5456,13 @@ function writeConfig(homeDir, config2) {
|
|
|
5161
5456
|
}
|
|
5162
5457
|
function resolveSettings(env, homeDir, flags = {}) {
|
|
5163
5458
|
const config2 = readConfig(homeDir);
|
|
5164
|
-
const
|
|
5459
|
+
const environment3 = flags.environment ? { environment: flags.environment, environmentSource: "flag" } : env[environmentEnvVar()] ? { environment: env[environmentEnvVar()], environmentSource: "env" } : config2.environment ? { environment: config2.environment, environmentSource: "config" } : { environment: void 0, environmentSource: null };
|
|
5165
5460
|
return {
|
|
5166
|
-
...
|
|
5167
|
-
|
|
5168
|
-
env[
|
|
5461
|
+
...environment3,
|
|
5462
|
+
baseURL: withoutTrailingSlashes2(
|
|
5463
|
+
flags.baseUrl || env[BASE_URL_ENV] || config2.baseURL || DEFAULT_BASE_URL
|
|
5169
5464
|
),
|
|
5465
|
+
baseURLSource: flags.baseUrl ? "flag" : env[BASE_URL_ENV] ? "env" : config2.baseURL ? "config" : null,
|
|
5170
5466
|
token: env[tokenEnvVar()] ?? config2.token,
|
|
5171
5467
|
workspace: env[`${brand.identifier.toUpperCase()}_WORKSPACE`] ?? config2.workspace
|
|
5172
5468
|
};
|
|
@@ -5177,6 +5473,28 @@ function withoutTrailingSlashes2(url) {
|
|
|
5177
5473
|
return url.slice(0, end);
|
|
5178
5474
|
}
|
|
5179
5475
|
|
|
5476
|
+
// src/errors.ts
|
|
5477
|
+
var EXIT = {
|
|
5478
|
+
ok: 0,
|
|
5479
|
+
failure: 1,
|
|
5480
|
+
usage: 2,
|
|
5481
|
+
auth: 4
|
|
5482
|
+
};
|
|
5483
|
+
var UsageError = class extends Error {
|
|
5484
|
+
exitCode = EXIT.usage;
|
|
5485
|
+
constructor(message) {
|
|
5486
|
+
super(message);
|
|
5487
|
+
this.name = "UsageError";
|
|
5488
|
+
}
|
|
5489
|
+
};
|
|
5490
|
+
var NotLoggedInError = class extends Error {
|
|
5491
|
+
exitCode = EXIT.auth;
|
|
5492
|
+
constructor(message) {
|
|
5493
|
+
super(message);
|
|
5494
|
+
this.name = "NotLoggedInError";
|
|
5495
|
+
}
|
|
5496
|
+
};
|
|
5497
|
+
|
|
5180
5498
|
// src/http.ts
|
|
5181
5499
|
async function rawRequest(ctx, options) {
|
|
5182
5500
|
const needsWorkspace = !options.path.startsWith("/v1/user");
|
|
@@ -5185,7 +5503,7 @@ async function rawRequest(ctx, options) {
|
|
|
5185
5503
|
return unwrap(
|
|
5186
5504
|
await client.request(options.method, options.path, {
|
|
5187
5505
|
// The client's base URL ends in /v1; the path given here is absolute.
|
|
5188
|
-
baseUrl: ctx.credentials({ workspace: workspace2 }).
|
|
5506
|
+
baseUrl: ctx.credentials({ workspace: workspace2 }).baseURL,
|
|
5189
5507
|
body: options.body
|
|
5190
5508
|
})
|
|
5191
5509
|
);
|
|
@@ -5284,9 +5602,10 @@ var approvals = (program2, ctx) => {
|
|
|
5284
5602
|
// src/usage.ts
|
|
5285
5603
|
var usage = (program2, ctx) => {
|
|
5286
5604
|
const workspace2 = program2.commands.find((c) => c.name() === "workspace") ?? program2.command("workspace");
|
|
5287
|
-
workspace2.
|
|
5605
|
+
const planUsage = workspace2.commands.find((c) => c.name() === "plan-usage") ?? workspace2.command("plan-usage").description("Your plan's usage this period");
|
|
5606
|
+
planUsage.command("get").description("Show your plan's usage this period").option("--workspace <slug>", "act in this workspace for one call").option("--json", "machine-readable output").action(async (options) => {
|
|
5288
5607
|
const result = unwrap(
|
|
5289
|
-
await ctx.client({ workspace: options.workspace }).GET("/workspace/usage")
|
|
5608
|
+
await ctx.client({ workspace: options.workspace }).GET("/workspace/plan-usage")
|
|
5290
5609
|
);
|
|
5291
5610
|
if (options.json) {
|
|
5292
5611
|
ctx.io.stdout(json(result));
|
|
@@ -5318,13 +5637,14 @@ function usageLines(usage2) {
|
|
|
5318
5637
|
async function me(ctx) {
|
|
5319
5638
|
return unwrap(await ctx.client({ workspace: false }).GET("/user/me"));
|
|
5320
5639
|
}
|
|
5321
|
-
async function saveToken(ctx, token
|
|
5640
|
+
async function saveToken(ctx, token) {
|
|
5641
|
+
const { baseURL, baseURLSource } = ctx.settings();
|
|
5322
5642
|
if (!token.startsWith(`pat_${brand.identifier}_`)) {
|
|
5323
5643
|
throw new Error(`that is not a ${brand.productName} personal access token`);
|
|
5324
5644
|
}
|
|
5325
5645
|
const previous = readConfig(ctx.io.homeDir);
|
|
5326
5646
|
const config2 = { ...previous, token };
|
|
5327
|
-
if (
|
|
5647
|
+
if (baseURLSource === "flag") config2.baseURL = baseURL;
|
|
5328
5648
|
writeConfig(ctx.io.homeDir, config2);
|
|
5329
5649
|
let user;
|
|
5330
5650
|
try {
|
|
@@ -5354,24 +5674,28 @@ async function saveToken(ctx, token, api2) {
|
|
|
5354
5674
|
var login = (program2, ctx) => {
|
|
5355
5675
|
program2.command("login").description(
|
|
5356
5676
|
"Sign in through the browser, or store a personal access token with --token"
|
|
5357
|
-
).option("--token <pat>", "a personal access token (CI, servers)").option("--
|
|
5677
|
+
).option("--token <pat>", "a personal access token (CI, servers)").option("--web <origin>", "web app origin for the browser sign-in").addHelpText(
|
|
5678
|
+
"after",
|
|
5679
|
+
`
|
|
5680
|
+
The global --base-url signs in to another API (default ${DEFAULT_BASE_URL}), and is saved for later commands.`
|
|
5681
|
+
).action(async (options) => {
|
|
5358
5682
|
if (!productFeatures.personalTokens) {
|
|
5359
5683
|
throw new Error(
|
|
5360
5684
|
`${brand.productName} has no personal access tokens, so this command line cannot sign in.`
|
|
5361
5685
|
);
|
|
5362
5686
|
}
|
|
5363
5687
|
if (options.token) {
|
|
5364
|
-
await saveToken(ctx, options.token
|
|
5688
|
+
await saveToken(ctx, options.token);
|
|
5365
5689
|
return;
|
|
5366
5690
|
}
|
|
5367
5691
|
if (!ctx.io.interactive) {
|
|
5368
5692
|
ctx.io.stderr(
|
|
5369
5693
|
`Paste a personal access token (Account \u2192 Personal access tokens in ${brand.productName}), then Enter:`
|
|
5370
5694
|
);
|
|
5371
|
-
await saveToken(ctx, (await ctx.io.stdin()).trim()
|
|
5695
|
+
await saveToken(ctx, (await ctx.io.stdin()).trim());
|
|
5372
5696
|
return;
|
|
5373
5697
|
}
|
|
5374
|
-
const api2 =
|
|
5698
|
+
const api2 = ctx.settings().baseURL;
|
|
5375
5699
|
const webOrigin = options.web ?? webOriginFor(api2);
|
|
5376
5700
|
if (!webOrigin) {
|
|
5377
5701
|
throw new Error(
|
|
@@ -5387,15 +5711,15 @@ var login = (program2, ctx) => {
|
|
|
5387
5711
|
${url}`
|
|
5388
5712
|
)
|
|
5389
5713
|
});
|
|
5390
|
-
await saveToken(ctx, token
|
|
5714
|
+
await saveToken(ctx, token);
|
|
5391
5715
|
});
|
|
5392
5716
|
};
|
|
5393
5717
|
var logout = (program2, ctx) => {
|
|
5394
5718
|
program2.command("logout").description("Revoke the stored token and forget it").action(async () => {
|
|
5395
5719
|
const config2 = readConfig(ctx.io.homeDir);
|
|
5396
5720
|
if (config2.token) {
|
|
5397
|
-
const revoked = await ctx.
|
|
5398
|
-
new Request(`${ctx.settings().
|
|
5721
|
+
const revoked = await ctx.fetch(
|
|
5722
|
+
new Request(`${ctx.settings().baseURL}/v1/user/token`, {
|
|
5399
5723
|
method: "DELETE",
|
|
5400
5724
|
headers: { authorization: `Bearer ${config2.token}` }
|
|
5401
5725
|
})
|
|
@@ -5453,7 +5777,7 @@ var workspace = (program2, ctx) => {
|
|
|
5453
5777
|
ctx.io.stdout(`Default workspace: ${slug}`);
|
|
5454
5778
|
});
|
|
5455
5779
|
};
|
|
5456
|
-
var
|
|
5780
|
+
var environment2 = (program2, ctx) => {
|
|
5457
5781
|
const group = program2.command("environment").description("Choose the environment commands act in");
|
|
5458
5782
|
group.command("list", { isDefault: true }).description("Show the environment commands act in").action(() => {
|
|
5459
5783
|
const { environment: current, environmentSource } = ctx.settings();
|
|
@@ -5496,9 +5820,16 @@ var api = (program2, ctx) => {
|
|
|
5496
5820
|
program2.command("api <method> <path>").description("Call any API endpoint directly, in the selected workspace").option("--data <json>", "JSON request body").option("--workspace <slug>", "act in this workspace for one call").action(
|
|
5497
5821
|
async (method, path2, options) => {
|
|
5498
5822
|
if (!path2.startsWith("/")) {
|
|
5499
|
-
throw new
|
|
5823
|
+
throw new UsageError(
|
|
5824
|
+
"usage: api <method> </v1/...> [--data '<json>']"
|
|
5825
|
+
);
|
|
5826
|
+
}
|
|
5827
|
+
let body;
|
|
5828
|
+
try {
|
|
5829
|
+
body = options.data === void 0 ? void 0 : JSON.parse(options.data);
|
|
5830
|
+
} catch {
|
|
5831
|
+
throw new UsageError("--data must be JSON");
|
|
5500
5832
|
}
|
|
5501
|
-
const body = options.data === void 0 ? void 0 : JSON.parse(options.data);
|
|
5502
5833
|
ctx.io.stdout(
|
|
5503
5834
|
json(
|
|
5504
5835
|
await rawRequest(ctx, {
|
|
@@ -5517,8 +5848,8 @@ var config = (program2, ctx) => {
|
|
|
5517
5848
|
const settings = ctx.settings();
|
|
5518
5849
|
ctx.io.stdout(
|
|
5519
5850
|
json({
|
|
5520
|
-
|
|
5521
|
-
|
|
5851
|
+
baseURL: settings.baseURL,
|
|
5852
|
+
baseURLDefault: DEFAULT_BASE_URL,
|
|
5522
5853
|
token: settings.token ? `${settings.token.slice(0, 12)}\u2026` : null,
|
|
5523
5854
|
tokenSource: ctx.io.env[tokenEnvVar()] ? tokenEnvVar() : settings.token ? "config" : null,
|
|
5524
5855
|
workspace: settings.workspace ?? null,
|
|
@@ -5534,7 +5865,7 @@ var platformCommands = [
|
|
|
5534
5865
|
logout,
|
|
5535
5866
|
whoami,
|
|
5536
5867
|
workspace,
|
|
5537
|
-
|
|
5868
|
+
environment2,
|
|
5538
5869
|
api,
|
|
5539
5870
|
config,
|
|
5540
5871
|
approvals,
|
|
@@ -5602,10 +5933,10 @@ var OPERATIONS = [
|
|
|
5602
5933
|
"in": "body",
|
|
5603
5934
|
"type": "json",
|
|
5604
5935
|
"required": true,
|
|
5605
|
-
"description": 'Who is acting, such as `{"kind": "user", "id": "
|
|
5936
|
+
"description": 'Who is acting, such as `{"kind": "user", "id": "user_123"}`.',
|
|
5606
5937
|
"example": {
|
|
5607
5938
|
"kind": "user",
|
|
5608
|
-
"id": "
|
|
5939
|
+
"id": "user_123"
|
|
5609
5940
|
},
|
|
5610
5941
|
"schema": {
|
|
5611
5942
|
"type": "object",
|
|
@@ -5627,7 +5958,7 @@ var OPERATIONS = [
|
|
|
5627
5958
|
"kind",
|
|
5628
5959
|
"id"
|
|
5629
5960
|
],
|
|
5630
|
-
"description": 'Who is acting, such as `{"kind": "user", "id": "
|
|
5961
|
+
"description": 'Who is acting, such as `{"kind": "user", "id": "user_123"}`.'
|
|
5631
5962
|
}
|
|
5632
5963
|
},
|
|
5633
5964
|
{
|
|
@@ -5725,84 +6056,97 @@ var OPERATIONS = [
|
|
|
5725
6056
|
"scope": "checks:write"
|
|
5726
6057
|
},
|
|
5727
6058
|
{
|
|
5728
|
-
"operationId": "checks.
|
|
6059
|
+
"operationId": "checks.list",
|
|
5729
6060
|
"method": "get",
|
|
5730
|
-
"path": "/checks
|
|
5731
|
-
"summary": "List
|
|
6061
|
+
"path": "/checks",
|
|
6062
|
+
"summary": "List checks",
|
|
5732
6063
|
"cli": {
|
|
5733
|
-
"command": "checks
|
|
6064
|
+
"command": "checks list",
|
|
5734
6065
|
"args": [],
|
|
5735
6066
|
"confirm": false
|
|
5736
6067
|
},
|
|
5737
6068
|
"mcp": {
|
|
5738
6069
|
"exposed": true,
|
|
5739
|
-
"name": "
|
|
6070
|
+
"name": "checks_list",
|
|
5740
6071
|
"hints": {
|
|
5741
6072
|
"readOnlyHint": true,
|
|
5742
6073
|
"destructiveHint": false,
|
|
5743
6074
|
"idempotentHint": true
|
|
5744
6075
|
}
|
|
5745
6076
|
},
|
|
5746
|
-
"description": "Lists the checks of the last 3 days, newest first, with every subject each one named and whether Limitry allowed it. A refused check says whose budget refused it. Name a `subject` as `kind:id` for only the checks that named it, or set `refused` for only refused ones. Limitry keeps the last 3 days, and at most 100,000 checks in each environment. Results come a page at a time.",
|
|
6077
|
+
"description": "Lists the checks of the last 3 days, newest first, with every subject each one named and whether Limitry allowed it. A refused check says whose budget refused it. Name a `subject` as `kind:id` for only the checks that named it, or set `refused` for only refused ones. Send `before` to start from a moment. Limitry keeps the last 3 days, and at most 100,000 checks in each environment. Results come a page at a time.",
|
|
5747
6078
|
"fields": [
|
|
5748
6079
|
{
|
|
5749
|
-
"name": "
|
|
6080
|
+
"name": "limit",
|
|
6081
|
+
"in": "query",
|
|
6082
|
+
"type": "number",
|
|
6083
|
+
"required": false,
|
|
6084
|
+
"description": "Items per page, 1\u2013100 (default 25).",
|
|
6085
|
+
"example": 25,
|
|
6086
|
+
"schema": {
|
|
6087
|
+
"type": "integer",
|
|
6088
|
+
"minimum": 1,
|
|
6089
|
+
"maximum": 100,
|
|
6090
|
+
"default": 25,
|
|
6091
|
+
"description": "Items per page, 1\u2013100 (default 25)."
|
|
6092
|
+
}
|
|
6093
|
+
},
|
|
6094
|
+
{
|
|
6095
|
+
"name": "cursor",
|
|
5750
6096
|
"in": "query",
|
|
5751
6097
|
"type": "string",
|
|
5752
6098
|
"required": false,
|
|
5753
|
-
"description": "
|
|
5754
|
-
"example": "user:usr_123",
|
|
6099
|
+
"description": "Opaque token from a previous page's nextCursor.",
|
|
5755
6100
|
"schema": {
|
|
5756
6101
|
"type": "string",
|
|
5757
|
-
"
|
|
5758
|
-
"description": "Only checks that named this subject, as `kind:id`."
|
|
6102
|
+
"description": "Opaque token from a previous page's nextCursor."
|
|
5759
6103
|
}
|
|
5760
6104
|
},
|
|
5761
6105
|
{
|
|
5762
|
-
"name": "
|
|
6106
|
+
"name": "before",
|
|
5763
6107
|
"in": "query",
|
|
5764
6108
|
"type": "string",
|
|
5765
6109
|
"required": false,
|
|
5766
|
-
"description": "`
|
|
5767
|
-
"example": "
|
|
6110
|
+
"description": "Start from this moment: items older than it, newest first. Ignored with `cursor`, which already says where to go on.",
|
|
6111
|
+
"example": "2026-11-01T00:00:00.000Z",
|
|
5768
6112
|
"schema": {
|
|
5769
6113
|
"type": "string",
|
|
5770
|
-
"
|
|
5771
|
-
|
|
5772
|
-
"false"
|
|
5773
|
-
],
|
|
5774
|
-
"description": "`true` for only refused checks."
|
|
6114
|
+
"format": "date-time",
|
|
6115
|
+
"description": "Start from this moment: items older than it, newest first. Ignored with `cursor`, which already says where to go on."
|
|
5775
6116
|
}
|
|
5776
6117
|
},
|
|
5777
6118
|
{
|
|
5778
|
-
"name": "
|
|
6119
|
+
"name": "subject",
|
|
5779
6120
|
"in": "query",
|
|
5780
|
-
"type": "
|
|
6121
|
+
"type": "string",
|
|
5781
6122
|
"required": false,
|
|
5782
|
-
"description": "
|
|
5783
|
-
"example":
|
|
6123
|
+
"description": "Only checks that named this subject, as `kind:id`.",
|
|
6124
|
+
"example": "user:user_123",
|
|
5784
6125
|
"schema": {
|
|
5785
|
-
"type": "
|
|
5786
|
-
"
|
|
5787
|
-
"
|
|
5788
|
-
"default": 25,
|
|
5789
|
-
"description": "How many to return, from 1 to 100. Default: 25."
|
|
6126
|
+
"type": "string",
|
|
6127
|
+
"maxLength": 301,
|
|
6128
|
+
"description": "Only checks that named this subject, as `kind:id`."
|
|
5790
6129
|
}
|
|
5791
6130
|
},
|
|
5792
6131
|
{
|
|
5793
|
-
"name": "
|
|
6132
|
+
"name": "refused",
|
|
5794
6133
|
"in": "query",
|
|
5795
6134
|
"type": "string",
|
|
5796
6135
|
"required": false,
|
|
5797
|
-
"description": "
|
|
6136
|
+
"description": "`true` for only refused checks.",
|
|
6137
|
+
"example": "true",
|
|
5798
6138
|
"schema": {
|
|
5799
6139
|
"type": "string",
|
|
5800
|
-
"
|
|
5801
|
-
|
|
6140
|
+
"enum": [
|
|
6141
|
+
"true",
|
|
6142
|
+
"false"
|
|
6143
|
+
],
|
|
6144
|
+
"description": "`true` for only refused checks."
|
|
5802
6145
|
}
|
|
5803
6146
|
}
|
|
5804
6147
|
],
|
|
5805
6148
|
"hasBody": false,
|
|
6149
|
+
"paginated": true,
|
|
5806
6150
|
"workspace": true,
|
|
5807
6151
|
"acceptsApiKey": true,
|
|
5808
6152
|
"scope": "limits:read"
|
|
@@ -5888,7 +6232,7 @@ var OPERATIONS = [
|
|
|
5888
6232
|
"in": "body",
|
|
5889
6233
|
"type": "json",
|
|
5890
6234
|
"required": true,
|
|
5891
|
-
"description": 'Who the limit applies to. `{"kind": "user"}` covers every user, and `{"kind": "user", "id": "
|
|
6235
|
+
"description": 'Who the limit applies to. `{"kind": "user"}` covers every user, and `{"kind": "user", "id": "user_123"}` covers one.',
|
|
5892
6236
|
"example": {
|
|
5893
6237
|
"kind": "user"
|
|
5894
6238
|
},
|
|
@@ -5914,7 +6258,7 @@ var OPERATIONS = [
|
|
|
5914
6258
|
"required": [
|
|
5915
6259
|
"kind"
|
|
5916
6260
|
],
|
|
5917
|
-
"description": 'Who the limit applies to. `{"kind": "user"}` covers every user, and `{"kind": "user", "id": "
|
|
6261
|
+
"description": 'Who the limit applies to. `{"kind": "user"}` covers every user, and `{"kind": "user", "id": "user_123"}` covers one.'
|
|
5918
6262
|
}
|
|
5919
6263
|
},
|
|
5920
6264
|
{
|
|
@@ -6148,27 +6492,28 @@ var OPERATIONS = [
|
|
|
6148
6492
|
"scope": "limits:write"
|
|
6149
6493
|
},
|
|
6150
6494
|
{
|
|
6151
|
-
"operationId": "limits.credits.
|
|
6495
|
+
"operationId": "limits.credits.get",
|
|
6152
6496
|
"method": "get",
|
|
6153
|
-
"path": "/limits/{limitId}/credits",
|
|
6154
|
-
"summary": "
|
|
6497
|
+
"path": "/limits/{limitId}/credits/{creditId}",
|
|
6498
|
+
"summary": "Get a credit",
|
|
6155
6499
|
"cli": {
|
|
6156
|
-
"command": "limits credits
|
|
6500
|
+
"command": "limits credits get",
|
|
6157
6501
|
"args": [
|
|
6158
|
-
"limitId"
|
|
6502
|
+
"limitId",
|
|
6503
|
+
"creditId"
|
|
6159
6504
|
],
|
|
6160
6505
|
"confirm": false
|
|
6161
6506
|
},
|
|
6162
6507
|
"mcp": {
|
|
6163
6508
|
"exposed": true,
|
|
6164
|
-
"name": "
|
|
6509
|
+
"name": "limits_credits_get",
|
|
6165
6510
|
"hints": {
|
|
6166
6511
|
"readOnlyHint": true,
|
|
6167
6512
|
"destructiveHint": false,
|
|
6168
6513
|
"idempotentHint": true
|
|
6169
6514
|
}
|
|
6170
6515
|
},
|
|
6171
|
-
"description": "
|
|
6516
|
+
"description": "Returns one credit added to a subject's balance on this limit.",
|
|
6172
6517
|
"fields": [
|
|
6173
6518
|
{
|
|
6174
6519
|
"name": "limitId",
|
|
@@ -6183,23 +6528,76 @@ var OPERATIONS = [
|
|
|
6183
6528
|
}
|
|
6184
6529
|
},
|
|
6185
6530
|
{
|
|
6186
|
-
"name": "
|
|
6187
|
-
"in": "
|
|
6188
|
-
"type": "
|
|
6189
|
-
"required":
|
|
6190
|
-
"description": "
|
|
6191
|
-
"example":
|
|
6531
|
+
"name": "creditId",
|
|
6532
|
+
"in": "path",
|
|
6533
|
+
"type": "string",
|
|
6534
|
+
"required": true,
|
|
6535
|
+
"description": "The credit's ID.",
|
|
6536
|
+
"example": "crd_5a8d3f2b-9c1e-4b7a-8f6d-2e0c9b4a1d73",
|
|
6192
6537
|
"schema": {
|
|
6193
|
-
"type": "
|
|
6194
|
-
"
|
|
6195
|
-
"maximum": 100,
|
|
6196
|
-
"default": 25,
|
|
6197
|
-
"description": "Items per page, 1\u2013100 (default 25)."
|
|
6538
|
+
"type": "string",
|
|
6539
|
+
"description": "The credit's ID."
|
|
6198
6540
|
}
|
|
6199
|
-
}
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6541
|
+
}
|
|
6542
|
+
],
|
|
6543
|
+
"hasBody": false,
|
|
6544
|
+
"workspace": true,
|
|
6545
|
+
"acceptsApiKey": true,
|
|
6546
|
+
"scope": "limits:read"
|
|
6547
|
+
},
|
|
6548
|
+
{
|
|
6549
|
+
"operationId": "limits.credits.list",
|
|
6550
|
+
"method": "get",
|
|
6551
|
+
"path": "/limits/{limitId}/credits",
|
|
6552
|
+
"summary": "List a balance's credits",
|
|
6553
|
+
"cli": {
|
|
6554
|
+
"command": "limits credits list",
|
|
6555
|
+
"args": [
|
|
6556
|
+
"limitId"
|
|
6557
|
+
],
|
|
6558
|
+
"confirm": false
|
|
6559
|
+
},
|
|
6560
|
+
"mcp": {
|
|
6561
|
+
"exposed": true,
|
|
6562
|
+
"name": "limits_credits_list",
|
|
6563
|
+
"hints": {
|
|
6564
|
+
"readOnlyHint": true,
|
|
6565
|
+
"destructiveHint": false,
|
|
6566
|
+
"idempotentHint": true
|
|
6567
|
+
}
|
|
6568
|
+
},
|
|
6569
|
+
"description": "Lists the credits added to subjects' balances on this limit, including any taken back, newest first. Page through them with the opaque `nextCursor`. `before` starts from a moment, and `subjectId` keeps one subject's credits.",
|
|
6570
|
+
"fields": [
|
|
6571
|
+
{
|
|
6572
|
+
"name": "limitId",
|
|
6573
|
+
"in": "path",
|
|
6574
|
+
"type": "string",
|
|
6575
|
+
"required": true,
|
|
6576
|
+
"description": "The limit's ID, or its name, such as `AI budget` (URL-encoded). A name matches an active limit in this environment, exactly or else ignoring case.",
|
|
6577
|
+
"example": "lmt_6f1c2a9e-4b7d-4e3a-9c5f-8d2b1a0e7c34",
|
|
6578
|
+
"schema": {
|
|
6579
|
+
"type": "string",
|
|
6580
|
+
"description": "The limit's ID, or its name, such as `AI budget` (URL-encoded). A name matches an active limit in this environment, exactly or else ignoring case."
|
|
6581
|
+
}
|
|
6582
|
+
},
|
|
6583
|
+
{
|
|
6584
|
+
"name": "limit",
|
|
6585
|
+
"in": "query",
|
|
6586
|
+
"type": "number",
|
|
6587
|
+
"required": false,
|
|
6588
|
+
"description": "Items per page, 1\u2013100 (default 25).",
|
|
6589
|
+
"example": 25,
|
|
6590
|
+
"schema": {
|
|
6591
|
+
"type": "integer",
|
|
6592
|
+
"minimum": 1,
|
|
6593
|
+
"maximum": 100,
|
|
6594
|
+
"default": 25,
|
|
6595
|
+
"description": "Items per page, 1\u2013100 (default 25)."
|
|
6596
|
+
}
|
|
6597
|
+
},
|
|
6598
|
+
{
|
|
6599
|
+
"name": "cursor",
|
|
6600
|
+
"in": "query",
|
|
6203
6601
|
"type": "string",
|
|
6204
6602
|
"required": false,
|
|
6205
6603
|
"description": "Opaque token from a previous page's nextCursor.",
|
|
@@ -6237,6 +6635,7 @@ var OPERATIONS = [
|
|
|
6237
6635
|
}
|
|
6238
6636
|
],
|
|
6239
6637
|
"hasBody": false,
|
|
6638
|
+
"paginated": true,
|
|
6240
6639
|
"workspace": true,
|
|
6241
6640
|
"acceptsApiKey": true,
|
|
6242
6641
|
"scope": "limits:read"
|
|
@@ -6372,6 +6771,7 @@ var OPERATIONS = [
|
|
|
6372
6771
|
}
|
|
6373
6772
|
],
|
|
6374
6773
|
"hasBody": false,
|
|
6774
|
+
"paginated": true,
|
|
6375
6775
|
"workspace": true,
|
|
6376
6776
|
"acceptsApiKey": true,
|
|
6377
6777
|
"scope": "limits:read"
|
|
@@ -6437,7 +6837,7 @@ var OPERATIONS = [
|
|
|
6437
6837
|
"idempotentHint": false
|
|
6438
6838
|
}
|
|
6439
6839
|
},
|
|
6440
|
-
"description": "Makes the environment's limits match the list in `limits`, pairing them up by name. It creates the limits that are missing and changes the ones that differ, where an omitted field means its default. With `archiveMissing`, it also archives the active limits the list doesn't name. Running it twice changes nothing the second time. Limitry checks the whole list before writing anything. If any entry has a problem, nothing changes, and the 400 lists each problem in `details`. Otherwise Limitry writes every change at once. You can't change a limit's subject, action, unit, window, every, start or rolling under the same name, so rename the entry to do that. With `
|
|
6840
|
+
"description": "Makes the environment's limits match the list in `limits`, pairing them up by name. It creates the limits that are missing and changes the ones that differ, where an omitted field means its default. With `archiveMissing`, it also archives the active limits the list doesn't name. Running it twice changes nothing the second time. Limitry checks the whole list before writing anything. If any entry has a problem, nothing changes, and the 400 lists each problem in `details`. Otherwise Limitry writes every change at once. You can't change a limit's subject, action, unit, window, every, start or rolling under the same name, so rename the entry to do that. With `dryRun`, it returns what it would do without writing anything. What a sync sets is locked in the app until the next sync, which names its `source`. This is the call behind `limitry sync`, for keeping your limits in a file in your repository. With a personal access token, only owners and admins can call this. A workspace API key with this scope can.",
|
|
6441
6841
|
"fields": [
|
|
6442
6842
|
{
|
|
6443
6843
|
"name": "limits",
|
|
@@ -6497,7 +6897,7 @@ var OPERATIONS = [
|
|
|
6497
6897
|
}
|
|
6498
6898
|
},
|
|
6499
6899
|
{
|
|
6500
|
-
"name": "
|
|
6900
|
+
"name": "dryRun",
|
|
6501
6901
|
"in": "body",
|
|
6502
6902
|
"type": "boolean",
|
|
6503
6903
|
"required": false,
|
|
@@ -6830,7 +7230,7 @@ var OPERATIONS = [
|
|
|
6830
7230
|
"idempotentHint": false
|
|
6831
7231
|
}
|
|
6832
7232
|
},
|
|
6833
|
-
"description": "Commits a reservation with the amount actually used (`cost`). If `cost` is less than the amount reserved, the rest goes back at once. If it's more, Limitry charges the whole `cost`, since the work happened. A commit up to 24 hours after the reservation expired still charges `cost`. Repeating a commit with the same `cost` returns the same result, and a different `cost` gets a 400. We cache its API key check briefly for speed. A revoked key can keep working here for up to 60 seconds.",
|
|
7233
|
+
"description": "Commits a reservation with the amount actually used (`cost`). If `cost` is less than the amount reserved, the rest goes back at once. If it's more, Limitry charges the whole `cost`, since the work happened. A commit up to 24 hours after the reservation expired still charges `cost`. Repeating a commit with the same `cost` returns the same result, and a different `cost` gets a 400. Committing a released reservation gets a 409. We cache its API key check briefly for speed. A revoked key can keep working here for up to 60 seconds.",
|
|
6834
7234
|
"fields": [
|
|
6835
7235
|
{
|
|
6836
7236
|
"name": "reservationId",
|
|
@@ -6917,12 +7317,12 @@ var OPERATIONS = [
|
|
|
6917
7317
|
"scope": "checks:write"
|
|
6918
7318
|
},
|
|
6919
7319
|
{
|
|
6920
|
-
"operationId": "reservations.
|
|
6921
|
-
"method": "
|
|
6922
|
-
"path": "/reservations/{reservationId}
|
|
6923
|
-
"summary": "
|
|
7320
|
+
"operationId": "reservations.get",
|
|
7321
|
+
"method": "get",
|
|
7322
|
+
"path": "/reservations/{reservationId}",
|
|
7323
|
+
"summary": "Get a reservation",
|
|
6924
7324
|
"cli": {
|
|
6925
|
-
"command": "reservations
|
|
7325
|
+
"command": "reservations get",
|
|
6926
7326
|
"args": [
|
|
6927
7327
|
"reservationId"
|
|
6928
7328
|
],
|
|
@@ -6930,14 +7330,14 @@ var OPERATIONS = [
|
|
|
6930
7330
|
},
|
|
6931
7331
|
"mcp": {
|
|
6932
7332
|
"exposed": true,
|
|
6933
|
-
"name": "
|
|
7333
|
+
"name": "reservations_get",
|
|
6934
7334
|
"hints": {
|
|
6935
|
-
"readOnlyHint":
|
|
7335
|
+
"readOnlyHint": true,
|
|
6936
7336
|
"destructiveHint": false,
|
|
6937
|
-
"idempotentHint":
|
|
7337
|
+
"idempotentHint": true
|
|
6938
7338
|
}
|
|
6939
7339
|
},
|
|
6940
|
-
"description": "
|
|
7340
|
+
"description": "Returns a reservation as it stands: held, committed, released or expired, with what it reserved and what it finally used. A reservation past its expiry that nobody committed or released reads as expired. Reading it changes nothing.",
|
|
6941
7341
|
"fields": [
|
|
6942
7342
|
{
|
|
6943
7343
|
"name": "reservationId",
|
|
@@ -6957,62 +7357,44 @@ var OPERATIONS = [
|
|
|
6957
7357
|
"scope": "checks:write"
|
|
6958
7358
|
},
|
|
6959
7359
|
{
|
|
6960
|
-
"operationId": "
|
|
6961
|
-
"method": "
|
|
6962
|
-
"path": "/
|
|
6963
|
-
"summary": "
|
|
7360
|
+
"operationId": "reservations.release",
|
|
7361
|
+
"method": "post",
|
|
7362
|
+
"path": "/reservations/{reservationId}/release",
|
|
7363
|
+
"summary": "Release a reservation",
|
|
6964
7364
|
"cli": {
|
|
6965
|
-
"command": "
|
|
7365
|
+
"command": "reservations release",
|
|
6966
7366
|
"args": [
|
|
6967
|
-
"
|
|
6968
|
-
"subjectId"
|
|
7367
|
+
"reservationId"
|
|
6969
7368
|
],
|
|
6970
|
-
"confirm":
|
|
7369
|
+
"confirm": false
|
|
6971
7370
|
},
|
|
6972
7371
|
"mcp": {
|
|
6973
7372
|
"exposed": true,
|
|
6974
|
-
"name": "
|
|
7373
|
+
"name": "reservations_release",
|
|
6975
7374
|
"hints": {
|
|
6976
7375
|
"readOnlyHint": false,
|
|
6977
|
-
"destructiveHint":
|
|
6978
|
-
"idempotentHint":
|
|
7376
|
+
"destructiveHint": false,
|
|
7377
|
+
"idempotentHint": false
|
|
6979
7378
|
}
|
|
6980
7379
|
},
|
|
6981
|
-
"description": "
|
|
7380
|
+
"description": "Gives the whole reservation back, because the work didn't happen. Repeating a release within 24 hours returns the same result. You can't release a reservation you've already committed. We cache its API key check briefly for speed. A revoked key can keep working here for up to 60 seconds.",
|
|
6982
7381
|
"fields": [
|
|
6983
7382
|
{
|
|
6984
|
-
"name": "
|
|
6985
|
-
"in": "path",
|
|
6986
|
-
"type": "string",
|
|
6987
|
-
"required": true,
|
|
6988
|
-
"description": "The subject kind's ID.",
|
|
6989
|
-
"example": "team",
|
|
6990
|
-
"schema": {
|
|
6991
|
-
"type": "string",
|
|
6992
|
-
"minLength": 1,
|
|
6993
|
-
"maxLength": 100,
|
|
6994
|
-
"description": "The subject kind's ID."
|
|
6995
|
-
}
|
|
6996
|
-
},
|
|
6997
|
-
{
|
|
6998
|
-
"name": "subjectId",
|
|
7383
|
+
"name": "reservationId",
|
|
6999
7384
|
"in": "path",
|
|
7000
7385
|
"type": "string",
|
|
7001
7386
|
"required": true,
|
|
7002
|
-
"description": "The
|
|
7003
|
-
"example": "team_42",
|
|
7387
|
+
"description": "The reservation's ID.",
|
|
7004
7388
|
"schema": {
|
|
7005
7389
|
"type": "string",
|
|
7006
|
-
"
|
|
7007
|
-
"maxLength": 200,
|
|
7008
|
-
"description": "The subject's ID."
|
|
7390
|
+
"description": "The reservation's ID."
|
|
7009
7391
|
}
|
|
7010
7392
|
}
|
|
7011
7393
|
],
|
|
7012
7394
|
"hasBody": false,
|
|
7013
7395
|
"workspace": true,
|
|
7014
7396
|
"acceptsApiKey": true,
|
|
7015
|
-
"scope": "
|
|
7397
|
+
"scope": "checks:write"
|
|
7016
7398
|
},
|
|
7017
7399
|
{
|
|
7018
7400
|
"operationId": "subjects.get",
|
|
@@ -7182,6 +7564,32 @@ var OPERATIONS = [
|
|
|
7182
7564
|
},
|
|
7183
7565
|
"description": "Lists every subject your checks have named in this environment, and every one you named, most recently checked first. Filter by `kind` or by one `label`, and search the name or the ID with `q`. Results come a page at a time.",
|
|
7184
7566
|
"fields": [
|
|
7567
|
+
{
|
|
7568
|
+
"name": "limit",
|
|
7569
|
+
"in": "query",
|
|
7570
|
+
"type": "number",
|
|
7571
|
+
"required": false,
|
|
7572
|
+
"description": "Items per page, 1\u2013100 (default 25).",
|
|
7573
|
+
"example": 25,
|
|
7574
|
+
"schema": {
|
|
7575
|
+
"type": "integer",
|
|
7576
|
+
"minimum": 1,
|
|
7577
|
+
"maximum": 100,
|
|
7578
|
+
"default": 25,
|
|
7579
|
+
"description": "Items per page, 1\u2013100 (default 25)."
|
|
7580
|
+
}
|
|
7581
|
+
},
|
|
7582
|
+
{
|
|
7583
|
+
"name": "cursor",
|
|
7584
|
+
"in": "query",
|
|
7585
|
+
"type": "string",
|
|
7586
|
+
"required": false,
|
|
7587
|
+
"description": "Opaque token from a previous page's nextCursor.",
|
|
7588
|
+
"schema": {
|
|
7589
|
+
"type": "string",
|
|
7590
|
+
"description": "Opaque token from a previous page's nextCursor."
|
|
7591
|
+
}
|
|
7592
|
+
},
|
|
7185
7593
|
{
|
|
7186
7594
|
"name": "kind",
|
|
7187
7595
|
"in": "query",
|
|
@@ -7221,39 +7629,71 @@ var OPERATIONS = [
|
|
|
7221
7629
|
"maxLength": 200,
|
|
7222
7630
|
"description": "Only subjects whose name or ID contains this text, in any case."
|
|
7223
7631
|
}
|
|
7224
|
-
}
|
|
7632
|
+
}
|
|
7633
|
+
],
|
|
7634
|
+
"hasBody": false,
|
|
7635
|
+
"paginated": true,
|
|
7636
|
+
"workspace": true,
|
|
7637
|
+
"acceptsApiKey": true,
|
|
7638
|
+
"scope": "limits:read"
|
|
7639
|
+
},
|
|
7640
|
+
{
|
|
7641
|
+
"operationId": "subjects.names.delete",
|
|
7642
|
+
"method": "delete",
|
|
7643
|
+
"path": "/subjects/{subjectKind}/{subjectId}/names",
|
|
7644
|
+
"summary": "Erase a subject's name and labels",
|
|
7645
|
+
"cli": {
|
|
7646
|
+
"command": "subjects names delete",
|
|
7647
|
+
"args": [
|
|
7648
|
+
"subjectKind",
|
|
7649
|
+
"subjectId"
|
|
7650
|
+
],
|
|
7651
|
+
"confirm": true
|
|
7652
|
+
},
|
|
7653
|
+
"mcp": {
|
|
7654
|
+
"exposed": true,
|
|
7655
|
+
"name": "subjects_names_delete",
|
|
7656
|
+
"hints": {
|
|
7657
|
+
"readOnlyHint": false,
|
|
7658
|
+
"destructiveHint": true,
|
|
7659
|
+
"idempotentHint": true
|
|
7660
|
+
}
|
|
7661
|
+
},
|
|
7662
|
+
"description": "Erases the name and labels you gave a subject. Its limits, usage and billing date stay, because they're kept by its ID. Use it when one of your users asks you to delete their data. Erasing a subject with no name or labels succeeds too. With a personal access token, only owners and admins can call this. A workspace API key with this scope can.",
|
|
7663
|
+
"fields": [
|
|
7225
7664
|
{
|
|
7226
|
-
"name": "
|
|
7227
|
-
"in": "
|
|
7228
|
-
"type": "
|
|
7229
|
-
"required":
|
|
7230
|
-
"description": "
|
|
7231
|
-
"example":
|
|
7665
|
+
"name": "subjectKind",
|
|
7666
|
+
"in": "path",
|
|
7667
|
+
"type": "string",
|
|
7668
|
+
"required": true,
|
|
7669
|
+
"description": "The subject kind's ID.",
|
|
7670
|
+
"example": "team",
|
|
7232
7671
|
"schema": {
|
|
7233
|
-
"type": "
|
|
7234
|
-
"
|
|
7235
|
-
"
|
|
7236
|
-
"
|
|
7237
|
-
"description": "How many to return, from 1 to 100. Default: 25."
|
|
7672
|
+
"type": "string",
|
|
7673
|
+
"minLength": 1,
|
|
7674
|
+
"maxLength": 100,
|
|
7675
|
+
"description": "The subject kind's ID."
|
|
7238
7676
|
}
|
|
7239
7677
|
},
|
|
7240
7678
|
{
|
|
7241
|
-
"name": "
|
|
7242
|
-
"in": "
|
|
7679
|
+
"name": "subjectId",
|
|
7680
|
+
"in": "path",
|
|
7243
7681
|
"type": "string",
|
|
7244
|
-
"required":
|
|
7245
|
-
"description": "The
|
|
7682
|
+
"required": true,
|
|
7683
|
+
"description": "The subject's ID.",
|
|
7684
|
+
"example": "team_42",
|
|
7246
7685
|
"schema": {
|
|
7247
7686
|
"type": "string",
|
|
7687
|
+
"minLength": 1,
|
|
7248
7688
|
"maxLength": 200,
|
|
7249
|
-
"description": "The
|
|
7689
|
+
"description": "The subject's ID."
|
|
7250
7690
|
}
|
|
7251
7691
|
}
|
|
7252
7692
|
],
|
|
7253
7693
|
"hasBody": false,
|
|
7254
7694
|
"workspace": true,
|
|
7255
7695
|
"acceptsApiKey": true,
|
|
7256
|
-
"scope": "limits:
|
|
7696
|
+
"scope": "limits:write"
|
|
7257
7697
|
},
|
|
7258
7698
|
{
|
|
7259
7699
|
"operationId": "subjects.reset",
|
|
@@ -7326,12 +7766,12 @@ var OPERATIONS = [
|
|
|
7326
7766
|
"scope": "limits:write"
|
|
7327
7767
|
},
|
|
7328
7768
|
{
|
|
7329
|
-
"operationId": "subjects.
|
|
7330
|
-
"method": "
|
|
7331
|
-
"path": "/subjects/{subjectKind}/{subjectId}/
|
|
7332
|
-
"summary": "
|
|
7769
|
+
"operationId": "subjects.standing",
|
|
7770
|
+
"method": "get",
|
|
7771
|
+
"path": "/subjects/{subjectKind}/{subjectId}/standing",
|
|
7772
|
+
"summary": "Get where a subject stands",
|
|
7333
7773
|
"cli": {
|
|
7334
|
-
"command": "subjects
|
|
7774
|
+
"command": "subjects standing",
|
|
7335
7775
|
"args": [
|
|
7336
7776
|
"subjectKind",
|
|
7337
7777
|
"subjectId"
|
|
@@ -7340,14 +7780,14 @@ var OPERATIONS = [
|
|
|
7340
7780
|
},
|
|
7341
7781
|
"mcp": {
|
|
7342
7782
|
"exposed": true,
|
|
7343
|
-
"name": "
|
|
7783
|
+
"name": "subjects_standing",
|
|
7344
7784
|
"hints": {
|
|
7345
|
-
"readOnlyHint":
|
|
7785
|
+
"readOnlyHint": true,
|
|
7346
7786
|
"destructiveHint": false,
|
|
7347
7787
|
"idempotentHint": true
|
|
7348
7788
|
}
|
|
7349
7789
|
},
|
|
7350
|
-
"description": "
|
|
7790
|
+
"description": "Returns where one subject stands on every enabled limit, exact as of now. It covers the subject's own limits and the limits on its shared subjects. List the shared subjects in `shared`, such as `team:team_42`. Each limit shows what's used, what's left and when it resets. Use it to show your users where they stand. Call it from your server with your key, never from a browser. It isn't a check, so it counts nothing. A subject with no limits returns an empty `limits` list.",
|
|
7351
7791
|
"fields": [
|
|
7352
7792
|
{
|
|
7353
7793
|
"name": "subjectKind",
|
|
@@ -7378,54 +7818,29 @@ var OPERATIONS = [
|
|
|
7378
7818
|
}
|
|
7379
7819
|
},
|
|
7380
7820
|
{
|
|
7381
|
-
"name": "
|
|
7382
|
-
"in": "
|
|
7821
|
+
"name": "shared",
|
|
7822
|
+
"in": "query",
|
|
7383
7823
|
"type": "string",
|
|
7384
7824
|
"required": false,
|
|
7385
|
-
"description": "
|
|
7386
|
-
"example": "
|
|
7387
|
-
"schema": {
|
|
7388
|
-
"type": [
|
|
7389
|
-
"string",
|
|
7390
|
-
"null"
|
|
7391
|
-
],
|
|
7392
|
-
"minLength": 1,
|
|
7393
|
-
"maxLength": 200,
|
|
7394
|
-
"description": "A name people can read, up to 200 characters. Optional. Names don't have to be unique. Send null to clear it."
|
|
7395
|
-
}
|
|
7396
|
-
},
|
|
7397
|
-
{
|
|
7398
|
-
"name": "labels",
|
|
7399
|
-
"in": "body",
|
|
7400
|
-
"type": "json",
|
|
7401
|
-
"required": false,
|
|
7402
|
-
"description": "Labels to filter by, such as a plan or a region: up to 20 keys of up to 40 characters, with values of up to 200. Optional. They replace the subject's labels. Send null to clear them.",
|
|
7403
|
-
"example": {
|
|
7404
|
-
"plan": "pro"
|
|
7405
|
-
},
|
|
7825
|
+
"description": "Shared subjects to include, as comma-separated `kind:id` pairs. Send up to 4.",
|
|
7826
|
+
"example": "team:team_42",
|
|
7406
7827
|
"schema": {
|
|
7407
|
-
"type":
|
|
7408
|
-
|
|
7409
|
-
|
|
7410
|
-
],
|
|
7411
|
-
"additionalProperties": {
|
|
7412
|
-
"type": "string",
|
|
7413
|
-
"maxLength": 200
|
|
7414
|
-
},
|
|
7415
|
-
"description": "Labels to filter by, such as a plan or a region: up to 20 keys of up to 40 characters, with values of up to 200. Optional. They replace the subject's labels. Send null to clear them."
|
|
7828
|
+
"type": "string",
|
|
7829
|
+
"maxLength": 1500,
|
|
7830
|
+
"description": "Shared subjects to include, as comma-separated `kind:id` pairs. Send up to 4."
|
|
7416
7831
|
}
|
|
7417
7832
|
}
|
|
7418
7833
|
],
|
|
7419
|
-
"hasBody":
|
|
7834
|
+
"hasBody": false,
|
|
7420
7835
|
"workspace": true,
|
|
7421
7836
|
"acceptsApiKey": true,
|
|
7422
|
-
"scope": "limits:
|
|
7837
|
+
"scope": "limits:read"
|
|
7423
7838
|
},
|
|
7424
7839
|
{
|
|
7425
7840
|
"operationId": "subjects.update",
|
|
7426
7841
|
"method": "patch",
|
|
7427
7842
|
"path": "/subjects/{subjectKind}/{subjectId}",
|
|
7428
|
-
"summary": "
|
|
7843
|
+
"summary": "Update a subject",
|
|
7429
7844
|
"cli": {
|
|
7430
7845
|
"command": "subjects update",
|
|
7431
7846
|
"args": [
|
|
@@ -7443,7 +7858,7 @@ var OPERATIONS = [
|
|
|
7443
7858
|
"idempotentHint": false
|
|
7444
7859
|
}
|
|
7445
7860
|
},
|
|
7446
|
-
"description": "Sets
|
|
7861
|
+
"description": "Sets a subject's billing date, its name, its labels, or any of them. A field you leave out stays as it is, and null clears a name or labels. Labels you send replace the subject's labels. The billing date is the moment the subject's `billing_date` limits count their periods from, usually the subscription's start, set from your billing system's webhook. The subject's allowance then resets on its own billing day, and a monthly limit still resets monthly on an annual plan. A name and labels are optional, and checks never need them. With a personal access token, only owners and admins can call this. A workspace API key with this scope can.",
|
|
7447
7862
|
"fields": [
|
|
7448
7863
|
{
|
|
7449
7864
|
"name": "subjectKind",
|
|
@@ -7474,16 +7889,54 @@ var OPERATIONS = [
|
|
|
7474
7889
|
}
|
|
7475
7890
|
},
|
|
7476
7891
|
{
|
|
7477
|
-
"name": "
|
|
7892
|
+
"name": "billingAnchorAt",
|
|
7478
7893
|
"in": "body",
|
|
7479
7894
|
"type": "string",
|
|
7480
|
-
"required":
|
|
7481
|
-
"description": "The
|
|
7895
|
+
"required": false,
|
|
7896
|
+
"description": "The moment the subject's periods start from, in ISO 8601, such as a subscription's start.",
|
|
7482
7897
|
"example": "2026-03-17T14:30:00Z",
|
|
7483
7898
|
"schema": {
|
|
7484
7899
|
"type": "string",
|
|
7485
7900
|
"format": "date-time",
|
|
7486
|
-
"description": "The
|
|
7901
|
+
"description": "The moment the subject's periods start from, in ISO 8601, such as a subscription's start."
|
|
7902
|
+
}
|
|
7903
|
+
},
|
|
7904
|
+
{
|
|
7905
|
+
"name": "name",
|
|
7906
|
+
"in": "body",
|
|
7907
|
+
"type": "string",
|
|
7908
|
+
"required": false,
|
|
7909
|
+
"description": "A name people can read, up to 200 characters. Optional. Names don't have to be unique. Send null to clear it.",
|
|
7910
|
+
"example": "Design team",
|
|
7911
|
+
"schema": {
|
|
7912
|
+
"type": [
|
|
7913
|
+
"string",
|
|
7914
|
+
"null"
|
|
7915
|
+
],
|
|
7916
|
+
"minLength": 1,
|
|
7917
|
+
"maxLength": 200,
|
|
7918
|
+
"description": "A name people can read, up to 200 characters. Optional. Names don't have to be unique. Send null to clear it."
|
|
7919
|
+
}
|
|
7920
|
+
},
|
|
7921
|
+
{
|
|
7922
|
+
"name": "labels",
|
|
7923
|
+
"in": "body",
|
|
7924
|
+
"type": "json",
|
|
7925
|
+
"required": false,
|
|
7926
|
+
"description": "Labels to filter by, such as a plan or a region: up to 20 keys of up to 40 characters, with values of up to 200. Optional. They replace the subject's labels. Send null to clear them.",
|
|
7927
|
+
"example": {
|
|
7928
|
+
"plan": "pro"
|
|
7929
|
+
},
|
|
7930
|
+
"schema": {
|
|
7931
|
+
"type": [
|
|
7932
|
+
"object",
|
|
7933
|
+
"null"
|
|
7934
|
+
],
|
|
7935
|
+
"additionalProperties": {
|
|
7936
|
+
"type": "string",
|
|
7937
|
+
"maxLength": 200
|
|
7938
|
+
},
|
|
7939
|
+
"description": "Labels to filter by, such as a plan or a region: up to 20 keys of up to 40 characters, with values of up to 200. Optional. They replace the subject's labels. Send null to clear them."
|
|
7487
7940
|
}
|
|
7488
7941
|
}
|
|
7489
7942
|
],
|
|
@@ -7649,7 +8102,7 @@ var OPERATIONS = [
|
|
|
7649
8102
|
"type": "string",
|
|
7650
8103
|
"required": false,
|
|
7651
8104
|
"description": "One subject, as `kind:id`, to see its usage instead of every subject's.",
|
|
7652
|
-
"example": "user:
|
|
8105
|
+
"example": "user:user_123",
|
|
7653
8106
|
"schema": {
|
|
7654
8107
|
"type": "string",
|
|
7655
8108
|
"minLength": 3,
|
|
@@ -7724,59 +8177,6 @@ var OPERATIONS = [
|
|
|
7724
8177
|
"acceptsApiKey": true,
|
|
7725
8178
|
"scope": "limits:read"
|
|
7726
8179
|
},
|
|
7727
|
-
{
|
|
7728
|
-
"operationId": "usage.standing",
|
|
7729
|
-
"method": "get",
|
|
7730
|
-
"path": "/usage/standing",
|
|
7731
|
-
"summary": "Get where a subject stands",
|
|
7732
|
-
"cli": {
|
|
7733
|
-
"command": "usage standing",
|
|
7734
|
-
"args": [],
|
|
7735
|
-
"confirm": false
|
|
7736
|
-
},
|
|
7737
|
-
"mcp": {
|
|
7738
|
-
"exposed": true,
|
|
7739
|
-
"name": "usage_standing",
|
|
7740
|
-
"hints": {
|
|
7741
|
-
"readOnlyHint": true,
|
|
7742
|
-
"destructiveHint": false,
|
|
7743
|
-
"idempotentHint": true
|
|
7744
|
-
}
|
|
7745
|
-
},
|
|
7746
|
-
"description": "Returns where one subject stands on every enabled limit, exact as of now. It covers the subject's own limits and the limits on its shared subjects. Name the subject as `kind:id`, such as `user:usr_123`, and list its shared subjects in `shared`, such as `team:team_42`. Each limit shows what's used, what's left and when it resets. Use it to show your users where they stand. Call it from your server with your key, never from a browser. It isn't a check, so it counts nothing. A subject with no limits returns an empty `limits` list.",
|
|
7747
|
-
"fields": [
|
|
7748
|
-
{
|
|
7749
|
-
"name": "subject",
|
|
7750
|
-
"in": "query",
|
|
7751
|
-
"type": "string",
|
|
7752
|
-
"required": true,
|
|
7753
|
-
"description": "The subject, written as `kind:id` exactly as your checks send it.",
|
|
7754
|
-
"example": "user:usr_123",
|
|
7755
|
-
"schema": {
|
|
7756
|
-
"type": "string",
|
|
7757
|
-
"minLength": 3,
|
|
7758
|
-
"maxLength": 301,
|
|
7759
|
-
"description": "The subject, written as `kind:id` exactly as your checks send it."
|
|
7760
|
-
}
|
|
7761
|
-
},
|
|
7762
|
-
{
|
|
7763
|
-
"name": "shared",
|
|
7764
|
-
"in": "query",
|
|
7765
|
-
"type": "string",
|
|
7766
|
-
"required": false,
|
|
7767
|
-
"description": "Shared subjects to include, as comma-separated `kind:id` pairs. Send up to 4.",
|
|
7768
|
-
"example": "team:team_42",
|
|
7769
|
-
"schema": {
|
|
7770
|
-
"type": "string",
|
|
7771
|
-
"description": "Shared subjects to include, as comma-separated `kind:id` pairs. Send up to 4."
|
|
7772
|
-
}
|
|
7773
|
-
}
|
|
7774
|
-
],
|
|
7775
|
-
"hasBody": false,
|
|
7776
|
-
"workspace": true,
|
|
7777
|
-
"acceptsApiKey": true,
|
|
7778
|
-
"scope": "limits:read"
|
|
7779
|
-
},
|
|
7780
8180
|
{
|
|
7781
8181
|
"operationId": "usage.subjects",
|
|
7782
8182
|
"method": "get",
|
|
@@ -7885,17 +8285,17 @@ var OPERATIONS = [
|
|
|
7885
8285
|
}
|
|
7886
8286
|
},
|
|
7887
8287
|
{
|
|
7888
|
-
"name": "
|
|
8288
|
+
"name": "top",
|
|
7889
8289
|
"in": "query",
|
|
7890
8290
|
"type": "number",
|
|
7891
8291
|
"required": false,
|
|
7892
|
-
"description": "How many subjects to
|
|
8292
|
+
"description": "How many subjects to rank, up to 50. Default: 50. A `concurrent` limit ranks at most 25.",
|
|
7893
8293
|
"schema": {
|
|
7894
8294
|
"type": "integer",
|
|
7895
8295
|
"minimum": 1,
|
|
7896
|
-
"maximum":
|
|
8296
|
+
"maximum": 50,
|
|
7897
8297
|
"default": 50,
|
|
7898
|
-
"description": "How many subjects to
|
|
8298
|
+
"description": "How many subjects to rank, up to 50. Default: 50. A `concurrent` limit ranks at most 25."
|
|
7899
8299
|
}
|
|
7900
8300
|
}
|
|
7901
8301
|
],
|
|
@@ -7963,9 +8363,10 @@ var OPERATIONS = [
|
|
|
7963
8363
|
"idempotentHint": true
|
|
7964
8364
|
}
|
|
7965
8365
|
},
|
|
7966
|
-
"description": "Lists the actions a credential can't take itself but can ask a person to approve. Each action comes with its input as a JSON Schema, who can approve it and whether it creates a secret.",
|
|
8366
|
+
"description": "Lists the actions a credential can't take itself but can ask a person to approve. Each action comes with its input as a JSON Schema (`inputSchema`), who can approve it and whether it creates a secret. Every action fits on one page, so `nextCursor` is null.",
|
|
7967
8367
|
"fields": [],
|
|
7968
8368
|
"hasBody": false,
|
|
8369
|
+
"paginated": true,
|
|
7969
8370
|
"workspace": true,
|
|
7970
8371
|
"acceptsApiKey": true,
|
|
7971
8372
|
"scope": "workspace.approvals:read"
|
|
@@ -8044,12 +8445,12 @@ var OPERATIONS = [
|
|
|
8044
8445
|
{
|
|
8045
8446
|
"operationId": "workspace.approvalRequests.get",
|
|
8046
8447
|
"method": "get",
|
|
8047
|
-
"path": "/workspace/approval-requests/{
|
|
8448
|
+
"path": "/workspace/approval-requests/{approvalRequestId}",
|
|
8048
8449
|
"summary": "Check an approval request",
|
|
8049
8450
|
"cli": {
|
|
8050
8451
|
"command": "workspace approval-requests get",
|
|
8051
8452
|
"args": [
|
|
8052
|
-
"
|
|
8453
|
+
"approvalRequestId"
|
|
8053
8454
|
],
|
|
8054
8455
|
"confirm": false
|
|
8055
8456
|
},
|
|
@@ -8065,15 +8466,15 @@ var OPERATIONS = [
|
|
|
8065
8466
|
"description": "Returns an approval request you created, with its status. A `pending` request is waiting for a person to decide. A `completed` request's action ran, and `result` holds the outcome. An `approved` request is waiting for the CLI to redeem it. A request can also be `denied`, `failed` or `expired`.",
|
|
8066
8467
|
"fields": [
|
|
8067
8468
|
{
|
|
8068
|
-
"name": "
|
|
8469
|
+
"name": "approvalRequestId",
|
|
8069
8470
|
"in": "path",
|
|
8070
8471
|
"type": "string",
|
|
8071
8472
|
"required": true,
|
|
8072
|
-
"description": "The request's id.",
|
|
8073
|
-
"example": "
|
|
8473
|
+
"description": "The approval request's id.",
|
|
8474
|
+
"example": "apr_7c2e9b4d-1f3a-4e5b-8c6d-7e8f9a0b1c2d",
|
|
8074
8475
|
"schema": {
|
|
8075
8476
|
"type": "string",
|
|
8076
|
-
"description": "The request's id."
|
|
8477
|
+
"description": "The approval request's id."
|
|
8077
8478
|
}
|
|
8078
8479
|
}
|
|
8079
8480
|
],
|
|
@@ -8085,12 +8486,12 @@ var OPERATIONS = [
|
|
|
8085
8486
|
{
|
|
8086
8487
|
"operationId": "workspace.approvalRequests.redeem",
|
|
8087
8488
|
"method": "post",
|
|
8088
|
-
"path": "/workspace/approval-requests/{
|
|
8489
|
+
"path": "/workspace/approval-requests/{approvalRequestId}/redeem",
|
|
8089
8490
|
"summary": "Redeem an approved request",
|
|
8090
8491
|
"cli": {
|
|
8091
8492
|
"command": "workspace approval-requests redeem",
|
|
8092
8493
|
"args": [
|
|
8093
|
-
"
|
|
8494
|
+
"approvalRequestId"
|
|
8094
8495
|
],
|
|
8095
8496
|
"confirm": false
|
|
8096
8497
|
},
|
|
@@ -8101,15 +8502,15 @@ var OPERATIONS = [
|
|
|
8101
8502
|
"description": "Runs an approved action that creates a secret, and returns the secret. The action runs only once. Only the personal access token that asked can redeem it. The CLI writes the secret to a file without printing it.",
|
|
8102
8503
|
"fields": [
|
|
8103
8504
|
{
|
|
8104
|
-
"name": "
|
|
8505
|
+
"name": "approvalRequestId",
|
|
8105
8506
|
"in": "path",
|
|
8106
8507
|
"type": "string",
|
|
8107
8508
|
"required": true,
|
|
8108
|
-
"description": "The request's id.",
|
|
8109
|
-
"example": "
|
|
8509
|
+
"description": "The approval request's id.",
|
|
8510
|
+
"example": "apr_7c2e9b4d-1f3a-4e5b-8c6d-7e8f9a0b1c2d",
|
|
8110
8511
|
"schema": {
|
|
8111
8512
|
"type": "string",
|
|
8112
|
-
"description": "The request's id."
|
|
8513
|
+
"description": "The approval request's id."
|
|
8113
8514
|
}
|
|
8114
8515
|
}
|
|
8115
8516
|
],
|
|
@@ -8184,7 +8585,7 @@ var OPERATIONS = [
|
|
|
8184
8585
|
"type": "string",
|
|
8185
8586
|
"required": false,
|
|
8186
8587
|
"description": "Only events of this action.",
|
|
8187
|
-
"example": "workspace.
|
|
8588
|
+
"example": "workspace.member.invited",
|
|
8188
8589
|
"schema": {
|
|
8189
8590
|
"type": "string",
|
|
8190
8591
|
"maxLength": 100,
|
|
@@ -8197,7 +8598,7 @@ var OPERATIONS = [
|
|
|
8197
8598
|
"type": "string",
|
|
8198
8599
|
"required": false,
|
|
8199
8600
|
"description": "Only what one person did (`user:` and the item's `actor.id`), or one key or token (`credential:` and the item's `credential.id`).",
|
|
8200
|
-
"example": "user:
|
|
8601
|
+
"example": "user:usr_4f8a2c1e-7b3d-4e9f-a6c5-2d1b0e9f8a7c",
|
|
8201
8602
|
"schema": {
|
|
8202
8603
|
"type": "string",
|
|
8203
8604
|
"pattern": "^(user|credential):[\\w-]+$",
|
|
@@ -8206,6 +8607,7 @@ var OPERATIONS = [
|
|
|
8206
8607
|
}
|
|
8207
8608
|
],
|
|
8208
8609
|
"hasBody": false,
|
|
8610
|
+
"paginated": true,
|
|
8209
8611
|
"workspace": true,
|
|
8210
8612
|
"acceptsApiKey": true,
|
|
8211
8613
|
"scope": "workspace.audit:read"
|
|
@@ -8229,9 +8631,10 @@ var OPERATIONS = [
|
|
|
8229
8631
|
"idempotentHint": true
|
|
8230
8632
|
}
|
|
8231
8633
|
},
|
|
8232
|
-
"description": "Lists every workspace event a webhook endpoint can subscribe to, and what each one means. Pass some as `eventTypes` when you add an endpoint. An endpoint without a list receives every event.",
|
|
8634
|
+
"description": "Lists every workspace event a webhook endpoint can subscribe to, and what each one means. Pass some as `eventTypes` when you add an endpoint. An endpoint without a list receives every event. Every type fits on one page, so `nextCursor` is null.",
|
|
8233
8635
|
"fields": [],
|
|
8234
8636
|
"hasBody": false,
|
|
8637
|
+
"paginated": true,
|
|
8235
8638
|
"workspace": true,
|
|
8236
8639
|
"acceptsApiKey": true,
|
|
8237
8640
|
"scope": "workspace.webhooks:read"
|
|
@@ -8311,6 +8714,7 @@ var OPERATIONS = [
|
|
|
8311
8714
|
}
|
|
8312
8715
|
],
|
|
8313
8716
|
"hasBody": false,
|
|
8717
|
+
"paginated": true,
|
|
8314
8718
|
"workspace": true,
|
|
8315
8719
|
"acceptsApiKey": true,
|
|
8316
8720
|
"scope": "workspace.members:read"
|
|
@@ -8364,10 +8768,37 @@ var OPERATIONS = [
|
|
|
8364
8768
|
}
|
|
8365
8769
|
],
|
|
8366
8770
|
"hasBody": false,
|
|
8771
|
+
"paginated": true,
|
|
8367
8772
|
"workspace": true,
|
|
8368
8773
|
"acceptsApiKey": true,
|
|
8369
8774
|
"scope": "workspace.members:read"
|
|
8370
8775
|
},
|
|
8776
|
+
{
|
|
8777
|
+
"operationId": "workspace.planUsage.get",
|
|
8778
|
+
"method": "get",
|
|
8779
|
+
"path": "/workspace/plan-usage",
|
|
8780
|
+
"summary": "Get your plan's usage this period",
|
|
8781
|
+
"cli": {
|
|
8782
|
+
"command": "workspace plan-usage get",
|
|
8783
|
+
"args": [],
|
|
8784
|
+
"confirm": false
|
|
8785
|
+
},
|
|
8786
|
+
"mcp": {
|
|
8787
|
+
"exposed": true,
|
|
8788
|
+
"name": "workspace_plan_usage_get",
|
|
8789
|
+
"hints": {
|
|
8790
|
+
"readOnlyHint": true,
|
|
8791
|
+
"destructiveHint": false,
|
|
8792
|
+
"idempotentHint": true
|
|
8793
|
+
}
|
|
8794
|
+
},
|
|
8795
|
+
"description": "Returns what the workspace used this period, with one entry for each thing its plan counts. Each entry has the plan's limit, or null when there is no limit. Each entry also says where it stands and where we start refusing new use. A period is one month from the workspace's billing date. That date comes from its subscription or, without one, from the day you created the workspace. On an annual plan, the counts still reset every month from the subscription's start.",
|
|
8796
|
+
"fields": [],
|
|
8797
|
+
"hasBody": false,
|
|
8798
|
+
"workspace": true,
|
|
8799
|
+
"acceptsApiKey": true,
|
|
8800
|
+
"scope": "workspace:read"
|
|
8801
|
+
},
|
|
8371
8802
|
{
|
|
8372
8803
|
"operationId": "workspace.teams.list",
|
|
8373
8804
|
"method": "get",
|
|
@@ -8417,36 +8848,11 @@ var OPERATIONS = [
|
|
|
8417
8848
|
}
|
|
8418
8849
|
],
|
|
8419
8850
|
"hasBody": false,
|
|
8851
|
+
"paginated": true,
|
|
8420
8852
|
"workspace": true,
|
|
8421
8853
|
"acceptsApiKey": true,
|
|
8422
8854
|
"scope": "workspace.teams:read"
|
|
8423
8855
|
},
|
|
8424
|
-
{
|
|
8425
|
-
"operationId": "workspace.usage",
|
|
8426
|
-
"method": "get",
|
|
8427
|
-
"path": "/workspace/usage",
|
|
8428
|
-
"summary": "Get your plan's usage this period",
|
|
8429
|
-
"cli": {
|
|
8430
|
-
"command": "workspace usage",
|
|
8431
|
-
"args": [],
|
|
8432
|
-
"confirm": false
|
|
8433
|
-
},
|
|
8434
|
-
"mcp": {
|
|
8435
|
-
"exposed": true,
|
|
8436
|
-
"name": "workspace_usage",
|
|
8437
|
-
"hints": {
|
|
8438
|
-
"readOnlyHint": true,
|
|
8439
|
-
"destructiveHint": false,
|
|
8440
|
-
"idempotentHint": true
|
|
8441
|
-
}
|
|
8442
|
-
},
|
|
8443
|
-
"description": "Returns what the workspace used this period, with one entry for each thing its plan counts. Each entry has the plan's limit, or null when there is no limit. Each entry also says where it stands and where we start refusing new use. A period is one month from the workspace's billing date. That date comes from its subscription or, without one, from the day you created the workspace. On an annual plan, the counts still reset every month from the subscription's start.",
|
|
8444
|
-
"fields": [],
|
|
8445
|
-
"hasBody": false,
|
|
8446
|
-
"workspace": true,
|
|
8447
|
-
"acceptsApiKey": true,
|
|
8448
|
-
"scope": "workspace:read"
|
|
8449
|
-
},
|
|
8450
8856
|
{
|
|
8451
8857
|
"operationId": "workspace.webhookDeliveries.list",
|
|
8452
8858
|
"method": "get",
|
|
@@ -8468,7 +8874,7 @@ var OPERATIONS = [
|
|
|
8468
8874
|
"idempotentHint": true
|
|
8469
8875
|
}
|
|
8470
8876
|
},
|
|
8471
|
-
"description": "Lists one endpoint's delivery history, newest first. Each entry shows the
|
|
8877
|
+
"description": "Lists one endpoint's delivery history, newest first. Each entry shows the delivery's state, its attempts and the last HTTP status code. Payloads aren't included. We keep the history for 30 days. Paginate with the opaque `nextCursor`. `before` starts from a moment, and `status` keeps one kind of delivery. With a personal access token, the workspace's owners and admins can call this, and members on the test side. A workspace API key with this scope can.",
|
|
8472
8878
|
"fields": [
|
|
8473
8879
|
{
|
|
8474
8880
|
"name": "endpointId",
|
|
@@ -8476,7 +8882,7 @@ var OPERATIONS = [
|
|
|
8476
8882
|
"type": "string",
|
|
8477
8883
|
"required": true,
|
|
8478
8884
|
"description": "The endpoint's ID.",
|
|
8479
|
-
"example": "
|
|
8885
|
+
"example": "we_3f0c1a2e-4b5d-4c6e-8f70-1a2b3c4d5e6f",
|
|
8480
8886
|
"schema": {
|
|
8481
8887
|
"type": "string",
|
|
8482
8888
|
"description": "The endpoint's ID."
|
|
@@ -8540,6 +8946,7 @@ var OPERATIONS = [
|
|
|
8540
8946
|
}
|
|
8541
8947
|
],
|
|
8542
8948
|
"hasBody": false,
|
|
8949
|
+
"paginated": true,
|
|
8543
8950
|
"workspace": true,
|
|
8544
8951
|
"acceptsApiKey": true,
|
|
8545
8952
|
"scope": "workspace.webhooks:read"
|
|
@@ -8566,7 +8973,7 @@ var OPERATIONS = [
|
|
|
8566
8973
|
"idempotentHint": false
|
|
8567
8974
|
}
|
|
8568
8975
|
},
|
|
8569
|
-
"description": "Sends a recorded delivery's event again, as a new delivery. The new delivery gets its own history entry. The event id stays the same, so receivers can deduplicate. Redelivery only works on an enabled endpoint. With a personal access token, the workspace's owners and admins can call this, and members on the test side. A workspace API key with this scope can.",
|
|
8976
|
+
"description": "Sends a recorded delivery's event again, as a new delivery. The new delivery gets its own history entry. The event id stays the same, so receivers can deduplicate. Redelivery only works on an enabled endpoint. It answers 200 when we attempted the delivery right away, with the endpoint's answer, and 202 when it went to the queue. With a personal access token, the workspace's owners and admins can call this, and members on the test side. A workspace API key with this scope can.",
|
|
8570
8977
|
"fields": [
|
|
8571
8978
|
{
|
|
8572
8979
|
"name": "endpointId",
|
|
@@ -8574,7 +8981,7 @@ var OPERATIONS = [
|
|
|
8574
8981
|
"type": "string",
|
|
8575
8982
|
"required": true,
|
|
8576
8983
|
"description": "The endpoint's ID.",
|
|
8577
|
-
"example": "
|
|
8984
|
+
"example": "we_3f0c1a2e-4b5d-4c6e-8f70-1a2b3c4d5e6f",
|
|
8578
8985
|
"schema": {
|
|
8579
8986
|
"type": "string",
|
|
8580
8987
|
"description": "The endpoint's ID."
|
|
@@ -8586,7 +8993,7 @@ var OPERATIONS = [
|
|
|
8586
8993
|
"type": "string",
|
|
8587
8994
|
"required": true,
|
|
8588
8995
|
"description": "The delivery's ID.",
|
|
8589
|
-
"example": "
|
|
8996
|
+
"example": "del_8a1b2c3d-4e5f-4a6b-9c7d-8e9f0a1b2c3d",
|
|
8590
8997
|
"schema": {
|
|
8591
8998
|
"type": "string",
|
|
8592
8999
|
"description": "The delivery's ID."
|
|
@@ -8612,7 +9019,7 @@ var OPERATIONS = [
|
|
|
8612
9019
|
"exposed": false,
|
|
8613
9020
|
"reason": "Changes where workspace data is sent. A person configures webhook endpoints (Settings \u2192 Developers in the app)."
|
|
8614
9021
|
},
|
|
8615
|
-
"description": "Registers an HTTPS URL to receive the workspace's events. Deliveries use the same signature format as Svix. The response
|
|
9022
|
+
"description": "Registers an HTTPS URL to receive the workspace's events. Deliveries use the same signature format as Svix. The response is the new endpoint with its signing secret (`whsec_\u2026`) in `secret`. You see it only once, so store it to verify deliveries. The API refuses private hosts and hosts without HTTPS. A workspace can have at most 10 endpoints. With a personal access token, the workspace's owners and admins can call this, and members on the test side. A workspace API key with this scope can.",
|
|
8616
9023
|
"fields": [
|
|
8617
9024
|
{
|
|
8618
9025
|
"name": "url",
|
|
@@ -8688,7 +9095,7 @@ var OPERATIONS = [
|
|
|
8688
9095
|
"type": "string",
|
|
8689
9096
|
"required": true,
|
|
8690
9097
|
"description": "The endpoint's ID.",
|
|
8691
|
-
"example": "
|
|
9098
|
+
"example": "we_3f0c1a2e-4b5d-4c6e-8f70-1a2b3c4d5e6f",
|
|
8692
9099
|
"schema": {
|
|
8693
9100
|
"type": "string",
|
|
8694
9101
|
"description": "The endpoint's ID."
|
|
@@ -8724,7 +9131,7 @@ var OPERATIONS = [
|
|
|
8724
9131
|
"type": "string",
|
|
8725
9132
|
"required": true,
|
|
8726
9133
|
"description": "The endpoint's ID.",
|
|
8727
|
-
"example": "
|
|
9134
|
+
"example": "we_3f0c1a2e-4b5d-4c6e-8f70-1a2b3c4d5e6f",
|
|
8728
9135
|
"schema": {
|
|
8729
9136
|
"type": "string",
|
|
8730
9137
|
"description": "The endpoint's ID."
|
|
@@ -8765,7 +9172,7 @@ var OPERATIONS = [
|
|
|
8765
9172
|
"type": "string",
|
|
8766
9173
|
"required": true,
|
|
8767
9174
|
"description": "The endpoint's ID.",
|
|
8768
|
-
"example": "
|
|
9175
|
+
"example": "we_3f0c1a2e-4b5d-4c6e-8f70-1a2b3c4d5e6f",
|
|
8769
9176
|
"schema": {
|
|
8770
9177
|
"type": "string",
|
|
8771
9178
|
"description": "The endpoint's ID."
|
|
@@ -8799,6 +9206,7 @@ var OPERATIONS = [
|
|
|
8799
9206
|
"description": "Lists the workspace's outgoing webhook endpoints, newest first. The list leaves out their signing secrets. A workspace has at most 10 endpoints, so the list is a single page. Its `nextCursor` is null. With a personal access token, the workspace's owners and admins can call this, and members on the test side. A workspace API key with this scope can.",
|
|
8800
9207
|
"fields": [],
|
|
8801
9208
|
"hasBody": false,
|
|
9209
|
+
"paginated": true,
|
|
8802
9210
|
"workspace": true,
|
|
8803
9211
|
"acceptsApiKey": true,
|
|
8804
9212
|
"scope": "workspace.webhooks:read"
|
|
@@ -8824,7 +9232,7 @@ var OPERATIONS = [
|
|
|
8824
9232
|
"idempotentHint": false
|
|
8825
9233
|
}
|
|
8826
9234
|
},
|
|
8827
|
-
"description": "Sends a `ping` event to the endpoint, signed like every delivery. Use it to check that an integration verifies and accepts deliveries. With a personal access token, the workspace's owners and admins can call this, and members on the test side. A workspace API key with this scope can.",
|
|
9235
|
+
"description": "Sends a `ping` event to the endpoint, signed like every delivery. Use it to check that an integration verifies and accepts deliveries. It answers 200 when we attempted the delivery right away, with the endpoint's answer, and 202 when it went to the queue. With a personal access token, the workspace's owners and admins can call this, and members on the test side. A workspace API key with this scope can.",
|
|
8828
9236
|
"fields": [
|
|
8829
9237
|
{
|
|
8830
9238
|
"name": "endpointId",
|
|
@@ -8832,7 +9240,7 @@ var OPERATIONS = [
|
|
|
8832
9240
|
"type": "string",
|
|
8833
9241
|
"required": true,
|
|
8834
9242
|
"description": "The endpoint's ID.",
|
|
8835
|
-
"example": "
|
|
9243
|
+
"example": "we_3f0c1a2e-4b5d-4c6e-8f70-1a2b3c4d5e6f",
|
|
8836
9244
|
"schema": {
|
|
8837
9245
|
"type": "string",
|
|
8838
9246
|
"description": "The endpoint's ID."
|
|
@@ -8868,7 +9276,7 @@ var OPERATIONS = [
|
|
|
8868
9276
|
"type": "string",
|
|
8869
9277
|
"required": true,
|
|
8870
9278
|
"description": "The endpoint's ID.",
|
|
8871
|
-
"example": "
|
|
9279
|
+
"example": "we_3f0c1a2e-4b5d-4c6e-8f70-1a2b3c4d5e6f",
|
|
8872
9280
|
"schema": {
|
|
8873
9281
|
"type": "string",
|
|
8874
9282
|
"description": "The endpoint's ID."
|
|
@@ -8948,6 +9356,56 @@ function coveredOperations(program2) {
|
|
|
8948
9356
|
return covered;
|
|
8949
9357
|
}
|
|
8950
9358
|
|
|
9359
|
+
// src/flags.ts
|
|
9360
|
+
function kebab(name) {
|
|
9361
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
9362
|
+
}
|
|
9363
|
+
function optionKey(flagName) {
|
|
9364
|
+
return flagName.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
9365
|
+
}
|
|
9366
|
+
function singular(word) {
|
|
9367
|
+
if (/[^aeiou]ies$/.test(word)) return `${word.slice(0, -3)}y`;
|
|
9368
|
+
if (/(ss|us|is)$/.test(word)) return word;
|
|
9369
|
+
if (/(x|ch|sh|ss)es$/.test(word)) return word.slice(0, -2);
|
|
9370
|
+
if (word.endsWith("s")) return word.slice(0, -1);
|
|
9371
|
+
return word;
|
|
9372
|
+
}
|
|
9373
|
+
function types(schema) {
|
|
9374
|
+
if (!schema) return [];
|
|
9375
|
+
const own = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
|
|
9376
|
+
const variants = [...schema.anyOf ?? [], ...schema.oneOf ?? []];
|
|
9377
|
+
return [
|
|
9378
|
+
...own,
|
|
9379
|
+
...variants.flatMap(types),
|
|
9380
|
+
...schema.nullable ? ["null"] : []
|
|
9381
|
+
];
|
|
9382
|
+
}
|
|
9383
|
+
function nullable(field) {
|
|
9384
|
+
return types(field.schema).includes("null");
|
|
9385
|
+
}
|
|
9386
|
+
function fieldFlag(field, taken = /* @__PURE__ */ new Set()) {
|
|
9387
|
+
const schema = field.schema;
|
|
9388
|
+
const name = kebab(field.name);
|
|
9389
|
+
const clear = field.in === "body" && nullable(field) ? name : void 0;
|
|
9390
|
+
const base = { ...clear ? { clear } : {} };
|
|
9391
|
+
if (field.type === "boolean") return { name, kind: "boolean", ...base };
|
|
9392
|
+
const all = types(schema);
|
|
9393
|
+
const items = schema.items ?? [...schema.anyOf ?? []].find((s) => s.items)?.items;
|
|
9394
|
+
const itemTypes = types(items);
|
|
9395
|
+
const scalar = itemTypes.length > 0 && itemTypes.every((t) => ["string", "number", "integer"].includes(t));
|
|
9396
|
+
if (all.includes("array") && (scalar || Array.isArray(items?.enum))) {
|
|
9397
|
+
const words = name.split("-");
|
|
9398
|
+
const one = [...words.slice(0, -1), singular(words.at(-1))].join("-");
|
|
9399
|
+
return {
|
|
9400
|
+
name: one !== name && taken.has(one) ? name : one,
|
|
9401
|
+
kind: "list",
|
|
9402
|
+
...itemTypes.every((t) => t === "number" || t === "integer") ? { numbers: true } : {},
|
|
9403
|
+
...base
|
|
9404
|
+
};
|
|
9405
|
+
}
|
|
9406
|
+
return { name, kind: field.type === "json" ? "json" : "value", ...base };
|
|
9407
|
+
}
|
|
9408
|
+
|
|
8951
9409
|
// src/generated.ts
|
|
8952
9410
|
var generatedCommands = (program2, ctx) => {
|
|
8953
9411
|
const groups = /* @__PURE__ */ new Set();
|
|
@@ -8963,12 +9421,10 @@ var generatedCommands = (program2, ctx) => {
|
|
|
8963
9421
|
}
|
|
8964
9422
|
};
|
|
8965
9423
|
var RESERVED = /* @__PURE__ */ new Set(["json", "yes", "workspace", "data", "environment"]);
|
|
8966
|
-
|
|
8967
|
-
|
|
8968
|
-
|
|
8969
|
-
|
|
8970
|
-
return flag(name).replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
8971
|
-
}
|
|
9424
|
+
var collect = (value, previous) => [
|
|
9425
|
+
...previous ?? [],
|
|
9426
|
+
...value.split(",").map((part) => part.trim()).filter(Boolean)
|
|
9427
|
+
];
|
|
8972
9428
|
function register(program2, ctx, op, groups, hidden) {
|
|
8973
9429
|
const words = op.cli.command.split(" ");
|
|
8974
9430
|
const action = words.pop();
|
|
@@ -8987,22 +9443,41 @@ function register(program2, ctx, op, groups, hidden) {
|
|
|
8987
9443
|
return;
|
|
8988
9444
|
}
|
|
8989
9445
|
const positional = new Set(op.cli.args);
|
|
8990
|
-
const
|
|
9446
|
+
const fields = op.fields.filter(
|
|
8991
9447
|
(field) => !positional.has(field.name) && !RESERVED.has(field.name)
|
|
8992
9448
|
);
|
|
9449
|
+
const names = new Set(fields.map((field) => kebab(field.name)));
|
|
9450
|
+
const flags = fields.map((field) => ({
|
|
9451
|
+
field,
|
|
9452
|
+
spec: fieldFlag(field, names)
|
|
9453
|
+
}));
|
|
8993
9454
|
const command = parent.command(action, { hidden }).description(op.summary).addHelpText("after", `
|
|
8994
9455
|
${op.description}`);
|
|
8995
9456
|
markOperation(command, op.operationId);
|
|
8996
|
-
for (const arg of op.cli.args) command.argument(`<${
|
|
8997
|
-
for (const field of flags) {
|
|
9457
|
+
for (const arg of op.cli.args) command.argument(`<${kebab(arg)}>`);
|
|
9458
|
+
for (const { field, spec } of flags) {
|
|
8998
9459
|
const description = [
|
|
8999
9460
|
field.description ?? `${field.in} field`,
|
|
9461
|
+
spec.kind === "list" ? "Repeat it for each value." : "",
|
|
9000
9462
|
field.required ? "(required)" : ""
|
|
9001
9463
|
].filter(Boolean).join(" ");
|
|
9002
|
-
|
|
9003
|
-
|
|
9004
|
-
|
|
9005
|
-
)
|
|
9464
|
+
if (spec.kind === "boolean") {
|
|
9465
|
+
command.option(`--${spec.name}`, description);
|
|
9466
|
+
command.option(`--no-${spec.name}`, `turn --${spec.name} off`);
|
|
9467
|
+
} else if (spec.kind === "list") {
|
|
9468
|
+
command.option(`--${spec.name} <value>`, description, collect);
|
|
9469
|
+
} else {
|
|
9470
|
+
command.option(
|
|
9471
|
+
`--${spec.name} <${spec.kind === "json" ? "json" : "value"}>`,
|
|
9472
|
+
description
|
|
9473
|
+
);
|
|
9474
|
+
}
|
|
9475
|
+
if (spec.clear) {
|
|
9476
|
+
command.option(`--clear-${spec.clear}`, `set ${field.name} to null`);
|
|
9477
|
+
}
|
|
9478
|
+
}
|
|
9479
|
+
if (op.paginated) {
|
|
9480
|
+
command.option("--all", "every page, not just the first");
|
|
9006
9481
|
}
|
|
9007
9482
|
if (op.hasBody) command.option("--data <json>", "the whole JSON body");
|
|
9008
9483
|
if (op.rawBody) command.requiredOption("--file <path>", "the file to send");
|
|
@@ -9019,7 +9494,7 @@ ${op.description}`);
|
|
|
9019
9494
|
const values = input.slice(0, op.cli.args.length);
|
|
9020
9495
|
const options = input[op.cli.args.length];
|
|
9021
9496
|
if (op.cli.confirm && !options.yes) {
|
|
9022
|
-
throw new
|
|
9497
|
+
throw new UsageError(
|
|
9023
9498
|
`${op.summary} cannot be undone. Run it again with --yes to confirm.`
|
|
9024
9499
|
);
|
|
9025
9500
|
}
|
|
@@ -9037,62 +9512,111 @@ ${op.description}`);
|
|
|
9037
9512
|
print(ctx, result, options.json === true);
|
|
9038
9513
|
});
|
|
9039
9514
|
}
|
|
9040
|
-
function
|
|
9041
|
-
|
|
9042
|
-
|
|
9043
|
-
|
|
9044
|
-
throw new Error(`--${flag(field.name)} must be a number`);
|
|
9045
|
-
return n;
|
|
9515
|
+
function number2(name, raw) {
|
|
9516
|
+
const n = Number(raw);
|
|
9517
|
+
if (raw === "" || Number.isNaN(n)) {
|
|
9518
|
+
throw new UsageError(`--${name} must be a number`);
|
|
9046
9519
|
}
|
|
9520
|
+
return n;
|
|
9521
|
+
}
|
|
9522
|
+
function coerce({ field, spec }, raw) {
|
|
9523
|
+
if (spec.kind === "list") {
|
|
9524
|
+
const values = raw;
|
|
9525
|
+
return spec.numbers ? values.map((v) => number2(spec.name, v)) : values;
|
|
9526
|
+
}
|
|
9527
|
+
if (spec.kind === "boolean") return raw === true;
|
|
9528
|
+
if (field.type === "number") return number2(spec.name, raw);
|
|
9047
9529
|
if (field.type === "json") {
|
|
9048
9530
|
try {
|
|
9049
9531
|
return JSON.parse(String(raw));
|
|
9050
9532
|
} catch {
|
|
9051
|
-
throw new
|
|
9533
|
+
throw new UsageError(`--${spec.name} must be JSON`);
|
|
9052
9534
|
}
|
|
9053
9535
|
}
|
|
9054
9536
|
return raw;
|
|
9055
9537
|
}
|
|
9056
9538
|
async function call2(ctx, op, args, options, flags) {
|
|
9057
|
-
const { api: api2, token, workspace: workspace2, environment: environment2 } = ctx.credentials({
|
|
9058
|
-
workspace: op.workspace ? options.workspace ?? void 0 : false
|
|
9059
|
-
});
|
|
9060
|
-
const values = (field) => field.in === "path" || op.cli.args.includes(field.name) ? args[field.name] : options[optionKey(field.name)];
|
|
9061
9539
|
let whole = {};
|
|
9062
9540
|
if (op.hasBody && options.data) {
|
|
9063
9541
|
try {
|
|
9064
9542
|
whole = JSON.parse(String(options.data));
|
|
9065
9543
|
} catch {
|
|
9066
|
-
throw new
|
|
9544
|
+
throw new UsageError("--data must be a JSON object");
|
|
9067
9545
|
}
|
|
9068
9546
|
}
|
|
9069
9547
|
const input = {};
|
|
9070
9548
|
for (const field of op.fields) {
|
|
9071
|
-
|
|
9072
|
-
|
|
9073
|
-
|
|
9549
|
+
if (field.in === "path" || op.cli.args.includes(field.name)) {
|
|
9550
|
+
if (args[field.name] !== void 0) input[field.name] = args[field.name];
|
|
9551
|
+
}
|
|
9552
|
+
}
|
|
9553
|
+
for (const flagged of flags) {
|
|
9554
|
+
const { field, spec } = flagged;
|
|
9555
|
+
const raw = options[optionKey(spec.name)];
|
|
9556
|
+
const clear = spec.clear && options[optionKey(`clear-${spec.clear}`)];
|
|
9557
|
+
if (clear && raw !== void 0) {
|
|
9558
|
+
throw new UsageError(
|
|
9559
|
+
`pass --${spec.name} or --clear-${spec.clear}, not both`
|
|
9560
|
+
);
|
|
9561
|
+
}
|
|
9562
|
+
if (clear) input[field.name] = null;
|
|
9563
|
+
else if (raw !== void 0) {
|
|
9564
|
+
input[field.name] = field.in === "body" || spec.kind !== "value" ? coerce(flagged, raw) : raw;
|
|
9565
|
+
}
|
|
9074
9566
|
}
|
|
9075
9567
|
const missing = flags.filter(
|
|
9076
|
-
(field) => field.required && input[field.name] === void 0 && (field.in !== "body" || whole[field.name] === void 0)
|
|
9568
|
+
({ field }) => field.required && input[field.name] === void 0 && (field.in !== "body" || whole[field.name] === void 0)
|
|
9077
9569
|
);
|
|
9078
9570
|
if (missing.length > 0) {
|
|
9079
|
-
throw new
|
|
9080
|
-
`missing ${missing.map((
|
|
9571
|
+
throw new UsageError(
|
|
9572
|
+
`missing ${missing.map(({ spec }) => `--${spec.name}`).join(", ")}`
|
|
9081
9573
|
);
|
|
9082
9574
|
}
|
|
9083
9575
|
const problem = variantProblem(op, input, whole);
|
|
9084
|
-
if (problem) throw new
|
|
9085
|
-
const
|
|
9576
|
+
if (problem) throw new UsageError(problem);
|
|
9577
|
+
const credentials = ctx.credentials({
|
|
9578
|
+
workspace: op.workspace ? options.workspace ?? void 0 : false
|
|
9579
|
+
});
|
|
9580
|
+
if (op.paginated && options.all === true) {
|
|
9581
|
+
const paged = op.fields.some(
|
|
9582
|
+
(f) => f.in === "query" && f.name === "cursor"
|
|
9583
|
+
);
|
|
9584
|
+
const items = [];
|
|
9585
|
+
let cursor = input.cursor;
|
|
9586
|
+
for (; ; ) {
|
|
9587
|
+
const page = await send(
|
|
9588
|
+
ctx,
|
|
9589
|
+
op,
|
|
9590
|
+
credentials,
|
|
9591
|
+
operationRequest(op, { ...input, cursor }, whole),
|
|
9592
|
+
options
|
|
9593
|
+
);
|
|
9594
|
+
items.push(...page.items);
|
|
9595
|
+
if (!paged || typeof page.nextCursor !== "string") break;
|
|
9596
|
+
cursor = page.nextCursor;
|
|
9597
|
+
}
|
|
9598
|
+
return { items, nextCursor: null };
|
|
9599
|
+
}
|
|
9600
|
+
return send(
|
|
9601
|
+
ctx,
|
|
9602
|
+
op,
|
|
9603
|
+
credentials,
|
|
9604
|
+
operationRequest(op, input, whole),
|
|
9605
|
+
options
|
|
9606
|
+
);
|
|
9607
|
+
}
|
|
9608
|
+
async function send(ctx, op, credentials, request, options) {
|
|
9609
|
+
const { baseURL, token, workspace: workspace2, environment: environment3 } = credentials;
|
|
9086
9610
|
const headers = {
|
|
9087
9611
|
authorization: `Bearer ${token}`
|
|
9088
9612
|
};
|
|
9089
9613
|
if (workspace2) headers["x-workspace"] = workspace2;
|
|
9090
|
-
if (
|
|
9614
|
+
if (environment3) headers["x-environment"] = environment3;
|
|
9091
9615
|
if (request.body) headers["content-type"] = "application/json";
|
|
9092
9616
|
const raw = op.rawBody ? readFileSync3(String(options.file)) : void 0;
|
|
9093
9617
|
if (op.rawBody) headers["content-type"] = op.rawBody;
|
|
9094
9618
|
const response = await ctx.fetch(
|
|
9095
|
-
new Request(`${
|
|
9619
|
+
new Request(`${baseURL}/v1${request.path}`, {
|
|
9096
9620
|
method: request.method,
|
|
9097
9621
|
headers,
|
|
9098
9622
|
...request.body ? { body: JSON.stringify(request.body) } : {},
|
|
@@ -9103,17 +9627,13 @@ async function call2(ctx, op, args, options, flags) {
|
|
|
9103
9627
|
return new Uint8Array(await response.arrayBuffer());
|
|
9104
9628
|
}
|
|
9105
9629
|
const text = await response.text();
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
error?.code ?? "internal_error",
|
|
9112
|
-
error?.message ?? `HTTP ${response.status}`,
|
|
9113
|
-
error?.requestId,
|
|
9114
|
-
response.headers
|
|
9115
|
-
);
|
|
9630
|
+
let data = null;
|
|
9631
|
+
try {
|
|
9632
|
+
data = text ? JSON.parse(text) : null;
|
|
9633
|
+
} catch {
|
|
9634
|
+
if (response.ok) throw new Error("the API's answer is not JSON");
|
|
9116
9635
|
}
|
|
9636
|
+
if (!response.ok) throw apiErrorFrom(data, response);
|
|
9117
9637
|
return data;
|
|
9118
9638
|
}
|
|
9119
9639
|
function scalarColumns(rows) {
|
|
@@ -9138,7 +9658,9 @@ function print(ctx, data, asJson) {
|
|
|
9138
9658
|
rows.length === 0 ? "No results." : table(rows, scalarColumns(rows))
|
|
9139
9659
|
);
|
|
9140
9660
|
if (typeof page.nextCursor === "string") {
|
|
9141
|
-
ctx.io.stdout(
|
|
9661
|
+
ctx.io.stdout(
|
|
9662
|
+
`More: --cursor ${page.nextCursor}, or --all for every page`
|
|
9663
|
+
);
|
|
9142
9664
|
}
|
|
9143
9665
|
return;
|
|
9144
9666
|
}
|
|
@@ -9160,12 +9682,12 @@ function variantProblem(op, input, whole) {
|
|
|
9160
9682
|
const chosen = String(input[key] ?? whole[key]);
|
|
9161
9683
|
const needs = op.variants.required[chosen];
|
|
9162
9684
|
if (!needs) {
|
|
9163
|
-
return `--${
|
|
9685
|
+
return `--${kebab(key)} must be one of ${Object.keys(op.variants.required).join(", ")}`;
|
|
9164
9686
|
}
|
|
9165
9687
|
const absent = needs.filter(
|
|
9166
9688
|
(name) => input[name] === void 0 && whole[name] === void 0
|
|
9167
9689
|
);
|
|
9168
|
-
return absent.length > 0 ? `missing ${absent.map((name) => `--${
|
|
9690
|
+
return absent.length > 0 ? `missing ${absent.map((name) => `--${kebab(name)}`).join(", ")} (needed with --${kebab(key)} ${chosen})` : void 0;
|
|
9169
9691
|
}
|
|
9170
9692
|
|
|
9171
9693
|
// src/product/index.ts
|
|
@@ -9175,21 +9697,29 @@ __export(product_exports2, {
|
|
|
9175
9697
|
});
|
|
9176
9698
|
|
|
9177
9699
|
// src/product/check.ts
|
|
9700
|
+
var EXIT_REFUSED = 5;
|
|
9701
|
+
var RefusedError = class extends Error {
|
|
9702
|
+
exitCode = EXIT_REFUSED;
|
|
9703
|
+
constructor() {
|
|
9704
|
+
super("The check was refused");
|
|
9705
|
+
this.name = "RefusedError";
|
|
9706
|
+
}
|
|
9707
|
+
};
|
|
9178
9708
|
var checkCommand = (program2, ctx) => {
|
|
9179
|
-
program2.command("check").description(`Short for \`${brand.name} checks create\``).argument("<subject>", "who is acting, as kind:id (user:
|
|
9709
|
+
program2.command("check").description(`Short for \`${brand.name} checks create\``).argument("<subject>", "who is acting, as kind:id (user:user_123)").argument("<action>", "what they want to do (ai-call)").option("--cost <n>", "units it would use (default 1)").option(
|
|
9180
9710
|
"--shared <kind:id>",
|
|
9181
9711
|
"a shared subject it also draws from (a team's pool); repeat for more",
|
|
9182
9712
|
(value, previous = []) => [...previous, value]
|
|
9183
9713
|
).option("--workspace <slug>", "act in this workspace for one call").option("--json", "the decision as the API answers it").addHelpText(
|
|
9184
9714
|
"after",
|
|
9185
9715
|
`
|
|
9186
|
-
Example: ${brand.name} check user:
|
|
9187
|
-
|
|
9716
|
+
Example: ${brand.name} check user:user_123 ai-call --cost 5
|
|
9717
|
+
Exit codes: 0 allowed, 5 refused, 2 wrong usage, 1 any other failure.`
|
|
9188
9718
|
).action(
|
|
9189
9719
|
async (subject, action, options) => {
|
|
9190
9720
|
const cost = options.cost === void 0 ? void 0 : Number(options.cost);
|
|
9191
9721
|
if (cost !== void 0 && !Number.isInteger(cost)) {
|
|
9192
|
-
throw new
|
|
9722
|
+
throw new UsageError("--cost must be a whole number");
|
|
9193
9723
|
}
|
|
9194
9724
|
const decision = await ctx.client({ workspace: options.workspace }).checks.create(
|
|
9195
9725
|
{
|
|
@@ -9197,24 +9727,25 @@ A refusal exits 0: it's an answer. Errors exit 1.`
|
|
|
9197
9727
|
action,
|
|
9198
9728
|
...cost !== void 0 ? { cost } : {},
|
|
9199
9729
|
...options.shared?.length ? { shared: options.shared.map(parseSubject) } : {}
|
|
9200
|
-
}
|
|
9201
|
-
|
|
9730
|
+
}
|
|
9731
|
+
// No key here: the client sends one, or the global
|
|
9732
|
+
// --idempotency-key's, for every write.
|
|
9202
9733
|
);
|
|
9203
|
-
if (!decision) throw new Error("Limitry answered without a decision");
|
|
9204
9734
|
ctx.io.stdout(options.json ? json(decision) : answer(decision));
|
|
9735
|
+
if (!decision.allowed) throw new RefusedError();
|
|
9205
9736
|
}
|
|
9206
9737
|
);
|
|
9207
9738
|
};
|
|
9208
9739
|
function parseSubject(value) {
|
|
9209
9740
|
const at = value.indexOf(":");
|
|
9210
9741
|
if (at <= 0 || at === value.length - 1) {
|
|
9211
|
-
throw new
|
|
9212
|
-
`"${value}": write a subject as kind:id, e.g. user:
|
|
9742
|
+
throw new UsageError(
|
|
9743
|
+
`"${value}": write a subject as kind:id, e.g. user:user_123`
|
|
9213
9744
|
);
|
|
9214
9745
|
}
|
|
9215
9746
|
return { kind: value.slice(0, at), id: value.slice(at + 1) };
|
|
9216
9747
|
}
|
|
9217
|
-
var left = (r) => `${r.
|
|
9748
|
+
var left = (r) => `${r.limitName}: ${r.remaining} ${r.unit} left${r.resetsAt ? `, resets ${r.resetsAt}` : ""}`;
|
|
9218
9749
|
function answer(decision) {
|
|
9219
9750
|
if (decision.allowed) {
|
|
9220
9751
|
return decision.limits.length === 0 ? "Allowed. No limit applies." : `Allowed. ${decision.limits.map(left).join("; ")}`;
|
|
@@ -9244,7 +9775,7 @@ Shortcut: \`${brand.name} sync\`, the same command.`
|
|
|
9244
9775
|
);
|
|
9245
9776
|
};
|
|
9246
9777
|
function syncCommand(command, ctx, description, more) {
|
|
9247
|
-
command.description(description).argument("[file]", "the file to read", "limitry.json").option("--
|
|
9778
|
+
command.description(description).argument("[file]", "the file to read, or - for stdin", "limitry.json").option("--dry-run", "show what would change, and change nothing").option(
|
|
9248
9779
|
"--data <json>",
|
|
9249
9780
|
"the whole JSON body, as every command takes, instead of a file"
|
|
9250
9781
|
).option(
|
|
@@ -9259,19 +9790,21 @@ function syncCommand(command, ctx, description, more) {
|
|
|
9259
9790
|
).action(
|
|
9260
9791
|
async (file, options) => {
|
|
9261
9792
|
const data = options.data === void 0 ? {} : parseData(options.data);
|
|
9262
|
-
const
|
|
9263
|
-
const
|
|
9793
|
+
const fromStdin = file === "-";
|
|
9794
|
+
const fromFile = data.limits !== void 0 ? null : fromStdin ? parseSyncFile(await ctx.io.stdin(), "stdin") : readSyncFile(file);
|
|
9795
|
+
const limits = data.limits !== void 0 ? limitsIn(data.limits) : fromFile.limits;
|
|
9264
9796
|
const kinds = data.kinds !== void 0 ? data.kinds : fromFile?.kinds;
|
|
9265
|
-
const source = options.source ?? (typeof data.source === "string" ? data.source : void 0) ?? (fromFile ? file : void 0);
|
|
9797
|
+
const source = options.source ?? (typeof data.source === "string" ? data.source : void 0) ?? (fromFile && !fromStdin ? file : void 0);
|
|
9266
9798
|
const result = await ctx.client({ workspace: options.workspace }).limits.sync(
|
|
9267
9799
|
{
|
|
9268
9800
|
limits,
|
|
9269
9801
|
archiveMissing: options.archiveMissing ?? data.archiveMissing === true,
|
|
9270
|
-
|
|
9802
|
+
dryRun: options.dryRun ?? data.dryRun === true,
|
|
9271
9803
|
...kinds !== void 0 ? { kinds } : {},
|
|
9272
9804
|
...source !== void 0 ? { source } : {}
|
|
9273
|
-
}
|
|
9274
|
-
|
|
9805
|
+
}
|
|
9806
|
+
// No key here: the client sends one, or the global
|
|
9807
|
+
// --idempotency-key's, for every write.
|
|
9275
9808
|
);
|
|
9276
9809
|
if (options.json) {
|
|
9277
9810
|
ctx.io.stdout(json(result));
|
|
@@ -9289,6 +9822,9 @@ function readSyncFile(file) {
|
|
|
9289
9822
|
} catch (error) {
|
|
9290
9823
|
throw new Error(`${file}: no such file`, { cause: error });
|
|
9291
9824
|
}
|
|
9825
|
+
return parseSyncFile(text, file);
|
|
9826
|
+
}
|
|
9827
|
+
function parseSyncFile(text, file) {
|
|
9292
9828
|
let parsed;
|
|
9293
9829
|
try {
|
|
9294
9830
|
parsed = JSON.parse(text);
|
|
@@ -9309,20 +9845,6 @@ function readSyncFile(file) {
|
|
|
9309
9845
|
...body.kinds !== void 0 ? { kinds: body.kinds } : {}
|
|
9310
9846
|
};
|
|
9311
9847
|
}
|
|
9312
|
-
function parseLimits(text, flag2) {
|
|
9313
|
-
let parsed;
|
|
9314
|
-
try {
|
|
9315
|
-
parsed = JSON.parse(text);
|
|
9316
|
-
} catch (error) {
|
|
9317
|
-
throw new Error(`${flag2} must be a JSON array of limits`, {
|
|
9318
|
-
cause: error
|
|
9319
|
-
});
|
|
9320
|
-
}
|
|
9321
|
-
if (!Array.isArray(parsed)) {
|
|
9322
|
-
throw new Error(`${flag2} must be a JSON array of limits`);
|
|
9323
|
-
}
|
|
9324
|
-
return parsed;
|
|
9325
|
-
}
|
|
9326
9848
|
function parseData(text) {
|
|
9327
9849
|
let parsed;
|
|
9328
9850
|
try {
|
|
@@ -9343,7 +9865,7 @@ function limitsIn(value) {
|
|
|
9343
9865
|
}
|
|
9344
9866
|
var show = (value) => typeof value === "string" ? value : JSON.stringify(value);
|
|
9345
9867
|
function summary(result) {
|
|
9346
|
-
const dry = result.
|
|
9868
|
+
const dry = result.dryRun;
|
|
9347
9869
|
const lines = [
|
|
9348
9870
|
...result.created.map(
|
|
9349
9871
|
(name) => `${dry ? "Would create" : "Created"}: ${name}`
|
|
@@ -9373,7 +9895,7 @@ function summary(result) {
|
|
|
9373
9895
|
];
|
|
9374
9896
|
}
|
|
9375
9897
|
if (same2 > 0) lines.push(`Unchanged: ${same2}`);
|
|
9376
|
-
if (dry) lines.push("
|
|
9898
|
+
if (dry) lines.push("Dry run: nothing was changed.");
|
|
9377
9899
|
return lines;
|
|
9378
9900
|
}
|
|
9379
9901
|
|
|
@@ -9391,15 +9913,18 @@ var commands = [
|
|
|
9391
9913
|
function tokenEnvVar() {
|
|
9392
9914
|
return `${brand.identifier.toUpperCase()}_TOKEN`;
|
|
9393
9915
|
}
|
|
9916
|
+
var VERSION2 = "1.0.0-rc.19";
|
|
9394
9917
|
function build(io) {
|
|
9395
9918
|
let actedIn = null;
|
|
9396
9919
|
let sending;
|
|
9397
|
-
const program2 = new Command().name(brand.name).description(`The ${brand.productName} CLI`).version(
|
|
9920
|
+
const program2 = new Command().name(brand.name).description(`The ${brand.productName} CLI`).version(VERSION2).addHelpText(
|
|
9398
9921
|
"after",
|
|
9399
9922
|
`
|
|
9400
9923
|
Token: \`${brand.name} login\` stores it in ~/.config/${brand.name}/; ${tokenEnvVar()} overrides.
|
|
9401
|
-
Environment: --environment, else ${environmentEnvVar()}, else \`${brand.name} environment use\`, else the default
|
|
9402
|
-
|
|
9924
|
+
Environment: --environment, else ${environmentEnvVar()}, else \`${brand.name} environment use\`, else the default.
|
|
9925
|
+
API: --base-url, else ${baseURLEnvVar()}, else the one \`${brand.name} login --base-url\` saved.
|
|
9926
|
+
Exit codes: 0 success, 1 failure, 2 wrong usage, 4 not logged in.`
|
|
9927
|
+
).option("--base-url <url>", "the API's origin, without /v1").option(
|
|
9403
9928
|
"--environment <name>",
|
|
9404
9929
|
"act in this environment (where the product has them)"
|
|
9405
9930
|
).option(
|
|
@@ -9411,13 +9936,15 @@ Environment: --environment, else ${environmentEnvVar()}, else \`${brand.name} en
|
|
|
9411
9936
|
}).showHelpAfterError();
|
|
9412
9937
|
const ctx = {
|
|
9413
9938
|
io,
|
|
9414
|
-
settings: () => resolveSettings(
|
|
9415
|
-
|
|
9416
|
-
|
|
9939
|
+
settings: () => resolveSettings(
|
|
9940
|
+
io.env,
|
|
9941
|
+
io.homeDir,
|
|
9942
|
+
program2.opts()
|
|
9943
|
+
),
|
|
9417
9944
|
credentials: (options = {}) => {
|
|
9418
9945
|
const settings = ctx.settings();
|
|
9419
9946
|
if (!settings.token) {
|
|
9420
|
-
throw new
|
|
9947
|
+
throw new NotLoggedInError(
|
|
9421
9948
|
`not logged in. Run \`${brand.name} login\` or set ${tokenEnvVar()}.`
|
|
9422
9949
|
);
|
|
9423
9950
|
}
|
|
@@ -9428,7 +9955,7 @@ Environment: --environment, else ${environmentEnvVar()}, else \`${brand.name} en
|
|
|
9428
9955
|
);
|
|
9429
9956
|
}
|
|
9430
9957
|
return {
|
|
9431
|
-
|
|
9958
|
+
baseURL: settings.baseURL,
|
|
9432
9959
|
token: settings.token,
|
|
9433
9960
|
workspace: void 0,
|
|
9434
9961
|
environment: settings.environment
|
|
@@ -9441,7 +9968,7 @@ Environment: --environment, else ${environmentEnvVar()}, else \`${brand.name} en
|
|
|
9441
9968
|
);
|
|
9442
9969
|
}
|
|
9443
9970
|
return {
|
|
9444
|
-
|
|
9971
|
+
baseURL: settings.baseURL,
|
|
9445
9972
|
token: settings.token,
|
|
9446
9973
|
workspace: workspace2,
|
|
9447
9974
|
environment: settings.environment
|
|
@@ -9455,7 +9982,7 @@ Environment: --environment, else ${environmentEnvVar()}, else \`${brand.name} en
|
|
|
9455
9982
|
maxRetries: 0
|
|
9456
9983
|
})
|
|
9457
9984
|
),
|
|
9458
|
-
fetch: (request) => {
|
|
9985
|
+
fetch: async (request) => {
|
|
9459
9986
|
sending ??= withRetries(
|
|
9460
9987
|
async (attempt) => {
|
|
9461
9988
|
const response = await io.fetch(attempt);
|
|
@@ -9468,7 +9995,14 @@ Environment: --environment, else ${environmentEnvVar()}, else \`${brand.name} en
|
|
|
9468
9995
|
)
|
|
9469
9996
|
}
|
|
9470
9997
|
);
|
|
9471
|
-
|
|
9998
|
+
const headers = new Headers(request.headers);
|
|
9999
|
+
headers.set("user-agent", `${brand.name}-cli/${VERSION2}`);
|
|
10000
|
+
const named = new Request(request, { headers });
|
|
10001
|
+
try {
|
|
10002
|
+
return await sending(named);
|
|
10003
|
+
} catch (error) {
|
|
10004
|
+
throw connectionErrorFrom(error, request.signal);
|
|
10005
|
+
}
|
|
9472
10006
|
}
|
|
9473
10007
|
};
|
|
9474
10008
|
for (const register2 of commands) register2(program2, ctx);
|
|
@@ -9478,37 +10012,59 @@ async function run(argv, io) {
|
|
|
9478
10012
|
const { program: program2, actedIn } = build(io);
|
|
9479
10013
|
try {
|
|
9480
10014
|
await program2.parseAsync(argv, { from: "user" });
|
|
9481
|
-
const
|
|
9482
|
-
if (
|
|
9483
|
-
return
|
|
10015
|
+
const environment3 = actedIn();
|
|
10016
|
+
if (environment3) io.stderr(`Environment: ${environment3}`);
|
|
10017
|
+
return EXIT.ok;
|
|
9484
10018
|
} catch (error) {
|
|
9485
|
-
const
|
|
9486
|
-
if (error instanceof CommanderError)
|
|
10019
|
+
const environment3 = actedIn();
|
|
10020
|
+
if (error instanceof CommanderError) {
|
|
10021
|
+
return error.exitCode === 0 ? EXIT.ok : EXIT.usage;
|
|
10022
|
+
}
|
|
10023
|
+
const code2 = exitCode(error);
|
|
9487
10024
|
if (argv.includes("--json")) {
|
|
9488
10025
|
io.stderr(
|
|
9489
10026
|
JSON.stringify({
|
|
9490
|
-
error: error instanceof
|
|
10027
|
+
error: error instanceof APIError ? {
|
|
9491
10028
|
code: error.code,
|
|
9492
10029
|
message: error.message,
|
|
9493
10030
|
status: error.status,
|
|
9494
|
-
...error.requestId ? { requestId: error.requestId } : {}
|
|
9495
|
-
|
|
9496
|
-
|
|
10031
|
+
...error.requestId ? { requestId: error.requestId } : {},
|
|
10032
|
+
...error.docs ? { docs: error.docs } : {},
|
|
10033
|
+
...error.details ? { details: error.details } : {}
|
|
10034
|
+
} : {
|
|
10035
|
+
code: code2 === EXIT.usage ? "usage_error" : code2 === EXIT.auth ? "not_logged_in" : "cli_error",
|
|
10036
|
+
message: error.message
|
|
10037
|
+
},
|
|
10038
|
+
...environment3 ? { environment: environment3 } : {}
|
|
9497
10039
|
})
|
|
9498
10040
|
);
|
|
9499
|
-
return
|
|
10041
|
+
return code2;
|
|
9500
10042
|
}
|
|
9501
|
-
if (error instanceof
|
|
10043
|
+
if (error instanceof APIError) {
|
|
9502
10044
|
const requestId = error.requestId ? ` [request ${error.requestId}]` : "";
|
|
9503
10045
|
io.stderr(`${brand.name}: ${error.message} (${error.code})${requestId}`);
|
|
10046
|
+
for (const detail of error.details ?? []) {
|
|
10047
|
+
io.stderr(
|
|
10048
|
+
` ${detail.path ? `${detail.path}: ` : ""}${detail.message}`
|
|
10049
|
+
);
|
|
10050
|
+
}
|
|
9504
10051
|
const hint = scopeHint(error);
|
|
9505
10052
|
if (hint) io.stderr(hint);
|
|
10053
|
+
if (error.docs) io.stderr(`See ${error.docs}`);
|
|
9506
10054
|
} else {
|
|
9507
|
-
|
|
10055
|
+
const cause = error instanceof APIConnectionError && error.cause instanceof Error ? ` (${error.cause.message})` : "";
|
|
10056
|
+
io.stderr(`${brand.name}: ${error.message}${cause}`);
|
|
9508
10057
|
}
|
|
9509
|
-
if (
|
|
9510
|
-
return
|
|
10058
|
+
if (environment3) io.stderr(`Environment: ${environment3}`);
|
|
10059
|
+
return code2;
|
|
10060
|
+
}
|
|
10061
|
+
}
|
|
10062
|
+
function exitCode(error) {
|
|
10063
|
+
if (error instanceof AuthenticationError || error?.cause instanceof AuthenticationError) {
|
|
10064
|
+
return EXIT.auth;
|
|
9511
10065
|
}
|
|
10066
|
+
const own = error?.exitCode;
|
|
10067
|
+
return typeof own === "number" && !(error instanceof APIError) ? own : EXIT.failure;
|
|
9512
10068
|
}
|
|
9513
10069
|
function scopeHint(error) {
|
|
9514
10070
|
const own = Reflect.get(product_exports2, "productErrorHint");
|