b23-lib 1.11.3 → 1.12.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/dist/Classes/Address.d.mts +7 -0
  2. package/dist/Classes/Address.d.ts +7 -0
  3. package/dist/Classes/Address.js +1 -1
  4. package/dist/Classes/Address.js.map +1 -1
  5. package/dist/Classes/Address.mjs +1 -1
  6. package/dist/Classes/Cart.js +1 -1
  7. package/dist/Classes/Cart.js.map +1 -1
  8. package/dist/Classes/Cart.mjs +1 -1
  9. package/dist/Classes/Customer.d.mts +7 -0
  10. package/dist/Classes/Customer.d.ts +7 -0
  11. package/dist/Classes/Customer.js +1 -1
  12. package/dist/Classes/Customer.js.map +1 -1
  13. package/dist/Classes/Customer.mjs +1 -1
  14. package/dist/Classes/Customer.mjs.map +1 -1
  15. package/dist/Classes/CustomerAddress.js +1 -1
  16. package/dist/Classes/CustomerAddress.js.map +1 -1
  17. package/dist/Classes/CustomerAddress.mjs +1 -1
  18. package/dist/Classes/Order.js +1 -1
  19. package/dist/Classes/Order.js.map +1 -1
  20. package/dist/Classes/Order.mjs +1 -1
  21. package/dist/Classes/Order.mjs.map +1 -1
  22. package/dist/Classes/ShoppingContainer.js +1 -1
  23. package/dist/Classes/ShoppingContainer.js.map +1 -1
  24. package/dist/Classes/ShoppingContainer.mjs +1 -1
  25. package/dist/chunk-H5GPM4LA.mjs +2 -0
  26. package/dist/chunk-H5GPM4LA.mjs.map +1 -0
  27. package/dist/{chunk-4LCZLYP7.mjs → chunk-LMMJSJTO.mjs} +2 -2
  28. package/dist/{chunk-4LCZLYP7.mjs.map → chunk-LMMJSJTO.mjs.map} +1 -1
  29. package/dist/{chunk-QKV5D6JZ.mjs → chunk-WOMA746Z.mjs} +2 -2
  30. package/dist/{chunk-QKV5D6JZ.mjs.map → chunk-WOMA746Z.mjs.map} +1 -1
  31. package/dist/index.d.mts +6 -0
  32. package/dist/index.d.ts +6 -0
  33. package/dist/index.js +1 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/index.mjs +1 -1
  36. package/dist/index.mjs.map +1 -1
  37. package/package.json +1 -1
  38. package/dist/chunk-HTJJLLGW.mjs +0 -2
  39. package/dist/chunk-HTJJLLGW.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Classes/Customer.ts"],"names":["CustomerStatus","CustomerModel","BaseModel","data","date","withId","customerStatus"],"mappings":"6CAEYA,IAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GACVA,EAAA,OAAU,CAAA,SAAA,CACVA,EAAA,eAAkB,CAAA,iBAAA,CAClBA,EAAA,cAAiB,CAAA,gBAAA,CACjBA,EAAA,SAAY,CAAA,WAAA,CACZA,EAAA,cAAiB,CAAA,gBAAA,CACjBA,EAAA,SAAY,CAAA,WAAA,CACZA,EAAA,WAAc,CAAA,aAAA,CAPJA,OAAA,EA4BSC,CAAAA,CAAAA,CAAAA,CAArB,cAA2CC,GAAU,CACzC,GACA,KACA,CAAA,KAAA,CACA,UACA,QACA,CAAA,eAAA,CACA,eAQV,WAAYC,CAAAA,CAAAA,CAA0BC,EAAa,IAAI,IAAA,CAAQ,CAC7D,KAAMD,CAAAA,CAAAA,CAAMC,CAAI,CAChB,CAAA,IAAA,CAAK,GAAKD,CAAK,CAAA,EAAA,CACf,KAAK,KAAQA,CAAAA,CAAAA,CAAK,MAClB,IAAK,CAAA,KAAA,CAAQA,EAAK,KAClB,CAAA,IAAA,CAAK,UAAYA,CAAK,CAAA,SAAA,CACtB,KAAK,QAAWA,CAAAA,CAAAA,CAAK,SACrB,IAAK,CAAA,eAAA,CAAkBA,EAAK,eAAmB,EAAA,CAAA,CAAA,CAC/C,KAAK,cAAiB,CAAA,IAAI,IACxB,CAAC,GAAIA,EAAK,cAAiB,CAAA,KAAA,CAAM,KAAqBA,CAAK,CAAA,cAAc,EAAI,EAAC,CAAI,SAAsB,CAC1G,EACF,CAUA,UAAWE,CAAAA,CAAAA,CAAkB,GAA6C,CACxE,OAAO,CACL,GAAG,KAAA,CAAM,YACT,CAAA,GAAIA,EAAS,CAAE,EAAA,CAAI,KAAK,KAAM,EAAE,EAAI,EAAC,CACrC,MAAO,IAAK,CAAA,QAAA,GACZ,KAAO,CAAA,IAAA,CAAK,UACZ,CAAA,SAAA,CAAW,KAAK,YAAa,EAAA,CAC7B,SAAU,IAAK,CAAA,WAAA,GACf,eAAiB,CAAA,IAAA,CAAK,oBACtB,CAAA,cAAA,CAAgB,KAAK,iBAAkB,EACzC,CACF,CAMA,KAAA,EAAgB,CACd,OAAO,IAAA,CAAK,EACd,CAMA,QAAA,EAAmB,CACjB,OAAO,IAAA,CAAK,KACd,CAMA,QAAA,EAA+B,CAC7B,OAAO,IAAA,CAAK,KACd,CAOA,YAAA,EAAuB,CACrB,OAAO,IAAA,CAAK,SACd,CAOA,WAAA,EAAsB,CACpB,OAAO,IAAA,CAAK,QACd,CAOA,kBAAA,EAA8B,CAC5B,OAAO,IAAA,CAAK,eACd,CAOA,iBAAA,EAAsC,CACpC,OAAO,KAAA,CAAM,KAAK,IAAK,CAAA,cAAc,CACvC,CAQA,iBAAA,CAAkBC,EAAyC,CACzD,OAAO,KAAK,cAAe,CAAA,GAAA,CAAIA,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 GOOGLE_AUTH = \"GOOGLE_AUTH\"\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<Omit<CustomerDataWithArrayStatus, 'phone'>> & { phone?: string};\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 | undefined {\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"]}
