@twin.org/api-auth-entity-storage-rest-client 0.0.3-next.4 → 0.0.3-next.41

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 (24) hide show
  1. package/README.md +3 -3
  2. package/dist/es/entityStorageAuthenticationAdminRestClient.js +114 -0
  3. package/dist/es/entityStorageAuthenticationAdminRestClient.js.map +1 -0
  4. package/dist/es/entityStorageAuthenticationAuditRestClient.js +73 -0
  5. package/dist/es/entityStorageAuthenticationAuditRestClient.js.map +1 -0
  6. package/dist/es/entityStorageAuthenticationRestClient.js +27 -13
  7. package/dist/es/entityStorageAuthenticationRestClient.js.map +1 -1
  8. package/dist/es/index.js +3 -0
  9. package/dist/es/index.js.map +1 -1
  10. package/dist/es/models/entityStorageAuthenticationRestClientConstructorOptions.js +2 -0
  11. package/dist/es/models/entityStorageAuthenticationRestClientConstructorOptions.js.map +1 -0
  12. package/dist/types/entityStorageAuthenticationAdminRestClient.d.ts +62 -0
  13. package/dist/types/entityStorageAuthenticationAuditRestClient.d.ts +54 -0
  14. package/dist/types/entityStorageAuthenticationRestClient.d.ts +3 -4
  15. package/dist/types/index.d.ts +3 -0
  16. package/dist/types/models/entityStorageAuthenticationRestClientConstructorOptions.d.ts +11 -0
  17. package/docs/changelog.md +659 -54
  18. package/docs/examples.md +111 -1
  19. package/docs/reference/classes/EntityStorageAuthenticationAdminRestClient.md +295 -0
  20. package/docs/reference/classes/EntityStorageAuthenticationAuditRestClient.md +231 -0
  21. package/docs/reference/classes/EntityStorageAuthenticationRestClient.md +74 -14
  22. package/docs/reference/index.md +6 -0
  23. package/docs/reference/interfaces/IEntityStorageAuthenticationRestClientConstructorOptions.md +141 -0
  24. package/package.json +7 -7
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # TWIN Auth Entity Storage
1
+ # TWIN API Auth Entity Storage REST Client
2
2
 
3
- Perform REST authentication using entity storage.
3
+ This package provides REST clients for authentication and admin operations against entity storage endpoints.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```shell
8
- npm install @twin.org/api-auth-entity-storage
8
+ npm install @twin.org/api-auth-entity-storage-rest-client
9
9
  ```
10
10
 
11
11
  ## Examples
