@3sixty/api-auth-entity-storage-rest-client 0.0.0-stage → 0.20.0-next.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 (26) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +24 -2
  3. package/dist/es/entityStorageAuthenticationAdminRestClient.js +115 -0
  4. package/dist/es/entityStorageAuthenticationAdminRestClient.js.map +1 -0
  5. package/dist/es/entityStorageAuthenticationAuditRestClient.js +111 -0
  6. package/dist/es/entityStorageAuthenticationAuditRestClient.js.map +1 -0
  7. package/dist/es/entityStorageAuthenticationRestClient.js +103 -0
  8. package/dist/es/entityStorageAuthenticationRestClient.js.map +1 -0
  9. package/dist/es/index.js +7 -0
  10. package/dist/es/index.js.map +1 -0
  11. package/dist/es/models/entityStorageAuthenticationRestClientConstructorOptions.js +2 -0
  12. package/dist/es/models/entityStorageAuthenticationRestClientConstructorOptions.js.map +1 -0
  13. package/dist/types/entityStorageAuthenticationAdminRestClient.d.ts +62 -0
  14. package/dist/types/entityStorageAuthenticationAuditRestClient.d.ts +73 -0
  15. package/dist/types/entityStorageAuthenticationRestClient.d.ts +54 -0
  16. package/dist/types/index.d.ts +4 -0
  17. package/dist/types/models/entityStorageAuthenticationRestClientConstructorOptions.d.ts +11 -0
  18. package/docs/changelog.md +0 -0
  19. package/docs/examples.md +111 -0
  20. package/docs/reference/classes/EntityStorageAuthenticationAdminRestClient.md +323 -0
  21. package/docs/reference/classes/EntityStorageAuthenticationAuditRestClient.md +343 -0
  22. package/docs/reference/classes/EntityStorageAuthenticationRestClient.md +271 -0
  23. package/docs/reference/index.md +11 -0
  24. package/docs/reference/interfaces/IEntityStorageAuthenticationRestClientConstructorOptions.md +153 -0
  25. package/locales/en.json +1 -0
  26. package/package.json +54 -5
