@open-mercato/upgrade-actions 0.0.0-stage → 0.11.1-develop.8805.1.6357054d1a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -2
- package/dist/index.js +5 -0
- package/dist/index.js.map +7 -0
- package/dist/modules/upgrade_actions/api/contract.js +13 -0
- package/dist/modules/upgrade_actions/api/contract.js.map +7 -0
- package/dist/modules/upgrade_actions/components/UpgradeActionBanner.js +118 -0
- package/dist/modules/upgrade_actions/components/UpgradeActionBanner.js.map +7 -0
- package/dist/modules/upgrade_actions/index.js +13 -0
- package/dist/modules/upgrade_actions/index.js.map +7 -0
- package/dist/modules/upgrade_actions/widgets/injection/banner/widget.js +20 -0
- package/dist/modules/upgrade_actions/widgets/injection/banner/widget.js.map +7 -0
- package/dist/modules/upgrade_actions/widgets/injection-table.js +11 -0
- package/dist/modules/upgrade_actions/widgets/injection-table.js.map +7 -0
- package/package.json +65 -3
- package/src/index.ts +1 -0
- package/src/modules/upgrade_actions/api/contract.ts +6 -0
- package/src/modules/upgrade_actions/components/UpgradeActionBanner.tsx +156 -0
- package/src/modules/upgrade_actions/index.ts +11 -0
- package/src/modules/upgrade_actions/widgets/injection/banner/widget.tsx +22 -0
- package/src/modules/upgrade_actions/widgets/injection-table.ts +10 -0
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Upgrade actions
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This optional Open Mercato module displays the first pending release action to backoffice operators with `configs.manage`. Applying an action records completion in the existing tenant and organization history.
|
|
4
|
+
|
|
5
|
+
## Enable
|
|
6
|
+
|
|
7
|
+
Install the package at the same version as the rest of Open Mercato:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
yarn add @open-mercato/upgrade-actions
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Register it in the app's `src/modules.ts` with `configs` and `directory` enabled:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
{ id: 'upgrade_actions', from: '@open-mercato/upgrade-actions' },
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Set `UPGRADE_ACTIONS_ENABLED=true` to enable the server handler. Set `NEXT_PUBLIC_UPGRADE_ACTIONS_ENABLED=true` in the app's build environment to show the banner. Run `yarn generate` and rebuild the app.
|
|
20
|
+
|
|
21
|
+
The module mounts the banner in the backoffice layout. Remove any manually mounted legacy banner when enabling the module. During the compatibility bridge, Configs continues to serve both methods at `/api/configs/upgrade-actions` for existing clients. The HTTP route keeps the existing permissions and completion records, so activation does not require a data migration. The route transfer follows after at least one minor release.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
upgradeActionSchema,
|
|
3
|
+
upgradeActionsListResponseSchema,
|
|
4
|
+
executeUpgradeActionRequestSchema,
|
|
5
|
+
executeUpgradeActionResponseSchema
|
|
6
|
+
} from "@open-mercato/core/modules/configs/lib/upgrade-actions-contract";
|
|
7
|
+
export {
|
|
8
|
+
executeUpgradeActionRequestSchema,
|
|
9
|
+
executeUpgradeActionResponseSchema,
|
|
10
|
+
upgradeActionSchema,
|
|
11
|
+
upgradeActionsListResponseSchema
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/upgrade_actions/api/contract.ts"],
|
|
4
|
+
"sourcesContent": ["export {\n upgradeActionSchema,\n upgradeActionsListResponseSchema,\n executeUpgradeActionRequestSchema,\n executeUpgradeActionResponseSchema,\n} from '@open-mercato/core/modules/configs/lib/upgrade-actions-contract'\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Sparkles } from "lucide-react";
|
|
5
|
+
import { Button } from "@open-mercato/ui/primitives/button";
|
|
6
|
+
import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
|
|
7
|
+
import { useGuardedMutation } from "@open-mercato/ui/backend/injection/useGuardedMutation";
|
|
8
|
+
import { flash } from "@open-mercato/ui/backend/FlashMessages";
|
|
9
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
10
|
+
import { useBackendChrome } from "@open-mercato/ui/backend/BackendChromeProvider";
|
|
11
|
+
import { hasFeature } from "@open-mercato/shared/security/features";
|
|
12
|
+
function upgradeActionsEnabled() {
|
|
13
|
+
return process.env.NEXT_PUBLIC_UPGRADE_ACTIONS_ENABLED === "true" || process.env.UPGRADE_ACTIONS_ENABLED === "true";
|
|
14
|
+
}
|
|
15
|
+
const mutationContextId = "upgrade-action-banner";
|
|
16
|
+
const forbiddenRedirectOptOutHeader = { "x-om-forbidden-redirect": "0" };
|
|
17
|
+
function UpgradeActionBanner() {
|
|
18
|
+
const t = useT();
|
|
19
|
+
const { payload, isReady } = useBackendChrome();
|
|
20
|
+
const canManageConfigs = isReady && hasFeature(payload?.grantedFeatures, "configs.manage");
|
|
21
|
+
const [action, setAction] = React.useState(null);
|
|
22
|
+
const [loading, setLoading] = React.useState(false);
|
|
23
|
+
const cancelledRef = React.useRef(false);
|
|
24
|
+
const applyingRef = React.useRef(false);
|
|
25
|
+
const { runMutation, retryLastMutation } = useGuardedMutation({
|
|
26
|
+
contextId: mutationContextId,
|
|
27
|
+
enabled: canManageConfigs && upgradeActionsEnabled()
|
|
28
|
+
});
|
|
29
|
+
const loadNextAction = React.useCallback(async () => {
|
|
30
|
+
if (!canManageConfigs) return;
|
|
31
|
+
if (!upgradeActionsEnabled()) return;
|
|
32
|
+
if (typeof window === "undefined" || typeof fetch === "undefined") return;
|
|
33
|
+
const call = await apiCall("/api/configs/upgrade-actions", {
|
|
34
|
+
headers: forbiddenRedirectOptOutHeader
|
|
35
|
+
});
|
|
36
|
+
if (cancelledRef.current) return;
|
|
37
|
+
if (!call.ok || !call.result || !Array.isArray(call.result.actions) || !call.result.actions.length) {
|
|
38
|
+
setAction(null);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
setAction(call.result.actions[0]);
|
|
42
|
+
}, [canManageConfigs]);
|
|
43
|
+
React.useEffect(() => {
|
|
44
|
+
cancelledRef.current = false;
|
|
45
|
+
void loadNextAction();
|
|
46
|
+
return () => {
|
|
47
|
+
cancelledRef.current = true;
|
|
48
|
+
};
|
|
49
|
+
}, [loadNextAction]);
|
|
50
|
+
if (!upgradeActionsEnabled() || !canManageConfigs || !action) return null;
|
|
51
|
+
async function handleRun() {
|
|
52
|
+
if (!upgradeActionsEnabled() || !action || applyingRef.current) return;
|
|
53
|
+
applyingRef.current = true;
|
|
54
|
+
setLoading(true);
|
|
55
|
+
try {
|
|
56
|
+
const mutationPayload = { actionId: action.id };
|
|
57
|
+
const response = await runMutation({
|
|
58
|
+
context: { formId: mutationContextId, resourceKind: "upgrade_actions.action", retryLastMutation },
|
|
59
|
+
mutationPayload,
|
|
60
|
+
operation: async () => {
|
|
61
|
+
const call = await apiCall("/api/configs/upgrade-actions", {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: { ...forbiddenRedirectOptOutHeader, "Content-Type": "application/json" },
|
|
64
|
+
body: JSON.stringify(mutationPayload)
|
|
65
|
+
});
|
|
66
|
+
if (!call.ok) {
|
|
67
|
+
const baseError = call.result?.error || t("upgrades.runFailed", "We could not run this upgrade action.");
|
|
68
|
+
const detail = typeof call.result?.details === "string" ? call.result.details : null;
|
|
69
|
+
throw new Error(detail ? `${baseError} (${detail})` : baseError);
|
|
70
|
+
}
|
|
71
|
+
return call.result;
|
|
72
|
+
},
|
|
73
|
+
onSuccess: async () => {
|
|
74
|
+
setAction(null);
|
|
75
|
+
await loadNextAction();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
const message = response?.message || action.successMessage || t("upgrades.v034.success", "Example catalog products and categories installed.");
|
|
79
|
+
flash(message, "success");
|
|
80
|
+
} catch (error) {
|
|
81
|
+
const message = error instanceof Error ? error.message : t("upgrades.runFailed", "We could not run this upgrade action.");
|
|
82
|
+
flash(message, "error");
|
|
83
|
+
} finally {
|
|
84
|
+
applyingRef.current = false;
|
|
85
|
+
setLoading(false);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const loadingLabel = action.loadingLabel || t("upgrades.v034.loading", "Installing\u2026");
|
|
89
|
+
const title = action.ctaLabel || action.message;
|
|
90
|
+
const description = action.message && action.message !== title ? action.message : null;
|
|
91
|
+
return /* @__PURE__ */ jsxs("div", { className: "mb-4 flex flex-col gap-3 rounded-md border border-status-warning-border bg-status-warning-bg px-3 py-3 text-sm text-status-warning-text md:flex-row md:items-center md:justify-between", children: [
|
|
92
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2 text-sm", children: [
|
|
93
|
+
/* @__PURE__ */ jsx(Sparkles, { className: "mt-0.5 size-4 text-status-warning-icon", "aria-hidden": "true" }),
|
|
94
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
95
|
+
/* @__PURE__ */ jsx("div", { className: "font-medium text-status-warning-text", children: title }),
|
|
96
|
+
description ? /* @__PURE__ */ jsx("div", { className: "text-xs text-status-warning-text", children: description }) : null,
|
|
97
|
+
/* @__PURE__ */ jsx("div", { className: "text-xs text-status-warning-text", children: t("upgrades.versionLabel", { version: action.version }) })
|
|
98
|
+
] })
|
|
99
|
+
] }),
|
|
100
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap items-center gap-2", children: /* @__PURE__ */ jsx(
|
|
101
|
+
Button,
|
|
102
|
+
{
|
|
103
|
+
variant: "outline",
|
|
104
|
+
size: "sm",
|
|
105
|
+
onClick: () => {
|
|
106
|
+
void handleRun();
|
|
107
|
+
},
|
|
108
|
+
disabled: loading,
|
|
109
|
+
className: "border-status-warning-border text-status-warning-text hover:bg-status-warning-bg",
|
|
110
|
+
children: loading ? loadingLabel : action.ctaLabel
|
|
111
|
+
}
|
|
112
|
+
) })
|
|
113
|
+
] });
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
UpgradeActionBanner
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=UpgradeActionBanner.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/upgrade_actions/components/UpgradeActionBanner.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport { Sparkles } from 'lucide-react'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { useBackendChrome } from '@open-mercato/ui/backend/BackendChromeProvider'\nimport { hasFeature } from '@open-mercato/shared/security/features'\n\nfunction upgradeActionsEnabled() {\n return (\n process.env.NEXT_PUBLIC_UPGRADE_ACTIONS_ENABLED === 'true' ||\n process.env.UPGRADE_ACTIONS_ENABLED === 'true'\n )\n}\n\ntype UpgradeActionPayload = {\n id: string\n version: string\n message: string\n ctaLabel: string\n successMessage?: string\n loadingLabel?: string\n}\n\ntype UpgradeActionResponse = {\n version: string\n actions?: UpgradeActionPayload[]\n error?: string\n}\n\ntype RunActionResponse = {\n status?: 'completed' | 'already_completed'\n message?: string\n error?: string\n details?: unknown\n}\n\nconst mutationContextId = 'upgrade-action-banner'\nconst forbiddenRedirectOptOutHeader = { 'x-om-forbidden-redirect': '0' } as const\n\nexport function UpgradeActionBanner() {\n const t = useT()\n const { payload, isReady } = useBackendChrome()\n const canManageConfigs = isReady && hasFeature(payload?.grantedFeatures, 'configs.manage')\n const [action, setAction] = React.useState<UpgradeActionPayload | null>(null)\n const [loading, setLoading] = React.useState(false)\n const cancelledRef = React.useRef(false)\n const applyingRef = React.useRef(false)\n const { runMutation, retryLastMutation } = useGuardedMutation({\n contextId: mutationContextId,\n enabled: canManageConfigs && upgradeActionsEnabled(),\n })\n\n const loadNextAction = React.useCallback(async () => {\n if (!canManageConfigs) return\n if (!upgradeActionsEnabled()) return\n if (typeof window === 'undefined' || typeof fetch === 'undefined') return\n const call = await apiCall<UpgradeActionResponse>('/api/configs/upgrade-actions', {\n headers: forbiddenRedirectOptOutHeader,\n })\n if (cancelledRef.current) return\n if (!call.ok || !call.result || !Array.isArray(call.result.actions) || !call.result.actions.length) {\n setAction(null)\n return\n }\n setAction(call.result.actions[0]!)\n }, [canManageConfigs])\n\n React.useEffect(() => {\n cancelledRef.current = false\n void loadNextAction()\n return () => {\n cancelledRef.current = true\n }\n }, [loadNextAction])\n\n if (!upgradeActionsEnabled() || !canManageConfigs || !action) return null\n\n async function handleRun() {\n if (!upgradeActionsEnabled() || !action || applyingRef.current) return\n applyingRef.current = true\n setLoading(true)\n try {\n const mutationPayload = { actionId: action.id }\n const response = await runMutation({\n context: { formId: mutationContextId, resourceKind: 'upgrade_actions.action', retryLastMutation },\n mutationPayload,\n operation: async () => {\n const call = await apiCall<RunActionResponse>('/api/configs/upgrade-actions', {\n method: 'POST',\n headers: { ...forbiddenRedirectOptOutHeader, 'Content-Type': 'application/json' },\n body: JSON.stringify(mutationPayload),\n })\n if (!call.ok) {\n const baseError = call.result?.error || t('upgrades.runFailed', 'We could not run this upgrade action.')\n const detail = typeof call.result?.details === 'string' ? call.result.details : null\n throw new Error(detail ? `${baseError} (${detail})` : baseError)\n }\n return call.result\n },\n onSuccess: async () => {\n setAction(null)\n await loadNextAction()\n },\n })\n const message =\n response?.message ||\n action.successMessage ||\n t('upgrades.v034.success', 'Example catalog products and categories installed.')\n flash(message, 'success')\n } catch (error) {\n const message = error instanceof Error ? error.message : t('upgrades.runFailed', 'We could not run this upgrade action.')\n flash(message, 'error')\n } finally {\n applyingRef.current = false\n setLoading(false)\n }\n }\n\n const loadingLabel = action.loadingLabel || t('upgrades.v034.loading', 'Installing\u2026')\n const title = action.ctaLabel || action.message\n const description = action.message && action.message !== title ? action.message : null\n\n return (\n <div className=\"mb-4 flex flex-col gap-3 rounded-md border border-status-warning-border bg-status-warning-bg px-3 py-3 text-sm text-status-warning-text md:flex-row md:items-center md:justify-between\">\n <div className=\"flex items-start gap-2 text-sm\">\n <Sparkles className=\"mt-0.5 size-4 text-status-warning-icon\" aria-hidden=\"true\" />\n <div className=\"flex flex-col gap-1\">\n <div className=\"font-medium text-status-warning-text\">\n {title}\n </div>\n {description ? (\n <div className=\"text-xs text-status-warning-text\">\n {description}\n </div>\n ) : null}\n <div className=\"text-xs text-status-warning-text\">{t('upgrades.versionLabel', { version: action.version })}</div>\n </div>\n </div>\n <div className=\"flex flex-wrap items-center gap-2\">\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={() => { void handleRun() }}\n disabled={loading}\n className=\"border-status-warning-border text-status-warning-text hover:bg-status-warning-bg\"\n >\n {loading ? loadingLabel : action.ctaLabel}\n </Button>\n </div>\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAiIQ,cACA,YADA;AAhIR,YAAY,WAAW;AACvB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,0BAA0B;AACnC,SAAS,aAAa;AACtB,SAAS,YAAY;AACrB,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAE3B,SAAS,wBAAwB;AAC/B,SACE,QAAQ,IAAI,wCAAwC,UACpD,QAAQ,IAAI,4BAA4B;AAE5C;AAwBA,MAAM,oBAAoB;AAC1B,MAAM,gCAAgC,EAAE,2BAA2B,IAAI;AAEhE,SAAS,sBAAsB;AACpC,QAAM,IAAI,KAAK;AACf,QAAM,EAA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,qBAAC,SAAI,WAAU,uBACb;AAAA,4BAAC,SAAI,WAAU,wCACZ,iBACH;AAAA,QACC,cACC,oBAAC,SAAI,WAAU,oCACZ,uBACH,IACE;AAAA,QACJ,oBAAC,SAAI,WAAU,oCAAoC,YAAE,yBAAyB,EAAE,SAAS,OAAO,QAAQ,CAAC,GAAE;AAAA,SAC7G;AAAA,OACF;AAAA,IACA,oBAAC,SAAI,WAAU,qCACb;AAAA,MAAC;AAAA;AAAA,QACC,SAAQ;AAAA,QACR,MAAK;AAAA,QACL,SAAS,MAAM;AAAE,eAAK,UAAU;AAAA,QAAE;AAAA,QAClC,UAAU;AAAA,QACV,WAAU;AAAA,QAET,oBAAU,eAAe,OAAO;AAAA;AAAA,IACnC,GACF;AAAA,KACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const metadata = {
|
|
2
|
+
name: "upgrade_actions",
|
|
3
|
+
title: "Upgrade actions",
|
|
4
|
+
version: "0.1.0",
|
|
5
|
+
description: "Shows and applies pending release upgrade actions in the backoffice.",
|
|
6
|
+
author: "Open Mercato Team",
|
|
7
|
+
license: "MIT",
|
|
8
|
+
requires: ["configs", "directory"]
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
metadata
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/modules/upgrade_actions/index.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ModuleInfo } from '@open-mercato/shared/modules/registry'\n\nexport const metadata: ModuleInfo = {\n name: 'upgrade_actions',\n title: 'Upgrade actions',\n version: '0.1.0',\n description: 'Shows and applies pending release upgrade actions in the backoffice.',\n author: 'Open Mercato Team',\n license: 'MIT',\n requires: ['configs', 'directory'],\n}\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,WAAuB;AAAA,EAClC,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SAAS;AAAA,EACT,aAAa;AAAA,EACb,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU,CAAC,WAAW,WAAW;AACnC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { UpgradeActionBanner } from "../../../components/UpgradeActionBanner.js";
|
|
4
|
+
function UpgradeActionBannerWidget({ context }) {
|
|
5
|
+
if (context?.canManageUpgradeActions === false) return null;
|
|
6
|
+
return /* @__PURE__ */ jsx(UpgradeActionBanner, {});
|
|
7
|
+
}
|
|
8
|
+
const widget = {
|
|
9
|
+
metadata: {
|
|
10
|
+
id: "upgrade_actions.injection.banner",
|
|
11
|
+
title: "Upgrade action banner",
|
|
12
|
+
features: ["configs.manage"]
|
|
13
|
+
},
|
|
14
|
+
Widget: UpgradeActionBannerWidget
|
|
15
|
+
};
|
|
16
|
+
var widget_default = widget;
|
|
17
|
+
export {
|
|
18
|
+
widget_default as default
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=widget.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/modules/upgrade_actions/widgets/injection/banner/widget.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport type { InjectionWidgetModule } from '@open-mercato/shared/modules/widgets/injection'\nimport { UpgradeActionBanner } from '../../../components/UpgradeActionBanner'\n\ntype LayoutContext = { canManageUpgradeActions?: boolean }\n\nfunction UpgradeActionBannerWidget({ context }: { context: LayoutContext }) {\n if (context?.canManageUpgradeActions === false) return null\n return <UpgradeActionBanner />\n}\n\nconst widget: InjectionWidgetModule<LayoutContext> = {\n metadata: {\n id: 'upgrade_actions.injection.banner',\n title: 'Upgrade action banner',\n features: ['configs.manage'],\n },\n Widget: UpgradeActionBannerWidget,\n}\n\nexport default widget\n"],
|
|
5
|
+
"mappings": ";AASS;AANT,SAAS,2BAA2B;AAIpC,SAAS,0BAA0B,EAAE,QAAQ,GAA+B;AAC1E,MAAI,SAAS,4BAA4B,MAAO,QAAO;AACvD,SAAO,oBAAC,uBAAoB;AAC9B;AAEA,MAAM,SAA+C;AAAA,EACnD,UAAU;AAAA,IACR,IAAI;AAAA,IACJ,OAAO;AAAA,IACP,UAAU,CAAC,gBAAgB;AAAA,EAC7B;AAAA,EACA,QAAQ;AACV;AAEA,IAAO,iBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const banner = { widgetId: "upgrade_actions.injection.banner" };
|
|
2
|
+
const injectionTable = {
|
|
3
|
+
"backend:layout:top": [banner],
|
|
4
|
+
"backend:upgrade-actions:legacy-banner": [banner]
|
|
5
|
+
};
|
|
6
|
+
var injection_table_default = injectionTable;
|
|
7
|
+
export {
|
|
8
|
+
injection_table_default as default,
|
|
9
|
+
injectionTable
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=injection-table.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/upgrade_actions/widgets/injection-table.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ModuleInjectionTable } from '@open-mercato/shared/modules/widgets/injection'\n\nconst banner = { widgetId: 'upgrade_actions.injection.banner' }\n\nexport const injectionTable: ModuleInjectionTable = {\n 'backend:layout:top': [banner],\n 'backend:upgrade-actions:legacy-banner': [banner],\n}\n\nexport default injectionTable\n"],
|
|
5
|
+
"mappings": "AAEA,MAAM,SAAS,EAAE,UAAU,mCAAmC;AAEvD,MAAM,iBAAuC;AAAA,EAClD,sBAAsB,CAAC,MAAM;AAAA,EAC7B,yCAAyC,CAAC,MAAM;AAClD;AAEA,IAAO,0BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/upgrade-actions",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.11.1-develop.8805.1.6357054d1a",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"src",
|
|
10
|
+
"!src/**/__tests__"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "node build.mjs",
|
|
14
|
+
"watch": "node build.mjs --watch",
|
|
15
|
+
"test": "jest --config jest.config.cjs",
|
|
16
|
+
"typecheck": "tsc --noEmit"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./src/index.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./*.json": "./src/*.json",
|
|
24
|
+
"./*": {
|
|
25
|
+
"types": [
|
|
26
|
+
"./src/*.ts",
|
|
27
|
+
"./src/*.tsx"
|
|
28
|
+
],
|
|
29
|
+
"default": "./dist/*.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@open-mercato/core": "0.11.1-develop.8805.1.6357054d1a",
|
|
34
|
+
"@open-mercato/ui": "0.11.1-develop.8805.1.6357054d1a",
|
|
35
|
+
"lucide-react": "^1.34.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@open-mercato/ai-assistant": "0.11.1-develop.8805.1.6357054d1a",
|
|
39
|
+
"@open-mercato/shared": "0.11.1-develop.8805.1.6357054d1a",
|
|
40
|
+
"react": "^19.0.0",
|
|
41
|
+
"react-dom": "^19.0.0",
|
|
42
|
+
"react-is": ">=18.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@open-mercato/ai-assistant": "0.11.1-develop.8805.1.6357054d1a",
|
|
46
|
+
"@open-mercato/shared": "0.11.1-develop.8805.1.6357054d1a",
|
|
47
|
+
"@testing-library/dom": "^10.4.1",
|
|
48
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
49
|
+
"@testing-library/react": "^16.3.3",
|
|
50
|
+
"@types/jest": "^30.0.0",
|
|
51
|
+
"@types/react": "^19.2.18",
|
|
52
|
+
"jest": "^30.4.2",
|
|
53
|
+
"jest-environment-jsdom": "^30.4.1",
|
|
54
|
+
"react": "19.2.8",
|
|
55
|
+
"react-dom": "19.2.8",
|
|
56
|
+
"react-is": "^19.2.8",
|
|
57
|
+
"typescript": "7.0.2"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
},
|
|
62
|
+
"repository": {
|
|
63
|
+
"type": "git",
|
|
64
|
+
"url": "https://github.com/open-mercato/open-mercato",
|
|
65
|
+
"directory": "packages/upgrade-actions"
|
|
66
|
+
},
|
|
67
|
+
"stableVersion": "0.11.0"
|
|
6
68
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { metadata } from './modules/upgrade_actions'
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { Sparkles } from 'lucide-react'
|
|
4
|
+
import { Button } from '@open-mercato/ui/primitives/button'
|
|
5
|
+
import { apiCall } from '@open-mercato/ui/backend/utils/apiCall'
|
|
6
|
+
import { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'
|
|
7
|
+
import { flash } from '@open-mercato/ui/backend/FlashMessages'
|
|
8
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
9
|
+
import { useBackendChrome } from '@open-mercato/ui/backend/BackendChromeProvider'
|
|
10
|
+
import { hasFeature } from '@open-mercato/shared/security/features'
|
|
11
|
+
|
|
12
|
+
function upgradeActionsEnabled() {
|
|
13
|
+
return (
|
|
14
|
+
process.env.NEXT_PUBLIC_UPGRADE_ACTIONS_ENABLED === 'true' ||
|
|
15
|
+
process.env.UPGRADE_ACTIONS_ENABLED === 'true'
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type UpgradeActionPayload = {
|
|
20
|
+
id: string
|
|
21
|
+
version: string
|
|
22
|
+
message: string
|
|
23
|
+
ctaLabel: string
|
|
24
|
+
successMessage?: string
|
|
25
|
+
loadingLabel?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type UpgradeActionResponse = {
|
|
29
|
+
version: string
|
|
30
|
+
actions?: UpgradeActionPayload[]
|
|
31
|
+
error?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type RunActionResponse = {
|
|
35
|
+
status?: 'completed' | 'already_completed'
|
|
36
|
+
message?: string
|
|
37
|
+
error?: string
|
|
38
|
+
details?: unknown
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const mutationContextId = 'upgrade-action-banner'
|
|
42
|
+
const forbiddenRedirectOptOutHeader = { 'x-om-forbidden-redirect': '0' } as const
|
|
43
|
+
|
|
44
|
+
export function UpgradeActionBanner() {
|
|
45
|
+
const t = useT()
|
|
46
|
+
const { payload, isReady } = useBackendChrome()
|
|
47
|
+
const canManageConfigs = isReady && hasFeature(payload?.grantedFeatures, 'configs.manage')
|
|
48
|
+
const [action, setAction] = React.useState<UpgradeActionPayload | null>(null)
|
|
49
|
+
const [loading, setLoading] = React.useState(false)
|
|
50
|
+
const cancelledRef = React.useRef(false)
|
|
51
|
+
const applyingRef = React.useRef(false)
|
|
52
|
+
const { runMutation, retryLastMutation } = useGuardedMutation({
|
|
53
|
+
contextId: mutationContextId,
|
|
54
|
+
enabled: canManageConfigs && upgradeActionsEnabled(),
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const loadNextAction = React.useCallback(async () => {
|
|
58
|
+
if (!canManageConfigs) return
|
|
59
|
+
if (!upgradeActionsEnabled()) return
|
|
60
|
+
if (typeof window === 'undefined' || typeof fetch === 'undefined') return
|
|
61
|
+
const call = await apiCall<UpgradeActionResponse>('/api/configs/upgrade-actions', {
|
|
62
|
+
headers: forbiddenRedirectOptOutHeader,
|
|
63
|
+
})
|
|
64
|
+
if (cancelledRef.current) return
|
|
65
|
+
if (!call.ok || !call.result || !Array.isArray(call.result.actions) || !call.result.actions.length) {
|
|
66
|
+
setAction(null)
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
setAction(call.result.actions[0]!)
|
|
70
|
+
}, [canManageConfigs])
|
|
71
|
+
|
|
72
|
+
React.useEffect(() => {
|
|
73
|
+
cancelledRef.current = false
|
|
74
|
+
void loadNextAction()
|
|
75
|
+
return () => {
|
|
76
|
+
cancelledRef.current = true
|
|
77
|
+
}
|
|
78
|
+
}, [loadNextAction])
|
|
79
|
+
|
|
80
|
+
if (!upgradeActionsEnabled() || !canManageConfigs || !action) return null
|
|
81
|
+
|
|
82
|
+
async function handleRun() {
|
|
83
|
+
if (!upgradeActionsEnabled() || !action || applyingRef.current) return
|
|
84
|
+
applyingRef.current = true
|
|
85
|
+
setLoading(true)
|
|
86
|
+
try {
|
|
87
|
+
const mutationPayload = { actionId: action.id }
|
|
88
|
+
const response = await runMutation({
|
|
89
|
+
context: { formId: mutationContextId, resourceKind: 'upgrade_actions.action', retryLastMutation },
|
|
90
|
+
mutationPayload,
|
|
91
|
+
operation: async () => {
|
|
92
|
+
const call = await apiCall<RunActionResponse>('/api/configs/upgrade-actions', {
|
|
93
|
+
method: 'POST',
|
|
94
|
+
headers: { ...forbiddenRedirectOptOutHeader, 'Content-Type': 'application/json' },
|
|
95
|
+
body: JSON.stringify(mutationPayload),
|
|
96
|
+
})
|
|
97
|
+
if (!call.ok) {
|
|
98
|
+
const baseError = call.result?.error || t('upgrades.runFailed', 'We could not run this upgrade action.')
|
|
99
|
+
const detail = typeof call.result?.details === 'string' ? call.result.details : null
|
|
100
|
+
throw new Error(detail ? `${baseError} (${detail})` : baseError)
|
|
101
|
+
}
|
|
102
|
+
return call.result
|
|
103
|
+
},
|
|
104
|
+
onSuccess: async () => {
|
|
105
|
+
setAction(null)
|
|
106
|
+
await loadNextAction()
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
const message =
|
|
110
|
+
response?.message ||
|
|
111
|
+
action.successMessage ||
|
|
112
|
+
t('upgrades.v034.success', 'Example catalog products and categories installed.')
|
|
113
|
+
flash(message, 'success')
|
|
114
|
+
} catch (error) {
|
|
115
|
+
const message = error instanceof Error ? error.message : t('upgrades.runFailed', 'We could not run this upgrade action.')
|
|
116
|
+
flash(message, 'error')
|
|
117
|
+
} finally {
|
|
118
|
+
applyingRef.current = false
|
|
119
|
+
setLoading(false)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const loadingLabel = action.loadingLabel || t('upgrades.v034.loading', 'Installing…')
|
|
124
|
+
const title = action.ctaLabel || action.message
|
|
125
|
+
const description = action.message && action.message !== title ? action.message : null
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<div className="mb-4 flex flex-col gap-3 rounded-md border border-status-warning-border bg-status-warning-bg px-3 py-3 text-sm text-status-warning-text md:flex-row md:items-center md:justify-between">
|
|
129
|
+
<div className="flex items-start gap-2 text-sm">
|
|
130
|
+
<Sparkles className="mt-0.5 size-4 text-status-warning-icon" aria-hidden="true" />
|
|
131
|
+
<div className="flex flex-col gap-1">
|
|
132
|
+
<div className="font-medium text-status-warning-text">
|
|
133
|
+
{title}
|
|
134
|
+
</div>
|
|
135
|
+
{description ? (
|
|
136
|
+
<div className="text-xs text-status-warning-text">
|
|
137
|
+
{description}
|
|
138
|
+
</div>
|
|
139
|
+
) : null}
|
|
140
|
+
<div className="text-xs text-status-warning-text">{t('upgrades.versionLabel', { version: action.version })}</div>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
144
|
+
<Button
|
|
145
|
+
variant="outline"
|
|
146
|
+
size="sm"
|
|
147
|
+
onClick={() => { void handleRun() }}
|
|
148
|
+
disabled={loading}
|
|
149
|
+
className="border-status-warning-border text-status-warning-text hover:bg-status-warning-bg"
|
|
150
|
+
>
|
|
151
|
+
{loading ? loadingLabel : action.ctaLabel}
|
|
152
|
+
</Button>
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ModuleInfo } from '@open-mercato/shared/modules/registry'
|
|
2
|
+
|
|
3
|
+
export const metadata: ModuleInfo = {
|
|
4
|
+
name: 'upgrade_actions',
|
|
5
|
+
title: 'Upgrade actions',
|
|
6
|
+
version: '0.1.0',
|
|
7
|
+
description: 'Shows and applies pending release upgrade actions in the backoffice.',
|
|
8
|
+
author: 'Open Mercato Team',
|
|
9
|
+
license: 'MIT',
|
|
10
|
+
requires: ['configs', 'directory'],
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import type { InjectionWidgetModule } from '@open-mercato/shared/modules/widgets/injection'
|
|
4
|
+
import { UpgradeActionBanner } from '../../../components/UpgradeActionBanner'
|
|
5
|
+
|
|
6
|
+
type LayoutContext = { canManageUpgradeActions?: boolean }
|
|
7
|
+
|
|
8
|
+
function UpgradeActionBannerWidget({ context }: { context: LayoutContext }) {
|
|
9
|
+
if (context?.canManageUpgradeActions === false) return null
|
|
10
|
+
return <UpgradeActionBanner />
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const widget: InjectionWidgetModule<LayoutContext> = {
|
|
14
|
+
metadata: {
|
|
15
|
+
id: 'upgrade_actions.injection.banner',
|
|
16
|
+
title: 'Upgrade action banner',
|
|
17
|
+
features: ['configs.manage'],
|
|
18
|
+
},
|
|
19
|
+
Widget: UpgradeActionBannerWidget,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default widget
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ModuleInjectionTable } from '@open-mercato/shared/modules/widgets/injection'
|
|
2
|
+
|
|
3
|
+
const banner = { widgetId: 'upgrade_actions.injection.banner' }
|
|
4
|
+
|
|
5
|
+
export const injectionTable: ModuleInjectionTable = {
|
|
6
|
+
'backend:layout:top': [banner],
|
|
7
|
+
'backend:upgrade-actions:legacy-banner': [banner],
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default injectionTable
|