@@ -0,0 +1,114 @@
1
+ import { BaseRestClient } from "@twin.org/api-core";
2
+ import { Guards } from "@twin.org/core";
3
+ /**
4
+ * The client to connect to the authentication admin service.
5
+ */
6
+ export class EntityStorageAuthenticationAdminRestClient extends BaseRestClient {
7
+ /**
8
+ * Runtime name for the class.
9
+ */
10
+ static CLASS_NAME = "EntityStorageAuthenticationAdminRestClient";
11
+ /**
12
+ * Create a new instance of EntityStorageAuthenticationAdminRestClient.
13
+ * @param config The configuration for the client.
14
+ */
15
+ constructor(config) {
16
+ super("EntityStorageAuthenticationAdminRestClient", config, "authentication/admin");
17
+ }
18
+ /**
19
+ * Returns the class name of the component.
20
+ * @returns The class name of the component.
21
+ */
22
+ className() {
23
+ return EntityStorageAuthenticationAdminRestClient.CLASS_NAME;
24
+ }
25
+ /**
26
+ * Create a login for the user.
27
+ * @param user The user to create.
28
+ * @returns Nothing.
29
+ */
30
+ async create(user) {
31
+ Guards.object(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "user", user);
32
+ Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "user.email", user.email);
33
+ await this.fetch("/users", "POST", {
34
+ body: user
35
+ });
36
+ }
37
+ /**
38
+ * Update a login for the user.
39
+ * @param user The user to update.
40
+ * @returns Nothing.
41
+ */
42
+ async update(user) {
43
+ Guards.object(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "user", user);
44
+ Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "user.email", user.email);
45
+ await this.fetch("/users/:email", "PUT", {
46
+ pathParams: {
47
+ email: user.email
48
+ },
49
+ body: user
50
+ });
51
+ }
52
+ /**
53
+ * Get a user by email.
54
+ * @param email The email address of the user to get.
55
+ * @returns The user details.
56
+ */
57
+ async get(email) {
58
+ Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "email", email);
59
+ const response = await this.fetch("/users/:email", "GET", {
60
+ pathParams: {
61
+ email
62
+ }
63
+ });
64
+ return response.body;
65
+ }
66
+ /**
67
+ * Get a user by identity.
68
+ * @param identity The identity of the user to get.
69
+ * @returns The user details.
70
+ */
71
+ async getByIdentity(identity) {
72
+ Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "identity", identity);
73
+ const response = await this.fetch("/users/identity/:identity", "GET", {
74
+ pathParams: {
75
+ identity
76
+ }
77
+ });
78
+ return response.body;
79
+ }
80
+ /**
81
+ * Remove a user.
82
+ * @param email The email address of the user to remove.
83
+ * @returns Nothing.
84
+ */
85
+ async remove(email) {
86
+ Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "email", email);
87
+ await this.fetch("/users/:email", "DELETE", {
88
+ pathParams: {
89
+ email
90
+ }
91
+ });
92
+ }
93
+ /**
94
+ * Update the user's password.
95
+ * @param email The email address of the user to update.
96
+ * @param newPassword The new password for the user.
97
+ * @param currentPassword The current password, optional, if supplied will check against existing.
98
+ * @returns Nothing.
99
+ */
100
+ async updatePassword(email, newPassword, currentPassword) {
101
+ Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "email", email);
102
+ Guards.stringValue(EntityStorageAuthenticationAdminRestClient.CLASS_NAME, "newPassword", newPassword);
103
+ await this.fetch("/users/:email/password", "PUT", {
104
+ pathParams: {
105
+ email
106
+ },
107
+ body: {
108
+ newPassword,
109
+ currentPassword
110
+ }
111
+ });
112
+ }
113
+ }
114
+ //# sourceMappingURL=entityStorageAuthenticationAdminRestClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entityStorageAuthenticationAdminRestClient.js","sourceRoot":"","sources":["../../src/entityStorageAuthenticationAdminRestClient.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OA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L;YACC,UAAU,EAAE;gBACX,KAAK;aACL;SACD,CACD,CAAC;QAEF,OAAO,QAAQ,CAAC,IAAI,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,aAAa,CAAC,QAAgB;QAC1C,MAAM,CAAC,WAAW,CACjB,0CAA0C,CAAC,UAAU,cAErD,QAAQ,CACR,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAChC,2BAA2B,EAC3B,KAAK,EACL;YACC,UAAU,EAAE;gBACX,QAAQ;aACR;SACD,CACD,CAAC;QAEF,OAAO,QAAQ,CAAC,IAAI,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,MAAM,CAAC,KAAa;QAChC,MAAM,CAAC,WAAW,CAAC,0CAA0C,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAEhG,MAAM,IAAI,CAAC,KAAK,CAA8C,eAAe,EAAE,QAAQ,EAAE;YACxF,UAAU,EAAE;gBACX,KAAK;aACL;SACD,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,cAAc,CAC1B,KAAa,EACb,WAAmB,EACnB,eAAwB;QAExB,MAAM,CAAC,WAAW,CAAC,0CAA0C,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAChG,MAAM,CAAC,WAAW,CACjB,0CAA0C,CAAC,UAAU,iBAErD,WAAW,CACX,CAAC;QAEF,MAAM,IAAI,CAAC,KAAK,CACf,wBAAwB,EACxB,KAAK,EACL;YACC,UAAU,EAAE;gBACX,KAAK;aACL;YACD,IAAI,EAAE;gBACL,WAAW;gBACX,eAAe;aACf;SACD,CACD,CAAC;IACH,CAAC","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 \"@twin.org/api-auth-entity-storage-models\";\nimport { BaseRestClient } from \"@twin.org/api-core\";\nimport type { IBaseRestClientConfig, INoContentResponse } from \"@twin.org/api-models\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\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 = nameof<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(nameof<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, nameof(user), user);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationAdminRestClient.CLASS_NAME,\n\t\t\tnameof(user.email),\n\t\t\tuser.email\n\t\t);\n\n\t\tawait this.fetch<IAdminUserCreateRequest, INoContentResponse>(\"/users\", \"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, nameof(user), user);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationAdminRestClient.CLASS_NAME,\n\t\t\tnameof(user.email),\n\t\t\tuser.email\n\t\t);\n\n\t\tawait this.fetch<IAdminUserUpdateRequest, INoContentResponse>(\"/users/:email\", \"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, nameof(email), email);\n\n\t\tconst response = await this.fetch<IAdminUserGetRequest, IAdminUserGetResponse>(\n\t\t\t\"/users/:email\",\n\t\t\t\"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\tnameof(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, nameof(email), email);\n\n\t\tawait this.fetch<IAdminUserRemoveRequest, INoContentResponse>(\"/users/:email\", \"DELETE\", {\n\t\t\tpathParams: {\n\t\t\t\temail\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, nameof(email), email);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationAdminRestClient.CLASS_NAME,\n\t\t\tnameof(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\t\"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,73 @@
1
+ import { BaseRestClient } from "@twin.org/api-core";
2
+ import { Coerce, Guards } from "@twin.org/core";
3
+ import { HeaderTypes } from "@twin.org/web";
4
+ /**
5
+ * The client to connect to the authentication audit service.
6
+ */
7
+ export class EntityStorageAuthenticationAuditRestClient extends BaseRestClient {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ static CLASS_NAME = "EntityStorageAuthenticationAuditRestClient";
12
+ /**
13
+ * Create a new instance of EntityStorageAuthenticationAuditRestClient.
14
+ * @param config The configuration for the client.
15
+ */
16
+ constructor(config) {
17
+ super("EntityStorageAuthenticationAuditRestClient", config, "authentication/audit");
18
+ }
19
+ /**
20
+ * Returns the class name of the component.
21
+ * @returns The class name of the component.
22
+ */
23
+ className() {
24
+ return EntityStorageAuthenticationAuditRestClient.CLASS_NAME;
25
+ }
26
+ /**
27
+ * Create a new audit entry.
28
+ * @param entry The audit entry to be logged.
29
+ * @returns The unique identifier of the created audit entry.
30
+ */
31
+ async create(entry) {
32
+ Guards.object(EntityStorageAuthenticationAuditRestClient.CLASS_NAME, "entry", entry);
33
+ Guards.stringValue(EntityStorageAuthenticationAuditRestClient.CLASS_NAME, "entry.event", entry.event);
34
+ const response = await this.fetch("", "POST", {
35
+ body: entry
36
+ });
37
+ return response.headers?.[HeaderTypes.Location] ?? "";
38
+ }
39
+ /**
40
+ * Query the audit entries.
41
+ * @param options The query options.
42
+ * @param options.actorId The actor identifier to filter the audit entries, optional.
43
+ * @param options.organizationId The organization identifier to filter the audit entries, optional.
44
+ * @param options.tenantId The tenant identifier to filter the audit entries, optional.
45
+ * @param options.nodeId The node identifier to filter the audit entries, optional.
46
+ * @param options.event The audit event to filter the audit entries, optional.
47
+ * @param options.startDate The start date to filter the audit entries, optional.
48
+ * @param options.endDate The end date to filter the audit entries, optional.
49
+ * @param cursor The cursor for pagination.
50
+ * @param limit The maximum number of entries to return.
51
+ * @returns The audit entries.
52
+ */
53
+ async query(options, cursor, limit) {
54
+ const response = await this.fetch("", "GET", {
55
+ query: {
56
+ actorId: options?.actorId,
57
+ organizationId: options?.organizationId,
58
+ tenantId: options?.tenantId,
59
+ nodeId: options?.nodeId,
60
+ event: options?.event,
61
+ startDate: options?.startDate,
62
+ endDate: options?.endDate,
63
+ cursor,
64
+ limit: Coerce.string(limit)
65
+ }
66
+ });
67
+ return {
68
+ entries: response.body.entries,
69
+ cursor: response.body.cursor
70
+ };
71
+ }
72
+ }
73
+ //# sourceMappingURL=entityStorageAuthenticationAuditRestClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entityStorageAuthenticationAuditRestClient.js","sourceRoot":"","sources":["../../src/entityStorageAuthenticationAuditRestClient.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,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O;gBACzB,MAAM;gBACN,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;aAC3B;SACD,CAAC,CAAC;QAEH,OAAO;YACN,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,OAAO;YAC9B,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;SAC5B,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tAuthAuditEvent,\n\tIAuditCreateRequest,\n\tIAuditQueryRequest,\n\tIAuditQueryResponse,\n\tIAuthenticationAuditComponent,\n\tIAuthenticationAuditEntry\n} from \"@twin.org/api-auth-entity-storage-models\";\nimport { BaseRestClient } from \"@twin.org/api-core\";\nimport type { IBaseRestClientConfig, ICreatedResponse } from \"@twin.org/api-models\";\nimport { Coerce, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HeaderTypes } from \"@twin.org/web\";\n\n/**\n * The client to connect to the authentication audit service.\n */\nexport class EntityStorageAuthenticationAuditRestClient\n\textends BaseRestClient\n\timplements IAuthenticationAuditComponent\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<EntityStorageAuthenticationAuditRestClient>();\n\n\t/**\n\t * Create a new instance of EntityStorageAuthenticationAuditRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(nameof<EntityStorageAuthenticationAuditRestClient>(), config, \"authentication/audit\");\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 EntityStorageAuthenticationAuditRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new audit entry.\n\t * @param entry The audit entry to be logged.\n\t * @returns The unique identifier of the created audit entry.\n\t */\n\tpublic async create(\n\t\tentry: Omit<IAuthenticationAuditEntry, \"id\" | \"dateCreated\">\n\t): Promise<string> {\n\t\tGuards.object(EntityStorageAuthenticationAuditRestClient.CLASS_NAME, nameof(entry), entry);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationAuditRestClient.CLASS_NAME,\n\t\t\tnameof(entry.event),\n\t\t\tentry.event\n\t\t);\n\n\t\tconst response = await this.fetch<IAuditCreateRequest, ICreatedResponse>(\"\", \"POST\", {\n\t\t\tbody: entry\n\t\t});\n\n\t\treturn response.headers?.[HeaderTypes.Location] ?? \"\";\n\t}\n\n\t/**\n\t * Query the audit entries.\n\t * @param options The query options.\n\t * @param options.actorId The actor identifier to filter the audit entries, optional.\n\t * @param options.organizationId The organization identifier to filter the audit entries, optional.\n\t * @param options.tenantId The tenant identifier to filter the audit entries, optional.\n\t * @param options.nodeId The node identifier to filter the audit entries, optional.\n\t * @param options.event The audit event to filter the audit entries, optional.\n\t * @param options.startDate The start date to filter the audit entries, optional.\n\t * @param options.endDate The end date to filter the audit entries, optional.\n\t * @param cursor The cursor for pagination.\n\t * @param limit The maximum number of entries to return.\n\t * @returns The audit entries.\n\t */\n\tpublic async query(\n\t\toptions?: {\n\t\t\tactorId?: string;\n\t\t\torganizationId?: string;\n\t\t\ttenantId?: string;\n\t\t\tnodeId?: string;\n\t\t\tevent?: AuthAuditEvent | string;\n\t\t\tstartDate?: string;\n\t\t\tendDate?: string;\n\t\t},\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentries: IAuthenticationAuditEntry[];\n\t\tcursor?: string;\n\t}> {\n\t\tconst response = await this.fetch<IAuditQueryRequest, IAuditQueryResponse>(\"\", \"GET\", {\n\t\t\tquery: {\n\t\t\t\tactorId: options?.actorId,\n\t\t\t\torganizationId: options?.organizationId,\n\t\t\t\ttenantId: options?.tenantId,\n\t\t\t\tnodeId: options?.nodeId,\n\t\t\t\tevent: options?.event,\n\t\t\t\tstartDate: options?.startDate,\n\t\t\t\tendDate: options?.endDate,\n\t\t\t\tcursor,\n\t\t\t\tlimit: Coerce.string(limit)\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\tentries: response.body.entries,\n\t\t\tcursor: response.body.cursor\n\t\t};\n\t}\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { BaseRestClient } from "@twin.org/api-core";
2
2
  import { Guards } from "@twin.org/core";
