b23-lib 1.7.0 → 1.7.2
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/Auth/index.d.mts +130 -0
- package/dist/Auth/index.d.ts +130 -0
- package/dist/Auth/index.js +2 -0
- package/dist/Auth/index.js.map +1 -0
- package/dist/Auth/index.mjs +2 -0
- package/dist/Auth/index.mjs.map +1 -0
- package/dist/Classes/Address.d.mts +142 -0
- package/dist/Classes/Address.d.ts +142 -0
- package/dist/Classes/Address.js +2 -0
- package/dist/Classes/Address.js.map +1 -0
- package/dist/Classes/Address.mjs +2 -0
- package/dist/Classes/Address.mjs.map +1 -0
- package/dist/Classes/Base.d.mts +98 -0
- package/dist/Classes/Base.d.ts +98 -0
- package/dist/Classes/Base.js +2 -0
- package/dist/Classes/Base.js.map +1 -0
- package/dist/Classes/Base.mjs +2 -0
- package/dist/Classes/Base.mjs.map +1 -0
- package/dist/Classes/Cart.d.mts +68 -0
- package/dist/Classes/Cart.d.ts +68 -0
- package/dist/Classes/Cart.js +2 -0
- package/dist/Classes/Cart.js.map +1 -0
- package/dist/Classes/Cart.mjs +2 -0
- package/dist/Classes/Cart.mjs.map +1 -0
- package/dist/Classes/Common.d.mts +75 -0
- package/dist/Classes/Common.d.ts +75 -0
- package/dist/Classes/Common.js +2 -0
- package/dist/Classes/Common.js.map +1 -0
- package/dist/Classes/Common.mjs +2 -0
- package/dist/Classes/Common.mjs.map +1 -0
- package/dist/Classes/Coupon.d.mts +142 -0
- package/dist/Classes/Coupon.d.ts +142 -0
- package/dist/Classes/Coupon.js +2 -0
- package/dist/Classes/Coupon.js.map +1 -0
- package/dist/Classes/Coupon.mjs +2 -0
- package/dist/Classes/Coupon.mjs.map +1 -0
- package/dist/Classes/Customer.d.mts +97 -0
- package/dist/Classes/Customer.d.ts +97 -0
- package/dist/Classes/Customer.js +2 -0
- package/dist/Classes/Customer.js.map +1 -0
- package/dist/Classes/Customer.mjs +2 -0
- package/dist/Classes/Customer.mjs.map +1 -0
- package/dist/Classes/CustomerAddress.d.mts +71 -0
- package/dist/Classes/CustomerAddress.d.ts +71 -0
- package/dist/Classes/CustomerAddress.js +2 -0
- package/dist/Classes/CustomerAddress.js.map +1 -0
- package/dist/Classes/CustomerAddress.mjs +2 -0
- package/dist/Classes/CustomerAddress.mjs.map +1 -0
- package/dist/Classes/Enum.d.mts +34 -0
- package/dist/Classes/Enum.d.ts +34 -0
- package/dist/Classes/Enum.js +2 -0
- package/dist/Classes/Enum.js.map +1 -0
- package/dist/Classes/Enum.mjs +2 -0
- package/dist/Classes/Enum.mjs.map +1 -0
- package/dist/Classes/ImageInfo.d.mts +92 -0
- package/dist/Classes/ImageInfo.d.ts +92 -0
- package/dist/Classes/ImageInfo.js +2 -0
- package/dist/Classes/ImageInfo.js.map +1 -0
- package/dist/Classes/ImageInfo.mjs +2 -0
- package/dist/Classes/ImageInfo.mjs.map +1 -0
- package/dist/Classes/LineItem.d.mts +124 -0
- package/dist/Classes/LineItem.d.ts +124 -0
- package/dist/Classes/LineItem.js +2 -0
- package/dist/Classes/LineItem.js.map +1 -0
- package/dist/Classes/LineItem.mjs +2 -0
- package/dist/Classes/LineItem.mjs.map +1 -0
- package/dist/Classes/Order.d.mts +83 -0
- package/dist/Classes/Order.d.ts +83 -0
- package/dist/Classes/Order.js +2 -0
- package/dist/Classes/Order.js.map +1 -0
- package/dist/Classes/Order.mjs +2 -0
- package/dist/Classes/Order.mjs.map +1 -0
- package/dist/Classes/Payment.d.mts +161 -0
- package/dist/Classes/Payment.d.ts +161 -0
- package/dist/Classes/Payment.js +2 -0
- package/dist/Classes/Payment.js.map +1 -0
- package/dist/Classes/Payment.mjs +2 -0
- package/dist/Classes/Payment.mjs.map +1 -0
- package/dist/Classes/Price.d.mts +70 -0
- package/dist/Classes/Price.d.ts +70 -0
- package/dist/Classes/Price.js +2 -0
- package/dist/Classes/Price.js.map +1 -0
- package/dist/Classes/Price.mjs +2 -0
- package/dist/Classes/Price.mjs.map +1 -0
- package/dist/Classes/Product.d.mts +209 -0
- package/dist/Classes/Product.d.ts +209 -0
- package/dist/Classes/Product.js +2 -0
- package/dist/Classes/Product.js.map +1 -0
- package/dist/Classes/Product.mjs +2 -0
- package/dist/Classes/Product.mjs.map +1 -0
- package/dist/Classes/ShoppingContainer.d.mts +194 -0
- package/dist/Classes/ShoppingContainer.d.ts +194 -0
- package/dist/Classes/ShoppingContainer.js +2 -0
- package/dist/Classes/ShoppingContainer.js.map +1 -0
- package/dist/Classes/ShoppingContainer.mjs +2 -0
- package/dist/Classes/ShoppingContainer.mjs.map +1 -0
- package/dist/Dynamodb/index.d.mts +58 -0
- package/dist/Dynamodb/index.d.ts +58 -0
- package/dist/Dynamodb/index.js +2 -0
- package/dist/Dynamodb/index.js.map +1 -0
- package/dist/Dynamodb/index.mjs +2 -0
- package/dist/Dynamodb/index.mjs.map +1 -0
- package/dist/chunk-4H4LJ3UL.mjs +2 -0
- package/dist/chunk-4H4LJ3UL.mjs.map +1 -0
- package/dist/chunk-65X54TKF.mjs +2 -0
- package/dist/chunk-65X54TKF.mjs.map +1 -0
- package/dist/chunk-763MN5XV.mjs +2 -0
- package/dist/chunk-763MN5XV.mjs.map +1 -0
- package/dist/chunk-CWKGR4AF.mjs +2 -0
- package/dist/chunk-CWKGR4AF.mjs.map +1 -0
- package/dist/chunk-DKI6BDWK.mjs +2 -0
- package/dist/chunk-DKI6BDWK.mjs.map +1 -0
- package/dist/chunk-SPLTJRHG.mjs +2 -0
- package/dist/chunk-SPLTJRHG.mjs.map +1 -0
- package/dist/chunk-T6IVHYQQ.mjs +2 -0
- package/dist/chunk-T6IVHYQQ.mjs.map +1 -0
- package/dist/chunk-T6YCHB3K.mjs +2 -0
- package/dist/chunk-T6YCHB3K.mjs.map +1 -0
- package/dist/chunk-WU6FFDBS.mjs +2 -0
- package/dist/chunk-WU6FFDBS.mjs.map +1 -0
- package/dist/index.d.mts +1 -624
- package/dist/index.d.ts +1 -624
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +163 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import BaseModel, { BaseAttributes } from './Base.js';
|
|
2
|
+
import { LocalizedString, ISODateTime, RegionalPriceList, LocaleCode, CountryCode, RegionalPrice } from './Common.js';
|
|
3
|
+
import './Enum.js';
|
|
4
|
+
|
|
5
|
+
declare enum CouponType {
|
|
6
|
+
COUPON = "coupon",
|
|
7
|
+
AUTOMATIC = "automatic"
|
|
8
|
+
}
|
|
9
|
+
declare enum CouponDiscountMethod {
|
|
10
|
+
FLAT = "flat",
|
|
11
|
+
PERCENTAGE = "percentage"
|
|
12
|
+
}
|
|
13
|
+
declare enum CouponCategory {
|
|
14
|
+
SHIPPING = "SHIPPING",
|
|
15
|
+
CUSTOMER = "CUSTOMER"
|
|
16
|
+
}
|
|
17
|
+
declare enum ApplicableTo {
|
|
18
|
+
ALL = "all",
|
|
19
|
+
FTB = "ftb"
|
|
20
|
+
}
|
|
21
|
+
type CouponAttribute = BaseAttributes & {
|
|
22
|
+
couponCode: string;
|
|
23
|
+
name: LocalizedString;
|
|
24
|
+
description: LocalizedString;
|
|
25
|
+
type: CouponType;
|
|
26
|
+
customerId?: string;
|
|
27
|
+
validFrom: ISODateTime;
|
|
28
|
+
validTo: ISODateTime;
|
|
29
|
+
minCartValue: RegionalPriceList;
|
|
30
|
+
maxCartDiscount: RegionalPriceList;
|
|
31
|
+
discountMethod: CouponDiscountMethod;
|
|
32
|
+
percentageValue?: number;
|
|
33
|
+
applicableTo: ApplicableTo;
|
|
34
|
+
category: CouponCategory;
|
|
35
|
+
};
|
|
36
|
+
type CouponData = Required<CouponAttribute>;
|
|
37
|
+
/**
|
|
38
|
+
* Represents a discount coupon, extending BaseModel.
|
|
39
|
+
*/
|
|
40
|
+
declare class CouponModel extends BaseModel {
|
|
41
|
+
protected couponCode: string;
|
|
42
|
+
protected name: LocalizedString;
|
|
43
|
+
protected description: LocalizedString;
|
|
44
|
+
protected type: CouponType;
|
|
45
|
+
protected customerId?: string;
|
|
46
|
+
protected validFrom: ISODateTime;
|
|
47
|
+
protected validTo: ISODateTime;
|
|
48
|
+
protected minCartValue: RegionalPriceList;
|
|
49
|
+
protected maxCartDiscount: RegionalPriceList;
|
|
50
|
+
protected discountMethod: CouponDiscountMethod;
|
|
51
|
+
protected percentageValue: number;
|
|
52
|
+
protected applicableTo: ApplicableTo;
|
|
53
|
+
protected category: CouponCategory;
|
|
54
|
+
/**
|
|
55
|
+
* Creates an instance of CouponModel.
|
|
56
|
+
* @param data - The initial coupon attributes.
|
|
57
|
+
* @param date - Optional date for setting creation/modification times (defaults to now).
|
|
58
|
+
*/
|
|
59
|
+
constructor(data: CouponAttribute, date?: Date);
|
|
60
|
+
/** Gets the unique coupon code. */
|
|
61
|
+
getCode(): string;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the full localized coupon name object.
|
|
64
|
+
* @returns A copy of the LocalizedString object for the name.
|
|
65
|
+
*/
|
|
66
|
+
getName(): LocalizedString;
|
|
67
|
+
/**
|
|
68
|
+
* Gets the coupon name for a specific locale, falling back to English ('en').
|
|
69
|
+
* @param locale - The desired locale code.
|
|
70
|
+
* @returns The name string for the specified locale.
|
|
71
|
+
*/
|
|
72
|
+
getName(locale: LocaleCode): string;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the full localized coupon description object.
|
|
75
|
+
* @returns A copy of the LocalizedString object for the description, or undefined.
|
|
76
|
+
*/
|
|
77
|
+
getDescription(): LocalizedString;
|
|
78
|
+
/**
|
|
79
|
+
* Gets the coupon description for a specific locale, falling back to English ('en').
|
|
80
|
+
* @param locale - The desired locale code.
|
|
81
|
+
* @returns The description string for the specified locale.
|
|
82
|
+
*/
|
|
83
|
+
getDescription(locale: LocaleCode): string;
|
|
84
|
+
/** Gets the type of coupon (COUPON or AUTOMATIC). */
|
|
85
|
+
getType(): CouponType;
|
|
86
|
+
/** Gets the specific customer ID this coupon is limited to, if any. */
|
|
87
|
+
getCustomerId(): string;
|
|
88
|
+
/** Gets the ISO date string from when the coupon is valid. */
|
|
89
|
+
getValidFrom(): ISODateTime;
|
|
90
|
+
/** Gets the ISO date string until when the coupon is valid. */
|
|
91
|
+
getValidTo(): ISODateTime;
|
|
92
|
+
/**
|
|
93
|
+
* Gets the list of minimum cart values required for the coupon across different regions.
|
|
94
|
+
* Returns copies of the price objects.
|
|
95
|
+
* @returns The full list of regional minimum cart values.
|
|
96
|
+
*/
|
|
97
|
+
getMinCartValue(): RegionalPriceList;
|
|
98
|
+
/**
|
|
99
|
+
* Gets the minimum cart value required for the coupon for a specific country.
|
|
100
|
+
* @param country - The country code to filter the minimum value for.
|
|
101
|
+
* @returns The regional minimum cart value for the specified country, or undefined if not set for that country.
|
|
102
|
+
*/
|
|
103
|
+
getMinCartValue(country: CountryCode): RegionalPrice | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Gets the list of maximum discount amounts allowed for the coupon across different regions.
|
|
106
|
+
* Returns copies of the price objects.
|
|
107
|
+
* @returns The full list of regional maximum discount caps.
|
|
108
|
+
*/
|
|
109
|
+
getMaxCartDiscount(): RegionalPriceList;
|
|
110
|
+
/**
|
|
111
|
+
* Gets the maximum discount amount allowed for the coupon for a specific country.
|
|
112
|
+
* @param country - The country code to filter the maximum discount for.
|
|
113
|
+
* @returns The regional maximum discount cap for the specified country, or undefined if not set for that country.
|
|
114
|
+
*/
|
|
115
|
+
getMaxCartDiscount(country: CountryCode): RegionalPrice | undefined;
|
|
116
|
+
/** Gets the discount method (FLAT or PERCENTAGE). */
|
|
117
|
+
getDiscountMethod(): CouponDiscountMethod;
|
|
118
|
+
/** Gets the percentage discount value (0-100). */
|
|
119
|
+
getPercentageValue(): number;
|
|
120
|
+
/** Gets the customer applicability rule (ALL or FTB). */
|
|
121
|
+
getApplicableTo(): ApplicableTo;
|
|
122
|
+
/** Gets the category of the coupon (SHIPPING or CUSTOMER). */
|
|
123
|
+
getCategory(): CouponCategory;
|
|
124
|
+
/**
|
|
125
|
+
* Gets a plain data object representing the coupon's details.
|
|
126
|
+
* @returns A CouponData object.
|
|
127
|
+
*/
|
|
128
|
+
getDetails(): CouponData;
|
|
129
|
+
/**
|
|
130
|
+
* Checks if the coupon is currently active based on its validity dates.
|
|
131
|
+
* @returns True if the coupon is currently within its validity period, false otherwise.
|
|
132
|
+
*/
|
|
133
|
+
isActive(): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Checks if the coupon is applicable to a customer based on their status (e.g., first-time buyer).
|
|
136
|
+
* @param ftbCustomer - A boolean indicating whether the customer is a first-time buyer.
|
|
137
|
+
* @returns True if the coupon's applicability rule matches the customer's status, false otherwise.
|
|
138
|
+
*/
|
|
139
|
+
isApplicableTo(ftbCustomer: boolean): boolean;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { ApplicableTo, type CouponAttribute, CouponCategory, type CouponData, CouponDiscountMethod, CouponType, CouponModel as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var i=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(e,t=new Date){this.customFields={...e.customFields},this.version=e.version??1,this.createdAt=e.createdAt&&!isNaN(Date.parse(e.createdAt))?new Date(e.createdAt).toISOString():t.toISOString(),this.modifiedAt=e.modifiedAt&&!isNaN(Date.parse(e.modifiedAt))?new Date(e.modifiedAt).toISOString():t.toISOString(),this.modifiedBy=e.modifiedBy??"";}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return this.modifiedBy}setModifiedBy(e){this.modifiedBy=e;}getCustomField(e){return this.customFields[e]??null}setCustomField(e,t){this.customFields[e]=t;}getAllCustomFields(){return {...this.customFields}}};var a=(t=>(t.COUPON="coupon",t.AUTOMATIC="automatic",t))(a||{}),d=(t=>(t.FLAT="flat",t.PERCENTAGE="percentage",t))(d||{}),c=(t=>(t.SHIPPING="SHIPPING",t.CUSTOMER="CUSTOMER",t))(c||{}),u=(t=>(t.ALL="all",t.FTB="ftb",t))(u||{}),r=class extends i{couponCode;name;description;type;customerId;validFrom;validTo;minCartValue;maxCartDiscount;discountMethod;percentageValue;applicableTo;category;constructor(e,t=new Date){super(e,t),this.couponCode=e.couponCode,this.name={...e.name},this.description={...e.description},this.type=e.type,this.customerId=e.customerId,this.validFrom=e.validFrom&&Date.parse(e.validFrom)?new Date(e.validFrom).toISOString():t.toISOString(),this.validTo=e.validTo&&Date.parse(e.validTo)?new Date(e.validTo).toISOString():t.toISOString(),this.minCartValue=e.minCartValue.map(o=>({...o})),this.maxCartDiscount=e.maxCartDiscount.map(o=>({...o})),this.discountMethod=e.discountMethod,this.percentageValue=e.percentageValue??0,this.applicableTo=e.applicableTo,this.category=e.category;}getCode(){return this.couponCode}getName(e){return e?this.name[e]??this.name.en:{...this.name}}getDescription(e){return e?this.description[e]??this.description.en:{...this.description}}getType(){return this.type}getCustomerId(){return this.customerId??""}getValidFrom(){return this.validFrom}getValidTo(){return this.validTo}getMinCartValue(e){return e?this.minCartValue.find(t=>t.country===e):this.minCartValue}getMaxCartDiscount(e){return e?this.maxCartDiscount.find(t=>t.country===e):this.maxCartDiscount}getDiscountMethod(){return this.discountMethod}getPercentageValue(){return this.percentageValue}getApplicableTo(){return this.applicableTo}getCategory(){return this.category}getDetails(){return {...super.getDetails(),couponCode:this.getCode(),name:this.getName(),description:this.getDescription(),type:this.getType(),customerId:this.getCustomerId(),validFrom:this.getValidFrom(),validTo:this.getValidTo(),minCartValue:this.getMinCartValue(),maxCartDiscount:this.getMaxCartDiscount(),discountMethod:this.getDiscountMethod(),percentageValue:this.getPercentageValue(),applicableTo:this.getApplicableTo(),category:this.getCategory()}}isActive(){return new Date(this.validFrom)<=new Date&&new Date(this.validTo)>=new Date}isApplicableTo(e){return this.applicableTo==="all"||this.applicableTo==="ftb"&&e}};exports.ApplicableTo=u;exports.CouponCategory=c;exports.CouponDiscountMethod=d;exports.CouponType=a;exports.default=r;//# sourceMappingURL=Coupon.js.map
|
|
2
|
+
//# sourceMappingURL=Coupon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/Base.ts","../../src/Classes/Coupon.ts"],"names":["BaseModel","data","date","modifiedBy","fieldName","value","CouponType","CouponDiscountMethod","CouponCategory","ApplicableTo","CouponModel","price","locale","country","ftbCustomer"],"mappings":"sEA0BA,IAAqBA,CAArB,CAAA,KAA+B,CACnB,YAAA,CACA,OACA,CAAA,SAAA,CACA,UACA,CAAA,UAAA,CAQV,WAAYC,CAAAA,CAAAA,CAAsBC,CAAa,CAAA,IAAI,KAAQ,CACzD,IAAA,CAAK,YAAe,CAAA,CAAE,GAAGD,CAAAA,CAAK,YAAa,CAAA,CAC3C,KAAK,OAAUA,CAAAA,CAAAA,CAAK,OAAW,EAAA,CAAA,CAC/B,IAAK,CAAA,SAAA,CAAYA,CAAK,CAAA,SAAA,EAAa,CAAC,KAAM,CAAA,IAAA,CAAK,KAAMA,CAAAA,CAAAA,CAAK,SAAS,CAAC,CAElE,CAAA,IAAI,KAAKA,CAAK,CAAA,SAAS,CAAE,CAAA,WAAA,EAEzBC,CAAAA,CAAAA,CAAK,WAAY,EAAA,CACnB,KAAK,UAAaD,CAAAA,CAAAA,CAAK,UAAc,EAAA,CAAC,KAAM,CAAA,IAAA,CAAK,KAAMA,CAAAA,CAAAA,CAAK,UAAU,CAAC,CAAA,CACnE,IAAI,IAAA,CAAKA,CAAK,CAAA,UAAU,CAAE,CAAA,WAAA,GAC1BC,CAAK,CAAA,WAAA,EAET,CAAA,IAAA,CAAK,UAAaD,CAAAA,CAAAA,CAAK,UAAc,EA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AiB,GAAA,KAAA,EAAoBA,CAC9F,CACF","file":"Coupon.js","sourcesContent":["import { ISODateTime } from \"./Common\";\r\n\r\nexport interface CustomFields {\r\n [key: string]: any;\r\n}\r\n\r\nexport type BaseAttributes = {\r\n customFields?: CustomFields;\r\n version?: number;\r\n createdAt?: ISODateTime;\r\n modifiedAt?: ISODateTime;\r\n modifiedBy?: string;\r\n};\r\n\r\nexport type BaseData = {\r\n customFields: CustomFields;\r\n version: number;\r\n createdAt: ISODateTime;\r\n modifiedAt: ISODateTime;\r\n modifiedBy: string;\r\n};\r\n\r\n/**\r\n * Provides common foundational properties and methods for other data models.\r\n * Handles tracking of custom fields, versioning, and timestamps.\r\n */\r\nexport default class BaseModel {\r\n protected customFields: CustomFields;\r\n protected version: number;\r\n protected createdAt: ISODateTime;\r\n protected modifiedAt: ISODateTime;\r\n protected modifiedBy: string;\r\n\r\n /**\r\n * Creates an instance of BaseModel.\r\n * Initializes common properties like timestamps, version, and custom fields.\r\n * @param data - Optional initial attributes for the base model.\r\n * @param date - Optional date object to use for default timestamps (defaults to current time).\r\n */\r\n constructor(data: BaseAttributes, date: Date = new Date()) {\r\n this.customFields = { ...data.customFields };\r\n this.version = data.version ?? 1;\r\n this.createdAt = data.createdAt && !isNaN(Date.parse(data.createdAt))\r\n ?\r\n new Date(data.createdAt).toISOString()\r\n :\r\n date.toISOString();\r\n this.modifiedAt = data.modifiedAt && !isNaN(Date.parse(data.modifiedAt))\r\n ? new Date(data.modifiedAt).toISOString()\r\n : date.toISOString();\r\n\r\n this.modifiedBy = data.modifiedBy ?? '';\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the base model's current state.\r\n * @returns BaseData object containing common properties.\r\n */\r\n getDetails(): BaseData {\r\n return {\r\n customFields: this.getAllCustomFields(), // Use getter to return a copy\r\n version: this.getVersion(),\r\n createdAt: this.getCreatedAt(),\r\n modifiedAt: this.getModifiedAt(),\r\n modifiedBy: this.getModifiedBy(),\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current version number of the model instance.\r\n * @returns The version number.\r\n */\r\n getVersion(): number {\r\n return this.version;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as an ISO 8601 string.\r\n * @returns The creation timestamp string.\r\n */\r\n getCreatedAt(): string {\r\n return this.createdAt;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as a Unix epoch time (milliseconds).\r\n * @returns The creation time in milliseconds since the epoch.\r\n */\r\n getCreatedAtTime(): number {\r\n return new Date(this.createdAt).getTime();\r\n }\r\n\r\n\r\n /**\r\n * Gets the last modification timestamp as an ISO 8601 string.\r\n * @returns The last modification timestamp string.\r\n */\r\n getModifiedAt(): string {\r\n return this.modifiedAt;\r\n }\r\n\r\n /**\r\n * Gets the last modification timestamp as a Unix epoch time (milliseconds).\r\n * @returns The last modification time in milliseconds since the epoch.\r\n */\r\n getModifiedAtTime(): number {\r\n return new Date(this.modifiedAt).getTime();\r\n }\r\n\r\n /**\r\n * Gets the identifier of the user or process that last modified the instance.\r\n * @returns The modifier identifier string.\r\n */\r\n getModifiedBy(): string {\r\n return this.modifiedBy;\r\n }\r\n\r\n /**\r\n * Sets the identifier of the user or process that last modified the instance.\r\n * @param modifiedBy - The identifier string.\r\n */\r\n setModifiedBy(modifiedBy: string): void {\r\n this.modifiedBy = modifiedBy;\r\n }\r\n\r\n /**\r\n * Retrieves the value of a specific custom field.\r\n * @param fieldName - The name (key) of the custom field to retrieve.\r\n * @returns The value of the custom field, or null if the field does not exist.\r\n */\r\n getCustomField(fieldName: string): any {\r\n return this.customFields[fieldName] ?? null;\r\n }\r\n\r\n /**\r\n * Sets the value of a specific custom field.\r\n * Also updates the modification timestamp and increments the version.\r\n * @param fieldName - The name (key) of the custom field to set.\r\n * @param value - The value to assign to the custom field.\r\n */\r\n setCustomField(fieldName: string, value: any): void {\r\n this.customFields[fieldName] = value;\r\n }\r\n\r\n /**\r\n * Retrieves a shallow copy of all custom fields associated with the instance.\r\n * @returns An object containing all custom fields.\r\n */\r\n getAllCustomFields(): CustomFields {\r\n return { ...this.customFields };\r\n }\r\n}\r\n","import BaseModel, { BaseAttributes } from \"./Base\";\r\nimport { CountryCode, ISODateTime, LocaleCode, LocalizedString, RegionalPrice, RegionalPriceList } from \"./Common\";\r\n\r\nexport enum CouponType {\r\n COUPON = \"coupon\",\r\n AUTOMATIC = \"automatic\",\r\n}\r\n\r\nexport enum CouponDiscountMethod {\r\n FLAT = \"flat\",\r\n PERCENTAGE = \"percentage\",\r\n}\r\n\r\nexport enum CouponCategory {\r\n SHIPPING = \"SHIPPING\",\r\n CUSTOMER = \"CUSTOMER\",\r\n}\r\n\r\nexport enum ApplicableTo {\r\n ALL = \"all\",\r\n FTB = \"ftb\",\r\n}\r\n\r\nexport type CouponAttribute = BaseAttributes & {\r\n couponCode: string;\r\n name: LocalizedString;\r\n description: LocalizedString;\r\n type: CouponType;\r\n customerId?: string;\r\n validFrom: ISODateTime;\r\n validTo: ISODateTime;\r\n minCartValue: RegionalPriceList;\r\n maxCartDiscount: RegionalPriceList;\r\n discountMethod: CouponDiscountMethod;\r\n percentageValue?: number;\r\n applicableTo: ApplicableTo;\r\n category: CouponCategory;\r\n};\r\n\r\nexport type CouponData = Required<CouponAttribute>\r\n\r\n/**\r\n * Represents a discount coupon, extending BaseModel.\r\n */\r\nexport default class CouponModel extends BaseModel {\r\n protected couponCode: string;\r\n protected name: LocalizedString;\r\n protected description: LocalizedString;\r\n protected type: CouponType;\r\n protected customerId?: string;\r\n protected validFrom: ISODateTime;\r\n protected validTo: ISODateTime;\r\n protected minCartValue: RegionalPriceList;\r\n protected maxCartDiscount: RegionalPriceList;\r\n protected discountMethod: CouponDiscountMethod;\r\n protected percentageValue: number;\r\n protected applicableTo: ApplicableTo;\r\n protected category: CouponCategory;\r\n\r\n /**\r\n * Creates an instance of CouponModel.\r\n * @param data - The initial coupon attributes.\r\n * @param date - Optional date for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: CouponAttribute, date: Date = new Date()) {\r\n super(data, date);\r\n\r\n this.couponCode = data.couponCode;\r\n this.name = { ...data.name };\r\n this.description = { ...data.description };\r\n this.type = data.type;\r\n this.customerId = data.customerId;\r\n this.validFrom = data.validFrom && Date.parse(data.validFrom) ? new Date(data.validFrom).toISOString() : date.toISOString();\r\n this.validTo = data.validTo && Date.parse(data.validTo) ? new Date(data.validTo).toISOString() : date.toISOString();\r\n this.minCartValue = data.minCartValue.map(price => ({ ...price }));\r\n this.maxCartDiscount = data.maxCartDiscount.map(price => ({ ...price }));\r\n this.discountMethod = data.discountMethod;\r\n this.percentageValue = data.percentageValue ?? 0;\r\n this.applicableTo = data.applicableTo;\r\n this.category = data.category;\r\n }\r\n\r\n /** Gets the unique coupon code. */\r\n getCode(): string {\r\n return this.couponCode;\r\n }\r\n\r\n /**\r\n * Gets the full localized coupon name object.\r\n * @returns A copy of the LocalizedString object for the name.\r\n */\r\n getName(): LocalizedString\r\n /**\r\n * Gets the coupon name for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The name string for the specified locale.\r\n */\r\n getName(locale: LocaleCode): string\r\n getName(locale?: LocaleCode): LocalizedString | string {\r\n if (locale) {\r\n return this.name[locale] ?? this.name.en;\r\n } else {\r\n return { ...this.name };\r\n }\r\n }\r\n\r\n /**\r\n * Gets the full localized coupon description object.\r\n * @returns A copy of the LocalizedString object for the description, or undefined.\r\n */\r\n getDescription(): LocalizedString\r\n /**\r\n * Gets the coupon description for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The description string for the specified locale.\r\n */\r\n getDescription(locale: LocaleCode): string\r\n getDescription(locale?: LocaleCode): LocalizedString | string {\r\n if (locale) {\r\n return this.description[locale] ?? this.description.en;\r\n } else {\r\n return { ...this.description };\r\n }\r\n }\r\n\r\n /** Gets the type of coupon (COUPON or AUTOMATIC). */\r\n getType(): CouponType {\r\n return this.type;\r\n }\r\n\r\n /** Gets the specific customer ID this coupon is limited to, if any. */\r\n getCustomerId(): string {\r\n return this.customerId ?? '';\r\n }\r\n\r\n /** Gets the ISO date string from when the coupon is valid. */\r\n getValidFrom(): ISODateTime {\r\n return this.validFrom;\r\n }\r\n\r\n /** Gets the ISO date string until when the coupon is valid. */\r\n getValidTo(): ISODateTime {\r\n return this.validTo;\r\n }\r\n\r\n /**\r\n * Gets the list of minimum cart values required for the coupon across different regions.\r\n * Returns copies of the price objects.\r\n * @returns The full list of regional minimum cart values.\r\n */\r\n getMinCartValue(): RegionalPriceList\r\n /**\r\n * Gets the minimum cart value required for the coupon for a specific country.\r\n * @param country - The country code to filter the minimum value for.\r\n * @returns The regional minimum cart value for the specified country, or undefined if not set for that country.\r\n */\r\n getMinCartValue(country: CountryCode): RegionalPrice | undefined\r\n getMinCartValue(country?: CountryCode){\r\n if(country) {\r\n return this.minCartValue.find(price => price.country === country);\r\n }\r\n return this.minCartValue;\r\n }\r\n\r\n /**\r\n * Gets the list of maximum discount amounts allowed for the coupon across different regions.\r\n * Returns copies of the price objects.\r\n * @returns The full list of regional maximum discount caps.\r\n */\r\n getMaxCartDiscount(): RegionalPriceList\r\n /**\r\n * Gets the maximum discount amount allowed for the coupon for a specific country.\r\n * @param country - The country code to filter the maximum discount for.\r\n * @returns The regional maximum discount cap for the specified country, or undefined if not set for that country.\r\n */\r\n getMaxCartDiscount(country: CountryCode): RegionalPrice | undefined\r\n getMaxCartDiscount(country?: CountryCode){\r\n if(country) {\r\n return this.maxCartDiscount.find(price => price.country === country);\r\n }\r\n return this.maxCartDiscount;\r\n }\r\n\r\n /** Gets the discount method (FLAT or PERCENTAGE). */\r\n getDiscountMethod(): CouponDiscountMethod {\r\n return this.discountMethod;\r\n }\r\n\r\n /** Gets the percentage discount value (0-100). */\r\n getPercentageValue(): number {\r\n return this.percentageValue;\r\n }\r\n\r\n /** Gets the customer applicability rule (ALL or FTB). */\r\n getApplicableTo(): ApplicableTo {\r\n return this.applicableTo;\r\n }\r\n\r\n /** Gets the category of the coupon (SHIPPING or CUSTOMER). */\r\n getCategory(): CouponCategory {\r\n return this.category;\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the coupon's details.\r\n * @returns A CouponData object.\r\n */\r\n getDetails(): CouponData {\r\n return {\r\n ...super.getDetails(),\r\n couponCode: this.getCode(),\r\n name: this.getName(),\r\n description: this.getDescription(),\r\n type: this.getType(),\r\n customerId: this.getCustomerId(),\r\n validFrom: this.getValidFrom(),\r\n validTo: this.getValidTo(),\r\n minCartValue: this.getMinCartValue(),\r\n maxCartDiscount: this.getMaxCartDiscount(),\r\n discountMethod: this.getDiscountMethod(),\r\n percentageValue: this.getPercentageValue(),\r\n applicableTo: this.getApplicableTo(),\r\n category: this.getCategory(),\r\n };\r\n }\r\n\r\n /**\r\n * Checks if the coupon is currently active based on its validity dates.\r\n * @returns True if the coupon is currently within its validity period, false otherwise.\r\n */\r\n isActive(): boolean {\r\n return new Date(this.validFrom) <= new Date() && new Date(this.validTo) >= new Date();\r\n }\r\n\r\n \r\n /**\r\n * Checks if the coupon is applicable to a customer based on their status (e.g., first-time buyer).\r\n * @param ftbCustomer - A boolean indicating whether the customer is a first-time buyer.\r\n * @returns True if the coupon's applicability rule matches the customer's status, false otherwise.\r\n */\r\n isApplicableTo(ftbCustomer: boolean): boolean {\r\n return this.applicableTo === ApplicableTo.ALL || (this.applicableTo === ApplicableTo.FTB && ftbCustomer);\r\n }\r\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"Coupon.mjs"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import BaseModel, { BaseAttributes, BaseData } from './Base.mjs';
|
|
2
|
+
import './Common.mjs';
|
|
3
|
+
import './Enum.mjs';
|
|
4
|
+
|
|
5
|
+
declare enum CustomerStatus {
|
|
6
|
+
CREATED = "CREATED",
|
|
7
|
+
REGISTERED_USER = "REGISTERED_USER",
|
|
8
|
+
ACTIVATED_USER = "ACTIVATED_USER",
|
|
9
|
+
EMAIL_OTP = "EMAIL_OTP",
|
|
10
|
+
EMAIL_PASSWORD = "EMAIL_PASSWORD",
|
|
11
|
+
PHONE_OTP = "PHONE_OTP"
|
|
12
|
+
}
|
|
13
|
+
type CustomerAttributes = BaseAttributes & {
|
|
14
|
+
id: string;
|
|
15
|
+
email: string;
|
|
16
|
+
phone: string;
|
|
17
|
+
firstName: string;
|
|
18
|
+
lastName: string;
|
|
19
|
+
isEmailVerified?: boolean;
|
|
20
|
+
customerStatus?: Set<CustomerStatus>;
|
|
21
|
+
};
|
|
22
|
+
type CustomerDataWithArrayStatus = Omit<CustomerAttributes, 'customerStatus'> & BaseData & {
|
|
23
|
+
customerStatus: CustomerStatus[];
|
|
24
|
+
};
|
|
25
|
+
type CustomerData = Required<CustomerDataWithArrayStatus>;
|
|
26
|
+
type CustomerDataWithOutId = Omit<CustomerData, 'id'>;
|
|
27
|
+
/**
|
|
28
|
+
* Represents a customer entity, managing customer information and status.
|
|
29
|
+
*/
|
|
30
|
+
declare class CustomerModel extends BaseModel {
|
|
31
|
+
protected id: string;
|
|
32
|
+
protected email: string;
|
|
33
|
+
protected phone: string;
|
|
34
|
+
protected firstName: string;
|
|
35
|
+
protected lastName: string;
|
|
36
|
+
protected isEmailVerified: boolean;
|
|
37
|
+
protected customerStatus: Set<CustomerStatus>;
|
|
38
|
+
/**
|
|
39
|
+
* Creates an instance of CustomerModel.
|
|
40
|
+
* Initializes customer properties and ensures the CREATED status is always present.
|
|
41
|
+
* @param data - The initial attributes for the customer.
|
|
42
|
+
* @param date - Optional date object for setting creation/modification times (defaults to now).
|
|
43
|
+
*/
|
|
44
|
+
constructor(data: CustomerAttributes, date?: Date);
|
|
45
|
+
/**
|
|
46
|
+
* Gets a plain data object representing the customer's current state.
|
|
47
|
+
* Can optionally exclude the customer ID. Includes base model details.
|
|
48
|
+
* @param withId - If true, includes the 'id' field. Defaults to false.
|
|
49
|
+
* @returns CustomerData or CustomerDataWithOutId object suitable for serialization.
|
|
50
|
+
*/
|
|
51
|
+
getDetails(withId?: false): CustomerDataWithOutId;
|
|
52
|
+
getDetails(withId: true): CustomerData;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the unique identifier for the customer.
|
|
55
|
+
* @returns The customer ID.
|
|
56
|
+
*/
|
|
57
|
+
getId(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the email address of the customer.
|
|
60
|
+
* @returns The email address.
|
|
61
|
+
*/
|
|
62
|
+
getEmail(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the phone number of the customer.
|
|
65
|
+
* @returns The phone number.
|
|
66
|
+
*/
|
|
67
|
+
getPhone(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the first name of the customer.
|
|
70
|
+
* @returns The first name.
|
|
71
|
+
*/
|
|
72
|
+
getFirstName(): string;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the last name of the customer.
|
|
75
|
+
* @returns The last name.
|
|
76
|
+
*/
|
|
77
|
+
getLastName(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Checks if the customer's email address has been verified.
|
|
80
|
+
* @returns True if the email is verified, false otherwise.
|
|
81
|
+
*/
|
|
82
|
+
getIsEmailVerified(): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Gets the customer's current statuses as an array.
|
|
85
|
+
* @returns An array of CustomerStatus enum values.
|
|
86
|
+
*/
|
|
87
|
+
getCustomerStatus(): CustomerStatus[];
|
|
88
|
+
/**
|
|
89
|
+
* Checks if the customer has a specific status.
|
|
90
|
+
* Note: This method currently returns void. It should likely return boolean.
|
|
91
|
+
* @param customerStatus - The status to check for.
|
|
92
|
+
* @returns return boolean: true if the status exists, false otherwise.
|
|
93
|
+
*/
|
|
94
|
+
hasCustomerStatus(customerStatus: CustomerStatus): boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { type CustomerAttributes, type CustomerData, type CustomerDataWithOutId, CustomerStatus, CustomerModel as default };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import BaseModel, { BaseAttributes, BaseData } from './Base.js';
|
|
2
|
+
import './Common.js';
|
|
3
|
+
import './Enum.js';
|
|
4
|
+
|
|
5
|
+
declare enum CustomerStatus {
|
|
6
|
+
CREATED = "CREATED",
|
|
7
|
+
REGISTERED_USER = "REGISTERED_USER",
|
|
8
|
+
ACTIVATED_USER = "ACTIVATED_USER",
|
|
9
|
+
EMAIL_OTP = "EMAIL_OTP",
|
|
10
|
+
EMAIL_PASSWORD = "EMAIL_PASSWORD",
|
|
11
|
+
PHONE_OTP = "PHONE_OTP"
|
|
12
|
+
}
|
|
13
|
+
type CustomerAttributes = BaseAttributes & {
|
|
14
|
+
id: string;
|
|
15
|
+
email: string;
|
|
16
|
+
phone: string;
|
|
17
|
+
firstName: string;
|
|
18
|
+
lastName: string;
|
|
19
|
+
isEmailVerified?: boolean;
|
|
20
|
+
customerStatus?: Set<CustomerStatus>;
|
|
21
|
+
};
|
|
22
|
+
type CustomerDataWithArrayStatus = Omit<CustomerAttributes, 'customerStatus'> & BaseData & {
|
|
23
|
+
customerStatus: CustomerStatus[];
|
|
24
|
+
};
|
|
25
|
+
type CustomerData = Required<CustomerDataWithArrayStatus>;
|
|
26
|
+
type CustomerDataWithOutId = Omit<CustomerData, 'id'>;
|
|
27
|
+
/**
|
|
28
|
+
* Represents a customer entity, managing customer information and status.
|
|
29
|
+
*/
|
|
30
|
+
declare class CustomerModel extends BaseModel {
|
|
31
|
+
protected id: string;
|
|
32
|
+
protected email: string;
|
|
33
|
+
protected phone: string;
|
|
34
|
+
protected firstName: string;
|
|
35
|
+
protected lastName: string;
|
|
36
|
+
protected isEmailVerified: boolean;
|
|
37
|
+
protected customerStatus: Set<CustomerStatus>;
|
|
38
|
+
/**
|
|
39
|
+
* Creates an instance of CustomerModel.
|
|
40
|
+
* Initializes customer properties and ensures the CREATED status is always present.
|
|
41
|
+
* @param data - The initial attributes for the customer.
|
|
42
|
+
* @param date - Optional date object for setting creation/modification times (defaults to now).
|
|
43
|
+
*/
|
|
44
|
+
constructor(data: CustomerAttributes, date?: Date);
|
|
45
|
+
/**
|
|
46
|
+
* Gets a plain data object representing the customer's current state.
|
|
47
|
+
* Can optionally exclude the customer ID. Includes base model details.
|
|
48
|
+
* @param withId - If true, includes the 'id' field. Defaults to false.
|
|
49
|
+
* @returns CustomerData or CustomerDataWithOutId object suitable for serialization.
|
|
50
|
+
*/
|
|
51
|
+
getDetails(withId?: false): CustomerDataWithOutId;
|
|
52
|
+
getDetails(withId: true): CustomerData;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the unique identifier for the customer.
|
|
55
|
+
* @returns The customer ID.
|
|
56
|
+
*/
|
|
57
|
+
getId(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the email address of the customer.
|
|
60
|
+
* @returns The email address.
|
|
61
|
+
*/
|
|
62
|
+
getEmail(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the phone number of the customer.
|
|
65
|
+
* @returns The phone number.
|
|
66
|
+
*/
|
|
67
|
+
getPhone(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the first name of the customer.
|
|
70
|
+
* @returns The first name.
|
|
71
|
+
*/
|
|
72
|
+
getFirstName(): string;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the last name of the customer.
|
|
75
|
+
* @returns The last name.
|
|
76
|
+
*/
|
|
77
|
+
getLastName(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Checks if the customer's email address has been verified.
|
|
80
|
+
* @returns True if the email is verified, false otherwise.
|
|
81
|
+
*/
|
|
82
|
+
getIsEmailVerified(): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Gets the customer's current statuses as an array.
|
|
85
|
+
* @returns An array of CustomerStatus enum values.
|
|
86
|
+
*/
|
|
87
|
+
getCustomerStatus(): CustomerStatus[];
|
|
88
|
+
/**
|
|
89
|
+
* Checks if the customer has a specific status.
|
|
90
|
+
* Note: This method currently returns void. It should likely return boolean.
|
|
91
|
+
* @param customerStatus - The status to check for.
|
|
92
|
+
* @returns return boolean: true if the status exists, false otherwise.
|
|
93
|
+
*/
|
|
94
|
+
hasCustomerStatus(customerStatus: CustomerStatus): boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { type CustomerAttributes, type CustomerData, type CustomerDataWithOutId, CustomerStatus, CustomerModel as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var s=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(t,e=new Date){this.customFields={...t.customFields},this.version=t.version??1,this.createdAt=t.createdAt&&!isNaN(Date.parse(t.createdAt))?new Date(t.createdAt).toISOString():e.toISOString(),this.modifiedAt=t.modifiedAt&&!isNaN(Date.parse(t.modifiedAt))?new Date(t.modifiedAt).toISOString():e.toISOString(),this.modifiedBy=t.modifiedBy??"";}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return this.modifiedBy}setModifiedBy(t){this.modifiedBy=t;}getCustomField(t){return this.customFields[t]??null}setCustomField(t,e){this.customFields[t]=e;}getAllCustomFields(){return {...this.customFields}}};var a=(i=>(i.CREATED="CREATED",i.REGISTERED_USER="REGISTERED_USER",i.ACTIVATED_USER="ACTIVATED_USER",i.EMAIL_OTP="EMAIL_OTP",i.EMAIL_PASSWORD="EMAIL_PASSWORD",i.PHONE_OTP="PHONE_OTP",i))(a||{}),r=class extends s{id;email;phone;firstName;lastName;isEmailVerified;customerStatus;constructor(t,e=new Date){super(t,e),this.id=t.id,this.email=t.email,this.phone=t.phone,this.firstName=t.firstName,this.lastName=t.lastName,this.isEmailVerified=t.isEmailVerified??!1,this.customerStatus=new Set([...t.customerStatus?Array.from(t.customerStatus):[],"CREATED"]);}getDetails(t=!1){return {...super.getDetails(),...t?{id:this.getId()}:{},email:this.getEmail(),phone:this.getPhone(),firstName:this.getFirstName(),lastName:this.getLastName(),isEmailVerified:this.getIsEmailVerified(),customerStatus:this.getCustomerStatus()}}getId(){return this.id}getEmail(){return this.email}getPhone(){return this.phone}getFirstName(){return this.firstName}getLastName(){return this.lastName}getIsEmailVerified(){return this.isEmailVerified}getCustomerStatus(){return Array.from(this.customerStatus)}hasCustomerStatus(t){return this.customerStatus.has(t)}};exports.CustomerStatus=a;exports.default=r;//# sourceMappingURL=Customer.js.map
|
|
2
|
+
//# sourceMappingURL=Customer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/Base.ts","../../src/Classes/Customer.ts"],"names":["BaseModel","data","date","modifiedBy","fieldName","value","CustomerStatus","CustomerModel","withId","customerStatus"],"mappings":"sEA0BA,IAAqBA,EAArB,KAA+B,CACnB,aACA,OACA,CAAA,SAAA,CACA,WACA,UAQV,CAAA,WAAA,CAAYC,EAAsBC,CAAa,CAAA,IAAI,KAAQ,CACzD,IAAA,CAAK,aAAe,CAAE,GAAGD,EAAK,YAAa,CAAA,CAC3C,KAAK,OAAUA,CAAAA,CAAAA,CAAK,SAAW,CAC/B,CAAA,IAAA,CAAK,UAAYA,CAAK,CAAA,SAAA,EAAa,CAAC,KAAM,CAAA,IAAA,CAAK,MAAMA,CAAK,CAAA,SAAS,CAAC,CAElE,CAAA,IAAI,KAAKA,CAAK,CAAA,SAAS,EAAE,WAAY,EAAA,CAErCC,CAAK,CAAA,WAAA,GACP,IAAK,CAAA,UAAA,CAAaD,EAAK,UAAc,EAAA,CAAC,MAAM,IAAK,CAAA,KAAA,CAAMA,EAAK,UAAU,CAAC,EACnE,IAAI,IAAA,CAAKA,EAAK,UAAU,CAAA,CAAE,aAC1BC,CAAAA,CAAAA,CAAK,aAET,CAAA,IAAA,CAAK,WAAaD,CAAK,CAAA,UAAA,EAAc,GACvC,CAMA,UAAA,EAAuB,CACrB,OA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C,OAAO,KAAM,CAAA,IAAA,CAAK,KAAK,cAAc,CACvC,CAQA,iBAAkBC,CAAAA,CAAAA,CAAyC,CACzD,OAAO,IAAA,CAAK,eAAe,GAAIA,CAAAA,CAAc,CAC/C,CACF","file":"Customer.js","sourcesContent":["import { ISODateTime } from \"./Common\";\r\n\r\nexport interface CustomFields {\r\n [key: string]: any;\r\n}\r\n\r\nexport type BaseAttributes = {\r\n customFields?: CustomFields;\r\n version?: number;\r\n createdAt?: ISODateTime;\r\n modifiedAt?: ISODateTime;\r\n modifiedBy?: string;\r\n};\r\n\r\nexport type BaseData = {\r\n customFields: CustomFields;\r\n version: number;\r\n createdAt: ISODateTime;\r\n modifiedAt: ISODateTime;\r\n modifiedBy: string;\r\n};\r\n\r\n/**\r\n * Provides common foundational properties and methods for other data models.\r\n * Handles tracking of custom fields, versioning, and timestamps.\r\n */\r\nexport default class BaseModel {\r\n protected customFields: CustomFields;\r\n protected version: number;\r\n protected createdAt: ISODateTime;\r\n protected modifiedAt: ISODateTime;\r\n protected modifiedBy: string;\r\n\r\n /**\r\n * Creates an instance of BaseModel.\r\n * Initializes common properties like timestamps, version, and custom fields.\r\n * @param data - Optional initial attributes for the base model.\r\n * @param date - Optional date object to use for default timestamps (defaults to current time).\r\n */\r\n constructor(data: BaseAttributes, date: Date = new Date()) {\r\n this.customFields = { ...data.customFields };\r\n this.version = data.version ?? 1;\r\n this.createdAt = data.createdAt && !isNaN(Date.parse(data.createdAt))\r\n ?\r\n new Date(data.createdAt).toISOString()\r\n :\r\n date.toISOString();\r\n this.modifiedAt = data.modifiedAt && !isNaN(Date.parse(data.modifiedAt))\r\n ? new Date(data.modifiedAt).toISOString()\r\n : date.toISOString();\r\n\r\n this.modifiedBy = data.modifiedBy ?? '';\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the base model's current state.\r\n * @returns BaseData object containing common properties.\r\n */\r\n getDetails(): BaseData {\r\n return {\r\n customFields: this.getAllCustomFields(), // Use getter to return a copy\r\n version: this.getVersion(),\r\n createdAt: this.getCreatedAt(),\r\n modifiedAt: this.getModifiedAt(),\r\n modifiedBy: this.getModifiedBy(),\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current version number of the model instance.\r\n * @returns The version number.\r\n */\r\n getVersion(): number {\r\n return this.version;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as an ISO 8601 string.\r\n * @returns The creation timestamp string.\r\n */\r\n getCreatedAt(): string {\r\n return this.createdAt;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as a Unix epoch time (milliseconds).\r\n * @returns The creation time in milliseconds since the epoch.\r\n */\r\n getCreatedAtTime(): number {\r\n return new Date(this.createdAt).getTime();\r\n }\r\n\r\n\r\n /**\r\n * Gets the last modification timestamp as an ISO 8601 string.\r\n * @returns The last modification timestamp string.\r\n */\r\n getModifiedAt(): string {\r\n return this.modifiedAt;\r\n }\r\n\r\n /**\r\n * Gets the last modification timestamp as a Unix epoch time (milliseconds).\r\n * @returns The last modification time in milliseconds since the epoch.\r\n */\r\n getModifiedAtTime(): number {\r\n return new Date(this.modifiedAt).getTime();\r\n }\r\n\r\n /**\r\n * Gets the identifier of the user or process that last modified the instance.\r\n * @returns The modifier identifier string.\r\n */\r\n getModifiedBy(): string {\r\n return this.modifiedBy;\r\n }\r\n\r\n /**\r\n * Sets the identifier of the user or process that last modified the instance.\r\n * @param modifiedBy - The identifier string.\r\n */\r\n setModifiedBy(modifiedBy: string): void {\r\n this.modifiedBy = modifiedBy;\r\n }\r\n\r\n /**\r\n * Retrieves the value of a specific custom field.\r\n * @param fieldName - The name (key) of the custom field to retrieve.\r\n * @returns The value of the custom field, or null if the field does not exist.\r\n */\r\n getCustomField(fieldName: string): any {\r\n return this.customFields[fieldName] ?? null;\r\n }\r\n\r\n /**\r\n * Sets the value of a specific custom field.\r\n * Also updates the modification timestamp and increments the version.\r\n * @param fieldName - The name (key) of the custom field to set.\r\n * @param value - The value to assign to the custom field.\r\n */\r\n setCustomField(fieldName: string, value: any): void {\r\n this.customFields[fieldName] = value;\r\n }\r\n\r\n /**\r\n * Retrieves a shallow copy of all custom fields associated with the instance.\r\n * @returns An object containing all custom fields.\r\n */\r\n getAllCustomFields(): CustomFields {\r\n return { ...this.customFields };\r\n }\r\n}\r\n","import BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\n\r\nexport enum CustomerStatus {\r\n CREATED = \"CREATED\",\r\n REGISTERED_USER = \"REGISTERED_USER\",\r\n ACTIVATED_USER = \"ACTIVATED_USER\",\r\n EMAIL_OTP = \"EMAIL_OTP\",\r\n EMAIL_PASSWORD = \"EMAIL_PASSWORD\",\r\n PHONE_OTP = \"PHONE_OTP\",\r\n}\r\n\r\nexport type CustomerAttributes = BaseAttributes & {\r\n id: string;\r\n email: string;\r\n phone: string;\r\n firstName: string;\r\n lastName: string;\r\n isEmailVerified?: boolean;\r\n customerStatus?: Set<CustomerStatus>;\r\n};\r\n\r\n\r\ntype CustomerDataWithArrayStatus = Omit<CustomerAttributes, 'customerStatus'> & BaseData & { customerStatus: CustomerStatus[]; }\r\nexport type CustomerData = Required<CustomerDataWithArrayStatus>;\r\nexport type CustomerDataWithOutId = Omit<CustomerData, 'id'>;\r\n\r\n/**\r\n * Represents a customer entity, managing customer information and status.\r\n */\r\nexport default class CustomerModel extends BaseModel {\r\n protected id: string;\r\n protected email: string;\r\n protected phone: string;\r\n protected firstName: string;\r\n protected lastName: string;\r\n protected isEmailVerified: boolean;\r\n protected customerStatus: Set<CustomerStatus>;\r\n\r\n /**\r\n * Creates an instance of CustomerModel.\r\n * Initializes customer properties and ensures the CREATED status is always present.\r\n * @param data - The initial attributes for the customer.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: CustomerAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.email = data.email;\r\n this.phone = data.phone;\r\n this.firstName = data.firstName;\r\n this.lastName = data.lastName;\r\n this.isEmailVerified = data.isEmailVerified ?? false;\r\n this.customerStatus = new Set<CustomerStatus>(\r\n [...(data.customerStatus ? Array.from<CustomerStatus>(data.customerStatus) : []), CustomerStatus.CREATED]\r\n );\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the customer's current state.\r\n * Can optionally exclude the customer ID. Includes base model details.\r\n * @param withId - If true, includes the 'id' field. Defaults to false.\r\n * @returns CustomerData or CustomerDataWithOutId object suitable for serialization.\r\n */\r\n getDetails(withId?: false): CustomerDataWithOutId;\r\n getDetails(withId: true): CustomerData;\r\n getDetails(withId: boolean = false): CustomerData | CustomerDataWithOutId {\r\n return {\r\n ...super.getDetails(),\r\n ...(withId ? { id: this.getId() } : {}),\r\n email: this.getEmail(),\r\n phone: this.getPhone(),\r\n firstName: this.getFirstName(),\r\n lastName: this.getLastName(),\r\n isEmailVerified: this.getIsEmailVerified(),\r\n customerStatus: this.getCustomerStatus()\r\n };\r\n }\r\n\r\n /**\r\n * Gets the unique identifier for the customer.\r\n * @returns The customer ID.\r\n */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the email address of the customer.\r\n * @returns The email address.\r\n */\r\n getEmail(): string {\r\n return this.email;\r\n }\r\n\r\n /**\r\n * Gets the phone number of the customer.\r\n * @returns The phone number.\r\n */\r\n getPhone(): string {\r\n return this.phone;\r\n }\r\n\r\n\r\n /**\r\n * Gets the first name of the customer.\r\n * @returns The first name.\r\n */\r\n getFirstName(): string {\r\n return this.firstName;\r\n }\r\n\r\n\r\n /**\r\n * Gets the last name of the customer.\r\n * @returns The last name.\r\n */\r\n getLastName(): string {\r\n return this.lastName;\r\n }\r\n\r\n\r\n /**\r\n * Checks if the customer's email address has been verified.\r\n * @returns True if the email is verified, false otherwise.\r\n */\r\n getIsEmailVerified(): boolean {\r\n return this.isEmailVerified;\r\n }\r\n\r\n\r\n /**\r\n * Gets the customer's current statuses as an array.\r\n * @returns An array of CustomerStatus enum values.\r\n */\r\n getCustomerStatus(): CustomerStatus[] {\r\n return Array.from(this.customerStatus);\r\n }\r\n\r\n /**\r\n * Checks if the customer has a specific status.\r\n * Note: This method currently returns void. It should likely return boolean.\r\n * @param customerStatus - The status to check for.\r\n * @returns return boolean: true if the status exists, false otherwise.\r\n */\r\n hasCustomerStatus(customerStatus: CustomerStatus): boolean {\r\n return this.customerStatus.has(customerStatus);\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {a as a$1}from'../chunk-SPLTJRHG.mjs';var a=(e=>(e.CREATED="CREATED",e.REGISTERED_USER="REGISTERED_USER",e.ACTIVATED_USER="ACTIVATED_USER",e.EMAIL_OTP="EMAIL_OTP",e.EMAIL_PASSWORD="EMAIL_PASSWORD",e.PHONE_OTP="PHONE_OTP",e))(a||{}),s=class extends a$1{id;email;phone;firstName;lastName;isEmailVerified;customerStatus;constructor(t,r=new Date){super(t,r),this.id=t.id,this.email=t.email,this.phone=t.phone,this.firstName=t.firstName,this.lastName=t.lastName,this.isEmailVerified=t.isEmailVerified??!1,this.customerStatus=new Set([...t.customerStatus?Array.from(t.customerStatus):[],"CREATED"]);}getDetails(t=!1){return {...super.getDetails(),...t?{id:this.getId()}:{},email:this.getEmail(),phone:this.getPhone(),firstName:this.getFirstName(),lastName:this.getLastName(),isEmailVerified:this.getIsEmailVerified(),customerStatus:this.getCustomerStatus()}}getId(){return this.id}getEmail(){return this.email}getPhone(){return this.phone}getFirstName(){return this.firstName}getLastName(){return this.lastName}getIsEmailVerified(){return this.isEmailVerified}getCustomerStatus(){return Array.from(this.customerStatus)}hasCustomerStatus(t){return this.customerStatus.has(t)}};export{a as CustomerStatus,s as default};//# sourceMappingURL=Customer.mjs.map
|
|
2
|
+
//# sourceMappingURL=Customer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/Customer.ts"],"names":["CustomerStatus","CustomerModel","BaseModel","data","date","withId","customerStatus"],"mappings":"6CAEO,IAAKA,OACVA,CAAA,CAAA,OAAA,CAAU,UACVA,CAAA,CAAA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A,EACd,CAMA,QAAmB,EAAA,CACjB,OAAO,IAAK,CAAA,KACd,CAMA,QAAmB,EAAA,CACjB,OAAO,IAAK,CAAA,KACd,CAOA,YAAuB,EAAA,CACrB,OAAO,IAAK,CAAA,SACd,CAOA,WAAsB,EAAA,CACpB,OAAO,IAAK,CAAA,QACd,CAOA,kBAA8B,EAAA,CAC5B,OAAO,IAAK,CAAA,eACd,CAOA,iBAAsC,EAAA,CACpC,OAAO,KAAM,CAAA,IAAA,CAAK,KAAK,cAAc,CACvC,CAQA,iBAAkBC,CAAAA,CAAAA,CAAyC,CACzD,OAAO,IAAA,CAAK,eAAe,GAAIA,CAAAA,CAAc,CAC/C,CACF","file":"Customer.mjs","sourcesContent":["import BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\n\r\nexport enum CustomerStatus {\r\n CREATED = \"CREATED\",\r\n REGISTERED_USER = \"REGISTERED_USER\",\r\n ACTIVATED_USER = \"ACTIVATED_USER\",\r\n EMAIL_OTP = \"EMAIL_OTP\",\r\n EMAIL_PASSWORD = \"EMAIL_PASSWORD\",\r\n PHONE_OTP = \"PHONE_OTP\",\r\n}\r\n\r\nexport type CustomerAttributes = BaseAttributes & {\r\n id: string;\r\n email: string;\r\n phone: string;\r\n firstName: string;\r\n lastName: string;\r\n isEmailVerified?: boolean;\r\n customerStatus?: Set<CustomerStatus>;\r\n};\r\n\r\n\r\ntype CustomerDataWithArrayStatus = Omit<CustomerAttributes, 'customerStatus'> & BaseData & { customerStatus: CustomerStatus[]; }\r\nexport type CustomerData = Required<CustomerDataWithArrayStatus>;\r\nexport type CustomerDataWithOutId = Omit<CustomerData, 'id'>;\r\n\r\n/**\r\n * Represents a customer entity, managing customer information and status.\r\n */\r\nexport default class CustomerModel extends BaseModel {\r\n protected id: string;\r\n protected email: string;\r\n protected phone: string;\r\n protected firstName: string;\r\n protected lastName: string;\r\n protected isEmailVerified: boolean;\r\n protected customerStatus: Set<CustomerStatus>;\r\n\r\n /**\r\n * Creates an instance of CustomerModel.\r\n * Initializes customer properties and ensures the CREATED status is always present.\r\n * @param data - The initial attributes for the customer.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: CustomerAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.email = data.email;\r\n this.phone = data.phone;\r\n this.firstName = data.firstName;\r\n this.lastName = data.lastName;\r\n this.isEmailVerified = data.isEmailVerified ?? false;\r\n this.customerStatus = new Set<CustomerStatus>(\r\n [...(data.customerStatus ? Array.from<CustomerStatus>(data.customerStatus) : []), CustomerStatus.CREATED]\r\n );\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the customer's current state.\r\n * Can optionally exclude the customer ID. Includes base model details.\r\n * @param withId - If true, includes the 'id' field. Defaults to false.\r\n * @returns CustomerData or CustomerDataWithOutId object suitable for serialization.\r\n */\r\n getDetails(withId?: false): CustomerDataWithOutId;\r\n getDetails(withId: true): CustomerData;\r\n getDetails(withId: boolean = false): CustomerData | CustomerDataWithOutId {\r\n return {\r\n ...super.getDetails(),\r\n ...(withId ? { id: this.getId() } : {}),\r\n email: this.getEmail(),\r\n phone: this.getPhone(),\r\n firstName: this.getFirstName(),\r\n lastName: this.getLastName(),\r\n isEmailVerified: this.getIsEmailVerified(),\r\n customerStatus: this.getCustomerStatus()\r\n };\r\n }\r\n\r\n /**\r\n * Gets the unique identifier for the customer.\r\n * @returns The customer ID.\r\n */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the email address of the customer.\r\n * @returns The email address.\r\n */\r\n getEmail(): string {\r\n return this.email;\r\n }\r\n\r\n /**\r\n * Gets the phone number of the customer.\r\n * @returns The phone number.\r\n */\r\n getPhone(): string {\r\n return this.phone;\r\n }\r\n\r\n\r\n /**\r\n * Gets the first name of the customer.\r\n * @returns The first name.\r\n */\r\n getFirstName(): string {\r\n return this.firstName;\r\n }\r\n\r\n\r\n /**\r\n * Gets the last name of the customer.\r\n * @returns The last name.\r\n */\r\n getLastName(): string {\r\n return this.lastName;\r\n }\r\n\r\n\r\n /**\r\n * Checks if the customer's email address has been verified.\r\n * @returns True if the email is verified, false otherwise.\r\n */\r\n getIsEmailVerified(): boolean {\r\n return this.isEmailVerified;\r\n }\r\n\r\n\r\n /**\r\n * Gets the customer's current statuses as an array.\r\n * @returns An array of CustomerStatus enum values.\r\n */\r\n getCustomerStatus(): CustomerStatus[] {\r\n return Array.from(this.customerStatus);\r\n }\r\n\r\n /**\r\n * Checks if the customer has a specific status.\r\n * Note: This method currently returns void. It should likely return boolean.\r\n * @param customerStatus - The status to check for.\r\n * @returns return boolean: true if the status exists, false otherwise.\r\n */\r\n hasCustomerStatus(customerStatus: CustomerStatus): boolean {\r\n return this.customerStatus.has(customerStatus);\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import AddressModel, { AddressData } from './Address.mjs';
|
|
2
|
+
import BaseModel, { BaseAttributes } from './Base.mjs';
|
|
3
|
+
import './Common.mjs';
|
|
4
|
+
import './Enum.mjs';
|
|
5
|
+
|
|
6
|
+
type CustomerAddressAttributes = BaseAttributes & {
|
|
7
|
+
id: string;
|
|
8
|
+
addresses: AddressData[];
|
|
9
|
+
defaultBillingAddressId: string;
|
|
10
|
+
defaultShippingAddressId: string;
|
|
11
|
+
};
|
|
12
|
+
type CustomerAddressWithoutDefaultAddress = Omit<CustomerAddressAttributes, 'addresses' | 'defaultBillingAddressId' | 'defaultShippingAddressId'> & {
|
|
13
|
+
addresses: AddressData[];
|
|
14
|
+
defaultBillingAddressId: string | null;
|
|
15
|
+
defaultShippingAddressId: string | null;
|
|
16
|
+
};
|
|
17
|
+
type CustomerAddressDataWithOutId = Required<Omit<CustomerAddressWithoutDefaultAddress, 'id'>>;
|
|
18
|
+
type CustomerAddressData = Required<CustomerAddressWithoutDefaultAddress>;
|
|
19
|
+
declare class CustomerAddressModel extends BaseModel {
|
|
20
|
+
protected id: string;
|
|
21
|
+
protected addresses: AddressModel[];
|
|
22
|
+
protected defaultBillingAddressId: string;
|
|
23
|
+
protected defaultShippingAddressId: string;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an instance of CustomerAddressModel.
|
|
26
|
+
* Initializes the address list, sorting them by modification date (most recent first).
|
|
27
|
+
* @param data - The initial attributes for the customer's addresses.
|
|
28
|
+
* @param date - Optional date object for setting creation/modification times (defaults to now).
|
|
29
|
+
*/
|
|
30
|
+
constructor(data: CustomerAddressAttributes, date?: Date);
|
|
31
|
+
/**
|
|
32
|
+
* Gets a plain data object representing the customer's addresses.
|
|
33
|
+
* Can optionally exclude the customer address collection ID. Includes base model details.
|
|
34
|
+
* @param withId - If true, includes the 'id' field of the CustomerAddressModel. Defaults to false.
|
|
35
|
+
* @returns CustomerAddressData or CustomerAddressDataWithOutId object suitable for serialization.
|
|
36
|
+
*/
|
|
37
|
+
getDetails(withId?: false): CustomerAddressDataWithOutId;
|
|
38
|
+
getDetails(withId: true): CustomerAddressData;
|
|
39
|
+
getId(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the list of all associated address models, sorted by modification date (most recent first).
|
|
42
|
+
* @returns An array of AddressModel instances.
|
|
43
|
+
*/
|
|
44
|
+
getAddresses(): AddressModel[];
|
|
45
|
+
/**
|
|
46
|
+
* Gets a filtered list of addresses designated as shipping addresses.
|
|
47
|
+
* @returns An array of AddressModel instances marked as shipping addresses.
|
|
48
|
+
*/
|
|
49
|
+
getShippingAddresses(): AddressModel[];
|
|
50
|
+
/**
|
|
51
|
+
* Gets a filtered list of addresses designated as billing addresses.
|
|
52
|
+
* @returns An array of AddressModel instances marked as billing addresses.
|
|
53
|
+
*/
|
|
54
|
+
getBillingAddresses(): AddressModel[];
|
|
55
|
+
/**
|
|
56
|
+
* Gets the ID of the default billing address.
|
|
57
|
+
* If the stored default ID is invalid or doesn't correspond to a billing address,
|
|
58
|
+
* it falls back to the most recently modified billing address.
|
|
59
|
+
* @returns The ID of the default billing address, or null if no valid billing address exists.
|
|
60
|
+
*/
|
|
61
|
+
getDefaultBillingAddressId(): string | null;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the ID of the default shipping address.
|
|
64
|
+
* If the stored default ID is invalid or doesn't correspond to a shipping address,
|
|
65
|
+
* it falls back to the most recently modified shipping address.
|
|
66
|
+
* @returns The ID of the default shipping address, or null if no valid shipping address exists.
|
|
67
|
+
*/
|
|
68
|
+
getDefaultShippingAddressId(): string | null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { type CustomerAddressAttributes, type CustomerAddressData, type CustomerAddressDataWithOutId, CustomerAddressModel as default };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import AddressModel, { AddressData } from './Address.js';
|
|
2
|
+
import BaseModel, { BaseAttributes } from './Base.js';
|
|
3
|
+
import './Common.js';
|
|
4
|
+
import './Enum.js';
|
|
5
|
+
|
|
6
|
+
type CustomerAddressAttributes = BaseAttributes & {
|
|
7
|
+
id: string;
|
|
8
|
+
addresses: AddressData[];
|
|
9
|
+
defaultBillingAddressId: string;
|
|
10
|
+
defaultShippingAddressId: string;
|
|
11
|
+
};
|
|
12
|
+
type CustomerAddressWithoutDefaultAddress = Omit<CustomerAddressAttributes, 'addresses' | 'defaultBillingAddressId' | 'defaultShippingAddressId'> & {
|
|
13
|
+
addresses: AddressData[];
|
|
14
|
+
defaultBillingAddressId: string | null;
|
|
15
|
+
defaultShippingAddressId: string | null;
|
|
16
|
+
};
|
|
17
|
+
type CustomerAddressDataWithOutId = Required<Omit<CustomerAddressWithoutDefaultAddress, 'id'>>;
|
|
18
|
+
type CustomerAddressData = Required<CustomerAddressWithoutDefaultAddress>;
|
|
19
|
+
declare class CustomerAddressModel extends BaseModel {
|
|
20
|
+
protected id: string;
|
|
21
|
+
protected addresses: AddressModel[];
|
|
22
|
+
protected defaultBillingAddressId: string;
|
|
23
|
+
protected defaultShippingAddressId: string;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an instance of CustomerAddressModel.
|
|
26
|
+
* Initializes the address list, sorting them by modification date (most recent first).
|
|
27
|
+
* @param data - The initial attributes for the customer's addresses.
|
|
28
|
+
* @param date - Optional date object for setting creation/modification times (defaults to now).
|
|
29
|
+
*/
|
|
30
|
+
constructor(data: CustomerAddressAttributes, date?: Date);
|
|
31
|
+
/**
|
|
32
|
+
* Gets a plain data object representing the customer's addresses.
|
|
33
|
+
* Can optionally exclude the customer address collection ID. Includes base model details.
|
|
34
|
+
* @param withId - If true, includes the 'id' field of the CustomerAddressModel. Defaults to false.
|
|
35
|
+
* @returns CustomerAddressData or CustomerAddressDataWithOutId object suitable for serialization.
|
|
36
|
+
*/
|
|
37
|
+
getDetails(withId?: false): CustomerAddressDataWithOutId;
|
|
38
|
+
getDetails(withId: true): CustomerAddressData;
|
|
39
|
+
getId(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the list of all associated address models, sorted by modification date (most recent first).
|
|
42
|
+
* @returns An array of AddressModel instances.
|
|
43
|
+
*/
|
|
44
|
+
getAddresses(): AddressModel[];
|
|
45
|
+
/**
|
|
46
|
+
* Gets a filtered list of addresses designated as shipping addresses.
|
|
47
|
+
* @returns An array of AddressModel instances marked as shipping addresses.
|
|
48
|
+
*/
|
|
49
|
+
getShippingAddresses(): AddressModel[];
|
|
50
|
+
/**
|
|
51
|
+
* Gets a filtered list of addresses designated as billing addresses.
|
|
52
|
+
* @returns An array of AddressModel instances marked as billing addresses.
|
|
53
|
+
*/
|
|
54
|
+
getBillingAddresses(): AddressModel[];
|
|
55
|
+
/**
|
|
56
|
+
* Gets the ID of the default billing address.
|
|
57
|
+
* If the stored default ID is invalid or doesn't correspond to a billing address,
|
|
58
|
+
* it falls back to the most recently modified billing address.
|
|
59
|
+
* @returns The ID of the default billing address, or null if no valid billing address exists.
|
|
60
|
+
*/
|
|
61
|
+
getDefaultBillingAddressId(): string | null;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the ID of the default shipping address.
|
|
64
|
+
* If the stored default ID is invalid or doesn't correspond to a shipping address,
|
|
65
|
+
* it falls back to the most recently modified shipping address.
|
|
66
|
+
* @returns The ID of the default shipping address, or null if no valid shipping address exists.
|
|
67
|
+
*/
|
|
68
|
+
getDefaultShippingAddressId(): string | null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { type CustomerAddressAttributes, type CustomerAddressData, type CustomerAddressDataWithOutId, CustomerAddressModel as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var s=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(e,t=new Date){this.customFields={...e.customFields},this.version=e.version??1,this.createdAt=e.createdAt&&!isNaN(Date.parse(e.createdAt))?new Date(e.createdAt).toISOString():t.toISOString(),this.modifiedAt=e.modifiedAt&&!isNaN(Date.parse(e.modifiedAt))?new Date(e.modifiedAt).toISOString():t.toISOString(),this.modifiedBy=e.modifiedBy??"";}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return this.modifiedBy}setModifiedBy(e){this.modifiedBy=e;}getCustomField(e){return this.customFields[e]??null}setCustomField(e,t){this.customFields[e]=t;}getAllCustomFields(){return {...this.customFields}}};var i=class extends s{id;firstName;lastName;phone;email;addressLine1;addressLine2;city;postalCode;state;country;isBillingAddress;isShippingAddress;constructor(e,t=new Date){super(e,t),this.id=e.id,this.firstName=e.firstName,this.lastName=e.lastName,this.phone=e.phone,this.email=e.email,this.addressLine1=e.addressLine1,this.addressLine2=e.addressLine2||"",this.city=e.city,this.postalCode=e.postalCode,this.state=e.state,this.country=e.country,this.isBillingAddress=e.isBillingAddress,this.isShippingAddress=e.isShippingAddress;}getDetails(){return {...super.getDetails(),id:this.getId(),firstName:this.getFirstName(),lastName:this.getLastName(),phone:this.getPhone(),email:this.getEmail(),addressLine1:this.getAddressLine1(),addressLine2:this.getAddressLine2(),city:this.getCity(),postalCode:this.getPostalCode(),state:this.getState(),country:this.getCountry(),isBillingAddress:this.getIsBillingAddress(),isShippingAddress:this.getIsShippingAddress()}}getId(){return this.id}getFirstName(){return this.firstName}getLastName(){return this.lastName}getPhone(){return this.phone}getEmail(){return this.email}getAddressLine1(){return this.addressLine1}getAddressLine2(){return this.addressLine2}getCity(){return this.city}getPostalCode(){return this.postalCode}getState(){return this.state}getCountry(){return this.country}getIsBillingAddress(){return this.isBillingAddress}getIsShippingAddress(){return this.isShippingAddress}getAddressType(){return this.isBillingAddress&&this.isShippingAddress?"billing&shipping":this.isBillingAddress?"billing":this.isShippingAddress?"shipping":"none"}static checkIfShippingAddress(e){return e==="shipping"||e==="billing&shipping"}static checkIfBillingAddress(e){return e==="billing"||e==="billing&shipping"}};var r=class extends s{id;addresses;defaultBillingAddressId;defaultShippingAddressId;constructor(e,t=new Date){super(e,t),this.id=e.id,this.addresses=e.addresses.map(d=>new i(d,t)).sort((d,o)=>o.getModifiedAtTime()-d.getModifiedAtTime()),this.defaultBillingAddressId=e.defaultBillingAddressId,this.defaultShippingAddressId=e.defaultShippingAddressId;}getDetails(e=!1){return {...e?{id:this.getId()}:{},addresses:this.getAddresses().map(t=>t.getDetails()),defaultBillingAddressId:this.getDefaultBillingAddressId(),defaultShippingAddressId:this.getDefaultShippingAddressId(),...super.getDetails()}}getId(){return this.id}getAddresses(){return [...this.addresses]}getShippingAddresses(){return this.addresses.filter(e=>e.getIsShippingAddress())}getBillingAddresses(){return this.addresses.filter(e=>e.getIsBillingAddress())}getDefaultBillingAddressId(){let e=this.addresses.find(t=>t.getId()===this.defaultBillingAddressId&&t.getIsBillingAddress());return e?e.getId():this.addresses.find(t=>t.getIsBillingAddress())?.getId()||null}getDefaultShippingAddressId(){let e=this.addresses.find(t=>t.getId()===this.defaultShippingAddressId&&t.getIsShippingAddress());return e?e.getId():this.addresses.find(t=>t.getIsShippingAddress())?.getId()||null}};module.exports=r;//# sourceMappingURL=CustomerAddress.js.map
|
|
2
|
+
//# sourceMappingURL=CustomerAddress.js.map
|