@or-sdk/authorizer 0.24.14-beta.971.0 → 0.24.14
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/CHANGELOG.md +8 -0
- package/dist/cjs/Basic/BasicAuth.js +162 -0
- package/dist/cjs/Basic/BasicAuth.js.map +1 -0
- package/dist/cjs/Basic/BasicCollection.js +24 -117
- package/dist/cjs/Basic/BasicCollection.js.map +1 -1
- package/dist/cjs/OAuth/OAuth.js +49 -78
- package/dist/cjs/OAuth/OAuth.js.map +1 -1
- package/dist/cjs/OAuth/OAuthCollection.js +10 -25
- package/dist/cjs/OAuth/OAuthCollection.js.map +1 -1
- package/dist/cjs/OAuth/types.js.map +1 -1
- package/dist/cjs/Token/TokenAuth.js +140 -0
- package/dist/cjs/Token/TokenAuth.js.map +1 -0
- package/dist/cjs/Token/TokenCollection.js +22 -88
- package/dist/cjs/Token/TokenCollection.js.map +1 -1
- package/dist/cjs/index.js +13 -8
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/Basic/BasicAuth.js +88 -0
- package/dist/esm/Basic/BasicAuth.js.map +1 -0
- package/dist/esm/Basic/BasicCollection.js +21 -83
- package/dist/esm/Basic/BasicCollection.js.map +1 -1
- package/dist/esm/OAuth/OAuth.js +35 -60
- package/dist/esm/OAuth/OAuth.js.map +1 -1
- package/dist/esm/OAuth/OAuthCollection.js +10 -24
- package/dist/esm/OAuth/OAuthCollection.js.map +1 -1
- package/dist/esm/OAuth/types.js.map +1 -1
- package/dist/esm/Token/TokenAuth.js +66 -0
- package/dist/esm/Token/TokenAuth.js.map +1 -0
- package/dist/esm/Token/TokenCollection.js +20 -55
- package/dist/esm/Token/TokenCollection.js.map +1 -1
- package/dist/esm/index.js +6 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/types/Basic/BasicAuth.d.ts +20 -0
- package/dist/types/Basic/BasicAuth.d.ts.map +1 -0
- package/dist/types/Basic/BasicCollection.d.ts +7 -17
- package/dist/types/Basic/BasicCollection.d.ts.map +1 -1
- package/dist/types/Basic/types.d.ts +1 -3
- package/dist/types/Basic/types.d.ts.map +1 -1
- package/dist/types/OAuth/OAuth.d.ts +1 -1
- package/dist/types/OAuth/OAuth.d.ts.map +1 -1
- package/dist/types/OAuth/OAuthCollection.d.ts +6 -9
- package/dist/types/OAuth/OAuthCollection.d.ts.map +1 -1
- package/dist/types/OAuth/types.d.ts +1 -9
- package/dist/types/OAuth/types.d.ts.map +1 -1
- package/dist/types/Token/TokenAuth.d.ts +12 -0
- package/dist/types/Token/TokenAuth.d.ts.map +1 -0
- package/dist/types/Token/TokenCollection.d.ts +8 -9
- package/dist/types/Token/TokenCollection.d.ts.map +1 -1
- package/dist/types/Token/types.d.ts +0 -2
- package/dist/types/Token/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +6 -3
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +6 -38
- package/src/Basic/BasicAuth.ts +129 -0
- package/src/Basic/BasicCollection.ts +30 -141
- package/src/Basic/types.ts +1 -3
- package/src/OAuth/OAuth.ts +51 -109
- package/src/OAuth/OAuthCollection.ts +18 -48
- package/src/OAuth/types.ts +3 -32
- package/src/Token/TokenAuth.ts +102 -0
- package/src/Token/TokenCollection.ts +28 -98
- package/src/Token/types.ts +0 -2
- package/src/index.ts +8 -3
- package/dist/cjs/Basic/index.js +0 -21
- package/dist/cjs/Basic/index.js.map +0 -1
- package/dist/cjs/OAuth/index.js +0 -23
- package/dist/cjs/OAuth/index.js.map +0 -1
- package/dist/cjs/Token/index.js +0 -21
- package/dist/cjs/Token/index.js.map +0 -1
- package/dist/esm/Basic/index.js +0 -3
- package/dist/esm/Basic/index.js.map +0 -1
- package/dist/esm/OAuth/index.js +0 -4
- package/dist/esm/OAuth/index.js.map +0 -1
- package/dist/esm/Token/index.js +0 -3
- package/dist/esm/Token/index.js.map +0 -1
- package/dist/types/Basic/index.d.ts +0 -3
- package/dist/types/Basic/index.d.ts.map +0 -1
- package/dist/types/OAuth/index.d.ts +0 -4
- package/dist/types/OAuth/index.d.ts.map +0 -1
- package/dist/types/Token/index.d.ts +0 -3
- package/dist/types/Token/index.d.ts.map +0 -1
- package/src/Basic/index.ts +0 -3
- package/src/OAuth/index.ts +0 -4
- package/src/Token/index.ts +0 -3
|
@@ -1,81 +1,62 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Token } from '@or-sdk/base';
|
|
2
2
|
import { KeyValueStorage } from '@or-sdk/key-value-storage';
|
|
3
|
-
import {
|
|
4
|
-
import { createAuthKey } from './utils/createAuthKey';
|
|
3
|
+
import { TokenAuth } from './TokenAuth';
|
|
5
4
|
|
|
6
5
|
import {
|
|
7
6
|
TokenCollectionConfig,
|
|
8
7
|
CreateTokenAuthInCollectionConfig,
|
|
9
|
-
TokenAuthData,
|
|
10
8
|
} from './types';
|
|
11
9
|
|
|
12
10
|
export class TokenCollection {
|
|
13
|
-
private serviceName: string;
|
|
11
|
+
private readonly serviceName: string;
|
|
14
12
|
private readonly keyValueStorage: KeyValueStorage;
|
|
13
|
+
private readonly localToken: Token;
|
|
14
|
+
private readonly localDiscoveryUrl: string;
|
|
15
15
|
|
|
16
16
|
constructor(params: TokenCollectionConfig) {
|
|
17
|
-
const { token, discoveryUrl, serviceName
|
|
17
|
+
const { token, discoveryUrl, serviceName } = params;
|
|
18
18
|
|
|
19
|
-
this.
|
|
19
|
+
this.localToken = token;
|
|
20
|
+
this.localDiscoveryUrl = discoveryUrl;
|
|
21
|
+
this.serviceName = serviceName;
|
|
20
22
|
this.keyValueStorage = new KeyValueStorage({
|
|
21
23
|
token,
|
|
22
24
|
discoveryUrl,
|
|
23
|
-
accountId,
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Allows to explicitly (re-)set authorization service name
|
|
30
|
-
*/
|
|
31
|
-
public init(serviceName: string) {
|
|
32
|
-
if (!serviceName) throw new Error('Servide name is required.');
|
|
33
|
-
|
|
34
|
-
this.serviceName = serviceName;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
28
|
/**
|
|
39
29
|
* Returns array of auth keys from this collection
|
|
40
30
|
*/
|
|
41
|
-
public async listAuthorizations(): Promise<
|
|
31
|
+
public async listAuthorizations(): Promise<string[]> {
|
|
42
32
|
const { items: records } = await this.keyValueStorage.listKeys(this.serviceName);
|
|
43
33
|
|
|
44
|
-
return
|
|
34
|
+
return records.map((record) => record.key);
|
|
45
35
|
}
|
|
46
36
|
|
|
47
37
|
/**
|
|
48
38
|
* Returns TokenAuth instance for given key
|
|
49
39
|
*/
|
|
50
|
-
public async getAuthorization(key: string): Promise<
|
|
51
|
-
|
|
52
|
-
if (!key.includes('::token')) throw new Error('The Token authorization key should contain "token" type specifier.');
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const record = await this.keyValueStorage.getValueByKey(this.serviceName, encodeURIComponent(key));
|
|
40
|
+
public async getAuthorization(key: string): Promise<TokenAuth> {
|
|
41
|
+
const record = await this.keyValueStorage.getValueByKey(this.serviceName, key);
|
|
56
42
|
if (!record.value) {
|
|
57
43
|
throw new Error('Authorization does not exist');
|
|
58
44
|
}
|
|
59
45
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
...authData,
|
|
68
|
-
key,
|
|
69
|
-
} as TokenAuthData;
|
|
46
|
+
return new TokenAuth({
|
|
47
|
+
serviceName: this.serviceName,
|
|
48
|
+
authKey: key,
|
|
49
|
+
discoveryUrl: this.localDiscoveryUrl,
|
|
50
|
+
token: this.localToken,
|
|
51
|
+
});
|
|
70
52
|
}
|
|
71
53
|
|
|
72
|
-
|
|
73
54
|
/**
|
|
74
55
|
* Creates a new auth record in current collection with the given config.
|
|
75
56
|
* @returns TokenCollection instance connected to created auth
|
|
76
57
|
*
|
|
77
58
|
* ```typescript
|
|
78
|
-
* const
|
|
59
|
+
* const tokenCollectionInstance = await tokenCollectionInstance.createAuthorization({
|
|
79
60
|
* authName: 'my-auth-name',
|
|
80
61
|
* credentials: {
|
|
81
62
|
* token: 'secrettoken'
|
|
@@ -85,64 +66,13 @@ export class TokenCollection {
|
|
|
85
66
|
*/
|
|
86
67
|
public async createAuthorization(
|
|
87
68
|
params: CreateTokenAuthInCollectionConfig
|
|
88
|
-
): Promise<
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const authData = {
|
|
98
|
-
...credentials,
|
|
99
|
-
auth_name: authName,
|
|
100
|
-
date_created: new Date().toISOString(),
|
|
101
|
-
} as Omit<TokenAuthData, 'key'>;
|
|
102
|
-
|
|
103
|
-
await this.keyValueStorage.setValueByKey(this.serviceName, encodeURIComponent(authKey), authData);
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
...authData,
|
|
107
|
-
key: authKey,
|
|
108
|
-
} as TokenAuthData;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Updates credentials
|
|
114
|
-
*/
|
|
115
|
-
public async updateAuthorization(
|
|
116
|
-
tokenAuth: TokenAuthData,
|
|
117
|
-
newCredentials: Record<string, unknown>
|
|
118
|
-
): Promise<TokenAuthData> {
|
|
119
|
-
if (!this.serviceName) throw new Error('Service name is not defined.');
|
|
120
|
-
if (!newCredentials) throw new Error('New credentials are empty or invalid');
|
|
121
|
-
if (!tokenAuth || !tokenAuth.auth_name || !tokenAuth.date_created)
|
|
122
|
-
throw new Error('Token authorization data is invalid');
|
|
123
|
-
|
|
124
|
-
const updatedData = {
|
|
125
|
-
...tokenAuth,
|
|
126
|
-
...newCredentials,
|
|
127
|
-
key: undefined,
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const response = await this.keyValueStorage.setValueByKey(this.serviceName, encodeURIComponent(tokenAuth.key), updatedData);
|
|
131
|
-
|
|
132
|
-
const updatedRecord = response.value as Omit<TokenAuthData, 'key'>;
|
|
133
|
-
return {
|
|
134
|
-
...updatedRecord,
|
|
135
|
-
key: tokenAuth.key,
|
|
136
|
-
} as TokenAuthData;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Deletes authorization from collection
|
|
142
|
-
*/
|
|
143
|
-
public async deleteAuthorization(key: string): Promise<void> {
|
|
144
|
-
if (!this.serviceName) throw new Error('Service name is not defined.');
|
|
145
|
-
if (!key) throw new Error('Key is missing or invalid');
|
|
146
|
-
await this.keyValueStorage.deleteKey(this.serviceName, encodeURIComponent(key));
|
|
69
|
+
): Promise<TokenAuth> {
|
|
70
|
+
return await TokenAuth.create({
|
|
71
|
+
discoveryUrl: this.localDiscoveryUrl,
|
|
72
|
+
token: this.localToken,
|
|
73
|
+
serviceName: this.serviceName,
|
|
74
|
+
authName: params.authName,
|
|
75
|
+
credentials: params.credentials,
|
|
76
|
+
});
|
|
147
77
|
}
|
|
148
78
|
}
|
package/src/Token/types.ts
CHANGED
|
@@ -12,7 +12,6 @@ export type TokenAuthConfig = {
|
|
|
12
12
|
|
|
13
13
|
export type TokenAuthData = {
|
|
14
14
|
auth_name: string;
|
|
15
|
-
key: string;
|
|
16
15
|
/**
|
|
17
16
|
* Datetime of auth creation in YYYY-MM-DDTHH:MM:SSZ format
|
|
18
17
|
*/
|
|
@@ -49,5 +48,4 @@ export type TokenCollectionConfig = {
|
|
|
49
48
|
token: Token;
|
|
50
49
|
discoveryUrl: string;
|
|
51
50
|
serviceName: string;
|
|
52
|
-
accountId?: string;
|
|
53
51
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
|
|
1
|
+
export { BasicAuth } from './Basic/BasicAuth';
|
|
2
|
+
export { BasicCollection } from './Basic/BasicCollection';
|
|
3
|
+
|
|
4
|
+
export { TokenAuth } from './Token/TokenAuth';
|
|
5
|
+
export { TokenCollection } from './Token/TokenCollection';
|
|
6
|
+
|
|
7
|
+
export { OAuth } from './OAuth/OAuth';
|
|
8
|
+
export { OAuthCollection } from './OAuth/OAuthCollection';
|
|
4
9
|
|
|
5
10
|
export * from './types';
|
package/dist/cjs/Basic/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.BasicCollection = void 0;
|
|
18
|
-
var BasicCollection_1 = require("./BasicCollection");
|
|
19
|
-
Object.defineProperty(exports, "BasicCollection", { enumerable: true, get: function () { return BasicCollection_1.BasicCollection; } });
|
|
20
|
-
__exportStar(require("./types"), exports);
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Basic/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AAExB,0CAAwB"}
|
package/dist/cjs/OAuth/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.OAuthCollection = exports.OAuth = void 0;
|
|
18
|
-
var OAuth_1 = require("./OAuth");
|
|
19
|
-
Object.defineProperty(exports, "OAuth", { enumerable: true, get: function () { return OAuth_1.OAuth; } });
|
|
20
|
-
var OAuthCollection_1 = require("./OAuthCollection");
|
|
21
|
-
Object.defineProperty(exports, "OAuthCollection", { enumerable: true, get: function () { return OAuthCollection_1.OAuthCollection; } });
|
|
22
|
-
__exportStar(require("./types"), exports);
|
|
23
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/OAuth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AAExB,0CAAwB"}
|
package/dist/cjs/Token/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.TokenCollection = void 0;
|
|
18
|
-
var TokenCollection_1 = require("./TokenCollection");
|
|
19
|
-
Object.defineProperty(exports, "TokenCollection", { enumerable: true, get: function () { return TokenCollection_1.TokenCollection; } });
|
|
20
|
-
__exportStar(require("./types"), exports);
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Token/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AAExB,0CAAwB"}
|
package/dist/esm/Basic/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Basic/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,cAAc,SAAS,CAAC"}
|
package/dist/esm/OAuth/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/OAuth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,cAAc,SAAS,CAAC"}
|
package/dist/esm/Token/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Token/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,cAAc,SAAS,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Basic/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,cAAc,SAAS,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/OAuth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,cAAc,SAAS,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Token/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,cAAc,SAAS,CAAC"}
|
package/src/Basic/index.ts
DELETED
package/src/OAuth/index.ts
DELETED
package/src/Token/index.ts
DELETED