1
+ {"version":3,"sources":["../../src/Classes/Customer.ts"],"names":["CustomerStatus","CustomerModel","BaseModel","data","date","withId","customerStatus"],"mappings":"6CAEYA,IAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GACVA,EAAA,OAAU,CAAA,SAAA,CACVA,EAAA,eAAkB,CAAA,iBAAA,CAClBA,CAAA,CAAA,cAAA,CAAiB,gBACjBA,CAAAA,CAAAA,CAAA,UAAY,WACZA,CAAAA,CAAAA,CAAA,eAAiB,gBACjBA,CAA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,CAAA,IAAA,CAAK,mBACvB,CACF,CAMA,KAAgB,EAAA,CACd,OAAO,IAAK,CAAA,EACd,CAMA,QAAA,EAAmB,CACjB,OAAO,KAAK,KACd,CAMA,UAA+B,CAC7B,OAAO,KAAK,KACd,CAOA,YAAuB,EAAA,CACrB,OAAO,IAAA,CAAK,SACd,CAOA,WAAA,EAAsB,CACpB,OAAO,IAAA,CAAK,QACd,CAMA,UAAA,EAAqB,CACnB,OAAO,IAAK,CAAA,OACd,CAMA,kBAA8B,EAAA,CAC5B,OAAO,IAAK,CAAA,eACd,CAOA,iBAAsC,EAAA,CACpC,OAAO,KAAA,CAAM,IAAK,CAAA,IAAA,CAAK,cAAc,CACvC,CAQA,iBAAkBC,CAAAA,CAAAA,CAAyC,CACzD,OAAO,KAAK,cAAe,CAAA,GAAA,CAAIA,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 GOOGLE_AUTH = \"GOOGLE_AUTH\"\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 company?: 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<Omit<CustomerDataWithArrayStatus, 'phone'>> & { phone?: string};\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 company: 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.company = data.company ?? '';\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 company: this.getCompany(),\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 | undefined {\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 * Gets the company name associated with the customer.\r\n * @returns The company name.\r\n */\r\n getCompany(): string {\r\n return this.company;\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"]}
@@ -1,2 +1,2 @@
1
- 'use strict';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,t,s,l){this.modifiedBy={id:e,authType:t,requestId:s,lambdaName:l};}getCustomField(e){return this.customFields[e]??null}setCustomField(e,t){this.customFields[e]=t;}getAllCustomFields(){return {...this.customFields}}};var d=class extends i{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 i{id;addresses;defaultBillingAddressId;defaultShippingAddressId;constructor(e,t=new Date){super(e,t),this.id=e.id,this.addresses={},Object.keys(e.addresses).map(s=>this.addresses[s]=new d(e.addresses[s],t)),this.defaultBillingAddressId=e.defaultBillingAddressId??null,this.defaultShippingAddressId=e.defaultShippingAddressId??null;}getDetails(e=!1){return {...e?{id:this.getId()}:{},addresses:this.getAddresses().reduce((t,s)=>(t[s.getId()]=s.getDetails(),t),{}),defaultBillingAddressId:this.getDefaultBillingAddressId(),defaultShippingAddressId:this.getDefaultShippingAddressId(),...super.getDetails()}}getId(){return this.id}getAddresses(){return Object.values(this.addresses).sort((e,t)=>t.getCreatedAtTime()-e.getCreatedAtTime())}getShippingAddresses(){return this.getAddresses().filter(e=>e.getIsShippingAddress())}getBillingAddresses(){return this.getAddresses().filter(e=>e.getIsBillingAddress())}getDefaultBillingAddressId(){let e=this.getAddresses().find(t=>t.getId()===this.defaultBillingAddressId&&t.getIsBillingAddress());return e?e.getId():this.getAddresses().find(t=>t.getIsBillingAddress())?.getId()||null}getDefaultShippingAddressId(){let e=this.getAddresses().find(t=>t.getId()===this.defaultShippingAddressId&&t.getIsShippingAddress());return e?e.getId():this.getAddresses().find(t=>t.getIsShippingAddress())?.getId()||null}};module.exports=r;//# sourceMappingURL=CustomerAddress.js.map
1
+ 'use strict';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,t,s,o){this.modifiedBy={id:e,authType:t,requestId:s,lambdaName:o};}getCustomField(e){return this.customFields[e]??null}setCustomField(e,t){this.customFields[e]=t;}getAllCustomFields(){return {...this.customFields}}};var r=class extends i{id;firstName;lastName;company;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.company=e.company||"",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(),company:this.getCompany(),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}getCompany(){return this.company}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 d=class extends i{id;addresses;defaultBillingAddressId;defaultShippingAddressId;constructor(e,t=new Date){super(e,t),this.id=e.id,this.addresses={},Object.keys(e.addresses).map(s=>this.addresses[s]=new r(e.addresses[s],t)),this.defaultBillingAddressId=e.defaultBillingAddressId??null,this.defaultShippingAddressId=e.defaultShippingAddressId??null;}getDetails(e=!1){return {...e?{id:this.getId()}:{},addresses:this.getAddresses().reduce((t,s)=>(t[s.getId()]=s.getDetails(),t),{}),defaultBillingAddressId:this.getDefaultBillingAddressId(),defaultShippingAddressId:this.getDefaultShippingAddressId(),...super.getDetails()}}getId(){return this.id}getAddresses(){return Object.values(this.addresses).sort((e,t)=>t.getCreatedAtTime()-e.getCreatedAtTime())}getShippingAddresses(){return this.getAddresses().filter(e=>e.getIsShippingAddress())}getBillingAddresses(){return this.getAddresses().filter(e=>e.getIsBillingAddress())}getDefaultBillingAddressId(){let e=this.getAddresses().find(t=>t.getId()===this.defaultBillingAddressId&&t.getIsBillingAddress());return e?e.getId():this.getAddresses().find(t=>t.getIsBillingAddress())?.getId()||null}getDefaultShippingAddressId(){let e=this.getAddresses().find(t=>t.getId()===this.defaultShippingAddressId&&t.getIsShippingAddress());return e?e.getId():this.getAddresses().find(t=>t.getIsShippingAddress())?.getId()||null}};module.exports=d;//# sourceMappingURL=CustomerAddress.js.map
2
2
  //# sourceMappingURL=CustomerAddress.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Classes/Base.ts","../../src/Classes/Address.ts","../../src/Classes/CustomerAddress.ts"],"names":["BaseModel","data","date","id","authType","requestId","lambdaName","fieldName","value","AddressModel","addressType","CustomerAddressModel","addressId","withId","acc","address","a","b","explicitDefault"],"mappings":"aA4BA,IAAqBA,EAArB,KAA+B,CACnB,YACA,CAAA,OAAA,CACA,UACA,UACA,CAAA,UAAA,CAQV,WAAYC,CAAAA,CAAAA,CAAsBC,EAAa,IAAI,IAAA,CAAQ,CACzD,IAAK,CAAA,YAAA,CAAe,CAAE,GAAGD,CAAAA,CAAK,YAAa,CAAA,CAC3C,KAAK,OAAUA,CAAAA,CAAAA,CAAK,SAAW,CAC/B,CAAA,IAAA,CAAK,UAAYA,CAAK,CAAA,S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AAO,OAAO,MAAO,CAAA,IAAA,CAAK,SAAS,CAChC,CAAA,IAAA,CAAK,CAACE,CAAAA,CAAGC,IAAMA,CAAE,CAAA,gBAAA,GAAqBD,CAAE,CAAA,gBAAA,EAAkB,CAC/D,CAMA,oBAAuC,EAAA,CACrC,OAAO,IAAK,CAAA,YAAA,GAAe,MAAQD,CAAAA,CAAAA,EAAYA,EAAQ,oBAAqB,EAAC,CAC/E,CAMA,qBAAsC,CACpC,OAAO,KAAK,YAAa,EAAA,CAAE,OAAQA,CAAYA,EAAAA,CAAAA,CAAQ,mBAAoB,EAAC,CAC9E,CAQA,0BAAA,EAA4C,CAC1C,IAAMG,CAAAA,CAAkB,KAAK,YAAa,EAAA,CAAE,IACzCH,CAAAA,CAAAA,EAAYA,EAAQ,KAAM,EAAA,GAAM,KAAK,uBAA2BA,EAAAA,CAAAA,CAAQ,qBAC3E,CAAA,CACA,OAAIG,CAAAA,CACKA,EAAgB,KAAM,EAAA,CAGxB,KAAK,YAAa,EAAA,CAAE,KAAMH,CAAYA,EAAAA,CAAAA,CAAQ,mBAAoB,EAAC,GAAG,KAAM,EAAA,EAAK,IAC1F,CAQA,2BAAA,EAA6C,CAE3C,IAAMG,CAAAA,CAAkB,IAAK,CAAA,YAAA,GAAe,IACzCH,CAAAA,CAAAA,EAAYA,EAAQ,KAAM,EAAA,GAAM,KAAK,wBAA4BA,EAAAA,CAAAA,CAAQ,oBAAqB,EACjG,EACA,OAAIG,CAAAA,CACKA,EAAgB,KAAM,EAAA,CAGxB,KAAK,YAAa,EAAA,CAAE,IAAMH,CAAAA,CAAAA,EAAYA,EAAQ,oBAAqB,EAAC,GAAG,KAAM,EAAA,EAAK,IAC3F,CACF","file":"CustomerAddress.js","sourcesContent":["import { AuthType } from \"../Auth\";\r\nimport { ISODateTime } from \"./Common\";\r\n\r\nexport interface CustomFields {\r\n [key: string]: any;\r\n}\r\n\r\nexport type ModifiedBy = {\r\n id?: string;\r\n authType?: string;\r\n requestId?: string;\r\n lambdaName?: string;\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?: ModifiedBy;\r\n};\r\n\r\nexport type BaseData = Required<BaseAttributes>;\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: ModifiedBy;\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\r\n */\r\n getModifiedBy(): ModifiedBy {\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(id?: string, authType?: AuthType, requestId?: string, lambdaName?: string): void {\r\n this.modifiedBy = {\r\n id,\r\n authType,\r\n requestId,\r\n lambdaName,\r\n };\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\n\r\nexport enum AddressType {\r\n BILLING = \"billing\",\r\n SHIPPING = \"shipping\",\r\n BILLING_AND_SHIPPING = \"billing&shipping\",\r\n NONE = \"none\",\r\n}\r\n\r\nexport type AddressAttributes = BaseAttributes & {\r\n id: string;\r\n firstName: string;\r\n lastName?: string;\r\n phone: string;\r\n email: string;\r\n addressLine1: string;\r\n addressLine2?: string;\r\n city: string;\r\n postalCode: string\r\n state: string;\r\n country: string;\r\n isBillingAddress: boolean;\r\n isShippingAddress: boolean;\r\n};\r\n\r\nexport type AddressData = Required<AddressAttributes>;\r\n\r\n/**\r\n * Represents a physical address associated with a customer or order.\r\n * Handles both billing and shipping address types.\r\n */\r\nexport default class AddressModel extends BaseModel {\r\n protected id: string;\r\n protected firstName: string;\r\n protected lastName: string;\r\n protected phone: string;\r\n protected email: string;\r\n protected addressLine1: string;\r\n protected addressLine2: string;\r\n protected city: string;\r\n protected postalCode: string\r\n protected state: string;\r\n protected country: string;\r\n protected isBillingAddress: boolean;\r\n protected isShippingAddress: boolean;\r\n\r\n /**\r\n * Creates an instance of AddressModel.\r\n * @param data - The initial address attributes.\r\n * @param date - Optional date for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: AddressAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.firstName = data.firstName;\r\n this.lastName = data.lastName || '';\r\n this.phone = data.phone;\r\n this.email = data.email;\r\n this.addressLine1 = data.addressLine1;\r\n this.addressLine2 = data.addressLine2 || '';\r\n this.city = data.city;\r\n this.postalCode = data.postalCode;\r\n this.state = data.state;\r\n this.country = data.country;\r\n this.isBillingAddress = data.isBillingAddress;\r\n this.isShippingAddress = data.isShippingAddress;\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the address's current state.\r\n * Includes all address fields and base model fields.\r\n * @returns AddressData object suitable for serialization or API responses.\r\n */\r\n getDetails(): AddressData {\r\n return {\r\n ...super.getDetails(),\r\n id: this.getId(),\r\n firstName: this.getFirstName(),\r\n lastName: this.getLastName(),\r\n phone: this.getPhone(),\r\n email: this.getEmail(),\r\n addressLine1: this.getAddressLine1(),\r\n addressLine2: this.getAddressLine2(),\r\n city: this.getCity(),\r\n postalCode: this.getPostalCode(),\r\n state: this.getState(),\r\n country: this.getCountry(),\r\n isBillingAddress: this.getIsBillingAddress(),\r\n isShippingAddress: this.getIsShippingAddress(),\r\n }\r\n }\r\n\r\n /**\r\n * Gets the unique identifier for the address.\r\n * @returns The address ID.\r\n */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the first name associated with the address.\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 * Gets the last name associated with the address.\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 * Gets the phone number associated with the address.\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 * Gets the email address associated with the address.\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 primary address line (e.g., street address).\r\n * @returns The first address line.\r\n */\r\n getAddressLine1(): string {\r\n return this.addressLine1;\r\n }\r\n\r\n /**\r\n * Gets the secondary address line (e.g., apartment, suite).\r\n * Returns an empty string if not provided.\r\n * @returns The second address line or an empty string.\r\n */\r\n getAddressLine2(): string {\r\n return this.addressLine2;\r\n }\r\n\r\n /**\r\n * Gets the city name.\r\n * @returns The city.\r\n */\r\n getCity(): string {\r\n return this.city;\r\n }\r\n\r\n /**\r\n * Gets the postal code (e.g., ZIP code).\r\n * @returns The postal code.\r\n */\r\n getPostalCode(): string {\r\n return this.postalCode;\r\n }\r\n\r\n /**\r\n * Gets the state, province, or region.\r\n * @returns The state.\r\n */\r\n getState(): string {\r\n return this.state;\r\n }\r\n\r\n /**\r\n * Gets the country name or code.\r\n * @returns The country.\r\n */\r\n getCountry(): string {\r\n return this.country;\r\n }\r\n\r\n /**\r\n * Checks if this address is designated as a billing address.\r\n * @returns True if it's a billing address, false otherwise.\r\n */\r\n getIsBillingAddress(): boolean {\r\n return this.isBillingAddress;\r\n }\r\n\r\n /**\r\n * Checks if this address is designated as a shipping address.\r\n * @returns True if it's a shipping address, false otherwise.\r\n */\r\n getIsShippingAddress(): boolean {\r\n return this.isShippingAddress;\r\n }\r\n\r\n /**\r\n * Determines the type of the address based on its billing and shipping flags.\r\n * @returns The AddressType enum value representing the address's role.\r\n */\r\n getAddressType(): AddressType {\r\n if (this.isBillingAddress && this.isShippingAddress) {\r\n return AddressType.BILLING_AND_SHIPPING;\r\n } else if (this.isBillingAddress) {\r\n return AddressType.BILLING;\r\n } else if (this.isShippingAddress) {\r\n return AddressType.SHIPPING;\r\n } else {\r\n return AddressType.NONE;\r\n }\r\n }\r\n\r\n /**\r\n * Static method to check if a given AddressType includes shipping.\r\n * @param addressType - The address type to check.\r\n * @returns True if the type is SHIPPING or BILLING_AND_SHIPPING.\r\n */\r\n static checkIfShippingAddress(addressType: AddressType): boolean {\r\n return addressType === AddressType.SHIPPING || addressType === AddressType.BILLING_AND_SHIPPING;\r\n }\r\n\r\n /**\r\n * Static method to check if a given AddressType includes billing.\r\n * @param addressType - The address type to check.\r\n * @returns True if the type is BILLING or BILLING_AND_SHIPPING.\r\n */\r\n static checkIfBillingAddress(addressType: AddressType): boolean {\r\n return addressType === AddressType.BILLING || addressType === AddressType.BILLING_AND_SHIPPING;\r\n }\r\n}","import AddressModel, { AddressData } from \"./Address\";\r\nimport BaseModel, { BaseAttributes } from \"./Base\";\r\n\r\nexport type CustomerAddressAttributes = BaseAttributes & {\r\n id: string;\r\n addresses: { [key: string]: AddressData };\r\n defaultBillingAddressId?: string;\r\n defaultShippingAddressId?: string;\r\n}\r\n\r\ntype CustomerAddressWithoutDefaultAddress = Omit<CustomerAddressAttributes, 'defaultBillingAddressId' | 'defaultShippingAddressId'> & {\r\n defaultBillingAddressId: string | null;\r\n defaultShippingAddressId: string | null;\r\n};\r\nexport type CustomerAddressDataWithOutId = Required<Omit<CustomerAddressWithoutDefaultAddress, 'id'>>;\r\nexport type CustomerAddressData = Required<CustomerAddressWithoutDefaultAddress>;\r\n\r\n\r\nexport default class CustomerAddressModel extends BaseModel {\r\n protected id: string;\r\n protected addresses: { [key: string]: AddressModel };\r\n protected defaultBillingAddressId: string | null;\r\n protected defaultShippingAddressId: string | null;\r\n\r\n /**\r\n * Creates an instance of CustomerAddressModel.\r\n * Initializes the address list, sorting them by modification date (most recent first).\r\n * @param data - The initial attributes for the customer's addresses.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: CustomerAddressAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.addresses = { }\r\n \r\n Object.keys(data.addresses)\r\n .map((addressId: string) => this.addresses[addressId] = new AddressModel(data.addresses[addressId], date));\r\n\r\n this.defaultBillingAddressId = data.defaultBillingAddressId ?? null;\r\n this.defaultShippingAddressId = data.defaultShippingAddressId ?? null;\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the customer's addresses.\r\n * Can optionally exclude the customer address collection ID. Includes base model details.\r\n * @param withId - If true, includes the 'id' field of the CustomerAddressModel. Defaults to false.\r\n * @returns CustomerAddressData or CustomerAddressDataWithOutId object suitable for serialization.\r\n */\r\n getDetails(withId?: false): CustomerAddressDataWithOutId;\r\n getDetails(withId: true): CustomerAddressData;\r\n getDetails(withId: boolean = false): CustomerAddressData | CustomerAddressDataWithOutId {\r\n return {\r\n ...(withId ? { id: this.getId() } : {}),\r\n addresses: this.getAddresses().reduce((acc, address) => {\r\n acc[address.getId()] = address.getDetails();\r\n return acc;\r\n }, {} as Record<string, AddressData>),\r\n defaultBillingAddressId: this.getDefaultBillingAddressId(),\r\n defaultShippingAddressId: this.getDefaultShippingAddressId(),\r\n ...super.getDetails()\r\n }\r\n }\r\n \r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the list of all associated address models, sorted by creation date (most recent first).\r\n * @returns An array of AddressModel instances.\r\n */\r\n getAddresses(): AddressModel[] {\r\n return Object.values(this.addresses)\r\n .sort((a, b) => b.getCreatedAtTime() - a.getCreatedAtTime());;\r\n }\r\n\r\n /**\r\n * Gets a filtered list of addresses designated as shipping addresses.\r\n * @returns An array of AddressModel instances marked as shipping addresses.\r\n */\r\n getShippingAddresses(): AddressModel[] {\r\n return this.getAddresses().filter((address) => address.getIsShippingAddress());\r\n }\r\n\r\n /**\r\n * Gets a filtered list of addresses designated as billing addresses.\r\n * @returns An array of AddressModel instances marked as billing addresses.\r\n */\r\n getBillingAddresses(): AddressModel[] {\r\n return this.getAddresses().filter((address) => address.getIsBillingAddress());\r\n }\r\n\r\n /**\r\n * Gets the ID of the default billing address.\r\n * If the stored default ID is invalid or doesn't correspond to a billing address,\r\n * it falls back to the most recently modified billing address.\r\n * @returns The ID of the default billing address, or null if no valid billing address exists.\r\n */\r\n getDefaultBillingAddressId(): string | null {\r\n const explicitDefault = this.getAddresses().find(\r\n (address) => address.getId() === this.defaultBillingAddressId && address.getIsBillingAddress()\r\n );\r\n if (explicitDefault) {\r\n return explicitDefault.getId();\r\n }\r\n // Fallback: Find the first address marked as billing (already sorted by most recent)\r\n return this.getAddresses().find((address) => address.getIsBillingAddress())?.getId() || null;\r\n }\r\n\r\n /**\r\n * Gets the ID of the default shipping address.\r\n * If the stored default ID is invalid or doesn't correspond to a shipping address,\r\n * it falls back to the most recently modified shipping address.\r\n * @returns The ID of the default shipping address, or null if no valid shipping address exists.\r\n */\r\n getDefaultShippingAddressId(): string | null {\r\n // Check if the explicitly set default exists, is valid, and is a shipping address\r\n const explicitDefault = this.getAddresses().find(\r\n (address) => address.getId() === this.defaultShippingAddressId && address.getIsShippingAddress()\r\n );\r\n if (explicitDefault) {\r\n return explicitDefault.getId();\r\n }\r\n // Fallback: Find the first address marked as shipping (already sorted by most recent)\r\n return this.getAddresses().find((address) => address.getIsShippingAddress())?.getId() || null;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"sources":["../../src/Classes/Base.ts","../../src/Classes/Address.ts","../../src/Classes/CustomerAddress.ts"],"names":["BaseModel","data","date","id","authType","requestId","lambdaName","fieldName","value","AddressModel","addressType","CustomerAddressModel","addressId","withId","acc","address","a","b","explicitDefault"],"mappings":"aA4BA,IAAqBA,EAArB,KAA+B,CACnB,aACA,OACA,CAAA,SAAA,CACA,WACA,UAQV,CAAA,WAAA,CAAYC,CAAsBC,CAAAA,CAAAA,CAAa,IAAI,IAAQ,CAAA,CACzD,KAAK,YAAe,CAAA,CAAE,GAAGD,CAAK,CAAA,YAAa,CAC3C,CAAA,IAAA,CAAK,QAAUA,CAAK,CAAA,OAAA,EAAW,EAC/B,IAAK,CAAA,SAAA,CAAYA,EAAK,SAAa,EAAA,CAAC,KAAM,CAAA,IAAA,CAAK,MAAMA,CAAK,CAAA,SAAS,CAAC,CAElE,CAAA,IAAI,KAAKA,CAAK,CAAA,SAAS,CAAE,CAAA,WAAA,GAEzBC,CAAK,CAAA,WAAA,GACP,IAAK,CAAA,UAAA,CAAaD,EAAK,UAAc,EAAA,CAAC,KAAM,CAAA,IAAA,CAAK,MAAMA,CAAK,CAAA,UAAU,CAAC,CACnE,CAAA,IAAI,KAAKA,CAAK,CAAA,UAAU,CAAE,CAAA,WAAA,GAC1BC,CAAK,CAAA,WAAA,GAET,IAAK,CAAA,UAAA,CAAa,CAAE,GAAGD,CAAAA,CAAK,UAAW,EACzC,CAMA,YAAuB,CACrB,OAAO,CACL,YAAc,CAAA,IAAA,CAAK,oBACnB,CAAA,OAAA,CAAS,IAAK,CAAA,UAAA,GACd,SAAW,CAAA,IAAA,CAAK,cAChB,CAAA,UAAA,CAAY,KAAK,aAAc,EAAA,CAC/B,UAAY,CAAA,IAAA,CAAK,eACnB,CACF,CAMA,UAAqB,EAAA,CACnB,OAAO,IAAK,CAAA,OACd,CAMA,YAAA,EAAuB,CACrB,OAAO,IAAA,CAAK,SACd,CAMA,gBAAA,EAA2B,CACzB,OAAO,IAAI,IA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A,EAAYA,CAAQ,CAAA,mBAAA,EAAqB,CAAG,EAAA,KAAA,IAAW,IAC1F,CAQA,6BAA6C,CAE3C,IAAMG,CAAkB,CAAA,IAAA,CAAK,cAAe,CAAA,IAAA,CACzCH,GAAYA,CAAQ,CAAA,KAAA,KAAY,IAAK,CAAA,wBAAA,EAA4BA,CAAQ,CAAA,oBAAA,EAC5E,CACA,CAAA,OAAIG,EACKA,CAAgB,CAAA,KAAA,GAGlB,IAAK,CAAA,YAAA,GAAe,IAAMH,CAAAA,CAAAA,EAAYA,EAAQ,oBAAqB,EAAC,GAAG,KAAM,EAAA,EAAK,IAC3F,CACF","file":"CustomerAddress.js","sourcesContent":["import { AuthType } from \"../Auth\";\r\nimport { ISODateTime } from \"./Common\";\r\n\r\nexport interface CustomFields {\r\n [key: string]: any;\r\n}\r\n\r\nexport type ModifiedBy = {\r\n id?: string;\r\n authType?: string;\r\n requestId?: string;\r\n lambdaName?: string;\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?: ModifiedBy;\r\n};\r\n\r\nexport type BaseData = Required<BaseAttributes>;\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: ModifiedBy;\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\r\n */\r\n getModifiedBy(): ModifiedBy {\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(id?: string, authType?: AuthType, requestId?: string, lambdaName?: string): void {\r\n this.modifiedBy = {\r\n id,\r\n authType,\r\n requestId,\r\n lambdaName,\r\n };\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\n\r\nexport enum AddressType {\r\n BILLING = \"billing\",\r\n SHIPPING = \"shipping\",\r\n BILLING_AND_SHIPPING = \"billing&shipping\",\r\n NONE = \"none\",\r\n}\r\n\r\nexport type AddressAttributes = BaseAttributes & {\r\n id: string;\r\n firstName: string;\r\n lastName?: string;\r\n company?: string;\r\n phone: string;\r\n email: string;\r\n addressLine1: string;\r\n addressLine2?: string;\r\n city: string;\r\n postalCode: string\r\n state: string;\r\n country: string;\r\n isBillingAddress: boolean;\r\n isShippingAddress: boolean;\r\n};\r\n\r\nexport type AddressData = Required<AddressAttributes>;\r\n\r\n/**\r\n * Represents a physical address associated with a customer or order.\r\n * Handles both billing and shipping address types.\r\n */\r\nexport default class AddressModel extends BaseModel {\r\n protected id: string;\r\n protected firstName: string;\r\n protected lastName: string;\r\n protected company: string;\r\n protected phone: string;\r\n protected email: string;\r\n protected addressLine1: string;\r\n protected addressLine2: string;\r\n protected city: string;\r\n protected postalCode: string\r\n protected state: string;\r\n protected country: string;\r\n protected isBillingAddress: boolean;\r\n protected isShippingAddress: boolean;\r\n\r\n /**\r\n * Creates an instance of AddressModel.\r\n * @param data - The initial address attributes.\r\n * @param date - Optional date for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: AddressAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.firstName = data.firstName;\r\n this.lastName = data.lastName || '';\r\n this.company = data.company || '';\r\n this.phone = data.phone;\r\n this.email = data.email;\r\n this.addressLine1 = data.addressLine1;\r\n this.addressLine2 = data.addressLine2 || '';\r\n this.city = data.city;\r\n this.postalCode = data.postalCode;\r\n this.state = data.state;\r\n this.country = data.country;\r\n this.isBillingAddress = data.isBillingAddress;\r\n this.isShippingAddress = data.isShippingAddress;\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the address's current state.\r\n * Includes all address fields and base model fields.\r\n * @returns AddressData object suitable for serialization or API responses.\r\n */\r\n getDetails(): AddressData {\r\n return {\r\n ...super.getDetails(),\r\n id: this.getId(),\r\n firstName: this.getFirstName(),\r\n lastName: this.getLastName(),\r\n company: this.getCompany(),\r\n phone: this.getPhone(),\r\n email: this.getEmail(),\r\n addressLine1: this.getAddressLine1(),\r\n addressLine2: this.getAddressLine2(),\r\n city: this.getCity(),\r\n postalCode: this.getPostalCode(),\r\n state: this.getState(),\r\n country: this.getCountry(),\r\n isBillingAddress: this.getIsBillingAddress(),\r\n isShippingAddress: this.getIsShippingAddress(),\r\n }\r\n }\r\n\r\n /**\r\n * Gets the unique identifier for the address.\r\n * @returns The address ID.\r\n */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the first name associated with the address.\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 * Gets the last name associated with the address.\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 * Gets the company name associated with the address.\r\n * @returns The company name.\r\n */\r\n getCompany(): string {\r\n return this.company;\r\n }\r\n\r\n /**\r\n * Gets the phone number associated with the address.\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 * Gets the email address associated with the address.\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 primary address line (e.g., street address).\r\n * @returns The first address line.\r\n */\r\n getAddressLine1(): string {\r\n return this.addressLine1;\r\n }\r\n\r\n /**\r\n * Gets the secondary address line (e.g., apartment, suite).\r\n * Returns an empty string if not provided.\r\n * @returns The second address line or an empty string.\r\n */\r\n getAddressLine2(): string {\r\n return this.addressLine2;\r\n }\r\n\r\n /**\r\n * Gets the city name.\r\n * @returns The city.\r\n */\r\n getCity(): string {\r\n return this.city;\r\n }\r\n\r\n /**\r\n * Gets the postal code (e.g., ZIP code).\r\n * @returns The postal code.\r\n */\r\n getPostalCode(): string {\r\n return this.postalCode;\r\n }\r\n\r\n /**\r\n * Gets the state, province, or region.\r\n * @returns The state.\r\n */\r\n getState(): string {\r\n return this.state;\r\n }\r\n\r\n /**\r\n * Gets the country name or code.\r\n * @returns The country.\r\n */\r\n getCountry(): string {\r\n return this.country;\r\n }\r\n\r\n /**\r\n * Checks if this address is designated as a billing address.\r\n * @returns True if it's a billing address, false otherwise.\r\n */\r\n getIsBillingAddress(): boolean {\r\n return this.isBillingAddress;\r\n }\r\n\r\n /**\r\n * Checks if this address is designated as a shipping address.\r\n * @returns True if it's a shipping address, false otherwise.\r\n */\r\n getIsShippingAddress(): boolean {\r\n return this.isShippingAddress;\r\n }\r\n\r\n /**\r\n * Determines the type of the address based on its billing and shipping flags.\r\n * @returns The AddressType enum value representing the address's role.\r\n */\r\n getAddressType(): AddressType {\r\n if (this.isBillingAddress && this.isShippingAddress) {\r\n return AddressType.BILLING_AND_SHIPPING;\r\n } else if (this.isBillingAddress) {\r\n return AddressType.BILLING;\r\n } else if (this.isShippingAddress) {\r\n return AddressType.SHIPPING;\r\n } else {\r\n return AddressType.NONE;\r\n }\r\n }\r\n\r\n /**\r\n * Static method to check if a given AddressType includes shipping.\r\n * @param addressType - The address type to check.\r\n * @returns True if the type is SHIPPING or BILLING_AND_SHIPPING.\r\n */\r\n static checkIfShippingAddress(addressType: AddressType): boolean {\r\n return addressType === AddressType.SHIPPING || addressType === AddressType.BILLING_AND_SHIPPING;\r\n }\r\n\r\n /**\r\n * Static method to check if a given AddressType includes billing.\r\n * @param addressType - The address type to check.\r\n * @returns True if the type is BILLING or BILLING_AND_SHIPPING.\r\n */\r\n static checkIfBillingAddress(addressType: AddressType): boolean {\r\n return addressType === AddressType.BILLING || addressType === AddressType.BILLING_AND_SHIPPING;\r\n }\r\n}","import AddressModel, { AddressData } from \"./Address\";\r\nimport BaseModel, { BaseAttributes } from \"./Base\";\r\n\r\nexport type CustomerAddressAttributes = BaseAttributes & {\r\n id: string;\r\n addresses: { [key: string]: AddressData };\r\n defaultBillingAddressId?: string;\r\n defaultShippingAddressId?: string;\r\n}\r\n\r\ntype CustomerAddressWithoutDefaultAddress = Omit<CustomerAddressAttributes, 'defaultBillingAddressId' | 'defaultShippingAddressId'> & {\r\n defaultBillingAddressId: string | null;\r\n defaultShippingAddressId: string | null;\r\n};\r\nexport type CustomerAddressDataWithOutId = Required<Omit<CustomerAddressWithoutDefaultAddress, 'id'>>;\r\nexport type CustomerAddressData = Required<CustomerAddressWithoutDefaultAddress>;\r\n\r\n\r\nexport default class CustomerAddressModel extends BaseModel {\r\n protected id: string;\r\n protected addresses: { [key: string]: AddressModel };\r\n protected defaultBillingAddressId: string | null;\r\n protected defaultShippingAddressId: string | null;\r\n\r\n /**\r\n * Creates an instance of CustomerAddressModel.\r\n * Initializes the address list, sorting them by modification date (most recent first).\r\n * @param data - The initial attributes for the customer's addresses.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: CustomerAddressAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.addresses = { }\r\n \r\n Object.keys(data.addresses)\r\n .map((addressId: string) => this.addresses[addressId] = new AddressModel(data.addresses[addressId], date));\r\n\r\n this.defaultBillingAddressId = data.defaultBillingAddressId ?? null;\r\n this.defaultShippingAddressId = data.defaultShippingAddressId ?? null;\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the customer's addresses.\r\n * Can optionally exclude the customer address collection ID. Includes base model details.\r\n * @param withId - If true, includes the 'id' field of the CustomerAddressModel. Defaults to false.\r\n * @returns CustomerAddressData or CustomerAddressDataWithOutId object suitable for serialization.\r\n */\r\n getDetails(withId?: false): CustomerAddressDataWithOutId;\r\n getDetails(withId: true): CustomerAddressData;\r\n getDetails(withId: boolean = false): CustomerAddressData | CustomerAddressDataWithOutId {\r\n return {\r\n ...(withId ? { id: this.getId() } : {}),\r\n addresses: this.getAddresses().reduce((acc, address) => {\r\n acc[address.getId()] = address.getDetails();\r\n return acc;\r\n }, {} as Record<string, AddressData>),\r\n defaultBillingAddressId: this.getDefaultBillingAddressId(),\r\n defaultShippingAddressId: this.getDefaultShippingAddressId(),\r\n ...super.getDetails()\r\n }\r\n }\r\n \r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the list of all associated address models, sorted by creation date (most recent first).\r\n * @returns An array of AddressModel instances.\r\n */\r\n getAddresses(): AddressModel[] {\r\n return Object.values(this.addresses)\r\n .sort((a, b) => b.getCreatedAtTime() - a.getCreatedAtTime());;\r\n }\r\n\r\n /**\r\n * Gets a filtered list of addresses designated as shipping addresses.\r\n * @returns An array of AddressModel instances marked as shipping addresses.\r\n */\r\n getShippingAddresses(): AddressModel[] {\r\n return this.getAddresses().filter((address) => address.getIsShippingAddress());\r\n }\r\n\r\n /**\r\n * Gets a filtered list of addresses designated as billing addresses.\r\n * @returns An array of AddressModel instances marked as billing addresses.\r\n */\r\n getBillingAddresses(): AddressModel[] {\r\n return this.getAddresses().filter((address) => address.getIsBillingAddress());\r\n }\r\n\r\n /**\r\n * Gets the ID of the default billing address.\r\n * If the stored default ID is invalid or doesn't correspond to a billing address,\r\n * it falls back to the most recently modified billing address.\r\n * @returns The ID of the default billing address, or null if no valid billing address exists.\r\n */\r\n getDefaultBillingAddressId(): string | null {\r\n const explicitDefault = this.getAddresses().find(\r\n (address) => address.getId() === this.defaultBillingAddressId && address.getIsBillingAddress()\r\n );\r\n if (explicitDefault) {\r\n return explicitDefault.getId();\r\n }\r\n // Fallback: Find the first address marked as billing (already sorted by most recent)\r\n return this.getAddresses().find((address) => address.getIsBillingAddress())?.getId() || null;\r\n }\r\n\r\n /**\r\n * Gets the ID of the default shipping address.\r\n * If the stored default ID is invalid or doesn't correspond to a shipping address,\r\n * it falls back to the most recently modified shipping address.\r\n * @returns The ID of the default shipping address, or null if no valid shipping address exists.\r\n */\r\n getDefaultShippingAddressId(): string | null {\r\n // Check if the explicitly set default exists, is valid, and is a shipping address\r\n const explicitDefault = this.getAddresses().find(\r\n (address) => address.getId() === this.defaultShippingAddressId && address.getIsShippingAddress()\r\n );\r\n if (explicitDefault) {\r\n return explicitDefault.getId();\r\n }\r\n // Fallback: Find the first address marked as shipping (already sorted by most recent)\r\n return this.getAddresses().find((address) => address.getIsShippingAddress())?.getId() || null;\r\n }\r\n}\r\n"]}
