@meshagent/meshagent 0.33.3 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/browser/memory-client.d.ts +200 -0
- package/dist/browser/memory-client.js +532 -6
- package/dist/browser/meshagent-client.d.ts +140 -0
- package/dist/browser/meshagent-client.js +406 -15
- package/dist/esm/memory-client.d.ts +200 -0
- package/dist/esm/memory-client.js +532 -6
- package/dist/esm/meshagent-client.d.ts +140 -0
- package/dist/esm/meshagent-client.js +406 -15
- package/dist/node/memory-client.d.ts +200 -0
- package/dist/node/memory-client.js +532 -6
- package/dist/node/meshagent-client.d.ts +140 -0
- package/dist/node/meshagent-client.js +406 -15
- package/package.json +1 -1
|
@@ -226,6 +226,29 @@ export interface KeysSecret extends BaseSecret {
|
|
|
226
226
|
data: Record<string, string>;
|
|
227
227
|
}
|
|
228
228
|
export type SecretLike = PullSecret | KeysSecret;
|
|
229
|
+
export interface ManagedSecretInfo {
|
|
230
|
+
id: string;
|
|
231
|
+
type: string;
|
|
232
|
+
name: string;
|
|
233
|
+
delegatedTo?: string | null;
|
|
234
|
+
}
|
|
235
|
+
export interface ManagedSecret extends ManagedSecretInfo {
|
|
236
|
+
dataBase64: string;
|
|
237
|
+
data: Uint8Array;
|
|
238
|
+
}
|
|
239
|
+
export interface ConnectorRef {
|
|
240
|
+
openaiConnectorId?: string | null;
|
|
241
|
+
serverUrl?: string | null;
|
|
242
|
+
clientSecretId?: string | null;
|
|
243
|
+
}
|
|
244
|
+
export interface ExternalOAuthClientRegistration {
|
|
245
|
+
id: string;
|
|
246
|
+
delegatedTo: string;
|
|
247
|
+
connector?: ConnectorRef | null;
|
|
248
|
+
oauth?: OAuthClientConfig | null;
|
|
249
|
+
clientId: string;
|
|
250
|
+
clientSecret?: string | null;
|
|
251
|
+
}
|
|
229
252
|
export declare class Meshagent {
|
|
230
253
|
private readonly baseUrl;
|
|
231
254
|
private readonly token?;
|
|
@@ -245,7 +268,13 @@ export declare class Meshagent {
|
|
|
245
268
|
private parseBalance;
|
|
246
269
|
private parseTransaction;
|
|
247
270
|
private parseSecret;
|
|
271
|
+
private parseManagedSecretInfo;
|
|
272
|
+
private parseManagedSecret;
|
|
273
|
+
private parseSecretPayload;
|
|
248
274
|
private toSecretPayload;
|
|
275
|
+
private parseConnectorRef;
|
|
276
|
+
private serializeConnectorRef;
|
|
277
|
+
private parseExternalOAuthClientRegistration;
|
|
249
278
|
private parseOAuthClient;
|
|
250
279
|
private parseRoomConnectionInfo;
|
|
251
280
|
private encodePathComponent;
|
|
@@ -359,10 +388,121 @@ export declare class Meshagent {
|
|
|
359
388
|
getService(projectId: string, serviceId: string): Promise<ServiceSpec>;
|
|
360
389
|
listServices(projectId: string): Promise<ServiceSpec[]>;
|
|
361
390
|
deleteService(projectId: string, serviceId: string): Promise<void>;
|
|
391
|
+
createProjectSecret(params: {
|
|
392
|
+
projectId: string;
|
|
393
|
+
name: string;
|
|
394
|
+
type: string;
|
|
395
|
+
data: Uint8Array | ArrayBuffer | Buffer;
|
|
396
|
+
}): Promise<string>;
|
|
397
|
+
updateProjectSecret(params: {
|
|
398
|
+
projectId: string;
|
|
399
|
+
secretId: string;
|
|
400
|
+
name: string;
|
|
401
|
+
type: string;
|
|
402
|
+
data: Uint8Array | ArrayBuffer | Buffer;
|
|
403
|
+
}): Promise<void>;
|
|
404
|
+
getProjectSecret(projectId: string, secretId: string): Promise<ManagedSecret>;
|
|
405
|
+
listProjectSecrets(projectId: string): Promise<ManagedSecretInfo[]>;
|
|
406
|
+
deleteProjectSecret(projectId: string, secretId: string): Promise<void>;
|
|
407
|
+
createRoomSecret(params: {
|
|
408
|
+
projectId: string;
|
|
409
|
+
roomName: string;
|
|
410
|
+
data: Uint8Array | ArrayBuffer | Buffer;
|
|
411
|
+
secretId?: string;
|
|
412
|
+
name?: string;
|
|
413
|
+
type?: string;
|
|
414
|
+
delegatedTo?: string;
|
|
415
|
+
forIdentity?: string;
|
|
416
|
+
}): Promise<string>;
|
|
417
|
+
updateRoomSecret(params: {
|
|
418
|
+
projectId: string;
|
|
419
|
+
roomName: string;
|
|
420
|
+
secretId: string;
|
|
421
|
+
data: Uint8Array | ArrayBuffer | Buffer;
|
|
422
|
+
name?: string;
|
|
423
|
+
type?: string;
|
|
424
|
+
delegatedTo?: string;
|
|
425
|
+
forIdentity?: string;
|
|
426
|
+
}): Promise<void>;
|
|
427
|
+
getRoomSecret(params: {
|
|
428
|
+
projectId: string;
|
|
429
|
+
roomName: string;
|
|
430
|
+
secretId: string;
|
|
431
|
+
delegatedTo?: string;
|
|
432
|
+
forIdentity?: string;
|
|
433
|
+
}): Promise<ManagedSecret>;
|
|
434
|
+
listRoomSecrets(params: {
|
|
435
|
+
projectId: string;
|
|
436
|
+
roomName: string;
|
|
437
|
+
forIdentity?: string;
|
|
438
|
+
}): Promise<ManagedSecretInfo[]>;
|
|
439
|
+
deleteRoomSecret(params: {
|
|
440
|
+
projectId: string;
|
|
441
|
+
roomName: string;
|
|
442
|
+
secretId: string;
|
|
443
|
+
delegatedTo?: string;
|
|
444
|
+
forIdentity?: string;
|
|
445
|
+
}): Promise<void>;
|
|
362
446
|
createSecret(projectId: string, secret: SecretLike): Promise<void>;
|
|
363
447
|
updateSecret(projectId: string, secret: SecretLike): Promise<void>;
|
|
364
448
|
deleteSecret(projectId: string, secretId: string): Promise<void>;
|
|
365
449
|
listSecrets(projectId: string): Promise<SecretLike[]>;
|
|
450
|
+
createProjectExternalOAuthRegistration(params: {
|
|
451
|
+
projectId: string;
|
|
452
|
+
oauth: OAuthClientConfig;
|
|
453
|
+
clientId: string;
|
|
454
|
+
clientSecret?: string | null;
|
|
455
|
+
delegatedTo?: string | null;
|
|
456
|
+
connector?: ConnectorRef | null;
|
|
457
|
+
}): Promise<string>;
|
|
458
|
+
updateProjectExternalOAuthRegistration(params: {
|
|
459
|
+
projectId: string;
|
|
460
|
+
registrationId: string;
|
|
461
|
+
oauth: OAuthClientConfig;
|
|
462
|
+
clientId: string;
|
|
463
|
+
clientSecret?: string | null;
|
|
464
|
+
delegatedTo?: string | null;
|
|
465
|
+
connector?: ConnectorRef | null;
|
|
466
|
+
}): Promise<void>;
|
|
467
|
+
listProjectExternalOAuthRegistrations(params: {
|
|
468
|
+
projectId: string;
|
|
469
|
+
delegatedTo?: string | null;
|
|
470
|
+
}): Promise<ExternalOAuthClientRegistration[]>;
|
|
471
|
+
deleteProjectExternalOAuthRegistration(params: {
|
|
472
|
+
projectId: string;
|
|
473
|
+
registrationId: string;
|
|
474
|
+
delegatedTo?: string | null;
|
|
475
|
+
}): Promise<void>;
|
|
476
|
+
createRoomExternalOAuthRegistration(params: {
|
|
477
|
+
projectId: string;
|
|
478
|
+
roomName: string;
|
|
479
|
+
oauth: OAuthClientConfig;
|
|
480
|
+
clientId: string;
|
|
481
|
+
clientSecret?: string | null;
|
|
482
|
+
delegatedTo?: string | null;
|
|
483
|
+
connector?: ConnectorRef | null;
|
|
484
|
+
}): Promise<string>;
|
|
485
|
+
updateRoomExternalOAuthRegistration(params: {
|
|
486
|
+
projectId: string;
|
|
487
|
+
roomName: string;
|
|
488
|
+
registrationId: string;
|
|
489
|
+
oauth: OAuthClientConfig;
|
|
490
|
+
clientId: string;
|
|
491
|
+
clientSecret?: string | null;
|
|
492
|
+
delegatedTo?: string | null;
|
|
493
|
+
connector?: ConnectorRef | null;
|
|
494
|
+
}): Promise<void>;
|
|
495
|
+
listRoomExternalOAuthRegistrations(params: {
|
|
496
|
+
projectId: string;
|
|
497
|
+
roomName: string;
|
|
498
|
+
delegatedTo?: string | null;
|
|
499
|
+
}): Promise<ExternalOAuthClientRegistration[]>;
|
|
500
|
+
deleteRoomExternalOAuthRegistration(params: {
|
|
501
|
+
projectId: string;
|
|
502
|
+
roomName: string;
|
|
503
|
+
registrationId: string;
|
|
504
|
+
delegatedTo?: string | null;
|
|
505
|
+
}): Promise<void>;
|
|
366
506
|
createRoom(params: {
|
|
367
507
|
projectId: string;
|
|
368
508
|
name: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { meshagentBaseUrl } from "./helpers";
|
|
2
2
|
import { RoomException } from "./requirement";
|
|
3
3
|
import { ApiScope } from "./participant-token";
|
|
4
|
+
import { decoder, encoder } from "./utils";
|
|
4
5
|
function pruneUndefinedValues(value) {
|
|
5
6
|
if (Array.isArray(value)) {
|
|
6
7
|
const prunedItems = value
|
|
@@ -41,6 +42,40 @@ function serializeServiceSpec(service) {
|
|
|
41
42
|
agents,
|
|
42
43
|
});
|
|
43
44
|
}
|
|
45
|
+
const globalScope = globalThis;
|
|
46
|
+
function bytesToBase64(bytes) {
|
|
47
|
+
if (globalScope.Buffer) {
|
|
48
|
+
return globalScope.Buffer.from(bytes).toString("base64");
|
|
49
|
+
}
|
|
50
|
+
if (!globalScope.btoa) {
|
|
51
|
+
throw new Error("base64 encoding is not available in this runtime");
|
|
52
|
+
}
|
|
53
|
+
let binary = "";
|
|
54
|
+
for (const byte of bytes) {
|
|
55
|
+
binary += String.fromCharCode(byte);
|
|
56
|
+
}
|
|
57
|
+
return globalScope.btoa(binary);
|
|
58
|
+
}
|
|
59
|
+
function base64ToBytes(base64) {
|
|
60
|
+
if (globalScope.Buffer) {
|
|
61
|
+
return Uint8Array.from(globalScope.Buffer.from(base64, "base64"));
|
|
62
|
+
}
|
|
63
|
+
if (!globalScope.atob) {
|
|
64
|
+
throw new Error("base64 decoding is not available in this runtime");
|
|
65
|
+
}
|
|
66
|
+
const binary = globalScope.atob(base64);
|
|
67
|
+
const bytes = new Uint8Array(binary.length);
|
|
68
|
+
for (let index = 0; index < binary.length; index += 1) {
|
|
69
|
+
bytes[index] = binary.charCodeAt(index);
|
|
70
|
+
}
|
|
71
|
+
return bytes;
|
|
72
|
+
}
|
|
73
|
+
function normalizeBinary(data) {
|
|
74
|
+
if (data instanceof Uint8Array) {
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
77
|
+
return new Uint8Array(data);
|
|
78
|
+
}
|
|
44
79
|
export class Meshagent {
|
|
45
80
|
constructor({ baseUrl, token } = {}) {
|
|
46
81
|
const resolvedBaseUrl = meshagentBaseUrl(baseUrl).replace(/\/+$/, "");
|
|
@@ -324,6 +359,75 @@ export class Meshagent {
|
|
|
324
359
|
}
|
|
325
360
|
throw new RoomException(`Unknown secret type: ${type}`);
|
|
326
361
|
}
|
|
362
|
+
parseManagedSecretInfo(data) {
|
|
363
|
+
if (!data || typeof data !== "object") {
|
|
364
|
+
throw new RoomException("Invalid managed secret payload");
|
|
365
|
+
}
|
|
366
|
+
const { id, type, name, delegated_to: delegatedToRaw, delegatedTo } = data;
|
|
367
|
+
if (typeof id !== "string" || typeof type !== "string" || typeof name !== "string") {
|
|
368
|
+
throw new RoomException("Invalid managed secret payload: missing id, type, or name");
|
|
369
|
+
}
|
|
370
|
+
const delegatedToValue = typeof delegatedTo === "string"
|
|
371
|
+
? delegatedTo
|
|
372
|
+
: typeof delegatedToRaw === "string"
|
|
373
|
+
? delegatedToRaw
|
|
374
|
+
: null;
|
|
375
|
+
return {
|
|
376
|
+
id,
|
|
377
|
+
type,
|
|
378
|
+
name,
|
|
379
|
+
delegatedTo: delegatedToValue,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
parseManagedSecret(data) {
|
|
383
|
+
const secret = this.parseManagedSecretInfo(data);
|
|
384
|
+
const dataBase64 = data.data_base64 ?? data.dataBase64;
|
|
385
|
+
if (typeof dataBase64 !== "string") {
|
|
386
|
+
throw new RoomException("Invalid managed secret payload: missing data_base64");
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
...secret,
|
|
390
|
+
dataBase64,
|
|
391
|
+
data: base64ToBytes(dataBase64),
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
parseSecretPayload(secret, rawData) {
|
|
395
|
+
let payload;
|
|
396
|
+
try {
|
|
397
|
+
payload = JSON.parse(decoder.decode(rawData));
|
|
398
|
+
}
|
|
399
|
+
catch {
|
|
400
|
+
throw new RoomException(`Invalid secret payload for ${secret.id}`);
|
|
401
|
+
}
|
|
402
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
403
|
+
throw new RoomException(`Invalid secret payload for ${secret.id}`);
|
|
404
|
+
}
|
|
405
|
+
if (secret.type === "docker") {
|
|
406
|
+
const { server, username, password, email } = payload;
|
|
407
|
+
if (typeof server !== "string" || typeof username !== "string" || typeof password !== "string") {
|
|
408
|
+
throw new RoomException(`Invalid secret payload for ${secret.id}`);
|
|
409
|
+
}
|
|
410
|
+
return {
|
|
411
|
+
id: secret.id,
|
|
412
|
+
name: secret.name,
|
|
413
|
+
type: "docker",
|
|
414
|
+
server,
|
|
415
|
+
username,
|
|
416
|
+
password,
|
|
417
|
+
email: typeof email === "string" ? email : "none@example.com",
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
const entries = Object.entries(payload);
|
|
421
|
+
if (entries.some(([, value]) => typeof value !== "string")) {
|
|
422
|
+
throw new RoomException(`Invalid secret payload for ${secret.id}`);
|
|
423
|
+
}
|
|
424
|
+
return {
|
|
425
|
+
id: secret.id,
|
|
426
|
+
name: secret.name,
|
|
427
|
+
type: "keys",
|
|
428
|
+
data: Object.fromEntries(entries),
|
|
429
|
+
};
|
|
430
|
+
}
|
|
327
431
|
toSecretPayload(secret) {
|
|
328
432
|
if (secret.type === "docker") {
|
|
329
433
|
return {
|
|
@@ -343,6 +447,68 @@ export class Meshagent {
|
|
|
343
447
|
data: { ...secret.data },
|
|
344
448
|
};
|
|
345
449
|
}
|
|
450
|
+
parseConnectorRef(data) {
|
|
451
|
+
if (data == null) {
|
|
452
|
+
return null;
|
|
453
|
+
}
|
|
454
|
+
if (typeof data !== "object") {
|
|
455
|
+
throw new RoomException("Invalid connector payload");
|
|
456
|
+
}
|
|
457
|
+
const { openai_connector_id: openaiConnectorIdRaw, openaiConnectorId, server_url: serverUrlRaw, serverUrl, client_secret_id: clientSecretIdRaw, clientSecretId, } = data;
|
|
458
|
+
return {
|
|
459
|
+
openaiConnectorId: typeof openaiConnectorId === "string"
|
|
460
|
+
? openaiConnectorId
|
|
461
|
+
: typeof openaiConnectorIdRaw === "string"
|
|
462
|
+
? openaiConnectorIdRaw
|
|
463
|
+
: null,
|
|
464
|
+
serverUrl: typeof serverUrl === "string"
|
|
465
|
+
? serverUrl
|
|
466
|
+
: typeof serverUrlRaw === "string"
|
|
467
|
+
? serverUrlRaw
|
|
468
|
+
: null,
|
|
469
|
+
clientSecretId: typeof clientSecretId === "string"
|
|
470
|
+
? clientSecretId
|
|
471
|
+
: typeof clientSecretIdRaw === "string"
|
|
472
|
+
? clientSecretIdRaw
|
|
473
|
+
: null,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
serializeConnectorRef(connector) {
|
|
477
|
+
if (connector == null) {
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
const payload = {};
|
|
481
|
+
if (connector.openaiConnectorId) {
|
|
482
|
+
payload.openai_connector_id = connector.openaiConnectorId;
|
|
483
|
+
}
|
|
484
|
+
if (connector.serverUrl) {
|
|
485
|
+
payload.server_url = connector.serverUrl;
|
|
486
|
+
}
|
|
487
|
+
if (connector.clientSecretId) {
|
|
488
|
+
payload.client_secret_id = connector.clientSecretId;
|
|
489
|
+
}
|
|
490
|
+
return payload;
|
|
491
|
+
}
|
|
492
|
+
parseExternalOAuthClientRegistration(data) {
|
|
493
|
+
if (!data || typeof data !== "object") {
|
|
494
|
+
throw new RoomException("Invalid external oauth registration payload");
|
|
495
|
+
}
|
|
496
|
+
const { id, delegated_to: delegatedToRaw, delegatedTo, connector, oauth, client_id: clientIdRaw, clientId, client_secret: clientSecretRaw, clientSecret, } = data;
|
|
497
|
+
const delegatedToValue = typeof delegatedTo === "string" ? delegatedTo : delegatedToRaw;
|
|
498
|
+
const clientIdValue = typeof clientId === "string" ? clientId : clientIdRaw;
|
|
499
|
+
const clientSecretValue = typeof clientSecret === "string" ? clientSecret : clientSecretRaw;
|
|
500
|
+
if (typeof id !== "string" || typeof delegatedToValue !== "string" || typeof clientIdValue !== "string") {
|
|
501
|
+
throw new RoomException("Invalid external oauth registration payload: missing fields");
|
|
502
|
+
}
|
|
503
|
+
return {
|
|
504
|
+
id,
|
|
505
|
+
delegatedTo: delegatedToValue,
|
|
506
|
+
connector: this.parseConnectorRef(connector),
|
|
507
|
+
oauth: oauth && typeof oauth === "object" ? oauth : null,
|
|
508
|
+
clientId: clientIdValue,
|
|
509
|
+
clientSecret: typeof clientSecretValue === "string" ? clientSecretValue : null,
|
|
510
|
+
};
|
|
511
|
+
}
|
|
346
512
|
parseOAuthClient(data) {
|
|
347
513
|
if (!data || typeof data !== "object") {
|
|
348
514
|
throw new RoomException("Invalid OAuth client payload");
|
|
@@ -821,38 +987,263 @@ export class Meshagent {
|
|
|
821
987
|
responseType: "void",
|
|
822
988
|
});
|
|
823
989
|
}
|
|
824
|
-
async
|
|
825
|
-
|
|
990
|
+
async createProjectSecret(params) {
|
|
991
|
+
const { projectId, name, type, data } = params;
|
|
992
|
+
const payload = await this.request(`/accounts/projects/${projectId}/secrets`, {
|
|
826
993
|
method: "POST",
|
|
827
|
-
json:
|
|
828
|
-
|
|
994
|
+
json: {
|
|
995
|
+
name,
|
|
996
|
+
type,
|
|
997
|
+
data_base64: bytesToBase64(normalizeBinary(data)),
|
|
998
|
+
},
|
|
999
|
+
action: "create project secret",
|
|
1000
|
+
});
|
|
1001
|
+
if (!payload || typeof payload !== "object" || typeof payload.id !== "string") {
|
|
1002
|
+
throw new RoomException("Invalid create project secret response payload");
|
|
1003
|
+
}
|
|
1004
|
+
return payload.id;
|
|
1005
|
+
}
|
|
1006
|
+
async updateProjectSecret(params) {
|
|
1007
|
+
const { projectId, secretId, name, type, data } = params;
|
|
1008
|
+
await this.request(`/accounts/projects/${projectId}/secrets/${secretId}`, {
|
|
1009
|
+
method: "PUT",
|
|
1010
|
+
json: {
|
|
1011
|
+
name,
|
|
1012
|
+
type,
|
|
1013
|
+
data_base64: bytesToBase64(normalizeBinary(data)),
|
|
1014
|
+
},
|
|
1015
|
+
action: "update project secret",
|
|
829
1016
|
responseType: "void",
|
|
830
1017
|
});
|
|
831
1018
|
}
|
|
1019
|
+
async getProjectSecret(projectId, secretId) {
|
|
1020
|
+
const data = await this.request(`/accounts/projects/${projectId}/secrets/${secretId}`, {
|
|
1021
|
+
action: "fetch project secret",
|
|
1022
|
+
});
|
|
1023
|
+
return this.parseManagedSecret(data);
|
|
1024
|
+
}
|
|
1025
|
+
async listProjectSecrets(projectId) {
|
|
1026
|
+
const data = await this.request(`/accounts/projects/${projectId}/secrets`, {
|
|
1027
|
+
action: "list project secrets",
|
|
1028
|
+
});
|
|
1029
|
+
const secrets = Array.isArray(data?.secrets) ? data.secrets : [];
|
|
1030
|
+
return secrets.map((item) => this.parseManagedSecretInfo(item));
|
|
1031
|
+
}
|
|
1032
|
+
async deleteProjectSecret(projectId, secretId) {
|
|
1033
|
+
await this.request(`/accounts/projects/${projectId}/secrets/${secretId}`, {
|
|
1034
|
+
method: "DELETE",
|
|
1035
|
+
action: "delete project secret",
|
|
1036
|
+
responseType: "void",
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
async createRoomSecret(params) {
|
|
1040
|
+
const { projectId, roomName, data, secretId, name, type, delegatedTo, forIdentity } = params;
|
|
1041
|
+
const payload = await this.request(`/accounts/projects/${projectId}/rooms/${roomName}/secrets`, {
|
|
1042
|
+
method: "POST",
|
|
1043
|
+
json: {
|
|
1044
|
+
data_base64: bytesToBase64(normalizeBinary(data)),
|
|
1045
|
+
secret_id: secretId,
|
|
1046
|
+
name,
|
|
1047
|
+
type,
|
|
1048
|
+
delegated_to: delegatedTo,
|
|
1049
|
+
for_identity: forIdentity,
|
|
1050
|
+
},
|
|
1051
|
+
action: "create room secret",
|
|
1052
|
+
});
|
|
1053
|
+
if (!payload || typeof payload !== "object" || typeof payload.id !== "string") {
|
|
1054
|
+
throw new RoomException("Invalid create room secret response payload");
|
|
1055
|
+
}
|
|
1056
|
+
return payload.id;
|
|
1057
|
+
}
|
|
1058
|
+
async updateRoomSecret(params) {
|
|
1059
|
+
const { projectId, roomName, secretId, data, name, type, delegatedTo, forIdentity } = params;
|
|
1060
|
+
await this.request(`/accounts/projects/${projectId}/rooms/${roomName}/secrets/${secretId}`, {
|
|
1061
|
+
method: "PUT",
|
|
1062
|
+
json: {
|
|
1063
|
+
data_base64: bytesToBase64(normalizeBinary(data)),
|
|
1064
|
+
name,
|
|
1065
|
+
type,
|
|
1066
|
+
delegated_to: delegatedTo,
|
|
1067
|
+
for_identity: forIdentity,
|
|
1068
|
+
},
|
|
1069
|
+
action: "update room secret",
|
|
1070
|
+
responseType: "void",
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
async getRoomSecret(params) {
|
|
1074
|
+
const { projectId, roomName, secretId, delegatedTo, forIdentity } = params;
|
|
1075
|
+
const data = await this.request(`/accounts/projects/${projectId}/rooms/${roomName}/secrets/${secretId}`, {
|
|
1076
|
+
query: {
|
|
1077
|
+
delegated_to: delegatedTo,
|
|
1078
|
+
for_identity: forIdentity,
|
|
1079
|
+
},
|
|
1080
|
+
action: "fetch room secret",
|
|
1081
|
+
});
|
|
1082
|
+
return this.parseManagedSecret(data);
|
|
1083
|
+
}
|
|
1084
|
+
async listRoomSecrets(params) {
|
|
1085
|
+
const { projectId, roomName, forIdentity } = params;
|
|
1086
|
+
const data = await this.request(`/accounts/projects/${projectId}/rooms/${roomName}/secrets`, {
|
|
1087
|
+
query: {
|
|
1088
|
+
for_identity: forIdentity,
|
|
1089
|
+
},
|
|
1090
|
+
action: "list room secrets",
|
|
1091
|
+
});
|
|
1092
|
+
const secrets = Array.isArray(data?.secrets) ? data.secrets : [];
|
|
1093
|
+
return secrets.map((item) => this.parseManagedSecretInfo(item));
|
|
1094
|
+
}
|
|
1095
|
+
async deleteRoomSecret(params) {
|
|
1096
|
+
const { projectId, roomName, secretId, delegatedTo, forIdentity } = params;
|
|
1097
|
+
await this.request(`/accounts/projects/${projectId}/rooms/${roomName}/secrets/${secretId}`, {
|
|
1098
|
+
method: "DELETE",
|
|
1099
|
+
query: {
|
|
1100
|
+
delegated_to: delegatedTo,
|
|
1101
|
+
for_identity: forIdentity,
|
|
1102
|
+
},
|
|
1103
|
+
action: "delete room secret",
|
|
1104
|
+
responseType: "void",
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
async createSecret(projectId, secret) {
|
|
1108
|
+
await this.createProjectSecret({
|
|
1109
|
+
projectId,
|
|
1110
|
+
name: secret.name,
|
|
1111
|
+
type: secret.type,
|
|
1112
|
+
data: encoder.encode(JSON.stringify(this.toSecretPayload(secret).data)),
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
832
1115
|
async updateSecret(projectId, secret) {
|
|
833
1116
|
if (!secret.id) {
|
|
834
1117
|
throw new RoomException("Secret id is required to update a secret");
|
|
835
1118
|
}
|
|
836
|
-
await this.
|
|
1119
|
+
await this.updateProjectSecret({
|
|
1120
|
+
projectId,
|
|
1121
|
+
secretId: secret.id,
|
|
1122
|
+
name: secret.name,
|
|
1123
|
+
type: secret.type,
|
|
1124
|
+
data: encoder.encode(JSON.stringify(this.toSecretPayload(secret).data)),
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
async deleteSecret(projectId, secretId) {
|
|
1128
|
+
await this.deleteProjectSecret(projectId, secretId);
|
|
1129
|
+
}
|
|
1130
|
+
async listSecrets(projectId) {
|
|
1131
|
+
const secretInfos = await this.listProjectSecrets(projectId);
|
|
1132
|
+
const secrets = await Promise.all(secretInfos.map(async (secretInfo) => {
|
|
1133
|
+
const secret = await this.getProjectSecret(projectId, secretInfo.id);
|
|
1134
|
+
return this.parseSecretPayload(secret, secret.data);
|
|
1135
|
+
}));
|
|
1136
|
+
return secrets;
|
|
1137
|
+
}
|
|
1138
|
+
async createProjectExternalOAuthRegistration(params) {
|
|
1139
|
+
const { projectId, oauth, clientId, clientSecret, delegatedTo, connector } = params;
|
|
1140
|
+
const payload = await this.request(`/accounts/projects/${projectId}/external-oauth`, {
|
|
1141
|
+
method: "POST",
|
|
1142
|
+
json: {
|
|
1143
|
+
oauth,
|
|
1144
|
+
client_id: clientId,
|
|
1145
|
+
client_secret: clientSecret,
|
|
1146
|
+
delegated_to: delegatedTo,
|
|
1147
|
+
connector: this.serializeConnectorRef(connector),
|
|
1148
|
+
},
|
|
1149
|
+
action: "create project external oauth registration",
|
|
1150
|
+
});
|
|
1151
|
+
if (!payload || typeof payload !== "object" || typeof payload.id !== "string") {
|
|
1152
|
+
throw new RoomException("Invalid create project external oauth registration response payload");
|
|
1153
|
+
}
|
|
1154
|
+
return payload.id;
|
|
1155
|
+
}
|
|
1156
|
+
async updateProjectExternalOAuthRegistration(params) {
|
|
1157
|
+
const { projectId, registrationId, oauth, clientId, clientSecret, delegatedTo, connector } = params;
|
|
1158
|
+
await this.request(`/accounts/projects/${projectId}/external-oauth/${registrationId}`, {
|
|
837
1159
|
method: "PUT",
|
|
838
|
-
json:
|
|
839
|
-
|
|
1160
|
+
json: {
|
|
1161
|
+
oauth,
|
|
1162
|
+
client_id: clientId,
|
|
1163
|
+
client_secret: clientSecret,
|
|
1164
|
+
delegated_to: delegatedTo,
|
|
1165
|
+
connector: this.serializeConnectorRef(connector),
|
|
1166
|
+
},
|
|
1167
|
+
action: "update project external oauth registration",
|
|
840
1168
|
responseType: "void",
|
|
841
1169
|
});
|
|
842
1170
|
}
|
|
843
|
-
async
|
|
844
|
-
|
|
1171
|
+
async listProjectExternalOAuthRegistrations(params) {
|
|
1172
|
+
const { projectId, delegatedTo } = params;
|
|
1173
|
+
const data = await this.request(`/accounts/projects/${projectId}/external-oauth`, {
|
|
1174
|
+
query: {
|
|
1175
|
+
delegated_to: delegatedTo,
|
|
1176
|
+
},
|
|
1177
|
+
action: "list project external oauth registrations",
|
|
1178
|
+
});
|
|
1179
|
+
const registrations = Array.isArray(data?.registrations) ? data.registrations : [];
|
|
1180
|
+
return registrations.map((item) => this.parseExternalOAuthClientRegistration(item));
|
|
1181
|
+
}
|
|
1182
|
+
async deleteProjectExternalOAuthRegistration(params) {
|
|
1183
|
+
const { projectId, registrationId, delegatedTo } = params;
|
|
1184
|
+
await this.request(`/accounts/projects/${projectId}/external-oauth/${registrationId}`, {
|
|
845
1185
|
method: "DELETE",
|
|
846
|
-
|
|
1186
|
+
query: {
|
|
1187
|
+
delegated_to: delegatedTo,
|
|
1188
|
+
},
|
|
1189
|
+
action: "delete project external oauth registration",
|
|
847
1190
|
responseType: "void",
|
|
848
1191
|
});
|
|
849
1192
|
}
|
|
850
|
-
async
|
|
851
|
-
const
|
|
852
|
-
|
|
1193
|
+
async createRoomExternalOAuthRegistration(params) {
|
|
1194
|
+
const { projectId, roomName, oauth, clientId, clientSecret, delegatedTo, connector } = params;
|
|
1195
|
+
const payload = await this.request(`/accounts/projects/${projectId}/rooms/${roomName}/external-oauth`, {
|
|
1196
|
+
method: "POST",
|
|
1197
|
+
json: {
|
|
1198
|
+
oauth,
|
|
1199
|
+
client_id: clientId,
|
|
1200
|
+
client_secret: clientSecret,
|
|
1201
|
+
delegated_to: delegatedTo,
|
|
1202
|
+
connector: this.serializeConnectorRef(connector),
|
|
1203
|
+
},
|
|
1204
|
+
action: "create room external oauth registration",
|
|
1205
|
+
});
|
|
1206
|
+
if (!payload || typeof payload !== "object" || typeof payload.id !== "string") {
|
|
1207
|
+
throw new RoomException("Invalid create room external oauth registration response payload");
|
|
1208
|
+
}
|
|
1209
|
+
return payload.id;
|
|
1210
|
+
}
|
|
1211
|
+
async updateRoomExternalOAuthRegistration(params) {
|
|
1212
|
+
const { projectId, roomName, registrationId, oauth, clientId, clientSecret, delegatedTo, connector } = params;
|
|
1213
|
+
await this.request(`/accounts/projects/${projectId}/rooms/${roomName}/external-oauth/${registrationId}`, {
|
|
1214
|
+
method: "PUT",
|
|
1215
|
+
json: {
|
|
1216
|
+
oauth,
|
|
1217
|
+
client_id: clientId,
|
|
1218
|
+
client_secret: clientSecret,
|
|
1219
|
+
delegated_to: delegatedTo,
|
|
1220
|
+
connector: this.serializeConnectorRef(connector),
|
|
1221
|
+
},
|
|
1222
|
+
action: "update room external oauth registration",
|
|
1223
|
+
responseType: "void",
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
async listRoomExternalOAuthRegistrations(params) {
|
|
1227
|
+
const { projectId, roomName, delegatedTo } = params;
|
|
1228
|
+
const data = await this.request(`/accounts/projects/${projectId}/rooms/${roomName}/external-oauth`, {
|
|
1229
|
+
query: {
|
|
1230
|
+
delegated_to: delegatedTo,
|
|
1231
|
+
},
|
|
1232
|
+
action: "list room external oauth registrations",
|
|
1233
|
+
});
|
|
1234
|
+
const registrations = Array.isArray(data?.registrations) ? data.registrations : [];
|
|
1235
|
+
return registrations.map((item) => this.parseExternalOAuthClientRegistration(item));
|
|
1236
|
+
}
|
|
1237
|
+
async deleteRoomExternalOAuthRegistration(params) {
|
|
1238
|
+
const { projectId, roomName, registrationId, delegatedTo } = params;
|
|
1239
|
+
await this.request(`/accounts/projects/${projectId}/rooms/${roomName}/external-oauth/${registrationId}`, {
|
|
1240
|
+
method: "DELETE",
|
|
1241
|
+
query: {
|
|
1242
|
+
delegated_to: delegatedTo,
|
|
1243
|
+
},
|
|
1244
|
+
action: "delete room external oauth registration",
|
|
1245
|
+
responseType: "void",
|
|
853
1246
|
});
|
|
854
|
-
const secrets = Array.isArray(data?.secrets) ? data.secrets : [];
|
|
855
|
-
return secrets.map((item) => this.parseSecret(item));
|
|
856
1247
|
}
|
|
857
1248
|
async createRoom(params) {
|
|
858
1249
|
const { projectId, name, ifNotExists = false, metadata, annotations, permissions } = params;
|