@classytic/loyalty 0.1.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.
Files changed (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +191 -0
  3. package/dist/config-aNigy4ec.d.mts +90 -0
  4. package/dist/constants-C75GvizO.mjs +49 -0
  5. package/dist/domain/enums/index.d.mts +2 -0
  6. package/dist/domain/enums/index.mjs +2 -0
  7. package/dist/domain/index.d.mts +90 -0
  8. package/dist/domain/index.mjs +4 -0
  9. package/dist/domain-errors-D7q-2LYD.mjs +120 -0
  10. package/dist/event-emitter.port-CLYPoMni.d.mts +8 -0
  11. package/dist/event-types-xQBtYBbX.mjs +24 -0
  12. package/dist/events/index.d.mts +2 -0
  13. package/dist/events/index.mjs +3 -0
  14. package/dist/events-CprEWlN7.mjs +25 -0
  15. package/dist/index-B6ZstxSP.d.mts +2357 -0
  16. package/dist/index-BcoGeDco.d.mts +127 -0
  17. package/dist/index-CaH4GhSF.d.mts +19 -0
  18. package/dist/index-DqzTjeEB.d.mts +148 -0
  19. package/dist/index-O7TL4R2P.d.mts +86 -0
  20. package/dist/index-_pg4J11t.d.mts +191 -0
  21. package/dist/index.d.mts +21 -0
  22. package/dist/index.mjs +95 -0
  23. package/dist/models/index.d.mts +2 -0
  24. package/dist/models/index.mjs +2 -0
  25. package/dist/models-CrZPmVxt.mjs +417 -0
  26. package/dist/notification.port-BzUsH0It.d.mts +13 -0
  27. package/dist/notifications/index.d.mts +21 -0
  28. package/dist/notifications/index.mjs +19 -0
  29. package/dist/repositories/index.d.mts +2 -0
  30. package/dist/repositories/index.mjs +2 -0
  31. package/dist/repositories-qMX7Xh_y.mjs +440 -0
  32. package/dist/services/index.d.mts +2 -0
  33. package/dist/services/index.mjs +2 -0
  34. package/dist/services-CoTqC4E6.mjs +1098 -0
  35. package/dist/tier-definition-Djf72UPa.d.mts +120 -0
  36. package/dist/tier-definition.port-BzrHYBRo.d.mts +143 -0
  37. package/dist/types/index.d.mts +3 -0
  38. package/dist/types/index.mjs +1 -0
  39. package/package.json +111 -0
@@ -0,0 +1,127 @@
1
+ import { a as PointTransaction, n as TierDefinition, o as Member, u as EarningRule } from "./tier-definition-Djf72UPa.mjs";
2
+ import { a as MemberPort, i as PointTransactionPort, l as Referral, n as ReferralPort, o as EarningRulePort, r as RedemptionPort, t as TierDefinitionPort, u as Redemption } from "./tier-definition.port-BzrHYBRo.mjs";
3
+ import { a as RepositoryPlugins } from "./config-aNigy4ec.mjs";
4
+ import { t as LoyaltyModels } from "./index-B6ZstxSP.mjs";
5
+ import { Model } from "mongoose";
6
+ import { PluginType } from "@classytic/mongokit";
7
+
8
+ //#region src/repositories/earning-rule.repository.d.ts
9
+ declare class EarningRuleRepository implements EarningRulePort {
10
+ private repo;
11
+ private tenantField;
12
+ constructor(model: Model<any>, plugins?: PluginType[], tenantField?: string);
13
+ create(data: Record<string, unknown>, session?: unknown): Promise<EarningRule>;
14
+ getById(id: string, tenantId?: string): Promise<EarningRule | null>;
15
+ update(id: string, data: Record<string, unknown>, tenantId?: string, session?: unknown): Promise<EarningRule>;
16
+ findActive(tenantId?: string, programId?: string): Promise<EarningRule[]>;
17
+ paginate(query: Record<string, unknown>, options: {
18
+ page?: number;
19
+ limit?: number;
20
+ sort?: Record<string, number>;
21
+ }): Promise<{
22
+ docs: EarningRule[];
23
+ total: number;
24
+ page: number;
25
+ pages: number;
26
+ }>;
27
+ }
28
+ //#endregion
29
+ //#region src/repositories/member.repository.d.ts
30
+ declare class MemberRepository implements MemberPort {
31
+ private repo;
32
+ private tenantField;
33
+ constructor(model: Model<any>, plugins?: PluginType[], tenantField?: string);
34
+ create(data: Record<string, unknown>, session?: unknown): Promise<Member>;
35
+ getById(id: string, tenantId?: string): Promise<Member | null>;
36
+ getByExternalId(externalId: string, externalType: string, tenantId?: string): Promise<Member | null>;
37
+ getByCardId(cardId: string, tenantId?: string): Promise<Member | null>;
38
+ getByReferralCode(code: string, tenantId?: string): Promise<Member | null>;
39
+ update(id: string, data: Record<string, unknown>, tenantId?: string, session?: unknown): Promise<Member>;
40
+ updateBalance(id: string, balanceUpdate: Record<string, number>, tenantId?: string, session?: unknown): Promise<Member>;
41
+ findMany(query: Record<string, unknown>, options?: Record<string, unknown>): Promise<Member[]>;
42
+ }
43
+ //#endregion
44
+ //#region src/repositories/point-transaction.repository.d.ts
45
+ declare class PointTransactionRepository implements PointTransactionPort {
46
+ private repo;
47
+ private tenantField;
48
+ constructor(model: Model<any>, plugins?: PluginType[], tenantField?: string);
49
+ create(data: Record<string, unknown>, session?: unknown): Promise<PointTransaction>;
50
+ getById(id: string, tenantId?: string): Promise<PointTransaction | null>;
51
+ getByIdempotencyKey(key: string, tenantId?: string): Promise<PointTransaction | null>;
52
+ update(id: string, data: Record<string, unknown>, session?: unknown): Promise<PointTransaction>;
53
+ findMany(query: Record<string, unknown>, options?: Record<string, unknown>): Promise<PointTransaction[]>;
54
+ paginate(query: Record<string, unknown>, options: {
55
+ page?: number;
56
+ limit?: number;
57
+ sort?: Record<string, number>;
58
+ }): Promise<{
59
+ docs: PointTransaction[];
60
+ total: number;
61
+ page: number;
62
+ pages: number;
63
+ }>;
64
+ findExpired(now: Date, tenantId?: string, limit?: number): Promise<PointTransaction[]>;
65
+ }
66
+ //#endregion
67
+ //#region src/repositories/redemption.repository.d.ts
68
+ declare class RedemptionRepository implements RedemptionPort {
69
+ private repo;
70
+ private tenantField;
71
+ constructor(model: Model<any>, plugins?: PluginType[], tenantField?: string);
72
+ create(data: Record<string, unknown>, session?: unknown): Promise<Redemption>;
73
+ getById(id: string, tenantId?: string): Promise<Redemption | null>;
74
+ getByOwner(ownerType: string, ownerId: string, tenantId?: string): Promise<Redemption | null>;
75
+ update(id: string, data: Record<string, unknown>, tenantId?: string, session?: unknown): Promise<Redemption>;
76
+ atomicStatusTransition(id: string, expectedStatus: string, data: Record<string, unknown>, tenantId?: string, session?: unknown): Promise<Redemption | null>;
77
+ findExpired(now: Date, tenantId?: string): Promise<Redemption[]>;
78
+ }
79
+ //#endregion
80
+ //#region src/repositories/referral.repository.d.ts
81
+ declare class ReferralRepository implements ReferralPort {
82
+ private repo;
83
+ private tenantField;
84
+ constructor(model: Model<any>, plugins?: PluginType[], tenantField?: string);
85
+ create(data: Record<string, unknown>, session?: unknown): Promise<Referral>;
86
+ getById(id: string, tenantId?: string): Promise<Referral | null>;
87
+ getByReferee(refereeId: string, tenantId?: string): Promise<Referral | null>;
88
+ update(id: string, data: Record<string, unknown>, tenantId?: string, session?: unknown): Promise<Referral>;
89
+ atomicStatusTransition(id: string, expectedStatus: string, data: Record<string, unknown>, tenantId?: string, session?: unknown): Promise<Referral | null>;
90
+ countByReferrerInPeriod(referrerId: string, since: Date, tenantId?: string): Promise<number>;
91
+ findByReferrer(referrerId: string, options: {
92
+ page?: number;
93
+ limit?: number;
94
+ }, tenantId?: string): Promise<{
95
+ docs: Referral[];
96
+ total: number;
97
+ page: number;
98
+ pages: number;
99
+ }>;
100
+ findExpired(now: Date, tenantId?: string): Promise<Referral[]>;
101
+ }
102
+ //#endregion
103
+ //#region src/repositories/tier-definition.repository.d.ts
104
+ declare class TierDefinitionRepository implements TierDefinitionPort {
105
+ private repo;
106
+ private tenantField;
107
+ constructor(model: Model<any>, plugins?: PluginType[], tenantField?: string);
108
+ create(data: Record<string, unknown>, session?: unknown): Promise<TierDefinition>;
109
+ getById(id: string, tenantId?: string): Promise<TierDefinition | null>;
110
+ getByName(name: string, tenantId?: string, programId?: string): Promise<TierDefinition | null>;
111
+ update(id: string, data: Record<string, unknown>, tenantId?: string, session?: unknown): Promise<TierDefinition>;
112
+ delete(id: string, tenantId?: string): Promise<void>;
113
+ findAll(tenantId?: string, programId?: string): Promise<TierDefinition[]>;
114
+ }
115
+ //#endregion
116
+ //#region src/repositories/index.d.ts
117
+ interface LoyaltyRepositories {
118
+ member: MemberPort;
119
+ pointTransaction: PointTransactionPort;
120
+ earningRule: EarningRulePort;
121
+ tierDefinition: TierDefinitionPort;
122
+ redemption: RedemptionPort;
123
+ referral: ReferralPort;
124
+ }
125
+ declare function createRepositories(models: LoyaltyModels, plugins?: RepositoryPlugins, tenantField?: string): LoyaltyRepositories;
126
+ //#endregion
127
+ export { RedemptionRepository as a, EarningRuleRepository as c, ReferralRepository as i, createRepositories as n, PointTransactionRepository as o, TierDefinitionRepository as r, MemberRepository as s, LoyaltyRepositories as t };
@@ -0,0 +1,19 @@
1
+ //#region src/constants.d.ts
2
+ declare const TRANSACTION_TYPES: readonly ["earn", "redeem", "adjust", "expire", "transfer", "referral_bonus"];
3
+ declare const MEMBER_STATUSES: readonly ["active", "inactive", "suspended"];
4
+ declare const RULE_TYPES: readonly ["order", "action", "category", "tier_bonus"];
5
+ declare const RULE_STATUSES: readonly ["active", "paused", "expired"];
6
+ declare const REFERRAL_STATUSES: readonly ["pending", "approved", "rejected", "expired"];
7
+ declare const REDEMPTION_STATUSES: readonly ["reserved", "confirmed", "released", "expired"];
8
+ declare const EARNING_ACTIONS: readonly ["signup", "referral", "birthday", "review", "profile_complete"];
9
+ //#endregion
10
+ //#region src/domain/enums/index.d.ts
11
+ type TransactionType = (typeof TRANSACTION_TYPES)[number];
12
+ type MemberStatus = (typeof MEMBER_STATUSES)[number];
13
+ type RuleType = (typeof RULE_TYPES)[number];
14
+ type RuleStatus = (typeof RULE_STATUSES)[number];
15
+ type ReferralStatus = (typeof REFERRAL_STATUSES)[number];
16
+ type RedemptionStatus = (typeof REDEMPTION_STATUSES)[number];
17
+ type EarningAction = (typeof EARNING_ACTIONS)[number];
18
+ //#endregion
19
+ export { RuleStatus as a, EARNING_ACTIONS as c, REFERRAL_STATUSES as d, RULE_STATUSES as f, ReferralStatus as i, MEMBER_STATUSES as l, TRANSACTION_TYPES as m, MemberStatus as n, RuleType as o, RULE_TYPES as p, RedemptionStatus as r, TransactionType as s, EarningAction as t, REDEMPTION_STATUSES as u };
@@ -0,0 +1,148 @@
1
+ import { a as PointTransaction, c as EarningConditions, i as TierQualification, l as EarningReward, r as TierDowngrade, s as MemberBalance, t as TierBenefits } from "./tier-definition-Djf72UPa.mjs";
2
+ //#region src/types/results.d.ts
3
+ interface BalanceSummary extends MemberBalance {
4
+ tier: string | null;
5
+ tierOverride: string | null;
6
+ }
7
+ interface EarningBreakdown {
8
+ ruleId: string;
9
+ ruleName: string;
10
+ points: number;
11
+ }
12
+ interface EarningResult {
13
+ totalPoints: number;
14
+ breakdown: EarningBreakdown[];
15
+ transactions: PointTransaction[];
16
+ }
17
+ interface TierEvaluation {
18
+ memberId: string;
19
+ previousTier: string | null;
20
+ newTier: string | null;
21
+ action: 'upgraded' | 'downgraded' | 'grace_period' | 'unchanged';
22
+ graceExpiresAt?: Date;
23
+ }
24
+ interface TierEvaluationBatch {
25
+ upgraded: number;
26
+ downgraded: number;
27
+ unchanged: number;
28
+ }
29
+ interface RedemptionValidation {
30
+ valid: boolean;
31
+ error?: string;
32
+ pointsToRedeem: number;
33
+ discountAmount: number;
34
+ maxAllowedPoints: number;
35
+ }
36
+ interface ExpirationResult {
37
+ membersAffected: number;
38
+ pointsExpired: number;
39
+ transactionCount: number;
40
+ }
41
+ interface PaginatedResult<T> {
42
+ docs: T[];
43
+ total: number;
44
+ page: number;
45
+ pages: number;
46
+ hasNext: boolean;
47
+ hasPrev: boolean;
48
+ }
49
+ interface ListQuery {
50
+ page?: number;
51
+ limit?: number;
52
+ sort?: Record<string, 1 | -1>;
53
+ }
54
+ //#endregion
55
+ //#region src/types/index.d.ts
56
+ /**
57
+ * Context passed to every loyalty operation.
58
+ *
59
+ * The tenant key is dynamic — if you configured `tenant: { field: 'companyId', contextKey: 'companyId' }`,
60
+ * pass `{ companyId: '...' }` in the context. The `[key: string]: unknown` index allows this.
61
+ *
62
+ * For the default config (`tenant: true` or `tenant: undefined`), pass `organizationId`.
63
+ * For `tenant: false`, the tenant key is ignored.
64
+ */
65
+ interface LoyaltyContext {
66
+ /** Required: who is performing this operation */
67
+ actorId: string;
68
+ /** Default tenant key (used when tenant config uses default 'organizationId' field) */
69
+ organizationId?: string;
70
+ /** Override program ID for multi-program setups */
71
+ programId?: string;
72
+ /** Deduplication key for earn/adjust operations */
73
+ idempotencyKey?: string;
74
+ /** Dynamic tenant key support — e.g. `{ companyId: '...' }` */
75
+ [key: string]: unknown;
76
+ }
77
+ interface EnrollInput {
78
+ externalId: string;
79
+ externalType: string;
80
+ programId?: string;
81
+ tier?: string;
82
+ cardId?: string;
83
+ metadata?: Record<string, unknown>;
84
+ }
85
+ interface EarnPointsInput {
86
+ memberId: string;
87
+ points: number;
88
+ description: string;
89
+ referenceType?: string;
90
+ referenceId?: string;
91
+ earningRuleId?: string;
92
+ expiresAt?: Date;
93
+ idempotencyKey?: string;
94
+ metadata?: Record<string, unknown>;
95
+ }
96
+ interface AdjustPointsInput {
97
+ memberId: string;
98
+ points: number;
99
+ description: string;
100
+ reason: string;
101
+ referenceType?: string;
102
+ referenceId?: string;
103
+ idempotencyKey?: string;
104
+ metadata?: Record<string, unknown>;
105
+ }
106
+ interface CreateEarningRuleInput {
107
+ name: string;
108
+ type: 'order' | 'action' | 'category' | 'tier_bonus';
109
+ priority?: number;
110
+ description?: string;
111
+ conditions?: EarningConditions;
112
+ reward: EarningReward;
113
+ startsAt?: Date | string;
114
+ endsAt?: Date | string;
115
+ programId?: string;
116
+ metadata?: Record<string, unknown>;
117
+ }
118
+ interface UpdateEarningRuleInput {
119
+ name?: string;
120
+ priority?: number;
121
+ description?: string;
122
+ conditions?: EarningConditions;
123
+ reward?: EarningReward;
124
+ startsAt?: Date | string;
125
+ endsAt?: Date | string;
126
+ metadata?: Record<string, unknown>;
127
+ }
128
+ interface CreateTierInput {
129
+ name: string;
130
+ rank: number;
131
+ qualificationCriteria?: TierQualification;
132
+ benefits?: TierBenefits;
133
+ downgrade?: TierDowngrade;
134
+ color?: string;
135
+ programId?: string;
136
+ metadata?: Record<string, unknown>;
137
+ }
138
+ interface UpdateTierInput {
139
+ name?: string;
140
+ rank?: number;
141
+ qualificationCriteria?: TierQualification;
142
+ benefits?: TierBenefits;
143
+ downgrade?: TierDowngrade;
144
+ color?: string;
145
+ metadata?: Record<string, unknown>;
146
+ }
147
+ //#endregion
148
+ export { TierEvaluationBatch as _, EnrollInput as a, UpdateTierInput as c, EarningResult as d, ExpirationResult as f, TierEvaluation as g, RedemptionValidation as h, EarnPointsInput as i, BalanceSummary as l, PaginatedResult as m, CreateEarningRuleInput as n, LoyaltyContext as o, ListQuery as p, CreateTierInput as r, UpdateEarningRuleInput as s, AdjustPointsInput as t, EarningBreakdown as u };
@@ -0,0 +1,86 @@
1
+ import { t as EventEmitterPort } from "./event-emitter.port-CLYPoMni.mjs";
2
+
3
+ //#region src/events/event-bus.d.ts
4
+ type Handler = (payload: unknown) => void | Promise<void>;
5
+ declare class InProcessEventBus implements EventEmitterPort {
6
+ private handlers;
7
+ emit(event: string, payload: unknown): void;
8
+ on(event: string, handler: Handler): void;
9
+ off(event: string, handler: Handler): void;
10
+ }
11
+ //#endregion
12
+ //#region src/events/event-types.d.ts
13
+ declare const LoyaltyEvents: {
14
+ readonly MEMBER_ENROLLED: "loyalty.member.enrolled";
15
+ readonly MEMBER_DEACTIVATED: "loyalty.member.deactivated";
16
+ readonly MEMBER_REACTIVATED: "loyalty.member.reactivated";
17
+ readonly MEMBER_SUSPENDED: "loyalty.member.suspended";
18
+ readonly POINTS_EARNED: "loyalty.points.earned";
19
+ readonly POINTS_REDEEMED: "loyalty.points.redeemed";
20
+ readonly POINTS_ADJUSTED: "loyalty.points.adjusted";
21
+ readonly POINTS_EXPIRED: "loyalty.points.expired";
22
+ readonly POINTS_EXPIRING_SOON: "loyalty.points.expiring_soon";
23
+ readonly TIER_UPGRADED: "loyalty.tier.upgraded";
24
+ readonly TIER_DOWNGRADED: "loyalty.tier.downgraded";
25
+ readonly TIER_GRACE_STARTED: "loyalty.tier.grace_started";
26
+ readonly REDEMPTION_RESERVED: "loyalty.redemption.reserved";
27
+ readonly REDEMPTION_CONFIRMED: "loyalty.redemption.confirmed";
28
+ readonly REDEMPTION_RELEASED: "loyalty.redemption.released";
29
+ readonly REFERRAL_RECORDED: "loyalty.referral.recorded";
30
+ readonly REFERRAL_APPROVED: "loyalty.referral.approved";
31
+ readonly REFERRAL_REJECTED: "loyalty.referral.rejected";
32
+ readonly REFERRAL_REWARDED: "loyalty.referral.rewarded";
33
+ };
34
+ type LoyaltyEvent = (typeof LoyaltyEvents)[keyof typeof LoyaltyEvents];
35
+ interface PointsEarnedPayload {
36
+ memberId: string;
37
+ externalId: string;
38
+ externalType: string;
39
+ points: number;
40
+ balanceAfter: number;
41
+ transactionId: string;
42
+ earningRuleName?: string;
43
+ referenceType?: string;
44
+ referenceId?: string;
45
+ }
46
+ interface PointsAdjustedPayload {
47
+ memberId: string;
48
+ externalId: string;
49
+ points: number;
50
+ balanceAfter: number;
51
+ transactionId: string;
52
+ description: string;
53
+ }
54
+ interface TierChangedPayload {
55
+ memberId: string;
56
+ externalId: string;
57
+ previousTier: string | null;
58
+ newTier: string | null;
59
+ lifetimePoints: number;
60
+ }
61
+ interface MemberLifecyclePayload {
62
+ memberId: string;
63
+ externalId: string;
64
+ externalType: string;
65
+ status: string;
66
+ }
67
+ interface RedemptionPayload {
68
+ memberId: string;
69
+ externalId: string;
70
+ redemptionId: string;
71
+ points: number;
72
+ discountAmount: number;
73
+ ownerType: string;
74
+ ownerId: string;
75
+ }
76
+ interface ReferralPayload {
77
+ referralId: string;
78
+ referrerId: string;
79
+ refereeId: string;
80
+ referralCode: string;
81
+ status: string;
82
+ referrerRewardPoints?: number;
83
+ refereeRewardPoints?: number;
84
+ }
85
+ //#endregion
86
+ export { PointsEarnedPayload as a, TierChangedPayload as c, PointsAdjustedPayload as i, InProcessEventBus as l, LoyaltyEvents as n, RedemptionPayload as o, MemberLifecyclePayload as r, ReferralPayload as s, LoyaltyEvent as t };
@@ -0,0 +1,191 @@
1
+ import { a as PointTransaction, n as TierDefinition, o as Member, u as EarningRule } from "./tier-definition-Djf72UPa.mjs";
2
+ import { a as MemberPort, c as UnitOfWork, i as PointTransactionPort, l as Referral, n as ReferralPort, o as EarningRulePort, r as RedemptionPort, t as TierDefinitionPort, u as Redemption } from "./tier-definition.port-BzrHYBRo.mjs";
3
+ import { t as EventEmitterPort } from "./event-emitter.port-CLYPoMni.mjs";
4
+ import { t as NotificationAdapter } from "./notification.port-BzUsH0It.mjs";
5
+ import { o as ResolvedConfig } from "./config-aNigy4ec.mjs";
6
+ import { t as LoyaltyRepositories } from "./index-BcoGeDco.mjs";
7
+ import { _ as TierEvaluationBatch, c as UpdateTierInput, d as EarningResult, f as ExpirationResult, g as TierEvaluation, h as RedemptionValidation, l as BalanceSummary, m as PaginatedResult, n as CreateEarningRuleInput, o as LoyaltyContext, p as ListQuery, r as CreateTierInput, s as UpdateEarningRuleInput } from "./index-DqzTjeEB.mjs";
8
+
9
+ //#region src/services/ledger.service.d.ts
10
+ declare class LedgerService {
11
+ private txPort;
12
+ private memberPort;
13
+ private events;
14
+ private notifications;
15
+ private unitOfWork;
16
+ private config;
17
+ constructor(txPort: PointTransactionPort, memberPort: MemberPort, events: EventEmitterPort, notifications: NotificationAdapter | null, unitOfWork: UnitOfWork, config: ResolvedConfig);
18
+ earnPoints(input: {
19
+ memberId: string;
20
+ points: number;
21
+ description: string;
22
+ referenceType?: string;
23
+ referenceId?: string;
24
+ earningRuleId?: string;
25
+ expiresAt?: Date;
26
+ idempotencyKey?: string;
27
+ metadata?: Record<string, unknown>;
28
+ }, ctx: LoyaltyContext): Promise<PointTransaction>;
29
+ adjustPoints(input: {
30
+ memberId: string;
31
+ points: number;
32
+ description: string;
33
+ reason: string;
34
+ referenceType?: string;
35
+ referenceId?: string;
36
+ idempotencyKey?: string;
37
+ metadata?: Record<string, unknown>;
38
+ }, ctx: LoyaltyContext): Promise<PointTransaction>;
39
+ getHistory(memberId: string, query: ListQuery, ctx: LoyaltyContext): Promise<PaginatedResult<PointTransaction>>;
40
+ getBalance(memberId: string, ctx: LoyaltyContext): Promise<number>;
41
+ processExpirations(ctx: LoyaltyContext): Promise<ExpirationResult>;
42
+ }
43
+ //#endregion
44
+ //#region src/services/earning.service.d.ts
45
+ declare class EarningService {
46
+ private rulePort;
47
+ private ledger;
48
+ private memberPort;
49
+ private config;
50
+ constructor(rulePort: EarningRulePort, ledger: LedgerService, memberPort: MemberPort, config: ResolvedConfig);
51
+ evaluateOrder(input: {
52
+ memberId: string;
53
+ orderId: string;
54
+ orderTotal: number;
55
+ items?: Array<{
56
+ categoryId?: string;
57
+ amount: number;
58
+ quantity: number;
59
+ }>;
60
+ }, ctx: LoyaltyContext): Promise<EarningResult>;
61
+ evaluateAction(input: {
62
+ memberId: string;
63
+ action: string;
64
+ referenceId?: string;
65
+ }, ctx: LoyaltyContext): Promise<EarningResult>;
66
+ createRule(input: CreateEarningRuleInput, ctx: LoyaltyContext): Promise<EarningRule>;
67
+ updateRule(ruleId: string, input: UpdateEarningRuleInput, ctx: LoyaltyContext): Promise<EarningRule>;
68
+ deactivateRule(ruleId: string, ctx: LoyaltyContext): Promise<EarningRule>;
69
+ listRules(query: ListQuery, ctx: LoyaltyContext): Promise<PaginatedResult<EarningRule>>;
70
+ private matchesConditions;
71
+ private calculateOrderPoints;
72
+ private calculateCategoryPoints;
73
+ private applyRounding;
74
+ }
75
+ //#endregion
76
+ //#region src/services/member.service.d.ts
77
+ declare class MemberService {
78
+ private memberPort;
79
+ private events;
80
+ private notifications;
81
+ private unitOfWork;
82
+ private config;
83
+ constructor(memberPort: MemberPort, events: EventEmitterPort, notifications: NotificationAdapter | null, unitOfWork: UnitOfWork, config: ResolvedConfig);
84
+ enroll(input: {
85
+ externalId: string;
86
+ externalType: string;
87
+ programId?: string;
88
+ tier?: string; /** Public loyalty card identifier (set by integration layer, e.g. MBR-DHK-00004821-8) */
89
+ cardId?: string;
90
+ metadata?: Record<string, unknown>;
91
+ }, ctx: LoyaltyContext): Promise<Member>;
92
+ deactivate(memberId: string, ctx: LoyaltyContext): Promise<Member>;
93
+ reactivate(memberId: string, ctx: LoyaltyContext): Promise<Member>;
94
+ suspend(memberId: string, reason: string, ctx: LoyaltyContext): Promise<Member>;
95
+ getById(memberId: string, ctx: LoyaltyContext): Promise<Member>;
96
+ getByExternalId(externalId: string, externalType: string, ctx: LoyaltyContext): Promise<Member | null>;
97
+ getByCardId(cardId: string, ctx: LoyaltyContext): Promise<Member | null>;
98
+ getBalance(memberId: string, ctx: LoyaltyContext): Promise<BalanceSummary>;
99
+ }
100
+ //#endregion
101
+ //#region src/services/redemption.service.d.ts
102
+ declare class RedemptionService {
103
+ private redemptionPort;
104
+ private memberPort;
105
+ private txPort;
106
+ private events;
107
+ private notifications;
108
+ private unitOfWork;
109
+ private config;
110
+ constructor(redemptionPort: RedemptionPort, memberPort: MemberPort, txPort: PointTransactionPort, events: EventEmitterPort, notifications: NotificationAdapter | null, unitOfWork: UnitOfWork, config: ResolvedConfig);
111
+ validate(input: {
112
+ memberId: string;
113
+ pointsToRedeem: number;
114
+ orderTotal: number;
115
+ }, ctx: LoyaltyContext): Promise<RedemptionValidation>;
116
+ reserve(input: {
117
+ memberId: string;
118
+ pointsToRedeem: number;
119
+ orderTotal: number;
120
+ ownerType: string;
121
+ ownerId: string;
122
+ expiresAt?: Date;
123
+ }, ctx: LoyaltyContext): Promise<Redemption>;
124
+ confirm(redemptionId: string, ctx: LoyaltyContext): Promise<Redemption>;
125
+ release(redemptionId: string, ctx: LoyaltyContext): Promise<Redemption>;
126
+ cleanupExpired(ctx: LoyaltyContext): Promise<number>;
127
+ }
128
+ //#endregion
129
+ //#region src/services/referral.service.d.ts
130
+ declare class ReferralService {
131
+ private referralPort;
132
+ private memberPort;
133
+ private ledger;
134
+ private events;
135
+ private notifications;
136
+ private config;
137
+ constructor(referralPort: ReferralPort, memberPort: MemberPort, ledger: LedgerService, events: EventEmitterPort, notifications: NotificationAdapter | null, config: ResolvedConfig);
138
+ generateCode(memberId: string, ctx: LoyaltyContext): Promise<string>;
139
+ lookupByCode(code: string, ctx: LoyaltyContext): Promise<Member | null>;
140
+ recordReferral(input: {
141
+ referralCode: string;
142
+ refereeExternalId: string;
143
+ refereeExternalType: string;
144
+ }, ctx: LoyaltyContext): Promise<Referral>;
145
+ approve(referralId: string, ctx: LoyaltyContext): Promise<Referral>;
146
+ reject(referralId: string, reason: string, ctx: LoyaltyContext): Promise<Referral>;
147
+ getReferralsByReferrer(memberId: string, query: ListQuery, ctx: LoyaltyContext): Promise<PaginatedResult<Referral>>;
148
+ cleanupExpired(ctx: LoyaltyContext): Promise<number>;
149
+ private rewardBothSides;
150
+ private requireReferral;
151
+ }
152
+ //#endregion
153
+ //#region src/services/tier.service.d.ts
154
+ declare class TierService {
155
+ private tierPort;
156
+ private memberPort;
157
+ private events;
158
+ private notifications;
159
+ private config;
160
+ constructor(tierPort: TierDefinitionPort, memberPort: MemberPort, events: EventEmitterPort, notifications: NotificationAdapter | null, config: ResolvedConfig);
161
+ evaluateMember(memberId: string, ctx: LoyaltyContext): Promise<TierEvaluation>;
162
+ evaluateAll(ctx: LoyaltyContext): Promise<TierEvaluationBatch>;
163
+ setOverride(memberId: string, tierName: string, reason: string, ctx: LoyaltyContext): Promise<Member>;
164
+ clearOverride(memberId: string, ctx: LoyaltyContext): Promise<TierEvaluation>;
165
+ createTier(input: CreateTierInput, ctx: LoyaltyContext): Promise<TierDefinition>;
166
+ updateTier(tierId: string, input: UpdateTierInput, ctx: LoyaltyContext): Promise<TierDefinition>;
167
+ deleteTier(tierId: string, ctx: LoyaltyContext): Promise<void>;
168
+ listTiers(ctx: LoyaltyContext): Promise<TierDefinition[]>;
169
+ private applyUpgrade;
170
+ private applyDowngrade;
171
+ }
172
+ //#endregion
173
+ //#region src/services/index.d.ts
174
+ interface LoyaltyServices {
175
+ member: MemberService;
176
+ ledger: LedgerService;
177
+ earning: EarningService;
178
+ tier: TierService;
179
+ redemption: RedemptionService;
180
+ referral: ReferralService;
181
+ }
182
+ interface CreateServicesInput {
183
+ repositories: LoyaltyRepositories;
184
+ unitOfWork: UnitOfWork;
185
+ events: EventEmitterPort;
186
+ notifications: NotificationAdapter | null;
187
+ config: ResolvedConfig;
188
+ }
189
+ declare function createServices(input: CreateServicesInput): LoyaltyServices;
190
+ //#endregion
191
+ export { ReferralService as a, EarningService as c, TierService as i, LedgerService as l, LoyaltyServices as n, RedemptionService as o, createServices as r, MemberService as s, CreateServicesInput as t };
@@ -0,0 +1,21 @@
1
+ import { a as PointTransaction, n as TierDefinition, o as Member, s as MemberBalance, u as EarningRule } from "./tier-definition-Djf72UPa.mjs";
2
+ import { l as Referral, u as Redemption } from "./tier-definition.port-BzrHYBRo.mjs";
3
+ import { t as EventEmitterPort } from "./event-emitter.port-CLYPoMni.mjs";
4
+ import { n as LoyaltyEvents } from "./index-O7TL4R2P.mjs";
5
+ import { n as LoyaltyConfig, o as ResolvedConfig, s as ResolvedTenant } from "./config-aNigy4ec.mjs";
6
+ import { t as LoyaltyModels } from "./index-B6ZstxSP.mjs";
7
+ import { t as LoyaltyRepositories } from "./index-BcoGeDco.mjs";
8
+ import { a as EnrollInput, c as UpdateTierInput, d as EarningResult, g as TierEvaluation, h as RedemptionValidation, i as EarnPointsInput, l as BalanceSummary, n as CreateEarningRuleInput, o as LoyaltyContext, r as CreateTierInput, s as UpdateEarningRuleInput, t as AdjustPointsInput } from "./index-DqzTjeEB.mjs";
9
+ import { n as LoyaltyServices } from "./index-_pg4J11t.mjs";
10
+
11
+ //#region src/index.d.ts
12
+ declare function resolveConfig(config: LoyaltyConfig): ResolvedConfig;
13
+ interface LoyaltyEngine {
14
+ models: LoyaltyModels;
15
+ repositories: LoyaltyRepositories;
16
+ services: LoyaltyServices;
17
+ events: EventEmitterPort;
18
+ }
19
+ declare function createLoyaltyEngine(config: LoyaltyConfig): LoyaltyEngine;
20
+ //#endregion
21
+ export { type AdjustPointsInput, type BalanceSummary, type CreateEarningRuleInput, type CreateTierInput, type EarnPointsInput, type EarningResult, type EarningRule, type EnrollInput, type EventEmitterPort, type LoyaltyConfig, type LoyaltyContext, LoyaltyEngine, LoyaltyEvents, type LoyaltyModels, type LoyaltyRepositories, type LoyaltyServices, type Member, type MemberBalance, type PointTransaction, type Redemption, type RedemptionValidation, type Referral, type ResolvedConfig, type ResolvedTenant, type TierDefinition, type TierEvaluation, type UpdateEarningRuleInput, type UpdateTierInput, createLoyaltyEngine, resolveConfig };