@faable/faable 1.5.16 → 1.5.17-next.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/dist/api/FaableApi.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
|
-
import {
|
|
2
|
+
import { base_client } from './base_client.js';
|
|
3
3
|
|
|
4
|
-
function handleError(
|
|
4
|
+
function handleError() {
|
|
5
5
|
return function (target, propertyKey, descriptor) {
|
|
6
6
|
const method = descriptor.value;
|
|
7
7
|
descriptor.value = async function (...args) {
|
|
@@ -13,10 +13,10 @@ function handleError(message) {
|
|
|
13
13
|
if (e.isAxiosError) {
|
|
14
14
|
const res = e.response;
|
|
15
15
|
if (res) {
|
|
16
|
-
throw new Error(`FaableApi ${e.config.url} ${res.status}: ${res?.data.message}
|
|
16
|
+
throw new Error(`FaableApi ${e.config.url} ${res.status}: ${res?.data.message}`, { cause: error });
|
|
17
17
|
}
|
|
18
18
|
else {
|
|
19
|
-
throw new Error(`FaableApi ${e.message}
|
|
19
|
+
throw new Error(`FaableApi ${e.message}`, { cause: error });
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
throw error;
|
|
@@ -35,7 +35,20 @@ const data = async (res) => {
|
|
|
35
35
|
class FaableApi {
|
|
36
36
|
client;
|
|
37
37
|
constructor(config) {
|
|
38
|
-
|
|
38
|
+
const { authStrategy, auth } = config;
|
|
39
|
+
this.client = base_client;
|
|
40
|
+
const strategy = authStrategy && authStrategy(auth);
|
|
41
|
+
this.client.interceptors.request.use(async function (config) {
|
|
42
|
+
// Do something before request is sent
|
|
43
|
+
const headers = strategy ? await strategy.headers() : {};
|
|
44
|
+
config.headers.set(headers);
|
|
45
|
+
// console.log("all headers");
|
|
46
|
+
// console.log(headers);
|
|
47
|
+
return config;
|
|
48
|
+
}, function (error) {
|
|
49
|
+
// Do something with request error
|
|
50
|
+
return Promise.reject(error);
|
|
51
|
+
});
|
|
39
52
|
}
|
|
40
53
|
static create(config = {}) {
|
|
41
54
|
return new FaableApi(config);
|
|
@@ -1,12 +1,27 @@
|
|
|
1
|
+
import { base_client } from '../base_client.js';
|
|
2
|
+
|
|
3
|
+
const exchangeGithubOidcToken = async (gh_token) => {
|
|
4
|
+
const res = await base_client.post("/auth/github-oidc", {
|
|
5
|
+
token: gh_token
|
|
6
|
+
});
|
|
7
|
+
const { token } = res.data;
|
|
8
|
+
console.log("Obtained github token exchange");
|
|
9
|
+
console.log(token);
|
|
10
|
+
return token;
|
|
11
|
+
};
|
|
1
12
|
const oidc_strategy = (config) => {
|
|
2
13
|
const { idToken } = config;
|
|
3
14
|
if (!idToken) {
|
|
4
15
|
throw new Error("Missing idToken.");
|
|
5
16
|
}
|
|
17
|
+
let token = "";
|
|
6
18
|
return {
|
|
7
19
|
headers: async () => {
|
|
20
|
+
if (!token) {
|
|
21
|
+
token = await exchangeGithubOidcToken(idToken);
|
|
22
|
+
}
|
|
8
23
|
return {
|
|
9
|
-
Authorization: `Bearer ${
|
|
24
|
+
Authorization: `Bearer ${token}`,
|
|
10
25
|
};
|
|
11
26
|
},
|
|
12
27
|
};
|
package/package.json
CHANGED
package/dist/api/client.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
function prepare_client({ authStrategy, auth, } = {}) {
|
|
4
|
-
const strategy = authStrategy && authStrategy(auth);
|
|
5
|
-
const client = axios.create({
|
|
6
|
-
baseURL: "https://api.faable.com",
|
|
7
|
-
timeout: 10000,
|
|
8
|
-
});
|
|
9
|
-
client.interceptors.request.use(async function (config) {
|
|
10
|
-
// Do something before request is sent
|
|
11
|
-
const headers = strategy ? await strategy.headers() : {};
|
|
12
|
-
config.headers.set(headers);
|
|
13
|
-
// console.log("all headers");
|
|
14
|
-
// console.log(headers);
|
|
15
|
-
return config;
|
|
16
|
-
}, function (error) {
|
|
17
|
-
// Do something with request error
|
|
18
|
-
return Promise.reject(error);
|
|
19
|
-
});
|
|
20
|
-
return client;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { prepare_client };
|