b23-lib 1.7.0 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/Auth/index.d.mts +130 -0
  2. package/dist/Auth/index.d.ts +130 -0
  3. package/dist/Auth/index.js +2 -0
  4. package/dist/Auth/index.js.map +1 -0
  5. package/dist/Auth/index.mjs +2 -0
  6. package/dist/Auth/index.mjs.map +1 -0
  7. package/dist/Classes/Address.d.mts +142 -0
  8. package/dist/Classes/Address.d.ts +142 -0
  9. package/dist/Classes/Address.js +2 -0
  10. package/dist/Classes/Address.js.map +1 -0
  11. package/dist/Classes/Address.mjs +2 -0
  12. package/dist/Classes/Address.mjs.map +1 -0
  13. package/dist/Classes/Base.d.mts +98 -0
  14. package/dist/Classes/Base.d.ts +98 -0
  15. package/dist/Classes/Base.js +2 -0
  16. package/dist/Classes/Base.js.map +1 -0
  17. package/dist/Classes/Base.mjs +2 -0
  18. package/dist/Classes/Base.mjs.map +1 -0
  19. package/dist/Classes/Cart.d.mts +68 -0
  20. package/dist/Classes/Cart.d.ts +68 -0
  21. package/dist/Classes/Cart.js +2 -0
  22. package/dist/Classes/Cart.js.map +1 -0
  23. package/dist/Classes/Cart.mjs +2 -0
  24. package/dist/Classes/Cart.mjs.map +1 -0
  25. package/dist/Classes/Common.d.mts +75 -0
  26. package/dist/Classes/Common.d.ts +75 -0
  27. package/dist/Classes/Common.js +2 -0
  28. package/dist/Classes/Common.js.map +1 -0
  29. package/dist/Classes/Common.mjs +2 -0
  30. package/dist/Classes/Common.mjs.map +1 -0
  31. package/dist/Classes/Coupon.d.mts +142 -0
  32. package/dist/Classes/Coupon.d.ts +142 -0
  33. package/dist/Classes/Coupon.js +2 -0
  34. package/dist/Classes/Coupon.js.map +1 -0
  35. package/dist/Classes/Coupon.mjs +2 -0
  36. package/dist/Classes/Coupon.mjs.map +1 -0
  37. package/dist/Classes/Customer.d.mts +97 -0
  38. package/dist/Classes/Customer.d.ts +97 -0
  39. package/dist/Classes/Customer.js +2 -0
  40. package/dist/Classes/Customer.js.map +1 -0
  41. package/dist/Classes/Customer.mjs +2 -0
  42. package/dist/Classes/Customer.mjs.map +1 -0
  43. package/dist/Classes/CustomerAddress.d.mts +71 -0
  44. package/dist/Classes/CustomerAddress.d.ts +71 -0
  45. package/dist/Classes/CustomerAddress.js +2 -0
  46. package/dist/Classes/CustomerAddress.js.map +1 -0
  47. package/dist/Classes/CustomerAddress.mjs +2 -0
  48. package/dist/Classes/CustomerAddress.mjs.map +1 -0
  49. package/dist/Classes/Enum.d.mts +34 -0
  50. package/dist/Classes/Enum.d.ts +34 -0
  51. package/dist/Classes/Enum.js +2 -0
  52. package/dist/Classes/Enum.js.map +1 -0
  53. package/dist/Classes/Enum.mjs +2 -0
  54. package/dist/Classes/Enum.mjs.map +1 -0
  55. package/dist/Classes/ImageInfo.d.mts +92 -0
  56. package/dist/Classes/ImageInfo.d.ts +92 -0
  57. package/dist/Classes/ImageInfo.js +2 -0
  58. package/dist/Classes/ImageInfo.js.map +1 -0
  59. package/dist/Classes/ImageInfo.mjs +2 -0
  60. package/dist/Classes/ImageInfo.mjs.map +1 -0
  61. package/dist/Classes/LineItem.d.mts +124 -0
  62. package/dist/Classes/LineItem.d.ts +124 -0
  63. package/dist/Classes/LineItem.js +2 -0
  64. package/dist/Classes/LineItem.js.map +1 -0
  65. package/dist/Classes/LineItem.mjs +2 -0
  66. package/dist/Classes/LineItem.mjs.map +1 -0
  67. package/dist/Classes/Order.d.mts +83 -0
  68. package/dist/Classes/Order.d.ts +83 -0
  69. package/dist/Classes/Order.js +2 -0
  70. package/dist/Classes/Order.js.map +1 -0
  71. package/dist/Classes/Order.mjs +2 -0
  72. package/dist/Classes/Order.mjs.map +1 -0
  73. package/dist/Classes/Payment.d.mts +161 -0
  74. package/dist/Classes/Payment.d.ts +161 -0
  75. package/dist/Classes/Payment.js +2 -0
  76. package/dist/Classes/Payment.js.map +1 -0
  77. package/dist/Classes/Payment.mjs +2 -0
  78. package/dist/Classes/Payment.mjs.map +1 -0
  79. package/dist/Classes/Price.d.mts +70 -0
  80. package/dist/Classes/Price.d.ts +70 -0
  81. package/dist/Classes/Price.js +2 -0
  82. package/dist/Classes/Price.js.map +1 -0
  83. package/dist/Classes/Price.mjs +2 -0
  84. package/dist/Classes/Price.mjs.map +1 -0
  85. package/dist/Classes/Product.d.mts +209 -0
  86. package/dist/Classes/Product.d.ts +209 -0
  87. package/dist/Classes/Product.js +2 -0
  88. package/dist/Classes/Product.js.map +1 -0
  89. package/dist/Classes/Product.mjs +2 -0
  90. package/dist/Classes/Product.mjs.map +1 -0
  91. package/dist/Classes/ShoppingContainer.d.mts +194 -0
  92. package/dist/Classes/ShoppingContainer.d.ts +194 -0
  93. package/dist/Classes/ShoppingContainer.js +2 -0
  94. package/dist/Classes/ShoppingContainer.js.map +1 -0
  95. package/dist/Classes/ShoppingContainer.mjs +2 -0
  96. package/dist/Classes/ShoppingContainer.mjs.map +1 -0
  97. package/dist/Dynamodb/index.d.mts +58 -0
  98. package/dist/Dynamodb/index.d.ts +58 -0
  99. package/dist/Dynamodb/index.js +2 -0
  100. package/dist/Dynamodb/index.js.map +1 -0
  101. package/dist/Dynamodb/index.mjs +2 -0
  102. package/dist/Dynamodb/index.mjs.map +1 -0
  103. package/dist/chunk-4H4LJ3UL.mjs +2 -0
  104. package/dist/chunk-4H4LJ3UL.mjs.map +1 -0
  105. package/dist/chunk-65X54TKF.mjs +2 -0
  106. package/dist/chunk-65X54TKF.mjs.map +1 -0
  107. package/dist/chunk-763MN5XV.mjs +2 -0
  108. package/dist/chunk-763MN5XV.mjs.map +1 -0
  109. package/dist/chunk-CWKGR4AF.mjs +2 -0
  110. package/dist/chunk-CWKGR4AF.mjs.map +1 -0
  111. package/dist/chunk-DKI6BDWK.mjs +2 -0
  112. package/dist/chunk-DKI6BDWK.mjs.map +1 -0
  113. package/dist/chunk-SPLTJRHG.mjs +2 -0
  114. package/dist/chunk-SPLTJRHG.mjs.map +1 -0
  115. package/dist/chunk-T6IVHYQQ.mjs +2 -0
  116. package/dist/chunk-T6IVHYQQ.mjs.map +1 -0
  117. package/dist/chunk-T6YCHB3K.mjs +2 -0
  118. package/dist/chunk-T6YCHB3K.mjs.map +1 -0
  119. package/dist/chunk-WU6FFDBS.mjs +2 -0
  120. package/dist/chunk-WU6FFDBS.mjs.map +1 -0
  121. package/dist/index.d.mts +1 -624
  122. package/dist/index.d.ts +1 -624
  123. package/dist/index.js +2 -1
  124. package/dist/index.js.map +1 -1
  125. package/dist/index.mjs +2 -1
  126. package/dist/index.mjs.map +1 -1
  127. package/package.json +163 -1
