@or-sdk/authorizer 0.25.0-beta.990.0 → 0.25.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.
Files changed (109) hide show
  1. package/CHANGELOG.md +317 -0
  2. package/README.md +12 -32
  3. package/dist/cjs/Basic/BasicCollection.js +166 -26
  4. package/dist/cjs/Basic/BasicCollection.js.map +1 -1
  5. package/dist/cjs/Basic/utils/createAuthKey.js +4 -0
  6. package/dist/cjs/Basic/utils/createAuthKey.js.map +1 -1
  7. package/dist/cjs/OAuth/OAuth.js +92 -138
  8. package/dist/cjs/OAuth/OAuth.js.map +1 -1
  9. package/dist/cjs/OAuth/index.js +1 -3
  10. package/dist/cjs/OAuth/index.js.map +1 -1
  11. package/dist/cjs/OAuth/types.js +1 -1
  12. package/dist/cjs/OAuth/types.js.map +1 -1
  13. package/dist/cjs/OAuth/utils/ServiceDefinition.js.map +1 -1
  14. package/dist/cjs/OAuth/utils/createAuthKey.js +4 -0
  15. package/dist/cjs/OAuth/utils/createAuthKey.js.map +1 -1
  16. package/dist/cjs/OAuth/utils/createOAuthHelper.js +379 -0
  17. package/dist/cjs/OAuth/utils/createOAuthHelper.js.map +1 -0
  18. package/dist/cjs/OAuth/utils/formatScope.js.map +1 -1
  19. package/dist/cjs/{OAuth → OAuthCollection}/OAuthCollection.js +132 -28
  20. package/dist/cjs/OAuthCollection/OAuthCollection.js.map +1 -0
  21. package/dist/cjs/OAuthCollection/index.js +21 -0
  22. package/dist/cjs/OAuthCollection/index.js.map +1 -0
  23. package/dist/cjs/Token/TokenCollection.js +166 -21
  24. package/dist/cjs/Token/TokenCollection.js.map +1 -1
  25. package/dist/cjs/Token/utils/createAuthKey.js +4 -0
  26. package/dist/cjs/Token/utils/createAuthKey.js.map +1 -1
  27. package/dist/cjs/constants.js +3 -2
  28. package/dist/cjs/constants.js.map +1 -1
  29. package/dist/cjs/index.js +2 -1
  30. package/dist/cjs/index.js.map +1 -1
  31. package/dist/esm/Basic/BasicCollection.js +115 -17
  32. package/dist/esm/Basic/BasicCollection.js.map +1 -1
  33. package/dist/esm/Basic/utils/createAuthKey.js +3 -0
  34. package/dist/esm/Basic/utils/createAuthKey.js.map +1 -1
  35. package/dist/esm/OAuth/OAuth.js +56 -115
  36. package/dist/esm/OAuth/OAuth.js.map +1 -1
  37. package/dist/esm/OAuth/index.js +0 -1
  38. package/dist/esm/OAuth/index.js.map +1 -1
  39. package/dist/esm/OAuth/types.js.map +1 -1
  40. package/dist/esm/OAuth/utils/ServiceDefinition.js.map +1 -1
  41. package/dist/esm/OAuth/utils/createAuthKey.js +3 -0
  42. package/dist/esm/OAuth/utils/createAuthKey.js.map +1 -1
  43. package/dist/esm/OAuth/utils/createOAuthHelper.js +262 -0
  44. package/dist/esm/OAuth/utils/createOAuthHelper.js.map +1 -0
  45. package/dist/esm/OAuth/utils/formatScope.js.map +1 -1
  46. package/dist/esm/OAuthCollection/OAuthCollection.js +190 -0
  47. package/dist/esm/OAuthCollection/OAuthCollection.js.map +1 -0
  48. package/dist/esm/OAuthCollection/index.js +3 -0
  49. package/dist/esm/OAuthCollection/index.js.map +1 -0
  50. package/dist/esm/Token/TokenCollection.js +115 -12
  51. package/dist/esm/Token/TokenCollection.js.map +1 -1
  52. package/dist/esm/Token/utils/createAuthKey.js +3 -0
  53. package/dist/esm/Token/utils/createAuthKey.js.map +1 -1
  54. package/dist/esm/constants.js +1 -0
  55. package/dist/esm/constants.js.map +1 -1
  56. package/dist/esm/index.js +2 -1
  57. package/dist/esm/index.js.map +1 -1
  58. package/dist/types/Basic/BasicCollection.d.ts +6 -4
  59. package/dist/types/Basic/BasicCollection.d.ts.map +1 -1
  60. package/dist/types/Basic/types.d.ts +20 -11
  61. package/dist/types/Basic/types.d.ts.map +1 -1
  62. package/dist/types/Basic/utils/createAuthKey.d.ts +1 -0
  63. package/dist/types/Basic/utils/createAuthKey.d.ts.map +1 -1
  64. package/dist/types/OAuth/OAuth.d.ts +8 -5
  65. package/dist/types/OAuth/OAuth.d.ts.map +1 -1
  66. package/dist/types/OAuth/index.d.ts +0 -1
  67. package/dist/types/OAuth/index.d.ts.map +1 -1
  68. package/dist/types/OAuth/types.d.ts +95 -19
  69. package/dist/types/OAuth/types.d.ts.map +1 -1
  70. package/dist/types/OAuth/utils/createAuthKey.d.ts +1 -0
  71. package/dist/types/OAuth/utils/createAuthKey.d.ts.map +1 -1
  72. package/dist/types/OAuth/utils/createOAuthHelper.d.ts +33 -0
  73. package/dist/types/OAuth/utils/createOAuthHelper.d.ts.map +1 -0
  74. package/dist/types/OAuthCollection/OAuthCollection.d.ts +27 -0
  75. package/dist/types/OAuthCollection/OAuthCollection.d.ts.map +1 -0
  76. package/dist/types/OAuthCollection/index.d.ts +3 -0
  77. package/dist/types/OAuthCollection/index.d.ts.map +1 -0
  78. package/dist/types/Token/TokenCollection.d.ts +5 -2
  79. package/dist/types/Token/TokenCollection.d.ts.map +1 -1
  80. package/dist/types/Token/types.d.ts +19 -5
  81. package/dist/types/Token/types.d.ts.map +1 -1
  82. package/dist/types/Token/utils/createAuthKey.d.ts +1 -0
  83. package/dist/types/Token/utils/createAuthKey.d.ts.map +1 -1
  84. package/dist/types/constants.d.ts +1 -0
  85. package/dist/types/constants.d.ts.map +1 -1
  86. package/dist/types/index.d.ts +2 -1
  87. package/dist/types/index.d.ts.map +1 -1
  88. package/package.json +32 -26
  89. package/src/Basic/BasicCollection.ts +170 -18
  90. package/src/Basic/types.ts +17 -14
  91. package/src/Basic/utils/createAuthKey.ts +4 -0
  92. package/src/OAuth/OAuth.ts +111 -195
  93. package/src/OAuth/index.ts +0 -1
  94. package/src/OAuth/types.ts +171 -15
  95. package/src/OAuth/utils/createAuthKey.ts +8 -0
  96. package/src/OAuth/utils/createOAuthHelper.ts +374 -0
  97. package/src/OAuthCollection/OAuthCollection.ts +348 -0
  98. package/src/OAuthCollection/index.ts +3 -0
  99. package/src/Token/TokenCollection.ts +174 -16
  100. package/src/Token/types.ts +15 -0
  101. package/src/Token/utils/createAuthKey.ts +4 -0
  102. package/src/constants.ts +1 -0
  103. package/src/index.ts +2 -1
  104. package/dist/cjs/OAuth/OAuthCollection.js.map +0 -1
  105. package/dist/esm/OAuth/OAuthCollection.js +0 -120
  106. package/dist/esm/OAuth/OAuthCollection.js.map +0 -1
  107. package/dist/types/OAuth/OAuthCollection.d.ts +0 -21
  108. package/dist/types/OAuth/OAuthCollection.d.ts.map +0 -1
  109. package/src/OAuth/OAuthCollection.ts +0 -206
