@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.
Files changed (83) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/Basic/BasicAuth.js +162 -0
  3. package/dist/cjs/Basic/BasicAuth.js.map +1 -0
  4. package/dist/cjs/Basic/BasicCollection.js +24 -117
  5. package/dist/cjs/Basic/BasicCollection.js.map +1 -1
  6. package/dist/cjs/OAuth/OAuth.js +49 -78
  7. package/dist/cjs/OAuth/OAuth.js.map +1 -1
  8. package/dist/cjs/OAuth/OAuthCollection.js +10 -25
  9. package/dist/cjs/OAuth/OAuthCollection.js.map +1 -1
  10. package/dist/cjs/OAuth/types.js.map +1 -1
  11. package/dist/cjs/Token/TokenAuth.js +140 -0
  12. package/dist/cjs/Token/TokenAuth.js.map +1 -0
  13. package/dist/cjs/Token/TokenCollection.js +22 -88
  14. package/dist/cjs/Token/TokenCollection.js.map +1 -1
  15. package/dist/cjs/index.js +13 -8
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/esm/Basic/BasicAuth.js +88 -0
  18. package/dist/esm/Basic/BasicAuth.js.map +1 -0
  19. package/dist/esm/Basic/BasicCollection.js +21 -83
  20. package/dist/esm/Basic/BasicCollection.js.map +1 -1
  21. package/dist/esm/OAuth/OAuth.js +35 -60
  22. package/dist/esm/OAuth/OAuth.js.map +1 -1
  23. package/dist/esm/OAuth/OAuthCollection.js +10 -24
  24. package/dist/esm/OAuth/OAuthCollection.js.map +1 -1
  25. package/dist/esm/OAuth/types.js.map +1 -1
  26. package/dist/esm/Token/TokenAuth.js +66 -0
  27. package/dist/esm/Token/TokenAuth.js.map +1 -0
  28. package/dist/esm/Token/TokenCollection.js +20 -55
  29. package/dist/esm/Token/TokenCollection.js.map +1 -1
  30. package/dist/esm/index.js +6 -3
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/types/Basic/BasicAuth.d.ts +20 -0
  33. package/dist/types/Basic/BasicAuth.d.ts.map +1 -0
  34. package/dist/types/Basic/BasicCollection.d.ts +7 -17
  35. package/dist/types/Basic/BasicCollection.d.ts.map +1 -1
  36. package/dist/types/Basic/types.d.ts +1 -3
  37. package/dist/types/Basic/types.d.ts.map +1 -1
  38. package/dist/types/OAuth/OAuth.d.ts +1 -1
  39. package/dist/types/OAuth/OAuth.d.ts.map +1 -1
  40. package/dist/types/OAuth/OAuthCollection.d.ts +6 -9
  41. package/dist/types/OAuth/OAuthCollection.d.ts.map +1 -1
  42. package/dist/types/OAuth/types.d.ts +1 -9
  43. package/dist/types/OAuth/types.d.ts.map +1 -1
  44. package/dist/types/Token/TokenAuth.d.ts +12 -0
  45. package/dist/types/Token/TokenAuth.d.ts.map +1 -0
  46. package/dist/types/Token/TokenCollection.d.ts +8 -9
  47. package/dist/types/Token/TokenCollection.d.ts.map +1 -1
  48. package/dist/types/Token/types.d.ts +0 -2
  49. package/dist/types/Token/types.d.ts.map +1 -1
  50. package/dist/types/index.d.ts +6 -3
  51. package/dist/types/index.d.ts.map +1 -1
  52. package/package.json +6 -38
  53. package/src/Basic/BasicAuth.ts +129 -0
  54. package/src/Basic/BasicCollection.ts +30 -141
  55. package/src/Basic/types.ts +1 -3
  56. package/src/OAuth/OAuth.ts +51 -109
  57. package/src/OAuth/OAuthCollection.ts +18 -48
  58. package/src/OAuth/types.ts +3 -32
  59. package/src/Token/TokenAuth.ts +102 -0
  60. package/src/Token/TokenCollection.ts +28 -98
  61. package/src/Token/types.ts +0 -2
  62. package/src/index.ts +8 -3
  63. package/dist/cjs/Basic/index.js +0 -21
  64. package/dist/cjs/Basic/index.js.map +0 -1
  65. package/dist/cjs/OAuth/index.js +0 -23
  66. package/dist/cjs/OAuth/index.js.map +0 -1
  67. package/dist/cjs/Token/index.js +0 -21
  68. package/dist/cjs/Token/index.js.map +0 -1
  69. package/dist/esm/Basic/index.js +0 -3
  70. package/dist/esm/Basic/index.js.map +0 -1
  71. package/dist/esm/OAuth/index.js +0 -4
  72. package/dist/esm/OAuth/index.js.map +0 -1
  73. package/dist/esm/Token/index.js +0 -3
  74. package/dist/esm/Token/index.js.map +0 -1
  75. package/dist/types/Basic/index.d.ts +0 -3
  76. package/dist/types/Basic/index.d.ts.map +0 -1
  77. package/dist/types/OAuth/index.d.ts +0 -4
  78. package/dist/types/OAuth/index.d.ts.map +0 -1
  79. package/dist/types/Token/index.d.ts +0 -3
  80. package/dist/types/Token/index.d.ts.map +0 -1
  81. package/src/Basic/index.ts +0 -3
  82. package/src/OAuth/index.ts +0 -4
  83. package/src/Token/index.ts +0 -3
