@darraghor/nest-backend-libs 2.22.0 → 2.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/authz/ApiKeyAuthGuard.d.ts +5 -0
  2. package/dist/authz/ApiKeyAuthGuard.js +27 -0
  3. package/dist/authz/ApiKeyAuthGuard.js.map +1 -0
  4. package/dist/authz/UserValidation.service.d.ts +9 -4
  5. package/dist/authz/UserValidation.service.js +74 -23
  6. package/dist/authz/UserValidation.service.js.map +1 -1
  7. package/dist/authz/apikeystrategy.d.ts +12 -0
  8. package/dist/authz/apikeystrategy.js +43 -0
  9. package/dist/authz/apikeystrategy.js.map +1 -0
  10. package/dist/authz/authz.module.js +10 -1
  11. package/dist/authz/authz.module.js.map +1 -1
  12. package/dist/authz/authzstrategy.js +2 -1
  13. package/dist/authz/authzstrategy.js.map +1 -1
  14. package/dist/authz/index.d.ts +3 -0
  15. package/dist/authz/index.js +7 -1
  16. package/dist/authz/index.js.map +1 -1
  17. package/dist/authz/isOwnerOrThrow.d.ts +2 -0
  18. package/dist/authz/isOwnerOrThrow.js +20 -0
  19. package/dist/authz/isOwnerOrThrow.js.map +1 -0
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.js +1 -0
  22. package/dist/index.js.map +1 -1
  23. package/dist/invitations/entities/invitation.entity.d.ts +3 -3
  24. package/dist/invitations/entities/invitation.entity.js +11 -9
  25. package/dist/invitations/entities/invitation.entity.js.map +1 -1
  26. package/dist/invitations/invitation.module.js +3 -2
  27. package/dist/invitations/invitation.module.js.map +1 -1
  28. package/dist/invitations/invitation.service.d.ts +9 -3
  29. package/dist/invitations/invitation.service.js +132 -34
  30. package/dist/invitations/invitation.service.js.map +1 -1
  31. package/dist/organisation-memberships/entities/organisation-membership.entity.d.ts +2 -0
  32. package/dist/organisation-memberships/entities/organisation-membership.entity.js +11 -0
  33. package/dist/organisation-memberships/entities/organisation-membership.entity.js.map +1 -1
  34. package/dist/user-api-key/CreateApiKeyDto.d.ts +3 -0
  35. package/dist/user-api-key/CreateApiKeyDto.js +24 -0
  36. package/dist/user-api-key/CreateApiKeyDto.js.map +1 -0
  37. package/dist/user-api-key/index.d.ts +3 -0
  38. package/dist/user-api-key/index.js +10 -0
  39. package/dist/user-api-key/index.js.map +1 -0
  40. package/dist/user-api-key/user-apikey.controller.d.ts +13 -0
  41. package/dist/user-api-key/user-apikey.controller.js +88 -0
  42. package/dist/user-api-key/user-apikey.controller.js.map +1 -0
  43. package/dist/user-api-key/user-apikey.module.d.ts +2 -0
  44. package/dist/user-api-key/user-apikey.module.js +27 -0
  45. package/dist/user-api-key/user-apikey.module.js.map +1 -0
  46. package/dist/user-api-key/user-apikey.service.d.ts +17 -0
  47. package/dist/user-api-key/user-apikey.service.js +91 -0
  48. package/dist/user-api-key/user-apikey.service.js.map +1 -0
  49. package/dist/user-api-key/userApiKey.entity.d.ts +12 -0
  50. package/dist/user-api-key/userApiKey.entity.js +77 -0
  51. package/dist/user-api-key/userApiKey.entity.js.map +1 -0
  52. package/dist/user-external/user-external.module.js +0 -2
  53. package/dist/user-external/user-external.module.js.map +1 -1
  54. package/dist/user-internal/dto/userResponseDto.d.ts +2 -2
  55. package/dist/user-internal/dto/userResponseDto.js +2 -2
  56. package/dist/user-internal/dto/userResponseDto.js.map +1 -1
  57. package/dist/user-internal/entities/user.entity.d.ts +4 -2
  58. package/dist/user-internal/entities/user.entity.js +12 -4
  59. package/dist/user-internal/entities/user.entity.js.map +1 -1
  60. package/dist/user-internal/user-internal.module.js +0 -1
  61. package/dist/user-internal/user-internal.module.js.map +1 -1
  62. package/package.json +5 -1
@@ -11,6 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
+ var InvitationService_1;
14
15
  Object.defineProperty(exports, "__esModule", { value: true });
15
16
  exports.InvitationService = void 0;
16
17
  const common_1 = require("@nestjs/common");
@@ -19,76 +20,173 @@ const typeorm_2 = require("typeorm");
19
20
  const RolesEnum_1 = require("../organisation/dto/RolesEnum");
20
21
  const invitation_entity_1 = require("./entities/invitation.entity");
21
22
  const email_client_service_1 = require("../smtp-email-client/email-client.service");
22
- const organisation_entity_1 = require("../organisation/entities/organisation.entity");
23
23
  const InvitationConfigurationService_1 = require("./InvitationConfigurationService");
