@asteby/metacore-runtime-react 53.22.0 → 53.23.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 +18 -0
- package/dist/assist-interview.d.ts.map +1 -1
- package/dist/assist-interview.js +7 -10
- package/dist/custom-stages.d.ts.map +1 -1
- package/dist/custom-stages.js +2 -10
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +5 -3
- package/dist/dialogs/use-inline-relations.d.ts.map +1 -1
- package/dist/dialogs/use-inline-relations.js +4 -4
- package/dist/genui/settings-block.d.ts.map +1 -1
- package/dist/genui/settings-block.js +7 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/record-picker-dialog.d.ts.map +1 -1
- package/dist/record-picker-dialog.js +4 -3
- package/dist/setup/addon-config-surface.d.ts.map +1 -1
- package/dist/setup/addon-config-surface.js +14 -12
- package/dist/stage-automations.d.ts.map +1 -1
- package/dist/stage-automations.js +3 -12
- package/dist/stage-layout.d.ts.map +1 -1
- package/dist/stage-layout.js +2 -7
- package/dist/use-addon-installed-probe.d.ts +8 -0
- package/dist/use-addon-installed-probe.d.ts.map +1 -0
- package/dist/use-addon-installed-probe.js +36 -0
- package/dist/use-addon-settings.d.ts +24 -0
- package/dist/use-addon-settings.d.ts.map +1 -1
- package/dist/use-addon-settings.js +39 -13
- package/dist/use-org-document-templates.d.ts.map +1 -1
- package/dist/use-org-document-templates.js +5 -9
- package/dist/views/data-source.d.ts.map +1 -1
- package/dist/views/data-source.js +9 -14
- package/package.json +4 -3
- package/src/__tests__/genui-settings-block.test.tsx +6 -3
- package/src/__tests__/use-addon-settings-hooks.test.tsx +73 -0
- package/src/__tests__/use-addon-settings.test.ts +19 -3
- package/src/assist-interview.tsx +7 -11
- package/src/custom-stages.tsx +2 -7
- package/src/dialogs/dynamic-record.tsx +7 -2
- package/src/dialogs/use-inline-relations.ts +4 -5
- package/src/genui/settings-block.tsx +7 -13
- package/src/index.ts +1 -0
- package/src/record-picker-dialog.tsx +4 -3
- package/src/setup/addon-config-surface.tsx +16 -15
- package/src/stage-automations.tsx +3 -9
- package/src/stage-layout.ts +2 -7
- package/src/use-addon-installed-probe.ts +39 -0
- package/src/use-addon-settings.ts +66 -12
- package/src/use-org-document-templates.ts +5 -10
- package/src/views/data-source.ts +6 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stage-layout.d.ts","sourceRoot":"","sources":["../src/stage-layout.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stage-layout.d.ts","sourceRoot":"","sources":["../src/stage-layout.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,4EAA4E;IAC5E,WAAW,EAAE,MAAM,EAAE,CAAA;CACxB;AAED,MAAM,WAAW,oBAAoB;IACjC,iFAAiF;IACjF,SAAS,EAAE,OAAO,CAAA;IAClB,oFAAoF;IACpF,eAAe,EAAE,OAAO,CAAA;IACxB,wFAAwF;IACxF,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACxC,oEAAoE;IACpE,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB,CA6ClE"}
|
package/dist/stage-layout.js
CHANGED
|
@@ -13,14 +13,9 @@
|
|
|
13
13
|
// GET /stage-layout?model=<m> → { model, stage_order: string[] } | null
|
|
14
14
|
// PUT /stage-layout { model, stage_order: string[] } (full order)
|
|
15
15
|
// DELETE /stage-layout?model=<m> → reset to the declared order
|
|
16
|
+
import { unwrapResponse } from '@asteby/metacore-lib/envelope';
|
|
16
17
|
import { useCallback, useEffect, useState } from 'react';
|
|
17
18
|
import { useApi } from './api-context';
|
|
18
|
-
function unwrap(res) {
|
|
19
|
-
const body = res?.data;
|
|
20
|
-
if (body && typeof body === 'object' && 'data' in body)
|
|
21
|
-
return body.data;
|
|
22
|
-
return body;
|
|
23
|
-
}
|
|
24
19
|
/**
|
|
25
20
|
* Loads a model's saved lane order (only to learn availability + whether a
|
|
26
21
|
* custom order exists) and exposes save/reset. A missing endpoint degrades to
|
|
@@ -39,7 +34,7 @@ export function useStageLayout(model) {
|
|
|
39
34
|
if (cancelled)
|
|
40
35
|
return;
|
|
41
36
|
setAvailable(true);
|
|
42
|
-
const data =
|
|
37
|
+
const data = unwrapResponse(res);
|
|
43
38
|
const order = data?.stage_order;
|
|
44
39
|
setHasCustomLayout(Array.isArray(order) && order.length > 0);
|
|
45
40
|
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface UseAddonInstalledProbeResult {
|
|
2
|
+
installed: boolean | undefined;
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function useAddonInstalledProbe(addonKey: string, opts?: {
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
}): UseAddonInstalledProbeResult;
|
|
8
|
+
//# sourceMappingURL=use-addon-installed-probe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-addon-installed-probe.d.ts","sourceRoot":"","sources":["../src/use-addon-installed-probe.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,4BAA4B;IACzC,SAAS,EAAE,OAAO,GAAG,SAAS,CAAA;IAC9B,SAAS,EAAE,OAAO,CAAA;CACrB;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,4BAA4B,CAqBvH"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// useAddonInstalledProbe — "is addon X installed here?" for hosts/addons that do
|
|
2
|
+
// NOT mount an <InstalledAddonsProvider>: asks the installation API
|
|
3
|
+
// (`GET /addons/:key/settings`, the same call everyone used to hand-roll).
|
|
4
|
+
// With a provider present it answers from it and never touches the network.
|
|
5
|
+
// installed: true → 2xx
|
|
6
|
+
// false → 404 (not installed) or the provider says no
|
|
7
|
+
// undefined → still loading, or unknown (403/network error: never "absent")
|
|
8
|
+
import { useQuery } from '@tanstack/react-query';
|
|
9
|
+
import { useApi } from './api-context';
|
|
10
|
+
import { addonSettingsUrl } from './use-addon-settings';
|
|
11
|
+
import { useInstalledAddons } from './installed-addons-context';
|
|
12
|
+
export function useAddonInstalledProbe(addonKey, opts = {}) {
|
|
13
|
+
const api = useApi();
|
|
14
|
+
const ctx = useInstalledAddons();
|
|
15
|
+
const query = useQuery({
|
|
16
|
+
queryKey: ['addon-installed', addonKey],
|
|
17
|
+
queryFn: async () => {
|
|
18
|
+
try {
|
|
19
|
+
await api.get(addonSettingsUrl(addonKey));
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
const status = e?.response?.status;
|
|
24
|
+
if (status === 404)
|
|
25
|
+
return false;
|
|
26
|
+
throw e;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
retry: false,
|
|
30
|
+
staleTime: 60_000,
|
|
31
|
+
enabled: !ctx && (opts.enabled ?? true) && !!addonKey,
|
|
32
|
+
});
|
|
33
|
+
if (ctx)
|
|
34
|
+
return { installed: ctx.addons.has(addonKey), isLoading: false };
|
|
35
|
+
return { installed: query.data, isLoading: query.isLoading };
|
|
36
|
+
}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
import type { SettingDefLike } from './genui/settings-block';
|
|
2
|
+
/** What `GET /addons/:key/settings` answers, normalised. */
|
|
3
|
+
export interface AddonSettingsPayload<T = Record<string, unknown>> {
|
|
4
|
+
/** Stored values (org, or the branch's resolution when `branchId` is given). */
|
|
5
|
+
values: Partial<T>;
|
|
6
|
+
/** The manifest's setting definitions the host serves alongside the values. */
|
|
7
|
+
definitions: SettingDefLike[];
|
|
8
|
+
/** Branch overrides (only meaningful with `branchId`). */
|
|
9
|
+
overrides: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Normalises the settings response. Envelope `{ success?, data, definitions?,
|
|
13
|
+
* overrides? }` (definitions/overrides are siblings of `data`); a bare
|
|
14
|
+
* `{ key: value }` map is accepted too. Pure + exported for tests.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseAddonSettingsBody<T = Record<string, unknown>>(body: unknown): AddonSettingsPayload<T>;
|
|
1
17
|
/** Stable react-query key for an addon's per-org settings (per branch when given). */
|
|
2
18
|
export declare function addonSettingsKey(addonKey: string, branchId?: string | null): readonly ["addon-settings", string, string] | readonly ["addon-settings", string];
|
|
3
19
|
/**
|
|
@@ -35,9 +51,17 @@ export interface UseAddonSettingsOptions<T> {
|
|
|
35
51
|
export interface UseAddonSettingsResult<T> {
|
|
36
52
|
/** Saved org values merged over `defaults`. Never null. */
|
|
37
53
|
settings: T;
|
|
54
|
+
/** Stored values only (no defaults merged); `{}` until loaded. */
|
|
55
|
+
stored: Partial<T>;
|
|
56
|
+
/** Setting definitions served with the values (`[]` when the host sends none). */
|
|
57
|
+
definitions: SettingDefLike[];
|
|
58
|
+
/** Branch overrides served with the values. */
|
|
59
|
+
overrides: Record<string, unknown>;
|
|
38
60
|
isLoading: boolean;
|
|
39
61
|
error: unknown;
|
|
40
62
|
refetch: () => void;
|
|
63
|
+
/** Forces a fresh GET (bypassing staleTime), updates the cache and resolves with the payload. Rejects on error. */
|
|
64
|
+
reload: () => Promise<AddonSettingsPayload<T>>;
|
|
41
65
|
}
|
|
42
66
|
/**
|
|
43
67
|
* Read an addon's per-organization settings.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-addon-settings.d.ts","sourceRoot":"","sources":["../src/use-addon-settings.ts"],"names":[],"mappings":"AA6BA,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,qFAE1E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"use-addon-settings.d.ts","sourceRoot":"","sources":["../src/use-addon-settings.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAE5D,4DAA4D;AAC5D,MAAM,WAAW,oBAAoB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC7D,gFAAgF;IAChF,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IAClB,+EAA+E;IAC/E,WAAW,EAAE,cAAc,EAAE,CAAA;IAC7B,0DAA0D;IAC1D,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACrC;AAID;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAS1G;AAED,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,qFAE1E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAKnF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,EAChC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GACtC,CAAC,CAQH;AAED,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACtC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IACrB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B;AAED,MAAM,WAAW,sBAAsB,CAAC,CAAC;IACrC,2DAA2D;IAC3D,QAAQ,EAAE,CAAC,CAAA;IACX,kEAAkE;IAClE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IAClB,kFAAkF;IAClF,WAAW,EAAE,cAAc,EAAE,CAAA;IAC7B,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClC,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,mHAAmH;IACnH,MAAM,EAAE,MAAM,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAA;CACjD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxF,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,uBAAuB,CAAC,CAAC,CAAM,GACtC,sBAAsB,CAAC,CAAC,CAAC,CA4C3B;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9F,QAAQ,EAAE,MAAM;AAChB,mGAAmG;AACnG,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,6FAiB3B"}
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
//
|
|
5
5
|
// The host (ops) persists settings per org on `AddonInstallation.settings`
|
|
6
6
|
// (jsonb) and exposes:
|
|
7
|
-
// GET /
|
|
8
|
-
// PUT /
|
|
7
|
+
// GET /addons/:key/settings → { success, data: { <key>: <value> }, definitions?, overrides? }
|
|
8
|
+
// PUT /addons/:key/settings → body = object of values
|
|
9
|
+
// (paths are relative to the host api client's baseURL, like every other call.)
|
|
9
10
|
// A setting the org has never saved simply isn't present in `data`; the
|
|
10
11
|
// caller supplies the fallback via `opts.defaults` (which mirror the
|
|
11
12
|
// manifest's `settings[].default`). runtime-react has no access to the
|
|
@@ -19,9 +20,25 @@
|
|
|
19
20
|
// Server-side gating (wasm/Go backends) is out of scope here: a backend that
|
|
20
21
|
// must gate behaviour on org config reads the same `AddonInstallation.settings`
|
|
21
22
|
// jsonb directly — this hook is the client-read half of that contract.
|
|
22
|
-
import { useMemo } from 'react';
|
|
23
|
+
import { useCallback, useMemo } from 'react';
|
|
23
24
|
import { useMutation, useQuery, useQueryClient, } from '@tanstack/react-query';
|
|
24
25
|
import { useApi } from './api-context';
|
|
26
|
+
const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
27
|
+
/**
|
|
28
|
+
* Normalises the settings response. Envelope `{ success?, data, definitions?,
|
|
29
|
+
* overrides? }` (definitions/overrides are siblings of `data`); a bare
|
|
30
|
+
* `{ key: value }` map is accepted too. Pure + exported for tests.
|
|
31
|
+
*/
|
|
32
|
+
export function parseAddonSettingsBody(body) {
|
|
33
|
+
if (isRecord(body) && ('data' in body || 'success' in body)) {
|
|
34
|
+
return {
|
|
35
|
+
values: (isRecord(body.data) ? body.data : {}),
|
|
36
|
+
definitions: Array.isArray(body.definitions) ? body.definitions : [],
|
|
37
|
+
overrides: isRecord(body.overrides) ? body.overrides : {},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return { values: (isRecord(body) ? body : {}), definitions: [], overrides: {} };
|
|
41
|
+
}
|
|
25
42
|
/** Stable react-query key for an addon's per-org settings (per branch when given). */
|
|
26
43
|
export function addonSettingsKey(addonKey, branchId) {
|
|
27
44
|
return branchId ? ['addon-settings', addonKey, branchId] : ['addon-settings', addonKey];
|
|
@@ -32,7 +49,9 @@ export function addonSettingsKey(addonKey, branchId) {
|
|
|
32
49
|
* override (POS-1). Without one, the org values (legacy behaviour).
|
|
33
50
|
*/
|
|
34
51
|
export function addonSettingsUrl(addonKey, branchId) {
|
|
35
|
-
|
|
52
|
+
// Relative to the host api client's baseURL (ops: `/api`); a literal `/api`
|
|
53
|
+
// here would double-prefix to `/api/api/addons/...`.
|
|
54
|
+
const base = `/addons/${addonKey}/settings`;
|
|
36
55
|
return branchId ? `${base}?branch_id=${encodeURIComponent(branchId)}` : base;
|
|
37
56
|
}
|
|
38
57
|
/**
|
|
@@ -69,21 +88,28 @@ export function mergeAddonSettings(defaults, stored) {
|
|
|
69
88
|
export function useAddonSettings(addonKey, opts = {}) {
|
|
70
89
|
const api = useApi();
|
|
71
90
|
const { defaults, staleTime, enabled, branchId } = opts;
|
|
91
|
+
const qc = useQueryClient();
|
|
92
|
+
const queryKey = addonSettingsKey(addonKey, branchId);
|
|
93
|
+
const fetchPayload = useCallback(async () => {
|
|
94
|
+
const res = await api.get(addonSettingsUrl(addonKey, branchId));
|
|
95
|
+
return parseAddonSettingsBody(res.data);
|
|
96
|
+
}, [api, addonKey, branchId]);
|
|
72
97
|
const query = useQuery({
|
|
73
|
-
queryKey
|
|
74
|
-
queryFn:
|
|
75
|
-
const res = await api.get(addonSettingsUrl(addonKey, branchId));
|
|
76
|
-
const body = res.data;
|
|
77
|
-
// Host envelope: { success, data: { <key>: <value> } }.
|
|
78
|
-
const values = body?.success ? body.data : body;
|
|
79
|
-
return (values ?? {});
|
|
80
|
-
},
|
|
98
|
+
queryKey,
|
|
99
|
+
queryFn: fetchPayload,
|
|
81
100
|
staleTime: staleTime ?? 30_000,
|
|
82
101
|
enabled: (enabled ?? true) && !!addonKey,
|
|
83
102
|
});
|
|
84
|
-
const settings = useMemo(() => mergeAddonSettings(defaults, query.data), [defaults, query.data]);
|
|
103
|
+
const settings = useMemo(() => mergeAddonSettings(defaults, query.data?.values), [defaults, query.data]);
|
|
104
|
+
const reload = useCallback(() => qc.fetchQuery({ queryKey, queryFn: fetchPayload, staleTime: 0 }),
|
|
105
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
106
|
+
[qc, fetchPayload, addonKey, branchId]);
|
|
85
107
|
return {
|
|
86
108
|
settings,
|
|
109
|
+
stored: query.data?.values ?? {},
|
|
110
|
+
definitions: query.data?.definitions ?? [],
|
|
111
|
+
overrides: query.data?.overrides ?? {},
|
|
112
|
+
reload,
|
|
87
113
|
isLoading: query.isLoading,
|
|
88
114
|
error: query.error,
|
|
89
115
|
refetch: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-org-document-templates.d.ts","sourceRoot":"","sources":["../src/use-org-document-templates.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-org-document-templates.d.ts","sourceRoot":"","sources":["../src/use-org-document-templates.ts"],"names":[],"mappings":"AAwBA,MAAM,WAAW,sBAAsB;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,yBAA0B,SAAQ,sBAAsB;IACrE,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;CACvB;AAED,wBAAgB,qBAAqB,wCAEpC;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,uDAE3E;AAED,wBAAgB,qBAAqB,CAAC,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE;;;;;EAoBjE;AAED,wBAAgB,sBAAsB,CAClC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE;;;;;EAsB/B;AAED,wBAAgB,0BAA0B;cAMtB,MAAM;iBAAe,MAAM;UAAQ,MAAM;YAAU,MAAM;YAgB5E;AAED,wBAAgB,2BAA2B;cAMvB,MAAM;iBAAe,MAAM;YAe9C;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,WAGxB;IACT,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB,KAAG,OAAO,CAAC,MAAM,CAAC,CAmB1B;AAED,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,sBAAsB,EAAE,GAChC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,sBAAsB,EAAE,CAAA;CAAE,EAAE,CAoBhF;AAED,wBAAgB,4BAA4B,CAAC,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE;;kBAtB1D,MAAM;mBAAa,MAAM;mBAAa,sBAAsB,EAAE;;;;;;EA6B5E"}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// POST /api/settings/templates/preview → application/pdf
|
|
14
14
|
//
|
|
15
15
|
// ApiClient is a PEER via <ApiProvider> (same one usePrintDocument uses).
|
|
16
|
+
import { unwrapResponse } from '@asteby/metacore-lib/envelope';
|
|
16
17
|
import { useCallback, useMemo } from 'react';
|
|
17
18
|
import { useMutation, useQuery, useQueryClient, } from '@tanstack/react-query';
|
|
18
19
|
import { useApi } from './api-context';
|
|
@@ -22,18 +23,13 @@ export function orgDocumentCatalogKey() {
|
|
|
22
23
|
export function orgDocumentTemplateKey(addonKey, documentKey) {
|
|
23
24
|
return ['org-document-templates', addonKey, documentKey];
|
|
24
25
|
}
|
|
25
|
-
function unwrapData(res) {
|
|
26
|
-
const body = res.data;
|
|
27
|
-
const values = body?.success ? body.data : body;
|
|
28
|
-
return values;
|
|
29
|
-
}
|
|
30
26
|
export function useOrgDocumentCatalog(opts) {
|
|
31
27
|
const api = useApi();
|
|
32
28
|
const query = useQuery({
|
|
33
29
|
queryKey: orgDocumentCatalogKey(),
|
|
34
30
|
queryFn: async () => {
|
|
35
31
|
const res = await api.get('/settings/templates');
|
|
36
|
-
const data =
|
|
32
|
+
const data = unwrapResponse(res);
|
|
37
33
|
return Array.isArray(data) ? data : [];
|
|
38
34
|
},
|
|
39
35
|
staleTime: 30_000,
|
|
@@ -54,7 +50,7 @@ export function useOrgDocumentTemplate(addonKey, documentKey, opts) {
|
|
|
54
50
|
queryKey: orgDocumentTemplateKey(addonKey, documentKey),
|
|
55
51
|
queryFn: async () => {
|
|
56
52
|
const res = await api.get(`/settings/templates/${encodeURIComponent(addonKey)}/${encodeURIComponent(documentKey)}`);
|
|
57
|
-
return
|
|
53
|
+
return unwrapResponse(res);
|
|
58
54
|
},
|
|
59
55
|
enabled: (opts?.enabled ?? true) && !!addonKey && !!documentKey,
|
|
60
56
|
});
|
|
@@ -73,7 +69,7 @@ export function useSaveOrgDocumentTemplate() {
|
|
|
73
69
|
return useMutation({
|
|
74
70
|
mutationFn: async ({ addonKey, documentKey, html, paper }) => {
|
|
75
71
|
const res = await api.put(`/settings/templates/${encodeURIComponent(addonKey)}/${encodeURIComponent(documentKey)}`, { html, paper });
|
|
76
|
-
return
|
|
72
|
+
return unwrapResponse(res);
|
|
77
73
|
},
|
|
78
74
|
onSuccess: (_data, vars) => {
|
|
79
75
|
void qc.invalidateQueries({ queryKey: orgDocumentCatalogKey() });
|
|
@@ -89,7 +85,7 @@ export function useResetOrgDocumentTemplate() {
|
|
|
89
85
|
return useMutation({
|
|
90
86
|
mutationFn: async ({ addonKey, documentKey }) => {
|
|
91
87
|
const res = await api.delete(`/settings/templates/${encodeURIComponent(addonKey)}/${encodeURIComponent(documentKey)}`);
|
|
92
|
-
return
|
|
88
|
+
return unwrapResponse(res);
|
|
93
89
|
},
|
|
94
90
|
onSuccess: (_data, vars) => {
|
|
95
91
|
void qc.invalidateQueries({ queryKey: orgDocumentCatalogKey() });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-source.d.ts","sourceRoot":"","sources":["../../src/views/data-source.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"data-source.d.ts","sourceRoot":"","sources":["../../src/views/data-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,KAAK,EAAgB,cAAc,EAA4B,MAAM,SAAS,CAAA;AAErF,MAAM,WAAW,wBAAwB;IACrC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,+FAA+F;IAC/F,cAAc,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,wBAAgB,uBAAuB,CACnC,GAAG,EAAE,SAAS,EACd,IAAI,GAAE,wBAA6B,GACpC,cAAc,CA4BhB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQzB;AAED,oEAAoE;AACpE,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAM9F;AAED,2DAA2D;AAC3D,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAU9C;AAED,4CAA4C;AAC5C,wBAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,CAGtC;AAED,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,KAAK,GAAG,MAAe,GAAG,CAAC,EAAE,CAMzH;AAED,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAQ/C"}
|
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
throw new Error(env.message || 'request failed');
|
|
6
|
-
return { data: env.data, total: env.meta?.total };
|
|
7
|
-
}
|
|
8
|
-
return { data: body };
|
|
9
|
-
}
|
|
1
|
+
// Default ViewDataSource over the runtime-react ApiClient, plus the pure
|
|
2
|
+
// helpers renderers share (capability input mapping, item extraction, date
|
|
3
|
+
// grouping). Light on purpose: this module is in the static graph.
|
|
4
|
+
import { unwrapEnvelope, unwrapList } from '@asteby/metacore-lib/envelope';
|
|
10
5
|
export function createApiViewDataSource(api, opts = {}) {
|
|
11
6
|
const chartPath = opts.chartPath ?? '/views/chart';
|
|
12
7
|
const capabilityPath = opts.capabilityPath ?? '/capabilities/query';
|
|
13
8
|
return {
|
|
14
9
|
async list(model, params) {
|
|
15
10
|
const res = await api.get(`/data/${encodeURIComponent(model)}`, params ? { params } : undefined);
|
|
16
|
-
const {
|
|
17
|
-
return { rows:
|
|
11
|
+
const { items, meta } = unwrapList(res.data);
|
|
12
|
+
return { rows: items, total: meta.total };
|
|
18
13
|
},
|
|
19
14
|
async record(model, id) {
|
|
20
15
|
const res = await api.get(`/data/${encodeURIComponent(model)}/${encodeURIComponent(id)}`);
|
|
21
|
-
return
|
|
16
|
+
return unwrapEnvelope(res.data) ?? null;
|
|
22
17
|
},
|
|
23
18
|
async chart(req) {
|
|
24
19
|
const res = await api.post(chartPath, {
|
|
@@ -28,11 +23,11 @@ export function createApiViewDataSource(api, opts = {}) {
|
|
|
28
23
|
record_id: req.recordId,
|
|
29
24
|
panel_key: req.panelKey,
|
|
30
25
|
});
|
|
31
|
-
return
|
|
26
|
+
return unwrapEnvelope(res.data) ?? {};
|
|
32
27
|
},
|
|
33
28
|
async capability(key, input) {
|
|
34
29
|
const res = await api.post(capabilityPath, { capability: key, input });
|
|
35
|
-
return
|
|
30
|
+
return unwrapEnvelope(res.data);
|
|
36
31
|
},
|
|
37
32
|
};
|
|
38
33
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asteby/metacore-runtime-react",
|
|
3
|
-
"version": "53.
|
|
3
|
+
"version": "53.23.1",
|
|
4
4
|
"description": "React runtime for metacore hosts — renders addon contributions dynamically",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@asteby/metacore-charts": "^0.1.0",
|
|
41
|
+
"@asteby/metacore-lib": "^0.10.0",
|
|
41
42
|
"@dnd-kit/core": "^6.3.0",
|
|
42
43
|
"@dnd-kit/sortable": "^10.0.0",
|
|
43
44
|
"@dnd-kit/utilities": "^3.2.2",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"zod": "^4.3.0"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
|
-
"@asteby/metacore-sdk": "^3.
|
|
50
|
+
"@asteby/metacore-sdk": "^3.20.0",
|
|
50
51
|
"@asteby/metacore-ui": "^2.34.0",
|
|
51
52
|
"@tanstack/react-query": ">=5",
|
|
52
53
|
"@tanstack/react-router": ">=1.100",
|
|
@@ -82,7 +83,7 @@
|
|
|
82
83
|
}
|
|
83
84
|
},
|
|
84
85
|
"devDependencies": {
|
|
85
|
-
"@asteby/metacore-sdk": "3.
|
|
86
|
+
"@asteby/metacore-sdk": "3.20.0",
|
|
86
87
|
"@asteby/metacore-ui": "2.34.0",
|
|
87
88
|
"@tanstack/react-query": "^5.95.0",
|
|
88
89
|
"@tanstack/react-router": "^1.168.0",
|
|
@@ -7,6 +7,7 @@ vi.mock('react-i18next', () => {
|
|
|
7
7
|
return { useTranslation: () => ({ t, i18n: { language: 'es', exists: () => false } }) }
|
|
8
8
|
})
|
|
9
9
|
|
|
10
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
10
11
|
import { GenUI } from '@asteby/metacore-genui'
|
|
11
12
|
import { ApiProvider } from '../api-context'
|
|
12
13
|
import { coerceSettings, registerGenUISettingsBlock, settingsToFields } from '../genui'
|
|
@@ -50,9 +51,11 @@ describe('genui settings block (pilot)', () => {
|
|
|
50
51
|
delete: vi.fn(),
|
|
51
52
|
}
|
|
52
53
|
render(
|
|
53
|
-
<
|
|
54
|
-
<
|
|
55
|
-
|
|
54
|
+
<QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}>
|
|
55
|
+
<ApiProvider client={client as never}>
|
|
56
|
+
<GenUI spec={{ version: 'genui/v2', blocks: [{ type: 'settings', addon: 'inventory', scope: 'org' }] }} />
|
|
57
|
+
</ApiProvider>
|
|
58
|
+
</QueryClientProvider>,
|
|
56
59
|
)
|
|
57
60
|
const lines = await screen.findByRole('spinbutton')
|
|
58
61
|
expect(screen.queryByText(/Token/)).toBeNull()
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import { cleanup, renderHook, waitFor } from '@testing-library/react'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import type { ReactNode } from 'react'
|
|
6
|
+
import { ApiProvider } from '../api-context'
|
|
7
|
+
import { InstalledAddonsProvider } from '../installed-addons-context'
|
|
8
|
+
import { useAddonSettings } from '../use-addon-settings'
|
|
9
|
+
import { useAddonInstalledProbe } from '../use-addon-installed-probe'
|
|
10
|
+
|
|
11
|
+
afterEach(cleanup)
|
|
12
|
+
|
|
13
|
+
function wrap(get: (url: string) => Promise<unknown>, installed?: string[]) {
|
|
14
|
+
const client = { get: vi.fn(get), post: vi.fn(), put: vi.fn(), delete: vi.fn() }
|
|
15
|
+
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
16
|
+
const W = ({ children }: { children: ReactNode }) => (
|
|
17
|
+
<QueryClientProvider client={qc}>
|
|
18
|
+
<ApiProvider client={client as never}>
|
|
19
|
+
{installed ? <InstalledAddonsProvider addons={installed}>{children}</InstalledAddonsProvider> : children}
|
|
20
|
+
</ApiProvider>
|
|
21
|
+
</QueryClientProvider>
|
|
22
|
+
)
|
|
23
|
+
return { W, client }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('useAddonSettings', () => {
|
|
27
|
+
it('merges defaults under stored values and exposes definitions/overrides', async () => {
|
|
28
|
+
const { W, client } = wrap(async () => ({ data: { success: true, data: { a: 5 }, definitions: [{ key: 'a' }], overrides: { a: 6 } } }))
|
|
29
|
+
const defaults = { a: 1, b: 2 }
|
|
30
|
+
const { result } = renderHook(() => useAddonSettings('pos', { defaults, branchId: 'b1' }), { wrapper: W })
|
|
31
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false))
|
|
32
|
+
expect(client.get).toHaveBeenCalledWith('/addons/pos/settings?branch_id=b1')
|
|
33
|
+
expect(result.current.settings).toEqual({ a: 5, b: 2 })
|
|
34
|
+
expect(result.current.stored).toEqual({ a: 5 })
|
|
35
|
+
expect(result.current.definitions).toEqual([{ key: 'a' }])
|
|
36
|
+
expect(result.current.overrides).toEqual({ a: 6 })
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('reload() fetches again and resolves with the payload', async () => {
|
|
40
|
+
const { W, client } = wrap(async () => ({ data: { data: { a: 1 } } }))
|
|
41
|
+
const { result } = renderHook(() => useAddonSettings('pos', { enabled: false }), { wrapper: W })
|
|
42
|
+
const payload = await result.current.reload()
|
|
43
|
+
expect(payload.values).toEqual({ a: 1 })
|
|
44
|
+
await result.current.reload()
|
|
45
|
+
expect(client.get).toHaveBeenCalledTimes(2)
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
describe('useAddonInstalledProbe', () => {
|
|
50
|
+
it('true on 2xx, false on 404, unknown on other errors', async () => {
|
|
51
|
+
const ok = wrap(async () => ({ data: {} }))
|
|
52
|
+
const r1 = renderHook(() => useAddonInstalledProbe('caja'), { wrapper: ok.W })
|
|
53
|
+
await waitFor(() => expect(r1.result.current.installed).toBe(true))
|
|
54
|
+
|
|
55
|
+
const nf = wrap(async () => Promise.reject({ response: { status: 404 } }))
|
|
56
|
+
const r2 = renderHook(() => useAddonInstalledProbe('caja'), { wrapper: nf.W })
|
|
57
|
+
await waitFor(() => expect(r2.result.current.installed).toBe(false))
|
|
58
|
+
|
|
59
|
+
const forbidden = wrap(async () => Promise.reject({ response: { status: 403 } }))
|
|
60
|
+
const r3 = renderHook(() => useAddonInstalledProbe('caja'), { wrapper: forbidden.W })
|
|
61
|
+
await waitFor(() => expect(r3.result.current.isLoading).toBe(false))
|
|
62
|
+
expect(r3.result.current.installed).toBeUndefined()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('answers from the provider without touching the network', () => {
|
|
66
|
+
const { W, client } = wrap(async () => ({ data: {} }), ['fiscal'])
|
|
67
|
+
const yes = renderHook(() => useAddonInstalledProbe('fiscal'), { wrapper: W })
|
|
68
|
+
const no = renderHook(() => useAddonInstalledProbe('caja'), { wrapper: W })
|
|
69
|
+
expect(yes.result.current.installed).toBe(true)
|
|
70
|
+
expect(no.result.current.installed).toBe(false)
|
|
71
|
+
expect(client.get).not.toHaveBeenCalled()
|
|
72
|
+
})
|
|
73
|
+
})
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// itself is a thin react-query wrapper over `useApi`; the load-bearing logic
|
|
5
5
|
// is this pure merge, so that's what we test directly.
|
|
6
6
|
import { describe, it, expect } from 'vitest'
|
|
7
|
-
import { mergeAddonSettings, addonSettingsKey, addonSettingsUrl } from '../use-addon-settings'
|
|
7
|
+
import { mergeAddonSettings, addonSettingsKey, addonSettingsUrl, parseAddonSettingsBody } from '../use-addon-settings'
|
|
8
8
|
|
|
9
9
|
interface PosSettings extends Record<string, unknown> {
|
|
10
10
|
allowNegativeStock: boolean
|
|
@@ -77,8 +77,8 @@ describe('branch-scoped settings (POS-1)', () => {
|
|
|
77
77
|
it('keys and urls carry the branch only when given', () => {
|
|
78
78
|
expect(addonSettingsKey('pos', 'b1')).toEqual(['addon-settings', 'pos', 'b1'])
|
|
79
79
|
expect(addonSettingsKey('pos', null)).toEqual(['addon-settings', 'pos'])
|
|
80
|
-
expect(addonSettingsUrl('pos')).toBe('/
|
|
81
|
-
expect(addonSettingsUrl('pos', 'b 1')).toBe('/
|
|
80
|
+
expect(addonSettingsUrl('pos')).toBe('/addons/pos/settings')
|
|
81
|
+
expect(addonSettingsUrl('pos', 'b 1')).toBe('/addons/pos/settings?branch_id=b%201')
|
|
82
82
|
})
|
|
83
83
|
|
|
84
84
|
it('an org-key prefix matches every branch read (invalidation)', () => {
|
|
@@ -87,3 +87,19 @@ describe('branch-scoped settings (POS-1)', () => {
|
|
|
87
87
|
expect(branch.slice(0, org.length)).toEqual([...org])
|
|
88
88
|
})
|
|
89
89
|
})
|
|
90
|
+
|
|
91
|
+
describe('parseAddonSettingsBody', () => {
|
|
92
|
+
it('reads values, definitions and overrides from the envelope', () => {
|
|
93
|
+
const defs = [{ key: 'a' }]
|
|
94
|
+
expect(parseAddonSettingsBody({ success: true, data: { a: 1 }, definitions: defs, overrides: { a: 2 } })).toEqual({
|
|
95
|
+
values: { a: 1 },
|
|
96
|
+
definitions: defs,
|
|
97
|
+
overrides: { a: 2 },
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
it('tolerates a missing data/definitions and a bare map', () => {
|
|
101
|
+
expect(parseAddonSettingsBody({ success: true })).toEqual({ values: {}, definitions: [], overrides: {} })
|
|
102
|
+
expect(parseAddonSettingsBody({ a: 1 })).toEqual({ values: { a: 1 }, definitions: [], overrides: {} })
|
|
103
|
+
expect(parseAddonSettingsBody(null)).toEqual({ values: {}, definitions: [], overrides: {} })
|
|
104
|
+
})
|
|
105
|
+
})
|
package/src/assist-interview.tsx
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// POST /assist/:provider/sessions { input } → Session
|
|
13
13
|
// GET /assist/:provider/sessions/:id → Session (poll while working)
|
|
14
14
|
// POST /assist/:provider/sessions/:id/reply { key, value } → Session
|
|
15
|
+
import { unwrapResponse } from '@asteby/metacore-lib/envelope'
|
|
15
16
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
16
17
|
import { Button, Input } from '@asteby/metacore-ui/primitives'
|
|
17
18
|
import { ArrowRight, Check, CheckCircle2, Loader2, RotateCcw, Sparkles, XCircle } from 'lucide-react'
|
|
@@ -81,11 +82,6 @@ export interface AssistInterviewProps {
|
|
|
81
82
|
const POLL_MS = 800
|
|
82
83
|
const THINKING_HINTS = ['Un momento…', 'Sigo trabajando…', 'Casi listo…']
|
|
83
84
|
|
|
84
|
-
function unwrap(res: any): AssistSession {
|
|
85
|
-
const d = res?.data?.data ?? res?.data ?? res
|
|
86
|
-
return d as AssistSession
|
|
87
|
-
}
|
|
88
|
-
|
|
89
85
|
function useTypewriter(text: string) {
|
|
90
86
|
const [n, setN] = useState(0)
|
|
91
87
|
const reduce = typeof window !== 'undefined' && !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
|
|
@@ -128,7 +124,7 @@ export function AssistInterview({ assist, values, onApply, autoStart = true, eye
|
|
|
128
124
|
answersRef.current = []
|
|
129
125
|
try {
|
|
130
126
|
const res = await api.post(base, { input: inputPayload })
|
|
131
|
-
setSession(
|
|
127
|
+
setSession(unwrapResponse<AssistSession>(res))
|
|
132
128
|
} catch (e: any) {
|
|
133
129
|
setError(e?.response?.data?.message || e?.message || 'No se pudo iniciar el asistente')
|
|
134
130
|
} finally {
|
|
@@ -149,7 +145,7 @@ export function AssistInterview({ assist, values, onApply, autoStart = true, eye
|
|
|
149
145
|
const t = setInterval(async () => {
|
|
150
146
|
try {
|
|
151
147
|
const res = await api.get(`${base}/${session.id}`)
|
|
152
|
-
setSession(
|
|
148
|
+
setSession(unwrapResponse<AssistSession>(res))
|
|
153
149
|
} catch (e: any) {
|
|
154
150
|
if (isGone(e)) {
|
|
155
151
|
try {
|
|
@@ -190,15 +186,15 @@ export function AssistInterview({ assist, values, onApply, autoStart = true, eye
|
|
|
190
186
|
// Recreate the session and replay every answer (host lost it).
|
|
191
187
|
const recover = useCallback(async () => {
|
|
192
188
|
const res = await api.post(base, { input: inputPayload })
|
|
193
|
-
let s =
|
|
189
|
+
let s = unwrapResponse<AssistSession>(res)
|
|
194
190
|
for (const a of answersRef.current) {
|
|
195
191
|
// wait until the provider is ready for the next answer
|
|
196
192
|
for (let i = 0; i < 120 && s.working && !s.done; i++) {
|
|
197
193
|
await new Promise(r => setTimeout(r, POLL_MS))
|
|
198
|
-
s =
|
|
194
|
+
s = unwrapResponse<AssistSession>(await api.get(`${base}/${s.id}`))
|
|
199
195
|
}
|
|
200
196
|
if (s.done) break
|
|
201
|
-
s =
|
|
197
|
+
s = unwrapResponse<AssistSession>(await api.post(`${base}/${s.id}/reply`, { key: a.key, value: a.value }))
|
|
202
198
|
}
|
|
203
199
|
return s
|
|
204
200
|
}, [api, base, inputPayload])
|
|
@@ -212,7 +208,7 @@ export function AssistInterview({ assist, values, onApply, autoStart = true, eye
|
|
|
212
208
|
try {
|
|
213
209
|
const res = await api.post(`${base}/${session.id}/reply`, { key, value })
|
|
214
210
|
answersRef.current = [...answersRef.current, { key, value }]
|
|
215
|
-
setSession(
|
|
211
|
+
setSession(unwrapResponse<AssistSession>(res))
|
|
216
212
|
} catch (e: any) {
|
|
217
213
|
if (isGone(e)) {
|
|
218
214
|
try {
|
package/src/custom-stages.tsx
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
// or errors the hook reports `available: false`, the "+ Agregar etapa" column
|
|
18
18
|
// and the lane context menus simply don't render, and the board keeps working.
|
|
19
19
|
// All UI text goes through t() with a Spanish defaultValue.
|
|
20
|
+
import { unwrapResponse } from '@asteby/metacore-lib/envelope'
|
|
20
21
|
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
|
21
22
|
import { useTranslation } from 'react-i18next'
|
|
22
23
|
import { Plus, Trash2, Pencil, MoreVertical, Filter, Flag, GripVertical, Lock, RotateCcw, X } from 'lucide-react'
|
|
@@ -310,12 +311,6 @@ export function slugifyStageKey(label: string): string {
|
|
|
310
311
|
// Data hook
|
|
311
312
|
// ---------------------------------------------------------------------------
|
|
312
313
|
|
|
313
|
-
function unwrap(res: { data: any }): any {
|
|
314
|
-
const body = res?.data
|
|
315
|
-
if (body && typeof body === 'object' && 'data' in body) return body.data
|
|
316
|
-
return body
|
|
317
|
-
}
|
|
318
|
-
|
|
319
314
|
export interface UseCustomStagesResult {
|
|
320
315
|
/** False when the endpoint is missing/errored — hide the whole feature. */
|
|
321
316
|
available: boolean
|
|
@@ -351,7 +346,7 @@ export function useCustomStages(model: string): UseCustomStagesResult {
|
|
|
351
346
|
const res = await api.get(
|
|
352
347
|
`/custom-stages?model=${encodeURIComponent(model)}`,
|
|
353
348
|
)
|
|
354
|
-
const data =
|
|
349
|
+
const data = unwrapResponse<any>(res)
|
|
355
350
|
setStages(Array.isArray(data) ? data : [])
|
|
356
351
|
setAvailable(true)
|
|
357
352
|
} catch {
|