@@ -1,81 +1,62 @@
1
- import { makeList, List } from '@or-sdk/base';
1
+ import { Token } from '@or-sdk/base';
2
2
  import { KeyValueStorage } from '@or-sdk/key-value-storage';
3
- import { v4 as uuidv4 } from 'uuid';
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, accountId } = params;
17
+ const { token, discoveryUrl, serviceName } = params;
18
18
 
19
- this.serviceName = serviceName || '';
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<List<string>> {
31
+ public async listAuthorizations(): Promise<string[]> {
42
32
  const { items: records } = await this.keyValueStorage.listKeys(this.serviceName);
43
33
 
44
- return makeList<string>(records.map((record) => record.key).filter(key => key.includes('::token')));
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<TokenAuthData> {
51
- if (!this.serviceName) throw new Error('Service name is not defined.');
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
- const authData = record.value as Omit<TokenAuthData, 'key'>;
61
-
62
- if (!authData.auth_name || !authData.date_created) {
63
- throw new Error('Authorization is invalid.');
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 tokenCollectionData = await tokenCollectionInstance.createAuthorization({
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<TokenAuthData> {
89
- const { authName, credentials } = params;
90
-
91
- if (!this.serviceName) throw new Error('Service name is not defined.');
92
- if (!authName || !credentials) throw new Error('Invalid authorization parameters passed.');
93
-
94
- const id = uuidv4();
95
- const authKey = createAuthKey(id, authName);
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
  }
@@ -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 { BasicCollection } from './Basic/index';
2
- export { TokenCollection } from './Token/index';
3
- export { OAuth, OAuthCollection } from './OAuth/index';
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';
@@ -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"}
@@ -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"}
@@ -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"}
@@ -1,3 +0,0 @@
1
- export { BasicCollection } from './BasicCollection';
2
- export * from './types';
3
- //# sourceMappingURL=index.js.map
@@ -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"}
@@ -1,4 +0,0 @@
1
- export { OAuth } from './OAuth';
2
- export { OAuthCollection } from './OAuthCollection';
3
- export * from './types';
4
- //# sourceMappingURL=index.js.map
@@ -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"}
@@ -1,3 +0,0 @@
1
- export { TokenCollection } from './TokenCollection';
2
- export * from './types';
3
- //# sourceMappingURL=index.js.map
@@ -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,3 +0,0 @@
1
- export { BasicCollection } from './BasicCollection';
2
- export * from './types';
3
- //# sourceMappingURL=index.d.ts.map
@@ -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,4 +0,0 @@
1
- export { OAuth } from './OAuth';
2
- export { OAuthCollection } from './OAuthCollection';
3
- export * from './types';
4
- //# sourceMappingURL=index.d.ts.map
@@ -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,3 +0,0 @@
1
- export { TokenCollection } from './TokenCollection';
2
- export * from './types';
3
- //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -1,3 +0,0 @@
1
- export { BasicCollection } from './BasicCollection';
2
-
3
- export * from './types';
@@ -1,4 +0,0 @@
1
- export { OAuth } from './OAuth';
2
- export { OAuthCollection } from './OAuthCollection';
3
-
4
- export * from './types';
@@ -1,3 +0,0 @@
1
- export { TokenCollection } from './TokenCollection';
2
-
3
- export * from './types';