@logto/schemas 1.13.1 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/alterations/1.14.0-1708916601-remove-management-api-scopes-assigned-to-user-role.ts +47 -0
- package/alterations/1.14.0-1709190131-enhance-dau-data-accuracy.ts +18 -0
- package/alterations-js/1.14.0-1708916601-remove-management-api-scopes-assigned-to-user-role.d.ts +3 -0
- package/alterations-js/1.14.0-1708916601-remove-management-api-scopes-assigned-to-user-role.js +36 -0
- package/alterations-js/1.14.0-1709190131-enhance-dau-data-accuracy.d.ts +3 -0
- package/alterations-js/1.14.0-1709190131-enhance-dau-data-accuracy.js +14 -0
- package/lib/db-entries/daily-active-user.d.ts +1 -1
- package/lib/db-entries/daily-active-user.js +1 -1
- package/lib/seeds/cloud-api.d.ts +2 -2
- package/lib/seeds/cloud-api.js +2 -2
- package/package.json +1 -1
- package/tables/_before_all.sql +1 -1
- package/tables/daily_active_users.sql +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { sql } from 'slonik';
|
|
2
|
+
|
|
3
|
+
import type { AlterationScript } from '../lib/types/alteration.js';
|
|
4
|
+
|
|
5
|
+
enum RoleType {
|
|
6
|
+
User = 'User',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const getManagementApiResourceIndicator = (tenantId: string) => `https://${tenantId}.logto.app/api`;
|
|
10
|
+
|
|
11
|
+
// Remove management API scopes assigned to user roles, in case they were assigned by management API and bypassed the constraints in admin console.
|
|
12
|
+
const alteration: AlterationScript = {
|
|
13
|
+
up: async (pool) => {
|
|
14
|
+
const { rows } = await pool.query<{
|
|
15
|
+
rolesScopesId: string;
|
|
16
|
+
indicator: string;
|
|
17
|
+
tenantId: string;
|
|
18
|
+
}>(sql`
|
|
19
|
+
select
|
|
20
|
+
roles_scopes.id as "rolesScopesId",
|
|
21
|
+
roles_scopes.tenant_id as "tenantId",
|
|
22
|
+
resources.indicator as indicator from roles_scopes
|
|
23
|
+
join roles
|
|
24
|
+
on roles_scopes.role_id = roles.id and roles_scopes.tenant_id = roles.tenant_id
|
|
25
|
+
join scopes on
|
|
26
|
+
roles_scopes.scope_id = scopes.id and roles_scopes.tenant_id = scopes.tenant_id
|
|
27
|
+
join resources on
|
|
28
|
+
scopes.resource_id = resources.id and scopes.tenant_id = resources.tenant_id
|
|
29
|
+
where roles.type = ${RoleType.User};
|
|
30
|
+
`);
|
|
31
|
+
const rolesScopesIdsToRemove = rows
|
|
32
|
+
.filter(
|
|
33
|
+
({ indicator, tenantId }) => indicator === getManagementApiResourceIndicator(tenantId)
|
|
34
|
+
)
|
|
35
|
+
.map(({ rolesScopesId }) => rolesScopesId);
|
|
36
|
+
if (rolesScopesIdsToRemove.length > 0) {
|
|
37
|
+
await pool.query(sql`
|
|
38
|
+
delete from roles_scopes where id in (${sql.join(rolesScopesIdsToRemove, sql`, `)});
|
|
39
|
+
`);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
down: async (pool) => {
|
|
43
|
+
// It cannot be reverted automatically.
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default alteration;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { sql } from 'slonik';
|
|
2
|
+
|
|
3
|
+
import type { AlterationScript } from '../lib/types/alteration.js';
|
|
4
|
+
|
|
5
|
+
const alteration: AlterationScript = {
|
|
6
|
+
up: async (pool) => {
|
|
7
|
+
await pool.query(sql`
|
|
8
|
+
alter table daily_active_users alter column date set default now();
|
|
9
|
+
`);
|
|
10
|
+
},
|
|
11
|
+
down: async (pool) => {
|
|
12
|
+
await pool.query(sql`
|
|
13
|
+
alter table daily_active_users alter column date drop default;
|
|
14
|
+
`);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default alteration;
|
package/alterations-js/1.14.0-1708916601-remove-management-api-scopes-assigned-to-user-role.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { sql } from 'slonik';
|
|
2
|
+
var RoleType;
|
|
3
|
+
(function (RoleType) {
|
|
4
|
+
RoleType["User"] = "User";
|
|
5
|
+
})(RoleType || (RoleType = {}));
|
|
6
|
+
const getManagementApiResourceIndicator = (tenantId) => `https://${tenantId}.logto.app/api`;
|
|
7
|
+
// Remove management API scopes assigned to user roles, in case they were assigned by management API and bypassed the constraints in admin console.
|
|
8
|
+
const alteration = {
|
|
9
|
+
up: async (pool) => {
|
|
10
|
+
const { rows } = await pool.query(sql `
|
|
11
|
+
select
|
|
12
|
+
roles_scopes.id as "rolesScopesId",
|
|
13
|
+
roles_scopes.tenant_id as "tenantId",
|
|
14
|
+
resources.indicator as indicator from roles_scopes
|
|
15
|
+
join roles
|
|
16
|
+
on roles_scopes.role_id = roles.id and roles_scopes.tenant_id = roles.tenant_id
|
|
17
|
+
join scopes on
|
|
18
|
+
roles_scopes.scope_id = scopes.id and roles_scopes.tenant_id = scopes.tenant_id
|
|
19
|
+
join resources on
|
|
20
|
+
scopes.resource_id = resources.id and scopes.tenant_id = resources.tenant_id
|
|
21
|
+
where roles.type = ${RoleType.User};
|
|
22
|
+
`);
|
|
23
|
+
const rolesScopesIdsToRemove = rows
|
|
24
|
+
.filter(({ indicator, tenantId }) => indicator === getManagementApiResourceIndicator(tenantId))
|
|
25
|
+
.map(({ rolesScopesId }) => rolesScopesId);
|
|
26
|
+
if (rolesScopesIdsToRemove.length > 0) {
|
|
27
|
+
await pool.query(sql `
|
|
28
|
+
delete from roles_scopes where id in (${sql.join(rolesScopesIdsToRemove, sql `, `)});
|
|
29
|
+
`);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
down: async (pool) => {
|
|
33
|
+
// It cannot be reverted automatically.
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
export default alteration;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { sql } from 'slonik';
|
|
2
|
+
const alteration = {
|
|
3
|
+
up: async (pool) => {
|
|
4
|
+
await pool.query(sql `
|
|
5
|
+
alter table daily_active_users alter column date set default now();
|
|
6
|
+
`);
|
|
7
|
+
},
|
|
8
|
+
down: async (pool) => {
|
|
9
|
+
await pool.query(sql `
|
|
10
|
+
alter table daily_active_users alter column date drop default;
|
|
11
|
+
`);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
export default alteration;
|
package/lib/seeds/cloud-api.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ export declare enum CloudScope {
|
|
|
13
13
|
ManageAffiliate = "manage:affiliate",
|
|
14
14
|
/** The user can create new affiliates and logs. */
|
|
15
15
|
CreateAffiliate = "create:affiliate",
|
|
16
|
-
/** The user can
|
|
17
|
-
|
|
16
|
+
/** The user can prune logs which are expired. */
|
|
17
|
+
PruneLogs = "prune:logs"
|
|
18
18
|
}
|
|
19
19
|
export declare const createCloudApi: () => readonly [UpdateAdminData, ...CreateScope[]];
|
|
20
20
|
export declare const createTenantApplicationRole: () => Readonly<Role>;
|
package/lib/seeds/cloud-api.js
CHANGED
|
@@ -16,8 +16,8 @@ export var CloudScope;
|
|
|
16
16
|
CloudScope["ManageAffiliate"] = "manage:affiliate";
|
|
17
17
|
/** The user can create new affiliates and logs. */
|
|
18
18
|
CloudScope["CreateAffiliate"] = "create:affiliate";
|
|
19
|
-
/** The user can
|
|
20
|
-
CloudScope["
|
|
19
|
+
/** The user can prune logs which are expired. */
|
|
20
|
+
CloudScope["PruneLogs"] = "prune:logs";
|
|
21
21
|
})(CloudScope || (CloudScope = {}));
|
|
22
22
|
export const createCloudApi = () => {
|
|
23
23
|
const resourceId = generateStandardId();
|
package/package.json
CHANGED
package/tables/_before_all.sql
CHANGED
|
@@ -3,7 +3,7 @@ create table daily_active_users (
|
|
|
3
3
|
tenant_id varchar(21) not null
|
|
4
4
|
references tenants (id) on update cascade on delete cascade,
|
|
5
5
|
user_id varchar(21) not null,
|
|
6
|
-
date timestamptz not null,
|
|
6
|
+
date timestamptz not null default (now()),
|
|
7
7
|
primary key (id),
|
|
8
8
|
constraint daily_active_users__user_id_date
|
|
9
9
|
unique (user_id, date)
|