3
+ import { CookieHelper, HeaderTypes } from "@twin.org/web";
3
4
  /**
4
5
  * The client to connect to the authentication service.
5
6
  */
@@ -8,12 +9,24 @@ export class EntityStorageAuthenticationRestClient extends BaseRestClient {
8
9
  * Runtime name for the class.
9
10
  */
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;
11
22
  /**
12
23
  * Create a new instance of EntityStorageAuthenticationRestClient.
13
24
  * @param config The configuration for the client.
14
25
  */
15
26
  constructor(config) {
16
27
  super("EntityStorageAuthenticationRestClient", config, "authentication");
28
+ this._cookieName =
29
+ config.cookieName ?? EntityStorageAuthenticationRestClient.DEFAULT_COOKIE_NAME;
17
30
  }
18
31
  /**
19
32
  * Returns the class name of the component.
@@ -37,7 +50,10 @@ export class EntityStorageAuthenticationRestClient extends BaseRestClient {
37
50
  password
38
51
  }
39
52
  });
40
- return response.body;
53
+ return {
54
+ token: CookieHelper.getCookieFromHeaders(response?.headers?.[HeaderTypes.SetCookie], this._cookieName),
55
+ expiry: response.body.expiry
56
+ };
41
57
  }
42
58
  /**
43
59
  * Logout the current user.
@@ -45,8 +61,8 @@ export class EntityStorageAuthenticationRestClient extends BaseRestClient {
45
61
  * @returns Nothing.
46
62
  */
47
63
  async logout(token) {
48
- await this.fetch("/logout", "GET", {
49
- query: {
64
+ await this.fetch("/logout", "POST", {
65
+ body: {
50
66
  token
51
67
  }
52
68
  });
@@ -57,28 +73,26 @@ export class EntityStorageAuthenticationRestClient extends BaseRestClient {
57
73
  * @returns The refreshed token, if it uses a mechanism with public access.
58
74
  */
59
75
  async refresh(token) {
60
- const response = await this.fetch("/refresh", "GET", {
61
- query: {
76
+ const response = await this.fetch("/refresh", "POST", {
77
+ body: {
62
78
  token
63
79
  }
64
80
  });
65
- return response.body;
81
+ return {
82
+ token: CookieHelper.getCookieFromHeaders(response?.headers?.[HeaderTypes.SetCookie], this._cookieName),
83
+ expiry: response.body.expiry
84
+ };
66
85
  }
67
86
  /**
68
87
  * Update the user's password.
69
- * @param email The email address of the user to update.
70
88
  * @param currentPassword The current password for the user.
71
89
  * @param newPassword The new password for the user.
72
90
  * @returns Nothing.
73
91
  */
74
- async updatePassword(email, currentPassword, newPassword) {
75
- Guards.stringValue(EntityStorageAuthenticationRestClient.CLASS_NAME, "email", email);
92
+ async updatePassword(currentPassword, newPassword) {
76
93
  Guards.stringValue(EntityStorageAuthenticationRestClient.CLASS_NAME, "currentPassword", currentPassword);
77
94
  Guards.stringValue(EntityStorageAuthenticationRestClient.CLASS_NAME, "newPassword", newPassword);
78
- await this.fetch("/:email/password", "PUT", {
79
- pathParams: {
80
- email
81
- },
95
+ await this.fetch("/password", "PUT", {
82
96
  body: {
83
97
  currentPassword,
84
98
  newPassword
@@ -1 +1 @@
1
- {"version":3,"file":"entityStorageAuthenticationRestClient.js","sourceRoot":"","sources":["../../src/entityStorageAuthenticationRestClient.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;GAEG;AACH,MAAM,OAAO,qCACZ,SAAQ,cAAc;IAGtB;;OAEG;IACI,MAAM,CAAU,UAAU,2CAA2D;IAE5F;;;OAGG;IACH,YAAY,MAA6B;QACxC,KAAK,0CAAkD,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAClF,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,qCAAqC,CAAC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,KAAK;aACL;YACD,IAAI,EAAE;gBACL,eAAe;gBACf,WAAW;aACX;SACD,CAAC,CAAC;IACJ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIAuthenticationComponent,\n\tILoginRequest,\n\tILoginResponse,\n\tILogoutRequest,\n\tIRefreshTokenRequest,\n\tIRefreshTokenResponse,\n\tIUpdatePasswordRequest\n} from \"@twin.org/api-auth-entity-storage-models\";\nimport { BaseRestClient } from \"@twin.org/api-core\";\nimport type { IBaseRestClientConfig, INoContentResponse } from \"@twin.org/api-models\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\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 = nameof<EntityStorageAuthenticationRestClient>();\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: IBaseRestClientConfig) {\n\t\tsuper(nameof<EntityStorageAuthenticationRestClient>(), config, \"authentication\");\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, nameof(email), email);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationRestClient.CLASS_NAME,\n\t\t\tnameof(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 response.body;\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 Nothing.\n\t */\n\tpublic async logout(token?: string): Promise<void> {\n\t\tawait this.fetch<ILogoutRequest, INoContentResponse>(\"/logout\", \"GET\", {\n\t\t\tquery: {\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\"GET\",\n\t\t\t{\n\t\t\t\tquery: {\n\t\t\t\t\ttoken\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 * Update the user's password.\n\t * @param email The email address of the user to update.\n\t * @param currentPassword The current password for the user.\n\t * @param newPassword The new password for the user.\n\t * @returns Nothing.\n\t */\n\tpublic async updatePassword(\n\t\temail: string,\n\t\tcurrentPassword: string,\n\t\tnewPassword: string\n\t): Promise<void> {\n\t\tGuards.stringValue(EntityStorageAuthenticationRestClient.CLASS_NAME, nameof(email), email);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationRestClient.CLASS_NAME,\n\t\t\tnameof(currentPassword),\n\t\t\tcurrentPassword\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationRestClient.CLASS_NAME,\n\t\t\tnameof(newPassword),\n\t\t\tnewPassword\n\t\t);\n\n\t\tawait this.fetch<IUpdatePasswordRequest, INoContentResponse>(\"/:email/password\", \"PUT\", {\n\t\t\tpathParams: {\n\t\t\t\temail\n\t\t\t},\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"]}
1
+ {"version":3,"file":"entityStorageAuthenticationRestClient.js","sourceRoot":"","sources":["../../src/entityStorageAuthenticationRestClient.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG1D;;GAEG;AACH,MAAM,OAAO,qCACZ,SAAQ,cAAc;IAGtB;;OAEG;IACI,MAAM,CAAU,UAAU,2CAA2D;IAE5F;;;OAGG;IACI,MAAM,CAAU,mBAAmB,GAAW,cAAc,CAAC;IAEpE;;;OAGG;IACc,WAAW,CAAS;IAErC;;;OAGG;IACH,YAAY,MAAgE;QAC3E,KAAK,0CAAkD,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACjF,IAAI,CAAC,WAAW;YACf,MAAM,CAAC,UAAU,IAAI,qCAAqC,CAAC,mBAAmB,CAAC;IACjF,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,qCAAqC,CAAC,UAAU,CAAC;IACzD,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,KAAK,CACjB,KAAa,EACb,QAAgB;QAKhB,MAAM,CAAC,WAAW,CAAC,qCAAqC,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC3F,MAAM,CAAC,WAAW,CACjB,qCAAqC,CAAC,UAAU,cAEhD,QAAQ,CACR,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAgC,QAAQ,EAAE,MAAM,EAAE;YAClF,IAAI,EAAE;gBACL,KAAK;gBACL,QAAQ;aACR;SACD,CAAC,CAAC;QAEH,OAAO;YACN,KAAK,EAAE,YAAY,CAAC,oBAAoB,CACvC,QAAQ,EAAE,OAAO,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,EAC1C,IAAI,CAAC,WAAW,CAChB;YACD,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;SAC5B,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,MAAM,CAAC,KAAc;QACjC,MAAM,IAAI,CAAC,KAAK,CAAqC,SAAS,EAAE,MAAM,EAAE;YACvE,IAAI,EAAE;gBACL,KAAK;aACL;SACD,CAAC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,OAAO,CAAC,KAAc;QAIlC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAChC,UAAU,EACV,MAAM,EACN;YACC,IAAI,EAAE;gBACL,KAAK;aACL;SACD,CACD,CAAC;QAEF,OAAO;YACN,KAAK,EAAE,YAAY,CAAC,oBAAoB,CACvC,QAAQ,EAAE,OAAO,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,EAC1C,IAAI,CAAC,WAAW,CAChB;YACD,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;SAC5B,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,cAAc,CAAC,eAAuB,EAAE,WAAmB;QACvE,MAAM,CAAC,WAAW,CACjB,qCAAqC,CAAC,UAAU,qBAEhD,eAAe,CACf,CAAC;QACF,MAAM,CAAC,WAAW,CACjB,qCAAqC,CAAC,UAAU,iBAEhD,WAAW,CACX,CAAC;QAEF,MAAM,IAAI,CAAC,KAAK,CAA6C,WAAW,EAAE,KAAK,EAAE;YAChF,IAAI,EAAE;gBACL,eAAe;gBACf,WAAW;aACX;SACD,CAAC,CAAC;IACJ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIAuthenticationComponent,\n\tILoginRequest,\n\tILoginResponse,\n\tILogoutRequest,\n\tIRefreshTokenRequest,\n\tIRefreshTokenResponse,\n\tIUpdatePasswordRequest\n} from \"@twin.org/api-auth-entity-storage-models\";\nimport { BaseRestClient } from \"@twin.org/api-core\";\nimport type { INoContentResponse } from \"@twin.org/api-models\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { CookieHelper, HeaderTypes } from \"@twin.org/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 = nameof<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(nameof<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, nameof(email), email);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationRestClient.CLASS_NAME,\n\t\t\tnameof(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 Nothing.\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 Nothing.\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\tnameof(currentPassword),\n\t\t\tcurrentPassword\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageAuthenticationRestClient.CLASS_NAME,\n\t\t\tnameof(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"]}
package/dist/es/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  // Copyright 2024 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./entityStorageAuthenticationAdminRestClient.js";
4
+ export * from "./entityStorageAuthenticationAuditRestClient.js";
3
5
  export * from "./entityStorageAuthenticationRestClient.js";
6
+ export * from "./models/entityStorageAuthenticationRestClientConstructorOptions.js";
4
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,4CAA4C,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./entityStorageAuthenticationRestClient.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,iDAAiD,CAAC;AAChE,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 \"./entityStorageAuthenticationAuditRestClient.js\";\nexport * from \"./entityStorageAuthenticationRestClient.js\";\nexport * from \"./models/entityStorageAuthenticationRestClientConstructorOptions.js\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=entityStorageAuthenticationRestClientConstructorOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entityStorageAuthenticationRestClientConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/entityStorageAuthenticationRestClientConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IBaseRestClientConfig } from \"@twin.org/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 "@twin.org/api-auth-entity-storage-models";
2
+ import { BaseRestClient } from "@twin.org/api-core";
3
+ import type { IBaseRestClientConfig } from "@twin.org/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,54 @@
1
+ import type { AuthAuditEvent, IAuthenticationAuditComponent, IAuthenticationAuditEntry } from "@twin.org/api-auth-entity-storage-models";
2
+ import { BaseRestClient } from "@twin.org/api-core";
3
+ import type { IBaseRestClientConfig } from "@twin.org/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
+ * Query the audit entries.
30
+ * @param options The query options.
31
+ * @param options.actorId The actor identifier to filter the audit entries, optional.
32
+ * @param options.organizationId The organization identifier to filter the audit entries, optional.
33
+ * @param options.tenantId The tenant identifier to filter the audit entries, optional.
34
+ * @param options.nodeId The node identifier to filter the audit entries, optional.
35
+ * @param options.event The audit event to filter the audit entries, optional.
36
+ * @param options.startDate The start date to filter the audit entries, optional.
37
+ * @param options.endDate The end date to filter the audit entries, optional.
38
+ * @param cursor The cursor for pagination.
39
+ * @param limit The maximum number of entries to return.
40
+ * @returns The audit entries.
41
+ */
42
+ query(options?: {
43
+ actorId?: string;
44
+ organizationId?: string;
45
+ tenantId?: string;
46
+ nodeId?: string;
47
+ event?: AuthAuditEvent | string;
48
+ startDate?: string;
49
+ endDate?: string;
50
+ }, cursor?: string, limit?: number): Promise<{
51
+ entries: IAuthenticationAuditEntry[];
52
+ cursor?: string;
53
+ }>;
54
+ }
@@ -1,6 +1,6 @@
1
1
  import type { IAuthenticationComponent } from "@twin.org/api-auth-entity-storage-models";
2
2
  import { BaseRestClient } from "@twin.org/api-core";
3
- import type { IBaseRestClientConfig } from "@twin.org/api-models";
3
+ import type { IEntityStorageAuthenticationRestClientConstructorOptions } from "./models/entityStorageAuthenticationRestClientConstructorOptions.js";
4
4
  /**
5
5
  * The client to connect to the authentication service.
6
6
  */
@@ -13,7 +13,7 @@ export declare class EntityStorageAuthenticationRestClient extends BaseRestClien
13
13
  * Create a new instance of EntityStorageAuthenticationRestClient.
14
14
  * @param config The configuration for the client.
15
15
  */
16
- constructor(config: IBaseRestClientConfig);
16
+ constructor(config: IEntityStorageAuthenticationRestClientConstructorOptions);
17
17
  /**
18
18
  * Returns the class name of the component.
19
19
  * @returns The class name of the component.
@@ -46,10 +46,9 @@ export declare class EntityStorageAuthenticationRestClient extends BaseRestClien
46
46
  }>;
47
47
  /**
48
48
  * Update the user's password.
49
- * @param email The email address of the user to update.
50
49
  * @param currentPassword The current password for the user.
51
50
  * @param newPassword The new password for the user.
52
51
  * @returns Nothing.
53
52
  */
54
- updatePassword(email: string, currentPassword: string, newPassword: string): Promise<void>;
53
+ updatePassword(currentPassword: string, newPassword: string): Promise<void>;
55
54
  }
@@ -1 +1,4 @@
1
+ export * from "./entityStorageAuthenticationAdminRestClient.js";
2
+ export * from "./entityStorageAuthenticationAuditRestClient.js";
1
3
  export * from "./entityStorageAuthenticationRestClient.js";
4
+ export * from "./models/entityStorageAuthenticationRestClientConstructorOptions.js";
@@ -0,0 +1,11 @@
1
+ import type { IBaseRestClientConfig } from "@twin.org/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
+ }