@astralibx/email-rule-engine 12.5.2 → 12.7.0

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/index.d.mts CHANGED
@@ -2,7 +2,7 @@ import * as mongoose from 'mongoose';
2
2
  import { Connection, Model, HydratedDocument, Schema, Types } from 'mongoose';
3
3
  import { Redis } from 'ioredis';
4
4
  import { LogAdapter, AlxError } from '@astralibx/core';
5
- export { LogAdapter } from '@astralibx/core';
5
+ export { LogAdapter, RedisLock } from '@astralibx/core';
6
6
  import { Router } from 'express';
7
7
 
8
8
  declare const TEMPLATE_CATEGORY: {
@@ -101,6 +101,11 @@ interface EmailRule {
101
101
  minGapDays?: number;
102
102
  };
103
103
  emailType: EmailType;
104
+ schedule?: {
105
+ enabled: boolean;
106
+ cron: string;
107
+ timezone?: string;
108
+ };
104
109
  totalSent: number;
105
110
  totalSkipped: number;
106
111
  lastRunAt?: Date;
@@ -128,6 +133,11 @@ interface CreateEmailRuleInput {
128
133
  minGapDays?: number;
129
134
  };
130
135
  emailType?: EmailType;
136
+ schedule?: {
137
+ enabled: boolean;
138
+ cron: string;
139
+ timezone?: string;
140
+ };
131
141
  }
132
142
  interface UpdateEmailRuleInput {
133
143
  name?: string;
@@ -150,6 +160,11 @@ interface UpdateEmailRuleInput {
150
160
  minGapDays?: number;
151
161
  };
152
162
  emailType?: EmailType;
163
+ schedule?: {
164
+ enabled: boolean;
165
+ cron: string;
166
+ timezone?: string;
167
+ };
153
168
  }
154
169
  interface EmailRuleSend {
155
170
  _id: string;
@@ -550,10 +565,16 @@ declare class TemplateService {
550
565
  errors: string[];
551
566
  variables: string[];
552
567
  }>;
568
+ clone(sourceId: string, newName?: string): Promise<any>;
553
569
  sendTestEmail(id: string, testEmail: string, sampleData: Record<string, unknown>): Promise<{
554
570
  success: boolean;
555
571
  error?: string;
556
572
  }>;
573
+ previewWithRecipient(templateId: string, recipientData: Record<string, unknown>): Promise<{
574
+ html: string;
575
+ text: string;
576
+ subject: string;
577
+ } | null>;
557
578
  }
558
579
 
559
580
  declare class RuleService {
@@ -576,7 +597,13 @@ declare class RuleService {
576
597
  effectiveLimit: number;
577
598
  willProcess: number;
578
599
  ruleId: string;
600
+ sample: Array<{
601
+ email: string;
602
+ name?: string;
603
+ [key: string]: unknown;
604
+ }>;
579
605
  }>;
606
+ clone(sourceId: string, newName?: string): Promise<any>;
580
607
  getRunHistory(limit?: number): Promise<unknown[]>;
581
608
  }
582
609
 
@@ -681,15 +708,27 @@ declare class TemplateRenderService {
681
708
  };
682
709
  }
683
710
 
