@deliverart/sdk-js-authentication 1.2.1 → 2.0.0
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.cjs +13 -9
- package/dist/index.js +13 -9
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -40,16 +40,20 @@ var AuthenticationPlugin = class {
|
|
|
40
40
|
this.config = config;
|
|
41
41
|
}
|
|
42
42
|
setup(client) {
|
|
43
|
-
client.
|
|
44
|
-
if (!this.enabled)
|
|
45
|
-
return config;
|
|
46
|
-
}
|
|
43
|
+
client.addRequestMiddleware(async (ctx) => {
|
|
44
|
+
if (!this.enabled) return ctx;
|
|
47
45
|
const token = await this.config.getAccessToken();
|
|
48
|
-
if (!token)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
if (!token) throw new AuthenticationError("No access token found. Please authenticate first.");
|
|
47
|
+
return {
|
|
48
|
+
...ctx,
|
|
49
|
+
init: {
|
|
50
|
+
...ctx.init,
|
|
51
|
+
headers: {
|
|
52
|
+
...ctx.init.headers,
|
|
53
|
+
Authorization: `Bearer ${token}`
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
53
57
|
});
|
|
54
58
|
return {
|
|
55
59
|
authentication: {
|
package/dist/index.js
CHANGED
|
@@ -13,16 +13,20 @@ var AuthenticationPlugin = class {
|
|
|
13
13
|
this.config = config;
|
|
14
14
|
}
|
|
15
15
|
setup(client) {
|
|
16
|
-
client.
|
|
17
|
-
if (!this.enabled)
|
|
18
|
-
return config;
|
|
19
|
-
}
|
|
16
|
+
client.addRequestMiddleware(async (ctx) => {
|
|
17
|
+
if (!this.enabled) return ctx;
|
|
20
18
|
const token = await this.config.getAccessToken();
|
|
21
|
-
if (!token)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
if (!token) throw new AuthenticationError("No access token found. Please authenticate first.");
|
|
20
|
+
return {
|
|
21
|
+
...ctx,
|
|
22
|
+
init: {
|
|
23
|
+
...ctx.init,
|
|
24
|
+
headers: {
|
|
25
|
+
...ctx.init.headers,
|
|
26
|
+
Authorization: `Bearer ${token}`
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
26
30
|
});
|
|
27
31
|
return {
|
|
28
32
|
authentication: {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deliverart/sdk-js-authentication",
|
|
3
3
|
"description": "Authentication module for DeliverArt SDK",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@deliverart/sdk-js-core": "
|
|
21
|
+
"@deliverart/sdk-js-core": "2.0.0"
|
|
22
22
|
},
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public"
|