@@ -1,2 +1,2 @@
1
- import {b}from'../chunk-HTJJLLGW.mjs';import {a}from'../chunk-ATUUYYQT.mjs';var t=class extends a{id;addresses;defaultBillingAddressId;defaultShippingAddressId;constructor(e,s=new Date){super(e,s),this.id=e.id,this.addresses={},Object.keys(e.addresses).map(d=>this.addresses[d]=new b(e.addresses[d],s)),this.defaultBillingAddressId=e.defaultBillingAddressId??null,this.defaultShippingAddressId=e.defaultShippingAddressId??null;}getDetails(e=!1){return {...e?{id:this.getId()}:{},addresses:this.getAddresses().reduce((s,d)=>(s[d.getId()]=d.getDetails(),s),{}),defaultBillingAddressId:this.getDefaultBillingAddressId(),defaultShippingAddressId:this.getDefaultShippingAddressId(),...super.getDetails()}}getId(){return this.id}getAddresses(){return Object.values(this.addresses).sort((e,s)=>s.getCreatedAtTime()-e.getCreatedAtTime())}getShippingAddresses(){return this.getAddresses().filter(e=>e.getIsShippingAddress())}getBillingAddresses(){return this.getAddresses().filter(e=>e.getIsBillingAddress())}getDefaultBillingAddressId(){let e=this.getAddresses().find(s=>s.getId()===this.defaultBillingAddressId&&s.getIsBillingAddress());return e?e.getId():this.getAddresses().find(s=>s.getIsBillingAddress())?.getId()||null}getDefaultShippingAddressId(){let e=this.getAddresses().find(s=>s.getId()===this.defaultShippingAddressId&&s.getIsShippingAddress());return e?e.getId():this.getAddresses().find(s=>s.getIsShippingAddress())?.getId()||null}};export{t as default};//# sourceMappingURL=CustomerAddress.mjs.map
1
+ import {b}from'../chunk-H5GPM4LA.mjs';import {a}from'../chunk-ATUUYYQT.mjs';var t=class extends a{id;addresses;defaultBillingAddressId;defaultShippingAddressId;constructor(e,s=new Date){super(e,s),this.id=e.id,this.addresses={},Object.keys(e.addresses).map(d=>this.addresses[d]=new b(e.addresses[d],s)),this.defaultBillingAddressId=e.defaultBillingAddressId??null,this.defaultShippingAddressId=e.defaultShippingAddressId??null;}getDetails(e=!1){return {...e?{id:this.getId()}:{},addresses:this.getAddresses().reduce((s,d)=>(s[d.getId()]=d.getDetails(),s),{}),defaultBillingAddressId:this.getDefaultBillingAddressId(),defaultShippingAddressId:this.getDefaultShippingAddressId(),...super.getDetails()}}getId(){return this.id}getAddresses(){return Object.values(this.addresses).sort((e,s)=>s.getCreatedAtTime()-e.getCreatedAtTime())}getShippingAddresses(){return this.getAddresses().filter(e=>e.getIsShippingAddress())}getBillingAddresses(){return this.getAddresses().filter(e=>e.getIsBillingAddress())}getDefaultBillingAddressId(){let e=this.getAddresses().find(s=>s.getId()===this.defaultBillingAddressId&&s.getIsBillingAddress());return e?e.getId():this.getAddresses().find(s=>s.getIsBillingAddress())?.getId()||null}getDefaultShippingAddressId(){let e=this.getAddresses().find(s=>s.getId()===this.defaultShippingAddressId&&s.getIsShippingAddress());return e?e.getId():this.getAddresses().find(s=>s.getIsShippingAddress())?.getId()||null}};export{t as default};//# sourceMappingURL=CustomerAddress.mjs.map
2
2
  //# sourceMappingURL=CustomerAddress.mjs.map