684
- declare class RedisLock {
685
- private redis;
686
- private lockKey;
687
- private ttlMs;
688
- private logger?;
689
- private lockValue;
690
- constructor(redis: Redis, lockKey: string, ttlMs: number, logger?: LogAdapter | undefined);
691
- acquire(): Promise<boolean>;
692
- release(): Promise<void>;
711
+ declare class SchedulerService {
712
+ private queue;
713
+ private worker?;
714
+ private keyPrefix;
715
+ constructor(connection: Redis, keyPrefix?: string);
716
+ syncRule(rule: {
717
+ _id: any;
718
+ schedule?: {
719
+ enabled: boolean;
720
+ cron: string;
721
+ timezone?: string;
722
+ };
723
+ }): Promise<void>;
724
+ removeRule(ruleId: string): Promise<void>;
725
+ startWorker(runFn: (triggeredBy: string) => Promise<any>): void;
726
+ stopWorker(): Promise<void>;
727
+ getScheduledJobs(): Promise<Array<{
728
+ ruleId: string;
729
+ cron: string;
730
+ next: number | null;
731
+ }>>;
693
732
  }
694
733
 
695
734
  /**
@@ -727,4 +766,4 @@ interface EmailRuleEngine {
727
766
  */
728
767
  declare function createEmailRuleEngine(config: EmailRuleEngineConfig): EmailRuleEngine;
729
768
 
730
- export { type AgentSelection, AlxEmailError, type BeforeSendParams, type BeforeSendResult, type CompiledTemplate, ConfigValidationError, type CreateEmailRuleInput, type CreateEmailTemplateInput, DuplicateSlugError, EMAIL_SEND_STATUS, EMAIL_TYPE, type EmailRule, type EmailRuleDocument, type EmailRuleEngine, type EmailRuleEngineConfig, type EmailRuleModel, type EmailRuleRunLog, type EmailRuleRunLogDocument, type EmailRuleRunLogModel, type EmailRuleRunLogStatics, type EmailRuleSend, type EmailRuleSendDocument, type EmailRuleSendModel, type EmailRuleSendStatics, type EmailRuleStatics, type EmailSendStatus, type EmailTemplate, type EmailTemplateDocument, type EmailTemplateModel, type EmailTemplateStatics, type EmailThrottleConfig, type EmailThrottleConfigDocument, type EmailThrottleConfigModel, type EmailThrottleConfigStatics, type EmailType, type IEmailRule, type IEmailRuleRunLog, type IEmailRuleSend, type IEmailTemplate, type IEmailThrottleConfig, type ListTarget, LockAcquisitionError, type PerRuleStats, type QueryTarget, RULE_OPERATOR, RUN_TRIGGER, type RecipientIdentifier, RedisLock, type RenderResult, type RuleCondition, RuleNotFoundError, type RuleOperator, type RuleRunStats, RuleRunnerService, RuleService, type RuleTarget, RuleTemplateIncompatibleError, type RunTrigger, type SendEmailParams, TEMPLATE_AUDIENCE, TEMPLATE_CATEGORY, THROTTLE_WINDOW, type TemplateAudience, type TemplateCategory, TemplateNotFoundError, TemplateRenderService, TemplateService, TemplateSyntaxError, type ThrottleWindow, type UpdateEmailRuleInput, type UpdateEmailTemplateInput, type UpdateEmailThrottleConfigInput, createEmailRuleEngine, createEmailRuleRunLogSchema, createEmailRuleSchema, createEmailRuleSendSchema, createEmailTemplateSchema, createEmailThrottleConfigSchema, validateConfig };
769
+ export { type AgentSelection, AlxEmailError, type BeforeSendParams, type BeforeSendResult, type CompiledTemplate, ConfigValidationError, type CreateEmailRuleInput, type CreateEmailTemplateInput, DuplicateSlugError, EMAIL_SEND_STATUS, EMAIL_TYPE, type EmailRule, type EmailRuleDocument, type EmailRuleEngine, type EmailRuleEngineConfig, type EmailRuleModel, type EmailRuleRunLog, type EmailRuleRunLogDocument, type EmailRuleRunLogModel, type EmailRuleRunLogStatics, type EmailRuleSend, type EmailRuleSendDocument, type EmailRuleSendModel, type EmailRuleSendStatics, type EmailRuleStatics, type EmailSendStatus, type EmailTemplate, type EmailTemplateDocument, type EmailTemplateModel, type EmailTemplateStatics, type EmailThrottleConfig, type EmailThrottleConfigDocument, type EmailThrottleConfigModel, type EmailThrottleConfigStatics, type EmailType, type IEmailRule, type IEmailRuleRunLog, type IEmailRuleSend, type IEmailTemplate, type IEmailThrottleConfig, type ListTarget, LockAcquisitionError, type PerRuleStats, type QueryTarget, RULE_OPERATOR, RUN_TRIGGER, type RecipientIdentifier, type RenderResult, type RuleCondition, RuleNotFoundError, type RuleOperator, type RuleRunStats, RuleRunnerService, RuleService, type RuleTarget, RuleTemplateIncompatibleError, type RunTrigger, SchedulerService, type SendEmailParams, TEMPLATE_AUDIENCE, TEMPLATE_CATEGORY, THROTTLE_WINDOW, type TemplateAudience, type TemplateCategory, TemplateNotFoundError, TemplateRenderService, TemplateService, TemplateSyntaxError, type ThrottleWindow, type UpdateEmailRuleInput, type UpdateEmailTemplateInput, type UpdateEmailThrottleConfigInput, createEmailRuleEngine, createEmailRuleRunLogSchema, createEmailRuleSchema, createEmailRuleSendSchema, createEmailTemplateSchema, createEmailThrottleConfigSchema, validateConfig };
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as mongoose from 'mongoose';
2
2
  import { Connection, Model, HydratedDocument, Schema, Types } from 'mongoose';
3
3
  import { Redis } from 'ioredis';
4
4
  import { LogAdapter, AlxError } from '@astralibx/core';
5
- export { LogAdapter } from '@astralibx/core';
5
+ export { LogAdapter, RedisLock } from '@astralibx/core';
6
6
  import { Router } from 'express';
7
7
 
8
8
  declare const TEMPLATE_CATEGORY: {
@@ -101,6 +101,11 @@ interface EmailRule {
101
101
  minGapDays?: number;
102
102
  };
103
103
  emailType: EmailType;
104
+ schedule?: {
105
+ enabled: boolean;
106
+ cron: string;
107
+ timezone?: string;
108
+ };
104
109
  totalSent: number;
105
110
  totalSkipped: number;
106
111
  lastRunAt?: Date;
@@ -128,6 +133,11 @@ interface CreateEmailRuleInput {
128
133
  minGapDays?: number;
129
134
  };
130
135
  emailType?: EmailType;
136
+ schedule?: {
137
+ enabled: boolean;
138
+ cron: string;
139
+ timezone?: string;
140
+ };
131
141
  }
132
142
  interface UpdateEmailRuleInput {
133
143
  name?: string;
@@ -150,6 +160,11 @@ interface UpdateEmailRuleInput {
150
160
  minGapDays?: number;
151
161
  };
152
162
  emailType?: EmailType;
163
+ schedule?: {
164
+ enabled: boolean;
165
+ cron: string;
166
+ timezone?: string;
167
+ };
153
168
  }
154
169
  interface EmailRuleSend {
155
170
  _id: string;
@@ -550,10 +565,16 @@ declare class TemplateService {
550
565
  errors: string[];
551
566
  variables: string[];
552
567
  }>;
568
+ clone(sourceId: string, newName?: string): Promise<any>;
553
569
  sendTestEmail(id: string, testEmail: string, sampleData: Record<string, unknown>): Promise<{
554
570
  success: boolean;
555
571
  error?: string;
556
572
  }>;
573
+ previewWithRecipient(templateId: string, recipientData: Record<string, unknown>): Promise<{
574
+ html: string;
575
+ text: string;
576
+ subject: string;
577
+ } | null>;
557
578
  }
558
579
 
559
580
  declare class RuleService {
@@ -576,7 +597,13 @@ declare class RuleService {
576
597
  effectiveLimit: number;
577
598
  willProcess: number;
578
599
  ruleId: string;
600
+ sample: Array<{
601
+ email: string;
602
+ name?: string;
603
+ [key: string]: unknown;
604
+ }>;
579
605
  }>;
606
+ clone(sourceId: string, newName?: string): Promise<any>;
580
607
  getRunHistory(limit?: number): Promise<unknown[]>;
581
608
  }
582
609
 
@@ -681,15 +708,27 @@ declare class TemplateRenderService {
681
708
  };
682
709
  }
