@3sixty/api-auth-entity-storage-rest-client 0.0.0-stage → 0.20.0-next.1
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/LICENSE +201 -0
- package/README.md +24 -2
- package/dist/es/entityStorageAuthenticationAdminRestClient.js +115 -0
- package/dist/es/entityStorageAuthenticationAdminRestClient.js.map +1 -0
- package/dist/es/entityStorageAuthenticationRestClient.js +111 -0
- package/dist/es/entityStorageAuthenticationRestClient.js.map +1 -0
- package/dist/es/index.js +6 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/entityStorageAuthenticationRestClientConstructorOptions.js +2 -0
- package/dist/es/models/entityStorageAuthenticationRestClientConstructorOptions.js.map +1 -0
- package/dist/types/entityStorageAuthenticationAdminRestClient.d.ts +62 -0
- package/dist/types/entityStorageAuthenticationRestClient.d.ts +59 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/models/entityStorageAuthenticationRestClientConstructorOptions.d.ts +11 -0
- package/docs/changelog.md +18 -0
- package/docs/examples.md +74 -0
- package/docs/reference/classes/EntityStorageAuthenticationAdminRestClient.md +229 -0
- package/docs/reference/classes/EntityStorageAuthenticationRestClient.md +195 -0
- package/docs/reference/index.md +10 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationRestClientConstructorOptions.md +21 -0
- package/locales/en.json +1 -0
- package/package.json +54 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 IOTA Stiftung.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 3Sixty API Auth Entity Storage REST Client
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This package provides REST clients for authentication and admin operations against entity storage endpoints.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm install @3sixty/api-auth-entity-storage-rest-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
Usage of the APIs is shown in the examples [docs/examples.md](docs/examples.md)
|
|
14
|
+
|
|
15
|
+
## Reference
|
|
16
|
+
|
|
17
|
+
Detailed reference documentation for the API can be found in [docs/reference/index.md](docs/reference/index.md)
|
|
18
|
+
|
|
19
|
+
## Changelog
|
|
20
|
+
|
|
21
|
+
The changes between each version can be found in [docs/changelog.md](docs/changelog.md)
|
|
22
|
+
|
|
23
|
+
## Origin
|
|
24
|
+
|
|
25
|
+
This package is derived from the original [iotaledger/twin-api-auth](https://github.com/iotaledger/twin-api-auth/tree/next/packages/api-auth-entity-storage-rest-client) repository.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { BaseRestClient } from "@3sixty/api-core";
|
|
2
|
+
import { Guards } from "@3sixty/core";
|
|
3
|
+
import { HttpMethod } from "@3sixty/web";
|
|
4
|
+
/**
|
|
5
|
+
* The client to connect to the authentication admin service.
|
|
6
|
+
*/
|
|
7
|
+
export class EntityStorageAuthenticationAdminRestClient extends BaseRestClient {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static CLASS_NAME = "EntityStorageAuthenticationAdminRestClient";
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of EntityStorageAuthenticationAdminRestClient.
|
|
14
|
+
* @param config The configuration for the client.
|
|
15
|
+
*/
|
|
16
|
+
constructor(config) {
|
|
17
|
+
super("EntityStorageAuthenticationAdminRestClient", config, "authentication/admin");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns the class name of the component.
|
|
21
|
+
* @returns The class name of the component.
|
|
22
|
+
*/
|
|
23
|
+
className() {
|
|
24
|
+
return EntityStorageAuthenticationAdminRestClient.CLASS_NAME;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a login for the user.
|
|
28
|
+
* @param user The user to create.
|
|
29
|
+
* @returns Nothing.
|
|
30
|
+
*/
|
|
31
|
+
async create(user) {
|
|
32
|
+
Guards.object(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "user", user);
|
|
33
|
+
Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "user.email", user.email);
|
|
34
|
+
await this.fetch("/users", HttpMethod.POST, {
|
|
35
|
+
body: user
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Update a login for the user.
|
|
40
|
+
* @param user The user to update.
|
|
41
|
+
* @returns Nothing.
|
|
42
|
+
*/
|
|
43
|
+
async update(user) {
|
|
44
|
+
Guards.object(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "user", user);
|
|
45
|
+
Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "user.email", user.email);
|
|
46
|
+
await this.fetch("/users/:email", HttpMethod.PUT, {
|
|
47
|
+
pathParams: {
|
|
48
|
+
email: user.email
|
|
49
|
+
},
|
|
50
|
+
body: user
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get a user by email.
|
|
55
|
+
* @param email The email address of the user to get.
|
|
56
|
+
* @returns The user details.
|
|
57
|
+
*/
|
|
58
|
+
async get(email) {
|
|
59
|
+
Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "email", email);
|
|
60
|
+
const response = await this.fetch("/users/:email", HttpMethod.GET, {
|
|
61
|
+
pathParams: {
|
|
62
|
+
email
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return response.body;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get a user by identity.
|
|
69
|
+
* @param identity The identity of the user to get.
|
|
70
|
+
* @returns The user details.
|
|
71
|
+
*/
|
|
72
|
+
async getByIdentity(identity) {
|
|
73
|
+
Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "identity", identity);
|
|
74
|
+
const response = await this.fetch("/users/identity/:identity", "GET", {
|
|
75
|
+
pathParams: {
|
|
76
|
+
identity
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return response.body;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Remove a user.
|
|
83
|
+
* @param email The email address of the user to remove.
|
|
84
|
+
* @returns Nothing.
|
|
85
|
+
*/
|
|
86
|
+
async remove(email) {
|
|
87
|
+
Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "email", email);
|
|
88
|
+
await this.fetch("/users/:email", HttpMethod.DELETE, {
|
|
89
|
+
pathParams: {
|
|
90
|
+
email
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Update the user's password.
|
|
96
|
+
* @param email The email address of the user to update.
|
|
97
|
+
* @param newPassword The new password for the user.
|
|
98
|
+
* @param currentPassword The current password, optional, if supplied will check against existing.
|
|
99
|
+
* @returns Nothing.
|
|
100
|
+
*/
|
|
101
|
+
async updatePassword(email, newPassword, currentPassword) {
|
|
102
|
+
Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "email", email);
|
|
103
|
+
Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "newPassword", newPassword);
|
|
104
|
+
await this.fetch("/users/:email/password", HttpMethod.PUT, {
|
|
105
|
+
pathParams: {
|
|
106
|
+
email
|
|
107
|
+
},
|
|
108
|
+
body: {
|
|
109
|
+
newPassword,
|
|
110
|
+
currentPassword
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=entityStorageAuthenticationAdminRestClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityStorageAuthenticationAdminRestClient.js","sources":["../../src/entityStorageAuthenticationAdminRestClient.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIAdminUserCreateRequest,\n\tIAdminUserGetByIdentityRequest,\n\tIAdminUserGetRequest,\n\tIAdminUserGetResponse,\n\tIAdminUserRemoveRequest,\n\tIAdminUserUpdatePasswordRequest,\n\tIAdminUserUpdateRequest,\n\tIAuthenticationAdminComponent,\n\tIAuthenticationUser\n} from \"@3sixty/api-auth-entity-storage-models\";\nimport { BaseRestClient } from \"@3sixty/api-core\";\nimport type { IBaseRestClientConfig, INoContentResponse } from \"@3sixty/api-models\";\nimport { Guards } from \"@3sixty/core\";\n\nimport { HttpMethod } from \"@3sixty/web\";\n\n/**\n * The client to connect to the authentication admin service.\n */\nexport class EntityStorageAuthenticationAdminRestClient\n\textends BaseRestClient\n\timplements IAuthenticationAdminComponent\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = \"EntityStorageAuthenticationAdminRestClient\";\n\n\t/**\n\t * Create a new instance of EntityStorageAuthenticationAdminRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(\"EntityStorageAuthenticationAdminRestClient\", config, \"authentication/admin\");\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn EntityStorageAuthenticationAdminRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a login for the user.\n\t * @param user The user to create.\n\t * @returns Nothing.\n\t */\n\tpublic async create(user: IAuthenticationUser & { password: string }): Promise<void> {\n\t\tGuards.object(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, \"user\", user);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationAdminRestClient.CLASS_NAME,\n\t\t\t\"user.email\",\n\t\t\tuser.email\n\t\t);\n\n\t\tawait this.fetch<IAdminUserCreateRequest, INoContentResponse>(\"/users\", HttpMethod.POST, {\n\t\t\tbody: user\n\t\t});\n\t}\n\n\t/**\n\t * Update a login for the user.\n\t * @param user The user to update.\n\t * @returns Nothing.\n\t */\n\tpublic async update(user: Partial<IAuthenticationUser>): Promise<void> {\n\t\tGuards.object(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, \"user\", user);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationAdminRestClient.CLASS_NAME,\n\t\t\t\"user.email\",\n\t\t\tuser.email\n\t\t);\n\n\t\tawait this.fetch<IAdminUserUpdateRequest, INoContentResponse>(\"/users/:email\", HttpMethod.PUT, {\n\t\t\tpathParams: {\n\t\t\t\temail: user.email\n\t\t\t},\n\t\t\tbody: user\n\t\t});\n\t}\n\n\t/**\n\t * Get a user by email.\n\t * @param email The email address of the user to get.\n\t * @returns The user details.\n\t */\n\tpublic async get(email: string): Promise<IAuthenticationUser> {\n\t\tGuards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, \"email\", email);\n\n\t\tconst response = await this.fetch<IAdminUserGetRequest, IAdminUserGetResponse>(\n\t\t\t\"/users/:email\",\n\t\t\tHttpMethod.GET,\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\temail\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Get a user by identity.\n\t * @param identity The identity of the user to get.\n\t * @returns The user details.\n\t */\n\tpublic async getByIdentity(identity: string): Promise<IAuthenticationUser> {\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationAdminRestClient.CLASS_NAME,\n\t\t\t\"identity\",\n\t\t\tidentity\n\t\t);\n\n\t\tconst response = await this.fetch<IAdminUserGetByIdentityRequest, IAdminUserGetResponse>(\n\t\t\t\"/users/identity/:identity\",\n\t\t\t\"GET\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tidentity\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Remove a user.\n\t * @param email The email address of the user to remove.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(email: string): Promise<void> {\n\t\tGuards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, \"email\", email);\n\n\t\tawait this.fetch<IAdminUserRemoveRequest, INoContentResponse>(\n\t\t\t\"/users/:email\",\n\t\t\tHttpMethod.DELETE,\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\temail\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Update the user's password.\n\t * @param email The email address of the user to update.\n\t * @param newPassword The new password for the user.\n\t * @param currentPassword The current password, optional, if supplied will check against existing.\n\t * @returns Nothing.\n\t */\n\tpublic async updatePassword(\n\t\temail: string,\n\t\tnewPassword: string,\n\t\tcurrentPassword?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, \"email\", email);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationAdminRestClient.CLASS_NAME,\n\t\t\t\"newPassword\",\n\t\t\tnewPassword\n\t\t);\n\n\t\tawait this.fetch<IAdminUserUpdatePasswordRequest, INoContentResponse>(\n\t\t\t\"/users/:email/password\",\n\t\t\tHttpMethod.PUT,\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\temail\n\t\t\t\t},\n\t\t\t\tbody: {\n\t\t\t\t\tnewPassword,\n\t\t\t\t\tcurrentPassword\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { BaseRestClient } from "@3sixty/api-core";
|
|
2
|
+
import { Guards } from "@3sixty/core";
|
|
3
|
+
import { CookieHelper, HeaderTypes } from "@3sixty/web";
|
|
4
|
+
/**
|
|
5
|
+
* The client to connect to the authentication service.
|
|
6
|
+
*/
|
|
7
|
+
export class EntityStorageAuthenticationRestClient extends BaseRestClient {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static CLASS_NAME = "EntityStorageAuthenticationRestClient";
|
|
12
|
+
/**
|
|
13
|
+
* The default name for the access token as a cookie.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
static DEFAULT_COOKIE_NAME = "access_token";
|
|
17
|
+
/**
|
|
18
|
+
* The name of the cookie to use for storing the auth token.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
_cookieName;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new instance of EntityStorageAuthenticationRestClient.
|
|
24
|
+
* @param config The configuration for the client.
|
|
25
|
+
*/
|
|
26
|
+
constructor(config) {
|
|
27
|
+
super("EntityStorageAuthenticationRestClient", config, "authentication");
|
|
28
|
+
this._cookieName =
|
|
29
|
+
config.cookieName ?? EntityStorageAuthenticationRestClient.DEFAULT_COOKIE_NAME;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns the class name of the component.
|
|
33
|
+
* @returns The class name of the component.
|
|
34
|
+
*/
|
|
35
|
+
className() {
|
|
36
|
+
return EntityStorageAuthenticationRestClient.CLASS_NAME;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Perform a login for the user.
|
|
40
|
+
* @param email The email address for the user.
|
|
41
|
+
* @param password The password for the user.
|
|
42
|
+
* @returns The authentication token for the user, if it uses a mechanism with public access.
|
|
43
|
+
*/
|
|
44
|
+
async login(email, password) {
|
|
45
|
+
Guards.stringValue(EntityStorageAuthenticationRestClient.CLASS_NAME, "email", email);
|
|
46
|
+
Guards.stringValue(EntityStorageAuthenticationRestClient.CLASS_NAME, "password", password);
|
|
47
|
+
const response = await this.fetch("/login", "POST", {
|
|
48
|
+
body: {
|
|
49
|
+
email,
|
|
50
|
+
password
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
token: CookieHelper.getCookieFromHeaders(response?.headers?.[HeaderTypes.SetCookie], this._cookieName),
|
|
55
|
+
expiry: response.body.expiry
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Logout the current user.
|
|
60
|
+
* @param token The token to logout, if it uses a mechanism with public access.
|
|
61
|
+
* @returns A promise that resolves when the logout request has completed.
|
|
62
|
+
*/
|
|
63
|
+
async logout(token) {
|
|
64
|
+
await this.fetch("/logout", "POST", {
|
|
65
|
+
body: {
|
|
66
|
+
token
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Refresh the token.
|
|
72
|
+
* @param token The token to refresh, if it uses a mechanism with public access.
|
|
73
|
+
* @returns The refreshed token, if it uses a mechanism with public access.
|
|
74
|
+
*/
|
|
75
|
+
async refresh(token) {
|
|
76
|
+
const response = await this.fetch("/refresh", "POST", {
|
|
77
|
+
body: {
|
|
78
|
+
token
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
token: CookieHelper.getCookieFromHeaders(response?.headers?.[HeaderTypes.SetCookie], this._cookieName),
|
|
83
|
+
expiry: response.body.expiry
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Update the user's password.
|
|
88
|
+
* @param currentPassword The current password for the user.
|
|
89
|
+
* @param newPassword The new password for the user.
|
|
90
|
+
* @returns A promise that resolves when the password has been updated on the server.
|
|
91
|
+
*/
|
|
92
|
+
async updatePassword(currentPassword, newPassword) {
|
|
93
|
+
Guards.stringValue(EntityStorageAuthenticationRestClient.CLASS_NAME, "currentPassword", currentPassword);
|
|
94
|
+
Guards.stringValue(EntityStorageAuthenticationRestClient.CLASS_NAME, "newPassword", newPassword);
|
|
95
|
+
await this.fetch("/password", "PUT", {
|
|
96
|
+
body: {
|
|
97
|
+
currentPassword,
|
|
98
|
+
newPassword
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the password policy used for password validation.
|
|
104
|
+
* @returns The password policy options.
|
|
105
|
+
*/
|
|
106
|
+
async passwordPolicy() {
|
|
107
|
+
const response = await this.fetch("/policy", "GET");
|
|
108
|
+
return response.body;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=entityStorageAuthenticationRestClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityStorageAuthenticationRestClient.js","sources":["../../src/entityStorageAuthenticationRestClient.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIAuthenticationComponent,\n\tILoginRequest,\n\tILoginResponse,\n\tILogoutRequest,\n\tIPasswordPolicyResponse,\n\tIPasswordOptions,\n\tIRefreshTokenRequest,\n\tIRefreshTokenResponse,\n\tIUpdatePasswordRequest\n} from \"@3sixty/api-auth-entity-storage-models\";\nimport { BaseRestClient } from \"@3sixty/api-core\";\nimport type { INoContentRequest, INoContentResponse } from \"@3sixty/api-models\";\nimport { Guards } from \"@3sixty/core\";\n\nimport { CookieHelper, HeaderTypes } from \"@3sixty/web\";\nimport type { IEntityStorageAuthenticationRestClientConstructorOptions } from \"./models/entityStorageAuthenticationRestClientConstructorOptions.js\";\n\n/**\n * The client to connect to the authentication service.\n */\nexport class EntityStorageAuthenticationRestClient\n\textends BaseRestClient\n\timplements IAuthenticationComponent\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = \"EntityStorageAuthenticationRestClient\";\n\n\t/**\n\t * The default name for the access token as a cookie.\n\t * @internal\n\t */\n\tpublic static readonly DEFAULT_COOKIE_NAME: string = \"access_token\";\n\n\t/**\n\t * The name of the cookie to use for storing the auth token.\n\t * @internal\n\t */\n\tprivate readonly _cookieName: string;\n\n\t/**\n\t * Create a new instance of EntityStorageAuthenticationRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IEntityStorageAuthenticationRestClientConstructorOptions) {\n\t\tsuper(\"EntityStorageAuthenticationRestClient\", config, \"authentication\");\n\t\tthis._cookieName =\n\t\t\tconfig.cookieName ?? EntityStorageAuthenticationRestClient.DEFAULT_COOKIE_NAME;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn EntityStorageAuthenticationRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Perform a login for the user.\n\t * @param email The email address for the user.\n\t * @param password The password for the user.\n\t * @returns The authentication token for the user, if it uses a mechanism with public access.\n\t */\n\tpublic async login(\n\t\temail: string,\n\t\tpassword: string\n\t): Promise<{\n\t\ttoken?: string;\n\t\texpiry: number;\n\t}> {\n\t\tGuards.stringValue(EntityStorageAuthenticationRestClient.CLASS_NAME, \"email\", email);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationRestClient.CLASS_NAME,\n\t\t\t\"password\",\n\t\t\tpassword\n\t\t);\n\n\t\tconst response = await this.fetch<ILoginRequest, ILoginResponse>(\"/login\", \"POST\", {\n\t\t\tbody: {\n\t\t\t\temail,\n\t\t\t\tpassword\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\ttoken: CookieHelper.getCookieFromHeaders(\n\t\t\t\tresponse?.headers?.[HeaderTypes.SetCookie],\n\t\t\t\tthis._cookieName\n\t\t\t),\n\t\t\texpiry: response.body.expiry\n\t\t};\n\t}\n\n\t/**\n\t * Logout the current user.\n\t * @param token The token to logout, if it uses a mechanism with public access.\n\t * @returns A promise that resolves when the logout request has completed.\n\t */\n\tpublic async logout(token?: string): Promise<void> {\n\t\tawait this.fetch<ILogoutRequest, INoContentResponse>(\"/logout\", \"POST\", {\n\t\t\tbody: {\n\t\t\t\ttoken\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Refresh the token.\n\t * @param token The token to refresh, if it uses a mechanism with public access.\n\t * @returns The refreshed token, if it uses a mechanism with public access.\n\t */\n\tpublic async refresh(token?: string): Promise<{\n\t\ttoken?: string;\n\t\texpiry: number;\n\t}> {\n\t\tconst response = await this.fetch<IRefreshTokenRequest, IRefreshTokenResponse>(\n\t\t\t\"/refresh\",\n\t\t\t\"POST\",\n\t\t\t{\n\t\t\t\tbody: {\n\t\t\t\t\ttoken\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn {\n\t\t\ttoken: CookieHelper.getCookieFromHeaders(\n\t\t\t\tresponse?.headers?.[HeaderTypes.SetCookie],\n\t\t\t\tthis._cookieName\n\t\t\t),\n\t\t\texpiry: response.body.expiry\n\t\t};\n\t}\n\n\t/**\n\t * Update the user's password.\n\t * @param currentPassword The current password for the user.\n\t * @param newPassword The new password for the user.\n\t * @returns A promise that resolves when the password has been updated on the server.\n\t */\n\tpublic async updatePassword(currentPassword: string, newPassword: string): Promise<void> {\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationRestClient.CLASS_NAME,\n\t\t\t\"currentPassword\",\n\t\t\tcurrentPassword\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationRestClient.CLASS_NAME,\n\t\t\t\"newPassword\",\n\t\t\tnewPassword\n\t\t);\n\n\t\tawait this.fetch<IUpdatePasswordRequest, INoContentResponse>(\"/password\", \"PUT\", {\n\t\t\tbody: {\n\t\t\t\tcurrentPassword,\n\t\t\t\tnewPassword\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Get the password policy used for password validation.\n\t * @returns The password policy options.\n\t */\n\tpublic async passwordPolicy(): Promise<IPasswordOptions> {\n\t\tconst response = await this.fetch<INoContentRequest, IPasswordPolicyResponse>(\"/policy\", \"GET\");\n\n\t\treturn response.body;\n\t}\n}\n"]}
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
export * from "./entityStorageAuthenticationAdminRestClient.js";
|
|
4
|
+
export * from "./entityStorageAuthenticationRestClient.js";
|
|
5
|
+
export * from "./models/entityStorageAuthenticationRestClientConstructorOptions.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,iDAAiD,CAAC;AAChE,cAAc,4CAA4C,CAAC;AAC3D,cAAc,qEAAqE,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./entityStorageAuthenticationAdminRestClient.js\";\nexport * from \"./entityStorageAuthenticationRestClient.js\";\nexport * from \"./models/entityStorageAuthenticationRestClientConstructorOptions.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityStorageAuthenticationRestClientConstructorOptions.js","sources":["../../../src/models/entityStorageAuthenticationRestClientConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IBaseRestClientConfig } from \"@3sixty/api-models\";\n\n/**\n * Options for the Entity Storage Authentication REST client constructor.\n */\nexport interface IEntityStorageAuthenticationRestClientConstructorOptions extends IBaseRestClientConfig {\n\t/**\n\t * The name of the cookie to use for storing the auth token.\n\t * @default access_token\n\t */\n\tcookieName?: string;\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { IAuthenticationAdminComponent, IAuthenticationUser } from "@3sixty/api-auth-entity-storage-models";
|
|
2
|
+
import { BaseRestClient } from "@3sixty/api-core";
|
|
3
|
+
import type { IBaseRestClientConfig } from "@3sixty/api-models";
|
|
4
|
+
/**
|
|
5
|
+
* The client to connect to the authentication admin service.
|
|
6
|
+
*/
|
|
7
|
+
export declare class EntityStorageAuthenticationAdminRestClient extends BaseRestClient implements IAuthenticationAdminComponent {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static readonly CLASS_NAME: string;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of EntityStorageAuthenticationAdminRestClient.
|
|
14
|
+
* @param config The configuration for the client.
|
|
15
|
+
*/
|
|
16
|
+
constructor(config: IBaseRestClientConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Returns the class name of the component.
|
|
19
|
+
* @returns The class name of the component.
|
|
20
|
+
*/
|
|
21
|
+
className(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Create a login for the user.
|
|
24
|
+
* @param user The user to create.
|
|
25
|
+
* @returns Nothing.
|
|
26
|
+
*/
|
|
27
|
+
create(user: IAuthenticationUser & {
|
|
28
|
+
password: string;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Update a login for the user.
|
|
32
|
+
* @param user The user to update.
|
|
33
|
+
* @returns Nothing.
|
|
34
|
+
*/
|
|
35
|
+
update(user: Partial<IAuthenticationUser>): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Get a user by email.
|
|
38
|
+
* @param email The email address of the user to get.
|
|
39
|
+
* @returns The user details.
|
|
40
|
+
*/
|
|
41
|
+
get(email: string): Promise<IAuthenticationUser>;
|
|
42
|
+
/**
|
|
43
|
+
* Get a user by identity.
|
|
44
|
+
* @param identity The identity of the user to get.
|
|
45
|
+
* @returns The user details.
|
|
46
|
+
*/
|
|
47
|
+
getByIdentity(identity: string): Promise<IAuthenticationUser>;
|
|
48
|
+
/**
|
|
49
|
+
* Remove a user.
|
|
50
|
+
* @param email The email address of the user to remove.
|
|
51
|
+
* @returns Nothing.
|
|
52
|
+
*/
|
|
53
|
+
remove(email: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Update the user's password.
|
|
56
|
+
* @param email The email address of the user to update.
|
|
57
|
+
* @param newPassword The new password for the user.
|
|
58
|
+
* @param currentPassword The current password, optional, if supplied will check against existing.
|
|
59
|
+
* @returns Nothing.
|
|
60
|
+
*/
|
|
61
|
+
updatePassword(email: string, newPassword: string, currentPassword?: string): Promise<void>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { IAuthenticationComponent, IPasswordOptions } from "@3sixty/api-auth-entity-storage-models";
|
|
2
|
+
import { BaseRestClient } from "@3sixty/api-core";
|
|
3
|
+
import type { IEntityStorageAuthenticationRestClientConstructorOptions } from "./models/entityStorageAuthenticationRestClientConstructorOptions.js";
|
|
4
|
+
/**
|
|
5
|
+
* The client to connect to the authentication service.
|
|
6
|
+
*/
|
|
7
|
+
export declare class EntityStorageAuthenticationRestClient extends BaseRestClient implements IAuthenticationComponent {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static readonly CLASS_NAME: string;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of EntityStorageAuthenticationRestClient.
|
|
14
|
+
* @param config The configuration for the client.
|
|
15
|
+
*/
|
|
16
|
+
constructor(config: IEntityStorageAuthenticationRestClientConstructorOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Returns the class name of the component.
|
|
19
|
+
* @returns The class name of the component.
|
|
20
|
+
*/
|
|
21
|
+
className(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Perform a login for the user.
|
|
24
|
+
* @param email The email address for the user.
|
|
25
|
+
* @param password The password for the user.
|
|
26
|
+
* @returns The authentication token for the user, if it uses a mechanism with public access.
|
|
27
|
+
*/
|
|
28
|
+
login(email: string, password: string): Promise<{
|
|
29
|
+
token?: string;
|
|
30
|
+
expiry: number;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Logout the current user.
|
|
34
|
+
* @param token The token to logout, if it uses a mechanism with public access.
|
|
35
|
+
* @returns A promise that resolves when the logout request has completed.
|
|
36
|
+
*/
|
|
37
|
+
logout(token?: string): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Refresh the token.
|
|
40
|
+
* @param token The token to refresh, if it uses a mechanism with public access.
|
|
41
|
+
* @returns The refreshed token, if it uses a mechanism with public access.
|
|
42
|
+
*/
|
|
43
|
+
refresh(token?: string): Promise<{
|
|
44
|
+
token?: string;
|
|
45
|
+
expiry: number;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Update the user's password.
|
|
49
|
+
* @param currentPassword The current password for the user.
|
|
50
|
+
* @param newPassword The new password for the user.
|
|
51
|
+
* @returns A promise that resolves when the password has been updated on the server.
|
|
52
|
+
*/
|
|
53
|
+
updatePassword(currentPassword: string, newPassword: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Get the password policy used for password validation.
|
|
56
|
+
* @returns The password policy options.
|
|
57
|
+
*/
|
|
58
|
+
passwordPolicy(): Promise<IPasswordOptions>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IBaseRestClientConfig } from "@3sixty/api-models";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the Entity Storage Authentication REST client constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface IEntityStorageAuthenticationRestClientConstructorOptions extends IBaseRestClientConfig {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the cookie to use for storing the auth token.
|
|
8
|
+
* @default access_token
|
|
9
|
+
*/
|
|
10
|
+
cookieName?: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.20.0-next.1](https://github.com/3sixtyglobal/api-auth/compare/api-auth-entity-storage-rest-client-v0.20.0-next.0...api-auth-entity-storage-rest-client-v0.20.0-next.1) (2026-10-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* authorization ([#3](https://github.com/3sixtyglobal/api-auth/issues/3)) ([5688693](https://github.com/3sixtyglobal/api-auth/commit/568869364065b9d2c82c5c17c81f07cbdc64ec8b))
|
|
9
|
+
* initial commit ([b9112fb](https://github.com/3sixtyglobal/api-auth/commit/b9112fb6994758b43effdde1b9e41435ff50fe50))
|
|
10
|
+
* publish packages under the [@3sixty](https://github.com/3sixty) namespace ([6c22482](https://github.com/3sixtyglobal/api-auth/commit/6c2248295620000807ff91087c3b1dfc9b018b31))
|
|
11
|
+
* updated ts compile ([83c72bd](https://github.com/3sixtyglobal/api-auth/commit/83c72bd5d2e9d81208b7a2755450d96fbbb04004))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Dependencies
|
|
15
|
+
|
|
16
|
+
* The following workspace dependencies were updated
|
|
17
|
+
* dependencies
|
|
18
|
+
* @3sixty/api-auth-entity-storage-models bumped from 0.20.0-next.0 to 0.20.0-next.1
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Auth Entity Storage Rest Client Examples
|
|
2
|
+
|
|
3
|
+
Use these snippets to integrate sign-in and user administration flows from browser or server-side TypeScript applications.
|
|
4
|
+
|
|
5
|
+
## EntityStorageAuthenticationAdminRestClient
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { EntityStorageAuthenticationAdminRestClient } from '@3sixty/api-auth-entity-storage-rest-client';
|
|
9
|
+
|
|
10
|
+
const adminClient = new EntityStorageAuthenticationAdminRestClient({
|
|
11
|
+
endpoint: 'https://api.example.org',
|
|
12
|
+
pathPrefix: 'v1'
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
console.log(adminClient.className()); // EntityStorageAuthenticationAdminRestClient
|
|
16
|
+
|
|
17
|
+
await adminClient.create({
|
|
18
|
+
email: 'ops@example.org',
|
|
19
|
+
password: 'StrongPassword123',
|
|
20
|
+
userIdentity: 'did:example:ops',
|
|
21
|
+
organizationIdentity: 'did:example:core'
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await adminClient.update({
|
|
25
|
+
email: 'ops@example.org',
|
|
26
|
+
userIdentity: 'did:example:ops:team'
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
await adminClient.updatePassword('ops@example.org', 'StrongPassword124', 'StrongPassword123');
|
|
30
|
+
const adminUser = await adminClient.get('ops@example.org');
|
|
31
|
+
console.log(adminUser.email); // ops@example.org
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { EntityStorageAuthenticationAdminRestClient } from '@3sixty/api-auth-entity-storage-rest-client';
|
|
36
|
+
|
|
37
|
+
const adminClient = new EntityStorageAuthenticationAdminRestClient({
|
|
38
|
+
endpoint: 'https://api.example.org',
|
|
39
|
+
pathPrefix: 'v1'
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const byEmail = await adminClient.get('ops@example.org');
|
|
43
|
+
const byIdentity = await adminClient.getByIdentity('did:example:ops:team');
|
|
44
|
+
await adminClient.remove('ops@example.org');
|
|
45
|
+
|
|
46
|
+
console.log(byEmail.email); // ops@example.org
|
|
47
|
+
console.log(byIdentity.userIdentity); // did:example:ops:team
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## EntityStorageAuthenticationRestClient
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { EntityStorageAuthenticationRestClient } from '@3sixty/api-auth-entity-storage-rest-client';
|
|
54
|
+
|
|
55
|
+
const authClient = new EntityStorageAuthenticationRestClient({
|
|
56
|
+
endpoint: 'https://api.example.org',
|
|
57
|
+
pathPrefix: 'v1',
|
|
58
|
+
cookieName: 'access_token'
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
console.log(authClient.className()); // EntityStorageAuthenticationRestClient
|
|
62
|
+
|
|
63
|
+
const policy = await authClient.passwordPolicy();
|
|
64
|
+
console.log(policy.minPasswordLength); // 8
|
|
65
|
+
|
|
66
|
+
const loginResponse = await authClient.login('alice@example.org', 'correct-horse-battery-staple');
|
|
67
|
+
|
|
68
|
+
await authClient.updatePassword('correct-horse-battery-staple', 'correct-horse-battery-staple-2');
|
|
69
|
+
|
|
70
|
+
const refreshResponse = await authClient.refresh(loginResponse.token);
|
|
71
|
+
|
|
72
|
+
await authClient.logout(refreshResponse.token);
|
|
73
|
+
console.log(refreshResponse.expiry > 0); // true
|
|
74
|
+
```
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Class: EntityStorageAuthenticationAdminRestClient
|
|
2
|
+
|
|
3
|
+
The client to connect to the authentication admin service.
|
|
4
|
+
|
|
5
|
+
## Extends
|
|
6
|
+
|
|
7
|
+
- `BaseRestClient`
|
|
8
|
+
|
|
9
|
+
## Implements
|
|
10
|
+
|
|
11
|
+
- `IAuthenticationAdminComponent`
|
|
12
|
+
|
|
13
|
+
## Constructors
|
|
14
|
+
|
|
15
|
+
### Constructor
|
|
16
|
+
|
|
17
|
+
> **new EntityStorageAuthenticationAdminRestClient**(`config`): `EntityStorageAuthenticationAdminRestClient`
|
|
18
|
+
|
|
19
|
+
Create a new instance of EntityStorageAuthenticationAdminRestClient.
|
|
20
|
+
|
|
21
|
+
#### Parameters
|
|
22
|
+
|
|
23
|
+
##### config
|
|
24
|
+
|
|
25
|
+
`IBaseRestClientConfig`
|
|
26
|
+
|
|
27
|
+
The configuration for the client.
|
|
28
|
+
|
|
29
|
+
#### Returns
|
|
30
|
+
|
|
31
|
+
`EntityStorageAuthenticationAdminRestClient`
|
|
32
|
+
|
|
33
|
+
#### Overrides
|
|
34
|
+
|
|
35
|
+
`BaseRestClient.constructor`
|
|
36
|
+
|
|
37
|
+
## Properties
|
|
38
|
+
|
|
39
|
+
### CLASS\_NAME {#class_name}
|
|
40
|
+
|
|
41
|
+
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
42
|
+
|
|
43
|
+
Runtime name for the class.
|
|
44
|
+
|
|
45
|
+
## Methods
|
|
46
|
+
|
|
47
|
+
### className() {#classname}
|
|
48
|
+
|
|
49
|
+
> **className**(): `string`
|
|
50
|
+
|
|
51
|
+
Returns the class name of the component.
|
|
52
|
+
|
|
53
|
+
#### Returns
|
|
54
|
+
|
|
55
|
+
`string`
|
|
56
|
+
|
|
57
|
+
The class name of the component.
|
|
58
|
+
|
|
59
|
+
#### Implementation of
|
|
60
|
+
|
|
61
|
+
`IAuthenticationAdminComponent.className`
|
|
62
|
+
|
|
63
|
+
***
|
|
64
|
+
|
|
65
|
+
### create() {#create}
|
|
66
|
+
|
|
67
|
+
> **create**(`user`): `Promise`\<`void`\>
|
|
68
|
+
|
|
69
|
+
Create a login for the user.
|
|
70
|
+
|
|
71
|
+
#### Parameters
|
|
72
|
+
|
|
73
|
+
##### user
|
|
74
|
+
|
|
75
|
+
`IAuthenticationUser` & `object`
|
|
76
|
+
|
|
77
|
+
The user to create.
|
|
78
|
+
|
|
79
|
+
#### Returns
|
|
80
|
+
|
|
81
|
+
`Promise`\<`void`\>
|
|
82
|
+
|
|
83
|
+
Nothing.
|
|
84
|
+
|
|
85
|
+
#### Implementation of
|
|
86
|
+
|
|
87
|
+
`IAuthenticationAdminComponent.create`
|
|
88
|
+
|
|
89
|
+
***
|
|
90
|
+
|
|
91
|
+
### update() {#update}
|
|
92
|
+
|
|
93
|
+
> **update**(`user`): `Promise`\<`void`\>
|
|
94
|
+
|
|
95
|
+
Update a login for the user.
|
|
96
|
+
|
|
97
|
+
#### Parameters
|
|
98
|
+
|
|
99
|
+
##### user
|
|
100
|
+
|
|
101
|
+
`Partial`\<`IAuthenticationUser`\>
|
|
102
|
+
|
|
103
|
+
The user to update.
|
|
104
|
+
|
|
105
|
+
#### Returns
|
|
106
|
+
|
|
107
|
+
`Promise`\<`void`\>
|
|
108
|
+
|
|
109
|
+
Nothing.
|
|
110
|
+
|
|
111
|
+
#### Implementation of
|
|
112
|
+
|
|
113
|
+
`IAuthenticationAdminComponent.update`
|
|
114
|
+
|
|
115
|
+
***
|
|
116
|
+
|
|
117
|
+
### get() {#get}
|
|
118
|
+
|
|
119
|
+
> **get**(`email`): `Promise`\<`IAuthenticationUser`\>
|
|
120
|
+
|
|
121
|
+
Get a user by email.
|
|
122
|
+
|
|
123
|
+
#### Parameters
|
|
124
|
+
|
|
125
|
+
##### email
|
|
126
|
+
|
|
127
|
+
`string`
|
|
128
|
+
|
|
129
|
+
The email address of the user to get.
|
|
130
|
+
|
|
131
|
+
#### Returns
|
|
132
|
+
|
|
133
|
+
`Promise`\<`IAuthenticationUser`\>
|
|
134
|
+
|
|
135
|
+
The user details.
|
|
136
|
+
|
|
137
|
+
#### Implementation of
|
|
138
|
+
|
|
139
|
+
`IAuthenticationAdminComponent.get`
|
|
140
|
+
|
|
141
|
+
***
|
|
142
|
+
|
|
143
|
+
### getByIdentity() {#getbyidentity}
|
|
144
|
+
|
|
145
|
+
> **getByIdentity**(`identity`): `Promise`\<`IAuthenticationUser`\>
|
|
146
|
+
|
|
147
|
+
Get a user by identity.
|
|
148
|
+
|
|
149
|
+
#### Parameters
|
|
150
|
+
|
|
151
|
+
##### identity
|
|
152
|
+
|
|
153
|
+
`string`
|
|
154
|
+
|
|
155
|
+
The identity of the user to get.
|
|
156
|
+
|
|
157
|
+
#### Returns
|
|
158
|
+
|
|
159
|
+
`Promise`\<`IAuthenticationUser`\>
|
|
160
|
+
|
|
161
|
+
The user details.
|
|
162
|
+
|
|
163
|
+
#### Implementation of
|
|
164
|
+
|
|
165
|
+
`IAuthenticationAdminComponent.getByIdentity`
|
|
166
|
+
|
|
167
|
+
***
|
|
168
|
+
|
|
169
|
+
### remove() {#remove}
|
|
170
|
+
|
|
171
|
+
> **remove**(`email`): `Promise`\<`void`\>
|
|
172
|
+
|
|
173
|
+
Remove a user.
|
|
174
|
+
|
|
175
|
+
#### Parameters
|
|
176
|
+
|
|
177
|
+
##### email
|
|
178
|
+
|
|
179
|
+
`string`
|
|
180
|
+
|
|
181
|
+
The email address of the user to remove.
|
|
182
|
+
|
|
183
|
+
#### Returns
|
|
184
|
+
|
|
185
|
+
`Promise`\<`void`\>
|
|
186
|
+
|
|
187
|
+
Nothing.
|
|
188
|
+
|
|
189
|
+
#### Implementation of
|
|
190
|
+
|
|
191
|
+
`IAuthenticationAdminComponent.remove`
|
|
192
|
+
|
|
193
|
+
***
|
|
194
|
+
|
|
195
|
+
### updatePassword() {#updatepassword}
|
|
196
|
+
|
|
197
|
+
> **updatePassword**(`email`, `newPassword`, `currentPassword?`): `Promise`\<`void`\>
|
|
198
|
+
|
|
199
|
+
Update the user's password.
|
|
200
|
+
|
|
201
|
+
#### Parameters
|
|
202
|
+
|
|
203
|
+
##### email
|
|
204
|
+
|
|
205
|
+
`string`
|
|
206
|
+
|
|
207
|
+
The email address of the user to update.
|
|
208
|
+
|
|
209
|
+
##### newPassword
|
|
210
|
+
|
|
211
|
+
`string`
|
|
212
|
+
|
|
213
|
+
The new password for the user.
|
|
214
|
+
|
|
215
|
+
##### currentPassword?
|
|
216
|
+
|
|
217
|
+
`string`
|
|
218
|
+
|
|
219
|
+
The current password, optional, if supplied will check against existing.
|
|
220
|
+
|
|
221
|
+
#### Returns
|
|
222
|
+
|
|
223
|
+
`Promise`\<`void`\>
|
|
224
|
+
|
|
225
|
+
Nothing.
|
|
226
|
+
|
|
227
|
+
#### Implementation of
|
|
228
|
+
|
|
229
|
+
`IAuthenticationAdminComponent.updatePassword`
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Class: EntityStorageAuthenticationRestClient
|
|
2
|
+
|
|
3
|
+
The client to connect to the authentication service.
|
|
4
|
+
|
|
5
|
+
## Extends
|
|
6
|
+
|
|
7
|
+
- `BaseRestClient`
|
|
8
|
+
|
|
9
|
+
## Implements
|
|
10
|
+
|
|
11
|
+
- `IAuthenticationComponent`
|
|
12
|
+
|
|
13
|
+
## Constructors
|
|
14
|
+
|
|
15
|
+
### Constructor
|
|
16
|
+
|
|
17
|
+
> **new EntityStorageAuthenticationRestClient**(`config`): `EntityStorageAuthenticationRestClient`
|
|
18
|
+
|
|
19
|
+
Create a new instance of EntityStorageAuthenticationRestClient.
|
|
20
|
+
|
|
21
|
+
#### Parameters
|
|
22
|
+
|
|
23
|
+
##### config
|
|
24
|
+
|
|
25
|
+
[`IEntityStorageAuthenticationRestClientConstructorOptions`](../interfaces/IEntityStorageAuthenticationRestClientConstructorOptions.md)
|
|
26
|
+
|
|
27
|
+
The configuration for the client.
|
|
28
|
+
|
|
29
|
+
#### Returns
|
|
30
|
+
|
|
31
|
+
`EntityStorageAuthenticationRestClient`
|
|
32
|
+
|
|
33
|
+
#### Overrides
|
|
34
|
+
|
|
35
|
+
`BaseRestClient.constructor`
|
|
36
|
+
|
|
37
|
+
## Properties
|
|
38
|
+
|
|
39
|
+
### CLASS\_NAME {#class_name}
|
|
40
|
+
|
|
41
|
+
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
42
|
+
|
|
43
|
+
Runtime name for the class.
|
|
44
|
+
|
|
45
|
+
## Methods
|
|
46
|
+
|
|
47
|
+
### className() {#classname}
|
|
48
|
+
|
|
49
|
+
> **className**(): `string`
|
|
50
|
+
|
|
51
|
+
Returns the class name of the component.
|
|
52
|
+
|
|
53
|
+
#### Returns
|
|
54
|
+
|
|
55
|
+
`string`
|
|
56
|
+
|
|
57
|
+
The class name of the component.
|
|
58
|
+
|
|
59
|
+
#### Implementation of
|
|
60
|
+
|
|
61
|
+
`IAuthenticationComponent.className`
|
|
62
|
+
|
|
63
|
+
***
|
|
64
|
+
|
|
65
|
+
### login() {#login}
|
|
66
|
+
|
|
67
|
+
> **login**(`email`, `password`): `Promise`\<\{ `token?`: `string`; `expiry`: `number`; \}\>
|
|
68
|
+
|
|
69
|
+
Perform a login for the user.
|
|
70
|
+
|
|
71
|
+
#### Parameters
|
|
72
|
+
|
|
73
|
+
##### email
|
|
74
|
+
|
|
75
|
+
`string`
|
|
76
|
+
|
|
77
|
+
The email address for the user.
|
|
78
|
+
|
|
79
|
+
##### password
|
|
80
|
+
|
|
81
|
+
`string`
|
|
82
|
+
|
|
83
|
+
The password for the user.
|
|
84
|
+
|
|
85
|
+
#### Returns
|
|
86
|
+
|
|
87
|
+
`Promise`\<\{ `token?`: `string`; `expiry`: `number`; \}\>
|
|
88
|
+
|
|
89
|
+
The authentication token for the user, if it uses a mechanism with public access.
|
|
90
|
+
|
|
91
|
+
#### Implementation of
|
|
92
|
+
|
|
93
|
+
`IAuthenticationComponent.login`
|
|
94
|
+
|
|
95
|
+
***
|
|
96
|
+
|
|
97
|
+
### logout() {#logout}
|
|
98
|
+
|
|
99
|
+
> **logout**(`token?`): `Promise`\<`void`\>
|
|
100
|
+
|
|
101
|
+
Logout the current user.
|
|
102
|
+
|
|
103
|
+
#### Parameters
|
|
104
|
+
|
|
105
|
+
##### token?
|
|
106
|
+
|
|
107
|
+
`string`
|
|
108
|
+
|
|
109
|
+
The token to logout, if it uses a mechanism with public access.
|
|
110
|
+
|
|
111
|
+
#### Returns
|
|
112
|
+
|
|
113
|
+
`Promise`\<`void`\>
|
|
114
|
+
|
|
115
|
+
A promise that resolves when the logout request has completed.
|
|
116
|
+
|
|
117
|
+
#### Implementation of
|
|
118
|
+
|
|
119
|
+
`IAuthenticationComponent.logout`
|
|
120
|
+
|
|
121
|
+
***
|
|
122
|
+
|
|
123
|
+
### refresh() {#refresh}
|
|
124
|
+
|
|
125
|
+
> **refresh**(`token?`): `Promise`\<\{ `token?`: `string`; `expiry`: `number`; \}\>
|
|
126
|
+
|
|
127
|
+
Refresh the token.
|
|
128
|
+
|
|
129
|
+
#### Parameters
|
|
130
|
+
|
|
131
|
+
##### token?
|
|
132
|
+
|
|
133
|
+
`string`
|
|
134
|
+
|
|
135
|
+
The token to refresh, if it uses a mechanism with public access.
|
|
136
|
+
|
|
137
|
+
#### Returns
|
|
138
|
+
|
|
139
|
+
`Promise`\<\{ `token?`: `string`; `expiry`: `number`; \}\>
|
|
140
|
+
|
|
141
|
+
The refreshed token, if it uses a mechanism with public access.
|
|
142
|
+
|
|
143
|
+
#### Implementation of
|
|
144
|
+
|
|
145
|
+
`IAuthenticationComponent.refresh`
|
|
146
|
+
|
|
147
|
+
***
|
|
148
|
+
|
|
149
|
+
### updatePassword() {#updatepassword}
|
|
150
|
+
|
|
151
|
+
> **updatePassword**(`currentPassword`, `newPassword`): `Promise`\<`void`\>
|
|
152
|
+
|
|
153
|
+
Update the user's password.
|
|
154
|
+
|
|
155
|
+
#### Parameters
|
|
156
|
+
|
|
157
|
+
##### currentPassword
|
|
158
|
+
|
|
159
|
+
`string`
|
|
160
|
+
|
|
161
|
+
The current password for the user.
|
|
162
|
+
|
|
163
|
+
##### newPassword
|
|
164
|
+
|
|
165
|
+
`string`
|
|
166
|
+
|
|
167
|
+
The new password for the user.
|
|
168
|
+
|
|
169
|
+
#### Returns
|
|
170
|
+
|
|
171
|
+
`Promise`\<`void`\>
|
|
172
|
+
|
|
173
|
+
A promise that resolves when the password has been updated on the server.
|
|
174
|
+
|
|
175
|
+
#### Implementation of
|
|
176
|
+
|
|
177
|
+
`IAuthenticationComponent.updatePassword`
|
|
178
|
+
|
|
179
|
+
***
|
|
180
|
+
|
|
181
|
+
### passwordPolicy() {#passwordpolicy}
|
|
182
|
+
|
|
183
|
+
> **passwordPolicy**(): `Promise`\<`IPasswordOptions`\>
|
|
184
|
+
|
|
185
|
+
Get the password policy used for password validation.
|
|
186
|
+
|
|
187
|
+
#### Returns
|
|
188
|
+
|
|
189
|
+
`Promise`\<`IPasswordOptions`\>
|
|
190
|
+
|
|
191
|
+
The password policy options.
|
|
192
|
+
|
|
193
|
+
#### Implementation of
|
|
194
|
+
|
|
195
|
+
`IAuthenticationComponent.passwordPolicy`
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @3sixty/api-auth-entity-storage-rest-client
|
|
2
|
+
|
|
3
|
+
## Classes
|
|
4
|
+
|
|
5
|
+
- [EntityStorageAuthenticationAdminRestClient](classes/EntityStorageAuthenticationAdminRestClient.md)
|
|
6
|
+
- [EntityStorageAuthenticationRestClient](classes/EntityStorageAuthenticationRestClient.md)
|
|
7
|
+
|
|
8
|
+
## Interfaces
|
|
9
|
+
|
|
10
|
+
- [IEntityStorageAuthenticationRestClientConstructorOptions](interfaces/IEntityStorageAuthenticationRestClientConstructorOptions.md)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Interface: IEntityStorageAuthenticationRestClientConstructorOptions
|
|
2
|
+
|
|
3
|
+
Options for the Entity Storage Authentication REST client constructor.
|
|
4
|
+
|
|
5
|
+
## Extends
|
|
6
|
+
|
|
7
|
+
- `IBaseRestClientConfig`
|
|
8
|
+
|
|
9
|
+
## Properties
|
|
10
|
+
|
|
11
|
+
### cookieName? {#cookiename}
|
|
12
|
+
|
|
13
|
+
> `optional` **cookieName?**: `string`
|
|
14
|
+
|
|
15
|
+
The name of the cookie to use for storing the auth token.
|
|
16
|
+
|
|
17
|
+
#### Default
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
access_token
|
|
21
|
+
```
|
package/locales/en.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@3sixty/api-auth-entity-storage-rest-client",
|
|
3
|
+
"version": "0.20.0-next.1",
|
|
4
|
+
"description": "REST clients for authentication and admin operations against entity storage endpoints.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/3sixtyglobal/api-auth.git",
|
|
8
|
+
"directory": "packages/api-auth-entity-storage-rest-client"
|
|
9
|
+
},
|
|
10
|
+
"author": "martyn.janes@iota.org",
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=24.0.0"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@3sixty/api-auth-entity-storage-models": "0.20.0-next.1",
|
|
18
|
+
"@3sixty/api-core": "next",
|
|
19
|
+
"@3sixty/api-models": "next",
|
|
20
|
+
"@3sixty/core": "next",
|
|
21
|
+
"@3sixty/nameof": "next",
|
|
22
|
+
"@3sixty/web": "next"
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/es/index.js",
|
|
25
|
+
"types": "./dist/types/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/types/index.d.ts",
|
|
29
|
+
"import": "./dist/es/index.js",
|
|
30
|
+
"default": "./dist/es/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/es",
|
|
35
|
+
"dist/types",
|
|
36
|
+
"locales",
|
|
37
|
+
"docs"
|
|
38
|
+
],
|
|
39
|
+
"keywords": [
|
|
40
|
+
"twin",
|
|
41
|
+
"trade",
|
|
42
|
+
"iota",
|
|
43
|
+
"framework",
|
|
44
|
+
"blockchain",
|
|
45
|
+
"api",
|
|
46
|
+
"entity",
|
|
47
|
+
"storage",
|
|
48
|
+
"persistence",
|
|
49
|
+
"database"
|
|
50
|
+
],
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "git+https://github.com/3sixtyglobal/api-auth/issues"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://3sixty.global"
|
|
55
|
+
}
|