@@ -1,2 +1,2 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var l=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,e,i,r){this.modifiedBy={id:t,authType:e,requestId:i,lambdaName:r};}getCustomField(t){return this.customFields[t]??null}setCustomField(t,e){this.customFields[t]=e;}getAllCustomFields(){return {...this.customFields}}};var m={"en-IN":"en","kn-IN":"kn"};var y={IN:"INR"},S={INR:"\u20B9"};var h=class extends l{couponCode;name;description;type;customerId;validFrom;validTo;minCartValue;maxCartDiscount;discountMethod;percentageValue;applicableTo;category;constructor(t,e=new Date){super(t,e),this.couponCode=t.couponCode,this.name={...t.name},this.description={...t.description},this.type=t.type,this.customerId=t.customerId,this.validFrom=t.validFrom&&Date.parse(t.validFrom)?new Date(t.validFrom).toISOString():e.toISOString(),this.validTo=t.validTo&&Date.parse(t.validTo)?new Date(t.validTo).toISOString():e.toISOString(),this.minCartValue=t.minCartValue.map(i=>({...i})),this.maxCartDiscount=t.maxCartDiscount.map(i=>({...i})),this.discountMethod=t.discountMethod,this.percentageValue=t.percentageValue??0,this.applicableTo=t.applicableTo,this.category=t.category;}getCode(){return this.couponCode}getName(t){return t?this.name[t]??this.name[m[t]]??this.name.en:{...this.name}}getDescription(t){return t?this.description[t]??this.description[m[t]]??this.description.en:{...this.description}}getType(){return this.type}getCustomerId(){return this.customerId??""}getValidFrom(){return this.validFrom}getValidTo(){return this.validTo}getMinCartValue(t){return t?this.minCartValue.find(e=>e.country===t):this.minCartValue}getMaxCartDiscount(t){return t?this.maxCartDiscount.find(e=>e.country===t):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(t){return this.applicableTo==="all"||this.applicableTo==="ftb"&&t}};var n=class a{price;country;constructor(t,e){if(this.country=e,t<0)throw new Error("InvalidPrice: Price cannot be negative.");this.price=t;}getCountry(){return this.country}getRoundedPrice(){return a.getRoundedPrice(this.price,this.country)}getFormattedString(t){return a.getFormattedString(this.price,this.country,t)}static getFormattedString(t,e,i,r={}){let s=r.displayAsInteger??!1,u=y[e];if(u===void 0)throw new Error("Currency mapping not found for CountryCode");let d=t,g=s?0:a.getDecimalPlaces(u),f={style:r.style??"currency",currency:u,signDisplay:"never",currencyDisplay:r.currencyDisplay,minimumFractionDigits:g,maximumFractionDigits:g};s&&(d=Math.round(d));try{return new Intl.NumberFormat(i,f).format(d)}catch(o){return console.error(`Error formatting price for country "${e}" and currency "${u}":`,o),`${S[u]??u} ${a.addThousandSeparators(d.toFixed(g))}`}}static getDecimalPlaces(t){switch(t){case"INR":default:return 2}}static addThousandSeparators(t){let e=t.split("."),i=e[0],r=e.length>1?"."+e[1]:"";return i.replace(/\B(?=(\d{3})+(?!\d))/g,",")+r}static getRoundedPrice(t,e){if(t<0)throw new Error("Price cannot be negative for rounding.");let i=y[e];if(i===void 0)throw new Error(`Currency mapping not found for CountryCode: ${e}`);let r=a.getDecimalPlaces(i),s=Math.pow(10,r);return Math.round(t*s)/s}static getCurrency(t){return y[t]}};var p=class extends l{id;firstName;lastName;phone;email;addressLine1;addressLine2;city;postalCode;state;country;isBillingAddress;isShippingAddress;constructor(t,e=new Date){super(t,e),this.id=t.id,this.firstName=t.firstName,this.lastName=t.lastName||"",this.phone=t.phone,this.email=t.email,this.addressLine1=t.addressLine1,this.addressLine2=t.addressLine2||"",this.city=t.city,this.postalCode=t.postalCode,this.state=t.state,this.country=t.country,this.isBillingAddress=t.isBillingAddress,this.isShippingAddress=t.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(t){return t==="shipping"||t==="billing&shipping"}static checkIfBillingAddress(t){return t==="billing"||t==="billing&shipping"}};var I=class{sources;alt;order;label;constructor(t){if(this.sources={...t.sources},this.alt=t.alt,this.order=t.order,this.label=t.label,!this.sources.original)throw "ImageInfoModel cannot be created without an 'original' source URL."}getSources(){return {...this.sources}}getSource(t){return this.sources[t]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(t){this.alt=t;}setOrder(t){this.order=t;}setLabel(t){this.label=t;}setSource(t,e){if(e===void 0){if(t==="original")throw "Cannot remove the 'original' image source.";delete this.sources[t];}else this.sources[t]=e;}getDetails(){return {sources:this.getSources(),alt:this.getAlt(),order:this.getOrder(),label:this.getLabel()}}};var b=class{id;productKey;variantId;name;attributes;specifications;primaryImage;subItems;totalQuantity;basePrice;priceTotals;priceTiers;constructor(t){this.id=t.id,this.productKey=t.productKey,this.variantId=t.variantId,this.name={...t.name},this.attributes={...t.attributes},this.specifications={...t.specifications},this.primaryImage=new I(t.primaryImage),this.subItems=t.subItems.map(e=>({...e})),this.basePrice={...t.basePrice},this.priceTiers=t.priceTiers.map(e=>({...e})),this.totalQuantity=0,this.priceTotals={subtotal:0,mrpTotal:0},this.recalculateTotalQuantity(),this.recalculatePriceTotal();}getId(){return this.id}getProductKey(){return this.productKey}getVariantId(){return this.variantId}getName(t){return t?this.name[t]??this.name[m[t]]??this.name.en:{...this.name}}getAttributes(){return {...this.attributes}}getSpecifications(t){return t?this.specifications[t]??this.specifications[m[t]]??this.specifications.en:JSON.parse(JSON.stringify(this.specifications))}getImage(){return this.primaryImage}getSubItems(){return this.subItems.map(t=>({...t}))}getTotalQuantity(){return this.totalQuantity}getBasePrice(){return {...this.basePrice}}getPriceTotals(){return {...this.priceTotals}}getPriceTiers(){return this.priceTiers.map(t=>({...t}))}recalculateTotalQuantity(){this.totalQuantity=this.subItems.reduce((t,e)=>t+e.quantity,0);}recalculatePriceTotal(){let t=this.totalQuantity,e=this.basePrice.unitPrice,i=null;for(let r of this.priceTiers.sort((s,u)=>u.minQuantity-s.minQuantity))if(t>=r.minQuantity){i=r;break}i&&(e=i.unitPrice),this.priceTotals.mrpTotal=this.basePrice.unitPrice*t,this.priceTotals.subtotal=e*t;}getDetails(){return {id:this.getId(),productKey:this.getProductKey(),variantId:this.getVariantId(),name:this.getName(),attributes:this.getAttributes(),specifications:this.getSpecifications(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),totalQuantity:this.getTotalQuantity(),basePrice:this.getBasePrice(),priceTotals:this.getPriceTotals(),priceTiers:this.getPriceTiers()}}addSubItems(t,e){t.forEach(i=>{let r=this.subItems.find(s=>s.size===i.size);r?r.quantity=e?r.quantity+i.quantity:i.quantity:this.subItems.push(i);}),this.subItems=this.subItems.filter(i=>i.quantity),this.recalculateTotalQuantity(),this.recalculatePriceTotal();}clearLineItem(){this.id="",this.productKey="",this.variantId="",this.name={en:""},this.attributes={color:{name:"",hex:""}},this.primaryImage=new I({sources:{original:""}}),this.subItems=[],this.recalculateTotalQuantity(),this.recalculatePriceTotal();}};var C=class extends l{id;customerId;customerEmail;anonymousId;lineItems;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;constructor(t,e=new Date){super(t,e),this.id=t.id,this.customerId=t.customerId,this.customerEmail=t.customerEmail,this.anonymousId=t.anonymousId,this.country=t.country,this.currency=t.currency,this.locale=t.locale,this.lineItems=(t.lineItems??[]).map(i=>new b(i)),this.billingAddress=t.billingAddress?new p(t.billingAddress,e):null,this.shippingAddress=t.shippingAddress?new p(t.shippingAddress,e):null,this.coupons=(t.coupons||[]).map(i=>new h(i)),this.shippingDetails=t.shippingDetails?{...t.shippingDetails}:null,this.total={shipping:t.total?.shipping||0,effectiveShipping:t.total?.effectiveShipping??t.total?.shipping??0,subtotal:t.total?.subtotal||0,mrpTotal:t.total?.mrpTotal||0,couponTotal:t.total?.couponTotal||{},grandTotal:t.total?.grandTotal||0};}recalculateBaseTotals(){this.total.subtotal=n.getRoundedPrice(this.lineItems.reduce((t,e)=>t+e.getPriceTotals().subtotal,0),this.country),this.total.mrpTotal=n.getRoundedPrice(this.lineItems.reduce((t,e)=>t+e.getPriceTotals().mrpTotal,0),this.country);}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new b(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getShippingDetails(){return this.shippingDetails?{...this.shippingDetails}:null}getShippingAddress(){return this.shippingAddress?new p(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new p(this.billingAddress.getDetails()):null}getCoupons(){return this.coupons.map(t=>new h(t.getDetails()))}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return {...this.total,couponTotal:{...this.total.couponTotal}}}calculateApplicableCouponDiscount(t,e=!0){if(e&&!t.isActive())return 0;let i=t.getMinCartValue(this.country),r=t.getMaxCartDiscount(this.country);if(!i||this.total.subtotal<i.price||!r||r.price<0)return 0;let s=t.getCategory(),u=t.getDiscountMethod(),d=0,g=s==="SHIPPING"?this.total.shipping:this.total.subtotal;if(g<=0)return 0;switch(u){case"flat":let o=r?.price??0;d=Math.min(g,o);break;case"percentage":d=g*(t.getPercentageValue()/100);break;default:return 0}let f=Math.min(d,r.price);return n.getRoundedPrice(Math.max(0,f),this.country)}recalculateCouponTotals(t=!0){this.total.couponTotal={};let e=0;return this.coupons.forEach(i=>{let r=this.calculateApplicableCouponDiscount(i,t);r>0&&(this.total.couponTotal[i.getCode()]=r,e+=r);}),n.getRoundedPrice(e,this.country)}getDetails(){return {...super.getDetails(),id:this.getId(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),anonymousId:this.getAnonymousId(),lineItems:this.getLineItems().map(t=>t.getDetails()),shippingDetails:this.getShippingDetails(),shippingAddress:this.getShippingAddress()?.getDetails()||null,billingAddress:this.getBillingAddress()?.getDetails()||null,coupons:this.getCoupons().map(t=>t.getDetails()),total:this.getTotal(),country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}};var A=class extends Error{constructor(t){super(`Line item with ID '${t}' not found in the cart.`),this.name="LineItemNotFoundError";}};var L=(s=>(s.PLACED="PLACED",s.PENDING_PAYMENT="PENDING_PAYMENT",s.PROCESSING="PROCESSING",s.CANCELLED="CANCELLED",s.COMPLETED="COMPLETED",s))(L||{}),P=(o=>(o.INITIAL="INITIAL",o.PROCESSING="PROCESSING",o.SHIPPED="SHIPPED",o.DELIVERED="DELIVERED",o.CANCELLED="CANCELLED",o.RETURN_REQUESTED="RETURN_REQUESTED",o.RETURNED="RETURNED",o.REFUND_INITIATED="REFUND_INITIATED",o.REFUNDED="REFUNDED",o.ON_HOLD="ON_HOLD",o))(P||{}),D=class extends C{orderNumber;cartId;paymentStatus;holdReason;state;lineItemStateMap;constructor(t,e=new Date){super(t,e),this.orderNumber=t.orderNumber,this.cartId=t.cartId,this.paymentStatus=t.paymentStatus,this.holdReason=t.holdReason||"",this.state=t.state;let i={};t.lineItems.forEach(r=>{let s=t.lineItemStateMap?.[r.id];i[r.id]={state:s?.state||"INITIAL",reason:s?.reason||"",transitionAt:s?.transitionAt||this.createdAt};}),this.lineItemStateMap=i;}recalculateOrderBaseTotals(t=!1){let e=this.lineItems.filter(i=>this.lineItemStateMap[i.getId()]?.state!=="CANCELLED"||t&&["RETURN_REQUESTED","RETURNED","REFUND_INITIATED","REFUNDED"].includes(this.lineItemStateMap[i.getId()]?.state));this.total.subtotal=n.getRoundedPrice(e.reduce((i,r)=>i+r.getPriceTotals().subtotal,0),this.country),this.total.mrpTotal=n.getRoundedPrice(e.reduce((i,r)=>i+r.getPriceTotals().mrpTotal,0),this.country);}updateOrderTotals(){this.recalculateOrderBaseTotals(!0),this.recalculateCouponTotals(!1),this.recalculateOrderBaseTotals();let t=this.coupons.filter(r=>r.getCategory()==="SHIPPING").reduce((r,s)=>r+(this.total.couponTotal[s.getCode()]??0),0);this.total.effectiveShipping=n.getRoundedPrice(Math.max(0,this.total.shipping-t),this.country);let e=this.coupons.filter(r=>r.getCategory()!=="SHIPPING").reduce((r,s)=>r+(this.total.couponTotal[s.getCode()]??0),0),i=this.total.subtotal+this.total.effectiveShipping;this.total.grandTotal=n.getRoundedPrice(Math.max(0,i-e),this.country);}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getShippingAddress(){return this.shippingAddress}getBillingAddress(){return this.billingAddress}getOrderNumber(){return this.orderNumber}getCartId(){return this.cartId}getPaymentStatus(){return this.paymentStatus}getHoldReason(){return this.holdReason}getState(){return this.state}getLineItemsStateMap(){return {...this.lineItemStateMap}}getLineItemState(t){if(!this.lineItemStateMap[t])throw new A(t);return this.lineItemStateMap[t].state}getDetails(){return {...super.getDetails(),orderNumber:this.getOrderNumber(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),shippingAddress:this.getShippingAddress().getDetails(),billingAddress:this.getBillingAddress().getDetails(),cartId:this.getCartId(),paymentStatus:this.getPaymentStatus(),holdReason:this.getHoldReason(),state:this.getState(),lineItemStateMap:this.getLineItemsStateMap()}}};exports.OrderLineItemState=P;exports.OrderState=L;exports.default=D;//# sourceMappingURL=Order.js.map
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var l=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,e,i,r){this.modifiedBy={id:t,authType:e,requestId:i,lambdaName:r};}getCustomField(t){return this.customFields[t]??null}setCustomField(t,e){this.customFields[t]=e;}getAllCustomFields(){return {...this.customFields}}};var m={"en-IN":"en","kn-IN":"kn"};var y={IN:"INR"},S={INR:"\u20B9"};var h=class extends l{couponCode;name;description;type;customerId;validFrom;validTo;minCartValue;maxCartDiscount;discountMethod;percentageValue;applicableTo;category;constructor(t,e=new Date){super(t,e),this.couponCode=t.couponCode,this.name={...t.name},this.description={...t.description},this.type=t.type,this.customerId=t.customerId,this.validFrom=t.validFrom&&Date.parse(t.validFrom)?new Date(t.validFrom).toISOString():e.toISOString(),this.validTo=t.validTo&&Date.parse(t.validTo)?new Date(t.validTo).toISOString():e.toISOString(),this.minCartValue=t.minCartValue.map(i=>({...i})),this.maxCartDiscount=t.maxCartDiscount.map(i=>({...i})),this.discountMethod=t.discountMethod,this.percentageValue=t.percentageValue??0,this.applicableTo=t.applicableTo,this.category=t.category;}getCode(){return this.couponCode}getName(t){return t?this.name[t]??this.name[m[t]]??this.name.en:{...this.name}}getDescription(t){return t?this.description[t]??this.description[m[t]]??this.description.en:{...this.description}}getType(){return this.type}getCustomerId(){return this.customerId??""}getValidFrom(){return this.validFrom}getValidTo(){return this.validTo}getMinCartValue(t){return t?this.minCartValue.find(e=>e.country===t):this.minCartValue}getMaxCartDiscount(t){return t?this.maxCartDiscount.find(e=>e.country===t):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(t){return this.applicableTo==="all"||this.applicableTo==="ftb"&&t}};var n=class a{price;country;constructor(t,e){if(this.country=e,t<0)throw new Error("InvalidPrice: Price cannot be negative.");this.price=t;}getCountry(){return this.country}getRoundedPrice(){return a.getRoundedPrice(this.price,this.country)}getFormattedString(t){return a.getFormattedString(this.price,this.country,t)}static getFormattedString(t,e,i,r={}){let s=r.displayAsInteger??!1,u=y[e];if(u===void 0)throw new Error("Currency mapping not found for CountryCode");let d=t,g=s?0:a.getDecimalPlaces(u),f={style:r.style??"currency",currency:u,signDisplay:"never",currencyDisplay:r.currencyDisplay,minimumFractionDigits:g,maximumFractionDigits:g};s&&(d=Math.round(d));try{return new Intl.NumberFormat(i,f).format(d)}catch(o){return console.error(`Error formatting price for country "${e}" and currency "${u}":`,o),`${S[u]??u} ${a.addThousandSeparators(d.toFixed(g))}`}}static getDecimalPlaces(t){switch(t){case"INR":default:return 2}}static addThousandSeparators(t){let e=t.split("."),i=e[0],r=e.length>1?"."+e[1]:"";return i.replace(/\B(?=(\d{3})+(?!\d))/g,",")+r}static getRoundedPrice(t,e){if(t<0)throw new Error("Price cannot be negative for rounding.");let i=y[e];if(i===void 0)throw new Error(`Currency mapping not found for CountryCode: ${e}`);let r=a.getDecimalPlaces(i),s=Math.pow(10,r);return Math.round(t*s)/s}static getCurrency(t){return y[t]}};var p=class extends l{id;firstName;lastName;company;phone;email;addressLine1;addressLine2;city;postalCode;state;country;isBillingAddress;isShippingAddress;constructor(t,e=new Date){super(t,e),this.id=t.id,this.firstName=t.firstName,this.lastName=t.lastName||"",this.company=t.company||"",this.phone=t.phone,this.email=t.email,this.addressLine1=t.addressLine1,this.addressLine2=t.addressLine2||"",this.city=t.city,this.postalCode=t.postalCode,this.state=t.state,this.country=t.country,this.isBillingAddress=t.isBillingAddress,this.isShippingAddress=t.isShippingAddress;}getDetails(){return {...super.getDetails(),id:this.getId(),firstName:this.getFirstName(),lastName:this.getLastName(),company:this.getCompany(),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}getCompany(){return this.company}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(t){return t==="shipping"||t==="billing&shipping"}static checkIfBillingAddress(t){return t==="billing"||t==="billing&shipping"}};var I=class{sources;alt;order;label;constructor(t){if(this.sources={...t.sources},this.alt=t.alt,this.order=t.order,this.label=t.label,!this.sources.original)throw "ImageInfoModel cannot be created without an 'original' source URL."}getSources(){return {...this.sources}}getSource(t){return this.sources[t]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(t){this.alt=t;}setOrder(t){this.order=t;}setLabel(t){this.label=t;}setSource(t,e){if(e===void 0){if(t==="original")throw "Cannot remove the 'original' image source.";delete this.sources[t];}else this.sources[t]=e;}getDetails(){return {sources:this.getSources(),alt:this.getAlt(),order:this.getOrder(),label:this.getLabel()}}};var C=class{id;productKey;variantId;name;attributes;specifications;primaryImage;subItems;totalQuantity;basePrice;priceTotals;priceTiers;constructor(t){this.id=t.id,this.productKey=t.productKey,this.variantId=t.variantId,this.name={...t.name},this.attributes={...t.attributes},this.specifications={...t.specifications},this.primaryImage=new I(t.primaryImage),this.subItems=t.subItems.map(e=>({...e})),this.basePrice={...t.basePrice},this.priceTiers=t.priceTiers.map(e=>({...e})),this.totalQuantity=0,this.priceTotals={subtotal:0,mrpTotal:0},this.recalculateTotalQuantity(),this.recalculatePriceTotal();}getId(){return this.id}getProductKey(){return this.productKey}getVariantId(){return this.variantId}getName(t){return t?this.name[t]??this.name[m[t]]??this.name.en:{...this.name}}getAttributes(){return {...this.attributes}}getSpecifications(t){return t?this.specifications[t]??this.specifications[m[t]]??this.specifications.en:JSON.parse(JSON.stringify(this.specifications))}getImage(){return this.primaryImage}getSubItems(){return this.subItems.map(t=>({...t}))}getTotalQuantity(){return this.totalQuantity}getBasePrice(){return {...this.basePrice}}getPriceTotals(){return {...this.priceTotals}}getPriceTiers(){return this.priceTiers.map(t=>({...t}))}recalculateTotalQuantity(){this.totalQuantity=this.subItems.reduce((t,e)=>t+e.quantity,0);}recalculatePriceTotal(){let t=this.totalQuantity,e=this.basePrice.unitPrice,i=null;for(let r of this.priceTiers.sort((s,u)=>u.minQuantity-s.minQuantity))if(t>=r.minQuantity){i=r;break}i&&(e=i.unitPrice),this.priceTotals.mrpTotal=this.basePrice.unitPrice*t,this.priceTotals.subtotal=e*t;}getDetails(){return {id:this.getId(),productKey:this.getProductKey(),variantId:this.getVariantId(),name:this.getName(),attributes:this.getAttributes(),specifications:this.getSpecifications(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),totalQuantity:this.getTotalQuantity(),basePrice:this.getBasePrice(),priceTotals:this.getPriceTotals(),priceTiers:this.getPriceTiers()}}addSubItems(t,e){t.forEach(i=>{let r=this.subItems.find(s=>s.size===i.size);r?r.quantity=e?r.quantity+i.quantity:i.quantity:this.subItems.push(i);}),this.subItems=this.subItems.filter(i=>i.quantity),this.recalculateTotalQuantity(),this.recalculatePriceTotal();}clearLineItem(){this.id="",this.productKey="",this.variantId="",this.name={en:""},this.attributes={color:{name:"",hex:""}},this.primaryImage=new I({sources:{original:""}}),this.subItems=[],this.recalculateTotalQuantity(),this.recalculatePriceTotal();}};var b=class extends l{id;customerId;customerEmail;anonymousId;lineItems;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;constructor(t,e=new Date){super(t,e),this.id=t.id,this.customerId=t.customerId,this.customerEmail=t.customerEmail,this.anonymousId=t.anonymousId,this.country=t.country,this.currency=t.currency,this.locale=t.locale,this.lineItems=(t.lineItems??[]).map(i=>new C(i)),this.billingAddress=t.billingAddress?new p(t.billingAddress,e):null,this.shippingAddress=t.shippingAddress?new p(t.shippingAddress,e):null,this.coupons=(t.coupons||[]).map(i=>new h(i)),this.shippingDetails=t.shippingDetails?{...t.shippingDetails}:null,this.total={shipping:t.total?.shipping||0,effectiveShipping:t.total?.effectiveShipping??t.total?.shipping??0,subtotal:t.total?.subtotal||0,mrpTotal:t.total?.mrpTotal||0,couponTotal:t.total?.couponTotal||{},grandTotal:t.total?.grandTotal||0};}recalculateBaseTotals(){this.total.subtotal=n.getRoundedPrice(this.lineItems.reduce((t,e)=>t+e.getPriceTotals().subtotal,0),this.country),this.total.mrpTotal=n.getRoundedPrice(this.lineItems.reduce((t,e)=>t+e.getPriceTotals().mrpTotal,0),this.country);}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new C(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getShippingDetails(){return this.shippingDetails?{...this.shippingDetails}:null}getShippingAddress(){return this.shippingAddress?new p(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new p(this.billingAddress.getDetails()):null}getCoupons(){return this.coupons.map(t=>new h(t.getDetails()))}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return {...this.total,couponTotal:{...this.total.couponTotal}}}calculateApplicableCouponDiscount(t,e=!0){if(e&&!t.isActive())return 0;let i=t.getMinCartValue(this.country),r=t.getMaxCartDiscount(this.country);if(!i||this.total.subtotal<i.price||!r||r.price<0)return 0;let s=t.getCategory(),u=t.getDiscountMethod(),d=0,g=s==="SHIPPING"?this.total.shipping:this.total.subtotal;if(g<=0)return 0;switch(u){case"flat":let o=r?.price??0;d=Math.min(g,o);break;case"percentage":d=g*(t.getPercentageValue()/100);break;default:return 0}let f=Math.min(d,r.price);return n.getRoundedPrice(Math.max(0,f),this.country)}recalculateCouponTotals(t=!0){this.total.couponTotal={};let e=0;return this.coupons.forEach(i=>{let r=this.calculateApplicableCouponDiscount(i,t);r>0&&(this.total.couponTotal[i.getCode()]=r,e+=r);}),n.getRoundedPrice(e,this.country)}getDetails(){return {...super.getDetails(),id:this.getId(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),anonymousId:this.getAnonymousId(),lineItems:this.getLineItems().map(t=>t.getDetails()),shippingDetails:this.getShippingDetails(),shippingAddress:this.getShippingAddress()?.getDetails()||null,billingAddress:this.getBillingAddress()?.getDetails()||null,coupons:this.getCoupons().map(t=>t.getDetails()),total:this.getTotal(),country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}};var A=class extends Error{constructor(t){super(`Line item with ID '${t}' not found in the cart.`),this.name="LineItemNotFoundError";}};var L=(s=>(s.PLACED="PLACED",s.PENDING_PAYMENT="PENDING_PAYMENT",s.PROCESSING="PROCESSING",s.CANCELLED="CANCELLED",s.COMPLETED="COMPLETED",s))(L||{}),P=(o=>(o.INITIAL="INITIAL",o.PROCESSING="PROCESSING",o.SHIPPED="SHIPPED",o.DELIVERED="DELIVERED",o.CANCELLED="CANCELLED",o.RETURN_REQUESTED="RETURN_REQUESTED",o.RETURNED="RETURNED",o.REFUND_INITIATED="REFUND_INITIATED",o.REFUNDED="REFUNDED",o.ON_HOLD="ON_HOLD",o))(P||{}),D=class extends b{orderNumber;cartId;paymentStatus;holdReason;state;lineItemStateMap;constructor(t,e=new Date){super(t,e),this.orderNumber=t.orderNumber,this.cartId=t.cartId,this.paymentStatus=t.paymentStatus,this.holdReason=t.holdReason||"",this.state=t.state;let i={};t.lineItems.forEach(r=>{let s=t.lineItemStateMap?.[r.id];i[r.id]={state:s?.state||"INITIAL",reason:s?.reason||"",transitionAt:s?.transitionAt||this.createdAt};}),this.lineItemStateMap=i;}recalculateOrderBaseTotals(t=!1){let e=this.lineItems.filter(i=>!(this.lineItemStateMap[i.getId()]?.state==="CANCELLED"||t&&["RETURN_REQUESTED","RETURNED","REFUND_INITIATED","REFUNDED"].includes(this.lineItemStateMap[i.getId()]?.state)));this.total.subtotal=n.getRoundedPrice(e.reduce((i,r)=>i+r.getPriceTotals().subtotal,0),this.country),this.total.mrpTotal=n.getRoundedPrice(e.reduce((i,r)=>i+r.getPriceTotals().mrpTotal,0),this.country);}updateOrderTotals(){this.recalculateOrderBaseTotals(!0),this.recalculateCouponTotals(!1),this.recalculateOrderBaseTotals();let t=this.coupons.filter(r=>r.getCategory()==="SHIPPING").reduce((r,s)=>r+(this.total.couponTotal[s.getCode()]??0),0);this.total.effectiveShipping=n.getRoundedPrice(Math.max(0,this.total.shipping-t),this.country);let e=this.coupons.filter(r=>r.getCategory()!=="SHIPPING").reduce((r,s)=>r+(this.total.couponTotal[s.getCode()]??0),0),i=this.total.subtotal+this.total.effectiveShipping;this.total.grandTotal=n.getRoundedPrice(Math.max(0,i-e),this.country);}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getShippingAddress(){return this.shippingAddress}getBillingAddress(){return this.billingAddress}getOrderNumber(){return this.orderNumber}getCartId(){return this.cartId}getPaymentStatus(){return this.paymentStatus}getHoldReason(){return this.holdReason}getState(){return this.state}getLineItemsStateMap(){return {...this.lineItemStateMap}}getLineItemState(t){if(!this.lineItemStateMap[t])throw new A(t);return this.lineItemStateMap[t].state}getDetails(){return {...super.getDetails(),orderNumber:this.getOrderNumber(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),shippingAddress:this.getShippingAddress().getDetails(),billingAddress:this.getBillingAddress().getDetails(),cartId:this.getCartId(),paymentStatus:this.getPaymentStatus(),holdReason:this.getHoldReason(),state:this.getState(),lineItemStateMap:this.getLineItemsStateMap()}}};exports.OrderLineItemState=P;exports.OrderState=L;exports.default=D;//# sourceMappingURL=Order.js.map
2
2
  //# sourceMappingURL=Order.js.map