binoauth 0.0.1

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.
@@ -0,0 +1,51 @@
1
+ export interface BinoAuthConfig {
2
+ apiKey: string;
3
+ tenant: string;
4
+ baseUrl?: string;
5
+ }
6
+ export interface LoginCredentials {
7
+ email?: string;
8
+ password?: string;
9
+ otp?: string;
10
+ phone?: string;
11
+ }
12
+ export interface BinoAuthResponse<T = any> {
13
+ ok: boolean;
14
+ data?: T;
15
+ error?: string;
16
+ error_description?: string;
17
+ }
18
+ export declare class BinoAuth {
19
+ private tenantConfig;
20
+ private adminConfig;
21
+ private authApi;
22
+ private oauthApi;
23
+ private userProfileApi;
24
+ private adminApi;
25
+ constructor(config: BinoAuthConfig);
26
+ sendEmailOTP(email: string): Promise<BinoAuthResponse>;
27
+ sendPhoneOTP(phone: string): Promise<BinoAuthResponse>;
28
+ sendMagicLink(email: string): Promise<BinoAuthResponse>;
29
+ login(type: 'password' | 'otp', credentials: LoginCredentials): Promise<BinoAuthResponse>;
30
+ sendResetPasswordEmailOTP(email: string): Promise<BinoAuthResponse>;
31
+ sendResetPasswordPhoneOTP(phone: string): Promise<BinoAuthResponse>;
32
+ resetPassword(params: {
33
+ otp: string;
34
+ newPassword: string;
35
+ repeatNewPassword: string;
36
+ }): Promise<BinoAuthResponse>;
37
+ refreshToken(refreshToken: string): Promise<BinoAuthResponse>;
38
+ logout(accessToken?: string): Promise<BinoAuthResponse>;
39
+ getProfile(): Promise<BinoAuthResponse>;
40
+ requestDeviceCode(): Promise<BinoAuthResponse>;
41
+ pollDeviceToken(deviceCode: string): Promise<BinoAuthResponse>;
42
+ createUser(userData: any): Promise<BinoAuthResponse>;
43
+ getUser(userId: string): Promise<BinoAuthResponse>;
44
+ getUsers(params?: {
45
+ page?: number;
46
+ limit?: number;
47
+ }): Promise<BinoAuthResponse>;
48
+ updateUser(userId: string, userData: any): Promise<BinoAuthResponse>;
49
+ deleteUser(userId: string): Promise<BinoAuthResponse>;
50
+ }
51
+ export default BinoAuth;
package/dist/index.js ADDED
@@ -0,0 +1,347 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BinoAuth = void 0;
4
+ const tenant_sdk_1 = require("@binoauth/tenant-sdk");
5
+ const admin_sdk_1 = require("@binoauth/admin-sdk");
6
+ class BinoAuth {
7
+ constructor(config) {
8
+ const baseUrl = config.baseUrl || 'https://api.binoauth.com';
9
+ // Configure tenant SDK
10
+ this.tenantConfig = new tenant_sdk_1.Configuration({
11
+ basePath: baseUrl,
12
+ headers: {
13
+ 'X-API-Key': config.apiKey,
14
+ 'X-Tenant-ID': config.tenant
15
+ }
16
+ });
17
+ // Configure admin SDK
18
+ this.adminConfig = new admin_sdk_1.Configuration({
19
+ basePath: baseUrl,
20
+ headers: {
21
+ 'X-API-Key': config.apiKey,
22
+ 'X-Tenant-ID': config.tenant
23
+ }
24
+ });
25
+ // Initialize APIs
26
+ this.authApi = new tenant_sdk_1.AuthenticationApi(this.tenantConfig);
27
+ this.oauthApi = new tenant_sdk_1.OAuth2Api(this.tenantConfig);
28
+ this.userProfileApi = new tenant_sdk_1.UserProfileApi(this.tenantConfig);
29
+ this.adminApi = new admin_sdk_1.AdminApi(this.adminConfig);
30
+ }
31
+ // Authentication Methods
32
+ async sendEmailOTP(email) {
33
+ try {
34
+ const response = await this.authApi.requestMagicLinkApiV1AuthMlPost({
35
+ magicLinkRequest: { email }
36
+ });
37
+ return { ok: true, data: response };
38
+ }
39
+ catch (error) {
40
+ return {
41
+ ok: false,
42
+ error: error.message || 'Failed to send email OTP',
43
+ error_description: error.response?.data?.detail || error.message
44
+ };
45
+ }
46
+ }
47
+ async sendPhoneOTP(phone) {
48
+ try {
49
+ const response = await this.authApi.requestOtpViaPhoneApiV1AuthPhonePost({
50
+ phoneOTPRequest: { phone }
51
+ });
52
+ return { ok: true, data: response };
53
+ }
54
+ catch (error) {
55
+ return {
56
+ ok: false,
57
+ error: error.message || 'Failed to send phone OTP',
58
+ error_description: error.response?.data?.detail || error.message
59
+ };
60
+ }
61
+ }
62
+ async sendMagicLink(email) {
63
+ try {
64
+ const response = await this.authApi.requestMagicLinkApiV1AuthMlPost({
65
+ magicLinkRequest: { email }
66
+ });
67
+ return { ok: true, data: response };
68
+ }
69
+ catch (error) {
70
+ return {
71
+ ok: false,
72
+ error: error.message || 'Failed to send magic link',
73
+ error_description: error.response?.data?.detail || error.message
74
+ };
75
+ }
76
+ }
77
+ async login(type, credentials) {
78
+ try {
79
+ let response;
80
+ if (type === 'password') {
81
+ if (!credentials.email || !credentials.password) {
82
+ return {
83
+ ok: false,
84
+ error: 'Missing credentials',
85
+ error_description: 'Email and password are required for password login'
86
+ };
87
+ }
88
+ response = await this.authApi.loginApiV1AuthLoginPost({
89
+ loginRequest: {
90
+ email: credentials.email,
91
+ password: credentials.password
92
+ }
93
+ });
94
+ }
95
+ else if (type === 'otp') {
96
+ if (!credentials.otp) {
97
+ return {
98
+ ok: false,
99
+ error: 'Missing OTP',
100
+ error_description: 'OTP code is required for OTP login'
101
+ };
102
+ }
103
+ // For OTP login, we need to verify the OTP
104
+ if (credentials.phone) {
105
+ response = await this.authApi.verifyPhoneOtpApiV1AuthPhoneVerifyPost({
106
+ phoneOTPVerificationRequest: {
107
+ otp: credentials.otp.toString()
108
+ }
109
+ });
110
+ }
111
+ else {
112
+ response = await this.authApi.verifyMagicLinkCodeApiV1AuthMlCodeVerifyPost({
113
+ verifyMagicLinkCodeRequest: {
114
+ code: credentials.otp.toString()
115
+ }
116
+ });
117
+ }
118
+ }
119
+ return { ok: true, data: response };
120
+ }
121
+ catch (error) {
122
+ return {
123
+ ok: false,
124
+ error: error.message || 'Login failed',
125
+ error_description: error.response?.data?.detail || error.message
126
+ };
127
+ }
128
+ }
129
+ // Password Reset
130
+ async sendResetPasswordEmailOTP(email) {
131
+ try {
132
+ const response = await this.authApi.requestMagicLinkApiV1AuthMlPost({
133
+ magicLinkRequest: { email }
134
+ });
135
+ return { ok: true, data: response };
136
+ }
137
+ catch (error) {
138
+ return {
139
+ ok: false,
140
+ error: error.message || 'Failed to send reset password email',
141
+ error_description: error.response?.data?.detail || error.message
142
+ };
143
+ }
144
+ }
145
+ async sendResetPasswordPhoneOTP(phone) {
146
+ try {
147
+ const response = await this.authApi.requestOtpViaPhoneApiV1AuthPhonePost({
148
+ phoneOTPRequest: { phone }
149
+ });
150
+ return { ok: true, data: response };
151
+ }
152
+ catch (error) {
153
+ return {
154
+ ok: false,
155
+ error: error.message || 'Failed to send reset password phone OTP',
156
+ error_description: error.response?.data?.detail || error.message
157
+ };
158
+ }
159
+ }
160
+ async resetPassword(params) {
161
+ try {
162
+ if (params.newPassword !== params.repeatNewPassword) {
163
+ return {
164
+ ok: false,
165
+ error: 'Password mismatch',
166
+ error_description: 'New password and repeat password do not match'
167
+ };
168
+ }
169
+ // This would typically be handled by verifying the OTP first, then updating password
170
+ // For now, we'll verify the magic link code
171
+ const response = await this.authApi.verifyMagicLinkCodeApiV1AuthMlCodeVerifyPost({
172
+ verifyMagicLinkCodeRequest: {
173
+ code: params.otp
174
+ }
175
+ });
176
+ return { ok: true, data: response };
177
+ }
178
+ catch (error) {
179
+ return {
180
+ ok: false,
181
+ error: error.message || 'Failed to reset password',
182
+ error_description: error.response?.data?.detail || error.message
183
+ };
184
+ }
185
+ }
186
+ // Token Management
187
+ async refreshToken(refreshToken) {
188
+ try {
189
+ const response = await this.oauthApi.getTokensApiV1OauthTokenPost({
190
+ tokenRequest: {
191
+ grantType: 'refresh_token',
192
+ clientId: 'binoauth-sdk',
193
+ refreshToken: refreshToken
194
+ }
195
+ });
196
+ return { ok: true, data: response };
197
+ }
198
+ catch (error) {
199
+ return {
200
+ ok: false,
201
+ error: error.message || 'Failed to refresh token',
202
+ error_description: error.response?.data?.detail || error.message
203
+ };
204
+ }
205
+ }
206
+ async logout(accessToken) {
207
+ try {
208
+ const response = await this.authApi.logoutApiV1AuthLogoutPost({
209
+ sessionBinoauth: accessToken || ''
210
+ });
211
+ return { ok: true, data: response };
212
+ }
213
+ catch (error) {
214
+ return {
215
+ ok: false,
216
+ error: error.message || 'Failed to logout',
217
+ error_description: error.response?.data?.detail || error.message
218
+ };
219
+ }
220
+ }
221
+ // User Profile
222
+ async getProfile() {
223
+ try {
224
+ const response = await this.userProfileApi.getCurrentUserApiV1AuthUserinfoGet();
225
+ return { ok: true, data: response };
226
+ }
227
+ catch (error) {
228
+ return {
229
+ ok: false,
230
+ error: error.message || 'Failed to get profile',
231
+ error_description: error.response?.data?.detail || error.message
232
+ };
233
+ }
234
+ }
235
+ // Device Code Flow
236
+ async requestDeviceCode() {
237
+ try {
238
+ const response = await this.oauthApi.deviceAuthorizationApiV1OauthDeviceCodePost({
239
+ deviceAuthorizationRequest: {
240
+ clientId: 'binoauth-sdk'
241
+ }
242
+ });
243
+ return { ok: true, data: response };
244
+ }
245
+ catch (error) {
246
+ return {
247
+ ok: false,
248
+ error: error.message || 'Failed to request device code',
249
+ error_description: error.response?.data?.detail || error.message
250
+ };
251
+ }
252
+ }
253
+ async pollDeviceToken(deviceCode) {
254
+ try {
255
+ const response = await this.oauthApi.getTokensApiV1OauthTokenPost({
256
+ tokenRequest: {
257
+ grantType: 'urn:ietf:params:oauth:grant-type:device_code',
258
+ clientId: 'binoauth-sdk',
259
+ deviceCode: deviceCode
260
+ }
261
+ });
262
+ return { ok: true, data: response };
263
+ }
264
+ catch (error) {
265
+ return {
266
+ ok: false,
267
+ error: error.message || 'Failed to poll device token',
268
+ error_description: error.response?.data?.detail || error.message
269
+ };
270
+ }
271
+ }
272
+ // User Management (Admin API)
273
+ async createUser(userData) {
274
+ try {
275
+ // Admin API user creation method may not be available - this is a placeholder
276
+ throw new Error('User creation not implemented in admin SDK');
277
+ }
278
+ catch (error) {
279
+ return {
280
+ ok: false,
281
+ error: error.message || 'Failed to create user',
282
+ error_description: error.response?.data?.detail || error.message
283
+ };
284
+ }
285
+ }
286
+ async getUser(userId) {
287
+ try {
288
+ const response = await this.adminApi.getUserApiV1UsersUserIdGet({
289
+ userId,
290
+ xTenantId: ''
291
+ });
292
+ return { ok: true, data: response };
293
+ }
294
+ catch (error) {
295
+ return {
296
+ ok: false,
297
+ error: error.message || 'Failed to get user',
298
+ error_description: error.response?.data?.detail || error.message
299
+ };
300
+ }
301
+ }
302
+ async getUsers(params = {}) {
303
+ try {
304
+ const response = await this.adminApi.getUsersApiV1UsersGet({
305
+ page: params.page || 1,
306
+ limit: params.limit || 10,
307
+ xTenantId: ''
308
+ });
309
+ return { ok: true, data: response };
310
+ }
311
+ catch (error) {
312
+ return {
313
+ ok: false,
314
+ error: error.message || 'Failed to get users',
315
+ error_description: error.response?.data?.detail || error.message
316
+ };
317
+ }
318
+ }
319
+ async updateUser(userId, userData) {
320
+ try {
321
+ // Admin API user update method may not be available - this is a placeholder
322
+ throw new Error('User update not implemented in admin SDK');
323
+ }
324
+ catch (error) {
325
+ return {
326
+ ok: false,
327
+ error: error.message || 'Failed to update user',
328
+ error_description: error.response?.data?.detail || error.message
329
+ };
330
+ }
331
+ }
332
+ async deleteUser(userId) {
333
+ try {
334
+ // Admin API user delete method may not be available - this is a placeholder
335
+ throw new Error('User delete not implemented in admin SDK');
336
+ }
337
+ catch (error) {
338
+ return {
339
+ ok: false,
340
+ error: error.message || 'Failed to delete user',
341
+ error_description: error.response?.data?.detail || error.message
342
+ };
343
+ }
344
+ }
345
+ }
346
+ exports.BinoAuth = BinoAuth;
347
+ exports.default = BinoAuth;
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "binoauth",
3
+ "version": "0.0.1",
4
+ "description": "Node.js SDK for BinoAuth authentication",
5
+ "author": "BinoAuth",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/binoauth/binoauth.git"
9
+ },
10
+ "main": "./dist/index.js",
11
+ "typings": "./dist/index.d.ts",
12
+ "module": "./dist/esm/index.js",
13
+ "sideEffects": false,
14
+ "scripts": {
15
+ "build": "tsc && tsc -p tsconfig.esm.json",
16
+ "prepare": "npm run build",
17
+ "test": "jest",
18
+ "dev": "tsc --watch"
19
+ },
20
+ "keywords": [
21
+ "authentication",
22
+ "auth",
23
+ "binoauth",
24
+ "oauth2",
25
+ "jwt",
26
+ "otp",
27
+ "mfa",
28
+ "api-key"
29
+ ],
30
+ "dependencies": {
31
+ "@binoauth/tenant-sdk": "../tenant-sdk",
32
+ "@binoauth/admin-sdk": "../admin-sdk"
33
+ },
34
+ "devDependencies": {
35
+ "typescript": "^4.0 || ^5.0",
36
+ "@types/jest": "^29.0.0",
37
+ "jest": "^29.0.0",
38
+ "ts-jest": "^29.0.0"
39
+ },
40
+ "peerDependencies": {
41
+ "typescript": "^4.0 || ^5.0"
42
+ },
43
+ "private": false,
44
+ "publishConfig": {
45
+ "access": "public"
46
+ }
47
+ }