@eide/foir-cli 0.3.0 → 0.3.2
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.js +2324 -82
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -345,12 +345,14 @@ async function loginAction(globalOpts) {
|
|
|
345
345
|
const port = await findAvailablePort(9876, 9900);
|
|
346
346
|
const redirectUri = `http://localhost:${port}/callback`;
|
|
347
347
|
const authCode = await new Promise((resolve7, reject) => {
|
|
348
|
+
let timeoutId;
|
|
348
349
|
const server = http.createServer((req, res) => {
|
|
349
350
|
const url = new URL(req.url, `http://localhost:${port}`);
|
|
350
351
|
if (url.pathname === "/callback") {
|
|
351
352
|
const code = url.searchParams.get("code");
|
|
352
353
|
const returnedState = url.searchParams.get("state");
|
|
353
354
|
const error = url.searchParams.get("error");
|
|
355
|
+
clearTimeout(timeoutId);
|
|
354
356
|
if (error) {
|
|
355
357
|
res.writeHead(400, { "Content-Type": "text/html" });
|
|
356
358
|
res.end(
|
|
@@ -372,16 +374,20 @@ async function loginAction(globalOpts) {
|
|
|
372
374
|
const apiHost = new URL(apiUrl).host;
|
|
373
375
|
const mainHost = apiHost.replace(/^api\./, "");
|
|
374
376
|
const mainUrl = `https://${mainHost}`;
|
|
375
|
-
res.writeHead(200, {
|
|
377
|
+
res.writeHead(200, {
|
|
378
|
+
"Content-Type": "text/html",
|
|
379
|
+
"Connection": "close"
|
|
380
|
+
});
|
|
376
381
|
res.end(
|
|
377
382
|
`<html><head><meta http-equiv="refresh" content="2;url=${mainUrl}"></head><body style="font-family:system-ui;text-align:center;padding:50px"><h1>Authentication successful!</h1><p>You can close this window.</p></body></html>`
|
|
378
383
|
);
|
|
384
|
+
server.closeAllConnections();
|
|
379
385
|
server.close();
|
|
380
386
|
resolve7(code);
|
|
381
387
|
}
|
|
382
388
|
});
|
|
383
389
|
server.listen(port);
|
|
384
|
-
setTimeout(
|
|
390
|
+
timeoutId = setTimeout(
|
|
385
391
|
() => {
|
|
386
392
|
server.close();
|
|
387
393
|
reject(new Error("Authentication timed out after 5 minutes"));
|
|
@@ -416,58 +422,2271 @@ async function loginAction(globalOpts) {
|
|
|
416
422
|
expiresAt: new Date(Date.now() + tokens.expiresIn * 1e3).toISOString(),
|
|
417
423
|
user: tokens.user
|
|
418
424
|
};
|
|
419
|
-
await writeCredentials(credentials);
|
|
420
|
-
console.log(`
|
|
421
|
-
\u2713 Logged in as ${tokens.user.email}`);
|
|
422
|
-
console.log("\nRun `foir select-project` to choose a project.");
|
|
425
|
+
await writeCredentials(credentials);
|
|
426
|
+
console.log(`
|
|
427
|
+
\u2713 Logged in as ${tokens.user.email}`);
|
|
428
|
+
console.log("\nRun `foir select-project` to choose a project.");
|
|
429
|
+
}
|
|
430
|
+
function registerLoginCommand(program2, globalOpts) {
|
|
431
|
+
program2.command("login").description("Authenticate via browser OAuth").action(
|
|
432
|
+
withErrorHandler(globalOpts, async () => {
|
|
433
|
+
await loginAction(globalOpts());
|
|
434
|
+
})
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// src/commands/logout.ts
|
|
439
|
+
function registerLogoutCommand(program2, globalOpts) {
|
|
440
|
+
program2.command("logout").description("Clear stored credentials").action(
|
|
441
|
+
withErrorHandler(globalOpts, async () => {
|
|
442
|
+
const credentials = await getCredentials();
|
|
443
|
+
if (!credentials) {
|
|
444
|
+
console.log("Not logged in.");
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
await deleteCredentials();
|
|
448
|
+
console.log(`\u2713 Logged out (was ${credentials.user.email})`);
|
|
449
|
+
})
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// src/commands/select-project.ts
|
|
454
|
+
import inquirer from "inquirer";
|
|
455
|
+
|
|
456
|
+
// src/lib/client.ts
|
|
457
|
+
import { createClient as createRpcClient } from "@connectrpc/connect";
|
|
458
|
+
import { createConnectTransport } from "@connectrpc/connect-node";
|
|
459
|
+
import { IdentityService as IdentityService2 } from "@eide/foir-proto-ts/identity/v1/identity_pb";
|
|
460
|
+
import { ModelsService as ModelsService2 } from "@eide/foir-proto-ts/models/v1/models_pb";
|
|
461
|
+
import { RecordsService as RecordsService2 } from "@eide/foir-proto-ts/records/v1/records_pb";
|
|
462
|
+
import { ConfigsService as ConfigsService2 } from "@eide/foir-proto-ts/configs/v1/configs_pb";
|
|
463
|
+
import { SegmentsService as SegmentsService2 } from "@eide/foir-proto-ts/segments/v1/segments_pb";
|
|
464
|
+
import { ExperimentsService as ExperimentsService2 } from "@eide/foir-proto-ts/experiments/v1/experiments_pb";
|
|
465
|
+
import { SettingsService as SettingsService2 } from "@eide/foir-proto-ts/settings/v1/settings_pb";
|
|
466
|
+
import { StorageService as StorageService2 } from "@eide/foir-proto-ts/storage/v1/storage_pb";
|
|
467
|
+
|
|
468
|
+
// src/lib/rpc/identity.ts
|
|
469
|
+
import { create } from "@bufbuild/protobuf";
|
|
470
|
+
import {
|
|
471
|
+
LoginRequestSchema,
|
|
472
|
+
LoginWithOTPRequestSchema,
|
|
473
|
+
RequestOTPRequestSchema,
|
|
474
|
+
LogoutRequestSchema,
|
|
475
|
+
GetMeRequestSchema,
|
|
476
|
+
GetSessionContextRequestSchema,
|
|
477
|
+
SwitchTenantRequestSchema,
|
|
478
|
+
SwitchProjectRequestSchema,
|
|
479
|
+
ClearSessionContextRequestSchema,
|
|
480
|
+
RefreshTokenRequestSchema,
|
|
481
|
+
RegisterRequestSchema,
|
|
482
|
+
VerifyEmailRequestSchema,
|
|
483
|
+
ResendVerificationEmailRequestSchema,
|
|
484
|
+
UpdatePasswordRequestSchema,
|
|
485
|
+
RequestPasswordResetRequestSchema,
|
|
486
|
+
ResetPasswordRequestSchema,
|
|
487
|
+
SendEmailVerificationCodeRequestSchema,
|
|
488
|
+
VerifyEmailCodeRequestSchema,
|
|
489
|
+
CreateAdminUserRequestSchema,
|
|
490
|
+
GetAdminUserRequestSchema,
|
|
491
|
+
UpdateAdminUserRequestSchema,
|
|
492
|
+
ListAdminUsersRequestSchema,
|
|
493
|
+
GrantAccessRequestSchema,
|
|
494
|
+
RevokeAccessRequestSchema,
|
|
495
|
+
CreateCustomerRequestSchema,
|
|
496
|
+
GetCustomerRequestSchema,
|
|
497
|
+
UpdateCustomerRequestSchema,
|
|
498
|
+
DeleteCustomerRequestSchema,
|
|
499
|
+
ListCustomersRequestSchema,
|
|
500
|
+
SuspendCustomerRequestSchema,
|
|
501
|
+
CreateTenantRequestSchema,
|
|
502
|
+
GetTenantRequestSchema,
|
|
503
|
+
UpdateTenantRequestSchema,
|
|
504
|
+
ListTenantsRequestSchema,
|
|
505
|
+
DeleteTenantRequestSchema,
|
|
506
|
+
CreateProjectRequestSchema,
|
|
507
|
+
GetProjectRequestSchema,
|
|
508
|
+
UpdateProjectRequestSchema,
|
|
509
|
+
ListProjectsRequestSchema,
|
|
510
|
+
DeleteProjectRequestSchema,
|
|
511
|
+
GetDefaultProjectRequestSchema,
|
|
512
|
+
SetDefaultProjectRequestSchema,
|
|
513
|
+
CreateInvitationRequestSchema,
|
|
514
|
+
ListInvitationsRequestSchema,
|
|
515
|
+
RevokeInvitationRequestSchema,
|
|
516
|
+
AcceptInvitationRequestSchema,
|
|
517
|
+
ValidateInvitationRequestSchema,
|
|
518
|
+
CreateApiKeyRequestSchema,
|
|
519
|
+
GetApiKeyRequestSchema,
|
|
520
|
+
ListApiKeysRequestSchema,
|
|
521
|
+
UpdateApiKeyRequestSchema,
|
|
522
|
+
RotateApiKeyRequestSchema,
|
|
523
|
+
RevokeApiKeyRequestSchema,
|
|
524
|
+
MintServiceTokenRequestSchema,
|
|
525
|
+
ListAuthProvidersRequestSchema,
|
|
526
|
+
GetAuthProviderRequestSchema,
|
|
527
|
+
CreateAuthProviderRequestSchema,
|
|
528
|
+
UpdateAuthProviderRequestSchema,
|
|
529
|
+
DeleteAuthProviderRequestSchema,
|
|
530
|
+
EnabledOAuthProvidersRequestSchema,
|
|
531
|
+
CheckEmailAvailabilityRequestSchema,
|
|
532
|
+
CompleteAccountSetupRequestSchema,
|
|
533
|
+
CreateSignupSessionRequestSchema,
|
|
534
|
+
UpdateMyProfileRequestSchema,
|
|
535
|
+
ListMyOAuthConnectionsRequestSchema,
|
|
536
|
+
UnlinkOAuthProviderRequestSchema,
|
|
537
|
+
ResendInvitationRequestSchema,
|
|
538
|
+
GetCustomerAuthConfigRequestSchema,
|
|
539
|
+
VerifyCustomerTokenRequestSchema,
|
|
540
|
+
GetCustomerManagementStatusRequestSchema
|
|
541
|
+
} from "@eide/foir-proto-ts/identity/v1/identity_pb";
|
|
542
|
+
import {
|
|
543
|
+
InviteType,
|
|
544
|
+
AccessRole,
|
|
545
|
+
CustomerStatus,
|
|
546
|
+
AdminUserStatus,
|
|
547
|
+
TenantStatus,
|
|
548
|
+
ProjectStatus,
|
|
549
|
+
InvitationStatus
|
|
550
|
+
} from "@eide/foir-proto-ts/identity/v1/identity_pb";
|
|
551
|
+
function createIdentityMethods(client) {
|
|
552
|
+
return {
|
|
553
|
+
// ── Auth ──────────────────────────────────────────────
|
|
554
|
+
async login(email, password, tenantId, projectId) {
|
|
555
|
+
const resp = await client.login(
|
|
556
|
+
create(LoginRequestSchema, { email, password, tenantId, projectId })
|
|
557
|
+
);
|
|
558
|
+
return {
|
|
559
|
+
sessionId: resp.sessionId,
|
|
560
|
+
user: resp.user ?? null
|
|
561
|
+
};
|
|
562
|
+
},
|
|
563
|
+
async loginWithOTP(email, otp, tenantId, projectId) {
|
|
564
|
+
const resp = await client.loginWithOTP(
|
|
565
|
+
create(LoginWithOTPRequestSchema, { email, otp, tenantId, projectId })
|
|
566
|
+
);
|
|
567
|
+
return {
|
|
568
|
+
sessionId: resp.sessionId,
|
|
569
|
+
user: resp.user ?? null
|
|
570
|
+
};
|
|
571
|
+
},
|
|
572
|
+
async requestOTP(email, tenantId, projectId) {
|
|
573
|
+
const resp = await client.requestOTP(
|
|
574
|
+
create(RequestOTPRequestSchema, { email, tenantId, projectId })
|
|
575
|
+
);
|
|
576
|
+
return { success: resp.success };
|
|
577
|
+
},
|
|
578
|
+
async logout() {
|
|
579
|
+
const resp = await client.logout(create(LogoutRequestSchema, {}));
|
|
580
|
+
return { success: resp.success };
|
|
581
|
+
},
|
|
582
|
+
async register(params) {
|
|
583
|
+
const resp = await client.register(
|
|
584
|
+
create(RegisterRequestSchema, {
|
|
585
|
+
email: params.email,
|
|
586
|
+
password: params.password,
|
|
587
|
+
tenantId: params.tenantId,
|
|
588
|
+
projectId: params.projectId,
|
|
589
|
+
role: params.role
|
|
590
|
+
})
|
|
591
|
+
);
|
|
592
|
+
return { user: resp.user ?? null };
|
|
593
|
+
},
|
|
594
|
+
// ── Email Verification ────────────────────────────────
|
|
595
|
+
async verifyEmail(token) {
|
|
596
|
+
const resp = await client.verifyEmail(
|
|
597
|
+
create(VerifyEmailRequestSchema, { token })
|
|
598
|
+
);
|
|
599
|
+
return { success: resp.success };
|
|
600
|
+
},
|
|
601
|
+
async resendVerificationEmail() {
|
|
602
|
+
const resp = await client.resendVerificationEmail(
|
|
603
|
+
create(ResendVerificationEmailRequestSchema, {})
|
|
604
|
+
);
|
|
605
|
+
return { success: resp.success };
|
|
606
|
+
},
|
|
607
|
+
async sendEmailVerificationCode(email) {
|
|
608
|
+
const resp = await client.sendEmailVerificationCode(
|
|
609
|
+
create(SendEmailVerificationCodeRequestSchema, { email })
|
|
610
|
+
);
|
|
611
|
+
return { success: resp.success };
|
|
612
|
+
},
|
|
613
|
+
async verifyEmailCode(email, code) {
|
|
614
|
+
const resp = await client.verifyEmailCode(
|
|
615
|
+
create(VerifyEmailCodeRequestSchema, { email, code })
|
|
616
|
+
);
|
|
617
|
+
return { success: resp.success, verified: resp.verified };
|
|
618
|
+
},
|
|
619
|
+
// ── Password ──────────────────────────────────────────
|
|
620
|
+
async updatePassword(currentPassword, newPassword) {
|
|
621
|
+
const resp = await client.updatePassword(
|
|
622
|
+
create(UpdatePasswordRequestSchema, { currentPassword, newPassword })
|
|
623
|
+
);
|
|
624
|
+
return { success: resp.success };
|
|
625
|
+
},
|
|
626
|
+
async requestPasswordReset(email) {
|
|
627
|
+
const resp = await client.requestPasswordReset(
|
|
628
|
+
create(RequestPasswordResetRequestSchema, { email })
|
|
629
|
+
);
|
|
630
|
+
return { success: resp.success };
|
|
631
|
+
},
|
|
632
|
+
async resetPassword(token, newPassword) {
|
|
633
|
+
const resp = await client.resetPassword(
|
|
634
|
+
create(ResetPasswordRequestSchema, { token, newPassword })
|
|
635
|
+
);
|
|
636
|
+
return { success: resp.success };
|
|
637
|
+
},
|
|
638
|
+
// ── Session Context ───────────────────────────────────
|
|
639
|
+
async getMe() {
|
|
640
|
+
const resp = await client.getMe(create(GetMeRequestSchema, {}));
|
|
641
|
+
return { user: resp.user ?? null };
|
|
642
|
+
},
|
|
643
|
+
async getSessionContext() {
|
|
644
|
+
const resp = await client.getSessionContext(
|
|
645
|
+
create(GetSessionContextRequestSchema, {})
|
|
646
|
+
);
|
|
647
|
+
return resp.context ?? null;
|
|
648
|
+
},
|
|
649
|
+
async switchTenant(tenantId) {
|
|
650
|
+
const resp = await client.switchTenant(
|
|
651
|
+
create(SwitchTenantRequestSchema, { tenantId })
|
|
652
|
+
);
|
|
653
|
+
return resp.context ?? null;
|
|
654
|
+
},
|
|
655
|
+
async switchProject(projectId) {
|
|
656
|
+
const resp = await client.switchProject(
|
|
657
|
+
create(SwitchProjectRequestSchema, { projectId })
|
|
658
|
+
);
|
|
659
|
+
return resp.context ?? null;
|
|
660
|
+
},
|
|
661
|
+
async clearSessionContext() {
|
|
662
|
+
await client.clearSessionContext(
|
|
663
|
+
create(ClearSessionContextRequestSchema, {})
|
|
664
|
+
);
|
|
665
|
+
return { success: true };
|
|
666
|
+
},
|
|
667
|
+
async refreshToken(refreshToken) {
|
|
668
|
+
const resp = await client.refreshToken(
|
|
669
|
+
create(RefreshTokenRequestSchema, { refreshToken })
|
|
670
|
+
);
|
|
671
|
+
return { accessToken: resp.accessToken, refreshToken: resp.refreshToken };
|
|
672
|
+
},
|
|
673
|
+
// ── Admin Users ───────────────────────────────────────
|
|
674
|
+
async createAdminUser(params) {
|
|
675
|
+
const resp = await client.createAdminUser(
|
|
676
|
+
create(CreateAdminUserRequestSchema, params)
|
|
677
|
+
);
|
|
678
|
+
return { user: resp.user ?? null };
|
|
679
|
+
},
|
|
680
|
+
async getAdminUser(id) {
|
|
681
|
+
const resp = await client.getAdminUser(
|
|
682
|
+
create(GetAdminUserRequestSchema, { id })
|
|
683
|
+
);
|
|
684
|
+
return { user: resp.user ?? null };
|
|
685
|
+
},
|
|
686
|
+
async updateAdminUser(params) {
|
|
687
|
+
const resp = await client.updateAdminUser(
|
|
688
|
+
create(UpdateAdminUserRequestSchema, params)
|
|
689
|
+
);
|
|
690
|
+
return { user: resp.user ?? null };
|
|
691
|
+
},
|
|
692
|
+
async listAdminUsers(params = {}) {
|
|
693
|
+
const resp = await client.listAdminUsers(
|
|
694
|
+
create(ListAdminUsersRequestSchema, {
|
|
695
|
+
search: params.search,
|
|
696
|
+
status: params.status,
|
|
697
|
+
role: params.role,
|
|
698
|
+
limit: params.limit ?? 50,
|
|
699
|
+
offset: params.offset ?? 0
|
|
700
|
+
})
|
|
701
|
+
);
|
|
702
|
+
return {
|
|
703
|
+
items: resp.items ?? [],
|
|
704
|
+
total: Number(resp.total)
|
|
705
|
+
};
|
|
706
|
+
},
|
|
707
|
+
async grantAccess(params) {
|
|
708
|
+
const resp = await client.grantAccess(
|
|
709
|
+
create(GrantAccessRequestSchema, params)
|
|
710
|
+
);
|
|
711
|
+
return { access: resp.access ?? null };
|
|
712
|
+
},
|
|
713
|
+
async revokeAccess(accessId) {
|
|
714
|
+
const resp = await client.revokeAccess(
|
|
715
|
+
create(RevokeAccessRequestSchema, { accessId })
|
|
716
|
+
);
|
|
717
|
+
return { success: resp.success };
|
|
718
|
+
},
|
|
719
|
+
// ── Customers ─────────────────────────────────────────
|
|
720
|
+
async createCustomer(params) {
|
|
721
|
+
const resp = await client.createCustomer(
|
|
722
|
+
create(CreateCustomerRequestSchema, {
|
|
723
|
+
email: params.email,
|
|
724
|
+
password: params.password
|
|
725
|
+
})
|
|
726
|
+
);
|
|
727
|
+
return {
|
|
728
|
+
customer: resp.customer ?? null
|
|
729
|
+
};
|
|
730
|
+
},
|
|
731
|
+
async getCustomer(id) {
|
|
732
|
+
const resp = await client.getCustomer(
|
|
733
|
+
create(GetCustomerRequestSchema, { id })
|
|
734
|
+
);
|
|
735
|
+
return {
|
|
736
|
+
customer: resp.customer ?? null
|
|
737
|
+
};
|
|
738
|
+
},
|
|
739
|
+
async updateCustomer(params) {
|
|
740
|
+
const resp = await client.updateCustomer(
|
|
741
|
+
create(UpdateCustomerRequestSchema, {
|
|
742
|
+
id: params.id,
|
|
743
|
+
email: params.email,
|
|
744
|
+
status: params.status
|
|
745
|
+
})
|
|
746
|
+
);
|
|
747
|
+
return {
|
|
748
|
+
customer: resp.customer ?? null
|
|
749
|
+
};
|
|
750
|
+
},
|
|
751
|
+
async deleteCustomer(id) {
|
|
752
|
+
const resp = await client.deleteCustomer(
|
|
753
|
+
create(DeleteCustomerRequestSchema, { id })
|
|
754
|
+
);
|
|
755
|
+
return { success: resp.success };
|
|
756
|
+
},
|
|
757
|
+
async listCustomers(params = {}) {
|
|
758
|
+
const resp = await client.listCustomers(
|
|
759
|
+
create(ListCustomersRequestSchema, {
|
|
760
|
+
search: params.search,
|
|
761
|
+
status: params.status,
|
|
762
|
+
limit: params.limit ?? 50,
|
|
763
|
+
offset: params.offset ?? 0
|
|
764
|
+
})
|
|
765
|
+
);
|
|
766
|
+
return {
|
|
767
|
+
items: resp.items ?? [],
|
|
768
|
+
total: Number(resp.total)
|
|
769
|
+
};
|
|
770
|
+
},
|
|
771
|
+
async suspendCustomer(id) {
|
|
772
|
+
const resp = await client.suspendCustomer(
|
|
773
|
+
create(SuspendCustomerRequestSchema, { id })
|
|
774
|
+
);
|
|
775
|
+
return {
|
|
776
|
+
customer: resp.customer ?? null
|
|
777
|
+
};
|
|
778
|
+
},
|
|
779
|
+
// ── Tenants ───────────────────────────────────────────
|
|
780
|
+
async createTenant(params) {
|
|
781
|
+
const resp = await client.createTenant(
|
|
782
|
+
create(CreateTenantRequestSchema, { name: params.name })
|
|
783
|
+
);
|
|
784
|
+
return { tenant: resp.tenant ?? null };
|
|
785
|
+
},
|
|
786
|
+
async getTenant(id) {
|
|
787
|
+
const resp = await client.getTenant(
|
|
788
|
+
create(GetTenantRequestSchema, { id })
|
|
789
|
+
);
|
|
790
|
+
return { tenant: resp.tenant ?? null };
|
|
791
|
+
},
|
|
792
|
+
async updateTenant(params) {
|
|
793
|
+
const resp = await client.updateTenant(
|
|
794
|
+
create(UpdateTenantRequestSchema, {
|
|
795
|
+
id: params.id,
|
|
796
|
+
name: params.name,
|
|
797
|
+
status: params.status
|
|
798
|
+
})
|
|
799
|
+
);
|
|
800
|
+
return { tenant: resp.tenant ?? null };
|
|
801
|
+
},
|
|
802
|
+
async listTenants(params = {}) {
|
|
803
|
+
const resp = await client.listTenants(
|
|
804
|
+
create(ListTenantsRequestSchema, {
|
|
805
|
+
status: params.status,
|
|
806
|
+
limit: params.limit ?? 50,
|
|
807
|
+
offset: params.offset ?? 0
|
|
808
|
+
})
|
|
809
|
+
);
|
|
810
|
+
return {
|
|
811
|
+
items: resp.items ?? [],
|
|
812
|
+
total: Number(resp.total)
|
|
813
|
+
};
|
|
814
|
+
},
|
|
815
|
+
async deleteTenant(id) {
|
|
816
|
+
const resp = await client.deleteTenant(
|
|
817
|
+
create(DeleteTenantRequestSchema, { id })
|
|
818
|
+
);
|
|
819
|
+
return { success: resp.success };
|
|
820
|
+
},
|
|
821
|
+
// ── Projects ──────────────────────────────────────────
|
|
822
|
+
async createProject(params) {
|
|
823
|
+
const resp = await client.createProject(
|
|
824
|
+
create(CreateProjectRequestSchema, {
|
|
825
|
+
tenantId: params.tenantId,
|
|
826
|
+
name: params.name,
|
|
827
|
+
description: params.description
|
|
828
|
+
})
|
|
829
|
+
);
|
|
830
|
+
return { project: resp.project ?? null };
|
|
831
|
+
},
|
|
832
|
+
async getProject(id) {
|
|
833
|
+
const resp = await client.getProject(
|
|
834
|
+
create(GetProjectRequestSchema, { id })
|
|
835
|
+
);
|
|
836
|
+
return { project: resp.project ?? null };
|
|
837
|
+
},
|
|
838
|
+
async updateProject(params) {
|
|
839
|
+
const resp = await client.updateProject(
|
|
840
|
+
create(UpdateProjectRequestSchema, {
|
|
841
|
+
id: params.id,
|
|
842
|
+
name: params.name,
|
|
843
|
+
description: params.description
|
|
844
|
+
})
|
|
845
|
+
);
|
|
846
|
+
return { project: resp.project ?? null };
|
|
847
|
+
},
|
|
848
|
+
async listProjects(params) {
|
|
849
|
+
const resp = await client.listProjects(
|
|
850
|
+
create(ListProjectsRequestSchema, {
|
|
851
|
+
tenantId: params.tenantId,
|
|
852
|
+
status: params.status,
|
|
853
|
+
limit: params.limit ?? 50,
|
|
854
|
+
offset: params.offset ?? 0
|
|
855
|
+
})
|
|
856
|
+
);
|
|
857
|
+
return {
|
|
858
|
+
items: resp.items ?? [],
|
|
859
|
+
total: Number(resp.total)
|
|
860
|
+
};
|
|
861
|
+
},
|
|
862
|
+
async deleteProject(id) {
|
|
863
|
+
const resp = await client.deleteProject(
|
|
864
|
+
create(DeleteProjectRequestSchema, { id })
|
|
865
|
+
);
|
|
866
|
+
return { success: resp.success };
|
|
867
|
+
},
|
|
868
|
+
async getDefaultProject(tenantId) {
|
|
869
|
+
const resp = await client.getDefaultProject(
|
|
870
|
+
create(GetDefaultProjectRequestSchema, { tenantId })
|
|
871
|
+
);
|
|
872
|
+
return { project: resp.project ?? null };
|
|
873
|
+
},
|
|
874
|
+
async setDefaultProject(params) {
|
|
875
|
+
const resp = await client.setDefaultProject(
|
|
876
|
+
create(SetDefaultProjectRequestSchema, {
|
|
877
|
+
projectId: params.projectId
|
|
878
|
+
})
|
|
879
|
+
);
|
|
880
|
+
return { project: resp.project ?? null };
|
|
881
|
+
},
|
|
882
|
+
// ── Invitations ───────────────────────────────────────
|
|
883
|
+
async createInvitation(params) {
|
|
884
|
+
const resp = await client.createInvitation(
|
|
885
|
+
create(CreateInvitationRequestSchema, {
|
|
886
|
+
email: params.email,
|
|
887
|
+
tenantId: params.tenantId,
|
|
888
|
+
projectIds: params.projectIds ?? [],
|
|
889
|
+
role: params.role,
|
|
890
|
+
inviteType: params.inviteType,
|
|
891
|
+
message: params.message
|
|
892
|
+
})
|
|
893
|
+
);
|
|
894
|
+
return {
|
|
895
|
+
invitation: resp.invitation ?? null
|
|
896
|
+
};
|
|
897
|
+
},
|
|
898
|
+
async listInvitations(params) {
|
|
899
|
+
const resp = await client.listInvitations(
|
|
900
|
+
create(ListInvitationsRequestSchema, {
|
|
901
|
+
tenantId: params.tenantId,
|
|
902
|
+
status: params.status,
|
|
903
|
+
limit: params.limit ?? 50,
|
|
904
|
+
offset: params.offset ?? 0
|
|
905
|
+
})
|
|
906
|
+
);
|
|
907
|
+
return {
|
|
908
|
+
items: resp.items ?? [],
|
|
909
|
+
total: Number(resp.total)
|
|
910
|
+
};
|
|
911
|
+
},
|
|
912
|
+
async revokeInvitation(invitationId) {
|
|
913
|
+
const resp = await client.revokeInvitation(
|
|
914
|
+
create(RevokeInvitationRequestSchema, { invitationId })
|
|
915
|
+
);
|
|
916
|
+
return { success: resp.success };
|
|
917
|
+
},
|
|
918
|
+
async acceptInvitation(params) {
|
|
919
|
+
const resp = await client.acceptInvitation(
|
|
920
|
+
create(AcceptInvitationRequestSchema, {
|
|
921
|
+
token: params.token,
|
|
922
|
+
password: params.password
|
|
923
|
+
})
|
|
924
|
+
);
|
|
925
|
+
return {
|
|
926
|
+
user: resp.user ?? null,
|
|
927
|
+
sessionId: resp.sessionId
|
|
928
|
+
};
|
|
929
|
+
},
|
|
930
|
+
async validateInvitation(params) {
|
|
931
|
+
const resp = await client.validateInvitation(
|
|
932
|
+
create(ValidateInvitationRequestSchema, { token: params.token })
|
|
933
|
+
);
|
|
934
|
+
return {
|
|
935
|
+
invitation: resp.invitation ?? null
|
|
936
|
+
};
|
|
937
|
+
},
|
|
938
|
+
// ── API Keys ──────────────────────────────────────────
|
|
939
|
+
async createApiKey(params) {
|
|
940
|
+
const resp = await client.createApiKey(
|
|
941
|
+
create(CreateApiKeyRequestSchema, {
|
|
942
|
+
name: params.name,
|
|
943
|
+
keyType: params.keyType,
|
|
944
|
+
rateLimitPerHour: params.rateLimitPerHour
|
|
945
|
+
})
|
|
946
|
+
);
|
|
947
|
+
return { apiKey: resp.apiKey ?? null };
|
|
948
|
+
},
|
|
949
|
+
async getApiKey(id) {
|
|
950
|
+
const resp = await client.getApiKey(
|
|
951
|
+
create(GetApiKeyRequestSchema, { id })
|
|
952
|
+
);
|
|
953
|
+
return { apiKey: resp.apiKey ?? null };
|
|
954
|
+
},
|
|
955
|
+
async listApiKeys(params = {}) {
|
|
956
|
+
const resp = await client.listApiKeys(
|
|
957
|
+
create(ListApiKeysRequestSchema, {
|
|
958
|
+
limit: params.limit ?? 50,
|
|
959
|
+
offset: params.offset ?? 0
|
|
960
|
+
})
|
|
961
|
+
);
|
|
962
|
+
return {
|
|
963
|
+
items: resp.items ?? [],
|
|
964
|
+
total: Number(resp.total)
|
|
965
|
+
};
|
|
966
|
+
},
|
|
967
|
+
async updateApiKey(params) {
|
|
968
|
+
const resp = await client.updateApiKey(
|
|
969
|
+
create(UpdateApiKeyRequestSchema, {
|
|
970
|
+
id: params.id,
|
|
971
|
+
name: params.name,
|
|
972
|
+
isActive: params.isActive,
|
|
973
|
+
rateLimitPerHour: params.rateLimitPerHour
|
|
974
|
+
})
|
|
975
|
+
);
|
|
976
|
+
return { apiKey: resp.apiKey ?? null };
|
|
977
|
+
},
|
|
978
|
+
async rotateApiKey(id) {
|
|
979
|
+
const resp = await client.rotateApiKey(
|
|
980
|
+
create(RotateApiKeyRequestSchema, { id })
|
|
981
|
+
);
|
|
982
|
+
return { apiKey: resp.apiKey ?? null };
|
|
983
|
+
},
|
|
984
|
+
async revokeApiKey(id) {
|
|
985
|
+
const resp = await client.revokeApiKey(
|
|
986
|
+
create(RevokeApiKeyRequestSchema, { id })
|
|
987
|
+
);
|
|
988
|
+
return { success: resp.success };
|
|
989
|
+
},
|
|
990
|
+
// ── Service Tokens ──────────────────────────────────────────
|
|
991
|
+
async mintServiceToken(purpose) {
|
|
992
|
+
const resp = await client.mintServiceToken(
|
|
993
|
+
create(MintServiceTokenRequestSchema, { purpose })
|
|
994
|
+
);
|
|
995
|
+
return {
|
|
996
|
+
token: resp.token,
|
|
997
|
+
purpose: resp.purpose,
|
|
998
|
+
expiresAt: resp.expiresAt
|
|
999
|
+
};
|
|
1000
|
+
},
|
|
1001
|
+
// ── Auth Providers ───────────────────────────────────────
|
|
1002
|
+
async listAuthProviders(params = {}) {
|
|
1003
|
+
const resp = await client.listAuthProviders(
|
|
1004
|
+
create(ListAuthProvidersRequestSchema, {
|
|
1005
|
+
enabled: params.enabled,
|
|
1006
|
+
limit: params.limit ?? 50,
|
|
1007
|
+
offset: params.offset ?? 0
|
|
1008
|
+
})
|
|
1009
|
+
);
|
|
1010
|
+
return {
|
|
1011
|
+
items: resp.providers ?? [],
|
|
1012
|
+
total: resp.total
|
|
1013
|
+
};
|
|
1014
|
+
},
|
|
1015
|
+
async getAuthProvider(id) {
|
|
1016
|
+
const resp = await client.getAuthProvider(
|
|
1017
|
+
create(GetAuthProviderRequestSchema, { id })
|
|
1018
|
+
);
|
|
1019
|
+
return resp.provider ?? null;
|
|
1020
|
+
},
|
|
1021
|
+
async createAuthProvider(params) {
|
|
1022
|
+
const resp = await client.createAuthProvider(
|
|
1023
|
+
create(CreateAuthProviderRequestSchema, {
|
|
1024
|
+
key: params.key,
|
|
1025
|
+
name: params.name,
|
|
1026
|
+
type: params.type,
|
|
1027
|
+
config: params.config,
|
|
1028
|
+
enabled: params.enabled,
|
|
1029
|
+
isDefault: params.isDefault,
|
|
1030
|
+
priority: params.priority
|
|
1031
|
+
})
|
|
1032
|
+
);
|
|
1033
|
+
return resp.provider ?? null;
|
|
1034
|
+
},
|
|
1035
|
+
async updateAuthProvider(params) {
|
|
1036
|
+
const resp = await client.updateAuthProvider(
|
|
1037
|
+
create(UpdateAuthProviderRequestSchema, {
|
|
1038
|
+
id: params.id,
|
|
1039
|
+
name: params.name,
|
|
1040
|
+
config: params.config,
|
|
1041
|
+
enabled: params.enabled,
|
|
1042
|
+
isDefault: params.isDefault,
|
|
1043
|
+
priority: params.priority
|
|
1044
|
+
})
|
|
1045
|
+
);
|
|
1046
|
+
return resp.provider ?? null;
|
|
1047
|
+
},
|
|
1048
|
+
async deleteAuthProvider(id) {
|
|
1049
|
+
const resp = await client.deleteAuthProvider(
|
|
1050
|
+
create(DeleteAuthProviderRequestSchema, { id })
|
|
1051
|
+
);
|
|
1052
|
+
return resp.success;
|
|
1053
|
+
},
|
|
1054
|
+
async enabledOAuthProviders() {
|
|
1055
|
+
const resp = await client.enabledOAuthProviders(
|
|
1056
|
+
create(EnabledOAuthProvidersRequestSchema, {})
|
|
1057
|
+
);
|
|
1058
|
+
return resp.providers ?? [];
|
|
1059
|
+
},
|
|
1060
|
+
// ── Signup / Account Setup ───────────────────────────────
|
|
1061
|
+
async checkEmailAvailability(email) {
|
|
1062
|
+
const resp = await client.checkEmailAvailability(
|
|
1063
|
+
create(CheckEmailAvailabilityRequestSchema, { email })
|
|
1064
|
+
);
|
|
1065
|
+
return { available: resp.available };
|
|
1066
|
+
},
|
|
1067
|
+
async completeAccountSetup(params) {
|
|
1068
|
+
const resp = await client.completeAccountSetup(
|
|
1069
|
+
create(CompleteAccountSetupRequestSchema, {
|
|
1070
|
+
firstName: params.firstName,
|
|
1071
|
+
lastName: params.lastName,
|
|
1072
|
+
password: params.password
|
|
1073
|
+
})
|
|
1074
|
+
);
|
|
1075
|
+
return {
|
|
1076
|
+
success: resp.success,
|
|
1077
|
+
redirectUrl: resp.redirectUrl ?? void 0
|
|
1078
|
+
};
|
|
1079
|
+
},
|
|
1080
|
+
async createSignupSession(userId) {
|
|
1081
|
+
const resp = await client.createSignupSession(
|
|
1082
|
+
create(CreateSignupSessionRequestSchema, { userId })
|
|
1083
|
+
);
|
|
1084
|
+
return { success: resp.success };
|
|
1085
|
+
},
|
|
1086
|
+
// ── Profile / OAuth ───────────────────────────────────────
|
|
1087
|
+
async updateMyProfile(params) {
|
|
1088
|
+
const resp = await client.updateMyProfile(
|
|
1089
|
+
create(UpdateMyProfileRequestSchema, {
|
|
1090
|
+
firstName: params.firstName,
|
|
1091
|
+
lastName: params.lastName,
|
|
1092
|
+
avatarUrl: params.avatarUrl
|
|
1093
|
+
})
|
|
1094
|
+
);
|
|
1095
|
+
return resp.user ?? null;
|
|
1096
|
+
},
|
|
1097
|
+
async listMyOAuthConnections() {
|
|
1098
|
+
const resp = await client.listMyOAuthConnections(
|
|
1099
|
+
create(ListMyOAuthConnectionsRequestSchema, {})
|
|
1100
|
+
);
|
|
1101
|
+
return resp.connections ?? [];
|
|
1102
|
+
},
|
|
1103
|
+
async unlinkOAuthProvider(provider) {
|
|
1104
|
+
const resp = await client.unlinkOAuthProvider(
|
|
1105
|
+
create(UnlinkOAuthProviderRequestSchema, { provider })
|
|
1106
|
+
);
|
|
1107
|
+
return resp.success;
|
|
1108
|
+
},
|
|
1109
|
+
// ── Invitations (additional) ─────────────────────────────
|
|
1110
|
+
async resendInvitation(invitationId) {
|
|
1111
|
+
const resp = await client.resendInvitation(
|
|
1112
|
+
create(ResendInvitationRequestSchema, { invitationId })
|
|
1113
|
+
);
|
|
1114
|
+
return resp.success;
|
|
1115
|
+
},
|
|
1116
|
+
// ── Customer Auth ────────────────────────────────────────
|
|
1117
|
+
async getCustomerAuthConfig() {
|
|
1118
|
+
const resp = await client.getCustomerAuthConfig(
|
|
1119
|
+
create(GetCustomerAuthConfigRequestSchema, {})
|
|
1120
|
+
);
|
|
1121
|
+
return resp.config ?? null;
|
|
1122
|
+
},
|
|
1123
|
+
async verifyCustomerToken(token) {
|
|
1124
|
+
const resp = await client.verifyCustomerToken(
|
|
1125
|
+
create(VerifyCustomerTokenRequestSchema, { token })
|
|
1126
|
+
);
|
|
1127
|
+
return resp;
|
|
1128
|
+
},
|
|
1129
|
+
async getCustomerManagementStatus() {
|
|
1130
|
+
const resp = await client.getCustomerManagementStatus(
|
|
1131
|
+
create(GetCustomerManagementStatusRequestSchema, {})
|
|
1132
|
+
);
|
|
1133
|
+
return resp.status ?? null;
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
// src/lib/rpc/models.ts
|
|
1139
|
+
import { create as create2 } from "@bufbuild/protobuf";
|
|
1140
|
+
import {
|
|
1141
|
+
FieldSchema as ProtoFieldSchema,
|
|
1142
|
+
SharingConfigSchema as ProtoSharingConfigSchema,
|
|
1143
|
+
ModelConfigSchema as ProtoModelConfigSchema,
|
|
1144
|
+
CreateModelRequestSchema,
|
|
1145
|
+
GetModelRequestSchema,
|
|
1146
|
+
GetModelByKeyRequestSchema,
|
|
1147
|
+
ListModelsRequestSchema,
|
|
1148
|
+
UpdateModelRequestSchema,
|
|
1149
|
+
DeleteModelRequestSchema,
|
|
1150
|
+
DuplicateModelRequestSchema,
|
|
1151
|
+
ListModelVersionsRequestSchema,
|
|
1152
|
+
RestoreModelVersionRequestSchema
|
|
1153
|
+
} from "@eide/foir-proto-ts/models/v1/models_pb";
|
|
1154
|
+
function jsFieldToProto(f) {
|
|
1155
|
+
return create2(ProtoFieldSchema, {
|
|
1156
|
+
id: f.id,
|
|
1157
|
+
key: f.key,
|
|
1158
|
+
label: f.label,
|
|
1159
|
+
type: f.type,
|
|
1160
|
+
required: f.required,
|
|
1161
|
+
helpText: f.helpText,
|
|
1162
|
+
placeholder: f.placeholder,
|
|
1163
|
+
config: f.config && Object.keys(f.config).length > 0 ? f.config : void 0,
|
|
1164
|
+
itemType: f.itemType,
|
|
1165
|
+
storage: f.storage,
|
|
1166
|
+
templateZone: f.templateZone,
|
|
1167
|
+
zoneOrder: f.zoneOrder
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
function jsConfigToProto(c) {
|
|
1171
|
+
return create2(ProtoModelConfigSchema, {
|
|
1172
|
+
versioning: c.versioning ?? false,
|
|
1173
|
+
publishing: c.publishing ?? false,
|
|
1174
|
+
variants: c.variants ?? false,
|
|
1175
|
+
inline: c.inline ?? false,
|
|
1176
|
+
customerScoped: c.customerScoped ?? false,
|
|
1177
|
+
sharing: c.sharing ? create2(ProtoSharingConfigSchema, {
|
|
1178
|
+
enabled: c.sharing.enabled,
|
|
1179
|
+
requireAcceptance: c.sharing.requireAcceptance
|
|
1180
|
+
}) : void 0,
|
|
1181
|
+
pluralName: c.pluralName,
|
|
1182
|
+
description: c.description,
|
|
1183
|
+
category: c.category,
|
|
1184
|
+
icon: c.icon,
|
|
1185
|
+
displayField: c.displayField,
|
|
1186
|
+
naturalKeyField: c.naturalKeyField,
|
|
1187
|
+
systemEntity: c.systemEntity ?? false,
|
|
1188
|
+
deletable: c.deletable,
|
|
1189
|
+
editable: c.editable
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
function createModelsMethods(client) {
|
|
1193
|
+
return {
|
|
1194
|
+
// ── Queries ──────────────────────────────────────────────
|
|
1195
|
+
async getModel(id) {
|
|
1196
|
+
const resp = await client.getModel(create2(GetModelRequestSchema, { id }));
|
|
1197
|
+
return resp.model ?? null;
|
|
1198
|
+
},
|
|
1199
|
+
async getModelByKey(key) {
|
|
1200
|
+
const resp = await client.getModelByKey(
|
|
1201
|
+
create2(GetModelByKeyRequestSchema, { key })
|
|
1202
|
+
);
|
|
1203
|
+
return resp.model ?? null;
|
|
1204
|
+
},
|
|
1205
|
+
async listModels(params = {}) {
|
|
1206
|
+
const resp = await client.listModels(
|
|
1207
|
+
create2(ListModelsRequestSchema, {
|
|
1208
|
+
search: params.search,
|
|
1209
|
+
category: params.category,
|
|
1210
|
+
configId: params.configId,
|
|
1211
|
+
limit: params.limit ?? 50,
|
|
1212
|
+
offset: params.offset ?? 0
|
|
1213
|
+
})
|
|
1214
|
+
);
|
|
1215
|
+
return {
|
|
1216
|
+
items: resp.models ?? [],
|
|
1217
|
+
total: resp.total
|
|
1218
|
+
};
|
|
1219
|
+
},
|
|
1220
|
+
// ── Mutations ────────────────────────────────────────────
|
|
1221
|
+
async createModel(params) {
|
|
1222
|
+
const resp = await client.createModel(
|
|
1223
|
+
create2(CreateModelRequestSchema, {
|
|
1224
|
+
key: params.key,
|
|
1225
|
+
name: params.name,
|
|
1226
|
+
fields: params.fields.map(jsFieldToProto),
|
|
1227
|
+
config: params.config ? jsConfigToProto(params.config) : void 0,
|
|
1228
|
+
configId: params.configId
|
|
1229
|
+
})
|
|
1230
|
+
);
|
|
1231
|
+
return resp.model ?? null;
|
|
1232
|
+
},
|
|
1233
|
+
async updateModel(params) {
|
|
1234
|
+
const resp = await client.updateModel(
|
|
1235
|
+
create2(UpdateModelRequestSchema, {
|
|
1236
|
+
id: params.id,
|
|
1237
|
+
name: params.name,
|
|
1238
|
+
updateFields: params.fields != null,
|
|
1239
|
+
fields: params.fields?.map(jsFieldToProto) ?? [],
|
|
1240
|
+
config: params.config ? jsConfigToProto(params.config) : void 0,
|
|
1241
|
+
changeDescription: params.changeDescription
|
|
1242
|
+
})
|
|
1243
|
+
);
|
|
1244
|
+
return resp.model ?? null;
|
|
1245
|
+
},
|
|
1246
|
+
async deleteModel(id) {
|
|
1247
|
+
const resp = await client.deleteModel(
|
|
1248
|
+
create2(DeleteModelRequestSchema, { id })
|
|
1249
|
+
);
|
|
1250
|
+
return resp.success;
|
|
1251
|
+
},
|
|
1252
|
+
async duplicateModel(params) {
|
|
1253
|
+
const resp = await client.duplicateModel(
|
|
1254
|
+
create2(DuplicateModelRequestSchema, params)
|
|
1255
|
+
);
|
|
1256
|
+
return resp.model ?? null;
|
|
1257
|
+
},
|
|
1258
|
+
// ── Versioning ───────────────────────────────────────────
|
|
1259
|
+
async listModelVersions(modelId, params = {}) {
|
|
1260
|
+
const resp = await client.listModelVersions(
|
|
1261
|
+
create2(ListModelVersionsRequestSchema, {
|
|
1262
|
+
modelId,
|
|
1263
|
+
limit: params.limit ?? 50,
|
|
1264
|
+
offset: params.offset ?? 0
|
|
1265
|
+
})
|
|
1266
|
+
);
|
|
1267
|
+
return {
|
|
1268
|
+
items: resp.versions ?? [],
|
|
1269
|
+
total: resp.total
|
|
1270
|
+
};
|
|
1271
|
+
},
|
|
1272
|
+
async restoreModelVersion(modelId, versionId) {
|
|
1273
|
+
const resp = await client.restoreModelVersion(
|
|
1274
|
+
create2(RestoreModelVersionRequestSchema, { modelId, versionId })
|
|
1275
|
+
);
|
|
1276
|
+
return resp.model ?? null;
|
|
1277
|
+
}
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
// src/lib/rpc/records.ts
|
|
1282
|
+
import { create as create3 } from "@bufbuild/protobuf";
|
|
1283
|
+
import {
|
|
1284
|
+
CreateRecordRequestSchema,
|
|
1285
|
+
GetRecordRequestSchema,
|
|
1286
|
+
GetRecordByKeyRequestSchema,
|
|
1287
|
+
GetRecordByKeyOrIdRequestSchema,
|
|
1288
|
+
ListRecordsRequestSchema,
|
|
1289
|
+
UpdateRecordRequestSchema,
|
|
1290
|
+
DeleteRecordRequestSchema,
|
|
1291
|
+
DuplicateRecordRequestSchema,
|
|
1292
|
+
DuplicateRecordsBulkRequestSchema,
|
|
1293
|
+
BatchRecordOperationsRequestSchema,
|
|
1294
|
+
BatchOperationSchema,
|
|
1295
|
+
RecordFilterSchema,
|
|
1296
|
+
BulkUpdateRecordsRequestSchema,
|
|
1297
|
+
CreateVersionRequestSchema,
|
|
1298
|
+
PublishVersionRequestSchema,
|
|
1299
|
+
UnpublishRecordRequestSchema,
|
|
1300
|
+
RevertToVersionRequestSchema,
|
|
1301
|
+
ListRecordVersionsRequestSchema,
|
|
1302
|
+
SaveContentRequestSchema,
|
|
1303
|
+
CreateVariantRequestSchema,
|
|
1304
|
+
UpdateVariantRequestSchema,
|
|
1305
|
+
DeleteVariantRequestSchema,
|
|
1306
|
+
SetDefaultVariantRequestSchema,
|
|
1307
|
+
ListRecordVariantsRequestSchema,
|
|
1308
|
+
ScheduleRecordPublishRequestSchema,
|
|
1309
|
+
CancelScheduledRecordPublishRequestSchema,
|
|
1310
|
+
ListScheduledPublishesRequestSchema,
|
|
1311
|
+
ListDraftVersionsRequestSchema,
|
|
1312
|
+
BatchPublishVersionsRequestSchema,
|
|
1313
|
+
CreatePublishBatchRequestSchema,
|
|
1314
|
+
UpdatePublishBatchRequestSchema,
|
|
1315
|
+
CancelPublishBatchRequestSchema,
|
|
1316
|
+
RollbackPublishBatchRequestSchema,
|
|
1317
|
+
RetryFailedBatchItemsRequestSchema,
|
|
1318
|
+
AddItemsToPublishBatchRequestSchema,
|
|
1319
|
+
RemoveItemsFromPublishBatchRequestSchema,
|
|
1320
|
+
ListPublishBatchesRequestSchema,
|
|
1321
|
+
GetPublishBatchRequestSchema,
|
|
1322
|
+
GlobalSearchRequestSchema,
|
|
1323
|
+
GetEmbeddingStatsRequestSchema,
|
|
1324
|
+
GetRecordEmbeddingsRequestSchema,
|
|
1325
|
+
FindSimilarRecordsRequestSchema
|
|
1326
|
+
} from "@eide/foir-proto-ts/records/v1/records_pb";
|
|
1327
|
+
import { RecordType, BatchStatus } from "@eide/foir-proto-ts/records/v1/records_pb";
|
|
1328
|
+
function sanitizeData(obj) {
|
|
1329
|
+
const result = {};
|
|
1330
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1331
|
+
if (value === void 0) continue;
|
|
1332
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
1333
|
+
result[key] = sanitizeData(value);
|
|
1334
|
+
} else if (Array.isArray(value)) {
|
|
1335
|
+
result[key] = value.map((item) => {
|
|
1336
|
+
if (item === void 0) return null;
|
|
1337
|
+
if (item !== null && typeof item === "object" && !Array.isArray(item)) {
|
|
1338
|
+
return sanitizeData(item);
|
|
1339
|
+
}
|
|
1340
|
+
return item;
|
|
1341
|
+
});
|
|
1342
|
+
} else {
|
|
1343
|
+
result[key] = value;
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
return result;
|
|
1347
|
+
}
|
|
1348
|
+
function createRecordsMethods(client) {
|
|
1349
|
+
return {
|
|
1350
|
+
// ── CRUD ──────────────────────────────────────────────────
|
|
1351
|
+
async createRecord(params) {
|
|
1352
|
+
const resp = await client.createRecord(
|
|
1353
|
+
create3(CreateRecordRequestSchema, {
|
|
1354
|
+
modelKey: params.modelKey,
|
|
1355
|
+
naturalKey: params.naturalKey,
|
|
1356
|
+
data: params.data ? sanitizeData(params.data) : void 0,
|
|
1357
|
+
customerId: params.customerId,
|
|
1358
|
+
metadata: params.metadata ? sanitizeData(params.metadata) : void 0,
|
|
1359
|
+
changeDescription: params.changeDescription
|
|
1360
|
+
})
|
|
1361
|
+
);
|
|
1362
|
+
return {
|
|
1363
|
+
record: resp.record ?? null,
|
|
1364
|
+
variant: resp.variant ?? null,
|
|
1365
|
+
version: resp.version ?? null
|
|
1366
|
+
};
|
|
1367
|
+
},
|
|
1368
|
+
async getRecord(id) {
|
|
1369
|
+
const resp = await client.getRecord(
|
|
1370
|
+
create3(GetRecordRequestSchema, { id })
|
|
1371
|
+
);
|
|
1372
|
+
return resp.record ?? null;
|
|
1373
|
+
},
|
|
1374
|
+
async getRecordByKey(modelKey, naturalKey) {
|
|
1375
|
+
const resp = await client.getRecordByKey(
|
|
1376
|
+
create3(GetRecordByKeyRequestSchema, { modelKey, naturalKey })
|
|
1377
|
+
);
|
|
1378
|
+
return resp.record ?? null;
|
|
1379
|
+
},
|
|
1380
|
+
async getRecordByKeyOrId(modelKey, identifier) {
|
|
1381
|
+
const resp = await client.getRecordByKeyOrId(
|
|
1382
|
+
create3(GetRecordByKeyOrIdRequestSchema, { modelKey, identifier })
|
|
1383
|
+
);
|
|
1384
|
+
return resp.record ?? null;
|
|
1385
|
+
},
|
|
1386
|
+
async listRecords(params) {
|
|
1387
|
+
const resp = await client.listRecords(
|
|
1388
|
+
create3(ListRecordsRequestSchema, {
|
|
1389
|
+
modelKey: params.modelKey,
|
|
1390
|
+
limit: params.limit ?? 50,
|
|
1391
|
+
offset: params.offset ?? 0,
|
|
1392
|
+
customerId: params.customerId,
|
|
1393
|
+
search: params.search,
|
|
1394
|
+
filters: params.filters?.map(
|
|
1395
|
+
(f) => create3(RecordFilterSchema, {
|
|
1396
|
+
field: f.field,
|
|
1397
|
+
operator: f.operator
|
|
1398
|
+
})
|
|
1399
|
+
)
|
|
1400
|
+
})
|
|
1401
|
+
);
|
|
1402
|
+
return {
|
|
1403
|
+
items: resp.records ?? [],
|
|
1404
|
+
total: resp.total
|
|
1405
|
+
};
|
|
1406
|
+
},
|
|
1407
|
+
async updateRecord(params) {
|
|
1408
|
+
const resp = await client.updateRecord(
|
|
1409
|
+
create3(UpdateRecordRequestSchema, {
|
|
1410
|
+
id: params.id,
|
|
1411
|
+
data: sanitizeData(params.data),
|
|
1412
|
+
naturalKey: params.naturalKey
|
|
1413
|
+
})
|
|
1414
|
+
);
|
|
1415
|
+
return resp.record ?? null;
|
|
1416
|
+
},
|
|
1417
|
+
async deleteRecord(id) {
|
|
1418
|
+
const resp = await client.deleteRecord(
|
|
1419
|
+
create3(DeleteRecordRequestSchema, { id })
|
|
1420
|
+
);
|
|
1421
|
+
return resp.success;
|
|
1422
|
+
},
|
|
1423
|
+
async duplicateRecord(id, newNaturalKey) {
|
|
1424
|
+
const resp = await client.duplicateRecord(
|
|
1425
|
+
create3(DuplicateRecordRequestSchema, { id, newNaturalKey })
|
|
1426
|
+
);
|
|
1427
|
+
return resp.record ?? null;
|
|
1428
|
+
},
|
|
1429
|
+
async duplicateRecordsBulk(ids, modelKey) {
|
|
1430
|
+
const resp = await client.duplicateRecordsBulk(
|
|
1431
|
+
create3(DuplicateRecordsBulkRequestSchema, { ids, modelKey })
|
|
1432
|
+
);
|
|
1433
|
+
return resp.records ?? [];
|
|
1434
|
+
},
|
|
1435
|
+
async batchRecordOperations(operations) {
|
|
1436
|
+
const typeMap = { create: 1, update: 2, delete: 3 };
|
|
1437
|
+
const resp = await client.batchRecordOperations(
|
|
1438
|
+
create3(BatchRecordOperationsRequestSchema, {
|
|
1439
|
+
operations: operations.map(
|
|
1440
|
+
(op) => create3(BatchOperationSchema, {
|
|
1441
|
+
type: typeMap[op.type],
|
|
1442
|
+
id: op.id,
|
|
1443
|
+
modelKey: op.modelKey,
|
|
1444
|
+
naturalKey: op.naturalKey,
|
|
1445
|
+
data: op.data ? sanitizeData(
|
|
1446
|
+
op.data
|
|
1447
|
+
) : void 0,
|
|
1448
|
+
customerId: op.customerId
|
|
1449
|
+
})
|
|
1450
|
+
)
|
|
1451
|
+
})
|
|
1452
|
+
);
|
|
1453
|
+
return resp.results ?? [];
|
|
1454
|
+
},
|
|
1455
|
+
async bulkUpdateRecords(params) {
|
|
1456
|
+
const resp = await client.bulkUpdateRecords(
|
|
1457
|
+
create3(BulkUpdateRecordsRequestSchema, {
|
|
1458
|
+
modelKey: params.modelKey,
|
|
1459
|
+
data: sanitizeData(params.data)
|
|
1460
|
+
})
|
|
1461
|
+
);
|
|
1462
|
+
return { count: resp.count };
|
|
1463
|
+
},
|
|
1464
|
+
// ── Versioning ────────────────────────────────────────────
|
|
1465
|
+
async createVersion(parentId, data, changeDescription) {
|
|
1466
|
+
const resp = await client.createVersion(
|
|
1467
|
+
create3(CreateVersionRequestSchema, {
|
|
1468
|
+
parentId,
|
|
1469
|
+
data: data ? sanitizeData(data) : void 0,
|
|
1470
|
+
changeDescription
|
|
1471
|
+
})
|
|
1472
|
+
);
|
|
1473
|
+
return resp.version ?? null;
|
|
1474
|
+
},
|
|
1475
|
+
async publishVersion(versionId) {
|
|
1476
|
+
const resp = await client.publishVersion(
|
|
1477
|
+
create3(PublishVersionRequestSchema, { versionId })
|
|
1478
|
+
);
|
|
1479
|
+
return resp.record ?? null;
|
|
1480
|
+
},
|
|
1481
|
+
async unpublishRecord(recordId) {
|
|
1482
|
+
const resp = await client.unpublishRecord(
|
|
1483
|
+
create3(UnpublishRecordRequestSchema, { recordId })
|
|
1484
|
+
);
|
|
1485
|
+
return resp.success;
|
|
1486
|
+
},
|
|
1487
|
+
async revertToVersion(versionId) {
|
|
1488
|
+
const resp = await client.revertToVersion(
|
|
1489
|
+
create3(RevertToVersionRequestSchema, { versionId })
|
|
1490
|
+
);
|
|
1491
|
+
return resp.record ?? null;
|
|
1492
|
+
},
|
|
1493
|
+
async listRecordVersions(parentId, params) {
|
|
1494
|
+
const resp = await client.listRecordVersions(
|
|
1495
|
+
create3(ListRecordVersionsRequestSchema, {
|
|
1496
|
+
parentId,
|
|
1497
|
+
limit: params?.limit ?? 50,
|
|
1498
|
+
offset: params?.offset ?? 0
|
|
1499
|
+
})
|
|
1500
|
+
);
|
|
1501
|
+
return {
|
|
1502
|
+
items: resp.versions ?? [],
|
|
1503
|
+
total: resp.total
|
|
1504
|
+
};
|
|
1505
|
+
},
|
|
1506
|
+
async saveContent(params) {
|
|
1507
|
+
const resp = await client.saveContent(
|
|
1508
|
+
create3(SaveContentRequestSchema, {
|
|
1509
|
+
recordId: params.recordId,
|
|
1510
|
+
data: sanitizeData(params.data),
|
|
1511
|
+
variantKey: params.variantKey,
|
|
1512
|
+
changeDescription: params.changeDescription
|
|
1513
|
+
})
|
|
1514
|
+
);
|
|
1515
|
+
return {
|
|
1516
|
+
record: resp.record ?? null,
|
|
1517
|
+
version: resp.version ?? null
|
|
1518
|
+
};
|
|
1519
|
+
},
|
|
1520
|
+
// ── Variants ──────────────────────────────────────────────
|
|
1521
|
+
async createVariant(recordId, variantKey, data) {
|
|
1522
|
+
const resp = await client.createVariant(
|
|
1523
|
+
create3(CreateVariantRequestSchema, {
|
|
1524
|
+
recordId,
|
|
1525
|
+
variantKey,
|
|
1526
|
+
data: data ? sanitizeData(data) : void 0
|
|
1527
|
+
})
|
|
1528
|
+
);
|
|
1529
|
+
return resp.variant ?? null;
|
|
1530
|
+
},
|
|
1531
|
+
async updateVariant(variantId, data) {
|
|
1532
|
+
const resp = await client.updateVariant(
|
|
1533
|
+
create3(UpdateVariantRequestSchema, {
|
|
1534
|
+
variantId,
|
|
1535
|
+
data: sanitizeData(data)
|
|
1536
|
+
})
|
|
1537
|
+
);
|
|
1538
|
+
return resp.variant ?? null;
|
|
1539
|
+
},
|
|
1540
|
+
async deleteVariant(variantId) {
|
|
1541
|
+
const resp = await client.deleteVariant(
|
|
1542
|
+
create3(DeleteVariantRequestSchema, { variantId })
|
|
1543
|
+
);
|
|
1544
|
+
return resp.success;
|
|
1545
|
+
},
|
|
1546
|
+
async setDefaultVariant(recordId, variantId) {
|
|
1547
|
+
const resp = await client.setDefaultVariant(
|
|
1548
|
+
create3(SetDefaultVariantRequestSchema, { recordId, variantId })
|
|
1549
|
+
);
|
|
1550
|
+
return resp.record ?? null;
|
|
1551
|
+
},
|
|
1552
|
+
async listRecordVariants(recordId, params) {
|
|
1553
|
+
const resp = await client.listRecordVariants(
|
|
1554
|
+
create3(ListRecordVariantsRequestSchema, {
|
|
1555
|
+
recordId,
|
|
1556
|
+
limit: params?.limit ?? 50,
|
|
1557
|
+
offset: params?.offset ?? 0
|
|
1558
|
+
})
|
|
1559
|
+
);
|
|
1560
|
+
return {
|
|
1561
|
+
items: resp.variants ?? [],
|
|
1562
|
+
total: resp.total
|
|
1563
|
+
};
|
|
1564
|
+
},
|
|
1565
|
+
// ── Scheduling ────────────────────────────────────────────
|
|
1566
|
+
async scheduleRecordPublish(versionId, publishAt, unpublishAt) {
|
|
1567
|
+
const resp = await client.scheduleRecordPublish(
|
|
1568
|
+
create3(ScheduleRecordPublishRequestSchema, {
|
|
1569
|
+
versionId,
|
|
1570
|
+
publishAt: {
|
|
1571
|
+
seconds: BigInt(Math.floor(publishAt.getTime() / 1e3)),
|
|
1572
|
+
nanos: 0
|
|
1573
|
+
},
|
|
1574
|
+
unpublishAt: unpublishAt ? {
|
|
1575
|
+
seconds: BigInt(Math.floor(unpublishAt.getTime() / 1e3)),
|
|
1576
|
+
nanos: 0
|
|
1577
|
+
} : void 0
|
|
1578
|
+
})
|
|
1579
|
+
);
|
|
1580
|
+
return resp.version ?? null;
|
|
1581
|
+
},
|
|
1582
|
+
async cancelScheduledRecordPublish(versionId) {
|
|
1583
|
+
const resp = await client.cancelScheduledRecordPublish(
|
|
1584
|
+
create3(CancelScheduledRecordPublishRequestSchema, { versionId })
|
|
1585
|
+
);
|
|
1586
|
+
return resp.version ?? null;
|
|
1587
|
+
},
|
|
1588
|
+
async listScheduledPublishes(params) {
|
|
1589
|
+
const resp = await client.listScheduledPublishes(
|
|
1590
|
+
create3(ListScheduledPublishesRequestSchema, {
|
|
1591
|
+
from: params?.from ? {
|
|
1592
|
+
seconds: BigInt(Math.floor(params.from.getTime() / 1e3)),
|
|
1593
|
+
nanos: 0
|
|
1594
|
+
} : void 0,
|
|
1595
|
+
to: params?.to ? {
|
|
1596
|
+
seconds: BigInt(Math.floor(params.to.getTime() / 1e3)),
|
|
1597
|
+
nanos: 0
|
|
1598
|
+
} : void 0,
|
|
1599
|
+
modelKey: params?.modelKey,
|
|
1600
|
+
limit: params?.limit ?? 50,
|
|
1601
|
+
offset: params?.offset ?? 0
|
|
1602
|
+
})
|
|
1603
|
+
);
|
|
1604
|
+
return {
|
|
1605
|
+
items: resp.versions ?? [],
|
|
1606
|
+
total: resp.total
|
|
1607
|
+
};
|
|
1608
|
+
},
|
|
1609
|
+
async listDraftVersions(params) {
|
|
1610
|
+
const resp = await client.listDraftVersions(
|
|
1611
|
+
create3(ListDraftVersionsRequestSchema, {
|
|
1612
|
+
modelKey: params?.modelKey,
|
|
1613
|
+
search: params?.search,
|
|
1614
|
+
limit: params?.limit ?? 50,
|
|
1615
|
+
offset: params?.offset ?? 0
|
|
1616
|
+
})
|
|
1617
|
+
);
|
|
1618
|
+
return {
|
|
1619
|
+
items: resp.versions ?? [],
|
|
1620
|
+
total: resp.total
|
|
1621
|
+
};
|
|
1622
|
+
},
|
|
1623
|
+
// ── Batch Publishing ──────────────────────────────────────
|
|
1624
|
+
async batchPublishVersions(versionIds) {
|
|
1625
|
+
const resp = await client.batchPublishVersions(
|
|
1626
|
+
create3(BatchPublishVersionsRequestSchema, { versionIds })
|
|
1627
|
+
);
|
|
1628
|
+
return {
|
|
1629
|
+
records: resp.records ?? [],
|
|
1630
|
+
publishedCount: resp.publishedCount
|
|
1631
|
+
};
|
|
1632
|
+
},
|
|
1633
|
+
// ── Publish Batches ───────────────────────────────────────
|
|
1634
|
+
async createPublishBatch(params) {
|
|
1635
|
+
const resp = await client.createPublishBatch(
|
|
1636
|
+
create3(CreatePublishBatchRequestSchema, {
|
|
1637
|
+
name: params.name,
|
|
1638
|
+
versionIds: params.versionIds,
|
|
1639
|
+
scheduledAt: params.scheduledAt ? {
|
|
1640
|
+
seconds: BigInt(
|
|
1641
|
+
Math.floor(params.scheduledAt.getTime() / 1e3)
|
|
1642
|
+
),
|
|
1643
|
+
nanos: 0
|
|
1644
|
+
} : void 0
|
|
1645
|
+
})
|
|
1646
|
+
);
|
|
1647
|
+
return resp.batch ?? null;
|
|
1648
|
+
},
|
|
1649
|
+
async updatePublishBatch(params) {
|
|
1650
|
+
const resp = await client.updatePublishBatch(
|
|
1651
|
+
create3(UpdatePublishBatchRequestSchema, {
|
|
1652
|
+
batchId: params.batchId,
|
|
1653
|
+
name: params.name,
|
|
1654
|
+
scheduledAt: params.scheduledAt ? {
|
|
1655
|
+
seconds: BigInt(
|
|
1656
|
+
Math.floor(params.scheduledAt.getTime() / 1e3)
|
|
1657
|
+
),
|
|
1658
|
+
nanos: 0
|
|
1659
|
+
} : void 0
|
|
1660
|
+
})
|
|
1661
|
+
);
|
|
1662
|
+
return resp.batch ?? null;
|
|
1663
|
+
},
|
|
1664
|
+
async cancelPublishBatch(batchId) {
|
|
1665
|
+
const resp = await client.cancelPublishBatch(
|
|
1666
|
+
create3(CancelPublishBatchRequestSchema, { batchId })
|
|
1667
|
+
);
|
|
1668
|
+
return resp.batch ?? null;
|
|
1669
|
+
},
|
|
1670
|
+
async rollbackPublishBatch(batchId) {
|
|
1671
|
+
const resp = await client.rollbackPublishBatch(
|
|
1672
|
+
create3(RollbackPublishBatchRequestSchema, { batchId })
|
|
1673
|
+
);
|
|
1674
|
+
return resp.batch ?? null;
|
|
1675
|
+
},
|
|
1676
|
+
async retryFailedBatchItems(batchId) {
|
|
1677
|
+
const resp = await client.retryFailedBatchItems(
|
|
1678
|
+
create3(RetryFailedBatchItemsRequestSchema, { batchId })
|
|
1679
|
+
);
|
|
1680
|
+
return {
|
|
1681
|
+
batch: resp.batch ?? null,
|
|
1682
|
+
retriedCount: resp.retriedCount
|
|
1683
|
+
};
|
|
1684
|
+
},
|
|
1685
|
+
async addItemsToPublishBatch(batchId, versionIds) {
|
|
1686
|
+
const resp = await client.addItemsToPublishBatch(
|
|
1687
|
+
create3(AddItemsToPublishBatchRequestSchema, { batchId, versionIds })
|
|
1688
|
+
);
|
|
1689
|
+
return resp.batch ?? null;
|
|
1690
|
+
},
|
|
1691
|
+
async removeItemsFromPublishBatch(batchId, versionIds) {
|
|
1692
|
+
const resp = await client.removeItemsFromPublishBatch(
|
|
1693
|
+
create3(RemoveItemsFromPublishBatchRequestSchema, {
|
|
1694
|
+
batchId,
|
|
1695
|
+
versionIds
|
|
1696
|
+
})
|
|
1697
|
+
);
|
|
1698
|
+
return resp.batch ?? null;
|
|
1699
|
+
},
|
|
1700
|
+
async listPublishBatches(params) {
|
|
1701
|
+
const resp = await client.listPublishBatches(
|
|
1702
|
+
create3(ListPublishBatchesRequestSchema, {
|
|
1703
|
+
status: params?.status,
|
|
1704
|
+
from: params?.from ? {
|
|
1705
|
+
seconds: BigInt(Math.floor(params.from.getTime() / 1e3)),
|
|
1706
|
+
nanos: 0
|
|
1707
|
+
} : void 0,
|
|
1708
|
+
to: params?.to ? {
|
|
1709
|
+
seconds: BigInt(Math.floor(params.to.getTime() / 1e3)),
|
|
1710
|
+
nanos: 0
|
|
1711
|
+
} : void 0,
|
|
1712
|
+
limit: params?.limit ?? 50,
|
|
1713
|
+
offset: params?.offset ?? 0
|
|
1714
|
+
})
|
|
1715
|
+
);
|
|
1716
|
+
return {
|
|
1717
|
+
items: resp.batches ?? [],
|
|
1718
|
+
total: resp.total
|
|
1719
|
+
};
|
|
1720
|
+
},
|
|
1721
|
+
async getPublishBatch(batchId) {
|
|
1722
|
+
const resp = await client.getPublishBatch(
|
|
1723
|
+
create3(GetPublishBatchRequestSchema, { batchId })
|
|
1724
|
+
);
|
|
1725
|
+
return {
|
|
1726
|
+
batch: resp.batch ?? null,
|
|
1727
|
+
versions: resp.versions ?? []
|
|
1728
|
+
};
|
|
1729
|
+
},
|
|
1730
|
+
// ── Search & Embeddings ──────────────────────────────────
|
|
1731
|
+
async globalSearch(params) {
|
|
1732
|
+
const resp = await client.globalSearch(
|
|
1733
|
+
create3(GlobalSearchRequestSchema, {
|
|
1734
|
+
query: params.query,
|
|
1735
|
+
modelKeys: params.modelKeys ?? [],
|
|
1736
|
+
limit: params.limit ?? 20
|
|
1737
|
+
})
|
|
1738
|
+
);
|
|
1739
|
+
return {
|
|
1740
|
+
items: resp.records ?? [],
|
|
1741
|
+
total: resp.total
|
|
1742
|
+
};
|
|
1743
|
+
},
|
|
1744
|
+
async getEmbeddingStats(modelKey) {
|
|
1745
|
+
const resp = await client.getEmbeddingStats(
|
|
1746
|
+
create3(GetEmbeddingStatsRequestSchema, {
|
|
1747
|
+
modelKey
|
|
1748
|
+
})
|
|
1749
|
+
);
|
|
1750
|
+
return resp.stats ?? [];
|
|
1751
|
+
},
|
|
1752
|
+
async getRecordEmbeddings(recordId) {
|
|
1753
|
+
const resp = await client.getRecordEmbeddings(
|
|
1754
|
+
create3(GetRecordEmbeddingsRequestSchema, { recordId })
|
|
1755
|
+
);
|
|
1756
|
+
return resp.embeddings ?? [];
|
|
1757
|
+
},
|
|
1758
|
+
async findSimilarRecords(params) {
|
|
1759
|
+
const resp = await client.findSimilarRecords(
|
|
1760
|
+
create3(FindSimilarRecordsRequestSchema, {
|
|
1761
|
+
recordId: params.recordId,
|
|
1762
|
+
modelKey: params.modelKey,
|
|
1763
|
+
limit: params.limit ?? 10
|
|
1764
|
+
})
|
|
1765
|
+
);
|
|
1766
|
+
return resp.records ?? [];
|
|
1767
|
+
}
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
// src/lib/rpc/configs.ts
|
|
1772
|
+
import { create as create4 } from "@bufbuild/protobuf";
|
|
1773
|
+
import {
|
|
1774
|
+
CreateConfigRequestSchema,
|
|
1775
|
+
GetConfigRequestSchema,
|
|
1776
|
+
GetConfigByKeyRequestSchema,
|
|
1777
|
+
ListConfigsRequestSchema,
|
|
1778
|
+
UpdateConfigRequestSchema,
|
|
1779
|
+
DeleteConfigRequestSchema,
|
|
1780
|
+
ConfigDirection,
|
|
1781
|
+
ListOperationsRequestSchema,
|
|
1782
|
+
ApplyConfigRequestSchema
|
|
1783
|
+
} from "@eide/foir-proto-ts/configs/v1/configs_pb";
|
|
1784
|
+
import { ConfigDirection as ConfigDirection2 } from "@eide/foir-proto-ts/configs/v1/configs_pb";
|
|
1785
|
+
var DIRECTION_TO_PROTO = {
|
|
1786
|
+
read: ConfigDirection.READ,
|
|
1787
|
+
write: ConfigDirection.WRITE,
|
|
1788
|
+
bidirectional: ConfigDirection.BIDIRECTIONAL
|
|
1789
|
+
};
|
|
1790
|
+
function createConfigsMethods(client) {
|
|
1791
|
+
return {
|
|
1792
|
+
// ── Operations ────────────────────────────────────────────
|
|
1793
|
+
async listOperations(params = {}) {
|
|
1794
|
+
return client.listOperations(
|
|
1795
|
+
create4(ListOperationsRequestSchema, {
|
|
1796
|
+
category: params.category,
|
|
1797
|
+
isActive: params.isActive,
|
|
1798
|
+
search: params.search,
|
|
1799
|
+
limit: params.limit ?? 50,
|
|
1800
|
+
offset: params.offset ?? 0
|
|
1801
|
+
})
|
|
1802
|
+
);
|
|
1803
|
+
},
|
|
1804
|
+
// ── Queries ──────────────────────────────────────────────
|
|
1805
|
+
async getConfig(id) {
|
|
1806
|
+
const resp = await client.getConfig(
|
|
1807
|
+
create4(GetConfigRequestSchema, { id })
|
|
1808
|
+
);
|
|
1809
|
+
return resp.config ?? null;
|
|
1810
|
+
},
|
|
1811
|
+
async getConfigByKey(key) {
|
|
1812
|
+
const resp = await client.getConfigByKey(
|
|
1813
|
+
create4(GetConfigByKeyRequestSchema, { key })
|
|
1814
|
+
);
|
|
1815
|
+
return resp.config ?? null;
|
|
1816
|
+
},
|
|
1817
|
+
async listConfigs(params = {}) {
|
|
1818
|
+
return client.listConfigs(
|
|
1819
|
+
create4(ListConfigsRequestSchema, {
|
|
1820
|
+
configType: params.configType,
|
|
1821
|
+
enabled: params.enabled,
|
|
1822
|
+
limit: params.limit ?? 50,
|
|
1823
|
+
offset: params.offset ?? 0
|
|
1824
|
+
})
|
|
1825
|
+
);
|
|
1826
|
+
},
|
|
1827
|
+
// ── Mutations ────────────────────────────────────────────
|
|
1828
|
+
async createConfig(params) {
|
|
1829
|
+
const resp = await client.createConfig(
|
|
1830
|
+
create4(CreateConfigRequestSchema, {
|
|
1831
|
+
key: params.key,
|
|
1832
|
+
configType: params.configType,
|
|
1833
|
+
direction: DIRECTION_TO_PROTO[params.direction ?? "read"] ?? ConfigDirection.READ,
|
|
1834
|
+
name: params.name,
|
|
1835
|
+
description: params.description,
|
|
1836
|
+
config: params.config,
|
|
1837
|
+
enabled: params.enabled
|
|
1838
|
+
})
|
|
1839
|
+
);
|
|
1840
|
+
return resp.config ?? null;
|
|
1841
|
+
},
|
|
1842
|
+
async updateConfig(params) {
|
|
1843
|
+
const resp = await client.updateConfig(
|
|
1844
|
+
create4(UpdateConfigRequestSchema, {
|
|
1845
|
+
id: params.id,
|
|
1846
|
+
name: params.name,
|
|
1847
|
+
description: params.description,
|
|
1848
|
+
config: params.config,
|
|
1849
|
+
enabled: params.enabled,
|
|
1850
|
+
webhooks: params.webhooks,
|
|
1851
|
+
hooks: params.hooks
|
|
1852
|
+
})
|
|
1853
|
+
);
|
|
1854
|
+
return resp.config ?? null;
|
|
1855
|
+
},
|
|
1856
|
+
async applyConfig(configKey, configData) {
|
|
1857
|
+
const resp = await client.applyConfig(
|
|
1858
|
+
create4(ApplyConfigRequestSchema, {
|
|
1859
|
+
configKey,
|
|
1860
|
+
configData
|
|
1861
|
+
})
|
|
1862
|
+
);
|
|
1863
|
+
return resp.config ?? null;
|
|
1864
|
+
},
|
|
1865
|
+
async deleteConfig(id) {
|
|
1866
|
+
const resp = await client.deleteConfig(
|
|
1867
|
+
create4(DeleteConfigRequestSchema, { id })
|
|
1868
|
+
);
|
|
1869
|
+
return resp.success;
|
|
1870
|
+
}
|
|
1871
|
+
};
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
// src/lib/rpc/segments.ts
|
|
1875
|
+
import { create as create5 } from "@bufbuild/protobuf";
|
|
1876
|
+
import {
|
|
1877
|
+
CreateSegmentRequestSchema,
|
|
1878
|
+
GetSegmentRequestSchema,
|
|
1879
|
+
GetSegmentByKeyRequestSchema,
|
|
1880
|
+
ListSegmentsRequestSchema,
|
|
1881
|
+
UpdateSegmentRequestSchema,
|
|
1882
|
+
DeleteSegmentRequestSchema,
|
|
1883
|
+
GetCustomerMembershipsRequestSchema,
|
|
1884
|
+
PreviewSegmentRulesRequestSchema,
|
|
1885
|
+
TestSegmentEvaluationRequestSchema,
|
|
1886
|
+
SetGlobalOptOutRequestSchema,
|
|
1887
|
+
OptOutOfSegmentRequestSchema,
|
|
1888
|
+
OptBackIntoSegmentRequestSchema
|
|
1889
|
+
} from "@eide/foir-proto-ts/segments/v1/segments_pb";
|
|
1890
|
+
function createSegmentsMethods(client) {
|
|
1891
|
+
return {
|
|
1892
|
+
// ── Queries ──────────────────────────────────────────────
|
|
1893
|
+
async getSegment(id) {
|
|
1894
|
+
const resp = await client.getSegment(
|
|
1895
|
+
create5(GetSegmentRequestSchema, { id })
|
|
1896
|
+
);
|
|
1897
|
+
return resp.segment ?? null;
|
|
1898
|
+
},
|
|
1899
|
+
async getSegmentByKey(key) {
|
|
1900
|
+
const resp = await client.getSegmentByKey(
|
|
1901
|
+
create5(GetSegmentByKeyRequestSchema, { key })
|
|
1902
|
+
);
|
|
1903
|
+
return resp.segment ?? null;
|
|
1904
|
+
},
|
|
1905
|
+
async listSegments(params = {}) {
|
|
1906
|
+
return client.listSegments(
|
|
1907
|
+
create5(ListSegmentsRequestSchema, {
|
|
1908
|
+
isActive: params.isActive,
|
|
1909
|
+
limit: params.limit ?? 50,
|
|
1910
|
+
offset: params.offset ?? 0
|
|
1911
|
+
})
|
|
1912
|
+
);
|
|
1913
|
+
},
|
|
1914
|
+
// ── Mutations ────────────────────────────────────────────
|
|
1915
|
+
async createSegment(params) {
|
|
1916
|
+
const resp = await client.createSegment(
|
|
1917
|
+
create5(CreateSegmentRequestSchema, {
|
|
1918
|
+
key: params.key,
|
|
1919
|
+
name: params.name,
|
|
1920
|
+
description: params.description,
|
|
1921
|
+
rules: params.rules,
|
|
1922
|
+
evaluationMode: params.evaluationMode,
|
|
1923
|
+
isActive: params.isActive
|
|
1924
|
+
})
|
|
1925
|
+
);
|
|
1926
|
+
return resp.segment ?? null;
|
|
1927
|
+
},
|
|
1928
|
+
async updateSegment(params) {
|
|
1929
|
+
const resp = await client.updateSegment(
|
|
1930
|
+
create5(UpdateSegmentRequestSchema, {
|
|
1931
|
+
id: params.id,
|
|
1932
|
+
name: params.name,
|
|
1933
|
+
description: params.description,
|
|
1934
|
+
rules: params.rules,
|
|
1935
|
+
evaluationMode: params.evaluationMode,
|
|
1936
|
+
isActive: params.isActive
|
|
1937
|
+
})
|
|
1938
|
+
);
|
|
1939
|
+
return resp.segment ?? null;
|
|
1940
|
+
},
|
|
1941
|
+
async deleteSegment(id) {
|
|
1942
|
+
const resp = await client.deleteSegment(
|
|
1943
|
+
create5(DeleteSegmentRequestSchema, { id })
|
|
1944
|
+
);
|
|
1945
|
+
return resp.success;
|
|
1946
|
+
},
|
|
1947
|
+
// ── Customer Operations ──────────────────────────────────
|
|
1948
|
+
async getCustomerMemberships(customerId) {
|
|
1949
|
+
return client.getCustomerMemberships(
|
|
1950
|
+
create5(GetCustomerMembershipsRequestSchema, { customerId })
|
|
1951
|
+
);
|
|
1952
|
+
},
|
|
1953
|
+
async previewSegmentRules(rules, sampleSize) {
|
|
1954
|
+
const resp = await client.previewSegmentRules(
|
|
1955
|
+
create5(PreviewSegmentRulesRequestSchema, {
|
|
1956
|
+
rules,
|
|
1957
|
+
sampleSize: sampleSize ?? 10
|
|
1958
|
+
})
|
|
1959
|
+
);
|
|
1960
|
+
return resp.preview ?? null;
|
|
1961
|
+
},
|
|
1962
|
+
async testSegmentEvaluation(segmentId, customerId) {
|
|
1963
|
+
const resp = await client.testSegmentEvaluation(
|
|
1964
|
+
create5(TestSegmentEvaluationRequestSchema, { segmentId, customerId })
|
|
1965
|
+
);
|
|
1966
|
+
return resp.result ?? null;
|
|
1967
|
+
},
|
|
1968
|
+
// ── Opt-out Management ───────────────────────────────────
|
|
1969
|
+
async setGlobalOptOut(customerId, optedOut) {
|
|
1970
|
+
const resp = await client.setGlobalOptOut(
|
|
1971
|
+
create5(SetGlobalOptOutRequestSchema, { customerId, optedOut })
|
|
1972
|
+
);
|
|
1973
|
+
return resp.success;
|
|
1974
|
+
},
|
|
1975
|
+
async optOutOfSegment(customerId, segmentId) {
|
|
1976
|
+
const resp = await client.optOutOfSegment(
|
|
1977
|
+
create5(OptOutOfSegmentRequestSchema, { customerId, segmentId })
|
|
1978
|
+
);
|
|
1979
|
+
return resp.success;
|
|
1980
|
+
},
|
|
1981
|
+
async optBackIntoSegment(customerId, segmentId) {
|
|
1982
|
+
const resp = await client.optBackIntoSegment(
|
|
1983
|
+
create5(OptBackIntoSegmentRequestSchema, { customerId, segmentId })
|
|
1984
|
+
);
|
|
1985
|
+
return resp.success;
|
|
1986
|
+
}
|
|
1987
|
+
};
|
|
423
1988
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
1989
|
+
|
|
1990
|
+
// src/lib/rpc/experiments.ts
|
|
1991
|
+
import { create as create6 } from "@bufbuild/protobuf";
|
|
1992
|
+
import {
|
|
1993
|
+
ExperimentStatus,
|
|
1994
|
+
CreateExperimentRequestSchema,
|
|
1995
|
+
GetExperimentRequestSchema,
|
|
1996
|
+
GetExperimentByKeyRequestSchema,
|
|
1997
|
+
ListExperimentsRequestSchema,
|
|
1998
|
+
UpdateExperimentRequestSchema,
|
|
1999
|
+
DeleteExperimentRequestSchema,
|
|
2000
|
+
StartExperimentRequestSchema,
|
|
2001
|
+
PauseExperimentRequestSchema,
|
|
2002
|
+
ResumeExperimentRequestSchema,
|
|
2003
|
+
EndExperimentRequestSchema,
|
|
2004
|
+
GetExperimentStatsRequestSchema,
|
|
2005
|
+
ForceAssignExperimentRequestSchema,
|
|
2006
|
+
RemoveExperimentAssignmentRequestSchema,
|
|
2007
|
+
ApplyExperimentWinnerRequestSchema,
|
|
2008
|
+
GetCustomerAssignmentsRequestSchema,
|
|
2009
|
+
ExperimentVariantSchema
|
|
2010
|
+
} from "@eide/foir-proto-ts/experiments/v1/experiments_pb";
|
|
2011
|
+
import { ExperimentStatus as ExperimentStatus2 } from "@eide/foir-proto-ts/experiments/v1/experiments_pb";
|
|
2012
|
+
var STATUS_TO_PROTO = {
|
|
2013
|
+
draft: ExperimentStatus.DRAFT,
|
|
2014
|
+
running: ExperimentStatus.RUNNING,
|
|
2015
|
+
paused: ExperimentStatus.PAUSED,
|
|
2016
|
+
ended: ExperimentStatus.COMPLETED,
|
|
2017
|
+
completed: ExperimentStatus.COMPLETED
|
|
2018
|
+
};
|
|
2019
|
+
function createExperimentsMethods(client) {
|
|
2020
|
+
return {
|
|
2021
|
+
// ── Queries ──────────────────────────────────────────────
|
|
2022
|
+
async getExperiment(id) {
|
|
2023
|
+
const resp = await client.getExperiment(
|
|
2024
|
+
create6(GetExperimentRequestSchema, { id })
|
|
2025
|
+
);
|
|
2026
|
+
return resp.experiment ?? null;
|
|
2027
|
+
},
|
|
2028
|
+
async getExperimentByKey(key) {
|
|
2029
|
+
const resp = await client.getExperimentByKey(
|
|
2030
|
+
create6(GetExperimentByKeyRequestSchema, { key })
|
|
2031
|
+
);
|
|
2032
|
+
return resp.experiment ?? null;
|
|
2033
|
+
},
|
|
2034
|
+
async listExperiments(params = {}) {
|
|
2035
|
+
return client.listExperiments(
|
|
2036
|
+
create6(ListExperimentsRequestSchema, {
|
|
2037
|
+
status: params.status ? STATUS_TO_PROTO[params.status] : void 0,
|
|
2038
|
+
isActive: params.isActive,
|
|
2039
|
+
limit: params.limit ?? 50,
|
|
2040
|
+
offset: params.offset ?? 0
|
|
2041
|
+
})
|
|
2042
|
+
);
|
|
2043
|
+
},
|
|
2044
|
+
async getExperimentStats(experimentId) {
|
|
2045
|
+
const resp = await client.getExperimentStats(
|
|
2046
|
+
create6(GetExperimentStatsRequestSchema, { experimentId })
|
|
2047
|
+
);
|
|
2048
|
+
return resp.stats ?? null;
|
|
2049
|
+
},
|
|
2050
|
+
// ── Mutations ────────────────────────────────────────────
|
|
2051
|
+
async createExperiment(params) {
|
|
2052
|
+
const resp = await client.createExperiment(
|
|
2053
|
+
create6(CreateExperimentRequestSchema, {
|
|
2054
|
+
key: params.key,
|
|
2055
|
+
name: params.name,
|
|
2056
|
+
description: params.description,
|
|
2057
|
+
targeting: params.targeting,
|
|
2058
|
+
controlPercent: params.controlPercent,
|
|
2059
|
+
variants: params.variants?.map(
|
|
2060
|
+
(v) => create6(ExperimentVariantSchema, {
|
|
2061
|
+
key: v.key,
|
|
2062
|
+
name: v.name,
|
|
2063
|
+
percent: v.percent
|
|
2064
|
+
})
|
|
2065
|
+
) ?? []
|
|
2066
|
+
})
|
|
2067
|
+
);
|
|
2068
|
+
return resp.experiment ?? null;
|
|
2069
|
+
},
|
|
2070
|
+
async updateExperiment(params) {
|
|
2071
|
+
const resp = await client.updateExperiment(
|
|
2072
|
+
create6(UpdateExperimentRequestSchema, {
|
|
2073
|
+
id: params.id,
|
|
2074
|
+
name: params.name,
|
|
2075
|
+
description: params.description,
|
|
2076
|
+
targeting: params.targeting,
|
|
2077
|
+
controlPercent: params.controlPercent,
|
|
2078
|
+
variants: params.variants?.map(
|
|
2079
|
+
(v) => create6(ExperimentVariantSchema, {
|
|
2080
|
+
key: v.key,
|
|
2081
|
+
name: v.name,
|
|
2082
|
+
percent: v.percent
|
|
2083
|
+
})
|
|
2084
|
+
)
|
|
2085
|
+
})
|
|
2086
|
+
);
|
|
2087
|
+
return resp.experiment ?? null;
|
|
2088
|
+
},
|
|
2089
|
+
async deleteExperiment(id) {
|
|
2090
|
+
const resp = await client.deleteExperiment(
|
|
2091
|
+
create6(DeleteExperimentRequestSchema, { id })
|
|
2092
|
+
);
|
|
2093
|
+
return resp.success;
|
|
2094
|
+
},
|
|
2095
|
+
// ── Lifecycle ────────────────────────────────────────────
|
|
2096
|
+
async startExperiment(experimentId) {
|
|
2097
|
+
const resp = await client.startExperiment(
|
|
2098
|
+
create6(StartExperimentRequestSchema, { experimentId })
|
|
2099
|
+
);
|
|
2100
|
+
return resp.experiment ?? null;
|
|
2101
|
+
},
|
|
2102
|
+
async pauseExperiment(experimentId) {
|
|
2103
|
+
const resp = await client.pauseExperiment(
|
|
2104
|
+
create6(PauseExperimentRequestSchema, { experimentId })
|
|
2105
|
+
);
|
|
2106
|
+
return resp.experiment ?? null;
|
|
2107
|
+
},
|
|
2108
|
+
async resumeExperiment(experimentId) {
|
|
2109
|
+
const resp = await client.resumeExperiment(
|
|
2110
|
+
create6(ResumeExperimentRequestSchema, { experimentId })
|
|
2111
|
+
);
|
|
2112
|
+
return resp.experiment ?? null;
|
|
2113
|
+
},
|
|
2114
|
+
async endExperiment(experimentId) {
|
|
2115
|
+
const resp = await client.endExperiment(
|
|
2116
|
+
create6(EndExperimentRequestSchema, { experimentId })
|
|
2117
|
+
);
|
|
2118
|
+
return resp.experiment ?? null;
|
|
2119
|
+
},
|
|
2120
|
+
async applyExperimentWinner(experimentId, winnerVariantKey) {
|
|
2121
|
+
const resp = await client.applyExperimentWinner(
|
|
2122
|
+
create6(ApplyExperimentWinnerRequestSchema, {
|
|
2123
|
+
experimentId,
|
|
2124
|
+
winnerVariantKey
|
|
2125
|
+
})
|
|
2126
|
+
);
|
|
2127
|
+
return resp.experiment ?? null;
|
|
2128
|
+
},
|
|
2129
|
+
// ── Assignments ──────────────────────────────────────────
|
|
2130
|
+
async forceAssignExperiment(customerId, experimentId, variantKey) {
|
|
2131
|
+
const resp = await client.forceAssignExperiment(
|
|
2132
|
+
create6(ForceAssignExperimentRequestSchema, {
|
|
2133
|
+
customerId,
|
|
2134
|
+
experimentId,
|
|
2135
|
+
variantKey
|
|
2136
|
+
})
|
|
2137
|
+
);
|
|
2138
|
+
return resp.assignment ?? null;
|
|
2139
|
+
},
|
|
2140
|
+
async removeExperimentAssignment(customerId, experimentId) {
|
|
2141
|
+
const resp = await client.removeExperimentAssignment(
|
|
2142
|
+
create6(RemoveExperimentAssignmentRequestSchema, {
|
|
2143
|
+
customerId,
|
|
2144
|
+
experimentId
|
|
2145
|
+
})
|
|
2146
|
+
);
|
|
2147
|
+
return resp.success;
|
|
2148
|
+
},
|
|
2149
|
+
async getCustomerAssignments(customerId) {
|
|
2150
|
+
const resp = await client.getCustomerAssignments(
|
|
2151
|
+
create6(GetCustomerAssignmentsRequestSchema, { customerId })
|
|
2152
|
+
);
|
|
2153
|
+
return resp.assignments ?? [];
|
|
2154
|
+
}
|
|
2155
|
+
};
|
|
430
2156
|
}
|
|
431
2157
|
|
|
432
|
-
// src/
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
2158
|
+
// src/lib/rpc/settings.ts
|
|
2159
|
+
import { create as create7 } from "@bufbuild/protobuf";
|
|
2160
|
+
import {
|
|
2161
|
+
GetSettingsRequestSchema,
|
|
2162
|
+
UpdateSettingRequestSchema,
|
|
2163
|
+
ListContextDimensionsRequestSchema,
|
|
2164
|
+
GetContextDimensionRequestSchema,
|
|
2165
|
+
CreateContextDimensionRequestSchema,
|
|
2166
|
+
UpdateContextDimensionRequestSchema,
|
|
2167
|
+
DeleteContextDimensionRequestSchema,
|
|
2168
|
+
GetContextDimensionValuesRequestSchema,
|
|
2169
|
+
GetCustomerProfileSchemaRequestSchema,
|
|
2170
|
+
GetCustomerProfileRequestSchema,
|
|
2171
|
+
SetCustomerProfileRequestSchema,
|
|
2172
|
+
UpdateCustomerProfileSchemaRequestSchema,
|
|
2173
|
+
GetCustomerResolutionAttributesRequestSchema,
|
|
2174
|
+
GetEditorConfigsRequestSchema,
|
|
2175
|
+
ListEmailActionsRequestSchema,
|
|
2176
|
+
ListResendTemplatesRequestSchema,
|
|
2177
|
+
UpdateEmailActionRequestSchema,
|
|
2178
|
+
ListVariantCatalogRequestSchema,
|
|
2179
|
+
GetVariantCatalogEntryRequestSchema,
|
|
2180
|
+
CreateVariantCatalogEntryRequestSchema,
|
|
2181
|
+
UpdateVariantCatalogEntryRequestSchema,
|
|
2182
|
+
DeleteVariantCatalogEntryRequestSchema,
|
|
2183
|
+
CreateNoteRequestSchema,
|
|
2184
|
+
GetNoteRequestSchema,
|
|
2185
|
+
ListNotesRequestSchema,
|
|
2186
|
+
UpdateNoteRequestSchema,
|
|
2187
|
+
DeleteNoteRequestSchema,
|
|
2188
|
+
ListMyMentionsRequestSchema,
|
|
2189
|
+
UpdateMentionStatusRequestSchema,
|
|
2190
|
+
ListLocalesRequestSchema,
|
|
2191
|
+
GetLocaleRequestSchema,
|
|
2192
|
+
CreateLocaleRequestSchema,
|
|
2193
|
+
UpdateLocaleRequestSchema,
|
|
2194
|
+
DeleteLocaleRequestSchema,
|
|
2195
|
+
GetNavPreferencesRequestSchema,
|
|
2196
|
+
UpdateNavPreferencesRequestSchema,
|
|
2197
|
+
ListRecentlyOpenedRequestSchema,
|
|
2198
|
+
TrackRecentlyOpenedRequestSchema,
|
|
2199
|
+
RemoveRecentlyOpenedRequestSchema,
|
|
2200
|
+
ClearRecentlyOpenedRequestSchema
|
|
2201
|
+
} from "@eide/foir-proto-ts/settings/v1/settings_pb";
|
|
2202
|
+
function createSettingsMethods(client) {
|
|
2203
|
+
return {
|
|
2204
|
+
// ── Settings ─────────────────────────────────────────────
|
|
2205
|
+
async getSettings(params = {}) {
|
|
2206
|
+
const resp = await client.getSettings(
|
|
2207
|
+
create7(GetSettingsRequestSchema, {
|
|
2208
|
+
category: params.category,
|
|
2209
|
+
key: params.key
|
|
2210
|
+
})
|
|
2211
|
+
);
|
|
2212
|
+
return resp.settings ?? [];
|
|
2213
|
+
},
|
|
2214
|
+
async updateSetting(params) {
|
|
2215
|
+
const resp = await client.updateSetting(
|
|
2216
|
+
create7(UpdateSettingRequestSchema, {
|
|
2217
|
+
key: params.key,
|
|
2218
|
+
value: params.value
|
|
2219
|
+
})
|
|
2220
|
+
);
|
|
2221
|
+
return resp.setting ?? null;
|
|
2222
|
+
},
|
|
2223
|
+
// ── Mentions ─────────────────────────────────────────────
|
|
2224
|
+
async listMyMentions(params = {}) {
|
|
2225
|
+
return client.listMyMentions(
|
|
2226
|
+
create7(ListMyMentionsRequestSchema, {
|
|
2227
|
+
status: params.status ?? [],
|
|
2228
|
+
entityType: params.entityType,
|
|
2229
|
+
limit: params.limit ?? 50,
|
|
2230
|
+
offset: params.offset ?? 0
|
|
2231
|
+
})
|
|
2232
|
+
);
|
|
2233
|
+
},
|
|
2234
|
+
async updateMentionStatus(params) {
|
|
2235
|
+
const resp = await client.updateMentionStatus(
|
|
2236
|
+
create7(UpdateMentionStatusRequestSchema, {
|
|
2237
|
+
mentionId: params.mentionId,
|
|
2238
|
+
status: params.status,
|
|
2239
|
+
completedNote: params.completedNote,
|
|
2240
|
+
dismissReason: params.dismissReason
|
|
2241
|
+
})
|
|
2242
|
+
);
|
|
2243
|
+
return resp.mention ?? null;
|
|
2244
|
+
},
|
|
2245
|
+
// ── Notes ────────────────────────────────────────────────
|
|
2246
|
+
async createNote(params) {
|
|
2247
|
+
const resp = await client.createNote(
|
|
2248
|
+
create7(CreateNoteRequestSchema, {
|
|
2249
|
+
...params,
|
|
2250
|
+
content: params.content
|
|
2251
|
+
})
|
|
2252
|
+
);
|
|
2253
|
+
return resp.note ?? null;
|
|
2254
|
+
},
|
|
2255
|
+
async getNote(id) {
|
|
2256
|
+
const resp = await client.getNote(create7(GetNoteRequestSchema, { id }));
|
|
2257
|
+
return resp.note ?? null;
|
|
2258
|
+
},
|
|
2259
|
+
async listNotes(params) {
|
|
2260
|
+
return client.listNotes(
|
|
2261
|
+
create7(ListNotesRequestSchema, {
|
|
2262
|
+
entityType: params.entityType,
|
|
2263
|
+
entityId: params.entityId,
|
|
2264
|
+
limit: params.limit ?? 50,
|
|
2265
|
+
offset: params.offset ?? 0
|
|
2266
|
+
})
|
|
2267
|
+
);
|
|
2268
|
+
},
|
|
2269
|
+
async updateNote(params) {
|
|
2270
|
+
const resp = await client.updateNote(
|
|
2271
|
+
create7(UpdateNoteRequestSchema, {
|
|
2272
|
+
id: params.id,
|
|
2273
|
+
content: params.content,
|
|
2274
|
+
isResolved: params.isResolved
|
|
2275
|
+
})
|
|
2276
|
+
);
|
|
2277
|
+
return resp.note ?? null;
|
|
2278
|
+
},
|
|
2279
|
+
async deleteNote(id) {
|
|
2280
|
+
const resp = await client.deleteNote(
|
|
2281
|
+
create7(DeleteNoteRequestSchema, { id })
|
|
2282
|
+
);
|
|
2283
|
+
return resp.success;
|
|
2284
|
+
},
|
|
2285
|
+
// ── Context Dimensions ───────────────────────────────────
|
|
2286
|
+
async listContextDimensions(params = {}) {
|
|
2287
|
+
return client.listContextDimensions(
|
|
2288
|
+
create7(ListContextDimensionsRequestSchema, {
|
|
2289
|
+
search: params.search,
|
|
2290
|
+
limit: params.limit ?? 50,
|
|
2291
|
+
offset: params.offset ?? 0
|
|
2292
|
+
})
|
|
2293
|
+
);
|
|
2294
|
+
},
|
|
2295
|
+
async getContextDimension(id) {
|
|
2296
|
+
const resp = await client.getContextDimension(
|
|
2297
|
+
create7(GetContextDimensionRequestSchema, { id })
|
|
2298
|
+
);
|
|
2299
|
+
return resp.dimension ?? null;
|
|
2300
|
+
},
|
|
2301
|
+
async createContextDimension(params) {
|
|
2302
|
+
const resp = await client.createContextDimension(
|
|
2303
|
+
create7(CreateContextDimensionRequestSchema, params)
|
|
2304
|
+
);
|
|
2305
|
+
return resp.dimension ?? null;
|
|
2306
|
+
},
|
|
2307
|
+
async updateContextDimension(params) {
|
|
2308
|
+
const resp = await client.updateContextDimension(
|
|
2309
|
+
create7(UpdateContextDimensionRequestSchema, params)
|
|
2310
|
+
);
|
|
2311
|
+
return resp.dimension ?? null;
|
|
2312
|
+
},
|
|
2313
|
+
async deleteContextDimension(id) {
|
|
2314
|
+
const resp = await client.deleteContextDimension(
|
|
2315
|
+
create7(DeleteContextDimensionRequestSchema, { id })
|
|
2316
|
+
);
|
|
2317
|
+
return resp.success;
|
|
2318
|
+
},
|
|
2319
|
+
async getContextDimensionValues(dimensionKey, params = {}) {
|
|
2320
|
+
return client.getContextDimensionValues(
|
|
2321
|
+
create7(GetContextDimensionValuesRequestSchema, {
|
|
2322
|
+
dimensionKey,
|
|
2323
|
+
search: params.search,
|
|
2324
|
+
limit: params.limit ?? 50,
|
|
2325
|
+
offset: params.offset ?? 0
|
|
2326
|
+
})
|
|
2327
|
+
);
|
|
2328
|
+
},
|
|
2329
|
+
// ── Customer Profile Schema ──────────────────────────────
|
|
2330
|
+
async getCustomerProfileSchema() {
|
|
2331
|
+
const resp = await client.getCustomerProfileSchema(
|
|
2332
|
+
create7(GetCustomerProfileSchemaRequestSchema, {})
|
|
2333
|
+
);
|
|
2334
|
+
return resp.schema ?? null;
|
|
2335
|
+
},
|
|
2336
|
+
async getCustomerProfile(customerId) {
|
|
2337
|
+
const resp = await client.getCustomerProfile(
|
|
2338
|
+
create7(GetCustomerProfileRequestSchema, { customerId })
|
|
2339
|
+
);
|
|
2340
|
+
return resp.data ?? null;
|
|
2341
|
+
},
|
|
2342
|
+
async setCustomerProfile(params) {
|
|
2343
|
+
const resp = await client.setCustomerProfile(
|
|
2344
|
+
create7(SetCustomerProfileRequestSchema, {
|
|
2345
|
+
customerId: params.customerId,
|
|
2346
|
+
data: params.data
|
|
2347
|
+
})
|
|
2348
|
+
);
|
|
2349
|
+
return resp.success;
|
|
2350
|
+
},
|
|
2351
|
+
async updateCustomerProfileSchema(params) {
|
|
2352
|
+
const resp = await client.updateCustomerProfileSchema(
|
|
2353
|
+
create7(UpdateCustomerProfileSchemaRequestSchema, {
|
|
2354
|
+
fields: params.fields.map((f) => ({
|
|
2355
|
+
id: f.id,
|
|
2356
|
+
key: f.key,
|
|
2357
|
+
type: f.type,
|
|
2358
|
+
label: f.label,
|
|
2359
|
+
required: f.required,
|
|
2360
|
+
helpText: f.helpText,
|
|
2361
|
+
placeholder: f.placeholder,
|
|
2362
|
+
config: f.config
|
|
2363
|
+
})),
|
|
2364
|
+
publicFields: params.publicFields
|
|
2365
|
+
})
|
|
2366
|
+
);
|
|
2367
|
+
return resp.schema ?? null;
|
|
2368
|
+
},
|
|
2369
|
+
async getCustomerResolutionAttributes(customerId) {
|
|
2370
|
+
return client.getCustomerResolutionAttributes(
|
|
2371
|
+
create7(GetCustomerResolutionAttributesRequestSchema, { customerId })
|
|
2372
|
+
);
|
|
2373
|
+
},
|
|
2374
|
+
async getEditorConfigs(modelKey) {
|
|
2375
|
+
const resp = await client.getEditorConfigs(
|
|
2376
|
+
create7(GetEditorConfigsRequestSchema, { modelKey })
|
|
2377
|
+
);
|
|
2378
|
+
return resp.placements ?? [];
|
|
2379
|
+
},
|
|
2380
|
+
// ── Variant Catalog ──────────────────────────────────────
|
|
2381
|
+
async listVariantCatalog(params = {}) {
|
|
2382
|
+
return client.listVariantCatalog(
|
|
2383
|
+
create7(ListVariantCatalogRequestSchema, {
|
|
2384
|
+
isActive: params.isActive,
|
|
2385
|
+
limit: params.limit ?? 50,
|
|
2386
|
+
offset: params.offset ?? 0
|
|
2387
|
+
})
|
|
2388
|
+
);
|
|
2389
|
+
},
|
|
2390
|
+
async getVariantCatalogEntry(id) {
|
|
2391
|
+
const resp = await client.getVariantCatalogEntry(
|
|
2392
|
+
create7(GetVariantCatalogEntryRequestSchema, { id })
|
|
2393
|
+
);
|
|
2394
|
+
return resp.entry ?? null;
|
|
2395
|
+
},
|
|
2396
|
+
async createVariantCatalogEntry(params) {
|
|
2397
|
+
const resp = await client.createVariantCatalogEntry(
|
|
2398
|
+
create7(CreateVariantCatalogEntryRequestSchema, {
|
|
2399
|
+
key: params.key,
|
|
2400
|
+
name: params.name,
|
|
2401
|
+
description: params.description,
|
|
2402
|
+
targetingRules: params.targetingRules,
|
|
2403
|
+
priority: params.priority,
|
|
2404
|
+
isDefault: params.isDefault,
|
|
2405
|
+
isActive: params.isActive
|
|
2406
|
+
})
|
|
2407
|
+
);
|
|
2408
|
+
return resp.entry ?? null;
|
|
2409
|
+
},
|
|
2410
|
+
async updateVariantCatalogEntry(params) {
|
|
2411
|
+
const resp = await client.updateVariantCatalogEntry(
|
|
2412
|
+
create7(UpdateVariantCatalogEntryRequestSchema, {
|
|
2413
|
+
id: params.id,
|
|
2414
|
+
name: params.name,
|
|
2415
|
+
description: params.description,
|
|
2416
|
+
targetingRules: params.targetingRules,
|
|
2417
|
+
priority: params.priority,
|
|
2418
|
+
isDefault: params.isDefault,
|
|
2419
|
+
isActive: params.isActive
|
|
2420
|
+
})
|
|
2421
|
+
);
|
|
2422
|
+
return resp.entry ?? null;
|
|
2423
|
+
},
|
|
2424
|
+
async deleteVariantCatalogEntry(id) {
|
|
2425
|
+
const resp = await client.deleteVariantCatalogEntry(
|
|
2426
|
+
create7(DeleteVariantCatalogEntryRequestSchema, { id })
|
|
2427
|
+
);
|
|
2428
|
+
return resp.success;
|
|
2429
|
+
},
|
|
2430
|
+
// ── Locales ──────────────────────────────────────────────
|
|
2431
|
+
async listLocales(params = {}) {
|
|
2432
|
+
return client.listLocales(
|
|
2433
|
+
create7(ListLocalesRequestSchema, {
|
|
2434
|
+
includeInactive: params.includeInactive,
|
|
2435
|
+
limit: params.limit ?? 50,
|
|
2436
|
+
offset: params.offset ?? 0
|
|
2437
|
+
})
|
|
2438
|
+
);
|
|
2439
|
+
},
|
|
2440
|
+
async getLocale(id) {
|
|
2441
|
+
const resp = await client.getLocale(
|
|
2442
|
+
create7(GetLocaleRequestSchema, { id })
|
|
2443
|
+
);
|
|
2444
|
+
return resp.locale ?? null;
|
|
2445
|
+
},
|
|
2446
|
+
async createLocale(params) {
|
|
2447
|
+
const resp = await client.createLocale(
|
|
2448
|
+
create7(CreateLocaleRequestSchema, {
|
|
2449
|
+
locale: params.locale,
|
|
2450
|
+
displayName: params.displayName,
|
|
2451
|
+
nativeName: params.nativeName,
|
|
2452
|
+
isDefault: params.isDefault,
|
|
2453
|
+
isRtl: params.isRtl,
|
|
2454
|
+
fallbackLocale: params.fallbackLocale
|
|
2455
|
+
})
|
|
2456
|
+
);
|
|
2457
|
+
return resp.locale ?? null;
|
|
2458
|
+
},
|
|
2459
|
+
async updateLocale(params) {
|
|
2460
|
+
const resp = await client.updateLocale(
|
|
2461
|
+
create7(UpdateLocaleRequestSchema, {
|
|
2462
|
+
id: params.id,
|
|
2463
|
+
displayName: params.displayName,
|
|
2464
|
+
nativeName: params.nativeName,
|
|
2465
|
+
isDefault: params.isDefault,
|
|
2466
|
+
isActive: params.isActive,
|
|
2467
|
+
isRtl: params.isRtl,
|
|
2468
|
+
fallbackLocale: params.fallbackLocale
|
|
2469
|
+
})
|
|
2470
|
+
);
|
|
2471
|
+
return resp.locale ?? null;
|
|
2472
|
+
},
|
|
2473
|
+
async deleteLocale(id) {
|
|
2474
|
+
const resp = await client.deleteLocale(
|
|
2475
|
+
create7(DeleteLocaleRequestSchema, { id })
|
|
2476
|
+
);
|
|
2477
|
+
return resp.success;
|
|
2478
|
+
},
|
|
2479
|
+
// ── Nav Preferences ─────────────────────────────────────
|
|
2480
|
+
async getNavPreferences() {
|
|
2481
|
+
const resp = await client.getNavPreferences(
|
|
2482
|
+
create7(GetNavPreferencesRequestSchema, {})
|
|
2483
|
+
);
|
|
2484
|
+
return resp.preferences ?? null;
|
|
2485
|
+
},
|
|
2486
|
+
async updateNavPreferences(params) {
|
|
2487
|
+
const resp = await client.updateNavPreferences(
|
|
2488
|
+
create7(UpdateNavPreferencesRequestSchema, {
|
|
2489
|
+
preferences: params.preferences ? {
|
|
2490
|
+
favoriteProjects: params.preferences.favoriteProjects,
|
|
2491
|
+
favoriteNavItems: params.preferences.favoriteNavItems,
|
|
2492
|
+
collapsedSections: params.preferences.collapsedSections,
|
|
2493
|
+
navItemOrder: params.preferences.navItemOrder
|
|
2494
|
+
} : void 0,
|
|
2495
|
+
toggleProjectId: params.toggleProjectId,
|
|
2496
|
+
toggleNavItem: params.toggleNavItem,
|
|
2497
|
+
toggleSection: params.toggleSection
|
|
2498
|
+
})
|
|
2499
|
+
);
|
|
2500
|
+
return resp.preferences ?? null;
|
|
2501
|
+
},
|
|
2502
|
+
// ── Recently Opened ─────────────────────────────────────
|
|
2503
|
+
async listRecentlyOpened(limit) {
|
|
2504
|
+
const resp = await client.listRecentlyOpened(
|
|
2505
|
+
create7(ListRecentlyOpenedRequestSchema, {
|
|
2506
|
+
limit: limit ?? 20
|
|
2507
|
+
})
|
|
2508
|
+
);
|
|
2509
|
+
return resp.items ?? [];
|
|
2510
|
+
},
|
|
2511
|
+
async trackRecentlyOpened(params) {
|
|
2512
|
+
const resp = await client.trackRecentlyOpened(
|
|
2513
|
+
create7(TrackRecentlyOpenedRequestSchema, {
|
|
2514
|
+
type: params.type,
|
|
2515
|
+
id: params.id,
|
|
2516
|
+
label: params.label,
|
|
2517
|
+
path: params.path
|
|
2518
|
+
})
|
|
2519
|
+
);
|
|
2520
|
+
return resp.success;
|
|
2521
|
+
},
|
|
2522
|
+
async removeRecentlyOpened(params) {
|
|
2523
|
+
const resp = await client.removeRecentlyOpened(
|
|
2524
|
+
create7(RemoveRecentlyOpenedRequestSchema, {
|
|
2525
|
+
type: params.type,
|
|
2526
|
+
id: params.id
|
|
2527
|
+
})
|
|
2528
|
+
);
|
|
2529
|
+
return resp.success;
|
|
2530
|
+
},
|
|
2531
|
+
async clearRecentlyOpened() {
|
|
2532
|
+
const resp = await client.clearRecentlyOpened(
|
|
2533
|
+
create7(ClearRecentlyOpenedRequestSchema, {})
|
|
2534
|
+
);
|
|
2535
|
+
return resp.success;
|
|
2536
|
+
},
|
|
2537
|
+
// ── Email Actions ──────────────────────────────────────────
|
|
2538
|
+
async listEmailActions(params = {}) {
|
|
2539
|
+
return client.listEmailActions(
|
|
2540
|
+
create7(ListEmailActionsRequestSchema, {
|
|
2541
|
+
limit: params.limit ?? 50,
|
|
2542
|
+
offset: params.offset ?? 0
|
|
2543
|
+
})
|
|
2544
|
+
);
|
|
2545
|
+
},
|
|
2546
|
+
async updateEmailAction(params) {
|
|
2547
|
+
const resp = await client.updateEmailAction(
|
|
2548
|
+
create7(UpdateEmailActionRequestSchema, {
|
|
2549
|
+
key: params.key,
|
|
2550
|
+
resendTemplateId: params.resendTemplateId,
|
|
2551
|
+
defaultFrom: params.defaultFrom,
|
|
2552
|
+
defaultSubject: params.defaultSubject,
|
|
2553
|
+
customData: params.customData,
|
|
2554
|
+
isActive: params.isActive
|
|
2555
|
+
})
|
|
2556
|
+
);
|
|
2557
|
+
return resp.action ?? null;
|
|
2558
|
+
},
|
|
2559
|
+
async listResendTemplates() {
|
|
2560
|
+
const resp = await client.listResendTemplates(
|
|
2561
|
+
create7(ListResendTemplatesRequestSchema, {})
|
|
2562
|
+
);
|
|
2563
|
+
return resp.templates ?? [];
|
|
2564
|
+
}
|
|
2565
|
+
};
|
|
445
2566
|
}
|
|
446
2567
|
|
|
447
|
-
// src/
|
|
448
|
-
import
|
|
2568
|
+
// src/lib/rpc/storage.ts
|
|
2569
|
+
import { create as create8 } from "@bufbuild/protobuf";
|
|
2570
|
+
import {
|
|
2571
|
+
CreateFileUploadRequestSchema,
|
|
2572
|
+
ConfirmFileUploadRequestSchema,
|
|
2573
|
+
GetFileRequestSchema,
|
|
2574
|
+
ListFilesRequestSchema,
|
|
2575
|
+
GetStorageUsageRequestSchema,
|
|
2576
|
+
UpdateFileRequestSchema,
|
|
2577
|
+
UpdateFileMetadataRequestSchema,
|
|
2578
|
+
DeleteFileRequestSchema,
|
|
2579
|
+
PermanentlyDeleteFileRequestSchema,
|
|
2580
|
+
RestoreFileRequestSchema,
|
|
2581
|
+
TrackFileUsageRequestSchema,
|
|
2582
|
+
RemoveFileUsageRequestSchema,
|
|
2583
|
+
CleanupOrphanedFilesRequestSchema
|
|
2584
|
+
} from "@eide/foir-proto-ts/storage/v1/storage_pb";
|
|
2585
|
+
function createStorageMethods(client) {
|
|
2586
|
+
return {
|
|
2587
|
+
async createFileUpload(params) {
|
|
2588
|
+
return client.createFileUpload(
|
|
2589
|
+
create8(CreateFileUploadRequestSchema, {
|
|
2590
|
+
filename: params.filename,
|
|
2591
|
+
mimeType: params.mimeType,
|
|
2592
|
+
size: BigInt(params.size),
|
|
2593
|
+
folder: params.folder
|
|
2594
|
+
})
|
|
2595
|
+
);
|
|
2596
|
+
},
|
|
2597
|
+
async confirmFileUpload(uploadId) {
|
|
2598
|
+
const resp = await client.confirmFileUpload(
|
|
2599
|
+
create8(ConfirmFileUploadRequestSchema, { uploadId })
|
|
2600
|
+
);
|
|
2601
|
+
return resp.file ?? null;
|
|
2602
|
+
},
|
|
2603
|
+
async getFile(id) {
|
|
2604
|
+
const resp = await client.getFile(create8(GetFileRequestSchema, { id }));
|
|
2605
|
+
return resp.file ?? null;
|
|
2606
|
+
},
|
|
2607
|
+
async listFiles(params) {
|
|
2608
|
+
return client.listFiles(
|
|
2609
|
+
create8(ListFilesRequestSchema, {
|
|
2610
|
+
folder: params.folder,
|
|
2611
|
+
mimeType: params.mimeType,
|
|
2612
|
+
search: params.search,
|
|
2613
|
+
includeDeleted: params.includeDeleted ?? false,
|
|
2614
|
+
limit: params.limit ?? 50,
|
|
2615
|
+
offset: params.offset ?? 0
|
|
2616
|
+
})
|
|
2617
|
+
);
|
|
2618
|
+
},
|
|
2619
|
+
async getStorageUsage() {
|
|
2620
|
+
const resp = await client.getStorageUsage(
|
|
2621
|
+
create8(GetStorageUsageRequestSchema, {})
|
|
2622
|
+
);
|
|
2623
|
+
return resp.usage ?? null;
|
|
2624
|
+
},
|
|
2625
|
+
async updateFile(params) {
|
|
2626
|
+
const resp = await client.updateFile(
|
|
2627
|
+
create8(UpdateFileRequestSchema, {
|
|
2628
|
+
id: params.id,
|
|
2629
|
+
filename: params.filename,
|
|
2630
|
+
folder: params.folder,
|
|
2631
|
+
tags: params.tags ?? []
|
|
2632
|
+
})
|
|
2633
|
+
);
|
|
2634
|
+
return resp.file ?? null;
|
|
2635
|
+
},
|
|
2636
|
+
async updateFileMetadata(params) {
|
|
2637
|
+
const resp = await client.updateFileMetadata(
|
|
2638
|
+
create8(UpdateFileMetadataRequestSchema, {
|
|
2639
|
+
id: params.id,
|
|
2640
|
+
altText: params.altText,
|
|
2641
|
+
caption: params.caption,
|
|
2642
|
+
description: params.description
|
|
2643
|
+
})
|
|
2644
|
+
);
|
|
2645
|
+
return resp.file ?? null;
|
|
2646
|
+
},
|
|
2647
|
+
async deleteFile(id) {
|
|
2648
|
+
const resp = await client.deleteFile(
|
|
2649
|
+
create8(DeleteFileRequestSchema, { id })
|
|
2650
|
+
);
|
|
2651
|
+
return resp.success;
|
|
2652
|
+
},
|
|
2653
|
+
async permanentlyDeleteFile(id) {
|
|
2654
|
+
const resp = await client.permanentlyDeleteFile(
|
|
2655
|
+
create8(PermanentlyDeleteFileRequestSchema, { id })
|
|
2656
|
+
);
|
|
2657
|
+
return resp.success;
|
|
2658
|
+
},
|
|
2659
|
+
async restoreFile(id) {
|
|
2660
|
+
const resp = await client.restoreFile(
|
|
2661
|
+
create8(RestoreFileRequestSchema, { id })
|
|
2662
|
+
);
|
|
2663
|
+
return resp.file ?? null;
|
|
2664
|
+
},
|
|
2665
|
+
async trackFileUsage(fileId, entityType) {
|
|
2666
|
+
const resp = await client.trackFileUsage(
|
|
2667
|
+
create8(TrackFileUsageRequestSchema, { fileId, entityType })
|
|
2668
|
+
);
|
|
2669
|
+
return resp.file ?? null;
|
|
2670
|
+
},
|
|
2671
|
+
async removeFileUsage(fileId, entityType) {
|
|
2672
|
+
const resp = await client.removeFileUsage(
|
|
2673
|
+
create8(RemoveFileUsageRequestSchema, { fileId, entityType })
|
|
2674
|
+
);
|
|
2675
|
+
return resp.success;
|
|
2676
|
+
},
|
|
2677
|
+
async cleanupOrphanedFiles(params) {
|
|
2678
|
+
return client.cleanupOrphanedFiles(
|
|
2679
|
+
create8(CleanupOrphanedFilesRequestSchema, {
|
|
2680
|
+
orphanThresholdDays: params?.orphanThresholdDays ?? 30,
|
|
2681
|
+
dryRun: params?.dryRun ?? false,
|
|
2682
|
+
limit: params?.limit ?? 100
|
|
2683
|
+
})
|
|
2684
|
+
);
|
|
2685
|
+
}
|
|
2686
|
+
};
|
|
2687
|
+
}
|
|
449
2688
|
|
|
450
2689
|
// src/lib/client.ts
|
|
451
|
-
import { createClient as createRpcClient } from "@connectrpc/connect";
|
|
452
|
-
import { createConnectTransport } from "@connectrpc/connect-node";
|
|
453
|
-
import {
|
|
454
|
-
IdentityService,
|
|
455
|
-
ModelsService,
|
|
456
|
-
RecordsService,
|
|
457
|
-
ConfigsService,
|
|
458
|
-
SegmentsService,
|
|
459
|
-
ExperimentsService,
|
|
460
|
-
SettingsService,
|
|
461
|
-
StorageService
|
|
462
|
-
} from "@eide/foir-connect-clients/services";
|
|
463
|
-
import { createIdentityMethods } from "@eide/foir-connect-clients/identity";
|
|
464
|
-
import { createModelsMethods } from "@eide/foir-connect-clients/models";
|
|
465
|
-
import { createRecordsMethods } from "@eide/foir-connect-clients/records";
|
|
466
|
-
import { createConfigsMethods } from "@eide/foir-connect-clients/configs";
|
|
467
|
-
import { createSegmentsMethods } from "@eide/foir-connect-clients/segments";
|
|
468
|
-
import { createExperimentsMethods } from "@eide/foir-connect-clients/experiments";
|
|
469
|
-
import { createSettingsMethods } from "@eide/foir-connect-clients/settings";
|
|
470
|
-
import { createStorageMethods } from "@eide/foir-connect-clients/storage";
|
|
471
2690
|
import { GraphQLClient } from "graphql-request";
|
|
472
2691
|
async function createPlatformClient(options) {
|
|
473
2692
|
const apiUrl = getApiUrl(options);
|
|
@@ -504,16 +2723,16 @@ async function createPlatformClient(options) {
|
|
|
504
2723
|
interceptors: [authInterceptor]
|
|
505
2724
|
});
|
|
506
2725
|
return {
|
|
507
|
-
identity: createIdentityMethods(createRpcClient(
|
|
508
|
-
models: createModelsMethods(createRpcClient(
|
|
509
|
-
records: createRecordsMethods(createRpcClient(
|
|
510
|
-
configs: createConfigsMethods(createRpcClient(
|
|
511
|
-
segments: createSegmentsMethods(createRpcClient(
|
|
2726
|
+
identity: createIdentityMethods(createRpcClient(IdentityService2, transport)),
|
|
2727
|
+
models: createModelsMethods(createRpcClient(ModelsService2, transport)),
|
|
2728
|
+
records: createRecordsMethods(createRpcClient(RecordsService2, transport)),
|
|
2729
|
+
configs: createConfigsMethods(createRpcClient(ConfigsService2, transport)),
|
|
2730
|
+
segments: createSegmentsMethods(createRpcClient(SegmentsService2, transport)),
|
|
512
2731
|
experiments: createExperimentsMethods(
|
|
513
|
-
createRpcClient(
|
|
2732
|
+
createRpcClient(ExperimentsService2, transport)
|
|
514
2733
|
),
|
|
515
|
-
settings: createSettingsMethods(createRpcClient(
|
|
516
|
-
storage: createStorageMethods(createRpcClient(
|
|
2734
|
+
settings: createSettingsMethods(createRpcClient(SettingsService2, transport)),
|
|
2735
|
+
storage: createStorageMethods(createRpcClient(StorageService2, transport))
|
|
517
2736
|
};
|
|
518
2737
|
}
|
|
519
2738
|
function createPlatformClientWithHeaders(apiUrl, headers) {
|
|
@@ -529,16 +2748,16 @@ function createPlatformClientWithHeaders(apiUrl, headers) {
|
|
|
529
2748
|
interceptors: [authInterceptor]
|
|
530
2749
|
});
|
|
531
2750
|
return {
|
|
532
|
-
identity: createIdentityMethods(createRpcClient(
|
|
533
|
-
models: createModelsMethods(createRpcClient(
|
|
534
|
-
records: createRecordsMethods(createRpcClient(
|
|
535
|
-
configs: createConfigsMethods(createRpcClient(
|
|
536
|
-
segments: createSegmentsMethods(createRpcClient(
|
|
2751
|
+
identity: createIdentityMethods(createRpcClient(IdentityService2, transport)),
|
|
2752
|
+
models: createModelsMethods(createRpcClient(ModelsService2, transport)),
|
|
2753
|
+
records: createRecordsMethods(createRpcClient(RecordsService2, transport)),
|
|
2754
|
+
configs: createConfigsMethods(createRpcClient(ConfigsService2, transport)),
|
|
2755
|
+
segments: createSegmentsMethods(createRpcClient(SegmentsService2, transport)),
|
|
537
2756
|
experiments: createExperimentsMethods(
|
|
538
|
-
createRpcClient(
|
|
2757
|
+
createRpcClient(ExperimentsService2, transport)
|
|
539
2758
|
),
|
|
540
|
-
settings: createSettingsMethods(createRpcClient(
|
|
541
|
-
storage: createStorageMethods(createRpcClient(
|
|
2759
|
+
settings: createSettingsMethods(createRpcClient(SettingsService2, transport)),
|
|
2760
|
+
storage: createStorageMethods(createRpcClient(StorageService2, transport))
|
|
542
2761
|
};
|
|
543
2762
|
}
|
|
544
2763
|
async function getStorageAuth(options) {
|
|
@@ -620,11 +2839,24 @@ function registerSelectProjectCommand(program2, globalOpts) {
|
|
|
620
2839
|
name: t.name
|
|
621
2840
|
})
|
|
622
2841
|
);
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
2842
|
+
if (tenants.length === 0) {
|
|
2843
|
+
console.log(
|
|
2844
|
+
"No workspaces found. Create one in the platform first."
|
|
2845
|
+
);
|
|
2846
|
+
throw new Error("No workspaces available");
|
|
2847
|
+
}
|
|
2848
|
+
const projects = [];
|
|
2849
|
+
for (const tenant of tenants) {
|
|
2850
|
+
const { items } = await client.identity.listProjects({
|
|
2851
|
+
tenantId: tenant.id,
|
|
2852
|
+
status: 1,
|
|
2853
|
+
// PROJECT_STATUS_ACTIVE
|
|
2854
|
+
limit: 100
|
|
2855
|
+
});
|
|
2856
|
+
for (const p of items) {
|
|
2857
|
+
projects.push({ id: p.id, name: p.name, tenantId: p.tenantId });
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
628
2860
|
if (projects.length === 0) {
|
|
629
2861
|
console.log("No projects found. Create one in the platform first.");
|
|
630
2862
|
throw new Error("No projects available");
|
|
@@ -873,7 +3105,9 @@ function registerWhoamiCommand(program2, globalOpts) {
|
|
|
873
3105
|
import { promises as fs2 } from "fs";
|
|
874
3106
|
import { basename } from "path";
|
|
875
3107
|
import chalk3 from "chalk";
|
|
876
|
-
import {
|
|
3108
|
+
import { createClient } from "@connectrpc/connect";
|
|
3109
|
+
import { createConnectTransport as createConnectTransport2 } from "@connectrpc/connect-node";
|
|
3110
|
+
import { StorageService as StorageService3 } from "@eide/foir-proto-ts/storage/v1/storage_pb";
|
|
877
3111
|
|
|
878
3112
|
// src/lib/input.ts
|
|
879
3113
|
import inquirer2 from "inquirer";
|
|
@@ -967,11 +3201,19 @@ function guessMimeType(filename) {
|
|
|
967
3201
|
function getStorageUrl() {
|
|
968
3202
|
return process.env.FOIR_STORAGE_URL ?? "https://storage.foir.dev";
|
|
969
3203
|
}
|
|
970
|
-
function
|
|
971
|
-
|
|
3204
|
+
function createStorageRpcClient(getToken) {
|
|
3205
|
+
const transport = createConnectTransport2({
|
|
972
3206
|
baseUrl: getStorageUrl(),
|
|
973
|
-
|
|
3207
|
+
httpVersion: "1.1",
|
|
3208
|
+
interceptors: [
|
|
3209
|
+
(next) => async (req) => {
|
|
3210
|
+
const token = await getToken();
|
|
3211
|
+
if (token) req.header.set("Authorization", `Bearer ${token}`);
|
|
3212
|
+
return next(req);
|
|
3213
|
+
}
|
|
3214
|
+
]
|
|
974
3215
|
});
|
|
3216
|
+
return createStorageMethods(createClient(StorageService3, transport));
|
|
975
3217
|
}
|
|
976
3218
|
function registerMediaCommands(program2, globalOpts) {
|
|
977
3219
|
const media = program2.command("media").description("Media file operations");
|
|
@@ -981,7 +3223,7 @@ function registerMediaCommands(program2, globalOpts) {
|
|
|
981
3223
|
async (filepath, flags) => {
|
|
982
3224
|
const opts = globalOpts();
|
|
983
3225
|
const { getToken } = await getStorageAuth(opts);
|
|
984
|
-
const storage =
|
|
3226
|
+
const storage = createStorageRpcClient(getToken);
|
|
985
3227
|
const fileBuffer = await fs2.readFile(filepath);
|
|
986
3228
|
const filename = basename(filepath);
|
|
987
3229
|
const mimeType = guessMimeType(filename);
|
|
@@ -1022,7 +3264,7 @@ function registerMediaCommands(program2, globalOpts) {
|
|
|
1022
3264
|
async (flags) => {
|
|
1023
3265
|
const opts = globalOpts();
|
|
1024
3266
|
const { getToken } = await getStorageAuth(opts);
|
|
1025
|
-
const storage =
|
|
3267
|
+
const storage = createStorageRpcClient(getToken);
|
|
1026
3268
|
const result = await storage.listFiles({
|
|
1027
3269
|
folder: flags.folder,
|
|
1028
3270
|
mimeType: flags["mime-type"] ?? flags.mimeType,
|
|
@@ -1064,7 +3306,7 @@ function registerMediaCommands(program2, globalOpts) {
|
|
|
1064
3306
|
withErrorHandler(globalOpts, async (id) => {
|
|
1065
3307
|
const opts = globalOpts();
|
|
1066
3308
|
const { getToken } = await getStorageAuth(opts);
|
|
1067
|
-
const storage =
|
|
3309
|
+
const storage = createStorageRpcClient(getToken);
|
|
1068
3310
|
const file = await storage.getFile(id);
|
|
1069
3311
|
formatOutput(file, opts);
|
|
1070
3312
|
})
|
|
@@ -1073,7 +3315,7 @@ function registerMediaCommands(program2, globalOpts) {
|
|
|
1073
3315
|
withErrorHandler(globalOpts, async () => {
|
|
1074
3316
|
const opts = globalOpts();
|
|
1075
3317
|
const { getToken } = await getStorageAuth(opts);
|
|
1076
|
-
const storage =
|
|
3318
|
+
const storage = createStorageRpcClient(getToken);
|
|
1077
3319
|
const usage = await storage.getStorageUsage();
|
|
1078
3320
|
if (opts.json || opts.jsonl) {
|
|
1079
3321
|
formatOutput(usage, opts);
|
|
@@ -1092,7 +3334,7 @@ function registerMediaCommands(program2, globalOpts) {
|
|
|
1092
3334
|
async (id, flags) => {
|
|
1093
3335
|
const opts = globalOpts();
|
|
1094
3336
|
const { getToken } = await getStorageAuth(opts);
|
|
1095
|
-
const storage =
|
|
3337
|
+
const storage = createStorageRpcClient(getToken);
|
|
1096
3338
|
const file = await storage.updateFile({
|
|
1097
3339
|
id,
|
|
1098
3340
|
filename: flags.filename,
|
|
@@ -1113,7 +3355,7 @@ function registerMediaCommands(program2, globalOpts) {
|
|
|
1113
3355
|
async (id, flags) => {
|
|
1114
3356
|
const opts = globalOpts();
|
|
1115
3357
|
const { getToken } = await getStorageAuth(opts);
|
|
1116
|
-
const storage =
|
|
3358
|
+
const storage = createStorageRpcClient(getToken);
|
|
1117
3359
|
const file = await storage.updateFileMetadata({
|
|
1118
3360
|
id,
|
|
1119
3361
|
altText: flags.altText ?? flags["alt-text"],
|
|
@@ -1141,7 +3383,7 @@ function registerMediaCommands(program2, globalOpts) {
|
|
|
1141
3383
|
return;
|
|
1142
3384
|
}
|
|
1143
3385
|
const { getToken } = await getStorageAuth(opts);
|
|
1144
|
-
const storage =
|
|
3386
|
+
const storage = createStorageRpcClient(getToken);
|
|
1145
3387
|
if (flags.permanent) {
|
|
1146
3388
|
await storage.permanentlyDeleteFile(id);
|
|
1147
3389
|
success("Permanently deleted file");
|
|
@@ -1156,7 +3398,7 @@ function registerMediaCommands(program2, globalOpts) {
|
|
|
1156
3398
|
withErrorHandler(globalOpts, async (id) => {
|
|
1157
3399
|
const opts = globalOpts();
|
|
1158
3400
|
const { getToken } = await getStorageAuth(opts);
|
|
1159
|
-
const storage =
|
|
3401
|
+
const storage = createStorageRpcClient(getToken);
|
|
1160
3402
|
const file = await storage.restoreFile(id);
|
|
1161
3403
|
if (opts.json || opts.jsonl) {
|
|
1162
3404
|
formatOutput(file, opts);
|
|
@@ -3721,7 +5963,7 @@ import {
|
|
|
3721
5963
|
} from "graphql";
|
|
3722
5964
|
|
|
3723
5965
|
// src/commands/register-commands.ts
|
|
3724
|
-
import { RecordType } from "@eide/foir-
|
|
5966
|
+
import { RecordType as RecordType2 } from "@eide/foir-proto-ts/records/v1/records_pb";
|
|
3725
5967
|
function buildDispatchTable() {
|
|
3726
5968
|
return {
|
|
3727
5969
|
// ── Models ──────────────────────────────────────────────────
|
|
@@ -4367,7 +6609,7 @@ function registerDynamicCommands(program2, globalOpts) {
|
|
|
4367
6609
|
} else {
|
|
4368
6610
|
try {
|
|
4369
6611
|
const record = await client.records.getRecord(versionIdValue);
|
|
4370
|
-
if (record?.recordType ===
|
|
6612
|
+
if (record?.recordType === RecordType2.RECORD && record?.currentVersionId) {
|
|
4371
6613
|
variables.versionId = record.currentVersionId;
|
|
4372
6614
|
}
|
|
4373
6615
|
} catch {
|