@mondomob/gae-node-nestjs 12.0.0-alpha-2 → 12.0.0-alpha-3

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 (206) hide show
  1. package/dist/_test/mocks.d.ts +9 -0
  2. package/dist/_test/mocks.js +27 -0
  3. package/dist/_test/mocks.js.map +1 -0
  4. package/dist/_test/request-scope-test-utils.d.ts +3 -0
  5. package/dist/_test/request-scope-test-utils.js +18 -0
  6. package/dist/_test/request-scope-test-utils.js.map +1 -0
  7. package/dist/auth/auth-user.model.d.ts +9 -0
  8. package/dist/auth/auth-user.model.js +33 -0
  9. package/dist/auth/auth-user.model.js.map +1 -0
  10. package/dist/auth/auth.callbacks.d.ts +8 -0
  11. package/dist/auth/auth.callbacks.js +5 -0
  12. package/dist/auth/auth.callbacks.js.map +1 -0
  13. package/dist/auth/auth.configurer.d.ts +35 -0
  14. package/dist/auth/auth.configurer.js +212 -0
  15. package/dist/auth/auth.configurer.js.map +1 -0
  16. package/dist/auth/auth.controller.d.ts +27 -0
  17. package/dist/auth/auth.controller.js +312 -0
  18. package/dist/auth/auth.controller.js.map +1 -0
  19. package/dist/auth/auth.guard.d.ts +16 -0
  20. package/dist/auth/auth.guard.js +127 -0
  21. package/dist/auth/auth.guard.js.map +1 -0
  22. package/dist/auth/auth.listener.d.ts +5 -0
  23. package/dist/auth/auth.listener.js +5 -0
  24. package/dist/auth/auth.listener.js.map +1 -0
  25. package/dist/auth/auth.repository.d.ts +52 -0
  26. package/dist/auth/auth.repository.js +79 -0
  27. package/dist/auth/auth.repository.js.map +1 -0
  28. package/dist/auth/auth.resolver.d.ts +13 -0
  29. package/dist/auth/auth.resolver.js +86 -0
  30. package/dist/auth/auth.resolver.js.map +1 -0
  31. package/dist/auth/auth.service.d.ts +35 -0
  32. package/dist/auth/auth.service.js +299 -0
  33. package/dist/auth/auth.service.js.map +1 -0
  34. package/dist/auth/auth.task.controller.d.ts +13 -0
  35. package/dist/auth/auth.task.controller.js +76 -0
  36. package/dist/auth/auth.task.controller.js.map +1 -0
  37. package/dist/auth/auth.task.service.d.ts +8 -0
  38. package/dist/auth/auth.task.service.js +26 -0
  39. package/dist/auth/auth.task.service.js.map +1 -0
  40. package/dist/auth/csrf.interceptor.d.ts +11 -0
  41. package/dist/auth/csrf.interceptor.js +38 -0
  42. package/dist/auth/csrf.interceptor.js.map +1 -0
  43. package/dist/auth/invite-user.service.d.ts +45 -0
  44. package/dist/auth/invite-user.service.js +215 -0
  45. package/dist/auth/invite-user.service.js.map +1 -0
  46. package/dist/auth/invite.callbacks.d.ts +6 -0
  47. package/dist/auth/invite.callbacks.js +5 -0
  48. package/dist/auth/invite.callbacks.js.map +1 -0
  49. package/dist/auth/login-identifier.repository.d.ts +13 -0
  50. package/dist/auth/login-identifier.repository.js +28 -0
  51. package/dist/auth/login-identifier.repository.js.map +1 -0
  52. package/dist/auth/password-reset.service.d.ts +15 -0
  53. package/dist/auth/password-reset.service.js +81 -0
  54. package/dist/auth/password-reset.service.js.map +1 -0
  55. package/dist/auth/user.service.d.ts +27 -0
  56. package/dist/auth/user.service.js +94 -0
  57. package/dist/auth/user.service.js.map +1 -0
  58. package/dist/configuration.d.ts +84 -0
  59. package/dist/configuration.js +5 -0
  60. package/dist/configuration.js.map +1 -0
  61. package/dist/configure.d.ts +40 -0
  62. package/dist/configure.js +85 -0
  63. package/dist/configure.js.map +1 -0
  64. package/dist/context/context-middleware.d.ts +15 -0
  65. package/dist/context/context-middleware.js +37 -0
  66. package/dist/context/context-middleware.js.map +1 -0
  67. package/dist/context/context-request-scope.d.ts +8 -0
  68. package/dist/context/context-request-scope.js +29 -0
  69. package/dist/context/context-request-scope.js.map +1 -0
  70. package/dist/context/index.d.ts +2 -0
  71. package/dist/context/index.js +9 -0
  72. package/dist/context/index.js.map +1 -0
  73. package/dist/datastore/context.d.ts +36 -0
  74. package/dist/datastore/context.js +27 -0
  75. package/dist/datastore/context.js.map +1 -0
  76. package/dist/datastore/datastore.provider.d.ts +8 -0
  77. package/dist/datastore/datastore.provider.js +30 -0
  78. package/dist/datastore/datastore.provider.js.map +1 -0
  79. package/dist/datastore/filters.d.ts +19 -0
  80. package/dist/datastore/filters.js +27 -0
  81. package/dist/datastore/filters.js.map +1 -0
  82. package/dist/datastore/loader.d.ts +50 -0
  83. package/dist/datastore/loader.js +147 -0
  84. package/dist/datastore/loader.js.map +1 -0
  85. package/dist/datastore/node-datastore-session.d.ts +17 -0
  86. package/dist/datastore/node-datastore-session.js +87 -0
  87. package/dist/datastore/node-datastore-session.js.map +1 -0
  88. package/dist/datastore/repository.d.ts +45 -0
  89. package/dist/datastore/repository.js +150 -0
  90. package/dist/datastore/repository.js.map +1 -0
  91. package/dist/datastore/transactional.d.ts +4 -0
  92. package/dist/datastore/transactional.js +13 -0
  93. package/dist/datastore/transactional.js.map +1 -0
  94. package/dist/error/NonFatalError.d.ts +3 -0
  95. package/dist/error/NonFatalError.js +11 -0
  96. package/dist/error/NonFatalError.js.map +1 -0
  97. package/dist/filter.d.ts +5 -0
  98. package/dist/filter.js +40 -0
  99. package/dist/filter.js.map +1 -0
  100. package/dist/gcloud/logging.d.ts +1 -0
  101. package/dist/gcloud/logging.js +5 -0
  102. package/dist/gcloud/logging.js.map +1 -0
  103. package/dist/gcloud/storage.provider.d.ts +12 -0
  104. package/dist/gcloud/storage.provider.js +41 -0
  105. package/dist/gcloud/storage.provider.js.map +1 -0
  106. package/dist/gcloud/tasks.d.ts +10 -0
  107. package/dist/gcloud/tasks.js +68 -0
  108. package/dist/gcloud/tasks.js.map +1 -0
  109. package/dist/graphql/GraphQLMiddleware.d.ts +0 -0
  110. package/dist/graphql/GraphQLMiddleware.js +2 -0
  111. package/dist/graphql/GraphQLMiddleware.js.map +1 -0
  112. package/dist/index.d.ts +28 -0
  113. package/dist/index.js +65 -0
  114. package/dist/index.js.map +1 -0
  115. package/dist/logging/index.d.ts +1 -0
  116. package/dist/logging/index.js +8 -0
  117. package/dist/logging/index.js.map +1 -0
  118. package/dist/logging/logging-internal.d.ts +2 -0
  119. package/dist/logging/logging-internal.js +20 -0
  120. package/dist/logging/logging-internal.js.map +1 -0
  121. package/dist/logging/logging-request-scope.d.ts +15 -0
  122. package/dist/logging/logging-request-scope.js +39 -0
  123. package/dist/logging/logging-request-scope.js.map +1 -0
  124. package/dist/logging/logging.d.ts +34 -0
  125. package/dist/logging/logging.js +55 -0
  126. package/dist/logging/logging.js.map +1 -0
  127. package/dist/mail/gmail/gmail.configurer.d.ts +15 -0
  128. package/dist/mail/gmail/gmail.configurer.js +59 -0
  129. package/dist/mail/gmail/gmail.configurer.js.map +1 -0
  130. package/dist/mail/gmail/gmail.controller.d.ts +9 -0
  131. package/dist/mail/gmail/gmail.controller.js +62 -0
  132. package/dist/mail/gmail/gmail.controller.js.map +1 -0
  133. package/dist/mail/gmail/gmail.sender.d.ts +12 -0
  134. package/dist/mail/gmail/gmail.sender.js +62 -0
  135. package/dist/mail/gmail/gmail.sender.js.map +1 -0
  136. package/dist/mail/gmail/stored.credentials.repository.d.ts +12 -0
  137. package/dist/mail/gmail/stored.credentials.repository.js +23 -0
  138. package/dist/mail/gmail/stored.credentials.repository.js.map +1 -0
  139. package/dist/mail/mail-logging.sender.d.ts +9 -0
  140. package/dist/mail/mail-logging.sender.js +42 -0
  141. package/dist/mail/mail-logging.sender.js.map +1 -0
  142. package/dist/mail/mail-subject.sender.d.ts +12 -0
  143. package/dist/mail/mail-subject.sender.js +33 -0
  144. package/dist/mail/mail-subject.sender.js.map +1 -0
  145. package/dist/mail/mail-whitelist.sender.d.ts +14 -0
  146. package/dist/mail/mail-whitelist.sender.js +59 -0
  147. package/dist/mail/mail-whitelist.sender.js.map +1 -0
  148. package/dist/mail/mail.diverter.d.ts +13 -0
  149. package/dist/mail/mail.diverter.js +65 -0
  150. package/dist/mail/mail.diverter.js.map +1 -0
  151. package/dist/mail/mail.sender.d.ts +6 -0
  152. package/dist/mail/mail.sender.js +5 -0
  153. package/dist/mail/mail.sender.js.map +1 -0
  154. package/dist/mail/smtp/smtp.sender.d.ts +10 -0
  155. package/dist/mail/smtp/smtp.sender.js +65 -0
  156. package/dist/mail/smtp/smtp.sender.js.map +1 -0
  157. package/dist/mail-templates/base.d.ts +2 -0
  158. package/dist/mail-templates/base.js +328 -0
  159. package/dist/mail-templates/base.js.map +1 -0
  160. package/dist/mail-templates/invite.d.ts +1 -0
  161. package/dist/mail-templates/invite.js +19 -0
  162. package/dist/mail-templates/invite.js.map +1 -0
  163. package/dist/module.d.ts +16 -0
  164. package/dist/module.js +136 -0
  165. package/dist/module.js.map +1 -0
  166. package/dist/request-scope/index.d.ts +2 -0
  167. package/dist/request-scope/index.js +9 -0
  168. package/dist/request-scope/index.js.map +1 -0
  169. package/dist/request-scope/request-scope-interceptor.d.ts +5 -0
  170. package/dist/request-scope/request-scope-interceptor.js +3 -0
  171. package/dist/request-scope/request-scope-interceptor.js.map +1 -0
  172. package/dist/request-scope/request-scope.d.ts +12 -0
  173. package/dist/request-scope/request-scope.js +79 -0
  174. package/dist/request-scope/request-scope.js.map +1 -0
  175. package/dist/request-scope/request-scope.middleware.d.ts +15 -0
  176. package/dist/request-scope/request-scope.middleware.js +53 -0
  177. package/dist/request-scope/request-scope.middleware.js.map +1 -0
  178. package/dist/search/search.service.d.ts +52 -0
  179. package/dist/search/search.service.js +90 -0
  180. package/dist/search/search.service.js.map +1 -0
  181. package/dist/search/searchable.repository.d.ts +36 -0
  182. package/dist/search/searchable.repository.js +95 -0
  183. package/dist/search/searchable.repository.js.map +1 -0
  184. package/dist/types.d.ts +3 -0
  185. package/dist/types.js +9 -0
  186. package/dist/types.js.map +1 -0
  187. package/dist/util/arrays.d.ts +1 -0
  188. package/dist/util/arrays.js +10 -0
  189. package/dist/util/arrays.js.map +1 -0
  190. package/dist/util/guards.d.ts +1 -0
  191. package/dist/util/guards.js +7 -0
  192. package/dist/util/guards.js.map +1 -0
  193. package/dist/util/index.d.ts +1 -0
  194. package/dist/util/index.js +5 -0
  195. package/dist/util/index.js.map +1 -0
  196. package/dist/util/nestjs.d.ts +9 -0
  197. package/dist/util/nestjs.js +9 -0
  198. package/dist/util/nestjs.js.map +1 -0
  199. package/dist/util/types.d.ts +4 -0
  200. package/dist/util/types.js +8 -0
  201. package/dist/util/types.js.map +1 -0
  202. package/dist/validator.d.ts +1 -0
  203. package/dist/validator.js +5 -0
  204. package/dist/validator.js.map +1 -0
  205. package/mondomob-gae-node-nestjs-12.0.0-alpha-3.tgz +0 -0
  206. package/package.json +1 -1
