@bagelink/auth 1.12.27 → 1.12.31
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/api.d.ts +9 -1
- package/dist/index.cjs +23 -2
- package/dist/index.mjs +23 -2
- package/dist/useAuth.d.ts +1 -0
- package/package.json +1 -1
- package/src/api.ts +23 -1
- package/src/useAuth.ts +3 -0
package/dist/api.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
1
2
|
import { RegisterRequest, UpdateAccountRequest, ChangePasswordRequest, ForgotPasswordRequest, ResetPasswordRequest, SendVerificationRequest, VerifyEmailRequest, AuthenticationAccount, PasswordLoginRequest, EmailTokenSendRequest, EmailTokenVerifyRequest, OTPSendRequest, OTPVerifyRequest, SMSSendRequest, SMSVerifyRequest, GenerateTokenRequest, RedeemTokenRequest, SSOLoginRequest, LoginResponse, RegisterResponse, LogoutResponse, GetMeResponse, UpdateMeResponse, DeleteMeResponse, ChangePasswordResponse, ForgotPasswordResponse, ResetPasswordResponse, VerifyResetTokenResponse, SendVerificationResponse, VerifyEmailResponse, RefreshSessionResponse, GetSessionsResponse, DeleteSessionResponse, DeleteAllSessionsResponse, CleanupSessionsResponse, GetMethodsResponse, GetAuthStatusResponse, SendEmailTokenResponse, VerifyEmailTokenResponse, SendOTPResponse, VerifyOTPResponse, SendSMSResponse, VerifySMSResponse, GenerateLoginTokenResponse, RedeemLoginTokenResponse, LegacySSOLoginResponse, SSOProvider, SSOInitiateRequest, SSOCallbackRequest, SSOLinkRequest, InitiateSSOResponse, CallbackSSOResponse, LinkSSOResponse, UnlinkSSOResponse, GetTenantsResponse, GetTenantResponse, CreateTenantResponse, UpdateTenantResponse, DeleteTenantResponse, GetTenantMembersResponse, AddTenantMemberResponse, UpdateTenantMemberResponse, DeleteTenantMemberResponse, GetTenantRolesResponse, CreateInvitationResponse, GetInvitationResponse, AcceptInvitationResponse, CreateTenantRequest, UpdateTenantRequest, AddMemberRequest, UpdateMemberRequest, CreateInvitationRequest, AcceptInvitationRequest } from './types';
|
|
2
3
|
export declare class AuthApi {
|
|
3
4
|
private api;
|
|
4
5
|
private currentTenantId;
|
|
6
|
+
private externalAxiosInstances;
|
|
5
7
|
constructor(baseURL?: string);
|
|
6
8
|
/**
|
|
7
|
-
*
|
|
9
|
+
* Register an external axios instance so that tenant headers
|
|
10
|
+
* are automatically applied to it when setTenantId() is called.
|
|
11
|
+
*/
|
|
12
|
+
registerAxios(instance: AxiosInstance): void;
|
|
13
|
+
/**
|
|
14
|
+
* Set the current tenant ID for multi-tenant requests.
|
|
15
|
+
* Also updates the header on any externally registered axios instances.
|
|
8
16
|
*/
|
|
9
17
|
setTenantId(tenantId: string | null): void;
|
|
10
18
|
/**
|
package/dist/index.cjs
CHANGED
|
@@ -64,14 +64,33 @@ class AuthApi {
|
|
|
64
64
|
constructor(baseURL = "") {
|
|
65
65
|
__publicField(this, "api");
|
|
66
66
|
__publicField(this, "currentTenantId", null);
|
|
67
|
+
__publicField(this, "externalAxiosInstances", /* @__PURE__ */ new Set());
|
|
67
68
|
this.api = createAxiosInstance(baseURL);
|
|
68
69
|
this.setupInterceptors();
|
|
69
70
|
}
|
|
70
71
|
/**
|
|
71
|
-
*
|
|
72
|
+
* Register an external axios instance so that tenant headers
|
|
73
|
+
* are automatically applied to it when setTenantId() is called.
|
|
74
|
+
*/
|
|
75
|
+
registerAxios(instance) {
|
|
76
|
+
this.externalAxiosInstances.add(instance);
|
|
77
|
+
if (this.currentTenantId !== null) {
|
|
78
|
+
instance.defaults.headers.common["X-Tenant-ID"] = this.currentTenantId;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Set the current tenant ID for multi-tenant requests.
|
|
83
|
+
* Also updates the header on any externally registered axios instances.
|
|
72
84
|
*/
|
|
73
85
|
setTenantId(tenantId) {
|
|
74
86
|
this.currentTenantId = tenantId;
|
|
87
|
+
for (const instance of this.externalAxiosInstances) {
|
|
88
|
+
if (tenantId !== null) {
|
|
89
|
+
instance.defaults.headers.common["X-Tenant-ID"] = tenantId;
|
|
90
|
+
} else {
|
|
91
|
+
delete instance.defaults.headers.common["X-Tenant-ID"];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
75
94
|
}
|
|
76
95
|
/**
|
|
77
96
|
* Get the current tenant ID
|
|
@@ -1507,7 +1526,9 @@ function useAuth() {
|
|
|
1507
1526
|
// Invitations
|
|
1508
1527
|
createInvitation,
|
|
1509
1528
|
getInvitation,
|
|
1510
|
-
acceptInvitation
|
|
1529
|
+
acceptInvitation,
|
|
1530
|
+
// Axios integration
|
|
1531
|
+
registerAxios: (instance) => api.registerAxios(instance)
|
|
1511
1532
|
};
|
|
1512
1533
|
}
|
|
1513
1534
|
const useAuth$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
package/dist/index.mjs
CHANGED
|
@@ -62,14 +62,33 @@ class AuthApi {
|
|
|
62
62
|
constructor(baseURL = "") {
|
|
63
63
|
__publicField(this, "api");
|
|
64
64
|
__publicField(this, "currentTenantId", null);
|
|
65
|
+
__publicField(this, "externalAxiosInstances", /* @__PURE__ */ new Set());
|
|
65
66
|
this.api = createAxiosInstance(baseURL);
|
|
66
67
|
this.setupInterceptors();
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
|
-
*
|
|
70
|
+
* Register an external axios instance so that tenant headers
|
|
71
|
+
* are automatically applied to it when setTenantId() is called.
|
|
72
|
+
*/
|
|
73
|
+
registerAxios(instance) {
|
|
74
|
+
this.externalAxiosInstances.add(instance);
|
|
75
|
+
if (this.currentTenantId !== null) {
|
|
76
|
+
instance.defaults.headers.common["X-Tenant-ID"] = this.currentTenantId;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Set the current tenant ID for multi-tenant requests.
|
|
81
|
+
* Also updates the header on any externally registered axios instances.
|
|
70
82
|
*/
|
|
71
83
|
setTenantId(tenantId) {
|
|
72
84
|
this.currentTenantId = tenantId;
|
|
85
|
+
for (const instance of this.externalAxiosInstances) {
|
|
86
|
+
if (tenantId !== null) {
|
|
87
|
+
instance.defaults.headers.common["X-Tenant-ID"] = tenantId;
|
|
88
|
+
} else {
|
|
89
|
+
delete instance.defaults.headers.common["X-Tenant-ID"];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
73
92
|
}
|
|
74
93
|
/**
|
|
75
94
|
* Get the current tenant ID
|
|
@@ -1505,7 +1524,9 @@ function useAuth() {
|
|
|
1505
1524
|
// Invitations
|
|
1506
1525
|
createInvitation,
|
|
1507
1526
|
getInvitation,
|
|
1508
|
-
acceptInvitation
|
|
1527
|
+
acceptInvitation,
|
|
1528
|
+
// Axios integration
|
|
1529
|
+
registerAxios: (instance) => api.registerAxios(instance)
|
|
1509
1530
|
};
|
|
1510
1531
|
}
|
|
1511
1532
|
const useAuth$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
package/dist/useAuth.d.ts
CHANGED
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -79,6 +79,7 @@ import { createAxiosInstance } from './utils'
|
|
|
79
79
|
export class AuthApi {
|
|
80
80
|
private api: AxiosInstance
|
|
81
81
|
private currentTenantId: string | null = null
|
|
82
|
+
private externalAxiosInstances: Set<AxiosInstance> = new Set()
|
|
82
83
|
|
|
83
84
|
constructor(baseURL: string = '') {
|
|
84
85
|
this.api = createAxiosInstance(baseURL)
|
|
@@ -86,10 +87,31 @@ export class AuthApi {
|
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
/**
|
|
89
|
-
*
|
|
90
|
+
* Register an external axios instance so that tenant headers
|
|
91
|
+
* are automatically applied to it when setTenantId() is called.
|
|
92
|
+
*/
|
|
93
|
+
registerAxios(instance: AxiosInstance) {
|
|
94
|
+
this.externalAxiosInstances.add(instance)
|
|
95
|
+
// Apply current tenant immediately if already set
|
|
96
|
+
if (this.currentTenantId !== null) {
|
|
97
|
+
instance.defaults.headers.common['X-Tenant-ID'] = this.currentTenantId
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Set the current tenant ID for multi-tenant requests.
|
|
103
|
+
* Also updates the header on any externally registered axios instances.
|
|
90
104
|
*/
|
|
91
105
|
setTenantId(tenantId: string | null) {
|
|
92
106
|
this.currentTenantId = tenantId
|
|
107
|
+
// Update all registered external axios instances
|
|
108
|
+
for (const instance of this.externalAxiosInstances) {
|
|
109
|
+
if (tenantId !== null) {
|
|
110
|
+
instance.defaults.headers.common['X-Tenant-ID'] = tenantId
|
|
111
|
+
} else {
|
|
112
|
+
delete instance.defaults.headers.common['X-Tenant-ID']
|
|
113
|
+
}
|
|
114
|
+
}
|
|
93
115
|
}
|
|
94
116
|
|
|
95
117
|
/**
|