@asteby/metacore-runtime-react 53.7.0 → 53.8.1
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/CHANGELOG.md +32 -0
- package/dist/action-modal-dispatcher.d.ts.map +1 -1
- package/dist/action-modal-dispatcher.js +3 -1
- package/dist/api-context.d.ts.map +1 -1
- package/dist/api-context.js +15 -0
- package/dist/cache-scope.d.ts +52 -0
- package/dist/cache-scope.d.ts.map +1 -0
- package/dist/cache-scope.js +200 -0
- package/dist/capability-providers/index.d.ts +4 -0
- package/dist/capability-providers/index.d.ts.map +1 -0
- package/dist/capability-providers/index.js +3 -0
- package/dist/capability-providers/model.d.ts +201 -0
- package/dist/capability-providers/model.d.ts.map +1 -0
- package/dist/capability-providers/model.js +293 -0
- package/dist/capability-providers/provider-sortable-list.d.ts +86 -0
- package/dist/capability-providers/provider-sortable-list.d.ts.map +1 -0
- package/dist/capability-providers/provider-sortable-list.js +263 -0
- package/dist/capability-providers/reorder.d.ts +10 -0
- package/dist/capability-providers/reorder.d.ts.map +1 -0
- package/dist/capability-providers/reorder.js +31 -0
- package/dist/dashboard-types.d.ts +2 -4
- package/dist/dashboard-types.d.ts.map +1 -1
- package/dist/dynamic-kanban.d.ts.map +1 -1
- package/dist/dynamic-kanban.js +9 -4
- package/dist/dynamic-relation.d.ts.map +1 -1
- package/dist/dynamic-relation.js +5 -2
- package/dist/dynamic-table.d.ts +2 -0
- package/dist/dynamic-table.d.ts.map +1 -1
- package/dist/dynamic-table.js +40 -6
- package/dist/dynamic-view.d.ts.map +1 -1
- package/dist/dynamic-view.js +3 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/metadata-cache.d.ts +22 -2
- package/dist/metadata-cache.d.ts.map +1 -1
- package/dist/metadata-cache.js +73 -13
- package/dist/query-batch.d.ts +12 -0
- package/dist/query-batch.d.ts.map +1 -1
- package/dist/query-batch.js +70 -29
- package/dist/use-option-ids.d.ts.map +1 -1
- package/dist/use-option-ids.js +3 -1
- package/dist/use-options-resolver.d.ts +4 -1
- package/dist/use-options-resolver.d.ts.map +1 -1
- package/dist/use-options-resolver.js +27 -16
- package/dist/widgets/charts.d.ts.map +1 -1
- package/dist/widgets/charts.js +11 -43
- package/dist/widgets/widget-format.d.ts +1 -41
- package/dist/widgets/widget-format.d.ts.map +1 -1
- package/dist/widgets/widget-format.js +3 -138
- package/package.json +4 -4
- package/src/__tests__/charts-reexport.test.ts +30 -0
- package/src/action-modal-dispatcher.tsx +3 -1
- package/src/api-context.tsx +14 -0
- package/src/cache-scope-inflight.test.ts +369 -0
- package/src/cache-scope.test.ts +234 -0
- package/src/cache-scope.ts +202 -0
- package/src/capability-providers/index.ts +46 -0
- package/src/capability-providers/model.test.ts +186 -0
- package/src/capability-providers/model.ts +464 -0
- package/src/capability-providers/provider-sortable-list.test.tsx +284 -0
- package/src/capability-providers/provider-sortable-list.tsx +452 -0
- package/src/capability-providers/reorder.ts +29 -0
- package/src/dashboard-types.ts +2 -11
- package/src/dynamic-kanban.tsx +9 -4
- package/src/dynamic-relation.tsx +5 -2
- package/src/dynamic-table.tsx +41 -10
- package/src/dynamic-view.tsx +3 -1
- package/src/index.ts +13 -0
- package/src/metadata-cache.ts +85 -15
- package/src/query-batch.ts +71 -30
- package/src/use-option-ids.ts +3 -1
- package/src/use-options-resolver.ts +28 -15
- package/src/widgets/charts.tsx +26 -189
- package/src/widgets/widget-format.ts +14 -181
- package/vitest.setup.ts +16 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @asteby/metacore-runtime-react
|
|
2
2
|
|
|
3
|
+
## 53.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3f85831: Seguimiento de las cachés por alcance `org:user:lang`.
|
|
8
|
+
|
|
9
|
+
runtime-react: `DynamicTable` calcula la clave de arranque de las filas en caché con `peekCacheScope()` y una sola vez (antes llamaba a `cacheScope()` en cada render y, si el alcance había cambiado, disparaba oyentes que hacían `set` del store en pleno render: aviso «Cannot update a component while rendering»). La decodificación del JWT de `peekCacheScope` se memoiza por el texto del token (una entrada). La documentación de `setCacheScopeProvider` aclara que el proveedor debe cambiar con cada usuario y organización.
|
|
10
|
+
|
|
11
|
+
starter-core (seguridad): el almacén `metadata-cache` (persistido) y su prefetch de la barra lateral guardaban permisos sin dueño, que la siguiente cuenta del navegador veía. Ahora lleva el campo `scope` (`org:user:lang`, reutilizando `cacheScope`/`peekCacheScope`/`onCacheScopeChange` de runtime-react, que ya es dependencia), lee solo dentro del alcance vigente, escribe con el alcance capturado al pedir (`setMetadata`/`setModalMetadata` aceptan `{ scope }` y descartan la respuesta si la identidad cambió), `prefetchAll` no pide sin identidad ni guarda una respuesta de otra cuenta, y se vacía (memoria y almacenamiento persistido) al cambiar de alcance. Nueva `clearMetadataCache()` para el logout. La versión del persist sube a 4 y la migración descarta lo anterior.
|
|
12
|
+
|
|
13
|
+
## 53.8.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- bb03d31: New `@asteby/metacore-charts` package (the `ui.charts` page share): shared chart palette and value formatting, a dependency-free SVG `Sparkline`, and lazy `BarChart`/`LineChart`/`AreaChart`/`PieChart`/`DonutChart` (recharts loads on demand; eager bodies at `@asteby/metacore-charts/recharts`). `@asteby/metacore-runtime-react` now builds its dashboard chart widgets on it, keeps re-exporting everything it exposed before (`BarWidget`…, `formatWidgetValue`, `paletteColor`, …) and also re-exports `Sparkline`.
|
|
18
|
+
- e529899: Nueva lista ordenable de proveedores con estado (`ProviderSortableList`: insignias Listo / Sin credenciales / Sandbox / Con fallas / No atiende / Desactivado, arrastre con puntero y teclado, interruptor «Hereda de la organización», interruptor de activación y acciones por elemento) y el modelo puro de resolución de capacidades por mercado (`resolveCapability`, `groupByDomain`, `bundleSelections`, `changeImpact`, `providerStatus`…) portado desde ops, para que la pantalla Mercados y otras apps host lo reutilicen. Genérico, sin nociones de pagos y sin dependencias nuevas. `CapabilityProvider` del modelo se exporta como `CapabilityProviderBinding` para no chocar con `capability-gate`.
|
|
19
|
+
|
|
20
|
+
Notas de contrato:
|
|
21
|
+
- `ProviderStatus` incluye ya `unhealthy` y `disabled` (alineado con ready / not_configured / unhealthy / disabled del diseño de mercados del kernel; `missing_credentials` equivale a `not_configured`). `providerStatus` marca `unavailable` a un proveedor no instalado y acepta `{ enabled, healthy }`.
|
|
22
|
+
- `resolveCapability` refleja `capability.Select` v1 (regla de hoy). Select v2 (prioridad y estado por mercado) sigue pendiente del release F2 del kernel; el orden que emite la lista no lo consume este modelo.
|
|
23
|
+
- `onReorder` emite solo los elegibles: un host que guarda la lista completa debe conservar sus entradas no elegibles.
|
|
24
|
+
- Las etiquetas por omisión pasan por i18n (`capability_providers.*`, con el español como `defaultValue`); `labels` sigue siendo el override.
|
|
25
|
+
|
|
26
|
+
- c9910c4: Seguridad: las cachés del cliente (almacén de metadata persistido y cachés del lote `/q`) ahora se llavean por el alcance `org:user:lang` (`cacheScope()`); si falta la organización, el usuario o el idioma no se sirve ni se guarda nada. Al cambiar de alcance (logout, otra organización, otro usuario u otro idioma) se vacían las cachés en memoria y la persistida. Nuevas funciones para el host en logout: `clearQueryBatchCaches()` y `clearMetadataCache()`; además `syncCacheScope()` y `setCacheScopeLanguageProvider()` (el idioma sale de `i18nextLng` o `<html lang>`). El almacén `metacore-metadata-cache` sube a v6 y descarta lo anterior. El lote tolera un `status` por parte (403 prohibido, 424 rechaza, 5xx/413 un reintento por GET directo); sin `status` conserva la heurística por mensaje.
|
|
27
|
+
|
|
28
|
+
Revisión de seguridad: una respuesta del lote (filas o `not_modified`) que llega después de cambiar la identidad se rechaza antes de tocar cualquier caché. La identidad `auth_user` se contrasta con los claims del JWT guardado en `auth_token` (sin verificar la firma; si no coinciden el alcance es desconocido y no se cachea; un token que no es JWT conserva el comportamiento anterior) y el host puede alimentar el alcance con `setCacheScopeProvider(() => ({ org, user, lang }))`, que tiene precedencia. `setMetadata`/`setModalMetadata` aceptan `{ scope }` (el alcance capturado al pedir) y descartan la respuesta si la identidad cambió en el camino. El caché de opciones se llavea por `org:user:lang|sucursal`, se vacía al cambiar de alcance y no se usa sin identidad; un lote descartado por cambio de alcance cae al GET en vez de mostrar error. Las filas de primera página de `DynamicTable` en `sessionStorage` incluyen el alcance en la clave, se borran al cambiar de alcance y no se guardan sin alcance.
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [bb03d31]
|
|
33
|
+
- @asteby/metacore-charts@0.1.0
|
|
34
|
+
|
|
3
35
|
## 53.7.0
|
|
4
36
|
|
|
5
37
|
### Minor Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-modal-dispatcher.d.ts","sourceRoot":"","sources":["../src/action-modal-dispatcher.tsx"],"names":[],"mappings":"AAmDA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"action-modal-dispatcher.d.ts","sourceRoot":"","sources":["../src/action-modal-dispatcher.tsx"],"names":[],"mappings":"AAmDA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AA+B/C,OAAO,KAAK,EAAE,cAAc,EAAmC,MAAM,SAAS,CAAA;AAE9E,OAAO,EACH,KAAK,cAAc,EACnB,KAAK,gBAAgB,EAKxB,MAAM,sBAAsB,CAAA;AAQ7B,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAA;AAiBhD,MAAM,WAAW,WAAW;IACxB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,SAAS,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,C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AAM,EAAE,SAAS,cAAc,EAAE,GAAG,SAAS,EAC7C,CAAC,EAAE,SAAS,EACZ,QAAQ,CAAC,EAAE,MAAM,GAClB,MAAM,CAWR;AA6bD,4DAA4D;AAC5D,MAAM,WAAW,mBAAmB;IAChC,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,qBAAqB;IACrB,GAAG,CAAC,EAAE,IAAI,CAAA;CACb;AAID;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,GAAE,mBAAwB,GAAG,OAAO,CASjG;AAKD,wBAAgB,kBAAkB,CAC9B,MAAM,EAAE,cAAc,EAAE,EACxB,MAAM,EAAE,GAAG,EACX,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,GAAE,mBAAwB,GAC9B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAoBrB;AAwPD,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,GAAG,EACV,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC7B,OAAO,wBAAwB,EAAE,cAAc,GAAG,SAAS,CAuB7D;AAED,oGAAoG;AACpG,wBAAgB,WAAW,CACvB,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,EAK9B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,+BAiFvC"}
|
|
@@ -42,6 +42,7 @@ import { UploadField } from './upload-field';
|
|
|
42
42
|
import { isLineItemsField, resolveWidget, resolveDependsValue, getDependsOn, getFieldRef, applyOptionWhen } from './dynamic-form-schema';
|
|
43
43
|
import { FieldGrid, FieldCell, FieldLabel } from './field-grid';
|
|
44
44
|
import { useMetadataCache } from './metadata-cache';
|
|
45
|
+
import { cacheScope } from './cache-scope';
|
|
45
46
|
import { ViewValue, objectLabel, relationSiblingValue, isLineItemsField as isRecordLineItemsField, } from './dialogs/dynamic-record';
|
|
46
47
|
// Canonical registry lives in @asteby/metacore-sdk
|
|
47
48
|
import { adaptActionProps, getActionComponent, subscribeActionComponents, } from '@asteby/metacore-sdk';
|
|
@@ -537,6 +538,7 @@ function RecordPreview({ model, record }) {
|
|
|
537
538
|
if (cached || !model)
|
|
538
539
|
return;
|
|
539
540
|
let cancelled = false;
|
|
541
|
+
const askedScope = cacheScope();
|
|
540
542
|
api
|
|
541
543
|
.get(`/metadata/table/${model}`)
|
|
542
544
|
.then((res) => {
|
|
@@ -545,7 +547,7 @@ function RecordPreview({ model, record }) {
|
|
|
545
547
|
const meta = (res.data?.data ?? res.data);
|
|
546
548
|
if (meta && Array.isArray(meta.columns)) {
|
|
547
549
|
setFetched(meta);
|
|
548
|
-
setMetadata(model, meta);
|
|
550
|
+
setMetadata(model, meta, { scope: askedScope });
|
|
549
551
|
}
|
|
550
552
|
})
|
|
551
553
|
.catch(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-context.d.ts","sourceRoot":"","sources":["../src/api-context.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAwD,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"api-context.d.ts","sourceRoot":"","sources":["../src/api-context.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAwD,MAAM,OAAO,CAAA;AAY5E,uEAAuE;AACvE,MAAM,WAAW,SAAS;IACtB,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC,CAAA;IACzE,IAAI,EAAE,CAAC,GAAG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
|
@@ -5,11 +5,26 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
5
5
|
// their app in <ApiProvider value={axiosInstance}> once at the root.
|
|
6
6
|
import { createContext, useContext, useEffect, useMemo } from 'react';
|
|
7
7
|
import { batchGet, invalidateQueryBatchData } from './query-batch';
|
|
8
|
+
import { syncCacheScope } from './cache-scope';
|
|
8
9
|
import { invalidateOptionsCache } from './use-options-resolver';
|
|
9
10
|
import { epochFromAxiosHeaders, isStaleStateError, reportCacheEpoch, STALE_RETRIED_FLAG, STALE_RETRY_DELAY_MS, } from './cache-coherence';
|
|
10
11
|
const ApiContext = createContext(null);
|
|
11
12
|
const BatchContext = createContext(true);
|
|
12
13
|
export function ApiProvider({ client, batch = true, children }) {
|
|
14
|
+
// Login, logout or an org/user/language switch (also from another tab)
|
|
15
|
+
// empties the scoped caches (metadata store, query batch).
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
syncCacheScope();
|
|
18
|
+
if (typeof window === 'undefined')
|
|
19
|
+
return;
|
|
20
|
+
const onChange = () => syncCacheScope();
|
|
21
|
+
window.addEventListener('storage', onChange);
|
|
22
|
+
window.addEventListener('focus', onChange);
|
|
23
|
+
return () => {
|
|
24
|
+
window.removeEventListener('storage', onChange);
|
|
25
|
+
window.removeEventListener('focus', onChange);
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
13
28
|
// Hosts also write through their own client (native dialogs, settings
|
|
14
29
|
// screens) without going through useApi(). When the client is axios,
|
|
15
30
|
// every non-GET response drops what the runtime remembered as well.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scope of every client-side cache that holds server answers shaped by who is
|
|
3
|
+
* asking: `org:user:lang`.
|
|
4
|
+
*
|
|
5
|
+
* Metadata carries the user's permissions (`actions[]`, `can*` flags) and the
|
|
6
|
+
* operator's language, and rows depend on the organization. On a shared
|
|
7
|
+
* browser a cache keyed by anything less shows the first paint of the previous
|
|
8
|
+
* account. The scope is read from what the SDK already knows: the host session
|
|
9
|
+
* (`auth_user` in localStorage: `organization_id`, `id`) and the UI language
|
|
10
|
+
* (`i18nextLng`, or `<html lang>`; a host with another source calls
|
|
11
|
+
* {@link setCacheScopeLanguageProvider}).
|
|
12
|
+
*
|
|
13
|
+
* Fails closed: when the organization, the user or the language is unknown the
|
|
14
|
+
* scope is `null` and nothing is served from nor stored in a cache.
|
|
15
|
+
*/
|
|
16
|
+
type ScopeListener = (next: string | null, prev: string | null) => void;
|
|
17
|
+
export interface CacheScopeParts {
|
|
18
|
+
org?: string | null;
|
|
19
|
+
user?: string | null;
|
|
20
|
+
lang?: string | null;
|
|
21
|
+
}
|
|
22
|
+
/** Lets a host with its own language source (not i18next / `<html lang>`) feed the scope. */
|
|
23
|
+
export declare function setCacheScopeLanguageProvider(fn: (() => string | null | undefined) | null): void;
|
|
24
|
+
/**
|
|
25
|
+
* Lets the host feed the whole scope from its own session store instead of
|
|
26
|
+
* `localStorage`. Takes precedence over `auth_user` and the token check; a
|
|
27
|
+
* missing `lang` falls back to the language sources above. Returning `null`
|
|
28
|
+
* (no session) makes the scope unknown, so nothing is cached. Pass `null` to
|
|
29
|
+
* go back to reading `localStorage`.
|
|
30
|
+
*
|
|
31
|
+
* The provider MUST change with every user AND every organization (a switch of
|
|
32
|
+
* either has to yield different `org`/`user`). A scope that stays the same
|
|
33
|
+
* across accounts defeats the protection: caches would be served to the next
|
|
34
|
+
* account as if nothing changed.
|
|
35
|
+
*/
|
|
36
|
+
export declare function setCacheScopeProvider(fn: (() => CacheScopeParts | null | undefined) | null): void;
|
|
37
|
+
/** Reads the scope without notifying anyone (safe inside render/selectors). */
|
|
38
|
+
export declare function peekCacheScope(): string | null;
|
|
39
|
+
/**
|
|
40
|
+
* Current `org:user:lang` scope, or `null` when any part is unknown (callers
|
|
41
|
+
* must then neither read nor write caches). When the scope moved since the
|
|
42
|
+
* last call, every registered cache is told to drop what it holds.
|
|
43
|
+
*/
|
|
44
|
+
export declare function cacheScope(): string | null;
|
|
45
|
+
/** Re-reads the scope and clears caches if it changed (login, logout, org/user/lang switch). */
|
|
46
|
+
export declare function syncCacheScope(): void;
|
|
47
|
+
/** Registers a cache to be cleared when the scope changes. Returns the unsubscribe. */
|
|
48
|
+
export declare function onCacheScopeChange(fn: ScopeListener): () => void;
|
|
49
|
+
/** Test helper: forget the last seen scope without notifying. */
|
|
50
|
+
export declare function resetCacheScopeTracking(): void;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=cache-scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-scope.d.ts","sourceRoot":"","sources":["../src/cache-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,KAAK,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;AAKvE,MAAM,WAAW,eAAe;IAC5B,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB;AAID,6FAA6F;AAC7F,wBAAgB,6BAA6B,CAAC,EAAE,EAAE,CAAC,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI,GAAG,IAAI,CAEhG;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI,GAAG,IAAI,CAEjG;AAoFD,+EAA+E;AAC/E,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CA8B9C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CAe1C;AAED,gGAAgG;AAChG,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAED,uFAAuF;AACvF,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,aAAa,GAAG,MAAM,IAAI,CAGhE;AAED,iEAAiE;AACjE,wBAAgB,uBAAuB,IAAI,IAAI,CAE9C"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scope of every client-side cache that holds server answers shaped by who is
|
|
3
|
+
* asking: `org:user:lang`.
|
|
4
|
+
*
|
|
5
|
+
* Metadata carries the user's permissions (`actions[]`, `can*` flags) and the
|
|
6
|
+
* operator's language, and rows depend on the organization. On a shared
|
|
7
|
+
* browser a cache keyed by anything less shows the first paint of the previous
|
|
8
|
+
* account. The scope is read from what the SDK already knows: the host session
|
|
9
|
+
* (`auth_user` in localStorage: `organization_id`, `id`) and the UI language
|
|
10
|
+
* (`i18nextLng`, or `<html lang>`; a host with another source calls
|
|
11
|
+
* {@link setCacheScopeLanguageProvider}).
|
|
12
|
+
*
|
|
13
|
+
* Fails closed: when the organization, the user or the language is unknown the
|
|
14
|
+
* scope is `null` and nothing is served from nor stored in a cache.
|
|
15
|
+
*/
|
|
16
|
+
let languageProvider = null;
|
|
17
|
+
let scopeProvider = null;
|
|
18
|
+
const listeners = new Set();
|
|
19
|
+
let lastScope;
|
|
20
|
+
/** Lets a host with its own language source (not i18next / `<html lang>`) feed the scope. */
|
|
21
|
+
export function setCacheScopeLanguageProvider(fn) {
|
|
22
|
+
languageProvider = fn;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Lets the host feed the whole scope from its own session store instead of
|
|
26
|
+
* `localStorage`. Takes precedence over `auth_user` and the token check; a
|
|
27
|
+
* missing `lang` falls back to the language sources above. Returning `null`
|
|
28
|
+
* (no session) makes the scope unknown, so nothing is cached. Pass `null` to
|
|
29
|
+
* go back to reading `localStorage`.
|
|
30
|
+
*
|
|
31
|
+
* The provider MUST change with every user AND every organization (a switch of
|
|
32
|
+
* either has to yield different `org`/`user`). A scope that stays the same
|
|
33
|
+
* across accounts defeats the protection: caches would be served to the next
|
|
34
|
+
* account as if nothing changed.
|
|
35
|
+
*/
|
|
36
|
+
export function setCacheScopeProvider(fn) {
|
|
37
|
+
scopeProvider = fn;
|
|
38
|
+
}
|
|
39
|
+
// One-entry memo: peekCacheScope runs on every render (inScope) and the token
|
|
40
|
+
// rarely changes, so decode it once per distinct text.
|
|
41
|
+
let lastDecoded = null;
|
|
42
|
+
function decodeJwtClaims(token) {
|
|
43
|
+
if (lastDecoded && lastDecoded.token === token)
|
|
44
|
+
return lastDecoded.claims;
|
|
45
|
+
const claims = decodeJwtClaimsUncached(token);
|
|
46
|
+
lastDecoded = { token, claims };
|
|
47
|
+
return claims;
|
|
48
|
+
}
|
|
49
|
+
function decodeJwtClaimsUncached(token) {
|
|
50
|
+
const parts = token.split('.');
|
|
51
|
+
if (parts.length !== 3 || !parts[1])
|
|
52
|
+
return null;
|
|
53
|
+
try {
|
|
54
|
+
const b64 = parts[1].replace(/-/g, '+').replace(/_/g, '/');
|
|
55
|
+
const padded = b64 + '='.repeat((4 - (b64.length % 4)) % 4);
|
|
56
|
+
const json = typeof atob === 'function'
|
|
57
|
+
? decodeURIComponent(Array.from(atob(padded), (c) => '%' + c.charCodeAt(0).toString(16).padStart(2, '0')).join(''))
|
|
58
|
+
: '';
|
|
59
|
+
const claims = JSON.parse(json);
|
|
60
|
+
return claims && typeof claims === 'object' ? claims : null;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function claimOf(claims, keys) {
|
|
67
|
+
for (const k of keys) {
|
|
68
|
+
const v = claims[k];
|
|
69
|
+
if (v != null && String(v).trim())
|
|
70
|
+
return String(v).trim();
|
|
71
|
+
}
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* `auth_user` is written by the host after `/auth/me`, while the token
|
|
76
|
+
* (`auth_token`) may already be the NEW one (SSO plants it first). Decodes the
|
|
77
|
+
* stored JWT WITHOUT verifying it (the server verifies; here it is only a
|
|
78
|
+
* consistency check) and returns false when the user/org it carries is not the
|
|
79
|
+
* one in `auth_user`: the identity is in transition, so the scope is unknown.
|
|
80
|
+
* A missing or non-JWT token (opaque/session tokens) keeps trusting `auth_user`
|
|
81
|
+
* alone; that is the documented limit — such hosts should use
|
|
82
|
+
* {@link setCacheScopeProvider}.
|
|
83
|
+
*/
|
|
84
|
+
function tokenMatches(org, user) {
|
|
85
|
+
let token = '';
|
|
86
|
+
try {
|
|
87
|
+
token = localStorage.getItem('auth_token') ?? '';
|
|
88
|
+
// The auth store may keep it JSON-encoded.
|
|
89
|
+
if (token.startsWith('"'))
|
|
90
|
+
token = String(JSON.parse(token));
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
token = token.replace(/^Bearer\s+/i, '').trim();
|
|
96
|
+
if (!token)
|
|
97
|
+
return true;
|
|
98
|
+
const claims = decodeJwtClaims(token);
|
|
99
|
+
if (!claims)
|
|
100
|
+
return true;
|
|
101
|
+
const tUser = claimOf(claims, ['sub', 'ID', 'id', 'user_id', 'UserID']);
|
|
102
|
+
const tOrg = claimOf(claims, ['org', 'OrganizationID', 'organization_id', 'org_id']);
|
|
103
|
+
if (tUser && tUser !== user)
|
|
104
|
+
return false;
|
|
105
|
+
if (tOrg && tOrg !== org)
|
|
106
|
+
return false;
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
function readLang() {
|
|
110
|
+
try {
|
|
111
|
+
if (languageProvider)
|
|
112
|
+
return String(languageProvider() ?? '').trim();
|
|
113
|
+
if (typeof localStorage !== 'undefined') {
|
|
114
|
+
const l = localStorage.getItem('i18nextLng');
|
|
115
|
+
if (l)
|
|
116
|
+
return l.trim();
|
|
117
|
+
}
|
|
118
|
+
if (typeof document !== 'undefined')
|
|
119
|
+
return (document.documentElement?.lang ?? '').trim();
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
/* unreadable storage: unknown language */
|
|
123
|
+
}
|
|
124
|
+
return '';
|
|
125
|
+
}
|
|
126
|
+
/** Reads the scope without notifying anyone (safe inside render/selectors). */
|
|
127
|
+
export function peekCacheScope() {
|
|
128
|
+
if (scopeProvider) {
|
|
129
|
+
try {
|
|
130
|
+
const p = scopeProvider();
|
|
131
|
+
if (!p)
|
|
132
|
+
return null;
|
|
133
|
+
const org = String(p.org ?? '').trim();
|
|
134
|
+
const user = String(p.user ?? '').trim();
|
|
135
|
+
const lang = String(p.lang ?? '').trim() || readLang();
|
|
136
|
+
if (!org || !user || !lang)
|
|
137
|
+
return null;
|
|
138
|
+
return [org, user, lang].map(encodeURIComponent).join(':');
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (typeof localStorage === 'undefined')
|
|
145
|
+
return null;
|
|
146
|
+
let org = '';
|
|
147
|
+
let user = '';
|
|
148
|
+
try {
|
|
149
|
+
const raw = localStorage.getItem('auth_user');
|
|
150
|
+
if (!raw)
|
|
151
|
+
return null;
|
|
152
|
+
const parsed = JSON.parse(raw);
|
|
153
|
+
org = String(parsed.organization_id ?? '').trim();
|
|
154
|
+
user = String(parsed.id ?? '').trim();
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
const lang = readLang();
|
|
160
|
+
if (!org || !user || !lang)
|
|
161
|
+
return null;
|
|
162
|
+
if (!tokenMatches(org, user))
|
|
163
|
+
return null;
|
|
164
|
+
return [org, user, lang].map(encodeURIComponent).join(':');
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Current `org:user:lang` scope, or `null` when any part is unknown (callers
|
|
168
|
+
* must then neither read nor write caches). When the scope moved since the
|
|
169
|
+
* last call, every registered cache is told to drop what it holds.
|
|
170
|
+
*/
|
|
171
|
+
export function cacheScope() {
|
|
172
|
+
const next = peekCacheScope();
|
|
173
|
+
if (lastScope !== undefined && next !== lastScope) {
|
|
174
|
+
const prev = lastScope;
|
|
175
|
+
lastScope = next;
|
|
176
|
+
for (const fn of [...listeners]) {
|
|
177
|
+
try {
|
|
178
|
+
fn(next, prev);
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
/* a cache failing to clear must not break the others */
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
lastScope = next;
|
|
186
|
+
return next;
|
|
187
|
+
}
|
|
188
|
+
/** Re-reads the scope and clears caches if it changed (login, logout, org/user/lang switch). */
|
|
189
|
+
export function syncCacheScope() {
|
|
190
|
+
cacheScope();
|
|
191
|
+
}
|
|
192
|
+
/** Registers a cache to be cleared when the scope changes. Returns the unsubscribe. */
|
|
193
|
+
export function onCacheScopeChange(fn) {
|
|
194
|
+
listeners.add(fn);
|
|
195
|
+
return () => listeners.delete(fn);
|
|
196
|
+
}
|
|
197
|
+
/** Test helper: forget the last seen scope without notifying. */
|
|
198
|
+
export function resetCacheScopeTracking() {
|
|
199
|
+
lastScope = undefined;
|
|
200
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { pickText, domainOf, humanizeSegment, servesMarket, resolveCapability, recommendProvider, groupByDomain, activeMarkets, bundleSelections, storedSelections, choiceBlock, checkoutBlockers, changeImpact, providerStatus, usableCapabilities, needsProviderChoice, competingProviderAddons, type CapabilityProvider as CapabilityProviderBinding, type I18nText as ProviderI18nText, type CapabilityView, type CapabilityDomain, type ConnectionState, type ProviderInfo, type Market, type CapabilitiesPayload, type ResolutionReason, type Resolution, type CellStatus, type DomainCell, type DomainGroup, type ChoiceBlock, type ChangeImpact, type UsableCapability, type ProviderStatus, } from './model';
|
|
2
|
+
export { moveItem, moveId, dropIndexFromPointer } from './reorder';
|
|
3
|
+
export { ProviderSortableList, sortableOrder, DEFAULT_PROVIDER_LIST_LABELS, type ProviderSortableItem, type ProviderSortableListLabels, type ProviderSortableListProps, } from './provider-sortable-list';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/capability-providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EAEvB,KAAK,kBAAkB,IAAI,yBAAyB,EACpD,KAAK,QAAQ,IAAI,gBAAgB,EACjC,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,cAAc,GACtB,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAClE,OAAO,EACH,oBAAoB,EACpB,aAAa,EACb,4BAA4B,EAC5B,KAAK,oBAAoB,EACzB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,GACjC,MAAM,0BAA0B,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { pickText, domainOf, humanizeSegment, servesMarket, resolveCapability, recommendProvider, groupByDomain, activeMarkets, bundleSelections, storedSelections, choiceBlock, checkoutBlockers, changeImpact, providerStatus, usableCapabilities, needsProviderChoice, competingProviderAddons, } from './model';
|
|
2
|
+
export { moveItem, moveId, dropIndexFromPointer } from './reorder';
|
|
3
|
+
export { ProviderSortableList, sortableOrder, DEFAULT_PROVIDER_LIST_LABELS, } from './provider-sortable-list';
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
export type I18nText = Record<string, string>;
|
|
2
|
+
export type CapabilityProvider = {
|
|
3
|
+
addon_key: string;
|
|
4
|
+
/** Addon i18n key of the binding label (e.g. mercadopago.capability.session.label). */
|
|
5
|
+
label?: string;
|
|
6
|
+
installed: boolean;
|
|
7
|
+
/** Org-level default (used where a market has no selection of its own). */
|
|
8
|
+
default: boolean;
|
|
9
|
+
/** Market codes this provider is explicitly selected for. */
|
|
10
|
+
markets?: string[];
|
|
11
|
+
/** ISO countries the provider declared it serves; empty = any. */
|
|
12
|
+
countries?: string[];
|
|
13
|
+
};
|
|
14
|
+
export type CapabilityView = {
|
|
15
|
+
key: string;
|
|
16
|
+
providers: CapabilityProvider[];
|
|
17
|
+
domain?: string;
|
|
18
|
+
title?: I18nText;
|
|
19
|
+
description?: I18nText;
|
|
20
|
+
/** A buyer-facing flow needs a provider for it in every market. */
|
|
21
|
+
checkout?: boolean;
|
|
22
|
+
/** Every eligible provider answers (shipping rates…): nothing to choose. */
|
|
23
|
+
fanout?: boolean;
|
|
24
|
+
/** Follow-ups go to the provider that created the operation. */
|
|
25
|
+
pinned?: boolean;
|
|
26
|
+
};
|
|
27
|
+
export type CapabilityDomain = {
|
|
28
|
+
key: string;
|
|
29
|
+
title?: I18nText;
|
|
30
|
+
description?: I18nText;
|
|
31
|
+
icon?: string;
|
|
32
|
+
order?: number;
|
|
33
|
+
};
|
|
34
|
+
export type ConnectionState = 'connected' | 'missing_credentials' | 'not_required';
|
|
35
|
+
export type ProviderInfo = {
|
|
36
|
+
addon_key: string;
|
|
37
|
+
name?: I18nText;
|
|
38
|
+
icon?: string;
|
|
39
|
+
connection?: {
|
|
40
|
+
state: ConnectionState;
|
|
41
|
+
environment?: 'sandbox' | 'production' | '';
|
|
42
|
+
connector?: string;
|
|
43
|
+
testable?: boolean;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export type Market = {
|
|
47
|
+
code: string;
|
|
48
|
+
name?: string;
|
|
49
|
+
countries?: string[];
|
|
50
|
+
currency?: string;
|
|
51
|
+
is_default?: boolean;
|
|
52
|
+
active?: boolean;
|
|
53
|
+
};
|
|
54
|
+
export type CapabilitiesPayload = {
|
|
55
|
+
data: CapabilityView[];
|
|
56
|
+
domains?: CapabilityDomain[];
|
|
57
|
+
providers?: Record<string, ProviderInfo>;
|
|
58
|
+
};
|
|
59
|
+
/** Pick a locale's text: exact, base language, es, en, any. */
|
|
60
|
+
export declare function pickText(text: I18nText | undefined, locale?: string): string;
|
|
61
|
+
/** "commerce.payments.session" → "commerce.payments" (fallback when the API has no domain). */
|
|
62
|
+
export declare function domainOf(key: string): string;
|
|
63
|
+
/** Readable title from a key segment, never the dotted id ("loyalty" → "Loyalty"). */
|
|
64
|
+
export declare function humanizeSegment(key: string): string;
|
|
65
|
+
export declare function servesMarket(p: CapabilityProvider, m: Market | null): boolean;
|
|
66
|
+
export type ResolutionReason = 'selected' | 'default' | 'only' | 'fanout' | 'ambiguous' | 'none';
|
|
67
|
+
export type Resolution = {
|
|
68
|
+
key: string;
|
|
69
|
+
addon?: string;
|
|
70
|
+
/** Fan-out: every provider that will answer. */
|
|
71
|
+
addons?: string[];
|
|
72
|
+
reason: ResolutionReason;
|
|
73
|
+
eligible: string[];
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Which provider answers capability `c` in market `m` (null = organization
|
|
77
|
+
* level). Mirrors kernel capability.Select v1 (today's rule): market
|
|
78
|
+
* selection, then org default among eligible, then the only eligible
|
|
79
|
+
* provider. Select v2 (priority and provider state) is pending kernel F2 and
|
|
80
|
+
* is not modeled here.
|
|
81
|
+
*/
|
|
82
|
+
export declare function resolveCapability(c: CapabilityView, m: Market | null): Resolution;
|
|
83
|
+
export type CellStatus = 'ok' | 'mixed' | 'needs_choice' | 'no_provider' | 'fanout';
|
|
84
|
+
export type DomainCell = {
|
|
85
|
+
market: Market | null;
|
|
86
|
+
status: CellStatus;
|
|
87
|
+
/** The provider of the bundle when status is ok. */
|
|
88
|
+
provider?: string;
|
|
89
|
+
/** Providers in use (mixed / fanout). */
|
|
90
|
+
providers: string[];
|
|
91
|
+
resolutions: Resolution[];
|
|
92
|
+
/** Providers that can be chosen for the bundle in this market. */
|
|
93
|
+
candidates: string[];
|
|
94
|
+
/** Installed providers of the domain that do NOT serve this market. */
|
|
95
|
+
blocked: string[];
|
|
96
|
+
/** One-click suggestion when exactly one candidate is ready. */
|
|
97
|
+
recommended?: string;
|
|
98
|
+
/** Checkout contracts left without a provider in this market. */
|
|
99
|
+
checkoutGaps: string[];
|
|
100
|
+
};
|
|
101
|
+
export type DomainGroup = {
|
|
102
|
+
key: string;
|
|
103
|
+
domain: CapabilityDomain;
|
|
104
|
+
capabilities: CapabilityView[];
|
|
105
|
+
/** Installed providers of any capability of the domain, sorted. */
|
|
106
|
+
providers: string[];
|
|
107
|
+
/** Capability keys each provider offers in this domain. */
|
|
108
|
+
provides: Record<string, string[]>;
|
|
109
|
+
cells: DomainCell[];
|
|
110
|
+
fanoutOnly: boolean;
|
|
111
|
+
};
|
|
112
|
+
export declare function recommendProvider(candidates: string[], providers: Record<string, ProviderInfo> | undefined): string | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* Group the usable capabilities (at least one installed provider) by domain
|
|
115
|
+
* and resolve each domain per market. With no active market the single
|
|
116
|
+
* column is the organization level (market null).
|
|
117
|
+
*/
|
|
118
|
+
export declare function groupByDomain(payload: CapabilitiesPayload, markets: Market[]): DomainGroup[];
|
|
119
|
+
/** Active markets, default first, then by name. */
|
|
120
|
+
export declare function activeMarkets(markets: Market[]): Market[];
|
|
121
|
+
/**
|
|
122
|
+
* The selections to send when `addon` becomes the provider of the whole
|
|
123
|
+
* domain in market m: every choosable contract of the domain the addon
|
|
124
|
+
* provides and serves there. Contracts it does not provide are left as they
|
|
125
|
+
* are.
|
|
126
|
+
*/
|
|
127
|
+
export declare function bundleSelections(group: DomainGroup, addon: string, m: Market | null): Record<string, string>;
|
|
128
|
+
/**
|
|
129
|
+
* What is stored today for these keys in market m ("" = nothing chosen), so
|
|
130
|
+
* the host can send it back as is (undo).
|
|
131
|
+
*/
|
|
132
|
+
export declare function storedSelections(group: DomainGroup, keys: string[], m: Market | null): Record<string, string>;
|
|
133
|
+
export type ChoiceBlock = {
|
|
134
|
+
addon: string;
|
|
135
|
+
reason: 'market' | 'not_provided';
|
|
136
|
+
countries?: string[];
|
|
137
|
+
};
|
|
138
|
+
/** Why `addon` cannot be the domain provider in market m (null = it can). */
|
|
139
|
+
export declare function choiceBlock(group: DomainGroup, addon: string, m: Market | null): ChoiceBlock | null;
|
|
140
|
+
/** Markets whose checkout lacks a provider for a contract it needs. */
|
|
141
|
+
export declare function checkoutBlockers(groups: DomainGroup[]): {
|
|
142
|
+
group: DomainGroup;
|
|
143
|
+
cell: DomainCell;
|
|
144
|
+
}[];
|
|
145
|
+
export type ChangeImpact = {
|
|
146
|
+
/** Contracts the change writes (the bundle the provider offers and serves). */
|
|
147
|
+
keys: string[];
|
|
148
|
+
/** Providers answering those contracts today (effective, not only stored). */
|
|
149
|
+
from: string[];
|
|
150
|
+
/** Every key already resolves to the provider. */
|
|
151
|
+
sameProvider: boolean;
|
|
152
|
+
/** Every key already STORES this provider as an explicit selection. */
|
|
153
|
+
alreadyStored: boolean;
|
|
154
|
+
/** Something would change on save (a different provider or an explicit pin). */
|
|
155
|
+
saveable: boolean;
|
|
156
|
+
};
|
|
157
|
+
/** Impact preview of making `addon` the provider of the domain in market m. */
|
|
158
|
+
export declare function changeImpact(group: DomainGroup, addon: string, m: Market | null): ChangeImpact;
|
|
159
|
+
export type UsableCapability = CapabilityView & {
|
|
160
|
+
installed: CapabilityProvider[];
|
|
161
|
+
/** The provider the host routes to today, if any. */
|
|
162
|
+
current?: CapabilityProvider;
|
|
163
|
+
/** Several installed providers and none marked default: dispatch fails. */
|
|
164
|
+
ambiguous: boolean;
|
|
165
|
+
};
|
|
166
|
+
export declare function usableCapabilities(data: CapabilityView[]): UsableCapability[];
|
|
167
|
+
/**
|
|
168
|
+
* Is there anything to decide on the provider-choice screen? Only when the
|
|
169
|
+
* organization sells in more than one market, or some function can be served
|
|
170
|
+
* by more than one installed provider. With a single market and one provider
|
|
171
|
+
* per function the screen would only repeat what is already installed
|
|
172
|
+
* («MX» under «MX»), so the entry stays out of the way until it matters.
|
|
173
|
+
*/
|
|
174
|
+
export declare function needsProviderChoice(capabilities: readonly CapabilityView[] | undefined, markets: readonly Market[] | undefined): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Installed addons that compete with another installed addon for the same
|
|
177
|
+
* function (a non-fan-out capability with 2+ installed providers). The host
|
|
178
|
+
* links their card in the installed-addons list to the provider-choice
|
|
179
|
+
* screen, where the choice is made.
|
|
180
|
+
*/
|
|
181
|
+
export declare function competingProviderAddons(capabilities: readonly CapabilityView[] | undefined): Set<string>;
|
|
182
|
+
/**
|
|
183
|
+
* Badge of a provider for a market. `missing_credentials` is the kernel's
|
|
184
|
+
* `not_configured`; `disabled` is the row's own `enabled = false`;
|
|
185
|
+
* `unhealthy` is a connected provider whose health check is failing;
|
|
186
|
+
* `unavailable` does not serve the market (or is not installed).
|
|
187
|
+
*/
|
|
188
|
+
export type ProviderStatus = 'ready' | 'missing_credentials' | 'sandbox' | 'unhealthy' | 'unavailable' | 'disabled';
|
|
189
|
+
/**
|
|
190
|
+
* The badge a provider deserves in market `m`, first match wins:
|
|
191
|
+
* `unavailable` when it is not installed or does not serve the market,
|
|
192
|
+
* `disabled` when `opts.enabled === false`, `missing_credentials` when it
|
|
193
|
+
* still needs to be connected, `unhealthy` when `opts.healthy === false`,
|
|
194
|
+
* `sandbox` when it runs against a test environment, else `ready`.
|
|
195
|
+
* Providers that need no connection are ready.
|
|
196
|
+
*/
|
|
197
|
+
export declare function providerStatus(provider: CapabilityProvider, info: ProviderInfo | undefined, m: Market | null, opts?: {
|
|
198
|
+
enabled?: boolean;
|
|
199
|
+
healthy?: boolean;
|
|
200
|
+
}): ProviderStatus;
|
|
201
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/capability-providers/model.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE7C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,uFAAuF;IACvF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,OAAO,CAAA;IAClB,2EAA2E;IAC3E,OAAO,EAAE,OAAO,CAAA;IAChB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,kBAAkB,EAAE,CAAA;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,WAAW,CAAC,EAAE,QAAQ,CAAA;IACtB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,4EAA4E;IAC5E,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,gEAAgE;IAChE,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,WAAW,CAAC,EAAE,QAAQ,CAAA;IACtB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,qBAAqB,GAAG,cAAc,CAAA;AAElF,MAAM,MAAM,YAAY,GAAG;IACzB,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