@faable/auth-sdk 1.0.16 → 1.0.18
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/.github/workflows/release.yml +2 -2
- package/dist/FaableAuthApi.d.ts +145 -82
- package/dist/FaableAuthApi.js +22 -40
- package/dist/error_handler.d.ts +5 -0
- package/dist/error_handler.js +16 -0
- package/dist/fetcher_axios.d.ts +8 -0
- package/dist/fetcher_axios.js +41 -0
- package/dist/paginator.d.ts +8 -3
- package/dist/paginator.js +15 -7
- package/package.json +17 -2
- package/tsconfig.json +3 -3
package/dist/FaableAuthApi.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
2
|
import { TeamCreate, UserCreate, UserUpdate } from "./types";
|
|
3
3
|
import { FaablePaginator, Page } from "./paginator";
|
|
4
|
+
import { Fetcher } from "./fetcher_axios";
|
|
4
5
|
export declare class FaableAuthApi {
|
|
5
|
-
|
|
6
|
+
fetcher: Fetcher;
|
|
6
7
|
paginator: FaablePaginator;
|
|
7
8
|
constructor(client?: AxiosInstance);
|
|
8
9
|
setUserMetadata(user_id: string, user_metadata: Record<string, string | any[] | boolean | number | null | undefined>): Promise<{
|
|
@@ -16,22 +17,22 @@ export declare class FaableAuthApi {
|
|
|
16
17
|
}): {
|
|
17
18
|
all: () => Promise<{
|
|
18
19
|
id: string;
|
|
19
|
-
name?: string;
|
|
20
|
-
username?: string;
|
|
21
|
-
given_name?: string;
|
|
22
|
-
family_name?: string;
|
|
23
|
-
email?: string;
|
|
20
|
+
name?: string | null | undefined;
|
|
21
|
+
username?: string | null | undefined;
|
|
22
|
+
given_name?: string | null | undefined;
|
|
23
|
+
family_name?: string | null | undefined;
|
|
24
|
+
email?: string | null | undefined;
|
|
24
25
|
email_verified: boolean;
|
|
25
|
-
phone?: string;
|
|
26
|
+
phone?: string | null | undefined;
|
|
26
27
|
phone_verified: boolean;
|
|
27
|
-
country_iso?: string;
|
|
28
|
-
birth_date?: string;
|
|
28
|
+
country_iso?: string | null | undefined;
|
|
29
|
+
birth_date?: string | null | undefined;
|
|
29
30
|
locale: string;
|
|
30
|
-
region?: string;
|
|
31
|
-
picture?: string;
|
|
31
|
+
region?: string | null | undefined;
|
|
32
|
+
picture?: string | null | undefined;
|
|
32
33
|
logins_count: number;
|
|
33
|
-
last_ip?: string;
|
|
34
|
-
last_login?: string;
|
|
34
|
+
last_ip?: string | null | undefined;
|
|
35
|
+
last_login?: string | null | undefined;
|
|
35
36
|
user_metadata: {
|
|
36
37
|
[key: string]: unknown;
|
|
37
38
|
};
|
|
@@ -40,26 +41,26 @@ export declare class FaableAuthApi {
|
|
|
40
41
|
};
|
|
41
42
|
account: string;
|
|
42
43
|
createdAt: string;
|
|
43
|
-
updatedAt?: string;
|
|
44
|
+
updatedAt?: string | undefined;
|
|
44
45
|
}[]>;
|
|
45
46
|
first: () => Promise<Page<{
|
|
46
47
|
id: string;
|
|
47
|
-
name?: string;
|
|
48
|
-
username?: string;
|
|
49
|
-
given_name?: string;
|
|
50
|
-
family_name?: string;
|
|
51
|
-
email?: string;
|
|
48
|
+
name?: string | null | undefined;
|
|
49
|
+
username?: string | null | undefined;
|
|
50
|
+
given_name?: string | null | undefined;
|
|
51
|
+
family_name?: string | null | undefined;
|
|
52
|
+
email?: string | null | undefined;
|
|
52
53
|
email_verified: boolean;
|
|
53
|
-
phone?: string;
|
|
54
|
+
phone?: string | null | undefined;
|
|
54
55
|
phone_verified: boolean;
|
|
55
|
-
country_iso?: string;
|
|
56
|
-
birth_date?: string;
|
|
56
|
+
country_iso?: string | null | undefined;
|
|
57
|
+
birth_date?: string | null | undefined;
|
|
57
58
|
locale: string;
|
|
58
|
-
region?: string;
|
|
59
|
-
picture?: string;
|
|
59
|
+
region?: string | null | undefined;
|
|
60
|
+
picture?: string | null | undefined;
|
|
60
61
|
logins_count: number;
|
|
61
|
-
last_ip?: string;
|
|
62
|
-
last_login?: string;
|
|
62
|
+
last_ip?: string | null | undefined;
|
|
63
|
+
last_login?: string | null | undefined;
|
|
63
64
|
user_metadata: {
|
|
64
65
|
[key: string]: unknown;
|
|
65
66
|
};
|
|
@@ -68,27 +69,58 @@ export declare class FaableAuthApi {
|
|
|
68
69
|
};
|
|
69
70
|
account: string;
|
|
70
71
|
createdAt: string;
|
|
71
|
-
updatedAt?: string;
|
|
72
|
+
updatedAt?: string | undefined;
|
|
73
|
+
}>>;
|
|
74
|
+
pass: (params?: {
|
|
75
|
+
cursor?: string | undefined;
|
|
76
|
+
pageSize?: string | undefined;
|
|
77
|
+
}) => Promise<Page<{
|
|
78
|
+
id: string;
|
|
79
|
+
name?: string | null | undefined;
|
|
80
|
+
username?: string | null | undefined;
|
|
81
|
+
given_name?: string | null | undefined;
|
|
82
|
+
family_name?: string | null | undefined;
|
|
83
|
+
email?: string | null | undefined;
|
|
84
|
+
email_verified: boolean;
|
|
85
|
+
phone?: string | null | undefined;
|
|
86
|
+
phone_verified: boolean;
|
|
87
|
+
country_iso?: string | null | undefined;
|
|
88
|
+
birth_date?: string | null | undefined;
|
|
89
|
+
locale: string;
|
|
90
|
+
region?: string | null | undefined;
|
|
91
|
+
picture?: string | null | undefined;
|
|
92
|
+
logins_count: number;
|
|
93
|
+
last_ip?: string | null | undefined;
|
|
94
|
+
last_login?: string | null | undefined;
|
|
95
|
+
user_metadata: {
|
|
96
|
+
[key: string]: unknown;
|
|
97
|
+
};
|
|
98
|
+
app_metadata: {
|
|
99
|
+
[key: string]: unknown;
|
|
100
|
+
};
|
|
101
|
+
account: string;
|
|
102
|
+
createdAt: string;
|
|
103
|
+
updatedAt?: string | undefined;
|
|
72
104
|
}>>;
|
|
73
105
|
};
|
|
74
|
-
getUser(user_id:
|
|
106
|
+
getUser(user_id: string): Promise<{
|
|
75
107
|
id: string;
|
|
76
|
-
name?: string;
|
|
77
|
-
username?: string;
|
|
78
|
-
given_name?: string;
|
|
79
|
-
family_name?: string;
|
|
80
|
-
email?: string;
|
|
108
|
+
name?: string | null | undefined;
|
|
109
|
+
username?: string | null | undefined;
|
|
110
|
+
given_name?: string | null | undefined;
|
|
111
|
+
family_name?: string | null | undefined;
|
|
112
|
+
email?: string | null | undefined;
|
|
81
113
|
email_verified: boolean;
|
|
82
|
-
phone?: string;
|
|
114
|
+
phone?: string | null | undefined;
|
|
83
115
|
phone_verified: boolean;
|
|
84
|
-
country_iso?: string;
|
|
85
|
-
birth_date?: string;
|
|
116
|
+
country_iso?: string | null | undefined;
|
|
117
|
+
birth_date?: string | null | undefined;
|
|
86
118
|
locale: string;
|
|
87
|
-
region?: string;
|
|
88
|
-
picture?: string;
|
|
119
|
+
region?: string | null | undefined;
|
|
120
|
+
picture?: string | null | undefined;
|
|
89
121
|
logins_count: number;
|
|
90
|
-
last_ip?: string;
|
|
91
|
-
last_login?: string;
|
|
122
|
+
last_ip?: string | null | undefined;
|
|
123
|
+
last_login?: string | null | undefined;
|
|
92
124
|
user_metadata: {
|
|
93
125
|
[key: string]: unknown;
|
|
94
126
|
};
|
|
@@ -97,26 +129,26 @@ export declare class FaableAuthApi {
|
|
|
97
129
|
};
|
|
98
130
|
account: string;
|
|
99
131
|
createdAt: string;
|
|
100
|
-
updatedAt?: string;
|
|
132
|
+
updatedAt?: string | undefined;
|
|
101
133
|
}>;
|
|
102
134
|
createUser(data: UserCreate): Promise<{
|
|
103
135
|
id: string;
|
|
104
|
-
name?: string;
|
|
105
|
-
username?: string;
|
|
106
|
-
given_name?: string;
|
|
107
|
-
family_name?: string;
|
|
108
|
-
email?: string;
|
|
136
|
+
name?: string | null | undefined;
|
|
137
|
+
username?: string | null | undefined;
|
|
138
|
+
given_name?: string | null | undefined;
|
|
139
|
+
family_name?: string | null | undefined;
|
|
140
|
+
email?: string | null | undefined;
|
|
109
141
|
email_verified: boolean;
|
|
110
|
-
phone?: string;
|
|
142
|
+
phone?: string | null | undefined;
|
|
111
143
|
phone_verified: boolean;
|
|
112
|
-
country_iso?: string;
|
|
113
|
-
birth_date?: string;
|
|
144
|
+
country_iso?: string | null | undefined;
|
|
145
|
+
birth_date?: string | null | undefined;
|
|
114
146
|
locale: string;
|
|
115
|
-
region?: string;
|
|
116
|
-
picture?: string;
|
|
147
|
+
region?: string | null | undefined;
|
|
148
|
+
picture?: string | null | undefined;
|
|
117
149
|
logins_count: number;
|
|
118
|
-
last_ip?: string;
|
|
119
|
-
last_login?: string;
|
|
150
|
+
last_ip?: string | null | undefined;
|
|
151
|
+
last_login?: string | null | undefined;
|
|
120
152
|
user_metadata: {
|
|
121
153
|
[key: string]: unknown;
|
|
122
154
|
};
|
|
@@ -125,26 +157,26 @@ export declare class FaableAuthApi {
|
|
|
125
157
|
};
|
|
126
158
|
account: string;
|
|
127
159
|
createdAt: string;
|
|
128
|
-
updatedAt?: string;
|
|
160
|
+
updatedAt?: string | undefined;
|
|
129
161
|
}>;
|
|
130
162
|
updateUser(user_id: string, data: UserUpdate): Promise<{
|
|
131
163
|
id: string;
|
|
132
|
-
name?: string;
|
|
133
|
-
username?: string;
|
|
134
|
-
given_name?: string;
|
|
135
|
-
family_name?: string;
|
|
136
|
-
email?: string;
|
|
164
|
+
name?: string | null | undefined;
|
|
165
|
+
username?: string | null | undefined;
|
|
166
|
+
given_name?: string | null | undefined;
|
|
167
|
+
family_name?: string | null | undefined;
|
|
168
|
+
email?: string | null | undefined;
|
|
137
169
|
email_verified: boolean;
|
|
138
|
-
phone?: string;
|
|
170
|
+
phone?: string | null | undefined;
|
|
139
171
|
phone_verified: boolean;
|
|
140
|
-
country_iso?: string;
|
|
141
|
-
birth_date?: string;
|
|
172
|
+
country_iso?: string | null | undefined;
|
|
173
|
+
birth_date?: string | null | undefined;
|
|
142
174
|
locale: string;
|
|
143
|
-
region?: string;
|
|
144
|
-
picture?: string;
|
|
175
|
+
region?: string | null | undefined;
|
|
176
|
+
picture?: string | null | undefined;
|
|
145
177
|
logins_count: number;
|
|
146
|
-
last_ip?: string;
|
|
147
|
-
last_login?: string;
|
|
178
|
+
last_ip?: string | null | undefined;
|
|
179
|
+
last_login?: string | null | undefined;
|
|
148
180
|
user_metadata: {
|
|
149
181
|
[key: string]: unknown;
|
|
150
182
|
};
|
|
@@ -153,33 +185,33 @@ export declare class FaableAuthApi {
|
|
|
153
185
|
};
|
|
154
186
|
account: string;
|
|
155
187
|
createdAt: string;
|
|
156
|
-
updatedAt?: string;
|
|
188
|
+
updatedAt?: string | undefined;
|
|
157
189
|
}>;
|
|
158
|
-
getTeam(team_id:
|
|
190
|
+
getTeam(team_id: string): Promise<{
|
|
159
191
|
id: string;
|
|
160
192
|
name: string;
|
|
161
193
|
slug: string;
|
|
162
|
-
description: string;
|
|
163
|
-
logo_url: string;
|
|
194
|
+
description: string | null;
|
|
195
|
+
logo_url: string | null;
|
|
164
196
|
metadata: {
|
|
165
197
|
[key: string]: unknown;
|
|
166
198
|
};
|
|
167
199
|
account: string;
|
|
168
200
|
createdAt: string;
|
|
169
|
-
updatedAt?: string;
|
|
201
|
+
updatedAt?: string | undefined;
|
|
170
202
|
}>;
|
|
171
203
|
createTeam(data: TeamCreate): Promise<{
|
|
172
204
|
id: string;
|
|
173
205
|
name: string;
|
|
174
206
|
slug: string;
|
|
175
|
-
description: string;
|
|
176
|
-
logo_url: string;
|
|
207
|
+
description: string | null;
|
|
208
|
+
logo_url: string | null;
|
|
177
209
|
metadata: {
|
|
178
210
|
[key: string]: unknown;
|
|
179
211
|
};
|
|
180
212
|
account: string;
|
|
181
213
|
createdAt: string;
|
|
182
|
-
updatedAt?: string;
|
|
214
|
+
updatedAt?: string | undefined;
|
|
183
215
|
}>;
|
|
184
216
|
listTeams(params?: {
|
|
185
217
|
user_id?: string;
|
|
@@ -188,27 +220,43 @@ export declare class FaableAuthApi {
|
|
|
188
220
|
id: string;
|
|
189
221
|
name: string;
|
|
190
222
|
slug: string;
|
|
191
|
-
description: string;
|
|
192
|
-
logo_url: string;
|
|
223
|
+
description: string | null;
|
|
224
|
+
logo_url: string | null;
|
|
193
225
|
metadata: {
|
|
194
226
|
[key: string]: unknown;
|
|
195
227
|
};
|
|
196
228
|
account: string;
|
|
197
229
|
createdAt: string;
|
|
198
|
-
updatedAt?: string;
|
|
230
|
+
updatedAt?: string | undefined;
|
|
199
231
|
}[]>;
|
|
200
232
|
first: () => Promise<Page<{
|
|
201
233
|
id: string;
|
|
202
234
|
name: string;
|
|
203
235
|
slug: string;
|
|
204
|
-
description: string;
|
|
205
|
-
logo_url: string;
|
|
236
|
+
description: string | null;
|
|
237
|
+
logo_url: string | null;
|
|
238
|
+
metadata: {
|
|
239
|
+
[key: string]: unknown;
|
|
240
|
+
};
|
|
241
|
+
account: string;
|
|
242
|
+
createdAt: string;
|
|
243
|
+
updatedAt?: string | undefined;
|
|
244
|
+
}>>;
|
|
245
|
+
pass: (params?: {
|
|
246
|
+
cursor?: string | undefined;
|
|
247
|
+
pageSize?: string | undefined;
|
|
248
|
+
}) => Promise<Page<{
|
|
249
|
+
id: string;
|
|
250
|
+
name: string;
|
|
251
|
+
slug: string;
|
|
252
|
+
description: string | null;
|
|
253
|
+
logo_url: string | null;
|
|
206
254
|
metadata: {
|
|
207
255
|
[key: string]: unknown;
|
|
208
256
|
};
|
|
209
257
|
account: string;
|
|
210
258
|
createdAt: string;
|
|
211
|
-
updatedAt?: string;
|
|
259
|
+
updatedAt?: string | undefined;
|
|
212
260
|
}>>;
|
|
213
261
|
};
|
|
214
262
|
listTeamMembers(params: {
|
|
@@ -224,7 +272,7 @@ export declare class FaableAuthApi {
|
|
|
224
272
|
};
|
|
225
273
|
account: string;
|
|
226
274
|
createdAt: string;
|
|
227
|
-
updatedAt?: string;
|
|
275
|
+
updatedAt?: string | undefined;
|
|
228
276
|
}[]>;
|
|
229
277
|
first: () => Promise<Page<{
|
|
230
278
|
id: string;
|
|
@@ -236,7 +284,22 @@ export declare class FaableAuthApi {
|
|
|
236
284
|
};
|
|
237
285
|
account: string;
|
|
238
286
|
createdAt: string;
|
|
239
|
-
updatedAt?: string;
|
|
287
|
+
updatedAt?: string | undefined;
|
|
288
|
+
}>>;
|
|
289
|
+
pass: (params?: {
|
|
290
|
+
cursor?: string | undefined;
|
|
291
|
+
pageSize?: string | undefined;
|
|
292
|
+
}) => Promise<Page<{
|
|
293
|
+
id: string;
|
|
294
|
+
user: unknown;
|
|
295
|
+
team: unknown;
|
|
296
|
+
roles: unknown[];
|
|
297
|
+
metadata: {
|
|
298
|
+
[key: string]: unknown;
|
|
299
|
+
};
|
|
300
|
+
account: string;
|
|
301
|
+
createdAt: string;
|
|
302
|
+
updatedAt?: string | undefined;
|
|
240
303
|
}>>;
|
|
241
304
|
};
|
|
242
305
|
isUserMemberOfTeam(user_id: string, team_id: string): Promise<boolean>;
|
package/dist/FaableAuthApi.js
CHANGED
|
@@ -3,55 +3,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FaableAuthApi = void 0;
|
|
4
4
|
const auth_helpers_axios_1 = require("@faable/auth-helpers-axios");
|
|
5
5
|
const paginator_1 = require("./paginator");
|
|
6
|
-
const
|
|
7
|
-
try {
|
|
8
|
-
const res = await q;
|
|
9
|
-
if (res.status >= 200 && res.status < 300) {
|
|
10
|
-
return res.data;
|
|
11
|
-
}
|
|
12
|
-
throw new Error(`Error API Call code=${res.status} url=${res.config.url}`);
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
const e = error;
|
|
16
|
-
if (e.isAxiosError) {
|
|
17
|
-
throw new Error(`API ERROR code=${e.response?.status} url=${e.response?.config.url}`);
|
|
18
|
-
}
|
|
19
|
-
throw new Error("Bad API");
|
|
20
|
-
}
|
|
21
|
-
};
|
|
6
|
+
const fetcher_axios_1 = require("./fetcher_axios");
|
|
22
7
|
class FaableAuthApi {
|
|
23
|
-
|
|
8
|
+
fetcher;
|
|
24
9
|
paginator;
|
|
25
10
|
constructor(client) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
this.paginator = new paginator_1.FaablePaginator(this.client);
|
|
11
|
+
this.fetcher = (0, fetcher_axios_1.fetcher_axios)(client || (0, auth_helpers_axios_1.authorize)());
|
|
12
|
+
this.paginator = new paginator_1.FaablePaginator(this.fetcher);
|
|
30
13
|
}
|
|
31
14
|
async setUserMetadata(user_id, user_metadata) {
|
|
32
|
-
|
|
15
|
+
const user = await this.fetcher.post(`/user/${user_id}`, {
|
|
16
|
+
user_metadata,
|
|
17
|
+
});
|
|
18
|
+
return user.user_metadata;
|
|
33
19
|
}
|
|
34
20
|
async getUserMetadata(user_id) {
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
const user = await this.fetcher.get(`/user/${user_id}`);
|
|
22
|
+
return user.user_metadata;
|
|
37
23
|
}
|
|
38
24
|
listUsers(params = {}) {
|
|
39
25
|
return this.paginator.paginate({ url: "/user", params });
|
|
40
26
|
}
|
|
41
|
-
|
|
42
|
-
return
|
|
27
|
+
getUser(user_id) {
|
|
28
|
+
return this.fetcher.get(`/user/${user_id}`);
|
|
43
29
|
}
|
|
44
|
-
|
|
45
|
-
return
|
|
30
|
+
createUser(data) {
|
|
31
|
+
return this.fetcher.post(`/user`, data);
|
|
46
32
|
}
|
|
47
|
-
|
|
48
|
-
return
|
|
33
|
+
updateUser(user_id, data) {
|
|
34
|
+
return this.fetcher.post(`/user/${user_id}`, data);
|
|
49
35
|
}
|
|
50
|
-
|
|
51
|
-
return
|
|
36
|
+
getTeam(team_id) {
|
|
37
|
+
return this.fetcher.get(`/team/${team_id}`);
|
|
52
38
|
}
|
|
53
|
-
|
|
54
|
-
return
|
|
39
|
+
createTeam(data) {
|
|
40
|
+
return this.fetcher.post(`/team`, data);
|
|
55
41
|
}
|
|
56
42
|
listTeams(params) {
|
|
57
43
|
return this.paginator.paginate({ url: "/team", params });
|
|
@@ -65,12 +51,8 @@ class FaableAuthApi {
|
|
|
65
51
|
},
|
|
66
52
|
});
|
|
67
53
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
validateStatus: () => true,
|
|
71
|
-
});
|
|
72
|
-
// Check access via status
|
|
73
|
-
return members_res.status == 200;
|
|
54
|
+
isUserMemberOfTeam(user_id, team_id) {
|
|
55
|
+
return this.fetcher.check(`/team/${team_id}/member/check/${user_id}`);
|
|
74
56
|
}
|
|
75
57
|
}
|
|
76
58
|
exports.FaableAuthApi = FaableAuthApi;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleErrorInterceptor = exports.FaableApiError = void 0;
|
|
4
|
+
class FaableApiError extends Error {
|
|
5
|
+
constructor(msg) {
|
|
6
|
+
super(msg);
|
|
7
|
+
this.name = "FaableApiError";
|
|
8
|
+
Object.setPrototypeOf(this, FaableApiError.prototype);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.FaableApiError = FaableApiError;
|
|
12
|
+
const handleErrorInterceptor = async (e) => {
|
|
13
|
+
const data = e.response?.data;
|
|
14
|
+
throw new FaableApiError(`FaableApiError: ${data?.message} (status=${e.response?.status}, url=${e.response?.config.url})`);
|
|
15
|
+
};
|
|
16
|
+
exports.handleErrorInterceptor = handleErrorInterceptor;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
2
|
+
export type Fetcher = ReturnType<typeof fetcher_axios>;
|
|
3
|
+
export declare const fetcher_axios: (instance: AxiosInstance) => {
|
|
4
|
+
get: <T>(url: string) => Promise<T>;
|
|
5
|
+
post: <T_1>(url: string, data: any) => Promise<T_1>;
|
|
6
|
+
request: <T_2>(params: AxiosRequestConfig) => Promise<T_2>;
|
|
7
|
+
check: <T_3>(url: string) => Promise<boolean>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetcher_axios = void 0;
|
|
4
|
+
const error_handler_1 = require("./error_handler");
|
|
5
|
+
const fetcher_axios = (instance) => {
|
|
6
|
+
// Add base interceptor
|
|
7
|
+
instance.interceptors.response.use((res) => {
|
|
8
|
+
console.log(`Request ${res.config.url}`);
|
|
9
|
+
return res;
|
|
10
|
+
}, error_handler_1.handleErrorInterceptor);
|
|
11
|
+
return {
|
|
12
|
+
get: async (url) => {
|
|
13
|
+
const res = await instance.request({
|
|
14
|
+
method: "GET",
|
|
15
|
+
url,
|
|
16
|
+
});
|
|
17
|
+
return res.data;
|
|
18
|
+
},
|
|
19
|
+
post: async (url, data) => {
|
|
20
|
+
const res = await instance.request({
|
|
21
|
+
method: "GET",
|
|
22
|
+
url,
|
|
23
|
+
data,
|
|
24
|
+
});
|
|
25
|
+
return res.data;
|
|
26
|
+
},
|
|
27
|
+
request: async (params) => {
|
|
28
|
+
const res = await instance.request(params);
|
|
29
|
+
return res.data;
|
|
30
|
+
},
|
|
31
|
+
check: async (url) => {
|
|
32
|
+
const res = await instance.request({
|
|
33
|
+
method: "GET",
|
|
34
|
+
url,
|
|
35
|
+
validateStatus: () => true,
|
|
36
|
+
});
|
|
37
|
+
return res.status == 200;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
exports.fetcher_axios = fetcher_axios;
|
package/dist/paginator.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosRequestConfig } from "axios";
|
|
2
|
+
import { Fetcher } from "./fetcher_axios";
|
|
2
3
|
export interface Page<T> {
|
|
3
4
|
next: string | null;
|
|
4
5
|
results: T[];
|
|
5
6
|
}
|
|
6
7
|
export declare class FaablePaginator {
|
|
7
|
-
client:
|
|
8
|
-
constructor(client:
|
|
8
|
+
client: Fetcher;
|
|
9
|
+
constructor(client: Fetcher);
|
|
9
10
|
paginate<T>(req: AxiosRequestConfig): {
|
|
10
11
|
all: () => Promise<T[]>;
|
|
11
12
|
first: () => Promise<Page<T>>;
|
|
13
|
+
pass: (params?: {
|
|
14
|
+
cursor?: string;
|
|
15
|
+
pageSize?: string;
|
|
16
|
+
}) => Promise<Page<T>>;
|
|
12
17
|
};
|
|
13
18
|
}
|
package/dist/paginator.js
CHANGED
|
@@ -10,19 +10,27 @@ class FaablePaginator {
|
|
|
10
10
|
return {
|
|
11
11
|
all: async () => {
|
|
12
12
|
const pages = [];
|
|
13
|
-
let
|
|
13
|
+
let data;
|
|
14
14
|
do {
|
|
15
|
-
|
|
15
|
+
data = await this.client.request({
|
|
16
16
|
...req,
|
|
17
|
-
params: { ...req.params, next:
|
|
17
|
+
params: { ...req.params, next: data && data?.next },
|
|
18
18
|
});
|
|
19
|
-
pages.push(
|
|
20
|
-
} while (
|
|
19
|
+
pages.push(data);
|
|
20
|
+
} while (data.next);
|
|
21
21
|
return pages.map((page) => page.results).flat();
|
|
22
22
|
},
|
|
23
23
|
first: async () => {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
return this.client.request(req);
|
|
25
|
+
},
|
|
26
|
+
pass: async (params = {}) => {
|
|
27
|
+
return this.client.request({
|
|
28
|
+
...req,
|
|
29
|
+
params: {
|
|
30
|
+
...req.params,
|
|
31
|
+
...params,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
26
34
|
},
|
|
27
35
|
};
|
|
28
36
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faable/auth-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"author": "Marc Pomar <marc@faable.com>",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,15 +16,30 @@
|
|
|
16
16
|
"@ava/typescript": "^5.0.0",
|
|
17
17
|
"@types/node": "^20.10.5",
|
|
18
18
|
"ava": "^6.1.3",
|
|
19
|
+
"dotenv": "^16.4.5",
|
|
19
20
|
"openapi-typescript": "^6.7.3",
|
|
20
21
|
"rimraf": "^5.0.5",
|
|
21
22
|
"semantic-release": "^22.0.12",
|
|
23
|
+
"tsimp": "^2.0.11",
|
|
22
24
|
"typescript": "^5.3.3"
|
|
23
25
|
},
|
|
26
|
+
"ava": {
|
|
27
|
+
"extensions": {
|
|
28
|
+
"ts": "module"
|
|
29
|
+
},
|
|
30
|
+
"require": [
|
|
31
|
+
"dotenv/config"
|
|
32
|
+
],
|
|
33
|
+
"nodeArguments": [
|
|
34
|
+
"--import=tsimp"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
24
37
|
"scripts": {
|
|
25
38
|
"gentypes": "openapi-typescript https://faable.auth.faable.link/docs/json -o src/types/api.ts",
|
|
26
39
|
"build": "rimraf dist && tsc",
|
|
27
|
-
"
|
|
40
|
+
"prebuild": "npm run gentypes",
|
|
41
|
+
"prepublishOnly": "npm run build",
|
|
42
|
+
"test": "ava",
|
|
28
43
|
"release": "semantic-release"
|
|
29
44
|
},
|
|
30
45
|
"resolutions": {
|
package/tsconfig.json
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
"module": "CommonJS",
|
|
7
7
|
"allowJs": false,
|
|
8
8
|
"outDir": "dist",
|
|
9
|
-
"resolveJsonModule":
|
|
10
|
-
"
|
|
11
|
-
"
|
|
9
|
+
"resolveJsonModule": false,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"strict": true
|
|
12
12
|
},
|
|
13
13
|
"include": ["src/**/*"],
|
|
14
14
|
"exclude": ["src/**/*.test.ts"]
|