@punks/backend-entity-manager 0.0.213 → 0.0.215

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