package/CHANGELOG.md CHANGED
@@ -3,6 +3,323 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.25.0](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.51...@or-sdk/authorizer@0.25.0) (2024-09-12)
7
+
8
+
9
+ ### Features
10
+
11
+ * **key-value-storage:** Improve types for methods and add several methods ([fd3c20b](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/commit/fd3c20be11a68fbcc3bfec58b32b356a3caf218c))
12
+
13
+
14
+
15
+ ## [0.24.51](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.50...@or-sdk/authorizer@0.24.51) (2024-08-15)
16
+
17
+ **Note:** Version bump only for package @or-sdk/authorizer
18
+
19
+
20
+
21
+
22
+
23
+ ## [0.24.50](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.49...@or-sdk/authorizer@0.24.50) (2024-08-09)
24
+
25
+ **Note:** Version bump only for package @or-sdk/authorizer
26
+
27
+
28
+
29
+
30
+
31
+ ## [0.24.49](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.48...@or-sdk/authorizer@0.24.49) (2024-08-06)
32
+
33
+
34
+ ### Bug Fixes
35
+
36
+ * Update build tools ([95411fd](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/commit/95411fd4764056751e6c2faeeaa958c22a3e5495))
37
+
38
+
39
+
40
+ ## [0.24.48](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.47...@or-sdk/authorizer@0.24.48) (2024-07-24)
41
+
42
+ **Note:** Version bump only for package @or-sdk/authorizer
43
+
44
+
45
+
46
+
47
+
48
+ ## [0.24.47](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.46...@or-sdk/authorizer@0.24.47) (2024-07-17)
49
+
50
+ **Note:** Version bump only for package @or-sdk/authorizer
51
+
52
+
53
+
54
+
55
+
56
+ ## [0.24.46](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.45...@or-sdk/authorizer@0.24.46) (2024-06-03)
57
+
58
+ **Note:** Version bump only for package @or-sdk/authorizer
59
+
60
+
61
+
62
+
63
+
64
+ ## [0.24.45](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.44...@or-sdk/authorizer@0.24.45) (2024-05-28)
65
+
66
+ **Note:** Version bump only for package @or-sdk/authorizer
67
+
68
+
69
+
70
+
71
+
72
+ ## [0.24.44](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.43...@or-sdk/authorizer@0.24.44) (2024-05-23)
73
+
74
+ **Note:** Version bump only for package @or-sdk/authorizer
75
+
76
+
77
+
78
+
79
+
80
+ ## [0.24.43](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.42...@or-sdk/authorizer@0.24.43) (2024-05-22)
81
+
82
+ **Note:** Version bump only for package @or-sdk/authorizer
83
+
84
+
85
+
86
+
87
+
88
+ ## [0.24.42](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.41...@or-sdk/authorizer@0.24.42) (2024-05-20)
89
+
90
+
91
+ ### Bug Fixes
92
+
93
+ * Sort package.json ([f00d2a0](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/commit/f00d2a002636d40177270fdf056b58ceea30dbad))
94
+
95
+
96
+
97
+ ## [0.24.41](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.40...@or-sdk/authorizer@0.24.41) (2024-05-20)
98
+
99
+ **Note:** Version bump only for package @or-sdk/authorizer
100
+
101
+
102
+
103
+
104
+
105
+ ## [0.24.40](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.39...@or-sdk/authorizer@0.24.40) (2024-05-14)
106
+
107
+ **Note:** Version bump only for package @or-sdk/authorizer
108
+
109
+
110
+
111
+
112
+
113
+ ## [0.24.39](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.38...@or-sdk/authorizer@0.24.39) (2024-04-11)
114
+
115
+ **Note:** Version bump only for package @or-sdk/authorizer
116
+
117
+
118
+
119
+
120
+
121
+ ## [0.24.38](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.37...@or-sdk/authorizer@0.24.38) (2024-04-11)
122
+
123
+ **Note:** Version bump only for package @or-sdk/authorizer
124
+
125
+
126
+
127
+
128
+
129
+ ## [0.24.37](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.36...@or-sdk/authorizer@0.24.37) (2024-04-09)
130
+
131
+
132
+ ### Bug Fixes
133
+
134
+ * update ts, review build pipeline ([e4dbf00](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/commit/e4dbf00b0aac58d94112fbd41ae5e4ae2312e566))
135
+
136
+
137
+
138
+ ## [0.24.36](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.35...@or-sdk/authorizer@0.24.36) (2024-04-08)
139
+
140
+ **Note:** Version bump only for package @or-sdk/authorizer
141
+
142
+
143
+
144
+
145
+
146
+ ## [0.24.35](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.34...@or-sdk/authorizer@0.24.35) (2024-04-08)
147
+
148
+ **Note:** Version bump only for package @or-sdk/authorizer
149
+
150
+
151
+
152
+
153
+
154
+ ## [0.24.34](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.33...@or-sdk/authorizer@0.24.34) (2024-03-30)
155
+
156
+ **Note:** Version bump only for package @or-sdk/authorizer
157
+
158
+
159
+
160
+
161
+
162
+ ## [0.24.33](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.32...@or-sdk/authorizer@0.24.33) (2024-03-26)
163
+
164
+ **Note:** Version bump only for package @or-sdk/authorizer
165
+
166
+
167
+
168
+
169
+
170
+ ## [0.24.32](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.31...@or-sdk/authorizer@0.24.32) (2024-02-29)
171
+
172
+ **Note:** Version bump only for package @or-sdk/authorizer
173
+
174
+
175
+
176
+
177
+
178
+ ## [0.24.31](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.30...@or-sdk/authorizer@0.24.31) (2024-02-20)
179
+
180
+ **Note:** Version bump only for package @or-sdk/authorizer
181
+
182
+
183
+
184
+
185
+
186
+ ## [0.24.30](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.29...@or-sdk/authorizer@0.24.30) (2024-02-16)
187
+
188
+ **Note:** Version bump only for package @or-sdk/authorizer
189
+
190
+
191
+
192
+
193
+
194
+ ## [0.24.29](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.28...@or-sdk/authorizer@0.24.29) (2024-02-16)
195
+
196
+ **Note:** Version bump only for package @or-sdk/authorizer
197
+
198
+
199
+
200
+
201
+
202
+ ## [0.24.28](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.27...@or-sdk/authorizer@0.24.28) (2024-02-16)
203
+
204
+ **Note:** Version bump only for package @or-sdk/authorizer
205
+
206
+
207
+
208
+
209
+
210
+ ## [0.24.27](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.26...@or-sdk/authorizer@0.24.27) (2024-02-12)
211
+
212
+ **Note:** Version bump only for package @or-sdk/authorizer
213
+
214
+
215
+
216
+
217
+
218
+ ## [0.24.26](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.25...@or-sdk/authorizer@0.24.26) (2024-02-05)
219
+
220
+ **Note:** Version bump only for package @or-sdk/authorizer
221
+
222
+
223
+
224
+
225
+
226
+ ## [0.24.25](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.24...@or-sdk/authorizer@0.24.25) (2024-02-02)
227
+
228
+ **Note:** Version bump only for package @or-sdk/authorizer
229
+
230
+
231
+
232
+
233
+
234
+ ## [0.24.24](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.23...@or-sdk/authorizer@0.24.24) (2024-02-01)
235
+
236
+ **Note:** Version bump only for package @or-sdk/authorizer
237
+
238
+
239
+
240
+
241
+
242
+ ## [0.24.23](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.22...@or-sdk/authorizer@0.24.23) (2024-02-01)
243
+
244
+ **Note:** Version bump only for package @or-sdk/authorizer
245
+
246
+
247
+
248
+
249
+
250
+ ## [0.24.22](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.21...@or-sdk/authorizer@0.24.22) (2023-12-18)
251
+
252
+ **Note:** Version bump only for package @or-sdk/authorizer
253
+
254
+
255
+
256
+
257
+
258
+ ## [0.24.21](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.20...@or-sdk/authorizer@0.24.21) (2023-12-04)
259
+
260
+ **Note:** Version bump only for package @or-sdk/authorizer
261
+
262
+
263
+
264
+
265
+
266
+ ## [0.24.20](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.19...@or-sdk/authorizer@0.24.20) (2023-11-23)
267
+
268
+ **Note:** Version bump only for package @or-sdk/authorizer
269
+
270
+
271
+
272
+
273
+
274
+ ## [0.24.19](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.18...@or-sdk/authorizer@0.24.19) (2023-11-21)
275
+
276
+ **Note:** Version bump only for package @or-sdk/authorizer
277
+
278
+
279
+
280
+
281
+
282
+ ## [0.24.18](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.17...@or-sdk/authorizer@0.24.18) (2023-10-12)
283
+
284
+
285
+ ### Bug Fixes
286
+
287
+ * **authorizer:** refactor authorizer ([380aab7](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/commit/380aab7b78280b47d9cf3840ada15331f8edac04))
288
+
289
+
290
+
291
+ ## [0.24.17](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.16...@or-sdk/authorizer@0.24.17) (2023-09-13)
292
+
293
+ **Note:** Version bump only for package @or-sdk/authorizer
294
+
295
+
296
+
297
+
298
+
299
+ ## [0.24.16](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.15...@or-sdk/authorizer@0.24.16) (2023-06-13)
300
+
301
+ **Note:** Version bump only for package @or-sdk/authorizer
302
+
303
+
304
+
305
+
306
+
307
+ ## [0.24.15](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.14...@or-sdk/authorizer@0.24.15) (2023-06-01)
308
+
309
+ **Note:** Version bump only for package @or-sdk/authorizer
310
+
311
+
312
+
313
+
314
+
315
+ ## [0.24.14](https://gitlab.internal.onereach.io/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.13...@or-sdk/authorizer@0.24.14) (2023-03-16)
316
+
317
+ **Note:** Version bump only for package @or-sdk/authorizer
318
+
319
+
320
+
321
+
322
+
6
323
  ### [0.24.13](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/authorizer@0.24.12...@or-sdk/authorizer@0.24.13) (2022-12-27)
