@limitry/cli 1.0.0-rc.7 → 1.0.0-rc.9
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 +112 -0
- package/README.md +4 -4
- package/dist/limitry.mjs +498 -473
- package/package.json +2 -2
package/dist/limitry.mjs
CHANGED
|
@@ -106,6 +106,13 @@ var brand = {
|
|
|
106
106
|
/** The support address the /contact page shows. Defaults to support@<domain>. */
|
|
107
107
|
supportContact: optional.supportContact ?? `support@${brand_default.domain}`,
|
|
108
108
|
colors: brand_default.colors,
|
|
109
|
+
/**
|
|
110
|
+
* True once the product has launched (brand.json `launched`, set at
|
|
111
|
+
* launch, never back): its data is customers', so the pre-launch
|
|
112
|
+
* product reset's `/ops` route is not mounted at all
|
|
113
|
+
* (docs/deployment.md "Resetting product data"). False when absent.
|
|
114
|
+
*/
|
|
115
|
+
launched: optional.launched === true,
|
|
109
116
|
/** True once the product has its own brand (brand.json `status: "ready"`), not the platform's placeholders. */
|
|
110
117
|
ready: brand_default.status === "ready"
|
|
111
118
|
};
|
|
@@ -690,66 +697,235 @@ function apiErrorFrom(error, response) {
|
|
|
690
697
|
return new ApiError(response.status, envelope.error?.code ?? "http_error", envelope.error?.message ?? `HTTP ${response.status}`, envelope.error?.requestId);
|
|
691
698
|
}
|
|
692
699
|
|
|
700
|
+
// node_modules/@limitry/sdk/dist/retry.js
|
|
701
|
+
var WRITES = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
702
|
+
var RETRY_STATUSES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
|
|
703
|
+
var DEFAULT_MAX_RETRIES = 2;
|
|
704
|
+
var MAX_WAIT_MS = 2e4;
|
|
705
|
+
var MOVING_MS = 3e4;
|
|
706
|
+
var MOVING_HEADER = "x-limitry-moving";
|
|
707
|
+
var JITTER_BASE_MS = 250;
|
|
708
|
+
var JITTER_CAP_MS = 4e3;
|
|
709
|
+
var MAX_BASE_KEY = 200;
|
|
710
|
+
var wait = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
711
|
+
function backoff(attempt) {
|
|
712
|
+
const base = Math.min(500 * 2 ** attempt, 8e3);
|
|
713
|
+
return base * (0.75 + Math.random() * 0.25);
|
|
714
|
+
}
|
|
715
|
+
function retryAfter(response) {
|
|
716
|
+
const value = response.headers.get("retry-after");
|
|
717
|
+
if (!value)
|
|
718
|
+
return void 0;
|
|
719
|
+
const seconds = Number(value);
|
|
720
|
+
if (Number.isFinite(seconds))
|
|
721
|
+
return Math.max(0, seconds * 1e3);
|
|
722
|
+
const date = Date.parse(value);
|
|
723
|
+
return Number.isNaN(date) ? void 0 : Math.max(0, date - Date.now());
|
|
724
|
+
}
|
|
725
|
+
function retryWaitMs(retryAfterMs2, attempt, random = Math.random) {
|
|
726
|
+
const floor = Math.max(1e3, retryAfterMs2 ?? 1e3);
|
|
727
|
+
const ceiling = Math.min(JITTER_CAP_MS, JITTER_BASE_MS * 2 ** attempt);
|
|
728
|
+
return floor + random() * ceiling;
|
|
729
|
+
}
|
|
730
|
+
async function retryLater(response) {
|
|
731
|
+
if (response.status !== 503)
|
|
732
|
+
return null;
|
|
733
|
+
try {
|
|
734
|
+
const body = await response.clone().json();
|
|
735
|
+
const code2 = body.error?.code;
|
|
736
|
+
return code2 === "moving" || code2 === "busy" ? code2 : null;
|
|
737
|
+
} catch {
|
|
738
|
+
return null;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
async function retryable(response) {
|
|
742
|
+
if (RETRY_STATUSES.has(response.status))
|
|
743
|
+
return true;
|
|
744
|
+
if (response.status !== 409)
|
|
745
|
+
return false;
|
|
746
|
+
try {
|
|
747
|
+
const body = await response.clone().json();
|
|
748
|
+
return body.error?.code === "idempotency_in_progress";
|
|
749
|
+
} catch {
|
|
750
|
+
return false;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
function withoutMovingHeader(fetch2) {
|
|
754
|
+
return (request) => {
|
|
755
|
+
if (!request.headers.has(MOVING_HEADER))
|
|
756
|
+
return fetch2(request);
|
|
757
|
+
const headers = new Headers(request.headers);
|
|
758
|
+
headers.delete(MOVING_HEADER);
|
|
759
|
+
return fetch2(new Request(request, { headers }));
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
function withRetries(fetch2, options = {}) {
|
|
763
|
+
const maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
764
|
+
const sleep = options.sleep ?? wait;
|
|
765
|
+
const random = options.random ?? Math.random;
|
|
766
|
+
return async (request) => {
|
|
767
|
+
const returnMoving = request.headers.get(MOVING_HEADER) === "return";
|
|
768
|
+
if (request.headers.has(MOVING_HEADER)) {
|
|
769
|
+
const headers = new Headers(request.headers);
|
|
770
|
+
headers.delete(MOVING_HEADER);
|
|
771
|
+
request = new Request(request, { headers });
|
|
772
|
+
}
|
|
773
|
+
if (WRITES.has(request.method) && !request.headers.has("idempotency-key")) {
|
|
774
|
+
const url = new URL(request.url);
|
|
775
|
+
const key = options.key ? await options.key(request.method, url.pathname) : crypto.randomUUID();
|
|
776
|
+
const headers = new Headers(request.headers);
|
|
777
|
+
headers.set("idempotency-key", key);
|
|
778
|
+
request = new Request(request, { headers });
|
|
779
|
+
}
|
|
780
|
+
let movingWaited = 0;
|
|
781
|
+
let movingTries = 0;
|
|
782
|
+
for (let attempt = 0; ; attempt++) {
|
|
783
|
+
const last = attempt >= maxRetries;
|
|
784
|
+
const sending = request.clone();
|
|
785
|
+
let response;
|
|
786
|
+
try {
|
|
787
|
+
response = await fetch2(sending);
|
|
788
|
+
} catch (error) {
|
|
789
|
+
if (last || request.signal.aborted)
|
|
790
|
+
throw error;
|
|
791
|
+
await sleep(backoff(attempt));
|
|
792
|
+
continue;
|
|
793
|
+
}
|
|
794
|
+
const later = await retryLater(response);
|
|
795
|
+
if (later && returnMoving)
|
|
796
|
+
return response;
|
|
797
|
+
if (later) {
|
|
798
|
+
const delay2 = retryWaitMs(retryAfter(response), movingTries++, random);
|
|
799
|
+
if (movingWaited + delay2 > MOVING_MS)
|
|
800
|
+
return response;
|
|
801
|
+
movingWaited += delay2;
|
|
802
|
+
await response.body?.cancel();
|
|
803
|
+
await sleep(delay2);
|
|
804
|
+
attempt--;
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
if (last || !await retryable(response))
|
|
808
|
+
return response;
|
|
809
|
+
const delay = retryAfter(response) ?? backoff(attempt);
|
|
810
|
+
if (delay > MAX_WAIT_MS)
|
|
811
|
+
return response;
|
|
812
|
+
await response.body?.cancel();
|
|
813
|
+
await sleep(delay);
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
var hex = (bytes) => Array.from(new Uint8Array(bytes), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
818
|
+
function keysFrom(base) {
|
|
819
|
+
if (base !== void 0 && (base.length === 0 || base.length > MAX_BASE_KEY)) {
|
|
820
|
+
throw new Error(`the idempotency key must be 1\u2013${MAX_BASE_KEY} characters`);
|
|
821
|
+
}
|
|
822
|
+
if (base !== void 0 && !/^[\x21-\x7e]+$/.test(base)) {
|
|
823
|
+
throw new Error("the idempotency key must be printable ASCII with no spaces");
|
|
824
|
+
}
|
|
825
|
+
const seen = /* @__PURE__ */ new Map();
|
|
826
|
+
return async (method, path2) => {
|
|
827
|
+
if (base === void 0)
|
|
828
|
+
return crypto.randomUUID();
|
|
829
|
+
const target = `${method} ${path2}`;
|
|
830
|
+
const n = (seen.get(target) ?? 0) + 1;
|
|
831
|
+
seen.set(target, n);
|
|
832
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${target}#${n}`));
|
|
833
|
+
return `${base}:${hex(digest).slice(0, 16)}`;
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
|
|
693
837
|
// node_modules/@limitry/sdk/dist/product/limits.js
|
|
694
838
|
var MAX_COST = 1e9;
|
|
695
839
|
function checkedCost(units) {
|
|
696
840
|
if (!Number.isInteger(units) || units < 0 || units > MAX_COST) {
|
|
697
|
-
throw new RangeError(`
|
|
841
|
+
throw new RangeError(`reservation.cost(${units}): the cost must be a whole number from 0 to ${MAX_COST}`);
|
|
698
842
|
}
|
|
699
843
|
return units;
|
|
700
844
|
}
|
|
701
|
-
var
|
|
845
|
+
var LimitReached = class extends Error {
|
|
702
846
|
reason;
|
|
703
|
-
/** The limit that refused; null
|
|
704
|
-
|
|
847
|
+
/** The limit that refused; null for too many open reservations. */
|
|
848
|
+
limitId;
|
|
705
849
|
retryAfterSeconds;
|
|
706
850
|
decision;
|
|
707
851
|
constructor(decision) {
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
this.name = "LimitExceeded";
|
|
714
|
-
this.reason = reason;
|
|
715
|
-
this.limit = decision?.reason?.limit ?? null;
|
|
716
|
-
this.retryAfterSeconds = decision?.retryAfterSeconds ?? null;
|
|
852
|
+
super(decision.reason?.message ?? "Refused");
|
|
853
|
+
this.name = "LimitReached";
|
|
854
|
+
this.reason = decision.reason?.code ?? "limit_reached";
|
|
855
|
+
this.limitId = decision.reason?.limitId ?? null;
|
|
856
|
+
this.retryAfterSeconds = decision.retryAfterSeconds ?? null;
|
|
717
857
|
this.decision = decision;
|
|
718
858
|
}
|
|
719
859
|
};
|
|
860
|
+
var Unavailable = class extends Error {
|
|
861
|
+
constructor() {
|
|
862
|
+
super("Limitry could not be reached and a limit refuses when unreachable");
|
|
863
|
+
this.name = "Unavailable";
|
|
864
|
+
}
|
|
865
|
+
};
|
|
720
866
|
var UNREACHABLE = /* @__PURE__ */ Symbol("unreachable");
|
|
721
867
|
var TIMED_OUT = /* @__PURE__ */ Symbol("timed out");
|
|
722
868
|
var SETTLE_TIMEOUT_MS = 5e3;
|
|
723
|
-
|
|
869
|
+
var wait2 = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
870
|
+
function retryAfterMs(response) {
|
|
871
|
+
const value = response.headers.get("retry-after");
|
|
872
|
+
const seconds = value === null ? NaN : Number(value);
|
|
873
|
+
return Number.isFinite(seconds) ? seconds * 1e3 : void 0;
|
|
874
|
+
}
|
|
875
|
+
function createLimits(client, options = {}, internals = {}) {
|
|
724
876
|
const timeoutMs = options.timeoutMs ?? 1500;
|
|
877
|
+
const sleep = internals.sleep ?? wait2;
|
|
878
|
+
const random = internals.random ?? Math.random;
|
|
725
879
|
const remembered = /* @__PURE__ */ new Map();
|
|
726
880
|
const key = (s, action) => `${s.kind}\0${s.id}\0${action}`;
|
|
727
881
|
const failMode = (s, action) => options.failMode ?? remembered.get(key(s, action)) ?? "open";
|
|
728
882
|
const remember = (s, action, decision) => {
|
|
729
883
|
if (options.failMode)
|
|
730
884
|
return;
|
|
731
|
-
const closed = decision.
|
|
885
|
+
const closed = decision.limits.some((r) => r.failMode === "closed");
|
|
732
886
|
remembered.set(key(s, action), closed ? "closed" : "open");
|
|
733
887
|
if (remembered.size > 1e4) {
|
|
734
888
|
remembered.delete(remembered.keys().next().value);
|
|
735
889
|
}
|
|
736
890
|
};
|
|
737
|
-
async function check(body, idempotencyKey,
|
|
891
|
+
async function check(body, idempotencyKey, wait3 = timeoutMs, finishOnly = false) {
|
|
892
|
+
let waited = 0;
|
|
893
|
+
for (let tries = 0; ; tries++) {
|
|
894
|
+
const answer2 = await checkOnce(body, idempotencyKey, wait3, finishOnly);
|
|
895
|
+
if (answer2.kind !== "later")
|
|
896
|
+
return answer2.value;
|
|
897
|
+
const pause = retryWaitMs(answer2.retryAfterMs, tries, random);
|
|
898
|
+
if (waited + pause > MOVING_MS)
|
|
899
|
+
return UNREACHABLE;
|
|
900
|
+
waited += pause;
|
|
901
|
+
await sleep(pause);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
async function checkOnce(body, idempotencyKey, wait3, finishOnly) {
|
|
738
905
|
let timer;
|
|
739
906
|
const late = new Promise((resolve2) => {
|
|
740
|
-
timer = setTimeout(() => resolve2(TIMED_OUT),
|
|
907
|
+
timer = setTimeout(() => resolve2(TIMED_OUT), wait3);
|
|
741
908
|
});
|
|
742
909
|
const asked = (async () => {
|
|
743
910
|
try {
|
|
744
911
|
const { data, error, response } = await client.POST("/checks", {
|
|
745
912
|
body,
|
|
746
|
-
headers: {
|
|
747
|
-
|
|
913
|
+
headers: {
|
|
914
|
+
"idempotency-key": idempotencyKey,
|
|
915
|
+
// `moving` and `busy` come back here at once: this loop
|
|
916
|
+
// retries them.
|
|
917
|
+
[MOVING_HEADER]: "return",
|
|
918
|
+
...finishOnly ? { "limitry-finish-only": "1" } : {}
|
|
919
|
+
},
|
|
920
|
+
signal: AbortSignal.timeout(wait3)
|
|
748
921
|
});
|
|
749
922
|
if (data)
|
|
750
923
|
return data;
|
|
751
|
-
if (response
|
|
924
|
+
if (isRetryLater(response, error))
|
|
925
|
+
return { later: retryAfterMs(response) };
|
|
926
|
+
if (response.status === 402 || response.status === 429) {
|
|
752
927
|
return UNREACHABLE;
|
|
928
|
+
}
|
|
753
929
|
if (response.status < 500 && error) {
|
|
754
930
|
return new Error(`Limitry refused the check (${response.status}): ${JSON.stringify(error)}`);
|
|
755
931
|
}
|
|
@@ -762,26 +938,41 @@ function createLimits(client, options = {}) {
|
|
|
762
938
|
const answer2 = await Promise.race([asked, late]);
|
|
763
939
|
if (answer2 instanceof Error)
|
|
764
940
|
throw answer2;
|
|
765
|
-
|
|
941
|
+
if (typeof answer2 === "object" && "later" in answer2)
|
|
942
|
+
return { kind: "later", retryAfterMs: answer2.later };
|
|
943
|
+
return { kind: "answer", value: answer2 };
|
|
766
944
|
} finally {
|
|
767
945
|
clearTimeout(timer);
|
|
768
946
|
}
|
|
769
947
|
}
|
|
770
948
|
async function settle(id, action, cost) {
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
949
|
+
const idempotencyKey = crypto.randomUUID();
|
|
950
|
+
let waited = 0;
|
|
951
|
+
for (let tries = 0; ; tries++) {
|
|
952
|
+
let retryMs = null;
|
|
953
|
+
try {
|
|
954
|
+
const headers = {
|
|
955
|
+
"idempotency-key": idempotencyKey,
|
|
956
|
+
[MOVING_HEADER]: "return"
|
|
957
|
+
};
|
|
958
|
+
const { error, response } = action === "commit" ? await client.POST("/reservations/{reservationId}/commit", {
|
|
774
959
|
params: { path: { reservationId: id } },
|
|
775
960
|
body: { cost: cost ?? 0 },
|
|
961
|
+
headers,
|
|
776
962
|
signal: AbortSignal.timeout(SETTLE_TIMEOUT_MS)
|
|
777
|
-
})
|
|
778
|
-
} else {
|
|
779
|
-
await client.POST("/reservations/{reservationId}/release", {
|
|
963
|
+
}) : await client.POST("/reservations/{reservationId}/release", {
|
|
780
964
|
params: { path: { reservationId: id } },
|
|
965
|
+
headers,
|
|
781
966
|
signal: AbortSignal.timeout(SETTLE_TIMEOUT_MS)
|
|
782
967
|
});
|
|
968
|
+
if (isRetryLater(response, error))
|
|
969
|
+
retryMs = retryWaitMs(retryAfterMs(response), tries, random);
|
|
970
|
+
} catch {
|
|
783
971
|
}
|
|
784
|
-
|
|
972
|
+
if (retryMs === null || waited + retryMs > MOVING_MS)
|
|
973
|
+
return;
|
|
974
|
+
waited += retryMs;
|
|
975
|
+
await sleep(retryMs);
|
|
785
976
|
}
|
|
786
977
|
}
|
|
787
978
|
async function releaseUnheard(body, idempotencyKey) {
|
|
@@ -802,8 +993,7 @@ function createLimits(client, options = {}) {
|
|
|
802
993
|
const { data, error, response } = await client.GET("/usage/standing", {
|
|
803
994
|
params: {
|
|
804
995
|
query: {
|
|
805
|
-
|
|
806
|
-
id: request.subject.id,
|
|
996
|
+
subject: `${request.subject.kind}:${request.subject.id}`,
|
|
807
997
|
...request.shared?.length ? {
|
|
808
998
|
shared: request.shared.map((s) => `${s.kind}:${s.id}`).join(",")
|
|
809
999
|
} : {}
|
|
@@ -816,36 +1006,42 @@ function createLimits(client, options = {}) {
|
|
|
816
1006
|
},
|
|
817
1007
|
/** Checks `cost`, runs `fn` only if allowed, and returns its result. */
|
|
818
1008
|
async guard(request, fn) {
|
|
819
|
-
const
|
|
1009
|
+
const body = {
|
|
820
1010
|
subject: request.subject,
|
|
821
1011
|
shared: request.shared,
|
|
822
1012
|
action: request.action,
|
|
823
1013
|
cost: request.cost ?? 1
|
|
824
|
-
}
|
|
1014
|
+
};
|
|
1015
|
+
const idempotencyKey = crypto.randomUUID();
|
|
1016
|
+
const decision = await check(body, idempotencyKey);
|
|
825
1017
|
if (decision === UNREACHABLE || decision === TIMED_OUT) {
|
|
826
1018
|
if (failMode(request.subject, request.action) === "closed") {
|
|
827
|
-
throw new
|
|
1019
|
+
throw new Unavailable();
|
|
1020
|
+
}
|
|
1021
|
+
if (decision === TIMED_OUT) {
|
|
1022
|
+
void check(body, idempotencyKey, SETTLE_TIMEOUT_MS, true).catch(() => {
|
|
1023
|
+
});
|
|
828
1024
|
}
|
|
829
1025
|
return fn();
|
|
830
1026
|
}
|
|
831
1027
|
remember(request.subject, request.action, decision);
|
|
832
1028
|
if (!decision.allowed)
|
|
833
|
-
throw new
|
|
1029
|
+
throw new LimitReached(decision);
|
|
834
1030
|
return fn();
|
|
835
1031
|
},
|
|
836
1032
|
/**
|
|
837
|
-
*
|
|
838
|
-
* (`
|
|
839
|
-
* `fn` throws, and rethrows. A concurrent limit's slot
|
|
840
|
-
* exactly as long as `fn` runs.
|
|
1033
|
+
* Reserves `cost`, runs `fn`, then commits the cost it reported
|
|
1034
|
+
* (`reservation.cost(n)`, default the reserved cost) — or releases the
|
|
1035
|
+
* reservation if `fn` throws, and rethrows. A concurrent limit's slot
|
|
1036
|
+
* is taken for exactly as long as `fn` runs.
|
|
841
1037
|
*/
|
|
842
|
-
async
|
|
843
|
-
const
|
|
1038
|
+
async reserve(request, fn) {
|
|
1039
|
+
const reserved = request.cost ?? 1;
|
|
844
1040
|
const body = {
|
|
845
1041
|
subject: request.subject,
|
|
846
1042
|
shared: request.shared,
|
|
847
1043
|
action: request.action,
|
|
848
|
-
cost:
|
|
1044
|
+
cost: reserved,
|
|
849
1045
|
mode: "reserve",
|
|
850
1046
|
ttlSeconds: request.ttlSeconds
|
|
851
1047
|
};
|
|
@@ -862,7 +1058,7 @@ function createLimits(client, options = {}) {
|
|
|
862
1058
|
const unheard = () => decision === TIMED_OUT ? releaseUnheard(body, idempotencyKey) : Promise.resolve();
|
|
863
1059
|
if (failMode(request.subject, request.action) === "closed") {
|
|
864
1060
|
await unheard();
|
|
865
|
-
throw new
|
|
1061
|
+
throw new Unavailable();
|
|
866
1062
|
}
|
|
867
1063
|
try {
|
|
868
1064
|
return await fn(unmetered);
|
|
@@ -872,11 +1068,11 @@ function createLimits(client, options = {}) {
|
|
|
872
1068
|
}
|
|
873
1069
|
remember(request.subject, request.action, decision);
|
|
874
1070
|
if (!decision.allowed || !decision.reservation) {
|
|
875
|
-
throw new
|
|
1071
|
+
throw new LimitReached(decision);
|
|
876
1072
|
}
|
|
877
1073
|
const id = decision.reservation.id;
|
|
878
|
-
let used =
|
|
879
|
-
const
|
|
1074
|
+
let used = reserved;
|
|
1075
|
+
const reservation = {
|
|
880
1076
|
cost(units) {
|
|
881
1077
|
used = checkedCost(units);
|
|
882
1078
|
},
|
|
@@ -892,7 +1088,7 @@ function createLimits(client, options = {}) {
|
|
|
892
1088
|
};
|
|
893
1089
|
let result;
|
|
894
1090
|
try {
|
|
895
|
-
result = await fn(
|
|
1091
|
+
result = await fn(reservation);
|
|
896
1092
|
} catch (error) {
|
|
897
1093
|
await settle(id, "release");
|
|
898
1094
|
throw error;
|
|
@@ -902,11 +1098,19 @@ function createLimits(client, options = {}) {
|
|
|
902
1098
|
}
|
|
903
1099
|
};
|
|
904
1100
|
}
|
|
1101
|
+
function isRetryLater(response, error) {
|
|
1102
|
+
const code2 = error?.error?.code;
|
|
1103
|
+
return response.status === 503 && (code2 === "moving" || code2 === "busy");
|
|
1104
|
+
}
|
|
905
1105
|
|
|
906
1106
|
// node_modules/@limitry/sdk/dist/product/index.js
|
|
907
1107
|
var productMethods = (client) => {
|
|
908
1108
|
const limits = createLimits(client);
|
|
909
|
-
return {
|
|
1109
|
+
return {
|
|
1110
|
+
guard: limits.guard,
|
|
1111
|
+
reserve: limits.reserve,
|
|
1112
|
+
standing: limits.standing
|
|
1113
|
+
};
|
|
910
1114
|
};
|
|
911
1115
|
|
|
912
1116
|
// node_modules/@limitry/sdk/dist/resources.js
|
|
@@ -958,20 +1162,20 @@ function resources(client) {
|
|
|
958
1162
|
/** Create a limit */
|
|
959
1163
|
(input, options) => call(client, { "method": "post", "path": "/limits", "query": [], "hasBody": true }, {}, input, options)
|
|
960
1164
|
),
|
|
961
|
-
|
|
962
|
-
/** Get a limit */
|
|
963
|
-
(limitId, options) => call(client, { "method": "get", "path": "/limits/{limitId}", "query": [], "hasBody": false }, { "limitId": limitId }, void 0, options)
|
|
964
|
-
),
|
|
965
|
-
grants: {
|
|
1165
|
+
credits: {
|
|
966
1166
|
create: (
|
|
967
1167
|
/** Add credits to a balance */
|
|
968
|
-
(limitId, input, options) => call(client, { "method": "post", "path": "/limits/{limitId}/
|
|
1168
|
+
(limitId, input, options) => call(client, { "method": "post", "path": "/limits/{limitId}/credits", "query": [], "hasBody": true }, { "limitId": limitId }, input, options)
|
|
969
1169
|
),
|
|
970
1170
|
list: (
|
|
971
|
-
/** List a balance's
|
|
972
|
-
(limitId, options) => call(client, { "method": "get", "path": "/limits/{limitId}/
|
|
1171
|
+
/** List a balance's credits */
|
|
1172
|
+
(limitId, options) => call(client, { "method": "get", "path": "/limits/{limitId}/credits", "query": [], "hasBody": false }, { "limitId": limitId }, void 0, options)
|
|
973
1173
|
)
|
|
974
1174
|
},
|
|
1175
|
+
get: (
|
|
1176
|
+
/** Get a limit */
|
|
1177
|
+
(limitId, options) => call(client, { "method": "get", "path": "/limits/{limitId}", "query": [], "hasBody": false }, { "limitId": limitId }, void 0, options)
|
|
1178
|
+
),
|
|
975
1179
|
list: (
|
|
976
1180
|
/** List limits */
|
|
977
1181
|
(input, options) => call(client, { "method": "get", "path": "/limits", "query": ["limit", "cursor", "subjectKind", "action", "archived"], "hasBody": false }, {}, input, options)
|
|
@@ -1013,18 +1217,18 @@ function resources(client) {
|
|
|
1013
1217
|
(subjectKind, subjectId, input, options) => call(client, { "method": "post", "path": "/subjects/{subjectKind}/{subjectId}/reset", "query": [], "hasBody": true }, { "subjectKind": subjectKind, "subjectId": subjectId }, input, options)
|
|
1014
1218
|
),
|
|
1015
1219
|
update: (
|
|
1016
|
-
/** Set a subject's
|
|
1220
|
+
/** Set a subject's billing date */
|
|
1017
1221
|
(subjectKind, subjectId, input, options) => call(client, { "method": "patch", "path": "/subjects/{subjectKind}/{subjectId}", "query": [], "hasBody": true }, { "subjectKind": subjectKind, "subjectId": subjectId }, input, options)
|
|
1018
1222
|
)
|
|
1019
1223
|
},
|
|
1020
1224
|
usage: {
|
|
1021
1225
|
query: (
|
|
1022
1226
|
/** Get a limit's usage over time */
|
|
1023
|
-
(input, options) => call(client, { "method": "get", "path": "/usage", "query": ["limitId", "
|
|
1227
|
+
(input, options) => call(client, { "method": "get", "path": "/usage", "query": ["limitId", "subject", "from", "to", "granularity"], "hasBody": false }, {}, input, options)
|
|
1024
1228
|
),
|
|
1025
1229
|
standing: (
|
|
1026
1230
|
/** Get where a subject stands */
|
|
1027
|
-
(input, options) => call(client, { "method": "get", "path": "/usage/standing", "query": ["
|
|
1231
|
+
(input, options) => call(client, { "method": "get", "path": "/usage/standing", "query": ["subject", "shared"], "hasBody": false }, {}, input, options)
|
|
1028
1232
|
),
|
|
1029
1233
|
subjects: (
|
|
1030
1234
|
/** List who is using a limit now */
|
|
@@ -1140,92 +1344,6 @@ function resources(client) {
|
|
|
1140
1344
|
};
|
|
1141
1345
|
}
|
|
1142
1346
|
|
|
1143
|
-
// node_modules/@limitry/sdk/dist/retry.js
|
|
1144
|
-
var WRITES = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
1145
|
-
var RETRY_STATUSES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
|
|
1146
|
-
var DEFAULT_MAX_RETRIES = 2;
|
|
1147
|
-
var MAX_WAIT_MS = 2e4;
|
|
1148
|
-
var MAX_BASE_KEY = 200;
|
|
1149
|
-
var wait = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
1150
|
-
function backoff(attempt) {
|
|
1151
|
-
const base = Math.min(500 * 2 ** attempt, 8e3);
|
|
1152
|
-
return base * (0.75 + Math.random() * 0.25);
|
|
1153
|
-
}
|
|
1154
|
-
function retryAfter(response) {
|
|
1155
|
-
const value = response.headers.get("retry-after");
|
|
1156
|
-
if (!value)
|
|
1157
|
-
return void 0;
|
|
1158
|
-
const seconds = Number(value);
|
|
1159
|
-
if (Number.isFinite(seconds))
|
|
1160
|
-
return Math.max(0, seconds * 1e3);
|
|
1161
|
-
const date = Date.parse(value);
|
|
1162
|
-
return Number.isNaN(date) ? void 0 : Math.max(0, date - Date.now());
|
|
1163
|
-
}
|
|
1164
|
-
async function retryable(response) {
|
|
1165
|
-
if (RETRY_STATUSES.has(response.status))
|
|
1166
|
-
return true;
|
|
1167
|
-
if (response.status !== 409)
|
|
1168
|
-
return false;
|
|
1169
|
-
try {
|
|
1170
|
-
const body = await response.clone().json();
|
|
1171
|
-
return body.error?.code === "idempotency_in_progress";
|
|
1172
|
-
} catch {
|
|
1173
|
-
return false;
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
function withRetries(fetch2, options = {}) {
|
|
1177
|
-
const maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
1178
|
-
const sleep = options.sleep ?? wait;
|
|
1179
|
-
return async (request) => {
|
|
1180
|
-
if (WRITES.has(request.method) && !request.headers.has("idempotency-key")) {
|
|
1181
|
-
const url = new URL(request.url);
|
|
1182
|
-
const key = options.key ? await options.key(request.method, url.pathname) : crypto.randomUUID();
|
|
1183
|
-
const headers = new Headers(request.headers);
|
|
1184
|
-
headers.set("idempotency-key", key);
|
|
1185
|
-
request = new Request(request, { headers });
|
|
1186
|
-
}
|
|
1187
|
-
for (let attempt = 0; ; attempt++) {
|
|
1188
|
-
const last = attempt >= maxRetries;
|
|
1189
|
-
const sending = last ? request : request.clone();
|
|
1190
|
-
let response;
|
|
1191
|
-
try {
|
|
1192
|
-
response = await fetch2(sending);
|
|
1193
|
-
} catch (error) {
|
|
1194
|
-
if (last || request.signal.aborted)
|
|
1195
|
-
throw error;
|
|
1196
|
-
await sleep(backoff(attempt));
|
|
1197
|
-
continue;
|
|
1198
|
-
}
|
|
1199
|
-
if (last || !await retryable(response))
|
|
1200
|
-
return response;
|
|
1201
|
-
const delay = retryAfter(response) ?? backoff(attempt);
|
|
1202
|
-
if (delay > MAX_WAIT_MS)
|
|
1203
|
-
return response;
|
|
1204
|
-
await response.body?.cancel();
|
|
1205
|
-
await sleep(delay);
|
|
1206
|
-
}
|
|
1207
|
-
};
|
|
1208
|
-
}
|
|
1209
|
-
var hex = (bytes) => Array.from(new Uint8Array(bytes), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
1210
|
-
function keysFrom(base) {
|
|
1211
|
-
if (base !== void 0 && (base.length === 0 || base.length > MAX_BASE_KEY)) {
|
|
1212
|
-
throw new Error(`the idempotency key must be 1\u2013${MAX_BASE_KEY} characters`);
|
|
1213
|
-
}
|
|
1214
|
-
if (base !== void 0 && !/^[\x21-\x7e]+$/.test(base)) {
|
|
1215
|
-
throw new Error("the idempotency key must be printable ASCII with no spaces");
|
|
1216
|
-
}
|
|
1217
|
-
const seen = /* @__PURE__ */ new Map();
|
|
1218
|
-
return async (method, path2) => {
|
|
1219
|
-
if (base === void 0)
|
|
1220
|
-
return crypto.randomUUID();
|
|
1221
|
-
const target = `${method} ${path2}`;
|
|
1222
|
-
const n = (seen.get(target) ?? 0) + 1;
|
|
1223
|
-
seen.set(target, n);
|
|
1224
|
-
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${target}#${n}`));
|
|
1225
|
-
return `${base}:${hex(digest).slice(0, 16)}`;
|
|
1226
|
-
};
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
1347
|
// node_modules/@limitry/sdk/dist/webhooks.js
|
|
1230
1348
|
var WebhookVerificationError = class extends Error {
|
|
1231
1349
|
constructor(message) {
|
|
@@ -1320,7 +1438,7 @@ function createBaseClient(options) {
|
|
|
1320
1438
|
const send = options.fetch ?? ((request) => fetch(request));
|
|
1321
1439
|
const client = createClient({
|
|
1322
1440
|
baseUrl: `${origin}/v1`,
|
|
1323
|
-
fetch: options.maxRetries === 0 ? send : withRetries(send, { maxRetries: options.maxRetries })
|
|
1441
|
+
fetch: options.maxRetries === 0 ? withoutMovingHeader(send) : withRetries(send, { maxRetries: options.maxRetries })
|
|
1324
1442
|
});
|
|
1325
1443
|
client.use({
|
|
1326
1444
|
onRequest({ request }) {
|
|
@@ -5253,7 +5371,7 @@ var OPERATIONS = [
|
|
|
5253
5371
|
"idempotentHint": false
|
|
5254
5372
|
}
|
|
5255
5373
|
},
|
|
5256
|
-
"description": "Asks whether `subject` may do `action` at `cost`, given every enabled limit that applies, and \u2014 in `consume` mode \u2014 uses it. Always 200 for a decision: read `allowed`; `
|
|
5374
|
+
"description": "Asks whether `subject` may do `action` at `cost`, given every enabled limit that applies, and \u2014 in `consume` mode \u2014 uses it. Always 200 for a decision, allowed or refused: read `allowed`; `limits` shows what is left on each limit and `retryAfterSeconds` when to try again. An `Idempotency-Key` header makes a retried check return the same decision without using twice. Its API-key check is cached briefly for speed: a revoked key can keep working here for up to 60 seconds.",
|
|
5257
5375
|
"fields": [
|
|
5258
5376
|
{
|
|
5259
5377
|
"name": "subject",
|
|
@@ -5358,7 +5476,7 @@ var OPERATIONS = [
|
|
|
5358
5476
|
"in": "body",
|
|
5359
5477
|
"type": "string",
|
|
5360
5478
|
"required": false,
|
|
5361
|
-
"description": "`consume` (default) decides and uses; `preview` decides without using; `reserve` decides and
|
|
5479
|
+
"description": "`consume` (default) decides and uses; `preview` decides without using; `reserve` decides and reserves `cost` (what it will probably use) until you commit the actual amount or release it \u2014 see `reservation` in the answer. Only a reservation takes a slot of a `concurrent` limit.",
|
|
5362
5480
|
"example": "consume",
|
|
5363
5481
|
"schema": {
|
|
5364
5482
|
"type": "string",
|
|
@@ -5367,7 +5485,7 @@ var OPERATIONS = [
|
|
|
5367
5485
|
"preview",
|
|
5368
5486
|
"reserve"
|
|
5369
5487
|
],
|
|
5370
|
-
"description": "`consume` (default) decides and uses; `preview` decides without using; `reserve` decides and
|
|
5488
|
+
"description": "`consume` (default) decides and uses; `preview` decides without using; `reserve` decides and reserves `cost` (what it will probably use) until you commit the actual amount or release it \u2014 see `reservation` in the answer. Only a reservation takes a slot of a `concurrent` limit."
|
|
5371
5489
|
}
|
|
5372
5490
|
},
|
|
5373
5491
|
{
|
|
@@ -5375,13 +5493,13 @@ var OPERATIONS = [
|
|
|
5375
5493
|
"in": "body",
|
|
5376
5494
|
"type": "number",
|
|
5377
5495
|
"required": false,
|
|
5378
|
-
"description": "With `reserve`: how long the
|
|
5496
|
+
"description": "With `reserve`: how long the reservation lasts before it releases itself. Default 300, at most 3600.",
|
|
5379
5497
|
"example": 300,
|
|
5380
5498
|
"schema": {
|
|
5381
5499
|
"type": "integer",
|
|
5382
5500
|
"minimum": 1,
|
|
5383
5501
|
"maximum": 3600,
|
|
5384
|
-
"description": "With `reserve`: how long the
|
|
5502
|
+
"description": "With `reserve`: how long the reservation lasts before it releases itself. Default 300, at most 3600."
|
|
5385
5503
|
}
|
|
5386
5504
|
}
|
|
5387
5505
|
],
|
|
@@ -5410,14 +5528,14 @@ var OPERATIONS = [
|
|
|
5410
5528
|
"idempotentHint": false
|
|
5411
5529
|
}
|
|
5412
5530
|
},
|
|
5413
|
-
"description": "Stops a limit: checks stop enforcing it
|
|
5531
|
+
"description": "Stops a limit: checks stop enforcing it at once, and it leaves the list. It is archived, not erased \u2014 its usage history and credits stay, and `POST /v1/limits/{limitId}/restore` brings it back. Owners and admins only, for a person's token.",
|
|
5414
5532
|
"fields": [
|
|
5415
5533
|
{
|
|
5416
5534
|
"name": "limitId",
|
|
5417
5535
|
"in": "path",
|
|
5418
5536
|
"type": "string",
|
|
5419
5537
|
"required": true,
|
|
5420
|
-
"example": "
|
|
5538
|
+
"example": "lmt_3f0c\u2026",
|
|
5421
5539
|
"schema": {
|
|
5422
5540
|
"type": "string"
|
|
5423
5541
|
}
|
|
@@ -5446,64 +5564,68 @@ var OPERATIONS = [
|
|
|
5446
5564
|
"idempotentHint": false
|
|
5447
5565
|
}
|
|
5448
5566
|
},
|
|
5449
|
-
"description": "Limits how much
|
|
5567
|
+
"description": "Limits how much a subject may use per window \u2014 for example 200 cents a month for every `user`. Only `subject.kind`, `amount` and `window` are needed: `action` defaults to every action (`*`), `unit` to units, and `name` to the sentence the limit reads as. Checks enforce it from then on. What it counts (subject, action, unit, window, every, start, rolling) is fixed once created. Owners and admins only, for a person's token.",
|
|
5450
5568
|
"fields": [
|
|
5451
5569
|
{
|
|
5452
5570
|
"name": "name",
|
|
5453
5571
|
"in": "body",
|
|
5454
5572
|
"type": "string",
|
|
5455
|
-
"required":
|
|
5456
|
-
"description":
|
|
5573
|
+
"required": false,
|
|
5574
|
+
"description": `A name, unique among the environment's active limits. Default: the sentence the limit reads as, such as "200 cents per user per month". If a limit already has that name, the answer is 409: give this one a name.`,
|
|
5457
5575
|
"example": "AI budget",
|
|
5458
5576
|
"schema": {
|
|
5459
5577
|
"type": "string",
|
|
5460
5578
|
"minLength": 1,
|
|
5461
5579
|
"maxLength": 100,
|
|
5462
|
-
"description":
|
|
5580
|
+
"description": `A name, unique among the environment's active limits. Default: the sentence the limit reads as, such as "200 cents per user per month". If a limit already has that name, the answer is 409: give this one a name.`
|
|
5463
5581
|
}
|
|
5464
5582
|
},
|
|
5465
5583
|
{
|
|
5466
|
-
"name": "
|
|
5584
|
+
"name": "subject",
|
|
5467
5585
|
"in": "body",
|
|
5468
|
-
"type": "
|
|
5586
|
+
"type": "json",
|
|
5469
5587
|
"required": true,
|
|
5470
|
-
"description": "
|
|
5471
|
-
"example":
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
"minLength": 1,
|
|
5475
|
-
"maxLength": 100,
|
|
5476
|
-
"description": "Your own label for who is checked."
|
|
5477
|
-
}
|
|
5478
|
-
},
|
|
5479
|
-
{
|
|
5480
|
-
"name": "subjectId",
|
|
5481
|
-
"in": "body",
|
|
5482
|
-
"type": "string",
|
|
5483
|
-
"required": false,
|
|
5484
|
-
"description": "One subject; omit or null for every subject of the kind. A subject's own limit replaces the kind's limits with the same action and window.",
|
|
5588
|
+
"description": 'Who it applies to: `{"kind": "user"}` for every user, `{"kind": "user", "id": "usr_123"}` for one.',
|
|
5589
|
+
"example": {
|
|
5590
|
+
"kind": "user"
|
|
5591
|
+
},
|
|
5485
5592
|
"schema": {
|
|
5486
|
-
"type":
|
|
5487
|
-
|
|
5488
|
-
"
|
|
5593
|
+
"type": "object",
|
|
5594
|
+
"properties": {
|
|
5595
|
+
"kind": {
|
|
5596
|
+
"type": "string",
|
|
5597
|
+
"minLength": 1,
|
|
5598
|
+
"maxLength": 100,
|
|
5599
|
+
"description": "Your own label for who is checked: user, team, apikey \u2026"
|
|
5600
|
+
},
|
|
5601
|
+
"id": {
|
|
5602
|
+
"type": [
|
|
5603
|
+
"string",
|
|
5604
|
+
"null"
|
|
5605
|
+
],
|
|
5606
|
+
"minLength": 1,
|
|
5607
|
+
"maxLength": 100,
|
|
5608
|
+
"description": "One subject; omit or null for every subject of the kind. A subject's own limit replaces the kind's limits with the same action and window."
|
|
5609
|
+
}
|
|
5610
|
+
},
|
|
5611
|
+
"required": [
|
|
5612
|
+
"kind"
|
|
5489
5613
|
],
|
|
5490
|
-
"
|
|
5491
|
-
"maxLength": 100,
|
|
5492
|
-
"description": "One subject; omit or null for every subject of the kind. A subject's own limit replaces the kind's limits with the same action and window."
|
|
5614
|
+
"description": 'Who it applies to: `{"kind": "user"}` for every user, `{"kind": "user", "id": "usr_123"}` for one.'
|
|
5493
5615
|
}
|
|
5494
5616
|
},
|
|
5495
5617
|
{
|
|
5496
5618
|
"name": "action",
|
|
5497
5619
|
"in": "body",
|
|
5498
5620
|
"type": "string",
|
|
5499
|
-
"required":
|
|
5500
|
-
"description": "The action to limit
|
|
5621
|
+
"required": false,
|
|
5622
|
+
"description": "The action to limit. Default: `*`, every action.",
|
|
5501
5623
|
"example": "ai-call",
|
|
5502
5624
|
"schema": {
|
|
5503
5625
|
"type": "string",
|
|
5504
5626
|
"minLength": 1,
|
|
5505
5627
|
"maxLength": 100,
|
|
5506
|
-
"description": "The action to limit
|
|
5628
|
+
"description": "The action to limit. Default: `*`, every action."
|
|
5507
5629
|
}
|
|
5508
5630
|
},
|
|
5509
5631
|
{
|
|
@@ -5525,13 +5647,13 @@ var OPERATIONS = [
|
|
|
5525
5647
|
"in": "body",
|
|
5526
5648
|
"type": "string",
|
|
5527
5649
|
"required": false,
|
|
5528
|
-
"description": "What the amount counts
|
|
5650
|
+
"description": "What the amount counts, in words. Default: units.",
|
|
5529
5651
|
"example": "cents",
|
|
5530
5652
|
"schema": {
|
|
5531
5653
|
"type": "string",
|
|
5532
5654
|
"minLength": 1,
|
|
5533
5655
|
"maxLength": 40,
|
|
5534
|
-
"description": "What the amount counts
|
|
5656
|
+
"description": "What the amount counts, in words. Default: units."
|
|
5535
5657
|
}
|
|
5536
5658
|
},
|
|
5537
5659
|
{
|
|
@@ -5539,7 +5661,7 @@ var OPERATIONS = [
|
|
|
5539
5661
|
"in": "body",
|
|
5540
5662
|
"type": "string",
|
|
5541
5663
|
"required": true,
|
|
5542
|
-
"description": "`minute`, `hour`, `day`, `week`, `month` or `year`: a period of `every` of them,
|
|
5664
|
+
"description": "`minute`, `hour`, `day`, `week`, `month` or `year`: a period of `every` of them, reset where `start` says (or rolling: see `rolling`). `total`: a balance that never resets, raised by credits. `concurrent`: at most `amount` open reservations at once.",
|
|
5543
5665
|
"example": "month",
|
|
5544
5666
|
"schema": {
|
|
5545
5667
|
"type": "string",
|
|
@@ -5553,7 +5675,7 @@ var OPERATIONS = [
|
|
|
5553
5675
|
"total",
|
|
5554
5676
|
"concurrent"
|
|
5555
5677
|
],
|
|
5556
|
-
"description": "`minute`, `hour`, `day`, `week`, `month` or `year`: a period of `every` of them,
|
|
5678
|
+
"description": "`minute`, `hour`, `day`, `week`, `month` or `year`: a period of `every` of them, reset where `start` says (or rolling: see `rolling`). `total`: a balance that never resets, raised by credits. `concurrent`: at most `amount` open reservations at once."
|
|
5557
5679
|
}
|
|
5558
5680
|
},
|
|
5559
5681
|
{
|
|
@@ -5575,16 +5697,16 @@ var OPERATIONS = [
|
|
|
5575
5697
|
"in": "body",
|
|
5576
5698
|
"type": "string",
|
|
5577
5699
|
"required": false,
|
|
5578
|
-
"description": "Where a period begins. `calendar`: UTC boundaries (midnight, Monday, the 1st, 1 January). `
|
|
5700
|
+
"description": "Where a period begins. `calendar`: UTC boundaries (midnight, Monday, the 1st, 1 January). `billing_date`: from the subject's billing date, set with `subjects.update` (its first check until then), so an annual plan can reset monthly from its start day. `first_use`: at the first check after the previous period ended. Default: calendar.",
|
|
5579
5701
|
"example": "calendar",
|
|
5580
5702
|
"schema": {
|
|
5581
5703
|
"type": "string",
|
|
5582
5704
|
"enum": [
|
|
5583
5705
|
"calendar",
|
|
5584
|
-
"
|
|
5706
|
+
"billing_date",
|
|
5585
5707
|
"first_use"
|
|
5586
5708
|
],
|
|
5587
|
-
"description": "Where a period begins. `calendar`: UTC boundaries (midnight, Monday, the 1st, 1 January). `
|
|
5709
|
+
"description": "Where a period begins. `calendar`: UTC boundaries (midnight, Monday, the 1st, 1 January). `billing_date`: from the subject's billing date, set with `subjects.update` (its first check until then), so an annual plan can reset monthly from its start day. `first_use`: at the first check after the previous period ended. Default: calendar."
|
|
5588
5710
|
}
|
|
5589
5711
|
},
|
|
5590
5712
|
{
|
|
@@ -5630,50 +5752,12 @@ var OPERATIONS = [
|
|
|
5630
5752
|
"scope": "limits:write"
|
|
5631
5753
|
},
|
|
5632
5754
|
{
|
|
5633
|
-
"operationId": "limits.
|
|
5634
|
-
"method": "get",
|
|
5635
|
-
"path": "/limits/{limitId}",
|
|
5636
|
-
"summary": "Get a limit",
|
|
5637
|
-
"cli": {
|
|
5638
|
-
"command": "limits get",
|
|
5639
|
-
"args": [
|
|
5640
|
-
"limitId"
|
|
5641
|
-
],
|
|
5642
|
-
"confirm": false
|
|
5643
|
-
},
|
|
5644
|
-
"mcp": {
|
|
5645
|
-
"exposed": true,
|
|
5646
|
-
"name": "limits_get",
|
|
5647
|
-
"hints": {
|
|
5648
|
-
"readOnlyHint": true,
|
|
5649
|
-
"destructiveHint": false,
|
|
5650
|
-
"idempotentHint": true
|
|
5651
|
-
}
|
|
5652
|
-
},
|
|
5653
|
-
"description": "One limit: who it applies to, the action, amount and window.",
|
|
5654
|
-
"fields": [
|
|
5655
|
-
{
|
|
5656
|
-
"name": "limitId",
|
|
5657
|
-
"in": "path",
|
|
5658
|
-
"type": "string",
|
|
5659
|
-
"required": true,
|
|
5660
|
-
"example": "lim_3f0c\u2026",
|
|
5661
|
-
"schema": {
|
|
5662
|
-
"type": "string"
|
|
5663
|
-
}
|
|
5664
|
-
}
|
|
5665
|
-
],
|
|
5666
|
-
"hasBody": false,
|
|
5667
|
-
"workspace": true,
|
|
5668
|
-
"scope": "limits:read"
|
|
5669
|
-
},
|
|
5670
|
-
{
|
|
5671
|
-
"operationId": "limits.grants.create",
|
|
5755
|
+
"operationId": "limits.credits.create",
|
|
5672
5756
|
"method": "post",
|
|
5673
|
-
"path": "/limits/{limitId}/
|
|
5757
|
+
"path": "/limits/{limitId}/credits",
|
|
5674
5758
|
"summary": "Add credits to a balance",
|
|
5675
5759
|
"cli": {
|
|
5676
|
-
"command": "limits
|
|
5760
|
+
"command": "limits credits create",
|
|
5677
5761
|
"args": [
|
|
5678
5762
|
"limitId"
|
|
5679
5763
|
],
|
|
@@ -5681,16 +5765,16 @@ var OPERATIONS = [
|
|
|
5681
5765
|
},
|
|
5682
5766
|
"mcp": {
|
|
5683
5767
|
"exposed": false,
|
|
5684
|
-
"reason": "Adding credits gives value away; an agent asks a person (limit.
|
|
5768
|
+
"reason": "Adding credits gives value away; an agent asks a person (limit.credit approval)"
|
|
5685
5769
|
},
|
|
5686
|
-
"description": "Adds `amount` to one subject's balance \u2014 a limit whose window is `total`. A negative `amount` takes credits back (a refund, a chargeback) and needs a `note` saying why; the balance may go below zero, and checks are refused until
|
|
5770
|
+
"description": "Adds `amount` credits to one subject's balance \u2014 a limit whose window is `total`. A negative `amount` takes credits back (a refund, a chargeback) and needs a `note` saying why; the balance may go below zero, and checks are refused until more credits are added. Owners and admins, or a workspace API key; an agent asks a person (the `limit.credit` approval).",
|
|
5687
5771
|
"fields": [
|
|
5688
5772
|
{
|
|
5689
5773
|
"name": "limitId",
|
|
5690
5774
|
"in": "path",
|
|
5691
5775
|
"type": "string",
|
|
5692
5776
|
"required": true,
|
|
5693
|
-
"example": "
|
|
5777
|
+
"example": "lmt_3f0c\u2026",
|
|
5694
5778
|
"schema": {
|
|
5695
5779
|
"type": "string"
|
|
5696
5780
|
}
|
|
@@ -5744,7 +5828,7 @@ var OPERATIONS = [
|
|
|
5744
5828
|
"type": "string",
|
|
5745
5829
|
"required": false,
|
|
5746
5830
|
"description": "Required when `amount` is negative.",
|
|
5747
|
-
"example": "October
|
|
5831
|
+
"example": "October credits",
|
|
5748
5832
|
"schema": {
|
|
5749
5833
|
"type": "string",
|
|
5750
5834
|
"maxLength": 200,
|
|
@@ -5757,12 +5841,12 @@ var OPERATIONS = [
|
|
|
5757
5841
|
"scope": "limits:write"
|
|
5758
5842
|
},
|
|
5759
5843
|
{
|
|
5760
|
-
"operationId": "limits.
|
|
5844
|
+
"operationId": "limits.credits.list",
|
|
5761
5845
|
"method": "get",
|
|
5762
|
-
"path": "/limits/{limitId}/
|
|
5763
|
-
"summary": "List a balance's
|
|
5846
|
+
"path": "/limits/{limitId}/credits",
|
|
5847
|
+
"summary": "List a balance's credits",
|
|
5764
5848
|
"cli": {
|
|
5765
|
-
"command": "limits
|
|
5849
|
+
"command": "limits credits list",
|
|
5766
5850
|
"args": [
|
|
5767
5851
|
"limitId"
|
|
5768
5852
|
],
|
|
@@ -5770,21 +5854,59 @@ var OPERATIONS = [
|
|
|
5770
5854
|
},
|
|
5771
5855
|
"mcp": {
|
|
5772
5856
|
"exposed": true,
|
|
5773
|
-
"name": "
|
|
5857
|
+
"name": "limits_credits_list",
|
|
5774
5858
|
"hints": {
|
|
5775
5859
|
"readOnlyHint": true,
|
|
5776
5860
|
"destructiveHint": false,
|
|
5777
5861
|
"idempotentHint": true
|
|
5778
5862
|
}
|
|
5779
5863
|
},
|
|
5780
|
-
"description": "Credits added to subjects' balances for this limit, newest first.",
|
|
5864
|
+
"description": "Credits added to (or taken back from) subjects' balances for this limit, newest first.",
|
|
5781
5865
|
"fields": [
|
|
5782
5866
|
{
|
|
5783
5867
|
"name": "limitId",
|
|
5784
5868
|
"in": "path",
|
|
5785
5869
|
"type": "string",
|
|
5786
5870
|
"required": true,
|
|
5787
|
-
"example": "
|
|
5871
|
+
"example": "lmt_3f0c\u2026",
|
|
5872
|
+
"schema": {
|
|
5873
|
+
"type": "string"
|
|
5874
|
+
}
|
|
5875
|
+
}
|
|
5876
|
+
],
|
|
5877
|
+
"hasBody": false,
|
|
5878
|
+
"workspace": true,
|
|
5879
|
+
"scope": "limits:read"
|
|
5880
|
+
},
|
|
5881
|
+
{
|
|
5882
|
+
"operationId": "limits.get",
|
|
5883
|
+
"method": "get",
|
|
5884
|
+
"path": "/limits/{limitId}",
|
|
5885
|
+
"summary": "Get a limit",
|
|
5886
|
+
"cli": {
|
|
5887
|
+
"command": "limits get",
|
|
5888
|
+
"args": [
|
|
5889
|
+
"limitId"
|
|
5890
|
+
],
|
|
5891
|
+
"confirm": false
|
|
5892
|
+
},
|
|
5893
|
+
"mcp": {
|
|
5894
|
+
"exposed": true,
|
|
5895
|
+
"name": "limits_get",
|
|
5896
|
+
"hints": {
|
|
5897
|
+
"readOnlyHint": true,
|
|
5898
|
+
"destructiveHint": false,
|
|
5899
|
+
"idempotentHint": true
|
|
5900
|
+
}
|
|
5901
|
+
},
|
|
5902
|
+
"description": "One limit: who it applies to, the action, amount and window.",
|
|
5903
|
+
"fields": [
|
|
5904
|
+
{
|
|
5905
|
+
"name": "limitId",
|
|
5906
|
+
"in": "path",
|
|
5907
|
+
"type": "string",
|
|
5908
|
+
"required": true,
|
|
5909
|
+
"example": "lmt_3f0c\u2026",
|
|
5788
5910
|
"schema": {
|
|
5789
5911
|
"type": "string"
|
|
5790
5912
|
}
|
|
@@ -5915,7 +6037,7 @@ var OPERATIONS = [
|
|
|
5915
6037
|
"in": "path",
|
|
5916
6038
|
"type": "string",
|
|
5917
6039
|
"required": true,
|
|
5918
|
-
"example": "
|
|
6040
|
+
"example": "lmt_3f0c\u2026",
|
|
5919
6041
|
"schema": {
|
|
5920
6042
|
"type": "string"
|
|
5921
6043
|
}
|
|
@@ -5945,18 +6067,20 @@ var OPERATIONS = [
|
|
|
5945
6067
|
"idempotentHint": false
|
|
5946
6068
|
}
|
|
5947
6069
|
},
|
|
5948
|
-
"description": "Makes the environment's limits match `limits`, by name: creates the missing, changes those that differ (an omitted field means its default) and, with `archiveMissing`, archives active limits the list doesn't name. Running it twice changes nothing the second time. Limitry checks the whole list first, and a problem anywhere changes nothing (400, each problem in `details`); then it writes every change at once. `
|
|
6070
|
+
"description": "Makes the environment's limits match `limits`, by name: creates the missing, changes those that differ (an omitted field means its default) and, with `archiveMissing`, archives active limits the list doesn't name. Running it twice changes nothing the second time. Limitry checks the whole list first, and a problem anywhere changes nothing (400, each problem in `details`); then it writes every change at once. What a limit counts is fixed: a different subject, action, unit or window under an existing name is refused until the entry is renamed. `preview` answers what it would do without writing. For keeping limits in a file in your repository (`limitry sync`). Owners and admins only, for a person's token.",
|
|
5949
6071
|
"fields": [
|
|
5950
6072
|
{
|
|
5951
6073
|
"name": "limits",
|
|
5952
6074
|
"in": "body",
|
|
5953
6075
|
"type": "json",
|
|
5954
6076
|
"required": true,
|
|
5955
|
-
"description": "Every limit you want, each described whole: an omitted field is its default, as on create. Names are the key and must be unique in the list. At most 200.",
|
|
6077
|
+
"description": "Every limit you want, each described whole: an omitted field is its default, as on create. Names are the key and must be unique in the list. What a limit counts (subject, action, unit, window, every, start, rolling) is fixed: to change it, rename the entry, which creates a new limit. At most 200.",
|
|
5956
6078
|
"example": [
|
|
5957
6079
|
{
|
|
5958
6080
|
"name": "AI budget",
|
|
5959
|
-
"
|
|
6081
|
+
"subject": {
|
|
6082
|
+
"kind": "user"
|
|
6083
|
+
},
|
|
5960
6084
|
"action": "ai-call",
|
|
5961
6085
|
"amount": 200,
|
|
5962
6086
|
"unit": "cents",
|
|
@@ -5966,103 +6090,29 @@ var OPERATIONS = [
|
|
|
5966
6090
|
"schema": {
|
|
5967
6091
|
"type": "array",
|
|
5968
6092
|
"items": {
|
|
5969
|
-
"
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
"type": "string",
|
|
5973
|
-
"minLength": 1,
|
|
5974
|
-
"maxLength": 100,
|
|
5975
|
-
"description": "A name for the limit, unique among its environment's active limits."
|
|
5976
|
-
},
|
|
5977
|
-
"subjectKind": {
|
|
5978
|
-
"type": "string",
|
|
5979
|
-
"minLength": 1,
|
|
5980
|
-
"maxLength": 100,
|
|
5981
|
-
"description": "Your own label for who is checked."
|
|
5982
|
-
},
|
|
5983
|
-
"subjectId": {
|
|
5984
|
-
"type": [
|
|
5985
|
-
"string",
|
|
5986
|
-
"null"
|
|
5987
|
-
],
|
|
5988
|
-
"minLength": 1,
|
|
5989
|
-
"maxLength": 100,
|
|
5990
|
-
"description": "One subject; omit or null for every subject of the kind. A subject's own limit replaces the kind's limits with the same action and window."
|
|
5991
|
-
},
|
|
5992
|
-
"action": {
|
|
5993
|
-
"type": "string",
|
|
5994
|
-
"minLength": 1,
|
|
5995
|
-
"maxLength": 100,
|
|
5996
|
-
"description": "The action to limit; `*` for every action."
|
|
5997
|
-
},
|
|
5998
|
-
"amount": {
|
|
5999
|
-
"type": "integer",
|
|
6000
|
-
"minimum": 1,
|
|
6001
|
-
"maximum": 1e9,
|
|
6002
|
-
"description": "How many units each subject may use per window."
|
|
6003
|
-
},
|
|
6004
|
-
"unit": {
|
|
6005
|
-
"type": "string",
|
|
6006
|
-
"minLength": 1,
|
|
6007
|
-
"maxLength": 40,
|
|
6008
|
-
"description": "What the amount counts (display only). Default: units."
|
|
6009
|
-
},
|
|
6010
|
-
"window": {
|
|
6011
|
-
"type": "string",
|
|
6012
|
-
"enum": [
|
|
6013
|
-
"minute",
|
|
6014
|
-
"hour",
|
|
6015
|
-
"day",
|
|
6016
|
-
"week",
|
|
6017
|
-
"month",
|
|
6018
|
-
"year",
|
|
6019
|
-
"total",
|
|
6020
|
-
"concurrent"
|
|
6021
|
-
],
|
|
6022
|
-
"description": "`minute`, `hour`, `day`, `week`, `month` or `year`: a period of `every` of them, refilled where `start` says (or rolling: see `rolling`). `total`: a balance that never resets, topped up by grants. `concurrent`: at most `amount` held reservations at once."
|
|
6023
|
-
},
|
|
6024
|
-
"every": {
|
|
6025
|
-
"type": "integer",
|
|
6026
|
-
"minimum": 1,
|
|
6027
|
-
"maximum": 1e3,
|
|
6028
|
-
"description": 'How many `window` units a period lasts: `window: "month", every: 3` is a quarter, `window: "hour", every: 5` five hours. Default: 1.'
|
|
6029
|
-
},
|
|
6030
|
-
"start": {
|
|
6031
|
-
"type": "string",
|
|
6032
|
-
"enum": [
|
|
6033
|
-
"calendar",
|
|
6034
|
-
"anchor",
|
|
6035
|
-
"first_use"
|
|
6036
|
-
],
|
|
6037
|
-
"description": "Where a period begins. `calendar`: UTC boundaries (midnight, Monday, the 1st, 1 January). `anchor`: from the subject's anchor, its billing date, set with `subjects.update` (its first check until then), so an annual plan can refill monthly from its start day. `first_use`: at the first check after the previous period ended. Default: calendar."
|
|
6038
|
-
},
|
|
6039
|
-
"rolling": {
|
|
6040
|
-
"type": "boolean",
|
|
6041
|
-
"description": "Count the last window instead of the calendar one (minute, hour or day only). Default: false."
|
|
6093
|
+
"allOf": [
|
|
6094
|
+
{
|
|
6095
|
+
"$ref": "#/components/schemas/LimitInput"
|
|
6042
6096
|
},
|
|
6043
|
-
|
|
6044
|
-
"type": "
|
|
6045
|
-
"
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6097
|
+
{
|
|
6098
|
+
"type": "object",
|
|
6099
|
+
"properties": {
|
|
6100
|
+
"name": {
|
|
6101
|
+
"type": "string",
|
|
6102
|
+
"minLength": 1,
|
|
6103
|
+
"maxLength": 100,
|
|
6104
|
+
"example": "AI budget",
|
|
6105
|
+
"description": "The limit's name: the key a sync matches on, unique in the list."
|
|
6106
|
+
}
|
|
6107
|
+
},
|
|
6108
|
+
"required": [
|
|
6109
|
+
"name"
|
|
6110
|
+
]
|
|
6054
6111
|
}
|
|
6055
|
-
},
|
|
6056
|
-
"required": [
|
|
6057
|
-
"name",
|
|
6058
|
-
"subjectKind",
|
|
6059
|
-
"action",
|
|
6060
|
-
"amount",
|
|
6061
|
-
"window"
|
|
6062
6112
|
]
|
|
6063
6113
|
},
|
|
6064
6114
|
"maxItems": 200,
|
|
6065
|
-
"description": "Every limit you want, each described whole: an omitted field is its default, as on create. Names are the key and must be unique in the list. At most 200."
|
|
6115
|
+
"description": "Every limit you want, each described whole: an omitted field is its default, as on create. Names are the key and must be unique in the list. What a limit counts (subject, action, unit, window, every, start, rolling) is fixed: to change it, rename the entry, which creates a new limit. At most 200."
|
|
6066
6116
|
}
|
|
6067
6117
|
},
|
|
6068
6118
|
{
|
|
@@ -6077,7 +6127,7 @@ var OPERATIONS = [
|
|
|
6077
6127
|
}
|
|
6078
6128
|
},
|
|
6079
6129
|
{
|
|
6080
|
-
"name": "
|
|
6130
|
+
"name": "preview",
|
|
6081
6131
|
"in": "body",
|
|
6082
6132
|
"type": "boolean",
|
|
6083
6133
|
"required": false,
|
|
@@ -6113,14 +6163,14 @@ var OPERATIONS = [
|
|
|
6113
6163
|
"idempotentHint": false
|
|
6114
6164
|
}
|
|
6115
6165
|
},
|
|
6116
|
-
"description": "Changes
|
|
6166
|
+
"description": "Changes a limit's name, amount, fail mode or whether it is enabled; checks use the new rule at once. What a limit counts (subject, action, unit, window, every, start, rolling) is fixed: a different value is refused (400) \u2014 create a new limit and archive this one. Owners and admins only, for a person's token.",
|
|
6117
6167
|
"fields": [
|
|
6118
6168
|
{
|
|
6119
6169
|
"name": "limitId",
|
|
6120
6170
|
"in": "path",
|
|
6121
6171
|
"type": "string",
|
|
6122
6172
|
"required": true,
|
|
6123
|
-
"example": "
|
|
6173
|
+
"example": "lmt_3f0c\u2026",
|
|
6124
6174
|
"schema": {
|
|
6125
6175
|
"type": "string"
|
|
6126
6176
|
}
|
|
@@ -6130,71 +6180,97 @@ var OPERATIONS = [
|
|
|
6130
6180
|
"in": "body",
|
|
6131
6181
|
"type": "string",
|
|
6132
6182
|
"required": false,
|
|
6133
|
-
"description": "A name
|
|
6183
|
+
"description": "A new name, unique among the environment's active limits.",
|
|
6134
6184
|
"example": "AI budget",
|
|
6135
6185
|
"schema": {
|
|
6136
6186
|
"type": "string",
|
|
6137
6187
|
"minLength": 1,
|
|
6138
6188
|
"maxLength": 100,
|
|
6139
|
-
"description": "A name
|
|
6189
|
+
"description": "A new name, unique among the environment's active limits."
|
|
6140
6190
|
}
|
|
6141
6191
|
},
|
|
6142
6192
|
{
|
|
6143
|
-
"name": "
|
|
6193
|
+
"name": "amount",
|
|
6144
6194
|
"in": "body",
|
|
6145
|
-
"type": "
|
|
6195
|
+
"type": "number",
|
|
6146
6196
|
"required": false,
|
|
6147
|
-
"description": "
|
|
6148
|
-
"example":
|
|
6197
|
+
"description": "How many units each subject may use per window.",
|
|
6198
|
+
"example": 300,
|
|
6149
6199
|
"schema": {
|
|
6150
|
-
"type": "
|
|
6151
|
-
"
|
|
6152
|
-
"
|
|
6153
|
-
"description": "
|
|
6200
|
+
"type": "integer",
|
|
6201
|
+
"minimum": 1,
|
|
6202
|
+
"maximum": 1e9,
|
|
6203
|
+
"description": "How many units each subject may use per window."
|
|
6154
6204
|
}
|
|
6155
6205
|
},
|
|
6156
6206
|
{
|
|
6157
|
-
"name": "
|
|
6207
|
+
"name": "enabled",
|
|
6158
6208
|
"in": "body",
|
|
6159
|
-
"type": "
|
|
6209
|
+
"type": "boolean",
|
|
6160
6210
|
"required": false,
|
|
6161
|
-
"description": "
|
|
6211
|
+
"description": "Whether checks enforce it.",
|
|
6162
6212
|
"schema": {
|
|
6163
|
-
"type":
|
|
6164
|
-
|
|
6165
|
-
"null"
|
|
6166
|
-
],
|
|
6167
|
-
"minLength": 1,
|
|
6168
|
-
"maxLength": 100,
|
|
6169
|
-
"description": "One subject; omit or null for every subject of the kind. A subject's own limit replaces the kind's limits with the same action and window."
|
|
6213
|
+
"type": "boolean",
|
|
6214
|
+
"description": "Whether checks enforce it."
|
|
6170
6215
|
}
|
|
6171
6216
|
},
|
|
6172
6217
|
{
|
|
6173
|
-
"name": "
|
|
6218
|
+
"name": "failMode",
|
|
6174
6219
|
"in": "body",
|
|
6175
6220
|
"type": "string",
|
|
6176
6221
|
"required": false,
|
|
6177
|
-
"description": "
|
|
6178
|
-
"example": "ai-call",
|
|
6222
|
+
"description": "What your code should do when Limitry can't be reached: `open` (allow) or `closed` (deny).",
|
|
6179
6223
|
"schema": {
|
|
6180
6224
|
"type": "string",
|
|
6181
|
-
"
|
|
6182
|
-
|
|
6183
|
-
|
|
6225
|
+
"enum": [
|
|
6226
|
+
"open",
|
|
6227
|
+
"closed"
|
|
6228
|
+
],
|
|
6229
|
+
"description": "What your code should do when Limitry can't be reached: `open` (allow) or `closed` (deny)."
|
|
6184
6230
|
}
|
|
6185
6231
|
},
|
|
6186
6232
|
{
|
|
6187
|
-
"name": "
|
|
6233
|
+
"name": "subject",
|
|
6188
6234
|
"in": "body",
|
|
6189
|
-
"type": "
|
|
6235
|
+
"type": "json",
|
|
6190
6236
|
"required": false,
|
|
6191
|
-
"description": "
|
|
6192
|
-
"example":
|
|
6237
|
+
"description": "Who it applies to. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6238
|
+
"example": {
|
|
6239
|
+
"kind": "user"
|
|
6240
|
+
},
|
|
6193
6241
|
"schema": {
|
|
6194
|
-
"type": "
|
|
6195
|
-
"
|
|
6196
|
-
|
|
6197
|
-
|
|
6242
|
+
"type": "object",
|
|
6243
|
+
"properties": {
|
|
6244
|
+
"kind": {
|
|
6245
|
+
"type": "string",
|
|
6246
|
+
"minLength": 1,
|
|
6247
|
+
"maxLength": 100,
|
|
6248
|
+
"description": "Your own label for who is checked: user, team, apikey \u2026"
|
|
6249
|
+
},
|
|
6250
|
+
"id": {
|
|
6251
|
+
"type": [
|
|
6252
|
+
"string",
|
|
6253
|
+
"null"
|
|
6254
|
+
],
|
|
6255
|
+
"minLength": 1,
|
|
6256
|
+
"maxLength": 100,
|
|
6257
|
+
"description": "One subject; omit or null for every subject of the kind. A subject's own limit replaces the kind's limits with the same action and window."
|
|
6258
|
+
}
|
|
6259
|
+
},
|
|
6260
|
+
"description": "Who it applies to. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6261
|
+
}
|
|
6262
|
+
},
|
|
6263
|
+
{
|
|
6264
|
+
"name": "action",
|
|
6265
|
+
"in": "body",
|
|
6266
|
+
"type": "string",
|
|
6267
|
+
"required": false,
|
|
6268
|
+
"description": "The action. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6269
|
+
"schema": {
|
|
6270
|
+
"type": "string",
|
|
6271
|
+
"minLength": 1,
|
|
6272
|
+
"maxLength": 100,
|
|
6273
|
+
"description": "The action. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6198
6274
|
}
|
|
6199
6275
|
},
|
|
6200
6276
|
{
|
|
@@ -6202,13 +6278,12 @@ var OPERATIONS = [
|
|
|
6202
6278
|
"in": "body",
|
|
6203
6279
|
"type": "string",
|
|
6204
6280
|
"required": false,
|
|
6205
|
-
"description": "What the amount counts
|
|
6206
|
-
"example": "cents",
|
|
6281
|
+
"description": "What the amount counts. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6207
6282
|
"schema": {
|
|
6208
6283
|
"type": "string",
|
|
6209
6284
|
"minLength": 1,
|
|
6210
6285
|
"maxLength": 40,
|
|
6211
|
-
"description": "What the amount counts
|
|
6286
|
+
"description": "What the amount counts. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6212
6287
|
}
|
|
6213
6288
|
},
|
|
6214
6289
|
{
|
|
@@ -6216,8 +6291,7 @@ var OPERATIONS = [
|
|
|
6216
6291
|
"in": "body",
|
|
6217
6292
|
"type": "string",
|
|
6218
6293
|
"required": false,
|
|
6219
|
-
"description": "
|
|
6220
|
-
"example": "month",
|
|
6294
|
+
"description": "The window. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6221
6295
|
"schema": {
|
|
6222
6296
|
"type": "string",
|
|
6223
6297
|
"enum": [
|
|
@@ -6230,7 +6304,7 @@ var OPERATIONS = [
|
|
|
6230
6304
|
"total",
|
|
6231
6305
|
"concurrent"
|
|
6232
6306
|
],
|
|
6233
|
-
"description": "
|
|
6307
|
+
"description": "The window. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6234
6308
|
}
|
|
6235
6309
|
},
|
|
6236
6310
|
{
|
|
@@ -6238,13 +6312,12 @@ var OPERATIONS = [
|
|
|
6238
6312
|
"in": "body",
|
|
6239
6313
|
"type": "number",
|
|
6240
6314
|
"required": false,
|
|
6241
|
-
"description":
|
|
6242
|
-
"example": 1,
|
|
6315
|
+
"description": "How many windows a period lasts. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6243
6316
|
"schema": {
|
|
6244
6317
|
"type": "integer",
|
|
6245
6318
|
"minimum": 1,
|
|
6246
6319
|
"maximum": 1e3,
|
|
6247
|
-
"description":
|
|
6320
|
+
"description": "How many windows a period lasts. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6248
6321
|
}
|
|
6249
6322
|
},
|
|
6250
6323
|
{
|
|
@@ -6252,16 +6325,15 @@ var OPERATIONS = [
|
|
|
6252
6325
|
"in": "body",
|
|
6253
6326
|
"type": "string",
|
|
6254
6327
|
"required": false,
|
|
6255
|
-
"description": "Where a period begins.
|
|
6256
|
-
"example": "calendar",
|
|
6328
|
+
"description": "Where a period begins. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6257
6329
|
"schema": {
|
|
6258
6330
|
"type": "string",
|
|
6259
6331
|
"enum": [
|
|
6260
6332
|
"calendar",
|
|
6261
|
-
"
|
|
6333
|
+
"billing_date",
|
|
6262
6334
|
"first_use"
|
|
6263
6335
|
],
|
|
6264
|
-
"description": "Where a period begins.
|
|
6336
|
+
"description": "Where a period begins. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6265
6337
|
}
|
|
6266
6338
|
},
|
|
6267
6339
|
{
|
|
@@ -6269,36 +6341,10 @@ var OPERATIONS = [
|
|
|
6269
6341
|
"in": "body",
|
|
6270
6342
|
"type": "boolean",
|
|
6271
6343
|
"required": false,
|
|
6272
|
-
"description": "
|
|
6273
|
-
"schema": {
|
|
6274
|
-
"type": "boolean",
|
|
6275
|
-
"description": "Count the last window instead of the calendar one (minute, hour or day only). Default: false."
|
|
6276
|
-
}
|
|
6277
|
-
},
|
|
6278
|
-
{
|
|
6279
|
-
"name": "enabled",
|
|
6280
|
-
"in": "body",
|
|
6281
|
-
"type": "boolean",
|
|
6282
|
-
"required": false,
|
|
6283
|
-
"description": "Whether checks enforce it. Default: true.",
|
|
6344
|
+
"description": "Whether it counts the last window. Fixed once the limit is created: to change it, create a new limit and archive this one.",
|
|
6284
6345
|
"schema": {
|
|
6285
6346
|
"type": "boolean",
|
|
6286
|
-
"description": "Whether
|
|
6287
|
-
}
|
|
6288
|
-
},
|
|
6289
|
-
{
|
|
6290
|
-
"name": "failMode",
|
|
6291
|
-
"in": "body",
|
|
6292
|
-
"type": "string",
|
|
6293
|
-
"required": false,
|
|
6294
|
-
"description": "What your code should do when Limitry can't be reached: `open` (allow) or `closed` (deny). Default: open.",
|
|
6295
|
-
"schema": {
|
|
6296
|
-
"type": "string",
|
|
6297
|
-
"enum": [
|
|
6298
|
-
"open",
|
|
6299
|
-
"closed"
|
|
6300
|
-
],
|
|
6301
|
-
"description": "What your code should do when Limitry can't be reached: `open` (allow) or `closed` (deny). Default: open."
|
|
6347
|
+
"description": "Whether it counts the last window. Fixed once the limit is created: to change it, create a new limit and archive this one."
|
|
6302
6348
|
}
|
|
6303
6349
|
}
|
|
6304
6350
|
],
|
|
@@ -6327,7 +6373,7 @@ var OPERATIONS = [
|
|
|
6327
6373
|
"idempotentHint": false
|
|
6328
6374
|
}
|
|
6329
6375
|
},
|
|
6330
|
-
"description": "
|
|
6376
|
+
"description": "Commits a reservation with the ACTUAL amount used (`cost`): less than reserved gives the rest back at once; more is charged in full \u2014 the work happened. A commit after the reservation expired still charges `cost`. Repeating a commit answers the same. Its API-key check is cached briefly for speed: a revoked key can keep working here for up to 60 seconds.",
|
|
6331
6377
|
"fields": [
|
|
6332
6378
|
{
|
|
6333
6379
|
"name": "reservationId",
|
|
@@ -6377,7 +6423,7 @@ var OPERATIONS = [
|
|
|
6377
6423
|
"idempotentHint": false
|
|
6378
6424
|
}
|
|
6379
6425
|
},
|
|
6380
|
-
"description": "Keeps a
|
|
6426
|
+
"description": "Keeps a reservation for longer work: it now expires `ttlSeconds` from now (default 300, at most 3600) \u2014 call it again as a heartbeat. Only an open reservation can be extended. Its API-key check is cached briefly for speed: a revoked key can keep working here for up to 60 seconds.",
|
|
6381
6427
|
"fields": [
|
|
6382
6428
|
{
|
|
6383
6429
|
"name": "reservationId",
|
|
@@ -6428,7 +6474,7 @@ var OPERATIONS = [
|
|
|
6428
6474
|
"idempotentHint": false
|
|
6429
6475
|
}
|
|
6430
6476
|
},
|
|
6431
|
-
"description": "Gives the whole
|
|
6477
|
+
"description": "Gives the whole reservation back \u2014 the work did not happen. Repeating a release answers the same; releasing a committed reservation is refused. Its API-key check is cached briefly for speed: a revoked key can keep working here for up to 60 seconds.",
|
|
6432
6478
|
"fields": [
|
|
6433
6479
|
{
|
|
6434
6480
|
"name": "reservationId",
|
|
@@ -6466,7 +6512,7 @@ var OPERATIONS = [
|
|
|
6466
6512
|
"idempotentHint": true
|
|
6467
6513
|
}
|
|
6468
6514
|
},
|
|
6469
|
-
"description": "A subject's
|
|
6515
|
+
"description": "A subject's billing date: when its `billing_date` limits' periods start from. A subject is yours (a user, a team, an agent) and exists once a check names it.",
|
|
6470
6516
|
"fields": [
|
|
6471
6517
|
{
|
|
6472
6518
|
"name": "subjectKind",
|
|
@@ -6519,7 +6565,7 @@ var OPERATIONS = [
|
|
|
6519
6565
|
"idempotentHint": false
|
|
6520
6566
|
}
|
|
6521
6567
|
},
|
|
6522
|
-
"description": "
|
|
6568
|
+
"description": "Resets one limit on a subject (`limitId`), or every limit on it (`{}`), at once: for goodwill, a promotion or support. The schedule doesn't move: the next reset is still the usual one. A balance goes back to its amount; a concurrent limit is skipped. Send an Idempotency-Key and a repeat resets once. Owners and admins only, for a person's token.",
|
|
6523
6569
|
"fields": [
|
|
6524
6570
|
{
|
|
6525
6571
|
"name": "subjectKind",
|
|
@@ -6551,7 +6597,7 @@ var OPERATIONS = [
|
|
|
6551
6597
|
"type": "string",
|
|
6552
6598
|
"required": false,
|
|
6553
6599
|
"description": "Just this limit. Default: every limit on the subject.",
|
|
6554
|
-
"example": "
|
|
6600
|
+
"example": "lmt_3f0c\u2026",
|
|
6555
6601
|
"schema": {
|
|
6556
6602
|
"type": "string",
|
|
6557
6603
|
"description": "Just this limit. Default: every limit on the subject."
|
|
@@ -6566,7 +6612,7 @@ var OPERATIONS = [
|
|
|
6566
6612
|
"operationId": "subjects.update",
|
|
6567
6613
|
"method": "patch",
|
|
6568
6614
|
"path": "/subjects/{subjectKind}/{subjectId}",
|
|
6569
|
-
"summary": "Set a subject's
|
|
6615
|
+
"summary": "Set a subject's billing date",
|
|
6570
6616
|
"cli": {
|
|
6571
6617
|
"command": "subjects update",
|
|
6572
6618
|
"args": [
|
|
@@ -6584,7 +6630,7 @@ var OPERATIONS = [
|
|
|
6584
6630
|
"idempotentHint": false
|
|
6585
6631
|
}
|
|
6586
6632
|
},
|
|
6587
|
-
"description": "Sets when a subject's `
|
|
6633
|
+
"description": "Sets when a subject's `billing_date` limits' periods start from: typically its subscription's start date, from your billing system's webhook, so its allowance resets on its own billing day (monthly for an annual plan, too). Owners and admins only, for a person's token.",
|
|
6588
6634
|
"fields": [
|
|
6589
6635
|
{
|
|
6590
6636
|
"name": "subjectKind",
|
|
@@ -6611,7 +6657,7 @@ var OPERATIONS = [
|
|
|
6611
6657
|
}
|
|
6612
6658
|
},
|
|
6613
6659
|
{
|
|
6614
|
-
"name": "
|
|
6660
|
+
"name": "billingDate",
|
|
6615
6661
|
"in": "body",
|
|
6616
6662
|
"type": "string",
|
|
6617
6663
|
"required": true,
|
|
@@ -6647,7 +6693,7 @@ var OPERATIONS = [
|
|
|
6647
6693
|
"idempotentHint": true
|
|
6648
6694
|
}
|
|
6649
6695
|
},
|
|
6650
|
-
"description": "Units used, checks allowed and
|
|
6696
|
+
"description": "Units used, checks allowed and refused for one limit \u2014 across all subjects, or one (`subject`, as `kind:id`) \u2014 per hour or per day (UTC), every bucket in the range included. Up to about a minute behind live checks. Default: the last 30 days, by day.",
|
|
6651
6697
|
"fields": [
|
|
6652
6698
|
{
|
|
6653
6699
|
"name": "limitId",
|
|
@@ -6655,34 +6701,24 @@ var OPERATIONS = [
|
|
|
6655
6701
|
"type": "string",
|
|
6656
6702
|
"required": true,
|
|
6657
6703
|
"description": "The limit.",
|
|
6658
|
-
"example": "
|
|
6704
|
+
"example": "lmt_3f0c\u2026",
|
|
6659
6705
|
"schema": {
|
|
6660
6706
|
"type": "string",
|
|
6661
6707
|
"description": "The limit."
|
|
6662
6708
|
}
|
|
6663
6709
|
},
|
|
6664
6710
|
{
|
|
6665
|
-
"name": "
|
|
6666
|
-
"in": "query",
|
|
6667
|
-
"type": "string",
|
|
6668
|
-
"required": false,
|
|
6669
|
-
"description": "With `subjectId`: one subject's usage, not every subject's.",
|
|
6670
|
-
"example": "user",
|
|
6671
|
-
"schema": {
|
|
6672
|
-
"type": "string",
|
|
6673
|
-
"description": "With `subjectId`: one subject's usage, not every subject's."
|
|
6674
|
-
}
|
|
6675
|
-
},
|
|
6676
|
-
{
|
|
6677
|
-
"name": "subjectId",
|
|
6711
|
+
"name": "subject",
|
|
6678
6712
|
"in": "query",
|
|
6679
6713
|
"type": "string",
|
|
6680
6714
|
"required": false,
|
|
6681
|
-
"description": "
|
|
6682
|
-
"example": "usr_123",
|
|
6715
|
+
"description": "One subject's usage, not every subject's, as `kind:id`.",
|
|
6716
|
+
"example": "user:usr_123",
|
|
6683
6717
|
"schema": {
|
|
6684
6718
|
"type": "string",
|
|
6685
|
-
"
|
|
6719
|
+
"minLength": 3,
|
|
6720
|
+
"maxLength": 301,
|
|
6721
|
+
"description": "One subject's usage, not every subject's, as `kind:id`."
|
|
6686
6722
|
}
|
|
6687
6723
|
},
|
|
6688
6724
|
{
|
|
@@ -6751,34 +6787,20 @@ var OPERATIONS = [
|
|
|
6751
6787
|
"idempotentHint": true
|
|
6752
6788
|
}
|
|
6753
6789
|
},
|
|
6754
|
-
"description": "Every enabled limit on one subject \u2014 and on its shared subjects (`shared`, comma-separated `kind:id`, such as `team:team_42`) \u2014 with what is used, what is left and when it resets, exact as of now. For showing an end user where they stand: call it from your server with your key, never from a browser. Not a check: nothing is counted. A subject with no limit here answers an empty `limits` list.",
|
|
6790
|
+
"description": "Every enabled limit on one subject (`subject`, as `kind:id`, such as `user:usr_123`) \u2014 and on its shared subjects (`shared`, comma-separated `kind:id`, such as `team:team_42`) \u2014 with what is used, what is left and when it resets, exact as of now. For showing an end user where they stand: call it from your server with your key, never from a browser. Not a check: nothing is counted. A subject with no limit here answers an empty `limits` list.",
|
|
6755
6791
|
"fields": [
|
|
6756
6792
|
{
|
|
6757
|
-
"name": "
|
|
6758
|
-
"in": "query",
|
|
6759
|
-
"type": "string",
|
|
6760
|
-
"required": true,
|
|
6761
|
-
"description": "The subject's kind, as your checks send it.",
|
|
6762
|
-
"example": "user",
|
|
6763
|
-
"schema": {
|
|
6764
|
-
"type": "string",
|
|
6765
|
-
"minLength": 1,
|
|
6766
|
-
"maxLength": 100,
|
|
6767
|
-
"description": "The subject's kind, as your checks send it."
|
|
6768
|
-
}
|
|
6769
|
-
},
|
|
6770
|
-
{
|
|
6771
|
-
"name": "id",
|
|
6793
|
+
"name": "subject",
|
|
6772
6794
|
"in": "query",
|
|
6773
6795
|
"type": "string",
|
|
6774
6796
|
"required": true,
|
|
6775
|
-
"description": "The subject
|
|
6776
|
-
"example": "usr_123",
|
|
6797
|
+
"description": "The subject, as `kind:id`: its kind and id as your checks send them.",
|
|
6798
|
+
"example": "user:usr_123",
|
|
6777
6799
|
"schema": {
|
|
6778
6800
|
"type": "string",
|
|
6779
|
-
"minLength":
|
|
6780
|
-
"maxLength":
|
|
6781
|
-
"description": "The subject
|
|
6801
|
+
"minLength": 3,
|
|
6802
|
+
"maxLength": 301,
|
|
6803
|
+
"description": "The subject, as `kind:id`: its kind and id as your checks send them."
|
|
6782
6804
|
}
|
|
6783
6805
|
},
|
|
6784
6806
|
{
|
|
@@ -6817,7 +6839,7 @@ var OPERATIONS = [
|
|
|
6817
6839
|
"idempotentHint": true
|
|
6818
6840
|
}
|
|
6819
6841
|
},
|
|
6820
|
-
"description": "A limit's subjects in its CURRENT window, most used first: units used, what is left, how many checks
|
|
6842
|
+
"description": "A limit's subjects in its CURRENT window, most used first: units used, what is left, and how many checks it refused. Up to about a minute behind live checks.",
|
|
6821
6843
|
"fields": [
|
|
6822
6844
|
{
|
|
6823
6845
|
"name": "limitId",
|
|
@@ -6825,7 +6847,7 @@ var OPERATIONS = [
|
|
|
6825
6847
|
"type": "string",
|
|
6826
6848
|
"required": true,
|
|
6827
6849
|
"description": "The limit.",
|
|
6828
|
-
"example": "
|
|
6850
|
+
"example": "lmt_3f0c\u2026",
|
|
6829
6851
|
"schema": {
|
|
6830
6852
|
"type": "string",
|
|
6831
6853
|
"description": "The limit."
|
|
@@ -7930,6 +7952,7 @@ A refusal exits 0: it's an answer. Errors exit 1.`
|
|
|
7930
7952
|
},
|
|
7931
7953
|
{ idempotencyKey: crypto.randomUUID() }
|
|
7932
7954
|
);
|
|
7955
|
+
if (!decision) throw new Error("Limitry answered without a decision");
|
|
7933
7956
|
ctx.io.stdout(options.json ? json(decision) : answer(decision));
|
|
7934
7957
|
}
|
|
7935
7958
|
);
|
|
@@ -7946,7 +7969,7 @@ function parseSubject(value) {
|
|
|
7946
7969
|
var left = (r) => `${r.name}: ${r.remaining} ${r.unit} left${r.resetsAt ? `, resets ${r.resetsAt}` : ""}`;
|
|
7947
7970
|
function answer(decision) {
|
|
7948
7971
|
if (decision.allowed) {
|
|
7949
|
-
return decision.
|
|
7972
|
+
return decision.limits.length === 0 ? "Allowed. No limit applies." : `Allowed. ${decision.limits.map(left).join("; ")}`;
|
|
7950
7973
|
}
|
|
7951
7974
|
return decision.reason?.message ?? "Refused.";
|
|
7952
7975
|
}
|
|
@@ -7955,7 +7978,9 @@ function answer(decision) {
|
|
|
7955
7978
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
7956
7979
|
import { resolve } from "node:path";
|
|
7957
7980
|
var limitsSyncCommand = (program2, ctx) => {
|
|
7958
|
-
const group = program2.commands.find((c) => c.name() === "limits") ?? program2.command("limits").description(
|
|
7981
|
+
const group = program2.commands.find((c) => c.name() === "limits") ?? program2.command("limits").description(
|
|
7982
|
+
"archive, create, credits, get, list, restore, sync, update"
|
|
7983
|
+
);
|
|
7959
7984
|
syncCommand(
|
|
7960
7985
|
group.command("sync"),
|
|
7961
7986
|
ctx,
|
|
@@ -7971,12 +7996,12 @@ Shortcut: \`${brand.name} sync\`, the same command.`
|
|
|
7971
7996
|
);
|
|
7972
7997
|
};
|
|
7973
7998
|
function syncCommand(command, ctx, description, more) {
|
|
7974
|
-
command.description(description).argument("[file]", "the file to read", "limitry.json").option("--
|
|
7999
|
+
command.description(description).argument("[file]", "the file to read", "limitry.json").option("--preview", "show what would change, and change nothing").option("--limits <json>", "the limits as a JSON array, instead of a file").option(
|
|
7975
8000
|
"--archive-missing",
|
|
7976
8001
|
"archive active limits the file doesn't name (restorable)"
|
|
7977
8002
|
).option("--workspace <slug>", "act in this workspace for one call").option("--json", "machine-readable output").addHelpText(
|
|
7978
8003
|
"after",
|
|
7979
|
-
'\nThe file: { "limits": [ { "name": "AI budget", "
|
|
8004
|
+
'\nThe file: { "limits": [ { "name": "AI budget", "subject": { "kind": "user" }, "action": "ai-call", "amount": 200, "unit": "cents", "window": "month" } ] }\nEach limit is described whole: a field left out is its default, as on `limits create`. Names are the key.\nWhat a limit counts (subject, action, unit, window, every, start, rolling) is fixed: to change it, give the entry a new name.' + more
|
|
7980
8005
|
).action(
|
|
7981
8006
|
async (file, options) => {
|
|
7982
8007
|
const limits = options.limits === void 0 ? readLimitsFile(file) : parseLimits(options.limits, "--limits");
|
|
@@ -7984,7 +8009,7 @@ function syncCommand(command, ctx, description, more) {
|
|
|
7984
8009
|
{
|
|
7985
8010
|
limits,
|
|
7986
8011
|
archiveMissing: options.archiveMissing ?? false,
|
|
7987
|
-
|
|
8012
|
+
preview: options.preview ?? false
|
|
7988
8013
|
},
|
|
7989
8014
|
{ idempotencyKey: crypto.randomUUID() }
|
|
7990
8015
|
);
|
|
@@ -8034,7 +8059,7 @@ function parseLimits(text, flag2) {
|
|
|
8034
8059
|
}
|
|
8035
8060
|
var show = (value) => typeof value === "string" ? value : JSON.stringify(value);
|
|
8036
8061
|
function summary(result) {
|
|
8037
|
-
const dry = result.
|
|
8062
|
+
const dry = result.preview;
|
|
8038
8063
|
const lines = [
|
|
8039
8064
|
...result.created.map(
|
|
8040
8065
|
(name) => `${dry ? "Would create" : "Created"}: ${name}`
|
|
@@ -8054,7 +8079,7 @@ function summary(result) {
|
|
|
8054
8079
|
];
|
|
8055
8080
|
}
|
|
8056
8081
|
if (same2 > 0) lines.push(`Unchanged: ${same2}`);
|
|
8057
|
-
if (dry) lines.push("
|
|
8082
|
+
if (dry) lines.push("Preview: nothing was changed.");
|
|
8058
8083
|
return lines;
|
|
8059
8084
|
}
|
|
8060
8085
|
|
|
@@ -8075,7 +8100,7 @@ function tokenEnvVar() {
|
|
|
8075
8100
|
function build(io) {
|
|
8076
8101
|
let actedIn = null;
|
|
8077
8102
|
let sending;
|
|
8078
|
-
const program2 = new Command().name(brand.name).description(`${brand.productName} command line`).version("1.0.0-rc.
|
|
8103
|
+
const program2 = new Command().name(brand.name).description(`${brand.productName} command line`).version("1.0.0-rc.9").addHelpText(
|
|
8079
8104
|
"after",
|
|
8080
8105
|
`
|
|
8081
8106
|
Token: \`${brand.name} login\` stores it in ~/.config/${brand.name}/; ${tokenEnvVar()} overrides.
|