@thelllabs/winehaus-sdk 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.
- package/README.md +32 -0
- package/dist/cjs/api/api.js +293 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/interfaces.js +2 -0
- package/dist/cjs/sdk.js +329 -0
- package/dist/esm/api/api.js +287 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/interfaces.js +1 -0
- package/dist/esm/sdk.js +300 -0
- package/dist/types/api/api.d.ts +282 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/interfaces.d.ts +16 -0
- package/dist/types/sdk.d.ts +40 -0
- package/dist/umd/index.js +2 -0
- package/dist/umd/index.js.LICENSE.txt +17 -0
- package/package.json +106 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
export interface CreateTenantUserDto {
|
|
2
|
+
/** @example "user@example.com" */
|
|
3
|
+
email: string;
|
|
4
|
+
/**
|
|
5
|
+
* Password should include lowercase, uppercase and digits and have between 8 and 32 digits. (This will be only used if the user has any account created in other tenants)
|
|
6
|
+
* @example "P@ssw0rd"
|
|
7
|
+
*/
|
|
8
|
+
password?: string;
|
|
9
|
+
/** @example ["operator"] */
|
|
10
|
+
roles: CreateTenantUserDtoRolesEnum[];
|
|
11
|
+
}
|
|
12
|
+
export declare enum CreateTenantUserDtoRolesEnum {
|
|
13
|
+
Operator = "operator",
|
|
14
|
+
Admin = "admin",
|
|
15
|
+
Owner = "owner"
|
|
16
|
+
}
|
|
17
|
+
export interface HttpExceptionDto {
|
|
18
|
+
/** @example null */
|
|
19
|
+
data?: object;
|
|
20
|
+
error: string;
|
|
21
|
+
/** @example "Something went wrong" */
|
|
22
|
+
message: object;
|
|
23
|
+
/** @example "/api/foo/bar" */
|
|
24
|
+
path: string;
|
|
25
|
+
/** @example 500 */
|
|
26
|
+
statusCode: number;
|
|
27
|
+
/** @example "2022-07-25T17:24:07.042Z" */
|
|
28
|
+
timestamp: string;
|
|
29
|
+
}
|
|
30
|
+
export interface RequestPasswordResetDto {
|
|
31
|
+
email: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ResetPasswordDto {
|
|
34
|
+
/** @example "user@example.com" */
|
|
35
|
+
email: string;
|
|
36
|
+
/**
|
|
37
|
+
* Password should include lowercase, uppercase and digits and have between 8 and 32 digits
|
|
38
|
+
* @example "P@ssw0rd"
|
|
39
|
+
*/
|
|
40
|
+
password: string;
|
|
41
|
+
/** @example "P@ssw0rd" */
|
|
42
|
+
passwordConfirmation: string;
|
|
43
|
+
token: string;
|
|
44
|
+
}
|
|
45
|
+
export interface SigninDto {
|
|
46
|
+
/** @example "user@example.com" */
|
|
47
|
+
email: string;
|
|
48
|
+
/** @example "P@ssw0rd" */
|
|
49
|
+
password: string;
|
|
50
|
+
}
|
|
51
|
+
export interface SigninResponseDto {
|
|
52
|
+
token: string;
|
|
53
|
+
user: UserEntityDto;
|
|
54
|
+
}
|
|
55
|
+
export interface TenantUserEntityDto {
|
|
56
|
+
roles: TenantUserEntityDtoRolesEnum[];
|
|
57
|
+
/** @example "enabled" */
|
|
58
|
+
status: TenantUserEntityDtoStatusEnum;
|
|
59
|
+
/** @format uuid */
|
|
60
|
+
tenantId: string;
|
|
61
|
+
user: UserEntityDto;
|
|
62
|
+
/** @format uuid */
|
|
63
|
+
userId: string;
|
|
64
|
+
}
|
|
65
|
+
export declare enum TenantUserEntityDtoRolesEnum {
|
|
66
|
+
Operator = "operator",
|
|
67
|
+
Admin = "admin",
|
|
68
|
+
Owner = "owner"
|
|
69
|
+
}
|
|
70
|
+
/** @example "enabled" */
|
|
71
|
+
export declare enum TenantUserEntityDtoStatusEnum {
|
|
72
|
+
Enabled = "enabled",
|
|
73
|
+
Blocked = "blocked"
|
|
74
|
+
}
|
|
75
|
+
export interface UserEntityDto {
|
|
76
|
+
/** @format date-time */
|
|
77
|
+
createdAt?: string;
|
|
78
|
+
/** @format date-time */
|
|
79
|
+
deletedAt?: string | null;
|
|
80
|
+
email: string;
|
|
81
|
+
/** @format uuid */
|
|
82
|
+
id: string;
|
|
83
|
+
name: string;
|
|
84
|
+
/** @format date-time */
|
|
85
|
+
updatedAt: string;
|
|
86
|
+
}
|
|
87
|
+
export declare namespace Auth {
|
|
88
|
+
/**
|
|
89
|
+
* No description
|
|
90
|
+
* @tags Authentication
|
|
91
|
+
* @name Logout
|
|
92
|
+
* @request POST:/auth/logout
|
|
93
|
+
* @secure
|
|
94
|
+
* @response `204` `void`
|
|
95
|
+
*/
|
|
96
|
+
namespace Logout {
|
|
97
|
+
type RequestParams = {};
|
|
98
|
+
type RequestQuery = {};
|
|
99
|
+
type RequestBody = never;
|
|
100
|
+
type RequestHeaders = {};
|
|
101
|
+
type ResponseBody = void;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* No description
|
|
105
|
+
* @tags Authentication
|
|
106
|
+
* @name RequestPasswordReset
|
|
107
|
+
* @request POST:/auth/request-password-reset
|
|
108
|
+
* @secure
|
|
109
|
+
* @response `204` `void`
|
|
110
|
+
*/
|
|
111
|
+
namespace RequestPasswordReset {
|
|
112
|
+
type RequestParams = {};
|
|
113
|
+
type RequestQuery = {};
|
|
114
|
+
type RequestBody = RequestPasswordResetDto;
|
|
115
|
+
type RequestHeaders = {};
|
|
116
|
+
type ResponseBody = void;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* No description
|
|
120
|
+
* @tags Authentication
|
|
121
|
+
* @name ResetPassword
|
|
122
|
+
* @request PATCH:/auth/reset-password
|
|
123
|
+
* @secure
|
|
124
|
+
* @response `200` `SigninResponseDto`
|
|
125
|
+
*/
|
|
126
|
+
namespace ResetPassword {
|
|
127
|
+
type RequestParams = {};
|
|
128
|
+
type RequestQuery = {};
|
|
129
|
+
type RequestBody = ResetPasswordDto;
|
|
130
|
+
type RequestHeaders = {};
|
|
131
|
+
type ResponseBody = SigninResponseDto;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* No description
|
|
135
|
+
* @tags Authentication
|
|
136
|
+
* @name SignIn
|
|
137
|
+
* @request POST:/auth/signin
|
|
138
|
+
* @secure
|
|
139
|
+
* @response `200` `SigninResponseDto`
|
|
140
|
+
*/
|
|
141
|
+
namespace SignIn {
|
|
142
|
+
type RequestParams = {};
|
|
143
|
+
type RequestQuery = {};
|
|
144
|
+
type RequestBody = SigninDto;
|
|
145
|
+
type RequestHeaders = {};
|
|
146
|
+
type ResponseBody = SigninResponseDto;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export declare namespace Admin {
|
|
150
|
+
/**
|
|
151
|
+
* @description Gives some user access to the tenant. If there's no account attached to this users, it creates a new one
|
|
152
|
+
* @tags Admin Users
|
|
153
|
+
* @name CreateTenantUser
|
|
154
|
+
* @request POST:/admin/tenants/{tenantId}/users
|
|
155
|
+
* @secure
|
|
156
|
+
* @response `201` `TenantUserEntityDto`
|
|
157
|
+
* @response `403` `HttpExceptionDto` Need user with one of these roles: owner, admin
|
|
158
|
+
*/
|
|
159
|
+
namespace CreateTenantUser {
|
|
160
|
+
type RequestParams = {
|
|
161
|
+
tenantId: string;
|
|
162
|
+
};
|
|
163
|
+
type RequestQuery = {};
|
|
164
|
+
type RequestBody = CreateTenantUserDto;
|
|
165
|
+
type RequestHeaders = {};
|
|
166
|
+
type ResponseBody = TenantUserEntityDto;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, ResponseType } from "axios";
|
|
170
|
+
export type QueryParamsType = Record<string | number, any>;
|
|
171
|
+
export interface FullRequestParams extends Omit<AxiosRequestConfig, "data" | "params" | "url" | "responseType"> {
|
|
172
|
+
/** set parameter to `true` for call `securityWorker` for this request */
|
|
173
|
+
secure?: boolean;
|
|
174
|
+
/** request path */
|
|
175
|
+
path: string;
|
|
176
|
+
/** content type of request body */
|
|
177
|
+
type?: ContentType;
|
|
178
|
+
/** query params */
|
|
179
|
+
query?: QueryParamsType;
|
|
180
|
+
/** format of response (i.e. response.json() -> format: "json") */
|
|
181
|
+
format?: ResponseType;
|
|
182
|
+
/** request body */
|
|
183
|
+
body?: unknown;
|
|
184
|
+
}
|
|
185
|
+
export type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
|
|
186
|
+
export interface ApiConfig<SecurityDataType = unknown> extends Omit<AxiosRequestConfig, "data" | "cancelToken"> {
|
|
187
|
+
securityWorker?: (securityData: SecurityDataType | null) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
|
|
188
|
+
secure?: boolean;
|
|
189
|
+
format?: ResponseType;
|
|
190
|
+
}
|
|
191
|
+
export declare enum ContentType {
|
|
192
|
+
Json = "application/json",
|
|
193
|
+
JsonApi = "application/vnd.api+json",
|
|
194
|
+
FormData = "multipart/form-data",
|
|
195
|
+
UrlEncoded = "application/x-www-form-urlencoded",
|
|
196
|
+
Text = "text/plain"
|
|
197
|
+
}
|
|
198
|
+
export declare class HttpClient<SecurityDataType = unknown> {
|
|
199
|
+
instance: AxiosInstance;
|
|
200
|
+
private securityData;
|
|
201
|
+
private securityWorker?;
|
|
202
|
+
private secure?;
|
|
203
|
+
private format?;
|
|
204
|
+
constructor({ securityWorker, secure, format, ...axiosConfig }?: ApiConfig<SecurityDataType>);
|
|
205
|
+
setSecurityData: (data: SecurityDataType | null) => void;
|
|
206
|
+
protected mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig;
|
|
207
|
+
protected stringifyFormItem(formItem: unknown): string;
|
|
208
|
+
protected createFormData(input: Record<string, unknown>): FormData;
|
|
209
|
+
request: <T = any, _E = any>({ secure, path, type, query, format, body, ...params }: FullRequestParams) => Promise<AxiosResponse<T, any>>;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* @title winehaus-api
|
|
213
|
+
* @version 0.0.1
|
|
214
|
+
* @baseUrl http://localhost:3000
|
|
215
|
+
* @contact
|
|
216
|
+
*/
|
|
217
|
+
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
218
|
+
/**
|
|
219
|
+
* No description
|
|
220
|
+
*
|
|
221
|
+
* @tags App
|
|
222
|
+
* @name Index
|
|
223
|
+
* @request GET:/
|
|
224
|
+
* @response `200` `void`
|
|
225
|
+
*/
|
|
226
|
+
index: (params?: RequestParams) => Promise<AxiosResponse<void, any>>;
|
|
227
|
+
auth: {
|
|
228
|
+
/**
|
|
229
|
+
* No description
|
|
230
|
+
*
|
|
231
|
+
* @tags Authentication
|
|
232
|
+
* @name Logout
|
|
233
|
+
* @request POST:/auth/logout
|
|
234
|
+
* @secure
|
|
235
|
+
* @response `204` `void`
|
|
236
|
+
*/
|
|
237
|
+
logout: (params?: RequestParams) => Promise<AxiosResponse<void, any>>;
|
|
238
|
+
/**
|
|
239
|
+
* No description
|
|
240
|
+
*
|
|
241
|
+
* @tags Authentication
|
|
242
|
+
* @name RequestPasswordReset
|
|
243
|
+
* @request POST:/auth/request-password-reset
|
|
244
|
+
* @secure
|
|
245
|
+
* @response `204` `void`
|
|
246
|
+
*/
|
|
247
|
+
requestPasswordReset: (data: RequestPasswordResetDto, params?: RequestParams) => Promise<AxiosResponse<void, any>>;
|
|
248
|
+
/**
|
|
249
|
+
* No description
|
|
250
|
+
*
|
|
251
|
+
* @tags Authentication
|
|
252
|
+
* @name ResetPassword
|
|
253
|
+
* @request PATCH:/auth/reset-password
|
|
254
|
+
* @secure
|
|
255
|
+
* @response `200` `SigninResponseDto`
|
|
256
|
+
*/
|
|
257
|
+
resetPassword: (data: ResetPasswordDto, params?: RequestParams) => Promise<AxiosResponse<SigninResponseDto, any>>;
|
|
258
|
+
/**
|
|
259
|
+
* No description
|
|
260
|
+
*
|
|
261
|
+
* @tags Authentication
|
|
262
|
+
* @name SignIn
|
|
263
|
+
* @request POST:/auth/signin
|
|
264
|
+
* @secure
|
|
265
|
+
* @response `200` `SigninResponseDto`
|
|
266
|
+
*/
|
|
267
|
+
signIn: (data: SigninDto, params?: RequestParams) => Promise<AxiosResponse<SigninResponseDto, any>>;
|
|
268
|
+
};
|
|
269
|
+
admin: {
|
|
270
|
+
/**
|
|
271
|
+
* @description Gives some user access to the tenant. If there's no account attached to this users, it creates a new one
|
|
272
|
+
*
|
|
273
|
+
* @tags Admin Users
|
|
274
|
+
* @name CreateTenantUser
|
|
275
|
+
* @request POST:/admin/tenants/{tenantId}/users
|
|
276
|
+
* @secure
|
|
277
|
+
* @response `201` `TenantUserEntityDto`
|
|
278
|
+
* @response `403` `HttpExceptionDto` Need user with one of these roles: owner, admin
|
|
279
|
+
*/
|
|
280
|
+
createTenantUser: (tenantId: string, data: CreateTenantUserDto, params?: RequestParams) => Promise<AxiosResponse<TenantUserEntityDto, any>>;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface SDKOptions {
|
|
2
|
+
baseURL: string;
|
|
3
|
+
autoRefresh?: boolean;
|
|
4
|
+
tokenExpireOffset?: number;
|
|
5
|
+
}
|
|
6
|
+
export type ApiSecurityDataType = {
|
|
7
|
+
bearer: string;
|
|
8
|
+
};
|
|
9
|
+
export type SDKEvents = {
|
|
10
|
+
connecting: void;
|
|
11
|
+
connected: void;
|
|
12
|
+
authChanged: {
|
|
13
|
+
authToken: string;
|
|
14
|
+
refreshToken: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { SDKOptions, ApiSecurityDataType, SDKEvents } from './interfaces';
|
|
3
|
+
import { JwtPayload } from 'jwt-decode';
|
|
4
|
+
import { Api, SigninDto } from './api/api';
|
|
5
|
+
import { Emitter } from 'mitt';
|
|
6
|
+
export declare class WinehausSDK {
|
|
7
|
+
api: Api<ApiSecurityDataType>;
|
|
8
|
+
protected authToken: string;
|
|
9
|
+
protected authTokenDecoded: JwtPayload | undefined;
|
|
10
|
+
protected refreshTokenDecoded: JwtPayload | undefined;
|
|
11
|
+
protected refreshToken: string;
|
|
12
|
+
protected options: SDKOptions;
|
|
13
|
+
protected autoRefreshTimer: NodeJS.Timeout | undefined;
|
|
14
|
+
protected credential: SigninDto | undefined;
|
|
15
|
+
emitter: Emitter<SDKEvents>;
|
|
16
|
+
protected defaultOptions: Partial<SDKOptions>;
|
|
17
|
+
constructor(options: SDKOptions);
|
|
18
|
+
enableAutoRefresh(force?: boolean): void;
|
|
19
|
+
disableAutoRefresh(): void;
|
|
20
|
+
private hookTimer;
|
|
21
|
+
private hookInterceptors;
|
|
22
|
+
clearTokens(): void;
|
|
23
|
+
authenticate(credential: SigninDto, opts?: {
|
|
24
|
+
avoidEvents?: boolean;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
reAuthenticate(): Promise<void>;
|
|
27
|
+
isAuthenticated(): boolean;
|
|
28
|
+
protected setAuthToken(token: string): void;
|
|
29
|
+
triggerRefreshToken(): Promise<void>;
|
|
30
|
+
isTokenExpired(): boolean;
|
|
31
|
+
getAuthToken(): string;
|
|
32
|
+
protected setRefreshToken(refreshToken: string): void;
|
|
33
|
+
getRefreshToken(): string;
|
|
34
|
+
refreshTokens(): Promise<void>;
|
|
35
|
+
private authenticateAsUser;
|
|
36
|
+
private setTokens;
|
|
37
|
+
getAuthTokenDecoded(): JwtPayload | undefined;
|
|
38
|
+
getRefreshTokenDecoded(): JwtPayload | undefined;
|
|
39
|
+
static decodeToken(token: string): JwtPayload | undefined;
|
|
40
|
+
}
|