anzar 1.1.12 → 1.2.6

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.d.cts CHANGED
@@ -1,58 +1,323 @@
1
- interface AuthError {
2
- message: string;
1
+ import * as axios from 'axios';
2
+ import { AxiosInstance, RawAxiosRequestConfig } from 'axios';
3
+
4
+ /**
5
+ * Anzar Software API
6
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
7
+ *
8
+ * The version of the OpenAPI document: 0.6.2
9
+ * Contact: dev@anzar.io
10
+ *
11
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
12
+ * https://openapi-generator.tech
13
+ * Do not edit the class manually.
14
+ */
15
+ interface AWSv4Configuration {
16
+ options?: {
17
+ region?: string;
18
+ service?: string;
19
+ };
20
+ credentials?: {
21
+ accessKeyId?: string;
22
+ secretAccessKey?: string;
23
+ sessionToken?: string;
24
+ };
25
+ }
26
+ interface ConfigurationParameters {
27
+ apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
28
+ username?: string;
29
+ password?: string;
30
+ accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
31
+ awsv4?: AWSv4Configuration;
32
+ basePath?: string;
33
+ serverIndex?: number;
34
+ baseOptions?: any;
35
+ formDataCtor?: new () => any;
36
+ }
37
+ declare class Configuration {
38
+ /**
39
+ * parameter for apiKey security
40
+ * @param name security name
41
+ */
42
+ apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
43
+ /**
44
+ * parameter for basic security
45
+ */
46
+ username?: string;
47
+ /**
48
+ * parameter for basic security
49
+ */
50
+ password?: string;
51
+ /**
52
+ * parameter for oauth2 security
53
+ * @param name security name
54
+ * @param scopes oauth2 scope
55
+ */
56
+ accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
57
+ /**
58
+ * parameter for aws4 signature security
59
+ * @param {Object} AWS4Signature - AWS4 Signature security
60
+ * @param {string} options.region - aws region
61
+ * @param {string} options.service - name of the service.
62
+ * @param {string} credentials.accessKeyId - aws access key id
63
+ * @param {string} credentials.secretAccessKey - aws access key
64
+ * @param {string} credentials.sessionToken - aws session token
65
+ * @memberof Configuration
66
+ */
67
+ awsv4?: AWSv4Configuration;
68
+ /**
69
+ * override base path
70
+ */
71
+ basePath?: string;
72
+ /**
73
+ * override server index
74
+ */
75
+ serverIndex?: number;
76
+ /**
77
+ * base options for axios calls
78
+ */
79
+ baseOptions?: any;
80
+ /**
81
+ * The FormData constructor that will be used to create multipart form data
82
+ * requests. You can inject this here so that execution environments that
83
+ * do not support the FormData class can still run the generated client.
84
+ *
85
+ * @type {new () => FormData}
86
+ */
87
+ formDataCtor?: new () => any;
88
+ constructor(param?: ConfigurationParameters);
89
+ /**
90
+ * Check if the given MIME is a JSON MIME.
91
+ * JSON MIME examples:
92
+ * application/json
93
+ * application/json; charset=UTF8
94
+ * APPLICATION/JSON
95
+ * application/vnd.company+json
96
+ * @param mime - MIME (Multipurpose Internet Mail Extensions)
97
+ * @return True if the given MIME is JSON, false otherwise.
98
+ */
99
+ isJsonMime(mime: string): boolean;
3
100
  }
4
101
 
5
- type HttpResult<R> = {
6
- ok: true;
7
- data: R;
8
- } | {
9
- ok: false;
10
- error: AuthError;
11
- };
102
+ /**
103
+ * Anzar Software API
104
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
105
+ *
106
+ * The version of the OpenAPI document: 0.6.2
107
+ * Contact: dev@anzar.io
108
+ *
109
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
110
+ * https://openapi-generator.tech
111
+ * Do not edit the class manually.
112
+ */
113
+
114
+ declare class BaseAPI {
115
+ protected basePath: string;
116
+ protected axios: AxiosInstance;
117
+ protected configuration: Configuration | undefined;
118
+ constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance);
119
+ }
12
120
 
