@steedos/service-package-registry 3.0.0-beta.25 → 3.0.0-beta.27

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.
@@ -0,0 +1,48 @@
1
+ module.exports = {
2
+ disable: function (object_name, record_id) {
3
+ Steedos.sobject(object_name).retrieve(record_id).then((record)=>{
4
+ if(!record){
5
+ return SteedosUI.notification.error({message: '未找到软件包'})
6
+ }
7
+ SteedosUI.Modal.confirm({
8
+ title: t('steedos_packages.disable.title'),
9
+ content: t('steedos_packages.disable.text') + ` ${record.name}?`,
10
+ okText: t('steedos_packages.disable.title'),
11
+ cancelText: t('Cancel'),
12
+ onOk: function(){
13
+ Steedos.authRequest(Steedos.absoluteUrl('/api/nodes/disable'), {type: 'post', async: false, data: JSON.stringify({
14
+ module: record.name,
15
+ nodeID: window.$("#steedos_package_main_node").val()
16
+ }),
17
+ success: function(data){
18
+ if(data.status == 1){
19
+ SteedosUI.notification.error({message: data.msg});
20
+ return;
21
+ }
22
+ setTimeout(function(){
23
+ SteedosUI.notification.success({
24
+ message: t('steedos_packages.disable.toastr_success')
25
+ });
26
+ window.location.reload()
27
+ }, 1000 * 2)
28
+ },
29
+ error: function(XMLHttpRequest){
30
+ SteedosUI.notification.error({message: XMLHttpRequest.responseJSON.msg});
31
+ }
32
+ })
33
+ }
34
+ });
35
+ })
36
+
37
+ },
38
+ disableVisible: function (object_name, record_id, permission, data) {
39
+ if(Steedos.settings.public.enable_saas){
40
+ return false;
41
+ }
42
+ const record = data?.record || {};
43
+ if (record.status === 'enable') {
44
+ return true;
45
+ }
46
+ return false
47
+ }
48
+ }
@@ -0,0 +1,4 @@
1
+ name: disable
2
+ is_enable: true
3
+ label: 停用
4
+ 'on': record
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ edit_npmrcVisible: function (object_name, record_id) {
3
+ if(Steedos.settings.public.enable_saas){
4
+ return false;
5
+ }
6
+ return Steedos.isSpaceAdmin();
7
+ }
8
+ }
@@ -0,0 +1,86 @@
1
+ name: edit_npmrc
2
+ amis_schema: |-
3
+ {
4
+ "type": "service",
5
+ "body": [
6
+ {
7
+ "type": "button",
8
+ "label": "验证信息",
9
+ "id": "u:edit_npmrc",
10
+ "editorState": "default",
11
+ "onEvent": {
12
+ "click": {
13
+ "weight": 0,
14
+ "actions": [
15
+ {
16
+ "actionType": "dialog",
17
+ "dialog": {
18
+ "type": "dialog",
19
+ "title": "验证信息",
20
+ "body": [
21
+ {
22
+ "type": "form",
23
+ "title": "表单",
24
+ "body": [
25
+ {
26
+ "type": "editor",
27
+ "label": false,
28
+ "name": "npmrc",
29
+ "id": "u:71b44f532def",
30
+ "language": "bat"
31
+ }
32
+ ],
33
+ "id": "u:c9b0e17d4ebd",
34
+ "initApi": {
35
+ "url": "/api/nodes/npmrc",
36
+ "method": "get"
37
+ },
38
+ "api": {
39
+ "url": "/api/nodes/npmrc",
40
+ "method": "post",
41
+ "requestAdaptor": "",
42
+ "adaptor": "",
43
+ "messages": {}
44
+ }
45
+ },
46
+ {
47
+ "type": "tpl",
48
+ "tpl": "<br/>"
49
+ },
50
+ {
51
+ "type": "markdown",
52
+ "value": "##### 验证信息说明(.npmrc):\r- `; 为范围包设置新的注册表`\r- `@myscope:registry=https://mycustomregistry.example.org`\r- `; 配置新注册表的认证信息(可选)`\r- `//mycustomregistry.example.org:_authToken=\"认证信息\"`"
53
+ }
54
+ ],
55
+ "showCloseButton": true,
56
+ "showErrorMsg": true,
57
+ "showLoading": true,
58
+ "className": "app-popover",
59
+ "id": "u:00682dd0eb74",
60
+ "closeOnEsc": false,
61
+ "size": "lg"
62
+ }
63
+ }
64
+ ]
65
+ }
66
+ }
67
+ }
68
+ ],
69
+ "regions": [
70
+ "body"
71
+ ],
72
+ "data": {
73
+ "context": {},
74
+ "dataComponentId": "",
75
+ "record_id": "",
76
+ "record": {},
77
+ "permissions": {}
78
+ },
79
+ "bodyClassName": "p-0",
80
+ "id": "u:743d34f49376"
81
+ }
82
+ is_enable: true
83
+ label: 验证信息
84
+ 'on': list
85
+ type: amis_button
86
+ visible: true
@@ -0,0 +1,49 @@
1
+ module.exports = {
2
+ enable: function (object_name, record_id) {
3
+ Steedos.sobject(object_name).retrieve(record_id).then((record)=>{
4
+ if(!record){
5
+ return SteedosUI.notification.error({message: '未找到软件包'})
6
+ }
7
+ console.log('record.....',record)
8
+
9
+ SteedosUI.Modal.confirm({
10
+ title: '启用',
11
+ content: `确定要启用${record.name}?`,
12
+ okText: '启用',
13
+ cancelText: '取消',
14
+ onOk: function(){
15
+ Steedos.authRequest(Steedos.absoluteUrl('/api/nodes/enable'), {type: 'post', async: false, data: JSON.stringify({
16
+ module: record.name,
17
+ nodeID: window.$("#steedos_package_main_node").val()
18
+ }),
19
+ success: function(data){
20
+ if(data.status == 1){
21
+ SteedosUI.notification.error({message: data.msg});
22
+ return;
23
+ }
24
+ setTimeout(function(){
25
+ SteedosUI.notification.success({
26
+ message: t('已启用')
27
+ });
28
+ window.location.reload()
29
+ }, 1000 * 2)
30
+ },
31
+ error: function(XMLHttpRequest){
32
+ SteedosUI.notification.error({message: XMLHttpRequest.responseJSON.msg});
33
+ }
34
+ })
35
+ }
36
+ });
37
+ })
38
+ },
39
+ enableVisible: function (object_name,record_id, permission, data) {
40
+ if(Steedos.settings.public.enable_saas){
41
+ return false;
42
+ }
43
+ const record = data?.record || {};
44
+ if(record.status !== 'enable'){
45
+ return true;
46
+ }
47
+ return false
48
+ }
49
+ }
@@ -0,0 +1,4 @@
1
+ name: enable
2
+ is_enable: true
3
+ label: 启用
4
+ 'on': record
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ installPackageFromUrlVisible: function (object_name, record_id) {
3
+ if(Steedos.settings.public.enable_saas){
4
+ return false;
5
+ }
6
+ return Steedos.isSpaceAdmin();
7
+ }
8
+ }
@@ -0,0 +1,129 @@
1
+ name: installPackageFromUrl
2
+ label: 手动安装软件包
3
+ 'on': list
4
+ #TODO: ${'steedos_packages.install.initialization_failure' | t} ,${'steedos_packages.install.installation_success' | t},${'steedos_packages.install.installation_failure' | t},等待amis合并分支,可用该代码,用于form组件的message属性
5
+ amis_schema: |-
6
+ {
7
+ "type": "service",
8
+ "body": [
9
+ {
10
+ "type": "button",
11
+ "label": "${'steedos_packages.install.install_package_from_url' | t}",
12
+ "id": "u:install_package_from_url",
13
+ "onEvent": {
14
+ "click": {
15
+ "actions": [
16
+ {
17
+ "actionType": "dialog",
18
+ "dialog": {
19
+ "type": "dialog",
20
+ "title": "${'steedos_packages.install.install_package_from_url' | t}",
21
+ "body": [
22
+ {
23
+ "type": "form",
24
+ "id": "u:add9d810b386",
25
+ "title": "",
26
+ "body": [
27
+ {
28
+ "label": "${'steedos_packages.install.package_name' | t}",
29
+ "type": "input-text",
30
+ "name": "package",
31
+ "id": "u:524cb8f8d888",
32
+ "required": true
33
+ },
34
+ {
35
+ "label": "镜像源",
36
+ "type": "input-text",
37
+ "name": "registry",
38
+ "id": "u:524cb8f8d666",
39
+ "required": false,
40
+ "options": [
41
+ {
42
+ "label": "淘宝源",
43
+ "value": "https://registry.npmmirror.com"
44
+ },
45
+ {
46
+ "label": "cnpm",
47
+ "value": "https://r.cnpmjs.org"
48
+ },
49
+ {
50
+ "label": "官方源",
51
+ "value": "https://registry.npmjs.org"
52
+ }
53
+ ]
54
+ }
55
+ ],
56
+ "mode": "normal",
57
+ "api": {
58
+ "method": "post",
59
+ "url": "${context.rootUrl}/api/nodes/package/add",
60
+ "data": {
61
+ "&": "$$"
62
+ },
63
+ "dataType": "json",
64
+ "requestAdaptor": "api.data = {package: api.body.registry ? `${api.body.package} --registry ${api.body.registry}` : api.body.package};",
65
+ "headers": {
66
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}"
67
+ }
68
+ },
69
+ "messages": {
70
+ "fetchFailed": "初始化失败",
71
+ "saveSuccess": "安装成功",
72
+ "saveFailed": "安装失败"
73
+ },
74
+ "onEvent": {
75
+ "submitSucc": {
76
+ "weight": 0,
77
+ "actions": [
78
+ {
79
+ "actionType": "broadcast",
80
+ "args": {
81
+ "eventName": "@data.changed.steedos_packages"
82
+ },
83
+ "data": {
84
+ "objectName": "steedos_packages",
85
+ "recordId": "install"
86
+ }
87
+ }
88
+ ]
89
+ }
90
+ }
91
+ },
92
+ {
93
+ "type": "tpl",
94
+ "tpl": "<br/>"
95
+ },
96
+ {
97
+ "type": "markdown",
98
+ "value": "##### 您可以使用以下选项之一指定版本: \r- `package-name`安装包的“最新”版本。 \r- `package-name@1.2.3`从以下位置安装包的特定版本 注册表。 \r- `package-name@tag`安装特定的“标签”。(例如)beta、next、latest"
99
+ },
100
+ {
101
+ "type": "markdown",
102
+ "value": "##### 您还可以指定来自不同位置的包:\r- `package-name` 从 npm 注册表安装包 \r- `file:/path/to/local/folder`安装一个位于本地文件系统的包。这对于测试您尚未发布到注册表的软件包很有用。 \r- `file:/path/to/local/tarball.tgz`从 gzip 压缩的 tarball,可用于在发布包之前共享包。 \r- `link:/path/to/local/folder`安装指向软件包的符号链接:在本地文件系统上。适用于monorepo环境。 \r- `<git remote url>`从远程 Git 存储库安装包。 \r- `<git remote url>#<branch/commit/tag>`从远程安装软件包特定 git 分支、git commit 或 git 标签处的 git 存储库。 \r- `https://my-project.org/package.tgz` 从远程gzip压缩压缩包。"
103
+ }
104
+ ],
105
+ "id": "u:efa30bace722",
106
+ "closeOnEsc": true,
107
+ "closeOnOutside": false,
108
+ "showCloseButton": true,
109
+ "size": "lg"
110
+ }
111
+ }
112
+ ],
113
+ "weight": 0
114
+ }
115
+ }
116
+ }
117
+ ],
118
+ "regions": [
119
+ "body"
120
+ ],
121
+ "data": {
122
+
123
+ },
124
+ "bodyClassName": "p-0",
125
+ "id": "u:43363bc48c62"
126
+ }
127
+ is_enable: true
128
+ type: amis_button
129
+ visible: true
@@ -0,0 +1,31 @@
1
+ module.exports = {
2
+ reload: function (object_name, record_id, permission, data) {
3
+ SteedosUI.notification.info({message: t('steedos_packages.reload.toastr_info')})
4
+ const record = data?.record || {};
5
+ //TODO nodeID
6
+ Steedos.authRequest(Steedos.absoluteUrl('/api/nodes/reload'), {type: 'post', async: false, data: JSON.stringify({
7
+ module: record.name,
8
+ nodeID: record.node_id
9
+ }),
10
+ success: function(){
11
+ setTimeout(function(){
12
+ SteedosUI.notification.success({message: t('steedos_packages.reload.toastr_success')})
13
+ window.location.reload()
14
+ }, 1000 * 5)
15
+ },
16
+ error: function(XMLHttpRequest){
17
+ SteedosUI.notification.error({message: XMLHttpRequest.responseJSON.error})
18
+ }
19
+ })
20
+ },
21
+ reloadVisible: function (object_name,record_id, permission, data) {
22
+ if(Steedos.settings.public.enable_saas){
23
+ return false;
24
+ }
25
+ const record = data?.record;
26
+ if(record.status === 'enable'){
27
+ return true;
28
+ }
29
+ return false
30
+ }
31
+ }
@@ -0,0 +1,4 @@
1
+ name: reload
2
+ is_enable: true
3
+ label: 重新加载
4
+ 'on': record
@@ -0,0 +1,54 @@
1
+ module.exports = {
2
+ uninstall: function (object_name, record_id) {
3
+
4
+
5
+ Steedos.sobject(object_name).retrieve(record_id).then((record)=>{
6
+ if(!record){
7
+ return SteedosUI.notification.error({message: '未找到软件包'})
8
+ }
9
+ console.log('record.....',record)
10
+
11
+ SteedosUI.Modal.confirm({
12
+ title: t('steedos_packages.uninstall.title'),
13
+ content: t('steedos_packages.uninstall.text') + ` ${record.name}`,
14
+ okText: t('steedos_packages.uninstall.title'),
15
+ cancelText: t('Cancel'),
16
+ onOk: function(){
17
+ Steedos.authRequest(Steedos.absoluteUrl('/api/nodes/uninstall'), {type: 'post', async: false, data: JSON.stringify({
18
+ module: record.name,
19
+ nodeID: window.$("#steedos_package_main_node").val()
20
+ }),
21
+ success: function(data){
22
+ if(data.status == 1){
23
+ SteedosUI.notification.error({message: data.msg});
24
+ return;
25
+ }
26
+ setTimeout(function(){
27
+ SteedosUI.notification.success({
28
+ message: t('steedos_packages.uninstall.toastr_success')
29
+ });
30
+ navigate("/app/admin/steedos_packages")
31
+ }, 1000 * 2)
32
+ },
33
+ error: function(XMLHttpRequest){
34
+ SteedosUI.notification.error({message: XMLHttpRequest.responseJSON.msg});
35
+ }
36
+ })
37
+ }
38
+ });
39
+ })
40
+ },
41
+ uninstallVisible: function (object_name,record_id, permission, data) {
42
+ if(Steedos.settings.public.enable_saas){
43
+ return false;
44
+ }
45
+ const record = data?.record;
46
+ if(record.local || record.static){
47
+ return false;
48
+ }
49
+ if(record.status){
50
+ return true;
51
+ }
52
+ return false
53
+ }
54
+ }
@@ -0,0 +1,4 @@
1
+ name: uninstall
2
+ is_enable: true
3
+ label: 卸载
4
+ 'on': record
@@ -0,0 +1,19 @@
1
+ /*
2
+ * @Author: baozhoutao@steedos.com
3
+ * @Date: 2022-12-09 18:23:36
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2025-03-07 11:59:52
6
+ * @Description:
7
+ */
8
+ module.exports = {
9
+ upgradePackageVisible: function (object_name, record_id, permission, data) {
10
+ if(Steedos.settings.public.enable_saas){
11
+ return false;
12
+ }
13
+ const record = data?.record;
14
+ if (record.status === 'enable' && !record.local && !record.static) {
15
+ return true;
16
+ }
17
+ return false
18
+ }
19
+ }
@@ -0,0 +1,147 @@
1
+ name: upgradePackage
2
+ is_enable: true
3
+ label: 升级
4
+ 'on': record_only
5
+ amis_schema: |-
6
+ {
7
+ "type": "service",
8
+ "body": [
9
+ {
10
+ "type": "button",
11
+ "label": "${'steedos_packages.upgrade.upgrade_package' | t}",
12
+ "id": "u:upgrade_package",
13
+ "onEvent": {
14
+ "click": {
15
+ "actions": [
16
+ {
17
+ "actionType": "dialog",
18
+ "dialog": {
19
+ "type": "dialog",
20
+ "title": "${'steedos_packages.upgrade.select_version' | t}",
21
+ "body": [
22
+ {
23
+ "type": "form",
24
+ "body": [
25
+ {
26
+ "type": "picker",
27
+ "required": true,
28
+ "id": "u:ae8d73bea81b",
29
+ "label": false,
30
+ "name": "version",
31
+ "valueField": "version",
32
+ "options": [
33
+ ],
34
+ "modalMode": "dialog",
35
+ "multiple": false,
36
+ "embed": true,
37
+ "source": {
38
+ "method": "get",
39
+ "url": "${context.rootUrl}/api/nodes/versions?module=${record.name}",
40
+ "requestAdaptor": "api.data={}; return api;",
41
+ "headers": {
42
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}"
43
+ }
44
+ },
45
+ "pickerSchema": {
46
+ "mode": "table",
47
+ "id": "u:34518bacaba7",
48
+ "perPageAvailable": [
49
+ 10
50
+ ],
51
+ "messages": {
52
+ },
53
+ "filter": null,
54
+ "columns": [
55
+ {
56
+ "label": "${'steedos_packages.upgrade.version_number' | t}",
57
+ "name": "version",
58
+ "id": "u:b0e787352cf4",
59
+ "placeholder": "-"
60
+ },
61
+ {
62
+ "label": "${'steedos_packages.upgrade.label' | t}",
63
+ "name": "tag",
64
+ "id": "u:f17df7e102a2",
65
+ "placeholder": "-"
66
+ }
67
+ ]
68
+ }
69
+ }
70
+ ],
71
+ "id": "u:14efe3589478",
72
+ "api": {
73
+ "method": "post",
74
+ "url": "${context.rootUrl}/api/nodes/upgrade",
75
+ "dataType": "json",
76
+ "requestAdaptor": "api.data = {module: api.body.record.name, version: api.body.version}",
77
+ "data": {
78
+ "&": "$$",
79
+ "context": "${context}",
80
+ "record": "${record}"
81
+ },
82
+ "headers": {
83
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}"
84
+ }
85
+ },
86
+ "messages": {
87
+ "saveSuccess": "升级成功",
88
+ "saveFailed": "安装失败"
89
+ }
90
+ }
91
+ ],
92
+ "id": "u:c3960c3b1049",
93
+ "closeOnEsc": false,
94
+ "closeOnOutside": false,
95
+ "showCloseButton": true,
96
+ "data": {
97
+ "&": "$$",
98
+ "context": "${context}",
99
+ "record": "${record}"
100
+ },
101
+ "size": "md",
102
+ "actions": [
103
+ {
104
+ "type": "button",
105
+ "label": "${'steedos_packages.upgrade.cancel' | t}",
106
+ "onEvent": {
107
+ "click": {
108
+ "actions": [
109
+ {
110
+ "componentId": "",
111
+ "args": {
112
+ },
113
+ "actionType": "closeDialog"
114
+ }
115
+ ]
116
+ }
117
+ },
118
+ "id": "u:dbf7b7a9821c"
119
+ },
120
+ {
121
+ "type": "submit",
122
+ "label": "${'steedos_packages.upgrade.confirm' | t}",
123
+ "id": "u:0318127b7745",
124
+ "close": true,
125
+ "confirmText": "${'steedos_packages.upgrade.second_confirm' | t}",
126
+ "level": "primary"
127
+ }
128
+ ]
129
+ }
130
+ }
131
+ ],
132
+ "weight": 0
133
+ }
134
+ }
135
+ }
136
+ ],
137
+ "regions": [
138
+ "body"
139
+ ],
140
+ "data": {
141
+
142
+ },
143
+ "bodyClassName": "p-0",
144
+ "id": "u:721e4093f456"
145
+ }
146
+ type: amis_button
147
+ visible: true
@@ -0,0 +1,289 @@
1
+ const express = require('express');
2
+ const router = express.Router();
3
+ const auth = require('@steedos/auth');
4
+ const objectql = require('@steedos/objectql');
5
+ let schema = objectql.getSteedosSchema();
6
+ const validator = require('validator');
7
+
8
+ const disabledChangePackageWithSaas = async (req, res, next) => {
9
+ if (validator.toBoolean(process.env.STEEDOS_TENANT_ENABLE_SAAS || 'false', true) != true) {
10
+ next();
11
+ }else {
12
+ // 禁止操作packages
13
+ res.status(500).send({ status: 'error', message: 'No permission' });
14
+ }
15
+ }
16
+
17
+ router.get('/api/nodes/install', disabledChangePackageWithSaas, auth.requireAuthentication, async function (req, res) {
18
+ const userSession = req.user;
19
+ const isSpaceAdmin = userSession.is_space_admin;
20
+ const body = JSON.parse(decodeURIComponent(Buffer.from(req.query.data, "base64").toString('utf8')));
21
+ if(!isSpaceAdmin){
22
+ return res.status(401).send({ message: 'No permission' });
23
+ }
24
+ try {
25
+ const { module, version, label, description, nodeID} = body || {};
26
+ let broker = schema.broker;
27
+ const result = await broker.call(`@steedos/service-project.installPackage`, {
28
+ module, version, label, description
29
+ },{
30
+ nodeID: nodeID
31
+ })
32
+ res.redirect(302, `/app/admin/steedos_packages/grid/all`);
33
+ // res.status(200).send(result); //TODO 完善返回信息
34
+ } catch (error) {
35
+ console.error(error);
36
+ res.status(500).send(error.message);
37
+ }
38
+ });
39
+
40
+ router.post('/api/nodes/uninstall', disabledChangePackageWithSaas, auth.requireAuthentication, async function (req, res) {
41
+ const userSession = req.user;
42
+ const isSpaceAdmin = userSession.is_space_admin;
43
+ const body = req.body;
44
+ if(!isSpaceAdmin){
45
+ return res.status(401).send({ message: 'No permission' });
46
+ }
47
+ try {
48
+ const { module, nodeID} = body || {};
49
+ let broker = schema.broker;
50
+ const result = await broker.call(`@steedos/service-project.uninstallPackage`, {
51
+ module
52
+ },{
53
+ nodeID: nodeID
54
+ })
55
+ res.status(200).send(result); //TODO 完善返回信息
56
+ } catch (error) {
57
+ console.error(error);
58
+ res.status(500).send(error.message);
59
+ }
60
+ });
61
+
62
+ router.post('/api/nodes/reload', disabledChangePackageWithSaas, auth.requireAuthentication, async function (req, res) {
63
+ const userSession = req.user;
64
+ const isSpaceAdmin = userSession.is_space_admin;
65
+ const body = req.body;
66
+ if(!isSpaceAdmin){
67
+ return res.status(401).send({ message: 'No permission' });
68
+ }
69
+ try {
70
+ const { module, nodeID} = body || {};
71
+ let broker = schema.broker;
72
+ const result = await broker.call(`@steedos/service-project.reloadPackage`, {
73
+ module
74
+ },{
75
+ nodeID: nodeID
76
+ })
77
+ res.status(200).send(result);
78
+ } catch (error) {
79
+ console.error(error);
80
+ res.status(500).send(error.message);
81
+ }
82
+ });
83
+
84
+ router.post('/api/nodes/disable', disabledChangePackageWithSaas, auth.requireAuthentication, async function (req, res) {
85
+ const userSession = req.user;
86
+ const isSpaceAdmin = userSession.is_space_admin;
87
+ const body = req.body;
88
+ if(!isSpaceAdmin){
89
+ return res.status(401).send({ message: 'No permission' });
90
+ }
91
+ try {
92
+ const { module, nodeID} = body || {};
93
+ let broker = schema.broker;
94
+ const result = await broker.call(`@steedos/service-project.disablePackage`, {
95
+ module
96
+ },{
97
+ nodeID: nodeID
98
+ })
99
+ res.status(200).send(result);
100
+ } catch (error) {
101
+ console.error(error);
102
+ res.status(500).send(error.message);
103
+ }
104
+ });
105
+
106
+ router.post('/api/nodes/enable', disabledChangePackageWithSaas, auth.requireAuthentication, async function (req, res) {
107
+ const userSession = req.user;
108
+ const isSpaceAdmin = userSession.is_space_admin;
109
+ const body = req.body;
110
+ if(!isSpaceAdmin){
111
+ return res.status(401).send({ message: 'No permission' });
112
+ }
113
+ try {
114
+ const { module, nodeID} = body || {};
115
+ let broker = schema.broker;
116
+ const result = await broker.call(`@steedos/service-project.enablePackage`, {
117
+ module
118
+ },{
119
+ nodeID: nodeID
120
+ })
121
+ res.status(200).send(result);
122
+ } catch (error) {
123
+ console.error(error);
124
+ res.status(200).send({
125
+ "status": 1,
126
+ "msg": error.message
127
+ }
128
+ );
129
+ // res.status(500).send(error.message);
130
+ }
131
+ });
132
+ router.get('/api/nodes/versions', disabledChangePackageWithSaas, auth.requireAuthentication, async function (req, res) {
133
+ const userSession = req.user;
134
+ const isSpaceAdmin = userSession.is_space_admin;
135
+ // console.log(`req.query`, req.query)
136
+ const body = req.query;
137
+ const { module } = body || {};
138
+ if(!module){
139
+ return res.status(500).send({ message: 'Not find module' });
140
+ }
141
+ if(!isSpaceAdmin){
142
+ return res.status(401).send({ message: 'No permission' });
143
+ }
144
+ try {
145
+
146
+ let broker = schema.broker;
147
+ const result = await broker.call(`@steedos/service-project.getPackageVersions`, {
148
+ module
149
+ })
150
+ res.status(200).send(result); //TODO 完善返回信息
151
+ } catch (error) {
152
+ console.error(error);
153
+ res.status(500).send(error.message);
154
+ }
155
+ });
156
+
157
+ router.post('/api/nodes/upgrade', disabledChangePackageWithSaas, auth.requireAuthentication, async function (req, res) {
158
+ const userSession = req.user;
159
+ const isSpaceAdmin = userSession.is_space_admin;
160
+ const body = req.body;
161
+ if(!isSpaceAdmin){
162
+ return res.status(401).send({ message: 'No permission' });
163
+ }
164
+ try {
165
+ const { module, version} = body || {};
166
+ let broker = schema.broker;
167
+ const result = await broker.call(`@steedos/service-project.upgradePackage`, {
168
+ module, version
169
+ })
170
+ res.status(200).send(result);
171
+ } catch (error) {
172
+ console.error(error);
173
+ res.status(500).send(error.message);
174
+ }
175
+ });
176
+
177
+ router.get('/api/nodes/cloud/saas/packages/purchased', disabledChangePackageWithSaas, auth.requireAuthentication, async function (req, res) {
178
+ const userSession = req.user;
179
+ try {
180
+ let broker = schema.broker;
181
+ const result = await broker.call(`@steedos/service-project.getCloudSaasPurchasedPackages`, {
182
+ }, {
183
+ meta: {
184
+ user: userSession
185
+ }
186
+ })
187
+ res.status(200).send(result);
188
+ } catch (error) {
189
+ console.error(error);
190
+ res.status(500).send(error.message);
191
+ }
192
+ });
193
+
194
+ router.post('/api/nodes/cloud/saas/packages/purchased', disabledChangePackageWithSaas, auth.requireAuthentication, async function(req, res){
195
+ const userSession = req.user;
196
+ try {
197
+ let broker = schema.broker;
198
+ const result = await broker.call(`@steedos/service-project.installPurchasedPackages`, {}, {
199
+ meta: {
200
+ user: userSession
201
+ }
202
+ })
203
+ res.status(200).send(result);
204
+ } catch (error) {
205
+ console.error(error);
206
+ res.status(500).send(error.message);
207
+ }
208
+ });
209
+
210
+ router.post('/api/nodes/cloud/saas/packages/url', disabledChangePackageWithSaas, auth.requireAuthentication, async function(req, res){
211
+ const userSession = req.user;
212
+ try {
213
+ let broker = schema.broker;
214
+ const { module, version, url, auth, registry_url } = req.body;
215
+ const result = await broker.call(`@steedos/service-project.installPackageFromUrl`, {module, version, url, auth, registry_url, fromClient: true}, {
216
+ meta: {
217
+ user: userSession
218
+ }
219
+ })
220
+ res.status(200).send(result);
221
+ } catch (error) {
222
+ console.error(error);
223
+ res.status(500).send(error.message);
224
+ }
225
+ })
226
+
227
+ router.get('/api/nodes/npmrc', disabledChangePackageWithSaas, auth.requireAuthentication, async function(req, res){
228
+ const userSession = req.user;
229
+ const isSpaceAdmin = userSession.is_space_admin;
230
+ if(!isSpaceAdmin){
231
+ return res.status(401).send({ message: 'No permission' });
232
+ }
233
+ try {
234
+ let broker = schema.broker;
235
+ const result = await broker.call(`@steedos/service-project.getNpmrc`, {}, {
236
+ meta: {
237
+ user: userSession
238
+ }
239
+ })
240
+ res.status(200).send({data: {npmrc: result}});
241
+ } catch (error) {
242
+ console.error(error);
243
+ res.status(500).send(error.message);
244
+ }
245
+ })
246
+
247
+ router.post('/api/nodes/npmrc', disabledChangePackageWithSaas, auth.requireAuthentication, async function(req, res){
248
+ const userSession = req.user;
249
+ const isSpaceAdmin = userSession.is_space_admin;
250
+ if(!isSpaceAdmin){
251
+ return res.status(401).send({ message: 'No permission' });
252
+ }
253
+ try {
254
+ let broker = schema.broker;
255
+ const { npmrc } = req.body;
256
+ const result = await broker.call(`@steedos/service-project.setNpmrc`, {npmrc}, {
257
+ meta: {
258
+ user: userSession
259
+ }
260
+ })
261
+ res.status(200).send(result);
262
+ } catch (error) {
263
+ console.error(error);
264
+ res.status(500).send(error.message);
265
+ }
266
+ });
267
+
268
+ router.post('/api/nodes/package/add', disabledChangePackageWithSaas, auth.requireAuthentication, async function(req, res){
269
+ const userSession = req.user;
270
+ const isSpaceAdmin = userSession.is_space_admin;
271
+ if(!isSpaceAdmin){
272
+ return res.status(401).send({ message: 'No permission' });
273
+ }
274
+ try {
275
+ let broker = schema.broker;
276
+ const { package: yarnPackage } = req.body;
277
+ const result = await broker.call(`@steedos/service-project.yarnAddPackage`, {yarnPackage}, {
278
+ meta: {
279
+ user: userSession
280
+ }
281
+ })
282
+ res.status(200).send(result);
283
+ } catch (error) {
284
+ console.error(error.message);
285
+ res.status(500).send("安装软件包异常, 请检查参数或网络");
286
+ }
287
+ });
288
+
289
+ exports.default = router;
@@ -0,0 +1,21 @@
1
+ /*
2
+ * @Author: baozhoutao@steedos.com
3
+ * @Date: 2022-11-18 16:32:30
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2025-01-21 17:28:27
6
+ * @Description:
7
+ */
8
+ const express = require('express');
9
+ const router = express.Router();
10
+ const auth = require("@steedos/auth");
11
+
12
+ let STEEDOS_REGISTRY_URL = process.env.STEEDOS_REGISTRY_URL ? process.env.STEEDOS_REGISTRY_URL : 'https://registry.steedos.cn/';
13
+
14
+ router.get("/api/nodes/registry", auth.requireAuthentication, async function (req, res) {
15
+ res.status(200).send([
16
+ { label: "https://registry.npmjs.org/", value: "https://registry.npmjs.org/" },
17
+ { label: "https://registry.npm.taobao.org/", value: "https://registry.npm.taobao.org/" },
18
+ { label: STEEDOS_REGISTRY_URL, value: STEEDOS_REGISTRY_URL },
19
+ ]);
20
+ });
21
+ exports.default = router;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-package-registry",
3
- "version": "3.0.0-beta.25",
3
+ "version": "3.0.0-beta.27",
4
4
  "description": "",
5
5
  "main": "package.service.js",
6
6
  "scripts": {
@@ -9,10 +9,10 @@
9
9
  "author": "",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
- "@steedos/auth": "3.0.0-beta.25",
13
- "@steedos/metadata-core": "3.0.0-beta.25",
14
- "@steedos/objectql": "3.0.0-beta.25",
15
- "@steedos/service-package-loader": "3.0.0-beta.25",
12
+ "@steedos/auth": "3.0.0-beta.27",
13
+ "@steedos/metadata-core": "3.0.0-beta.27",
14
+ "@steedos/objectql": "3.0.0-beta.27",
15
+ "@steedos/service-package-loader": "3.0.0-beta.27",
16
16
  "clone": "^2.1.2",
17
17
  "fs-extra": "8.1.0",
18
18
  "i18next": "20.3.2",
@@ -31,5 +31,5 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "bcc2f288c4444202c4ec728beed73d00fe429841"
34
+ "gitHead": "fe5a3b939e02c85e644b84a03c4dc2d62d8af5e1"
35
35
  }