@punks/backend-entity-manager 0.0.93 → 0.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +940 -929
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/import.d.ts +5 -2
- package/dist/cjs/types/converters/files.d.ts +7 -0
- package/dist/cjs/types/converters/index.d.ts +1 -0
- package/dist/cjs/types/index.d.ts +2 -0
- package/dist/esm/index.js +939 -930
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/import.d.ts +5 -2
- package/dist/esm/types/converters/files.d.ts +7 -0
- package/dist/esm/types/converters/index.d.ts +1 -0
- package/dist/esm/types/index.d.ts +2 -0
- package/dist/index.d.ts +15 -3
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -277,941 +277,550 @@ class EntitySerializer {
|
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
class NestEntityAuthorizationMiddleware {
|
|
280
|
+
class EntitiesCountAction {
|
|
281
|
+
constructor(services) {
|
|
282
|
+
this.services = services;
|
|
283
|
+
}
|
|
284
|
+
async execute(filters) {
|
|
285
|
+
return await this.services.resolveCountQuery().execute(filters);
|
|
286
|
+
}
|
|
288
287
|
}
|
|
289
288
|
|
|
290
|
-
class
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
this.
|
|
289
|
+
class EntityCreateAction {
|
|
290
|
+
constructor(services) {
|
|
291
|
+
this.services = services;
|
|
292
|
+
this.logger = Log.getLogger(`${services.getEntityName()} -> Create`);
|
|
294
293
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
294
|
+
async execute(input) {
|
|
295
|
+
this.logger.debug("Create action started", { input });
|
|
296
|
+
const converter = this.services.resolveConverter();
|
|
297
|
+
const createInput = converter?.createDtoToEntity(input) ?? input;
|
|
298
|
+
const entity = await this.services
|
|
299
|
+
.resolveCreateCommand()
|
|
300
|
+
.execute(createInput);
|
|
301
|
+
const result = converter?.toEntityDto(entity) ?? entity;
|
|
302
|
+
this.logger.debug("Create action completed", { input, result });
|
|
303
|
+
return result;
|
|
301
304
|
}
|
|
302
305
|
}
|
|
303
306
|
|
|
304
|
-
class
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
this.
|
|
307
|
+
class EntityDeleteAction {
|
|
308
|
+
constructor(services) {
|
|
309
|
+
this.services = services;
|
|
310
|
+
this.logger = Log.getLogger(`${services.getEntityName()} -> Delete`);
|
|
308
311
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
return this.managerInstance;
|
|
312
|
+
async execute(id) {
|
|
313
|
+
this.logger.debug("Delete action started", { id });
|
|
314
|
+
await this.services.resolveDeleteCommand().execute(id);
|
|
315
|
+
this.logger.debug("Delete action completed", { id });
|
|
315
316
|
}
|
|
316
317
|
}
|
|
317
318
|
|
|
318
|
-
class
|
|
319
|
-
constructor(
|
|
320
|
-
|
|
321
|
-
|
|
319
|
+
class EntitiesDeleteAction {
|
|
320
|
+
constructor(services) {
|
|
321
|
+
this.services = services;
|
|
322
|
+
this.logger = Log.getLogger(`${services.getEntityName()} -> DeleteItems`);
|
|
323
|
+
}
|
|
324
|
+
async execute(params) {
|
|
325
|
+
this.logger.debug("DeleteItems action started");
|
|
326
|
+
await this.services.resolveDeleteItemsCommand().execute(params);
|
|
327
|
+
this.logger.debug("DeleteItems action completed");
|
|
322
328
|
}
|
|
323
329
|
}
|
|
324
330
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
EntityConnector: Symbol.for("WP:ENTITY_CONNECTOR"),
|
|
334
|
-
EntityConverter: Symbol.for("WP:ENTITY_CONVERTER"),
|
|
335
|
-
EntitySerializer: Symbol.for("WP:ENTITY_SERIALIZER"),
|
|
336
|
-
EntityManager: Symbol.for("WP:ENTITY_MANAGER"),
|
|
337
|
-
EntityQueryBuilder: Symbol.for("WP:ENTITY_QUERY_BUILDER"),
|
|
338
|
-
EntitySeeder: Symbol.for("WP:ENTITY_SEEDER"),
|
|
339
|
-
EmailProvider: Symbol.for("WP:EMAIL_PROVIDER"),
|
|
340
|
-
EmailTemplate: Symbol.for("WP:EMAIL_TEMPLATE"),
|
|
341
|
-
BucketProvider: Symbol.for("WP:BUCKET_PROVIDER"),
|
|
342
|
-
PipelineTemplate: Symbol.for("WP:PIPELINE_TEMPLATE"),
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
const WpEntityAuthMiddleware = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntityAuthMiddleware, {
|
|
346
|
-
entityName,
|
|
347
|
-
...props,
|
|
348
|
-
}));
|
|
349
|
-
|
|
350
|
-
const WpBucketProvider = (providerId) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.BucketProvider, {
|
|
351
|
-
providerId,
|
|
352
|
-
}));
|
|
353
|
-
|
|
354
|
-
const WpEntityActions = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntityActions, {
|
|
355
|
-
entityName,
|
|
356
|
-
...props,
|
|
357
|
-
}));
|
|
358
|
-
|
|
359
|
-
const WpEntityAdapter = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntityAdapter, {
|
|
360
|
-
entityName,
|
|
361
|
-
...props,
|
|
362
|
-
}));
|
|
363
|
-
|
|
364
|
-
const WpEntityConnector = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntityConnector, {
|
|
365
|
-
entityName,
|
|
366
|
-
...props,
|
|
367
|
-
}));
|
|
368
|
-
|
|
369
|
-
const WpEntityConverter = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntityConverter, {
|
|
370
|
-
entityName,
|
|
371
|
-
...props,
|
|
372
|
-
}));
|
|
331
|
+
class EntityExistsAction {
|
|
332
|
+
constructor(services) {
|
|
333
|
+
this.services = services;
|
|
334
|
+
}
|
|
335
|
+
async execute(filters) {
|
|
336
|
+
return await this.services.resolveExistsQuery().execute(filters);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
373
339
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
340
|
+
class EntitiesExportAction {
|
|
341
|
+
constructor(services) {
|
|
342
|
+
this.services = services;
|
|
343
|
+
this.logger = Log.getLogger(`${services.getEntityName()} -> Export`);
|
|
344
|
+
}
|
|
345
|
+
async execute(input) {
|
|
346
|
+
this.logger.debug("Export action started", { input });
|
|
347
|
+
const result = await this.services.resolveExportCommand().execute(input);
|
|
348
|
+
this.logger.debug("Export action completed", { input });
|
|
349
|
+
return result;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
380
352
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
353
|
+
class EntityGetAction {
|
|
354
|
+
constructor(services) {
|
|
355
|
+
this.services = services;
|
|
356
|
+
}
|
|
357
|
+
async execute(id) {
|
|
358
|
+
const entity = await this.services.resolveGetQuery().execute(id);
|
|
359
|
+
const converter = this.services.resolveConverter();
|
|
360
|
+
return entity
|
|
361
|
+
? converter?.toEntityDto(entity) ?? entity
|
|
362
|
+
: undefined;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
385
365
|
|
|
386
|
-
|
|
366
|
+
class EntitiesImportAction {
|
|
367
|
+
constructor(services) {
|
|
368
|
+
this.services = services;
|
|
369
|
+
this.logger = Log.getLogger(`${services.getEntityName()} -> Import`);
|
|
370
|
+
}
|
|
371
|
+
async execute(input) {
|
|
372
|
+
this.logger.debug("Import action started", { input });
|
|
373
|
+
const result = await this.services.resolveImportCommand().execute(input);
|
|
374
|
+
this.logger.debug("Import action completed", { input });
|
|
375
|
+
return result;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
387
378
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
})
|
|
379
|
+
class EntitiesSampleDownloadAction {
|
|
380
|
+
constructor(services) {
|
|
381
|
+
this.services = services;
|
|
382
|
+
this.logger = Log.getLogger(`${services.getEntityName()} -> Import`);
|
|
383
|
+
}
|
|
384
|
+
async execute(input) {
|
|
385
|
+
this.logger.debug("Sample download action started", { input });
|
|
386
|
+
const result = await this.services
|
|
387
|
+
.resolveSampleDownloadCommand()
|
|
388
|
+
.execute(input);
|
|
389
|
+
this.logger.debug("Sample download action completed", { input });
|
|
390
|
+
return result;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
392
393
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
394
|
+
class EntitiesSearchAction {
|
|
395
|
+
constructor(services) {
|
|
396
|
+
this.services = services;
|
|
397
|
+
}
|
|
398
|
+
async execute(request) {
|
|
399
|
+
const results = await this.services
|
|
400
|
+
.resolveSearchQuery()
|
|
401
|
+
.execute(request);
|
|
402
|
+
const converter = this.services.resolveConverter();
|
|
403
|
+
return {
|
|
404
|
+
facets: results.facets,
|
|
405
|
+
paging: results.paging,
|
|
406
|
+
request: results.request,
|
|
407
|
+
items: results.items.map((x) => (converter?.toListItemDto(x) ?? x)),
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
}
|
|
397
411
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
})
|
|
412
|
+
class EntityUpdateAction {
|
|
413
|
+
constructor(services) {
|
|
414
|
+
this.services = services;
|
|
415
|
+
this.logger = Log.getLogger(`${services.getEntityName()} -> Update`);
|
|
416
|
+
}
|
|
417
|
+
async execute(id, input) {
|
|
418
|
+
this.logger.debug("Update action started", { id, input });
|
|
419
|
+
const converter = this.services.resolveConverter();
|
|
420
|
+
const updateInput = converter?.updateDtoToEntity(input) ?? input;
|
|
421
|
+
const entity = await this.services
|
|
422
|
+
.resolveUpdateCommand()
|
|
423
|
+
.execute(id, updateInput);
|
|
424
|
+
const result = converter?.toEntityDto(entity) ?? entity;
|
|
425
|
+
this.logger.debug("Update action started", { id, input, result });
|
|
426
|
+
return result;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
402
429
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
})
|
|
430
|
+
class EntityUpsertAction {
|
|
431
|
+
constructor(services) {
|
|
432
|
+
this.services = services;
|
|
433
|
+
this.logger = Log.getLogger(`${services.getEntityName()} -> Upsert`);
|
|
434
|
+
}
|
|
435
|
+
async execute(id, input) {
|
|
436
|
+
this.logger.debug("Upsert action started", { id, input });
|
|
437
|
+
const converter = this.services.resolveConverter();
|
|
438
|
+
const updateInput = converter?.updateDtoToEntity(input) ?? input;
|
|
439
|
+
const entity = await this.services
|
|
440
|
+
.resolveUpsertCommand()
|
|
441
|
+
.execute(id, updateInput);
|
|
442
|
+
const result = converter?.toEntityDto(entity) ?? entity;
|
|
443
|
+
this.logger.debug("Upsert action started", { id, input, result });
|
|
444
|
+
return result;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
407
447
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}));
|
|
412
|
-
|
|
413
|
-
const WpEntitySerializer = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntitySerializer, {
|
|
414
|
-
entityName,
|
|
415
|
-
...props,
|
|
416
|
-
}));
|
|
417
|
-
|
|
418
|
-
const WpEventsTracker = (props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EventsTracker, {
|
|
419
|
-
...props,
|
|
420
|
-
}));
|
|
421
|
-
|
|
422
|
-
/******************************************************************************
|
|
423
|
-
Copyright (c) Microsoft Corporation.
|
|
424
|
-
|
|
425
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
426
|
-
purpose with or without fee is hereby granted.
|
|
427
|
-
|
|
428
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
429
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
430
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
431
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
432
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
433
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
434
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
435
|
-
***************************************************************************** */
|
|
436
|
-
|
|
437
|
-
function __decorate(decorators, target, key, desc) {
|
|
438
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
439
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
440
|
-
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;
|
|
441
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
function __metadata(metadataKey, metadataValue) {
|
|
445
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
449
|
-
var e = new Error(message);
|
|
450
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
class NumericFacetItem {
|
|
454
|
-
}
|
|
455
|
-
__decorate([
|
|
456
|
-
ApiProperty(),
|
|
457
|
-
__metadata("design:type", Number)
|
|
458
|
-
], NumericFacetItem.prototype, "value", void 0);
|
|
459
|
-
__decorate([
|
|
460
|
-
ApiProperty({ required: false }),
|
|
461
|
-
__metadata("design:type", String)
|
|
462
|
-
], NumericFacetItem.prototype, "name", void 0);
|
|
463
|
-
__decorate([
|
|
464
|
-
ApiProperty({ required: false }),
|
|
465
|
-
__metadata("design:type", Number)
|
|
466
|
-
], NumericFacetItem.prototype, "count", void 0);
|
|
467
|
-
class NumericFacet {
|
|
468
|
-
}
|
|
469
|
-
__decorate([
|
|
470
|
-
ApiProperty({ type: [NumericFacetItem] }),
|
|
471
|
-
__metadata("design:type", Array)
|
|
472
|
-
], NumericFacet.prototype, "items", void 0);
|
|
473
|
-
class BooleanFacetItem {
|
|
474
|
-
}
|
|
475
|
-
__decorate([
|
|
476
|
-
ApiProperty(),
|
|
477
|
-
__metadata("design:type", Boolean)
|
|
478
|
-
], BooleanFacetItem.prototype, "value", void 0);
|
|
479
|
-
__decorate([
|
|
480
|
-
ApiProperty({ required: false }),
|
|
481
|
-
__metadata("design:type", String)
|
|
482
|
-
], BooleanFacetItem.prototype, "name", void 0);
|
|
483
|
-
__decorate([
|
|
484
|
-
ApiProperty({ required: false }),
|
|
485
|
-
__metadata("design:type", Number)
|
|
486
|
-
], BooleanFacetItem.prototype, "count", void 0);
|
|
487
|
-
class BooleanFacet {
|
|
488
|
-
}
|
|
489
|
-
__decorate([
|
|
490
|
-
ApiProperty({ type: [BooleanFacetItem] }),
|
|
491
|
-
__metadata("design:type", Array)
|
|
492
|
-
], BooleanFacet.prototype, "items", void 0);
|
|
493
|
-
class StringFacetItem {
|
|
494
|
-
}
|
|
495
|
-
__decorate([
|
|
496
|
-
ApiProperty(),
|
|
497
|
-
__metadata("design:type", String)
|
|
498
|
-
], StringFacetItem.prototype, "value", void 0);
|
|
499
|
-
__decorate([
|
|
500
|
-
ApiProperty({ required: false }),
|
|
501
|
-
__metadata("design:type", String)
|
|
502
|
-
], StringFacetItem.prototype, "name", void 0);
|
|
503
|
-
__decorate([
|
|
504
|
-
ApiProperty({ required: false }),
|
|
505
|
-
__metadata("design:type", Number)
|
|
506
|
-
], StringFacetItem.prototype, "count", void 0);
|
|
507
|
-
class StringFacet {
|
|
508
|
-
}
|
|
509
|
-
__decorate([
|
|
510
|
-
ApiProperty({ type: [StringFacetItem] }),
|
|
511
|
-
__metadata("design:type", Array)
|
|
512
|
-
], StringFacet.prototype, "items", void 0);
|
|
513
|
-
|
|
514
|
-
const AuthenticationExtensionSymbols = {
|
|
515
|
-
UserService: Symbol.for("WP.EXT:AUTHENTICATION.USER_SERVICE"),
|
|
516
|
-
RolesService: Symbol.for("WP.EXT:AUTHENTICATION.ROLES_SERVICE"),
|
|
517
|
-
UserRolesService: Symbol.for("WP.EXT:AUTHENTICATION.USER_ROLES_SERVICE"),
|
|
518
|
-
};
|
|
519
|
-
const AuthenticationGuardsSymbols = {
|
|
520
|
-
Authenticated: "guard:authenticated",
|
|
521
|
-
Public: "guard:public",
|
|
522
|
-
Roles: "guard:roles",
|
|
523
|
-
MemberOf: "guard:memberOf",
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
const Public = () => SetMetadata(AuthenticationGuardsSymbols.Public, true);
|
|
527
|
-
const Authenticated = () => SetMetadata(AuthenticationGuardsSymbols.Authenticated, true);
|
|
528
|
-
const Roles = (...roles) => SetMetadata(AuthenticationGuardsSymbols.Roles, roles);
|
|
529
|
-
const MemberOf = (...groups) => SetMetadata(AuthenticationGuardsSymbols.MemberOf, groups);
|
|
530
|
-
const buildRolesGuard = ({ mainRole, inheritedRoles, }, options) => Roles(mainRole.uid, ...(options?.inheritRoles && inheritedRoles
|
|
531
|
-
? inheritedRoles.map((role) => role.uid)
|
|
532
|
-
: []));
|
|
533
|
-
|
|
534
|
-
const WpRolesService = () => applyDecorators(Injectable(), SetMetadata(AuthenticationExtensionSymbols.RolesService, true));
|
|
535
|
-
|
|
536
|
-
const WpUserService = () => applyDecorators(Injectable(), SetMetadata(AuthenticationExtensionSymbols.UserService, true));
|
|
537
|
-
|
|
538
|
-
const WpUserRolesService = () => applyDecorators(Injectable(), SetMetadata(AuthenticationExtensionSymbols.UserRolesService, true));
|
|
539
|
-
|
|
540
|
-
const AuthenticationEmailTemplates = {
|
|
541
|
-
Registration: "registration",
|
|
542
|
-
PasswordReset: "passwordReset",
|
|
543
|
-
EmailVerify: "emailVerify",
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
class AuthenticationError extends Error {
|
|
547
|
-
constructor(message) {
|
|
548
|
-
super(message);
|
|
549
|
-
this.name = "AuthenticationError";
|
|
448
|
+
class EntityCreateCommand {
|
|
449
|
+
constructor(services) {
|
|
450
|
+
this.services = services;
|
|
550
451
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
this.
|
|
452
|
+
async execute(input) {
|
|
453
|
+
var entity = this.adaptEntity(input);
|
|
454
|
+
await this.authorize(entity);
|
|
455
|
+
var createdItem = await this.services.resolveRepository().create(entity);
|
|
456
|
+
await this.services
|
|
457
|
+
.resolveEventsManager()
|
|
458
|
+
.processEntityCreatedEvent(createdItem);
|
|
459
|
+
return createdItem;
|
|
556
460
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
461
|
+
adaptEntity(input) {
|
|
462
|
+
const adapter = this.services.resolveAdapter();
|
|
463
|
+
return adapter
|
|
464
|
+
? adapter.createDataToEntity(input)
|
|
465
|
+
: input;
|
|
466
|
+
}
|
|
467
|
+
async authorize(entity) {
|
|
468
|
+
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
469
|
+
if (!authorization) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
473
|
+
const context = await contextService?.getContext();
|
|
474
|
+
if (!context) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const authorizationResult = await authorization.canCreate(entity, context);
|
|
478
|
+
if (!authorizationResult.isAuthorized)
|
|
479
|
+
throw new EntityOperationUnauthorizedException(EntityOperationType.Create, this.services.getEntityName(), entity);
|
|
562
480
|
}
|
|
563
481
|
}
|
|
564
482
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
UserRegistrationStarted: `${AUTHENTICATION_EVENTS_NAMESPACE}:user.registrationStarted`,
|
|
569
|
-
UserRegistrationCompleted: `${AUTHENTICATION_EVENTS_NAMESPACE}:user.registrationCompleted`,
|
|
570
|
-
UserPasswordResetStarted: `${AUTHENTICATION_EVENTS_NAMESPACE}:user.passwordResetStarted`,
|
|
571
|
-
UserPasswordResetCompleted: `${AUTHENTICATION_EVENTS_NAMESPACE}:user.passwordResetCompleted`,
|
|
572
|
-
};
|
|
573
|
-
|
|
574
|
-
let AuthGuard = class AuthGuard {
|
|
575
|
-
constructor(reflector) {
|
|
576
|
-
this.reflector = reflector;
|
|
483
|
+
class EntityDeleteCommand {
|
|
484
|
+
constructor(services) {
|
|
485
|
+
this.services = services;
|
|
577
486
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
return true;
|
|
487
|
+
async execute(id) {
|
|
488
|
+
if (isNullOrUndefined(id)) {
|
|
489
|
+
throw new MissingEntityIdError();
|
|
582
490
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
491
|
+
await this.authorize(id);
|
|
492
|
+
await this.services.resolveRepository().delete(id);
|
|
493
|
+
await this.services.resolveEventsManager().processEntityDeletedEvent(id);
|
|
494
|
+
}
|
|
495
|
+
async authorize(id) {
|
|
496
|
+
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
497
|
+
if (!authorization) {
|
|
498
|
+
return;
|
|
587
499
|
}
|
|
588
|
-
const
|
|
589
|
-
if (
|
|
590
|
-
|
|
500
|
+
const entity = await this.services.resolveRepository().get(id);
|
|
501
|
+
if (entity == null) {
|
|
502
|
+
throw new EntityNotFoundException(id);
|
|
591
503
|
}
|
|
592
|
-
|
|
504
|
+
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
505
|
+
const context = await contextService?.getContext();
|
|
506
|
+
if (!context) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
const authorizationResult = await authorization.canDelete(entity, context);
|
|
510
|
+
if (!authorizationResult.isAuthorized)
|
|
511
|
+
throw new EntityOperationUnauthorizedException(EntityOperationType.Delete, this.services.getEntityName(), entity);
|
|
593
512
|
}
|
|
594
|
-
|
|
595
|
-
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
class EntitiesDeleteCommand {
|
|
516
|
+
constructor(services) {
|
|
517
|
+
this.services = services;
|
|
596
518
|
}
|
|
597
|
-
|
|
598
|
-
|
|
519
|
+
async execute(params) {
|
|
520
|
+
await this.authorize();
|
|
521
|
+
const context = await this.getContext();
|
|
522
|
+
const deleteResult = await this.services
|
|
523
|
+
.resolveQueryBuilder()
|
|
524
|
+
.delete(params.filters, context);
|
|
525
|
+
// todo: add entities deleted event
|
|
526
|
+
return deleteResult;
|
|
599
527
|
}
|
|
600
|
-
|
|
601
|
-
|
|
528
|
+
async getContext() {
|
|
529
|
+
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
530
|
+
if (!authorization) {
|
|
531
|
+
return undefined;
|
|
532
|
+
}
|
|
533
|
+
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
534
|
+
return await contextService.getContext();
|
|
602
535
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
return this.reflector.getAllAndOverride(symbol, [
|
|
617
|
-
context.getHandler(),
|
|
618
|
-
context.getClass(),
|
|
619
|
-
]);
|
|
536
|
+
async authorize() {
|
|
537
|
+
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
538
|
+
if (!authorization) {
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
542
|
+
const context = await contextService?.getContext();
|
|
543
|
+
if (!context) {
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
const authorizationResult = await authorization.canDeleteItems(context);
|
|
547
|
+
if (!authorizationResult.isAuthorized)
|
|
548
|
+
throw new EntityOperationUnauthorizedException(EntityOperationType.Delete, this.services.getEntityName());
|
|
620
549
|
}
|
|
621
|
-
}
|
|
622
|
-
AuthGuard = __decorate([
|
|
623
|
-
Injectable(),
|
|
624
|
-
__metadata("design:paramtypes", [Reflector])
|
|
625
|
-
], AuthGuard);
|
|
626
|
-
|
|
627
|
-
var UserCreationError;
|
|
628
|
-
(function (UserCreationError) {
|
|
629
|
-
UserCreationError["UserAlreadyExists"] = "userAlreadyExists";
|
|
630
|
-
})(UserCreationError || (UserCreationError = {}));
|
|
631
|
-
|
|
632
|
-
const sessionStorage = new AsyncLocalStorage();
|
|
550
|
+
}
|
|
633
551
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
this.getSession().set(key, undefined);
|
|
552
|
+
const createDayPath = (d) => `${d.getFullYear()}/${(d.getMonth() + 1).toString().padStart(2, "0")}/${d
|
|
553
|
+
.getDate()
|
|
554
|
+
.toString()
|
|
555
|
+
.padStart(2, "0")}`;
|
|
556
|
+
class EntitiesExportCommand {
|
|
557
|
+
constructor(services, settings) {
|
|
558
|
+
this.services = services;
|
|
559
|
+
this.settings = settings;
|
|
643
560
|
}
|
|
644
|
-
|
|
645
|
-
|
|
561
|
+
async execute(input) {
|
|
562
|
+
const exportEntities = await this.getExportEntities(input.filter);
|
|
563
|
+
const outputFile = await this.buildExportFile(exportEntities.items, input.options.format);
|
|
564
|
+
const downloadUrl = await this.uploadExportFile(outputFile);
|
|
565
|
+
return {
|
|
566
|
+
downloadUrl,
|
|
567
|
+
file: {
|
|
568
|
+
content: outputFile.content,
|
|
569
|
+
contentType: outputFile.contentType,
|
|
570
|
+
name: outputFile.fileName,
|
|
571
|
+
},
|
|
572
|
+
};
|
|
646
573
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
if (!store) {
|
|
650
|
-
throw new Error("No active context found");
|
|
651
|
-
}
|
|
652
|
-
return store;
|
|
574
|
+
async buildExportFile(data, format) {
|
|
575
|
+
return await this.services.resolveSerializer().serialize(data, format);
|
|
653
576
|
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
return await
|
|
577
|
+
async uploadExportFile(file) {
|
|
578
|
+
await this.bucket.fileUpload({
|
|
579
|
+
bucket: this.settings.exportBucket.bucket,
|
|
580
|
+
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
581
|
+
content: file.content,
|
|
582
|
+
contentType: file.contentType,
|
|
583
|
+
});
|
|
584
|
+
return await this.bucket.filePublicUrlCreate({
|
|
585
|
+
bucket: this.settings.exportBucket.bucket,
|
|
586
|
+
expirationMinutes: this.settings.exportBucket.publicLinksExpirationMinutes,
|
|
587
|
+
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
588
|
+
});
|
|
662
589
|
}
|
|
663
|
-
|
|
664
|
-
return
|
|
590
|
+
buildAbsoluteBucketPath(relativePath) {
|
|
591
|
+
return `${this.settings.exportBucket.rootFolderPath ?? ""}/exports/${createDayPath(new Date())}/${relativePath}`;
|
|
665
592
|
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
Injectable()
|
|
669
|
-
], AppHashingService);
|
|
670
|
-
|
|
671
|
-
class EntitiesCountAction {
|
|
672
|
-
constructor(services) {
|
|
673
|
-
this.services = services;
|
|
593
|
+
async getExportEntities(filters) {
|
|
594
|
+
return this.services.resolveSearchQuery().execute(filters ?? {});
|
|
674
595
|
}
|
|
675
|
-
|
|
676
|
-
return
|
|
596
|
+
get bucket() {
|
|
597
|
+
return this.services.getRootServices().resolveBucketProvider();
|
|
677
598
|
}
|
|
678
599
|
}
|
|
679
600
|
|
|
680
|
-
class
|
|
681
|
-
constructor(services) {
|
|
601
|
+
class EntitiesImportCommand {
|
|
602
|
+
constructor(services, settings) {
|
|
682
603
|
this.services = services;
|
|
683
|
-
this.
|
|
604
|
+
this.settings = settings;
|
|
684
605
|
}
|
|
685
606
|
async execute(input) {
|
|
686
|
-
this.
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
607
|
+
await this.uploadImportFile({
|
|
608
|
+
content: input.file.content,
|
|
609
|
+
contentType: input.file.contentType,
|
|
610
|
+
fileName: input.file.fileName,
|
|
611
|
+
});
|
|
612
|
+
const importEntities = await this.parseImportFile(input.file.content, input.format);
|
|
613
|
+
for (const entry of importEntities) {
|
|
614
|
+
await this.importEntity(entry);
|
|
615
|
+
}
|
|
616
|
+
return {
|
|
617
|
+
statistics: {
|
|
618
|
+
importedCount: importEntities.length,
|
|
619
|
+
createdCount: 0,
|
|
620
|
+
unchangedCount: 0,
|
|
621
|
+
updatedCount: 0,
|
|
622
|
+
},
|
|
623
|
+
};
|
|
702
624
|
}
|
|
703
|
-
async
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
625
|
+
async importEntity(entry) {
|
|
626
|
+
try {
|
|
627
|
+
if (!entry.id) {
|
|
628
|
+
return this.services.resolveCreateCommand().execute(entry.item);
|
|
629
|
+
}
|
|
630
|
+
return this.services.resolveUpsertCommand().execute(entry.id, entry.item);
|
|
631
|
+
}
|
|
632
|
+
catch (error) {
|
|
633
|
+
throw new Error(`Error importing entry with id ${entry.id}`);
|
|
634
|
+
}
|
|
707
635
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
class EntitiesDeleteAction {
|
|
711
|
-
constructor(services) {
|
|
712
|
-
this.services = services;
|
|
713
|
-
this.logger = Log.getLogger(`${services.getEntityName()} -> DeleteItems`);
|
|
636
|
+
async parseImportFile(content, format) {
|
|
637
|
+
return await this.services.resolveSerializer().parse(content, format);
|
|
714
638
|
}
|
|
715
|
-
async
|
|
716
|
-
this.
|
|
717
|
-
|
|
718
|
-
|
|
639
|
+
async uploadImportFile(file) {
|
|
640
|
+
await this.bucket.fileUpload({
|
|
641
|
+
bucket: this.settings.exportBucket.bucket,
|
|
642
|
+
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
643
|
+
content: file.content,
|
|
644
|
+
contentType: file.contentType,
|
|
645
|
+
});
|
|
719
646
|
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
class EntityExistsAction {
|
|
723
|
-
constructor(services) {
|
|
724
|
-
this.services = services;
|
|
647
|
+
buildAbsoluteBucketPath(relativePath) {
|
|
648
|
+
return `${this.settings.exportBucket.rootFolderPath ?? ""}/imports/${createDayPath(new Date())}/${relativePath}`;
|
|
725
649
|
}
|
|
726
|
-
|
|
727
|
-
return
|
|
650
|
+
get bucket() {
|
|
651
|
+
return this.services.getRootServices().resolveBucketProvider();
|
|
728
652
|
}
|
|
729
653
|
}
|
|
730
654
|
|
|
731
|
-
class
|
|
732
|
-
constructor(services) {
|
|
655
|
+
class EntitiesSampleDownloadCommand {
|
|
656
|
+
constructor(services, settings) {
|
|
733
657
|
this.services = services;
|
|
734
|
-
this.
|
|
658
|
+
this.settings = settings;
|
|
735
659
|
}
|
|
736
660
|
async execute(input) {
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
661
|
+
const sample = await this.services
|
|
662
|
+
.resolveSerializer()
|
|
663
|
+
.createSample(input.format);
|
|
664
|
+
const downloadUrl = await this.uploadSampleFile(sample);
|
|
665
|
+
return {
|
|
666
|
+
file: {
|
|
667
|
+
content: sample.content,
|
|
668
|
+
contentType: sample.contentType,
|
|
669
|
+
name: sample.fileName,
|
|
670
|
+
},
|
|
671
|
+
downloadUrl,
|
|
672
|
+
};
|
|
741
673
|
}
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
674
|
+
async uploadSampleFile(file) {
|
|
675
|
+
await this.bucket.fileUpload({
|
|
676
|
+
bucket: this.settings.exportBucket.bucket,
|
|
677
|
+
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
678
|
+
content: file.content,
|
|
679
|
+
contentType: file.contentType,
|
|
680
|
+
});
|
|
681
|
+
return await this.bucket.filePublicUrlCreate({
|
|
682
|
+
bucket: this.settings.exportBucket.bucket,
|
|
683
|
+
expirationMinutes: this.settings.exportBucket.publicLinksExpirationMinutes,
|
|
684
|
+
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
685
|
+
});
|
|
747
686
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
: undefined;
|
|
687
|
+
buildAbsoluteBucketPath(relativePath) {
|
|
688
|
+
return `${this.settings.exportBucket.rootFolderPath ?? ""}/samples/${createDayPath(new Date())}/${relativePath}`;
|
|
689
|
+
}
|
|
690
|
+
get bucket() {
|
|
691
|
+
return this.services.getRootServices().resolveBucketProvider();
|
|
754
692
|
}
|
|
755
693
|
}
|
|
756
694
|
|
|
757
|
-
class
|
|
695
|
+
class EntityUpdateCommand {
|
|
758
696
|
constructor(services) {
|
|
759
697
|
this.services = services;
|
|
760
|
-
this.logger = Log.getLogger(`${services.getEntityName()} -> Import`);
|
|
761
|
-
}
|
|
762
|
-
async execute(input) {
|
|
763
|
-
this.logger.debug("Import action started", { input });
|
|
764
|
-
const result = await this.services.resolveImportCommand().execute(input);
|
|
765
|
-
this.logger.debug("Import action completed", { input });
|
|
766
|
-
return result;
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
class EntitiesSampleDownloadAction {
|
|
771
|
-
constructor(services) {
|
|
772
|
-
this.services = services;
|
|
773
|
-
this.logger = Log.getLogger(`${services.getEntityName()} -> Import`);
|
|
774
|
-
}
|
|
775
|
-
async execute(input) {
|
|
776
|
-
this.logger.debug("Sample download action started", { input });
|
|
777
|
-
const result = await this.services
|
|
778
|
-
.resolveSampleDownloadCommand()
|
|
779
|
-
.execute(input);
|
|
780
|
-
this.logger.debug("Sample download action completed", { input });
|
|
781
|
-
return result;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
class EntitiesSearchAction {
|
|
786
|
-
constructor(services) {
|
|
787
|
-
this.services = services;
|
|
788
|
-
}
|
|
789
|
-
async execute(request) {
|
|
790
|
-
const results = await this.services
|
|
791
|
-
.resolveSearchQuery()
|
|
792
|
-
.execute(request);
|
|
793
|
-
const converter = this.services.resolveConverter();
|
|
794
|
-
return {
|
|
795
|
-
facets: results.facets,
|
|
796
|
-
paging: results.paging,
|
|
797
|
-
request: results.request,
|
|
798
|
-
items: results.items.map((x) => (converter?.toListItemDto(x) ?? x)),
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
class EntityUpdateAction {
|
|
804
|
-
constructor(services) {
|
|
805
|
-
this.services = services;
|
|
806
|
-
this.logger = Log.getLogger(`${services.getEntityName()} -> Update`);
|
|
807
|
-
}
|
|
808
|
-
async execute(id, input) {
|
|
809
|
-
this.logger.debug("Update action started", { id, input });
|
|
810
|
-
const converter = this.services.resolveConverter();
|
|
811
|
-
const updateInput = converter?.updateDtoToEntity(input) ?? input;
|
|
812
|
-
const entity = await this.services
|
|
813
|
-
.resolveUpdateCommand()
|
|
814
|
-
.execute(id, updateInput);
|
|
815
|
-
const result = converter?.toEntityDto(entity) ?? entity;
|
|
816
|
-
this.logger.debug("Update action started", { id, input, result });
|
|
817
|
-
return result;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
class EntityUpsertAction {
|
|
822
|
-
constructor(services) {
|
|
823
|
-
this.services = services;
|
|
824
|
-
this.logger = Log.getLogger(`${services.getEntityName()} -> Upsert`);
|
|
825
698
|
}
|
|
826
699
|
async execute(id, input) {
|
|
827
|
-
this.
|
|
828
|
-
|
|
829
|
-
const
|
|
830
|
-
|
|
831
|
-
.
|
|
832
|
-
.execute(id, updateInput);
|
|
833
|
-
const result = converter?.toEntityDto(entity) ?? entity;
|
|
834
|
-
this.logger.debug("Upsert action started", { id, input, result });
|
|
835
|
-
return result;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
class EntityCreateCommand {
|
|
840
|
-
constructor(services) {
|
|
841
|
-
this.services = services;
|
|
842
|
-
}
|
|
843
|
-
async execute(input) {
|
|
844
|
-
var entity = this.adaptEntity(input);
|
|
845
|
-
await this.authorize(entity);
|
|
846
|
-
var createdItem = await this.services.resolveRepository().create(entity);
|
|
700
|
+
const entity = this.adaptEntity(input);
|
|
701
|
+
await this.authorize(id);
|
|
702
|
+
const updatedEntity = await this.services
|
|
703
|
+
.resolveRepository()
|
|
704
|
+
.update(id, entity);
|
|
847
705
|
await this.services
|
|
848
706
|
.resolveEventsManager()
|
|
849
|
-
.
|
|
850
|
-
return
|
|
707
|
+
.processEntityUpdatedEvent(updatedEntity);
|
|
708
|
+
return updatedEntity;
|
|
851
709
|
}
|
|
852
710
|
adaptEntity(input) {
|
|
853
711
|
const adapter = this.services.resolveAdapter();
|
|
854
712
|
return adapter
|
|
855
|
-
? adapter.
|
|
713
|
+
? adapter.updateDataToEntity(input)
|
|
856
714
|
: input;
|
|
857
715
|
}
|
|
858
|
-
async authorize(
|
|
716
|
+
async authorize(id) {
|
|
859
717
|
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
860
718
|
if (!authorization) {
|
|
861
719
|
return;
|
|
862
720
|
}
|
|
721
|
+
const currentEntity = await this.services.resolveRepository().get(id);
|
|
722
|
+
if (currentEntity == null) {
|
|
723
|
+
throw new EntityNotFoundException();
|
|
724
|
+
}
|
|
863
725
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
864
726
|
const context = await contextService?.getContext();
|
|
865
727
|
if (!context) {
|
|
866
728
|
return;
|
|
867
729
|
}
|
|
868
|
-
const authorizationResult = await authorization.
|
|
730
|
+
const authorizationResult = await authorization.canUpdate(currentEntity, context);
|
|
869
731
|
if (!authorizationResult.isAuthorized)
|
|
870
|
-
throw new EntityOperationUnauthorizedException(EntityOperationType.Create, this.services.getEntityName(),
|
|
732
|
+
throw new EntityOperationUnauthorizedException(EntityOperationType.Create, this.services.getEntityName(), currentEntity);
|
|
871
733
|
}
|
|
872
734
|
}
|
|
873
735
|
|
|
874
|
-
class
|
|
736
|
+
class EntityUpsertCommand {
|
|
875
737
|
constructor(services) {
|
|
876
738
|
this.services = services;
|
|
877
739
|
}
|
|
878
|
-
async execute(id) {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
await this.
|
|
883
|
-
|
|
884
|
-
|
|
740
|
+
async execute(id, data) {
|
|
741
|
+
const entity = this.adaptEntity(data);
|
|
742
|
+
await this.authorize(id, entity);
|
|
743
|
+
const updatedEntity = await this.upsertEntity(id, entity);
|
|
744
|
+
await this.services
|
|
745
|
+
.resolveEventsManager()
|
|
746
|
+
.processEntityUpdatedEvent(updatedEntity);
|
|
747
|
+
return updatedEntity;
|
|
885
748
|
}
|
|
886
|
-
async
|
|
749
|
+
async upsertEntity(id, entity) {
|
|
750
|
+
return await this.services.resolveRepository().upsert(id, entity);
|
|
751
|
+
}
|
|
752
|
+
adaptEntity(input) {
|
|
753
|
+
const adapter = this.services.resolveAdapter();
|
|
754
|
+
return adapter
|
|
755
|
+
? adapter.updateDataToEntity(input)
|
|
756
|
+
: input;
|
|
757
|
+
}
|
|
758
|
+
async authorize(id, entity) {
|
|
887
759
|
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
888
760
|
if (!authorization) {
|
|
889
761
|
return;
|
|
890
762
|
}
|
|
891
|
-
const
|
|
892
|
-
if (entity == null) {
|
|
893
|
-
throw new EntityNotFoundException(id);
|
|
894
|
-
}
|
|
763
|
+
const currentEntity = await this.services.resolveRepository().get(id);
|
|
895
764
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
896
765
|
const context = await contextService?.getContext();
|
|
897
766
|
if (!context) {
|
|
898
767
|
return;
|
|
899
768
|
}
|
|
900
|
-
|
|
769
|
+
if (currentEntity) {
|
|
770
|
+
const updateResult = await authorization.canUpdate(currentEntity, context);
|
|
771
|
+
if (!updateResult.isAuthorized)
|
|
772
|
+
throw new EntityOperationUnauthorizedException(EntityOperationType.Update, this.services.getEntityName(), currentEntity);
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
const authorizationResult = await authorization.canCreate(entity, context);
|
|
901
776
|
if (!authorizationResult.isAuthorized)
|
|
902
|
-
throw new EntityOperationUnauthorizedException(EntityOperationType.
|
|
777
|
+
throw new EntityOperationUnauthorizedException(EntityOperationType.Create, this.services.getEntityName(), entity);
|
|
903
778
|
}
|
|
904
779
|
}
|
|
905
780
|
|
|
906
|
-
class
|
|
781
|
+
class EntityManager {
|
|
907
782
|
constructor(services) {
|
|
908
783
|
this.services = services;
|
|
909
784
|
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
const context = await this.getContext();
|
|
913
|
-
const deleteResult = await this.services
|
|
914
|
-
.resolveQueryBuilder()
|
|
915
|
-
.delete(params.filters, context);
|
|
916
|
-
// todo: add entities deleted event
|
|
917
|
-
return deleteResult;
|
|
785
|
+
get exists() {
|
|
786
|
+
return this.services.resolveExistsQuery();
|
|
918
787
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
if (!authorization) {
|
|
922
|
-
return undefined;
|
|
923
|
-
}
|
|
924
|
-
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
925
|
-
return await contextService.getContext();
|
|
788
|
+
get count() {
|
|
789
|
+
return this.services.resolveCountQuery();
|
|
926
790
|
}
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
if (!authorization) {
|
|
930
|
-
return;
|
|
931
|
-
}
|
|
932
|
-
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
933
|
-
const context = await contextService?.getContext();
|
|
934
|
-
if (!context) {
|
|
935
|
-
return;
|
|
936
|
-
}
|
|
937
|
-
const authorizationResult = await authorization.canDeleteItems(context);
|
|
938
|
-
if (!authorizationResult.isAuthorized)
|
|
939
|
-
throw new EntityOperationUnauthorizedException(EntityOperationType.Delete, this.services.getEntityName());
|
|
791
|
+
get deleteItems() {
|
|
792
|
+
return this.services.resolveDeleteItemsCommand();
|
|
940
793
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
const createDayPath = (d) => `${d.getFullYear()}/${(d.getMonth() + 1).toString().padStart(2, "0")}/${d
|
|
944
|
-
.getDate()
|
|
945
|
-
.toString()
|
|
946
|
-
.padStart(2, "0")}`;
|
|
947
|
-
class EntitiesExportCommand {
|
|
948
|
-
constructor(services, settings) {
|
|
949
|
-
this.services = services;
|
|
950
|
-
this.settings = settings;
|
|
794
|
+
get get() {
|
|
795
|
+
return this.services.resolveGetQuery();
|
|
951
796
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
const outputFile = await this.buildExportFile(exportEntities.items, input.options.format);
|
|
955
|
-
const downloadUrl = await this.uploadExportFile(outputFile);
|
|
956
|
-
return {
|
|
957
|
-
downloadUrl,
|
|
958
|
-
file: {
|
|
959
|
-
content: outputFile.content,
|
|
960
|
-
contentType: outputFile.contentType,
|
|
961
|
-
name: outputFile.fileName,
|
|
962
|
-
},
|
|
963
|
-
};
|
|
797
|
+
get search() {
|
|
798
|
+
return this.services.resolveSearchQuery();
|
|
964
799
|
}
|
|
965
|
-
|
|
966
|
-
return
|
|
800
|
+
get create() {
|
|
801
|
+
return this.services.resolveCreateCommand();
|
|
967
802
|
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
bucket: this.settings.exportBucket.bucket,
|
|
971
|
-
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
972
|
-
content: file.content,
|
|
973
|
-
contentType: file.contentType,
|
|
974
|
-
});
|
|
975
|
-
return await this.bucket.filePublicUrlCreate({
|
|
976
|
-
bucket: this.settings.exportBucket.bucket,
|
|
977
|
-
expirationMinutes: this.settings.exportBucket.publicLinksExpirationMinutes,
|
|
978
|
-
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
979
|
-
});
|
|
803
|
+
get update() {
|
|
804
|
+
return this.services.resolveUpdateCommand();
|
|
980
805
|
}
|
|
981
|
-
|
|
982
|
-
return
|
|
806
|
+
get upsert() {
|
|
807
|
+
return this.services.resolveUpsertCommand();
|
|
983
808
|
}
|
|
984
|
-
|
|
985
|
-
return this.services.
|
|
809
|
+
get delete() {
|
|
810
|
+
return this.services.resolveDeleteCommand();
|
|
986
811
|
}
|
|
987
|
-
get
|
|
988
|
-
return this.services.
|
|
812
|
+
get export() {
|
|
813
|
+
return this.services.resolveExportCommand();
|
|
814
|
+
}
|
|
815
|
+
get import() {
|
|
816
|
+
return this.services.resolveImportCommand();
|
|
817
|
+
}
|
|
818
|
+
get sampleDownload() {
|
|
819
|
+
return this.services.resolveSampleDownloadCommand();
|
|
989
820
|
}
|
|
990
821
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
constructor(services, settings) {
|
|
994
|
-
this.services = services;
|
|
995
|
-
this.settings = settings;
|
|
996
|
-
}
|
|
997
|
-
async execute(input) {
|
|
998
|
-
await this.uploadImportFile({
|
|
999
|
-
content: input.content,
|
|
1000
|
-
contentType: input.contentType,
|
|
1001
|
-
fileName: input.fileName,
|
|
1002
|
-
});
|
|
1003
|
-
const importEntities = await this.parseImportFile(input.content, input.format);
|
|
1004
|
-
for (const entry of importEntities) {
|
|
1005
|
-
await this.importEntity(entry);
|
|
1006
|
-
}
|
|
1007
|
-
return {
|
|
1008
|
-
statistics: {
|
|
1009
|
-
importedCount: importEntities.length,
|
|
1010
|
-
createdCount: 0,
|
|
1011
|
-
unchangedCount: 0,
|
|
1012
|
-
updatedCount: 0,
|
|
1013
|
-
},
|
|
1014
|
-
};
|
|
1015
|
-
}
|
|
1016
|
-
async importEntity(entry) {
|
|
1017
|
-
try {
|
|
1018
|
-
if (!entry.id) {
|
|
1019
|
-
return this.services.resolveCreateCommand().execute(entry.item);
|
|
1020
|
-
}
|
|
1021
|
-
return this.services.resolveUpsertCommand().execute(entry.id, entry.item);
|
|
1022
|
-
}
|
|
1023
|
-
catch (error) {
|
|
1024
|
-
throw new Error(`Error importing entry with id ${entry.id}`);
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
async parseImportFile(content, format) {
|
|
1028
|
-
return await this.services.resolveSerializer().parse(content, format);
|
|
1029
|
-
}
|
|
1030
|
-
async uploadImportFile(file) {
|
|
1031
|
-
await this.bucket.fileUpload({
|
|
1032
|
-
bucket: this.settings.exportBucket.bucket,
|
|
1033
|
-
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
1034
|
-
content: file.content,
|
|
1035
|
-
contentType: file.contentType,
|
|
1036
|
-
});
|
|
1037
|
-
}
|
|
1038
|
-
buildAbsoluteBucketPath(relativePath) {
|
|
1039
|
-
return `${this.settings.exportBucket.rootFolderPath ?? ""}/imports/${createDayPath(new Date())}/${relativePath}`;
|
|
1040
|
-
}
|
|
1041
|
-
get bucket() {
|
|
1042
|
-
return this.services.getRootServices().resolveBucketProvider();
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
class EntitiesSampleDownloadCommand {
|
|
1047
|
-
constructor(services, settings) {
|
|
1048
|
-
this.services = services;
|
|
1049
|
-
this.settings = settings;
|
|
1050
|
-
}
|
|
1051
|
-
async execute(input) {
|
|
1052
|
-
const sample = await this.services
|
|
1053
|
-
.resolveSerializer()
|
|
1054
|
-
.createSample(input.format);
|
|
1055
|
-
const downloadUrl = await this.uploadSampleFile(sample);
|
|
1056
|
-
return {
|
|
1057
|
-
file: {
|
|
1058
|
-
content: sample.content,
|
|
1059
|
-
contentType: sample.contentType,
|
|
1060
|
-
name: sample.fileName,
|
|
1061
|
-
},
|
|
1062
|
-
downloadUrl,
|
|
1063
|
-
};
|
|
1064
|
-
}
|
|
1065
|
-
async uploadSampleFile(file) {
|
|
1066
|
-
await this.bucket.fileUpload({
|
|
1067
|
-
bucket: this.settings.exportBucket.bucket,
|
|
1068
|
-
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
1069
|
-
content: file.content,
|
|
1070
|
-
contentType: file.contentType,
|
|
1071
|
-
});
|
|
1072
|
-
return await this.bucket.filePublicUrlCreate({
|
|
1073
|
-
bucket: this.settings.exportBucket.bucket,
|
|
1074
|
-
expirationMinutes: this.settings.exportBucket.publicLinksExpirationMinutes,
|
|
1075
|
-
filePath: this.buildAbsoluteBucketPath(file.fileName),
|
|
1076
|
-
});
|
|
1077
|
-
}
|
|
1078
|
-
buildAbsoluteBucketPath(relativePath) {
|
|
1079
|
-
return `${this.settings.exportBucket.rootFolderPath ?? ""}/samples/${createDayPath(new Date())}/${relativePath}`;
|
|
1080
|
-
}
|
|
1081
|
-
get bucket() {
|
|
1082
|
-
return this.services.getRootServices().resolveBucketProvider();
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
class EntityUpdateCommand {
|
|
1087
|
-
constructor(services) {
|
|
1088
|
-
this.services = services;
|
|
1089
|
-
}
|
|
1090
|
-
async execute(id, input) {
|
|
1091
|
-
const entity = this.adaptEntity(input);
|
|
1092
|
-
await this.authorize(id);
|
|
1093
|
-
const updatedEntity = await this.services
|
|
1094
|
-
.resolveRepository()
|
|
1095
|
-
.update(id, entity);
|
|
1096
|
-
await this.services
|
|
1097
|
-
.resolveEventsManager()
|
|
1098
|
-
.processEntityUpdatedEvent(updatedEntity);
|
|
1099
|
-
return updatedEntity;
|
|
1100
|
-
}
|
|
1101
|
-
adaptEntity(input) {
|
|
1102
|
-
const adapter = this.services.resolveAdapter();
|
|
1103
|
-
return adapter
|
|
1104
|
-
? adapter.updateDataToEntity(input)
|
|
1105
|
-
: input;
|
|
1106
|
-
}
|
|
1107
|
-
async authorize(id) {
|
|
1108
|
-
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
1109
|
-
if (!authorization) {
|
|
1110
|
-
return;
|
|
1111
|
-
}
|
|
1112
|
-
const currentEntity = await this.services.resolveRepository().get(id);
|
|
1113
|
-
if (currentEntity == null) {
|
|
1114
|
-
throw new EntityNotFoundException();
|
|
1115
|
-
}
|
|
1116
|
-
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
1117
|
-
const context = await contextService?.getContext();
|
|
1118
|
-
if (!context) {
|
|
1119
|
-
return;
|
|
1120
|
-
}
|
|
1121
|
-
const authorizationResult = await authorization.canUpdate(currentEntity, context);
|
|
1122
|
-
if (!authorizationResult.isAuthorized)
|
|
1123
|
-
throw new EntityOperationUnauthorizedException(EntityOperationType.Create, this.services.getEntityName(), currentEntity);
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
class EntityUpsertCommand {
|
|
1128
|
-
constructor(services) {
|
|
1129
|
-
this.services = services;
|
|
1130
|
-
}
|
|
1131
|
-
async execute(id, data) {
|
|
1132
|
-
const entity = this.adaptEntity(data);
|
|
1133
|
-
await this.authorize(id, entity);
|
|
1134
|
-
const updatedEntity = await this.upsertEntity(id, entity);
|
|
1135
|
-
await this.services
|
|
1136
|
-
.resolveEventsManager()
|
|
1137
|
-
.processEntityUpdatedEvent(updatedEntity);
|
|
1138
|
-
return updatedEntity;
|
|
1139
|
-
}
|
|
1140
|
-
async upsertEntity(id, entity) {
|
|
1141
|
-
return await this.services.resolveRepository().upsert(id, entity);
|
|
1142
|
-
}
|
|
1143
|
-
adaptEntity(input) {
|
|
1144
|
-
const adapter = this.services.resolveAdapter();
|
|
1145
|
-
return adapter
|
|
1146
|
-
? adapter.updateDataToEntity(input)
|
|
1147
|
-
: input;
|
|
1148
|
-
}
|
|
1149
|
-
async authorize(id, entity) {
|
|
1150
|
-
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
1151
|
-
if (!authorization) {
|
|
1152
|
-
return;
|
|
1153
|
-
}
|
|
1154
|
-
const currentEntity = await this.services.resolveRepository().get(id);
|
|
1155
|
-
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
1156
|
-
const context = await contextService?.getContext();
|
|
1157
|
-
if (!context) {
|
|
1158
|
-
return;
|
|
1159
|
-
}
|
|
1160
|
-
if (currentEntity) {
|
|
1161
|
-
const updateResult = await authorization.canUpdate(currentEntity, context);
|
|
1162
|
-
if (!updateResult.isAuthorized)
|
|
1163
|
-
throw new EntityOperationUnauthorizedException(EntityOperationType.Update, this.services.getEntityName(), currentEntity);
|
|
1164
|
-
return;
|
|
1165
|
-
}
|
|
1166
|
-
const authorizationResult = await authorization.canCreate(entity, context);
|
|
1167
|
-
if (!authorizationResult.isAuthorized)
|
|
1168
|
-
throw new EntityOperationUnauthorizedException(EntityOperationType.Create, this.services.getEntityName(), entity);
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
class EntityManager {
|
|
1173
|
-
constructor(services) {
|
|
1174
|
-
this.services = services;
|
|
1175
|
-
}
|
|
1176
|
-
get exists() {
|
|
1177
|
-
return this.services.resolveExistsQuery();
|
|
1178
|
-
}
|
|
1179
|
-
get count() {
|
|
1180
|
-
return this.services.resolveCountQuery();
|
|
1181
|
-
}
|
|
1182
|
-
get deleteItems() {
|
|
1183
|
-
return this.services.resolveDeleteItemsCommand();
|
|
1184
|
-
}
|
|
1185
|
-
get get() {
|
|
1186
|
-
return this.services.resolveGetQuery();
|
|
1187
|
-
}
|
|
1188
|
-
get search() {
|
|
1189
|
-
return this.services.resolveSearchQuery();
|
|
1190
|
-
}
|
|
1191
|
-
get create() {
|
|
1192
|
-
return this.services.resolveCreateCommand();
|
|
1193
|
-
}
|
|
1194
|
-
get update() {
|
|
1195
|
-
return this.services.resolveUpdateCommand();
|
|
1196
|
-
}
|
|
1197
|
-
get upsert() {
|
|
1198
|
-
return this.services.resolveUpsertCommand();
|
|
1199
|
-
}
|
|
1200
|
-
get delete() {
|
|
1201
|
-
return this.services.resolveDeleteCommand();
|
|
1202
|
-
}
|
|
1203
|
-
get export() {
|
|
1204
|
-
return this.services.resolveExportCommand();
|
|
1205
|
-
}
|
|
1206
|
-
get import() {
|
|
1207
|
-
return this.services.resolveImportCommand();
|
|
1208
|
-
}
|
|
1209
|
-
get sampleDownload() {
|
|
1210
|
-
return this.services.resolveSampleDownloadCommand();
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
class EntityActions {
|
|
1214
|
-
constructor(services) {
|
|
822
|
+
class EntityActions {
|
|
823
|
+
constructor(services) {
|
|
1215
824
|
this.services = services;
|
|
1216
825
|
}
|
|
1217
826
|
get exists() {
|
|
@@ -2138,139 +1747,539 @@ class ReplicasConfiguration {
|
|
|
2138
1747
|
}
|
|
2139
1748
|
}
|
|
2140
1749
|
|
|
2141
|
-
class EntityManagerServiceRoot {
|
|
2142
|
-
constructor() {
|
|
2143
|
-
this.services = new ServiceLocator();
|
|
2144
|
-
}
|
|
2145
|
-
get locator() {
|
|
2146
|
-
return this.services;
|
|
2147
|
-
}
|
|
2148
|
-
getEntitiesServicesLocator() {
|
|
2149
|
-
return new EntitiesServiceLocator(this.services);
|
|
2150
|
-
}
|
|
2151
|
-
getEntityServicesLocator(entityName) {
|
|
2152
|
-
return new EntityServiceLocator(this.getEntitiesServicesLocator(), entityName);
|
|
2153
|
-
}
|
|
2154
|
-
addAuthentication({ provider }) {
|
|
2155
|
-
this.getEntitiesServicesLocator().registerAuthenticationContextProvider(provider);
|
|
2156
|
-
}
|
|
2157
|
-
registerEntity(entityName, repository) {
|
|
2158
|
-
const collection = new EntityManagerServiceCollection(entityName, this.getEntitiesServicesLocator());
|
|
2159
|
-
const services = this.getEntityServicesLocator(entityName);
|
|
2160
|
-
collection.locator.registerEntityManager(entityName, new EntityManager(services));
|
|
2161
|
-
collection.locator.registerEntityActions(entityName, new EntityActions(services));
|
|
2162
|
-
collection.locator.registerRepository(entityName, repository);
|
|
2163
|
-
const replicaManager = new EntityReplicaManager(services);
|
|
2164
|
-
collection.locator.registerReplicaSyncManager(entityName, replicaManager);
|
|
2165
|
-
collection.locator.registerReplicaDeleteManager(entityName, replicaManager);
|
|
2166
|
-
collection.locator.registerReplicaConfiguration(entityName, new ReplicasConfiguration());
|
|
2167
|
-
const connectorsManager = new EntityConnectorsManager(services);
|
|
2168
|
-
collection.locator.registerConnectorSyncManager(entityName, connectorsManager);
|
|
2169
|
-
collection.locator.registerConnectorDeleteManager(entityName, connectorsManager);
|
|
2170
|
-
collection.locator.registerConnectorsConfiguration(entityName, new ConnectorsConfiguration());
|
|
2171
|
-
collection.locator.registerEventsManager(entityName, new EntityEventsManager(entityName, services));
|
|
2172
|
-
return collection;
|
|
1750
|
+
class EntityManagerServiceRoot {
|
|
1751
|
+
constructor() {
|
|
1752
|
+
this.services = new ServiceLocator();
|
|
1753
|
+
}
|
|
1754
|
+
get locator() {
|
|
1755
|
+
return this.services;
|
|
1756
|
+
}
|
|
1757
|
+
getEntitiesServicesLocator() {
|
|
1758
|
+
return new EntitiesServiceLocator(this.services);
|
|
1759
|
+
}
|
|
1760
|
+
getEntityServicesLocator(entityName) {
|
|
1761
|
+
return new EntityServiceLocator(this.getEntitiesServicesLocator(), entityName);
|
|
1762
|
+
}
|
|
1763
|
+
addAuthentication({ provider }) {
|
|
1764
|
+
this.getEntitiesServicesLocator().registerAuthenticationContextProvider(provider);
|
|
1765
|
+
}
|
|
1766
|
+
registerEntity(entityName, repository) {
|
|
1767
|
+
const collection = new EntityManagerServiceCollection(entityName, this.getEntitiesServicesLocator());
|
|
1768
|
+
const services = this.getEntityServicesLocator(entityName);
|
|
1769
|
+
collection.locator.registerEntityManager(entityName, new EntityManager(services));
|
|
1770
|
+
collection.locator.registerEntityActions(entityName, new EntityActions(services));
|
|
1771
|
+
collection.locator.registerRepository(entityName, repository);
|
|
1772
|
+
const replicaManager = new EntityReplicaManager(services);
|
|
1773
|
+
collection.locator.registerReplicaSyncManager(entityName, replicaManager);
|
|
1774
|
+
collection.locator.registerReplicaDeleteManager(entityName, replicaManager);
|
|
1775
|
+
collection.locator.registerReplicaConfiguration(entityName, new ReplicasConfiguration());
|
|
1776
|
+
const connectorsManager = new EntityConnectorsManager(services);
|
|
1777
|
+
collection.locator.registerConnectorSyncManager(entityName, connectorsManager);
|
|
1778
|
+
collection.locator.registerConnectorDeleteManager(entityName, connectorsManager);
|
|
1779
|
+
collection.locator.registerConnectorsConfiguration(entityName, new ConnectorsConfiguration());
|
|
1780
|
+
collection.locator.registerEventsManager(entityName, new EntityEventsManager(entityName, services));
|
|
1781
|
+
return collection;
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
class EntityManagerServiceCollection {
|
|
1785
|
+
constructor(entityName, locator) {
|
|
1786
|
+
this.entityName = entityName;
|
|
1787
|
+
this.locator = locator;
|
|
1788
|
+
this.replicas = new ReplicasConfiguration();
|
|
1789
|
+
this.connectors = new ConnectorsConfiguration();
|
|
1790
|
+
this.resolver = new EntityServiceLocator(locator, entityName);
|
|
1791
|
+
}
|
|
1792
|
+
getServiceLocator() {
|
|
1793
|
+
return this.resolver;
|
|
1794
|
+
}
|
|
1795
|
+
mapCrudOperations({ queryBuilder, settings, }) {
|
|
1796
|
+
this.mapGet();
|
|
1797
|
+
this.mapCount();
|
|
1798
|
+
this.mapExists();
|
|
1799
|
+
this.mapSearch({
|
|
1800
|
+
queryBuilder,
|
|
1801
|
+
});
|
|
1802
|
+
this.mapCreate();
|
|
1803
|
+
this.mapUpdate();
|
|
1804
|
+
this.mapDelete();
|
|
1805
|
+
this.mapImportExport(settings.importExport);
|
|
1806
|
+
return this;
|
|
1807
|
+
}
|
|
1808
|
+
mapGet() {
|
|
1809
|
+
this.locator.registerGetQuery(this.entityName, new EntityGetQuery(this.resolver));
|
|
1810
|
+
this.locator.registerGetAction(this.entityName, new EntityGetAction(this.resolver));
|
|
1811
|
+
return this;
|
|
1812
|
+
}
|
|
1813
|
+
mapCount() {
|
|
1814
|
+
this.locator.registerCountQuery(this.entityName, new EntitiesCountQuery(this.resolver));
|
|
1815
|
+
this.locator.registerCountAction(this.entityName, new EntitiesCountAction(this.resolver));
|
|
1816
|
+
return this;
|
|
1817
|
+
}
|
|
1818
|
+
mapExists() {
|
|
1819
|
+
this.locator.registerExistsQuery(this.entityName, new EntityExistsQuery(this.resolver));
|
|
1820
|
+
this.locator.registerExistsAction(this.entityName, new EntityExistsAction(this.resolver));
|
|
1821
|
+
return this;
|
|
1822
|
+
}
|
|
1823
|
+
mapSearch({ queryBuilder, }) {
|
|
1824
|
+
this.locator.registerSearchQuery(this.entityName, new EntitiesSearchQuery(this.resolver));
|
|
1825
|
+
this.locator.registerSearchAction(this.entityName, new EntitiesSearchAction(this.resolver));
|
|
1826
|
+
this.locator.registerQueryBuilder(this.entityName, queryBuilder);
|
|
1827
|
+
return this;
|
|
1828
|
+
}
|
|
1829
|
+
mapCreate() {
|
|
1830
|
+
this.locator.registerCreateCommand(this.entityName, new EntityCreateCommand(this.resolver));
|
|
1831
|
+
this.locator.registerCreateAction(this.entityName, new EntityCreateAction(this.resolver));
|
|
1832
|
+
return this;
|
|
1833
|
+
}
|
|
1834
|
+
mapImportExport(settings) {
|
|
1835
|
+
this.locator.registerExportCommand(this.entityName, new EntitiesExportCommand(this.resolver, settings));
|
|
1836
|
+
this.locator.registerExportAction(this.entityName, new EntitiesExportAction(this.resolver));
|
|
1837
|
+
this.locator.registerImportCommand(this.entityName, new EntitiesImportCommand(this.resolver, settings));
|
|
1838
|
+
this.locator.registerImportAction(this.entityName, new EntitiesImportAction(this.resolver));
|
|
1839
|
+
this.locator.registerSampleDownloadCommand(this.entityName, new EntitiesSampleDownloadCommand(this.resolver, settings));
|
|
1840
|
+
this.locator.registerSampleDownloadAction(this.entityName, new EntitiesSampleDownloadAction(this.resolver));
|
|
1841
|
+
return this;
|
|
1842
|
+
}
|
|
1843
|
+
mapUpdate() {
|
|
1844
|
+
this.locator.registerUpsertCommand(this.entityName, new EntityUpsertCommand(this.resolver));
|
|
1845
|
+
this.locator.registerUpsertAction(this.entityName, new EntityUpsertAction(this.resolver));
|
|
1846
|
+
this.locator.registerUpdateCommand(this.entityName, new EntityUpdateCommand(this.resolver));
|
|
1847
|
+
this.locator.registerUpdateAction(this.entityName, new EntityUpdateAction(this.resolver));
|
|
1848
|
+
return this;
|
|
1849
|
+
}
|
|
1850
|
+
mapDelete() {
|
|
1851
|
+
this.locator.registerDeleteCommand(this.entityName, new EntityDeleteCommand(this.resolver));
|
|
1852
|
+
this.locator.registerDeleteAction(this.entityName, new EntityDeleteAction(this.resolver));
|
|
1853
|
+
this.locator.registerDeleteItemsCommand(this.entityName, new EntitiesDeleteCommand(this.resolver));
|
|
1854
|
+
this.locator.registerDeleteItemsAction(this.entityName, new EntitiesDeleteAction(this.resolver));
|
|
1855
|
+
return this;
|
|
1856
|
+
}
|
|
1857
|
+
addAdapter(adapter) {
|
|
1858
|
+
this.locator.registerAdapter(this.entityName, adapter);
|
|
1859
|
+
return this;
|
|
1860
|
+
}
|
|
1861
|
+
addSerializer(serializer) {
|
|
1862
|
+
this.locator.registerSerializer(this.entityName, serializer);
|
|
1863
|
+
return this;
|
|
1864
|
+
}
|
|
1865
|
+
addConverter(converter) {
|
|
1866
|
+
this.locator.registerConverter(this.entityName, converter);
|
|
1867
|
+
return this;
|
|
1868
|
+
}
|
|
1869
|
+
addAuthorization({ middleware, }) {
|
|
1870
|
+
this.locator.registerAuthorizationMiddleware(this.entityName, middleware);
|
|
1871
|
+
return this;
|
|
1872
|
+
}
|
|
1873
|
+
withReplica({ name, options, repository, }) {
|
|
1874
|
+
this.replicas.configureReplica(name, options, repository);
|
|
1875
|
+
return this;
|
|
1876
|
+
}
|
|
1877
|
+
withSynchronization({ name, options, connector, mapper, }) {
|
|
1878
|
+
this.connectors.configureConnector(name, options, connector, mapper);
|
|
1879
|
+
return this;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
const createContainer = () => new EntityManagerServiceRoot();
|
|
1883
|
+
|
|
1884
|
+
const toEntitiesImportInput = (request) => ({
|
|
1885
|
+
format: request.format,
|
|
1886
|
+
file: {
|
|
1887
|
+
content: request.file.buffer,
|
|
1888
|
+
contentType: request.file.mimetype,
|
|
1889
|
+
fileName: request.file.originalname,
|
|
1890
|
+
},
|
|
1891
|
+
});
|
|
1892
|
+
|
|
1893
|
+
const PLATFORM_EVENT_NAMESPACE = "platform";
|
|
1894
|
+
const PlatformEvents = {
|
|
1895
|
+
Messaging: {
|
|
1896
|
+
EmailSent: `${PLATFORM_EVENT_NAMESPACE}:messaging.emailSent`,
|
|
1897
|
+
},
|
|
1898
|
+
};
|
|
1899
|
+
|
|
1900
|
+
class NestEntityAuthorizationMiddleware {
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
class NestEntityActions {
|
|
1904
|
+
// todo: resolve entity name from decorator
|
|
1905
|
+
constructor(entityName, registry) {
|
|
1906
|
+
this.services = registry.resolveEntityServicesCollection(entityName);
|
|
1907
|
+
}
|
|
1908
|
+
get manager() {
|
|
1909
|
+
if (!this.actionsInstance) {
|
|
1910
|
+
this.actionsInstance =
|
|
1911
|
+
this.services.resolveEntityActions();
|
|
1912
|
+
}
|
|
1913
|
+
return this.actionsInstance;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
class NestEntityManager {
|
|
1918
|
+
// todo: resolve entity name from decorator
|
|
1919
|
+
constructor(entityName, registry) {
|
|
1920
|
+
this.services = registry.resolveEntityServicesCollection(entityName);
|
|
1921
|
+
}
|
|
1922
|
+
get manager() {
|
|
1923
|
+
if (!this.managerInstance) {
|
|
1924
|
+
this.managerInstance =
|
|
1925
|
+
this.services.resolveEntityManager();
|
|
1926
|
+
}
|
|
1927
|
+
return this.managerInstance;
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
class NestEntitySerializer extends EntitySerializer {
|
|
1932
|
+
constructor(entityName, registry) {
|
|
1933
|
+
super(entityName);
|
|
1934
|
+
// this.services = registry.resolveEntityServicesCollection(entityName)
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
const EntityManagerSymbols = {
|
|
1939
|
+
AppInitializer: Symbol.for("WP:APP_INITIALIZER"),
|
|
1940
|
+
EventsTracker: Symbol.for("WP:EVENTS_TRACKER"),
|
|
1941
|
+
Entity: Symbol.for("WP:ENTITY"),
|
|
1942
|
+
EntityActions: Symbol.for("WP:ENTITY_ACTIONS"),
|
|
1943
|
+
EntityAdapter: Symbol.for("WP:ENTITY_ADAPTER"),
|
|
1944
|
+
EntityAuthMiddleware: Symbol.for("WP:ENTITY_AUTH_MIDDLEWARE"),
|
|
1945
|
+
EntityRepository: Symbol.for("WP:ENTITY_REPOSITORY"),
|
|
1946
|
+
EntityConnector: Symbol.for("WP:ENTITY_CONNECTOR"),
|
|
1947
|
+
EntityConverter: Symbol.for("WP:ENTITY_CONVERTER"),
|
|
1948
|
+
EntitySerializer: Symbol.for("WP:ENTITY_SERIALIZER"),
|
|
1949
|
+
EntityManager: Symbol.for("WP:ENTITY_MANAGER"),
|
|
1950
|
+
EntityQueryBuilder: Symbol.for("WP:ENTITY_QUERY_BUILDER"),
|
|
1951
|
+
EntitySeeder: Symbol.for("WP:ENTITY_SEEDER"),
|
|
1952
|
+
EmailProvider: Symbol.for("WP:EMAIL_PROVIDER"),
|
|
1953
|
+
EmailTemplate: Symbol.for("WP:EMAIL_TEMPLATE"),
|
|
1954
|
+
BucketProvider: Symbol.for("WP:BUCKET_PROVIDER"),
|
|
1955
|
+
PipelineTemplate: Symbol.for("WP:PIPELINE_TEMPLATE"),
|
|
1956
|
+
};
|
|
1957
|
+
|
|
1958
|
+
const WpEntityAuthMiddleware = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntityAuthMiddleware, {
|
|
1959
|
+
entityName,
|
|
1960
|
+
...props,
|
|
1961
|
+
}));
|
|
1962
|
+
|
|
1963
|
+
const WpBucketProvider = (providerId) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.BucketProvider, {
|
|
1964
|
+
providerId,
|
|
1965
|
+
}));
|
|
1966
|
+
|
|
1967
|
+
const WpEntityActions = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntityActions, {
|
|
1968
|
+
entityName,
|
|
1969
|
+
...props,
|
|
1970
|
+
}));
|
|
1971
|
+
|
|
1972
|
+
const WpEntityAdapter = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntityAdapter, {
|
|
1973
|
+
entityName,
|
|
1974
|
+
...props,
|
|
1975
|
+
}));
|
|
1976
|
+
|
|
1977
|
+
const WpEntityConnector = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntityConnector, {
|
|
1978
|
+
entityName,
|
|
1979
|
+
...props,
|
|
1980
|
+
}));
|
|
1981
|
+
|
|
1982
|
+
const WpEntityConverter = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntityConverter, {
|
|
1983
|
+
entityName,
|
|
1984
|
+
...props,
|
|
1985
|
+
}));
|
|
1986
|
+
|
|
1987
|
+
const WpEmailTemplate = (templateId) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EmailTemplate, {
|
|
1988
|
+
templateId,
|
|
1989
|
+
}));
|
|
1990
|
+
const WpEmailProvider = (providerId) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EmailProvider, {
|
|
1991
|
+
providerId,
|
|
1992
|
+
}));
|
|
1993
|
+
|
|
1994
|
+
const WpEntity = (name, props = {}) => applyDecorators(SetMetadata(EntityManagerSymbols.Entity, {
|
|
1995
|
+
name,
|
|
1996
|
+
...props,
|
|
1997
|
+
}));
|
|
1998
|
+
|
|
1999
|
+
const WpAppInitializer = (props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.AppInitializer, props));
|
|
2000
|
+
|
|
2001
|
+
const WpEntityRepository = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntityRepository, {
|
|
2002
|
+
entityName,
|
|
2003
|
+
...props,
|
|
2004
|
+
}));
|
|
2005
|
+
|
|
2006
|
+
const WpEntityManager = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntityManager, {
|
|
2007
|
+
entityName,
|
|
2008
|
+
...props,
|
|
2009
|
+
}));
|
|
2010
|
+
|
|
2011
|
+
const WpEntityQueryBuilder = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntityQueryBuilder, {
|
|
2012
|
+
entityName,
|
|
2013
|
+
...props,
|
|
2014
|
+
}));
|
|
2015
|
+
|
|
2016
|
+
const WpPipeline = (name, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.PipelineTemplate, {
|
|
2017
|
+
name,
|
|
2018
|
+
...props,
|
|
2019
|
+
}));
|
|
2020
|
+
|
|
2021
|
+
const WpEntitySeeder = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntitySeeder, {
|
|
2022
|
+
entityName,
|
|
2023
|
+
...props,
|
|
2024
|
+
}));
|
|
2025
|
+
|
|
2026
|
+
const WpEntitySerializer = (entityName, props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EntitySerializer, {
|
|
2027
|
+
entityName,
|
|
2028
|
+
...props,
|
|
2029
|
+
}));
|
|
2030
|
+
|
|
2031
|
+
const WpEventsTracker = (props = {}) => applyDecorators(Injectable(), SetMetadata(EntityManagerSymbols.EventsTracker, {
|
|
2032
|
+
...props,
|
|
2033
|
+
}));
|
|
2034
|
+
|
|
2035
|
+
/******************************************************************************
|
|
2036
|
+
Copyright (c) Microsoft Corporation.
|
|
2037
|
+
|
|
2038
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
2039
|
+
purpose with or without fee is hereby granted.
|
|
2040
|
+
|
|
2041
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
2042
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
2043
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
2044
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
2045
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
2046
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
2047
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
2048
|
+
***************************************************************************** */
|
|
2049
|
+
|
|
2050
|
+
function __decorate(decorators, target, key, desc) {
|
|
2051
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2052
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2053
|
+
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;
|
|
2054
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
function __metadata(metadataKey, metadataValue) {
|
|
2058
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
2062
|
+
var e = new Error(message);
|
|
2063
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
2064
|
+
};
|
|
2065
|
+
|
|
2066
|
+
class NumericFacetItem {
|
|
2067
|
+
}
|
|
2068
|
+
__decorate([
|
|
2069
|
+
ApiProperty(),
|
|
2070
|
+
__metadata("design:type", Number)
|
|
2071
|
+
], NumericFacetItem.prototype, "value", void 0);
|
|
2072
|
+
__decorate([
|
|
2073
|
+
ApiProperty({ required: false }),
|
|
2074
|
+
__metadata("design:type", String)
|
|
2075
|
+
], NumericFacetItem.prototype, "name", void 0);
|
|
2076
|
+
__decorate([
|
|
2077
|
+
ApiProperty({ required: false }),
|
|
2078
|
+
__metadata("design:type", Number)
|
|
2079
|
+
], NumericFacetItem.prototype, "count", void 0);
|
|
2080
|
+
class NumericFacet {
|
|
2081
|
+
}
|
|
2082
|
+
__decorate([
|
|
2083
|
+
ApiProperty({ type: [NumericFacetItem] }),
|
|
2084
|
+
__metadata("design:type", Array)
|
|
2085
|
+
], NumericFacet.prototype, "items", void 0);
|
|
2086
|
+
class BooleanFacetItem {
|
|
2087
|
+
}
|
|
2088
|
+
__decorate([
|
|
2089
|
+
ApiProperty(),
|
|
2090
|
+
__metadata("design:type", Boolean)
|
|
2091
|
+
], BooleanFacetItem.prototype, "value", void 0);
|
|
2092
|
+
__decorate([
|
|
2093
|
+
ApiProperty({ required: false }),
|
|
2094
|
+
__metadata("design:type", String)
|
|
2095
|
+
], BooleanFacetItem.prototype, "name", void 0);
|
|
2096
|
+
__decorate([
|
|
2097
|
+
ApiProperty({ required: false }),
|
|
2098
|
+
__metadata("design:type", Number)
|
|
2099
|
+
], BooleanFacetItem.prototype, "count", void 0);
|
|
2100
|
+
class BooleanFacet {
|
|
2101
|
+
}
|
|
2102
|
+
__decorate([
|
|
2103
|
+
ApiProperty({ type: [BooleanFacetItem] }),
|
|
2104
|
+
__metadata("design:type", Array)
|
|
2105
|
+
], BooleanFacet.prototype, "items", void 0);
|
|
2106
|
+
class StringFacetItem {
|
|
2107
|
+
}
|
|
2108
|
+
__decorate([
|
|
2109
|
+
ApiProperty(),
|
|
2110
|
+
__metadata("design:type", String)
|
|
2111
|
+
], StringFacetItem.prototype, "value", void 0);
|
|
2112
|
+
__decorate([
|
|
2113
|
+
ApiProperty({ required: false }),
|
|
2114
|
+
__metadata("design:type", String)
|
|
2115
|
+
], StringFacetItem.prototype, "name", void 0);
|
|
2116
|
+
__decorate([
|
|
2117
|
+
ApiProperty({ required: false }),
|
|
2118
|
+
__metadata("design:type", Number)
|
|
2119
|
+
], StringFacetItem.prototype, "count", void 0);
|
|
2120
|
+
class StringFacet {
|
|
2121
|
+
}
|
|
2122
|
+
__decorate([
|
|
2123
|
+
ApiProperty({ type: [StringFacetItem] }),
|
|
2124
|
+
__metadata("design:type", Array)
|
|
2125
|
+
], StringFacet.prototype, "items", void 0);
|
|
2126
|
+
|
|
2127
|
+
const AuthenticationExtensionSymbols = {
|
|
2128
|
+
UserService: Symbol.for("WP.EXT:AUTHENTICATION.USER_SERVICE"),
|
|
2129
|
+
RolesService: Symbol.for("WP.EXT:AUTHENTICATION.ROLES_SERVICE"),
|
|
2130
|
+
UserRolesService: Symbol.for("WP.EXT:AUTHENTICATION.USER_ROLES_SERVICE"),
|
|
2131
|
+
};
|
|
2132
|
+
const AuthenticationGuardsSymbols = {
|
|
2133
|
+
Authenticated: "guard:authenticated",
|
|
2134
|
+
Public: "guard:public",
|
|
2135
|
+
Roles: "guard:roles",
|
|
2136
|
+
MemberOf: "guard:memberOf",
|
|
2137
|
+
};
|
|
2138
|
+
|
|
2139
|
+
const Public = () => SetMetadata(AuthenticationGuardsSymbols.Public, true);
|
|
2140
|
+
const Authenticated = () => SetMetadata(AuthenticationGuardsSymbols.Authenticated, true);
|
|
2141
|
+
const Roles = (...roles) => SetMetadata(AuthenticationGuardsSymbols.Roles, roles);
|
|
2142
|
+
const MemberOf = (...groups) => SetMetadata(AuthenticationGuardsSymbols.MemberOf, groups);
|
|
2143
|
+
const buildRolesGuard = ({ mainRole, inheritedRoles, }, options) => Roles(mainRole.uid, ...(options?.inheritRoles && inheritedRoles
|
|
2144
|
+
? inheritedRoles.map((role) => role.uid)
|
|
2145
|
+
: []));
|
|
2146
|
+
|
|
2147
|
+
const WpRolesService = () => applyDecorators(Injectable(), SetMetadata(AuthenticationExtensionSymbols.RolesService, true));
|
|
2148
|
+
|
|
2149
|
+
const WpUserService = () => applyDecorators(Injectable(), SetMetadata(AuthenticationExtensionSymbols.UserService, true));
|
|
2150
|
+
|
|
2151
|
+
const WpUserRolesService = () => applyDecorators(Injectable(), SetMetadata(AuthenticationExtensionSymbols.UserRolesService, true));
|
|
2152
|
+
|
|
2153
|
+
const AuthenticationEmailTemplates = {
|
|
2154
|
+
Registration: "registration",
|
|
2155
|
+
PasswordReset: "passwordReset",
|
|
2156
|
+
EmailVerify: "emailVerify",
|
|
2157
|
+
};
|
|
2158
|
+
|
|
2159
|
+
class AuthenticationError extends Error {
|
|
2160
|
+
constructor(message) {
|
|
2161
|
+
super(message);
|
|
2162
|
+
this.name = "AuthenticationError";
|
|
2173
2163
|
}
|
|
2174
2164
|
}
|
|
2175
|
-
class
|
|
2176
|
-
constructor(
|
|
2177
|
-
|
|
2178
|
-
this.
|
|
2179
|
-
this.replicas = new ReplicasConfiguration();
|
|
2180
|
-
this.connectors = new ConnectorsConfiguration();
|
|
2181
|
-
this.resolver = new EntityServiceLocator(locator, entityName);
|
|
2165
|
+
class InvalidCredentialsError extends AuthenticationError {
|
|
2166
|
+
constructor(message) {
|
|
2167
|
+
super(message);
|
|
2168
|
+
this.name = "InvalidCredentialsError";
|
|
2182
2169
|
}
|
|
2183
|
-
|
|
2184
|
-
|
|
2170
|
+
}
|
|
2171
|
+
class OperationTokenMismatchError extends AuthenticationError {
|
|
2172
|
+
constructor(message) {
|
|
2173
|
+
super(message);
|
|
2174
|
+
this.name = "OperationTokenMismatchError";
|
|
2185
2175
|
}
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
const AUTHENTICATION_EVENTS_NAMESPACE = "authentication";
|
|
2179
|
+
const AuthenticationEvents = {
|
|
2180
|
+
UserLogin: `${AUTHENTICATION_EVENTS_NAMESPACE}:user.login`,
|
|
2181
|
+
UserRegistrationStarted: `${AUTHENTICATION_EVENTS_NAMESPACE}:user.registrationStarted`,
|
|
2182
|
+
UserRegistrationCompleted: `${AUTHENTICATION_EVENTS_NAMESPACE}:user.registrationCompleted`,
|
|
2183
|
+
UserPasswordResetStarted: `${AUTHENTICATION_EVENTS_NAMESPACE}:user.passwordResetStarted`,
|
|
2184
|
+
UserPasswordResetCompleted: `${AUTHENTICATION_EVENTS_NAMESPACE}:user.passwordResetCompleted`,
|
|
2185
|
+
};
|
|
2186
|
+
|
|
2187
|
+
let AuthGuard = class AuthGuard {
|
|
2188
|
+
constructor(reflector) {
|
|
2189
|
+
this.reflector = reflector;
|
|
2198
2190
|
}
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2191
|
+
canActivate(context) {
|
|
2192
|
+
const isPublic = this.getIsPublic(context);
|
|
2193
|
+
if (isPublic) {
|
|
2194
|
+
return true;
|
|
2195
|
+
}
|
|
2196
|
+
const auth = this.getCurrentAuth(context);
|
|
2197
|
+
const allowedRoles = this.getAllowedRoles(context);
|
|
2198
|
+
if (allowedRoles) {
|
|
2199
|
+
return this.isRoleMatching(allowedRoles, auth?.roles ?? []);
|
|
2200
|
+
}
|
|
2201
|
+
const isForAllAuthenticated = this.getIsForAllAuthenticated(context);
|
|
2202
|
+
if (isForAllAuthenticated) {
|
|
2203
|
+
return !!auth?.user;
|
|
2204
|
+
}
|
|
2205
|
+
return false;
|
|
2203
2206
|
}
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
this.locator.registerCountAction(this.entityName, new EntitiesCountAction(this.resolver));
|
|
2207
|
-
return this;
|
|
2207
|
+
isRoleMatching(allowedRoles, userRoles) {
|
|
2208
|
+
return userRoles.some((role) => allowedRoles.includes(role.uid));
|
|
2208
2209
|
}
|
|
2209
|
-
|
|
2210
|
-
this.
|
|
2211
|
-
this.locator.registerExistsAction(this.entityName, new EntityExistsAction(this.resolver));
|
|
2212
|
-
return this;
|
|
2210
|
+
getIsForAllAuthenticated(context) {
|
|
2211
|
+
return this.getMetadata(AuthenticationGuardsSymbols.Authenticated, context);
|
|
2213
2212
|
}
|
|
2214
|
-
|
|
2215
|
-
this.
|
|
2216
|
-
this.locator.registerSearchAction(this.entityName, new EntitiesSearchAction(this.resolver));
|
|
2217
|
-
this.locator.registerQueryBuilder(this.entityName, queryBuilder);
|
|
2218
|
-
return this;
|
|
2213
|
+
getIsPublic(context) {
|
|
2214
|
+
return this.getMetadata(AuthenticationGuardsSymbols.Public, context);
|
|
2219
2215
|
}
|
|
2220
|
-
|
|
2221
|
-
this.
|
|
2222
|
-
this.locator.registerCreateAction(this.entityName, new EntityCreateAction(this.resolver));
|
|
2223
|
-
return this;
|
|
2216
|
+
getAllowedRoles(context) {
|
|
2217
|
+
return this.getMetadata(AuthenticationGuardsSymbols.Roles, context);
|
|
2224
2218
|
}
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2219
|
+
getCurrentAuth(context) {
|
|
2220
|
+
const request = context.switchToHttp()?.getRequest();
|
|
2221
|
+
return request?.auth?.user
|
|
2222
|
+
? {
|
|
2223
|
+
user: request.auth.user,
|
|
2224
|
+
roles: request.auth.roles,
|
|
2225
|
+
}
|
|
2226
|
+
: undefined;
|
|
2233
2227
|
}
|
|
2234
|
-
|
|
2235
|
-
this.
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
return this;
|
|
2228
|
+
getMetadata(symbol, context) {
|
|
2229
|
+
return this.reflector.getAllAndOverride(symbol, [
|
|
2230
|
+
context.getHandler(),
|
|
2231
|
+
context.getClass(),
|
|
2232
|
+
]);
|
|
2240
2233
|
}
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2234
|
+
};
|
|
2235
|
+
AuthGuard = __decorate([
|
|
2236
|
+
Injectable(),
|
|
2237
|
+
__metadata("design:paramtypes", [Reflector])
|
|
2238
|
+
], AuthGuard);
|
|
2239
|
+
|
|
2240
|
+
var UserCreationError;
|
|
2241
|
+
(function (UserCreationError) {
|
|
2242
|
+
UserCreationError["UserAlreadyExists"] = "userAlreadyExists";
|
|
2243
|
+
})(UserCreationError || (UserCreationError = {}));
|
|
2244
|
+
|
|
2245
|
+
const sessionStorage = new AsyncLocalStorage();
|
|
2246
|
+
|
|
2247
|
+
let AppSessionService = class AppSessionService {
|
|
2248
|
+
getValue(key) {
|
|
2249
|
+
return this.getSession().get(key);
|
|
2247
2250
|
}
|
|
2248
|
-
|
|
2249
|
-
this.
|
|
2250
|
-
return this;
|
|
2251
|
+
setValue(key, value) {
|
|
2252
|
+
this.getSession().set(key, value);
|
|
2251
2253
|
}
|
|
2252
|
-
|
|
2253
|
-
this.
|
|
2254
|
-
return this;
|
|
2254
|
+
clearValue(key) {
|
|
2255
|
+
this.getSession().set(key, undefined);
|
|
2255
2256
|
}
|
|
2256
|
-
|
|
2257
|
-
this.
|
|
2258
|
-
return this;
|
|
2257
|
+
getRequest() {
|
|
2258
|
+
return this.getSession().request;
|
|
2259
2259
|
}
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2260
|
+
getSession() {
|
|
2261
|
+
const store = sessionStorage.getStore();
|
|
2262
|
+
if (!store) {
|
|
2263
|
+
throw new Error("No active context found");
|
|
2264
|
+
}
|
|
2265
|
+
return store;
|
|
2263
2266
|
}
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
+
};
|
|
2268
|
+
AppSessionService = __decorate([
|
|
2269
|
+
Injectable()
|
|
2270
|
+
], AppSessionService);
|
|
2271
|
+
|
|
2272
|
+
let AppHashingService = class AppHashingService {
|
|
2273
|
+
async hash(value, salt) {
|
|
2274
|
+
return await hash(value, salt);
|
|
2267
2275
|
}
|
|
2268
|
-
|
|
2269
|
-
this.
|
|
2270
|
-
return this;
|
|
2276
|
+
async compare(hash, value, salt) {
|
|
2277
|
+
return (await this.hash(value, salt)) === hash;
|
|
2271
2278
|
}
|
|
2272
|
-
}
|
|
2273
|
-
|
|
2279
|
+
};
|
|
2280
|
+
AppHashingService = __decorate([
|
|
2281
|
+
Injectable()
|
|
2282
|
+
], AppHashingService);
|
|
2274
2283
|
|
|
2275
2284
|
let EntityManagerRegistry = class EntityManagerRegistry {
|
|
2276
2285
|
constructor() {
|
|
@@ -27278,5 +27287,5 @@ InMemoryEmailProvider = __decorate([
|
|
|
27278
27287
|
WpEmailProvider("in-memory")
|
|
27279
27288
|
], InMemoryEmailProvider);
|
|
27280
27289
|
|
|
27281
|
-
export { AUTHENTICATION_EVENTS_NAMESPACE, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsBucketModule, AwsEmailModule, AwsS2BucketError, AwsS3BucketProvider, AwsSesEmailTemplate, BooleanFacet, BooleanFacetItem, BucketItemType, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntitySeeder, EntitySerializationFormat, EntitySerializer, EventsService, InMemoryBucketProvider, InMemoryEmailProvider, InvalidCredentialsError, MemberOf, MissingEntityIdError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestEntitySerializer, NestPipelineTemplate, NestTypeOrmEntitySeeder, NestTypeOrmQueryBuilder, NestTypeOrmRepository, NumericFacet, NumericFacetItem, OperationTokenMismatchError, PLATFORM_EVENT_NAMESPACE, PipelineController, PipelineErrorType, PipelineStatus, PipelineStepErrorType, PipelinesBuilder, PipelinesRunner, PlatformEvents, Public, QueryBuilderBase, ReplicationMode, Roles, SendgridEmailModule, SendgridEmailTemplate, SortDirection, StringFacet, StringFacetItem, TrackingService, UserCreationError, UserRegistrationError, WpAppInitializer, WpAwsSesEmailTemplate, WpBucketProvider, WpEmailTemplate, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEntitySerializer, WpEventsTracker, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpUserRolesService, WpUserService, buildRolesGuard, createExpressFileResponse, getLocalizedText, newUuid, renderHandlebarsTemplate };
|
|
27290
|
+
export { AUTHENTICATION_EVENTS_NAMESPACE, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsBucketModule, AwsEmailModule, AwsS2BucketError, AwsS3BucketProvider, AwsSesEmailTemplate, BooleanFacet, BooleanFacetItem, BucketItemType, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntitySeeder, EntitySerializationFormat, EntitySerializer, EventsService, InMemoryBucketProvider, InMemoryEmailProvider, InvalidCredentialsError, MemberOf, MissingEntityIdError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestEntitySerializer, NestPipelineTemplate, NestTypeOrmEntitySeeder, NestTypeOrmQueryBuilder, NestTypeOrmRepository, NumericFacet, NumericFacetItem, OperationTokenMismatchError, PLATFORM_EVENT_NAMESPACE, PipelineController, PipelineErrorType, PipelineStatus, PipelineStepErrorType, PipelinesBuilder, PipelinesRunner, PlatformEvents, Public, QueryBuilderBase, ReplicationMode, Roles, SendgridEmailModule, SendgridEmailTemplate, SortDirection, StringFacet, StringFacetItem, TrackingService, UserCreationError, UserRegistrationError, WpAppInitializer, WpAwsSesEmailTemplate, WpBucketProvider, WpEmailTemplate, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEntitySerializer, WpEventsTracker, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpUserRolesService, WpUserService, buildRolesGuard, createContainer, createExpressFileResponse, getLocalizedText, newUuid, renderHandlebarsTemplate, toEntitiesImportInput };
|
|
27282
27291
|
//# sourceMappingURL=index.js.map
|