plugin-workflow-portainer 0.0.0-stage → 0.1.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.
Files changed (98) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +31 -3
  3. package/client-v2.js +1 -0
  4. package/client.js +1 -0
  5. package/dist/client/127.5012da93825a6e5c.js +10 -0
  6. package/dist/client/57.ace9538136438718.js +10 -0
  7. package/dist/client/65.ec4a55173511c06d.js +10 -0
  8. package/dist/client/660.546c702d1ddf7eff.js +10 -0
  9. package/dist/client/index.js +10 -0
  10. package/dist/client-v2/127.0ec4dce7b13750e9.js +10 -0
  11. package/dist/client-v2/57.e7cfc50fb651ac14.js +10 -0
  12. package/dist/client-v2/65.9c745ea32ac96e98.js +10 -0
  13. package/dist/client-v2/660.29ae3c3b4040039d.js +10 -0
  14. package/dist/client-v2/index.js +10 -0
  15. package/dist/externalVersion.js +20 -0
  16. package/dist/index.js +48 -0
  17. package/dist/locale/en-US.json +151 -0
  18. package/dist/locale/vi-VN.json +151 -0
  19. package/dist/locale/zh-CN.json +151 -0
  20. package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
  21. package/dist/node_modules/joi/lib/annotate.js +175 -0
  22. package/dist/node_modules/joi/lib/base.js +1069 -0
  23. package/dist/node_modules/joi/lib/cache.js +143 -0
  24. package/dist/node_modules/joi/lib/common.js +216 -0
  25. package/dist/node_modules/joi/lib/compile.js +283 -0
  26. package/dist/node_modules/joi/lib/errors.js +271 -0
  27. package/dist/node_modules/joi/lib/extend.js +312 -0
  28. package/dist/node_modules/joi/lib/index.d.ts +2365 -0
  29. package/dist/node_modules/joi/lib/index.js +1 -0
  30. package/dist/node_modules/joi/lib/manifest.js +476 -0
  31. package/dist/node_modules/joi/lib/messages.js +207 -0
  32. package/dist/node_modules/joi/lib/modify.js +267 -0
  33. package/dist/node_modules/joi/lib/ref.js +414 -0
  34. package/dist/node_modules/joi/lib/schemas.js +302 -0
  35. package/dist/node_modules/joi/lib/state.js +166 -0
  36. package/dist/node_modules/joi/lib/template.js +463 -0
  37. package/dist/node_modules/joi/lib/trace.js +346 -0
  38. package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
  39. package/dist/node_modules/joi/lib/types/any.js +174 -0
  40. package/dist/node_modules/joi/lib/types/array.js +809 -0
  41. package/dist/node_modules/joi/lib/types/binary.js +100 -0
  42. package/dist/node_modules/joi/lib/types/boolean.js +150 -0
  43. package/dist/node_modules/joi/lib/types/date.js +233 -0
  44. package/dist/node_modules/joi/lib/types/function.js +93 -0
  45. package/dist/node_modules/joi/lib/types/keys.js +1084 -0
  46. package/dist/node_modules/joi/lib/types/link.js +184 -0
  47. package/dist/node_modules/joi/lib/types/number.js +363 -0
  48. package/dist/node_modules/joi/lib/types/object.js +22 -0
  49. package/dist/node_modules/joi/lib/types/string.js +850 -0
  50. package/dist/node_modules/joi/lib/types/symbol.js +102 -0
  51. package/dist/node_modules/joi/lib/validator.js +750 -0
  52. package/dist/node_modules/joi/lib/values.js +263 -0
  53. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  54. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
  55. package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
  56. package/dist/node_modules/joi/package.json +1 -0
  57. package/dist/server/actions/portainer.js +192 -0
  58. package/dist/server/collections/portainer-instances.js +54 -0
  59. package/dist/server/index.js +54 -0
  60. package/dist/server/instructions/PortainerStackControlInstruction.js +156 -0
  61. package/dist/server/instructions/PortainerStackRedeployInstruction.js +254 -0
  62. package/dist/server/instructions/helpers.js +211 -0
  63. package/dist/server/plugin.js +170 -0
  64. package/dist/server/services/PortainerClient.js +497 -0
  65. package/dist/shared/collection.js +57 -0
  66. package/dist/shared/constants.js +66 -0
  67. package/dist/shared/env.js +221 -0
  68. package/dist/shared/types.js +24 -0
  69. package/package.json +50 -4
  70. package/server.js +1 -0
  71. package/src/client/index.tsx +50 -0
  72. package/src/client/instructions.tsx +76 -0
  73. package/src/client-v2/__tests__/workflow-registration.test.tsx +132 -0
  74. package/src/client-v2/components/ControlFieldset.tsx +46 -0
  75. package/src/client-v2/components/PortainerEnvEditor.tsx +223 -0
  76. package/src/client-v2/components/PortainerSettingsPage.tsx +671 -0
  77. package/src/client-v2/components/PortainerTargetFields.tsx +317 -0
  78. package/src/client-v2/components/RedeployFieldset.tsx +123 -0
  79. package/src/client-v2/index.tsx +50 -0
  80. package/src/client-v2/instructions.tsx +162 -0
  81. package/src/client-v2/locale.ts +24 -0
  82. package/src/index.ts +11 -0
  83. package/src/locale/en-US.json +151 -0
  84. package/src/locale/vi-VN.json +151 -0
  85. package/src/locale/zh-CN.json +151 -0
  86. package/src/server/__tests__/portainer-workflow.test.ts +455 -0
  87. package/src/server/actions/portainer.ts +196 -0
  88. package/src/server/collections/portainer-instances.ts +34 -0
  89. package/src/server/index.ts +13 -0
  90. package/src/server/instructions/PortainerStackControlInstruction.ts +139 -0
  91. package/src/server/instructions/PortainerStackRedeployInstruction.ts +255 -0
  92. package/src/server/instructions/helpers.ts +237 -0
  93. package/src/server/plugin.ts +167 -0
  94. package/src/server/services/PortainerClient.ts +589 -0
  95. package/src/shared/collection.ts +32 -0
  96. package/src/shared/constants.ts +25 -0
  97. package/src/shared/env.ts +228 -0
  98. package/src/shared/types.ts +105 -0
