hazo_auth 10.23.3 → 10.25.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/README.md +8 -0
- package/cli-src/lib/auth/auth_types.ts +6 -0
- package/cli-src/lib/auth/hazo_get_auth.server.ts +3 -0
- package/cli-src/lib/location_fields_config.server.ts +42 -0
- package/cli-src/lib/my_settings_config.server.ts +6 -0
- package/cli-src/lib/register_config.server.ts +16 -0
- package/cli-src/lib/services/group_service.ts +380 -0
- package/cli-src/lib/services/index.ts +1 -0
- package/cli-src/lib/services/location_fields_helper.ts +30 -0
- package/cli-src/lib/services/registration_service.ts +21 -0
- package/cli-src/lib/services/user_update_service.ts +7 -0
- package/dist/components/layouts/my_settings/hooks/use_my_settings.d.ts +8 -0
- package/dist/components/layouts/my_settings/hooks/use_my_settings.d.ts.map +1 -1
- package/dist/components/layouts/my_settings/hooks/use_my_settings.js +37 -0
- package/dist/components/layouts/my_settings/index.d.ts +6 -1
- package/dist/components/layouts/my_settings/index.d.ts.map +1 -1
- package/dist/components/layouts/my_settings/index.js +3 -3
- package/dist/components/layouts/register/hooks/use_register_form.d.ts +15 -1
- package/dist/components/layouts/register/hooks/use_register_form.d.ts.map +1 -1
- package/dist/components/layouts/register/hooks/use_register_form.js +69 -4
- package/dist/components/layouts/register/index.d.ts +7 -1
- package/dist/components/layouts/register/index.d.ts.map +1 -1
- package/dist/components/layouts/register/index.js +24 -3
- package/dist/components/layouts/shared/hooks/use_auth_status.d.ts +3 -0
- package/dist/components/layouts/shared/hooks/use_auth_status.d.ts.map +1 -1
- package/dist/components/layouts/shared/hooks/use_auth_status.js +5 -2
- package/dist/lib/auth/auth_types.d.ts +3 -0
- package/dist/lib/auth/auth_types.d.ts.map +1 -1
- package/dist/lib/auth/hazo_get_auth.server.d.ts.map +1 -1
- package/dist/lib/auth/hazo_get_auth.server.js +3 -0
- package/dist/lib/location_fields_config.server.d.ts +22 -0
- package/dist/lib/location_fields_config.server.d.ts.map +1 -0
- package/dist/lib/location_fields_config.server.js +31 -0
- package/dist/lib/my_settings_config.server.d.ts +4 -0
- package/dist/lib/my_settings_config.server.d.ts.map +1 -1
- package/dist/lib/my_settings_config.server.js +3 -0
- package/dist/lib/register_config.server.d.ts +10 -0
- package/dist/lib/register_config.server.d.ts.map +1 -1
- package/dist/lib/register_config.server.js +7 -0
- package/dist/lib/services/group_service.d.ts +66 -0
- package/dist/lib/services/group_service.d.ts.map +1 -0
- package/dist/lib/services/group_service.js +266 -0
- package/dist/lib/services/index.d.ts +1 -0
- package/dist/lib/services/index.d.ts.map +1 -1
- package/dist/lib/services/index.js +1 -0
- package/dist/lib/services/location_fields_helper.d.ts +13 -0
- package/dist/lib/services/location_fields_helper.d.ts.map +1 -0
- package/dist/lib/services/location_fields_helper.js +24 -0
- package/dist/lib/services/registration_service.d.ts +9 -0
- package/dist/lib/services/registration_service.d.ts.map +1 -1
- package/dist/lib/services/registration_service.js +11 -0
- package/dist/lib/services/user_update_service.d.ts +5 -0
- package/dist/lib/services/user_update_service.d.ts.map +1 -1
- package/dist/lib/services/user_update_service.js +2 -0
- package/dist/locales/en.json +9 -0
- package/dist/page_components/my_settings.d.ts +9 -1
- package/dist/page_components/my_settings.d.ts.map +1 -1
- package/dist/page_components/my_settings.js +8 -2
- package/dist/server/routes/me.d.ts.map +1 -1
- package/dist/server/routes/me.js +5 -1
- package/dist/server/routes/register.d.ts.map +1 -1
- package/dist/server/routes/register.js +46 -0
- package/dist/server/routes/update_user.d.ts.map +1 -1
- package/dist/server/routes/update_user.js +24 -1
- package/dist/server/routes/user_management_users.d.ts +1 -1
- package/dist/server_pages/my_settings.d.ts.map +1 -1
- package/dist/server_pages/my_settings.js +1 -1
- package/dist/server_pages/register.d.ts.map +1 -1
- package/dist/server_pages/register.js +1 -1
- package/dist/server_pages/register_client_wrapper.d.ts +4 -2
- package/dist/server_pages/register_client_wrapper.d.ts.map +1 -1
- package/dist/server_pages/register_client_wrapper.js +2 -2
- package/package.json +10 -10
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// file_description: server-only helper to read location field toggles from hazo_auth_config.ini
|
|
2
|
+
// section: server-only-guard
|
|
3
|
+
import "server-only";
|
|
4
|
+
// section: imports
|
|
5
|
+
import { get_config_boolean } from "./config/config_loader.server.js";
|
|
6
|
+
// section: constants
|
|
7
|
+
const SECTION_NAME = "hazo_auth__custom_fields";
|
|
8
|
+
// section: helpers
|
|
9
|
+
/**
|
|
10
|
+
* Reads the indexed location field toggles (country / state_province / suburb)
|
|
11
|
+
* from `[hazo_auth__custom_fields]` in hazo_auth_config.ini. All default to
|
|
12
|
+
* `false` — registration is unchanged for apps that don't opt in. These three
|
|
13
|
+
* columns are indexed (migration 025) for cohort benchmarking (GROUP BY
|
|
14
|
+
* country, state_province); arbitrary free-form fields go through the
|
|
15
|
+
* existing app_user_data schema (`get_app_user_data_schema()`) instead.
|
|
16
|
+
* @returns Which location fields are enabled
|
|
17
|
+
*/
|
|
18
|
+
export function get_location_fields_config() {
|
|
19
|
+
return {
|
|
20
|
+
country: get_config_boolean(SECTION_NAME, "location_country", false),
|
|
21
|
+
state_province: get_config_boolean(SECTION_NAME, "location_state_province", false),
|
|
22
|
+
suburb: get_config_boolean(SECTION_NAME, "location_suburb", false),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* True if at least one location field is enabled — lets a consumer skip
|
|
27
|
+
* rendering an empty "Location" section entirely.
|
|
28
|
+
*/
|
|
29
|
+
export function is_any_location_field_enabled(config) {
|
|
30
|
+
return config.country || config.state_province || config.suburb;
|
|
31
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import "server-only";
|
|
2
|
+
import { type LocationFieldsConfig } from "./location_fields_config.server.js";
|
|
2
3
|
export type MySettingsConfig = {
|
|
3
4
|
userFields: {
|
|
4
5
|
show_name_field: boolean;
|
|
5
6
|
show_email_field: boolean;
|
|
6
7
|
show_password_field: boolean;
|
|
7
8
|
};
|
|
9
|
+
/** Which indexed location fields to show as an editable "Location" card —
|
|
10
|
+
* see [hazo_auth__custom_fields] in hazo_auth_config.ini. */
|
|
11
|
+
locationFields: LocationFieldsConfig;
|
|
8
12
|
passwordRequirements: {
|
|
9
13
|
minimum_length: number;
|
|
10
14
|
require_uppercase: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"my_settings_config.server.d.ts","sourceRoot":"","sources":["../../src/lib/my_settings_config.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"my_settings_config.server.d.ts","sourceRoot":"","sources":["../../src/lib/my_settings_config.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAUrB,OAAO,EAA8B,KAAK,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGxG,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE;QACV,eAAe,EAAE,OAAO,CAAC;QACzB,gBAAgB,EAAE,OAAO,CAAC;QAC1B,mBAAmB,EAAE,OAAO,CAAC;KAC9B,CAAC;IACF;kEAC8D;IAC9D,cAAc,EAAE,oBAAoB,CAAC;IACrC,oBAAoB,EAAE;QACpB,cAAc,EAAE,MAAM,CAAC;QACvB,iBAAiB,EAAE,OAAO,CAAC;QAC3B,iBAAiB,EAAE,OAAO,CAAC;QAC3B,cAAc,EAAE,OAAO,CAAC;QACxB,eAAe,EAAE,OAAO,CAAC;KAC1B,CAAC;IACF,cAAc,EAAE;QACd,kBAAkB,EAAE,OAAO,CAAC;QAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,cAAc,EAAE,MAAM,CAAC;QACvB,kBAAkB,EAAE,OAAO,CAAC;QAC5B,4BAA4B,EAAE,UAAU,GAAG,SAAS,CAAC;QACrD,4BAA4B,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;QACtD,kBAAkB,EAAE,MAAM,CAAC;KAC5B,CAAC;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,qBAAqB,EAAE,OAAO,CAAC;IAC/B,QAAQ,EAAE;QACR,6BAA6B,EAAE,MAAM,CAAC;QACtC,sBAAsB,EAAE,MAAM,CAAC;QAC/B,2BAA2B,EAAE,MAAM,CAAC;QACpC,uBAAuB,EAAE,MAAM,CAAC;KACjC,CAAC;IACF,OAAO,EAAE;QACP,aAAa,EAAE,MAAM,CAAC;QACtB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,yBAAyB,EAAE,MAAM,CAAC;QAClC,uBAAuB,EAAE,MAAM,CAAC;QAChC,0BAA0B,EAAE,MAAM,CAAC;QACnC,0BAA0B,EAAE,MAAM,CAAC;QACnC,+BAA+B,EAAE,MAAM,CAAC;QACxC,4BAA4B,EAAE,MAAM,CAAC;KACtC,CAAC;IACF,SAAS,EAAE;QACT,wBAAwB,EAAE,MAAM,EAAE,CAAC;QACnC,wBAAwB,EAAE,MAAM,EAAE,CAAC;KACpC,CAAC;CACH,CAAC;AAGF;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAoEzD"}
|
|
@@ -9,6 +9,7 @@ import { get_profile_picture_config } from "./profile_picture_config.server.js";
|
|
|
9
9
|
import { get_messages_config } from "./messages_config.server.js";
|
|
10
10
|
import { get_ui_sizes_config } from "./ui_sizes_config.server.js";
|
|
11
11
|
import { get_file_types_config } from "./file_types_config.server.js";
|
|
12
|
+
import { get_location_fields_config } from "./location_fields_config.server.js";
|
|
12
13
|
// section: helpers
|
|
13
14
|
/**
|
|
14
15
|
* Reads my settings layout configuration from hazo_auth_config.ini file
|
|
@@ -51,8 +52,10 @@ export function get_my_settings_config() {
|
|
|
51
52
|
const loginButtonLabel = get_config_value_optional(section, "login_button_label");
|
|
52
53
|
const loginPath = get_config_value(section, "login_path", "/hazo_auth/login");
|
|
53
54
|
const enableAccountDeletion = get_config_boolean(section, "enable_account_deletion", false);
|
|
55
|
+
const locationFields = get_location_fields_config();
|
|
54
56
|
return {
|
|
55
57
|
userFields,
|
|
58
|
+
locationFields,
|
|
56
59
|
passwordRequirements,
|
|
57
60
|
profilePicture,
|
|
58
61
|
heading,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import "server-only";
|
|
2
|
+
import { type LocationFieldsConfig } from "./location_fields_config.server.js";
|
|
3
|
+
import { type AppUserDataSchema } from "./app_user_data_config.server.js";
|
|
2
4
|
export type RegisterConfig = {
|
|
3
5
|
showNameField: boolean;
|
|
4
6
|
passwordRequirements: {
|
|
@@ -28,6 +30,14 @@ export type RegisterConfig = {
|
|
|
28
30
|
enable_facebook_oauth: boolean;
|
|
29
31
|
facebook_button_text: string | undefined;
|
|
30
32
|
};
|
|
33
|
+
/** Which indexed location fields to render on the registration form — see
|
|
34
|
+
* [hazo_auth__custom_fields] in hazo_auth_config.ini. */
|
|
35
|
+
locationFields: LocationFieldsConfig;
|
|
36
|
+
/** Arbitrary custom fields to render on the registration form, reusing the
|
|
37
|
+
* EXISTING [hazo_auth__app_user_data] JSON Schema config (ticket 09 does NOT
|
|
38
|
+
* introduce a second, parallel custom-field config format). Null when
|
|
39
|
+
* schema-based app_user_data editing isn't enabled. */
|
|
40
|
+
customFieldsSchema: AppUserDataSchema | null;
|
|
31
41
|
};
|
|
32
42
|
/**
|
|
33
43
|
* Reads register layout configuration from hazo_auth_config.ini file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register_config.server.d.ts","sourceRoot":"","sources":["../../src/lib/register_config.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"register_config.server.d.ts","sourceRoot":"","sources":["../../src/lib/register_config.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAarB,OAAO,EAA8B,KAAK,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACxG,OAAO,EAA4B,KAAK,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAQjG,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,oBAAoB,EAAE;QACpB,cAAc,EAAE,MAAM,CAAC;QACvB,iBAAiB,EAAE,OAAO,CAAC;QAC3B,iBAAiB,EAAE,OAAO,CAAC;QAC3B,cAAc,EAAE,OAAO,CAAC;QACxB,eAAe,EAAE,OAAO,CAAC;KAC1B,CAAC;IACF,sBAAsB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,gBAAgB,EAAE,OAAO,CAAC;IAC1B,oBAAoB,EAAE,OAAO,CAAC;IAC9B,qBAAqB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,kGAAkG;IAClG,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,0BAA0B;IAC1B,KAAK,EAAE;QACL,aAAa,EAAE,OAAO,CAAC;QACvB,qBAAqB,EAAE,OAAO,CAAC;QAC/B,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;QACvC,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;QACvC,qBAAqB,EAAE,OAAO,CAAC;QAC/B,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC;KAC1C,CAAC;IACF;8DAC0D;IAC1D,cAAc,EAAE,oBAAoB,CAAC;IACrC;;;4DAGwD;IACxD,kBAAkB,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAC9C,CAAC;AAGF;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,cAAc,CAqFpD"}
|
|
@@ -7,6 +7,8 @@ import { get_password_requirements_config } from "./password_requirements_config
|
|
|
7
7
|
import { get_already_logged_in_config } from "./already_logged_in_config.server.js";
|
|
8
8
|
import { get_user_fields_config } from "./user_fields_config.server.js";
|
|
9
9
|
import { get_oauth_config } from "./oauth_config.server.js";
|
|
10
|
+
import { get_location_fields_config } from "./location_fields_config.server.js";
|
|
11
|
+
import { get_app_user_data_schema } from "./app_user_data_config.server.js";
|
|
10
12
|
// Default image path - consuming apps should either:
|
|
11
13
|
// 1. Configure their own image_src in hazo_auth_config.ini
|
|
12
14
|
// 2. Copy the default images from node_modules/hazo_auth/public/hazo_auth/images/ to their public folder
|
|
@@ -42,6 +44,9 @@ export function get_register_config() {
|
|
|
42
44
|
const imageBackgroundColor = get_config_value("hazo_auth__register_layout", "image_background_color", "#e2e8f0");
|
|
43
45
|
// Get OAuth configuration (shared with login)
|
|
44
46
|
const oauthConfig = get_oauth_config();
|
|
47
|
+
// Location + arbitrary custom fields (ticket 09)
|
|
48
|
+
const locationFields = get_location_fields_config();
|
|
49
|
+
const customFieldsSchema = get_app_user_data_schema();
|
|
45
50
|
// For the register page, the Google button text is undefined unless the
|
|
46
51
|
// consumer explicitly overrides it — RegisterLayout falls back to
|
|
47
52
|
// `t("register.oauth.google_button_default")` ("Sign up with Google").
|
|
@@ -67,5 +72,7 @@ export function get_register_config() {
|
|
|
67
72
|
enable_facebook_oauth: oauthConfig.enable_facebook_oauth,
|
|
68
73
|
facebook_button_text: oauthConfig.facebook_button_text,
|
|
69
74
|
},
|
|
75
|
+
locationFields,
|
|
76
|
+
customFieldsSchema,
|
|
70
77
|
};
|
|
71
78
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { HazoConnectAdapter } from "hazo_connect";
|
|
2
|
+
export type GroupStatus = "ACTIVE" | "ARCHIVED";
|
|
3
|
+
export type GroupMembershipStatus = "ACTIVE" | "REMOVED";
|
|
4
|
+
export type GroupRecord = {
|
|
5
|
+
id: string;
|
|
6
|
+
scope_id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
join_code: string;
|
|
9
|
+
created_by: string | null;
|
|
10
|
+
metadata: Record<string, unknown> | null;
|
|
11
|
+
status: GroupStatus;
|
|
12
|
+
created_at: string;
|
|
13
|
+
changed_at: string;
|
|
14
|
+
};
|
|
15
|
+
export type GroupMembershipRecord = {
|
|
16
|
+
user_id: string;
|
|
17
|
+
group_id: string;
|
|
18
|
+
role_id: string | null;
|
|
19
|
+
joined_at: string;
|
|
20
|
+
status: GroupMembershipStatus;
|
|
21
|
+
};
|
|
22
|
+
export type GroupServiceResult = {
|
|
23
|
+
success: boolean;
|
|
24
|
+
group?: GroupRecord;
|
|
25
|
+
groups?: GroupRecord[];
|
|
26
|
+
membership?: GroupMembershipRecord;
|
|
27
|
+
members?: GroupMembershipRecord[];
|
|
28
|
+
total?: number;
|
|
29
|
+
error?: string;
|
|
30
|
+
};
|
|
31
|
+
export type CreateGroupData = {
|
|
32
|
+
scope_id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
created_by?: string;
|
|
35
|
+
metadata?: Record<string, unknown>;
|
|
36
|
+
};
|
|
37
|
+
export type JoinByCodeData = {
|
|
38
|
+
user_id: string;
|
|
39
|
+
join_code: string;
|
|
40
|
+
role_id?: string;
|
|
41
|
+
};
|
|
42
|
+
export type GetMembersOptions = {
|
|
43
|
+
limit?: number;
|
|
44
|
+
offset?: number;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new group within a scope, generating a unique join code.
|
|
48
|
+
* Uniqueness is checked proactively (and enforced at the DB level by a
|
|
49
|
+
* UNIQUE constraint on hazo_groups.join_code).
|
|
50
|
+
*/
|
|
51
|
+
export declare function create_group(adapter: HazoConnectAdapter, data: CreateGroupData): Promise<GroupServiceResult>;
|
|
52
|
+
/**
|
|
53
|
+
* Joins a user to a group by join code. Idempotent: an existing ACTIVE
|
|
54
|
+
* membership is returned as-is rather than erroring; a previously REMOVED
|
|
55
|
+
* membership is reactivated.
|
|
56
|
+
*/
|
|
57
|
+
export declare function join_by_code(adapter: HazoConnectAdapter, data: JoinByCodeData): Promise<GroupServiceResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Gets a paginated page of a group's active members.
|
|
60
|
+
*/
|
|
61
|
+
export declare function get_members(adapter: HazoConnectAdapter, group_id: string, options?: GetMembersOptions): Promise<GroupServiceResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Gets every group a user has an active membership in.
|
|
64
|
+
*/
|
|
65
|
+
export declare function get_user_groups(adapter: HazoConnectAdapter, user_id: string): Promise<GroupServiceResult>;
|
|
66
|
+
//# sourceMappingURL=group_service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group_service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/group_service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AA0BvD,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAC;AAChD,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzD,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC,MAAM,EAAE,WAAW,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,qBAAqB,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IACvB,UAAU,CAAC,EAAE,qBAAqB,CAAC;IACnC,OAAO,CAAC,EAAE,qBAAqB,EAAE,CAAC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAmCF;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,kBAAkB,CAAC,CAkE7B;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,kBAAkB,CAAC,CA+E7B;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,kBAAkB,CAAC,CA4C7B;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,kBAAkB,CAAC,CA0C7B"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { createCrudService } from "hazo_connect/server";
|
|
2
|
+
import { randomInt } from "crypto";
|
|
3
|
+
import { create_app_logger } from "../app_logger.js";
|
|
4
|
+
import { sanitize_error_for_user } from "../utils/error_sanitizer.js";
|
|
5
|
+
import { get_scope_by_id } from "./scope_service.js";
|
|
6
|
+
// section: constants
|
|
7
|
+
/**
|
|
8
|
+
* CRUD service options for hazo_group_memberships table
|
|
9
|
+
* This table uses a composite primary key (user_id, group_id) and no 'id' column
|
|
10
|
+
*/
|
|
11
|
+
const GROUP_MEMBERSHIPS_CRUD_OPTIONS = {
|
|
12
|
+
primaryKeys: ["user_id", "group_id"],
|
|
13
|
+
autoId: false,
|
|
14
|
+
};
|
|
15
|
+
// Uppercase alphanumeric, excluding ambiguous characters (0/O, 1/I/l).
|
|
16
|
+
const JOIN_CODE_ALPHABET = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
|
|
17
|
+
const JOIN_CODE_LENGTH = 6;
|
|
18
|
+
const MAX_JOIN_CODE_ATTEMPTS = 10;
|
|
19
|
+
const DEFAULT_MEMBERS_PAGE_SIZE = 50;
|
|
20
|
+
// section: helpers
|
|
21
|
+
/**
|
|
22
|
+
* Generates a 6-character join code from JOIN_CODE_ALPHABET.
|
|
23
|
+
* Excludes 0/O, 1/I/l so codes are easy to read aloud and transcribe.
|
|
24
|
+
*/
|
|
25
|
+
function generate_join_code() {
|
|
26
|
+
let code = "";
|
|
27
|
+
for (let i = 0; i < JOIN_CODE_LENGTH; i++) {
|
|
28
|
+
code += JOIN_CODE_ALPHABET[randomInt(JOIN_CODE_ALPHABET.length)];
|
|
29
|
+
}
|
|
30
|
+
return code;
|
|
31
|
+
}
|
|
32
|
+
/** Parses the metadata TEXT column back into an object, defaulting to null on bad JSON. */
|
|
33
|
+
function parse_metadata(raw) {
|
|
34
|
+
if (typeof raw !== "string" || raw.length === 0)
|
|
35
|
+
return null;
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(raw);
|
|
38
|
+
}
|
|
39
|
+
catch (_a) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function to_group_record(row) {
|
|
44
|
+
return Object.assign(Object.assign({}, row), { metadata: parse_metadata(row.metadata) });
|
|
45
|
+
}
|
|
46
|
+
// section: main_service
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new group within a scope, generating a unique join code.
|
|
49
|
+
* Uniqueness is checked proactively (and enforced at the DB level by a
|
|
50
|
+
* UNIQUE constraint on hazo_groups.join_code).
|
|
51
|
+
*/
|
|
52
|
+
export async function create_group(adapter, data) {
|
|
53
|
+
var _a;
|
|
54
|
+
try {
|
|
55
|
+
const group_service = createCrudService(adapter, "hazo_groups");
|
|
56
|
+
const now = new Date().toISOString();
|
|
57
|
+
const scope_result = await get_scope_by_id(adapter, data.scope_id);
|
|
58
|
+
if (!scope_result.success) {
|
|
59
|
+
return { success: false, error: "Scope not found" };
|
|
60
|
+
}
|
|
61
|
+
// Proactively avoid known collisions, then insert. If a race slips a
|
|
62
|
+
// duplicate past the proactive check, the DB's UNIQUE constraint on
|
|
63
|
+
// join_code rejects the insert and we regenerate and retry — the
|
|
64
|
+
// proactive check alone can't close that race.
|
|
65
|
+
let last_error;
|
|
66
|
+
for (let attempt = 0; attempt < MAX_JOIN_CODE_ATTEMPTS; attempt++) {
|
|
67
|
+
const candidate = generate_join_code();
|
|
68
|
+
const existing = await group_service.findBy({ join_code: candidate });
|
|
69
|
+
if (Array.isArray(existing) && existing.length > 0) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const inserted = await group_service.insert({
|
|
74
|
+
scope_id: data.scope_id,
|
|
75
|
+
name: data.name,
|
|
76
|
+
join_code: candidate,
|
|
77
|
+
created_by: (_a = data.created_by) !== null && _a !== void 0 ? _a : null,
|
|
78
|
+
metadata: data.metadata ? JSON.stringify(data.metadata) : null,
|
|
79
|
+
status: "ACTIVE",
|
|
80
|
+
created_at: now,
|
|
81
|
+
changed_at: now,
|
|
82
|
+
});
|
|
83
|
+
if (!Array.isArray(inserted) || inserted.length === 0) {
|
|
84
|
+
return { success: false, error: "Failed to create group" };
|
|
85
|
+
}
|
|
86
|
+
return { success: true, group: to_group_record(inserted[0]) };
|
|
87
|
+
}
|
|
88
|
+
catch (insert_error) {
|
|
89
|
+
const message = insert_error instanceof Error ? insert_error.message : String(insert_error);
|
|
90
|
+
if (!/unique/i.test(message)) {
|
|
91
|
+
throw insert_error;
|
|
92
|
+
}
|
|
93
|
+
// join_code collided at the DB level (race with another create_group
|
|
94
|
+
// call) — regenerate and retry.
|
|
95
|
+
last_error = insert_error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
throw last_error !== null && last_error !== void 0 ? last_error : new Error("Failed to generate a unique join code");
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
const logger = create_app_logger();
|
|
102
|
+
const error_message = sanitize_error_for_user(error, {
|
|
103
|
+
logToConsole: true,
|
|
104
|
+
logToLogger: true,
|
|
105
|
+
logger,
|
|
106
|
+
context: {
|
|
107
|
+
filename: "group_service.ts",
|
|
108
|
+
line_number: 0,
|
|
109
|
+
operation: "create_group",
|
|
110
|
+
scope_id: data.scope_id,
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
return { success: false, error: error_message };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Joins a user to a group by join code. Idempotent: an existing ACTIVE
|
|
118
|
+
* membership is returned as-is rather than erroring; a previously REMOVED
|
|
119
|
+
* membership is reactivated.
|
|
120
|
+
*/
|
|
121
|
+
export async function join_by_code(adapter, data) {
|
|
122
|
+
var _a, _b, _c;
|
|
123
|
+
try {
|
|
124
|
+
const group_service = createCrudService(adapter, "hazo_groups");
|
|
125
|
+
const membership_service = createCrudService(adapter, "hazo_group_memberships", GROUP_MEMBERSHIPS_CRUD_OPTIONS);
|
|
126
|
+
const now = new Date().toISOString();
|
|
127
|
+
const normalized_code = data.join_code.trim().toUpperCase();
|
|
128
|
+
const groups = await group_service.findBy({ join_code: normalized_code });
|
|
129
|
+
if (!Array.isArray(groups) || groups.length === 0) {
|
|
130
|
+
return { success: false, error: "Invalid join code" };
|
|
131
|
+
}
|
|
132
|
+
const group = to_group_record(groups[0]);
|
|
133
|
+
if (group.status !== "ACTIVE") {
|
|
134
|
+
return { success: false, error: "This group is no longer accepting members" };
|
|
135
|
+
}
|
|
136
|
+
const existing = await membership_service.findBy({
|
|
137
|
+
user_id: data.user_id,
|
|
138
|
+
group_id: group.id,
|
|
139
|
+
});
|
|
140
|
+
if (Array.isArray(existing) && existing.length > 0) {
|
|
141
|
+
const existing_membership = existing[0];
|
|
142
|
+
if (existing_membership.status === "ACTIVE") {
|
|
143
|
+
return { success: true, group, membership: existing_membership };
|
|
144
|
+
}
|
|
145
|
+
// Reactivate a previously-removed membership.
|
|
146
|
+
const reactivated = await membership_service.upsert({
|
|
147
|
+
user_id: data.user_id,
|
|
148
|
+
group_id: group.id,
|
|
149
|
+
role_id: (_b = (_a = data.role_id) !== null && _a !== void 0 ? _a : existing_membership.role_id) !== null && _b !== void 0 ? _b : null,
|
|
150
|
+
joined_at: now,
|
|
151
|
+
status: "ACTIVE",
|
|
152
|
+
}, ["user_id", "group_id"]);
|
|
153
|
+
return {
|
|
154
|
+
success: true,
|
|
155
|
+
group,
|
|
156
|
+
membership: reactivated[0],
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const inserted = await membership_service.insert({
|
|
160
|
+
user_id: data.user_id,
|
|
161
|
+
group_id: group.id,
|
|
162
|
+
role_id: (_c = data.role_id) !== null && _c !== void 0 ? _c : null,
|
|
163
|
+
joined_at: now,
|
|
164
|
+
status: "ACTIVE",
|
|
165
|
+
});
|
|
166
|
+
if (!Array.isArray(inserted) || inserted.length === 0) {
|
|
167
|
+
return { success: false, error: "Failed to join group" };
|
|
168
|
+
}
|
|
169
|
+
return { success: true, group, membership: inserted[0] };
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
const logger = create_app_logger();
|
|
173
|
+
const error_message = sanitize_error_for_user(error, {
|
|
174
|
+
logToConsole: true,
|
|
175
|
+
logToLogger: true,
|
|
176
|
+
logger,
|
|
177
|
+
context: {
|
|
178
|
+
filename: "group_service.ts",
|
|
179
|
+
line_number: 0,
|
|
180
|
+
operation: "join_by_code",
|
|
181
|
+
user_id: data.user_id,
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
return { success: false, error: error_message };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Gets a paginated page of a group's active members.
|
|
189
|
+
*/
|
|
190
|
+
export async function get_members(adapter, group_id, options = {}) {
|
|
191
|
+
var _a, _b;
|
|
192
|
+
try {
|
|
193
|
+
const membership_service = createCrudService(adapter, "hazo_group_memberships", GROUP_MEMBERSHIPS_CRUD_OPTIONS);
|
|
194
|
+
const limit = (_a = options.limit) !== null && _a !== void 0 ? _a : DEFAULT_MEMBERS_PAGE_SIZE;
|
|
195
|
+
const offset = (_b = options.offset) !== null && _b !== void 0 ? _b : 0;
|
|
196
|
+
const members = await membership_service.list((qb) => qb
|
|
197
|
+
.where("group_id", "eq", group_id)
|
|
198
|
+
.where("status", "eq", "ACTIVE")
|
|
199
|
+
.order("joined_at", "asc")
|
|
200
|
+
.limit(limit)
|
|
201
|
+
.offset(offset));
|
|
202
|
+
const total = await membership_service.findBy({
|
|
203
|
+
group_id,
|
|
204
|
+
status: "ACTIVE",
|
|
205
|
+
});
|
|
206
|
+
return {
|
|
207
|
+
success: true,
|
|
208
|
+
members: members,
|
|
209
|
+
total: Array.isArray(total) ? total.length : 0,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
const logger = create_app_logger();
|
|
214
|
+
const error_message = sanitize_error_for_user(error, {
|
|
215
|
+
logToConsole: true,
|
|
216
|
+
logToLogger: true,
|
|
217
|
+
logger,
|
|
218
|
+
context: {
|
|
219
|
+
filename: "group_service.ts",
|
|
220
|
+
line_number: 0,
|
|
221
|
+
operation: "get_members",
|
|
222
|
+
group_id,
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
return { success: false, error: error_message };
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Gets every group a user has an active membership in.
|
|
230
|
+
*/
|
|
231
|
+
export async function get_user_groups(adapter, user_id) {
|
|
232
|
+
try {
|
|
233
|
+
const membership_service = createCrudService(adapter, "hazo_group_memberships", GROUP_MEMBERSHIPS_CRUD_OPTIONS);
|
|
234
|
+
const group_service = createCrudService(adapter, "hazo_groups");
|
|
235
|
+
const memberships = await membership_service.findBy({
|
|
236
|
+
user_id,
|
|
237
|
+
status: "ACTIVE",
|
|
238
|
+
});
|
|
239
|
+
if (!Array.isArray(memberships) || memberships.length === 0) {
|
|
240
|
+
return { success: true, groups: [] };
|
|
241
|
+
}
|
|
242
|
+
const groups = [];
|
|
243
|
+
for (const membership of memberships) {
|
|
244
|
+
const found = await group_service.findBy({ id: membership.group_id });
|
|
245
|
+
if (Array.isArray(found) && found.length > 0) {
|
|
246
|
+
groups.push(to_group_record(found[0]));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return { success: true, groups };
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
const logger = create_app_logger();
|
|
253
|
+
const error_message = sanitize_error_for_user(error, {
|
|
254
|
+
logToConsole: true,
|
|
255
|
+
logToLogger: true,
|
|
256
|
+
logger,
|
|
257
|
+
context: {
|
|
258
|
+
filename: "group_service.ts",
|
|
259
|
+
line_number: 0,
|
|
260
|
+
operation: "get_user_groups",
|
|
261
|
+
user_id,
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
return { success: false, error: error_message };
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -16,6 +16,7 @@ export * from "./firm_service.js";
|
|
|
16
16
|
export * from "./post_verification_service.js";
|
|
17
17
|
export * from "./scope_service.js";
|
|
18
18
|
export * from "./user_scope_service.js";
|
|
19
|
+
export * from "./group_service.js";
|
|
19
20
|
export * from "./oauth_service.js";
|
|
20
21
|
export * from "./branding_service.js";
|
|
21
22
|
export * from "./google_token_service.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/services/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/services/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC"}
|
|
@@ -18,6 +18,7 @@ export * from "./firm_service.js";
|
|
|
18
18
|
export * from "./post_verification_service.js";
|
|
19
19
|
export * from "./scope_service.js";
|
|
20
20
|
export * from "./user_scope_service.js";
|
|
21
|
+
export * from "./group_service.js";
|
|
21
22
|
export * from "./oauth_service.js";
|
|
22
23
|
export * from "./branding_service.js";
|
|
23
24
|
export * from "./google_token_service.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type LocationFieldsInput = {
|
|
2
|
+
country?: string;
|
|
3
|
+
state_province?: string;
|
|
4
|
+
suburb?: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Returns only the location fields that were actually provided and non-blank,
|
|
8
|
+
* trimmed — ready to spread straight into an `insert`/`updateById` data object.
|
|
9
|
+
* @param location - Raw location input (e.g. from a registration or settings PATCH body)
|
|
10
|
+
* @returns A sparse object with only the fields worth persisting
|
|
11
|
+
*/
|
|
12
|
+
export declare function build_location_fields(location: LocationFieldsInput | undefined): Record<string, string>;
|
|
13
|
+
//# sourceMappingURL=location_fields_helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location_fields_helper.d.ts","sourceRoot":"","sources":["../../../src/lib/services/location_fields_helper.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAGF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAWvG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// file_description: pure helper shared by registration_service and user_update_service —
|
|
2
|
+
// picks and trims the three indexed location columns (country / state_province / suburb)
|
|
3
|
+
// from caller-supplied data, dropping anything undefined or blank after trimming.
|
|
4
|
+
// section: helpers
|
|
5
|
+
/**
|
|
6
|
+
* Returns only the location fields that were actually provided and non-blank,
|
|
7
|
+
* trimmed — ready to spread straight into an `insert`/`updateById` data object.
|
|
8
|
+
* @param location - Raw location input (e.g. from a registration or settings PATCH body)
|
|
9
|
+
* @returns A sparse object with only the fields worth persisting
|
|
10
|
+
*/
|
|
11
|
+
export function build_location_fields(location) {
|
|
12
|
+
if (!location)
|
|
13
|
+
return {};
|
|
14
|
+
const result = {};
|
|
15
|
+
for (const key of ["country", "state_province", "suburb"]) {
|
|
16
|
+
const value = location[key];
|
|
17
|
+
if (value === undefined)
|
|
18
|
+
continue;
|
|
19
|
+
const trimmed = value.trim();
|
|
20
|
+
if (trimmed)
|
|
21
|
+
result[key] = trimmed;
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { HazoConnectAdapter } from "hazo_connect";
|
|
2
|
+
import { type LocationFieldsInput } from "./location_fields_helper.js";
|
|
2
3
|
export type RegistrationData = {
|
|
3
4
|
email: string;
|
|
4
5
|
password: string;
|
|
@@ -9,6 +10,14 @@ export type RegistrationData = {
|
|
|
9
10
|
}>;
|
|
10
11
|
ip?: string | null;
|
|
11
12
|
user_agent?: string | null;
|
|
13
|
+
/** Indexed location columns — only persisted for fields enabled via
|
|
14
|
+
* `[hazo_auth__custom_fields]` (the route handler is responsible for
|
|
15
|
+
* stripping anything not enabled before calling here; see register.ts). */
|
|
16
|
+
location?: LocationFieldsInput;
|
|
17
|
+
/** Arbitrary custom fields (ticket 09's `custom_field_*` config), merged into the
|
|
18
|
+
* existing `app_user_data` JSONB column via `update_app_user_data()` — no new
|
|
19
|
+
* column or config parser for these; see register_config.server.ts. */
|
|
20
|
+
custom_fields?: Record<string, unknown>;
|
|
12
21
|
};
|
|
13
22
|
export type RegistrationResult = {
|
|
14
23
|
success: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registration_service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/registration_service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"registration_service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/registration_service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAkBvD,OAAO,EAAyB,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAI3F,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClD,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B;;gFAE4E;IAC5E,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B;;4EAEwE;IACxE,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAGF;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,kBAAkB,CAAC,CAqL7B"}
|
|
@@ -12,6 +12,8 @@ import { get_line_number } from "../utils/api_route_helpers.js";
|
|
|
12
12
|
import { is_user_types_enabled, get_default_user_type, } from "../user_types_config.server.js";
|
|
13
13
|
import { write_legal_acceptance } from "../legal/legal_docs_service.js";
|
|
14
14
|
import { fire_auth_hook } from "../auth_hooks.js";
|
|
15
|
+
import { build_location_fields } from "./location_fields_helper.js";
|
|
16
|
+
import { update_app_user_data } from "./app_user_data_service.js";
|
|
15
17
|
// section: helpers
|
|
16
18
|
/**
|
|
17
19
|
* Registers a new user in the database using hazo_connect
|
|
@@ -63,6 +65,9 @@ export async function register_user(adapter, data) {
|
|
|
63
65
|
insert_data.url_on_logon = url_on_logon;
|
|
64
66
|
}
|
|
65
67
|
}
|
|
68
|
+
// Indexed location columns (country / state_province / suburb) — additive,
|
|
69
|
+
// no-op when `data.location` is omitted (every pre-ticket-09 caller).
|
|
70
|
+
Object.assign(insert_data, build_location_fields(data.location));
|
|
66
71
|
// Set default profile picture if enabled
|
|
67
72
|
const profile_picture_config = get_profile_picture_config();
|
|
68
73
|
if (profile_picture_config.user_photo_default) {
|
|
@@ -88,6 +93,12 @@ export async function register_user(adapter, data) {
|
|
|
88
93
|
error: "Failed to create user account",
|
|
89
94
|
};
|
|
90
95
|
}
|
|
96
|
+
// Arbitrary custom fields (JSON Schema-driven, [hazo_auth__app_user_data]) —
|
|
97
|
+
// merge mode is a no-op concern here (brand new user, nothing to merge over),
|
|
98
|
+
// kept consistent with update_app_user_data()'s only mode of operation elsewhere.
|
|
99
|
+
if (data.custom_fields && Object.keys(data.custom_fields).length > 0) {
|
|
100
|
+
await update_app_user_data(adapter, user_id, data.custom_fields, { merge: true });
|
|
101
|
+
}
|
|
91
102
|
void fire_auth_hook("on_user_created", {
|
|
92
103
|
user_id,
|
|
93
104
|
email,
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type { HazoConnectAdapter } from "hazo_connect";
|
|
2
2
|
import { type ProfilePictureSourceUI } from "./profile_picture_source_mapper.js";
|
|
3
|
+
import { type LocationFieldsInput } from "./location_fields_helper.js";
|
|
3
4
|
export type UserUpdateData = {
|
|
4
5
|
name?: string;
|
|
5
6
|
email?: string;
|
|
6
7
|
profile_picture_url?: string;
|
|
7
8
|
profile_source?: ProfilePictureSourceUI;
|
|
8
9
|
preferred_locale?: string | null;
|
|
10
|
+
/** Indexed location columns (My Settings' "Location" card). Only non-blank,
|
|
11
|
+
* provided fields are persisted — omitted or blank fields are left unchanged
|
|
12
|
+
* (see build_location_fields; it has no "clear" semantics). */
|
|
13
|
+
location?: LocationFieldsInput;
|
|
9
14
|
};
|
|
10
15
|
export type UserUpdateResult = {
|
|
11
16
|
success: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user_update_service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/user_update_service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAuB,KAAK,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"user_update_service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/user_update_service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAuB,KAAK,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAInG,OAAO,EAAyB,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG3F,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,cAAc,CAAC,EAAE,sBAAsB,CAAC;IAIxC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC;;oEAEgE;IAChE,QAAQ,CAAC,EAAE,mBAAmB,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAGF;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,gBAAgB,CAAC,CA8G3B"}
|
|
@@ -3,6 +3,7 @@ import { map_ui_source_to_db } from "./profile_picture_source_mapper.js";
|
|
|
3
3
|
import { create_app_logger } from "../app_logger.js";
|
|
4
4
|
import { sanitize_error_for_user } from "../utils/error_sanitizer.js";
|
|
5
5
|
import { get_line_number } from "../utils/api_route_helpers.js";
|
|
6
|
+
import { build_location_fields } from "./location_fields_helper.js";
|
|
6
7
|
// section: helpers
|
|
7
8
|
/**
|
|
8
9
|
* Updates user profile information (name, email)
|
|
@@ -75,6 +76,7 @@ export async function update_user_profile(adapter, user_id, data) {
|
|
|
75
76
|
// null explicitly clears the preference (falls back to detection elsewhere)
|
|
76
77
|
update_data.preferred_locale = data.preferred_locale;
|
|
77
78
|
}
|
|
79
|
+
Object.assign(update_data, build_location_fields(data.location));
|
|
78
80
|
// If email changed, set email_verified to false
|
|
79
81
|
if (email_changed) {
|
|
80
82
|
update_data.email_verified = false;
|