@x12i/keyrox-store 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/delegation-memory.js +2 -2
- package/dist/delegation-memory.js.map +1 -1
- package/dist/delegation.d.ts +3 -3
- package/dist/delegation.d.ts.map +1 -1
- package/dist/directory-access.d.ts +7 -0
- package/dist/directory-access.d.ts.map +1 -1
- package/dist/directory-access.js +11 -0
- package/dist/directory-access.js.map +1 -1
- package/dist/directory-invitation.d.ts +1 -0
- package/dist/directory-invitation.d.ts.map +1 -1
- package/dist/directory-invitation.js +1 -0
- package/dist/directory-invitation.js.map +1 -1
- package/dist/directory-memory.d.ts +6 -1
- package/dist/directory-memory.d.ts.map +1 -1
- package/dist/directory-memory.js +54 -17
- package/dist/directory-memory.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +173 -33
- package/dist/memory.js.map +1 -1
- package/dist/repository.d.ts +36 -3
- package/dist/repository.d.ts.map +1 -1
- package/dist/safe-share.d.ts +3 -3
- package/dist/safe-share.d.ts.map +1 -1
- package/dist/stations.d.ts +6 -6
- package/dist/stations.d.ts.map +1 -1
- package/package.json +34 -34
package/dist/memory.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { environmentTypeOf, isProductionStage } from "@x12i/keyrox-types";
|
|
1
2
|
import { appIdFromTenantResource, applicationLifecycleTime, applicationMoveKeys, verifyApplicationTrashSnapshot } from "./application-lifecycle.js";
|
|
2
3
|
import { decideLongLived, effectiveActions } from "./access.js";
|
|
3
4
|
import { fail } from "./errors.js";
|
|
@@ -9,7 +10,7 @@ import { bindDelegationMemory, emptyDelegation } from "./delegation-memory.js";
|
|
|
9
10
|
import { nextSafeShareDocument, planSafeSharePush, safeShareDocumentProblem } from "./safe-share.js";
|
|
10
11
|
import { planStationRegistration } from "./stations.js";
|
|
11
12
|
import { asTime, asTimeOrNull, clone, isExpired } from "./time.js";
|
|
12
|
-
const roles = new Set(["owner", "admin", "member"]);
|
|
13
|
+
const roles = new Set(["owner", "admin", "member", "sandbox-developer", "support", "viewer"]);
|
|
13
14
|
function empty() {
|
|
14
15
|
return {
|
|
15
16
|
users: new Map(), orgs: new Map(), memberships: new Map(), challenges: new Map(), invites: new Map(),
|
|
@@ -61,9 +62,16 @@ function canSharePlatformSignIn(row) {
|
|
|
61
62
|
return row.provider !== "oidc" && (row.provider !== "microsoft" || row.directoryId === "common");
|
|
62
63
|
}
|
|
63
64
|
function stampEnvironment(row) {
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
const trashedAt = asTimeOrNull(row.trashedAt ?? null);
|
|
66
|
+
const next = {
|
|
67
|
+
...row, type: environmentTypeOf(row),
|
|
68
|
+
previousKeyExpiresAt: asTimeOrNull(row.previousKeyExpiresAt), createdAt: asTime(row.createdAt), updatedAt: asTime(row.updatedAt),
|
|
66
69
|
};
|
|
70
|
+
if (trashedAt)
|
|
71
|
+
next.trashedAt = trashedAt;
|
|
72
|
+
else
|
|
73
|
+
delete next.trashedAt;
|
|
74
|
+
return next;
|
|
67
75
|
}
|
|
68
76
|
function stampAppToken(row) {
|
|
69
77
|
return { ...row, payload: clone(row.payload), revokedAt: asTimeOrNull(row.revokedAt), expiresAt: asTimeOrNull(row.expiresAt), createdAt: asTime(row.createdAt) };
|
|
@@ -71,12 +79,18 @@ function stampAppToken(row) {
|
|
|
71
79
|
function stampMembership(membership) {
|
|
72
80
|
if (!roles.has(membership.role))
|
|
73
81
|
fail("conflict", "Invalid role.");
|
|
74
|
-
|
|
82
|
+
const applicationIds = membership.applicationIds?.map((id) => id.trim()).filter(Boolean);
|
|
83
|
+
const next = {
|
|
75
84
|
...membership,
|
|
76
85
|
productionAccess: membership.role === "owner" || membership.productionAccess === true,
|
|
77
86
|
actions: [...membership.actions],
|
|
78
87
|
createdAt: asTime(membership.createdAt),
|
|
79
88
|
};
|
|
89
|
+
if (applicationIds?.length)
|
|
90
|
+
next.applicationIds = applicationIds;
|
|
91
|
+
else
|
|
92
|
+
delete next.applicationIds;
|
|
93
|
+
return next;
|
|
80
94
|
}
|
|
81
95
|
function stampStation(row) {
|
|
82
96
|
if (row.keyType !== "ssh-ed25519" || row.name !== row.name.toLowerCase() || row.name.length < 1 || row.name.length > 64
|
|
@@ -236,6 +250,15 @@ export function createMemoryStore() {
|
|
|
236
250
|
const agent = (id) => tables.agents.get(id) ?? fail("conflict", "Agent is missing.");
|
|
237
251
|
const grantRow = (id) => tables.grants.get(id) ?? fail("conflict", "Grant is missing.");
|
|
238
252
|
const membershipsForUser = (userId) => rows(tables.memberships, (row) => row.userId === userId);
|
|
253
|
+
const companyInUse = (orgId) => {
|
|
254
|
+
const hit = (map) => [...map.values()].some((row) => row.orgId === orgId);
|
|
255
|
+
return hit(tables.agents) || hit(tables.grants) || hit(tables.longTokens) || hit(tables.refreshes)
|
|
256
|
+
|| hit(tables.providers) || hit(tables.trusts) || hit(tables.stations) || tables.stationRegistrations.has(orgId)
|
|
257
|
+
|| hit(tables.serviceCredentials) || hit(tables.principals) || hit(tables.workloadCredentials)
|
|
258
|
+
|| hit(tables.audiences) || hit(tables.roles) || hit(tables.assignments) || hit(tables.gatewayRoutes)
|
|
259
|
+
|| hit(tables.safeShares) || hit(tables.notificationSettings) || hit(tables.notificationWebhooks)
|
|
260
|
+
|| hit(tables.environments) || hit(tables.appTokens) || hit(tables.ssoLogins);
|
|
261
|
+
};
|
|
239
262
|
const revokeGrant = (id, at) => {
|
|
240
263
|
const grant = tables.grants.get(id);
|
|
241
264
|
if (!grant)
|
|
@@ -386,7 +409,7 @@ export function createMemoryStore() {
|
|
|
386
409
|
if (!app)
|
|
387
410
|
fail("conflict", "Application is missing.");
|
|
388
411
|
if (row.orgId !== app.orgId)
|
|
389
|
-
fail("conflict", "Environment
|
|
412
|
+
fail("conflict", "Environment Company does not match the application.");
|
|
390
413
|
if (row.status !== "active" && row.status !== "disabled")
|
|
391
414
|
fail("conflict", "Invalid environment status.");
|
|
392
415
|
if ([...tables.environments.values()].some((item) => item.appId === row.appId && item.name === row.name))
|
|
@@ -397,10 +420,10 @@ export function createMemoryStore() {
|
|
|
397
420
|
const app = activeApplication(row.appId);
|
|
398
421
|
const environment = tables.environments.get(row.environmentId);
|
|
399
422
|
if (app?.orgId !== row.orgId || environment?.appId !== row.appId || environment.orgId !== row.orgId) {
|
|
400
|
-
fail("conflict", "Application staff access must match the
|
|
423
|
+
fail("conflict", "Application staff access must match the Company, application, and environment.");
|
|
401
424
|
}
|
|
402
425
|
if (![...tables.memberships.values()].some((membership) => membership.orgId === row.orgId && membership.userId === row.userId)) {
|
|
403
|
-
fail("conflict", "Application staff access requires
|
|
426
|
+
fail("conflict", "Application staff access requires Company membership.");
|
|
404
427
|
}
|
|
405
428
|
if (typeof row.design !== "boolean" || !["none", "read", "manage"].includes(row.runtime)) {
|
|
406
429
|
fail("conflict", "Invalid application staff access level.");
|
|
@@ -544,6 +567,14 @@ export function createMemoryStore() {
|
|
|
544
567
|
}
|
|
545
568
|
});
|
|
546
569
|
},
|
|
570
|
+
async insertUser(user) {
|
|
571
|
+
tx(() => {
|
|
572
|
+
const next = stampUser(user);
|
|
573
|
+
if ([...tables.users.values()].some((row) => row.email.toLowerCase() === next.email.toLowerCase()))
|
|
574
|
+
fail("duplicate_email", "Email already exists.");
|
|
575
|
+
put(tables.users, next);
|
|
576
|
+
});
|
|
577
|
+
},
|
|
547
578
|
async createOrg(input) {
|
|
548
579
|
tx(() => {
|
|
549
580
|
const nextOrg = stampOrg(input.org);
|
|
@@ -584,6 +615,19 @@ export function createMemoryStore() {
|
|
|
584
615
|
},
|
|
585
616
|
async listMembershipsByUser(userId) { return membershipsForUser(userId); },
|
|
586
617
|
async listMembershipsByOrg(orgId) { return rows(tables.memberships, (row) => row.orgId === orgId); },
|
|
618
|
+
async addMembership(membership) {
|
|
619
|
+
tx(() => {
|
|
620
|
+
const next = stampMembership(membership);
|
|
621
|
+
if (!tables.users.has(next.userId))
|
|
622
|
+
fail("not_found", "Account not found.");
|
|
623
|
+
if (!tables.orgs.has(next.orgId))
|
|
624
|
+
fail("not_found", "Company not found.");
|
|
625
|
+
if ([...tables.memberships.values()].some((row) => row.userId === next.userId && row.orgId === next.orgId)) {
|
|
626
|
+
fail("duplicate", "Membership already exists.");
|
|
627
|
+
}
|
|
628
|
+
put(tables.memberships, next);
|
|
629
|
+
});
|
|
630
|
+
},
|
|
587
631
|
async saveMembership(membership) {
|
|
588
632
|
tx(() => {
|
|
589
633
|
const next = stampMembership(membership);
|
|
@@ -604,13 +648,15 @@ export function createMemoryStore() {
|
|
|
604
648
|
const existing = [...tables.memberships.values()].find((row) => row.userId === input.userId && row.orgId === input.orgId);
|
|
605
649
|
if (!existing)
|
|
606
650
|
fail("not_found", "Member not found.");
|
|
607
|
-
user(input.userId);
|
|
651
|
+
const account = user(input.userId);
|
|
608
652
|
if (membershipsForUser(input.userId).length < 2)
|
|
609
|
-
fail("last_membership", "An account must belong to at least one
|
|
653
|
+
fail("last_membership", "An account must belong to at least one Company.");
|
|
610
654
|
if (existing.role === "owner" && rows(tables.memberships, (row) => row.orgId === input.orgId && row.role === "owner").length < 2) {
|
|
611
655
|
fail("last_owner", "An organization must keep an owner.");
|
|
612
656
|
}
|
|
613
657
|
tables.memberships.delete(existing.id);
|
|
658
|
+
if (account.lastOrgId === input.orgId)
|
|
659
|
+
account.lastOrgId = membershipsForUser(input.userId)[0]?.orgId ?? null;
|
|
614
660
|
for (const access of tables.applicationStaffAccess.values()) {
|
|
615
661
|
if (access.orgId === existing.orgId && access.userId === existing.userId)
|
|
616
662
|
tables.applicationStaffAccess.delete(access.id);
|
|
@@ -623,6 +669,58 @@ export function createMemoryStore() {
|
|
|
623
669
|
}
|
|
624
670
|
});
|
|
625
671
|
},
|
|
672
|
+
async companyHasRecords(orgId) { return companyInUse(orgId); },
|
|
673
|
+
async deleteCompany(orgId) {
|
|
674
|
+
tx(() => {
|
|
675
|
+
if (!tables.orgs.has(orgId))
|
|
676
|
+
fail("not_found", "Company not found.");
|
|
677
|
+
if ([...tables.applications.values()].some((row) => row.orgId === orgId))
|
|
678
|
+
fail("company_has_applications", "Company has applications.");
|
|
679
|
+
const members = [...tables.memberships.values()].filter((row) => row.orgId === orgId);
|
|
680
|
+
for (const member of members) {
|
|
681
|
+
if ([...tables.memberships.values()].filter((row) => row.userId === member.userId).length < 2) {
|
|
682
|
+
fail("last_membership", "An account must belong to at least one Company.");
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
if (companyInUse(orgId))
|
|
686
|
+
fail("company_in_use", "Company still has records.");
|
|
687
|
+
for (const [id, role] of tables.directory.productRoles) {
|
|
688
|
+
if (role.catalogRoleId && tables.directory.tenantProductRoles.get(role.catalogRoleId)?.orgId === orgId) {
|
|
689
|
+
tables.directory.productRoles.set(id, { ...role, catalogRoleId: null });
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
for (const [id, role] of tables.directory.tenantProductRoles) {
|
|
693
|
+
if (role.orgId === orgId)
|
|
694
|
+
tables.directory.tenantProductRoles.delete(id);
|
|
695
|
+
}
|
|
696
|
+
for (const [key, row] of tables.cliLoginCodes)
|
|
697
|
+
if (row.orgId === orgId)
|
|
698
|
+
tables.cliLoginCodes.delete(key);
|
|
699
|
+
for (const [id, row] of tables.sessions)
|
|
700
|
+
if (row.orgId === orgId)
|
|
701
|
+
tables.sessions.delete(id);
|
|
702
|
+
for (const [id, row] of tables.invites)
|
|
703
|
+
if (row.orgId === orgId)
|
|
704
|
+
tables.invites.delete(id);
|
|
705
|
+
for (const [id, row] of tables.applicationStaffAccess)
|
|
706
|
+
if (row.orgId === orgId)
|
|
707
|
+
tables.applicationStaffAccess.delete(id);
|
|
708
|
+
for (const row of tables.audits.values())
|
|
709
|
+
if (row.orgId === orgId)
|
|
710
|
+
row.orgId = null;
|
|
711
|
+
for (const row of tables.authorizations.values())
|
|
712
|
+
if (row.orgId === orgId)
|
|
713
|
+
row.orgId = null;
|
|
714
|
+
for (const member of members) {
|
|
715
|
+
const account = tables.users.get(member.userId);
|
|
716
|
+
if (account?.lastOrgId === orgId) {
|
|
717
|
+
account.lastOrgId = [...tables.memberships.values()].find((row) => row.userId === member.userId && row.orgId !== orgId)?.orgId ?? null;
|
|
718
|
+
}
|
|
719
|
+
tables.memberships.delete(member.id);
|
|
720
|
+
}
|
|
721
|
+
tables.orgs.delete(orgId);
|
|
722
|
+
});
|
|
723
|
+
},
|
|
626
724
|
async insertChallenge(row) {
|
|
627
725
|
tx(() => {
|
|
628
726
|
user(row.userId);
|
|
@@ -678,6 +776,16 @@ export function createMemoryStore() {
|
|
|
678
776
|
return clone(account);
|
|
679
777
|
});
|
|
680
778
|
},
|
|
779
|
+
async previewAccountReset(tokenHash, at) {
|
|
780
|
+
const stamp = asTime(at);
|
|
781
|
+
const challenge = [...tables.challenges.values()].find((row) => row.tokenHash === tokenHash && row.purpose === "reset");
|
|
782
|
+
if (!challenge || challenge.usedAt || isExpired(challenge.expiresAt, stamp))
|
|
783
|
+
return null;
|
|
784
|
+
const account = tables.users.get(challenge.userId);
|
|
785
|
+
if (!account || account.disabledAt)
|
|
786
|
+
return null;
|
|
787
|
+
return { email: account.email, displayName: account.displayName };
|
|
788
|
+
},
|
|
681
789
|
async resetPassword(input) {
|
|
682
790
|
return tx(() => {
|
|
683
791
|
const stamp = asTime(input.at);
|
|
@@ -1138,7 +1246,7 @@ export function createMemoryStore() {
|
|
|
1138
1246
|
fail("conflict", "Creator access must target the new development environment.");
|
|
1139
1247
|
}
|
|
1140
1248
|
if (audit && audit.orgId !== application.orgId)
|
|
1141
|
-
fail("conflict", "Application registration audit must match the
|
|
1249
|
+
fail("conflict", "Application registration audit must match the Company.");
|
|
1142
1250
|
insertApp(application);
|
|
1143
1251
|
for (const environment of environments)
|
|
1144
1252
|
insertAppEnvironment(environment);
|
|
@@ -1160,10 +1268,10 @@ export function createMemoryStore() {
|
|
|
1160
1268
|
if (app?.orgId !== sourceOrgId)
|
|
1161
1269
|
fail("not_found", "Application not found.");
|
|
1162
1270
|
if (sourceOrgId === targetOrgId)
|
|
1163
|
-
fail("conflict", "Choose a different
|
|
1271
|
+
fail("conflict", "Choose a different Company.");
|
|
1164
1272
|
org(targetOrgId);
|
|
1165
1273
|
if (audit.some((event) => event.orgId !== sourceOrgId && event.orgId !== targetOrgId)) {
|
|
1166
|
-
fail("conflict", "Application move audit must match the source or destination
|
|
1274
|
+
fail("conflict", "Application move audit must match the source or destination Company.");
|
|
1167
1275
|
}
|
|
1168
1276
|
const stamp = applicationLifecycleTime(updatedAt, app.updatedAt);
|
|
1169
1277
|
const environments = rows(tables.environments, (row) => row.appId === appId);
|
|
@@ -1172,19 +1280,19 @@ export function createMemoryStore() {
|
|
|
1172
1280
|
const audiences = rows(tables.audiences, (row) => row.appId === appId);
|
|
1173
1281
|
const audienceIds = new Set(audiences.map(({ id }) => id));
|
|
1174
1282
|
if (rows(tables.audiences, (row) => row.orgId === targetOrgId).some((row) => audiences.some((audience) => audience.identifier === row.identifier))) {
|
|
1175
|
-
fail("conflict", "The destination
|
|
1283
|
+
fail("conflict", "The destination Company already uses an audience identifier from this application.");
|
|
1176
1284
|
}
|
|
1177
1285
|
const sourcePath = `/tenants/${sourceOrgId}/apps/${appId}`;
|
|
1178
1286
|
const targetPath = `/tenants/${targetOrgId}/apps/${appId}`;
|
|
1179
1287
|
const routes = rows(tables.gatewayRoutes, (row) => audienceIds.has(row.audienceId) || row.resource.replace(/\/+$/, "") === sourcePath);
|
|
1180
1288
|
if (routes.some((row) => !audienceIds.has(row.audienceId) || row.resource.replace(/\/+$/, "") !== sourcePath || row.orgId !== sourceOrgId)) {
|
|
1181
|
-
fail("conflict", "An application gateway route uses a shared
|
|
1289
|
+
fail("conflict", "An application gateway route uses a shared Company resource or audience. Update its scope before moving the application.");
|
|
1182
1290
|
}
|
|
1183
1291
|
removeApplicationTenantAccess(sourceOrgId, appId, stamp);
|
|
1184
|
-
// The safe-share belongs to the
|
|
1292
|
+
// The safe-share belongs to the Company's stations and agents, so it does not move: it is removed with its documents.
|
|
1185
1293
|
dropSafeShare(appId);
|
|
1186
|
-
// Customer access does not move with the application: the new
|
|
1187
|
-
// portal address and the allowed origins name hosts of the old
|
|
1294
|
+
// Customer access does not move with the application: the new Company opts in again, and no session of the old one goes on. The
|
|
1295
|
+
// portal address and the allowed origins name hosts of the old Company, and a link is built on the first of them, so neither stays.
|
|
1188
1296
|
for (const policy of tables.delegation.customerAccess.values()) {
|
|
1189
1297
|
if (!envIds.has(policy.environmentId) || !(policy.enabled || policy.portalUrl !== null || policy.allowedOrigins.length > 0))
|
|
1190
1298
|
continue;
|
|
@@ -1246,8 +1354,8 @@ export function createMemoryStore() {
|
|
|
1246
1354
|
if (app?.orgId !== orgId)
|
|
1247
1355
|
fail("not_found", "Application not found.");
|
|
1248
1356
|
if (audit && audit.orgId !== orgId)
|
|
1249
|
-
fail("conflict", "Application trash audit must match the
|
|
1250
|
-
if (!allowProduction && [...tables.environments.values()].some((row) => row.appId === appId && row
|
|
1357
|
+
fail("conflict", "Application trash audit must match the Company.");
|
|
1358
|
+
if (!allowProduction && [...tables.environments.values()].some((row) => row.appId === appId && isProductionStage(row))) {
|
|
1251
1359
|
fail("conflict", "Production access is required to move this application to Trash.");
|
|
1252
1360
|
}
|
|
1253
1361
|
const stamp = applicationLifecycleTime(trashedAt, app.updatedAt);
|
|
@@ -1267,7 +1375,7 @@ export function createMemoryStore() {
|
|
|
1267
1375
|
if (expectedTrashedAt && expectedTrashedAt !== trashedAt)
|
|
1268
1376
|
fail("conflict", "Trash changed. Review the application before restoring it.");
|
|
1269
1377
|
if (audit && audit.orgId !== orgId)
|
|
1270
|
-
fail("conflict", "Application restore audit must match the
|
|
1378
|
+
fail("conflict", "Application restore audit must match the Company.");
|
|
1271
1379
|
const restored = { ...app, updatedAt: applicationLifecycleTime(updatedAt, trashedAt) };
|
|
1272
1380
|
replace(tables.applications, restored);
|
|
1273
1381
|
tables.applicationTrash.delete(appId);
|
|
@@ -1280,10 +1388,10 @@ export function createMemoryStore() {
|
|
|
1280
1388
|
return tx(() => {
|
|
1281
1389
|
org(orgId);
|
|
1282
1390
|
if (audit && audit.orgId !== orgId)
|
|
1283
|
-
fail("conflict", "Application trash audit must match the
|
|
1391
|
+
fail("conflict", "Application trash audit must match the Company.");
|
|
1284
1392
|
const entries = listApplicationTrash(orgId);
|
|
1285
1393
|
verifyApplicationTrashSnapshot(entries, confirmed);
|
|
1286
|
-
if (!allowProduction && [...tables.environments.values()].some((row) => row
|
|
1394
|
+
if (!allowProduction && [...tables.environments.values()].some((row) => isProductionStage(row) && entries.some(({ id }) => id === row.appId))) {
|
|
1287
1395
|
fail("conflict", "Production access is required to empty this Trash.");
|
|
1288
1396
|
}
|
|
1289
1397
|
for (const entry of entries)
|
|
@@ -1350,7 +1458,7 @@ export function createMemoryStore() {
|
|
|
1350
1458
|
async listEnvironments(appId, options) {
|
|
1351
1459
|
if (!options?.includeTrashed && !activeApplication(appId))
|
|
1352
1460
|
return [];
|
|
1353
|
-
return rows(tables.environments, (row) => row.appId === appId)
|
|
1461
|
+
return rows(tables.environments, (row) => row.appId === appId && !row.trashedAt)
|
|
1354
1462
|
.sort((left, right) => left.createdAt.localeCompare(right.createdAt) || left.name.localeCompare(right.name));
|
|
1355
1463
|
},
|
|
1356
1464
|
async saveEnvironmentJwtProfile(environmentId, appId, orgId, profile, updatedAt) {
|
|
@@ -1381,7 +1489,39 @@ export function createMemoryStore() {
|
|
|
1381
1489
|
const next = stampEnvironment(row);
|
|
1382
1490
|
if (row.jwtProfile === undefined)
|
|
1383
1491
|
next.jwtProfile = current.jwtProfile;
|
|
1492
|
+
if (current.trashedAt)
|
|
1493
|
+
next.trashedAt = current.trashedAt;
|
|
1494
|
+
replace(tables.environments, next);
|
|
1495
|
+
});
|
|
1496
|
+
},
|
|
1497
|
+
async trashEnvironment({ environmentId, appId, orgId, trashedAt, audit }) {
|
|
1498
|
+
return tx(() => {
|
|
1499
|
+
const current = tables.environments.get(environmentId);
|
|
1500
|
+
if (!current || current.appId !== appId || current.orgId !== orgId || current.trashedAt || !activeApplication(appId))
|
|
1501
|
+
fail("not_found", "Environment not found.");
|
|
1502
|
+
const live = [...tables.environments.values()].filter((row) => row.appId === appId && !row.trashedAt);
|
|
1503
|
+
if (live.length < 2)
|
|
1504
|
+
fail("conflict", "An application must keep at least one environment.");
|
|
1505
|
+
const stamp = asTime(trashedAt);
|
|
1506
|
+
const next = stampEnvironment({ ...current, trashedAt: stamp, updatedAt: stamp });
|
|
1384
1507
|
replace(tables.environments, next);
|
|
1508
|
+
if (audit)
|
|
1509
|
+
writeAudit(audit);
|
|
1510
|
+
return clone(next);
|
|
1511
|
+
});
|
|
1512
|
+
},
|
|
1513
|
+
async restoreEnvironment({ environmentId, appId, orgId, updatedAt, audit }) {
|
|
1514
|
+
return tx(() => {
|
|
1515
|
+
const current = tables.environments.get(environmentId);
|
|
1516
|
+
if (!current || current.appId !== appId || current.orgId !== orgId || !current.trashedAt || !activeApplication(appId))
|
|
1517
|
+
fail("not_found", "Environment not found in Trash.");
|
|
1518
|
+
const stamp = asTime(updatedAt);
|
|
1519
|
+
const next = stampEnvironment({ ...current, updatedAt: stamp });
|
|
1520
|
+
delete next.trashedAt;
|
|
1521
|
+
replace(tables.environments, next);
|
|
1522
|
+
if (audit)
|
|
1523
|
+
writeAudit(audit);
|
|
1524
|
+
return clone(next);
|
|
1385
1525
|
});
|
|
1386
1526
|
},
|
|
1387
1527
|
async getNotificationSettings(environmentId) {
|
|
@@ -1403,7 +1543,7 @@ export function createMemoryStore() {
|
|
|
1403
1543
|
tables.notificationSettings.set(row.environmentId, clone({ ...row, templates: { ...row.templates }, updatedAt: asTime(row.updatedAt) }));
|
|
1404
1544
|
if (audit) {
|
|
1405
1545
|
if (audit.orgId !== row.orgId)
|
|
1406
|
-
fail("conflict", "Notification audit must match the
|
|
1546
|
+
fail("conflict", "Notification audit must match the Company.");
|
|
1407
1547
|
writeAudit(audit);
|
|
1408
1548
|
}
|
|
1409
1549
|
return true;
|
|
@@ -1465,7 +1605,7 @@ export function createMemoryStore() {
|
|
|
1465
1605
|
async saveApplicationStaffAccess(row, audit) {
|
|
1466
1606
|
return tx(() => {
|
|
1467
1607
|
if (audit && audit.orgId !== row.orgId)
|
|
1468
|
-
fail("conflict", "Application staff audit must match the
|
|
1608
|
+
fail("conflict", "Application staff audit must match the Company.");
|
|
1469
1609
|
const saved = saveStaffAccess(row);
|
|
1470
1610
|
if (audit)
|
|
1471
1611
|
writeAudit(audit);
|
|
@@ -1475,7 +1615,7 @@ export function createMemoryStore() {
|
|
|
1475
1615
|
async deleteApplicationStaffAccess(orgId, appId, environmentId, userId, audit) {
|
|
1476
1616
|
return tx(() => {
|
|
1477
1617
|
if (audit && audit.orgId !== orgId)
|
|
1478
|
-
fail("conflict", "Application staff audit must match the
|
|
1618
|
+
fail("conflict", "Application staff audit must match the Company.");
|
|
1479
1619
|
const current = [...tables.applicationStaffAccess.values()].find((row) => row.orgId === orgId && row.appId === appId && row.environmentId === environmentId && row.userId === userId);
|
|
1480
1620
|
if (!current)
|
|
1481
1621
|
return false;
|
|
@@ -1494,7 +1634,7 @@ export function createMemoryStore() {
|
|
|
1494
1634
|
if (!environment || environment.appId !== row.appId)
|
|
1495
1635
|
fail("conflict", "Environment is missing.");
|
|
1496
1636
|
if (row.orgId !== app.orgId)
|
|
1497
|
-
fail("conflict", "Token
|
|
1637
|
+
fail("conflict", "Token Company does not match the application.");
|
|
1498
1638
|
if (row.payload.keyVersion !== environment.keyVersion)
|
|
1499
1639
|
fail("conflict", "The environment key changed during token issuance.");
|
|
1500
1640
|
put(tables.appTokens, stampAppToken(row));
|
|
@@ -2117,11 +2257,11 @@ export function createMemoryStore() {
|
|
|
2117
2257
|
tx(() => {
|
|
2118
2258
|
org(row.orgId);
|
|
2119
2259
|
if (row.appId && activeApplication(row.appId)?.orgId !== row.orgId)
|
|
2120
|
-
fail("conflict", "Choose an application from this
|
|
2260
|
+
fail("conflict", "Choose an application from this Company.");
|
|
2121
2261
|
if (row.environmentId) {
|
|
2122
2262
|
const environment = tables.environments.get(row.environmentId);
|
|
2123
2263
|
if (!environment || environment.orgId !== row.orgId || (row.appId && environment.appId !== row.appId))
|
|
2124
|
-
fail("conflict", "Choose an environment from this
|
|
2264
|
+
fail("conflict", "Choose an environment from this Company.");
|
|
2125
2265
|
}
|
|
2126
2266
|
if ([...tables.audiences.values()].some((item) => item.orgId === row.orgId && item.identifier === row.identifier))
|
|
2127
2267
|
fail("duplicate", "Duplicate key.");
|
|
@@ -2153,7 +2293,7 @@ export function createMemoryStore() {
|
|
|
2153
2293
|
if (environmentId) {
|
|
2154
2294
|
const environment = tables.environments.get(environmentId);
|
|
2155
2295
|
if (!environment || environment.orgId !== orgId || (current.appId && environment.appId !== current.appId))
|
|
2156
|
-
fail("conflict", "Choose an environment from this
|
|
2296
|
+
fail("conflict", "Choose an environment from this Company.");
|
|
2157
2297
|
}
|
|
2158
2298
|
const next = { ...current, environmentId };
|
|
2159
2299
|
replace(tables.audiences, next);
|
|
@@ -2170,7 +2310,7 @@ export function createMemoryStore() {
|
|
|
2170
2310
|
const principal = tables.principals.get(row.principalId);
|
|
2171
2311
|
const role = tables.roles.get(row.roleId);
|
|
2172
2312
|
if (principal?.orgId !== row.orgId || role?.orgId !== row.orgId)
|
|
2173
|
-
fail("conflict", "Choose an app identity and role from this
|
|
2313
|
+
fail("conflict", "Choose an app identity and role from this Company.");
|
|
2174
2314
|
if (!principal.enabled)
|
|
2175
2315
|
fail("conflict", "This app identity is disabled.");
|
|
2176
2316
|
const scope = row.scope.replace(/\/+$/, "");
|
|
@@ -2198,10 +2338,10 @@ export function createMemoryStore() {
|
|
|
2198
2338
|
org(row.orgId);
|
|
2199
2339
|
const audience = tables.audiences.get(row.audienceId);
|
|
2200
2340
|
if (!audience || audience.orgId !== row.orgId)
|
|
2201
|
-
fail("conflict", "Choose an audience from this
|
|
2341
|
+
fail("conflict", "Choose an audience from this Company.");
|
|
2202
2342
|
const appId = appIdFromTenantResource(row.orgId, row.resource);
|
|
2203
2343
|
if ((audience.appId && activeApplication(audience.appId)?.orgId !== row.orgId) || (appId && activeApplication(appId)?.orgId !== row.orgId)) {
|
|
2204
|
-
fail("conflict", "Choose an application from this
|
|
2344
|
+
fail("conflict", "Choose an application from this Company.");
|
|
2205
2345
|
}
|
|
2206
2346
|
put(tables.gatewayRoutes, { ...row, createdAt: asTime(row.createdAt) });
|
|
2207
2347
|
});
|