@authyon/server 0.2.0-beta.32 → 0.2.0-beta.34
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/dist/{authorization-TbK43K94.d.ts → authorization-CF352ynn.d.ts} +1 -1
- package/dist/{authorization-CGex2N6O.d.cts → authorization-DlGXQXIW.d.cts} +1 -1
- package/dist/{authyonServerClient-DqY5OtxL.d.cts → authyonServerClient-CpTMX1GH.d.cts} +14 -0
- package/dist/{authyonServerClient-DqY5OtxL.d.ts → authyonServerClient-CpTMX1GH.d.ts} +14 -0
- package/dist/bff.cjs +81 -4
- package/dist/bff.d.cts +33 -2
- package/dist/bff.d.ts +33 -2
- package/dist/bff.js +77 -4
- package/dist/{chunk-SUL2HLRR.js → chunk-CSQJSNU7.js} +5 -1
- package/dist/index.cjs +429 -1
- package/dist/index.d.cts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +423 -1
- package/dist/next.d.cts +2 -2
- package/dist/next.d.ts +2 -2
- package/dist/preferences-CPQEbdxV.d.cts +447 -0
- package/dist/preferences-CPQEbdxV.d.ts +447 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { J as JwksTokenVerifier, A as AuthyonServerClient } from './authyonServerClient-
|
|
1
|
+
import { J as JwksTokenVerifier, A as AuthyonServerClient } from './authyonServerClient-CpTMX1GH.js';
|
|
2
2
|
|
|
3
3
|
type AbilitySubject = string | Record<string, unknown>;
|
|
4
4
|
type AbilityConditions = Record<string, unknown>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { J as JwksTokenVerifier, A as AuthyonServerClient } from './authyonServerClient-
|
|
1
|
+
import { J as JwksTokenVerifier, A as AuthyonServerClient } from './authyonServerClient-CpTMX1GH.cjs';
|
|
2
2
|
|
|
3
3
|
type AbilitySubject = string | Record<string, unknown>;
|
|
4
4
|
type AbilityConditions = Record<string, unknown>;
|
|
@@ -1051,6 +1051,11 @@ declare class UserScopedClient {
|
|
|
1051
1051
|
members: {
|
|
1052
1052
|
/** Newest first; `search` matches email, username or name (at most 100 characters). */
|
|
1053
1053
|
list: (tenantId: string, options?: MemberListOptions) => Promise<TenantMemberPage>;
|
|
1054
|
+
/**
|
|
1055
|
+
* One member, in the shape of a `list` row. A user who is not a direct
|
|
1056
|
+
* member fails with `tenant.member.not_found` (404).
|
|
1057
|
+
*/
|
|
1058
|
+
get: (tenantId: string, userId: string) => Promise<TenantMember>;
|
|
1054
1059
|
/** Adds an existing environment user by email; does not send an invitation email. */
|
|
1055
1060
|
invite: (tenantId: string, input: InviteTenantMemberInput) => Promise<TenantMember>;
|
|
1056
1061
|
remove: (tenantId: string, userId: string) => Promise<void>;
|
|
@@ -1190,6 +1195,15 @@ interface AuthyonJwtClaims extends JWTPayload {
|
|
|
1190
1195
|
scope?: string;
|
|
1191
1196
|
/** The active tenant and the grants held inside it. Absent until a switch. */
|
|
1192
1197
|
tenant?: AuthyonTenantClaim;
|
|
1198
|
+
/**
|
|
1199
|
+
* OIDC `zoneinfo`: IANA time zone (`America/Sao_Paulo`). The user's choice,
|
|
1200
|
+
* else the environment default; absent when neither is set. A console
|
|
1201
|
+
* (platform) token carries only the operator's own choice. Changes at the
|
|
1202
|
+
* next refresh. Authyon API of 2026-12-05 or newer.
|
|
1203
|
+
*/
|
|
1204
|
+
zoneinfo?: string;
|
|
1205
|
+
/** OIDC `locale`: BCP 47 tag (`pt-BR`), same fallback and timing as `zoneinfo`. */
|
|
1206
|
+
locale?: string;
|
|
1193
1207
|
}
|
|
1194
1208
|
interface VerifiedAccessToken {
|
|
1195
1209
|
claims: AuthyonJwtClaims;
|
|
@@ -1051,6 +1051,11 @@ declare class UserScopedClient {
|
|
|
1051
1051
|
members: {
|
|
1052
1052
|
/** Newest first; `search` matches email, username or name (at most 100 characters). */
|
|
1053
1053
|
list: (tenantId: string, options?: MemberListOptions) => Promise<TenantMemberPage>;
|
|
1054
|
+
/**
|
|
1055
|
+
* One member, in the shape of a `list` row. A user who is not a direct
|
|
1056
|
+
* member fails with `tenant.member.not_found` (404).
|
|
1057
|
+
*/
|
|
1058
|
+
get: (tenantId: string, userId: string) => Promise<TenantMember>;
|
|
1054
1059
|
/** Adds an existing environment user by email; does not send an invitation email. */
|
|
1055
1060
|
invite: (tenantId: string, input: InviteTenantMemberInput) => Promise<TenantMember>;
|
|
1056
1061
|
remove: (tenantId: string, userId: string) => Promise<void>;
|
|
@@ -1190,6 +1195,15 @@ interface AuthyonJwtClaims extends JWTPayload {
|
|
|
1190
1195
|
scope?: string;
|
|
1191
1196
|
/** The active tenant and the grants held inside it. Absent until a switch. */
|
|
1192
1197
|
tenant?: AuthyonTenantClaim;
|
|
1198
|
+
/**
|
|
1199
|
+
* OIDC `zoneinfo`: IANA time zone (`America/Sao_Paulo`). The user's choice,
|
|
1200
|
+
* else the environment default; absent when neither is set. A console
|
|
1201
|
+
* (platform) token carries only the operator's own choice. Changes at the
|
|
1202
|
+
* next refresh. Authyon API of 2026-12-05 or newer.
|
|
1203
|
+
*/
|
|
1204
|
+
zoneinfo?: string;
|
|
1205
|
+
/** OIDC `locale`: BCP 47 tag (`pt-BR`), same fallback and timing as `zoneinfo`. */
|
|
1206
|
+
locale?: string;
|
|
1193
1207
|
}
|
|
1194
1208
|
interface VerifiedAccessToken {
|
|
1195
1209
|
claims: AuthyonJwtClaims;
|
package/dist/bff.cjs
CHANGED
|
@@ -67,7 +67,11 @@ var ErrorCodes = {
|
|
|
67
67
|
CredentialThrottled: "credential_throttled",
|
|
68
68
|
ApprovalNotFound: "authorization_not_found",
|
|
69
69
|
SessionRevoked: "session_revoked",
|
|
70
|
-
TwoFactorTooManyFailures: "user.2fa.too_many_failures"
|
|
70
|
+
TwoFactorTooManyFailures: "user.2fa.too_many_failures",
|
|
71
|
+
/** Not an IANA time zone the API knows. See `TimeZones`. */
|
|
72
|
+
PreferencesTimeZoneInvalid: "preferences.time_zone.invalid",
|
|
73
|
+
/** Not a well-formed BCP 47 tag. See `Locales`. */
|
|
74
|
+
PreferencesLocaleInvalid: "preferences.locale.invalid"
|
|
71
75
|
};
|
|
72
76
|
var STANDARD_ERROR_FIELDS = /* @__PURE__ */ new Set([
|
|
73
77
|
"type",
|
|
@@ -496,6 +500,39 @@ var BffSessionManager = class {
|
|
|
496
500
|
});
|
|
497
501
|
});
|
|
498
502
|
}
|
|
503
|
+
/**
|
|
504
|
+
* Saves the user's time zone and language, then rotates the session's tokens
|
|
505
|
+
* so the access token carries the new `zoneinfo` / `locale` at once instead
|
|
506
|
+
* of at its natural refresh.
|
|
507
|
+
*
|
|
508
|
+
* Both steps run inside the session lease, the same lock a refresh or a
|
|
509
|
+
* tenant switch takes. A second rotation racing this one would present a
|
|
510
|
+
* refresh token this one already spent, and the API treats that as reuse
|
|
511
|
+
* and revokes the whole family — the user would be signed out for saving
|
|
512
|
+
* their language.
|
|
513
|
+
*/
|
|
514
|
+
async updatePreferences(id, input) {
|
|
515
|
+
const provider = this.options.provider;
|
|
516
|
+
if (!provider.updatePreferences)
|
|
517
|
+
throw new BffSessionError("provider.unsupported_operation", 501);
|
|
518
|
+
return this.update(id, async (lease) => {
|
|
519
|
+
const refreshed = await this.refreshIfNeeded(lease);
|
|
520
|
+
if (!refreshed && !await provider.validate(lease.record.tokens.accessToken)) {
|
|
521
|
+
throw new BffSessionError("session.revoked", 401, true);
|
|
522
|
+
}
|
|
523
|
+
try {
|
|
524
|
+
await provider.updatePreferences(lease.record.tokens.accessToken, input);
|
|
525
|
+
} catch (error) {
|
|
526
|
+
if (error instanceof AuthyonError && error.status === 400 && error.code.startsWith("preferences."))
|
|
527
|
+
throw new BffSessionError(error.code, 400);
|
|
528
|
+
throw error;
|
|
529
|
+
}
|
|
530
|
+
await this.rotate(lease, {
|
|
531
|
+
issue: () => provider.refresh(lease.record.tokens.refreshToken),
|
|
532
|
+
accepts: (user) => user.id === lease.record.user.id && user.tenant?.id === lease.record.user.tenant?.id
|
|
533
|
+
});
|
|
534
|
+
});
|
|
535
|
+
}
|
|
499
536
|
async logout(id) {
|
|
500
537
|
const lease = await this.repository.acquire(id);
|
|
501
538
|
await this.repository.remove(lease);
|
|
@@ -624,7 +661,9 @@ var BffSessionManager = class {
|
|
|
624
661
|
return {
|
|
625
662
|
id: user.id,
|
|
626
663
|
email: user.email,
|
|
627
|
-
tenant: tenant ? { id: tenant.id, slug: tenant.slug } : null
|
|
664
|
+
tenant: tenant ? { id: tenant.id, slug: tenant.slug } : null,
|
|
665
|
+
timeZone: user.timeZone ?? null,
|
|
666
|
+
locale: user.locale ?? null
|
|
628
667
|
};
|
|
629
668
|
}
|
|
630
669
|
async revokeUnstoredTokens(tokens) {
|
|
@@ -639,7 +678,26 @@ var BffSessionManager = class {
|
|
|
639
678
|
// src/bff/handlers.ts
|
|
640
679
|
function publicUser(user) {
|
|
641
680
|
const { id, email, tenant } = user;
|
|
642
|
-
return {
|
|
681
|
+
return {
|
|
682
|
+
id,
|
|
683
|
+
email,
|
|
684
|
+
tenant,
|
|
685
|
+
organization: tenant,
|
|
686
|
+
timeZone: user.timeZone ?? null,
|
|
687
|
+
locale: user.locale ?? null
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
function preferencesInput(body) {
|
|
691
|
+
const read = (name) => {
|
|
692
|
+
const value = body[name];
|
|
693
|
+
if (value === null || value === "") return null;
|
|
694
|
+
if (typeof value !== "string" || value.length > 100)
|
|
695
|
+
throw new BffSessionError("request.invalid_body", 400);
|
|
696
|
+
return value;
|
|
697
|
+
};
|
|
698
|
+
if (!("timeZone" in body) || !("locale" in body))
|
|
699
|
+
throw new BffSessionError("request.invalid_body", 400);
|
|
700
|
+
return { timeZone: read("timeZone"), locale: read("locale") };
|
|
643
701
|
}
|
|
644
702
|
function publicSession(record) {
|
|
645
703
|
return { authenticated: true, user: publicUser(record.user), expiresAt: record.expiresAt };
|
|
@@ -731,6 +789,16 @@ function createBffSession(options) {
|
|
|
731
789
|
),
|
|
732
790
|
/** Body `{ tenantSlug }` (the deprecated `{ organizationSlug }` is still read). */
|
|
733
791
|
switchTenant,
|
|
792
|
+
/**
|
|
793
|
+
* Body `{ timeZone, locale }`, both required (`null` clears). Saves them
|
|
794
|
+
* and rotates the session so the token carries them at once.
|
|
795
|
+
*/
|
|
796
|
+
updatePreferences: handler("PUT", async (request) => {
|
|
797
|
+
const input = preferencesInput(await readBffBody(request));
|
|
798
|
+
return http.response(
|
|
799
|
+
publicSession(await manager.updatePreferences(requiredSessionId(request), input))
|
|
800
|
+
);
|
|
801
|
+
}),
|
|
734
802
|
/** @deprecated Mount `switchTenant`; this is the same handler. */
|
|
735
803
|
switchOrganization: switchTenant,
|
|
736
804
|
logout: handler("POST", async (request) => {
|
|
@@ -1013,7 +1081,9 @@ function readProfile(value) {
|
|
|
1013
1081
|
return {
|
|
1014
1082
|
id: requiredString(user.id),
|
|
1015
1083
|
email: requiredString(user.email),
|
|
1016
|
-
tenant: tenant ? { id: requiredString(tenant.id), slug: requiredString(tenant.slug) } : null
|
|
1084
|
+
tenant: tenant ? { id: requiredString(tenant.id), slug: requiredString(tenant.slug) } : null,
|
|
1085
|
+
timeZone: typeof user.timeZone === "string" ? user.timeZone : null,
|
|
1086
|
+
locale: typeof user.locale === "string" ? user.locale : null
|
|
1017
1087
|
};
|
|
1018
1088
|
}
|
|
1019
1089
|
function createAuthyonBffProvider(options) {
|
|
@@ -1076,6 +1146,13 @@ function createAuthyonBffProvider(options) {
|
|
|
1076
1146
|
})
|
|
1077
1147
|
);
|
|
1078
1148
|
},
|
|
1149
|
+
async updatePreferences(accessToken, input) {
|
|
1150
|
+
await http.request("/auth/me/preferences", {
|
|
1151
|
+
method: "PUT",
|
|
1152
|
+
headers: bearer(accessToken),
|
|
1153
|
+
body: { timeZone: input.timeZone, locale: input.locale }
|
|
1154
|
+
});
|
|
1155
|
+
},
|
|
1079
1156
|
async validate(accessToken) {
|
|
1080
1157
|
try {
|
|
1081
1158
|
const result = await options.validator.validate(accessToken);
|
package/dist/bff.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { T as TimeZone, L as Locale } from './preferences-CPQEbdxV.cjs';
|
|
2
|
+
import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-CpTMX1GH.cjs';
|
|
2
3
|
import 'jose';
|
|
3
4
|
|
|
4
5
|
interface BffLoginInput {
|
|
@@ -40,6 +41,13 @@ interface BffUser {
|
|
|
40
41
|
id: string;
|
|
41
42
|
slug: string;
|
|
42
43
|
} | null;
|
|
44
|
+
/**
|
|
45
|
+
* IANA time zone in effect (the person's choice, else the environment
|
|
46
|
+
* default), or `null`. Absent from an API older than 2026-12-05.
|
|
47
|
+
*/
|
|
48
|
+
timeZone?: string | null;
|
|
49
|
+
/** BCP 47 language in effect, same fallback. Absent from an API older than 2026-12-05. */
|
|
50
|
+
locale?: string | null;
|
|
43
51
|
/**
|
|
44
52
|
* @deprecated Use `tenant`. Still read from custom providers and still sent
|
|
45
53
|
* to the browser as a mirror of `tenant`; removed in a later release.
|
|
@@ -72,9 +80,25 @@ interface BffAuthProvider {
|
|
|
72
80
|
switchTenant?(accessToken: string, slug: string): Promise<BffTokens>;
|
|
73
81
|
/** @deprecated Implement `switchTenant`. */
|
|
74
82
|
switchOrganization?(accessToken: string, slug: string): Promise<BffTokens>;
|
|
83
|
+
/**
|
|
84
|
+
* Saves the signed-in user's time zone and language (`PUT /auth/me/preferences`).
|
|
85
|
+
* Optional so existing custom providers keep compiling; without it the
|
|
86
|
+
* handler answers 501.
|
|
87
|
+
*/
|
|
88
|
+
updatePreferences?(accessToken: string, input: BffPreferencesInput): Promise<void>;
|
|
75
89
|
validate(accessToken: string): Promise<boolean>;
|
|
76
90
|
profile(accessToken: string): Promise<BffUser>;
|
|
77
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* A replace: both fields always travel, and `null` puts that one back on the
|
|
94
|
+
* environment default. IANA zone (`America/Sao_Paulo`), BCP 47 tag (`pt-BR`).
|
|
95
|
+
*/
|
|
96
|
+
interface BffPreferencesInput {
|
|
97
|
+
/** See `TimeZones`. */
|
|
98
|
+
timeZone: TimeZone | null;
|
|
99
|
+
/** See `Locales`. */
|
|
100
|
+
locale: Locale | null;
|
|
101
|
+
}
|
|
78
102
|
interface BffSessionRecord {
|
|
79
103
|
revision: string;
|
|
80
104
|
tokens: BffTokens;
|
|
@@ -119,6 +143,11 @@ declare function createBffSession(options: BffSessionOptions): {
|
|
|
119
143
|
session: (request: Request) => Promise<Response>;
|
|
120
144
|
/** Body `{ tenantSlug }` (the deprecated `{ organizationSlug }` is still read). */
|
|
121
145
|
switchTenant: (request: Request) => Promise<Response>;
|
|
146
|
+
/**
|
|
147
|
+
* Body `{ timeZone, locale }`, both required (`null` clears). Saves them
|
|
148
|
+
* and rotates the session so the token carries them at once.
|
|
149
|
+
*/
|
|
150
|
+
updatePreferences: (request: Request) => Promise<Response>;
|
|
122
151
|
/** @deprecated Mount `switchTenant`; this is the same handler. */
|
|
123
152
|
switchOrganization: (request: Request) => Promise<Response>;
|
|
124
153
|
logout: (request: Request) => Promise<Response>;
|
|
@@ -136,6 +165,8 @@ declare function createBffSession(options: BffSessionOptions): {
|
|
|
136
165
|
id: string;
|
|
137
166
|
slug: string;
|
|
138
167
|
} | null;
|
|
168
|
+
timeZone: string | null;
|
|
169
|
+
locale: string | null;
|
|
139
170
|
};
|
|
140
171
|
expiresAt: number;
|
|
141
172
|
}>;
|
|
@@ -179,4 +210,4 @@ interface RedisBffSessionStoreOptions {
|
|
|
179
210
|
/** node-redis-compatible adapter. Lua fences stale writers using the record revision. */
|
|
180
211
|
declare function createRedisBffSessionStore(options: RedisBffSessionStoreOptions): BffSessionStore;
|
|
181
212
|
|
|
182
|
-
export { type AuthyonBffProviderOptions, type BffAuthProvider, type BffChallenge, type BffLoginInput, type BffRedisClient, BffSessionError, type BffSessionLifetime, type BffSessionOptions, type BffSessionPersistence, type BffSessionRecord, type BffSessionStore, type BffTokens, type BffUser, type BffVerifyTwoFactorInput, type RedisBffSessionStoreOptions, createAuthyonBffProvider, createBffSession, createMemoryBffSessionStore, createRedisBffSessionStore };
|
|
213
|
+
export { type AuthyonBffProviderOptions, type BffAuthProvider, type BffChallenge, type BffLoginInput, type BffPreferencesInput, type BffRedisClient, BffSessionError, type BffSessionLifetime, type BffSessionOptions, type BffSessionPersistence, type BffSessionRecord, type BffSessionStore, type BffTokens, type BffUser, type BffVerifyTwoFactorInput, type RedisBffSessionStoreOptions, createAuthyonBffProvider, createBffSession, createMemoryBffSessionStore, createRedisBffSessionStore };
|
package/dist/bff.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { T as TimeZone, L as Locale } from './preferences-CPQEbdxV.js';
|
|
2
|
+
import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-CpTMX1GH.js';
|
|
2
3
|
import 'jose';
|
|
3
4
|
|
|
4
5
|
interface BffLoginInput {
|
|
@@ -40,6 +41,13 @@ interface BffUser {
|
|
|
40
41
|
id: string;
|
|
41
42
|
slug: string;
|
|
42
43
|
} | null;
|
|
44
|
+
/**
|
|
45
|
+
* IANA time zone in effect (the person's choice, else the environment
|
|
46
|
+
* default), or `null`. Absent from an API older than 2026-12-05.
|
|
47
|
+
*/
|
|
48
|
+
timeZone?: string | null;
|
|
49
|
+
/** BCP 47 language in effect, same fallback. Absent from an API older than 2026-12-05. */
|
|
50
|
+
locale?: string | null;
|
|
43
51
|
/**
|
|
44
52
|
* @deprecated Use `tenant`. Still read from custom providers and still sent
|
|
45
53
|
* to the browser as a mirror of `tenant`; removed in a later release.
|
|
@@ -72,9 +80,25 @@ interface BffAuthProvider {
|
|
|
72
80
|
switchTenant?(accessToken: string, slug: string): Promise<BffTokens>;
|
|
73
81
|
/** @deprecated Implement `switchTenant`. */
|
|
74
82
|
switchOrganization?(accessToken: string, slug: string): Promise<BffTokens>;
|
|
83
|
+
/**
|
|
84
|
+
* Saves the signed-in user's time zone and language (`PUT /auth/me/preferences`).
|
|
85
|
+
* Optional so existing custom providers keep compiling; without it the
|
|
86
|
+
* handler answers 501.
|
|
87
|
+
*/
|
|
88
|
+
updatePreferences?(accessToken: string, input: BffPreferencesInput): Promise<void>;
|
|
75
89
|
validate(accessToken: string): Promise<boolean>;
|
|
76
90
|
profile(accessToken: string): Promise<BffUser>;
|
|
77
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* A replace: both fields always travel, and `null` puts that one back on the
|
|
94
|
+
* environment default. IANA zone (`America/Sao_Paulo`), BCP 47 tag (`pt-BR`).
|
|
95
|
+
*/
|
|
96
|
+
interface BffPreferencesInput {
|
|
97
|
+
/** See `TimeZones`. */
|
|
98
|
+
timeZone: TimeZone | null;
|
|
99
|
+
/** See `Locales`. */
|
|
100
|
+
locale: Locale | null;
|
|
101
|
+
}
|
|
78
102
|
interface BffSessionRecord {
|
|
79
103
|
revision: string;
|
|
80
104
|
tokens: BffTokens;
|
|
@@ -119,6 +143,11 @@ declare function createBffSession(options: BffSessionOptions): {
|
|
|
119
143
|
session: (request: Request) => Promise<Response>;
|
|
120
144
|
/** Body `{ tenantSlug }` (the deprecated `{ organizationSlug }` is still read). */
|
|
121
145
|
switchTenant: (request: Request) => Promise<Response>;
|
|
146
|
+
/**
|
|
147
|
+
* Body `{ timeZone, locale }`, both required (`null` clears). Saves them
|
|
148
|
+
* and rotates the session so the token carries them at once.
|
|
149
|
+
*/
|
|
150
|
+
updatePreferences: (request: Request) => Promise<Response>;
|
|
122
151
|
/** @deprecated Mount `switchTenant`; this is the same handler. */
|
|
123
152
|
switchOrganization: (request: Request) => Promise<Response>;
|
|
124
153
|
logout: (request: Request) => Promise<Response>;
|
|
@@ -136,6 +165,8 @@ declare function createBffSession(options: BffSessionOptions): {
|
|
|
136
165
|
id: string;
|
|
137
166
|
slug: string;
|
|
138
167
|
} | null;
|
|
168
|
+
timeZone: string | null;
|
|
169
|
+
locale: string | null;
|
|
139
170
|
};
|
|
140
171
|
expiresAt: number;
|
|
141
172
|
}>;
|
|
@@ -179,4 +210,4 @@ interface RedisBffSessionStoreOptions {
|
|
|
179
210
|
/** node-redis-compatible adapter. Lua fences stale writers using the record revision. */
|
|
180
211
|
declare function createRedisBffSessionStore(options: RedisBffSessionStoreOptions): BffSessionStore;
|
|
181
212
|
|
|
182
|
-
export { type AuthyonBffProviderOptions, type BffAuthProvider, type BffChallenge, type BffLoginInput, type BffRedisClient, BffSessionError, type BffSessionLifetime, type BffSessionOptions, type BffSessionPersistence, type BffSessionRecord, type BffSessionStore, type BffTokens, type BffUser, type BffVerifyTwoFactorInput, type RedisBffSessionStoreOptions, createAuthyonBffProvider, createBffSession, createMemoryBffSessionStore, createRedisBffSessionStore };
|
|
213
|
+
export { type AuthyonBffProviderOptions, type BffAuthProvider, type BffChallenge, type BffLoginInput, type BffPreferencesInput, type BffRedisClient, BffSessionError, type BffSessionLifetime, type BffSessionOptions, type BffSessionPersistence, type BffSessionRecord, type BffSessionStore, type BffTokens, type BffUser, type BffVerifyTwoFactorInput, type RedisBffSessionStoreOptions, createAuthyonBffProvider, createBffSession, createMemoryBffSessionStore, createRedisBffSessionStore };
|
package/dist/bff.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
DEFAULT_BASE_URL,
|
|
4
4
|
JsonHttpClient,
|
|
5
5
|
createSharedTransport
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-CSQJSNU7.js";
|
|
7
7
|
import "./chunk-77J4NURK.js";
|
|
8
8
|
|
|
9
9
|
// src/bff/contracts.ts
|
|
@@ -336,6 +336,39 @@ var BffSessionManager = class {
|
|
|
336
336
|
});
|
|
337
337
|
});
|
|
338
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* Saves the user's time zone and language, then rotates the session's tokens
|
|
341
|
+
* so the access token carries the new `zoneinfo` / `locale` at once instead
|
|
342
|
+
* of at its natural refresh.
|
|
343
|
+
*
|
|
344
|
+
* Both steps run inside the session lease, the same lock a refresh or a
|
|
345
|
+
* tenant switch takes. A second rotation racing this one would present a
|
|
346
|
+
* refresh token this one already spent, and the API treats that as reuse
|
|
347
|
+
* and revokes the whole family — the user would be signed out for saving
|
|
348
|
+
* their language.
|
|
349
|
+
*/
|
|
350
|
+
async updatePreferences(id, input) {
|
|
351
|
+
const provider = this.options.provider;
|
|
352
|
+
if (!provider.updatePreferences)
|
|
353
|
+
throw new BffSessionError("provider.unsupported_operation", 501);
|
|
354
|
+
return this.update(id, async (lease) => {
|
|
355
|
+
const refreshed = await this.refreshIfNeeded(lease);
|
|
356
|
+
if (!refreshed && !await provider.validate(lease.record.tokens.accessToken)) {
|
|
357
|
+
throw new BffSessionError("session.revoked", 401, true);
|
|
358
|
+
}
|
|
359
|
+
try {
|
|
360
|
+
await provider.updatePreferences(lease.record.tokens.accessToken, input);
|
|
361
|
+
} catch (error) {
|
|
362
|
+
if (error instanceof AuthyonError && error.status === 400 && error.code.startsWith("preferences."))
|
|
363
|
+
throw new BffSessionError(error.code, 400);
|
|
364
|
+
throw error;
|
|
365
|
+
}
|
|
366
|
+
await this.rotate(lease, {
|
|
367
|
+
issue: () => provider.refresh(lease.record.tokens.refreshToken),
|
|
368
|
+
accepts: (user) => user.id === lease.record.user.id && user.tenant?.id === lease.record.user.tenant?.id
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
}
|
|
339
372
|
async logout(id) {
|
|
340
373
|
const lease = await this.repository.acquire(id);
|
|
341
374
|
await this.repository.remove(lease);
|
|
@@ -464,7 +497,9 @@ var BffSessionManager = class {
|
|
|
464
497
|
return {
|
|
465
498
|
id: user.id,
|
|
466
499
|
email: user.email,
|
|
467
|
-
tenant: tenant ? { id: tenant.id, slug: tenant.slug } : null
|
|
500
|
+
tenant: tenant ? { id: tenant.id, slug: tenant.slug } : null,
|
|
501
|
+
timeZone: user.timeZone ?? null,
|
|
502
|
+
locale: user.locale ?? null
|
|
468
503
|
};
|
|
469
504
|
}
|
|
470
505
|
async revokeUnstoredTokens(tokens) {
|
|
@@ -479,7 +514,26 @@ var BffSessionManager = class {
|
|
|
479
514
|
// src/bff/handlers.ts
|
|
480
515
|
function publicUser(user) {
|
|
481
516
|
const { id, email, tenant } = user;
|
|
482
|
-
return {
|
|
517
|
+
return {
|
|
518
|
+
id,
|
|
519
|
+
email,
|
|
520
|
+
tenant,
|
|
521
|
+
organization: tenant,
|
|
522
|
+
timeZone: user.timeZone ?? null,
|
|
523
|
+
locale: user.locale ?? null
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
function preferencesInput(body) {
|
|
527
|
+
const read = (name) => {
|
|
528
|
+
const value = body[name];
|
|
529
|
+
if (value === null || value === "") return null;
|
|
530
|
+
if (typeof value !== "string" || value.length > 100)
|
|
531
|
+
throw new BffSessionError("request.invalid_body", 400);
|
|
532
|
+
return value;
|
|
533
|
+
};
|
|
534
|
+
if (!("timeZone" in body) || !("locale" in body))
|
|
535
|
+
throw new BffSessionError("request.invalid_body", 400);
|
|
536
|
+
return { timeZone: read("timeZone"), locale: read("locale") };
|
|
483
537
|
}
|
|
484
538
|
function publicSession(record) {
|
|
485
539
|
return { authenticated: true, user: publicUser(record.user), expiresAt: record.expiresAt };
|
|
@@ -571,6 +625,16 @@ function createBffSession(options) {
|
|
|
571
625
|
),
|
|
572
626
|
/** Body `{ tenantSlug }` (the deprecated `{ organizationSlug }` is still read). */
|
|
573
627
|
switchTenant,
|
|
628
|
+
/**
|
|
629
|
+
* Body `{ timeZone, locale }`, both required (`null` clears). Saves them
|
|
630
|
+
* and rotates the session so the token carries them at once.
|
|
631
|
+
*/
|
|
632
|
+
updatePreferences: handler("PUT", async (request) => {
|
|
633
|
+
const input = preferencesInput(await readBffBody(request));
|
|
634
|
+
return http.response(
|
|
635
|
+
publicSession(await manager.updatePreferences(requiredSessionId(request), input))
|
|
636
|
+
);
|
|
637
|
+
}),
|
|
574
638
|
/** @deprecated Mount `switchTenant`; this is the same handler. */
|
|
575
639
|
switchOrganization: switchTenant,
|
|
576
640
|
logout: handler("POST", async (request) => {
|
|
@@ -641,7 +705,9 @@ function readProfile(value) {
|
|
|
641
705
|
return {
|
|
642
706
|
id: requiredString(user.id),
|
|
643
707
|
email: requiredString(user.email),
|
|
644
|
-
tenant: tenant ? { id: requiredString(tenant.id), slug: requiredString(tenant.slug) } : null
|
|
708
|
+
tenant: tenant ? { id: requiredString(tenant.id), slug: requiredString(tenant.slug) } : null,
|
|
709
|
+
timeZone: typeof user.timeZone === "string" ? user.timeZone : null,
|
|
710
|
+
locale: typeof user.locale === "string" ? user.locale : null
|
|
645
711
|
};
|
|
646
712
|
}
|
|
647
713
|
function createAuthyonBffProvider(options) {
|
|
@@ -704,6 +770,13 @@ function createAuthyonBffProvider(options) {
|
|
|
704
770
|
})
|
|
705
771
|
);
|
|
706
772
|
},
|
|
773
|
+
async updatePreferences(accessToken, input) {
|
|
774
|
+
await http.request("/auth/me/preferences", {
|
|
775
|
+
method: "PUT",
|
|
776
|
+
headers: bearer(accessToken),
|
|
777
|
+
body: { timeZone: input.timeZone, locale: input.locale }
|
|
778
|
+
});
|
|
779
|
+
},
|
|
707
780
|
async validate(accessToken) {
|
|
708
781
|
try {
|
|
709
782
|
const result = await options.validator.validate(accessToken);
|
|
@@ -26,7 +26,11 @@ var ErrorCodes = {
|
|
|
26
26
|
CredentialThrottled: "credential_throttled",
|
|
27
27
|
ApprovalNotFound: "authorization_not_found",
|
|
28
28
|
SessionRevoked: "session_revoked",
|
|
29
|
-
TwoFactorTooManyFailures: "user.2fa.too_many_failures"
|
|
29
|
+
TwoFactorTooManyFailures: "user.2fa.too_many_failures",
|
|
30
|
+
/** Not an IANA time zone the API knows. See `TimeZones`. */
|
|
31
|
+
PreferencesTimeZoneInvalid: "preferences.time_zone.invalid",
|
|
32
|
+
/** Not a well-formed BCP 47 tag. See `Locales`. */
|
|
33
|
+
PreferencesLocaleInvalid: "preferences.locale.invalid"
|
|
30
34
|
};
|
|
31
35
|
var STANDARD_ERROR_FIELDS = /* @__PURE__ */ new Set([
|
|
32
36
|
"type",
|