@faable/auth-sdk 1.0.17 → 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 +106 -105
- 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 +4 -3
- package/dist/paginator.js +7 -9
- 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,29 +69,29 @@ export declare class FaableAuthApi {
|
|
|
68
69
|
};
|
|
69
70
|
account: string;
|
|
70
71
|
createdAt: string;
|
|
71
|
-
updatedAt?: string;
|
|
72
|
+
updatedAt?: string | undefined;
|
|
72
73
|
}>>;
|
|
73
74
|
pass: (params?: {
|
|
74
|
-
cursor?: string;
|
|
75
|
-
pageSize?: string;
|
|
75
|
+
cursor?: string | undefined;
|
|
76
|
+
pageSize?: string | undefined;
|
|
76
77
|
}) => Promise<Page<{
|
|
77
78
|
id: string;
|
|
78
|
-
name?: string;
|
|
79
|
-
username?: string;
|
|
80
|
-
given_name?: string;
|
|
81
|
-
family_name?: string;
|
|
82
|
-
email?: 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;
|
|
83
84
|
email_verified: boolean;
|
|
84
|
-
phone?: string;
|
|
85
|
+
phone?: string | null | undefined;
|
|
85
86
|
phone_verified: boolean;
|
|
86
|
-
country_iso?: string;
|
|
87
|
-
birth_date?: string;
|
|
87
|
+
country_iso?: string | null | undefined;
|
|
88
|
+
birth_date?: string | null | undefined;
|
|
88
89
|
locale: string;
|
|
89
|
-
region?: string;
|
|
90
|
-
picture?: string;
|
|
90
|
+
region?: string | null | undefined;
|
|
91
|
+
picture?: string | null | undefined;
|
|
91
92
|
logins_count: number;
|
|
92
|
-
last_ip?: string;
|
|
93
|
-
last_login?: string;
|
|
93
|
+
last_ip?: string | null | undefined;
|
|
94
|
+
last_login?: string | null | undefined;
|
|
94
95
|
user_metadata: {
|
|
95
96
|
[key: string]: unknown;
|
|
96
97
|
};
|
|
@@ -99,27 +100,27 @@ export declare class FaableAuthApi {
|
|
|
99
100
|
};
|
|
100
101
|
account: string;
|
|
101
102
|
createdAt: string;
|
|
102
|
-
updatedAt?: string;
|
|
103
|
+
updatedAt?: string | undefined;
|
|
103
104
|
}>>;
|
|
104
105
|
};
|
|
105
|
-
getUser(user_id:
|
|
106
|
+
getUser(user_id: string): Promise<{
|
|
106
107
|
id: string;
|
|
107
|
-
name?: string;
|
|
108
|
-
username?: string;
|
|
109
|
-
given_name?: string;
|
|
110
|
-
family_name?: string;
|
|
111
|
-
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;
|
|
112
113
|
email_verified: boolean;
|
|
113
|
-
phone?: string;
|
|
114
|
+
phone?: string | null | undefined;
|
|
114
115
|
phone_verified: boolean;
|
|
115
|
-
country_iso?: string;
|
|
116
|
-
birth_date?: string;
|
|
116
|
+
country_iso?: string | null | undefined;
|
|
117
|
+
birth_date?: string | null | undefined;
|
|
117
118
|
locale: string;
|
|
118
|
-
region?: string;
|
|
119
|
-
picture?: string;
|
|
119
|
+
region?: string | null | undefined;
|
|
120
|
+
picture?: string | null | undefined;
|
|
120
121
|
logins_count: number;
|
|
121
|
-
last_ip?: string;
|
|
122
|
-
last_login?: string;
|
|
122
|
+
last_ip?: string | null | undefined;
|
|
123
|
+
last_login?: string | null | undefined;
|
|
123
124
|
user_metadata: {
|
|
124
125
|
[key: string]: unknown;
|
|
125
126
|
};
|
|
@@ -128,26 +129,26 @@ export declare class FaableAuthApi {
|
|
|
128
129
|
};
|
|
129
130
|
account: string;
|
|
130
131
|
createdAt: string;
|
|
131
|
-
updatedAt?: string;
|
|
132
|
+
updatedAt?: string | undefined;
|
|
132
133
|
}>;
|
|
133
134
|
createUser(data: UserCreate): Promise<{
|
|
134
135
|
id: string;
|
|
135
|
-
name?: string;
|
|
136
|
-
username?: string;
|
|
137
|
-
given_name?: string;
|
|
138
|
-
family_name?: string;
|
|
139
|
-
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;
|
|
140
141
|
email_verified: boolean;
|
|
141
|
-
phone?: string;
|
|
142
|
+
phone?: string | null | undefined;
|
|
142
143
|
phone_verified: boolean;
|
|
143
|
-
country_iso?: string;
|
|
144
|
-
birth_date?: string;
|
|
144
|
+
country_iso?: string | null | undefined;
|
|
145
|
+
birth_date?: string | null | undefined;
|
|
145
146
|
locale: string;
|
|
146
|
-
region?: string;
|
|
147
|
-
picture?: string;
|
|
147
|
+
region?: string | null | undefined;
|
|
148
|
+
picture?: string | null | undefined;
|
|
148
149
|
logins_count: number;
|
|
149
|
-
last_ip?: string;
|
|
150
|
-
last_login?: string;
|
|
150
|
+
last_ip?: string | null | undefined;
|
|
151
|
+
last_login?: string | null | undefined;
|
|
151
152
|
user_metadata: {
|
|
152
153
|
[key: string]: unknown;
|
|
153
154
|
};
|
|
@@ -156,26 +157,26 @@ export declare class FaableAuthApi {
|
|
|
156
157
|
};
|
|
157
158
|
account: string;
|
|
158
159
|
createdAt: string;
|
|
159
|
-
updatedAt?: string;
|
|
160
|
+
updatedAt?: string | undefined;
|
|
160
161
|
}>;
|
|
161
162
|
updateUser(user_id: string, data: UserUpdate): Promise<{
|
|
162
163
|
id: string;
|
|
163
|
-
name?: string;
|
|
164
|
-
username?: string;
|
|
165
|
-
given_name?: string;
|
|
166
|
-
family_name?: string;
|
|
167
|
-
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;
|
|
168
169
|
email_verified: boolean;
|
|
169
|
-
phone?: string;
|
|
170
|
+
phone?: string | null | undefined;
|
|
170
171
|
phone_verified: boolean;
|
|
171
|
-
country_iso?: string;
|
|
172
|
-
birth_date?: string;
|
|
172
|
+
country_iso?: string | null | undefined;
|
|
173
|
+
birth_date?: string | null | undefined;
|
|
173
174
|
locale: string;
|
|
174
|
-
region?: string;
|
|
175
|
-
picture?: string;
|
|
175
|
+
region?: string | null | undefined;
|
|
176
|
+
picture?: string | null | undefined;
|
|
176
177
|
logins_count: number;
|
|
177
|
-
last_ip?: string;
|
|
178
|
-
last_login?: string;
|
|
178
|
+
last_ip?: string | null | undefined;
|
|
179
|
+
last_login?: string | null | undefined;
|
|
179
180
|
user_metadata: {
|
|
180
181
|
[key: string]: unknown;
|
|
181
182
|
};
|
|
@@ -184,33 +185,33 @@ export declare class FaableAuthApi {
|
|
|
184
185
|
};
|
|
185
186
|
account: string;
|
|
186
187
|
createdAt: string;
|
|
187
|
-
updatedAt?: string;
|
|
188
|
+
updatedAt?: string | undefined;
|
|
188
189
|
}>;
|
|
189
|
-
getTeam(team_id:
|
|
190
|
+
getTeam(team_id: string): Promise<{
|
|
190
191
|
id: string;
|
|
191
192
|
name: string;
|
|
192
193
|
slug: string;
|
|
193
|
-
description: string;
|
|
194
|
-
logo_url: string;
|
|
194
|
+
description: string | null;
|
|
195
|
+
logo_url: string | null;
|
|
195
196
|
metadata: {
|
|
196
197
|
[key: string]: unknown;
|
|
197
198
|
};
|
|
198
199
|
account: string;
|
|
199
200
|
createdAt: string;
|
|
200
|
-
updatedAt?: string;
|
|
201
|
+
updatedAt?: string | undefined;
|
|
201
202
|
}>;
|
|
202
203
|
createTeam(data: TeamCreate): Promise<{
|
|
203
204
|
id: string;
|
|
204
205
|
name: string;
|
|
205
206
|
slug: string;
|
|
206
|
-
description: string;
|
|
207
|
-
logo_url: string;
|
|
207
|
+
description: string | null;
|
|
208
|
+
logo_url: string | null;
|
|
208
209
|
metadata: {
|
|
209
210
|
[key: string]: unknown;
|
|
210
211
|
};
|
|
211
212
|
account: string;
|
|
212
213
|
createdAt: string;
|
|
213
|
-
updatedAt?: string;
|
|
214
|
+
updatedAt?: string | undefined;
|
|
214
215
|
}>;
|
|
215
216
|
listTeams(params?: {
|
|
216
217
|
user_id?: string;
|
|
@@ -219,43 +220,43 @@ export declare class FaableAuthApi {
|
|
|
219
220
|
id: string;
|
|
220
221
|
name: string;
|
|
221
222
|
slug: string;
|
|
222
|
-
description: string;
|
|
223
|
-
logo_url: string;
|
|
223
|
+
description: string | null;
|
|
224
|
+
logo_url: string | null;
|
|
224
225
|
metadata: {
|
|
225
226
|
[key: string]: unknown;
|
|
226
227
|
};
|
|
227
228
|
account: string;
|
|
228
229
|
createdAt: string;
|
|
229
|
-
updatedAt?: string;
|
|
230
|
+
updatedAt?: string | undefined;
|
|
230
231
|
}[]>;
|
|
231
232
|
first: () => Promise<Page<{
|
|
232
233
|
id: string;
|
|
233
234
|
name: string;
|
|
234
235
|
slug: string;
|
|
235
|
-
description: string;
|
|
236
|
-
logo_url: string;
|
|
236
|
+
description: string | null;
|
|
237
|
+
logo_url: string | null;
|
|
237
238
|
metadata: {
|
|
238
239
|
[key: string]: unknown;
|
|
239
240
|
};
|
|
240
241
|
account: string;
|
|
241
242
|
createdAt: string;
|
|
242
|
-
updatedAt?: string;
|
|
243
|
+
updatedAt?: string | undefined;
|
|
243
244
|
}>>;
|
|
244
245
|
pass: (params?: {
|
|
245
|
-
cursor?: string;
|
|
246
|
-
pageSize?: string;
|
|
246
|
+
cursor?: string | undefined;
|
|
247
|
+
pageSize?: string | undefined;
|
|
247
248
|
}) => Promise<Page<{
|
|
248
249
|
id: string;
|
|
249
250
|
name: string;
|
|
250
251
|
slug: string;
|
|
251
|
-
description: string;
|
|
252
|
-
logo_url: string;
|
|
252
|
+
description: string | null;
|
|
253
|
+
logo_url: string | null;
|
|
253
254
|
metadata: {
|
|
254
255
|
[key: string]: unknown;
|
|
255
256
|
};
|
|
256
257
|
account: string;
|
|
257
258
|
createdAt: string;
|
|
258
|
-
updatedAt?: string;
|
|
259
|
+
updatedAt?: string | undefined;
|
|
259
260
|
}>>;
|
|
260
261
|
};
|
|
261
262
|
listTeamMembers(params: {
|
|
@@ -271,7 +272,7 @@ export declare class FaableAuthApi {
|
|
|
271
272
|
};
|
|
272
273
|
account: string;
|
|
273
274
|
createdAt: string;
|
|
274
|
-
updatedAt?: string;
|
|
275
|
+
updatedAt?: string | undefined;
|
|
275
276
|
}[]>;
|
|
276
277
|
first: () => Promise<Page<{
|
|
277
278
|
id: string;
|
|
@@ -283,11 +284,11 @@ export declare class FaableAuthApi {
|
|
|
283
284
|
};
|
|
284
285
|
account: string;
|
|
285
286
|
createdAt: string;
|
|
286
|
-
updatedAt?: string;
|
|
287
|
+
updatedAt?: string | undefined;
|
|
287
288
|
}>>;
|
|
288
289
|
pass: (params?: {
|
|
289
|
-
cursor?: string;
|
|
290
|
-
pageSize?: string;
|
|
290
|
+
cursor?: string | undefined;
|
|
291
|
+
pageSize?: string | undefined;
|
|
291
292
|
}) => Promise<Page<{
|
|
292
293
|
id: string;
|
|
293
294
|
user: unknown;
|
|
@@ -298,7 +299,7 @@ export declare class FaableAuthApi {
|
|
|
298
299
|
};
|
|
299
300
|
account: string;
|
|
300
301
|
createdAt: string;
|
|
301
|
-
updatedAt?: string;
|
|
302
|
+
updatedAt?: string | undefined;
|
|
302
303
|
}>>;
|
|
303
304
|
};
|
|
304
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,11 +1,12 @@
|
|
|
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>>;
|
package/dist/paginator.js
CHANGED
|
@@ -10,29 +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
|
-
return res.data;
|
|
24
|
+
return this.client.request(req);
|
|
26
25
|
},
|
|
27
26
|
pass: async (params = {}) => {
|
|
28
|
-
|
|
27
|
+
return this.client.request({
|
|
29
28
|
...req,
|
|
30
29
|
params: {
|
|
31
30
|
...req.params,
|
|
32
31
|
...params,
|
|
33
32
|
},
|
|
34
33
|
});
|
|
35
|
-
return res.data;
|
|
36
34
|
},
|
|
37
35
|
};
|
|
38
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"]
|