24
- let InvitationService = class InvitationService {
24
+ const organisation_membership_entity_1 = require("../organisation-memberships/entities/organisation-membership.entity");
25
+ const member_role_entity_1 = require("../organisation/entities/member-role.entity");
26
+ const user_internal_1 = require("../user-internal");
27
+ let InvitationService = InvitationService_1 = class InvitationService {
25
28
  invitationRepository;
26
- organisationRepository;
29
+ orgMembershipRepository;
30
+ userRepository;
27
31
  emailClient;
28
32
  configService;
29
- constructor(invitationRepository, organisationRepository, emailClient, configService) {
33
+ logger = new common_1.Logger(InvitationService_1.name);
34
+ constructor(invitationRepository, orgMembershipRepository, userRepository, emailClient, configService) {
30
35
  this.invitationRepository = invitationRepository;
31
- this.organisationRepository = organisationRepository;
36
+ this.orgMembershipRepository = orgMembershipRepository;
37
+ this.userRepository = userRepository;
32
38
  this.emailClient = emailClient;
33
39
  this.configService = configService;
34
40
  }
41
+ async getOneActiveInvitation(invitationCode) {
42
+ return this.invitationRepository.findOne({
43
+ where: {
44
+ uuid: invitationCode,
45
+ acceptedOn: (0, typeorm_2.IsNull)(),
46
+ expiresOn: (0, typeorm_2.LessThan)(new Date()),
47
+ },
48
+ relations: {
49
+ organisationMembership: {
50
+ user: true,
51
+ organisation: true,
52
+ },
53
+ },
54
+ });
55
+ }
56
+ async acceptInvitation(invitationId) {
57
+ await this.invitationRepository.manager.transaction(async (transactionalEntityManager) => {
58
+ // get the invitation again to ensure we have the latest version
59
+ const latestInvitation = await transactionalEntityManager.findOne(invitation_entity_1.Invitation, {
60
+ where: { id: invitationId },
61
+ relations: {
62
+ organisationMembership: true,
63
+ },
64
+ });
65
+ if (!latestInvitation) {
66
+ throw new common_1.NotFoundException(`Invitation with id ${invitationId} not found`);
67
+ }
68
+ // set the invitation to accepted
69
+ latestInvitation.acceptedOn = new Date();
70
+ await transactionalEntityManager.save(latestInvitation);
71
+ // set the user's membership to member and remove the invitation role
72
+ const memberRole = new member_role_entity_1.MembershipRole();
73
+ memberRole.name = RolesEnum_1.Roles.member;
74
+ latestInvitation.organisationMembership.roles = [memberRole];
75
+ await transactionalEntityManager.save(latestInvitation.organisationMembership);
76
+ });
77
+ }
35
78
  async create(createDto, createdBy) {
36
- const existingInvitations = await this.invitationRepository.find({
79
+ await this.canManageInvitationsForThisOrg(createDto.organisationId, createdBy.id);
80
+ const existingMemberships = await this.orgMembershipRepository.find({
37
81
  where: {
38
- emailAddress: createDto.emailAddress,
82
+ user: {
83
+ email: createDto.emailAddress,
84
+ },
39
85
  organisation: {
40
86
  id: createDto.organisationId,
41
87
  },
42
- // and it's not expired
43
- expiresOn: (0, typeorm_2.MoreThan)(new Date()),
88
+ },
89
+ relations: {
90
+ invitation: true,
91
+ roles: true,
44
92
  },
45
93
  });
46
- if (existingInvitations) {
47
- throw new Error("An valid invitation already exists for this email address for this organisation");
94
+ if (existingMemberships.some((m) => m.roles.some((r) => r.name === RolesEnum_1.Roles.member || r.name === RolesEnum_1.Roles.owner))) {
95
+ const message = "A user with this email address is already a member of this organisation";
96
+ this.logger.error(message, { createDto, createdBy });
97
+ throw new Error(message);
48
98
  }
49
- // otherwise, create a new invitation
99
+ if (existingMemberships.some((m) => m.invitation &&
100
+ m.invitation.acceptedOn === null &&
101
+ m.invitation.expiresOn > new Date())) {
102
+ const message = "An valid invitation with this email already exists for this organisation";
103
+ this.logger.error(message, { createDto, createdBy });
104
+ throw new Error(message);
105
+ }
106
+ // new empty user
107
+ const user = new user_internal_1.User();
108
+ user.email = createDto.emailAddress;
109
+ const savedUser = await this.userRepository.save(user);
110
+ // new role
111
+ const role = new member_role_entity_1.MembershipRole();
112
+ role.name = RolesEnum_1.Roles.invited;
113
+ // a new invitation
50
114
  const unsavedInvitation = new invitation_entity_1.Invitation();
51
115
  unsavedInvitation.emailAddress = createDto.emailAddress;
52
116
  unsavedInvitation.expiresOn = new Date();
53
117
  unsavedInvitation.expiresOn.setDate(unsavedInvitation.expiresOn.getDate() + 1);
54
- unsavedInvitation.organisation =
55
- await this.organisationRepository.findOneOrFail({
56
- where: { id: createDto.organisationId },
57
- });
58
118
  unsavedInvitation.givenName = createDto.givenName;
59
- const savedInvitation = await this.invitationRepository.save(unsavedInvitation);
119
+ // create a new membership
120
+ const membership = this.orgMembershipRepository.create();
121
+ membership.organisationId = createDto.organisationId;
122
+ membership.userId = savedUser.id;
123
+ membership.invitation = unsavedInvitation;
124
+ membership.roles = [role];
125
+ const savedMembership = await this.orgMembershipRepository.save(membership);
126
+ const retrievedMembership = await this.orgMembershipRepository.findOne({
127
+ where: { id: savedMembership.id },
128
+ relations: {
129
+ invitation: true,
130
+ organisation: true,
131
+ },
132
+ });
133
+ if (!retrievedMembership || !retrievedMembership.invitation) {
134
+ this.logger.error("Newly saved membership not found", {
135
+ createDto,
136
+ createdBy,
137
+ createdMembershipId: savedMembership?.id,
138
+ });
139
+ throw new Error("Newly saved membership not found");
140
+ }
60
141
  // try to email the invitation
61
- await this.emailClient.sendMail([unsavedInvitation.emailAddress], [], `Invitation to join ${unsavedInvitation.organisation.name}`, createdBy.uuid, `You have been invited to join ${unsavedInvitation.organisation.name} by ${createdBy.givenName || "another "} ${createdBy.familyName || "member"}. Please click the link below to accept the invitation.
142
+ await this.emailClient.sendMail([unsavedInvitation.emailAddress], [], `Invitation to join ${retrievedMembership.organisation.name}`, createdBy.uuid, `You have been invited to join ${retrievedMembership.organisation.name} by ${createdBy.givenName || "another member"}. Please click the link below to accept the invitation.
62
143
 
63
- ${this.configService.baseUrl}/accept-invitation/${savedInvitation.uuid}`);
64
- // if it gets to here we have a sent invitation
65
- savedInvitation.notificationSent = new Date();
66
- return this.invitationRepository.save(savedInvitation);
144
+ ${this.configService.baseUrl}/accept-invitation/${retrievedMembership.invitation.uuid}`);
145
+ // if it gets to here we have a queued invitation
146
+ retrievedMembership.invitation.notificationSent = new Date();
147
+ return this.invitationRepository.save(retrievedMembership.invitation);
148
+ }
149
+ async canManageInvitationsForThisOrg(orgId, userId) {
150
+ const requesterMembership = await this.orgMembershipRepository.findOneOrFail({
151
+ where: {
152
+ organisation: {
153
+ id: orgId,
154
+ },
155
+ user: {
156
+ id: userId,
157
+ },
158
+ },
159
+ relations: {
160
+ roles: true,
161
+ },
162
+ });
163
+ if (requesterMembership.roles.some((role) => role.name === RolesEnum_1.Roles.owner)) {
164
+ throw new Error("You must be an admin to invite users to an organisation");
165
+ }
67
166
  }
68
167
  async remove(uuid, currentUserId) {
69
168
  const invitation = await this.invitationRepository.findOneOrFail({
70
169
  where: {
71
170
  uuid,
72
- organisation: {
73
- memberships: {
74
- user: {
75
- id: currentUserId,
76
- },
77
- roles: {
78
- name: RolesEnum_1.Roles.owner,
79
- },
80
- },
81
- },
171
+ },
172
+ relations: {
173
+ organisationMembership: { organisation: true },
82
174
  },
83
175
  });
176
+ if (!invitation) {
177
+ throw new common_1.NotFoundException();
178
+ }
179
+ await this.canManageInvitationsForThisOrg(invitation.organisationMembership.organisation.id, currentUserId);
84
180
  return this.invitationRepository.remove(invitation);
85
181
  }
86
182
  };
87
- InvitationService = __decorate([
183
+ InvitationService = InvitationService_1 = __decorate([
88
184
  (0, common_1.Injectable)(),
89
185
  __param(0, (0, typeorm_1.InjectRepository)(invitation_entity_1.Invitation)),
90
- __param(1, (0, typeorm_1.InjectRepository)(organisation_entity_1.Organisation)),
186
+ __param(1, (0, typeorm_1.InjectRepository)(organisation_membership_entity_1.OrganisationMembership)),
187
+ __param(2, (0, typeorm_1.InjectRepository)(user_internal_1.User)),
91
188
  __metadata("design:paramtypes", [typeorm_2.Repository,
189
+ typeorm_2.Repository,
92
190
  typeorm_2.Repository,
93
191
  email_client_service_1.SmtpEmailClient,
94
192
  InvitationConfigurationService_1.InvitationsConfigurationService])
@@ -1 +1 @@
1
- {"version":3,"file":"invitation.service.js","sourceRoot":"","sources":["../../src/invitations/invitation.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA0C;AAC1C,6CAAiD;AACjD,qCAA6C;AAC7C,6DAAoD;AAEpD,oEAAwD;AACxD,oFAA0E;AAC1E,sFAA0E;AAC1E,qFAAiF;AAI1E,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAGd;IAEA;IACS;IACA;IANrB,YAEY,oBAA4C,EAE5C,sBAAgD,EACvC,WAA4B,EAC5B,aAA8C;QAJvD,yBAAoB,GAApB,oBAAoB,CAAwB;QAE5C,2BAAsB,GAAtB,sBAAsB,CAA0B;QACvC,gBAAW,GAAX,WAAW,CAAiB;QAC5B,kBAAa,GAAb,aAAa,CAAiC;IAChE,CAAC;IAEJ,KAAK,CAAC,MAAM,CACR,SAA8B,EAC9B,SAAsB;QAEtB,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC;YAC7D,KAAK,EAAE;gBACH,YAAY,EAAE,SAAS,CAAC,YAAY;gBACpC,YAAY,EAAE;oBACV,EAAE,EAAE,SAAS,CAAC,cAAc;iBAC/B;gBACD,uBAAuB;gBACvB,SAAS,EAAE,IAAA,kBAAQ,EAAC,IAAI,IAAI,EAAE,CAAC;aAClC;SACJ,CAAC,CAAC;QAEH,IAAI,mBAAmB,EAAE;YACrB,MAAM,IAAI,KAAK,CACX,iFAAiF,CACpF,CAAC;SACL;QAED,qCAAqC;QACrC,MAAM,iBAAiB,GAAG,IAAI,8BAAU,EAAE,CAAC;QAC3C,iBAAiB,CAAC,YAAY,GAAG,SAAS,CAAC,YAAY,CAAC;QACxD,iBAAiB,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QACzC,iBAAiB,CAAC,SAAS,CAAC,OAAO,CAC/B,iBAAiB,CAAC,SAAS,CAAC,OAAO,EAAE,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aAAa,CAAC;YAC7D,KAAK,EAAE;gBACH,IAAI;aACP;YACD,SAAS,EAAE;gBACP,sBAAsB,EAAE,EAAC,YAAY,EAAE,IAAI,EAAC;aAC/C;SACJ,CAAC,CAAC;QAEH,IAAI,CAAC,UAAU,EAAE;YACb,MAAM,IAAI,0BAAiB,EAAE,CAAC;SACjC;QACD,MAAM,IAAI,CAAC,8BAA8B,CACrC,UAAU,CAAC,sBAAsB,CAAC,YAAY,CAAC,EAAE,EACjD,aAAa,CAChB,CAAC;QACF,OAAO,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;CACJ,CAAA;AAlOY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAIJ,WAAA,IAAA,0BAAgB,EAAC,8BAAU,CAAC,CAAA;IAE5B,WAAA,IAAA,0BAAgB,EAAC,uDAAsB,CAAC,CAAA;IAExC,WAAA,IAAA,0BAAgB,EAAC,oBAAI,CAAC,CAAA;qCAHO,oBAAU;QAEP,oBAAU;QAEnB,oBAAU;QACJ,sCAAe;QACb,gEAA+B;GAV1D,iBAAiB,CAkO7B;AAlOY,8CAAiB"}
@@ -1,3 +1,4 @@
1
+ import { Invitation } from "../../invitations";
1
2
  import { MembershipRole } from "../../organisation/entities/member-role.entity";
2
3
  import { Organisation } from "../../organisation/entities/organisation.entity";
3
4
  import { User } from "../../user-internal/entities/user.entity";
@@ -7,6 +8,7 @@ export declare class OrganisationMembership {
7
8
  user: User;
8
9
  userId: number;
9
10
  organisation: Organisation;
11
+ invitation?: Invitation;
10
12
  organisationId: number;
11
13
  roles: MembershipRole[];
12
14
  createdDate: Date;
@@ -13,6 +13,7 @@ exports.OrganisationMembership = void 0;
13
13
  const swagger_1 = require("@nestjs/swagger");
14
14
  const class_transformer_1 = require("class-transformer");
15
15
  const typeorm_1 = require("typeorm");
16
+ const invitations_1 = require("../../invitations");
16
17
  const member_role_entity_1 = require("../../organisation/entities/member-role.entity");
17
18
  const organisation_entity_1 = require("../../organisation/entities/organisation.entity");
18
19
  const user_entity_1 = require("../../user-internal/entities/user.entity");
@@ -22,6 +23,7 @@ let OrganisationMembership = class OrganisationMembership {
22
23
  user;
23
24
  userId;
24
25
  organisation;
26
+ invitation;
25
27
  organisationId;
26
28
  roles;
27
29
  createdDate;
@@ -69,6 +71,15 @@ __decorate([
69
71
  }),
70
72
  __metadata("design:type", organisation_entity_1.Organisation)
71
73
  ], OrganisationMembership.prototype, "organisation", void 0);
74
+ __decorate([
75
+ (0, typeorm_1.OneToOne)(() => invitations_1.Invitation, (inv) => inv.organisationMembership, {
76
+ eager: true,
77
+ nullable: true,
78
+ cascade: ["insert", "update"],
79
+ }),
80
+ (0, typeorm_1.JoinColumn)(),
81
+ __metadata("design:type", invitations_1.Invitation)
82
+ ], OrganisationMembership.prototype, "invitation", void 0);
72
83
  __decorate([
73
84
  (0, typeorm_1.Column)(),
74
85
  (0, swagger_1.ApiProperty)(),
@@ -1 +1 @@
1
- {"version":3,"file":"organisation-membership.entity.js","sourceRoot":"","sources":["../../../src/organisation-memberships/entities/organisation-membership.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA4C;AAC5C,yDAAuC;AAEvC,qCAeiB;AACjB,uFAA8E;AAC9E,yFAA6E;AAC7E,0EAA8D;AAGvD,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAG/B,EAAE,CAAU;IASL,IAAI,CAAU;IAMrB,IAAI,CAAQ;IAKL,MAAM,CAAU;IAMvB,YAAY,CAAgB;IAKrB,cAAc,CAAU;IAS/B,KAAK,CAAoB;IAIzB,WAAW,CAAQ;IAInB,UAAU,CAAQ;IAIlB,WAAW,CAAQ;IAEnB,4DAA4D;IAItD,AAAN,KAAK,CAAC,UAAU;QACZ,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACb,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;SACnB;IACL,CAAC;CACJ,CAAA;AAjEG;IAAC,IAAA,gCAAsB,GAA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xD,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,IAAI;KAChB,CAAC;IACD,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,mCAAc,CAAC;;qDACF;AAEzB;IAAC,IAAA,0BAAgB,GAAE;IAClB,IAAA,qBAAW,GAAE;8BACA,IAAI;2DAAC;AAEnB;IAAC,IAAA,0BAAgB,GAAE;IAClB,IAAA,qBAAW,GAAE;8BACD,IAAI;0DAAC;AAElB;IAAC,IAAA,0BAAgB,GAAE;IAClB,IAAA,qBAAW,GAAE;8BACA,IAAI;2DAAC;AAMb;IAHL,IAAA,mBAAS,GAAE;IACX,IAAA,qBAAW,GAAE;IACb,IAAA,qBAAW,GAAE;;;;wDAKb;AAjEQ,sBAAsB;IADlC,IAAA,gBAAM,GAAE;GACI,sBAAsB,CAkElC;AAlEY,wDAAsB"}
1
+ {"version":3,"file":"organisation-membership.entity.js","sourceRoot":"","sources":["../../../src/organisation-memberships/entities/organisation-membership.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA4C;AAC5C,yDAAuC;AAEvC,qCAiBiB;AACjB,mDAA6C;AAC7C,uFAA8E;AAC9E,yFAA6E;AAC7E,0EAA8D;AAGvD,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAG/B,EAAE,CAAU;IASL,IAAI,CAAU;IAMrB,IAAI,CAAQ;IAKL,MAAM,CAAU;IAMvB,YAAY,CAAgB;IAQ5B,UAAU,CAAc;IAKjB,cAAc,CAAU;IAS/B,KAAK,CAAoB;IAIzB,WAAW,CAAQ;IAInB,UAAU,CAAQ;IAIlB,WAAW,CAAQ;IAEnB,4DAA4D;IAItD,AAAN,KAAK,CAAC,UAAU;QACZ,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACb,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;SACnB;IACL,CAAC;CACJ,CAAA;AAzEG;IAAC,IAAA,gCAAsB,GAAE;IACxB,IAAA,qBAAW,GAAE;;kDACF;AAEZ;I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AC,IAAA,qBAAW,EAAC,EAAC,IAAI,EAAE,GAAG,EAAE,CAAC,mCAAc,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;IACzD,+DAA+D;;IAC9D,IAAA,mBAAS,EAAC,GAAG,EAAE,CAAC,mCAAc,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE;QACxD,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,IAAI;KAChB,CAAC;IACD,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,mCAAc,CAAC;;qDACF;AAEzB;IAAC,IAAA,0BAAgB,GAAE;IAClB,IAAA,qBAAW,GAAE;8BACA,IAAI;2DAAC;AAEnB;IAAC,IAAA,0BAAgB,GAAE;IAClB,IAAA,qBAAW,GAAE;8BACD,IAAI;0DAAC;AAElB;IAAC,IAAA,0BAAgB,GAAE;IAClB,IAAA,qBAAW,GAAE;8BACA,IAAI;2DAAC;AAMb;IAHL,IAAA,mBAAS,GAAE;IACX,IAAA,qBAAW,GAAE;IACb,IAAA,qBAAW,GAAE;;;;wDAKb;AAzEQ,sBAAsB;IADlC,IAAA,gBAAM,GAAE;GACI,sBAAsB,CA0ElC;AA1EY,wDAAsB"}
@@ -0,0 +1,3 @@
1
+ export default class CreateApiKeyDto {
2
+ description: string;
3
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const swagger_1 = require("@nestjs/swagger");
13
+ const class_validator_1 = require("class-validator");
14
+ class CreateApiKeyDto {
15
+ description;
16
+ }
17
+ __decorate([
18
+ (0, class_validator_1.IsString)(),
19
+ (0, class_validator_1.IsNotEmpty)(),
20
+ (0, swagger_1.ApiProperty)(),
21
+ __metadata("design:type", String)
22
+ ], CreateApiKeyDto.prototype, "description", void 0);
23
+ exports.default = CreateApiKeyDto;
24
+ //# sourceMappingURL=CreateApiKeyDto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateApiKeyDto.js","sourceRoot":"","sources":["../../src/user-api-key/CreateApiKeyDto.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6CAA4C;AAC5C,qDAAqD;AAErD,MAAqB,eAAe;IAIhC,WAAW,CAAU;CACxB;AAJG;IAAC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;IACZ,IAAA,qBAAW,GAAE;;oDACO;AAJzB,kCAKC"}
@@ -0,0 +1,3 @@
1
+ export { UserApiKeyService } from "./user-apikey.service";
2
+ export { UserApiKeyController } from "./user-apikey.controller";
3
+ export { UserApiKeyModule } from "./user-apikey.module";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserApiKeyModule = exports.UserApiKeyController = exports.UserApiKeyService = void 0;
4
+ var user_apikey_service_1 = require("./user-apikey.service");
5
+ Object.defineProperty(exports, "UserApiKeyService", { enumerable: true, get: function () { return user_apikey_service_1.UserApiKeyService; } });
6
+ var user_apikey_controller_1 = require("./user-apikey.controller");
7
+ Object.defineProperty(exports, "UserApiKeyController", { enumerable: true, get: function () { return user_apikey_controller_1.UserApiKeyController; } });
8
+ var user_apikey_module_1 = require("./user-apikey.module");
9
+ Object.defineProperty(exports, "UserApiKeyModule", { enumerable: true, get: function () { return user_apikey_module_1.UserApiKeyModule; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/user-api-key/index.ts"],"names":[],"mappings":";;;AAAA,6DAAwD;AAAhD,wHAAA,iBAAiB,OAAA;AACzB,mEAA8D;AAAtD,8HAAA,oBAAoB,OAAA;AAC5B,2DAAsD;AAA9C,sHAAA,gBAAgB,OAAA"}
@@ -0,0 +1,13 @@
1
+ import { RequestWithUser } from "../authz/RequestWithUser";
2
+ import { BooleanResult } from "../root-app/models/boolean-result";
3
+ import { UserApiKey } from "./userApiKey.entity";
4
+ import { UserApiKeyService } from "./user-apikey.service";
5
+ import CreateApiKeyDto from "./CreateApiKeyDto";
6
+ export declare class UserApiKeyController {
7
+ private readonly apiKeyService;
8
+ constructor(apiKeyService: UserApiKeyService);
9
+ getAllForUser(request: RequestWithUser): Promise<UserApiKey[]>;
10
+ generateNewKey(uuid: string, request: RequestWithUser): Promise<UserApiKey>;
11
+ update(createKeyDto: CreateApiKeyDto, request: RequestWithUser): Promise<UserApiKey>;
12
+ remove(uuid: string, request: RequestWithUser): Promise<BooleanResult>;
13
+ }
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.UserApiKeyController = void 0;
19
+ const common_1 = require("@nestjs/common");
20
+ const swagger_1 = require("@nestjs/swagger");
21
+ const boolean_result_1 = require("../root-app/models/boolean-result");
22
+ const authz_1 = require("../authz");
23
+ const userApiKey_entity_1 = require("./userApiKey.entity");
24
+ const user_apikey_service_1 = require("./user-apikey.service");
25
+ const CreateApiKeyDto_1 = __importDefault(require("./CreateApiKeyDto"));
26
+ let UserApiKeyController = class UserApiKeyController {
27
+ apiKeyService;
28
+ constructor(apiKeyService) {
29
+ this.apiKeyService = apiKeyService;
30
+ }
31
+ async getAllForUser(request) {
32
+ return this.apiKeyService.getAllForUser(request.user.uuid);
33
+ }
34
+ async generateNewKey(uuid, request) {
35
+ return await this.apiKeyService.refreshKeyValue(uuid, request.user.uuid);
36
+ }
37
+ async update(createKeyDto, request) {
38
+ return await this.apiKeyService.createKey(request.user.id, createKeyDto.description);
39
+ }
40
+ async remove(uuid, request) {
41
+ const isDeleted = await this.apiKeyService.remove(uuid, request.user.uuid);
42
+ return { result: isDeleted };
43
+ }
44
+ };
45
+ __decorate([
46
+ (0, common_1.Get)(),
47
+ (0, swagger_1.ApiOkResponse)({ type: userApiKey_entity_1.UserApiKey, isArray: true }),
48
+ __param(0, (0, common_1.Request)()),
49
+ __metadata("design:type", Function),
50
+ __metadata("design:paramtypes", [Object]),
51
+ __metadata("design:returntype", Promise)
52
+ ], UserApiKeyController.prototype, "getAllForUser", null);
53
+ __decorate([
54
+ (0, common_1.Put)(":uuid"),
55
+ (0, swagger_1.ApiOkResponse)({ type: userApiKey_entity_1.UserApiKey }),
56
+ __param(0, (0, common_1.Param)("uuid")),
57
+ __param(1, (0, common_1.Request)()),
58
+ __metadata("design:type", Function),
59
+ __metadata("design:paramtypes", [String, Object]),
60
+ __metadata("design:returntype", Promise)
61
+ ], UserApiKeyController.prototype, "generateNewKey", null);
62
+ __decorate([
63
+ (0, common_1.Post)(),
64
+ (0, swagger_1.ApiOkResponse)({ type: userApiKey_entity_1.UserApiKey }),
65
+ __param(0, (0, common_1.Body)()),
66
+ __param(1, (0, common_1.Request)()),
67
+ __metadata("design:type", Function),
68
+ __metadata("design:paramtypes", [CreateApiKeyDto_1.default, Object]),
69
+ __metadata("design:returntype", Promise)
70
+ ], UserApiKeyController.prototype, "update", null);
71
+ __decorate([
72
+ (0, common_1.Delete)(":uuid"),
73
+ (0, swagger_1.ApiOkResponse)({ type: boolean_result_1.BooleanResult }),
74
+ __param(0, (0, common_1.Param)("uuid")),
75
+ __param(1, (0, common_1.Request)()),
76
+ __metadata("design:type", Function),
77
+ __metadata("design:paramtypes", [String, Object]),
78
+ __metadata("design:returntype", Promise)
79
+ ], UserApiKeyController.prototype, "remove", null);
80
+ UserApiKeyController = __decorate([
81
+ (0, common_1.UseGuards)(authz_1.DefaultAuthGuard, authz_1.ClaimsAuthorisationGuard),
82
+ (0, swagger_1.ApiBearerAuth)(),
83
+ (0, common_1.Controller)("api-key"),
84
+ (0, swagger_1.ApiTags)("Users"),
85
+ __metadata("design:paramtypes", [user_apikey_service_1.UserApiKeyService])
86
+ ], UserApiKeyController);
87
+ exports.UserApiKeyController = UserApiKeyController;
88
+ //# sourceMappingURL=user-apikey.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-apikey.controller.js","sourceRoot":"","sources":["../../src/user-api-key/user-apikey.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAUwB;AACxB,6CAAsE;AAEtE,sEAAgE;AAChE,oCAAoE;AACpE,2DAA+C;AAC/C,+DAAwD;AACxD,wEAAgD;AAMzC,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IACA;IAA7B,YAA6B,aAAgC;QAAhC,kBAAa,GAAb,aAAa,CAAmB;IAAG,CAAC;IAI3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AA,aAAI,GAAE,CAAA;IACN,WAAA,IAAA,gBAAO,GAAE,CAAA;;qCADY,yBAAe;;kDAOxC;AAIK;IAFL,IAAA,eAAM,EAAC,OAAO,CAAC;IACf,IAAA,uBAAa,EAAC,EAAC,IAAI,EAAE,8BAAa,EAAC,CAAC;IAEhC,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;IACb,WAAA,IAAA,gBAAO,GAAE,CAAA;;;;kDAOb;AA9CQ,oBAAoB;IAJhC,IAAA,kBAAS,EAAC,wBAAgB,EAAE,gCAAwB,CAAC;IACrD,IAAA,uBAAa,GAAE;IACf,IAAA,mBAAU,EAAC,SAAS,CAAC;IACrB,IAAA,iBAAO,EAAC,OAAO,CAAC;qCAE+B,uCAAiB;GADpD,oBAAoB,CA+ChC;AA/CY,oDAAoB"}
@@ -0,0 +1,2 @@
1
+ export declare class UserApiKeyModule {
2
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.UserApiKeyModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const user_internal_module_1 = require("../user-internal/user-internal.module");
12
+ const user_apikey_service_1 = require("./user-apikey.service");
13
+ const user_apikey_controller_1 = require("./user-apikey.controller");
14
+ const typeorm_1 = require("@nestjs/typeorm");
15
+ const userApiKey_entity_1 = require("./userApiKey.entity");
16
+ let UserApiKeyModule = class UserApiKeyModule {
17
+ };
18
+ UserApiKeyModule = __decorate([
19
+ (0, common_1.Module)({
20
+ imports: [typeorm_1.TypeOrmModule.forFeature([userApiKey_entity_1.UserApiKey]), user_internal_module_1.UserInternalModule],
21
+ controllers: [user_apikey_controller_1.UserApiKeyController],
22
+ providers: [user_apikey_service_1.UserApiKeyService],
23
+ exports: [],
24
+ })
25
+ ], UserApiKeyModule);
26
+ exports.UserApiKeyModule = UserApiKeyModule;
27
+ //# sourceMappingURL=user-apikey.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-apikey.module.js","sourceRoot":"","sources":["../../src/user-api-key/user-apikey.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAsC;AACtC,gFAAyE;AACzE,+DAAwD;AACxD,qEAA8D;AAC9D,6CAA8C;AAC9C,2DAA+C;AAQxC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAG,CAAA;AAAnB,gBAAgB;IAN5B,IAAA,eAAM,EAAC;QACJ,OAAO,EAAE,CAAC,uBAAa,CAAC,UAAU,CAAC,CAAC,8BAAU,CAAC,CAAC,EAAE,yCAAkB,CAAC;QACrE,WAAW,EAAE,CAAC,6CAAoB,CAAC;QACnC,SAAS,EAAE,CAAC,uCAAiB,CAAC;QAC9B,OAAO,EAAE,EAAE;KACd,CAAC;GACW,gBAAgB,CAAG;AAAnB,4CAAgB"}
@@ -0,0 +1,17 @@
1
+ import { Repository } from "typeorm";
2
+ import { UserApiKey } from "./userApiKey.entity";
3
+ export declare class UserApiKeyService {
4
+ private repository;
5
+ constructor(repository: Repository<UserApiKey>);
6
+ getAllForUser(uuid: string): Promise<UserApiKey[]>;
7
+ findOneByKey(apiKey: string): Promise<UserApiKey>;
8
+ /**
9
+ * When working on keys with the api, use an id to find the key
10
+ * @param id
11
+ * @returns
12
+ */
13
+ findOneById(id: number): Promise<UserApiKey>;
14
+ refreshKeyValue(uuid: string, currentUserUuid: string): Promise<UserApiKey>;
15
+ createKey(currentUserId: number, description: string): Promise<UserApiKey>;
16
+ remove(uuid: string, currentUserUuid: string): Promise<boolean>;
17
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.UserApiKeyService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const typeorm_1 = require("@nestjs/typeorm");
18
+ const nanoid_1 = require("nanoid");
19
+ const typeorm_2 = require("typeorm");
20
+ const userApiKey_entity_1 = require("./userApiKey.entity");
21
+ let UserApiKeyService = class UserApiKeyService {
22
+ repository;
23
+ // private readonly logger = new Logger(UserApiKeyService.name);
24
+ constructor(repository) {
25
+ this.repository = repository;
26
+ }
27
+ async getAllForUser(uuid) {
28
+ return this.repository.find({
29
+ where: {
30
+ user: { uuid },
31
+ },
32
+ });
33
+ }
34
+ async findOneByKey(apiKey) {
35
+ return this.repository.findOneOrFail({
36
+ where: { apiKey },
37
+ relations: {
38
+ user: true,
39
+ },
40
+ });
41
+ }
42
+ /**
43
+ * When working on keys with the api, use an id to find the key
44
+ * @param id
45
+ * @returns
46
+ */
47
+ async findOneById(id) {
48
+ return this.repository.findOneOrFail({
49
+ where: { id },
50
+ relations: {
51
+ user: true,
52
+ },
53
+ });
54
+ }
55
+ async refreshKeyValue(uuid, currentUserUuid) {
56
+ const userApiKey = await this.repository.findOneBy({
57
+ uuid,
58
+ user: { uuid: currentUserUuid },
59
+ });
60
+ if (!userApiKey) {
61
+ throw new common_1.NotFoundException();
62
+ }
63
+ userApiKey.apiKey = "mKey_" + (0, nanoid_1.nanoid)();
64
+ return this.repository.save(userApiKey);
65
+ }
66
+ async createKey(currentUserId, description) {
67
+ const userApiKey = new userApiKey_entity_1.UserApiKey();
68
+ userApiKey.description = description;
69
+ userApiKey.userId = currentUserId;
70
+ userApiKey.apiKey = "mKey_" + (0, nanoid_1.nanoid)();
71
+ return this.repository.save(userApiKey);
72
+ }
73
+ async remove(uuid, currentUserUuid) {
74
+ const userApiKey = await this.repository.findOneBy({
75
+ uuid,
76
+ user: { uuid: currentUserUuid },
77
+ });
78
+ if (!userApiKey) {
79
+ throw new common_1.NotFoundException();
80
+ }
81
+ const result = await this.repository.remove(userApiKey);
82
+ return result.deletedDate !== undefined;
83
+ }
84
+ };
85
+ UserApiKeyService = __decorate([
86
+ (0, common_1.Injectable)(),
87
+ __param(0, (0, typeorm_1.InjectRepository)(userApiKey_entity_1.UserApiKey)),
88
+ __metadata("design:paramtypes", [typeorm_2.Repository])
89
+ ], UserApiKeyService);
90
+ exports.UserApiKeyService = UserApiKeyService;
91
+ //# sourceMappingURL=user-apikey.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-apikey.service.js","sourceRoot":"","sources":["../../src/user-api-key/user-apikey.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA6D;AAC7D,6CAAiD;AACjD,mCAA8B;AAC9B,qCAAmC;AACnC,2DAA+C;AAGxC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAId;IAHZ,gEAAgE;IAChE,YAEY,UAAkC;QAAlC,eAAU,GAAV,UAAU,CAAwB;IAC3C,CAAC;IAEJ,KAAK,CAAC,aAAa,CAAC,IAAY;QAC5B,OAAO,IAAI,CAAC,UAAU,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CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,eAAuB;QAC9C,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;YAC/C,IAAI;YACJ,IAAI,EAAE,EAAC,IAAI,EAAE,eAAe,EAAC;SAChC,CAAC,CAAC;QACH,IAAI,CAAC,UAAU,EAAE;YACb,MAAM,IAAI,0BAAiB,EAAE,CAAC;SACjC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACxD,OAAO,MAAM,CAAC,WAAW,KAAK,SAAS,CAAC;IAC5C,CAAC;CACJ,CAAA;AA7EY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAIJ,WAAA,IAAA,0BAAgB,EAAC,8BAAU,CAAC,CAAA;qCACT,oBAAU;GAJzB,iBAAiB,CA6E7B;AA7EY,8CAAiB"}
@@ -0,0 +1,12 @@
1
+ import { User } from "../user-internal";
2
+ export declare class UserApiKey {
3
+ id: number;
4
+ uuid: string;
5
+ apiKey: string;
6
+ description: string;
7
+ user: User;
8
+ userId: number;
9
+ createdDate: Date;
10
+ updateDate: Date;
11
+ deletedDate: Date;
12
+ }