mongoose-currency-convert 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +239 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +10 -0
- package/dist/plugin.js +113 -0
- package/dist/plugin.js.map +1 -0
- package/dist/types.d.ts +30 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/cache.d.ts +10 -0
- package/dist/utils/cache.js +37 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/helpers.d.ts +5 -0
- package/dist/utils/helpers.js +142 -0
- package/dist/utils/helpers.js.map +1 -0
- package/package.json +103 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mauro Cunsolo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# mongoose-currency-convert
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/mongoose-currency-convert)
|
|
4
|
+
[](https://github.com/maku85/mongoose-currency-convert/actions/workflows/release.yml)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
A lightweight Mongoose plugin for automatic currency conversion at save time - flexible, extensible, and service-agnostic.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Automatic currency conversion** for specified fields when saving documents or updating them.
|
|
12
|
+
- **Customizable exchange rate logic** via a user-provided function or extension plugin.
|
|
13
|
+
- **Support for nested paths and array elements** in documents (e.g. `items.0.price`).
|
|
14
|
+
- **Pluggable rounding function** (default: round to 2 decimals).
|
|
15
|
+
- **Simple in-memory cache** for exchange rates (optional).
|
|
16
|
+
- **Error handling and rollback** on conversion failure.
|
|
17
|
+
- **Fully tested** with high code coverage.
|
|
18
|
+
- **Compatible with ESM and CommonJS**.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npm install mongoose-currency-convert
|
|
24
|
+
# or
|
|
25
|
+
pnpm add mongoose-currency-convert
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import mongoose, { Schema } from 'mongoose';
|
|
32
|
+
import { currencyConversionPlugin } from 'mongoose-currency-convert';
|
|
33
|
+
|
|
34
|
+
const ProductSchema = new Schema({
|
|
35
|
+
price: {
|
|
36
|
+
amount: Number,
|
|
37
|
+
currency: String,
|
|
38
|
+
date: Date,
|
|
39
|
+
},
|
|
40
|
+
priceConversion: {
|
|
41
|
+
amount: Number,
|
|
42
|
+
currency: String,
|
|
43
|
+
date: Date,
|
|
44
|
+
},
|
|
45
|
+
items: [
|
|
46
|
+
{
|
|
47
|
+
price: Number,
|
|
48
|
+
currency: String,
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
ProductSchema.plugin(currencyConversionPlugin, {
|
|
54
|
+
fields: [
|
|
55
|
+
{
|
|
56
|
+
sourcePath: 'price.amount',
|
|
57
|
+
currencyPath: 'price.currency',
|
|
58
|
+
datePath: 'price.date',
|
|
59
|
+
targetPath: 'priceConversion',
|
|
60
|
+
toCurrency: 'EUR',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
sourcePath: 'items.0.price',
|
|
64
|
+
currencyPath: 'items.0.currency',
|
|
65
|
+
targetPath: 'items.0.converted',
|
|
66
|
+
toCurrency: 'EUR',
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
getRate: async (from, to, date) => {
|
|
70
|
+
// Implement your logic to fetch the exchange rate
|
|
71
|
+
return 0.85; // Example: USD → EUR
|
|
72
|
+
},
|
|
73
|
+
// Optional: custom rounding function
|
|
74
|
+
round: (value) => Math.round(value * 100) / 100,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const Product = mongoose.model('Product', ProductSchema);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Supported Mongoose Operations
|
|
81
|
+
|
|
82
|
+
- `save`
|
|
83
|
+
- `updateOne`
|
|
84
|
+
- `findOneAndUpdate`
|
|
85
|
+
|
|
86
|
+
Currency conversion is automatically applied when saving or updating documents using these operations.
|
|
87
|
+
|
|
88
|
+
## Plugin Options
|
|
89
|
+
|
|
90
|
+
- `fields`: Array of field mapping objects:
|
|
91
|
+
- `sourcePath`: Path to the source amount (supports nested and array paths).
|
|
92
|
+
- `currencyPath`: Path to the source currency.
|
|
93
|
+
- `datePath` (optional): Path to the date for conversion.
|
|
94
|
+
- `targetPath`: Path to write the converted value.
|
|
95
|
+
- `toCurrency`: Target currency code.
|
|
96
|
+
- `getRate(from: string, to: string, date: Date)`: Async function returning the exchange rate.
|
|
97
|
+
- `round(value: number)`: Optional rounding function.
|
|
98
|
+
- `allowedCurrencyCodes`: Optional array of allowed currency codes (ISO 4217).
|
|
99
|
+
- `onError(ctx)`: Optional callback called when a conversion error occurs. Receives an object with details.
|
|
100
|
+
- `fallbackRate`: Optional fallback rate if the conversion rate is invalid or missing.
|
|
101
|
+
- `rollbackOnError`: Optional boolean. If true, revokes all conversions made if there's an error.
|
|
102
|
+
- `cache`: Optional cache object for exchange rates (see `SimpleCache`).
|
|
103
|
+
- `dateTransform(date: Date)`: Optional function to transform the conversion date.
|
|
104
|
+
|
|
105
|
+
## Caching Exchange Rates
|
|
106
|
+
|
|
107
|
+
You can use the built-in in-memory cache (`SimpleCache` in `src/utils/cache.ts`) or provide your own cache implementation (e.g. backed by Redis, Memcached, etc.).
|
|
108
|
+
|
|
109
|
+
### Using the Internal SimpleCache
|
|
110
|
+
```ts
|
|
111
|
+
import { SimpleCache } from 'mongoose-currency-convert';
|
|
112
|
+
|
|
113
|
+
const cache = new SimpleCache();
|
|
114
|
+
|
|
115
|
+
ProductSchema.plugin(currencyConversionPlugin, {
|
|
116
|
+
fields: [/* ... */],
|
|
117
|
+
getRate: async (from, to, date) => { /* ... */ },
|
|
118
|
+
cache,
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Using an External Cache (e.g. Redis)
|
|
123
|
+
You can implement the `CurrencyRateCache` interface to use any external service:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { createClient } from 'redis';
|
|
127
|
+
import type { CurrencyRateCache } from 'mongoose-currency-convert';
|
|
128
|
+
|
|
129
|
+
class RedisCache implements CurrencyRateCache<number> {
|
|
130
|
+
private client = createClient({ url: 'redis://localhost:6379' });
|
|
131
|
+
constructor() { this.client.connect(); }
|
|
132
|
+
|
|
133
|
+
async get(key: string): Promise<number | undefined> {
|
|
134
|
+
const value = await this.client.get(key);
|
|
135
|
+
return value ? Number(value) : undefined;
|
|
136
|
+
}
|
|
137
|
+
async set(key: string, value: number): Promise<void> {
|
|
138
|
+
await this.client.set(key, value.toString(), { EX: 86400 }); // 1 day expiry
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const cache = new RedisCache();
|
|
143
|
+
|
|
144
|
+
ProductSchema.plugin(currencyConversionPlugin, {
|
|
145
|
+
fields: [/* ... */],
|
|
146
|
+
getRate: async (from, to, date) => { /* ... */ },
|
|
147
|
+
cache,
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Error Handling Example
|
|
152
|
+
|
|
153
|
+
You can handle conversion errors using the `onError` callback:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
ProductSchema.plugin(currencyConversionPlugin, {
|
|
157
|
+
fields: [/* ... */],
|
|
158
|
+
getRate: async () => { throw new Error('rate error'); },
|
|
159
|
+
onError: (ctx) => {
|
|
160
|
+
console.error('Conversion error:', ctx);
|
|
161
|
+
},
|
|
162
|
+
rollbackOnError: true,
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## TypeScript Support
|
|
167
|
+
|
|
168
|
+
- Fully typed, with exported types for plugin options and error context.
|
|
169
|
+
- Example:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import type { CurrencyPluginOptions, CurrencyPluginErrorContext } from 'mongoose-currency-convert';
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Extension Plugins (e.g. BCE)
|
|
176
|
+
|
|
177
|
+
You can use or create extension plugins that provide a ready-to-use `getRate` function for external services (e.g. European Central Bank, exchangerate.host, etc.).
|
|
178
|
+
|
|
179
|
+
| Package | Description |
|
|
180
|
+
|---------|-------------|
|
|
181
|
+
| `mongoose-currency-converter-bce` | BCE provider for automatic exchange rate lookup. |
|
|
182
|
+
|
|
183
|
+
### How to Create Your Own Extension Plugin
|
|
184
|
+
|
|
185
|
+
1. Import the types from the base plugin:
|
|
186
|
+
```ts
|
|
187
|
+
import type { GetRateFn } from 'mongoose-currency-convert';
|
|
188
|
+
```
|
|
189
|
+
2. Implement a factory function that returns a `getRate` function:
|
|
190
|
+
```ts
|
|
191
|
+
export function createMyGetRate(): GetRateFn {
|
|
192
|
+
return async function getRate(from, to, date) {
|
|
193
|
+
// Fetch rate from your service
|
|
194
|
+
// Return the rate
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
3. Use your plugin in the base plugin configuration:
|
|
199
|
+
```ts
|
|
200
|
+
ProductSchema.plugin(currencyConversionPlugin, {
|
|
201
|
+
fields: [/* ... */],
|
|
202
|
+
getRate: createMyGetRate(),
|
|
203
|
+
cache,
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
> **Note:** The cache is managed by the base plugin. Extension plugins should not read or write to the cache directly; they only fetch rates from external services.
|
|
208
|
+
|
|
209
|
+
## Limitations & Known Issues
|
|
210
|
+
|
|
211
|
+
- Only `save`, `updateOne`, and `findOneAndUpdate` are supported for automatic conversion.
|
|
212
|
+
- Array paths are supported, but deep array updates (e.g. `items.$.price`) may require manual handling.
|
|
213
|
+
- Only `$set` and direct field updates are converted in update operations; other MongoDB operators (`$inc`, `$push`, etc.) are not automatically converted.
|
|
214
|
+
- The list of supported currency codes is static (ISO 4217).
|
|
215
|
+
- If you use custom cache, ensure it implements the required interface.
|
|
216
|
+
|
|
217
|
+
## Compatibility
|
|
218
|
+
|
|
219
|
+
- Node.js >= 18.x
|
|
220
|
+
- Mongoose >= 7.x
|
|
221
|
+
- TypeScript >= 5.x (optional)
|
|
222
|
+
|
|
223
|
+
## Contributing
|
|
224
|
+
|
|
225
|
+
Contributions are welcome! To contribute:
|
|
226
|
+
- Fork the repository and create a new branch.
|
|
227
|
+
- Submit a pull request with a clear description of your changes.
|
|
228
|
+
- Follow the coding style and add tests for new features or bug fixes.
|
|
229
|
+
- For major changes, open an issue first to discuss your idea.
|
|
230
|
+
|
|
231
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for more details (if available).
|
|
232
|
+
|
|
233
|
+
## Changelog
|
|
234
|
+
|
|
235
|
+
See [CHANGELOG.md](CHANGELOG.md) for a list of changes and release history.
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
MIT
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./plugin"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Schema } from "mongoose";
|
|
2
|
+
import type { CurrencyPluginErrorContext, CurrencyPluginOptions, CurrencyRateCache } from "./types";
|
|
3
|
+
export declare function currencyConversionPlugin(schema: Schema, options: CurrencyPluginOptions & {
|
|
4
|
+
allowedCurrencyCodes?: string[];
|
|
5
|
+
onError?: (ctx: CurrencyPluginErrorContext) => void;
|
|
6
|
+
fallbackRate?: number;
|
|
7
|
+
rollbackOnError?: boolean;
|
|
8
|
+
cache?: CurrencyRateCache<number>;
|
|
9
|
+
dateTransform?: (date: Date) => Date;
|
|
10
|
+
}): void;
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.currencyConversionPlugin = currencyConversionPlugin;
|
|
4
|
+
const helpers_1 = require("./utils/helpers");
|
|
5
|
+
function currencyConversionPlugin(schema, options) {
|
|
6
|
+
const { fields, getRate, round = helpers_1.defaultRound, allowedCurrencyCodes, onError, fallbackRate, rollbackOnError, cache, dateTransform, } = options;
|
|
7
|
+
if (!fields || !Array.isArray(fields) || fields.length === 0) {
|
|
8
|
+
throw new Error('[mongoose-currency-convert] option "fields" must be a non-empty array');
|
|
9
|
+
}
|
|
10
|
+
if (typeof getRate !== "function") {
|
|
11
|
+
throw new Error('[mongoose-currency-convert] option "getRate" must be a function');
|
|
12
|
+
}
|
|
13
|
+
async function applyCurrencyConversion(doc) {
|
|
14
|
+
const convertedFields = [];
|
|
15
|
+
for (const field of fields) {
|
|
16
|
+
const { sourcePath, currencyPath, datePath, targetPath, toCurrency } = field;
|
|
17
|
+
const amount = (0, helpers_1.getNestedValue)(doc, sourcePath);
|
|
18
|
+
const fromCurrency = (0, helpers_1.getNestedValue)(doc, currencyPath);
|
|
19
|
+
if (amount == null || typeof fromCurrency !== "string" || !fromCurrency)
|
|
20
|
+
continue;
|
|
21
|
+
if (!(0, helpers_1.isValidCurrencyCode)(fromCurrency, allowedCurrencyCodes)) {
|
|
22
|
+
console.warn(`[mongoose-currency-convert] Invalid source currency code: ${fromCurrency}`);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (!(0, helpers_1.isValidCurrencyCode)(toCurrency, allowedCurrencyCodes)) {
|
|
26
|
+
console.warn(`[mongoose-currency-convert] Invalid target currency code: ${toCurrency}`);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const dateValue = datePath ? (0, helpers_1.getNestedValue)(doc, datePath) : undefined;
|
|
30
|
+
let conversionDate = dateValue &&
|
|
31
|
+
(typeof dateValue === "string" ||
|
|
32
|
+
typeof dateValue === "number" ||
|
|
33
|
+
dateValue instanceof Date)
|
|
34
|
+
? new Date(dateValue)
|
|
35
|
+
: new Date();
|
|
36
|
+
if (dateTransform)
|
|
37
|
+
conversionDate = dateTransform(conversionDate);
|
|
38
|
+
let rate;
|
|
39
|
+
const cacheKey = `${fromCurrency}_${toCurrency}_${conversionDate.toISOString().slice(0, 10)}`;
|
|
40
|
+
try {
|
|
41
|
+
if (cache)
|
|
42
|
+
rate = await cache.get(cacheKey);
|
|
43
|
+
if (rate === undefined) {
|
|
44
|
+
rate = await getRate(fromCurrency, toCurrency, conversionDate);
|
|
45
|
+
if (cache && rate !== undefined && !Number.isNaN(rate)) {
|
|
46
|
+
await cache.set(cacheKey, rate);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!rate || Number.isNaN(rate)) {
|
|
50
|
+
if (typeof fallbackRate === "number") {
|
|
51
|
+
rate = fallbackRate;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
throw new Error("Invalid rate");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const convertedValue = {
|
|
58
|
+
amount: round(Number(amount) * rate),
|
|
59
|
+
currency: toCurrency,
|
|
60
|
+
date: conversionDate,
|
|
61
|
+
};
|
|
62
|
+
(0, helpers_1.setNestedValue)(doc, targetPath, convertedValue);
|
|
63
|
+
convertedFields.push(targetPath);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
if (onError) {
|
|
67
|
+
onError({
|
|
68
|
+
field: sourcePath,
|
|
69
|
+
fromCurrency: fromCurrency,
|
|
70
|
+
toCurrency,
|
|
71
|
+
date: conversionDate,
|
|
72
|
+
error: err,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
console.error(`[mongoose-currency-convert] Error converting ${sourcePath}:`, err);
|
|
77
|
+
}
|
|
78
|
+
if (rollbackOnError) {
|
|
79
|
+
for (const path of convertedFields) {
|
|
80
|
+
(0, helpers_1.setNestedValue)(doc, path, undefined);
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
schema.pre("save", async function () {
|
|
88
|
+
const doc = this.toObject({ depopulate: true });
|
|
89
|
+
await applyCurrencyConversion(doc);
|
|
90
|
+
Object.assign(this, doc);
|
|
91
|
+
});
|
|
92
|
+
async function handleUpdateMiddleware(next) {
|
|
93
|
+
const update = this.getUpdate();
|
|
94
|
+
if (!update)
|
|
95
|
+
return next();
|
|
96
|
+
const updateAny = update;
|
|
97
|
+
let doc;
|
|
98
|
+
if (typeof updateAny.$set === "object" && updateAny.$set !== null) {
|
|
99
|
+
doc = { ...updateAny.$set };
|
|
100
|
+
await applyCurrencyConversion(doc);
|
|
101
|
+
updateAny.$set = doc;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
doc = { ...updateAny };
|
|
105
|
+
await applyCurrencyConversion(doc);
|
|
106
|
+
Object.assign(updateAny, doc);
|
|
107
|
+
}
|
|
108
|
+
next();
|
|
109
|
+
}
|
|
110
|
+
schema.pre("findOneAndUpdate", handleUpdateMiddleware);
|
|
111
|
+
schema.pre("updateOne", handleUpdateMiddleware);
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0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M,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,KAAK,UAAU,sBAAsB,CAEnC,IAAgB;QAEhB,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,EAAE,CAAC;QAE3B,MAAM,SAAS,GAAG,MAAiC,CAAC;QACpD,IAAI,GAA4B,CAAC;QACjC,IAAI,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAClE,GAAG,GAAG,EAAE,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;YAC5B,MAAM,uBAAuB,CAAC,GAAG,CAAC,CAAC;YACnC,SAAS,CAAC,IAAI,GAAG,GAAG,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,GAAG,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC;YACvB,MAAM,uBAAuB,CAAC,GAAG,CAAC,CAAC;YACnC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;QAChC,CAAC;QACD,IAAI,EAAE,CAAC;IACT,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE,sBAAsB,CAAC,CAAC;IACvD,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAC;AAClD,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface CurrencyFieldConfig {
|
|
2
|
+
sourcePath: string;
|
|
3
|
+
currencyPath: string;
|
|
4
|
+
datePath?: string;
|
|
5
|
+
targetPath: string;
|
|
6
|
+
toCurrency: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CurrencyPluginOptions {
|
|
9
|
+
fields: CurrencyFieldConfig[];
|
|
10
|
+
getRate: (from: string, to: string, date?: Date) => Promise<number>;
|
|
11
|
+
round?: (value: number) => number;
|
|
12
|
+
}
|
|
13
|
+
export interface CurrencyPluginErrorContext {
|
|
14
|
+
field: string;
|
|
15
|
+
fromCurrency: string;
|
|
16
|
+
toCurrency: string;
|
|
17
|
+
date: Date;
|
|
18
|
+
error: unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface CurrencyRateCache<T = unknown> {
|
|
21
|
+
get(key: string): Promise<T | undefined> | T | undefined;
|
|
22
|
+
set(key: string, value: T): Promise<void> | void;
|
|
23
|
+
delete?(key: string): Promise<void> | void;
|
|
24
|
+
clear?(): Promise<void> | void;
|
|
25
|
+
}
|
|
26
|
+
export interface CacheEntry<T> {
|
|
27
|
+
value: T;
|
|
28
|
+
expiresAt: number;
|
|
29
|
+
}
|
|
30
|
+
export type GetRateFn = (from: string, to: string, date?: Date) => Promise<number>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleCache = void 0;
|
|
4
|
+
class SimpleCache {
|
|
5
|
+
store = new Map();
|
|
6
|
+
ttl;
|
|
7
|
+
constructor(ttlMinutes = 60) {
|
|
8
|
+
this.ttl = ttlMinutes * 60 * 1000;
|
|
9
|
+
}
|
|
10
|
+
isExpired(entry) {
|
|
11
|
+
return Date.now() > entry.expiresAt;
|
|
12
|
+
}
|
|
13
|
+
get(key) {
|
|
14
|
+
const entry = this.store.get(key);
|
|
15
|
+
if (!entry)
|
|
16
|
+
return undefined;
|
|
17
|
+
if (this.isExpired(entry)) {
|
|
18
|
+
this.store.delete(key);
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return entry.value;
|
|
22
|
+
}
|
|
23
|
+
set(key, value) {
|
|
24
|
+
this.store.set(key, {
|
|
25
|
+
value,
|
|
26
|
+
expiresAt: Date.now() + this.ttl,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
delete(key) {
|
|
30
|
+
this.store.delete(key);
|
|
31
|
+
}
|
|
32
|
+
clear() {
|
|
33
|
+
this.store.clear();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.SimpleCache = SimpleCache;
|
|
37
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/utils/cache.ts"],"names":[],"mappings":";;;AAEA,MAAa,WAAW;IACd,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;IACzC,GAAG,CAAS;IAEpB,YAAY,aAAqB,EAAE;QACjC,IAAI,CAAC,GAAG,GAAG,UAAU,GAAG,EAAE,GAAG,IAAI,CAAC;IACpC,CAAC;IAEO,SAAS,CAAC,KAAoB;QACpC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC;IACtC,CAAC;IAED,GAAG,CAAC,GAAW;QACb,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC;QAE7B,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACvB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;YAClB,KAAK;YACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG;SACjC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF;AAtCD,kCAsCC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function getPathArray(path: string): string[];
|
|
2
|
+
export declare function getNestedValue(obj: unknown, path: string | string[]): unknown;
|
|
3
|
+
export declare function setNestedValue(obj: unknown, path: string | string[], value: unknown): void;
|
|
4
|
+
export declare function defaultRound(value: number): number;
|
|
5
|
+
export declare function isValidCurrencyCode(code: string, allowedCodes?: string[]): boolean;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPathArray = getPathArray;
|
|
4
|
+
exports.getNestedValue = getNestedValue;
|
|
5
|
+
exports.setNestedValue = setNestedValue;
|
|
6
|
+
exports.defaultRound = defaultRound;
|
|
7
|
+
exports.isValidCurrencyCode = isValidCurrencyCode;
|
|
8
|
+
const ISO_4217_CODES = [
|
|
9
|
+
"USD",
|
|
10
|
+
"EUR",
|
|
11
|
+
"GBP",
|
|
12
|
+
"JPY",
|
|
13
|
+
"CHF",
|
|
14
|
+
"CAD",
|
|
15
|
+
"AUD",
|
|
16
|
+
"NZD",
|
|
17
|
+
"CNY",
|
|
18
|
+
"SEK",
|
|
19
|
+
"NOK",
|
|
20
|
+
"DKK",
|
|
21
|
+
"RUB",
|
|
22
|
+
"INR",
|
|
23
|
+
"BRL",
|
|
24
|
+
"ZAR",
|
|
25
|
+
"SGD",
|
|
26
|
+
"HKD",
|
|
27
|
+
"MXN",
|
|
28
|
+
"KRW",
|
|
29
|
+
"TRY",
|
|
30
|
+
"PLN",
|
|
31
|
+
"CZK",
|
|
32
|
+
"HUF",
|
|
33
|
+
"ILS",
|
|
34
|
+
"THB",
|
|
35
|
+
"MYR",
|
|
36
|
+
"IDR",
|
|
37
|
+
"PHP",
|
|
38
|
+
"TWD",
|
|
39
|
+
"SAR",
|
|
40
|
+
"AED",
|
|
41
|
+
"COP",
|
|
42
|
+
"CLP",
|
|
43
|
+
"PEN",
|
|
44
|
+
"ARS",
|
|
45
|
+
"VND",
|
|
46
|
+
"EGP",
|
|
47
|
+
"UAH",
|
|
48
|
+
"QAR",
|
|
49
|
+
"KZT",
|
|
50
|
+
"BGN",
|
|
51
|
+
"RON",
|
|
52
|
+
"HRK",
|
|
53
|
+
"ISK",
|
|
54
|
+
"LTL",
|
|
55
|
+
"LVL",
|
|
56
|
+
"EEK",
|
|
57
|
+
"SKK",
|
|
58
|
+
"YER",
|
|
59
|
+
"OMR",
|
|
60
|
+
"BHD",
|
|
61
|
+
"JOD",
|
|
62
|
+
"LBP",
|
|
63
|
+
"KWD",
|
|
64
|
+
"MAD",
|
|
65
|
+
"DZD",
|
|
66
|
+
"TND",
|
|
67
|
+
"LYD",
|
|
68
|
+
"SDG",
|
|
69
|
+
"IQD",
|
|
70
|
+
"SYP",
|
|
71
|
+
"MRO",
|
|
72
|
+
"CVE",
|
|
73
|
+
"GMD",
|
|
74
|
+
"GNF",
|
|
75
|
+
"SLL",
|
|
76
|
+
"XOF",
|
|
77
|
+
"XAF",
|
|
78
|
+
"XPF",
|
|
79
|
+
"XCD",
|
|
80
|
+
"XDR",
|
|
81
|
+
"XUA",
|
|
82
|
+
"XSU",
|
|
83
|
+
"XTS",
|
|
84
|
+
"XXX",
|
|
85
|
+
];
|
|
86
|
+
const pathCache = new Map();
|
|
87
|
+
function getPathArray(path) {
|
|
88
|
+
if (pathCache.has(path)) {
|
|
89
|
+
const cached = pathCache.get(path);
|
|
90
|
+
if (cached)
|
|
91
|
+
return [...cached];
|
|
92
|
+
}
|
|
93
|
+
const arr = path.split(".");
|
|
94
|
+
pathCache.set(path, arr);
|
|
95
|
+
return [...arr];
|
|
96
|
+
}
|
|
97
|
+
function getNestedValue(obj, path) {
|
|
98
|
+
const keys = Array.isArray(path) ? path : getPathArray(path);
|
|
99
|
+
return keys.reduce((acc, key) => {
|
|
100
|
+
if (acc && typeof acc === "object") {
|
|
101
|
+
if (!Number.isNaN(Number(key)) && Array.isArray(acc)) {
|
|
102
|
+
return acc[Number(key)];
|
|
103
|
+
}
|
|
104
|
+
return acc[key];
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
}, obj);
|
|
108
|
+
}
|
|
109
|
+
function setNestedValue(obj, path, value) {
|
|
110
|
+
const parts = Array.isArray(path) ? [...path] : [...getPathArray(path)];
|
|
111
|
+
const last = parts.pop();
|
|
112
|
+
if (!last)
|
|
113
|
+
return;
|
|
114
|
+
let target = obj;
|
|
115
|
+
for (const key of parts) {
|
|
116
|
+
if (!Number.isNaN(Number(key)) && Array.isArray(target)) {
|
|
117
|
+
if (!target[Number(key)])
|
|
118
|
+
target[Number(key)] = {};
|
|
119
|
+
target = target[Number(key)];
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
if (typeof target[key] !== "object" || target[key] === null) {
|
|
123
|
+
target[key] = {};
|
|
124
|
+
}
|
|
125
|
+
target = target[key];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (!Number.isNaN(Number(last)) && Array.isArray(target)) {
|
|
129
|
+
target[Number(last)] = value;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
target[last] = value;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function defaultRound(value) {
|
|
136
|
+
return Math.round(value * 100) / 100;
|
|
137
|
+
}
|
|
138
|
+
function isValidCurrencyCode(code, allowedCodes) {
|
|
139
|
+
const list = allowedCodes || ISO_4217_CODES;
|
|
140
|
+
return typeof code === "string" && list.includes(code.toUpperCase());
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":";;AAgFA,oCASC;AAED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",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A lightweight Mongoose plugin for automatic currency conversion at save time - flexible, extensible, and service-agnostic.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mongoose",
|
|
7
|
+
"plugin",
|
|
8
|
+
"currency",
|
|
9
|
+
"conversion",
|
|
10
|
+
"exchange-rate",
|
|
11
|
+
"mongodb",
|
|
12
|
+
"typescript",
|
|
13
|
+
"money"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "maku85",
|
|
18
|
+
"email": "makuma85@gmail.com"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/maku85/mongoose-currency-convert.git"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/maku85/mongoose-currency-convert#readme",
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"module": "dist/index.js",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"require": "./dist/index.cjs",
|
|
32
|
+
"types": "./dist/index.d.ts"
|
|
33
|
+
},
|
|
34
|
+
"./utils": {
|
|
35
|
+
"import": "./dist/utils/helpers.js",
|
|
36
|
+
"require": "./dist/utils/helpers.cjs",
|
|
37
|
+
"types": "./dist/utils/helpers.d.ts"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist"
|
|
42
|
+
],
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc -p tsconfig.json",
|
|
45
|
+
"clean": "rm -rf dist",
|
|
46
|
+
"prepare": "husky",
|
|
47
|
+
"lint": "biome check src --verbose",
|
|
48
|
+
"format": "biome format src --write",
|
|
49
|
+
"release": "semantic-release",
|
|
50
|
+
"prepublishOnly": "npm run build",
|
|
51
|
+
"test": "mocha --config .mocharc.json",
|
|
52
|
+
"test:watch": "mocha --watch --config .mocharc.json",
|
|
53
|
+
"coverage": "nyc npm test"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"mongoose": ">=7.0.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@biomejs/biome": "^2.2.5",
|
|
60
|
+
"@commitlint/config-conventional": "^20.0.0",
|
|
61
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
62
|
+
"@semantic-release/git": "^10.0.1",
|
|
63
|
+
"@semantic-release/github": "^11.0.6",
|
|
64
|
+
"@semantic-release/npm": "^12.0.2",
|
|
65
|
+
"@types/chai": "^5.2.2",
|
|
66
|
+
"@types/mocha": "^10.0.10",
|
|
67
|
+
"@types/node": "^24.7.0",
|
|
68
|
+
"chai": "^6.2.0",
|
|
69
|
+
"commitlint": "^20.1.0",
|
|
70
|
+
"husky": "^9.1.7",
|
|
71
|
+
"mocha": "^11.7.4",
|
|
72
|
+
"mongoose": "^8.19.0",
|
|
73
|
+
"nyc": "^17.1.0",
|
|
74
|
+
"semantic-release": "^24.2.9",
|
|
75
|
+
"ts-node": "^10.9.2",
|
|
76
|
+
"typescript": "^5.9.3"
|
|
77
|
+
},
|
|
78
|
+
"engines": {
|
|
79
|
+
"node": ">=18.0.0"
|
|
80
|
+
},
|
|
81
|
+
"nyc": {
|
|
82
|
+
"extension": [
|
|
83
|
+
".ts"
|
|
84
|
+
],
|
|
85
|
+
"include": [
|
|
86
|
+
"src/**/*.ts"
|
|
87
|
+
],
|
|
88
|
+
"exclude": [
|
|
89
|
+
"test/**/*.ts",
|
|
90
|
+
"dist/**/*.ts"
|
|
91
|
+
],
|
|
92
|
+
"reporter": [
|
|
93
|
+
"text",
|
|
94
|
+
"lcov"
|
|
95
|
+
],
|
|
96
|
+
"all": true,
|
|
97
|
+
"check-coverage": true,
|
|
98
|
+
"lines": 90,
|
|
99
|
+
"functions": 90,
|
|
100
|
+
"branches": 80,
|
|
101
|
+
"statements": 90
|
|
102
|
+
}
|
|
103
|
+
}
|