@punks/backend-entity-manager 0.0.509 → 0.0.511

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
@@ -23,6 +23,7 @@ var swagger = require('@nestjs/swagger');
23
23
  var clientS3 = require('@aws-sdk/client-s3');
24
24
  var s3RequestPresigner = require('@aws-sdk/s3-request-presigner');
25
25
  var clientSes = require('@aws-sdk/client-ses');
26
+ var nodemailer = require('nodemailer');
26
27
  var mail = require('@sendgrid/mail');
27
28
  var clientBatch = require('@aws-sdk/client-batch');
28
29
  var clientCloudwatchLogs = require('@aws-sdk/client-cloudwatch-logs');
@@ -37,8 +38,27 @@ var clientSecretsManager = require('@aws-sdk/client-secrets-manager');
37
38
 
38
39
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
39
40
 
41
+ function _interopNamespace(e) {
42
+ if (e && e.__esModule) return e;
43
+ var n = Object.create(null);
44
+ if (e) {
45
+ Object.keys(e).forEach(function (k) {
46
+ if (k !== 'default') {
47
+ var d = Object.getOwnPropertyDescriptor(e, k);
48
+ Object.defineProperty(n, k, d.get ? d : {
49
+ enumerable: true,
50
+ get: function () { return e[k]; }
51
+ });
52
+ }
53
+ });
54
+ }
55
+ n["default"] = e;
56
+ return Object.freeze(n);
57
+ }
58
+
40
59
  var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
41
60
  var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
61
+ var nodemailer__namespace = /*#__PURE__*/_interopNamespace(nodemailer);
42
62
  var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
43
63
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
44
64
  var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
@@ -3191,6 +3211,83 @@ class DynamoDbCacheInstance {
3191
3211
  }
3192
3212
  }
3193
3213
 
3214
+ class InMemoryCacheInstance {
3215
+ constructor(instanceName) {
3216
+ this.instanceName = instanceName;
3217
+ this.store = new Map();
3218
+ }
3219
+ async getEntries() {
3220
+ const now = new Date();
3221
+ const entries = [];
3222
+ for (const entry of this.store.values()) {
3223
+ if (!this.isExpired(entry, now)) {
3224
+ entries.push(this.toCacheEntryInfo(entry));
3225
+ }
3226
+ }
3227
+ return entries;
3228
+ }
3229
+ async getEntry(key) {
3230
+ const entry = this.store.get(key);
3231
+ if (!entry || this.isExpired(entry, new Date())) {
3232
+ if (entry) {
3233
+ this.store.delete(key);
3234
+ }
3235
+ return undefined;
3236
+ }
3237
+ return this.toCacheEntryDetail(entry);
3238
+ }
3239
+ async get(key) {
3240
+ const item = await this.getEntry(key);
3241
+ return item?.data;
3242
+ }
3243
+ async set(key, input) {
3244
+ const now = Date.now();
3245
+ this.store.set(key, {
3246
+ key,
3247
+ data: input.value,
3248
+ createdOn: now,
3249
+ updatedOn: now,
3250
+ expiration: backendCore.addTime(new Date(), input.ttl).getTime(),
3251
+ });
3252
+ }
3253
+ async retrieve(key, input) {
3254
+ const item = await this.get(key);
3255
+ if (item !== undefined) {
3256
+ return item;
3257
+ }
3258
+ const value = await input.valueFactory();
3259
+ await this.set(key, { value, ttl: input.ttl });
3260
+ return value;
3261
+ }
3262
+ async delete(key) {
3263
+ this.store.delete(key);
3264
+ }
3265
+ async clear() {
3266
+ this.store.clear();
3267
+ }
3268
+ getInstanceName() {
3269
+ return this.instanceName;
3270
+ }
3271
+ isExpired(entry, when) {
3272
+ return entry.expiration < when.getTime();
3273
+ }
3274
+ toCacheEntryInfo(entry) {
3275
+ return {
3276
+ instanceName: this.instanceName,
3277
+ key: entry.key,
3278
+ expiration: new Date(entry.expiration),
3279
+ createdOn: new Date(entry.createdOn),
3280
+ updatedOn: new Date(entry.updatedOn),
3281
+ };
3282
+ }
3283
+ toCacheEntryDetail(entry) {
3284
+ return {
3285
+ ...this.toCacheEntryInfo(entry),
3286
+ data: entry.data,
3287
+ };
3288
+ }
3289
+ }
3290
+
3194
3291
  class TypeormCacheInstance {
3195
3292
  constructor(instanceName) {
3196
3293
  this.instanceName = instanceName;
@@ -41331,6 +41428,7 @@ let AwsSesEmailProvider = class AwsSesEmailProvider {
41331
41428
  subjectTemplate: input.subjectTemplate,
41332
41429
  bodyTemplate: input.bodyTemplate,
41333
41430
  payload: input.payload,
41431
+ attachments: input.attachments,
41334
41432
  });
41335
41433
  }
