@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.
@@ -0,0 +1,2 @@
1
+ export { InMemoryCacheInstance } from "./instance";
2
+ export { InMemoryCacheEntry } from "./types";
@@ -0,0 +1,23 @@
1
+ import { CacheEntryDetail, CacheEntryInfo, CacheTtl, ICacheInstance } from "../../../abstractions/cache";
2
+ export declare abstract class InMemoryCacheInstance implements ICacheInstance {
3
+ protected readonly instanceName: string;
4
+ private readonly store;
5
+ constructor(instanceName: string);
6
+ getEntries(): Promise<CacheEntryInfo[]>;
7
+ getEntry(key: string): Promise<CacheEntryDetail | undefined>;
8
+ get<T>(key: string): Promise<T | undefined>;
9
+ set<T>(key: string, input: {
10
+ value: T;
11
+ ttl: CacheTtl;
12
+ }): Promise<void>;
13
+ retrieve<T>(key: string, input: {
14
+ ttl: CacheTtl;
15
+ valueFactory: () => Promise<T>;
16
+ }): Promise<T>;
17
+ delete(key: string): Promise<void>;
18
+ clear(): Promise<void>;
19
+ getInstanceName(): string;
20
+ private isExpired;
21
+ private toCacheEntryInfo;
22
+ private toCacheEntryDetail;
23
+ }
@@ -0,0 +1,7 @@
1
+ export type InMemoryCacheEntry = {
2
+ key: string;
3
+ data: unknown;
4
+ createdOn: number;
5
+ updatedOn: number;
6
+ expiration: number;
7
+ };
@@ -1,2 +1,3 @@
1
1
  export * from "./dynamo";
2
+ export * from "./in-memory";
2
3
  export * from "./typeorm";
package/dist/esm/index.js CHANGED
@@ -18,7 +18,8 @@ import require$$1 from 'fs';
18
18
  import { ApiProperty } from '@nestjs/swagger';
19
19
  import { ListObjectsCommand, PutObjectCommand, GetObjectCommand, DeleteObjectCommand, CopyObjectCommand, S3Client } from '@aws-sdk/client-s3';
20
20
  import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
21
- import { SendEmailCommand, SESClient } from '@aws-sdk/client-ses';
21
+ import { SendEmailCommand, SendRawEmailCommand, SESClient } from '@aws-sdk/client-ses';
22
+ import * as nodemailer from 'nodemailer';
22
23
  import { MailService } from '@sendgrid/mail';
23
24
  import { BatchClient, CancelJobCommand, ListJobsCommand, PlatformCapability, SubmitJobCommand, DeregisterJobDefinitionCommand, RegisterJobDefinitionCommand, JobDefinitionType, ResourceType, AssignPublicIp, DescribeJobDefinitionsCommand, CreateJobQueueCommand, UpdateJobQueueCommand, DescribeJobQueuesCommand, JobStatus as JobStatus$1 } from '@aws-sdk/client-batch';
24
25
  import { CloudWatchLogsClient, DescribeLogGroupsCommand, CreateLogGroupCommand } from '@aws-sdk/client-cloudwatch-logs';
@@ -3176,6 +3177,83 @@ class DynamoDbCacheInstance {
3176
3177
  }
3177
3178
  }
3178
3179
 
