@open-mercato/upgrade-actions 0.11.1-develop.8805.1.6357054d1a → 0.11.1-develop.8880.1.3acdbfc734
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 +4 -2
- package/dist/modules/upgrade_actions/api/actions/route.js +178 -0
- package/dist/modules/upgrade_actions/api/actions/route.js.map +7 -0
- package/dist/modules/upgrade_actions/api/contract.js +1 -1
- package/dist/modules/upgrade_actions/api/contract.js.map +1 -1
- package/dist/modules/upgrade_actions/cli.js +33 -0
- package/dist/modules/upgrade_actions/cli.js.map +7 -0
- package/dist/modules/upgrade_actions/components/UpgradeActionBanner.js +2 -2
- package/dist/modules/upgrade_actions/components/UpgradeActionBanner.js.map +1 -1
- package/dist/modules/upgrade_actions/data/entities.js +49 -0
- package/dist/modules/upgrade_actions/data/entities.js.map +7 -0
- package/dist/modules/upgrade_actions/di.js +19 -0
- package/dist/modules/upgrade_actions/di.js.map +7 -0
- package/dist/modules/upgrade_actions/index.js +1 -1
- package/dist/modules/upgrade_actions/index.js.map +1 -1
- package/dist/modules/upgrade_actions/lib/upgrade-action-catalog.js +145 -0
- package/dist/modules/upgrade_actions/lib/upgrade-action-catalog.js.map +7 -0
- package/dist/modules/upgrade_actions/lib/upgrade-actions-cli.js +276 -0
- package/dist/modules/upgrade_actions/lib/upgrade-actions-cli.js.map +7 -0
- package/dist/modules/upgrade_actions/lib/upgrade-actions.js +24 -0
- package/dist/modules/upgrade_actions/lib/upgrade-actions.js.map +7 -0
- package/dist/modules/upgrade_actions/migrations/.snapshot-open-mercato.json +120 -0
- package/dist/modules/upgrade_actions/services/upgradeActionsService.js +256 -0
- package/dist/modules/upgrade_actions/services/upgradeActionsService.js.map +7 -0
- package/dist/modules/upgrade_actions/upgrades/0.0.1-test-reversible-fixture.js +43 -0
- package/dist/modules/upgrade_actions/upgrades/0.0.1-test-reversible-fixture.js.map +7 -0
- package/dist/modules/upgrade_actions/upgrades.js +14 -0
- package/dist/modules/upgrade_actions/upgrades.js.map +7 -0
- package/package.json +16 -9
- package/src/modules/upgrade_actions/api/actions/route.ts +193 -0
- package/src/modules/upgrade_actions/api/contract.ts +1 -1
- package/src/modules/upgrade_actions/cli.ts +33 -0
- package/src/modules/upgrade_actions/components/UpgradeActionBanner.tsx +2 -2
- package/src/modules/upgrade_actions/data/entities.ts +30 -0
- package/src/modules/upgrade_actions/di.ts +17 -0
- package/src/modules/upgrade_actions/index.ts +1 -1
- package/src/modules/upgrade_actions/lib/upgrade-action-catalog.ts +181 -0
- package/src/modules/upgrade_actions/lib/upgrade-actions-cli.ts +334 -0
- package/src/modules/upgrade_actions/lib/upgrade-actions.ts +34 -0
- package/src/modules/upgrade_actions/migrations/.snapshot-open-mercato.json +120 -0
- package/src/modules/upgrade_actions/services/upgradeActionsService.ts +343 -0
- package/src/modules/upgrade_actions/upgrades/0.0.1-test-reversible-fixture.ts +46 -0
- package/src/modules/upgrade_actions/upgrades.ts +13 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Upgrade actions
|
|
2
2
|
|
|
3
|
-
This optional Open Mercato module
|
|
3
|
+
This optional Open Mercato module discovers module-owned release actions and runs them through the banner, HTTP API or operator CLI. Applying an action records completion in the existing tenant and organization history.
|
|
4
4
|
|
|
5
5
|
## Enable
|
|
6
6
|
|
|
@@ -18,4 +18,6 @@ Register it in the app's `src/modules.ts` with `configs` and `directory` enabled
|
|
|
18
18
|
|
|
19
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
20
|
|
|
21
|
-
The module mounts the banner in the backoffice layout. Remove any manually mounted legacy banner when enabling the module.
|
|
21
|
+
The module mounts the banner in the backoffice layout. Remove any manually mounted legacy banner when enabling the module. Use `GET` and `POST` at `/api/upgrade_actions/actions` with `configs.manage`. During the compatibility window the old Configs URL forwards authorized requests to the same handlers.
|
|
22
|
+
|
|
23
|
+
From a deployment shell, run `yarn mercato upgrade_actions actions --help` for the list, apply and revert commands. Disabling the module removes the banner, canonical API and CLI and preserves completion history.
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
3
|
+
import { getAuthFromRequest } from "@open-mercato/shared/lib/auth/server";
|
|
4
|
+
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
|
|
5
|
+
import { resolveFeatureCheckContext } from "@open-mercato/core/modules/directory/utils/organizationScope";
|
|
6
|
+
import { resolveSingleOrganizationIdOrDeny } from "@open-mercato/core/modules/directory/utils/organizationScopeFilter";
|
|
7
|
+
import {
|
|
8
|
+
executeUpgradeAction,
|
|
9
|
+
getCurrentVersion,
|
|
10
|
+
isUpgradeActionsEnabled,
|
|
11
|
+
listPendingUpgradeActions,
|
|
12
|
+
UpgradeActionPostCommitError
|
|
13
|
+
} from "../../services/upgradeActionsService.js";
|
|
14
|
+
import { configErrorSchema } from "@open-mercato/core/modules/configs/api/openapi";
|
|
15
|
+
import {
|
|
16
|
+
upgradeActionsListResponseSchema,
|
|
17
|
+
executeUpgradeActionRequestSchema,
|
|
18
|
+
executeUpgradeActionResponseSchema
|
|
19
|
+
} from "../contract.js";
|
|
20
|
+
import { createLogger } from "@open-mercato/shared/lib/logger";
|
|
21
|
+
const logger = createLogger("upgrade_actions");
|
|
22
|
+
const metadata = {
|
|
23
|
+
GET: { requireAuth: true, requireFeatures: ["configs.manage"] },
|
|
24
|
+
POST: { requireAuth: true, requireFeatures: ["configs.manage"] }
|
|
25
|
+
};
|
|
26
|
+
const runSchema = executeUpgradeActionRequestSchema.extend({
|
|
27
|
+
actionId: z.string().trim().pipe(executeUpgradeActionRequestSchema.shape.actionId)
|
|
28
|
+
});
|
|
29
|
+
async function resolveScope(req, translate) {
|
|
30
|
+
const auth = await getAuthFromRequest(req);
|
|
31
|
+
if (!auth?.sub) {
|
|
32
|
+
return { scope: null, container: null, error: Response.json({ error: "Unauthorized" }, { status: 401 }) };
|
|
33
|
+
}
|
|
34
|
+
const container = await createRequestContainer();
|
|
35
|
+
const featureContext = await resolveFeatureCheckContext({ container, auth, request: req });
|
|
36
|
+
const tenantId = featureContext.scope.tenantId ?? auth.tenantId ?? null;
|
|
37
|
+
const organizationId = featureContext.organizationId ?? resolveSingleOrganizationIdOrDeny(featureContext.scope, auth) ?? null;
|
|
38
|
+
if (!tenantId || !organizationId) {
|
|
39
|
+
const message = translate(
|
|
40
|
+
"upgrades.scopeRequired",
|
|
41
|
+
"Select an organization and tenant to apply this upgrade."
|
|
42
|
+
);
|
|
43
|
+
return { scope: null, container, error: Response.json({ error: message }, { status: 400 }) };
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
scope: { tenantId, organizationId },
|
|
47
|
+
container
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function GET(req) {
|
|
51
|
+
if (!isUpgradeActionsEnabled()) {
|
|
52
|
+
return Response.json({ version: getCurrentVersion(), actions: [] });
|
|
53
|
+
}
|
|
54
|
+
const { translate } = await resolveTranslations();
|
|
55
|
+
const scopeResult = await resolveScope(req, translate);
|
|
56
|
+
if (!scopeResult.scope) return scopeResult.error;
|
|
57
|
+
const container = scopeResult.container ?? await createRequestContainer();
|
|
58
|
+
const em = container.resolve("em");
|
|
59
|
+
const version = getCurrentVersion();
|
|
60
|
+
try {
|
|
61
|
+
const actions = await listPendingUpgradeActions(em, { ...scopeResult.scope, version });
|
|
62
|
+
const nextAction = actions[0];
|
|
63
|
+
const payload = nextAction ? [{
|
|
64
|
+
id: nextAction.id,
|
|
65
|
+
version: nextAction.version,
|
|
66
|
+
message: translate(
|
|
67
|
+
nextAction.messageKey,
|
|
68
|
+
'The version {{version}} has been installed. To fully use all the features from this edition please do "Install example catalog products and categories".',
|
|
69
|
+
{ version: nextAction.version }
|
|
70
|
+
),
|
|
71
|
+
ctaLabel: translate(
|
|
72
|
+
nextAction.ctaKey,
|
|
73
|
+
"Install example catalog products and categories"
|
|
74
|
+
),
|
|
75
|
+
successMessage: translate(
|
|
76
|
+
nextAction.successKey,
|
|
77
|
+
"Example catalog products and categories installed."
|
|
78
|
+
),
|
|
79
|
+
loadingLabel: nextAction.loadingKey ? translate(nextAction.loadingKey, "Installing\u2026") : translate("upgrades.loading", "Installing\u2026")
|
|
80
|
+
}] : [];
|
|
81
|
+
return Response.json({ version, actions: payload });
|
|
82
|
+
} catch (error) {
|
|
83
|
+
logger.error("failed to load upgrade actions", { component: "upgrade-actions", err: error });
|
|
84
|
+
return Response.json({ error: "Failed to load upgrade actions" }, { status: 500 });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function POST(req) {
|
|
88
|
+
if (!isUpgradeActionsEnabled()) {
|
|
89
|
+
return Response.json({ error: "Upgrade actions are disabled" }, { status: 403 });
|
|
90
|
+
}
|
|
91
|
+
const { translate } = await resolveTranslations();
|
|
92
|
+
const scopeResult = await resolveScope(req, translate);
|
|
93
|
+
if (!scopeResult.scope) return scopeResult.error;
|
|
94
|
+
let parsedBody;
|
|
95
|
+
try {
|
|
96
|
+
parsedBody = await req.json();
|
|
97
|
+
} catch {
|
|
98
|
+
parsedBody = null;
|
|
99
|
+
}
|
|
100
|
+
const parsed = runSchema.safeParse(parsedBody || {});
|
|
101
|
+
if (!parsed.success) {
|
|
102
|
+
return Response.json({ error: "Invalid request body" }, { status: 400 });
|
|
103
|
+
}
|
|
104
|
+
const container = scopeResult.container ?? await createRequestContainer();
|
|
105
|
+
const version = getCurrentVersion();
|
|
106
|
+
try {
|
|
107
|
+
const result = await executeUpgradeAction(container, {
|
|
108
|
+
actionId: parsed.data.actionId,
|
|
109
|
+
tenantId: scopeResult.scope.tenantId,
|
|
110
|
+
organizationId: scopeResult.scope.organizationId,
|
|
111
|
+
version
|
|
112
|
+
});
|
|
113
|
+
const successMessage = translate(
|
|
114
|
+
result.action.successKey,
|
|
115
|
+
"Example catalog products and categories installed."
|
|
116
|
+
);
|
|
117
|
+
return Response.json({
|
|
118
|
+
status: result.status,
|
|
119
|
+
message: successMessage,
|
|
120
|
+
version
|
|
121
|
+
});
|
|
122
|
+
} catch (error) {
|
|
123
|
+
if (error instanceof UpgradeActionPostCommitError) {
|
|
124
|
+
logger.error("upgrade action committed but a post-commit step failed", { component: "upgrade-actions", actionId: error.action.id, err: error.failures[0] });
|
|
125
|
+
return Response.json({
|
|
126
|
+
status: "completed",
|
|
127
|
+
message: translate(error.action.successKey, "Example catalog products and categories installed."),
|
|
128
|
+
version
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
logger.error("failed to execute upgrade action", { component: "upgrade-actions", err: error });
|
|
132
|
+
const message = translate("upgrades.runFailed", "We could not run this upgrade action.");
|
|
133
|
+
const details = error instanceof Error ? error.message : null;
|
|
134
|
+
return Response.json({ error: message, details }, { status: 500 });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const openApi = {
|
|
138
|
+
tag: "Upgrade Actions",
|
|
139
|
+
summary: "Upgrade actions management",
|
|
140
|
+
methods: {
|
|
141
|
+
GET: {
|
|
142
|
+
summary: "List pending upgrade actions",
|
|
143
|
+
description: "Returns a list of pending upgrade actions for the current version. These are one-time setup tasks that need to be executed after upgrading to a new version. Requires organization and tenant context.",
|
|
144
|
+
responses: [
|
|
145
|
+
{ status: 200, description: "List of pending upgrade actions", schema: upgradeActionsListResponseSchema }
|
|
146
|
+
],
|
|
147
|
+
errors: [
|
|
148
|
+
{ status: 400, description: "Missing organization or tenant context", schema: configErrorSchema },
|
|
149
|
+
{ status: 401, description: "Unauthorized", schema: configErrorSchema },
|
|
150
|
+
{ status: 500, description: "Failed to load upgrade actions", schema: configErrorSchema }
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
POST: {
|
|
154
|
+
summary: "Execute upgrade action",
|
|
155
|
+
description: "Executes a specific upgrade action by ID. Typically used for one-time setup tasks like seeding example data after version upgrade. Returns execution status and localized success message.",
|
|
156
|
+
requestBody: {
|
|
157
|
+
contentType: "application/json",
|
|
158
|
+
schema: executeUpgradeActionRequestSchema
|
|
159
|
+
},
|
|
160
|
+
responses: [
|
|
161
|
+
{ status: 200, description: "Upgrade action executed successfully", schema: executeUpgradeActionResponseSchema }
|
|
162
|
+
],
|
|
163
|
+
errors: [
|
|
164
|
+
{ status: 400, description: "Invalid request body or missing context", schema: configErrorSchema },
|
|
165
|
+
{ status: 401, description: "Unauthorized", schema: configErrorSchema },
|
|
166
|
+
{ status: 403, description: "Upgrade actions are disabled", schema: configErrorSchema },
|
|
167
|
+
{ status: 500, description: "Failed to execute upgrade action", schema: configErrorSchema }
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
export {
|
|
173
|
+
GET,
|
|
174
|
+
POST,
|
|
175
|
+
metadata,
|
|
176
|
+
openApi
|
|
177
|
+
};
|
|
178
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/modules/upgrade_actions/api/actions/route.ts"],
|
|
4
|
+
"sourcesContent": ["import { z } from 'zod'\nimport type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { resolveFeatureCheckContext } from '@open-mercato/core/modules/directory/utils/organizationScope'\nimport { resolveSingleOrganizationIdOrDeny } from '@open-mercato/core/modules/directory/utils/organizationScopeFilter'\nimport {\n executeUpgradeAction,\n getCurrentVersion,\n isUpgradeActionsEnabled,\n listPendingUpgradeActions,\n UpgradeActionPostCommitError,\n} from '../../services/upgradeActionsService'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { configErrorSchema } from '@open-mercato/core/modules/configs/api/openapi'\nimport {\n upgradeActionsListResponseSchema,\n executeUpgradeActionRequestSchema,\n executeUpgradeActionResponseSchema,\n} from '../contract'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\n\nconst logger = createLogger('upgrade_actions')\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['configs.manage'] },\n POST: { requireAuth: true, requireFeatures: ['configs.manage'] },\n} as const\n\nconst runSchema = executeUpgradeActionRequestSchema.extend({\n actionId: z.string().trim().pipe(executeUpgradeActionRequestSchema.shape.actionId),\n})\n\ntype Scope = { tenantId: string; organizationId: string }\n\nasync function resolveScope(\n req: Request,\n translate: (key: string, fallback?: string) => string,\n): Promise<{ scope: Scope | null; container: Awaited<ReturnType<typeof createRequestContainer>> | null; error?: Response }> {\n const auth = await getAuthFromRequest(req)\n if (!auth?.sub) {\n return { scope: null, container: null, error: Response.json({ error: 'Unauthorized' }, { status: 401 }) }\n }\n const container = await createRequestContainer()\n const featureContext = await resolveFeatureCheckContext({ container, auth, request: req })\n const tenantId = featureContext.scope.tenantId ?? auth.tenantId ?? null\n const organizationId = featureContext.organizationId ?? resolveSingleOrganizationIdOrDeny(featureContext.scope, auth) ?? null\n if (!tenantId || !organizationId) {\n const message = translate(\n 'upgrades.scopeRequired',\n 'Select an organization and tenant to apply this upgrade.'\n )\n return { scope: null, container, error: Response.json({ error: message }, { status: 400 }) }\n }\n return {\n scope: { tenantId, organizationId },\n container,\n }\n}\n\nexport async function GET(req: Request) {\n if (!isUpgradeActionsEnabled()) {\n return Response.json({ version: getCurrentVersion(), actions: [] })\n }\n const { translate } = await resolveTranslations()\n const scopeResult = await resolveScope(req, translate)\n if (!scopeResult.scope) return scopeResult.error!\n\n const container = scopeResult.container ?? (await createRequestContainer())\n const em = container.resolve<EntityManager>('em')\n const version = getCurrentVersion()\n try {\n const actions = await listPendingUpgradeActions(em, { ...scopeResult.scope, version })\n const nextAction = actions[0]\n const payload = nextAction\n ? [{\n id: nextAction.id,\n version: nextAction.version,\n message: translate(\n nextAction.messageKey,\n 'The version {{version}} has been installed. To fully use all the features from this edition please do \"Install example catalog products and categories\".',\n { version: nextAction.version }\n ),\n ctaLabel: translate(\n nextAction.ctaKey,\n 'Install example catalog products and categories'\n ),\n successMessage: translate(\n nextAction.successKey,\n 'Example catalog products and categories installed.'\n ),\n loadingLabel: nextAction.loadingKey\n ? translate(nextAction.loadingKey, 'Installing\u2026')\n : translate('upgrades.loading', 'Installing\u2026'),\n }]\n : []\n return Response.json({ version, actions: payload })\n } catch (error) {\n logger.error('failed to load upgrade actions', { component: 'upgrade-actions', err: error })\n return Response.json({ error: 'Failed to load upgrade actions' }, { status: 500 })\n }\n}\n\nexport async function POST(req: Request) {\n if (!isUpgradeActionsEnabled()) {\n return Response.json({ error: 'Upgrade actions are disabled' }, { status: 403 })\n }\n const { translate } = await resolveTranslations()\n const scopeResult = await resolveScope(req, translate)\n if (!scopeResult.scope) return scopeResult.error!\n\n let parsedBody: unknown\n try {\n parsedBody = await req.json()\n } catch {\n parsedBody = null\n }\n const parsed = runSchema.safeParse(parsedBody || {})\n if (!parsed.success) {\n return Response.json({ error: 'Invalid request body' }, { status: 400 })\n }\n\n const container = scopeResult.container ?? (await createRequestContainer())\n const version = getCurrentVersion()\n\n try {\n const result = await executeUpgradeAction(container, {\n actionId: parsed.data.actionId,\n tenantId: scopeResult.scope.tenantId,\n organizationId: scopeResult.scope.organizationId,\n version,\n })\n const successMessage = translate(\n result.action.successKey,\n 'Example catalog products and categories installed.'\n )\n return Response.json({\n status: result.status,\n message: successMessage,\n version,\n })\n } catch (error) {\n if (error instanceof UpgradeActionPostCommitError) {\n logger.error('upgrade action committed but a post-commit step failed', { component: 'upgrade-actions', actionId: error.action.id, err: error.failures[0] })\n return Response.json({\n status: 'completed',\n message: translate(error.action.successKey, 'Example catalog products and categories installed.'),\n version,\n })\n }\n logger.error('failed to execute upgrade action', { component: 'upgrade-actions', err: error })\n const message = translate('upgrades.runFailed', 'We could not run this upgrade action.')\n const details = error instanceof Error ? error.message : null\n return Response.json({ error: message, details }, { status: 500 })\n }\n}\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'Upgrade Actions',\n summary: 'Upgrade actions management',\n methods: {\n GET: {\n summary: 'List pending upgrade actions',\n description: 'Returns a list of pending upgrade actions for the current version. These are one-time setup tasks that need to be executed after upgrading to a new version. Requires organization and tenant context.',\n responses: [\n { status: 200, description: 'List of pending upgrade actions', schema: upgradeActionsListResponseSchema },\n ],\n errors: [\n { status: 400, description: 'Missing organization or tenant context', schema: configErrorSchema },\n { status: 401, description: 'Unauthorized', schema: configErrorSchema },\n { status: 500, description: 'Failed to load upgrade actions', schema: configErrorSchema },\n ],\n },\n POST: {\n summary: 'Execute upgrade action',\n description: 'Executes a specific upgrade action by ID. Typically used for one-time setup tasks like seeding example data after version upgrade. Returns execution status and localized success message.',\n requestBody: {\n contentType: 'application/json',\n schema: executeUpgradeActionRequestSchema,\n },\n responses: [\n { status: 200, description: 'Upgrade action executed successfully', schema: executeUpgradeActionResponseSchema },\n ],\n errors: [\n { status: 400, description: 'Invalid request body or missing context', schema: configErrorSchema },\n { status: 401, description: 'Unauthorized', schema: configErrorSchema },\n { status: 403, description: 'Upgrade actions are disabled', schema: configErrorSchema },\n { status: 500, description: 'Failed to execute upgrade action', schema: configErrorSchema },\n ],\n },\n },\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS;AAElB,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AACpC,SAAS,kCAAkC;AAC3C,SAAS,yCAAyC;AAClD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAE7B,MAAM,SAAS,aAAa,iBAAiB;AAEtC,MAAM,WAAW;AAAA,EACtB,KAAK,EAAE,aAAa,MAAM,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AW;AAAA,QACT,EAAE,QAAQ,KAAK,aAAa,mCAAmC,QAAQ,iCAAiC;AAAA,MAC1G;AAAA,MACA,QAAQ;AAAA,QACN,EAAE,QAAQ,KAAK,aAAa,0CAA0C,QAAQ,kBAAkB;AAAA,QAChG,EAAE,QAAQ,KAAK,aAAa,gBAAgB,QAAQ,kBAAkB;AAAA,QACtE,EAAE,QAAQ,KAAK,aAAa,kCAAkC,QAAQ,kBAAkB;AAAA,MAC1F;AAAA,IACF;AAAA,IACA,MAAM;AAAA,MACJ,SAAS;AAAA,MACT,aAAa;AAAA,MACb,aAAa;AAAA,QACX,aAAa;AAAA,QACb,QAAQ;AAAA,MACV;AAAA,MACA,WAAW;AAAA,QACT,EAAE,QAAQ,KAAK,aAAa,wCAAwC,QAAQ,mCAAmC;AAAA,MACjH;AAAA,MACA,QAAQ;AAAA,QACN,EAAE,QAAQ,KAAK,aAAa,2CAA2C,QAAQ,kBAAkB;AAAA,QACjG,EAAE,QAAQ,KAAK,aAAa,gBAAgB,QAAQ,kBAAkB;AAAA,QACtE,EAAE,QAAQ,KAAK,aAAa,gCAAgC,QAAQ,kBAAkB;AAAA,QACtF,EAAE,QAAQ,KAAK,aAAa,oCAAoC,QAAQ,kBAAkB;AAAA,MAC5F;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
upgradeActionsListResponseSchema,
|
|
4
4
|
executeUpgradeActionRequestSchema,
|
|
5
5
|
executeUpgradeActionResponseSchema
|
|
6
|
-
} from "@open-mercato/
|
|
6
|
+
} from "@open-mercato/shared/modules/upgrade-actions-http";
|
|
7
7
|
export {
|
|
8
8
|
executeUpgradeActionRequestSchema,
|
|
9
9
|
executeUpgradeActionResponseSchema,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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/
|
|
4
|
+
"sourcesContent": ["export {\n upgradeActionSchema,\n upgradeActionsListResponseSchema,\n executeUpgradeActionRequestSchema,\n executeUpgradeActionResponseSchema,\n} from '@open-mercato/shared/modules/upgrade-actions-http'\n"],
|
|
5
5
|
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
2
|
+
import { runUpgradeActionsCli, UPGRADE_ACTIONS_CLI_HELP } from "./lib/upgrade-actions-cli.js";
|
|
3
|
+
function isQuietCliOutput() {
|
|
4
|
+
return process.env.OM_CLI_QUIET === "1" || process.env.MERCATO_QUIET === "1";
|
|
5
|
+
}
|
|
6
|
+
const upgradeActionsCommand = {
|
|
7
|
+
command: "actions",
|
|
8
|
+
help: UPGRADE_ACTIONS_CLI_HELP,
|
|
9
|
+
handlesHelp: true,
|
|
10
|
+
async run(rest) {
|
|
11
|
+
const interactive = Boolean(process.stdout.isTTY) && !isQuietCliOutput();
|
|
12
|
+
const exitCode = await runUpgradeActionsCli(rest, {
|
|
13
|
+
io: {
|
|
14
|
+
line: (text) => console.log(text),
|
|
15
|
+
error: (text) => console.error(text),
|
|
16
|
+
progress: interactive ? (text) => process.stdout.write(text) : null
|
|
17
|
+
},
|
|
18
|
+
openScope: async () => {
|
|
19
|
+
const container = await createRequestContainer();
|
|
20
|
+
return {
|
|
21
|
+
scope: { container, em: container.resolve("em") },
|
|
22
|
+
close: () => container.dispose()
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
if (exitCode !== 0) process.exitCode = exitCode;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var cli_default = [upgradeActionsCommand];
|
|
30
|
+
export {
|
|
31
|
+
cli_default as default
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/modules/upgrade_actions/cli.ts"],
|
|
4
|
+
"sourcesContent": ["import { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { ModuleCli } from '@open-mercato/shared/modules/registry'\nimport { runUpgradeActionsCli, UPGRADE_ACTIONS_CLI_HELP } from './lib/upgrade-actions-cli'\n\nfunction isQuietCliOutput(): boolean {\n return process.env.OM_CLI_QUIET === '1' || process.env.MERCATO_QUIET === '1'\n}\n\nconst upgradeActionsCommand: ModuleCli = {\n command: 'actions',\n help: UPGRADE_ACTIONS_CLI_HELP,\n handlesHelp: true,\n async run(rest) {\n const interactive = Boolean(process.stdout.isTTY) && !isQuietCliOutput()\n const exitCode = await runUpgradeActionsCli(rest, {\n io: {\n line: (text) => console.log(text),\n error: (text) => console.error(text),\n progress: interactive ? (text) => process.stdout.write(text) : null,\n },\n openScope: async () => {\n const container = await createRequestContainer()\n return {\n scope: { container, em: container.resolve('em') },\n close: () => container.dispose(),\n }\n },\n })\n if (exitCode !== 0) process.exitCode = exitCode\n },\n}\n\nexport default [upgradeActionsCommand]\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,8BAA8B;AAEvC,SAAS,sBAAsB,gCAAgC;AAE/D,SAAS,mBAA4B;AACnC,SAAO,QAAQ,IAAI,iBAAiB,OAAO,QAAQ,IAAI,kBAAkB;AAC3E;AAEA,MAAM,wBAAmC;AAAA,EACvC,SAAS;AAAA,EACT,MAAM;AAAA,EACN,aAAa;AAAA,EACb,MAAM,IAAI,MAAM;AACd,UAAM,cAAc,QAAQ,QAAQ,OAAO,KAAK,KAAK,CAAC,iBAAiB;AACvE,UAAM,WAAW,MAAM,qBAAqB,MAAM;AAAA,MAChD,IAAI;AAAA,QACF,MAAM,CAAC,SAAS,QAAQ,IAAI,IAAI;AAAA,QAChC,OAAO,CAAC,SAAS,QAAQ,MAAM,IAAI;AAAA,QACnC,UAAU,cAAc,CAAC,SAAS,QAAQ,OAAO,MAAM,IAAI,IAAI;AAAA,MACjE;AAAA,MACA,WAAW,YAAY;AACrB,cAAM,YAAY,MAAM,uBAAuB;AAC/C,eAAO;AAAA,UACL,OAAO,EAAE,WAAW,IAAI,UAAU,QAAQ,IAAI,EAAE;AAAA,UAChD,OAAO,MAAM,UAAU,QAAQ;AAAA,QACjC;AAAA,MACF;AAAA,IACF,CAAC;AACD,QAAI,aAAa,EAAG,SAAQ,WAAW;AAAA,EACzC;AACF;AAEA,IAAO,cAAQ,CAAC,qBAAqB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -30,7 +30,7 @@ function UpgradeActionBanner() {
|
|
|
30
30
|
if (!canManageConfigs) return;
|
|
31
31
|
if (!upgradeActionsEnabled()) return;
|
|
32
32
|
if (typeof window === "undefined" || typeof fetch === "undefined") return;
|
|
33
|
-
const call = await apiCall("/api/
|
|
33
|
+
const call = await apiCall("/api/upgrade_actions/actions", {
|
|
34
34
|
headers: forbiddenRedirectOptOutHeader
|
|
35
35
|
});
|
|
36
36
|
if (cancelledRef.current) return;
|
|
@@ -58,7 +58,7 @@ function UpgradeActionBanner() {
|
|
|
58
58
|
context: { formId: mutationContextId, resourceKind: "upgrade_actions.action", retryLastMutation },
|
|
59
59
|
mutationPayload,
|
|
60
60
|
operation: async () => {
|
|
61
|
-
const call = await apiCall("/api/
|
|
61
|
+
const call = await apiCall("/api/upgrade_actions/actions", {
|
|
62
62
|
method: "POST",
|
|
63
63
|
headers: { ...forbiddenRedirectOptOutHeader, "Content-Type": "application/json" },
|
|
64
64
|
body: JSON.stringify(mutationPayload)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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/
|
|
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/upgrade_actions/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/upgrade_actions/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
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,EAAE,SAAS,QAAQ,IAAI,iBAAiB;AAC9C,QAAM,mBAAmB,WAAW,WAAW,SAAS,iBAAiB,gBAAgB;AACzF,QAAM,CAAC,QAAQ,SAAS,IAAI,MAAM,SAAsC,IAAI;AAC5E,QAAM,CAAC,SAAS,UAAU,IAAI,MAAM,SAAS,KAAK;AAClD,QAAM,eAAe,MAAM,OAAO,KAAK;AACvC,QAAM,cAAc,MAAM,OAAO,KAAK;AACtC,QAAM,EAAE,aAAa,kBAAkB,IAAI,mBAAmB;AAAA,IAC5D,WAAW;AAAA,IACX,SAAS,oBAAoB,sBAAsB;AAAA,EACrD,CAAC;AAED,QAAM,iBAAiB,MAAM,YAAY,YAAY;AACnD,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e,OAAO;AAAA;AAAA,IACnC,GACF;AAAA,KACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
import { OptionalProps } from "@mikro-orm/core";
|
|
12
|
+
import { Entity, Index, PrimaryKey, Property, Unique } from "@mikro-orm/decorators/legacy";
|
|
13
|
+
OptionalProps;
|
|
14
|
+
let UpgradeActionRun = class {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.completedAt = /* @__PURE__ */ new Date();
|
|
17
|
+
this.createdAt = /* @__PURE__ */ new Date();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
__decorateClass([
|
|
21
|
+
PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
|
|
22
|
+
], UpgradeActionRun.prototype, "id", 2);
|
|
23
|
+
__decorateClass([
|
|
24
|
+
Property({ name: "version", type: "text" })
|
|
25
|
+
], UpgradeActionRun.prototype, "version", 2);
|
|
26
|
+
__decorateClass([
|
|
27
|
+
Property({ name: "action_id", type: "text" })
|
|
28
|
+
], UpgradeActionRun.prototype, "actionId", 2);
|
|
29
|
+
__decorateClass([
|
|
30
|
+
Property({ name: "organization_id", type: "uuid" })
|
|
31
|
+
], UpgradeActionRun.prototype, "organizationId", 2);
|
|
32
|
+
__decorateClass([
|
|
33
|
+
Property({ name: "tenant_id", type: "uuid" })
|
|
34
|
+
], UpgradeActionRun.prototype, "tenantId", 2);
|
|
35
|
+
__decorateClass([
|
|
36
|
+
Property({ name: "completed_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
|
|
37
|
+
], UpgradeActionRun.prototype, "completedAt", 2);
|
|
38
|
+
__decorateClass([
|
|
39
|
+
Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
|
|
40
|
+
], UpgradeActionRun.prototype, "createdAt", 2);
|
|
41
|
+
UpgradeActionRun = __decorateClass([
|
|
42
|
+
Entity({ tableName: "upgrade_action_runs" }),
|
|
43
|
+
Index({ name: "upgrade_action_runs_scope_idx", properties: ["organizationId", "tenantId"] }),
|
|
44
|
+
Unique({ name: "upgrade_action_runs_action_scope_unique", properties: ["version", "actionId", "organizationId", "tenantId"] })
|
|
45
|
+
], UpgradeActionRun);
|
|
46
|
+
export {
|
|
47
|
+
UpgradeActionRun
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=entities.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/upgrade_actions/data/entities.ts"],
|
|
4
|
+
"sourcesContent": ["import { OptionalProps } from '@mikro-orm/core'\nimport { Entity, Index, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'\n\n@Entity({ tableName: 'upgrade_action_runs' })\n@Index({ name: 'upgrade_action_runs_scope_idx', properties: ['organizationId', 'tenantId'] })\n@Unique({ name: 'upgrade_action_runs_action_scope_unique', properties: ['version', 'actionId', 'organizationId', 'tenantId'] })\nexport class UpgradeActionRun {\n [OptionalProps]?: 'createdAt' | 'completedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'version', type: 'text' })\n version!: string\n\n @Property({ name: 'action_id', type: 'text' })\n actionId!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'completed_at', type: Date, onCreate: () => new Date() })\n completedAt: Date = new Date()\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;AAAA,SAAS,qBAAqB;AAC9B,SAAS,QAAQ,OAAO,YAAY,UAAU,cAAc;AAMzD;AADI,IAAM,mBAAN,MAAuB;AAAA,EAAvB;AAmBL,uBAAoB,oBAAI,KAAK;AAG7B,qBAAkB,oBAAI,KAAK;AAAA;AAC7B;AAnBE;AAAA,EADC,WAAW,EAAE,MAAM,QAAQ,YAAY,oBAAoB,CAAC;AAAA,GAHlD,iBAIX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,WAAW,MAAM,OAAO,CAAC;AAAA,GANhC,iBAOX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,OAAO,CAAC;AAAA,GATlC,iBAUX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,mBAAmB,MAAM,OAAO,CAAC;AAAA,GAZxC,iBAaX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,OAAO,CAAC;AAAA,GAflC,iBAgBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,gBAAgB,MAAM,MAAM,UAAU,MAAM,oBAAI,KAAK,EAAE,CAAC;AAAA,GAlB/D,iBAmBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,MAAM,UAAU,MAAM,oBAAI,KAAK,EAAE,CAAC;AAAA,GArB7D,iBAsBX;AAtBW,mBAAN;AAAA,EAHN,OAAO,EAAE,WAAW,sBAAsB,CAAC;AAAA,EAC3C,MAAM,EAAE,MAAM,iCAAiC,YAAY,CAAC,kBAAkB,UAAU,EAAE,CAAC;AAAA,EAC3F,OAAO,EAAE,MAAM,2CAA2C,YAAY,CAAC,WAAW,YAAY,kBAAkB,UAAU,EAAE,CAAC;AAAA,GACjH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { registerUpgradeActionsCompatibility } from "@open-mercato/shared/modules/upgrade-actions-compatibility";
|
|
2
|
+
import { actionsUpToVersion, findUpgradeAction } from "./lib/upgrade-actions.js";
|
|
3
|
+
import { executeUpgradeAction, isUpgradeActionsEnabled, listPendingUpgradeActions } from "./services/upgradeActionsService.js";
|
|
4
|
+
function register() {
|
|
5
|
+
registerUpgradeActionsCompatibility({
|
|
6
|
+
get: async (request) => (await import("./api/actions/route.js")).GET(request),
|
|
7
|
+
post: async (request) => (await import("./api/actions/route.js")).POST(request),
|
|
8
|
+
isEnabled: isUpgradeActionsEnabled,
|
|
9
|
+
actionsUpToVersion,
|
|
10
|
+
findUpgradeAction,
|
|
11
|
+
listPendingUpgradeActions,
|
|
12
|
+
executeUpgradeAction
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
register();
|
|
16
|
+
export {
|
|
17
|
+
register
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=di.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/modules/upgrade_actions/di.ts"],
|
|
4
|
+
"sourcesContent": ["import { registerUpgradeActionsCompatibility } from '@open-mercato/shared/modules/upgrade-actions-compatibility'\nimport { actionsUpToVersion, findUpgradeAction } from './lib/upgrade-actions'\nimport { executeUpgradeAction, isUpgradeActionsEnabled, listPendingUpgradeActions } from './services/upgradeActionsService'\n\nexport function register(): void {\n registerUpgradeActionsCompatibility({\n get: async (request) => (await import('./api/actions/route')).GET(request),\n post: async (request) => (await import('./api/actions/route')).POST(request),\n isEnabled: isUpgradeActionsEnabled,\n actionsUpToVersion,\n findUpgradeAction,\n listPendingUpgradeActions,\n executeUpgradeAction,\n })\n}\n\nregister()\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,2CAA2C;AACpD,SAAS,oBAAoB,yBAAyB;AACtD,SAAS,sBAAsB,yBAAyB,iCAAiC;AAElF,SAAS,WAAiB;AAC/B,sCAAoC;AAAA,IAClC,KAAK,OAAO,aAAa,MAAM,OAAO,qBAAqB,GAAG,IAAI,OAAO;AAAA,IACzE,MAAM,OAAO,aAAa,MAAM,OAAO,qBAAqB,GAAG,KAAK,OAAO;AAAA,IAC3E,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEA,SAAS;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -2,7 +2,7 @@ const metadata = {
|
|
|
2
2
|
name: "upgrade_actions",
|
|
3
3
|
title: "Upgrade actions",
|
|
4
4
|
version: "0.1.0",
|
|
5
|
-
description: "
|
|
5
|
+
description: "Discovers and runs release upgrade actions through the backoffice, API and CLI.",
|
|
6
6
|
author: "Open Mercato Team",
|
|
7
7
|
license: "MIT",
|
|
8
8
|
requires: ["configs", "directory"]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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: '
|
|
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: 'Discovers and runs release upgrade actions through the backoffice, API and CLI.',\n author: 'Open Mercato Team',\n license: 'MIT',\n requires: ['configs', 'directory'],\n}\n"],
|
|
5
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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import * as semver from "semver";
|
|
2
|
+
import { onModulesRegistered, tryGetModules } from "@open-mercato/shared/lib/modules/registry";
|
|
3
|
+
import { getEnabledModuleIds } from "@open-mercato/shared/security/enabledModulesRegistry";
|
|
4
|
+
import { createLogger } from "@open-mercato/shared/lib/logger";
|
|
5
|
+
const logger = createLogger("upgrade_actions").child({ component: "upgrade-actions" });
|
|
6
|
+
const ACTION_SCOPES = /* @__PURE__ */ new Set(["organization", "tenant"]);
|
|
7
|
+
function isNonEmptyString(value) {
|
|
8
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
9
|
+
}
|
|
10
|
+
function isValidVersion(value) {
|
|
11
|
+
return typeof value === "string" && semver.valid(semver.coerce(value)) !== null;
|
|
12
|
+
}
|
|
13
|
+
function upgradeActionKey(action) {
|
|
14
|
+
return `${action.version}::${action.id}`;
|
|
15
|
+
}
|
|
16
|
+
function validateModuleUpgradeAction(moduleId, candidate) {
|
|
17
|
+
if (!candidate || typeof candidate !== "object") return "descriptor is not an object";
|
|
18
|
+
const action = candidate;
|
|
19
|
+
if (!isNonEmptyString(action.id)) return "missing id";
|
|
20
|
+
if (!action.id.startsWith(`${moduleId}.`) || action.id.length <= moduleId.length + 1) {
|
|
21
|
+
return `id must be prefixed with "${moduleId}."`;
|
|
22
|
+
}
|
|
23
|
+
if (!isValidVersion(action.version)) return "invalid version";
|
|
24
|
+
if (!isNonEmptyString(action.messageKey) || !isNonEmptyString(action.ctaKey) || !isNonEmptyString(action.successKey)) {
|
|
25
|
+
return "missing translation keys";
|
|
26
|
+
}
|
|
27
|
+
if (action.loadingKey !== void 0 && !isNonEmptyString(action.loadingKey)) return "invalid loadingKey";
|
|
28
|
+
if (action.requiredModules !== void 0) {
|
|
29
|
+
if (!Array.isArray(action.requiredModules) || !action.requiredModules.every(isNonEmptyString)) {
|
|
30
|
+
return "invalid requiredModules";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (action.scope !== void 0 && !ACTION_SCOPES.has(action.scope)) return "invalid scope";
|
|
34
|
+
if (typeof action.run !== "function") return "missing run handler";
|
|
35
|
+
if (action.down !== void 0 && typeof action.down !== "function") return "invalid down handler";
|
|
36
|
+
if (action.down !== void 0 && action.scope === "tenant") return "tenant-wide actions cannot declare down";
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
function collectModuleUpgradeActions(modules) {
|
|
40
|
+
const candidates = [];
|
|
41
|
+
const issues = [];
|
|
42
|
+
for (const moduleEntry of modules) {
|
|
43
|
+
const declared = moduleEntry.upgradeActions;
|
|
44
|
+
if (declared === void 0) continue;
|
|
45
|
+
if (!Array.isArray(declared)) {
|
|
46
|
+
issues.push({ moduleId: moduleEntry.id, actionId: null, reason: "upgradeActions is not an array" });
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
for (const candidate of declared) {
|
|
50
|
+
const reason = validateModuleUpgradeAction(moduleEntry.id, candidate);
|
|
51
|
+
if (reason) {
|
|
52
|
+
const actionId = candidate && typeof candidate === "object" && isNonEmptyString(candidate.id) ? candidate.id : null;
|
|
53
|
+
issues.push({ moduleId: moduleEntry.id, actionId, reason });
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
candidates.push({ moduleId: moduleEntry.id, action: candidate });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const occurrences = /* @__PURE__ */ new Map();
|
|
60
|
+
for (const { action } of candidates) occurrences.set(action.id, (occurrences.get(action.id) ?? 0) + 1);
|
|
61
|
+
const actions = candidates.filter(({ moduleId, action }) => {
|
|
62
|
+
if ((occurrences.get(action.id) ?? 0) === 1) return true;
|
|
63
|
+
issues.push({ moduleId, actionId: action.id, reason: "id is declared more than once" });
|
|
64
|
+
return false;
|
|
65
|
+
});
|
|
66
|
+
return { actions, issues };
|
|
67
|
+
}
|
|
68
|
+
function createUpgradeActionCatalog(target) {
|
|
69
|
+
const state = {
|
|
70
|
+
syncedModules: null,
|
|
71
|
+
discovered: /* @__PURE__ */ new Set(),
|
|
72
|
+
owners: /* @__PURE__ */ new WeakMap(),
|
|
73
|
+
reportedCollisions: /* @__PURE__ */ new Set()
|
|
74
|
+
};
|
|
75
|
+
const sync = () => {
|
|
76
|
+
const modules = tryGetModules();
|
|
77
|
+
if (modules === state.syncedModules) return;
|
|
78
|
+
state.syncedModules = modules;
|
|
79
|
+
for (let index = target.length - 1; index >= 0; index -= 1) {
|
|
80
|
+
if (state.discovered.has(target[index])) target.splice(index, 1);
|
|
81
|
+
}
|
|
82
|
+
state.discovered = /* @__PURE__ */ new Set();
|
|
83
|
+
if (!modules) return;
|
|
84
|
+
const { actions, issues } = collectModuleUpgradeActions(modules);
|
|
85
|
+
for (const issue of issues) {
|
|
86
|
+
logger.error("Ignoring invalid upgrade action declaration", issue);
|
|
87
|
+
}
|
|
88
|
+
for (const { moduleId, action } of actions) {
|
|
89
|
+
state.owners.set(action, moduleId);
|
|
90
|
+
state.discovered.add(action);
|
|
91
|
+
target.push(action);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const list = () => {
|
|
95
|
+
sync();
|
|
96
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
97
|
+
for (const action of target) {
|
|
98
|
+
const key = upgradeActionKey(action);
|
|
99
|
+
byKey.set(key, [...byKey.get(key) ?? [], action]);
|
|
100
|
+
}
|
|
101
|
+
return target.filter((action) => {
|
|
102
|
+
const key = upgradeActionKey(action);
|
|
103
|
+
const entries = byKey.get(key) ?? [];
|
|
104
|
+
if (entries.length === 1) return true;
|
|
105
|
+
const discovered = entries.filter((entry) => state.discovered.has(entry));
|
|
106
|
+
const keep = discovered.length === 1 ? discovered[0] : null;
|
|
107
|
+
if (!state.reportedCollisions.has(key)) {
|
|
108
|
+
state.reportedCollisions.add(key);
|
|
109
|
+
logger.error(
|
|
110
|
+
keep ? "Ignoring legacy upgrade action registration shadowed by a module-owned action" : "Ignoring conflicting upgrade action registrations",
|
|
111
|
+
{ actionId: action.id, version: action.version }
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
return action === keep;
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
onModulesRegistered(() => sync());
|
|
118
|
+
sync();
|
|
119
|
+
return {
|
|
120
|
+
sync,
|
|
121
|
+
ownerOf: (action) => state.owners.get(action) ?? null,
|
|
122
|
+
list
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function resolveUpgradeActionScope(action) {
|
|
126
|
+
return action.scope ?? "organization";
|
|
127
|
+
}
|
|
128
|
+
function isUpgradeActionAvailable(action, ownerModuleId) {
|
|
129
|
+
const required = [
|
|
130
|
+
...ownerModuleId ? [ownerModuleId] : [],
|
|
131
|
+
...Array.isArray(action.requiredModules) ? action.requiredModules : []
|
|
132
|
+
];
|
|
133
|
+
if (required.length === 0) return true;
|
|
134
|
+
const enabled = new Set(getEnabledModuleIds());
|
|
135
|
+
return required.every((moduleId) => enabled.has(moduleId));
|
|
136
|
+
}
|
|
137
|
+
export {
|
|
138
|
+
collectModuleUpgradeActions,
|
|
139
|
+
createUpgradeActionCatalog,
|
|
140
|
+
isUpgradeActionAvailable,
|
|
141
|
+
resolveUpgradeActionScope,
|
|
142
|
+
upgradeActionKey,
|
|
143
|
+
validateModuleUpgradeAction
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=upgrade-action-catalog.js.map
|