@deliverart/sdk-js-authentication 1.1.0 → 1.1.2
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 +70 -0
- package/dist/index.d.cts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +42 -0
- package/package.json +2 -2
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AuthenticationError: () => AuthenticationError,
|
|
24
|
+
AuthenticationPlugin: () => AuthenticationPlugin
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/errors.ts
|
|
29
|
+
var AuthenticationError = class extends Error {
|
|
30
|
+
constructor(message = "Authentication failed") {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = "AuthenticationError";
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/plugin.ts
|
|
37
|
+
var AuthenticationPlugin = class {
|
|
38
|
+
constructor(config) {
|
|
39
|
+
this.enabled = true;
|
|
40
|
+
this.config = config;
|
|
41
|
+
}
|
|
42
|
+
setup(client) {
|
|
43
|
+
client.http.interceptors.request.use(async (config) => {
|
|
44
|
+
if (!this.enabled) {
|
|
45
|
+
return config;
|
|
46
|
+
}
|
|
47
|
+
const token = await this.config.getAccessToken();
|
|
48
|
+
if (!token) {
|
|
49
|
+
throw new AuthenticationError("No access token found. Please authenticate first.");
|
|
50
|
+
}
|
|
51
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
52
|
+
return config;
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
authentication: {
|
|
56
|
+
enable: () => {
|
|
57
|
+
this.enabled = true;
|
|
58
|
+
},
|
|
59
|
+
disable: () => {
|
|
60
|
+
this.enabled = false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
AuthenticationError,
|
|
69
|
+
AuthenticationPlugin
|
|
70
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ApiExtension, ApiClientPlugin, ApiClient } from '@deliverart/sdk-js-core';
|
|
2
|
+
|
|
3
|
+
declare class AuthenticationError extends Error {
|
|
4
|
+
constructor(message?: string);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface AuthenticationConfig {
|
|
8
|
+
getAccessToken: () => Promise<string | null>;
|
|
9
|
+
}
|
|
10
|
+
interface AuthenticationExtension extends ApiExtension {
|
|
11
|
+
authentication: {
|
|
12
|
+
enable: () => void;
|
|
13
|
+
disable: () => void;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare class AuthenticationPlugin implements ApiClientPlugin<AuthenticationExtension> {
|
|
18
|
+
private readonly config;
|
|
19
|
+
private enabled;
|
|
20
|
+
constructor(config: AuthenticationConfig);
|
|
21
|
+
setup(client: ApiClient): AuthenticationExtension;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { type AuthenticationConfig, AuthenticationError, type AuthenticationExtension, AuthenticationPlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ApiExtension, ApiClientPlugin, ApiClient } from '@deliverart/sdk-js-core';
|
|
2
|
+
|
|
3
|
+
declare class AuthenticationError extends Error {
|
|
4
|
+
constructor(message?: string);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface AuthenticationConfig {
|
|
8
|
+
getAccessToken: () => Promise<string | null>;
|
|
9
|
+
}
|
|
10
|
+
interface AuthenticationExtension extends ApiExtension {
|
|
11
|
+
authentication: {
|
|
12
|
+
enable: () => void;
|
|
13
|
+
disable: () => void;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare class AuthenticationPlugin implements ApiClientPlugin<AuthenticationExtension> {
|
|
18
|
+
private readonly config;
|
|
19
|
+
private enabled;
|
|
20
|
+
constructor(config: AuthenticationConfig);
|
|
21
|
+
setup(client: ApiClient): AuthenticationExtension;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { type AuthenticationConfig, AuthenticationError, type AuthenticationExtension, AuthenticationPlugin };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var AuthenticationError = class extends Error {
|
|
3
|
+
constructor(message = "Authentication failed") {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "AuthenticationError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/plugin.ts
|
|
10
|
+
var AuthenticationPlugin = class {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.enabled = true;
|
|
13
|
+
this.config = config;
|
|
14
|
+
}
|
|
15
|
+
setup(client) {
|
|
16
|
+
client.http.interceptors.request.use(async (config) => {
|
|
17
|
+
if (!this.enabled) {
|
|
18
|
+
return config;
|
|
19
|
+
}
|
|
20
|
+
const token = await this.config.getAccessToken();
|
|
21
|
+
if (!token) {
|
|
22
|
+
throw new AuthenticationError("No access token found. Please authenticate first.");
|
|
23
|
+
}
|
|
24
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
25
|
+
return config;
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
authentication: {
|
|
29
|
+
enable: () => {
|
|
30
|
+
this.enabled = true;
|
|
31
|
+
},
|
|
32
|
+
disable: () => {
|
|
33
|
+
this.enabled = false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
AuthenticationError,
|
|
41
|
+
AuthenticationPlugin
|
|
42
|
+
};
|
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": "1.1.
|
|
4
|
+
"version": "1.1.2",
|
|
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": "1.1.
|
|
21
|
+
"@deliverart/sdk-js-core": "1.1.2"
|
|
22
22
|
},
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public"
|