File tree Expand file tree Collapse file tree 4 files changed +70
-0
lines changed
src/foundations/jsonb-types Expand file tree Collapse file tree 4 files changed +70
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { sql } from '@silverhand/slonik' ;
2
+
3
+ import type { AlterationScript } from '../lib/types/alteration.js' ;
4
+
5
+ import { applyTableRls , dropTableRls } from './utils/1704934999-tables.js' ;
6
+
7
+ const alteration : AlterationScript = {
8
+ up : async ( pool ) => {
9
+ await pool . query ( sql `
10
+ create table account_centers (
11
+ tenant_id varchar(21) not null
12
+ references tenants (id) on update cascade on delete cascade,
13
+ id varchar(21) not null,
14
+ /** The whole feature can be disabled */
15
+ enabled boolean not null default false,
16
+ /** Control each fields */
17
+ fields jsonb /* @use AccountCenterFieldControl */ not null default '{}'::jsonb,
18
+ primary key (tenant_id, id)
19
+ );
20
+ ` ) ;
21
+ await applyTableRls ( pool , 'account_centers' ) ;
22
+ } ,
23
+ down : async ( pool ) => {
24
+ await dropTableRls ( pool , 'account_centers' ) ;
25
+ await pool . query ( sql `
26
+ drop table account_centers;
27
+ ` ) ;
28
+ } ,
29
+ } ;
30
+
31
+ export default alteration ;
Original file line number Diff line number Diff line change
1
+ import { z } from 'zod' ;
2
+
3
+ export enum AccountCenterControlValue {
4
+ Off = 'Off' ,
5
+ ReadOnly = 'ReadOnly' ,
6
+ Edit = 'Edit' ,
7
+ }
8
+
9
+ /**
10
+ * Control list of each field in the account center (profile API)
11
+ * all fields are optional, if not set, the default value is `Off`
12
+ * this can make the alteration of the field control easier
13
+ */
14
+ export const accountCenterFieldControlGuard = z
15
+ . object ( {
16
+ name : z . nativeEnum ( AccountCenterControlValue ) ,
17
+ avatar : z . nativeEnum ( AccountCenterControlValue ) ,
18
+ profile : z . nativeEnum ( AccountCenterControlValue ) ,
19
+ email : z . nativeEnum ( AccountCenterControlValue ) ,
20
+ phone : z . nativeEnum ( AccountCenterControlValue ) ,
21
+ password : z . nativeEnum ( AccountCenterControlValue ) ,
22
+ username : z . nativeEnum ( AccountCenterControlValue ) ,
23
+ social : z . nativeEnum ( AccountCenterControlValue ) ,
24
+ customData : z . nativeEnum ( AccountCenterControlValue ) ,
25
+ } )
26
+ . partial ( ) ;
27
+
28
+ export type AccountCenterFieldControl = z . infer < typeof accountCenterFieldControlGuard > ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ export * from './users.js';
9
9
export * from './sso-connector.js' ;
10
10
export * from './applications.js' ;
11
11
export * from './verification-records.js' ;
12
+ export * from './account-centers.js' ;
12
13
13
14
export {
14
15
configurableConnectorMetadataGuard ,
Original file line number Diff line number Diff line change
1
+ create table account_centers (
2
+ tenant_id varchar (21 ) not null
3
+ references tenants (id) on update cascade on delete cascade ,
4
+ id varchar (21 ) not null ,
5
+ /* * The whole feature can be disabled */
6
+ enabled boolean not null default false,
7
+ /* * Control each fields */
8
+ fields jsonb /* @use AccountCenterFieldControl */ not null default ' {}' ::jsonb,
9
+ primary key (tenant_id, id)
10
+ );
You can’t perform that action at this time.
0 commit comments