683
710
 
684
- declare class RedisLock {
685
- private redis;
686
- private lockKey;
687
- private ttlMs;
688
- private logger?;
689
- private lockValue;
690
- constructor(redis: Redis, lockKey: string, ttlMs: number, logger?: LogAdapter | undefined);
691
- acquire(): Promise<boolean>;
692
- release(): Promise<void>;
711
+ declare class SchedulerService {
712
+ private queue;
713
+ private worker?;
714
+ private keyPrefix;
715
+ constructor(connection: Redis, keyPrefix?: string);
716
+ syncRule(rule: {
717
+ _id: any;
718
+ schedule?: {
719
+ enabled: boolean;
720
+ cron: string;
721
+ timezone?: string;
722
+ };
723
+ }): Promise<void>;
724
+ removeRule(ruleId: string): Promise<void>;
725
+ startWorker(runFn: (triggeredBy: string) => Promise<any>): void;
726
+ stopWorker(): Promise<void>;
727
+ getScheduledJobs(): Promise<Array<{
728
+ ruleId: string;
729
+ cron: string;
730
+ next: number | null;
731
+ }>>;
693
732
  }
694
733
 
695
734
  /**
@@ -727,4 +766,4 @@ interface EmailRuleEngine {
727
766
  */
728
767
  declare function createEmailRuleEngine(config: EmailRuleEngineConfig): EmailRuleEngine;
729
768
 
730
- export { type AgentSelection, AlxEmailError, type BeforeSendParams, type BeforeSendResult, type CompiledTemplate, ConfigValidationError, type CreateEmailRuleInput, type CreateEmailTemplateInput, DuplicateSlugError, EMAIL_SEND_STATUS, EMAIL_TYPE, type EmailRule, type EmailRuleDocument, type EmailRuleEngine, type EmailRuleEngineConfig, type EmailRuleModel, type EmailRuleRunLog, type EmailRuleRunLogDocument, type EmailRuleRunLogModel, type EmailRuleRunLogStatics, type EmailRuleSend, type EmailRuleSendDocument, type EmailRuleSendModel, type EmailRuleSendStatics, type EmailRuleStatics, type EmailSendStatus, type EmailTemplate, type EmailTemplateDocument, type EmailTemplateModel, type EmailTemplateStatics, type EmailThrottleConfig, type EmailThrottleConfigDocument, type EmailThrottleConfigModel, type EmailThrottleConfigStatics, type EmailType, type IEmailRule, type IEmailRuleRunLog, type IEmailRuleSend, type IEmailTemplate, type IEmailThrottleConfig, type ListTarget, LockAcquisitionError, type PerRuleStats, type QueryTarget, RULE_OPERATOR, RUN_TRIGGER, type RecipientIdentifier, RedisLock, type RenderResult, type RuleCondition, RuleNotFoundError, type RuleOperator, type RuleRunStats, RuleRunnerService, RuleService, type RuleTarget, RuleTemplateIncompatibleError, type RunTrigger, type SendEmailParams, TEMPLATE_AUDIENCE, TEMPLATE_CATEGORY, THROTTLE_WINDOW, type TemplateAudience, type TemplateCategory, TemplateNotFoundError, TemplateRenderService, TemplateService, TemplateSyntaxError, type ThrottleWindow, type UpdateEmailRuleInput, type UpdateEmailTemplateInput, type UpdateEmailThrottleConfigInput, createEmailRuleEngine, createEmailRuleRunLogSchema, createEmailRuleSchema, createEmailRuleSendSchema, createEmailTemplateSchema, createEmailThrottleConfigSchema, validateConfig };
769
+ export { type AgentSelection, AlxEmailError, type BeforeSendParams, type BeforeSendResult, type CompiledTemplate, ConfigValidationError, type CreateEmailRuleInput, type CreateEmailTemplateInput, DuplicateSlugError, EMAIL_SEND_STATUS, EMAIL_TYPE, type EmailRule, type EmailRuleDocument, type EmailRuleEngine, type EmailRuleEngineConfig, type EmailRuleModel, type EmailRuleRunLog, type EmailRuleRunLogDocument, type EmailRuleRunLogModel, type EmailRuleRunLogStatics, type EmailRuleSend, type EmailRuleSendDocument, type EmailRuleSendModel, type EmailRuleSendStatics, type EmailRuleStatics, type EmailSendStatus, type EmailTemplate, type EmailTemplateDocument, type EmailTemplateModel, type EmailTemplateStatics, type EmailThrottleConfig, type EmailThrottleConfigDocument, type EmailThrottleConfigModel, type EmailThrottleConfigStatics, type EmailType, type IEmailRule, type IEmailRuleRunLog, type IEmailRuleSend, type IEmailTemplate, type IEmailThrottleConfig, type ListTarget, LockAcquisitionError, type PerRuleStats, type QueryTarget, RULE_OPERATOR, RUN_TRIGGER, type RecipientIdentifier, type RenderResult, type RuleCondition, RuleNotFoundError, type RuleOperator, type RuleRunStats, RuleRunnerService, RuleService, type RuleTarget, RuleTemplateIncompatibleError, type RunTrigger, SchedulerService, type SendEmailParams, TEMPLATE_AUDIENCE, TEMPLATE_CATEGORY, THROTTLE_WINDOW, type TemplateAudience, type TemplateCategory, TemplateNotFoundError, TemplateRenderService, TemplateService, TemplateSyntaxError, type ThrottleWindow, type UpdateEmailRuleInput, type UpdateEmailTemplateInput, type UpdateEmailThrottleConfigInput, createEmailRuleEngine, createEmailRuleRunLogSchema, createEmailRuleSchema, createEmailRuleSendSchema, createEmailTemplateSchema, createEmailThrottleConfigSchema, validateConfig };