@auth-gate/core 0.15.1 → 0.15.2
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/index.cjs +23 -4
- package/dist/index.d.cts +26 -2
- package/dist/index.d.ts +26 -2
- package/dist/index.mjs +23 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -731,11 +731,27 @@ var AuthGateClient = class {
|
|
|
731
731
|
* given, so callers must store the `refresh_token` it returns or their next
|
|
732
732
|
* refresh fails.
|
|
733
733
|
*
|
|
734
|
+
* Returns `null` for any failure. To end a session, use
|
|
735
|
+
* {@link attemptRefresh}, which separates a rejected token from a temporary
|
|
736
|
+
* failure.
|
|
737
|
+
*
|
|
734
738
|
* @param refreshToken - The opaque refresh token.
|
|
735
739
|
* @returns A new JWT, its `expires_in` (seconds) and the rotated
|
|
736
|
-
* `refresh_token`, or `null` if the refresh
|
|
740
|
+
* `refresh_token`, or `null` if the refresh failed.
|
|
737
741
|
*/
|
|
738
742
|
async refreshToken(refreshToken) {
|
|
743
|
+
const outcome = await this.attemptRefresh(refreshToken);
|
|
744
|
+
return outcome.status === "refreshed" ? outcome : null;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Exchange a refresh token for a new JWT and report why it failed, if it did.
|
|
748
|
+
*
|
|
749
|
+
* @param refreshToken - The opaque refresh token.
|
|
750
|
+
* @returns `refreshed` with the new tokens, `rejected` when the server refused
|
|
751
|
+
* the token, or `unavailable` when it gave no verdict (408, 429, 5xx, network
|
|
752
|
+
* error). Only `rejected` should end a session.
|
|
753
|
+
*/
|
|
754
|
+
async attemptRefresh(refreshToken) {
|
|
739
755
|
try {
|
|
740
756
|
const response = await fetch(`${this.config.baseUrl}/api/proxy/token/refresh`, {
|
|
741
757
|
method: "POST",
|
|
@@ -745,10 +761,13 @@ var AuthGateClient = class {
|
|
|
745
761
|
},
|
|
746
762
|
body: JSON.stringify({ refresh_token: refreshToken })
|
|
747
763
|
});
|
|
748
|
-
if (
|
|
749
|
-
|
|
764
|
+
if (response.ok) return {
|
|
765
|
+
status: "refreshed",
|
|
766
|
+
...await response.json()
|
|
767
|
+
};
|
|
768
|
+
return { status: response.status === 408 || response.status === 429 || response.status >= 500 ? "unavailable" : "rejected" };
|
|
750
769
|
} catch {
|
|
751
|
-
return
|
|
770
|
+
return { status: "unavailable" };
|
|
752
771
|
}
|
|
753
772
|
}
|
|
754
773
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -158,6 +158,17 @@ interface BackupCodesResponse {
|
|
|
158
158
|
}
|
|
159
159
|
//#endregion
|
|
160
160
|
//#region src/client.d.ts
|
|
161
|
+
/** The result of {@link AuthGateClient.attemptRefresh}. */
|
|
162
|
+
type TokenRefreshOutcome = {
|
|
163
|
+
status: "refreshed";
|
|
164
|
+
token: string;
|
|
165
|
+
refresh_token?: string;
|
|
166
|
+
expires_in: number;
|
|
167
|
+
} | {
|
|
168
|
+
status: "rejected";
|
|
169
|
+
} | {
|
|
170
|
+
status: "unavailable";
|
|
171
|
+
};
|
|
161
172
|
/**
|
|
162
173
|
* Core client for interacting with the AuthGate authentication proxy.
|
|
163
174
|
*
|
|
@@ -364,15 +375,28 @@ declare class AuthGateClient {
|
|
|
364
375
|
* given, so callers must store the `refresh_token` it returns or their next
|
|
365
376
|
* refresh fails.
|
|
366
377
|
*
|
|
378
|
+
* Returns `null` for any failure. To end a session, use
|
|
379
|
+
* {@link attemptRefresh}, which separates a rejected token from a temporary
|
|
380
|
+
* failure.
|
|
381
|
+
*
|
|
367
382
|
* @param refreshToken - The opaque refresh token.
|
|
368
383
|
* @returns A new JWT, its `expires_in` (seconds) and the rotated
|
|
369
|
-
* `refresh_token`, or `null` if the refresh
|
|
384
|
+
* `refresh_token`, or `null` if the refresh failed.
|
|
370
385
|
*/
|
|
371
386
|
refreshToken(refreshToken: string): Promise<{
|
|
372
387
|
token: string;
|
|
373
388
|
refresh_token?: string;
|
|
374
389
|
expires_in: number;
|
|
375
390
|
} | null>;
|
|
391
|
+
/**
|
|
392
|
+
* Exchange a refresh token for a new JWT and report why it failed, if it did.
|
|
393
|
+
*
|
|
394
|
+
* @param refreshToken - The opaque refresh token.
|
|
395
|
+
* @returns `refreshed` with the new tokens, `rejected` when the server refused
|
|
396
|
+
* the token, or `unavailable` when it gave no verdict (408, 429, 5xx, network
|
|
397
|
+
* error). Only `rejected` should end a session.
|
|
398
|
+
*/
|
|
399
|
+
attemptRefresh(refreshToken: string): Promise<TokenRefreshOutcome>;
|
|
376
400
|
/**
|
|
377
401
|
* Exchange a single-use authorization code (delivered on the callback URL)
|
|
378
402
|
* for the JWT + refresh token. Codes are one-shot and expire after ~60s.
|
|
@@ -1037,4 +1061,4 @@ declare function mergePermissions(projectRole: UserRoleAssignment | null | undef
|
|
|
1037
1061
|
*/
|
|
1038
1062
|
declare function hasMergedPermission(projectRole: UserRoleAssignment | null | undefined, orgMembership: OrgMembership | null | undefined, permission: string): boolean;
|
|
1039
1063
|
//#endregion
|
|
1040
|
-
export { AuthGateClient, type AuthGateConfig, type AuthGateConnection, AuthGateError, type AuthGateProjectConfig, type AuthGateUser, type BackupCodesResponse, type BillingEntitlement, type BillingEntitlementV2, type BillingPlan, type BillingPrice, type BillingSubscription, type BillingSubscriptionItem, type BooleanEntitlementDetail, ConfigurationError, type CookieOptions, DEFAULT_COOKIE_NAME, type EntitlementDetail, InvalidStateError, type MeteredEntitlementDetail, type MfaChallengeResponse, type MfaStatus, NONCE_COOKIE_NAME, type OAuthProvider, type OrgInvitation, type OrgMember, type OrgMembership, type OrgRole, type OrgWithMembership, type Organization, REFRESH_TOKEN_COOKIE_NAME, SESSION_MAX_AGE, STATE_TTL_MS, SUPPORTED_PROVIDERS, SessionDecryptionError, type SessionPayload, TokenVerificationError, type TokenVerifyResult, type TotpSetupResponse, type UsageEvent, type UserRoleAssignment, checkFeature, createAuthGateClient, defineConfig, hasAllPermissions, hasAnyPermission, hasFeature, hasMergedPermission, hasPermission, hasPlan, hasRole, mergePermissions };
|
|
1064
|
+
export { AuthGateClient, type AuthGateConfig, type AuthGateConnection, AuthGateError, type AuthGateProjectConfig, type AuthGateUser, type BackupCodesResponse, type BillingEntitlement, type BillingEntitlementV2, type BillingPlan, type BillingPrice, type BillingSubscription, type BillingSubscriptionItem, type BooleanEntitlementDetail, ConfigurationError, type CookieOptions, DEFAULT_COOKIE_NAME, type EntitlementDetail, InvalidStateError, type MeteredEntitlementDetail, type MfaChallengeResponse, type MfaStatus, NONCE_COOKIE_NAME, type OAuthProvider, type OrgInvitation, type OrgMember, type OrgMembership, type OrgRole, type OrgWithMembership, type Organization, REFRESH_TOKEN_COOKIE_NAME, SESSION_MAX_AGE, STATE_TTL_MS, SUPPORTED_PROVIDERS, SessionDecryptionError, type SessionPayload, type TokenRefreshOutcome, TokenVerificationError, type TokenVerifyResult, type TotpSetupResponse, type UsageEvent, type UserRoleAssignment, checkFeature, createAuthGateClient, defineConfig, hasAllPermissions, hasAnyPermission, hasFeature, hasMergedPermission, hasPermission, hasPlan, hasRole, mergePermissions };
|
package/dist/index.d.ts
CHANGED
|
@@ -158,6 +158,17 @@ interface BackupCodesResponse {
|
|
|
158
158
|
}
|
|
159
159
|
//#endregion
|
|
160
160
|
//#region src/client.d.ts
|
|
161
|
+
/** The result of {@link AuthGateClient.attemptRefresh}. */
|
|
162
|
+
type TokenRefreshOutcome = {
|
|
163
|
+
status: "refreshed";
|
|
164
|
+
token: string;
|
|
165
|
+
refresh_token?: string;
|
|
166
|
+
expires_in: number;
|
|
167
|
+
} | {
|
|
168
|
+
status: "rejected";
|
|
169
|
+
} | {
|
|
170
|
+
status: "unavailable";
|
|
171
|
+
};
|
|
161
172
|
/**
|
|
162
173
|
* Core client for interacting with the AuthGate authentication proxy.
|
|
163
174
|
*
|
|
@@ -364,15 +375,28 @@ declare class AuthGateClient {
|
|
|
364
375
|
* given, so callers must store the `refresh_token` it returns or their next
|
|
365
376
|
* refresh fails.
|
|
366
377
|
*
|
|
378
|
+
* Returns `null` for any failure. To end a session, use
|
|
379
|
+
* {@link attemptRefresh}, which separates a rejected token from a temporary
|
|
380
|
+
* failure.
|
|
381
|
+
*
|
|
367
382
|
* @param refreshToken - The opaque refresh token.
|
|
368
383
|
* @returns A new JWT, its `expires_in` (seconds) and the rotated
|
|
369
|
-
* `refresh_token`, or `null` if the refresh
|
|
384
|
+
* `refresh_token`, or `null` if the refresh failed.
|
|
370
385
|
*/
|
|
371
386
|
refreshToken(refreshToken: string): Promise<{
|
|
372
387
|
token: string;
|
|
373
388
|
refresh_token?: string;
|
|
374
389
|
expires_in: number;
|
|
375
390
|
} | null>;
|
|
391
|
+
/**
|
|
392
|
+
* Exchange a refresh token for a new JWT and report why it failed, if it did.
|
|
393
|
+
*
|
|
394
|
+
* @param refreshToken - The opaque refresh token.
|
|
395
|
+
* @returns `refreshed` with the new tokens, `rejected` when the server refused
|
|
396
|
+
* the token, or `unavailable` when it gave no verdict (408, 429, 5xx, network
|
|
397
|
+
* error). Only `rejected` should end a session.
|
|
398
|
+
*/
|
|
399
|
+
attemptRefresh(refreshToken: string): Promise<TokenRefreshOutcome>;
|
|
376
400
|
/**
|
|
377
401
|
* Exchange a single-use authorization code (delivered on the callback URL)
|
|
378
402
|
* for the JWT + refresh token. Codes are one-shot and expire after ~60s.
|
|
@@ -1037,4 +1061,4 @@ declare function mergePermissions(projectRole: UserRoleAssignment | null | undef
|
|
|
1037
1061
|
*/
|
|
1038
1062
|
declare function hasMergedPermission(projectRole: UserRoleAssignment | null | undefined, orgMembership: OrgMembership | null | undefined, permission: string): boolean;
|
|
1039
1063
|
//#endregion
|
|
1040
|
-
export { AuthGateClient, type AuthGateConfig, type AuthGateConnection, AuthGateError, type AuthGateProjectConfig, type AuthGateUser, type BackupCodesResponse, type BillingEntitlement, type BillingEntitlementV2, type BillingPlan, type BillingPrice, type BillingSubscription, type BillingSubscriptionItem, type BooleanEntitlementDetail, ConfigurationError, type CookieOptions, DEFAULT_COOKIE_NAME, type EntitlementDetail, InvalidStateError, type MeteredEntitlementDetail, type MfaChallengeResponse, type MfaStatus, NONCE_COOKIE_NAME, type OAuthProvider, type OrgInvitation, type OrgMember, type OrgMembership, type OrgRole, type OrgWithMembership, type Organization, REFRESH_TOKEN_COOKIE_NAME, SESSION_MAX_AGE, STATE_TTL_MS, SUPPORTED_PROVIDERS, SessionDecryptionError, type SessionPayload, TokenVerificationError, type TokenVerifyResult, type TotpSetupResponse, type UsageEvent, type UserRoleAssignment, checkFeature, createAuthGateClient, defineConfig, hasAllPermissions, hasAnyPermission, hasFeature, hasMergedPermission, hasPermission, hasPlan, hasRole, mergePermissions };
|
|
1064
|
+
export { AuthGateClient, type AuthGateConfig, type AuthGateConnection, AuthGateError, type AuthGateProjectConfig, type AuthGateUser, type BackupCodesResponse, type BillingEntitlement, type BillingEntitlementV2, type BillingPlan, type BillingPrice, type BillingSubscription, type BillingSubscriptionItem, type BooleanEntitlementDetail, ConfigurationError, type CookieOptions, DEFAULT_COOKIE_NAME, type EntitlementDetail, InvalidStateError, type MeteredEntitlementDetail, type MfaChallengeResponse, type MfaStatus, NONCE_COOKIE_NAME, type OAuthProvider, type OrgInvitation, type OrgMember, type OrgMembership, type OrgRole, type OrgWithMembership, type Organization, REFRESH_TOKEN_COOKIE_NAME, SESSION_MAX_AGE, STATE_TTL_MS, SUPPORTED_PROVIDERS, SessionDecryptionError, type SessionPayload, type TokenRefreshOutcome, TokenVerificationError, type TokenVerifyResult, type TotpSetupResponse, type UsageEvent, type UserRoleAssignment, checkFeature, createAuthGateClient, defineConfig, hasAllPermissions, hasAnyPermission, hasFeature, hasMergedPermission, hasPermission, hasPlan, hasRole, mergePermissions };
|
package/dist/index.mjs
CHANGED
|
@@ -730,11 +730,27 @@ var AuthGateClient = class {
|
|
|
730
730
|
* given, so callers must store the `refresh_token` it returns or their next
|
|
731
731
|
* refresh fails.
|
|
732
732
|
*
|
|
733
|
+
* Returns `null` for any failure. To end a session, use
|
|
734
|
+
* {@link attemptRefresh}, which separates a rejected token from a temporary
|
|
735
|
+
* failure.
|
|
736
|
+
*
|
|
733
737
|
* @param refreshToken - The opaque refresh token.
|
|
734
738
|
* @returns A new JWT, its `expires_in` (seconds) and the rotated
|
|
735
|
-
* `refresh_token`, or `null` if the refresh
|
|
739
|
+
* `refresh_token`, or `null` if the refresh failed.
|
|
736
740
|
*/
|
|
737
741
|
async refreshToken(refreshToken) {
|
|
742
|
+
const outcome = await this.attemptRefresh(refreshToken);
|
|
743
|
+
return outcome.status === "refreshed" ? outcome : null;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Exchange a refresh token for a new JWT and report why it failed, if it did.
|
|
747
|
+
*
|
|
748
|
+
* @param refreshToken - The opaque refresh token.
|
|
749
|
+
* @returns `refreshed` with the new tokens, `rejected` when the server refused
|
|
750
|
+
* the token, or `unavailable` when it gave no verdict (408, 429, 5xx, network
|
|
751
|
+
* error). Only `rejected` should end a session.
|
|
752
|
+
*/
|
|
753
|
+
async attemptRefresh(refreshToken) {
|
|
738
754
|
try {
|
|
739
755
|
const response = await fetch(`${this.config.baseUrl}/api/proxy/token/refresh`, {
|
|
740
756
|
method: "POST",
|
|
@@ -744,10 +760,13 @@ var AuthGateClient = class {
|
|
|
744
760
|
},
|
|
745
761
|
body: JSON.stringify({ refresh_token: refreshToken })
|
|
746
762
|
});
|
|
747
|
-
if (
|
|
748
|
-
|
|
763
|
+
if (response.ok) return {
|
|
764
|
+
status: "refreshed",
|
|
765
|
+
...await response.json()
|
|
766
|
+
};
|
|
767
|
+
return { status: response.status === 408 || response.status === 429 || response.status >= 500 ? "unavailable" : "rejected" };
|
|
749
768
|
} catch {
|
|
750
|
-
return
|
|
769
|
+
return { status: "unavailable" };
|
|
751
770
|
}
|
|
752
771
|
}
|
|
753
772
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth-gate/core",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "Core client library for AuthGate — the OAuth proxy that handles provider configuration, token exchange, and user normalization so you don't have to.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|