@@ -0,0 +1,45 @@
1
+ import { Configuration } from '../configuration';
2
+ import { Context, IUser } from '../datastore/context';
3
+ import { CredentialRepository, UserInviteRepository } from './auth.repository';
4
+ import { UserService } from './user.service';
5
+ import { InviteCallbacks } from './invite.callbacks';
6
+ import { AuthTaskService } from './auth.task.service';
7
+ export declare const DEFAULT_INVITE_CODE_EXPIRY: number;
8
+ export interface IInviteUserResponse {
9
+ user: IUser;
10
+ inviteId?: string;
11
+ }
12
+ export interface IInviteUserRequest {
13
+ email: string;
14
+ roles: string[];
15
+ name?: string;
16
+ skipEmail?: boolean;
17
+ }
18
+ export declare class InviteUserService {
19
+ private readonly authRepository;
20
+ private readonly configuration;
21
+ private readonly userService;
22
+ private readonly userInviteRepository;
23
+ private readonly authTaskService;
24
+ private readonly inviteCallbacks?;
25
+ private readonly logger;
26
+ constructor(authRepository: CredentialRepository, configuration: Configuration, userService: UserService<IUser>, userInviteRepository: UserInviteRepository, authTaskService: AuthTaskService, inviteCallbacks?: InviteCallbacks<IUser> | undefined);
27
+ inviteUserIfRequired(context: Context, request: IInviteUserRequest): Promise<IInviteUserResponse>;
28
+ inviteUser(context: Context, request: IInviteUserRequest): Promise<IInviteUserResponse>;
29
+ getInvitedUser(context: Context, code: string): Promise<IUser | undefined>;
30
+ reInviteForUserId(context: Context, userId: string): Promise<IInviteUserResponse>;
31
+ getUserInviteForUserId(context: Context, userId: string): Promise<{
32
+ id: string;
33
+ email: string;
34
+ createdAt: Date;
35
+ userId: string;
36
+ roles: string[];
37
+ } | undefined>;
38
+ protected reInviteUser(context: Context, existingInvite: any): Promise<IInviteUserResponse>;
39
+ protected inviteUserInternal(context: Context, request: IInviteUserRequest, validateNew: boolean): Promise<IInviteUserResponse>;
40
+ private getActivationExpiryInMillis;
41
+ private queueActivationEmail;
42
+ checkActivationCode(context: Context, code: string): Promise<string | null>;
43
+ activateAccount(context: Context, code: string, name: string, password: string): Promise<IUser>;
44
+ private checkInvite;
45
+ }
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InviteUserService = exports.DEFAULT_INVITE_CODE_EXPIRY = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const uuid_1 = require("uuid");
7
+ const configuration_1 = require("../configuration");
8
+ const transactional_1 = require("../datastore/transactional");
9
+ const logging_1 = require("../logging");
10
+ const arrays_1 = require("../util/arrays");
11
+ const auth_repository_1 = require("./auth.repository");
12
+ const auth_service_1 = require("./auth.service");
13
+ const user_service_1 = require("./user.service");
14
+ const invite_callbacks_1 = require("./invite.callbacks");
15
+ const types_1 = require("../util/types");
16
+ const auth_task_service_1 = require("./auth.task.service");
17
+ exports.DEFAULT_INVITE_CODE_EXPIRY = 7 * 24 * 60 * 60 * 1000;
18
+ let InviteUserService = class InviteUserService {
19
+ constructor(authRepository, configuration, userService, userInviteRepository, authTaskService, inviteCallbacks) {
20
+ this.authRepository = authRepository;
21
+ this.configuration = configuration;
22
+ this.userService = userService;
23
+ this.userInviteRepository = userInviteRepository;
24
+ this.authTaskService = authTaskService;
25
+ this.inviteCallbacks = inviteCallbacks;
26
+ this.getActivationExpiryInMillis = () => {
27
+ return this.configuration.auth.local && this.configuration.auth.local.activationExpiryInMinutes
28
+ ? this.configuration.auth.local.activationExpiryInMinutes * 60 * 1000
29
+ : exports.DEFAULT_INVITE_CODE_EXPIRY;
30
+ };
31
+ this.logger = (0, logging_1.createLogger)('invite-user-service');
32
+ }
33
+ async inviteUserIfRequired(context, request) {
34
+ return this.inviteUserInternal(context, request, false);
35
+ }
36
+ async inviteUser(context, request) {
37
+ return this.inviteUserInternal(context, request, true);
38
+ }
39
+ async getInvitedUser(context, code) {
40
+ const invite = await this.userInviteRepository.get(context, code);
41
+ if (!invite) {
42
+ return;
43
+ }
44
+ const activationExpiry = this.getActivationExpiryInMillis();
45
+ if (Date.now() - invite.createdAt.getTime() > activationExpiry) {
46
+ this.logger.info(`User invite for ${invite.email} has expired. Was created ${invite.createdAt}.`);
47
+ throw new Error('Account activation code expired');
48
+ }
49
+ return this.userService.get(context, invite.userId);
50
+ }
51
+ async reInviteForUserId(context, userId) {
52
+ this.logger.info(`Re Inviting user with id: ${userId}`);
53
+ const existingInvite = await this.getUserInviteForUserId(context, userId);
54
+ if (existingInvite) {
55
+ return this.reInviteUser(context, existingInvite);
56
+ }
57
+ else {
58
+ throw new Error('No user invites found.');
59
+ }
60
+ }
61
+ async getUserInviteForUserId(context, userId) {
62
+ const [existingInvites] = await this.userInviteRepository.query(context, {
63
+ filters: {
64
+ userId,
65
+ },
66
+ limit: 1,
67
+ });
68
+ this.logger.info(`Existing Invites ${existingInvites}`);
69
+ if (existingInvites && existingInvites.length > 0) {
70
+ return existingInvites[0];
71
+ }
72
+ else {
73
+ return undefined;
74
+ }
75
+ }
76
+ async reInviteUser(context, existingInvite) {
77
+ const user = await this.userService.getByEmail(context, existingInvite.email);
78
+ if (!user) {
79
+ throw new Error('User not found');
80
+ }
81
+ const newInvite = await this.userInviteRepository.save(context, {
82
+ id: (0, uuid_1.v4)(),
83
+ email: existingInvite.email,
84
+ createdAt: new Date(),
85
+ roles: existingInvite.roles,
86
+ userId: existingInvite.userId,
87
+ });
88
+ await this.userInviteRepository.delete(context, existingInvite.id);
89
+ await this.queueActivationEmail(context, newInvite.email, newInvite.id, false);
90
+ return { user, inviteId: newInvite.id };
91
+ }
92
+ async inviteUserInternal(context, request, validateNew) {
93
+ var _a;
94
+ const { email, roles } = request;
95
+ this.logger.info(`Inviting user with email: ${email}, roles: ${roles}, validateNew: ${validateNew}`);
96
+ if (roles.includes('super')) {
97
+ throw new Error('Cannot assign super role to users');
98
+ }
99
+ const auth = await this.authRepository.get(context, email);
100
+ if (validateNew && auth) {
101
+ throw new Error('Email already exists');
102
+ }
103
+ let user = await this.userService.getByEmail(context, email);
104
+ if (!user) {
105
+ user = await this.userService.create(context, {
106
+ email,
107
+ name: request.name,
108
+ enabled: false,
109
+ });
110
+ }
111
+ if (auth) {
112
+ this.logger.info(`User with email ${email} already has a login so does not need to be invited`);
113
+ const updatedUser = await this.userService.update(context, user.id, {
114
+ roles: (0, arrays_1.unique)(user.roles, ...roles),
115
+ enabled: true,
116
+ });
117
+ return { user: updatedUser };
118
+ }
119
+ else {
120
+ const inviteId = (0, uuid_1.v4)();
121
+ await this.userInviteRepository.save(context, {
122
+ id: inviteId,
123
+ email,
124
+ createdAt: new Date(),
125
+ roles,
126
+ userId: user.id,
127
+ });
128
+ await this.queueActivationEmail(context, email, inviteId, request.skipEmail);
129
+ if ((_a = this.inviteCallbacks) === null || _a === void 0 ? void 0 : _a.afterInvite) {
130
+ await (0, types_1.asPromise)(this.inviteCallbacks.afterInvite(context, user, inviteId));
131
+ }
132
+ return { user, inviteId };
133
+ }
134
+ }
135
+ async queueActivationEmail(context, email, inviteId, skipEmail) {
136
+ if (skipEmail) {
137
+ this.logger.info('Skipping sending invitation email based on request option');
138
+ return;
139
+ }
140
+ this.logger.info(`Queuing invitation email to ${email}`);
141
+ await this.authTaskService.queueActivationEmail(inviteId, email);
142
+ }
143
+ async checkActivationCode(context, code) {
144
+ const invite = await this.userInviteRepository.get(context, code);
145
+ return this.checkInvite(context, invite);
146
+ }
147
+ async activateAccount(context, code, name, password) {
148
+ var _a;
149
+ const invite = await this.userInviteRepository.get(context, code);
150
+ const err = await this.checkInvite(context, invite);
151
+ if (err) {
152
+ throw new Error(err);
153
+ }
154
+ const user = await this.userService.update(context, invite.userId, {
155
+ name,
156
+ roles: invite.roles,
157
+ enabled: true,
158
+ });
159
+ this.logger.info(`Accepting invitation and activating account for email ${user.email}, code ${code}, name ${name}`);
160
+ await this.authRepository.save(context, {
161
+ id: invite.email,
162
+ type: 'password',
163
+ password: await (0, auth_service_1.hashPassword)(password),
164
+ userId: user.id,
165
+ });
166
+ await this.userInviteRepository.delete(context, code);
167
+ if ((_a = this.inviteCallbacks) === null || _a === void 0 ? void 0 : _a.afterActivate) {
168
+ await (0, types_1.asPromise)(this.inviteCallbacks.afterActivate(context, user));
169
+ }
170
+ return user;
171
+ }
172
+ async checkInvite(context, invite) {
173
+ if (!invite) {
174
+ return "This activation code is no longer available. Please use the 'Activate Account' link in the most recent activation email you have received. If you're still experiencing problems please contact your administrator.";
175
+ }
176
+ const activationExpiry = this.getActivationExpiryInMillis();
177
+ if (Date.now() - invite.createdAt.getTime() > activationExpiry) {
178
+ return 'Sorry, your activation code has expired. Please contact your administrator';
179
+ }
180
+ const auth = await this.authRepository.get(context, invite.email);
181
+ if (auth) {
182
+ return 'Account already registered';
183
+ }
184
+ return null;
185
+ }
186
+ };
187
+ exports.InviteUserService = InviteUserService;
188
+ tslib_1.__decorate([
189
+ (0, transactional_1.Transactional)(),
190
+ tslib_1.__metadata("design:type", Function),
191
+ tslib_1.__metadata("design:paramtypes", [Object, Object]),
192
+ tslib_1.__metadata("design:returntype", Promise)
193
+ ], InviteUserService.prototype, "inviteUser", null);
194
+ tslib_1.__decorate([
195
+ (0, transactional_1.Transactional)(),
196
+ tslib_1.__metadata("design:type", Function),
197
+ tslib_1.__metadata("design:paramtypes", [Object, Object]),
198
+ tslib_1.__metadata("design:returntype", Promise)
199
+ ], InviteUserService.prototype, "reInviteUser", null);
200
+ tslib_1.__decorate([
201
+ (0, transactional_1.Transactional)(),
202
+ tslib_1.__metadata("design:type", Function),
203
+ tslib_1.__metadata("design:paramtypes", [Object, String, String, String]),
204
+ tslib_1.__metadata("design:returntype", Promise)
205
+ ], InviteUserService.prototype, "activateAccount", null);
206
+ exports.InviteUserService = InviteUserService = tslib_1.__decorate([
207
+ (0, common_1.Injectable)(),
208
+ tslib_1.__param(1, (0, common_1.Inject)(configuration_1.CONFIGURATION)),
209
+ tslib_1.__param(2, (0, common_1.Inject)(user_service_1.USER_SERVICE)),
210
+ tslib_1.__param(5, (0, common_1.Optional)()),
211
+ tslib_1.__param(5, (0, common_1.Inject)(invite_callbacks_1.INVITE_CALLBACKS)),
212
+ tslib_1.__metadata("design:paramtypes", [auth_repository_1.CredentialRepository, Object, Object, auth_repository_1.UserInviteRepository,
213
+ auth_task_service_1.AuthTaskService, Object])
214
+ ], InviteUserService);
215
+ //# sourceMappingURL=invite-user.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invite-user.service.js","sourceRoot":"","sources":["../../src/auth/invite-user.service.ts"],"names":[],"mappings":";;;;AAAA,2CAA8D;AAC9D,+BAAoC;AACpC,oDAAgE;AAEhE,8DAA2D;AAC3D,wCAAkD;AAClD,2CAAwC;AACxC,uDAA2F;AAC3F,iDAA8C;AAC9C,iDAA2D;AAC3D,yDAAuE;AACvE,yCAA0C;AAC1C,2DAAsD;AAEzC,QAAA,0BAA0B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAkB3D,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAG5B,YACmB,cAAoC,EAC9B,aAA6C,EAC9C,WAAgD,EACrD,oBAA0C,EAC1C,eAAgC,EACX,eAAyD;QAL9E,mBAAc,GAAd,cAAc,CAAsB;QACb,kBAAa,GAAb,aAAa,CAAe;QAC7B,gBAAW,GAAX,WAAW,CAAoB;QACrD,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,oBAAe,GAAf,eAAe,CAAiB;QACM,oBAAe,GAAf,eAAe,CAAyB;QAuKzF,gCAA2B,GAAG,GAAG,EAAE;YACzC,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,IAA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M,EAAC,6BAAa,CAAC,CAAA;IACrB,mBAAA,IAAA,eAAM,EAAC,2BAAY,CAAC,CAAA;IAGpB,mBAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,mBAAA,IAAA,eAAM,EAAC,mCAAgB,CAAC,CAAA;6CALJ,sCAAoB,kBAGd,sCAAoB;QACzB,mCAAe;GARxC,iBAAiB,CA+Q7B"}
@@ -0,0 +1,6 @@
1
+ import { Context, IUser } from '../datastore/context';
2
+ export declare const INVITE_CALLBACKS = "InviteCallbacks";
3
+ export interface InviteCallbacks<U extends IUser> {
4
+ afterInvite?(context: Context, user: U, inviteId: string): void | Promise<void>;
5
+ afterActivate?(context: Context, user: U): void | Promise<void>;
6
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.INVITE_CALLBACKS = void 0;
4
+ exports.INVITE_CALLBACKS = 'InviteCallbacks';
5
+ //# sourceMappingURL=invite.callbacks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invite.callbacks.js","sourceRoot":"","sources":["../../src/auth/invite.callbacks.ts"],"names":[],"mappings":";;;AAEa,QAAA,gBAAgB,GAAG,iBAAiB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import * as t from 'io-ts';
2
+ import { Repository } from '../datastore/repository';
3
+ import { DatastoreProvider } from '../datastore/datastore.provider';
4
+ declare const loginIdentifier: t.TypeC<{
5
+ id: t.StringC;
6
+ userId: t.StringC;
7
+ createdAt: t.Type<Date, Date, unknown>;
8
+ }>;
9
+ export type LoginIdentifier = t.TypeOf<typeof loginIdentifier>;
10
+ export declare class LoginIdentifierRepository extends Repository<LoginIdentifier> {
11
+ constructor(datastore: DatastoreProvider);
12
+ }
13
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoginIdentifierRepository = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const t = require("io-ts");
7
+ const repository_1 = require("../datastore/repository");
8
+ const datastore_provider_1 = require("../datastore/datastore.provider");
9
+ const loginIdentifier = t.interface({
10
+ id: t.string,
11
+ userId: t.string,
12
+ createdAt: repository_1.dateType,
13
+ });
14
+ let LoginIdentifierRepository = class LoginIdentifierRepository extends repository_1.Repository {
15
+ constructor(datastore) {
16
+ super(datastore.datastore, 'LoginIdentifier', loginIdentifier, {
17
+ index: {
18
+ userId: true,
19
+ },
20
+ });
21
+ }
22
+ };
23
+ exports.LoginIdentifierRepository = LoginIdentifierRepository;
24
+ exports.LoginIdentifierRepository = LoginIdentifierRepository = tslib_1.__decorate([
25
+ (0, common_1.Injectable)(),
26
+ tslib_1.__metadata("design:paramtypes", [datastore_provider_1.DatastoreProvider])
27
+ ], LoginIdentifierRepository);
28
+ //# sourceMappingURL=login-identifier.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-identifier.repository.js","sourceRoot":"","sources":["../../src/auth/login-identifier.repository.ts"],"names":[],"mappings":";;;;AAAA,2CAA4C;AAC5C,2BAA2B;AAC3B,wDAA+D;AAC/D,wEAAoE;AAEpE,MAAM,eAAe,GAAG,CAAC,CAAC,SAAS,CAAC;IAClC,EAAE,EAAE,CAAC,CAAC,MAAM;IACZ,MAAM,EAAE,CAAC,CAAC,MAAM;IAChB,SAAS,EAAE,qBAAQ;CACpB,CAAC,CAAC;AAKI,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,uBAA2B;IACxE,YAAY,SAA4B;QACtC,KAAK,CAAC,SAAS,CAAC,SAAS,EAAE,iBAAiB,EAAE,eAAe,EAAE;YAC7D,KAAK,EAAE;gBACL,MAAM,EAAE,IAAI;aACb;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AARY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;6CAEY,sCAAiB;GAD7B,yBAAyB,CAQrC"}
@@ -0,0 +1,15 @@
1
+ import { Context } from '../datastore/context';
2
+ import { CredentialRepository, PasswordResetRepository } from './auth.repository';
3
+ import { Configuration } from '../configuration';
4
+ import { AuthTaskService } from './auth.task.service';
5
+ export declare class PasswordResetService {
6
+ private readonly authRepository;
7
+ private readonly passwordResetRepository;
8
+ private readonly configuration;
9
+ private readonly authTaskService;
10
+ private readonly logger;
11
+ private readonly tokenExpiry;
12
+ constructor(authRepository: CredentialRepository, passwordResetRepository: PasswordResetRepository, configuration: Configuration, authTaskService: AuthTaskService);
13
+ resetPassword(context: Context, email: string): Promise<void>;
14
+ confirmResetPassword(context: Context, code: string, newPassword: string): Promise<void>;
15
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PasswordResetService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const uuid_1 = require("uuid");
7
+ const transactional_1 = require("../datastore/transactional");
8
+ const logging_1 = require("../logging");
9
+ const auth_repository_1 = require("./auth.repository");
10
+ const auth_service_1 = require("./auth.service");
11
+ const auth_task_service_1 = require("./auth.task.service");
12
+ const DEFAULT_PASSWORD_TOKEN_EXPIRY = 24 * 60 * 60 * 1000;
13
+ let PasswordResetService = class PasswordResetService {
14
+ constructor(authRepository, passwordResetRepository, configuration, authTaskService) {
15
+ this.authRepository = authRepository;
16
+ this.passwordResetRepository = passwordResetRepository;
17
+ this.configuration = configuration;
18
+ this.authTaskService = authTaskService;
19
+ this.logger = (0, logging_1.createLogger)('password-reset-service');
20
+ this.tokenExpiry = configuration.passwordTokenExpiry || DEFAULT_PASSWORD_TOKEN_EXPIRY;
21
+ }
22
+ async resetPassword(context, email) {
23
+ const credentials = await this.authRepository.get(context, email);
24
+ if (!credentials) {
25
+ this.logger.info(`No account found when trying to reset password for "${email}"`);
26
+ return;
27
+ }
28
+ if (credentials.type !== 'password') {
29
+ this.logger.info(`No account found when trying to reset password for "${email}"`);
30
+ return;
31
+ }
32
+ this.logger.info(`Queuing password reset email for "${email}"`);
33
+ const id = (0, uuid_1.v4)();
34
+ await this.passwordResetRepository.save(context, {
35
+ accountId: credentials.id,
36
+ createdAt: new Date(),
37
+ id,
38
+ });
39
+ await this.authTaskService.queuePasswordResetEmail(id, email);
40
+ }
41
+ async confirmResetPassword(context, code, newPassword) {
42
+ const resetToken = await this.passwordResetRepository.get(context, code);
43
+ if (!resetToken) {
44
+ throw new Error('Invalid password reset token');
45
+ }
46
+ if (Date.now() - resetToken.createdAt.getTime() > this.tokenExpiry) {
47
+ throw new Error('Token has expired');
48
+ }
49
+ const account = await this.authRepository.get(context, resetToken.accountId);
50
+ if (!account) {
51
+ throw new Error('Account no longer exists');
52
+ }
53
+ if (account.type !== 'password') {
54
+ throw new Error('Account no longer exists');
55
+ }
56
+ account.password = await (0, auth_service_1.hashPassword)(newPassword);
57
+ this.logger.info(`Resetting password for account ${resetToken.id}`);
58
+ await this.passwordResetRepository.delete(context, resetToken.id);
59
+ await this.authRepository.save(context, account);
60
+ }
61
+ };
62
+ exports.PasswordResetService = PasswordResetService;
63
+ tslib_1.__decorate([
64
+ (0, transactional_1.Transactional)(),
65
+ tslib_1.__metadata("design:type", Function),
66
+ tslib_1.__metadata("design:paramtypes", [Object, String]),
67
+ tslib_1.__metadata("design:returntype", Promise)
68
+ ], PasswordResetService.prototype, "resetPassword", null);
69
+ tslib_1.__decorate([
70
+ (0, transactional_1.Transactional)(),
71
+ tslib_1.__metadata("design:type", Function),
72
+ tslib_1.__metadata("design:paramtypes", [Object, String, String]),
73
+ tslib_1.__metadata("design:returntype", Promise)
74
+ ], PasswordResetService.prototype, "confirmResetPassword", null);
75
+ exports.PasswordResetService = PasswordResetService = tslib_1.__decorate([
76
+ (0, common_1.Injectable)(),
77
+ tslib_1.__param(2, (0, common_1.Inject)('Configuration')),
78
+ tslib_1.__metadata("design:paramtypes", [auth_repository_1.CredentialRepository,
79
+ auth_repository_1.PasswordResetRepository, Object, auth_task_service_1.AuthTaskService])
80
+ ], PasswordResetService);
81
+ //# sourceMappingURL=password-reset.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-reset.service.js","sourceRoot":"","sources":["../../src/auth/password-reset.service.ts"],"names":[],"mappings":";;;;AAAA,2CAAoD;AACpD,+BAAoC;AAEpC,8DAA2D;AAC3D,wCAAkD;AAClD,uDAAkF;AAClF,iDAA8C;AAE9C,2DAAsD;AAEtD,MAAM,6BAA6B,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAGnD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAI/B,YACmB,cAAoC,EACpC,uBAAgD,EACvB,aAA4B,EACrD,eAAgC;QAHhC,mBAAc,GAAd,cAAc,CAAsB;QACpC,4BAAuB,GAAvB,uBAAuB,CAAyB;QACvB,kBAAa,GAAb,aAAa,CAAe;QACrD,oBAAe,GAAf,eAAe,CAAiB;QAEjD,IAAI,CAAC,MAAM,GAAG,IAAA,sBAAY,EAAC,wBAAwB,CAAC,CAAC;QACrD,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC,mBAAmB,IAAI,6BAA6B,CAAC;IACxF,CAAC;IAWK,AAAN,KAAK,CAAC,aAAa,CAAC,OAAgB,EAAE,KAAa;QACjD,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAElE,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,uDAAuD,KAAK,GAAG,CAAC,CAAC;YAClF,OAAO;QACT,CAAC;QAED,IAAI,WAAW,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACpC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,uDAAuD,KAAK,GAAG,CAAC,CAAC;YAClF,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,qCAAqC,KAAK,GAAG,CAAC,CAAC;QAEhE,MAAM,EAA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AM,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;QAClE,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;CACF,CAAA;AArFY,oDAAoB;AAuBzB;IADL,IAAA,6BAAa,GAAE;;;;yDAyBf;AAUK;IADL,IAAA,6BAAa,GAAE;;;;gEA4Bf;+BApFU,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAQR,mBAAA,IAAA,eAAM,EAAC,eAAe,CAAC,CAAA;6CAFS,sCAAoB;QACX,yCAAuB,UAE/B,mCAAe;GARxC,oBAAoB,CAqFhC"}
@@ -0,0 +1,27 @@
1
+ import { LoginIdentifierRepository } from './login-identifier.repository';
2
+ import { Context, IUser, IUserCreateRequest, IUserUpdates } from '../datastore/context';
3
+ export declare const USER_SERVICE = "UserService";
4
+ export declare const normaliseEmail: (email: string) => string;
5
+ export interface UserService<T extends IUser, U extends IUserUpdates = IUserUpdates, C extends IUserCreateRequest & U = IUserCreateRequest & U> {
6
+ getByEmail(context: Context, email: string): Promise<T | undefined>;
7
+ get(context: Context, userId: string): Promise<T | undefined>;
8
+ createOrUpdate(context: Context, user: C, beforeUpdate?: (user: T) => void): Promise<T>;
9
+ create(context: Context, user: C): Promise<T>;
10
+ update(context: Context, id: string, updates: U): Promise<T>;
11
+ }
12
+ export declare abstract class AbstractUserService<T extends IUser, U extends IUserUpdates = IUserUpdates, C extends IUserCreateRequest & U = IUserCreateRequest & U> implements UserService<T, U, C> {
13
+ protected readonly loginIdentifierRepository: LoginIdentifierRepository;
14
+ private readonly baseLogger;
15
+ protected constructor(loginIdentifierRepository: LoginIdentifierRepository);
16
+ abstract get(context: Context, userId: string): Promise<T | undefined>;
17
+ protected abstract createUser(context: Context, user: C): Promise<T>;
18
+ protected abstract updateUser(context: Context, user: T, updates: U): Promise<T>;
19
+ getByEmail(context: Context, email: string): Promise<T | undefined>;
20
+ createOrUpdate(context: Context, updates: C, beforeUpdate?: (user: T) => void): Promise<T>;
21
+ create(context: Context, user: C): Promise<T>;
22
+ update(context: Context, id: string, updates: U): Promise<T>;
23
+ protected getIdByEmail(context: Context, email: string): Promise<string | undefined>;
24
+ private updateRetrievedUser;
25
+ private createLoginIdentifier;
26
+ private validateEmailAddressAvailable;
27
+ }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractUserService = exports.normaliseEmail = exports.USER_SERVICE = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const logging_1 = require("../logging");
6
+ const transactional_1 = require("../datastore/transactional");
7
+ exports.USER_SERVICE = 'UserService';
8
+ const normaliseEmail = (email) => email.toLowerCase();
9
+ exports.normaliseEmail = normaliseEmail;
10
+ class AbstractUserService {
11
+ constructor(loginIdentifierRepository) {
12
+ this.loginIdentifierRepository = loginIdentifierRepository;
13
+ this.baseLogger = (0, logging_1.createLogger)('abstract-user-service');
14
+ }
15
+ async getByEmail(context, email) {
16
+ const userId = await this.getIdByEmail(context, email);
17
+ return userId ? this.get(context, userId) : undefined;
18
+ }
19
+ async createOrUpdate(context, updates, beforeUpdate = () => { }) {
20
+ const existingUser = await this.getByEmail(context, updates.email);
21
+ if (existingUser) {
22
+ beforeUpdate(existingUser);
23
+ }
24
+ return existingUser ? this.updateRetrievedUser(context, existingUser, updates) : this.create(context, updates);
25
+ }
26
+ async create(context, user) {
27
+ const normalisedEmail = (0, exports.normaliseEmail)(user.email);
28
+ await this.validateEmailAddressAvailable(context, normalisedEmail);
29
+ const createdUser = await this.createUser(context, Object.assign(Object.assign({}, user), { email: normalisedEmail, roles: user.roles || [] }));
30
+ await this.createLoginIdentifier(context, normalisedEmail, createdUser.id);
31
+ this.baseLogger.info(`Created new user ${user.email}`);
32
+ return createdUser;
33
+ }
34
+ async update(context, id, updates) {
35
+ const user = await this.get(context, id);
36
+ if (!user) {
37
+ throw new Error(`No user exists with id: ${id}`);
38
+ }
39
+ return await this.updateRetrievedUser(context, user, updates);
40
+ }
41
+ async getIdByEmail(context, email) {
42
+ const loginIdentifier = await this.loginIdentifierRepository.get(context, (0, exports.normaliseEmail)(email));
43
+ return loginIdentifier === null || loginIdentifier === void 0 ? void 0 : loginIdentifier.userId;
44
+ }
45
+ async updateRetrievedUser(context, user, updates) {
46
+ if (updates.roles && updates.roles.includes('super')) {
47
+ throw new Error('Cannot assign super role to users');
48
+ }
49
+ const normalisedEmail = updates.email && (0, exports.normaliseEmail)(updates.email);
50
+ if (normalisedEmail && normalisedEmail !== user.email) {
51
+ this.baseLogger.info(`Email changed from [${user.email}] to [${normalisedEmail}]. Changing email for user id [${user.id}]`);
52
+ await this.validateEmailAddressAvailable(context, normalisedEmail);
53
+ await Promise.all([
54
+ this.loginIdentifierRepository.delete(context, user.email),
55
+ this.createLoginIdentifier(context, normalisedEmail, user.id),
56
+ ]);
57
+ }
58
+ const userUpdates = (normalisedEmail && Object.assign(Object.assign({}, updates), { email: normalisedEmail })) || updates;
59
+ return this.updateUser(context, user, userUpdates);
60
+ }
61
+ async createLoginIdentifier(context, email, userId) {
62
+ return this.loginIdentifierRepository.save(context, {
63
+ id: email,
64
+ createdAt: new Date(),
65
+ userId,
66
+ });
67
+ }
68
+ async validateEmailAddressAvailable(context, email) {
69
+ const existing = await this.loginIdentifierRepository.get(context, email);
70
+ if (existing) {
71
+ throw new Error(`Email address already exists: ${email}`);
72
+ }
73
+ }
74
+ }
75
+ exports.AbstractUserService = AbstractUserService;
76
+ tslib_1.__decorate([
77
+ (0, transactional_1.Transactional)(),
78
+ tslib_1.__metadata("design:type", Function),
79
+ tslib_1.__metadata("design:paramtypes", [Object, Object, Function]),
80
+ tslib_1.__metadata("design:returntype", Promise)
81
+ ], AbstractUserService.prototype, "createOrUpdate", null);
82
+ tslib_1.__decorate([
83
+ (0, transactional_1.Transactional)(),
84
+ tslib_1.__metadata("design:type", Function),
85
+ tslib_1.__metadata("design:paramtypes", [Object, Object]),
86
+ tslib_1.__metadata("design:returntype", Promise)
87
+ ], AbstractUserService.prototype, "create", null);
88
+ tslib_1.__decorate([
89
+ (0, transactional_1.Transactional)(),
90
+ tslib_1.__metadata("design:type", Function),
91
+ tslib_1.__metadata("design:paramtypes", [Object, String, Object]),
92
+ tslib_1.__metadata("design:returntype", Promise)
93
+ ], AbstractUserService.prototype, "update", null);
94
+ //# sourceMappingURL=user.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.service.js","sourceRoot":"","sources":["../../src/auth/user.service.ts"],"names":[],"mappings":";;;;AAEA,wCAAkD;AAClD,8DAA2D;AAE9C,QAAA,YAAY,GAAG,aAAa,CAAC;AAEnC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;AAAxD,QAAA,cAAc,kBAA0C;AAcrE,MAAsB,mBAAmB;IAQvC,YAAyC,yBAAoD;QAApD,8BAAyB,GAAzB,yBAAyB,CAA2B;QAC3F,IAAI,CAAC,UAAU,GAAG,IAAA,sBAAY,EAAC,uBAAuB,CAAC,CAAC;IAC1D,CAAC;IAMD,KAAK,CAAC,UAAU,CAAC,OAAgB,EAAE,KAAa;QAC9C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACvD,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACxD,CAAC;IAGK,AAAN,KAAK,CAAC,cAAc,CAAC,OAAgB,EAAE,OAAU,EAAE,eAAkC,GAAG,EAAE,GAAE,CAAC;QAC3F,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QACnE,IAAI,YAAY,EAAE,CAAC;YACjB,YAAY,CAAC,YAAY,CAAC,CAAC;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