@uplab/vendure-plugin-exchange-rates 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.
Files changed (94) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +369 -0
  3. package/dist/api/admin.resolver.d.ts +16 -0
  4. package/dist/api/admin.resolver.d.ts.map +1 -0
  5. package/dist/api/admin.resolver.js +66 -0
  6. package/dist/api/admin.resolver.js.map +1 -0
  7. package/dist/api/api-extensions.d.ts +6 -0
  8. package/dist/api/api-extensions.d.ts.map +1 -0
  9. package/dist/api/api-extensions.js +57 -0
  10. package/dist/api/api-extensions.js.map +1 -0
  11. package/dist/api/shop.resolver.d.ts +15 -0
  12. package/dist/api/shop.resolver.d.ts.map +1 -0
  13. package/dist/api/shop.resolver.js +63 -0
  14. package/dist/api/shop.resolver.js.map +1 -0
  15. package/dist/constants.d.ts +10 -0
  16. package/dist/constants.d.ts.map +1 -0
  17. package/dist/constants.js +13 -0
  18. package/dist/constants.js.map +1 -0
  19. package/dist/dashboard/format-rate.ts +8 -0
  20. package/dist/dashboard/graphql.ts +74 -0
  21. package/dist/dashboard/i18n/en.po +109 -0
  22. package/dist/dashboard/i18n/uk.po +109 -0
  23. package/dist/dashboard/index.tsx +7 -0
  24. package/dist/dashboard/routes/currency-exchange-rate-detail.tsx +194 -0
  25. package/dist/dashboard/routes/currency-exchange-rate-list.tsx +105 -0
  26. package/dist/derive-rates.d.ts +13 -0
  27. package/dist/derive-rates.d.ts.map +1 -0
  28. package/dist/derive-rates.js +40 -0
  29. package/dist/derive-rates.js.map +1 -0
  30. package/dist/effective-rate.d.ts +8 -0
  31. package/dist/effective-rate.d.ts.map +1 -0
  32. package/dist/effective-rate.js +13 -0
  33. package/dist/effective-rate.js.map +1 -0
  34. package/dist/entities/currency-exchange-rate.entity.d.ts +13 -0
  35. package/dist/entities/currency-exchange-rate.entity.d.ts.map +1 -0
  36. package/dist/entities/currency-exchange-rate.entity.js +55 -0
  37. package/dist/entities/currency-exchange-rate.entity.js.map +1 -0
  38. package/dist/events/currency-exchange-rate.event.d.ts +18 -0
  39. package/dist/events/currency-exchange-rate.event.d.ts.map +1 -0
  40. package/dist/events/currency-exchange-rate.event.js +18 -0
  41. package/dist/events/currency-exchange-rate.event.js.map +1 -0
  42. package/dist/exchange-rate-source-error.d.ts +16 -0
  43. package/dist/exchange-rate-source-error.d.ts.map +1 -0
  44. package/dist/exchange-rate-source-error.js +18 -0
  45. package/dist/exchange-rate-source-error.js.map +1 -0
  46. package/dist/exchange-rate-sync.task.d.ts +3 -0
  47. package/dist/exchange-rate-sync.task.d.ts.map +1 -0
  48. package/dist/exchange-rate-sync.task.js +18 -0
  49. package/dist/exchange-rate-sync.task.js.map +1 -0
  50. package/dist/exchange-rates.plugin.d.ts +24 -0
  51. package/dist/exchange-rates.plugin.d.ts.map +1 -0
  52. package/dist/exchange-rates.plugin.js +101 -0
  53. package/dist/exchange-rates.plugin.js.map +1 -0
  54. package/dist/index.d.ts +15 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +31 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/services/currency-exchange-rate-sync.service.d.ts +30 -0
  59. package/dist/services/currency-exchange-rate-sync.service.d.ts.map +1 -0
  60. package/dist/services/currency-exchange-rate-sync.service.js +145 -0
  61. package/dist/services/currency-exchange-rate-sync.service.js.map +1 -0
  62. package/dist/services/currency-exchange-rate.service.d.ts +30 -0
  63. package/dist/services/currency-exchange-rate.service.d.ts.map +1 -0
  64. package/dist/services/currency-exchange-rate.service.js +93 -0
  65. package/dist/services/currency-exchange-rate.service.js.map +1 -0
  66. package/dist/sources/ecb-exchange-rate-source.d.ts +20 -0
  67. package/dist/sources/ecb-exchange-rate-source.d.ts.map +1 -0
  68. package/dist/sources/ecb-exchange-rate-source.js +33 -0
  69. package/dist/sources/ecb-exchange-rate-source.js.map +1 -0
  70. package/dist/sources/fetch-body.d.ts +9 -0
  71. package/dist/sources/fetch-body.d.ts.map +1 -0
  72. package/dist/sources/fetch-body.js +59 -0
  73. package/dist/sources/fetch-body.js.map +1 -0
  74. package/dist/sources/frankfurter-exchange-rate-source.d.ts +23 -0
  75. package/dist/sources/frankfurter-exchange-rate-source.d.ts.map +1 -0
  76. package/dist/sources/frankfurter-exchange-rate-source.js +35 -0
  77. package/dist/sources/frankfurter-exchange-rate-source.js.map +1 -0
  78. package/dist/sources/monobank-exchange-rate-source.d.ts +29 -0
  79. package/dist/sources/monobank-exchange-rate-source.d.ts.map +1 -0
  80. package/dist/sources/monobank-exchange-rate-source.js +46 -0
  81. package/dist/sources/monobank-exchange-rate-source.js.map +1 -0
  82. package/dist/sources/nbu-exchange-rate-source.d.ts +20 -0
  83. package/dist/sources/nbu-exchange-rate-source.d.ts.map +1 -0
  84. package/dist/sources/nbu-exchange-rate-source.js +25 -0
  85. package/dist/sources/nbu-exchange-rate-source.js.map +1 -0
  86. package/dist/sources/static-exchange-rate-source.d.ts +20 -0
  87. package/dist/sources/static-exchange-rate-source.d.ts.map +1 -0
  88. package/dist/sources/static-exchange-rate-source.js +23 -0
  89. package/dist/sources/static-exchange-rate-source.js.map +1 -0
  90. package/dist/types.d.ts +64 -0
  91. package/dist/types.d.ts.map +1 -0
  92. package/dist/types.js +3 -0
  93. package/dist/types.js.map +1 -0
  94. package/package.json +96 -0
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.round8 = void 0;
4
+ exports.deriveRates = deriveRates;
5
+ const constants_1 = require("./constants");
6
+ const exchange_rate_source_error_1 = require("./exchange-rate-source-error");
7
+ /** The 8 decimals a rate is stored with. */
8
+ const round8 = (value) => Math.round(value * 1e8) / 1e8;
9
+ exports.round8 = round8;
10
+ /**
11
+ * @description
12
+ * Re-bases `quotes` (units of `sourceBase` per unit) onto `shopBase`. With a different base the cross
13
+ * rate is `rate(c) / rate(shopBase)`, so the source must quote the shop's base currency; it throws when
14
+ * it does not. A quote for the shop's base itself is dropped, and so is a result that rounds to 0 or does
15
+ * not fit decimal(19, 8).
16
+ */
17
+ function deriveRates(source, shopBase, sourceBase, quotes) {
18
+ let derived;
19
+ if (sourceBase === shopBase) {
20
+ derived = quotes;
21
+ }
22
+ else {
23
+ const pivot = quotes.find((q) => q.currencyCode === shopBase)?.rate;
24
+ if (!pivot || !Number.isFinite(pivot) || pivot <= 0) {
25
+ throw new exchange_rate_source_error_1.ExchangeRateSourceError(`${source} quotes against ${sourceBase} but not ${shopBase}, the shop's base currency`, { source });
26
+ }
27
+ derived = [
28
+ // A source may list its own base (at 1); it is derived from the pivot below instead.
29
+ ...quotes
30
+ .filter((q) => q.currencyCode !== sourceBase)
31
+ .map((q) => ({ currencyCode: q.currencyCode, rate: q.rate / pivot })),
32
+ { currencyCode: sourceBase, rate: 1 / pivot },
33
+ ];
34
+ }
35
+ return derived
36
+ .filter((q) => q.currencyCode !== shopBase)
37
+ .map((q) => ({ currencyCode: q.currencyCode, rate: (0, exports.round8)(q.rate) }))
38
+ .filter((q) => q.rate > 0 && q.rate < constants_1.MAX_RATE);
39
+ }
40
+ //# sourceMappingURL=derive-rates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derive-rates.js","sourceRoot":"","sources":["../src/derive-rates.ts"],"names":[],"mappings":";;;AAeA,kCA6BC;AA3CD,2CAAuC;AACvC,6EAAuE;AAGvE,4CAA4C;AACrC,MAAM,MAAM,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AAAlE,QAAA,MAAM,UAA4D;AAE/E;;;;;;GAMG;AACH,SAAgB,WAAW,CACzB,MAAc,EACd,QAAsB,EACtB,UAAwB,EACxB,MAA2B;IAE3B,IAAI,OAA4B,CAAC;IACjC,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,GAAG,MAAM,CAAC;IACnB,CAAC;SAAM,CAAC;QACN,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,QAAQ,CAAC,EAAE,IAAI,CAAC;QACpE,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YACpD,MAAM,IAAI,oDAAuB,CAC/B,GAAG,MAAM,mBAAmB,UAAU,YAAY,QAAQ,4BAA4B,EACtF,EAAE,MAAM,EAAE,CACX,CAAC;QACJ,CAAC;QACD,OAAO,GAAG;YACR,qFAAqF;YACrF,GAAG,MAAM;iBACN,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,UAAU,CAAC;iBAC5C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC,CAAC;YACvE,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,GAAG,KAAK,EAAE;SAC9C,CAAC;IACJ,CAAC;IACD,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,QAAQ,CAAC;SAC1C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,YAAY,EAAE,IAAI,EAAE,IAAA,cAAM,EAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SACpE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,oBAAQ,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { CurrencyExchangeRate } from './entities/currency-exchange-rate.entity';
2
+ /**
3
+ * @description
4
+ * The rate to convert with — the admin's custom rate while it is switched on, otherwise the fetched
5
+ * one — or `undefined` when that rate is not a positive number.
6
+ */
7
+ export declare function effectiveRate(rate: Pick<CurrencyExchangeRate, 'rate' | 'useCustomRate' | 'customRate'>): number | undefined;
8
+ //# sourceMappingURL=effective-rate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effective-rate.d.ts","sourceRoot":"","sources":["../src/effective-rate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAErF;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,eAAe,GAAG,YAAY,CAAC,GACxE,MAAM,GAAG,SAAS,CAGpB"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.effectiveRate = effectiveRate;
4
+ /**
5
+ * @description
6
+ * The rate to convert with — the admin's custom rate while it is switched on, otherwise the fetched
7
+ * one — or `undefined` when that rate is not a positive number.
8
+ */
9
+ function effectiveRate(rate) {
10
+ const value = rate.useCustomRate ? rate.customRate : rate.rate;
11
+ return value != null && Number.isFinite(value) && value > 0 ? value : undefined;
12
+ }
13
+ //# sourceMappingURL=effective-rate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effective-rate.js","sourceRoot":"","sources":["../src/effective-rate.ts"],"names":[],"mappings":";;AAOA,sCAKC;AAVD;;;;GAIG;AACH,SAAgB,aAAa,CAC3B,IAAyE;IAEzE,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IAC/D,OAAO,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAClF,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { CurrencyCode, DeepPartial, VendureEntity } from '@vendure/core';
2
+ export declare class CurrencyExchangeRate extends VendureEntity {
3
+ constructor(input?: DeepPartial<CurrencyExchangeRate>);
4
+ code: CurrencyCode;
5
+ /** The currency `rate` and `customRate` are expressed in. */
6
+ baseCurrency: CurrencyCode;
7
+ enabled: boolean;
8
+ /** Units of `baseCurrency` per one unit of `code`, as fetched from the source. */
9
+ rate: number;
10
+ useCustomRate: boolean;
11
+ customRate?: number | null;
12
+ }
13
+ //# sourceMappingURL=currency-exchange-rate.entity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency-exchange-rate.entity.d.ts","sourceRoot":"","sources":["../../src/entities/currency-exchange-rate.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AASzE,qBACa,oBAAqB,SAAQ,aAAa;gBACzC,KAAK,CAAC,EAAE,WAAW,CAAC,oBAAoB,CAAC;IAMrD,IAAI,EAAE,YAAY,CAAC;IAEnB,6DAA6D;IAE7D,YAAY,EAAE,YAAY,CAAC;IAG3B,OAAO,EAAE,OAAO,CAAC;IAEjB,kFAAkF;IAElF,IAAI,EAAE,MAAM,CAAC;IAGb,aAAa,EAAE,OAAO,CAAC;IAGvB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CurrencyExchangeRate = void 0;
13
+ const core_1 = require("@vendure/core");
14
+ const typeorm_1 = require("typeorm");
15
+ /** Decimal columns come back as strings from Postgres and MySQL; `null` stays `null`. */
16
+ const decimalToNumber = {
17
+ to: (value) => value,
18
+ from: (value) => (value == null ? value : Number(value)),
19
+ };
20
+ let CurrencyExchangeRate = class CurrencyExchangeRate extends core_1.VendureEntity {
21
+ constructor(input) {
22
+ super(input);
23
+ }
24
+ };
25
+ exports.CurrencyExchangeRate = CurrencyExchangeRate;
26
+ __decorate([
27
+ (0, typeorm_1.Column)({ type: 'varchar' }),
28
+ (0, typeorm_1.Index)({ unique: true }),
29
+ __metadata("design:type", String)
30
+ ], CurrencyExchangeRate.prototype, "code", void 0);
31
+ __decorate([
32
+ (0, typeorm_1.Column)({ type: 'varchar' }),
33
+ __metadata("design:type", String)
34
+ ], CurrencyExchangeRate.prototype, "baseCurrency", void 0);
35
+ __decorate([
36
+ (0, typeorm_1.Column)({ default: false }),
37
+ __metadata("design:type", Boolean)
38
+ ], CurrencyExchangeRate.prototype, "enabled", void 0);
39
+ __decorate([
40
+ (0, typeorm_1.Column)({ type: 'decimal', precision: 19, scale: 8, transformer: decimalToNumber }),
41
+ __metadata("design:type", Number)
42
+ ], CurrencyExchangeRate.prototype, "rate", void 0);
43
+ __decorate([
44
+ (0, typeorm_1.Column)({ default: false }),
45
+ __metadata("design:type", Boolean)
46
+ ], CurrencyExchangeRate.prototype, "useCustomRate", void 0);
47
+ __decorate([
48
+ (0, typeorm_1.Column)({ type: 'decimal', precision: 19, scale: 8, nullable: true, transformer: decimalToNumber }),
49
+ __metadata("design:type", Object)
50
+ ], CurrencyExchangeRate.prototype, "customRate", void 0);
51
+ exports.CurrencyExchangeRate = CurrencyExchangeRate = __decorate([
52
+ (0, typeorm_1.Entity)(),
53
+ __metadata("design:paramtypes", [Object])
54
+ ], CurrencyExchangeRate);
55
+ //# sourceMappingURL=currency-exchange-rate.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency-exchange-rate.entity.js","sourceRoot":"","sources":["../../src/entities/currency-exchange-rate.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAyE;AACzE,qCAAkE;AAElE,yFAAyF;AACzF,MAAM,eAAe,GAAqB;IACxC,EAAE,EAAE,CAAC,KAAgC,EAAE,EAAE,CAAC,KAAK;IAC/C,IAAI,EAAE,CAAC,KAA6B,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;CACjF,CAAC;AAGK,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,oBAAa;IACrD,YAAY,KAAyC;QACnD,KAAK,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;CAsBF,CAAA;AAzBY,oDAAoB;AAO/B;IAFC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAC3B,IAAA,eAAK,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;;kDACL;AAInB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;0DACD;AAG3B;IADC,IAAA,gBAAM,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;qDACV;AAIjB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC;;kDACtE;AAGb;IADC,IAAA,gBAAM,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;2DACJ;AAGvB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC;;wDACxE;+BAxBhB,oBAAoB;IADhC,IAAA,gBAAM,GAAE;;GACI,oBAAoB,CAyBhC"}
@@ -0,0 +1,18 @@
1
+ import { RequestContext, VendureEvent } from '@vendure/core';
2
+ import { CurrencyExchangeRate } from '../entities/currency-exchange-rate.entity';
3
+ /**
4
+ * `synced`: a sync changed something; `entities` are then every rate stored in the current base.
5
+ * `updated`: an admin changed one rate, which is `entities[0]`.
6
+ */
7
+ export type CurrencyExchangeRateEventType = 'synced' | 'updated';
8
+ /**
9
+ * Published whenever the stored rates change, so the host can drop caches that embed them. It carries
10
+ * `ctx`, so Vendure emits it only after the surrounding transaction commits.
11
+ */
12
+ export declare class CurrencyExchangeRateEvent extends VendureEvent {
13
+ readonly ctx: RequestContext;
14
+ readonly entities: CurrencyExchangeRate[];
15
+ readonly type: CurrencyExchangeRateEventType;
16
+ constructor(ctx: RequestContext, entities: CurrencyExchangeRate[], type: CurrencyExchangeRateEventType);
17
+ }
18
+ //# sourceMappingURL=currency-exchange-rate.event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency-exchange-rate.event.d.ts","sourceRoot":"","sources":["../../src/events/currency-exchange-rate.event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEjE;;;GAGG;AACH,qBAAa,yBAA0B,SAAQ,YAAY;aAEvC,GAAG,EAAE,cAAc;aACnB,QAAQ,EAAE,oBAAoB,EAAE;aAChC,IAAI,EAAE,6BAA6B;gBAFnC,GAAG,EAAE,cAAc,EACnB,QAAQ,EAAE,oBAAoB,EAAE,EAChC,IAAI,EAAE,6BAA6B;CAItD"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CurrencyExchangeRateEvent = void 0;
4
+ const core_1 = require("@vendure/core");
5
+ /**
6
+ * Published whenever the stored rates change, so the host can drop caches that embed them. It carries
7
+ * `ctx`, so Vendure emits it only after the surrounding transaction commits.
8
+ */
9
+ class CurrencyExchangeRateEvent extends core_1.VendureEvent {
10
+ constructor(ctx, entities, type) {
11
+ super();
12
+ this.ctx = ctx;
13
+ this.entities = entities;
14
+ this.type = type;
15
+ }
16
+ }
17
+ exports.CurrencyExchangeRateEvent = CurrencyExchangeRateEvent;
18
+ //# sourceMappingURL=currency-exchange-rate.event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency-exchange-rate.event.js","sourceRoot":"","sources":["../../src/events/currency-exchange-rate.event.ts"],"names":[],"mappings":";;;AAAA,wCAA6D;AAS7D;;;GAGG;AACH,MAAa,yBAA0B,SAAQ,mBAAY;IACzD,YACkB,GAAmB,EACnB,QAAgC,EAChC,IAAmC;QAEnD,KAAK,EAAE,CAAC;QAJQ,QAAG,GAAH,GAAG,CAAgB;QACnB,aAAQ,GAAR,QAAQ,CAAwB;QAChC,SAAI,GAAJ,IAAI,CAA+B;IAGrD,CAAC;CACF;AARD,8DAQC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @description
3
+ * A rate source could not be read: a network error or timeout, a non-2xx status, or a body that is
4
+ * not what the source documents.
5
+ */
6
+ export declare class ExchangeRateSourceError extends Error {
7
+ readonly source: string;
8
+ /** The HTTP status, when the source answered with a non-2xx. */
9
+ readonly status?: number;
10
+ constructor(message: string, details: {
11
+ source: string;
12
+ status?: number;
13
+ cause?: unknown;
14
+ });
15
+ }
16
+ //# sourceMappingURL=exchange-rate-source-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange-rate-source-error.d.ts","sourceRoot":"","sources":["../src/exchange-rate-source-error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gEAAgE;IAChE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAM3F"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExchangeRateSourceError = void 0;
4
+ /**
5
+ * @description
6
+ * A rate source could not be read: a network error or timeout, a non-2xx status, or a body that is
7
+ * not what the source documents.
8
+ */
9
+ class ExchangeRateSourceError extends Error {
10
+ constructor(message, details) {
11
+ super(message, details.cause === undefined ? undefined : { cause: details.cause });
12
+ this.name = 'ExchangeRateSourceError';
13
+ this.source = details.source;
14
+ this.status = details.status;
15
+ }
16
+ }
17
+ exports.ExchangeRateSourceError = ExchangeRateSourceError;
18
+ //# sourceMappingURL=exchange-rate-source-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange-rate-source-error.js","sourceRoot":"","sources":["../src/exchange-rate-source-error.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAKhD,YAAY,OAAe,EAAE,OAA6D;QACxF,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QACnF,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;CACF;AAXD,0DAWC"}
@@ -0,0 +1,3 @@
1
+ import { ScheduledTask, ScheduledTaskConfig } from '@vendure/core';
2
+ export declare function createExchangeRateSyncTask(schedule: ScheduledTaskConfig['schedule']): ScheduledTask;
3
+ //# sourceMappingURL=exchange-rate-sync.task.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange-rate-sync.task.d.ts","sourceRoot":"","sources":["../src/exchange-rate-sync.task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAInE,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,mBAAmB,CAAC,UAAU,CAAC,GAAG,aAAa,CAUnG"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createExchangeRateSyncTask = createExchangeRateSyncTask;
4
+ const core_1 = require("@vendure/core");
5
+ const constants_1 = require("./constants");
6
+ const currency_exchange_rate_sync_service_1 = require("./services/currency-exchange-rate-sync.service");
7
+ function createExchangeRateSyncTask(schedule) {
8
+ return new core_1.ScheduledTask({
9
+ id: constants_1.SYNC_TASK_ID,
10
+ description: 'Refresh currency exchange rates from the configured source',
11
+ schedule,
12
+ async execute({ injector, scheduledContext }) {
13
+ const rates = await injector.get(currency_exchange_rate_sync_service_1.CurrencyExchangeRateSyncService).syncRates(scheduledContext);
14
+ return { rates: rates.length };
15
+ },
16
+ });
17
+ }
18
+ //# sourceMappingURL=exchange-rate-sync.task.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange-rate-sync.task.js","sourceRoot":"","sources":["../src/exchange-rate-sync.task.ts"],"names":[],"mappings":";;AAIA,gEAUC;AAdD,wCAAmE;AACnE,2CAA2C;AAC3C,wGAAiG;AAEjG,SAAgB,0BAA0B,CAAC,QAAyC;IAClF,OAAO,IAAI,oBAAa,CAAC;QACvB,EAAE,EAAE,wBAAY;QAChB,WAAW,EAAE,4DAA4D;QACzE,QAAQ;QACR,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE;YAC1C,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,qEAA+B,CAAC,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;YAC9F,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;QACjC,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { OnApplicationBootstrap, OnApplicationShutdown } from '@nestjs/common';
2
+ import { ModuleRef } from '@nestjs/core';
3
+ import { ProcessContext, RequestContextService, Type } from '@vendure/core';
4
+ import { CurrencyExchangeRateSyncService } from './services/currency-exchange-rate-sync.service';
5
+ import { ExchangeRatesPluginOptions, ResolvedExchangeRatesPluginOptions } from './types';
6
+ /**
7
+ * @description
8
+ * Exchange rates for showing and charging prices in other currencies, in any base currency. Rates come
9
+ * from a pluggable {@link ExchangeRateSource} (the ECB, Frankfurter, Monobank, the NBU, fixed rates or
10
+ * your own), are refreshed on a schedule, and can be overridden per currency in the dashboard.
11
+ */
12
+ export declare class ExchangeRatesPlugin implements OnApplicationBootstrap, OnApplicationShutdown {
13
+ private readonly moduleRef;
14
+ private readonly processContext;
15
+ private readonly requestContextService;
16
+ private readonly syncService;
17
+ /** @internal */
18
+ static options: ResolvedExchangeRatesPluginOptions;
19
+ constructor(moduleRef: ModuleRef, processContext: ProcessContext, requestContextService: RequestContextService, syncService: CurrencyExchangeRateSyncService);
20
+ static init(options: ExchangeRatesPluginOptions): Type<ExchangeRatesPlugin>;
21
+ onApplicationBootstrap(): Promise<void>;
22
+ onApplicationShutdown(): Promise<void>;
23
+ }
24
+ //# sourceMappingURL=exchange-rates.plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange-rates.plugin.d.ts","sourceRoot":"","sources":["../src/exchange-rates.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAIL,cAAc,EACd,qBAAqB,EACrB,IAAI,EAEL,MAAM,eAAe,CAAC;AAOvB,OAAO,EAAE,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AAEjG,OAAO,EAAE,0BAA0B,EAAE,kCAAkC,EAAE,MAAM,SAAS,CAAC;AAgBzF;;;;;GAKG;AACH,qBA4Ba,mBAAoB,YAAW,sBAAsB,EAAE,qBAAqB;IAKrF,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAP9B,gBAAgB;IAChB,MAAM,CAAC,OAAO,EAAE,kCAAkC,CAAC;gBAGhC,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,cAAc,EAC9B,qBAAqB,EAAE,qBAAqB,EAC5C,WAAW,EAAE,+BAA+B;IAG/D,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,0BAA0B,GAAG,IAAI,CAAC,mBAAmB,CAAC;IAMrE,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAOvC,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7C"}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var ExchangeRatesPlugin_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.ExchangeRatesPlugin = void 0;
14
+ const core_1 = require("@nestjs/core");
15
+ const core_2 = require("@vendure/core");
16
+ const admin_resolver_1 = require("./api/admin.resolver");
17
+ const api_extensions_1 = require("./api/api-extensions");
18
+ const shop_resolver_1 = require("./api/shop.resolver");
19
+ const constants_1 = require("./constants");
20
+ const exchange_rate_sync_task_1 = require("./exchange-rate-sync.task");
21
+ const currency_exchange_rate_entity_1 = require("./entities/currency-exchange-rate.entity");
22
+ const currency_exchange_rate_sync_service_1 = require("./services/currency-exchange-rate-sync.service");
23
+ const currency_exchange_rate_service_1 = require("./services/currency-exchange-rate.service");
24
+ function resolveOptions(options) {
25
+ if (!options?.source) {
26
+ throw new Error('ExchangeRatesPlugin: "source" is required, e.g. new EcbExchangeRateSource()');
27
+ }
28
+ if (options.baseCurrency && !Object.values(core_2.CurrencyCode).includes(options.baseCurrency)) {
29
+ throw new Error(`ExchangeRatesPlugin: "${options.baseCurrency}" is not a CurrencyCode`);
30
+ }
31
+ return {
32
+ source: options.source,
33
+ baseCurrency: options.baseCurrency,
34
+ sync: options.sync === false ? false : { schedule: options.sync?.schedule ?? constants_1.DEFAULT_SYNC_SCHEDULE },
35
+ };
36
+ }
37
+ /**
38
+ * @description
39
+ * Exchange rates for showing and charging prices in other currencies, in any base currency. Rates come
40
+ * from a pluggable {@link ExchangeRateSource} (the ECB, Frankfurter, Monobank, the NBU, fixed rates or
41
+ * your own), are refreshed on a schedule, and can be overridden per currency in the dashboard.
42
+ */
43
+ let ExchangeRatesPlugin = class ExchangeRatesPlugin {
44
+ static { ExchangeRatesPlugin_1 = this; }
45
+ constructor(moduleRef, processContext, requestContextService, syncService) {
46
+ this.moduleRef = moduleRef;
47
+ this.processContext = processContext;
48
+ this.requestContextService = requestContextService;
49
+ this.syncService = syncService;
50
+ }
51
+ static init(options) {
52
+ this.options = resolveOptions(options);
53
+ return ExchangeRatesPlugin_1;
54
+ }
55
+ // Source first: the backfill needs it.
56
+ async onApplicationBootstrap() {
57
+ await ExchangeRatesPlugin_1.options.source.init?.(new core_2.Injector(this.moduleRef));
58
+ if (this.processContext.isServer) {
59
+ await this.syncService.backfillIfEmpty(await this.requestContextService.create({ apiType: 'admin' }));
60
+ }
61
+ }
62
+ async onApplicationShutdown() {
63
+ await ExchangeRatesPlugin_1.options.source.destroy?.();
64
+ }
65
+ };
66
+ exports.ExchangeRatesPlugin = ExchangeRatesPlugin;
67
+ exports.ExchangeRatesPlugin = ExchangeRatesPlugin = ExchangeRatesPlugin_1 = __decorate([
68
+ (0, core_2.VendurePlugin)({
69
+ imports: [core_2.PluginCommonModule],
70
+ entities: [currency_exchange_rate_entity_1.CurrencyExchangeRate],
71
+ shopApiExtensions: {
72
+ resolvers: [shop_resolver_1.CurrencyExchangeRateShopResolver, shop_resolver_1.CurrencyExchangeRateShopFieldResolver],
73
+ schema: api_extensions_1.shopApiExtensions,
74
+ },
75
+ adminApiExtensions: { resolvers: [admin_resolver_1.CurrencyExchangeRateAdminResolver], schema: api_extensions_1.adminApiExtensions },
76
+ // Resolved relative to the compiled plugin file; the sources are copied to `dist/dashboard/`.
77
+ dashboard: './dashboard/index.tsx',
78
+ providers: [
79
+ { provide: constants_1.EXCHANGE_RATES_PLUGIN_OPTIONS, useFactory: () => ExchangeRatesPlugin.options },
80
+ currency_exchange_rate_service_1.CurrencyExchangeRateService,
81
+ currency_exchange_rate_sync_service_1.CurrencyExchangeRateSyncService,
82
+ ],
83
+ exports: [currency_exchange_rate_service_1.CurrencyExchangeRateService, currency_exchange_rate_sync_service_1.CurrencyExchangeRateSyncService],
84
+ compatibility: '^3.7.0',
85
+ configuration: (config) => {
86
+ const { sync } = ExchangeRatesPlugin.options;
87
+ if (sync) {
88
+ config.schedulerOptions.tasks = [
89
+ ...(config.schedulerOptions.tasks ?? []),
90
+ (0, exchange_rate_sync_task_1.createExchangeRateSyncTask)(sync.schedule),
91
+ ];
92
+ }
93
+ return config;
94
+ },
95
+ }),
96
+ __metadata("design:paramtypes", [core_1.ModuleRef,
97
+ core_2.ProcessContext,
98
+ core_2.RequestContextService,
99
+ currency_exchange_rate_sync_service_1.CurrencyExchangeRateSyncService])
100
+ ], ExchangeRatesPlugin);
101
+ //# sourceMappingURL=exchange-rates.plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange-rates.plugin.js","sourceRoot":"","sources":["../src/exchange-rates.plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,uCAAyC;AACzC,wCAQuB;AACvB,yDAAyE;AACzE,yDAA6E;AAC7E,uDAA8G;AAC9G,2CAAmF;AACnF,uEAAuE;AACvE,4FAAgF;AAChF,wGAAiG;AACjG,8FAAwF;AAGxF,SAAS,cAAc,CAAC,OAAmC;IACzD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;IACjG,CAAC;IACD,IAAI,OAAO,CAAC,YAAY,IAAI,CAAE,MAAM,CAAC,MAAM,CAAC,mBAAY,CAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QACtG,MAAM,IAAI,KAAK,CAAC,yBAAyB,OAAO,CAAC,YAAY,yBAAyB,CAAC,CAAC;IAC1F,CAAC;IACD,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,IAAI,EAAE,OAAO,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,QAAQ,IAAI,iCAAqB,EAAE;KACrG,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AA6BI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;;IAI9B,YACmB,SAAoB,EACpB,cAA8B,EAC9B,qBAA4C,EAC5C,WAA4C;QAH5C,cAAS,GAAT,SAAS,CAAW;QACpB,mBAAc,GAAd,cAAc,CAAgB;QAC9B,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,gBAAW,GAAX,WAAW,CAAiC;IAC5D,CAAC;IAEJ,MAAM,CAAC,IAAI,CAAC,OAAmC;QAC7C,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;QACvC,OAAO,qBAAmB,CAAC;IAC7B,CAAC;IAED,uCAAuC;IACvC,KAAK,CAAC,sBAAsB;QAC1B,MAAM,qBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,IAAI,eAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QAC9E,IAAI,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YACjC,MAAM,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,MAAM,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;QACxG,CAAC;IACH,CAAC;IAED,KAAK,CAAC,qBAAqB;QACzB,MAAM,qBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;IACvD,CAAC;CACF,CAAA;AA3BY,kDAAmB;8BAAnB,mBAAmB;IA5B/B,IAAA,oBAAa,EAAC;QACb,OAAO,EAAE,CAAC,yBAAkB,CAAC;QAC7B,QAAQ,EAAE,CAAC,oDAAoB,CAAC;QAChC,iBAAiB,EAAE;YACjB,SAAS,EAAE,CAAC,gDAAgC,EAAE,qDAAqC,CAAC;YACpF,MAAM,EAAE,kCAAiB;SAC1B;QACD,kBAAkB,EAAE,EAAE,SAAS,EAAE,CAAC,kDAAiC,CAAC,EAAE,MAAM,EAAE,mCAAkB,EAAE;QAClG,8FAA8F;QAC9F,SAAS,EAAE,uBAAuB;QAClC,SAAS,EAAE;YACT,EAAE,OAAO,EAAE,yCAA6B,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE;YACzF,4DAA2B;YAC3B,qEAA+B;SAChC;QACD,OAAO,EAAE,CAAC,4DAA2B,EAAE,qEAA+B,CAAC;QACvE,aAAa,EAAE,QAAQ;QACvB,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE;YACxB,MAAM,EAAE,IAAI,EAAE,GAAG,mBAAmB,CAAC,OAAO,CAAC;YAC7C,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,CAAC,gBAAgB,CAAC,KAAK,GAAG;oBAC9B,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,KAAK,IAAI,EAAE,CAAC;oBACxC,IAAA,oDAA0B,EAAC,IAAI,CAAC,QAAQ,CAAC;iBAC1C,CAAC;YACJ,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;qCAM8B,gBAAS;QACJ,qBAAc;QACP,4BAAqB;QAC/B,qEAA+B;GARpD,mBAAmB,CA2B/B"}
@@ -0,0 +1,15 @@
1
+ export { DEFAULT_SYNC_SCHEDULE, SYNC_TASK_ID } from './constants';
2
+ export { effectiveRate } from './effective-rate';
3
+ export { CurrencyExchangeRate } from './entities/currency-exchange-rate.entity';
4
+ export { CurrencyExchangeRateEvent, type CurrencyExchangeRateEventType } from './events/currency-exchange-rate.event';
5
+ export { ExchangeRateSourceError } from './exchange-rate-source-error';
6
+ export { ExchangeRatesPlugin } from './exchange-rates.plugin';
7
+ export { CurrencyExchangeRateSyncService } from './services/currency-exchange-rate-sync.service';
8
+ export { CurrencyExchangeRateService } from './services/currency-exchange-rate.service';
9
+ export { EcbExchangeRateSource, type EcbExchangeRateSourceOptions } from './sources/ecb-exchange-rate-source';
10
+ export { FrankfurterExchangeRateSource, type FrankfurterExchangeRateSourceOptions, } from './sources/frankfurter-exchange-rate-source';
11
+ export { MonobankExchangeRateSource, type MonobankExchangeRateSourceOptions, } from './sources/monobank-exchange-rate-source';
12
+ export { NbuExchangeRateSource, type NbuExchangeRateSourceOptions } from './sources/nbu-exchange-rate-source';
13
+ export { StaticExchangeRateSource, type StaticExchangeRateSourceOptions } from './sources/static-exchange-rate-source';
14
+ export type { ExchangeRateQuote, ExchangeRateSource, ExchangeRateSourceResult, ExchangeRatesPluginOptions, UpdateCurrencyExchangeRateInput, } from './types';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,KAAK,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AACtH,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AACjG,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,qBAAqB,EAAE,KAAK,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAC9G,OAAO,EACL,6BAA6B,EAC7B,KAAK,oCAAoC,GAC1C,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACL,0BAA0B,EAC1B,KAAK,iCAAiC,GACvC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,KAAK,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAC9G,OAAO,EAAE,wBAAwB,EAAE,KAAK,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AACvH,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StaticExchangeRateSource = exports.NbuExchangeRateSource = exports.MonobankExchangeRateSource = exports.FrankfurterExchangeRateSource = exports.EcbExchangeRateSource = exports.CurrencyExchangeRateService = exports.CurrencyExchangeRateSyncService = exports.ExchangeRatesPlugin = exports.ExchangeRateSourceError = exports.CurrencyExchangeRateEvent = exports.CurrencyExchangeRate = exports.effectiveRate = exports.SYNC_TASK_ID = exports.DEFAULT_SYNC_SCHEDULE = void 0;
4
+ var constants_1 = require("./constants");
5
+ Object.defineProperty(exports, "DEFAULT_SYNC_SCHEDULE", { enumerable: true, get: function () { return constants_1.DEFAULT_SYNC_SCHEDULE; } });
6
+ Object.defineProperty(exports, "SYNC_TASK_ID", { enumerable: true, get: function () { return constants_1.SYNC_TASK_ID; } });
7
+ var effective_rate_1 = require("./effective-rate");
8
+ Object.defineProperty(exports, "effectiveRate", { enumerable: true, get: function () { return effective_rate_1.effectiveRate; } });
9
+ var currency_exchange_rate_entity_1 = require("./entities/currency-exchange-rate.entity");
10
+ Object.defineProperty(exports, "CurrencyExchangeRate", { enumerable: true, get: function () { return currency_exchange_rate_entity_1.CurrencyExchangeRate; } });
11
+ var currency_exchange_rate_event_1 = require("./events/currency-exchange-rate.event");
12
+ Object.defineProperty(exports, "CurrencyExchangeRateEvent", { enumerable: true, get: function () { return currency_exchange_rate_event_1.CurrencyExchangeRateEvent; } });
13
+ var exchange_rate_source_error_1 = require("./exchange-rate-source-error");
14
+ Object.defineProperty(exports, "ExchangeRateSourceError", { enumerable: true, get: function () { return exchange_rate_source_error_1.ExchangeRateSourceError; } });
15
+ var exchange_rates_plugin_1 = require("./exchange-rates.plugin");
16
+ Object.defineProperty(exports, "ExchangeRatesPlugin", { enumerable: true, get: function () { return exchange_rates_plugin_1.ExchangeRatesPlugin; } });
17
+ var currency_exchange_rate_sync_service_1 = require("./services/currency-exchange-rate-sync.service");
18
+ Object.defineProperty(exports, "CurrencyExchangeRateSyncService", { enumerable: true, get: function () { return currency_exchange_rate_sync_service_1.CurrencyExchangeRateSyncService; } });
19
+ var currency_exchange_rate_service_1 = require("./services/currency-exchange-rate.service");
20
+ Object.defineProperty(exports, "CurrencyExchangeRateService", { enumerable: true, get: function () { return currency_exchange_rate_service_1.CurrencyExchangeRateService; } });
21
+ var ecb_exchange_rate_source_1 = require("./sources/ecb-exchange-rate-source");
22
+ Object.defineProperty(exports, "EcbExchangeRateSource", { enumerable: true, get: function () { return ecb_exchange_rate_source_1.EcbExchangeRateSource; } });
23
+ var frankfurter_exchange_rate_source_1 = require("./sources/frankfurter-exchange-rate-source");
24
+ Object.defineProperty(exports, "FrankfurterExchangeRateSource", { enumerable: true, get: function () { return frankfurter_exchange_rate_source_1.FrankfurterExchangeRateSource; } });
25
+ var monobank_exchange_rate_source_1 = require("./sources/monobank-exchange-rate-source");
26
+ Object.defineProperty(exports, "MonobankExchangeRateSource", { enumerable: true, get: function () { return monobank_exchange_rate_source_1.MonobankExchangeRateSource; } });
27
+ var nbu_exchange_rate_source_1 = require("./sources/nbu-exchange-rate-source");
28
+ Object.defineProperty(exports, "NbuExchangeRateSource", { enumerable: true, get: function () { return nbu_exchange_rate_source_1.NbuExchangeRateSource; } });
29
+ var static_exchange_rate_source_1 = require("./sources/static-exchange-rate-source");
30
+ Object.defineProperty(exports, "StaticExchangeRateSource", { enumerable: true, get: function () { return static_exchange_rate_source_1.StaticExchangeRateSource; } });
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAAkE;AAAzD,kHAAA,qBAAqB,OAAA;AAAE,yGAAA,YAAY,OAAA;AAC5C,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,0FAAgF;AAAvE,qIAAA,oBAAoB,OAAA;AAC7B,sFAAsH;AAA7G,yIAAA,yBAAyB,OAAA;AAClC,2EAAuE;AAA9D,qIAAA,uBAAuB,OAAA;AAChC,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA;AAC5B,sGAAiG;AAAxF,sJAAA,+BAA+B,OAAA;AACxC,4FAAwF;AAA/E,6IAAA,2BAA2B,OAAA;AACpC,+EAA8G;AAArG,iIAAA,qBAAqB,OAAA;AAC9B,+FAGoD;AAFlD,iJAAA,6BAA6B,OAAA;AAG/B,yFAGiD;AAF/C,2IAAA,0BAA0B,OAAA;AAG5B,+EAA8G;AAArG,iIAAA,qBAAqB,OAAA;AAC9B,qFAAuH;AAA9G,uIAAA,wBAAwB,OAAA"}
@@ -0,0 +1,30 @@
1
+ import { EventBus, RequestContext, TransactionalConnection } from '@vendure/core';
2
+ import { CurrencyExchangeRateService } from './currency-exchange-rate.service';
3
+ import { CurrencyExchangeRate } from '../entities/currency-exchange-rate.entity';
4
+ import { ResolvedExchangeRatesPluginOptions } from '../types';
5
+ /**
6
+ * @description
7
+ * Pulls rates from the configured {@link ExchangeRateSource} into the `CurrencyExchangeRate` table,
8
+ * re-based onto the shop's base currency. A fetched rate only replaces `rate`: whether a currency is
9
+ * enabled and its custom rate stay as the admin left them, unless the base changed. New currencies arrive
10
+ * disabled.
11
+ */
12
+ export declare class CurrencyExchangeRateSyncService {
13
+ private readonly options;
14
+ private readonly connection;
15
+ private readonly eventBus;
16
+ private readonly rateService;
17
+ constructor(options: ResolvedExchangeRatesPluginOptions, connection: TransactionalConnection, eventBus: EventBus, rateService: CurrencyExchangeRateService);
18
+ /**
19
+ * Returns every rate stored in the current base afterwards, and publishes a `synced` event with them when
20
+ * anything changed — or `[]` when the source returned nothing usable, the stored rates left untouched. Throws when the source cannot be read or cannot be re-based; the stored rates are then
21
+ * left as they were.
22
+ */
23
+ syncRates(ctx: RequestContext): Promise<CurrencyExchangeRate[]>;
24
+ /**
25
+ * Syncs when no rate is stored in the current base: on the first boot, and after a restart that changed
26
+ * the base. Never throws: a source outage must not stop the server.
27
+ */
28
+ backfillIfEmpty(ctx: RequestContext): Promise<void>;
29
+ }
30
+ //# sourceMappingURL=currency-exchange-rate-sync.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency-exchange-rate-sync.service.d.ts","sourceRoot":"","sources":["../../src/services/currency-exchange-rate-sync.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,QAAQ,EAAU,cAAc,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAExG,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAG/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAqB,kCAAkC,EAAE,MAAM,UAAU,CAAC;AAajF;;;;;;GAMG;AACH,qBACa,+BAA+B;IAED,OAAO,CAAC,QAAQ,CAAC,OAAO;IAC/D,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAH4B,OAAO,EAAE,kCAAkC,EAClF,UAAU,EAAE,uBAAuB,EACnC,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,2BAA2B;IAG3D;;;;OAIG;IACG,SAAS,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAoErE;;;OAGG;IACG,eAAe,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAa1D"}