3180
+ class InMemoryCacheInstance {
3181
+ constructor(instanceName) {
3182
+ this.instanceName = instanceName;
3183
+ this.store = new Map();
3184
+ }
3185
+ async getEntries() {
3186
+ const now = new Date();
3187
+ const entries = [];
3188
+ for (const entry of this.store.values()) {
3189
+ if (!this.isExpired(entry, now)) {
3190
+ entries.push(this.toCacheEntryInfo(entry));
3191
+ }
3192
+ }
3193
+ return entries;
3194
+ }
3195
+ async getEntry(key) {
3196
+ const entry = this.store.get(key);
3197
+ if (!entry || this.isExpired(entry, new Date())) {
3198
+ if (entry) {
3199
+ this.store.delete(key);
3200
+ }
3201
+ return undefined;
3202
+ }
3203
+ return this.toCacheEntryDetail(entry);
3204
+ }
3205
+ async get(key) {
3206
+ const item = await this.getEntry(key);
3207
+ return item?.data;
3208
+ }
3209
+ async set(key, input) {
3210
+ const now = Date.now();
3211
+ this.store.set(key, {
3212
+ key,
3213
+ data: input.value,
3214
+ createdOn: now,
3215
+ updatedOn: now,
3216
+ expiration: addTime(new Date(), input.ttl).getTime(),
3217
+ });
3218
+ }
3219
+ async retrieve(key, input) {
3220
+ const item = await this.get(key);
3221
+ if (item !== undefined) {
3222
+ return item;
3223
+ }
3224
+ const value = await input.valueFactory();
3225
+ await this.set(key, { value, ttl: input.ttl });
3226
+ return value;
3227
+ }
3228
+ async delete(key) {
3229
+ this.store.delete(key);
3230
+ }
3231
+ async clear() {
3232
+ this.store.clear();
3233
+ }
3234
+ getInstanceName() {
3235
+ return this.instanceName;
3236
+ }
3237
+ isExpired(entry, when) {
3238
+ return entry.expiration < when.getTime();
3239
+ }
3240
+ toCacheEntryInfo(entry) {
3241
+ return {
3242
+ instanceName: this.instanceName,
3243
+ key: entry.key,
3244
+ expiration: new Date(entry.expiration),
3245
+ createdOn: new Date(entry.createdOn),
3246
+ updatedOn: new Date(entry.updatedOn),
3247
+ };
3248
+ }
3249
+ toCacheEntryDetail(entry) {
3250
+ return {
3251
+ ...this.toCacheEntryInfo(entry),
3252
+ data: entry.data,
3253
+ };
3254
+ }
3255
+ }
3256
+
3179
3257
  class TypeormCacheInstance {
3180
3258
  constructor(instanceName) {
3181
3259
  this.instanceName = instanceName;
@@ -41316,6 +41394,7 @@ let AwsSesEmailProvider = class AwsSesEmailProvider {
41316
41394
  subjectTemplate: input.subjectTemplate,
41317
41395
  bodyTemplate: input.bodyTemplate,
41318
41396
  payload: input.payload,
41397
+ attachments: input.attachments,
41319
41398
  });
41320
41399
  }
41321
41400
  return;
@@ -41328,31 +41407,72 @@ let AwsSesEmailProvider = class AwsSesEmailProvider {
41328
41407
  subjectTemplate: input.subjectTemplate,
41329
41408
  bodyTemplate: input.bodyTemplate,
41330
41409
  payload: input.payload,
41410
+ attachments: input.attachments,
41331
41411
  });
41332
41412
  }
