@oxy.so/core 4.5.0-oxy-one.1 → 4.5.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 +1 -1
- package/dist/cjs/HttpService.js +63 -19
- package/dist/cjs/api/accounts.js +10 -3
- package/dist/cjs/api/agency.js +3 -1
- package/dist/cjs/api/apps.js +15 -4
- package/dist/cjs/api/assets.js +39 -11
- package/dist/cjs/api/auth.js +28 -8
- package/dist/cjs/api/billing.js +24 -7
- package/dist/cjs/api/civic.js +14 -4
- package/dist/cjs/api/follows.js +9 -2
- package/dist/cjs/api/identity.js +31 -9
- package/dist/cjs/api/nodes.js +3 -1
- package/dist/cjs/api/privacy.js +8 -2
- package/dist/cjs/api/session.js +15 -4
- package/dist/cjs/api/store.js +15 -5
- package/dist/cjs/api/topics.js +10 -3
- package/dist/cjs/api/users.js +16 -4
- package/dist/cjs/boot/sessionColdBoot.js +40 -13
- package/dist/cjs/constants/version.js +6 -6
- package/dist/cjs/crypto/identityMarker.js +3 -1
- package/dist/cjs/crypto/identityProof.js +6 -1
- package/dist/cjs/crypto/keyManager.js +87 -32
- package/dist/cjs/crypto/recoveryPhrase.js +2 -2
- package/dist/cjs/crypto/signatureService.js +3 -4
- package/dist/cjs/i18n/index.js +16 -3
- package/dist/cjs/i18n/locales/ar-SA.js +366 -366
- package/dist/cjs/i18n/locales/ca-ES.js +366 -366
- package/dist/cjs/i18n/locales/de-DE.js +366 -366
- package/dist/cjs/i18n/locales/en-US.js +1994 -1994
- package/dist/cjs/i18n/locales/es-ES.js +1994 -1994
- package/dist/cjs/i18n/locales/fr-FR.js +366 -366
- package/dist/cjs/i18n/locales/it-IT.js +366 -366
- package/dist/cjs/i18n/locales/ja-JP.js +366 -366
- package/dist/cjs/i18n/locales/ko-KR.js +366 -366
- package/dist/cjs/i18n/locales/pt-PT.js +366 -366
- package/dist/cjs/i18n/locales/zh-CN.js +366 -366
- package/dist/cjs/inference/OxyInferenceClient.js +12 -18
- package/dist/cjs/models/interfaces.js +11 -11
- package/dist/cjs/server/OxyServer.js +86 -28
- package/dist/cjs/server/agentAccount.js +6 -2
- package/dist/cjs/server/aliaMachineCredential.js +39 -14
- package/dist/cjs/server/auth.js +5 -4
- package/dist/cjs/server/capabilityTicket.js +5 -5
- package/dist/cjs/server/index.js +2 -1
- package/dist/cjs/server/liveCapabilityTicket.js +4 -1
- package/dist/cjs/server/middleware.js +61 -42
- package/dist/cjs/server/namespaces.js +28 -7
- package/dist/cjs/server/requesterAssertion.js +36 -30
- package/dist/cjs/server/serviceTokenLifetime.js +7 -4
- package/dist/cjs/server/traffic.js +53 -14
- package/dist/cjs/server/trafficNodeHttp.js +33 -8
- package/dist/cjs/server/workloadIdentity.client.js +4 -0
- package/dist/cjs/server/workloadIdentity.js +28 -1
- package/dist/cjs/session/SessionClient.js +54 -17
- package/dist/cjs/session/accountDelegationAccess.js +4 -6
- package/dist/cjs/session/accountDialogController.js +1 -1
- package/dist/cjs/session/authStateStore.js +18 -9
- package/dist/cjs/session/identityPin.js +6 -2
- package/dist/cjs/session/refresh.js +81 -23
- package/dist/cjs/session/sharedDeviceCredential.js +28 -15
- package/dist/cjs/shared/utils/errorUtils.js +1 -1
- package/dist/cjs/shared/utils/networkUtils.js +1 -1
- package/dist/cjs/shared/utils/themeUtils.js +1 -1
- package/dist/cjs/utils/accountCacheSweep.js +3 -1
- package/dist/cjs/utils/accountUtils.js +1 -3
- package/dist/cjs/utils/asyncUtils.js +1 -1
- package/dist/cjs/utils/authHelpers.js +2 -1
- package/dist/cjs/utils/avatarUtils.js +4 -2
- package/dist/cjs/utils/cache.js +1 -1
- package/dist/cjs/utils/cacheKey.js +3 -1
- package/dist/cjs/utils/deviceManager.js +4 -4
- package/dist/cjs/utils/errorUtils.js +6 -4
- package/dist/cjs/utils/languageUtils.js +404 -57
- package/dist/cjs/utils/profileLinks.js +1 -3
- package/dist/cjs/utils/requestUtils.js +7 -1
- package/dist/cjs/utils/userIdentity.js +1 -1
- package/dist/cjs/utils/validationUtils.js +5 -6
- package/dist/esm/HttpService.js +64 -20
- package/dist/esm/api/accounts.js +11 -4
- package/dist/esm/api/agency.js +3 -1
- package/dist/esm/api/apps.js +15 -4
- package/dist/esm/api/assets.js +39 -11
- package/dist/esm/api/auth.js +28 -8
- package/dist/esm/api/billing.js +25 -8
- package/dist/esm/api/civic.js +14 -4
- package/dist/esm/api/follows.js +9 -2
- package/dist/esm/api/identity.js +31 -9
- package/dist/esm/api/nodes.js +3 -1
- package/dist/esm/api/privacy.js +8 -2
- package/dist/esm/api/session.js +15 -4
- package/dist/esm/api/store.js +15 -5
- package/dist/esm/api/topics.js +10 -3
- package/dist/esm/api/users.js +16 -4
- package/dist/esm/boot/sessionColdBoot.js +41 -14
- package/dist/esm/constants/version.js +6 -6
- package/dist/esm/crypto/identityMarker.js +3 -1
- package/dist/esm/crypto/identityProof.js +6 -1
- package/dist/esm/crypto/internal.js +1 -1
- package/dist/esm/crypto/keyManager.js +87 -32
- package/dist/esm/crypto/recoveryPhrase.js +2 -2
- package/dist/esm/crypto/signatureService.js +3 -4
- package/dist/esm/i18n/index.js +16 -3
- package/dist/esm/i18n/locales/ar-SA.js +366 -366
- package/dist/esm/i18n/locales/ca-ES.js +366 -366
- package/dist/esm/i18n/locales/de-DE.js +366 -366
- package/dist/esm/i18n/locales/en-US.js +1994 -1994
- package/dist/esm/i18n/locales/es-ES.js +1994 -1994
- package/dist/esm/i18n/locales/fr-FR.js +366 -366
- package/dist/esm/i18n/locales/it-IT.js +366 -366
- package/dist/esm/i18n/locales/ja-JP.js +366 -366
- package/dist/esm/i18n/locales/ko-KR.js +366 -366
- package/dist/esm/i18n/locales/pt-PT.js +366 -366
- package/dist/esm/i18n/locales/zh-CN.js +366 -366
- package/dist/esm/index.js +1 -1
- package/dist/esm/inference/OxyInferenceClient.js +13 -19
- package/dist/esm/models/interfaces.js +11 -11
- package/dist/esm/server/OxyServer.js +87 -29
- package/dist/esm/server/agentAccount.js +6 -2
- package/dist/esm/server/aliaMachineCredential.js +39 -14
- package/dist/esm/server/auth.js +6 -5
- package/dist/esm/server/capabilityTicket.js +6 -6
- package/dist/esm/server/index.js +5 -5
- package/dist/esm/server/liveCapabilityTicket.js +6 -3
- package/dist/esm/server/middleware.js +62 -43
- package/dist/esm/server/namespaces.js +31 -10
- package/dist/esm/server/requesterAssertion.js +36 -30
- package/dist/esm/server/serviceTokenLifetime.js +7 -4
- package/dist/esm/server/traffic.js +55 -16
- package/dist/esm/server/trafficNodeHttp.js +34 -9
- package/dist/esm/server/userInvalidation.js +1 -1
- package/dist/esm/server/workloadIdentity.client.js +3 -0
- package/dist/esm/server/workloadIdentity.js +27 -1
- package/dist/esm/session/SessionClient.js +54 -17
- package/dist/esm/session/accountDelegationAccess.js +5 -7
- package/dist/esm/session/accountDialogController.js +1 -1
- package/dist/esm/session/authStateStore.js +18 -9
- package/dist/esm/session/identityPin.js +6 -2
- package/dist/esm/session/refresh.js +82 -24
- package/dist/esm/session/sharedDeviceCredential.js +28 -15
- package/dist/esm/shared/utils/errorUtils.js +1 -1
- package/dist/esm/shared/utils/networkUtils.js +1 -1
- package/dist/esm/shared/utils/themeUtils.js +1 -1
- package/dist/esm/utils/accountCacheSweep.js +3 -1
- package/dist/esm/utils/accountUtils.js +1 -3
- package/dist/esm/utils/asyncUtils.js +1 -1
- package/dist/esm/utils/authHelpers.js +2 -1
- package/dist/esm/utils/avatarUtils.js +4 -2
- package/dist/esm/utils/cache.js +1 -1
- package/dist/esm/utils/cacheKey.js +3 -1
- package/dist/esm/utils/deviceManager.js +4 -4
- package/dist/esm/utils/errorUtils.js +6 -4
- package/dist/esm/utils/languageUtils.js +404 -57
- package/dist/esm/utils/profileLinks.js +1 -3
- package/dist/esm/utils/requestUtils.js +7 -1
- package/dist/esm/utils/userIdentity.js +1 -1
- package/dist/esm/utils/validationUtils.js +5 -6
- package/dist/types/HttpService.d.ts +1 -1
- package/dist/types/api/accounts.d.ts +1 -1
- package/dist/types/api/apps.d.ts +4 -4
- package/dist/types/crypto/internal.d.ts +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/server/index.d.ts +6 -6
- package/dist/types/server/workloadIdentity.client.d.ts +5 -1
- package/dist/types/server/workloadIdentity.d.ts +26 -0
- package/dist/types/session/accountDelegationAccess.d.ts +1 -1
- package/dist/types/session/index.d.ts +1 -1
- package/dist/types/utils/userIdentity.d.ts +1 -1
- package/dist/types/utils/validationUtils.d.ts +4 -5
- package/package.json +2 -3
- package/src/HttpService.ts +183 -53
- package/src/OxyServices.errors.ts +7 -3
- package/src/OxyServices.ts +6 -2
- package/src/api/accounts.ts +76 -26
- package/src/api/agency.ts +24 -9
- package/src/api/appData.ts +12 -2
- package/src/api/apps.ts +81 -31
- package/src/api/assets.ts +113 -43
- package/src/api/auth.ts +145 -77
- package/src/api/billing.ts +112 -65
- package/src/api/civic.ts +61 -19
- package/src/api/contacts.ts +4 -1
- package/src/api/devices.ts +54 -21
- package/src/api/follows.ts +88 -31
- package/src/api/identity.ts +101 -33
- package/src/api/linkedAccounts.ts +26 -8
- package/src/api/nodes.ts +18 -6
- package/src/api/notifications.ts +26 -6
- package/src/api/privacy.ts +42 -8
- package/src/api/reputation.ts +18 -7
- package/src/api/session.ts +23 -5
- package/src/api/store.ts +81 -31
- package/src/api/topics.ts +18 -6
- package/src/api/users.ts +98 -35
- package/src/boot/sessionColdBoot.ts +60 -19
- package/src/civic/payloads.ts +1 -4
- package/src/client/context.ts +6 -1
- package/src/constants/version.ts +7 -6
- package/src/crypto/aead.ts +1 -5
- package/src/crypto/ecdh.ts +1 -4
- package/src/crypto/identityDerivations.ts +5 -1
- package/src/crypto/identityMarker.ts +3 -1
- package/src/crypto/identityProof.ts +6 -1
- package/src/crypto/index.ts +11 -11
- package/src/crypto/internal.ts +6 -1
- package/src/crypto/keyManager.ts +348 -98
- package/src/crypto/recoveryPhrase.ts +14 -9
- package/src/crypto/registrationPow.ts +1 -1
- package/src/crypto/signatureService.ts +14 -6
- package/src/i18n/accountCategoryLabels.ts +1 -4
- package/src/i18n/accountRoleLabels.ts +1 -4
- package/src/i18n/index.ts +25 -7
- package/src/i18n/locales/ar-SA.ts +375 -366
- package/src/i18n/locales/ca-ES.ts +382 -366
- package/src/i18n/locales/de-DE.ts +387 -366
- package/src/i18n/locales/en-US.ts +2034 -1994
- package/src/i18n/locales/es-ES.ts +2043 -1994
- package/src/i18n/locales/fr-FR.ts +387 -366
- package/src/i18n/locales/it-IT.ts +380 -366
- package/src/i18n/locales/ja-JP.ts +380 -366
- package/src/i18n/locales/ko-KR.ts +377 -366
- package/src/i18n/locales/pt-PT.ts +383 -366
- package/src/i18n/locales/zh-CN.ts +373 -366
- package/src/i18n/trustTierLabels.ts +1 -4
- package/src/index.ts +371 -349
- package/src/inference/OxyInferenceClient.ts +784 -780
- package/src/models/interfaces.ts +30 -27
- package/src/server/OxyServer.ts +227 -68
- package/src/server/agentAccount.ts +8 -2
- package/src/server/aliaMachineCredential.ts +57 -16
- package/src/server/auth.ts +9 -5
- package/src/server/capabilityTicket.ts +30 -21
- package/src/server/index.ts +29 -6
- package/src/server/liveCapabilityTicket.ts +31 -9
- package/src/server/middleware.ts +212 -121
- package/src/server/namespaces.ts +247 -94
- package/src/server/rateLimit.ts +2 -4
- package/src/server/requesterAssertion.ts +93 -54
- package/src/server/serviceTokenLifetime.ts +9 -4
- package/src/server/traffic.ts +117 -23
- package/src/server/trafficNodeHttp.ts +61 -14
- package/src/server/userInvalidation.ts +1 -4
- package/src/server/workloadIdentity.client.ts +12 -1
- package/src/server/workloadIdentity.ts +52 -5
- package/src/session/SessionClient.ts +170 -49
- package/src/session/accountDelegationAccess.ts +24 -31
- package/src/session/accountDialogController.ts +59 -14
- package/src/session/accountSwitchTargets.ts +10 -15
- package/src/session/authStateStore.ts +121 -81
- package/src/session/deviceDirectory.ts +1 -3
- package/src/session/identityPin.ts +10 -11
- package/src/session/identitySession.ts +3 -1
- package/src/session/index.ts +87 -82
- package/src/session/refresh.ts +138 -44
- package/src/session/sessionClientHost.ts +1 -3
- package/src/session/sharedDeviceCredential.ts +35 -14
- package/src/session/socketLoader.ts +9 -2
- package/src/shared/utils/errorUtils.ts +5 -2
- package/src/shared/utils/networkUtils.ts +5 -8
- package/src/shared/utils/themeUtils.ts +2 -6
- package/src/types/buffer.d.ts +66 -21
- package/src/types/expo-secure-store.d.ts +5 -1
- package/src/utils/accountCacheSweep.ts +4 -5
- package/src/utils/accountUtils.ts +107 -108
- package/src/utils/apiUtils.ts +3 -3
- package/src/utils/asyncUtils.ts +2 -2
- package/src/utils/authHelpers.ts +10 -5
- package/src/utils/avatarUtils.ts +11 -6
- package/src/utils/cache.ts +9 -10
- package/src/utils/cacheKey.ts +5 -1
- package/src/utils/coldBoot.ts +1 -3
- package/src/utils/commonsDelivery.ts +1 -4
- package/src/utils/deviceManager.ts +15 -14
- package/src/utils/errorUtils.ts +68 -86
- package/src/utils/languageUtils.ts +407 -58
- package/src/utils/oauthPkce.ts +1 -4
- package/src/utils/platform.ts +0 -1
- package/src/utils/profileLinks.ts +2 -5
- package/src/utils/requestUtils.ts +18 -14
- package/src/utils/sessionUtils.ts +34 -33
- package/src/utils/userHandle.ts +3 -1
- package/src/utils/userIdentity.ts +1 -1
- package/src/utils/validationUtils.ts +11 -9
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Recovery Phrase Service - BIP39 Mnemonic Generation
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* Handles generation and restoration of recovery phrases (mnemonic seeds)
|
|
5
5
|
* for backing up and restoring user identities.
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* Note: This module requires the polyfill to be loaded first (done via crypto/index.ts)
|
|
8
8
|
*
|
|
9
9
|
* Oxy recovery phrases are English-only, so the English wordlist is imported by
|
|
@@ -26,7 +26,7 @@ function toHex(data: Uint8Array | ArrayLike<number>): string {
|
|
|
26
26
|
// Convert to array of numbers if needed
|
|
27
27
|
const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
28
28
|
return Array.from(bytes)
|
|
29
|
-
.map(b => b.toString(16).padStart(2, '0'))
|
|
29
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
30
30
|
.join('');
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -234,8 +234,15 @@ export class RecoveryPhraseService {
|
|
|
234
234
|
|
|
235
235
|
const seed = await mnemonicToSeed(normalizedPhrase);
|
|
236
236
|
const salt = utf8(BACKUP_KDF_SALT);
|
|
237
|
-
const backupKey = hkdfSha256(
|
|
238
|
-
|
|
237
|
+
const backupKey = hkdfSha256(
|
|
238
|
+
seed,
|
|
239
|
+
salt,
|
|
240
|
+
utf8(BACKUP_KDF_ENCRYPTION_INFO),
|
|
241
|
+
BACKUP_MATERIAL_LENGTH,
|
|
242
|
+
);
|
|
243
|
+
const lookupId = toHex(
|
|
244
|
+
hkdfSha256(seed, salt, utf8(BACKUP_KDF_LOOKUP_INFO), BACKUP_MATERIAL_LENGTH),
|
|
245
|
+
);
|
|
239
246
|
|
|
240
247
|
return { backupKey, lookupId };
|
|
241
248
|
}
|
|
@@ -307,7 +314,7 @@ export class RecoveryPhraseService {
|
|
|
307
314
|
*/
|
|
308
315
|
static async derivePublicKeyFromPhrase(phrase: string): Promise<string> {
|
|
309
316
|
const normalizedPhrase = phrase.trim().toLowerCase();
|
|
310
|
-
|
|
317
|
+
|
|
311
318
|
if (!validateMnemonic(normalizedPhrase, wordlist)) {
|
|
312
319
|
throw new Error('Invalid recovery phrase');
|
|
313
320
|
}
|
|
@@ -329,10 +336,8 @@ export class RecoveryPhraseService {
|
|
|
329
336
|
* Convert a word array to a phrase string
|
|
330
337
|
*/
|
|
331
338
|
static wordsToPhrase(words: string[]): string {
|
|
332
|
-
return words.map(w => w.toLowerCase().trim()).join(' ');
|
|
339
|
+
return words.map((w) => w.toLowerCase().trim()).join(' ');
|
|
333
340
|
}
|
|
334
341
|
}
|
|
335
342
|
|
|
336
343
|
export default RecoveryPhraseService;
|
|
337
|
-
|
|
338
|
-
|
|
@@ -48,7 +48,7 @@ export async function solveRegistrationPow(publicKey: string, timestamp: number)
|
|
|
48
48
|
for (let nonce = 0; ; nonce += 1) {
|
|
49
49
|
const candidate = String(nonce);
|
|
50
50
|
const digest = bytesToHex(
|
|
51
|
-
sha256(utf8ToBytes(registrationPowMessage(publicKey, timestamp, candidate)))
|
|
51
|
+
sha256(utf8ToBytes(registrationPowMessage(publicKey, timestamp, candidate))),
|
|
52
52
|
);
|
|
53
53
|
if (meetsRegistrationPowDifficulty(digest, REGISTRATION_POW_DIFFICULTY_BITS)) {
|
|
54
54
|
return candidate;
|
|
@@ -57,7 +57,11 @@ export class SignatureService {
|
|
|
57
57
|
return nodeCrypto.randomBytes(32).toString('hex');
|
|
58
58
|
} catch (error) {
|
|
59
59
|
// Node crypto failed to load — log and fall through to Web Crypto API
|
|
60
|
-
logger.warn(
|
|
60
|
+
logger.warn(
|
|
61
|
+
'[oxy.crypto] Node crypto unavailable, falling back to Web Crypto',
|
|
62
|
+
{ component: 'SignatureService' },
|
|
63
|
+
error,
|
|
64
|
+
);
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
67
|
|
|
@@ -65,7 +69,7 @@ export class SignatureService {
|
|
|
65
69
|
const bytes = new Uint8Array(32);
|
|
66
70
|
globalThis.crypto.getRandomValues(bytes);
|
|
67
71
|
return Array.from(bytes)
|
|
68
|
-
.map(b => b.toString(16).padStart(2, '0'))
|
|
72
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
69
73
|
.join('');
|
|
70
74
|
}
|
|
71
75
|
|
|
@@ -115,7 +119,7 @@ export class SignatureService {
|
|
|
115
119
|
*/
|
|
116
120
|
static async verifySignedMessage(
|
|
117
121
|
signedMessage: SignedMessage,
|
|
118
|
-
maxAgeMs: number = 5 * 60 * 1000 // 5 minutes default
|
|
122
|
+
maxAgeMs: number = 5 * 60 * 1000, // 5 minutes default
|
|
119
123
|
): Promise<boolean> {
|
|
120
124
|
const { message, signature, publicKey, timestamp } = signedMessage;
|
|
121
125
|
|
|
@@ -190,7 +194,7 @@ export class SignatureService {
|
|
|
190
194
|
static async verifyChallengeResponse(
|
|
191
195
|
originalChallenge: string,
|
|
192
196
|
response: AuthChallenge,
|
|
193
|
-
maxAgeMs: number = 5 * 60 * 1000
|
|
197
|
+
maxAgeMs: number = 5 * 60 * 1000,
|
|
194
198
|
): Promise<boolean> {
|
|
195
199
|
const { challenge: signature, publicKey, timestamp } = response;
|
|
196
200
|
|
|
@@ -209,7 +213,11 @@ export class SignatureService {
|
|
|
209
213
|
* Used when registering a new identity with the server
|
|
210
214
|
* Format matches server expectation: oxy:register:{publicKey}:{timestamp}
|
|
211
215
|
*/
|
|
212
|
-
static async createRegistrationSignature(): Promise<{
|
|
216
|
+
static async createRegistrationSignature(): Promise<{
|
|
217
|
+
signature: string;
|
|
218
|
+
publicKey: string;
|
|
219
|
+
timestamp: number;
|
|
220
|
+
}> {
|
|
213
221
|
const publicKey = await KeyManager.getPublicKey();
|
|
214
222
|
if (!publicKey) {
|
|
215
223
|
throw new Error('No identity found. Please create or import an identity first.');
|
|
@@ -244,7 +252,7 @@ export class SignatureService {
|
|
|
244
252
|
|
|
245
253
|
// Create canonical string representation
|
|
246
254
|
const sortedKeys = Object.keys(data).sort();
|
|
247
|
-
const canonicalParts = sortedKeys.map(key => `${key}:${JSON.stringify(data[key])}`);
|
|
255
|
+
const canonicalParts = sortedKeys.map((key) => `${key}:${JSON.stringify(data[key])}`);
|
|
248
256
|
const canonicalString = canonicalParts.join('|');
|
|
249
257
|
|
|
250
258
|
const message = `request:${publicKey}:${timestamp}:${canonicalString}`;
|
|
@@ -36,9 +36,6 @@ import { translate } from './index';
|
|
|
36
36
|
export const EN_ACCOUNT_CATEGORY_LABELS: Record<AccountCategoryId, string> =
|
|
37
37
|
enUS.accounts.accountCategory;
|
|
38
38
|
|
|
39
|
-
export function accountCategoryLabel(
|
|
40
|
-
locale: string | undefined,
|
|
41
|
-
id: AccountCategoryId,
|
|
42
|
-
): string {
|
|
39
|
+
export function accountCategoryLabel(locale: string | undefined, id: AccountCategoryId): string {
|
|
43
40
|
return translate(locale, `accounts.accountCategory.${id}`);
|
|
44
41
|
}
|
|
@@ -18,9 +18,6 @@ export const EN_ACCOUNT_ROLE_LABELS: Record<AccountRole, string> = {
|
|
|
18
18
|
viewer: enUS.accounts.roles.viewer.label,
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export function accountRoleLabel(
|
|
22
|
-
locale: string | undefined,
|
|
23
|
-
role: AccountRole,
|
|
24
|
-
): string {
|
|
21
|
+
export function accountRoleLabel(locale: string | undefined, role: AccountRole): string {
|
|
25
22
|
return translate(locale, `accounts.roles.${role}.label`);
|
|
26
23
|
}
|
package/src/i18n/index.ts
CHANGED
|
@@ -28,8 +28,17 @@ const LOADERS: Record<string, () => Promise<{ default: LocaleDict }>> = {
|
|
|
28
28
|
|
|
29
29
|
/** Base subtag → the dictionary that serves it. */
|
|
30
30
|
const ALIASES: Record<string, string> = {
|
|
31
|
-
en: 'en-US',
|
|
32
|
-
|
|
31
|
+
en: 'en-US',
|
|
32
|
+
es: 'es-ES',
|
|
33
|
+
ca: 'ca-ES',
|
|
34
|
+
fr: 'fr-FR',
|
|
35
|
+
de: 'de-DE',
|
|
36
|
+
it: 'it-IT',
|
|
37
|
+
pt: 'pt-PT',
|
|
38
|
+
ja: 'ja-JP',
|
|
39
|
+
ko: 'ko-KR',
|
|
40
|
+
zh: 'zh-CN',
|
|
41
|
+
ar: 'ar-SA',
|
|
33
42
|
};
|
|
34
43
|
|
|
35
44
|
const DICTS: Record<string, LocaleDict> = { [FALLBACK]: enUS };
|
|
@@ -107,13 +116,22 @@ function resolveLang(locale: string | undefined): string {
|
|
|
107
116
|
}
|
|
108
117
|
|
|
109
118
|
function getNested(obj: unknown, path: string): unknown {
|
|
110
|
-
return path
|
|
111
|
-
(
|
|
112
|
-
|
|
113
|
-
|
|
119
|
+
return path
|
|
120
|
+
.split('.')
|
|
121
|
+
.reduce<unknown>(
|
|
122
|
+
(acc, key) =>
|
|
123
|
+
acc && typeof acc === 'object' && (acc as Record<string, unknown>)[key] != null
|
|
124
|
+
? (acc as Record<string, unknown>)[key]
|
|
125
|
+
: undefined,
|
|
126
|
+
obj,
|
|
127
|
+
);
|
|
114
128
|
}
|
|
115
129
|
|
|
116
|
-
export function translate(
|
|
130
|
+
export function translate(
|
|
131
|
+
locale: string | undefined,
|
|
132
|
+
key: string,
|
|
133
|
+
vars?: Record<string, string | number>,
|
|
134
|
+
): string {
|
|
117
135
|
const lang = resolveLang(locale);
|
|
118
136
|
const dict = DICTS[lang] || DICTS[FALLBACK];
|
|
119
137
|
let val = getNested(dict, key);
|