7
324
 
8
325
  **Note:** Version bump only for package @or-sdk/authorizer
package/README.md CHANGED
@@ -5,56 +5,36 @@ $ npm i @or-sdk/authorizer
5
5
 
6
6
  ## Usage:
7
7
  ```typescript
8
- import { BasicAuth } from '@or-sdk/authorizer'
9
-
10
- const basicAuthInstance = new BasicAuth({
11
- token: 'my-account-token-string',
12
- discoveryUrl: 'discovery.example.onereach.ai',
13
- serviceName: '__authorization_service_test_service',
14
- authKey: '637ac446-1021-475f-9992-3ce7f3ddb637::basic::someAuth::__authorization_service_test_service::02bf4366-f987-49ea-90a6-0d346e13c3c1',
15
- });
16
-
17
- import { BasicCollection } from '@or-sdk/authorizer'
8
+ // Basic package (Username-password)
9
+ import { BasicCollection } from '@or-sdk/authorizer/Basic'
18
10
 
19
11
  const basicCollectionInstance = new BasicCollection({
20
12
  token: 'my-account-token-string',
21
13
  discoveryUrl: 'discovery.example.onereach.ai',
22
14
  serviceName: '__authorization_service_test_service',
15
+ accountId: 'my-account-ID' // Optional, for Super-Admins only
23
16
  });
24
17
 
25
- import { OAuth } from '@or-sdk/authorizer'
26
-
27
- const oAuthInstance = new OAuth({
28
- token: 'my-account-token-string',
29
- discoveryUrl: 'discovery.example.onereach.ai',
30
- serviceName: '__authorization_service_test_service',
31
- authKey: '637ac446-1021-475f-9992-3ce7f3ddb637::oauth::someAuth::__authorization_service_test_service::02bf4366-f987-49ea-90a6-0d346e13c3c1',
32
- keyValueCollection: 'custom_collection_name' // Pass this if you using custom name for key-value collection that differs from serviceName
33
- });
34
18
 
35
- import { OAuthCollection } from '@or-sdk/authorizer'
19
+ // Token package
20
+ import { TokenCollection } from '@or-sdk/authorizer/Token'
36
21
 
37
- const oAuthCollectionInstance = new OAuthCollection({
22
+ const tokenCollectionInstance = new TokenCollection({
38
23
  token: 'my-account-token-string',
39
24
  discoveryUrl: 'discovery.example.onereach.ai',
40
25
  serviceName: '__authorization_service_test_service',
41
- keyValueCollections: 'custom-collection-name' // Pass this if you using custom name for key-value collection that differs from serviceName
26
+ accountId: 'my-account-ID' // Optional, for Super-Admins only
42
27
  });
43
28
 
44
- import { TokenAuth } from '@or-sdk/authorizer'
45
-
46
- const instance = new TokenAuth({
47
- token: 'my-account-token-string',
48
- discoveryUrl: 'discovery.example.onereach.ai',
49
- serviceName: '__authorization_service_test_service',
50
- authKey: '637ac446-1021-475f-9992-3ce7f3ddb637::token::someAuth::__authorization_service_test_service::02bf4366-f987-49ea-90a6-0d346e13c3c1',
51
- });
52
29
 
53
- import { TokenCollection } from '@or-sdk/authorizer'
30
+ // OAuth package
31
+ import { OAuthCollection } from '@or-sdk/authorizer/OAuth'
54
32
 
55
- const tokenCollectionInstance = new TokenCollection({
33
+ const oAuthCollectionInstance = new OAuthCollection({
56
34
  token: 'my-account-token-string',
57
35
  discoveryUrl: 'discovery.example.onereach.ai',
58
36
  serviceName: '__authorization_service_test_service',
37
+ keyValueCollection: 'custom-collection-name', // Pass this if you using custom name for key-value collection that differs from serviceName
38
+ accountId: 'my-account-ID' // Optional, for Super-Admins only
59
39
  });
60
40
  ```
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
25
25
  function verb(n) { return function (v) { return step([n, v]); }; }