41333
- async invokeEmailSend({ from, to, cc, bcc, subjectTemplate, bodyTemplate, payload, }) {
41334
- await this.client.send(new SendEmailCommand({
41335
- Source: from,
41336
- Destination: {
41337
- ToAddresses: to ?? [],
41338
- CcAddresses: cc ?? [],
41339
- BccAddresses: bcc ?? [],
41340
- },
41341
- Message: {
41342
- Subject: {
41343
- Data: renderHandlebarsTemplate({
41344
- template: subjectTemplate,
41345
- context: payload,
41346
- }),
41413
+ async invokeEmailSend({ from, to, cc, bcc, subjectTemplate, bodyTemplate, payload, attachments, }) {
41414
+ const subject = renderHandlebarsTemplate({
41415
+ template: subjectTemplate,
41416
+ context: payload,
41417
+ });
41418
+ const htmlBody = renderHandlebarsTemplate({
41419
+ template: bodyTemplate,
41420
+ context: payload,
41421
+ });
41422
+ // If no attachments, use the simpler SendEmailCommand
41423
+ if (!attachments || attachments.length === 0) {
41424
+ await this.client.send(new SendEmailCommand({
41425
+ Source: from,
41426
+ Destination: {
41427
+ ToAddresses: to ?? [],
41428
+ CcAddresses: cc ?? [],
41429
+ BccAddresses: bcc ?? [],
41347
41430
  },
41348
- Body: {
41349
- Html: {
41350
- Data: renderHandlebarsTemplate({
41351
- template: bodyTemplate,
41352
- context: payload,
41353
- }),
41431
+ Message: {
41432
+ Subject: {
41433
+ Data: subject,
41434
+ },
41435
+ Body: {
41436
+ Html: {
41437
+ Data: htmlBody,
41438
+ },
41354
41439
  },
41355
41440
  },
41441
+ }));
41442
+ return;
41443
+ }
41444
+ // // With attachments, use SendRawEmailCommand
41445
+ // const rawMessage = this.buildRawEmailMessage({
41446
+ // from,
41447
+ // to: to ?? [],
41448
+ // cc: cc ?? [],
41449
+ // bcc: bcc ?? [],
41450
+ // subject,
41451
+ // htmlBody,
41452
+ // attachments,
41453
+ // })
41454
+ const message = {
41455
+ from: from,
41456
+ to: to ?? [],
41457
+ cc: cc ?? [],
41458
+ bcc: bcc ?? [],
41459
+ subject: subject,
41460
+ html: htmlBody,
41461
+ attachments: attachments.map((attachment) => ({
41462
+ filename: attachment.filename,
41463
+ content: attachment.content,
41464
+ contentType: attachment.type,
41465
+ })),
41466
+ };
41467
+ const transporter = nodemailer.createTransport({
41468
+ streamTransport: true,
41469
+ newline: "unix",
41470
+ buffer: true,
41471
+ });
41472
+ const rawEmail = await transporter.sendMail(message);
41473
+ await this.client.send(new SendRawEmailCommand({
41474
+ RawMessage: {
41475
+ Data: rawEmail.message,
41356
41476
  },
41357
41477
  }));
41358
41478
  }
@@ -45481,5 +45601,5 @@ class TestingAppSessionService {
45481
45601
  }
45482
45602
  }
45483
45603
 
45484
- export { AUTHENTICATION_EVENTS_NAMESPACE, ApiKeyAccess, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSession, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsBucketModule, AwsDynamoDbModule, AwsEmailModule, AwsJobsModule, AwsS3BucketError, AwsS3BucketProvider, AwsS3MediaError, AwsS3MediaModule, AwsS3MediaProvider, AwsSecretsModule, AwsSecretsProvider, AwsSesEmailTemplate, BucketItemType, CacheService, ConnectorMode, CurrentUser, CustomDiscoveryModule, CustomDiscoveryService, DataExportService, DataSerializationFormat, DataSheetsBuilder, DataSheetsExporterService, DynamoDbCacheInstance, DynamoDbCollection, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntityParseResult, EntityParseValidationError, EntitySeeder, EntitySerializationFormat, EntitySerializer, EntitySnapshotService, EntityVersionOperation, EventsService, ExclusiveOperationResult, FilesManager, IEntityVersionsCursor, InMemoryBucketProvider, InMemoryEmailProvider, InMemoryFileProvider, InMemoryMediaProvider, InMemorySecretsProvider, InvalidCredentialsError, InvalidEntityHandling, JobConcurrency, JobInstance, JobProviderState, JobRunType, JobSchedule, JobStatus, JobsModule, JobsService, LockNotFoundError, MediaLibraryService, MemberOf, MissingEntityIdError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestEntitySerializer, NestEntitySnapshotService, NestPipelineTemplate, NestTypeOrmEntitySeeder, NestTypeOrmQueryBuilder, NestTypeOrmRepository, OperationLockService, OperationTokenMismatchError, PLATFORM_EVENT_NAMESPACE, Permissions, PipelineController, PipelineErrorType, PipelineInvocationError, PipelineStatus, PipelineStepErrorType, PipelinesBuilder, PipelinesRunner, PlatformEvents, Public, QueryBuilderBase, QueryBuilderOperation, ReplicationMode, Roles, SanityMediaError, SanityMediaModule, SanityMediaProvider, SecretsService, SendgridEmailModule, SendgridEmailTemplate, SortDirection, TaskConcurrency, TaskRunType, TasksModule, TasksService, TestingAppSessionService, TrackingService, TypeOrmQueryBuilder, TypeOrmRepository, TypeormCacheInstance, TypeormOperationLockRepository, UserCreationError, UserRegistrationError, WpApiKeysService, WpAppInitializer, WpAwsSesEmailTemplate, WpBucketProvider, WpCacheInstance, WpEmailLogger, WpEmailProvider, WpEmailTemplate, WpEmailTemplateMiddleware, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConnectorMapper, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEntitySerializer, WpEntitySnapshotService, WpEntityVersioningProvider, WpEventsTracker, WpFileProvider, WpFileReferenceRepository, WpGlobalAuthenticationMiddleware, WpMediaFolderRepository, WpMediaProvider, WpMediaReferenceRepository, WpPermissionsService, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpTask, WpUserRolesService, WpUserService, awsBatchSettings, buildPermissionsGuard, buildProviderToken, buildRolesGuard, createContainer, createExpressFileResponse, fieldEmailValidator, fieldNumericValidator, fieldOptionValidator, fieldOptionsValidator, fieldRequiredValidator, fieldTextValidator, getEntityManagerProviderToken, getLocalizedText, newUuid, renderHandlebarsTemplate, sessionStorage, toEntitiesImportInput };
45604
+ export { AUTHENTICATION_EVENTS_NAMESPACE, ApiKeyAccess, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSession, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsBucketModule, AwsDynamoDbModule, AwsEmailModule, AwsJobsModule, AwsS3BucketError, AwsS3BucketProvider, AwsS3MediaError, AwsS3MediaModule, AwsS3MediaProvider, AwsSecretsModule, AwsSecretsProvider, AwsSesEmailTemplate, BucketItemType, CacheService, ConnectorMode, CurrentUser, CustomDiscoveryModule, CustomDiscoveryService, DataExportService, DataSerializationFormat, DataSheetsBuilder, DataSheetsExporterService, DynamoDbCacheInstance, DynamoDbCollection, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntityParseResult, EntityParseValidationError, EntitySeeder, EntitySerializationFormat, EntitySerializer, EntitySnapshotService, EntityVersionOperation, EventsService, ExclusiveOperationResult, FilesManager, IEntityVersionsCursor, InMemoryBucketProvider, InMemoryCacheInstance, InMemoryEmailProvider, InMemoryFileProvider, InMemoryMediaProvider, InMemorySecretsProvider, InvalidCredentialsError, InvalidEntityHandling, JobConcurrency, JobInstance, JobProviderState, JobRunType, JobSchedule, JobStatus, JobsModule, JobsService, LockNotFoundError, MediaLibraryService, MemberOf, MissingEntityIdError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestEntitySerializer, NestEntitySnapshotService, NestPipelineTemplate, NestTypeOrmEntitySeeder, NestTypeOrmQueryBuilder, NestTypeOrmRepository, OperationLockService, OperationTokenMismatchError, PLATFORM_EVENT_NAMESPACE, Permissions, PipelineController, PipelineErrorType, PipelineInvocationError, PipelineStatus, PipelineStepErrorType, PipelinesBuilder, PipelinesRunner, PlatformEvents, Public, QueryBuilderBase, QueryBuilderOperation, ReplicationMode, Roles, SanityMediaError, SanityMediaModule, SanityMediaProvider, SecretsService, SendgridEmailModule, SendgridEmailTemplate, SortDirection, TaskConcurrency, TaskRunType, TasksModule, TasksService, TestingAppSessionService, TrackingService, TypeOrmQueryBuilder, TypeOrmRepository, TypeormCacheInstance, TypeormOperationLockRepository, UserCreationError, UserRegistrationError, WpApiKeysService, WpAppInitializer, WpAwsSesEmailTemplate, WpBucketProvider, WpCacheInstance, WpEmailLogger, WpEmailProvider, WpEmailTemplate, WpEmailTemplateMiddleware, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConnectorMapper, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEntitySerializer, WpEntitySnapshotService, WpEntityVersioningProvider, WpEventsTracker, WpFileProvider, WpFileReferenceRepository, WpGlobalAuthenticationMiddleware, WpMediaFolderRepository, WpMediaProvider, WpMediaReferenceRepository, WpPermissionsService, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpTask, WpUserRolesService, WpUserService, awsBatchSettings, buildPermissionsGuard, buildProviderToken, buildRolesGuard, createContainer, createExpressFileResponse, fieldEmailValidator, fieldNumericValidator, fieldOptionValidator, fieldOptionsValidator, fieldRequiredValidator, fieldTextValidator, getEntityManagerProviderToken, getLocalizedText, newUuid, renderHandlebarsTemplate, sessionStorage, toEntitiesImportInput };
45485
45605
  //# sourceMappingURL=index.js.map