@asteby/metacore-app-providers 4.0.0 → 6.0.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/dist/index.d.ts CHANGED
@@ -4,5 +4,6 @@ export { LayoutProvider, useLayout, type Collapsible, type Variant, } from './la
4
4
  export { SearchProvider, useSearch, type SearchProviderProps } from './search-provider';
5
5
  export { getCookie, setCookie, removeCookie } from './cookies';
6
6
  export { PlatformConfigProvider, usePlatformConfig, applyBranding, applyCachedBranding, FALLBACK_BRANDING, type PlatformBranding, type BrandingFetcher, type PlatformConfigProviderProps, } from './platform-config-provider';
7
+ export { OrgConfigProvider, useOrgConfig, FALLBACK_ORG_CONFIG, type OrgConfig, type OrgConfigFetcher, type OrgConfigProviderProps, } from './org-config-provider';
7
8
  export { MetacoreAppShell, type MetacoreAppShellProps, } from './metacore-app-shell';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACtF,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAC/E,OAAO,EACL,cAAc,EACd,SAAS,EACT,KAAK,WAAW,EAChB,KAAK,OAAO,GACb,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAC9D,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,2BAA2B,GACjC,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACtF,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAC/E,OAAO,EACL,cAAc,EACd,SAAS,EACT,KAAK,WAAW,EAChB,KAAK,OAAO,GACb,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAC9D,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,2BAA2B,GACjC,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,GAC5B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,sBAAsB,CAAA"}
package/dist/index.js CHANGED
@@ -4,5 +4,6 @@ export { LayoutProvider, useLayout, } from './layout-provider';
4
4
  export { SearchProvider, useSearch } from './search-provider';
5
5
  export { getCookie, setCookie, removeCookie } from './cookies';
6
6
  export { PlatformConfigProvider, usePlatformConfig, applyBranding, applyCachedBranding, FALLBACK_BRANDING, } from './platform-config-provider';
7
+ export { OrgConfigProvider, useOrgConfig, FALLBACK_ORG_CONFIG, } from './org-config-provider';
7
8
  export { MetacoreAppShell, } from './metacore-app-shell';