13
- interface HttpClient {
14
- get<R>(url: string): Promise<HttpResult<R>>;
15
- post<T, R>(url: string, obj: T): Promise<HttpResult<R>>;
121
+ /**
122
+ * Anzar Software API
123
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
124
+ *
125
+ * The version of the OpenAPI document: 0.6.2
126
+ * Contact: dev@anzar.io
127
+ *
128
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
129
+ * https://openapi-generator.tech
130
+ * Do not edit the class manually.
131
+ */
132
+ interface SessionTokens {
133
+ 'access': string;
134
+ 'refresh': string;
16
135
  }
17
136
 
18
- type Session = {
19
- _id: string | null;
20
- userId: string;
21
- issuedAt: string;
22
- expiresAt: string;
23
- usedAt: string | null;
24
- token: string;
137
+ /**
138
+ * Anzar Software API
139
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
140
+ *
141
+ * The version of the OpenAPI document: 0.6.2
142
+ * Contact: dev@anzar.io
143
+ *
144
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
145
+ * https://openapi-generator.tech
146
+ * Do not edit the class manually.
147
+ */
148
+ declare const Role: {
149
+ readonly User: "User";
150
+ readonly Admin: "Admin";
25
151
  };
152
+ type Role = typeof Role[keyof typeof Role];
153
+
154
+ /**
155
+ * Anzar Software API
156
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
157
+ *
158
+ * The version of the OpenAPI document: 0.6.2
159
+ * Contact: dev@anzar.io
160
+ *
161
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
162
+ * https://openapi-generator.tech
163
+ * Do not edit the class manually.
164
+ */
26
165
 
27
- declare enum Role {
28
- Admin = "Admin",
29
- User = "User"
166
+ interface User {
167
+ '_id'?: string | null;
168
+ 'createdAt': string;
169
+ 'email': string;
170
+ 'role': Role;
171
+ 'username': string;
172
+ 'verified': boolean;
30
173
  }
31
- type User = {
32
- _id: string | null;
33
- username: string;
34
- email: string;
35
- role: Role;
36
- verified: boolean;
37
- createdAt: string;
38
- };
39
174
 
40
- type ResetLink = {
41
- link: string;
42
- expires_at: string;
43
- };
44
- type Verification = {
45
- token: string;
46
- link: string;
47
- };
48
- type AuthPayload = {
49
- user: User;
50
- verification: Verification | null;
51
- };
52
- type AuthUser = {
53
- user: User;
54
- session: Session | null;
55
- };
175
+ /**
176
+ * Anzar Software API
177
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
178
+ *
179
+ * The version of the OpenAPI document: 0.6.2
180
+ * Contact: dev@anzar.io
181
+ *
182
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
183
+ * https://openapi-generator.tech
184
+ * Do not edit the class manually.
185
+ */
186
+ /**
187
+ * Verification model
188
+ */
189
+ interface Verification {
190
+ 'link': string;
191
+ 'token': string;
192
+ }
193
+
194
+ /**
195
+ * Anzar Software API
196
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
197
+ *
198
+ * The version of the OpenAPI document: 0.6.2
199
+ * Contact: dev@anzar.io
200
+ *
201
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
202
+ * https://openapi-generator.tech
203
+ * Do not edit the class manually.
204
+ */
205
+
206
+ interface AuthResponse {
207
+ 'tokens'?: SessionTokens | null;
208
+ 'user': User;
209
+ 'verification'?: Verification | null;
210
+ }
211
+
212
+ /**
213
+ * Anzar Software API
214
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
215
+ *
216
+ * The version of the OpenAPI document: 0.6.2
217
+ * Contact: dev@anzar.io
218
+ *
219
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
220
+ * https://openapi-generator.tech
221
+ * Do not edit the class manually.
222
+ */
223
+ interface EmailRequest {
224
+ 'email': string;
225
+ }
226
+
227
+ /**
228
+ * Anzar Software API
229
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
230
+ *
231
+ * The version of the OpenAPI document: 0.6.2
232
+ * Contact: dev@anzar.io
233
+ *
234
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
235
+ * https://openapi-generator.tech
236
+ * Do not edit the class manually.
237
+ */
238
+ interface LoginRequest {
239
+ 'email': string;
240
+ 'password': string;
241
+ }
242
+
243
+ /**
244
+ * Anzar Software API
245
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
246
+ *
247
+ * The version of the OpenAPI document: 0.6.2
248
+ * Contact: dev@anzar.io
249
+ *
250
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
251
+ * https://openapi-generator.tech
252
+ * Do not edit the class manually.
253
+ */
254
+ interface RegisterRequest {
255
+ 'email': string;
256
+ 'password': string;
257
+ 'username': string;
258
+ }
259
+
260
+ /**
261
+ * Anzar Software API
262
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
263
+ *
264
+ * The version of the OpenAPI document: 0.6.2
265
+ * Contact: dev@anzar.io
266
+ *
267
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
268
+ * https://openapi-generator.tech
269
+ * Do not edit the class manually.
270
+ */
271
+ interface Session {
272
+ '_id'?: string | null;
273
+ 'expiresAt': string;
274
+ 'issuedAt': string;
275
+ 'token': string;
276
+ 'usedAt'?: string | null;
277
+ 'userId'?: string;
278
+ }
279
+
280
+ /**
281
+ * Anzar Software API
282
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
283
+ *
284
+ * The version of the OpenAPI document: 0.6.2
285
+ * Contact: dev@anzar.io
286
+ *
287
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
288
+ * https://openapi-generator.tech
289
+ * Do not edit the class manually.
290
+ */
291
+ interface TokenQuery {
292
+ 'token': string;
293
+ }
294
+
295
+ /**
296
+ * EmailApi - object-oriented interface
297
+ */
298
+ declare class EmailApi extends BaseAPI {
299
+ /**
300
+ * Validates the email token and update the user account.
301
+ * @summary Verify user email
302
+ * @param {TokenQuery} token Email Verification Token
303
+ * @param {*} [options] Override http request option.
304
+ * @throws {RequiredError}
305
+ */
306
+ verifyEmail(token: TokenQuery, options?: RawAxiosRequestConfig): Promise<axios.AxiosResponse<void, any, {}>>;
307
+ }
308
+
309
+ /**
310
+ * UsersApi - object-oriented interface
311
+ */
312
+ declare class UsersApi extends BaseAPI {
313
+ /**
314
+ * Returns the currently authenticated user\'s data. Requires a valid Bearer token.
315
+ * @summary Get current User
316
+ * @param {*} [options] Override http request option.
317
+ * @throws {RequiredError}
318
+ */
319
+ findUser(options?: RawAxiosRequestConfig): Promise<axios.AxiosResponse<User, any, {}>>;
320
+ }
56
321
 
57
322
  declare enum DatabaseDriver {
58
323
  SQLite = "SQLite",
@@ -124,20 +389,24 @@ type AnzarConfig = {
124
389
  auth: Authentication | null;
125
390
  };
126
391
 
127
- declare class AnzarAuth {
128
- private httpClient;
129
- private config;
130
- constructor(httpClient: HttpClient, config: AnzarConfig);
131
- auth: {
132
- login: (email: string, password: string) => Promise<AuthPayload | AuthError>;
133
- register: (username: string, email: string, password: string) => Promise<AuthPayload | AuthError>;
134
- logout: () => Promise<null | AuthError>;
135
- session: () => Promise<AuthError | AuthUser>;
136
- isLoggedIn: () => Promise<boolean>;
137
- resetPassword: (email: string) => Promise<ResetLink | AuthError>;
138
- };
392
+ interface SdkOptions {
393
+ getToken: () => string | null;
394
+ getRefreshToken: () => string | null;
395
+ onTokenRefresh?: (tokens: SessionTokens) => void;
396
+ onSessionExpired?: () => void;
397
+ onLogout?: () => void;
139
398
  }
140
399
 
141
- declare function Anzar(config: AnzarConfig): AnzarAuth;
400
+ declare function Anzar(anzarConfig: AnzarConfig, options?: SdkOptions): {
401
+ Auth: {
402
+ session?: (() => Promise<axios.AxiosResponse<Session, any, {}>>) | undefined;
403
+ login: (body: LoginRequest) => Promise<axios.AxiosResponse<AuthResponse, any, {}>>;
404
+ register: (body: RegisterRequest) => Promise<axios.AxiosResponse<AuthResponse, any, {}>>;
405
+ logout: () => Promise<void>;
406
+ resetPassword: (body: EmailRequest) => void;
407
+ };
408
+ User: UsersApi;
409
+ Email: EmailApi;
410
+ };
142
411
 
143
412
  export { Anzar };