b23-lib 1.9.2 → 1.9.3
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.
|
@@ -9,7 +9,8 @@ declare enum CustomerStatus {
|
|
|
9
9
|
ACTIVATED_USER = "ACTIVATED_USER",
|
|
10
10
|
EMAIL_OTP = "EMAIL_OTP",
|
|
11
11
|
EMAIL_PASSWORD = "EMAIL_PASSWORD",
|
|
12
|
-
PHONE_OTP = "PHONE_OTP"
|
|
12
|
+
PHONE_OTP = "PHONE_OTP",
|
|
13
|
+
GOOGLE_AUTH = "GOOGLE_AUTH"
|
|
13
14
|
}
|
|
14
15
|
type CustomerAttributes = BaseAttributes & {
|
|
15
16
|
id: string;
|
|
@@ -9,7 +9,8 @@ declare enum CustomerStatus {
|
|
|
9
9
|
ACTIVATED_USER = "ACTIVATED_USER",
|
|
10
10
|
EMAIL_OTP = "EMAIL_OTP",
|
|
11
11
|
EMAIL_PASSWORD = "EMAIL_PASSWORD",
|
|
12
|
-
PHONE_OTP = "PHONE_OTP"
|
|
12
|
+
PHONE_OTP = "PHONE_OTP",
|
|
13
|
+
GOOGLE_AUTH = "GOOGLE_AUTH"
|
|
13
14
|
}
|
|
14
15
|
type CustomerAttributes = BaseAttributes & {
|
|
15
16
|
id: string;
|
package/dist/Classes/Customer.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var s=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(t,e=new Date){this.customFields={...t.customFields},this.version=t.version??1,this.createdAt=t.createdAt&&!isNaN(Date.parse(t.createdAt))?new Date(t.createdAt).toISOString():e.toISOString(),this.modifiedAt=t.modifiedAt&&!isNaN(Date.parse(t.modifiedAt))?new Date(t.modifiedAt).toISOString():e.toISOString(),this.modifiedBy={...t.modifiedBy};}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return {...this.modifiedBy}}setModifiedBy(t,e,a,m){this.modifiedBy={id:t,authType:e,requestId:a,lambdaName:m};}getCustomField(t){return this.customFields[t]??null}setCustomField(t,e){this.customFields[t]=e;}getAllCustomFields(){return {...this.customFields}}};var
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var s=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(t,e=new Date){this.customFields={...t.customFields},this.version=t.version??1,this.createdAt=t.createdAt&&!isNaN(Date.parse(t.createdAt))?new Date(t.createdAt).toISOString():e.toISOString(),this.modifiedAt=t.modifiedAt&&!isNaN(Date.parse(t.modifiedAt))?new Date(t.modifiedAt).toISOString():e.toISOString(),this.modifiedBy={...t.modifiedBy};}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return {...this.modifiedBy}}setModifiedBy(t,e,a,m){this.modifiedBy={id:t,authType:e,requestId:a,lambdaName:m};}getCustomField(t){return this.customFields[t]??null}setCustomField(t,e){this.customFields[t]=e;}getAllCustomFields(){return {...this.customFields}}};var u=(i=>(i.CREATED="CREATED",i.REGISTERED_USER="REGISTERED_USER",i.ACTIVATED_USER="ACTIVATED_USER",i.EMAIL_OTP="EMAIL_OTP",i.EMAIL_PASSWORD="EMAIL_PASSWORD",i.PHONE_OTP="PHONE_OTP",i.GOOGLE_AUTH="GOOGLE_AUTH",i))(u||{}),r=class extends s{id;email;phone;firstName;lastName;isEmailVerified;customerStatus;constructor(t,e=new Date){super(t,e),this.id=t.id,this.email=t.email,this.phone=t.phone,this.firstName=t.firstName,this.lastName=t.lastName,this.isEmailVerified=t.isEmailVerified??!1,this.customerStatus=new Set([...t.customerStatus?Array.from(t.customerStatus):[],"CREATED"]);}getDetails(t=!1){return {...super.getDetails(),...t?{id:this.getId()}:{},email:this.getEmail(),phone:this.getPhone(),firstName:this.getFirstName(),lastName:this.getLastName(),isEmailVerified:this.getIsEmailVerified(),customerStatus:this.getCustomerStatus()}}getId(){return this.id}getEmail(){return this.email}getPhone(){return this.phone}getFirstName(){return this.firstName}getLastName(){return this.lastName}getIsEmailVerified(){return this.isEmailVerified}getCustomerStatus(){return Array.from(this.customerStatus)}hasCustomerStatus(t){return this.customerStatus.has(t)}};exports.CustomerStatus=u;exports.default=r;//# sourceMappingURL=Customer.js.map
|
|
2
2
|
//# sourceMappingURL=Customer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Classes/Base.ts","../../src/Classes/Customer.ts"],"names":["BaseModel","data","date","id","authType","requestId","lambdaName","fieldName","value","CustomerStatus","CustomerModel","withId","customerStatus"],"mappings":"sEA4BA,IAAqBA,CAAAA,CAArB,KAA+B,CACnB,YAAA,CACA,QACA,SACA,CAAA,UAAA,CACA,WAQV,WAAYC,CAAAA,CAAAA,CAAsBC,EAAa,IAAI,IAAA,CAAQ,CACzD,IAAK,CAAA,YAAA,CAAe,CAAE,GAAGD,CAAAA,CAAK,YAAa,CAC3C,CAAA,IAAA,CAAK,QAAUA,CAAK,CAAA,OAAA,EAAW,EAC/B,IAAK,CAAA,SAAA,CAAYA,EAAK,SAAa,EAAA,CAAC,MAAM,IAAK,CAAA,KAAA,CAAMA,EAAK,SAAS,CAAC,EAElE,IAAI,IAAA,CAAKA,EAAK,SAAS,CAAA,CAAE,WAAY,EAAA,CAErCC,CAAK,CAAA,WAAA,GACP,IAAK,CAAA,UAAA,CAAaD,EAA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kBAAA,GACtB,cAAgB,CAAA,IAAA,CAAK,mBACvB,CACF,CAMA,KAAgB,EAAA,CACd,OAAO,IAAA,CAAK,EACd,CAMA,UAAmB,CACjB,OAAO,KAAK,KACd,CAMA,UAA+B,CAC7B,OAAO,KAAK,KACd,CAOA,cAAuB,CACrB,OAAO,KAAK,SACd,CAOA,aAAsB,CACpB,OAAO,IAAK,CAAA,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.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, BaseData } from \"./Base\";\r\n\r\nexport enum CustomerStatus {\r\n CREATED = \"CREATED\",\r\n REGISTERED_USER = \"REGISTERED_USER\",\r\n ACTIVATED_USER = \"ACTIVATED_USER\",\r\n EMAIL_OTP = \"EMAIL_OTP\",\r\n EMAIL_PASSWORD = \"EMAIL_PASSWORD\",\r\n PHONE_OTP = \"PHONE_OTP\",\r\n}\r\n\r\nexport type CustomerAttributes = BaseAttributes & {\r\n id: string;\r\n email: string;\r\n phone?: string;\r\n firstName: string;\r\n lastName: string;\r\n isEmailVerified?: boolean;\r\n customerStatus?: Set<CustomerStatus>;\r\n};\r\n\r\n\r\ntype CustomerDataWithArrayStatus = Omit<CustomerAttributes, 'customerStatus'> & BaseData & { customerStatus: CustomerStatus[]; }\r\nexport type CustomerData = Required<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/Base.ts","../../src/Classes/Customer.ts"],"names":["BaseModel","data","date","id","authType","requestId","lambdaName","fieldName","value","CustomerStatus","CustomerModel","withId","customerStatus"],"mappings":"sEA4BA,IAAqBA,CAAAA,CAArB,KAA+B,CACnB,YAAA,CACA,QACA,SACA,CAAA,UAAA,CACA,WAQV,WAAYC,CAAAA,CAAAA,CAAsBC,EAAa,IAAI,IAAA,CAAQ,CACzD,IAAK,CAAA,YAAA,CAAe,CAAE,GAAGD,CAAAA,CAAK,YAAa,CAC3C,CAAA,IAAA,CAAK,QAAUA,CAAK,CAAA,OAAA,EAAW,EAC/B,IAAK,CAAA,SAAA,CAAYA,EAAK,SAAa,EAAA,CAAC,MAAM,IAAK,CAAA,KAAA,CAAMA,EAAK,SAAS,CAAC,EAElE,IAAI,IAAA,CAAKA,EAAK,SAAS,CAAA,CAAE,WAAY,EAAA,CAErCC,C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A,CACrB,MAAO,IAAK,CAAA,QAAA,GACZ,SAAW,CAAA,IAAA,CAAK,cAChB,CAAA,QAAA,CAAU,KAAK,WAAY,EAAA,CAC3B,gBAAiB,IAAK,CAAA,kBAAA,GACtB,cAAgB,CAAA,IAAA,CAAK,mBACvB,CACF,CAMA,KAAgB,EAAA,CACd,OAAO,IAAA,CAAK,EACd,CAMA,UAAmB,CACjB,OAAO,KAAK,KACd,CAMA,UAA+B,CAC7B,OAAO,KAAK,KACd,CAOA,cAAuB,CACrB,OAAO,KAAK,SACd,CAOA,aAAsB,CACpB,OAAO,IAAK,CAAA,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.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, 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,2 +1,2 @@
|
|
|
1
|
-
import {a as a$1}from'../chunk-ATUUYYQT.mjs';var a=(e=>(e.CREATED="CREATED",e.REGISTERED_USER="REGISTERED_USER",e.ACTIVATED_USER="ACTIVATED_USER",e.EMAIL_OTP="EMAIL_OTP",e.EMAIL_PASSWORD="EMAIL_PASSWORD",e.PHONE_OTP="PHONE_OTP",e))(a||{}),s=class extends a$1{id;email;phone;firstName;lastName;isEmailVerified;customerStatus;constructor(t,r=new Date){super(t,r),this.id=t.id,this.email=t.email,this.phone=t.phone,this.firstName=t.firstName,this.lastName=t.lastName,this.isEmailVerified=t.isEmailVerified??!1,this.customerStatus=new Set([...t.customerStatus?Array.from(t.customerStatus):[],"CREATED"]);}getDetails(t=!1){return {...super.getDetails(),...t?{id:this.getId()}:{},email:this.getEmail(),phone:this.getPhone(),firstName:this.getFirstName(),lastName:this.getLastName(),isEmailVerified:this.getIsEmailVerified(),customerStatus:this.getCustomerStatus()}}getId(){return this.id}getEmail(){return this.email}getPhone(){return this.phone}getFirstName(){return this.firstName}getLastName(){return this.lastName}getIsEmailVerified(){return this.isEmailVerified}getCustomerStatus(){return Array.from(this.customerStatus)}hasCustomerStatus(t){return this.customerStatus.has(t)}};export{a as CustomerStatus,s as default};//# sourceMappingURL=Customer.mjs.map
|
|
1
|
+
import {a as a$1}from'../chunk-ATUUYYQT.mjs';var a=(e=>(e.CREATED="CREATED",e.REGISTERED_USER="REGISTERED_USER",e.ACTIVATED_USER="ACTIVATED_USER",e.EMAIL_OTP="EMAIL_OTP",e.EMAIL_PASSWORD="EMAIL_PASSWORD",e.PHONE_OTP="PHONE_OTP",e.GOOGLE_AUTH="GOOGLE_AUTH",e))(a||{}),s=class extends a$1{id;email;phone;firstName;lastName;isEmailVerified;customerStatus;constructor(t,r=new Date){super(t,r),this.id=t.id,this.email=t.email,this.phone=t.phone,this.firstName=t.firstName,this.lastName=t.lastName,this.isEmailVerified=t.isEmailVerified??!1,this.customerStatus=new Set([...t.customerStatus?Array.from(t.customerStatus):[],"CREATED"]);}getDetails(t=!1){return {...super.getDetails(),...t?{id:this.getId()}:{},email:this.getEmail(),phone:this.getPhone(),firstName:this.getFirstName(),lastName:this.getLastName(),isEmailVerified:this.getIsEmailVerified(),customerStatus:this.getCustomerStatus()}}getId(){return this.id}getEmail(){return this.email}getPhone(){return this.phone}getFirstName(){return this.firstName}getLastName(){return this.lastName}getIsEmailVerified(){return this.isEmailVerified}getCustomerStatus(){return Array.from(this.customerStatus)}hasCustomerStatus(t){return this.customerStatus.has(t)}};export{a as CustomerStatus,s as default};//# sourceMappingURL=Customer.mjs.map
|
|
2
2
|
//# sourceMappingURL=Customer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Classes/Customer.ts"],"names":["CustomerStatus","CustomerModel","BaseModel","data","date","withId","customerStatus"],"mappings":"
|
|
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"]}
|