@unchainedshop/utils 4.8.11 → 5.0.0-alpha.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.
@@ -3,6 +3,7 @@ export interface IBaseAdapter {
3
3
  key: string;
4
4
  label: string;
5
5
  version: string;
6
+ adapterType?: symbol;
6
7
  asString: () => string;
7
8
  log: (message: string, options?: {
8
9
  level?: LogLevel;
@@ -4,8 +4,6 @@ export interface IBaseDirector<Adapter extends IBaseAdapter> {
4
4
  adapterFilter?: (adapter: Adapter) => boolean;
5
5
  }) => Adapter[];
6
6
  getAdapter: (key: string) => Adapter | null;
7
- registerAdapter: (A: Adapter) => void;
8
- unregisterAdapter: (key: string) => boolean;
9
7
  }
10
8
  export declare const BaseDirector: <AdapterType extends IBaseAdapter>(directorName: string, options?: {
11
9
  adapterSortKey?: string;
@@ -11,11 +11,5 @@ export const BaseDirector = (directorName, options) => {
11
11
  .toSorted((left, right) => left[sortKey] - right[sortKey])
12
12
  .filter(adapterFilter || (() => true));
13
13
  },
14
- registerAdapter: (Adapter) => {
15
- Adapters.set(Adapter[keyField], Adapter);
16
- },
17
- unregisterAdapter: (key) => {
18
- return Adapters.delete(key);
19
- },
20
14
  };
21
15
  };
@@ -1,5 +1,36 @@
1
- import { resolveAcceptLanguage } from 'resolve-accept-language';
2
1
  const { UNCHAINED_LANG = 'de', UNCHAINED_COUNTRY = 'CH', UNCHAINED_CURRENCY = 'CHF' } = process.env;
2
+ function parseAcceptLanguage(header) {
3
+ if (!header)
4
+ return [];
5
+ return header
6
+ .split(',')
7
+ .map((part) => {
8
+ const [locale, ...params] = part.trim().split(';');
9
+ const qParam = params.find((p) => p.trim().startsWith('q='));
10
+ const quality = qParam ? parseFloat(qParam.trim().slice(2)) : 1;
11
+ return { locale: locale.trim(), quality: Number.isNaN(quality) ? 0 : quality };
12
+ })
13
+ .sort((a, b) => b.quality - a.quality);
14
+ }
15
+ function resolveAcceptLanguage(acceptLanguage, supportedLocales, defaultLocale) {
16
+ if (!supportedLocales.length) {
17
+ return { match: defaultLocale };
18
+ }
19
+ const parsed = parseAcceptLanguage(acceptLanguage);
20
+ for (const { locale } of parsed) {
21
+ const exact = supportedLocales.find((s) => s.toLowerCase() === locale.toLowerCase());
22
+ if (exact)
23
+ return { match: exact };
24
+ const lang = locale.split('-')[0].toLowerCase();
25
+ const langMatch = supportedLocales.find((s) => s.toLowerCase().startsWith(lang + '-'));
26
+ if (langMatch)
27
+ return { match: langMatch };
28
+ }
29
+ if (supportedLocales.includes(defaultLocale)) {
30
+ return { match: defaultLocale };
31
+ }
32
+ return { match: supportedLocales[0] || defaultLocale };
33
+ }
3
34
  export const systemLocale = new Intl.Locale(`${UNCHAINED_LANG}-${UNCHAINED_COUNTRY}`);
4
35
  export const determineFallbackLocale = (countries, languages) => {
5
36
  try {
@@ -29,9 +60,7 @@ export const resolveBestSupported = (acceptLanguage, acceptCountry, { countries
29
60
  }, []);
30
61
  const fallbackLocale = determineFallbackLocale(countries, languages);
31
62
  try {
32
- const { match } = resolveAcceptLanguage(acceptLanguage || '', supportedLocales, fallbackLocale.baseName, {
33
- returnMatchType: true,
34
- });
63
+ const { match } = resolveAcceptLanguage(acceptLanguage || '', supportedLocales, fallbackLocale.baseName);
35
64
  return new Intl.Locale(match);
36
65
  }
37
66
  catch {
@@ -9,6 +9,7 @@ export { default as buildObfuscatedFieldsFilter } from './build-obfuscated-field
9
9
  export { default as sha256 } from './sha256.ts';
10
10
  export { default as sha1 } from './sha1.ts';
11
11
  export { timingSafeEqual, timingSafeStringEqual } from './timing-safe-equal.ts';
12
+ export { memoizeWithTTL } from './memoize-with-ttl.ts';
12
13
  export declare const SortDirection: {
13
14
  readonly ASC: "ASC";
14
15
  readonly DESC: "DESC";
@@ -27,6 +28,10 @@ export interface PricingCalculation {
27
28
  amount: number;
28
29
  baseCategory?: string;
29
30
  meta?: any;
31
+ discountId?: string;
32
+ isTaxable?: boolean;
33
+ isNetPrice?: boolean;
34
+ rate?: number;
30
35
  }
31
36
  export type NodeOrTree<T> = string | Tree<T>;
32
37
  export type Tree<T> = NodeOrTree<T>[];
@@ -9,6 +9,7 @@ export { default as buildObfuscatedFieldsFilter } from "./build-obfuscated-field
9
9
  export { default as sha256 } from "./sha256.js";
10
10
  export { default as sha1 } from "./sha1.js";
11
11
  export { timingSafeEqual, timingSafeStringEqual } from "./timing-safe-equal.js";
12
+ export { memoizeWithTTL } from "./memoize-with-ttl.js";
12
13
  export const SortDirection = {
13
14
  ASC: 'ASC',
14
15
  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": "4.8.11",
4
+ "version": "5.0.0-alpha.2",
5
5
  "main": "lib/utils-index.js",
6
6
  "types": "lib/utils-index.d.ts",
7
7
  "type": "module",
@@ -29,9 +29,8 @@
29
29
  },
30
30
  "homepage": "https://github.com/unchainedshop/unchained#readme",
31
31
  "dependencies": {
32
- "@unchainedshop/logger": "^4.6.0",
33
- "hashids": "^2.3.0",
34
- "resolve-accept-language": "^3.1.11"
32
+ "@unchainedshop/logger": "^5.0.0-alpha.1",
33
+ "hashids": "^2.3.0"
35
34
  },
36
35
  "devDependencies": {
37
36
  "@types/node": "^25.0.0",