@r-33/opencode 0.4.7-rc.28 → 0.4.7-rc.30
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/dist/cli/production-smoke/production-smoke.js +381 -256
- package/dist/index.js +968 -506
- package/dist/tui-entry/index.js +2206 -1369
- package/dist/v2-entry/index.js +1032 -487
- package/package.json +4 -4
|
@@ -90,6 +90,146 @@ var parseManagementSubject = (credential) => {
|
|
|
90
90
|
return subject;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
+
// src/attribution/read-legacy-key/read-legacy-key.ts
|
|
94
|
+
import * as path from "node:path";
|
|
95
|
+
var LEGACY_KEY_RELATIVE_PATH = path.join(".opencode", "route33.key");
|
|
96
|
+
|
|
97
|
+
// src/attribution/parse-attribution/read-org-id/read-org-id.ts
|
|
98
|
+
var readOrgId = (value) => {
|
|
99
|
+
const orgId = value["orgId"];
|
|
100
|
+
if (orgId === void 0) {
|
|
101
|
+
return void 0;
|
|
102
|
+
}
|
|
103
|
+
if (typeof orgId !== "string") {
|
|
104
|
+
throw new ContractParseError("invalid attribution");
|
|
105
|
+
}
|
|
106
|
+
return orgId;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/attribution/parse-attribution/parse-attribution.ts
|
|
110
|
+
var parseAttribution = (value) => {
|
|
111
|
+
if (!isRecord(value)) {
|
|
112
|
+
throw new ContractParseError("invalid attribution");
|
|
113
|
+
}
|
|
114
|
+
const orgId = readOrgId(value);
|
|
115
|
+
const binding = (() => {
|
|
116
|
+
const { boundKeyId, boundScopeId } = value;
|
|
117
|
+
if (boundKeyId === void 0 && boundScopeId === void 0) return {};
|
|
118
|
+
if (typeof boundKeyId !== "string" || !boundKeyId)
|
|
119
|
+
throw new ContractParseError("invalid bound key id");
|
|
120
|
+
if (boundScopeId === void 0) return { boundKeyId };
|
|
121
|
+
if (typeof boundScopeId !== "string" || !/^[a-f0-9]{64}$/u.test(boundScopeId))
|
|
122
|
+
throw new ContractParseError("invalid bound scope id");
|
|
123
|
+
return { boundKeyId, boundScopeId };
|
|
124
|
+
})();
|
|
125
|
+
if (value["kind"] === "personal") {
|
|
126
|
+
return { ...binding, kind: "personal", orgId };
|
|
127
|
+
}
|
|
128
|
+
if (value["kind"] === "project" && typeof value["projectId"] === "string") {
|
|
129
|
+
return {
|
|
130
|
+
...binding,
|
|
131
|
+
kind: "project",
|
|
132
|
+
...orgId === void 0 ? {} : { orgId },
|
|
133
|
+
projectId: value["projectId"]
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
throw new ContractParseError("invalid attribution");
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// src/attribution/remove-legacy-key/remove-legacy-key.ts
|
|
140
|
+
import * as path2 from "node:path";
|
|
141
|
+
var LEGACY_KEY_RELATIVE_PATH2 = path2.join(".opencode", "route33.key");
|
|
142
|
+
|
|
143
|
+
// src/key-lease/lease-state/lease-state.ts
|
|
144
|
+
var LeaseState = class _LeaseState {
|
|
145
|
+
/** Current committed snapshot; mutation is limited to compare-and-swap transitions. */
|
|
146
|
+
#current;
|
|
147
|
+
constructor(current) {
|
|
148
|
+
this.#current = current;
|
|
149
|
+
}
|
|
150
|
+
/** Restores untrusted persisted metadata or an empty lease.
|
|
151
|
+
* @param value - Persisted metadata, or undefined for a new installation.
|
|
152
|
+
* @returns A lease-state coordinator.
|
|
153
|
+
*/
|
|
154
|
+
static restore(value) {
|
|
155
|
+
if (value === void 0) {
|
|
156
|
+
return new _LeaseState(void 0);
|
|
157
|
+
}
|
|
158
|
+
if (!isRecord(value)) {
|
|
159
|
+
throw new ContractParseError("invalid gateway key lease state");
|
|
160
|
+
}
|
|
161
|
+
const fields = Object.keys(value);
|
|
162
|
+
if (fields.some(
|
|
163
|
+
(field) => !["attribution", "expiresAt", "keyId", "wizardRequest"].includes(
|
|
164
|
+
field
|
|
165
|
+
)
|
|
166
|
+
)) {
|
|
167
|
+
throw new ContractParseError("invalid gateway key lease state");
|
|
168
|
+
}
|
|
169
|
+
const expiresAt = value["expiresAt"];
|
|
170
|
+
const keyId = value["keyId"];
|
|
171
|
+
const wizardRequest = value["wizardRequest"];
|
|
172
|
+
if (typeof expiresAt !== "string" || !Number.isFinite(Date.parse(expiresAt)) || typeof keyId !== "string" || keyId.length === 0 || wizardRequest !== void 0 && typeof wizardRequest !== "string") {
|
|
173
|
+
throw new ContractParseError("invalid gateway key lease state");
|
|
174
|
+
}
|
|
175
|
+
return new _LeaseState({
|
|
176
|
+
attribution: parseAttribution(value["attribution"]),
|
|
177
|
+
expiresAt,
|
|
178
|
+
keyId,
|
|
179
|
+
wizardRequest
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/** Reads the current non-secret metadata.
|
|
183
|
+
* @returns The current lease metadata, if one is committed.
|
|
184
|
+
*/
|
|
185
|
+
snapshot() {
|
|
186
|
+
return this.#current;
|
|
187
|
+
}
|
|
188
|
+
/** Checks whether current metadata belongs to an attribution.
|
|
189
|
+
* @param attribution - The requested ownership choice.
|
|
190
|
+
* @returns Whether the current lease has the same attribution.
|
|
191
|
+
*/
|
|
192
|
+
matchesAttribution(attribution) {
|
|
193
|
+
if (this.#current === void 0) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
switch (this.#current.attribution.kind) {
|
|
197
|
+
case "personal":
|
|
198
|
+
return attribution.kind === "personal";
|
|
199
|
+
case "project":
|
|
200
|
+
return attribution.kind === "project" && attribution.projectId === this.#current.attribution.projectId;
|
|
201
|
+
default:
|
|
202
|
+
return _LeaseState.#unexpectedAttribution(this.#current.attribution);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/** Atomically swaps metadata when the expected snapshot is still current.
|
|
206
|
+
* @param expected - Snapshot observed before asynchronous renewal.
|
|
207
|
+
* @param next - Fresh metadata to commit.
|
|
208
|
+
* @returns Whether the swap committed.
|
|
209
|
+
*/
|
|
210
|
+
compareAndSwap(expected, next) {
|
|
211
|
+
if (this.#current !== expected) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
this.#current = next;
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
/** Clears metadata only while the expected snapshot remains current.
|
|
218
|
+
* @param expected - Snapshot whose lease is being invalidated.
|
|
219
|
+
* @returns Whether the state was cleared.
|
|
220
|
+
*/
|
|
221
|
+
clear(expected) {
|
|
222
|
+
if (this.#current !== expected) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
this.#current = void 0;
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
static #unexpectedAttribution(value) {
|
|
229
|
+
throw new TypeError(`Unexpected attribution: ${String(value)}`);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
93
233
|
// src/key-lease/key-lease-error/key-lease-error.ts
|
|
94
234
|
var REDACTED_CAUSE = "Route 33 gateway key lease dependency failed";
|
|
95
235
|
var KeyLeaseError = class extends Error {
|
|
@@ -253,9 +393,35 @@ var buildMintInput = (deps) => {
|
|
|
253
393
|
};
|
|
254
394
|
};
|
|
255
395
|
|
|
396
|
+
// src/key-lease/commit-staged-replacement/commit-staged-replacement.ts
|
|
397
|
+
var commitStagedReplacement = async (stage, save, persist) => {
|
|
398
|
+
const storeFailure = (cause) => {
|
|
399
|
+
throw new KeyLeaseError("KEY_LEASE_STORE_UNAVAILABLE", { cause });
|
|
400
|
+
};
|
|
401
|
+
const staged = await stage().catch(storeFailure);
|
|
402
|
+
try {
|
|
403
|
+
save();
|
|
404
|
+
await (staged ? staged.commit() : persist()).catch(storeFailure);
|
|
405
|
+
} finally {
|
|
406
|
+
await staged?.discard();
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
|
|
256
410
|
// src/key-lease/mint-fresh-lease/mint-fresh-lease.ts
|
|
257
411
|
var mintFreshLease = async (deps) => {
|
|
258
412
|
const now = deps.clock();
|
|
413
|
+
const current = deps.state.snapshot();
|
|
414
|
+
const reusable = () => {
|
|
415
|
+
if (deps.wizardRequest !== void 0 && current?.wizardRequest === deps.wizardRequest && deps.storedKey !== void 0 && Date.parse(current.expiresAt) > now) {
|
|
416
|
+
return { key: deps.storedKey, lease: current };
|
|
417
|
+
}
|
|
418
|
+
return void 0;
|
|
419
|
+
};
|
|
420
|
+
const reused = reusable();
|
|
421
|
+
if (reused !== void 0) {
|
|
422
|
+
deps.saveAttribution?.();
|
|
423
|
+
return reused;
|
|
424
|
+
}
|
|
259
425
|
const input = buildMintInput({
|
|
260
426
|
attribution: deps.attribution,
|
|
261
427
|
extras: deps.extras,
|
|
@@ -278,13 +444,23 @@ var mintFreshLease = async (deps) => {
|
|
|
278
444
|
lease: {
|
|
279
445
|
attribution: deps.attribution,
|
|
280
446
|
expiresAt: material.expires_at,
|
|
281
|
-
keyId: material.id
|
|
447
|
+
keyId: material.id,
|
|
448
|
+
...deps.wizardRequest === void 0 ? {} : { wizardRequest: deps.wizardRequest }
|
|
282
449
|
}
|
|
283
450
|
};
|
|
284
|
-
|
|
285
|
-
await deps.secretStore.set(minted.key);
|
|
286
|
-
} catch (cause) {
|
|
451
|
+
const storeFailure = (cause) => {
|
|
287
452
|
throw new KeyLeaseError("KEY_LEASE_STORE_UNAVAILABLE", { cause });
|
|
453
|
+
};
|
|
454
|
+
const persist = () => deps.secretStore.set(minted.key, minted.lease);
|
|
455
|
+
if (deps.saveAttribution && deps.storedKey !== void 0) {
|
|
456
|
+
await commitStagedReplacement(
|
|
457
|
+
() => deps.secretStore.stage?.(minted.key, minted.lease) ?? Promise.resolve(void 0),
|
|
458
|
+
deps.saveAttribution,
|
|
459
|
+
persist
|
|
460
|
+
);
|
|
461
|
+
} else {
|
|
462
|
+
await persist().catch(storeFailure);
|
|
463
|
+
deps.saveAttribution?.();
|
|
288
464
|
}
|
|
289
465
|
deps.state.compareAndSwap(deps.state.snapshot(), minted.lease);
|
|
290
466
|
return minted;
|
|
@@ -461,7 +637,7 @@ var renewKey = async (options) => {
|
|
|
461
637
|
}
|
|
462
638
|
}
|
|
463
639
|
try {
|
|
464
|
-
await options.secretStore.set(renewed.key);
|
|
640
|
+
await options.secretStore.set(renewed.key, renewed.lease);
|
|
465
641
|
} catch (cause) {
|
|
466
642
|
const cleared = await discard(renewed.lease.keyId);
|
|
467
643
|
if (!cleared) {
|
|
@@ -581,7 +757,10 @@ var leaseForAttribution = async (options) => {
|
|
|
581
757
|
secretStore: options.installation.secretStore,
|
|
582
758
|
state: options.installation.state,
|
|
583
759
|
stateStore: options.installation.stateStore,
|
|
584
|
-
ttlMs: policy.ttlMs
|
|
760
|
+
ttlMs: policy.ttlMs,
|
|
761
|
+
wizardRequest: options.request.wizardRequest,
|
|
762
|
+
saveAttribution: options.request.saveAttribution,
|
|
763
|
+
storedKey
|
|
585
764
|
});
|
|
586
765
|
}
|
|
587
766
|
const reusable = reusableLease({
|
|
@@ -632,131 +811,6 @@ var leaseForAttribution = async (options) => {
|
|
|
632
811
|
}
|
|
633
812
|
};
|
|
634
813
|
|
|
635
|
-
// src/attribution/read-legacy-key/read-legacy-key.ts
|
|
636
|
-
import * as path from "node:path";
|
|
637
|
-
var LEGACY_KEY_RELATIVE_PATH = path.join(".opencode", "route33.key");
|
|
638
|
-
|
|
639
|
-
// src/attribution/parse-attribution/read-org-id/read-org-id.ts
|
|
640
|
-
var readOrgId = (value) => {
|
|
641
|
-
const orgId = value["orgId"];
|
|
642
|
-
if (orgId === void 0) {
|
|
643
|
-
return void 0;
|
|
644
|
-
}
|
|
645
|
-
if (typeof orgId !== "string") {
|
|
646
|
-
throw new ContractParseError("invalid attribution");
|
|
647
|
-
}
|
|
648
|
-
return orgId;
|
|
649
|
-
};
|
|
650
|
-
|
|
651
|
-
// src/attribution/parse-attribution/parse-attribution.ts
|
|
652
|
-
var parseAttribution = (value) => {
|
|
653
|
-
if (!isRecord(value)) {
|
|
654
|
-
throw new ContractParseError("invalid attribution");
|
|
655
|
-
}
|
|
656
|
-
const orgId = readOrgId(value);
|
|
657
|
-
if (value["kind"] === "personal") {
|
|
658
|
-
return { kind: "personal", ...orgId === void 0 ? {} : { orgId } };
|
|
659
|
-
}
|
|
660
|
-
if (value["kind"] === "project" && typeof value["projectId"] === "string") {
|
|
661
|
-
return {
|
|
662
|
-
kind: "project",
|
|
663
|
-
...orgId === void 0 ? {} : { orgId },
|
|
664
|
-
projectId: value["projectId"]
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
throw new ContractParseError("invalid attribution");
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
// src/attribution/remove-legacy-key/remove-legacy-key.ts
|
|
671
|
-
import * as path2 from "node:path";
|
|
672
|
-
var LEGACY_KEY_RELATIVE_PATH2 = path2.join(".opencode", "route33.key");
|
|
673
|
-
|
|
674
|
-
// src/key-lease/lease-state/lease-state.ts
|
|
675
|
-
var LeaseState = class _LeaseState {
|
|
676
|
-
/** Current committed snapshot; mutation is limited to compare-and-swap transitions. */
|
|
677
|
-
#current;
|
|
678
|
-
constructor(current) {
|
|
679
|
-
this.#current = current;
|
|
680
|
-
}
|
|
681
|
-
/** Restores untrusted persisted metadata or an empty lease.
|
|
682
|
-
* @param value - Persisted metadata, or undefined for a new installation.
|
|
683
|
-
* @returns A lease-state coordinator.
|
|
684
|
-
*/
|
|
685
|
-
static restore(value) {
|
|
686
|
-
if (value === void 0) {
|
|
687
|
-
return new _LeaseState(void 0);
|
|
688
|
-
}
|
|
689
|
-
if (!isRecord(value)) {
|
|
690
|
-
throw new ContractParseError("invalid gateway key lease state");
|
|
691
|
-
}
|
|
692
|
-
const fields = Object.keys(value);
|
|
693
|
-
if (fields.length !== 3 || fields.some(
|
|
694
|
-
(field) => field !== "attribution" && field !== "expiresAt" && field !== "keyId"
|
|
695
|
-
)) {
|
|
696
|
-
throw new ContractParseError("invalid gateway key lease state");
|
|
697
|
-
}
|
|
698
|
-
const expiresAt = value["expiresAt"];
|
|
699
|
-
const keyId = value["keyId"];
|
|
700
|
-
if (typeof expiresAt !== "string" || !Number.isFinite(Date.parse(expiresAt)) || typeof keyId !== "string" || keyId.length === 0) {
|
|
701
|
-
throw new ContractParseError("invalid gateway key lease state");
|
|
702
|
-
}
|
|
703
|
-
return new _LeaseState({
|
|
704
|
-
attribution: parseAttribution(value["attribution"]),
|
|
705
|
-
expiresAt,
|
|
706
|
-
keyId
|
|
707
|
-
});
|
|
708
|
-
}
|
|
709
|
-
/** Reads the current non-secret metadata.
|
|
710
|
-
* @returns The current lease metadata, if one is committed.
|
|
711
|
-
*/
|
|
712
|
-
snapshot() {
|
|
713
|
-
return this.#current;
|
|
714
|
-
}
|
|
715
|
-
/** Checks whether current metadata belongs to an attribution.
|
|
716
|
-
* @param attribution - The requested ownership choice.
|
|
717
|
-
* @returns Whether the current lease has the same attribution.
|
|
718
|
-
*/
|
|
719
|
-
matchesAttribution(attribution) {
|
|
720
|
-
if (this.#current === void 0) {
|
|
721
|
-
return false;
|
|
722
|
-
}
|
|
723
|
-
switch (this.#current.attribution.kind) {
|
|
724
|
-
case "personal":
|
|
725
|
-
return attribution.kind === "personal";
|
|
726
|
-
case "project":
|
|
727
|
-
return attribution.kind === "project" && attribution.projectId === this.#current.attribution.projectId;
|
|
728
|
-
default:
|
|
729
|
-
return _LeaseState.#unexpectedAttribution(this.#current.attribution);
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
/** Atomically swaps metadata when the expected snapshot is still current.
|
|
733
|
-
* @param expected - Snapshot observed before asynchronous renewal.
|
|
734
|
-
* @param next - Fresh metadata to commit.
|
|
735
|
-
* @returns Whether the swap committed.
|
|
736
|
-
*/
|
|
737
|
-
compareAndSwap(expected, next) {
|
|
738
|
-
if (this.#current !== expected) {
|
|
739
|
-
return false;
|
|
740
|
-
}
|
|
741
|
-
this.#current = next;
|
|
742
|
-
return true;
|
|
743
|
-
}
|
|
744
|
-
/** Clears metadata only while the expected snapshot remains current.
|
|
745
|
-
* @param expected - Snapshot whose lease is being invalidated.
|
|
746
|
-
* @returns Whether the state was cleared.
|
|
747
|
-
*/
|
|
748
|
-
clear(expected) {
|
|
749
|
-
if (this.#current !== expected) {
|
|
750
|
-
return false;
|
|
751
|
-
}
|
|
752
|
-
this.#current = void 0;
|
|
753
|
-
return true;
|
|
754
|
-
}
|
|
755
|
-
static #unexpectedAttribution(value) {
|
|
756
|
-
throw new TypeError(`Unexpected attribution: ${String(value)}`);
|
|
757
|
-
}
|
|
758
|
-
};
|
|
759
|
-
|
|
760
814
|
// src/management/drain-pages/drain-pages.ts
|
|
761
815
|
var drainPages = async (fetchPage) => {
|
|
762
816
|
const first = await fetchPage("");
|
|
@@ -770,12 +824,6 @@ var drainPages = async (fetchPage) => {
|
|
|
770
824
|
return { data, page: { ...page, has_more: false, next_cursor: null } };
|
|
771
825
|
};
|
|
772
826
|
|
|
773
|
-
// src/management/sdk-management-keys/sdk-management-keys.ts
|
|
774
|
-
import {
|
|
775
|
-
createRoute33Client,
|
|
776
|
-
Route33SdkError
|
|
777
|
-
} from "@r-33/sdk";
|
|
778
|
-
|
|
779
827
|
// src/contract/management-keys/parse-api-key/parse-api-key.ts
|
|
780
828
|
var parseApiKey = (value) => {
|
|
781
829
|
if (!isRecord(value) || !isOwnerType(value["ownership_type"]) || !isNullableString(value["project_id"])) {
|
|
@@ -801,6 +849,7 @@ var parseApiKey = (value) => {
|
|
|
801
849
|
name: field("name"),
|
|
802
850
|
org_id: field("org_id"),
|
|
803
851
|
ownership_type: value["ownership_type"],
|
|
852
|
+
...typeof value["owner_user_id"] === "string" ? { owner_user_id: value["owner_user_id"] } : {},
|
|
804
853
|
project_id: value["project_id"],
|
|
805
854
|
revoked: value["revoked"] === true,
|
|
806
855
|
status
|
|
@@ -1036,6 +1085,32 @@ var parseUserMemberships = (value) => {
|
|
|
1036
1085
|
};
|
|
1037
1086
|
};
|
|
1038
1087
|
|
|
1088
|
+
// src/management/key-read-operations/key-read-operations.ts
|
|
1089
|
+
var keyReadOperations = (call) => {
|
|
1090
|
+
const withCursor = (cursor) => ({ request }) => {
|
|
1091
|
+
const url = new URL(request.url);
|
|
1092
|
+
url.searchParams.set("cursor", cursor);
|
|
1093
|
+
return new Request(url, request);
|
|
1094
|
+
};
|
|
1095
|
+
return {
|
|
1096
|
+
get: async (accessToken, id, orgId) => parseApiKey(
|
|
1097
|
+
await call(
|
|
1098
|
+
accessToken,
|
|
1099
|
+
orgId,
|
|
1100
|
+
(client) => client.GET("/api/v1/api-keys/{api_key_id}", {
|
|
1101
|
+
params: { path: { api_key_id: id } }
|
|
1102
|
+
})
|
|
1103
|
+
)
|
|
1104
|
+
),
|
|
1105
|
+
list: (accessToken, orgId) => drainPages(
|
|
1106
|
+
(cursor) => call(accessToken, orgId, (client) => {
|
|
1107
|
+
if (cursor !== "") client.use({ onRequest: withCursor(cursor) });
|
|
1108
|
+
return client.GET("/api/v1/api-keys", {});
|
|
1109
|
+
}).then((page) => parseCollection(page, parseApiKey))
|
|
1110
|
+
)
|
|
1111
|
+
};
|
|
1112
|
+
};
|
|
1113
|
+
|
|
1039
1114
|
// src/management/sdk-management-keys/mint-request-body/mint-request-body.ts
|
|
1040
1115
|
var buildMintRequestBody = (input) => ({
|
|
1041
1116
|
...input.allowedModels === void 0 ? {} : { allowed_models: [...input.allowedModels] },
|
|
@@ -1049,10 +1124,134 @@ var buildMintRequestBody = (input) => ({
|
|
|
1049
1124
|
...input.projectId === null ? {} : { project_id: input.projectId }
|
|
1050
1125
|
});
|
|
1051
1126
|
|
|
1052
|
-
// src/management/
|
|
1127
|
+
// src/management/key-write-operations/key-write-operations.ts
|
|
1128
|
+
var keyWriteOperations = (call) => ({
|
|
1129
|
+
create: async (accessToken, input) => parseKeyMaterial(
|
|
1130
|
+
await call(
|
|
1131
|
+
accessToken,
|
|
1132
|
+
input.activeOrgId,
|
|
1133
|
+
(client) => client.POST("/api/v1/api-keys", {
|
|
1134
|
+
body: buildMintRequestBody(input)
|
|
1135
|
+
})
|
|
1136
|
+
)
|
|
1137
|
+
),
|
|
1138
|
+
delete: async (accessToken, id) => {
|
|
1139
|
+
await call(
|
|
1140
|
+
accessToken,
|
|
1141
|
+
void 0,
|
|
1142
|
+
(client) => client.DELETE("/api/v1/api-keys/{api_key_id}", {
|
|
1143
|
+
params: { path: { api_key_id: id } }
|
|
1144
|
+
})
|
|
1145
|
+
);
|
|
1146
|
+
},
|
|
1147
|
+
regenerate: async (accessToken, id, expiresAt, orgId) => parseKeyMaterial(
|
|
1148
|
+
await call(
|
|
1149
|
+
accessToken,
|
|
1150
|
+
orgId,
|
|
1151
|
+
(client) => client.POST("/api/v1/api-keys/{api_key_id}/secrets", {
|
|
1152
|
+
body: expiresAt === void 0 ? {} : { expires_at: expiresAt },
|
|
1153
|
+
params: { path: { api_key_id: id } }
|
|
1154
|
+
})
|
|
1155
|
+
)
|
|
1156
|
+
),
|
|
1157
|
+
update: async (accessToken, id, input) => parseApiKey(
|
|
1158
|
+
await call(
|
|
1159
|
+
accessToken,
|
|
1160
|
+
void 0,
|
|
1161
|
+
(client) => client.PATCH("/api/v1/api-keys/{api_key_id}", {
|
|
1162
|
+
body: {
|
|
1163
|
+
budget_currency: "EUR",
|
|
1164
|
+
...input.expiresAt === void 0 ? {} : { expires_at: input.expiresAt },
|
|
1165
|
+
...input.name === void 0 ? {} : { name: input.name }
|
|
1166
|
+
},
|
|
1167
|
+
params: { path: { api_key_id: id } }
|
|
1168
|
+
})
|
|
1169
|
+
)
|
|
1170
|
+
)
|
|
1171
|
+
});
|
|
1172
|
+
|
|
1173
|
+
// src/management/sdk-management-keys/exposed-catalog-ids/exposed-catalog-ids.ts
|
|
1174
|
+
var exposedCatalogIds = async (readPage) => {
|
|
1175
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1176
|
+
let offset = 0;
|
|
1177
|
+
for (; ; ) {
|
|
1178
|
+
const page = await readPage(offset);
|
|
1179
|
+
if (!isRecord(page) || !Array.isArray(page.models) || page.offset !== offset || typeof page.total !== "number" || !Number.isSafeInteger(page.total) || page.total < 0) {
|
|
1180
|
+
throw new ContractParseError("invalid model catalog page");
|
|
1181
|
+
}
|
|
1182
|
+
page.models.forEach((row) => {
|
|
1183
|
+
if (!isRecord(row) || typeof row.id !== "string" || !row.id.trim() || typeof row.status !== "string")
|
|
1184
|
+
throw new ContractParseError("invalid model catalog item");
|
|
1185
|
+
if (row.status === "exposed") ids.add(row.id);
|
|
1186
|
+
});
|
|
1187
|
+
offset += page.models.length;
|
|
1188
|
+
if (offset >= page.total || page.models.length === 0)
|
|
1189
|
+
return [...ids].sort((left, right) => left.localeCompare(right));
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
|
|
1193
|
+
// src/management/model-catalog-operations/model-catalog-operations.ts
|
|
1194
|
+
var modelCatalogOperations = (call) => ({
|
|
1195
|
+
listModelIds: (token, { orgId, projectId }) => exposedCatalogIds(
|
|
1196
|
+
(offset) => call(token, orgId, (client) => {
|
|
1197
|
+
const query = { offset };
|
|
1198
|
+
if (projectId !== void 0)
|
|
1199
|
+
return client.GET("/api/v1/projects/{project_id}/model-catalog", {
|
|
1200
|
+
params: { path: { project_id: projectId }, query }
|
|
1201
|
+
});
|
|
1202
|
+
if (orgId !== void 0)
|
|
1203
|
+
return client.GET("/api/v1/orgs/{org_id}/model-catalog", {
|
|
1204
|
+
params: { path: { org_id: orgId }, query }
|
|
1205
|
+
});
|
|
1206
|
+
return client.GET("/api/v1/model-catalog", { params: { query } });
|
|
1207
|
+
})
|
|
1208
|
+
)
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1211
|
+
// src/management/list-sdk-projects/list-sdk-projects.ts
|
|
1212
|
+
var listSdkProjects = async (accessToken, organisationId, call) => {
|
|
1213
|
+
if (organisationId.trim().length === 0) {
|
|
1214
|
+
throw new ManagementError("MANAGEMENT_ORGANISATION_ID_REQUIRED", {
|
|
1215
|
+
statusCode: 400
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
const query = {
|
|
1219
|
+
member_user_id: parseManagementSubject(accessToken),
|
|
1220
|
+
org_id: organisationId
|
|
1221
|
+
};
|
|
1222
|
+
const fetchPage = (cursor) => call(
|
|
1223
|
+
accessToken,
|
|
1224
|
+
void 0,
|
|
1225
|
+
(client) => client.GET("/api/v1/projects", {
|
|
1226
|
+
params: {
|
|
1227
|
+
query: cursor === "" ? query : { ...query, cursor }
|
|
1228
|
+
}
|
|
1229
|
+
})
|
|
1230
|
+
).then((page) => parseCollection(page, parseProject));
|
|
1231
|
+
return drainPages(fetchPage);
|
|
1232
|
+
};
|
|
1233
|
+
|
|
1234
|
+
// src/management/organization-operations/organization-operations.ts
|
|
1235
|
+
var organizationOperations = (call) => ({
|
|
1236
|
+
listOrganizations: async (accessToken) => parseCollection(
|
|
1237
|
+
await call(
|
|
1238
|
+
accessToken,
|
|
1239
|
+
void 0,
|
|
1240
|
+
(client) => client.GET("/api/v1/orgs", {})
|
|
1241
|
+
),
|
|
1242
|
+
parseOrganization
|
|
1243
|
+
),
|
|
1244
|
+
listProjects: (accessToken, organisationId) => listSdkProjects(accessToken, organisationId, call)
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
// src/management/sdk-management-call/sdk-management-call.ts
|
|
1248
|
+
import {
|
|
1249
|
+
createRoute33Client,
|
|
1250
|
+
Route33SdkError
|
|
1251
|
+
} from "@r-33/sdk";
|
|
1053
1252
|
var API_PREFIX_PATTERN = /\/api\/v1\/?$/;
|
|
1054
1253
|
var ACTIVE_ORG_HEADER = "X-Active-Org-Id";
|
|
1055
|
-
var
|
|
1254
|
+
var createSdkCall = (options) => {
|
|
1056
1255
|
const baseUrl = options.apiBaseUrl.replace(API_PREFIX_PATTERN, "");
|
|
1057
1256
|
const timeoutMs = options.timeoutMs ?? 1e4;
|
|
1058
1257
|
const fetchImpl = options.fetchImpl;
|
|
@@ -1091,7 +1290,7 @@ var sdkManagementKeys = (options) => {
|
|
|
1091
1290
|
}
|
|
1092
1291
|
return new ManagementError("MANAGEMENT_NETWORK_ERROR", { cause });
|
|
1093
1292
|
};
|
|
1094
|
-
|
|
1293
|
+
return async (accessToken, activeOrgId, run) => {
|
|
1095
1294
|
try {
|
|
1096
1295
|
const outcome = await run(callClient(accessToken, activeOrgId));
|
|
1097
1296
|
const code = outcome.response?.status;
|
|
@@ -1106,123 +1305,49 @@ var sdkManagementKeys = (options) => {
|
|
|
1106
1305
|
throw mapFailure(cause);
|
|
1107
1306
|
}
|
|
1108
1307
|
};
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
)
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
)
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
await call(
|
|
1130
|
-
accessToken,
|
|
1131
|
-
void 0,
|
|
1132
|
-
(client) => client.GET("/api/v1/api-keys/{api_key_id}", {
|
|
1133
|
-
params: { path: { api_key_id: id } }
|
|
1134
|
-
})
|
|
1135
|
-
)
|
|
1136
|
-
),
|
|
1137
|
-
list: async (accessToken) => parseCollection(
|
|
1138
|
-
await call(
|
|
1139
|
-
accessToken,
|
|
1140
|
-
void 0,
|
|
1141
|
-
(client) => client.GET("/api/v1/api-keys", {})
|
|
1142
|
-
),
|
|
1143
|
-
parseApiKey
|
|
1144
|
-
),
|
|
1145
|
-
listOrganizations: async (accessToken) => parseCollection(
|
|
1146
|
-
await call(
|
|
1147
|
-
accessToken,
|
|
1148
|
-
void 0,
|
|
1149
|
-
(client) => client.GET("/api/v1/orgs", {})
|
|
1150
|
-
),
|
|
1151
|
-
parseOrganization
|
|
1152
|
-
),
|
|
1153
|
-
listMemberships: async (accessToken, userId) => parseUserMemberships(
|
|
1154
|
-
await call(
|
|
1155
|
-
accessToken,
|
|
1156
|
-
void 0,
|
|
1157
|
-
(client) => client.GET("/api/v1/users/{user_id}/memberships", {
|
|
1158
|
-
params: { path: { user_id: userId } }
|
|
1159
|
-
})
|
|
1160
|
-
)
|
|
1161
|
-
),
|
|
1162
|
-
listBudgetPolicy: async (accessToken, userId, activeOrgId) => parseBudgetPolicy(
|
|
1163
|
-
await call(
|
|
1164
|
-
accessToken,
|
|
1165
|
-
activeOrgId,
|
|
1166
|
-
(client) => client.GET("/api/v1/users/{user_id}/budget-policy", {
|
|
1167
|
-
params: { path: { user_id: userId } }
|
|
1168
|
-
})
|
|
1169
|
-
)
|
|
1170
|
-
),
|
|
1171
|
-
listProjectBudgets: async (accessToken, userId, activeOrgId) => parseCollection(
|
|
1172
|
-
await call(
|
|
1173
|
-
accessToken,
|
|
1174
|
-
activeOrgId,
|
|
1175
|
-
(client) => client.GET("/api/v1/users/{user_id}/project-budgets", {
|
|
1176
|
-
params: { path: { user_id: userId } }
|
|
1177
|
-
})
|
|
1178
|
-
),
|
|
1179
|
-
parseProjectBudgetState
|
|
1180
|
-
),
|
|
1181
|
-
listProjects: async (accessToken, organisationId) => {
|
|
1182
|
-
if (organisationId.trim().length === 0) {
|
|
1183
|
-
throw new ManagementError("MANAGEMENT_ORGANISATION_ID_REQUIRED", {
|
|
1184
|
-
statusCode: 400
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
const query = {
|
|
1188
|
-
member_user_id: parseManagementSubject(accessToken),
|
|
1189
|
-
org_id: organisationId
|
|
1190
|
-
};
|
|
1191
|
-
const fetchPage = (cursor) => call(
|
|
1192
|
-
accessToken,
|
|
1193
|
-
void 0,
|
|
1194
|
-
(client) => client.GET("/api/v1/projects", {
|
|
1195
|
-
params: {
|
|
1196
|
-
query: cursor === "" ? query : { ...query, cursor }
|
|
1197
|
-
}
|
|
1198
|
-
})
|
|
1199
|
-
).then((page) => parseCollection(page, parseProject));
|
|
1200
|
-
return drainPages(fetchPage);
|
|
1201
|
-
},
|
|
1202
|
-
regenerate: async (accessToken, id, expiresAt) => parseKeyMaterial(
|
|
1203
|
-
await call(
|
|
1204
|
-
accessToken,
|
|
1205
|
-
void 0,
|
|
1206
|
-
(client) => client.POST("/api/v1/api-keys/{api_key_id}/secrets", {
|
|
1207
|
-
body: expiresAt === void 0 ? {} : { expires_at: expiresAt },
|
|
1208
|
-
params: { path: { api_key_id: id } }
|
|
1209
|
-
})
|
|
1210
|
-
)
|
|
1211
|
-
),
|
|
1212
|
-
update: async (accessToken, id, input) => parseApiKey(
|
|
1213
|
-
await call(
|
|
1214
|
-
accessToken,
|
|
1215
|
-
void 0,
|
|
1216
|
-
(client) => client.PATCH("/api/v1/api-keys/{api_key_id}", {
|
|
1217
|
-
body: {
|
|
1218
|
-
budget_currency: "EUR",
|
|
1219
|
-
...input.expiresAt === void 0 ? {} : { expires_at: input.expiresAt },
|
|
1220
|
-
...input.name === void 0 ? {} : { name: input.name }
|
|
1221
|
-
},
|
|
1222
|
-
params: { path: { api_key_id: id } }
|
|
1223
|
-
})
|
|
1224
|
-
)
|
|
1308
|
+
};
|
|
1309
|
+
|
|
1310
|
+
// src/management/user-context-operations/user-context-operations.ts
|
|
1311
|
+
var userContextOperations = (call) => ({
|
|
1312
|
+
listMemberships: async (accessToken, userId) => parseUserMemberships(
|
|
1313
|
+
await call(
|
|
1314
|
+
accessToken,
|
|
1315
|
+
void 0,
|
|
1316
|
+
(client) => client.GET("/api/v1/users/{user_id}/memberships", {
|
|
1317
|
+
params: { path: { user_id: userId } }
|
|
1318
|
+
})
|
|
1319
|
+
)
|
|
1320
|
+
),
|
|
1321
|
+
listBudgetPolicy: async (accessToken, userId, activeOrgId) => parseBudgetPolicy(
|
|
1322
|
+
await call(
|
|
1323
|
+
accessToken,
|
|
1324
|
+
activeOrgId,
|
|
1325
|
+
(client) => client.GET("/api/v1/users/{user_id}/budget-policy", {
|
|
1326
|
+
params: { path: { user_id: userId } }
|
|
1327
|
+
})
|
|
1225
1328
|
)
|
|
1329
|
+
),
|
|
1330
|
+
listProjectBudgets: async (accessToken, userId, activeOrgId) => parseCollection(
|
|
1331
|
+
await call(
|
|
1332
|
+
accessToken,
|
|
1333
|
+
activeOrgId,
|
|
1334
|
+
(client) => client.GET("/api/v1/users/{user_id}/project-budgets", {
|
|
1335
|
+
params: { path: { user_id: userId } }
|
|
1336
|
+
})
|
|
1337
|
+
),
|
|
1338
|
+
parseProjectBudgetState
|
|
1339
|
+
)
|
|
1340
|
+
});
|
|
1341
|
+
|
|
1342
|
+
// src/management/sdk-management-keys/sdk-management-keys.ts
|
|
1343
|
+
var sdkManagementKeys = (options) => {
|
|
1344
|
+
const call = createSdkCall(options);
|
|
1345
|
+
return {
|
|
1346
|
+
...keyReadOperations(call),
|
|
1347
|
+
...keyWriteOperations(call),
|
|
1348
|
+
...modelCatalogOperations(call),
|
|
1349
|
+
...organizationOperations(call),
|
|
1350
|
+
...userContextOperations(call)
|
|
1226
1351
|
};
|
|
1227
1352
|
};
|
|
1228
1353
|
|