41336
41434
  return;
@@ -41343,31 +41441,72 @@ let AwsSesEmailProvider = class AwsSesEmailProvider {
41343
41441
  subjectTemplate: input.subjectTemplate,
41344
41442
  bodyTemplate: input.bodyTemplate,
41345
41443
  payload: input.payload,
41444
+ attachments: input.attachments,
41346
41445
  });
41347
41446
  }
41348
- async invokeEmailSend({ from, to, cc, bcc, subjectTemplate, bodyTemplate, payload, }) {
41349
- await this.client.send(new clientSes.SendEmailCommand({
41350
- Source: from,
41351
- Destination: {
41352
- ToAddresses: to ?? [],
41353
- CcAddresses: cc ?? [],
41354
- BccAddresses: bcc ?? [],
41355
- },
41356
- Message: {
41357
- Subject: {
41358
- Data: renderHandlebarsTemplate({
41359
- template: subjectTemplate,
41360
- context: payload,
41361
- }),
41447
+ async invokeEmailSend({ from, to, cc, bcc, subjectTemplate, bodyTemplate, payload, attachments, }) {
41448
+ const subject = renderHandlebarsTemplate({
41449
+ template: subjectTemplate,
41450
+ context: payload,
41451
+ });
41452
+ const htmlBody = renderHandlebarsTemplate({
41453
+ template: bodyTemplate,
41454
+ context: payload,
41455
+ });
41456
+ // If no attachments, use the simpler SendEmailCommand
41457
+ if (!attachments || attachments.length === 0) {
41458
+ await this.client.send(new clientSes.SendEmailCommand({
41459
+ Source: from,
41460
+ Destination: {
41461
+ ToAddresses: to ?? [],
41462
+ CcAddresses: cc ?? [],
41463
+ BccAddresses: bcc ?? [],
41362
41464
  },
41363
- Body: {
41364
- Html: {
41365
- Data: renderHandlebarsTemplate({
41366
- template: bodyTemplate,
41367
- context: payload,
41368
- }),
41465
+ Message: {
41466
+ Subject: {
41467
+ Data: subject,
41468
+ },
41469
+ Body: {
41470
+ Html: {
41471
+ Data: htmlBody,
41472
+ },
41369
41473
  },
41370
41474
  },
41475
+ }));
41476
+ return;
41477
+ }
41478
+ // // With attachments, use SendRawEmailCommand
41479
+ // const rawMessage = this.buildRawEmailMessage({
41480
+ // from,
41481
+ // to: to ?? [],
41482
+ // cc: cc ?? [],
41483
+ // bcc: bcc ?? [],
41484
+ // subject,
41485
+ // htmlBody,
41486
+ // attachments,
41487
+ // })
41488
+ const message = {
41489
+ from: from,
41490
+ to: to ?? [],
41491
+ cc: cc ?? [],
41492
+ bcc: bcc ?? [],
41493
+ subject: subject,
41494
+ html: htmlBody,
41495
+ attachments: attachments.map((attachment) => ({
41496
+ filename: attachment.filename,
41497
+ content: attachment.content,
41498
+ contentType: attachment.type,
41499
+ })),
41500
+ };
41501
+ const transporter = nodemailer__namespace.createTransport({
41502
+ streamTransport: true,
41503
+ newline: "unix",
41504
+ buffer: true,
41505
+ });
41506
+ const rawEmail = await transporter.sendMail(message);
41507
+ await this.client.send(new clientSes.SendRawEmailCommand({
41508
+ RawMessage: {
41509
+ Data: rawEmail.message,
41371
41510
  },
41372
41511
  }));
41373
41512
  }
@@ -45526,6 +45665,7 @@ exports.EntitySerializer = EntitySerializer;
45526
45665
  exports.EntitySnapshotService = EntitySnapshotService;
45527
45666
  exports.ExclusiveOperationResult = ExclusiveOperationResult;
45528
45667
  exports.IEntityVersionsCursor = IEntityVersionsCursor;
45668
+ exports.InMemoryCacheInstance = InMemoryCacheInstance;
45529
45669
  exports.InvalidCredentialsError = InvalidCredentialsError;
45530
45670
  exports.JobInstance = JobInstance;
45531
45671
  exports.JobSchedule = JobSchedule;