@jsb188/auth-web 1.1.11 → 1.1.12
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/package.json +9 -7
- package/src/hooks/use-auth-popup.ts +167 -0
- package/src/hooks/use-google-one-tap.ts +138 -0
- package/src/hooks/use-oauth.tsx +25 -51
- package/src/main.ts +11 -0
- package/src/modules/AssignRequiredAuth.tsx +93 -59
- package/src/modules/AuthFormUI.tsx +2 -2
- package/src/modules/AuthForms-SSO.tsx +43 -58
- package/src/modules/AuthForms.tsx +420 -287
- package/src/modules/AuthGate.tsx +8 -23
- package/src/modules/ConfirmPublicFormEmailCode.tsx +144 -0
- package/src/modules/InlineAuthForm.tsx +373 -75
- package/src/modules/ManagedSessions.tsx +22 -42
- package/src/modules/OtherAuthButtons.tsx +9 -7
- package/src/modules/_helpers.ts +94 -37
- package/src/modules/schemas.ts +114 -244
- package/src/schemas/account.ts +86 -149
- package/src/schemas/address.ts +108 -157
- package/src/utils/authPopup.ts +95 -0
- package/src/utils/googleIdentity.ts +100 -0
package/src/schemas/account.ts
CHANGED
|
@@ -1,177 +1,114 @@
|
|
|
1
1
|
import { SUPPORTED_LANGUAGES } from '@jsb188/app/constants/app.ts';
|
|
2
2
|
import i18n from '@jsb188/app/i18n/index.ts';
|
|
3
|
-
import type { AccountData } from '@jsb188/app/types/auth.d.ts';
|
|
3
|
+
import type { AccountData, AccountSettings } from '@jsb188/app/types/auth.d.ts';
|
|
4
4
|
import { formatPhoneNumber } from '@jsb188/app/utils/string.ts';
|
|
5
|
+
import { defineForm } from '@jsb188/form/libs/defineForm';
|
|
5
6
|
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
7
|
+
import { z } from 'zod';
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
* Length values for validation
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const MIN_LEN_VALUES = {
|
|
12
|
-
password: 8,
|
|
13
|
-
firstName: 32,
|
|
14
|
-
lastName: 32,
|
|
15
|
-
description: 750,
|
|
16
|
-
email: 80,
|
|
17
|
-
phone: 15,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Schema; Edit account
|
|
22
|
-
*/
|
|
23
|
-
|
|
9
|
+
/* Define editable account values and the existing verification action controls. */
|
|
24
10
|
export function makeEditAccountSchema(
|
|
25
|
-
formId: string,
|
|
26
|
-
focusedName: string,
|
|
27
|
-
formValues: any,
|
|
28
11
|
account: AccountData | null,
|
|
12
|
+
settings: AccountSettings | null,
|
|
29
13
|
openModalPopUp: OpenModalPopUpFn,
|
|
30
14
|
) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
name: 'profile.firstName',
|
|
54
|
-
maxLength: MIN_LEN_VALUES.firstName,
|
|
55
|
-
label: i18n.t('account.fName'),
|
|
56
|
-
placeholder: account?.profile?.firstName,
|
|
57
|
-
autoComplete: 'off',
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
__type: 'input',
|
|
62
|
-
item: {
|
|
63
|
-
name: 'profile.lastName',
|
|
64
|
-
maxLength: MIN_LEN_VALUES.lastName,
|
|
65
|
-
label: i18n.t('account.lName'),
|
|
66
|
-
placeholder: account?.profile?.lastName,
|
|
67
|
-
autoComplete: 'off',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
},
|
|
15
|
+
return defineForm({
|
|
16
|
+
schema: z.object({
|
|
17
|
+
profile: z.object({ firstName: z.string(), lastName: z.string() }),
|
|
18
|
+
settings: z.object({ language: z.string() }),
|
|
19
|
+
change_phoneNumber: z.string(),
|
|
20
|
+
change_emailAddress: z.string(),
|
|
21
|
+
change_password: z.string(),
|
|
22
|
+
}),
|
|
23
|
+
defaults: {
|
|
24
|
+
profile: { firstName: account?.profile?.firstName || '', lastName: account?.profile?.lastName || '' },
|
|
25
|
+
settings: { language: settings?.language || 'en' },
|
|
26
|
+
change_phoneNumber: '',
|
|
27
|
+
change_emailAddress: '',
|
|
28
|
+
change_password: '',
|
|
29
|
+
},
|
|
30
|
+
fields: {
|
|
31
|
+
'profile.firstName': {
|
|
32
|
+
kind: 'input',
|
|
33
|
+
maxLength: 32,
|
|
34
|
+
label: i18n.t('account.fName'),
|
|
35
|
+
placeholder: account?.profile?.firstName,
|
|
36
|
+
autoComplete: 'off',
|
|
72
37
|
},
|
|
73
|
-
{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
label: i18n.t('
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
38
|
+
'profile.lastName': {
|
|
39
|
+
kind: 'input',
|
|
40
|
+
maxLength: 32,
|
|
41
|
+
label: i18n.t('account.lName'),
|
|
42
|
+
placeholder: account?.profile?.lastName,
|
|
43
|
+
autoComplete: 'off',
|
|
44
|
+
},
|
|
45
|
+
'settings.language': {
|
|
46
|
+
kind: 'click',
|
|
47
|
+
label: i18n.t('account.ai_language'),
|
|
48
|
+
placeholder: i18n.t('c.activity_ph'),
|
|
49
|
+
getter: (value: string) => i18n.t(`c.lang.${value || 'en'}`),
|
|
50
|
+
resolve: ({ values }) => ({
|
|
85
51
|
popOverProps: {
|
|
86
|
-
id:
|
|
87
|
-
|
|
52
|
+
id: 'edit_account_settings.language',
|
|
53
|
+
zClassName: 'z9',
|
|
54
|
+
position: 'bottom_left',
|
|
55
|
+
offsetX: 0,
|
|
56
|
+
offsetY: 7,
|
|
88
57
|
iface: {
|
|
89
58
|
name: 'PO_LIST',
|
|
90
59
|
variables: {
|
|
91
60
|
designClassName: 'w_400',
|
|
92
61
|
className: 'max_h_40vh',
|
|
93
|
-
options: SUPPORTED_LANGUAGES.map((
|
|
62
|
+
options: SUPPORTED_LANGUAGES.map((language) => ({
|
|
94
63
|
__type: 'LIST_ITEM' as const,
|
|
95
|
-
text: i18n.t(`
|
|
96
|
-
// textClassName: 'ft_xs',
|
|
97
|
-
// rightIconClassName: 'ft_xs mb_2',
|
|
64
|
+
text: i18n.t(`c.lang.${language}`),
|
|
98
65
|
name: 'settings.language',
|
|
99
|
-
value:
|
|
100
|
-
selected: (
|
|
66
|
+
value: language,
|
|
67
|
+
selected: (values.settings.language || 'en') === language,
|
|
101
68
|
})),
|
|
102
69
|
},
|
|
103
70
|
},
|
|
104
71
|
},
|
|
105
|
-
},
|
|
72
|
+
}),
|
|
106
73
|
},
|
|
107
|
-
{
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
label: i18n.t('form.phone_number'),
|
|
117
|
-
autoComplete: 'off',
|
|
118
|
-
disabled: true,
|
|
119
|
-
buttonText: i18n.t('form.change'),
|
|
120
|
-
onClickButton: () =>
|
|
121
|
-
openModalPopUp({
|
|
122
|
-
preset: 'CHANGE_PHONE',
|
|
123
|
-
name: 'edit_account_phone',
|
|
124
|
-
}),
|
|
125
|
-
},
|
|
74
|
+
change_phoneNumber: {
|
|
75
|
+
kind: 'action',
|
|
76
|
+
maxLength: 15,
|
|
77
|
+
getter: () => formatPhoneNumber(account?.phone?.number || '') || '',
|
|
78
|
+
label: i18n.t('c.phone_number'),
|
|
79
|
+
autoComplete: 'off',
|
|
80
|
+
disabled: true,
|
|
81
|
+
buttonText: i18n.t('c.change'),
|
|
82
|
+
onClickButton: () => openModalPopUp({ preset: 'CHANGE_PHONE', name: 'edit_account_phone' }),
|
|
126
83
|
},
|
|
127
|
-
{
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
disabled: true,
|
|
137
|
-
buttonText: i18n.t('form.change'),
|
|
138
|
-
onClickButton: () =>
|
|
139
|
-
openModalPopUp({
|
|
140
|
-
preset: 'CHANGE_EMAIL',
|
|
141
|
-
name: 'edit_account_email',
|
|
142
|
-
}),
|
|
143
|
-
},
|
|
84
|
+
change_emailAddress: {
|
|
85
|
+
kind: 'action',
|
|
86
|
+
maxLength: 80,
|
|
87
|
+
getter: () => account?.email?.address || '',
|
|
88
|
+
label: i18n.t('account.email'),
|
|
89
|
+
autoComplete: 'off',
|
|
90
|
+
disabled: true,
|
|
91
|
+
buttonText: i18n.t('c.change'),
|
|
92
|
+
onClickButton: () => openModalPopUp({ preset: 'CHANGE_EMAIL', name: 'edit_account_email' }),
|
|
144
93
|
},
|
|
145
|
-
{
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
buttonText: i18n.t('form.change'),
|
|
156
|
-
onClickButton: () =>
|
|
157
|
-
openModalPopUp({
|
|
158
|
-
preset: 'CHANGE_PASSWORD',
|
|
159
|
-
name: 'edit_account_password',
|
|
160
|
-
}),
|
|
161
|
-
},
|
|
162
|
-
// __type: 'textarea',
|
|
163
|
-
// item: {
|
|
164
|
-
// name: 'description',
|
|
165
|
-
// maxLength: MIN_LEN_VALUES.description,
|
|
166
|
-
// setter: (data: any) => data?.profile?.description,
|
|
167
|
-
// label: i18n.t('account.about'),
|
|
168
|
-
// placeholder: i18n.t('account.about_ph'),
|
|
169
|
-
// autoComplete: 'off',
|
|
170
|
-
// },
|
|
94
|
+
change_password: {
|
|
95
|
+
kind: 'action',
|
|
96
|
+
minLength: 8,
|
|
97
|
+
getter: () => '....',
|
|
98
|
+
label: i18n.t('account.password'),
|
|
99
|
+
autoComplete: 'off',
|
|
100
|
+
type: 'password',
|
|
101
|
+
disabled: true,
|
|
102
|
+
buttonText: i18n.t('c.change'),
|
|
103
|
+
onClickButton: () => openModalPopUp({ preset: 'CHANGE_PASSWORD', name: 'edit_account_password' }),
|
|
171
104
|
},
|
|
105
|
+
},
|
|
106
|
+
layout: [
|
|
107
|
+
{ kind: 'row', fields: ['profile.firstName', 'profile.lastName'] },
|
|
108
|
+
'settings.language',
|
|
109
|
+
'change_phoneNumber',
|
|
110
|
+
'change_emailAddress',
|
|
111
|
+
'change_password',
|
|
172
112
|
],
|
|
173
|
-
|
|
174
|
-
// RULES.password,
|
|
175
|
-
],
|
|
176
|
-
};
|
|
113
|
+
});
|
|
177
114
|
}
|
package/src/schemas/address.ts
CHANGED
|
@@ -1,182 +1,133 @@
|
|
|
1
1
|
import { SUPPORTED_COUNTRIES } from '@jsb188/app/constants/app.ts';
|
|
2
2
|
import i18n from '@jsb188/app/i18n/index.ts';
|
|
3
|
+
import type { AddressObj } from '@jsb188/app/types/other.d.ts';
|
|
4
|
+
import { defineForm } from '@jsb188/form/libs/defineForm';
|
|
5
|
+
import { z } from 'zod';
|
|
3
6
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
for: `address.${fieldName}`,
|
|
20
|
-
rule: (_value: unknown, formValues: any) => {
|
|
21
|
-
const address = formValues?.address || {};
|
|
22
|
-
const hasAddressValueExceptCountry = [
|
|
23
|
-
'line1',
|
|
24
|
-
'line2',
|
|
25
|
-
'city',
|
|
26
|
-
'state',
|
|
27
|
-
'postalCode',
|
|
28
|
-
].some((key) => {
|
|
29
|
-
return String(address?.[key] || '').trim().length > 0;
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
if (!hasAddressValueExceptCountry) {
|
|
33
|
-
return true;
|
|
7
|
+
/* Validate an optional address, requiring its core fields once an address is entered. */
|
|
8
|
+
export function makeAddressValueSchema() {
|
|
9
|
+
return z
|
|
10
|
+
.object({
|
|
11
|
+
line1: z.string(),
|
|
12
|
+
line2: z.string(),
|
|
13
|
+
city: z.string(),
|
|
14
|
+
state: z.string(),
|
|
15
|
+
postalCode: z.string(),
|
|
16
|
+
country: z.string(),
|
|
17
|
+
})
|
|
18
|
+
.superRefine((address, context) => {
|
|
19
|
+
const hasAddress = [address.line1, address.line2, address.city, address.state, address.postalCode].some((value) => value.trim());
|
|
20
|
+
if (!hasAddress) {
|
|
21
|
+
return;
|
|
34
22
|
}
|
|
35
23
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
for (const field of ['line1', 'postalCode', 'city', 'state', 'country'] as const) {
|
|
25
|
+
if (!address[field].trim()) {
|
|
26
|
+
context.addIssue({
|
|
27
|
+
code: z.ZodIssueCode.custom,
|
|
28
|
+
path: [field],
|
|
29
|
+
message: i18n.t('error.msg_value_required', { value: i18n.t(`c.${field}`) }),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
42
34
|
}
|
|
43
35
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
line2: string | null;
|
|
54
|
-
city: string | null;
|
|
55
|
-
state: string | null;
|
|
56
|
-
postalCode: string | null;
|
|
57
|
-
country: string | null;
|
|
58
|
-
}> | null,
|
|
59
|
-
popOverDesignClassName?: string,
|
|
60
|
-
) {
|
|
61
|
-
const currentAddress = addressFormValues || {};
|
|
62
|
-
const selectedCountryCode = currentAddress?.country || '';
|
|
63
|
-
const priorityCountryOptions = ['US', 'MX', 'CA'].map((countryCode) => ({
|
|
64
|
-
__type: 'LIST_ITEM' as const,
|
|
65
|
-
text: i18n.t(`country.from_code.${countryCode}`),
|
|
66
|
-
name: 'address.country',
|
|
67
|
-
value: countryCode,
|
|
68
|
-
selected: selectedCountryCode === countryCode,
|
|
69
|
-
}));
|
|
70
|
-
const supportedCountryOptions = SUPPORTED_COUNTRIES.map((countryCode) => ({
|
|
71
|
-
__type: 'LIST_ITEM' as const,
|
|
72
|
-
text: i18n.t(`country.from_code.${countryCode}`),
|
|
73
|
-
name: 'address.country',
|
|
74
|
-
value: countryCode,
|
|
75
|
-
selected: selectedCountryCode === countryCode,
|
|
76
|
-
}));
|
|
77
|
-
const countryOptions = [
|
|
78
|
-
...priorityCountryOptions,
|
|
79
|
-
{
|
|
80
|
-
__type: 'BREAK' as const,
|
|
81
|
-
},
|
|
82
|
-
...supportedCountryOptions,
|
|
83
|
-
];
|
|
84
|
-
const popOverProps = {
|
|
85
|
-
zClassName: 'z9',
|
|
86
|
-
position: 'bottom_left' as const,
|
|
87
|
-
offsetX: 0,
|
|
88
|
-
offsetY: 7,
|
|
36
|
+
/* Map stored, nullable address data to the strings used by editable controls. */
|
|
37
|
+
export function addressFormValues(address?: Partial<AddressObj> | null) {
|
|
38
|
+
return {
|
|
39
|
+
line1: address?.line1 || '',
|
|
40
|
+
line2: address?.line2 || '',
|
|
41
|
+
postalCode: address?.postalCode || '',
|
|
42
|
+
city: address?.city || '',
|
|
43
|
+
state: address?.state || '',
|
|
44
|
+
country: address?.country || '',
|
|
89
45
|
};
|
|
46
|
+
}
|
|
90
47
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
48
|
+
/* Define the reusable address fields with the existing grouped country popover. */
|
|
49
|
+
export function makeAddressSchema(address?: Partial<AddressObj> | null, popOverDesignClassName = 'w_400') {
|
|
50
|
+
return defineForm({
|
|
51
|
+
schema: z.object({ address: makeAddressValueSchema() }),
|
|
52
|
+
defaults: { address: addressFormValues(address) },
|
|
53
|
+
fields: {
|
|
54
|
+
'address.line1': {
|
|
55
|
+
kind: 'input',
|
|
56
|
+
label: i18n.t('c.line1'),
|
|
57
|
+
placeholder: i18n.t('c.line1_ph'),
|
|
100
58
|
},
|
|
101
|
-
{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
label: i18n.t('form.line2_optional'),
|
|
106
|
-
placeholder: i18n.t('form.line2_ph'),
|
|
107
|
-
},
|
|
59
|
+
'address.line2': {
|
|
60
|
+
kind: 'input',
|
|
61
|
+
label: i18n.t('c.line2_optional'),
|
|
62
|
+
placeholder: i18n.t('c.line2_ph'),
|
|
108
63
|
},
|
|
109
|
-
{
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
label: i18n.t('form.postalCode'),
|
|
114
|
-
placeholder:
|
|
115
|
-
currentAddress?.postalCode || i18n.t('form.postalCode_ph'),
|
|
116
|
-
},
|
|
64
|
+
'address.postalCode': {
|
|
65
|
+
kind: 'input',
|
|
66
|
+
label: i18n.t('c.postalCode'),
|
|
67
|
+
placeholder: address?.postalCode || i18n.t('c.postalCode_ph'),
|
|
117
68
|
},
|
|
118
|
-
{
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
__type: 'input' as const,
|
|
133
|
-
item: {
|
|
134
|
-
name: 'address.state',
|
|
135
|
-
maxLength: MIN_LEN_VALUES.state,
|
|
136
|
-
label: i18n.t('form.state'),
|
|
137
|
-
placeholder: currentAddress?.state || '',
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
},
|
|
69
|
+
'address.city': {
|
|
70
|
+
kind: 'input',
|
|
71
|
+
maxLength: 100,
|
|
72
|
+
label: i18n.t('c.city'),
|
|
73
|
+
placeholder: address?.city || i18n.t('c.city_ph'),
|
|
74
|
+
},
|
|
75
|
+
'address.state': {
|
|
76
|
+
kind: 'input',
|
|
77
|
+
maxLength: 32,
|
|
78
|
+
label: i18n.t('c.state'),
|
|
79
|
+
placeholder: address?.state || '',
|
|
142
80
|
},
|
|
143
|
-
{
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
locked: true,
|
|
150
|
-
focused: focusedName === formId + '_address.country',
|
|
151
|
-
name: 'address.country',
|
|
152
|
-
getter: (value: string) =>
|
|
153
|
-
value ? i18n.t(`country.from_code.${value}`) : '',
|
|
154
|
-
placeholder: selectedCountryCode || i18n.t('form.country_ph'),
|
|
81
|
+
'address.country': {
|
|
82
|
+
kind: 'click',
|
|
83
|
+
label: i18n.t('c.country'),
|
|
84
|
+
getter: (value: string) => (value ? i18n.t(`country.from_code.${value}`) : ''),
|
|
85
|
+
resolve: ({ values }) => ({
|
|
86
|
+
placeholder: values.address.country || i18n.t('c.country_ph'),
|
|
155
87
|
popOverProps: {
|
|
156
|
-
|
|
157
|
-
|
|
88
|
+
id: 'address.country',
|
|
89
|
+
zClassName: 'z9',
|
|
90
|
+
position: 'bottom_left',
|
|
91
|
+
offsetX: 0,
|
|
92
|
+
offsetY: 7,
|
|
158
93
|
doNotFixToBottom: true,
|
|
159
94
|
iface: {
|
|
160
95
|
name: 'PO_LIST',
|
|
161
96
|
variables: {
|
|
162
|
-
designClassName: popOverDesignClassName
|
|
97
|
+
designClassName: popOverDesignClassName,
|
|
163
98
|
className: 'max_h_50vh',
|
|
164
|
-
initialState: {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
99
|
+
initialState: { 'address.country': values.address.country },
|
|
100
|
+
options: [
|
|
101
|
+
...['US', 'MX', 'CA'].map((country) => ({
|
|
102
|
+
id: `priority_country_${country}`,
|
|
103
|
+
__type: 'LIST_ITEM' as const,
|
|
104
|
+
text: i18n.t(`country.from_code.${country}`),
|
|
105
|
+
name: 'address.country',
|
|
106
|
+
value: country,
|
|
107
|
+
selected: values.address.country === country,
|
|
108
|
+
})),
|
|
109
|
+
{ __type: 'BREAK' as const },
|
|
110
|
+
...SUPPORTED_COUNTRIES.map((country) => ({
|
|
111
|
+
id: `country_${country}`,
|
|
112
|
+
__type: 'LIST_ITEM' as const,
|
|
113
|
+
text: i18n.t(`country.from_code.${country}`),
|
|
114
|
+
name: 'address.country',
|
|
115
|
+
value: country,
|
|
116
|
+
selected: values.address.country === country,
|
|
117
|
+
})),
|
|
118
|
+
],
|
|
168
119
|
},
|
|
169
120
|
},
|
|
170
121
|
},
|
|
171
|
-
},
|
|
122
|
+
}),
|
|
172
123
|
},
|
|
124
|
+
},
|
|
125
|
+
layout: [
|
|
126
|
+
'address.line1',
|
|
127
|
+
'address.line2',
|
|
128
|
+
'address.postalCode',
|
|
129
|
+
{ kind: 'row', fields: ['address.city', 'address.state'] },
|
|
130
|
+
'address.country',
|
|
173
131
|
],
|
|
174
|
-
|
|
175
|
-
makeAddressRequiredRule('line1', 'form.line1'),
|
|
176
|
-
makeAddressRequiredRule('postalCode', 'form.postalCode'),
|
|
177
|
-
makeAddressRequiredRule('city', 'form.city'),
|
|
178
|
-
makeAddressRequiredRule('state', 'form.state'),
|
|
179
|
-
makeAddressRequiredRule('country', 'form.country'),
|
|
180
|
-
],
|
|
181
|
-
};
|
|
132
|
+
});
|
|
182
133
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export const AUTH_POPUP_MESSAGE_TYPE = 'marketday-auth-complete';
|
|
2
|
+
|
|
3
|
+
export interface AuthPopupCompletionMessage {
|
|
4
|
+
popupId: string;
|
|
5
|
+
primaryOrganizationId?: string;
|
|
6
|
+
type: typeof AUTH_POPUP_MESSAGE_TYPE;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Return the completion route for one valid UUID-bound authentication popup.
|
|
11
|
+
*/
|
|
12
|
+
export function getAuthPopupCompletionPath(popupId?: string | null): string | null {
|
|
13
|
+
if (!popupId || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(popupId)) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return `/auth/popup-complete?${new URLSearchParams({ popupId })}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* Return whether a cross-window message completes the currently open
|
|
22
|
+
* authentication popup.
|
|
23
|
+
*/
|
|
24
|
+
export function isAuthPopupCompletionMessage(value: unknown, popupId: string): value is AuthPopupCompletionMessage {
|
|
25
|
+
if (!value || typeof value !== 'object') {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const message = value as Partial<AuthPopupCompletionMessage>;
|
|
30
|
+
return (
|
|
31
|
+
message.type === AUTH_POPUP_MESSAGE_TYPE &&
|
|
32
|
+
message.popupId === popupId &&
|
|
33
|
+
(message.primaryOrganizationId === undefined || typeof message.primaryOrganizationId === 'string')
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const AUTH_POPUP_RESPONDENT_MESSAGE_TYPE = 'marketday-form-auth-complete';
|
|
38
|
+
|
|
39
|
+
export interface AuthPopupRespondentCompletionMessage {
|
|
40
|
+
type: typeof AUTH_POPUP_RESPONDENT_MESSAGE_TYPE;
|
|
41
|
+
popupId: string;
|
|
42
|
+
formPublicId: string;
|
|
43
|
+
respondentToken: string;
|
|
44
|
+
respondentEmail: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/*
|
|
48
|
+
* Accept a respondent credential only for the popup and public form that requested it.
|
|
49
|
+
*/
|
|
50
|
+
export function isAuthPopupRespondentCompletionMessage(
|
|
51
|
+
value: unknown,
|
|
52
|
+
popupId: string,
|
|
53
|
+
formPublicId: string,
|
|
54
|
+
): value is AuthPopupRespondentCompletionMessage {
|
|
55
|
+
if (!value || typeof value !== 'object') return false;
|
|
56
|
+
const message = value as Partial<AuthPopupRespondentCompletionMessage>;
|
|
57
|
+
return (
|
|
58
|
+
message.type === AUTH_POPUP_RESPONDENT_MESSAGE_TYPE &&
|
|
59
|
+
message.popupId === popupId &&
|
|
60
|
+
message.formPublicId === formPublicId &&
|
|
61
|
+
typeof message.respondentToken === 'string' &&
|
|
62
|
+
!!message.respondentToken &&
|
|
63
|
+
typeof message.respondentEmail === 'string' &&
|
|
64
|
+
!!message.respondentEmail
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
* Hand a verified form identity directly to the same-origin opener without putting credentials in a URL or cookie.
|
|
70
|
+
*/
|
|
71
|
+
export function postAuthPopupRespondentCompletion(
|
|
72
|
+
popupId: string,
|
|
73
|
+
formPublicId: string,
|
|
74
|
+
respondentToken: string,
|
|
75
|
+
respondentEmail: string,
|
|
76
|
+
): boolean {
|
|
77
|
+
if (!getAuthPopupCompletionPath(popupId) || !formPublicId || !respondentToken || !respondentEmail || !globalThis.opener) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
globalThis.opener.postMessage(
|
|
82
|
+
{
|
|
83
|
+
type: AUTH_POPUP_RESPONDENT_MESSAGE_TYPE,
|
|
84
|
+
popupId,
|
|
85
|
+
formPublicId,
|
|
86
|
+
respondentToken,
|
|
87
|
+
respondentEmail,
|
|
88
|
+
} satisfies AuthPopupRespondentCompletionMessage,
|
|
89
|
+
globalThis.location.origin,
|
|
90
|
+
);
|
|
91
|
+
return true;
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|