8
9
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAkB,MAAM,sBAAsB,CAAA;AACtF,OAAO,EAAE,YAAY,EAAE,OAAO,EAA0B,MAAM,iBAAiB,CAAA;AAC/E,OAAO,EACL,cAAc,EACd,SAAS,GAGV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,SAAS,EAA4B,MAAM,mBAAmB,CAAA;AACvF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAC9D,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,iBAAiB,GAIlB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,gBAAgB,GAEjB,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAkB,MAAM,sBAAsB,CAAA;AACtF,OAAO,EAAE,YAAY,EAAE,OAAO,EAA0B,MAAM,iBAAiB,CAAA;AAC/E,OAAO,EACL,cAAc,EACd,SAAS,GAGV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,SAAS,EAA4B,MAAM,mBAAmB,CAAA;AACvF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAC9D,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,iBAAiB,GAIlB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,GAIpB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,gBAAgB,GAEjB,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,67 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface OrgConfig {
3
+ /** ISO 4217 currency code, e.g. "MXN", "COP", "USD". */
4
+ currency: string;
5
+ /** BCP-47 locale tag, e.g. "es-MX", "es-CO", "en-US". */
6
+ locale: string;
7
+ /**
8
+ * Validator identifiers keyed by the `$org.<key>` reference shape used
9
+ * by the kernel. e.g.
10
+ * { tax_id_validator: 'rfc.tax_id', postal_code: 'mx.cp' }
11
+ * The SDK resolves each $org.<key> token through this map at form time.
12
+ */
13
+ validators: Record<string, string>;
14
+ /**
15
+ * Address layout slug. The SDK has no built-in formats — apps register
16
+ * their own renderers and this string picks one. Empty defaults to a
17
+ * neutral 4-line layout.
18
+ */
19
+ addressFormat: string;
20
+ /**
21
+ * Free-form bag for app-specific config the SDK does not type. Use
22
+ * sparingly: anything the SDK consumes should land in a typed field
23
+ * above first.
24
+ */
25
+ extra: Record<string, unknown>;
26
+ }
27
+ export declare const FALLBACK_ORG_CONFIG: OrgConfig;
28
+ interface OrgConfigContextValue {
29
+ config: OrgConfig;
30
+ loading: boolean;
31
+ /**
32
+ * Resolves a `$org.<key>` reference (or a plain key) to the configured
33
+ * validator identifier. Returns null when the org has not configured
34
+ * that validator — callers decide between a built-in fallback and
35
+ * surfacing the missing config to the operator.
36
+ */
37
+ resolveValidator: (refOrKey: string) => string | null;
38
+ refetch: () => void;
39
+ }
40
+ export type OrgConfigFetcher = () => Promise<Partial<OrgConfig>>;
41
+ export interface OrgConfigProviderProps {
42
+ children: ReactNode;
43
+ /**
44
+ * Async function returning the current org's config. Apps wire whatever
45
+ * transport they already use (axios, fetch, ofetch).
46
+ */
47
+ fetcher: OrgConfigFetcher;
48
+ /**
49
+ * Defaults applied while the fetcher hasn't resolved yet OR when the
50
+ * server omits a field. Apps pass their static brand defaults
51
+ * (currency, locale) so the SDK never paints with FALLBACK_ORG_CONFIG.
52
+ */
53
+ defaults?: OrgConfig;
54
+ /** TanStack Query staleTime, defaults to 5 minutes. */
55
+ staleTime?: number;
56
+ }
57
+ export declare function OrgConfigProvider({ children, fetcher, defaults, staleTime, }: OrgConfigProviderProps): import("react/jsx-runtime").JSX.Element;
58
+ /**
59
+ * Returns the current org config plus a `resolveValidator` helper for
60
+ * `$org.<key>` references. Throws if used outside an `<OrgConfigProvider>`
61
+ * is NOT the contract — the hook returns the FALLBACK so legacy app
62
+ * shells without the provider keep rendering, just without locale-aware
63
+ * behaviour. Apps that depend on org config should mount the provider.
64
+ */
65
+ export declare function useOrgConfig(): OrgConfigContextValue;
66
+ export {};
67
+ //# sourceMappingURL=org-config-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org-config-provider.d.ts","sourceRoot":"","sources":["../src/org-config-provider.tsx"],"names":[],"mappings":"AAeA,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAGd,MAAM,WAAW,SAAS;IACxB,wDAAwD;IACxD,QAAQ,EAAE,MAAM,CAAA;IAChB,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAA;IACd;;;;;OAKG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAA;IACrB;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAED,eAAO,MAAM,mBAAmB,EAAE,SAMjC,CAAA;AAED,UAAU,qBAAqB;IAC7B,MAAM,EAAE,SAAS,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB;;;;;OAKG;IACH,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;IACrD,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AASD,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;AAEhE,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,SAAS,CAAA;IACnB;;;OAGG;IACH,OAAO,EAAE,gBAAgB,CAAA;IACzB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,OAAO,EACP,QAA8B,EAC9B,SAAyB,GAC1B,EAAE,sBAAsB,2CAmCxB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,IAAI,qBAAqB,CAEpD"}
@@ -0,0 +1,88 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // OrgConfigProvider — sibling to PlatformConfigProvider that exposes the
3
+ // per-org configuration the SDK needs for locale-aware behaviour:
4
+ // • currency / locale defaults
5
+ // • tax-id validator identifier (the kernel's $org.tax_id_validator
6
+ // reference resolves to whatever this provider returns for the key)
7
+ // • address format slug
8
+ // • any other org-scoped configuration the app wants to surface
9
+ //
10
+ // The principle (from project-wide doctrine): NOTHING fiscal/regional
11
+ // hardcoded in the SDK. The SDK only knows how to apply a validator the
12
+ // org config picks. This provider is the resolver surface — apps wire a
13
+ // fetcher pointing at their own /api/org/config endpoint and the SDK
14
+ // reads `validators[<key>]` / `currency` / etc. through `useOrgConfig`.
15
+ //
16
+ // Decoupled from the app: the fetcher is injected, no axios import here.
17
+ import { createContext, useContext, useMemo, } from 'react';
18
+ import { useQuery } from '@tanstack/react-query';
19
+ export const FALLBACK_ORG_CONFIG = {
20
+ currency: 'USD',
21
+ locale: 'en-US',
22
+ validators: {},
23
+ addressFormat: '',
24
+ extra: {},
25
+ };
26
+ const OrgConfigContext = createContext({
27
+ config: FALLBACK_ORG_CONFIG,
28
+ loading: false,
29
+ resolveValidator: () => null,
30
+ refetch: () => { },
31
+ });
32
+ export function OrgConfigProvider({ children, fetcher, defaults = FALLBACK_ORG_CONFIG, staleTime = 5 * 60 * 1000, }) {
33
+ const { data, isLoading, refetch } = useQuery({
34
+ queryKey: ['metacore-org-config'],
35
+ queryFn: async () => {
36
+ const res = await fetcher();
37
+ return mergeOrgConfig(defaults, res);
38
+ },
39
+ staleTime,
40
+ retry: 1,
41
+ });
42
+ const value = useMemo(() => {
43
+ const config = data ?? defaults;
44
+ return {
45
+ config,
46
+ loading: isLoading,
47
+ resolveValidator: (refOrKey) => {
48
+ if (!refOrKey)
49
+ return null;
50
+ const key = refOrKey.startsWith('$org.')
51
+ ? refOrKey.slice('$org.'.length)
52
+ : refOrKey;
53
+ const resolved = config.validators?.[key];
54
+ return resolved && resolved.length > 0 ? resolved : null;
55
+ },
56
+ refetch: () => {
57
+ refetch();
58
+ },
59
+ };
60
+ }, [data, defaults, isLoading, refetch]);
61
+ return (_jsx(OrgConfigContext, { value: value, children: children }));
62
+ }
63
+ /**
64
+ * Returns the current org config plus a `resolveValidator` helper for
65
+ * `$org.<key>` references. Throws if used outside an `<OrgConfigProvider>`
66
+ * is NOT the contract — the hook returns the FALLBACK so legacy app
67
+ * shells without the provider keep rendering, just without locale-aware
68
+ * behaviour. Apps that depend on org config should mount the provider.
69
+ */
70
+ export function useOrgConfig() {
71
+ return useContext(OrgConfigContext);
72
+ }
73
+ function mergeOrgConfig(defaults, partial) {
74
+ return {
75
+ currency: partial.currency || defaults.currency,
76
+ locale: partial.locale || defaults.locale,
77
+ validators: {
78
+ ...defaults.validators,
79
+ ...(partial.validators || {}),
80
+ },
81
+ addressFormat: partial.addressFormat || defaults.addressFormat,
82
+ extra: {
83
+ ...defaults.extra,
84
+ ...(partial.extra || {}),
85
+ },
86
+ };
87
+ }
88
+ //# sourceMappingURL=org-config-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org-config-provider.js","sourceRoot":"","sources":["../src/org-config-provider.tsx"],"names":[],"mappings":";AAAA,yEAAyE;AACzE,kEAAkE;AAClE,iCAAiC;AACjC,sEAAsE;AACtE,wEAAwE;AACxE,0BAA0B;AAC1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AAI,EAAE,CAAC;SACzB;KACF,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asteby/metacore-app-providers",
3
- "version": "4.0.0",
3
+ "version": "6.0.0",
4
4
  "description": "Providers genéricos reutilizables para apps metacore (direction, font, layout, search, platform-config)",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "react": ">=18",
28
28
  "react-dom": ">=18",
29
29
  "@asteby/metacore-pwa": ">=0.3.1",
30
- "@asteby/metacore-runtime-react": ">=9.1.0",
30
+ "@asteby/metacore-runtime-react": ">=10.0.0",
31
31
  "@asteby/metacore-ui": ">=2.0.0",
32
32
  "sonner": ">=1.7"
33
33
  },
@@ -50,9 +50,9 @@
50
50
  "react": "^19.2.4",
51
51
  "react-dom": "^19.2.4",
52
52
  "sonner": "^2.0.0",
53
- "typescript": "^5.6.0",
53
+ "typescript": "^6.0.0",
54
54
  "@asteby/metacore-pwa": "0.3.1",
55
- "@asteby/metacore-runtime-react": "9.1.0",
55
+ "@asteby/metacore-runtime-react": "10.0.0",
56
56
  "@asteby/metacore-ui": "2.0.0"
57
57
  },
58
58
  "publishConfig": {