@jsb188/app 1.1.9 → 1.1.11
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 +54 -45
- package/src/constants/agent.ts +58 -25
- package/src/constants/app.ts +18 -14
- package/src/constants/billing.ts +92 -92
- package/src/constants/emoji.ts +9144 -8936
- package/src/constants/other.ts +1 -5
- package/src/constants/user.ts +16 -25
- package/src/constants/wsActions.ts +35 -0
- package/src/i18n/account.ts +129 -107
- package/src/i18n/agent.ts +63 -43
- package/src/i18n/agentDoc.ts +110 -0
- package/src/i18n/app.ts +101 -91
- package/src/i18n/auth.ts +119 -102
- package/src/i18n/billing.ts +73 -78
- package/src/i18n/campaign.ts +217 -0
- package/src/i18n/country.ts +248 -248
- package/src/i18n/datetime.ts +26 -26
- package/src/i18n/error.ts +428 -182
- package/src/i18n/field_docs.ts +28 -0
- package/src/i18n/form.ts +464 -344
- package/src/i18n/index.ts +25 -18
- package/src/i18n/log.ts +53 -213
- package/src/i18n/memory.ts +39 -0
- package/src/i18n/message.ts +3 -4
- package/src/i18n/note.ts +17 -0
- package/src/i18n/org.ts +115 -109
- package/src/i18n/sheet.ts +376 -4
- package/src/i18n/workflow.ts +70 -23
- package/src/main.ts +66 -62
- package/src/platform.ts +25 -24
- package/src/types/ai.d.ts +33 -23
- package/src/types/app.d.ts +95 -37
- package/src/types/auth.d.ts +66 -40
- package/src/types/console.d.ts +3 -0
- package/src/types/form.d.ts +65 -61
- package/src/types/other.d.ts +6 -6
- package/src/types.d.ts +12 -14
- package/src/utils/account.ts +64 -58
- package/src/utils/api.ts +280 -77
- package/src/utils/authSession.ts +24 -0
- package/src/utils/billing.ts +110 -103
- package/src/utils/color.ts +202 -0
- package/src/utils/cron.ts +49 -18
- package/src/utils/datetime.ts +255 -103
- package/src/utils/emoji.ts +107 -84
- package/src/utils/expression.ts +867 -0
- package/src/utils/interval.ts +80 -0
- package/src/utils/logic.ts +209 -36
- package/src/utils/managedSession.ts +34 -0
- package/src/utils/managedSessionBff.test.ts +60 -0
- package/src/utils/managedSessionBff.ts +117 -0
- package/src/utils/number.ts +60 -32
- package/src/utils/object.ts +198 -30
- package/src/utils/promise.ts +27 -0
- package/src/utils/queryReset.ts +179 -0
- package/src/utils/recurringTask.ts +60 -0
- package/src/utils/schema.ts +293 -0
- package/src/utils/string.test.ts +220 -208
- package/src/utils/string.ts +471 -438
- package/src/utils/timeZone.ts +309 -851
- package/src/utils/url_client.ts +73 -69
- package/tsconfig.json +10 -10
- package/src/i18n/product.ts +0 -76
package/src/types/other.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { DAY_OF_WEEK, SCHEDULE_FREQUENCY } from '../constants/other.ts';
|
|
|
4
4
|
* Enums
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
export type DayOfWeekEnum = typeof DAY_OF_WEEK[number];
|
|
8
|
-
export type ScheduleFrequencyEnum = typeof SCHEDULE_FREQUENCY[number];
|
|
7
|
+
export type DayOfWeekEnum = (typeof DAY_OF_WEEK)[number];
|
|
8
|
+
export type ScheduleFrequencyEnum = (typeof SCHEDULE_FREQUENCY)[number];
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Address
|
|
@@ -39,13 +39,13 @@ export interface ScheduleObj {
|
|
|
39
39
|
*/
|
|
40
40
|
|
|
41
41
|
export interface LabelAndValue {
|
|
42
|
-
|
|
42
|
+
iconName?: String;
|
|
43
43
|
label: string;
|
|
44
44
|
value: string;
|
|
45
45
|
quantity?: number;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
unit?: string;
|
|
47
|
+
tax?: number;
|
|
48
|
+
note?: string;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
package/src/types.d.ts
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
|
|
2
1
|
declare global {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
interface Console {
|
|
3
|
+
dev: (...args: any[]) => void;
|
|
4
|
+
}
|
|
6
5
|
}
|
|
7
6
|
|
|
8
7
|
/** Declaration file generated by dts-gen */
|
|
9
8
|
|
|
10
9
|
declare class NodePolyglot {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
clear(): void;
|
|
10
|
+
constructor(options?: any);
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
clear(): void;
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
extend(morePhrases: any, prefix?: any): void;
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
has(key: any): any;
|
|
20
17
|
|
|
21
|
-
|
|
18
|
+
locale(newLocale: any): any;
|
|
22
19
|
|
|
23
|
-
|
|
20
|
+
replace(newPhrases: any): void;
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
t(key: any, options?: any): any;
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
unset(morePhrases: any, prefix: any): void;
|
|
28
25
|
|
|
26
|
+
static transformPhrase(phrase: any, substitutions: any, locale: any): any;
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
export = NodePolyglot;
|
package/src/utils/account.ts
CHANGED
|
@@ -10,82 +10,88 @@ type PlusGroupEnum = 'NORMAL' | 'PERKS' | 'PLUS' | 'PRO';
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
export function getLightMode(mode: string, mobileApp: boolean): LightModeValue {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (!mode) {
|
|
14
|
+
return 'LIGHT';
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const index = mobileApp ? 1 : 0;
|
|
18
|
+
const value = Number(mode.charAt(index));
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
return (['LIGHT', 'SYSTEM', 'DARK'][value] || 'LIGHT') as LightModeValue;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Update light mode value
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
export function updateLightMode(
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
export function updateLightMode(
|
|
28
|
+
mode_: string | undefined,
|
|
29
|
+
newValue: LightModeValue,
|
|
30
|
+
mobileApp: boolean,
|
|
31
|
+
): string {
|
|
32
|
+
const mode = mode_ || '00';
|
|
33
|
+
const index = mobileApp ? 1 : 0;
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
let value = ['LIGHT', 'SYSTEM', 'DARK'].indexOf(newValue);
|
|
36
|
+
if (value === -1) {
|
|
37
|
+
value = 0;
|
|
38
|
+
}
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
return mode.substring(0, index) + value + mode.substring(index + 1);
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
44
|
* Get user's subscription & status
|
|
41
45
|
*/
|
|
42
46
|
|
|
43
|
-
export const getUserSubscription = (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
export const getUserSubscription = (
|
|
48
|
+
plus: any,
|
|
49
|
+
): {
|
|
50
|
+
name: string | null;
|
|
51
|
+
group: PlusGroupEnum;
|
|
52
|
+
cancelled: boolean;
|
|
53
|
+
expired: boolean;
|
|
54
|
+
expireAt: Date | null;
|
|
49
55
|
} => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
if (!plus) {
|
|
57
|
+
return {
|
|
58
|
+
name: null,
|
|
59
|
+
group: 'NORMAL',
|
|
60
|
+
cancelled: false,
|
|
61
|
+
expired: false,
|
|
62
|
+
expireAt: null,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
59
65
|
|
|
60
|
-
|
|
66
|
+
const expired = new Date(plus.expireAt).getTime() < Date.now();
|
|
61
67
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
68
|
+
let group: PlusGroupEnum = 'NORMAL';
|
|
69
|
+
if (!expired) {
|
|
70
|
+
switch (plus.type) {
|
|
71
|
+
case 'kajiwoto_plus':
|
|
72
|
+
case 'kajiwoto_plus_yearly':
|
|
73
|
+
case 'big_planet_plus':
|
|
74
|
+
case 'big_planet_plus_yearly':
|
|
75
|
+
group = 'PLUS';
|
|
76
|
+
break;
|
|
77
|
+
case 'kajiwoto_pro':
|
|
78
|
+
case 'kajiwoto_pro_yearly':
|
|
79
|
+
case 'big_planet_pro':
|
|
80
|
+
case 'big_planet_pro_yearly':
|
|
81
|
+
group = 'PRO';
|
|
82
|
+
break;
|
|
83
|
+
case 'perks':
|
|
84
|
+
group = 'PERKS';
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
}
|
|
88
|
+
}
|
|
83
89
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
return {
|
|
91
|
+
name: plus.type,
|
|
92
|
+
group,
|
|
93
|
+
cancelled: !!plus.cancelled,
|
|
94
|
+
expired,
|
|
95
|
+
expireAt: plus.expireAt,
|
|
96
|
+
};
|
|
91
97
|
};
|
package/src/utils/api.ts
CHANGED
|
@@ -4,15 +4,213 @@ import type { ServerErrorObj } from '../types/app.d.ts';
|
|
|
4
4
|
|
|
5
5
|
let AUTH_TOKEN: string | null = null;
|
|
6
6
|
|
|
7
|
+
export type ManagedAccessTokenBinding = {
|
|
8
|
+
accountId: string;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type RealtimeCapabilityResource = 'DATA_TABLE' | 'SHEET';
|
|
13
|
+
|
|
14
|
+
export type RealtimeCapabilityBinding = ManagedAccessTokenBinding & {
|
|
15
|
+
resource: RealtimeCapabilityResource;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Decode an unverified JWT payload for client-side scheduling and request
|
|
20
|
+
* coordination only.
|
|
21
|
+
*/
|
|
22
|
+
function getUnverifiedJWTPayload(token: string): Record<string, any> | null {
|
|
23
|
+
try {
|
|
24
|
+
const rawToken = token.startsWith('Bearer ')
|
|
25
|
+
? token.slice('Bearer '.length)
|
|
26
|
+
: token;
|
|
27
|
+
const encodedPayload = rawToken.split('.')[1];
|
|
28
|
+
if (!encodedPayload) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const normalizedPayload = encodedPayload
|
|
33
|
+
.replace(/-/g, '+')
|
|
34
|
+
.replace(/_/g, '/')
|
|
35
|
+
.padEnd(Math.ceil(encodedPayload.length / 4) * 4, '=');
|
|
36
|
+
const payload = JSON.parse(atob(normalizedPayload));
|
|
37
|
+
return payload && typeof payload === 'object' ? payload : null;
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Read one JWT expiration as an unverified millisecond scheduling hint. This
|
|
45
|
+
* must never be used as authorization; the receiving server still verifies
|
|
46
|
+
* the signature, resource, principal, and exact expiry.
|
|
47
|
+
*/
|
|
48
|
+
export function getUnverifiedJWTExpirationMs(token: string): number | null {
|
|
49
|
+
const expirationSeconds = getUnverifiedJWTPayload(token)?.exp;
|
|
50
|
+
if (
|
|
51
|
+
typeof expirationSeconds !== 'number' ||
|
|
52
|
+
!Number.isSafeInteger(expirationSeconds) ||
|
|
53
|
+
expirationSeconds <= 0
|
|
54
|
+
) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const expirationMs = expirationSeconds * 1_000;
|
|
59
|
+
return Number.isSafeInteger(expirationMs) ? expirationMs : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Read one JWT issued-at as an unverified millisecond scheduling hint. Paired
|
|
64
|
+
* with the expiry claim it yields the token's server-clock lifetime, which
|
|
65
|
+
* stays correct on clients whose local clock is skewed.
|
|
66
|
+
*/
|
|
67
|
+
export function getUnverifiedJWTIssuedAtMs(token: string): number | null {
|
|
68
|
+
const issuedAtSeconds = getUnverifiedJWTPayload(token)?.iat;
|
|
69
|
+
if (
|
|
70
|
+
typeof issuedAtSeconds !== 'number' ||
|
|
71
|
+
!Number.isSafeInteger(issuedAtSeconds) ||
|
|
72
|
+
issuedAtSeconds <= 0
|
|
73
|
+
) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const issuedAtMs = issuedAtSeconds * 1_000;
|
|
78
|
+
return Number.isSafeInteger(issuedAtMs) ? issuedAtMs : null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Normalize one positive integer JWT hint to a bounded decimal string.
|
|
83
|
+
*/
|
|
84
|
+
function normalizeAccessTokenIntegerHint(value: unknown): string | null {
|
|
85
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (typeof value === 'number' && !Number.isSafeInteger(value)) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const normalizedValue = String(value).trim();
|
|
93
|
+
return normalizedValue.length <= 19 && /^[1-9][0-9]*$/.test(normalizedValue)
|
|
94
|
+
? normalizedValue
|
|
95
|
+
: null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Read an account hint from an access JWT for client-side coordination only.
|
|
100
|
+
*/
|
|
101
|
+
export function getAccessTokenAccountIdHint(token: string): string | null {
|
|
102
|
+
const payload = getUnverifiedJWTPayload(token);
|
|
103
|
+
return normalizeAccessTokenIntegerHint(payload?.accountId);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Read the account/session hint from a managed access JWT without treating it
|
|
108
|
+
* as authentication; the server still verifies every credential.
|
|
109
|
+
*/
|
|
110
|
+
export function getManagedAccessTokenBinding(
|
|
111
|
+
token: string,
|
|
112
|
+
): ManagedAccessTokenBinding | null {
|
|
113
|
+
const payload = getUnverifiedJWTPayload(token);
|
|
114
|
+
if (
|
|
115
|
+
payload?.__name !== 'type:AccountAuth' ||
|
|
116
|
+
Number(payload?.sessionVersion || 0) !== 1
|
|
117
|
+
) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const accountId = normalizeAccessTokenIntegerHint(payload?.accountId);
|
|
121
|
+
const canonicalSessionId = normalizeAccessTokenIntegerHint(
|
|
122
|
+
payload?.sessionId,
|
|
123
|
+
);
|
|
124
|
+
const aliasSessionId = normalizeAccessTokenIntegerHint(payload?.sid);
|
|
125
|
+
if (
|
|
126
|
+
canonicalSessionId &&
|
|
127
|
+
aliasSessionId &&
|
|
128
|
+
canonicalSessionId !== aliasSessionId
|
|
129
|
+
) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const sessionId = canonicalSessionId || aliasSessionId;
|
|
133
|
+
if (!accountId || !sessionId) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
accountId,
|
|
139
|
+
sessionId,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Check whether two access JWTs identify the same managed account session.
|
|
145
|
+
*/
|
|
146
|
+
export function managedAccessTokensShareBinding(
|
|
147
|
+
left: string,
|
|
148
|
+
right: string,
|
|
149
|
+
): boolean {
|
|
150
|
+
const leftBinding = getManagedAccessTokenBinding(left);
|
|
151
|
+
const rightBinding = getManagedAccessTokenBinding(right);
|
|
152
|
+
return Boolean(
|
|
153
|
+
leftBinding &&
|
|
154
|
+
rightBinding &&
|
|
155
|
+
leftBinding.accountId === rightBinding.accountId &&
|
|
156
|
+
leftBinding.sessionId === rightBinding.sessionId,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Read the stable managed-session owner from a signed realtime capability as
|
|
162
|
+
* an unverified client-side lifecycle hint. The websocket server remains the
|
|
163
|
+
* only authority for the capability itself.
|
|
164
|
+
*/
|
|
165
|
+
export function getRealtimeCapabilityBinding(
|
|
166
|
+
token: string,
|
|
167
|
+
expectedResource: RealtimeCapabilityResource,
|
|
168
|
+
): RealtimeCapabilityBinding | null {
|
|
169
|
+
const payload = getUnverifiedJWTPayload(token);
|
|
170
|
+
if (
|
|
171
|
+
payload?.__name !== 'type:RealtimeCapability' ||
|
|
172
|
+
Number(payload?.realtimeCapabilityVersion || 0) !== 2 ||
|
|
173
|
+
payload?.resource !== expectedResource
|
|
174
|
+
) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const accountId = normalizeAccessTokenIntegerHint(payload.accountId);
|
|
179
|
+
const sessionId = normalizeAccessTokenIntegerHint(payload.sessionId);
|
|
180
|
+
if (!accountId || !sessionId) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
accountId,
|
|
186
|
+
resource: expectedResource,
|
|
187
|
+
sessionId,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Return one exact account/session ownership key for client-retained realtime
|
|
193
|
+
* state. Token renewal within the same managed session intentionally keeps it.
|
|
194
|
+
*/
|
|
195
|
+
export function getRealtimeCapabilityOwnerKey(
|
|
196
|
+
token: string | null | undefined,
|
|
197
|
+
expectedResource: RealtimeCapabilityResource,
|
|
198
|
+
) {
|
|
199
|
+
const binding = token
|
|
200
|
+
? getRealtimeCapabilityBinding(token, expectedResource)
|
|
201
|
+
: null;
|
|
202
|
+
return binding ? JSON.stringify([binding.accountId, binding.sessionId]) : '';
|
|
203
|
+
}
|
|
204
|
+
|
|
7
205
|
/**
|
|
8
206
|
* Global; save auth token to memory
|
|
9
207
|
*/
|
|
10
208
|
|
|
11
209
|
export function setAuthToken(token: string | null) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
210
|
+
if (getENVVariable('IS_BROWSER')) {
|
|
211
|
+
// Only set auth token if it's browser; we don't want to share it across users
|
|
212
|
+
AUTH_TOKEN = token || null;
|
|
213
|
+
}
|
|
16
214
|
}
|
|
17
215
|
|
|
18
216
|
/**
|
|
@@ -20,7 +218,7 @@ export function setAuthToken(token: string | null) {
|
|
|
20
218
|
*/
|
|
21
219
|
|
|
22
220
|
export function getAuthToken(): string | null {
|
|
23
|
-
|
|
221
|
+
return getENVVariable('IS_BROWSER') ? AUTH_TOKEN : null;
|
|
24
222
|
}
|
|
25
223
|
|
|
26
224
|
/**
|
|
@@ -28,7 +226,7 @@ export function getAuthToken(): string | null {
|
|
|
28
226
|
*/
|
|
29
227
|
|
|
30
228
|
function i18nErrCodeExists(errorCode: string): boolean {
|
|
31
|
-
|
|
229
|
+
return i18n.has(`error.${errorCode}`) || i18n.has(`error.${errorCode}_other`);
|
|
32
230
|
}
|
|
33
231
|
|
|
34
232
|
/**
|
|
@@ -36,74 +234,79 @@ function i18nErrCodeExists(errorCode: string): boolean {
|
|
|
36
234
|
*/
|
|
37
235
|
|
|
38
236
|
export function normalizeServerError(error?: any): ServerErrorObj {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
237
|
+
let statusCode = 500;
|
|
238
|
+
let errorCode: string | undefined;
|
|
239
|
+
let errorValue: string | undefined;
|
|
240
|
+
let iconName: string | undefined;
|
|
241
|
+
let message = '';
|
|
242
|
+
|
|
243
|
+
if (!error || error instanceof Error) {
|
|
244
|
+
if (error?.message === 'Failed to fetch') {
|
|
245
|
+
errorCode = 'network_error';
|
|
246
|
+
iconName = 'wifi-off';
|
|
247
|
+
message = i18n.t('error.network_error');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (!errorCode && error?.errors?.length) {
|
|
252
|
+
const loggedError = error.errors.find(
|
|
253
|
+
(gErr: ServerErrorObj) =>
|
|
254
|
+
gErr.errorCode && i18nErrCodeExists(gErr.errorCode),
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
if (loggedError) {
|
|
258
|
+
statusCode = loggedError.statusCode;
|
|
259
|
+
errorCode = loggedError.errorCode;
|
|
260
|
+
errorValue = loggedError.variableWord;
|
|
261
|
+
} else {
|
|
262
|
+
statusCode = error.errors[0].statusCode;
|
|
263
|
+
errorCode = error.errors[0].errorCode;
|
|
264
|
+
errorValue = error.errors[0].variableWord;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Keep the returned error contract total even for malformed server payloads.
|
|
269
|
+
errorCode ||= 'unknown_error';
|
|
270
|
+
if (!message) {
|
|
271
|
+
if (i18nErrCodeExists(errorCode)) {
|
|
272
|
+
message = i18n.t(`error.${errorCode}`, {
|
|
273
|
+
value: errorValue,
|
|
274
|
+
smart_count: Number(errorValue),
|
|
275
|
+
});
|
|
276
|
+
} else {
|
|
277
|
+
message = i18n.t('error.unknown_error_msg');
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (
|
|
282
|
+
getENVVariable('NODE_ENV') === 'development' &&
|
|
283
|
+
message === i18n.t('error.unknown_error_msg')
|
|
284
|
+
) {
|
|
285
|
+
// Log for development so I can see what went wrong
|
|
286
|
+
console.warn(error);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
let title: string;
|
|
290
|
+
if (i18n.has(`error.${errorCode}_title`)) {
|
|
291
|
+
title = i18n.t(`error.${errorCode}_title`);
|
|
292
|
+
} else if (i18n.has(`error.${statusCode}_title`)) {
|
|
293
|
+
title = i18n.t(`error.${statusCode}_title`);
|
|
294
|
+
} else {
|
|
295
|
+
title = i18n.t('error.error');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (i18n.has(`error.${errorCode}_icon`)) {
|
|
299
|
+
iconName = i18n.t(`error.${errorCode}_icon`);
|
|
300
|
+
} else if (statusCode == 404) {
|
|
301
|
+
iconName = 'folder-question';
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return {
|
|
305
|
+
statusCode,
|
|
306
|
+
errorCode,
|
|
307
|
+
errorValue,
|
|
308
|
+
iconName,
|
|
309
|
+
title,
|
|
310
|
+
message,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const FILE_CONSTANTS = {
|
|
2
|
+
browserLockName: 'marketday:auth-session',
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Serialize participating authentication-cookie writers across same-origin
|
|
7
|
+
* tabs while retaining a compatibility fallback without the Web Locks API.
|
|
8
|
+
*/
|
|
9
|
+
export async function runWithAuthSessionBrowserLock<T>(
|
|
10
|
+
callback: () => Promise<T>,
|
|
11
|
+
): Promise<T> {
|
|
12
|
+
const lockManager = globalThis.navigator?.locks;
|
|
13
|
+
if (!lockManager) {
|
|
14
|
+
return callback();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return lockManager.request(
|
|
18
|
+
FILE_CONSTANTS.browserLockName,
|
|
19
|
+
{ mode: 'exclusive' },
|
|
20
|
+
callback,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { getManagedSessionRefreshAttemptId } from './managedSession.ts';
|