26
26
  function step(op) {
27
27
  if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
29
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
30
  if (y = 0, t) op = [op[0] & 2, t.value];
31
31
  switch (op[0]) {
@@ -49,6 +49,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
50
  exports.BasicCollection = void 0;
51
51
  var base_1 = require("@or-sdk/base");
52
+ var providers_1 = require("@or-sdk/providers");
52
53
  var key_value_storage_1 = require("@or-sdk/key-value-storage");
53
54
  var createAuthKey_1 = require("./utils/createAuthKey");
54
55
  var uuid_1 = require("uuid");
@@ -61,6 +62,10 @@ var BasicCollection = (function () {
61
62
  discoveryUrl: discoveryUrl,
62
63
  accountId: accountId,
63
64
  });
65
+ this.providers = new providers_1.Providers({
66
+ token: token,
67
+ discoveryUrl: discoveryUrl,
68
+ });
64
69
  }
65
70
  BasicCollection.prototype.init = function (serviceName) {
66
71
  if (!serviceName)
@@ -77,72 +82,128 @@ var BasicCollection = (function () {
77
82
  password: password,
78
83
  };
79
84
  };
80
- BasicCollection.prototype.listAuthorizations = function () {
85
+ BasicCollection.prototype.listAuthorizations = function (dynamicCollectionName) {
81
86
  return __awaiter(this, void 0, void 0, function () {
82
- var records;
87
+ var records, pattern;
83
88
  return __generator(this, function (_a) {
84
89
  switch (_a.label) {
85
90
  case 0: return [4, this.keyValueStorage.listKeys(this.serviceName)];
86
91
  case 1:
87
92
  records = (_a.sent()).items;
88
- return [2, (0, base_1.makeList)(records.map(function (record) { return record.key; }).filter(function (key) { return key.includes('::basic'); }))];
93
+ pattern = dynamicCollectionName ? '::basic-collection::' + dynamicCollectionName : '::basic::';
94
+ return [2, (0, base_1.makeList)(records.map(function (record) { return record.key; }).filter(function (key) { return key.includes(pattern); }))];
89
95
  }
90
96
  });
91
97
  });
92
98
  };
93
- BasicCollection.prototype.getAuthorization = function (key) {
99
+ BasicCollection.prototype.getAuthorization = function (key, dynamicCollectionName) {
94
100
  return __awaiter(this, void 0, void 0, function () {
95
- var record, authRecord;
101
+ var collectionRecord, collection, record, authRecord;
96
102
  return __generator(this, function (_a) {
97
103
  switch (_a.label) {
98
104
  case 0:
99
105
  if (!this.serviceName)
100
106
  throw new Error('Service name is not defined.');
101
- if (!key.includes('::basic'))
107
+ if (!dynamicCollectionName) return [3, 2];
108
+ return [4, this.keyValueStorage.getValueByKey('__authorizer_dynamic_collections', dynamicCollectionName)];
109
+ case 1:
110
+ collectionRecord = _a.sent();
111
+ collection = collectionRecord.value;
112
+ if (!collection || collection.type !== 'basic')
113
+ throw new Error('Dynamic collection name is invalid');
114
+ key = collection.authorizations[key];
115
+ if (!key)
116
+ throw new Error('Dynamic collection does not have such key');
117
+ _a.label = 2;
118
+ case 2:
119
+ if (!key.includes('::basic')) {
102
120
  throw new Error('The basic authorization key should contain "basic" type specifier.');
121
+ }
103
122
  return [4, this.keyValueStorage.getValueByKey(this.serviceName, encodeURIComponent(key))];
104
- case 1:
123
+ case 3:
105
124
  record = _a.sent();
106
125
  if (!record.value) {
107
126
  throw new Error('Authorization does not exist.');
108
127
  }
109
128
  authRecord = record.value;
110
- if (!authRecord.auth_name || !authRecord.access_token || !authRecord.date_created) {
129
+ if (!authRecord.auth_name ||
130
+ !authRecord.access_token ||
131
+ !(authRecord.date_created || authRecord._date_created)) {
111
132
  throw new Error('Authorization does not exist or invalid.');
112
133
  }
113
- return [2, {
114
- auth_name: authRecord.auth_name,
115
- access_token: authRecord.access_token,
116
- date_created: authRecord.date_created,
117
- key: key,
118
- }];
134
+ return [2, __assign(__assign({}, authRecord), { key: key })];
119
135
  }
120
136
  });
121
137
  });
122
138
  };
123
139
  BasicCollection.prototype.createAuthorization = function (params) {
124
140
  return __awaiter(this, void 0, void 0, function () {
125
- var authName, password, username, id, authKey, authData;
126
- return __generator(this, function (_a) {
127
- switch (_a.label) {
141
+ var authName, password, username, dynamicCollection, _a, destinationAccount, customAccountId, id, authKey, authData, value, collection, localRecord;
142
+ return __generator(this, function (_b) {
143
+ switch (_b.label) {
128
144
  case 0:
129
- authName = params.authName, password = params.password, username = params.username;
145
+ authName = params.authName, password = params.password, username = params.username, dynamicCollection = params.dynamicCollection, _a = params.destinationAccount, destinationAccount = _a === void 0 ? 'CURRENT' : _a, customAccountId = params.customAccountId;
130
146
  if (!authName || !username || !password) {
131
147
  throw new Error('Invalid authorization config passed.');
132
148
  }
133
149
  if (!this.serviceName)
134
150
  throw new Error('Service name is not defined.');
135
151
  id = (0, uuid_1.v4)();
136
- authKey = (0, createAuthKey_1.createAuthKey)(id, authName);
152
+ authKey = dynamicCollection ? (0, createAuthKey_1.createDynamicKey)(id, dynamicCollection) : (0, createAuthKey_1.createAuthKey)(id, authName);
137
153
  authData = {
138
154
  auth_name: authName,
139
155
  access_token: BasicCollection.encodeAccessToken(username, password),
140
- date_created: new Date().toISOString(),
156
+ _date_created: new Date().toISOString(),
141
157
  };
142
- return [4, this.keyValueStorage.setValueByKey(this.serviceName, encodeURIComponent(authKey), authData)];
158
+ if (!dynamicCollection) return [3, 3];
159
+ return [4, this.keyValueStorage.getValueByKey('__authorizer_dynamic_collections', dynamicCollection)];
143
160
  case 1:
144
- _a.sent();
145
- return [2, __assign(__assign({}, authData), { key: authKey })];
161
+ value = (_b.sent()).value;
162
+ collection = value;
163
+ if (!collection)
164
+ throw new Error('Dynamic collection name is invalid');
165
+ if (collection.type !== 'basic' || collection.service !== this.serviceName) {
166
+ throw new Error('Dynamic collection\'s type or service is invalid');
167
+ }
168
+ collection.authorizations[authName] = authKey;
169
+ return [4, this.keyValueStorage.setValueByKey('__authorizer_dynamic_collections', dynamicCollection, collection)];
170
+ case 2:
171
+ _b.sent();
172
+ _b.label = 3;
173
+ case 3:
174
+ if (!(destinationAccount === 'CURRENT')) return [3, 5];
175
+ return [4, this.keyValueStorage.setValueByKey(this.serviceName, encodeURIComponent(authKey), authData)];
176
+ case 4:
177
+ _b.sent();
178
+ return [3, 8];
179
+ case 5:
180
+ localRecord = {
181
+ auth_name: authData.auth_name,
182
+ isRemote: true,
183
+ id: id,
184
+ };
185
+ if (destinationAccount === 'CUSTOM' && !customAccountId) {
186
+ throw new Error('Custom Account ID is required if destinationAccount === "CUSTOM"');
187
+ }
188
+ return [4, this.providers.makeRequest({
189
+ route: 'authorizer/redirect',
190
+ params: {
191
+ method: 'PUT',
192
+ data: {
193
+ authData: authData,
194
+ id: id,
195
+ storeAccount: destinationAccount,
196
+ storeCustomAccountId: destinationAccount === 'CUSTOM' ? customAccountId : undefined,
197
+ },
198
+ },
199
+ }).catch(function () { throw new Error('Could not save basic credentials to the specified account'); })];
200
+ case 6:
201
+ _b.sent();
202
+ return [4, this.keyValueStorage.setValueByKey(this.serviceName, encodeURIComponent(authKey), localRecord)];
203
+ case 7:
204
+ _b.sent();
205
+ _b.label = 8;
206
+ case 8: return [2, __assign(__assign({}, authData), { key: authKey })];
146
207
  }
147
208
  });
148
209
  });
@@ -168,7 +229,7 @@ var BasicCollection = (function () {
168
229
  access_token = BasicCollection.encodeAccessToken(username, password);
169
230
  return [4, this.keyValueStorage.setValueByKey(this.serviceName, encodeURIComponent(basicAuth.key), {
170
231
  auth_name: basicAuth.auth_name,
171
- date_created: basicAuth.date_created,
232
+ _date_created: basicAuth.date_created || basicAuth._date_created,
172
233
  access_token: access_token,
173
234
  })];
174
235
  case 1:
@@ -181,13 +242,92 @@ var BasicCollection = (function () {
181
242
  };
182
243
  BasicCollection.prototype.deleteAuthorization = function (authKey) {
183
244
  return __awaiter(this, void 0, void 0, function () {
245
+ var dynamicCollectionName, value, collection_1, authName;
184
246
  return __generator(this, function (_a) {
185
247
  switch (_a.label) {
186
248
  case 0:
187
249
  if (!this.serviceName)
188
250
  throw new Error('Service name is not defined.');
189
- return [4, this.keyValueStorage.deleteKey(this.serviceName, encodeURIComponent(authKey))];
251
+ if (!authKey.includes('::basic-collection::')) return [3, 3];
252
+ dynamicCollectionName = authKey.split('::')[2].split(' ')[0];
253
+ return [4, this.keyValueStorage.getValueByKey('__authorizer_dynamic_collections', dynamicCollectionName)];
254
+ case 1:
255
+ value = (_a.sent()).value;
256
+ collection_1 = value;
257
+ if (!collection_1) return [3, 3];
258
+ authName = Object.keys(collection_1.authorizations)
259
+ .find(function (name) { return collection_1.authorizations[name] === authKey; });
260
+ if (!authName) return [3, 3];
261
+ delete collection_1.authorizations[authName];
262
+ return [4, this.keyValueStorage.setValueByKey('__authorizer_dynamic_collections', dynamicCollectionName, collection_1)];
263
+ case 2:
264
+ _a.sent();
265
+ _a.label = 3;
266
+ case 3: return [4, this.keyValueStorage.deleteKey(this.serviceName, encodeURIComponent(authKey))];
267
+ case 4:
268
+ _a.sent();
269
+ return [2];
270
+ }
271
+ });
272
+ });
273
+ };
274
+ BasicCollection.prototype.createDynamicCollection = function (dynamicCollectionName) {
275
+ return __awaiter(this, void 0, void 0, function () {
276
+ var value, collection;
277
+ return __generator(this, function (_a) {
278
+ switch (_a.label) {
279
+ case 0:
280
+ if (!dynamicCollectionName)
281
+ throw new Error('Dynamic collection name is empty or invalid');
282
+ return [4, this.keyValueStorage.getValueByKey('__authorizer_dynamic_collections', dynamicCollectionName)];
190
283
  case 1:
284
+ value = (_a.sent()).value;
285
+ collection = value;
286
+ if (!!value) return [3, 3];
287
+ return [4, this.keyValueStorage.setValueByKey('__authorizer_dynamic_collections', dynamicCollectionName, {
288
+ name: dynamicCollectionName,
289
+ type: 'basic',
290
+ service: this.serviceName,
291
+ serviceConfigName: this.serviceName,
292
+ authorizations: {},
293
+ })];
294
+ case 2:
295
+ _a.sent();
296
+ return [3, 4];
297
+ case 3:
298
+ if (collection.type === 'oauth' && collection.service === this.serviceName) {
299
+ throw new Error('Same collection already exists');
300
+ }
301
+ else {
302
+ throw new Error('Different collection exists with this name');
303
+ }
304
+ _a.label = 4;
305
+ case 4: return [2];
306
+ }
307
+ });
308
+ });
309
+ };
310
+ BasicCollection.prototype.deleteDynamicCollection = function (dynamicCollectionName) {
311
+ return __awaiter(this, void 0, void 0, function () {
312
+ var value, collection;
313
+ var _this = this;
314
+ return __generator(this, function (_a) {
315
+ switch (_a.label) {
316
+ case 0:
317
+ if (!dynamicCollectionName)
318
+ throw new Error('Dynamic collection name is empty or invalid');
319
+ return [4, this.keyValueStorage.getValueByKey('__authorizer_dynamic_collections', dynamicCollectionName)];
320
+ case 1:
321
+ value = (_a.sent()).value;
322
+ collection = value;
323
+ return [4, Promise.all(Object.keys(collection.authorizations)
324
+ .map(function (authName) {
325
+ return _this.keyValueStorage.deleteKey(collection.service, encodeURIComponent(collection.authorizations[authName]));
326
+ })).catch(function () { })];
327
+ case 2:
328
+ _a.sent();
329
+ return [4, this.keyValueStorage.deleteKey('__authorizer_dynamic_collections', dynamicCollectionName)];
330
+ case 3:
191
331
  _a.sent();
192
332
  return [2];
193
333
  }