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,223 @@
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 { CloudDownloadOutlined, DeleteOutlined, PlusOutlined } from '@ant-design/icons';
11
+ import { useApp } from '@nocobase/client-v2';
12
+ import {
13
+ WorkflowVariableInput,
14
+ WorkflowVariableJsonTextArea,
15
+ WorkflowVariableTextArea,
16
+ } from '@nocobase/plugin-workflow/client-v2';
17
+ import { Button, Checkbox, Collapse, Flex, Form, Input, message, Radio, Space } from 'antd';
18
+ import React, { useState } from 'react';
19
+ import { PORTAINER_RESOURCE } from '../../shared/constants';
20
+ import type { ConfigurableEnvItem } from '../../shared/types';
21
+ import { useT } from '../locale';
22
+ import type { StaticStackContext } from './PortainerTargetFields';
23
+
24
+ interface StackEnvEntry {
25
+ name: string;
26
+ value: string;
27
+ sensitive?: boolean;
28
+ }
29
+
30
+ export function PortainerEnvEditor({ stackContext }: { stackContext?: StaticStackContext }) {
31
+ const t = useT();
32
+ const api = useApp().apiClient;
33
+ const form = Form.useFormInstance();
34
+ const [loadingStackEnv, setLoadingStackEnv] = useState(false);
35
+
36
+ const canLoadFromStack = Boolean(stackContext?.stack?.id);
37
+
38
+ const handleLoadFromStack = async () => {
39
+ const stackId = stackContext?.stack?.id;
40
+ if (!stackId) {
41
+ return;
42
+ }
43
+ setLoadingStackEnv(true);
44
+ try {
45
+ const res = await api.request<{ data?: { env?: StackEnvEntry[] } }>({
46
+ url: `${PORTAINER_RESOURCE}:getStackDetail`,
47
+ method: 'get',
48
+ params: {
49
+ ...(stackContext?.instanceId ? { instanceId: stackContext.instanceId } : {}),
50
+ stackId,
51
+ includeValues: true,
52
+ },
53
+ });
54
+ const remoteEnv = Array.isArray(res?.data?.data?.env) ? res.data.data.env : [];
55
+ const currentPairs = (form.getFieldValue(['config', 'envPairs']) as ConfigurableEnvItem[] | undefined) ?? [];
56
+ const existingNames = new Set(currentPairs.map((item) => String(item?.name ?? '').trim()).filter(Boolean));
57
+
58
+ let importedCount = 0;
59
+ let skippedSensitiveCount = 0;
60
+ const nextPairs = [...currentPairs];
61
+
62
+ for (const entry of remoteEnv) {
63
+ const keyName = String(entry.name ?? '').trim();
64
+ if (!keyName || existingNames.has(keyName)) {
65
+ continue;
66
+ }
67
+ if (entry.sensitive) {
68
+ skippedSensitiveCount += 1;
69
+ continue;
70
+ }
71
+ nextPairs.push({
72
+ name: keyName,
73
+ value: entry.value,
74
+ secret: false,
75
+ });
76
+ existingNames.add(keyName);
77
+ importedCount += 1;
78
+ }
79
+
80
+ form.setFieldValue(['config', 'envPairs'], nextPairs);
81
+ if (skippedSensitiveCount > 0) {
82
+ message.info(
83
+ t('Loaded {{count}} variables ({{sensitive}} sensitive keys stay preserved on Portainer in Merge mode)', {
84
+ count: importedCount,
85
+ sensitive: skippedSensitiveCount,
86
+ }),
87
+ );
88
+ } else {
89
+ message.success(t('Loaded {{count}} variables from Portainer Stack', { count: importedCount }));
90
+ }
91
+ } catch {
92
+ message.error(t('Failed to load environment variables from Portainer Stack'));
93
+ } finally {
94
+ setLoadingStackEnv(false);
95
+ }
96
+ };
97
+
98
+ return (
99
+ <>
100
+ <Form.Item
101
+ name={['config', 'envStrategy']}
102
+ label={t('Environment merge strategy')}
103
+ initialValue="merge"
104
+ extra={t(
105
+ 'Merge keeps existing Portainer Stack variables intact and overrides matching keys; Replace overwrites the entire Stack Env list.',
106
+ )}
107
+ >
108
+ <Radio.Group
109
+ options={[
110
+ { value: 'merge', label: t('Merge & override existing Stack Env') },
111
+ { value: 'replace', label: t('Replace all Stack Env') },
112
+ ]}
113
+ />
114
+ </Form.Item>
115
+
116
+ <Form.Item
117
+ label={
118
+ <Flex align="center" justify="space-between" gap="middle" style={{ width: '100%' }}>
119
+ <span>{t('Environment variables (Key-Value)')}</span>
120
+ {canLoadFromStack ? (
121
+ <Button
122
+ size="small"
123
+ htmlType="button"
124
+ icon={<CloudDownloadOutlined />}
125
+ loading={loadingStackEnv}
126
+ onClick={handleLoadFromStack}
127
+ >
128
+ {t('Load Env from Stack')}
129
+ </Button>
130
+ ) : null}
131
+ </Flex>
132
+ }
133
+ extra={t(
134
+ 'Add variables such as IMAGE_TAG or runtime settings. Mark sensitive values as Secret to redact them in workflow execution logs.',
135
+ )}
136
+ >
137
+ <Form.List name={['config', 'envPairs']}>
138
+ {(fields, { add, remove }) => (
139
+ <Space direction="vertical" style={{ display: 'flex' }}>
140
+ {fields.map((field, index) => {
141
+ const currentName = String(form.getFieldValue(['config', 'envPairs', field.name, 'name']) ?? '').trim();
142
+ const deleteLabel = currentName
143
+ ? `${t('Delete environment variable')} ${currentName}`
144
+ : `${t('Delete environment variable')} #${index + 1}`;
145
+
146
+ return (
147
+ <Flex key={field.key} align="center" gap="small" wrap="wrap" style={{ width: '100%' }}>
148
+ <Form.Item name={[field.name, 'name']} style={{ flex: '1 1 160px', marginBottom: 0 }}>
149
+ <Input placeholder="IMAGE_TAG" autoCorrect="off" autoCapitalize="none" spellCheck={false} />
150
+ </Form.Item>
151
+ <Form.Item name={[field.name, 'value']} style={{ flex: '2 1 220px', marginBottom: 0 }}>
152
+ <WorkflowVariableInput placeholder={t('Value or {{variable}}')} />
153
+ </Form.Item>
154
+ <Form.Item
155
+ name={[field.name, 'secret']}
156
+ valuePropName="checked"
157
+ initialValue={false}
158
+ style={{ marginBottom: 0 }}
159
+ >
160
+ <Checkbox>{t('Secret')}</Checkbox>
161
+ </Form.Item>
162
+ <Button
163
+ htmlType="button"
164
+ aria-label={deleteLabel}
165
+ icon={<DeleteOutlined />}
166
+ onClick={() => remove(field.name)}
167
+ />
168
+ </Flex>
169
+ );
170
+ })}
171
+ <Button
172
+ htmlType="button"
173
+ icon={<PlusOutlined />}
174
+ onClick={() => add({ name: '', value: '', secret: false })}
175
+ style={{ width: '100%' }}
176
+ >
177
+ {t('Add environment variable')}
178
+ </Button>
179
+ </Space>
180
+ )}
181
+ </Form.List>
182
+ </Form.Item>
183
+
184
+ <Collapse
185
+ size="small"
186
+ style={{ marginBottom: 16 }}
187
+ items={[
188
+ {
189
+ key: 'bulk-env',
190
+ label: t('Bulk .env text & dynamic JSON environment'),
191
+ children: (
192
+ <>
193
+ <Form.Item
194
+ name={['config', 'envText']}
195
+ label={t('Bulk .env format')}
196
+ extra={t('Enter KEY=VALUE lines. Supports upstream workflow variables.')}
197
+ >
198
+ <WorkflowVariableTextArea
199
+ autoSize={{ minRows: 3, maxRows: 8 }}
200
+ placeholder={'IMAGE_TAG=v1.0.0\nNODE_ENV=production'}
201
+ />
202
+ </Form.Item>
203
+ <Form.Item
204
+ name={['config', 'dynamicEnv']}
205
+ label={t('Dynamic environment JSON / variable')}
206
+ extra={t(
207
+ 'Pass a JSON object {"KEY":"VAL"}, an array [{"name":"KEY","value":"VAL"}], or a workflow variable from a build catalog record.',
208
+ )}
209
+ style={{ marginBottom: 0 }}
210
+ >
211
+ <WorkflowVariableJsonTextArea
212
+ autoSize={{ minRows: 2, maxRows: 6 }}
213
+ placeholder={'{"IMAGE_TAG": "{{$context.data.imageTag}}"}'}
214
+ />
215
+ </Form.Item>
216
+ </>
217
+ ),
218
+ },
219
+ ]}
220
+ />
221
+ </>
222
+ );
223
+ }