@@ -0,0 +1,161 @@
1
+ import BaseModel, { BaseAttributes, BaseData } from './Base.js';
2
+ import { CurrencyCode, ISODateTime } from './Common.js';
3
+ import './Enum.js';
4
+
5
+ declare enum PaymentStatus {
6
+ PENDING = "PENDING",
7
+ AUTHORIZED = "AUTHORIZED",
8
+ CAPTURED = "CAPTURED",
9
+ FAILED = "FAILED",
10
+ REFUNDED = "REFUNDED",
11
+ PARTIALLY_REFUNDED = "PARTIALLY_REFUNDED"
12
+ }
13
+ declare enum PaymentMode {
14
+ PAY_LATER = "PAY_LATER",
15
+ CARD = "CARD",
16
+ CASH = "CASH",
17
+ NET_BANKING = "NET_BANKING",
18
+ WALLET = "WALLET",
19
+ COD = "COD",
20
+ UNKNOWN = "UNKNOWN"
21
+ }
22
+ /**
23
+ * Input attributes for creating or updating a PaymentModel.
24
+ */
25
+ type PaymentAttributes = BaseAttributes & {
26
+ txnId: string;
27
+ externalId?: string;
28
+ orderNumber: string;
29
+ customerId: string;
30
+ status: PaymentStatus;
31
+ subStatus?: string;
32
+ amount: number;
33
+ currency: CurrencyCode;
34
+ paymentMode: PaymentMode;
35
+ gatewayResponse?: string;
36
+ gatewayErrorCode?: string;
37
+ gatewayErrorMessage?: string;
38
+ amountRefunded?: number;
39
+ cardLast4?: string;
40
+ cardBrand?: string;
41
+ transactionAt: ISODateTime;
42
+ };
43
+ /**
44
+ * Output data structure for a PaymentModel.
45
+ * Excludes potentially large or sensitive fields by default.
46
+ */
47
+ type PaymentData = Omit<PaymentAttributes, 'gatewayResponse' | 'gatewayErrorMessage'> & BaseData;
48
+ /**
49
+ * Represents a payment transaction, attempt, or record associated with an order.
50
+ */
51
+ declare class PaymentModel extends BaseModel {
52
+ protected txnId: string;
53
+ protected externalId?: string;
54
+ protected orderNumber: string;
55
+ protected customerId: string;
56
+ protected status: PaymentStatus;
57
+ protected subStatus?: string;
58
+ protected amount: number;
59
+ protected currency: CurrencyCode;
60
+ protected paymentMode: PaymentMode;
61
+ protected gatewayResponse?: string;
62
+ protected gatewayErrorCode?: string;
63
+ protected gatewayErrorMessage?: string;
64
+ protected amountRefunded: number;
65
+ protected cardLast4?: string;
66
+ protected cardBrand?: string;
67
+ protected transactionAt: ISODateTime;
68
+ /**
69
+ * Creates an instance of PaymentModel.
70
+ * @param data - The initial payment attributes.
71
+ * @param date - Optional date object for setting creation/modification times (defaults to now).
72
+ */
73
+ constructor(data: PaymentAttributes, date?: Date);
74
+ /**
75
+ * Gets the primary transaction identifier.
76
+ * @returns The transaction ID string.
77
+ */
78
+ getTxnId(): string;
79
+ /**
80
+ * Gets the external identifier, often from a payment gateway.
81
+ * @returns The external ID string, or undefined if not set.
82
+ */
83
+ getExternalId(): string | undefined;
84
+ /**
85
+ * Gets the order number associated with this payment.
86
+ * @returns The order number string.
87
+ */
88
+ getOrderNumber(): string;
89
+ /**
90
+ * Gets the customer ID associated with this payment.
91
+ * @returns The customer ID string.
92
+ */
93
+ getCustomerId(): string;
94
+ /**
95
+ * Gets the current status of the payment (e.g., PENDING, CAPTURED).
96
+ * @returns The PaymentStatus enum value.
97
+ */
98
+ getStatus(): PaymentStatus;
99
+ /**
100
+ * Gets the detailed sub-status, often provided by the payment gateway.
101
+ * @returns The sub-status string, or undefined if not set.
102
+ */
103
+ getSubStatus(): string | undefined;
104
+ /**
105
+ * Gets the amount of the payment transaction.
106
+ * @returns The payment amount number.
107
+ */
108
+ getAmount(): number;
109
+ /**
110
+ * Gets the currency code for the payment amount.
111
+ * @returns The CurrencyCode enum value.
112
+ */
113
+ getCurrency(): CurrencyCode;
114
+ /**
115
+ * Gets the mode or method used for the payment (e.g., CARD, COD).
116
+ * @returns The PaymentMode enum value.
117
+ */
118
+ getPaymentMode(): PaymentMode;
119
+ /**
120
+ * Gets the raw response data from the payment gateway (potentially large).
121
+ * @returns The gateway response string, or undefined if not set.
122
+ */
123
+ getGatewayResponse(): string | undefined;
124
+ /**
125
+ * Gets the error code returned by the payment gateway, if any.
126
+ * @returns The gateway error code string, or undefined if no error occurred or wasn't recorded.
127
+ */
128
+ getGatewayErrorCode(): string | undefined;
129
+ /**
130
+ * Gets the error message returned by the payment gateway, if any.
131
+ * @returns The gateway error message string, or undefined if no error occurred or wasn't recorded.
132
+ */
133
+ getGatewayErrorMessage(): string | undefined;
134
+ /**
135
+ * Gets the total amount that has been refunded for this transaction.
136
+ * @returns The refunded amount number (defaults to 0).
137
+ */
138
+ getAmountRefunded(): number;
139
+ /**
140
+ * Gets the last 4 digits of the card used, if applicable.
141
+ * @returns The card's last 4 digits string, or undefined.
142
+ */
143
+ getCardLast4(): string | undefined;
144
+ /**
145
+ * Gets the brand of the card used (e.g., Visa, Mastercard), if applicable.
146
+ * @returns The card brand string, or undefined.
147
+ */
148
+ getCardBrand(): string | undefined;
149
+ /**
150
+ * Gets the timestamp when the transaction occurred or was recorded.
151
+ * @returns The transaction timestamp as an ISO 8601 string.
152
+ */
153
+ getTransactionAt(): ISODateTime;
154
+ /**
155
+ * Gets a plain data object representing the payment's current state.
156
+ * @returns PaymentData object suitable for serialization or API responses.
157
+ */
158
+ getDetails(): PaymentData;
159
+ }
160
+
161
+ export { type PaymentAttributes, type PaymentData, PaymentMode, PaymentStatus, PaymentModel as default };
@@ -0,0 +1,2 @@
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var i=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(t,r=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():r.toISOString(),this.modifiedAt=t.modifiedAt&&!isNaN(Date.parse(t.modifiedAt))?new Date(t.modifiedAt).toISOString():r.toISOString(),this.modifiedBy=t.modifiedBy??"";}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return this.modifiedBy}setModifiedBy(t){this.modifiedBy=t;}getCustomField(t){return this.customFields[t]??null}setCustomField(t,r){this.customFields[t]=r;}getAllCustomFields(){return {...this.customFields}}};var u=(s=>(s.PENDING="PENDING",s.AUTHORIZED="AUTHORIZED",s.CAPTURED="CAPTURED",s.FAILED="FAILED",s.REFUNDED="REFUNDED",s.PARTIALLY_REFUNDED="PARTIALLY_REFUNDED",s))(u||{}),a=(e=>(e.PAY_LATER="PAY_LATER",e.CARD="CARD",e.CASH="CASH",e.NET_BANKING="NET_BANKING",e.WALLET="WALLET",e.COD="COD",e.UNKNOWN="UNKNOWN",e))(a||{}),n=class extends i{txnId;externalId;orderNumber;customerId;status;subStatus;amount;currency;paymentMode;gatewayResponse;gatewayErrorCode;gatewayErrorMessage;amountRefunded;cardLast4;cardBrand;transactionAt;constructor(t,r=new Date){super(t,r),this.txnId=t.txnId,this.externalId=t.externalId,this.orderNumber=t.orderNumber,this.customerId=t.customerId,this.status=t.status,this.subStatus=t.subStatus,this.amount=t.amount,this.currency=t.currency,this.paymentMode=t.paymentMode,this.gatewayResponse=t.gatewayResponse,this.gatewayErrorCode=t.gatewayErrorCode,this.gatewayErrorMessage=t.gatewayErrorMessage,this.amountRefunded=t.amountRefunded||0,this.cardLast4=t.cardLast4,this.cardBrand=t.cardBrand,this.transactionAt=t.transactionAt;}getTxnId(){return this.txnId}getExternalId(){return this.externalId}getOrderNumber(){return this.orderNumber}getCustomerId(){return this.customerId}getStatus(){return this.status}getSubStatus(){return this.subStatus}getAmount(){return this.amount}getCurrency(){return this.currency}getPaymentMode(){return this.paymentMode}getGatewayResponse(){return this.gatewayResponse}getGatewayErrorCode(){return this.gatewayErrorCode}getGatewayErrorMessage(){return this.gatewayErrorMessage}getAmountRefunded(){return this.amountRefunded}getCardLast4(){return this.cardLast4}getCardBrand(){return this.cardBrand}getTransactionAt(){return this.transactionAt}getDetails(){return {...super.getDetails(),txnId:this.getTxnId(),externalId:this.getExternalId(),orderNumber:this.getOrderNumber(),customerId:this.getCustomerId(),status:this.getStatus(),subStatus:this.getSubStatus(),amount:this.getAmount(),currency:this.getCurrency(),paymentMode:this.getPaymentMode(),gatewayErrorCode:this.getGatewayErrorCode(),amountRefunded:this.getAmountRefunded(),cardLast4:this.getCardLast4(),cardBrand:this.getCardBrand(),transactionAt:this.getTransactionAt()}}};exports.PaymentMode=a;exports.PaymentStatus=u;exports.default=n;//# sourceMappingURL=Payment.js.map
2
+ //# sourceMappingURL=Payment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/Classes/Base.ts","../../src/Classes/Payment.ts"],"names":["BaseModel","data","date","modifiedBy","fieldName","value","PaymentStatus","PaymentMode","PaymentModel"],"mappings":"sEA0BA,IAAqBA,CAAAA,CAArB,KAA+B,CACnB,YACA,CAAA,OAAA,CACA,SACA,CAAA,UAAA,CACA,UAQV,CAAA,WAAA,CAAYC,CAAsBC,CAAAA,CAAAA,CAAa,IAAI,IAAA,CAAQ,CACzD,IAAK,CAAA,YAAA,CAAe,CAAE,GAAGD,CAAK,CAAA,YAAa,CAC3C,CAAA,IAAA,CAAK,OAAUA,CAAAA,CAAAA,CAAK,OAAW,EAAA,CAAA,CAC/B,IAAK,CAAA,SAAA,CA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AAA,WAAa,CAMzD,kBAAA,EAAyC,CAAE,OAAO,IAAA,CAAK,eAAiB,CAMxE,mBAA0C,EAAA,CAAE,OAAO,IAAA,CAAK,gBAAkB,CAM1E,sBAA6C,EAAA,CAAE,OAAO,IAAA,CAAK,mBAAqB,CAMhF,iBAAA,EAA4B,CAAE,OAAO,IAAK,CAAA,cAAgB,CAM1D,YAAA,EAAmC,CAAE,OAAO,IAAK,CAAA,SAAW,CAM5D,YAAA,EAAmC,CAAE,OAAO,IAAK,CAAA,SAAW,CAM5D,gBAAA,EAAgC,CAAE,OAAO,IAAK,CAAA,aAAe,CAOpE,UAAA,EAA0B,CAExB,OAAO,CACL,GAFkB,MAAM,UAAW,EAAA,CAGnC,KAAO,CAAA,IAAA,CAAK,QAAS,EAAA,CACrB,UAAY,CAAA,IAAA,CAAK,aAAc,EAAA,CAC/B,WAAa,CAAA,IAAA,CAAK,cAAe,EAAA,CACjC,UAAY,CAAA,IAAA,CAAK,aAAc,EAAA,CAC/B,MAAQ,CAAA,IAAA,CAAK,SAAU,EAAA,CACvB,SAAW,CAAA,IAAA,CAAK,YAAa,EAAA,CAC7B,MAAQ,CAAA,IAAA,CAAK,SAAU,EAAA,CACvB,SAAU,IAAK,CAAA,WAAA,EACf,CAAA,WAAA,CAAa,IAAK,CAAA,cAAA,EAClB,CAAA,gBAAA,CAAkB,IAAK,CAAA,mBAAA,EACvB,CAAA,cAAA,CAAgB,IAAK,CAAA,iBAAA,EACrB,CAAA,SAAA,CAAW,IAAK,CAAA,YAAA,EAChB,CAAA,SAAA,CAAW,IAAK,CAAA,YAAA,EAChB,CAAA,aAAA,CAAe,IAAK,CAAA,gBAAA,EACtB,CACF,CACF","file":"Payment.js","sourcesContent":["import { ISODateTime } from \"./Common\";\r\n\r\nexport interface CustomFields {\r\n [key: string]: any;\r\n}\r\n\r\nexport type BaseAttributes = {\r\n customFields?: CustomFields;\r\n version?: number;\r\n createdAt?: ISODateTime;\r\n modifiedAt?: ISODateTime;\r\n modifiedBy?: string;\r\n};\r\n\r\nexport type BaseData = {\r\n customFields: CustomFields;\r\n version: number;\r\n createdAt: ISODateTime;\r\n modifiedAt: ISODateTime;\r\n modifiedBy: string;\r\n};\r\n\r\n/**\r\n * Provides common foundational properties and methods for other data models.\r\n * Handles tracking of custom fields, versioning, and timestamps.\r\n */\r\nexport default class BaseModel {\r\n protected customFields: CustomFields;\r\n protected version: number;\r\n protected createdAt: ISODateTime;\r\n protected modifiedAt: ISODateTime;\r\n protected modifiedBy: string;\r\n\r\n /**\r\n * Creates an instance of BaseModel.\r\n * Initializes common properties like timestamps, version, and custom fields.\r\n * @param data - Optional initial attributes for the base model.\r\n * @param date - Optional date object to use for default timestamps (defaults to current time).\r\n */\r\n constructor(data: BaseAttributes, date: Date = new Date()) {\r\n this.customFields = { ...data.customFields };\r\n this.version = data.version ?? 1;\r\n this.createdAt = data.createdAt && !isNaN(Date.parse(data.createdAt))\r\n ?\r\n new Date(data.createdAt).toISOString()\r\n :\r\n date.toISOString();\r\n this.modifiedAt = data.modifiedAt && !isNaN(Date.parse(data.modifiedAt))\r\n ? new Date(data.modifiedAt).toISOString()\r\n : date.toISOString();\r\n\r\n this.modifiedBy = data.modifiedBy ?? '';\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the base model's current state.\r\n * @returns BaseData object containing common properties.\r\n */\r\n getDetails(): BaseData {\r\n return {\r\n customFields: this.getAllCustomFields(), // Use getter to return a copy\r\n version: this.getVersion(),\r\n createdAt: this.getCreatedAt(),\r\n modifiedAt: this.getModifiedAt(),\r\n modifiedBy: this.getModifiedBy(),\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current version number of the model instance.\r\n * @returns The version number.\r\n */\r\n getVersion(): number {\r\n return this.version;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as an ISO 8601 string.\r\n * @returns The creation timestamp string.\r\n */\r\n getCreatedAt(): string {\r\n return this.createdAt;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as a Unix epoch time (milliseconds).\r\n * @returns The creation time in milliseconds since the epoch.\r\n */\r\n getCreatedAtTime(): number {\r\n return new Date(this.createdAt).getTime();\r\n }\r\n\r\n\r\n /**\r\n * Gets the last modification timestamp as an ISO 8601 string.\r\n * @returns The last modification timestamp string.\r\n */\r\n getModifiedAt(): string {\r\n return this.modifiedAt;\r\n }\r\n\r\n /**\r\n * Gets the last modification timestamp as a Unix epoch time (milliseconds).\r\n * @returns The last modification time in milliseconds since the epoch.\r\n */\r\n getModifiedAtTime(): number {\r\n return new Date(this.modifiedAt).getTime();\r\n }\r\n\r\n /**\r\n * Gets the identifier of the user or process that last modified the instance.\r\n * @returns The modifier identifier string.\r\n */\r\n getModifiedBy(): string {\r\n return this.modifiedBy;\r\n }\r\n\r\n /**\r\n * Sets the identifier of the user or process that last modified the instance.\r\n * @param modifiedBy - The identifier string.\r\n */\r\n setModifiedBy(modifiedBy: string): void {\r\n this.modifiedBy = modifiedBy;\r\n }\r\n\r\n /**\r\n * Retrieves the value of a specific custom field.\r\n * @param fieldName - The name (key) of the custom field to retrieve.\r\n * @returns The value of the custom field, or null if the field does not exist.\r\n */\r\n getCustomField(fieldName: string): any {\r\n return this.customFields[fieldName] ?? null;\r\n }\r\n\r\n /**\r\n * Sets the value of a specific custom field.\r\n * Also updates the modification timestamp and increments the version.\r\n * @param fieldName - The name (key) of the custom field to set.\r\n * @param value - The value to assign to the custom field.\r\n */\r\n setCustomField(fieldName: string, value: any): void {\r\n this.customFields[fieldName] = value;\r\n }\r\n\r\n /**\r\n * Retrieves a shallow copy of all custom fields associated with the instance.\r\n * @returns An object containing all custom fields.\r\n */\r\n getAllCustomFields(): CustomFields {\r\n return { ...this.customFields };\r\n }\r\n}\r\n","import BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\nimport { CurrencyCode, ISODateTime } from \"./Common\";\r\n\r\nexport enum PaymentStatus {\r\n PENDING = \"PENDING\",\r\n AUTHORIZED = \"AUTHORIZED\",\r\n CAPTURED = \"CAPTURED\",\r\n FAILED = \"FAILED\",\r\n REFUNDED = \"REFUNDED\",\r\n PARTIALLY_REFUNDED = \"PARTIALLY_REFUNDED\",\r\n}\r\n\r\nexport enum PaymentMode {\r\n PAY_LATER = \"PAY_LATER\",\r\n CARD = \"CARD\",\r\n CASH = \"CASH\",\r\n NET_BANKING = \"NET_BANKING\",\r\n WALLET = \"WALLET\",\r\n COD = \"COD\",\r\n UNKNOWN = \"UNKNOWN\",\r\n}\r\n\r\n/**\r\n * Input attributes for creating or updating a PaymentModel.\r\n */\r\nexport type PaymentAttributes = BaseAttributes & {\r\n txnId: string;\r\n externalId?: string;\r\n orderNumber: string;\r\n customerId: string;\r\n status: PaymentStatus;\r\n subStatus?: string;\r\n amount: number;\r\n currency: CurrencyCode;\r\n paymentMode: PaymentMode;\r\n gatewayResponse?: string;\r\n gatewayErrorCode?: string;\r\n gatewayErrorMessage?: string;\r\n amountRefunded?: number;\r\n cardLast4?: string;\r\n cardBrand?: string;\r\n transactionAt: ISODateTime;\r\n};\r\n\r\n/**\r\n * Output data structure for a PaymentModel.\r\n * Excludes potentially large or sensitive fields by default.\r\n */\r\nexport type PaymentData = Omit<PaymentAttributes, 'gatewayResponse' | 'gatewayErrorMessage'> & BaseData\r\n\r\n/**\r\n * Represents a payment transaction, attempt, or record associated with an order.\r\n */\r\nexport default class PaymentModel extends BaseModel {\r\n protected txnId: string;\r\n protected externalId?: string;\r\n protected orderNumber: string;\r\n protected customerId: string;\r\n protected status: PaymentStatus;\r\n protected subStatus?: string;\r\n protected amount: number;\r\n protected currency: CurrencyCode;\r\n protected paymentMode: PaymentMode;\r\n protected gatewayResponse?: string;\r\n protected gatewayErrorCode?: string;\r\n protected gatewayErrorMessage?: string;\r\n protected amountRefunded: number;\r\n protected cardLast4?: string;\r\n protected cardBrand?: string;\r\n protected transactionAt: ISODateTime;\r\n\r\n /**\r\n * Creates an instance of PaymentModel.\r\n * @param data - The initial payment attributes.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: PaymentAttributes, date: Date = new Date()) {\r\n super(data, date); // Pass BaseAttributes to parent\r\n\r\n // Assign properties\r\n this.txnId = data.txnId;\r\n this.externalId = data.externalId;\r\n this.orderNumber = data.orderNumber;\r\n this.customerId = data.customerId;\r\n this.status = data.status;\r\n this.subStatus = data.subStatus;\r\n this.amount = data.amount;\r\n this.currency = data.currency;\r\n this.paymentMode = data.paymentMode;\r\n this.gatewayResponse = data.gatewayResponse;\r\n this.gatewayErrorCode = data.gatewayErrorCode;\r\n this.gatewayErrorMessage = data.gatewayErrorMessage;\r\n this.amountRefunded = data.amountRefunded || 0; // Default to 0 if undefined\r\n this.cardLast4 = data.cardLast4;\r\n this.cardBrand = data.cardBrand;\r\n this.transactionAt = data.transactionAt;\r\n }\r\n\r\n /**\r\n * Gets the primary transaction identifier.\r\n * @returns The transaction ID string.\r\n */\r\n public getTxnId(): string { return this.txnId; }\r\n\r\n /**\r\n * Gets the external identifier, often from a payment gateway.\r\n * @returns The external ID string, or undefined if not set.\r\n */\r\n public getExternalId(): string | undefined { return this.externalId; }\r\n\r\n /**\r\n * Gets the order number associated with this payment.\r\n * @returns The order number string.\r\n */\r\n public getOrderNumber(): string { return this.orderNumber; }\r\n\r\n /**\r\n * Gets the customer ID associated with this payment.\r\n * @returns The customer ID string.\r\n */\r\n public getCustomerId(): string { return this.customerId; }\r\n\r\n /**\r\n * Gets the current status of the payment (e.g., PENDING, CAPTURED).\r\n * @returns The PaymentStatus enum value.\r\n */\r\n public getStatus(): PaymentStatus { return this.status; }\r\n\r\n /**\r\n * Gets the detailed sub-status, often provided by the payment gateway.\r\n * @returns The sub-status string, or undefined if not set.\r\n */\r\n public getSubStatus(): string | undefined { return this.subStatus; }\r\n\r\n /**\r\n * Gets the amount of the payment transaction.\r\n * @returns The payment amount number.\r\n */\r\n public getAmount(): number { return this.amount; }\r\n\r\n /**\r\n * Gets the currency code for the payment amount.\r\n * @returns The CurrencyCode enum value.\r\n */\r\n public getCurrency(): CurrencyCode { return this.currency; }\r\n\r\n /**\r\n * Gets the mode or method used for the payment (e.g., CARD, COD).\r\n * @returns The PaymentMode enum value.\r\n */\r\n public getPaymentMode(): PaymentMode { return this.paymentMode; }\r\n\r\n /**\r\n * Gets the raw response data from the payment gateway (potentially large).\r\n * @returns The gateway response string, or undefined if not set.\r\n */\r\n public getGatewayResponse(): string | undefined { return this.gatewayResponse; }\r\n\r\n /**\r\n * Gets the error code returned by the payment gateway, if any.\r\n * @returns The gateway error code string, or undefined if no error occurred or wasn't recorded.\r\n */\r\n public getGatewayErrorCode(): string | undefined { return this.gatewayErrorCode; }\r\n\r\n /**\r\n * Gets the error message returned by the payment gateway, if any.\r\n * @returns The gateway error message string, or undefined if no error occurred or wasn't recorded.\r\n */\r\n public getGatewayErrorMessage(): string | undefined { return this.gatewayErrorMessage; }\r\n\r\n /**\r\n * Gets the total amount that has been refunded for this transaction.\r\n * @returns The refunded amount number (defaults to 0).\r\n */\r\n public getAmountRefunded(): number { return this.amountRefunded; }\r\n\r\n /**\r\n * Gets the last 4 digits of the card used, if applicable.\r\n * @returns The card's last 4 digits string, or undefined.\r\n */\r\n public getCardLast4(): string | undefined { return this.cardLast4; }\r\n\r\n /**\r\n * Gets the brand of the card used (e.g., Visa, Mastercard), if applicable.\r\n * @returns The card brand string, or undefined.\r\n */\r\n public getCardBrand(): string | undefined { return this.cardBrand; }\r\n\r\n /**\r\n * Gets the timestamp when the transaction occurred or was recorded.\r\n * @returns The transaction timestamp as an ISO 8601 string.\r\n */\r\n public getTransactionAt(): ISODateTime { return this.transactionAt; }\r\n\r\n\r\n /**\r\n * Gets a plain data object representing the payment's current state.\r\n * @returns PaymentData object suitable for serialization or API responses.\r\n */\r\n getDetails(): PaymentData {\r\n const baseDetails = super.getDetails();\r\n return {\r\n ...baseDetails,\r\n txnId: this.getTxnId(),\r\n externalId: this.getExternalId(),\r\n orderNumber: this.getOrderNumber(),\r\n customerId: this.getCustomerId(),\r\n status: this.getStatus(),\r\n subStatus: this.getSubStatus(),\r\n amount: this.getAmount(),\r\n currency: this.getCurrency(),\r\n paymentMode: this.getPaymentMode(),\r\n gatewayErrorCode: this.getGatewayErrorCode(),\r\n amountRefunded: this.getAmountRefunded(),\r\n cardLast4: this.getCardLast4(),\r\n cardBrand: this.getCardBrand(),\r\n transactionAt: this.getTransactionAt(),\r\n };\r\n }\r\n}\r\n"]}
@@ -0,0 +1,2 @@
1
+ import {a}from'../chunk-SPLTJRHG.mjs';var u=(r=>(r.PENDING="PENDING",r.AUTHORIZED="AUTHORIZED",r.CAPTURED="CAPTURED",r.FAILED="FAILED",r.REFUNDED="REFUNDED",r.PARTIALLY_REFUNDED="PARTIALLY_REFUNDED",r))(u||{}),i=(e=>(e.PAY_LATER="PAY_LATER",e.CARD="CARD",e.CASH="CASH",e.NET_BANKING="NET_BANKING",e.WALLET="WALLET",e.COD="COD",e.UNKNOWN="UNKNOWN",e))(i||{}),s=class extends a{txnId;externalId;orderNumber;customerId;status;subStatus;amount;currency;paymentMode;gatewayResponse;gatewayErrorCode;gatewayErrorMessage;amountRefunded;cardLast4;cardBrand;transactionAt;constructor(t,a=new Date){super(t,a),this.txnId=t.txnId,this.externalId=t.externalId,this.orderNumber=t.orderNumber,this.customerId=t.customerId,this.status=t.status,this.subStatus=t.subStatus,this.amount=t.amount,this.currency=t.currency,this.paymentMode=t.paymentMode,this.gatewayResponse=t.gatewayResponse,this.gatewayErrorCode=t.gatewayErrorCode,this.gatewayErrorMessage=t.gatewayErrorMessage,this.amountRefunded=t.amountRefunded||0,this.cardLast4=t.cardLast4,this.cardBrand=t.cardBrand,this.transactionAt=t.transactionAt;}getTxnId(){return this.txnId}getExternalId(){return this.externalId}getOrderNumber(){return this.orderNumber}getCustomerId(){return this.customerId}getStatus(){return this.status}getSubStatus(){return this.subStatus}getAmount(){return this.amount}getCurrency(){return this.currency}getPaymentMode(){return this.paymentMode}getGatewayResponse(){return this.gatewayResponse}getGatewayErrorCode(){return this.gatewayErrorCode}getGatewayErrorMessage(){return this.gatewayErrorMessage}getAmountRefunded(){return this.amountRefunded}getCardLast4(){return this.cardLast4}getCardBrand(){return this.cardBrand}getTransactionAt(){return this.transactionAt}getDetails(){return {...super.getDetails(),txnId:this.getTxnId(),externalId:this.getExternalId(),orderNumber:this.getOrderNumber(),customerId:this.getCustomerId(),status:this.getStatus(),subStatus:this.getSubStatus(),amount:this.getAmount(),currency:this.getCurrency(),paymentMode:this.getPaymentMode(),gatewayErrorCode:this.getGatewayErrorCode(),amountRefunded:this.getAmountRefunded(),cardLast4:this.getCardLast4(),cardBrand:this.getCardBrand(),transactionAt:this.getTransactionAt()}}};export{i as PaymentMode,u as PaymentStatus,s as default};//# sourceMappingURL=Payment.mjs.map
2
+ //# sourceMappingURL=Payment.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/Classes/Payment.ts"],"names":["PaymentStatus","PaymentMode","PaymentModel","BaseModel","data","date"],"mappings":"sCAGO,IAAKA,CACVA,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,CAAA,OAAU,CAAA,SAAA,CACVA,EAAA,UAAa,CAAA,YAAA,CACbA,CAAA,CAAA,QAAA,CAAW,WACXA,CAAA,CAAA,MAAA,CAAS,QACTA,CAAAA,CAAAA,CAAA,SAAW,UACXA,CAAAA,CAAAA,CAAA,kBAAqB,CAAA,oBAAA,CANXA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CASAC,CACVA,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,CAAA,UAAY,WACZA,CAAAA,CAAAA,CAAA,IAAO,CAAA,MAAA,CACPA,EAAA,IAAO,CAAA,MAAA,CACPA,CAAA,CAAA,WAAA,CAAc,cACdA,CAAA,CAAA,MAAA,CAAS,QACTA,CAAAA,CAAAA,CAAA,GAAM,CAAA,KAAA,CACNA,CAAA,CAAA,OAAA,CAAU,UAPAA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CAyCSC,CAArB,CAAA,cAA0CC,CAAU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","sourcesContent":["import BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\nimport { CurrencyCode, ISODateTime } from \"./Common\";\r\n\r\nexport enum PaymentStatus {\r\n PENDING = \"PENDING\",\r\n AUTHORIZED = \"AUTHORIZED\",\r\n CAPTURED = \"CAPTURED\",\r\n FAILED = \"FAILED\",\r\n REFUNDED = \"REFUNDED\",\r\n PARTIALLY_REFUNDED = \"PARTIALLY_REFUNDED\",\r\n}\r\n\r\nexport enum PaymentMode {\r\n PAY_LATER = \"PAY_LATER\",\r\n CARD = \"CARD\",\r\n CASH = \"CASH\",\r\n NET_BANKING = \"NET_BANKING\",\r\n WALLET = \"WALLET\",\r\n COD = \"COD\",\r\n UNKNOWN = \"UNKNOWN\",\r\n}\r\n\r\n/**\r\n * Input attributes for creating or updating a PaymentModel.\r\n */\r\nexport type PaymentAttributes = BaseAttributes & {\r\n txnId: string;\r\n externalId?: string;\r\n orderNumber: string;\r\n customerId: string;\r\n status: PaymentStatus;\r\n subStatus?: string;\r\n amount: number;\r\n currency: CurrencyCode;\r\n paymentMode: PaymentMode;\r\n gatewayResponse?: string;\r\n gatewayErrorCode?: string;\r\n gatewayErrorMessage?: string;\r\n amountRefunded?: number;\r\n cardLast4?: string;\r\n cardBrand?: string;\r\n transactionAt: ISODateTime;\r\n};\r\n\r\n/**\r\n * Output data structure for a PaymentModel.\r\n * Excludes potentially large or sensitive fields by default.\r\n */\r\nexport type PaymentData = Omit<PaymentAttributes, 'gatewayResponse' | 'gatewayErrorMessage'> & BaseData\r\n\r\n/**\r\n * Represents a payment transaction, attempt, or record associated with an order.\r\n */\r\nexport default class PaymentModel extends BaseModel {\r\n protected txnId: string;\r\n protected externalId?: string;\r\n protected orderNumber: string;\r\n protected customerId: string;\r\n protected status: PaymentStatus;\r\n protected subStatus?: string;\r\n protected amount: number;\r\n protected currency: CurrencyCode;\r\n protected paymentMode: PaymentMode;\r\n protected gatewayResponse?: string;\r\n protected gatewayErrorCode?: string;\r\n protected gatewayErrorMessage?: string;\r\n protected amountRefunded: number;\r\n protected cardLast4?: string;\r\n protected cardBrand?: string;\r\n protected transactionAt: ISODateTime;\r\n\r\n /**\r\n * Creates an instance of PaymentModel.\r\n * @param data - The initial payment attributes.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: PaymentAttributes, date: Date = new Date()) {\r\n super(data, date); // Pass BaseAttributes to parent\r\n\r\n // Assign properties\r\n this.txnId = data.txnId;\r\n this.externalId = data.externalId;\r\n this.orderNumber = data.orderNumber;\r\n this.customerId = data.customerId;\r\n this.status = data.status;\r\n this.subStatus = data.subStatus;\r\n this.amount = data.amount;\r\n this.currency = data.currency;\r\n this.paymentMode = data.paymentMode;\r\n this.gatewayResponse = data.gatewayResponse;\r\n this.gatewayErrorCode = data.gatewayErrorCode;\r\n this.gatewayErrorMessage = data.gatewayErrorMessage;\r\n this.amountRefunded = data.amountRefunded || 0; // Default to 0 if undefined\r\n this.cardLast4 = data.cardLast4;\r\n this.cardBrand = data.cardBrand;\r\n this.transactionAt = data.transactionAt;\r\n }\r\n\r\n /**\r\n * Gets the primary transaction identifier.\r\n * @returns The transaction ID string.\r\n */\r\n public getTxnId(): string { return this.txnId; }\r\n\r\n /**\r\n * Gets the external identifier, often from a payment gateway.\r\n * @returns The external ID string, or undefined if not set.\r\n */\r\n public getExternalId(): string | undefined { return this.externalId; }\r\n\r\n /**\r\n * Gets the order number associated with this payment.\r\n * @returns The order number string.\r\n */\r\n public getOrderNumber(): string { return this.orderNumber; }\r\n\r\n /**\r\n * Gets the customer ID associated with this payment.\r\n * @returns The customer ID string.\r\n */\r\n public getCustomerId(): string { return this.customerId; }\r\n\r\n /**\r\n * Gets the current status of the payment (e.g., PENDING, CAPTURED).\r\n * @returns The PaymentStatus enum value.\r\n */\r\n public getStatus(): PaymentStatus { return this.status; }\r\n\r\n /**\r\n * Gets the detailed sub-status, often provided by the payment gateway.\r\n * @returns The sub-status string, or undefined if not set.\r\n */\r\n public getSubStatus(): string | undefined { return this.subStatus; }\r\n\r\n /**\r\n * Gets the amount of the payment transaction.\r\n * @returns The payment amount number.\r\n */\r\n public getAmount(): number { return this.amount; }\r\n\r\n /**\r\n * Gets the currency code for the payment amount.\r\n * @returns The CurrencyCode enum value.\r\n */\r\n public getCurrency(): CurrencyCode { return this.currency; }\r\n\r\n /**\r\n * Gets the mode or method used for the payment (e.g., CARD, COD).\r\n * @returns The PaymentMode enum value.\r\n */\r\n public getPaymentMode(): PaymentMode { return this.paymentMode; }\r\n\r\n /**\r\n * Gets the raw response data from the payment gateway (potentially large).\r\n * @returns The gateway response string, or undefined if not set.\r\n */\r\n public getGatewayResponse(): string | undefined { return this.gatewayResponse; }\r\n\r\n /**\r\n * Gets the error code returned by the payment gateway, if any.\r\n * @returns The gateway error code string, or undefined if no error occurred or wasn't recorded.\r\n */\r\n public getGatewayErrorCode(): string | undefined { return this.gatewayErrorCode; }\r\n\r\n /**\r\n * Gets the error message returned by the payment gateway, if any.\r\n * @returns The gateway error message string, or undefined if no error occurred or wasn't recorded.\r\n */\r\n public getGatewayErrorMessage(): string | undefined { return this.gatewayErrorMessage; }\r\n\r\n /**\r\n * Gets the total amount that has been refunded for this transaction.\r\n * @returns The refunded amount number (defaults to 0).\r\n */\r\n public getAmountRefunded(): number { return this.amountRefunded; }\r\n\r\n /**\r\n * Gets the last 4 digits of the card used, if applicable.\r\n * @returns The card's last 4 digits string, or undefined.\r\n */\r\n public getCardLast4(): string | undefined { return this.cardLast4; }\r\n\r\n /**\r\n * Gets the brand of the card used (e.g., Visa, Mastercard), if applicable.\r\n * @returns The card brand string, or undefined.\r\n */\r\n public getCardBrand(): string | undefined { return this.cardBrand; }\r\n\r\n /**\r\n * Gets the timestamp when the transaction occurred or was recorded.\r\n * @returns The transaction timestamp as an ISO 8601 string.\r\n */\r\n public getTransactionAt(): ISODateTime { return this.transactionAt; }\r\n\r\n\r\n /**\r\n * Gets a plain data object representing the payment's current state.\r\n * @returns PaymentData object suitable for serialization or API responses.\r\n */\r\n getDetails(): PaymentData {\r\n const baseDetails = super.getDetails();\r\n return {\r\n ...baseDetails,\r\n txnId: this.getTxnId(),\r\n externalId: this.getExternalId(),\r\n orderNumber: this.getOrderNumber(),\r\n customerId: this.getCustomerId(),\r\n status: this.getStatus(),\r\n subStatus: this.getSubStatus(),\r\n amount: this.getAmount(),\r\n currency: this.getCurrency(),\r\n paymentMode: this.getPaymentMode(),\r\n gatewayErrorCode: this.getGatewayErrorCode(),\r\n amountRefunded: this.getAmountRefunded(),\r\n cardLast4: this.getCardLast4(),\r\n cardBrand: this.getCardBrand(),\r\n transactionAt: this.getTransactionAt(),\r\n };\r\n }\r\n}\r\n"]}
@@ -0,0 +1,70 @@
1
+ import { CountryCode, LocaleCode } from './Common.mjs';
2
+ import './Enum.mjs';
3
+
4
+ declare class PriceModel {
5
+ protected price: number;
6
+ protected country: CountryCode;
7
+ /**
8
+ * Creates an instance of PriceModel, storing the currency-correct rounded price.
9
+ * @param price - The initial price value.
10
+ * @param country - The country code used for rounding and determining the currency symbol.
11
+ * @throws {Error} If price is negative or country/currency mapping is missing.
12
+ */
13
+ constructor(price: number, country: CountryCode);
14
+ /**
15
+ * Gets the country code associated with this price instance.
16
+ * The country code is used for determining currency and formatting rules.
17
+ * @returns The CountryCode enum value.
18
+ */
19
+ getCountry(): CountryCode;
20
+ /**
21
+ * Gets the rounded price value based on standard currency rules.
22
+ * @returns The numeric price, rounded according to its currency's typical decimal places.
23
+ */
24
+ getRoundedPrice(): number;
25
+ /**
26
+ * Gets a locale-aware formatted display string for the price.
27
+ * Uses Intl.NumberFormat for accurate formatting based on locale and currency.
28
+ * @param locale - The locale code (e.g., 'en-US', 'de-DE', 'en-IN') to use for formatting rules.
29
+ * @param options - Configuration options for formatting.
30
+ * @param options.displayAsInteger - If true, the formatted string will show the price rounded to the nearest integer (no decimals). Defaults to false.
31
+ * @returns The formatted price string according to locale rules.
32
+ */
33
+ getFormattedString(locale: LocaleCode, options?: {
34
+ displayAsInteger?: boolean;
35
+ currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name';
36
+ }): string;
37
+ /**
38
+ * Helper method to determine standard decimal places for a currency.
39
+ * @param currency - The currency code.
40
+ * @returns The number of decimal places (0, 2, or 3 based on common rules).
41
+ */
42
+ private static getDecimalPlaces;
43
+ /**
44
+ * Adds basic thousand separators (commas) to a number string.
45
+ * Does not handle different locale separators (e.g., periods, spaces).
46
+ * @param numStr - The number string (potentially with decimals).
47
+ * @returns The number string with commas added.
48
+ */
49
+ private static addThousandSeparators;
50
+ /**
51
+ * Rounds a price value according to the standard decimal places
52
+ * for the currency associated with the given country.
53
+ *
54
+ * @param price - The price value to round. Must be a non-negative number.
55
+ * @param country - The country code to determine the currency and rounding rules.
56
+ * @returns The rounded price as a number.
57
+ * @throws {Error} If the country code is not found in the CountryCurrencyMap or price is negative.
58
+ */
59
+ static getRoundedPrice(price: number, country: CountryCode): number;
60
+ /**
61
+ * Static method to retrieve the currency code associated with a given country code.
62
+ * Uses the `CountryCurrencyMap` to find the corresponding currency.
63
+ *
64
+ * @param country - The country code (e.g., 'IN') for which to find the currency.
65
+ * @returns The currency code (e.g., 'INR') as a string, or undefined if the mapping doesn't exist.
66
+ */
67
+ static getCurrency(country: CountryCode): string;
68
+ }
69
+
70
+ export { PriceModel as default };
@@ -0,0 +1,70 @@
1
+ import { CountryCode, LocaleCode } from './Common.js';
2
+ import './Enum.js';
3
+
4
+ declare class PriceModel {
5
+ protected price: number;
6
+ protected country: CountryCode;
7
+ /**
8
+ * Creates an instance of PriceModel, storing the currency-correct rounded price.
9
+ * @param price - The initial price value.
10
+ * @param country - The country code used for rounding and determining the currency symbol.
11
+ * @throws {Error} If price is negative or country/currency mapping is missing.
12
+ */
13
+ constructor(price: number, country: CountryCode);
14
+ /**
15
+ * Gets the country code associated with this price instance.
16
+ * The country code is used for determining currency and formatting rules.
17
+ * @returns The CountryCode enum value.
18
+ */
19
+ getCountry(): CountryCode;
20
+ /**
21
+ * Gets the rounded price value based on standard currency rules.
22
+ * @returns The numeric price, rounded according to its currency's typical decimal places.
23
+ */
24
+ getRoundedPrice(): number;
25
+ /**
26
+ * Gets a locale-aware formatted display string for the price.
27
+ * Uses Intl.NumberFormat for accurate formatting based on locale and currency.
28
+ * @param locale - The locale code (e.g., 'en-US', 'de-DE', 'en-IN') to use for formatting rules.
29
+ * @param options - Configuration options for formatting.
30
+ * @param options.displayAsInteger - If true, the formatted string will show the price rounded to the nearest integer (no decimals). Defaults to false.
31
+ * @returns The formatted price string according to locale rules.
32
+ */
33
+ getFormattedString(locale: LocaleCode, options?: {
34
+ displayAsInteger?: boolean;
35
+ currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name';
36
+ }): string;
37
+ /**
38
+ * Helper method to determine standard decimal places for a currency.
39
+ * @param currency - The currency code.
40
+ * @returns The number of decimal places (0, 2, or 3 based on common rules).
41
+ */
42
+ private static getDecimalPlaces;
43
+ /**
44
+ * Adds basic thousand separators (commas) to a number string.
45
+ * Does not handle different locale separators (e.g., periods, spaces).
46
+ * @param numStr - The number string (potentially with decimals).
47
+ * @returns The number string with commas added.
48
+ */
49
+ private static addThousandSeparators;
50
+ /**
51
+ * Rounds a price value according to the standard decimal places
52
+ * for the currency associated with the given country.
53
+ *
54
+ * @param price - The price value to round. Must be a non-negative number.
55
+ * @param country - The country code to determine the currency and rounding rules.
56
+ * @returns The rounded price as a number.
57
+ * @throws {Error} If the country code is not found in the CountryCurrencyMap or price is negative.
58
+ */
59
+ static getRoundedPrice(price: number, country: CountryCode): number;
60
+ /**
61
+ * Static method to retrieve the currency code associated with a given country code.
62
+ * Uses the `CountryCurrencyMap` to find the corresponding currency.
63
+ *
64
+ * @param country - The country code (e.g., 'IN') for which to find the currency.
65
+ * @returns The currency code (e.g., 'INR') as a string, or undefined if the mapping doesn't exist.
66
+ */
67
+ static getCurrency(country: CountryCode): string;
68
+ }
69
+
70
+ export { PriceModel as default };
@@ -0,0 +1,2 @@
1
+ 'use strict';var i={IN:"INR"},s={INR:"\u20B9"};var a=class c{price;country;constructor(r,e){if(this.country=e,r<0)throw new Error("InvalidPrice: Price cannot be negative.");this.price=r;}getCountry(){return this.country}getRoundedPrice(){return c.getRoundedPrice(this.price,this.country)}getFormattedString(r,e={}){let o=e.displayAsInteger??!1,t=i[this.country];if(t===void 0)throw new Error("Currency mapping not found for CountryCode");let n=this.price,u=o?0:c.getDecimalPlaces(t),d={style:"currency",currency:t,signDisplay:"never",currencyDisplay:e.currencyDisplay,minimumFractionDigits:u,maximumFractionDigits:u};o&&(n=Math.round(n));try{return new Intl.NumberFormat(r,d).format(n)}catch(l){return console.error(`Error formatting price for locale "${r}" and currency "${t}":`,l),`${s[t]??t} ${c.addThousandSeparators(n.toFixed(u))}`}}static getDecimalPlaces(r){switch(r){case"INR":default:return 2}}static addThousandSeparators(r){let e=r.split("."),o=e[0],t=e.length>1?"."+e[1]:"";return o.replace(/\B(?=(\d{3})+(?!\d))/g,",")+t}static getRoundedPrice(r,e){if(r<0)throw new Error("Price cannot be negative for rounding.");let o=i[e];if(o===void 0)throw new Error(`Currency mapping not found for CountryCode: ${e}`);let t=c.getDecimalPlaces(o),n=Math.pow(10,t);return Math.round(r*n)/n}static getCurrency(r){return i[r]}};a.getRoundedPrice(-1,"IN");module.exports=a;//# sourceMappingURL=Price.js.map
2
+ //# sourceMappingURL=Price.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/Classes/Enum.ts","../../src/Classes/Price.ts"],"names":["CountryCurrencyMap","CurrencySymbolMap","PriceModel","_PriceModel","price","country","locale","options","displayAsInteger","currency","valueToFormat","fractionDigits","formattingOptions","error","numStr","parts","integerPart","decimalPart","decimalPlaces","multiplier"],"mappings":"aAkBO,IAAMA,CAAqB,CAAA,CAClB,EAAwB,CAAA,KACxC,CAEaC,CAAAA,CAAAA,CAAoB,CAC9B,GAAA,CAAiC,QACpC,CAAA,CCrBqBC,IAAAA,CAAAA,CAArB,MAAqBC,CAAW,CACpB,KAAA,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GxD,CASA,OAAO,WAAA,CAAYd,CAA8B,CAAA,CAC/C,OAAOL,CAAAA,CAAmBK,CAAO,CACnC,CAEF,EAEAH,CAAW,CAAA,eAAA,CAAgB,GAAI,IAAI,CAAA","file":"Price.js","sourcesContent":["/**\r\n * Represents the countries where the application operates or products are available.\r\n */\r\nexport enum OperationalCountry {\r\n /** India */ IN = 'IN',\r\n}\r\n \r\nexport enum OperationalCountryCurrency {\r\n /** India */ INR = 'INR',\r\n}\r\n\r\nexport enum OperationalLocale {\r\n /** India */ 'en-IN' = 'en-IN',\r\n}\r\n\r\n/**\r\n * Defines the supported ISO 4217 currency codes as an enumeration.\r\n */\r\nexport const CountryCurrencyMap = {\r\n /** India */ [OperationalCountry.IN]: OperationalCountryCurrency.INR,\r\n};\r\n\r\nexport const CurrencySymbolMap = {\r\n [OperationalCountryCurrency.INR]: '₹',\r\n}\r\n\r\n/**\r\n * Defines standard gender categories for product targeting.\r\n */\r\nexport enum GenderCategory {\r\n MALE = 'Male',\r\n FEMALE = 'Female',\r\n UNISEX = 'Unisex',\r\n KIDS = 'Kids',\r\n BOY = 'Boy',\r\n GIRL = 'Girl',\r\n}","import { CountryCode, CurrencyCode, LocaleCode } from \"./Common\"; // Assuming these are in Common.ts\r\nimport { CountryCurrencyMap, CurrencySymbolMap } from \"./Enum\"; // Ensure these maps exist\r\n\r\nexport default class PriceModel {\r\n protected price: number;\r\n protected country: CountryCode;\r\n\r\n /**\r\n * Creates an instance of PriceModel, storing the currency-correct rounded price.\r\n * @param price - The initial price value.\r\n * @param country - The country code used for rounding and determining the currency symbol.\r\n * @throws {Error} If price is negative or country/currency mapping is missing.\r\n */\r\n constructor(price: number, country: CountryCode) {\r\n this.country = country;\r\n\r\n if(price < 0) {\r\n throw new Error(\"InvalidPrice: Price cannot be negative.\");\r\n }\r\n\r\n this.price = price\r\n }\r\n\r\n /**\r\n * Gets the country code associated with this price instance.\r\n * The country code is used for determining currency and formatting rules.\r\n * @returns The CountryCode enum value.\r\n */\r\n public getCountry(): CountryCode {\r\n return this.country;\r\n }\r\n\r\n /**\r\n * Gets the rounded price value based on standard currency rules.\r\n * @returns The numeric price, rounded according to its currency's typical decimal places.\r\n */\r\n public getRoundedPrice(): number {\r\n return PriceModel.getRoundedPrice(this.price, this.country);\r\n }\r\n\r\n /**\r\n * Gets a locale-aware formatted display string for the price.\r\n * Uses Intl.NumberFormat for accurate formatting based on locale and currency.\r\n * @param locale - The locale code (e.g., 'en-US', 'de-DE', 'en-IN') to use for formatting rules.\r\n * @param options - Configuration options for formatting.\r\n * @param options.displayAsInteger - If true, the formatted string will show the price rounded to the nearest integer (no decimals). Defaults to false.\r\n * @returns The formatted price string according to locale rules.\r\n */\r\n public getFormattedString(locale: LocaleCode, options: { displayAsInteger?: boolean, currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name' } = {}): string {\r\n const displayAsInteger = options.displayAsInteger ?? false;\r\n const currency: CurrencyCode | undefined = CountryCurrencyMap[this.country];\r\n\r\n if (currency === undefined) {\r\n throw new Error('Currency mapping not found for CountryCode');\r\n }\r\n\r\n let valueToFormat = this.price;\r\n const fractionDigits = displayAsInteger ? 0 : PriceModel.getDecimalPlaces(currency);\r\n\r\n let formattingOptions: Intl.NumberFormatOptions = {\r\n style: 'currency',\r\n currency: currency,\r\n signDisplay: 'never',\r\n currencyDisplay: options.currencyDisplay,\r\n minimumFractionDigits: fractionDigits,\r\n maximumFractionDigits: fractionDigits,\r\n };\r\n\r\n if (displayAsInteger) {\r\n valueToFormat = Math.round(valueToFormat);\r\n }\r\n\r\n try {\r\n return new Intl.NumberFormat(locale, formattingOptions).format(valueToFormat);\r\n } catch (error) {\r\n console.error(`Error formatting price for locale \"${locale}\" and currency \"${currency}\":`, error);\r\n // Basic fallback without symbol if Intl fails completely\r\n return `${CurrencySymbolMap[currency] ?? currency} ${PriceModel.addThousandSeparators(valueToFormat.toFixed(fractionDigits))}`;\r\n }\r\n }\r\n\r\n /**\r\n * Helper method to determine standard decimal places for a currency.\r\n * @param currency - The currency code.\r\n * @returns The number of decimal places (0, 2, or 3 based on common rules).\r\n */\r\n private static getDecimalPlaces(currency: CurrencyCode): number {\r\n switch (currency) {\r\n case 'INR':\r\n default:\r\n return 2;\r\n }\r\n }\r\n\r\n /**\r\n * Adds basic thousand separators (commas) to a number string.\r\n * Does not handle different locale separators (e.g., periods, spaces).\r\n * @param numStr - The number string (potentially with decimals).\r\n * @returns The number string with commas added.\r\n */\r\n private static addThousandSeparators(numStr: string): string {\r\n const parts = numStr.split('.');\r\n const integerPart = parts[0];\r\n const decimalPart = parts.length > 1 ? '.' + parts[1] : '';\r\n\r\n const formattedInteger = integerPart.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',');\r\n return formattedInteger + decimalPart;\r\n }\r\n\r\n /**\r\n * Rounds a price value according to the standard decimal places\r\n * for the currency associated with the given country.\r\n *\r\n * @param price - The price value to round. Must be a non-negative number.\r\n * @param country - The country code to determine the currency and rounding rules.\r\n * @returns The rounded price as a number.\r\n * @throws {Error} If the country code is not found in the CountryCurrencyMap or price is negative.\r\n */\r\n static getRoundedPrice(price: number, country: CountryCode): number {\r\n if (price < 0) {\r\n throw new Error(\"Price cannot be negative for rounding.\");\r\n }\r\n\r\n const currency: CurrencyCode | undefined = CountryCurrencyMap[country];\r\n if (currency === undefined) {\r\n throw new Error(`Currency mapping not found for CountryCode: ${country}`);\r\n }\r\n\r\n const decimalPlaces = PriceModel.getDecimalPlaces(currency);\r\n const multiplier = Math.pow(10, decimalPlaces);\r\n const roundedValue = Math.round(price * multiplier) / multiplier;\r\n\r\n return roundedValue;\r\n }\r\n\r\n /**\r\n * Static method to retrieve the currency code associated with a given country code.\r\n * Uses the `CountryCurrencyMap` to find the corresponding currency.\r\n *\r\n * @param country - The country code (e.g., 'IN') for which to find the currency.\r\n * @returns The currency code (e.g., 'INR') as a string, or undefined if the mapping doesn't exist.\r\n */\r\n static getCurrency(country: CountryCode): string {\r\n return CountryCurrencyMap[country];\r\n }\r\n\r\n}\r\n\r\nPriceModel.getRoundedPrice(-1, 'IN')"]}
@@ -0,0 +1,2 @@
1
+ export{a as default}from'../chunk-763MN5XV.mjs';import'../chunk-65X54TKF.mjs';//# sourceMappingURL=Price.mjs.map
2
+ //# sourceMappingURL=Price.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"Price.mjs"}
@@ -0,0 +1,209 @@
1
+ import BaseModel, { BaseAttributes } from './Base.mjs';
2
+ import { LocalizedString, BasePriceList, PriceTierList, Color, LocaleCode, CountryCode } from './Common.mjs';
3
+ import { GenderCategory } from './Enum.mjs';
4
+ import ImageInfoModel, { ImageInfoData } from './ImageInfo.mjs';
5
+
6
+ type ProductVariantIdentifier = {
7
+ key: string;
8
+ variantId: string;
9
+ };
10
+ type ProductHashKey = {
11
+ id: string;
12
+ variantId: string;
13
+ };
14
+ type ProductAttributes = BaseAttributes & {
15
+ id: string;
16
+ key: string;
17
+ variantId: string;
18
+ name: LocalizedString;
19
+ description: LocalizedString;
20
+ slug: LocalizedString;
21
+ brand: string;
22
+ basePrices: BasePriceList;
23
+ priceTiers: PriceTierList;
24
+ attributes: {
25
+ color: Color;
26
+ sizes: string[];
27
+ };
28
+ primaryImage: ImageInfoData;
29
+ additionalImages?: ImageInfoData[];
30
+ isActive: boolean;
31
+ targetGender: GenderCategory;
32
+ categories: string[];
33
+ specifications: {
34
+ [locale: string]: {
35
+ [key: string]: string | string[];
36
+ };
37
+ };
38
+ searchTags?: string[];
39
+ };
40
+ type ProductData = Required<ProductAttributes>;
41
+ type ProductSpecification = {
42
+ [key: string]: string | string[];
43
+ };
44
+ type LocalizedProductSpecification = {
45
+ en: ProductSpecification;
46
+ } & {
47
+ [locale in LocaleCode]?: ProductSpecification;
48
+ };
49
+ declare class ProductModel extends BaseModel {
50
+ protected id: string;
51
+ protected key: string;
52
+ protected variantId: string;
53
+ protected name: LocalizedString;
54
+ protected description: LocalizedString;
55
+ protected slug: LocalizedString;
56
+ protected brand: string;
57
+ protected basePrices: BasePriceList;
58
+ protected priceTiers: PriceTierList;
59
+ protected attributes: {
60
+ color: Color;
61
+ sizes: string[];
62
+ };
63
+ protected primaryImage: ImageInfoModel;
64
+ protected additionalImages: ImageInfoModel[];
65
+ protected isActive: boolean;
66
+ protected targetGender: GenderCategory;
67
+ protected categories: string[];
68
+ protected specifications: LocalizedProductSpecification;
69
+ protected searchTags: string[];
70
+ static productKeyRegex: RegExp;
71
+ static variantIdRegex: RegExp;
72
+ /**
73
+ * Creates an instance of ProductModel.
74
+ * Initializes properties based on the provided data, creating copies where necessary.
75
+ * @param data - The initial product attributes.
76
+ * @param date - Optional date for setting creation/modification times (defaults to now).
77
+ */
78
+ constructor(data: ProductAttributes, date?: Date);
79
+ /**
80
+ * Gets the base Product ID.
81
+ * @returns Product ID.
82
+ */
83
+ getId(): string;
84
+ /**
85
+ * Gets the user-friendly product key.
86
+ * @returns Product Key.
87
+ */
88
+ getKey(): string;
89
+ /**
90
+ * Gets the specific Variant ID.
91
+ * @returns Variant ID.
92
+ */
93
+ getVariantId(): string;
94
+ /**
95
+ * Gets the full localized product name object.
96
+ * @returns A copy of the LocalizedString object for the name.
97
+ */
98
+ getName(): LocalizedString;
99
+ /**
100
+ * Gets the product name for a specific locale, falling back to English ('en').
101
+ * @param locale - The desired locale code.
102
+ * @returns The name string for the specified locale.
103
+ */
104
+ getName(locale: LocaleCode): string;
105
+ /**
106
+ * Gets the full localized product description object.
107
+ * @returns A copy of the LocalizedString object for the description.
108
+ */
109
+ getDescription(): LocalizedString;
110
+ /**
111
+ * Gets the product description for a specific locale, falling back to English ('en').
112
+ * @param locale - The desired locale code.
113
+ * @returns The description string for the specified locale.
114
+ */
115
+ getDescription(locale: LocaleCode): string;
116
+ /**
117
+ * Gets the full localized product slug object.
118
+ * @returns A copy of the LocalizedString object for the slug.
119
+ */
120
+ getSlug(): LocalizedString;
121
+ /**
122
+ * Gets the product slug for a specific locale, falling back to English ('en').
123
+ * @param locale - The desired locale code.
124
+ * @returns The slug string for the specified locale.
125
+ */
126
+ getSlug(locale: LocaleCode): string;
127
+ /**
128
+ * Gets the brand associated with the product.
129
+ * @returns The brand name string.
130
+ */
131
+ getBrand(): string;
132
+ /**
133
+ * Gets the list of base prices. Returns copies of the price objects.
134
+ * Optionally filters by country.
135
+ * @param country - Optional country code to filter prices for.
136
+ * @returns A list of base prices (or an empty list if none match).
137
+ */
138
+ getBasePrices(country?: CountryCode): BasePriceList;
139
+ /**
140
+ * Gets the list of quantity-based price tiers. Returns copies of the tier objects.
141
+ * Optionally filters by country.
142
+ * @param country - Optional country code to filter tiers for.
143
+ * @returns A list of price tiers (or an empty list if none match or none exist).
144
+ */
145
+ getPriceTiers(country?: CountryCode): PriceTierList;
146
+ /**
147
+ * Gets the variant-specific attributes (color, sizes). Returns copies.
148
+ * @returns Product Attributes.
149
+ */
150
+ getAttributes(): {
151
+ color: Color;
152
+ sizes: string[];
153
+ };
154
+ /**
155
+ * Gets details of product's primary image.
156
+ * @returns The ImageInfoModel instance for the primary image.
157
+ */
158
+ getPrimaryImage(): ImageInfoModel;
159
+ /**
160
+ * Gets the list of additional product images.
161
+ * @returns An array of ImageInfoModel instances.
162
+ */
163
+ getAdditionalImages(): ImageInfoModel[];
164
+ /**
165
+ * Checks if the product variant is active.
166
+ * @returns True if the product is active, false otherwise.
167
+ */
168
+ getIsActive(): boolean;
169
+ /**
170
+ * Gets the target gender category for the product.
171
+ * @returns The GenderCategory enum value.
172
+ */
173
+ getTargetGender(): GenderCategory;
174
+ /**
175
+ * Gets the list of categories the product belongs to. Returns a copy.
176
+ * @returns An array of category.
177
+ */
178
+ getCategories(): string[];
179
+ /**
180
+ * Gets the full localized product specifications object.
181
+ * @returns Product Specifications
182
+ */
183
+ getSpecifications(): LocalizedProductSpecification;
184
+ /**
185
+ * Gets the product specifications for a specific locale, falling back to English ('en').
186
+ * @param locale - The desired locale code.
187
+ * @returns The ProductSpecification object for the specified locale, or undefined if not found.
188
+ */
189
+ getSpecifications(locale: LocaleCode): ProductSpecification | undefined;
190
+ /**
191
+ * Gets the list of search tags. Returns a copy.
192
+ * @returns An array of search tags.
193
+ */
194
+ getSearchTags(): string[];
195
+ /**
196
+ *
197
+ * @returns ProductData
198
+ */
199
+ getDetails(): ProductData;
200
+ /**
201
+ * Calculates the maximum potential discount percentage for a given country
202
+ * based on the lowest price tier compared to the base price.
203
+ * @param country - The country code to calculate the discount for.
204
+ * @returns The maximum discount percentage (0-100), or 0 if calculation is not possible.
205
+ */
206
+ getMaxDiscountPercent(country: CountryCode): number;
207
+ }
208
+
209
+ export { type LocalizedProductSpecification, type ProductAttributes, type ProductData, type ProductHashKey, type ProductSpecification, type ProductVariantIdentifier, ProductModel as default };