@unchainedshop/utils 5.0.0-alpha.4 → 5.0.0-alpha.7

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  # @unchainedshop/utils
5
5
 
6
- Common utility functions and base classes for the Unchained Engine.
6
+ Common utility functions and adapter/director building blocks for the Unchained Engine.
7
7
 
8
8
  ## Installation
9
9
 
@@ -70,11 +70,11 @@ Available under the `calculation` namespace:
70
70
  | `objectInvert` | Invert object keys and values |
71
71
  | `buildObfuscatedFieldsFilter` | Build filter for obfuscating sensitive fields |
72
72
 
73
- ### Director/Adapter Base Classes
73
+ ### Director/Adapter Building Blocks
74
74
 
75
75
  | Export | Description |
76
76
  |--------|-------------|
77
- | `BaseAdapter` | Base class for all adapters with logging support |
77
+ | `BaseAdapter` | Base object for adapter implementations with logging support |
78
78
  | `BaseDirector` | Factory for creating adapter directors |
79
79
  | `IBaseAdapter` | Interface for adapter implementations |
80
80
  | `IBaseDirector` | Interface for director implementations |
@@ -1,5 +1,6 @@
1
- export declare const priceToString: ({ amount, currencyCode }: {
1
+ export declare const priceToString: ({ amount, currencyCode, locale, }: {
2
2
  amount: number;
3
3
  currencyCode: string;
4
+ locale?: Intl.Locale | string;
4
5
  }) => string;
5
6
  export default priceToString;
@@ -1,5 +1,14 @@
1
- export const priceToString = ({ amount, currencyCode }) => {
2
- const fixedPrice = amount / 100;
3
- return `${currencyCode} ${fixedPrice}`;
1
+ export const priceToString = ({ amount, currencyCode, locale = 'de-CH', }) => {
2
+ const majorUnitAmount = amount / 100;
3
+ try {
4
+ return new Intl.NumberFormat(locale, {
5
+ style: 'currency',
6
+ currency: currencyCode,
7
+ currencyDisplay: 'code',
8
+ }).format(majorUnitAmount);
9
+ }
10
+ catch {
11
+ return `${currencyCode} ${majorUnitAmount}`;
12
+ }
4
13
  };
5
14
  export default priceToString;
@@ -0,0 +1,4 @@
1
+ export declare function executeBulkOperation<T>(ids: readonly T[], operation: (id: T) => Promise<unknown>): Promise<{
2
+ successIds: T[];
3
+ failedIds: T[];
4
+ }>;
@@ -0,0 +1,19 @@
1
+ import { createLogger } from '@unchainedshop/logger';
2
+ const logger = createLogger('unchained:utils:bulk-operation');
3
+ export async function executeBulkOperation(ids, operation) {
4
+ const successIds = [];
5
+ const failedIds = [];
6
+ for (const id of new Set(ids)) {
7
+ try {
8
+ await operation(id);
9
+ successIds.push(id);
10
+ }
11
+ catch (error) {
12
+ failedIds.push(id);
13
+ logger.debug(`Bulk operation failed for entity ${String(id)}`, {
14
+ error: error instanceof Error ? error.message : String(error),
15
+ });
16
+ }
17
+ }
18
+ return { successIds, failedIds };
19
+ }
@@ -11,6 +11,7 @@ export { default as sha1 } from './sha1.ts';
11
11
  export { timingSafeEqual, timingSafeStringEqual } from './timing-safe-equal.ts';
12
12
  export { normalizePhoneNumber, phoneNumberToParts } from './phone-number.ts';
13
13
  export { default as memoizeWithTTL } from './memoize-with-ttl.ts';
14
+ export { executeBulkOperation } from './executeBulkOperation.ts';
14
15
  export declare const SortDirection: {
15
16
  readonly ASC: "ASC";
16
17
  readonly DESC: "DESC";
@@ -11,6 +11,7 @@ export { default as sha1 } from "./sha1.js";
11
11
  export { timingSafeEqual, timingSafeStringEqual } from "./timing-safe-equal.js";
12
12
  export { normalizePhoneNumber, phoneNumberToParts } from "./phone-number.js";
13
13
  export { default as memoizeWithTTL } from "./memoize-with-ttl.js";
14
+ export { executeBulkOperation } from "./executeBulkOperation.js";
14
15
  export const SortDirection = {
15
16
  ASC: 'ASC',
16
17
  DESC: 'DESC',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/utils",
3
3
  "description": "Common utility functions and base classes for the Unchained Engine",
4
- "version": "5.0.0-alpha.4",
4
+ "version": "5.0.0-alpha.7",
5
5
  "main": "lib/utils-index.js",
6
6
  "types": "lib/utils-index.d.ts",
7
7
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "homepage": "https://github.com/unchainedshop/unchained#readme",
31
31
  "dependencies": {
32
- "@unchainedshop/logger": "^5.0.0-alpha.1",
32
+ "@unchainedshop/logger": "^5.0.0-alpha.7",
33
33
  "awesome-phonenumber": "^7.8.0"
34
34
  },
35
35
  "devDependencies": {