@punks/backend-entity-manager 0.0.213 → 0.0.214

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 CHANGED
@@ -3420,6 +3420,12 @@ const WpEntityManager = (entityName, props = {}) => common.applyDecorators(commo
3420
3420
  const WpMediaProvider = (providerId) => common.applyDecorators(common.Injectable(), common.SetMetadata(EntityManagerSymbols.MediaProvider, {
3421
3421
  providerId,
3422
3422
  }));
3423
+ const WpMediaReferenceRepository = (providerId) => common.applyDecorators(common.Injectable(), common.SetMetadata(EntityManagerSymbols.MediaReferenceRepository, {
3424
+ providerId,
3425
+ }));
3426
+ const WpMediaFolderRepository = (providerId) => common.applyDecorators(common.Injectable(), common.SetMetadata(EntityManagerSymbols.MediaFolderRepository, {
3427
+ providerId,
3428
+ }));
3423
3429
 
3424
3430
  const WpEntityQueryBuilder = (entityName, props = {}) => common.applyDecorators(common.Injectable(), common.SetMetadata(EntityManagerSymbols.EntityQueryBuilder, {
3425
3431
  entityName,
@@ -23070,7 +23076,7 @@ AuthenticationMiddleware = __decorate([
23070
23076
  ], AuthenticationMiddleware);
23071
23077
 
23072
23078
  var AuthenticationModule_1;
23073
- const ModuleData$4 = {
23079
+ const ModuleData$5 = {
23074
23080
  imports: [exports.EntityManagerModule, jwt.JwtModule],
23075
23081
  providers: [
23076
23082
  AuthenticationServicesResolver,
@@ -23087,7 +23093,7 @@ exports.AuthenticationModule = AuthenticationModule_1 = class AuthenticationModu
23087
23093
  authSettings.initialize(input);
23088
23094
  return {
23089
23095
  module: AuthenticationModule_1,
23090
- ...ModuleData$4,
23096
+ ...ModuleData$5,
23091
23097
  };
23092
23098
  }
23093
23099
  configure(consumer) {
@@ -23100,7 +23106,7 @@ exports.AuthenticationModule = AuthenticationModule_1 = class AuthenticationModu
23100
23106
  };
23101
23107
  exports.AuthenticationModule = AuthenticationModule_1 = __decorate([
23102
23108
  common.Module({
23103
- ...ModuleData$4,
23109
+ ...ModuleData$5,
23104
23110
  })
23105
23111
  ], exports.AuthenticationModule);
23106
23112
 
@@ -23390,7 +23396,7 @@ class AwsS3BucketError extends Error {
23390
23396
 
23391
23397
  const awsBucketSettings = new AppInMemorySettings();
23392
23398
 
23393
- const createClient$2 = (settings) => new clientS3.S3Client({
23399
+ const createClient$3 = (settings) => new clientS3.S3Client({
23394
23400
  region: settings.region,
23395
23401
  credentials: settings.awsAccessKeyId && settings.awsSecretAccessKey
23396
23402
  ? {
@@ -23401,7 +23407,7 @@ const createClient$2 = (settings) => new clientS3.S3Client({
23401
23407
  });
23402
23408
  exports.AwsS3BucketProvider = class AwsS3BucketProvider {
23403
23409
  constructor() {
23404
- this.client = createClient$2(awsBucketSettings.value);
23410
+ this.client = createClient$3(awsBucketSettings.value);
23405
23411
  }
23406
23412
  async folderList(input) {
23407
23413
  try {
@@ -23557,7 +23563,7 @@ AwsS3FileProvider = __decorate([
23557
23563
  ], AwsS3FileProvider);
23558
23564
 
23559
23565
  var AwsBucketModule_1;
23560
- const ModuleData$3 = {
23566
+ const ModuleData$4 = {
23561
23567
  providers: [exports.AwsS3BucketProvider, AwsS3FileProvider],
23562
23568
  };
23563
23569
  exports.AwsBucketModule = AwsBucketModule_1 = class AwsBucketModule {
@@ -23565,13 +23571,13 @@ exports.AwsBucketModule = AwsBucketModule_1 = class AwsBucketModule {
23565
23571
  awsBucketSettings.initialize(input);
23566
23572
  return {
23567
23573
  module: AwsBucketModule_1,
23568
- ...ModuleData$3,
23574
+ ...ModuleData$4,
23569
23575
  };
23570
23576
  }
23571
23577
  };
23572
23578
  exports.AwsBucketModule = AwsBucketModule_1 = __decorate([
23573
23579
  common.Module({
23574
- ...ModuleData$3,
23580
+ ...ModuleData$4,
23575
23581
  })
23576
23582
  ], exports.AwsBucketModule);
23577
23583
 
@@ -28656,7 +28662,7 @@ const renderHandlebarsTemplate = (input) => {
28656
28662
 
28657
28663
  const newUuid = backendCore.newUuid;
28658
28664
 
28659
- const createClient$1 = (settings) => new clientSes.SESClient({
28665
+ const createClient$2 = (settings) => new clientSes.SESClient({
28660
28666
  region: settings.region,
28661
28667
  credentials: settings.awsAccessKeyId && settings.awsSecretAccessKey
28662
28668
  ? {
@@ -28667,7 +28673,7 @@ const createClient$1 = (settings) => new clientSes.SESClient({
28667
28673
  });
28668
28674
  let AwsSesEmailProvider = class AwsSesEmailProvider {
28669
28675
  constructor() {
28670
- this.client = createClient$1(awsSesSettings.value);
28676
+ this.client = createClient$2(awsSesSettings.value);
28671
28677
  }
28672
28678
  async sendTemplatedEmail(input, template) {
28673
28679
  const processedPayload = await template.processPayload(input.payload);
@@ -28715,7 +28721,7 @@ AwsSesEmailProvider = __decorate([
28715
28721
  ], AwsSesEmailProvider);
28716
28722
 
28717
28723
  var AwsEmailModule_1;
28718
- const ModuleData$2 = {
28724
+ const ModuleData$3 = {
28719
28725
  providers: [AwsSesEmailProvider],
28720
28726
  };
28721
28727
  exports.AwsEmailModule = AwsEmailModule_1 = class AwsEmailModule {
@@ -28723,13 +28729,13 @@ exports.AwsEmailModule = AwsEmailModule_1 = class AwsEmailModule {
28723
28729
  awsSesSettings.initialize(input);
28724
28730
  return {
28725
28731
  module: AwsEmailModule_1,
28726
- ...ModuleData$2,
28732
+ ...ModuleData$3,
28727
28733
  };
28728
28734
  }
28729
28735
  };
28730
28736
  exports.AwsEmailModule = AwsEmailModule_1 = __decorate([
28731
28737
  common.Module({
28732
- ...ModuleData$2,
28738
+ ...ModuleData$3,
28733
28739
  })
28734
28740
  ], exports.AwsEmailModule);
28735
28741
 
@@ -28882,7 +28888,7 @@ SendgridEmailProvider = __decorate([
28882
28888
  ], SendgridEmailProvider);
28883
28889
 
28884
28890
  var SendgridEmailModule_1;
28885
- const ModuleData$1 = {
28891
+ const ModuleData$2 = {
28886
28892
  imports: [exports.EntityManagerModule],
28887
28893
  providers: [SendgridEmailProvider],
28888
28894
  };
@@ -28891,13 +28897,13 @@ exports.SendgridEmailModule = SendgridEmailModule_1 = class SendgridEmailModule
28891
28897
  sendgridSettings.initialize(input);
28892
28898
  return {
28893
28899
  module: SendgridEmailModule_1,
28894
- ...ModuleData$1,
28900
+ ...ModuleData$2,
28895
28901
  };
28896
28902
  }
28897
28903
  };
28898
28904
  exports.SendgridEmailModule = SendgridEmailModule_1 = __decorate([
28899
28905
  common.Module({
28900
- ...ModuleData$1,
28906
+ ...ModuleData$2,
28901
28907
  })
28902
28908
  ], exports.SendgridEmailModule);
28903
28909
 
@@ -28926,6 +28932,158 @@ exports.InMemoryEmailProvider = __decorate([
28926
28932
  WpEmailProvider("in-memory")
28927
28933
  ], exports.InMemoryEmailProvider);
28928
28934
 
28935
+ class AwsS3MediaError extends Error {
28936
+ constructor(message) {
28937
+ super(message);
28938
+ this.name = "AwsS3MediaError";
28939
+ }
28940
+ }
28941
+
28942
+ const awsMediaSettings = new AppInMemorySettings();
28943
+
28944
+ const createClient$1 = (settings) => new clientS3.S3Client({
28945
+ region: settings.region,
28946
+ credentials: settings.awsAccessKeyId && settings.awsSecretAccessKey
28947
+ ? {
28948
+ accessKeyId: settings.awsAccessKeyId,
28949
+ secretAccessKey: settings.awsSecretAccessKey,
28950
+ }
28951
+ : undefined,
28952
+ });
28953
+ const buildRef = (bucket, path) => {
28954
+ return `s3://${bucket}/${path}`;
28955
+ };
28956
+ const parseRef = (ref) => {
28957
+ const parts = ref.split("/");
28958
+ return {
28959
+ bucket: parts[2],
28960
+ path: parts.slice(3).join("/"),
28961
+ };
28962
+ };
28963
+ exports.AwsS3MediaProvider = class AwsS3MediaProvider {
28964
+ constructor() {
28965
+ this.client = createClient$1(awsMediaSettings.value);
28966
+ }
28967
+ getFileName(input) {
28968
+ const parsedRef = parseRef(input.ref);
28969
+ return parsedRef.path.split("/").pop() ?? "";
28970
+ }
28971
+ async mediaUpload(input) {
28972
+ try {
28973
+ const path = this.buildUploadPath(input.fileName);
28974
+ const bucket = awsMediaSettings.value.defaultBucket;
28975
+ await this.client.send(new clientS3.PutObjectCommand({
28976
+ Bucket: bucket,
28977
+ Key: path,
28978
+ Body: input.content,
28979
+ ContentType: input.contentType,
28980
+ ACL: "public-read",
28981
+ }));
28982
+ return {
28983
+ ref: buildRef(bucket, path),
28984
+ };
28985
+ }
28986
+ catch (e) {
28987
+ throw new AwsS3MediaError(`AwsS3MediaProvider | mediaUpload | ${input.fileName} | Error -> ${e.message}`);
28988
+ }
28989
+ }
28990
+ async mediaDelete(input) {
28991
+ try {
28992
+ const parsedRef = parseRef(input.ref);
28993
+ await this.client.send(new clientS3.DeleteObjectCommand({
28994
+ Bucket: parsedRef.bucket,
28995
+ Key: parsedRef.path,
28996
+ }));
28997
+ }
28998
+ catch (e) {
28999
+ throw new AwsS3MediaError(`AwsS3MediaProvider | mediaDelete | ${input.ref} | Error -> ${e.message}`);
29000
+ }
29001
+ }
29002
+ async mediaDownload(input) {
29003
+ try {
29004
+ const parsedRef = parseRef(input.ref);
29005
+ const result = await this.client.send(new clientS3.GetObjectCommand({
29006
+ Bucket: parsedRef.bucket,
29007
+ Key: parsedRef.path,
29008
+ }));
29009
+ return result.Body;
29010
+ }
29011
+ catch (e) {
29012
+ throw new AwsS3MediaError(`AwsS3MediaProvider | mediaDownload | ${input.ref} | Error -> ${e.message}`);
29013
+ }
29014
+ }
29015
+ buildUploadPath(fileName) {
29016
+ return [
29017
+ awsMediaSettings.value.paths.filesUpload,
29018
+ createDayPath$1(new Date()),
29019
+ backendCore.newUuid(),
29020
+ fileName,
29021
+ ].join("/");
29022
+ }
29023
+ };
29024
+ exports.AwsS3MediaProvider = __decorate([
29025
+ WpMediaProvider("awsS3"),
29026
+ __metadata("design:paramtypes", [])
29027
+ ], exports.AwsS3MediaProvider);
29028
+
29029
+ var AwsS3MediaModule_1;
29030
+ const ModuleData$1 = {
29031
+ providers: [exports.AwsS3MediaProvider],
29032
+ };
29033
+ exports.AwsS3MediaModule = AwsS3MediaModule_1 = class AwsS3MediaModule {
29034
+ static forRoot(input) {
29035
+ awsMediaSettings.initialize(input);
29036
+ return {
29037
+ module: AwsS3MediaModule_1,
29038
+ ...ModuleData$1,
29039
+ };
29040
+ }
29041
+ };
29042
+ exports.AwsS3MediaModule = AwsS3MediaModule_1 = __decorate([
29043
+ common.Module({
29044
+ ...ModuleData$1,
29045
+ })
29046
+ ], exports.AwsS3MediaModule);
29047
+
29048
+ exports.InMemoryMediaProvider = class InMemoryMediaProvider {
29049
+ constructor() {
29050
+ this.provider = new exports.InMemoryBucketProvider();
29051
+ }
29052
+ async mediaUpload(input) {
29053
+ const path = [backendCore.newUuid(), input.fileName].join("/");
29054
+ await this.provider.fileUpload({
29055
+ bucket: "default",
29056
+ content: input.content,
29057
+ contentType: input.contentType,
29058
+ filePath: path,
29059
+ });
29060
+ return {
29061
+ ref: `inMemory://${path}`,
29062
+ };
29063
+ }
29064
+ async mediaDelete(input) {
29065
+ await this.provider.fileDelete({
29066
+ bucket: "default",
29067
+ filePath: input.ref.split("://")[1],
29068
+ });
29069
+ }
29070
+ async mediaDownload(input) {
29071
+ return this.provider.fileDownload({
29072
+ bucket: "default",
29073
+ filePath: input.ref.split("://")[1],
29074
+ });
29075
+ }
29076
+ getFileName(input) {
29077
+ return input.ref.split("/").pop() ?? "";
29078
+ }
29079
+ getProviderId() {
29080
+ return "inMemory";
29081
+ }
29082
+ };
29083
+ exports.InMemoryMediaProvider = __decorate([
29084
+ WpMediaProvider("inMemory")
29085
+ ], exports.InMemoryMediaProvider);
29086
+
28929
29087
  const awsSecretsSettings = new AppInMemorySettings();
28930
29088
 
28931
29089
  const WpSecretsProvider = (providerId) => common.applyDecorators(common.Injectable(), common.SetMetadata(EntityManagerSymbols.SecretsProvider, {
@@ -29131,6 +29289,7 @@ exports.AuthenticationError = AuthenticationError;
29131
29289
  exports.AuthenticationEvents = AuthenticationEvents;
29132
29290
  exports.AuthenticationExtensionSymbols = AuthenticationExtensionSymbols;
29133
29291
  exports.AwsS3BucketError = AwsS3BucketError;
29292
+ exports.AwsS3MediaError = AwsS3MediaError;
29134
29293
  exports.AwsSesEmailTemplate = AwsSesEmailTemplate;
29135
29294
  exports.CurrentUser = CurrentUser;
29136
29295
  exports.EntityManagerConfigurationError = EntityManagerConfigurationError;
@@ -29193,7 +29352,9 @@ exports.WpEventsTracker = WpEventsTracker;
29193
29352
  exports.WpFileProvider = WpFileProvider;
29194
29353
  exports.WpFileReferenceRepository = WpFileReferenceRepository;
29195
29354
  exports.WpGlobalAuthenticationMiddleware = WpGlobalAuthenticationMiddleware;
29355
+ exports.WpMediaFolderRepository = WpMediaFolderRepository;
29196
29356
  exports.WpMediaProvider = WpMediaProvider;
29357
+ exports.WpMediaReferenceRepository = WpMediaReferenceRepository;
29197
29358
  exports.WpPermissionsService = WpPermissionsService;
29198
29359
  exports.WpPipeline = WpPipeline;
29199
29360
  exports.WpRolesService = WpRolesService;