@@ -0,0 +1,221 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var env_exports = {};
28
+ __export(env_exports, {
29
+ buildEffectiveStackEnv: () => buildEffectiveStackEnv,
30
+ isLikelySensitiveKey: () => isLikelySensitiveKey,
31
+ isValidEnvKey: () => isValidEnvKey,
32
+ normalizeGitReference: () => normalizeGitReference,
33
+ parseDotEnvText: () => parseDotEnvText,
34
+ parseDynamicEnvInput: () => parseDynamicEnvInput,
35
+ stringifyEnvValue: () => stringifyEnvValue
36
+ });
37
+ module.exports = __toCommonJS(env_exports);
38
+ var import_constants = require("./constants");
39
+ const ENV_KEY_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
40
+ const SENSITIVE_ENV_KEY_PATTERN = /(password|passwd|secret|token|api[_-]?key|private[_-]?key|access[_-]?key)/i;
41
+ function isValidEnvKey(key) {
42
+ return ENV_KEY_PATTERN.test(key.trim());
43
+ }
44
+ function isLikelySensitiveKey(key) {
45
+ return SENSITIVE_ENV_KEY_PATTERN.test(key);
46
+ }
47
+ function stripMatchingQuotes(raw) {
48
+ if (raw.length >= 2) {
49
+ const first = raw[0];
50
+ const last = raw[raw.length - 1];
51
+ if (first === '"' && last === '"' || first === "'" && last === "'") {
52
+ return raw.slice(1, -1);
53
+ }
54
+ }
55
+ return raw;
56
+ }
57
+ function stringifyEnvValue(value) {
58
+ if (value === null || typeof value === "undefined") {
59
+ return "";
60
+ }
61
+ if (typeof value === "string") {
62
+ return value;
63
+ }
64
+ if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
65
+ return String(value);
66
+ }
67
+ return JSON.stringify(value);
68
+ }
69
+ function parseDotEnvText(text) {
70
+ if (!text || typeof text !== "string") {
71
+ return [];
72
+ }
73
+ const result = [];
74
+ const lines = text.split(/\r?\n/);
75
+ for (const rawLine of lines) {
76
+ const trimmed = rawLine.trim();
77
+ if (!trimmed || trimmed.startsWith("#")) {
78
+ continue;
79
+ }
80
+ const normalized = trimmed.startsWith("export ") ? trimmed.slice(7).trim() : trimmed;
81
+ const eqIndex = normalized.indexOf("=");
82
+ if (eqIndex <= 0) {
83
+ continue;
84
+ }
85
+ const name = normalized.slice(0, eqIndex).trim();
86
+ if (!isValidEnvKey(name)) {
87
+ continue;
88
+ }
89
+ const rawVal = normalized.slice(eqIndex + 1).trim();
90
+ result.push({
91
+ name,
92
+ value: stripMatchingQuotes(rawVal)
93
+ });
94
+ }
95
+ return result;
96
+ }
97
+ function isPlainRecord(value) {
98
+ return typeof value === "object" && value !== null && !Array.isArray(value);
99
+ }
100
+ function parseDynamicEnvInput(input) {
101
+ if (input === null || typeof input === "undefined" || input === "") {
102
+ return [];
103
+ }
104
+ let resolved = input;
105
+ if (typeof input === "string") {
106
+ const trimmed = input.trim();
107
+ if (!trimmed) {
108
+ return [];
109
+ }
110
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
111
+ try {
112
+ resolved = JSON.parse(trimmed);
113
+ } catch {
114
+ throw new Error("Dynamic environment JSON is invalid");
115
+ }
116
+ } else {
117
+ return parseDotEnvText(trimmed);
118
+ }
119
+ }
120
+ if (Array.isArray(resolved)) {
121
+ const pairs = [];
122
+ for (const item of resolved) {
123
+ if (!isPlainRecord(item)) {
124
+ continue;
125
+ }
126
+ const rawName = typeof item.name === "string" ? item.name : typeof item.key === "string" ? item.key : "";
127
+ const name = rawName.trim();
128
+ if (!name || !isValidEnvKey(name)) {
129
+ continue;
130
+ }
131
+ pairs.push({
132
+ name,
133
+ value: stringifyEnvValue(item.value)
134
+ });
135
+ }
136
+ return pairs;
137
+ }
138
+ if (isPlainRecord(resolved)) {
139
+ const pairs = [];
140
+ for (const [rawKey, val] of Object.entries(resolved)) {
141
+ const name = rawKey.trim();
142
+ if (!name || !isValidEnvKey(name)) {
143
+ continue;
144
+ }
145
+ pairs.push({
146
+ name,
147
+ value: stringifyEnvValue(val)
148
+ });
149
+ }
150
+ return pairs;
151
+ }
152
+ return [];
153
+ }
154
+ function buildEffectiveStackEnv(options) {
155
+ const map = /* @__PURE__ */ new Map();
156
+ const explicitSecrets = /* @__PURE__ */ new Set();
157
+ if ((options.strategy ?? "merge") === "merge" && Array.isArray(options.existingEnv)) {
158
+ for (const item of options.existingEnv) {
159
+ const name = String((item == null ? void 0 : item.name) ?? "").trim();
160
+ if (name) {
161
+ map.set(name, stringifyEnvValue(item.value));
162
+ }
163
+ }
164
+ }
165
+ for (const item of parseDynamicEnvInput(options.dynamicEnv)) {
166
+ map.set(item.name, item.value);
167
+ }
168
+ for (const item of parseDotEnvText(options.envText)) {
169
+ map.set(item.name, item.value);
170
+ }
171
+ if (Array.isArray(options.envPairs)) {
172
+ for (const item of options.envPairs) {
173
+ const name = String((item == null ? void 0 : item.name) ?? "").trim();
174
+ if (!name) {
175
+ continue;
176
+ }
177
+ if (!isValidEnvKey(name)) {
178
+ throw new Error(`Invalid environment variable name "${name}"`);
179
+ }
180
+ map.set(name, stringifyEnvValue(item.value));
181
+ if (item.secret) {
182
+ explicitSecrets.add(name);
183
+ }
184
+ }
185
+ }
186
+ const env = [];
187
+ const maskedEnv = {};
188
+ const secretKeys = [];
189
+ for (const [name, value] of map.entries()) {
190
+ env.push({ name, value });
191
+ const shouldMask = explicitSecrets.has(name) || isLikelySensitiveKey(name);
192
+ if (shouldMask) {
193
+ secretKeys.push(name);
194
+ maskedEnv[name] = import_constants.SECRET_MASK;
195
+ } else {
196
+ maskedEnv[name] = value;
197
+ }
198
+ }
199
+ return { env, maskedEnv, secretKeys };
200
+ }
201
+ function normalizeGitReference(ref, fallback) {
202
+ const raw = String(ref ?? "").trim();
203
+ if (!raw) {
204
+ const fb = String(fallback ?? "").trim();
205
+ return fb || "refs/heads/main";
206
+ }
207
+ if (raw.startsWith("refs/")) {
208
+ return raw;
209
+ }
210
+ return `refs/heads/${raw}`;
211
+ }
212
+ // Annotate the CommonJS export names for ESM import in node:
213
+ 0 && (module.exports = {
214
+ buildEffectiveStackEnv,
215
+ isLikelySensitiveKey,
216
+ isValidEnvKey,
217
+ normalizeGitReference,
218
+ parseDotEnvText,
219
+ parseDynamicEnvInput,
220
+ stringifyEnvValue
221
+ });
@@ -0,0 +1,24 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var types_exports = {};
24
+ module.exports = __toCommonJS(types_exports);
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "plugin-workflow-portainer",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "displayName": "Portainer Workflows",
4
+ "displayName.zh-CN": "Portainer 工作流",
5
+ "displayName.vi-VN": "Luồng công việc Portainer",
6
+ "description": "Workflow nodes and connection management for running, redeploying, and controlling Portainer stacks across environments.",
7
+ "description.zh-CN": "用于在多环境中运行、重新部署和控制 Portainer Stack 的工作流节点与连接管理插件。",
8
+ "description.vi-VN": "Cung cấp các node Workflow và quản lý kết nối để chạy, redeploy và kiểm soát Portainer Stack đa môi trường.",
9
+ "version": "0.1.1",
10
+ "license": "Apache-2.0",
11
+ "main": "dist/server/index.js",
12
+ "keywords": [
13
+ "NocoBase",
14
+ "Workflow",
15
+ "Portainer",
16
+ "Docker",
17
+ "CI/CD",
18
+ "GitOps"
19
+ ],
20
+ "files": [
21
+ "dist",
22
+ "src",
23
+ "client.js",
24
+ "client-v2.js",
25
+ "server.js"
26
+ ],
27
+ "nocobase": {
28
+ "supportedVersions": [
29
+ "2.x"
30
+ ],
31
+ "editionLevel": 0
32
+ },
33
+ "peerDependencies": {
34
+ "@nocobase/actions": "2.x",
35
+ "@nocobase/client": "2.x",
36
+ "@nocobase/client-v2": "2.x",
37
+ "@nocobase/database": "2.x",
38
+ "@nocobase/flow-engine": "2.x",
39
+ "@nocobase/server": "2.x",
40
+ "@nocobase/plugin-workflow": "2.x"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/OrgGem/nocobase-beta.git",
45
+ "directory": "packages/plugins/plugin-workflow-portainer"
46
+ },
47
+ "gitHead": "419b2f1cffa8a4020eb2f9ce66203a994d51a7b9",
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "registry": "https://registry.npmjs.org/"
51
+ }
52
+ }
package/server.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/server/index.js');
@@ -0,0 +1,50 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { Plugin } from '@nocobase/client';
11
+ import type { Instruction } from '@nocobase/plugin-workflow/client';
12
+ import React from 'react';
13
+ import type { WorkflowInstructionRegistryLike } from '../client-v2/instructions';
14
+ import { portainerInstancesCollection } from '../shared/collection';
15
+ import { PORTAINER_ACL_SNIPPET } from '../shared/constants';
16
+ import { registerInstructionsV1 } from './instructions';
17
+
18
+ const PortainerSettingsPage = React.lazy(() => import('../client-v2/components/PortainerSettingsPage'));
19
+
20
+ export class PluginWorkflowPortainerClient extends Plugin {
21
+ async load() {
22
+ const dataSource = this.app.dataSourceManager.getDataSource('main');
23
+ if (dataSource) {
24
+ const registerCollection = () => {
25
+ if (!dataSource.collectionManager.getCollection(portainerInstancesCollection.name)) {
26
+ dataSource.collectionManager.addCollections([portainerInstancesCollection]);
27
+ }
28
+ };
29
+ registerCollection();
30
+ dataSource.addReloadCallback(registerCollection);
31
+ }
32
+
33
+ const workflow = (this.app.pm.get('workflow') || this.app.pm.get('@nocobase/plugin-workflow')) as
34
+ | WorkflowInstructionRegistryLike<Instruction>
35
+ | undefined;
36
+
37
+ if (workflow) {
38
+ registerInstructionsV1(workflow);
39
+ }
40
+
41
+ this.app.pluginSettingsManager.add('workflow-portainer', {
42
+ title: this.t('Portainer Workflows'),
43
+ icon: 'CloudServerOutlined',
44
+ Component: PortainerSettingsPage,
45
+ aclSnippet: PORTAINER_ACL_SNIPPET,
46
+ });
47
+ }
48
+ }
49
+
50
+ export default PluginWorkflowPortainerClient;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { CloudUploadOutlined, ClusterOutlined } from '@ant-design/icons';
11
+ import { Instruction } from '@nocobase/plugin-workflow/client';
12
+ import type { UseVariableOptions } from '@nocobase/plugin-workflow/client-v2';
13
+ import React from 'react';
14
+ import {
15
+ buildControlVariableOption,
16
+ buildRedeployVariableOption,
17
+ defaultControlConfig,
18
+ defaultRedeployConfig,
19
+ type WorkflowInstructionRegistryLike,
20
+ } from '../client-v2/instructions';
21
+ import { tExpr } from '../client-v2/locale';
22
+ import { INSTRUCTION_GROUP_KEY, INSTRUCTION_TYPES } from '../shared/constants';
23
+
24
+ type NodeLike = {
25
+ key: string;
26
+ title: string;
27
+ };
28
+
29
+ export class PortainerStackRedeployInstructionV1 extends Instruction {
30
+ type = INSTRUCTION_TYPES.redeploy;
31
+ title = tExpr('Run / Redeploy Stack');
32
+ description = tExpr(
33
+ 'Pull Git changes, build compose services, or redeploy a Portainer Stack with full environment variable control.',
34
+ );
35
+ group = INSTRUCTION_GROUP_KEY;
36
+ icon = (<CloudUploadOutlined />);
37
+ testable = true;
38
+ FieldsetLoader = () =>
39
+ import('../client-v2/components/RedeployFieldset').then((module) => ({ default: module.RedeployFieldset }));
40
+
41
+ createDefaultConfig() {
42
+ return defaultRedeployConfig();
43
+ }
44
+
45
+ useVariables(node: NodeLike, options?: UseVariableOptions) {
46
+ return buildRedeployVariableOption(node, options);
47
+ }
48
+ }
49
+
50
+ export class PortainerStackControlInstructionV1 extends Instruction {
51
+ type = INSTRUCTION_TYPES.control;
52
+ title = tExpr('Control / Inspect Stack');
53
+ description = tExpr('Inspect Stack container health, start, or stop a Portainer Stack in an environment.');
54
+ group = INSTRUCTION_GROUP_KEY;
55
+ icon = (<ClusterOutlined />);
56
+ testable = true;
57
+ FieldsetLoader = () =>
58
+ import('../client-v2/components/ControlFieldset').then((module) => ({ default: module.ControlFieldset }));
59
+
60
+ createDefaultConfig() {
61
+ return defaultControlConfig();
62
+ }
63
+
64
+ useVariables(node: NodeLike, options?: UseVariableOptions) {
65
+ return buildControlVariableOption(node, options);
66
+ }
67
+ }
68
+
69
+ export function registerInstructionsV1(workflow: WorkflowInstructionRegistryLike<Instruction>) {
70
+ workflow.registerInstructionGroup?.(INSTRUCTION_GROUP_KEY, {
71
+ key: INSTRUCTION_GROUP_KEY,
72
+ label: tExpr('Portainer'),
73
+ });
74
+ workflow.registerInstruction?.(INSTRUCTION_TYPES.redeploy, PortainerStackRedeployInstructionV1);
75
+ workflow.registerInstruction?.(INSTRUCTION_TYPES.control, PortainerStackControlInstructionV1);
76
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import PluginWorkflowPortainerClient from '../../client';
11
+ import PluginWorkflowPortainerClientV2 from '../index';
12
+ import { INSTRUCTION_GROUP_KEY, INSTRUCTION_TYPES } from '../../shared/constants';
13
+
14
+ const runtimes = vi.hoisted(() => {
15
+ class V1Instruction {}
16
+ class V2Instruction {}
17
+ const ExtendCollectionsProvider = () => null;
18
+ return { V1Instruction, V2Instruction, ExtendCollectionsProvider };
19
+ });
20
+
21
+ vi.mock('@nocobase/client', () => ({ Plugin: class Plugin {} }));
22
+ vi.mock('@nocobase/client-v2', () => ({
23
+ Plugin: class Plugin {},
24
+ ExtendCollectionsProvider: runtimes.ExtendCollectionsProvider,
25
+ useApp: () => ({ i18n: { t: (key: string) => key } }),
26
+ }));
27
+ vi.mock('@nocobase/plugin-workflow/client', () => ({
28
+ Instruction: runtimes.V1Instruction,
29
+ }));
30
+ vi.mock('@nocobase/plugin-workflow/client-v2', () => ({
31
+ Instruction: runtimes.V2Instruction,
32
+ defaultFieldNames: { value: 'value', label: 'label', children: 'children' },
33
+ }));
34
+ vi.mock('@ant-design/icons', () => ({
35
+ CloudUploadOutlined: () => null,
36
+ ClusterOutlined: () => null,
37
+ }));
38
+
39
+ function createStrictWorkflow(baseClass: new (...args: never[]) => object) {
40
+ const instructions = new Map<string, Record<string, unknown>>();
41
+ const groups = new Map<string, { key: string; label: string }>();
42
+
43
+ return {
44
+ instructions,
45
+ groups,
46
+ registerInstructionGroup(key: string, group: { key: string; label: string }) {
47
+ groups.set(key, group);
48
+ },
49
+ registerInstruction(type: string, ctorOrInstance: object | (new () => object)) {
50
+ const instance = typeof ctorOrInstance === 'function' ? new ctorOrInstance() : ctorOrInstance;
51
+ if (!(instance instanceof baseClass)) {
52
+ throw new TypeError(`Instruction ${type} does not match runtime Instruction base class`);
53
+ }
54
+ instructions.set(type, instance as Record<string, unknown>);
55
+ },
56
+ };
57
+ }
58
+
59
+ describe('Portainer workflow dual-runtime client registration', () => {
60
+ it('registers v1 instructions extending @nocobase/plugin-workflow/client Instruction and collection reload hook', async () => {
61
+ const workflow = createStrictWorkflow(runtimes.V1Instruction);
62
+ const collections = new Map<string, object>();
63
+ const reloadCallbacks: Array<() => void> = [];
64
+ const dataSource = {
65
+ collectionManager: {
66
+ getCollection: (name: string) => collections.get(name),
67
+ addCollections: (items: Array<{ name: string }>) => {
68
+ for (const item of items) collections.set(item.name, item);
69
+ },
70
+ },
71
+ addReloadCallback: (cb: () => void) => reloadCallbacks.push(cb),
72
+ };
73
+
74
+ const pluginCtx = {
75
+ app: {
76
+ pm: { get: vi.fn(() => workflow) },
77
+ dataSourceManager: { getDataSource: vi.fn(() => dataSource) },
78
+ pluginSettingsManager: { add: vi.fn() },
79
+ },
80
+ t: (key: string) => key,
81
+ };
82
+
83
+ await PluginWorkflowPortainerClient.prototype.load.call(pluginCtx as unknown as PluginWorkflowPortainerClient);
84
+
85
+ expect(collections.has('portainerInstances')).toBe(true);
86
+ collections.delete('portainerInstances');
87
+ reloadCallbacks[0]();
88
+ expect(collections.has('portainerInstances')).toBe(true);
89
+
90
+ expect(workflow.groups.has(INSTRUCTION_GROUP_KEY)).toBe(true);
91
+ expect(workflow.instructions.has(INSTRUCTION_TYPES.redeploy)).toBe(true);
92
+ expect(workflow.instructions.has(INSTRUCTION_TYPES.control)).toBe(true);
93
+
94
+ const redeployInst = workflow.instructions.get(INSTRUCTION_TYPES.redeploy) as {
95
+ useVariables: (node: { key: string; title: string }) => { children: Array<{ value: string }> };
96
+ };
97
+ const vars = redeployInst.useVariables({ key: 'build_node', title: 'Build Stack' });
98
+ const childKeys = vars.children.map((item) => item.value);
99
+ expect(childKeys).toContain('stackId');
100
+ expect(childKeys).toContain('endpointId');
101
+ expect(childKeys).toContain('healthy');
102
+ expect(childKeys).toContain('appliedEnv');
103
+ });
104
+
105
+ it('registers v2 instructions extending @nocobase/plugin-workflow/client-v2 Instruction and settings page', async () => {
106
+ const workflow = createStrictWorkflow(runtimes.V2Instruction);
107
+ const addMenuItem = vi.fn();
108
+ const addPageTabItem = vi.fn();
109
+
110
+ const pluginCtx = {
111
+ app: {
112
+ pm: { get: vi.fn(() => workflow) },
113
+ addProvider: vi.fn(),
114
+ },
115
+ pluginSettingsManager: {
116
+ addMenuItem,
117
+ addPageTabItem,
118
+ },
119
+ t: (key: string) => key,
120
+ };
121
+
122
+ await PluginWorkflowPortainerClientV2.prototype.load.call(pluginCtx as unknown as PluginWorkflowPortainerClientV2);
123
+
124
+ expect(pluginCtx.app.addProvider).toHaveBeenCalledWith(runtimes.ExtendCollectionsProvider, {
125
+ collections: [expect.objectContaining({ name: 'portainerInstances' })],
126
+ });
127
+ expect(workflow.instructions.get(INSTRUCTION_TYPES.redeploy)).toBeInstanceOf(runtimes.V2Instruction);
128
+ expect(workflow.instructions.get(INSTRUCTION_TYPES.control)).toBeInstanceOf(runtimes.V2Instruction);
129
+ expect(addMenuItem).toHaveBeenCalledTimes(1);
130
+ expect(addPageTabItem).toHaveBeenCalledTimes(1);
131
+ });
132
+ });
@@ -0,0 +1,46 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { Checkbox, Form, Radio } from 'antd';
11
+ import React from 'react';
12
+ import { useT } from '../locale';
13
+ import { PortainerTargetFields } from './PortainerTargetFields';
14
+
15
+ export function ControlFieldset() {
16
+ const t = useT();
17
+
18
+ return (
19
+ <>
20
+ <Form.Item
21
+ name={['config', 'action']}
22
+ label={t('Stack operation')}
23
+ initialValue="inspect"
24
+ extra={t(
25
+ 'Inspect retrieves Stack status, current Env keys, and container health without restarting services; Start and Stop control the Stack lifecycle.',
26
+ )}
27
+ >
28
+ <Radio.Group
29
+ options={[
30
+ { value: 'inspect', label: t('Inspect Stack & Health') },
31
+ { value: 'start', label: t('Start Stack') },
32
+ { value: 'stop', label: t('Stop Stack') },
33
+ ]}
34
+ />
35
+ </Form.Item>
36
+
37
+ <PortainerTargetFields />
38
+
39
+ <Form.Item name={['config', 'ignoreFail']} valuePropName="checked" initialValue={false}>
40
+ <Checkbox>{t('Ignore failed execution and continue workflow')}</Checkbox>
41
+ </Form.Item>
42
+ </>
43
+ );
44
+ }
45
+
46
+ export default ControlFieldset;