@jskit-ai/users-core 0.1.33 → 0.1.35

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.
@@ -1,85 +0,0 @@
1
- const WORKSPACES_TABLE = "workspaces";
2
- const WORKSPACE_SETTINGS_TABLE = "workspace_settings";
3
- const LEGACY_COLOR_COLUMN = "color";
4
- const SETTINGS_LIGHT_PRIMARY_COLOR_COLUMN = "light_primary_color";
5
- const DEFAULT_WORKSPACE_COLOR = "#1867C0";
6
-
7
- async function hasTable(knex, tableName) {
8
- return knex.schema.hasTable(tableName);
9
- }
10
-
11
- async function hasColumn(knex, tableName, columnName) {
12
- return knex.schema.hasColumn(tableName, columnName);
13
- }
14
-
15
- function normalizeHexColor(value) {
16
- const normalized = String(value || "").trim().toUpperCase();
17
- return /^#[0-9A-F]{6}$/.test(normalized) ? normalized : "";
18
- }
19
-
20
- exports.up = async function up(knex) {
21
- const hasWorkspaces = await hasTable(knex, WORKSPACES_TABLE);
22
- if (!hasWorkspaces) {
23
- return;
24
- }
25
-
26
- const hasLegacyColor = await hasColumn(knex, WORKSPACES_TABLE, LEGACY_COLOR_COLUMN);
27
- if (!hasLegacyColor) {
28
- return;
29
- }
30
-
31
- await knex.schema.alterTable(WORKSPACES_TABLE, (table) => {
32
- table.dropColumn(LEGACY_COLOR_COLUMN);
33
- });
34
- };
35
-
36
- exports.down = async function down(knex) {
37
- const hasWorkspaces = await hasTable(knex, WORKSPACES_TABLE);
38
- if (!hasWorkspaces) {
39
- return;
40
- }
41
-
42
- const hasLegacyColor = await hasColumn(knex, WORKSPACES_TABLE, LEGACY_COLOR_COLUMN);
43
- if (!hasLegacyColor) {
44
- await knex.schema.alterTable(WORKSPACES_TABLE, (table) => {
45
- table.string(LEGACY_COLOR_COLUMN, 7).notNullable().defaultTo(DEFAULT_WORKSPACE_COLOR);
46
- });
47
- }
48
-
49
- const hasWorkspaceSettings = await hasTable(knex, WORKSPACE_SETTINGS_TABLE);
50
- if (!hasWorkspaceSettings) {
51
- return;
52
- }
53
-
54
- const hasLightPrimaryColor = await hasColumn(
55
- knex,
56
- WORKSPACE_SETTINGS_TABLE,
57
- SETTINGS_LIGHT_PRIMARY_COLOR_COLUMN
58
- );
59
- if (!hasLightPrimaryColor) {
60
- return;
61
- }
62
-
63
- const workspaceSettingsRows = await knex(WORKSPACE_SETTINGS_TABLE).select(
64
- "workspace_id",
65
- SETTINGS_LIGHT_PRIMARY_COLOR_COLUMN
66
- );
67
-
68
- for (const row of workspaceSettingsRows) {
69
- const workspaceId = Number(row?.workspace_id || 0);
70
- if (!Number.isInteger(workspaceId) || workspaceId < 1) {
71
- continue;
72
- }
73
-
74
- const restoredColor = normalizeHexColor(row?.[SETTINGS_LIGHT_PRIMARY_COLOR_COLUMN]);
75
- if (!restoredColor) {
76
- continue;
77
- }
78
-
79
- await knex(WORKSPACES_TABLE)
80
- .where({ id: workspaceId })
81
- .update({
82
- color: restoredColor
83
- });
84
- }
85
- };
@@ -1,197 +0,0 @@
1
- // @jskit-contract users.settings-fields.workspace.v1
2
- // Append-only settings field registrations for workspace settings.
3
-
4
- import { Type } from "typebox";
5
- import { normalizeText } from "@jskit-ai/kernel/shared/actions/textNormalization";
6
- import {
7
- DEFAULT_WORKSPACE_DARK_PALETTE,
8
- DEFAULT_WORKSPACE_LIGHT_PALETTE,
9
- coerceWorkspaceThemeColor
10
- } from "@jskit-ai/users-core/shared/settings";
11
- import {
12
- defineField,
13
- resetWorkspaceSettingsFields
14
- } from "@jskit-ai/users-core/shared/resources/workspaceSettingsFields";
15
-
16
- function normalizeHexColor(value) {
17
- const color = normalizeText(value);
18
- return /^#[0-9A-Fa-f]{6}$/.test(color) ? color.toUpperCase() : null;
19
- }
20
-
21
- resetWorkspaceSettingsFields();
22
-
23
- defineField({
24
- key: "lightPrimaryColor",
25
- dbColumn: "light_primary_color",
26
- required: true,
27
- inputSchema: Type.String({
28
- minLength: 7,
29
- maxLength: 7,
30
- pattern: "^#[0-9A-Fa-f]{6}$",
31
- messages: {
32
- required: "Light primary color is required.",
33
- pattern: "Light primary color must be a hex color like #1867C0.",
34
- default: "Light primary color must be a hex color like #1867C0."
35
- }
36
- }),
37
- outputSchema: Type.String({ minLength: 7, maxLength: 7, pattern: "^#[0-9A-Fa-f]{6}$" }),
38
- normalizeInput: normalizeHexColor,
39
- normalizeOutput: (value) => coerceWorkspaceThemeColor(value, DEFAULT_WORKSPACE_LIGHT_PALETTE.color),
40
- resolveDefault: () => DEFAULT_WORKSPACE_LIGHT_PALETTE.color
41
- });
42
-
43
- defineField({
44
- key: "lightSecondaryColor",
45
- dbColumn: "light_secondary_color",
46
- required: true,
47
- inputSchema: Type.String({
48
- minLength: 7,
49
- maxLength: 7,
50
- pattern: "^#[0-9A-Fa-f]{6}$",
51
- messages: {
52
- required: "Light secondary color is required.",
53
- pattern: "Light secondary color must be a hex color like #48A9A6.",
54
- default: "Light secondary color must be a hex color like #48A9A6."
55
- }
56
- }),
57
- outputSchema: Type.String({ minLength: 7, maxLength: 7, pattern: "^#[0-9A-Fa-f]{6}$" }),
58
- normalizeInput: normalizeHexColor,
59
- normalizeOutput: (value) => coerceWorkspaceThemeColor(value, DEFAULT_WORKSPACE_LIGHT_PALETTE.secondaryColor),
60
- resolveDefault: () => DEFAULT_WORKSPACE_LIGHT_PALETTE.secondaryColor
61
- });
62
-
63
- defineField({
64
- key: "lightSurfaceColor",
65
- dbColumn: "light_surface_color",
66
- required: true,
67
- inputSchema: Type.String({
68
- minLength: 7,
69
- maxLength: 7,
70
- pattern: "^#[0-9A-Fa-f]{6}$",
71
- messages: {
72
- required: "Light surface color is required.",
73
- pattern: "Light surface color must be a hex color like #FFFFFF.",
74
- default: "Light surface color must be a hex color like #FFFFFF."
75
- }
76
- }),
77
- outputSchema: Type.String({ minLength: 7, maxLength: 7, pattern: "^#[0-9A-Fa-f]{6}$" }),
78
- normalizeInput: normalizeHexColor,
79
- normalizeOutput: (value) => coerceWorkspaceThemeColor(value, DEFAULT_WORKSPACE_LIGHT_PALETTE.surfaceColor),
80
- resolveDefault: () => DEFAULT_WORKSPACE_LIGHT_PALETTE.surfaceColor
81
- });
82
-
83
- defineField({
84
- key: "lightSurfaceVariantColor",
85
- dbColumn: "light_surface_variant_color",
86
- required: true,
87
- inputSchema: Type.String({
88
- minLength: 7,
89
- maxLength: 7,
90
- pattern: "^#[0-9A-Fa-f]{6}$",
91
- messages: {
92
- required: "Light surface variant color is required.",
93
- pattern: "Light surface variant color must be a hex color like #424242.",
94
- default: "Light surface variant color must be a hex color like #424242."
95
- }
96
- }),
97
- outputSchema: Type.String({ minLength: 7, maxLength: 7, pattern: "^#[0-9A-Fa-f]{6}$" }),
98
- normalizeInput: normalizeHexColor,
99
- normalizeOutput: (value) => coerceWorkspaceThemeColor(value, DEFAULT_WORKSPACE_LIGHT_PALETTE.surfaceVariantColor),
100
- resolveDefault: () => DEFAULT_WORKSPACE_LIGHT_PALETTE.surfaceVariantColor
101
- });
102
-
103
- defineField({
104
- key: "darkPrimaryColor",
105
- dbColumn: "dark_primary_color",
106
- required: true,
107
- inputSchema: Type.String({
108
- minLength: 7,
109
- maxLength: 7,
110
- pattern: "^#[0-9A-Fa-f]{6}$",
111
- messages: {
112
- required: "Dark primary color is required.",
113
- pattern: "Dark primary color must be a hex color like #2196F3.",
114
- default: "Dark primary color must be a hex color like #2196F3."
115
- }
116
- }),
117
- outputSchema: Type.String({ minLength: 7, maxLength: 7, pattern: "^#[0-9A-Fa-f]{6}$" }),
118
- normalizeInput: normalizeHexColor,
119
- normalizeOutput: (value) => coerceWorkspaceThemeColor(value, DEFAULT_WORKSPACE_DARK_PALETTE.color),
120
- resolveDefault: () => DEFAULT_WORKSPACE_DARK_PALETTE.color
121
- });
122
-
123
- defineField({
124
- key: "darkSecondaryColor",
125
- dbColumn: "dark_secondary_color",
126
- required: true,
127
- inputSchema: Type.String({
128
- minLength: 7,
129
- maxLength: 7,
130
- pattern: "^#[0-9A-Fa-f]{6}$",
131
- messages: {
132
- required: "Dark secondary color is required.",
133
- pattern: "Dark secondary color must be a hex color like #54B6B2.",
134
- default: "Dark secondary color must be a hex color like #54B6B2."
135
- }
136
- }),
137
- outputSchema: Type.String({ minLength: 7, maxLength: 7, pattern: "^#[0-9A-Fa-f]{6}$" }),
138
- normalizeInput: normalizeHexColor,
139
- normalizeOutput: (value) => coerceWorkspaceThemeColor(value, DEFAULT_WORKSPACE_DARK_PALETTE.secondaryColor),
140
- resolveDefault: () => DEFAULT_WORKSPACE_DARK_PALETTE.secondaryColor
141
- });
142
-
143
- defineField({
144
- key: "darkSurfaceColor",
145
- dbColumn: "dark_surface_color",
146
- required: true,
147
- inputSchema: Type.String({
148
- minLength: 7,
149
- maxLength: 7,
150
- pattern: "^#[0-9A-Fa-f]{6}$",
151
- messages: {
152
- required: "Dark surface color is required.",
153
- pattern: "Dark surface color must be a hex color like #212121.",
154
- default: "Dark surface color must be a hex color like #212121."
155
- }
156
- }),
157
- outputSchema: Type.String({ minLength: 7, maxLength: 7, pattern: "^#[0-9A-Fa-f]{6}$" }),
158
- normalizeInput: normalizeHexColor,
159
- normalizeOutput: (value) => coerceWorkspaceThemeColor(value, DEFAULT_WORKSPACE_DARK_PALETTE.surfaceColor),
160
- resolveDefault: () => DEFAULT_WORKSPACE_DARK_PALETTE.surfaceColor
161
- });
162
-
163
- defineField({
164
- key: "darkSurfaceVariantColor",
165
- dbColumn: "dark_surface_variant_color",
166
- required: true,
167
- inputSchema: Type.String({
168
- minLength: 7,
169
- maxLength: 7,
170
- pattern: "^#[0-9A-Fa-f]{6}$",
171
- messages: {
172
- required: "Dark surface variant color is required.",
173
- pattern: "Dark surface variant color must be a hex color like #C8C8C8.",
174
- default: "Dark surface variant color must be a hex color like #C8C8C8."
175
- }
176
- }),
177
- outputSchema: Type.String({ minLength: 7, maxLength: 7, pattern: "^#[0-9A-Fa-f]{6}$" }),
178
- normalizeInput: normalizeHexColor,
179
- normalizeOutput: (value) => coerceWorkspaceThemeColor(value, DEFAULT_WORKSPACE_DARK_PALETTE.surfaceVariantColor),
180
- resolveDefault: () => DEFAULT_WORKSPACE_DARK_PALETTE.surfaceVariantColor
181
- });
182
-
183
- defineField({
184
- key: "invitesEnabled",
185
- dbColumn: "invites_enabled",
186
- required: true,
187
- inputSchema: Type.Boolean({
188
- messages: {
189
- required: "invitesEnabled is required.",
190
- default: "invitesEnabled must be a boolean."
191
- }
192
- }),
193
- outputSchema: Type.Boolean(),
194
- normalizeInput: (value) => value === true,
195
- normalizeOutput: (value) => value !== false,
196
- resolveDefault: ({ defaultInvitesEnabled } = {}) => defaultInvitesEnabled !== false
197
- });