@@ -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,73 @@
1
+ import type { AuthAuditEvent, IAuthenticationAuditComponent, IAuthenticationAuditEntry } 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 audit service.
6
+ */
7
+ export declare class EntityStorageAuthenticationAuditRestClient extends BaseRestClient implements IAuthenticationAuditComponent {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ static readonly CLASS_NAME: string;
12
+ /**
13
+ * Create a new instance of EntityStorageAuthenticationAuditRestClient.
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 new audit entry.
24
+ * @param entry The audit entry to be logged.
25
+ * @returns The unique identifier of the created audit entry.
26
+ */
27
+ create(entry: Omit<IAuthenticationAuditEntry, "id" | "dateCreated">): Promise<string>;
28
+ /**
29
+ * Get an audit entry by id.
30
+ * @param id The unique identifier of the audit entry.
31
+ * @returns The audit entry.
32
+ */
33
+ get(id: string): Promise<IAuthenticationAuditEntry>;
34
+ /**
35
+ * Update an audit entry.
36
+ * @param id The unique identifier of the audit entry to update.
37
+ * @param entry The fields to update on the audit entry.
38
+ * @returns A promise that resolves when the audit entry has been updated.
39
+ */
40
+ update(id: string, entry: Partial<Omit<IAuthenticationAuditEntry, "id" | "dateCreated">>): Promise<void>;
41
+ /**
42
+ * Remove an audit entry.
43
+ * @param id The unique identifier of the audit entry to remove.
44
+ * @returns A promise that resolves when the audit entry has been removed.
45
+ */
46
+ remove(id: string): Promise<void>;
47
+ /**
48
+ * Query the audit entries.
49
+ * @param options The query options.
50
+ * @param options.actorId The actor identifier to filter the audit entries, optional.
51
+ * @param options.organizationId The organization identifier to filter the audit entries, optional.
52
+ * @param options.tenantId The tenant identifier to filter the audit entries, optional.
53
+ * @param options.nodeId The node identifier to filter the audit entries, optional.
54
+ * @param options.event The audit event to filter the audit entries, optional.
55
+ * @param options.startDate The start date to filter the audit entries, optional.
56
+ * @param options.endDate The end date to filter the audit entries, optional.
57
+ * @param cursor The cursor for pagination.
58
+ * @param limit The maximum number of entries to return.
59
+ * @returns The audit entries.
60
+ */
61
+ query(options?: {
62
+ actorId?: string;
63
+ organizationId?: string;
64
+ tenantId?: string;
65
+ nodeId?: string;
66
+ event?: AuthAuditEvent | string;
67
+ startDate?: string;
68
+ endDate?: string;
69
+ }, cursor?: string, limit?: number): Promise<{
70
+ entries: IAuthenticationAuditEntry[];
71
+ cursor?: string;
72
+ }>;
73
+ }
@@ -0,0 +1,54 @@
1
+ import type { IAuthenticationComponent } 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
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./entityStorageAuthenticationAdminRestClient.js";
2
+ export * from "./entityStorageAuthenticationAuditRestClient.js";
3
+ export * from "./entityStorageAuthenticationRestClient.js";
4
+ export * from "./models/entityStorageAuthenticationRestClientConstructorOptions.js";
@@ -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
+ }
File without changes
@@ -0,0 +1,111 @@
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
+ scope: ['admin']
23
+ });
24
+
25
+ await adminClient.update({
26
+ email: 'ops@example.org',
27
+ userIdentity: 'did:example:ops:team',
28
+ scope: ['admin', 'support']
29
+ });
30
+
31
+ await adminClient.updatePassword('ops@example.org', 'StrongPassword124', 'StrongPassword123');
32
+ const adminUser = await adminClient.get('ops@example.org');
33
+ console.log(adminUser.email); // ops@example.org
34
+ ```
35
+
36
+ ```typescript
37
+ import { EntityStorageAuthenticationAdminRestClient } from '@3sixty/api-auth-entity-storage-rest-client';
38
+
39
+ const adminClient = new EntityStorageAuthenticationAdminRestClient({
40
+ endpoint: 'https://api.example.org',
41
+ pathPrefix: 'v1'
42
+ });
43
+
44
+ const byEmail = await adminClient.get('ops@example.org');
45
+ const byIdentity = await adminClient.getByIdentity('ops-team@example.org');
46
+ await adminClient.remove('ops@example.org');
47
+
48
+ console.log(byEmail.email); // ops@example.org
49
+ console.log(byIdentity.userIdentity); // did:example:ops:team
50
+ ```
51
+
52
+ ## EntityStorageAuthenticationRestClient
53
+
54
+ ```typescript
55
+ import { EntityStorageAuthenticationRestClient } from '@3sixty/api-auth-entity-storage-rest-client';
56
+
57
+ const authClient = new EntityStorageAuthenticationRestClient({
58
+ endpoint: 'https://api.example.org',
59
+ pathPrefix: 'v1',
60
+ cookieName: 'access_token'
61
+ });
62
+
63
+ console.log(authClient.className()); // EntityStorageAuthenticationRestClient
64
+
65
+ const loginResponse = await authClient.login('alice@example.org', 'correct-horse-battery-staple');
66
+
67
+ await authClient.updatePassword('correct-horse-battery-staple', 'correct-horse-battery-staple-2');
68
+
69
+ const refreshResponse = await authClient.refresh(loginResponse.token);
70
+
71
+ await authClient.logout(refreshResponse.token);
72
+ console.log(refreshResponse.expiry > 0); // true
73
+ ```
74
+
75
+ ## EntityStorageAuthenticationAuditRestClient
76
+
77
+ ```typescript
78
+ import { EntityStorageAuthenticationAuditRestClient } from '@3sixty/api-auth-entity-storage-rest-client';
79
+
80
+ const auditClient = new EntityStorageAuthenticationAuditRestClient({
81
+ endpoint: 'https://api.example.org',
82
+ pathPrefix: 'v1'
83
+ });
84
+
85
+ console.log(auditClient.className()); // EntityStorageAuthenticationAuditRestClient
86
+
87
+ const auditEntryId = await auditClient.create({
88
+ event: 'login-success',
89
+ actorId: 'did:example:user:alice',
90
+ organizationId: 'did:example:org:core',
91
+ tenantId: 'did:example:tenant:alpha',
92
+ data: {
93
+ channel: 'web'
94
+ }
95
+ });
96
+
97
+ const auditResult = await auditClient.query(
98
+ {
99
+ actorId: 'did:example:user:alice',
100
+ event: 'login-success',
101
+ startDate: '2026-04-01T00:00:00.000Z',
102
+ endDate: '2026-04-30T23:59:59.999Z'
103
+ },
104
+ undefined,
105
+ 25
106
+ );
107
+
108
+ console.log(auditEntryId); // /authentication/audit/018f2f67bb9d4a0caad8386f56df85ce
109
+ console.log(auditResult.entries.length); // 1
110
+ console.log(auditResult.cursor); // eyJpZCI6IjAxOGYyZjY3YmI5ZDRhMGNhYWQ4Mzg2ZjU2ZGY4NWNlIn0=
111
+ ```
@@ -0,0 +1,323 @@
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`
230
+
231
+ ***
232
+
233
+ ### getEndpointWithPrefix() {#getendpointwithprefix}
234
+
235
+ > **getEndpointWithPrefix**(): `string`
236
+
237
+ Get the endpoint with the prefix for the namespace.
238
+
239
+ #### Returns
240
+
241
+ `string`
242
+
243
+ The endpoint with namespace prefix attached.
244
+
245
+ #### Inherited from
246
+
247
+ `BaseRestClient.getEndpointWithPrefix`
248
+
249
+ ***
250
+
251
+ ### getPathPrefix() {#getpathprefix}
252
+
253
+ > **getPathPrefix**(): `string`
254
+
255
+ Get the path prefix as a URL path string provided in the constructor.
256
+
257
+ #### Returns
258
+
259
+ `string`
260
+
261
+ The path prefix.
262
+
263
+ #### Inherited from
264
+
265
+ `BaseRestClient.getPathPrefix`
266
+
267
+ ***
268
+
269
+ ### fetch() {#fetch}
270
+
271
+ > **fetch**\<`T`, `U`\>(`route`, `method`, `request?`, `options?`): `Promise`\<`U`\>
272
+
273
+ Perform a request in json format.
274
+
275
+ #### Type Parameters
276
+
277
+ ##### T
278
+
279
+ `T` *extends* `IHttpRequest`\<`any`\>
280
+
281
+ ##### U
282
+
283
+ `U` *extends* `IHttpResponse`\<`any`\>
284
+
285
+ #### Parameters
286
+
287
+ ##### route
288
+
289
+ `string`
290
+
291
+ The route of the request.
292
+
293
+ ##### method
294
+
295
+ `HttpMethod`
296
+
297
+ The http method.
298
+
299
+ ##### request?
300
+
301
+ `T`
302
+
303
+ Request to send to the endpoint.
304
+
305
+ ##### options?
306
+
307
+ Optional override options for the request.
308
+
309
+ ###### overridePrefix?
310
+
311
+ `string`
312
+
313
+ Optional override prefix to use for this request instead of the default prefix.
314
+
315
+ #### Returns
316
+
317
+ `Promise`\<`U`\>
318
+
319
+ The response.
320
+
321
+ #### Inherited from
322
+
323
+ `BaseRestClient.fetch`