@balena/pinejs 21.4.0-build-add-odata-actions-57ea3eb16fe9ec8e28ea12b969da062ec4374a2d-1 → 21.4.0-build-add-odata-actions-ae9038ff8df4e301ebeef7c283c978fcae5ea4e4-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.
@@ -1,6 +1,6 @@
|
|
1
1
|
- commits:
|
2
2
|
- subject: Add support for defining odata actions
|
3
|
-
hash:
|
3
|
+
hash: ae9038ff8df4e301ebeef7c283c978fcae5ea4e4
|
4
4
|
body: ""
|
5
5
|
footer:
|
6
6
|
See: https://balena.fibery.io/search/9OI72#Work/Improvement/Add-odata-actions-foundation-for-pinejs-2818
|
@@ -11,7 +11,7 @@
|
|
11
11
|
nested: []
|
12
12
|
version: 21.4.0
|
13
13
|
title: ""
|
14
|
-
date: 2025-05-
|
14
|
+
date: 2025-05-01T14:24:40.074Z
|
15
15
|
- commits:
|
16
16
|
- subject: Add multipart upload interface for handlers
|
17
17
|
hash: d78ee0da169cb9b252bfe8d51c4f57cd10051475
|
package/out/sbvr-api/actions.js
CHANGED
@@ -14,7 +14,7 @@ export const runAction = async (request, req) => {
|
|
14
14
|
}
|
15
15
|
const actionName = request.odataQuery.property.resource;
|
16
16
|
const action = actions?.[request.vocabulary]?.[request.resourceName]?.[actionName];
|
17
|
-
if (
|
17
|
+
if (action == null) {
|
18
18
|
throw new BadRequestError();
|
19
19
|
}
|
20
20
|
return sbvrUtils.db.transaction(async (tx) => {
|
@@ -25,10 +25,10 @@ export const runAction = async (request, req) => {
|
|
25
25
|
passthrough: { tx, req },
|
26
26
|
});
|
27
27
|
return await action({
|
28
|
-
request
|
28
|
+
request,
|
29
29
|
tx,
|
30
30
|
api: applicationApi,
|
31
|
-
req
|
31
|
+
req,
|
32
32
|
id,
|
33
33
|
});
|
34
34
|
});
|
@@ -41,16 +41,16 @@ export const addAction = (vocabulary, resourceName, actionName, action) => {
|
|
41
41
|
export const canRunAction = async (request, req, actionName, tx) => {
|
42
42
|
const canAccessUrl = request.url
|
43
43
|
.slice(1)
|
44
|
-
.split('?')[0]
|
44
|
+
.split('?', 1)[0]
|
45
45
|
.replace(new RegExp(`(${actionName})$`), 'canAccess');
|
46
46
|
if (!canAccessUrl.endsWith('/canAccess')) {
|
47
47
|
throw new UnauthorizedError();
|
48
48
|
}
|
49
49
|
const applicationApi = api[request.vocabulary];
|
50
|
-
if (
|
50
|
+
if (applicationApi == null) {
|
51
51
|
throw new BadRequestError(`Could not find model ${request.vocabulary}`);
|
52
52
|
}
|
53
|
-
const res = await
|
53
|
+
const res = await applicationApi.request({
|
54
54
|
method: 'POST',
|
55
55
|
url: canAccessUrl,
|
56
56
|
body: { action: actionName },
|
@@ -60,11 +60,11 @@ export const canRunAction = async (request, req, actionName, tx) => {
|
|
60
60
|
};
|
61
61
|
const canAccessResourceId = (canAccessResponse) => {
|
62
62
|
const item = canAccessResponse?.d?.[0];
|
63
|
-
if (
|
63
|
+
if (item == null || typeof item !== 'object') {
|
64
64
|
throw new UnauthorizedError();
|
65
65
|
}
|
66
66
|
const keys = Object.keys(item);
|
67
|
-
if (keys.length !== 1 ||
|
67
|
+
if (keys.length !== 1 || item[keys[0]] == null) {
|
68
68
|
throw new UnauthorizedError();
|
69
69
|
}
|
70
70
|
return item[keys[0]];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/sbvr-api/actions.ts"],"names":[],"mappings":"AACA,OAAO,EACN,eAAe,GAEf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,GAAG,EAAiB,MAAM,2BAA2B,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAuB1D,MAAM,OAAO,
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/sbvr-api/actions.ts"],"names":[],"mappings":"AACA,OAAO,EAC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C,IAAI,cAAc,IAAI,IAAI,EAAE,CAAC;QAC5B,MAAM,IAAI,eAAe,CAAC,wBAAwB,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC;QACxC,MAAM,EAAE,MAAM;QACd,GAAG,EAAE,YAAY;QACjB,IAAI,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE;QAC5B,WAAW,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE;KACxB,CAAC,CAAC;IAEH,OAAO,mBAAmB,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,CAAC,iBAA4B,EAAW,EAAE;IACrE,MAAM,IAAI,GAAG,iBAAiB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvC,IAAI,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9C,MAAM,IAAI,iBAAiB,EAAE,CAAC;IAC/B,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;QAChD,MAAM,IAAI,iBAAiB,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACtB,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@balena/pinejs",
|
3
|
-
"version": "21.4.0-build-add-odata-actions-
|
3
|
+
"version": "21.4.0-build-add-odata-actions-ae9038ff8df4e301ebeef7c283c978fcae5ea4e4-1",
|
4
4
|
"main": "out/server-glue/module.js",
|
5
5
|
"type": "module",
|
6
6
|
"repository": "git@github.com:balena-io/pinejs.git",
|
@@ -149,6 +149,6 @@
|
|
149
149
|
"recursive": true
|
150
150
|
},
|
151
151
|
"versionist": {
|
152
|
-
"publishedAt": "2025-05-
|
152
|
+
"publishedAt": "2025-05-01T14:24:41.105Z"
|
153
153
|
}
|
154
154
|
}
|
package/src/sbvr-api/actions.ts
CHANGED
@@ -30,13 +30,13 @@ export type ODataAction<Vocab extends string = string> = (
|
|
30
30
|
args: ODataActionArgs<Vocab>,
|
31
31
|
) => Promise<Response>;
|
32
32
|
|
33
|
-
const actions
|
33
|
+
const actions: {
|
34
34
|
[vocab: string]: {
|
35
35
|
[resourceName: string]: {
|
36
36
|
[actionName: string]: ODataAction;
|
37
37
|
};
|
38
38
|
};
|
39
|
-
};
|
39
|
+
} = {};
|
40
40
|
|
41
41
|
export const isActionRequest = (
|
42
42
|
request: ParsedODataRequest,
|
@@ -63,7 +63,7 @@ export const runAction = async (
|
|
63
63
|
const actionName = request.odataQuery.property.resource;
|
64
64
|
const action =
|
65
65
|
actions?.[request.vocabulary]?.[request.resourceName]?.[actionName];
|
66
|
-
if (
|
66
|
+
if (action == null) {
|
67
67
|
throw new BadRequestError();
|
68
68
|
}
|
69
69
|
|
@@ -82,10 +82,10 @@ export const runAction = async (
|
|
82
82
|
});
|
83
83
|
|
84
84
|
return await action({
|
85
|
-
request
|
85
|
+
request,
|
86
86
|
tx,
|
87
87
|
api: applicationApi,
|
88
|
-
req
|
88
|
+
req,
|
89
89
|
id,
|
90
90
|
});
|
91
91
|
});
|
@@ -110,7 +110,7 @@ export const canRunAction = async (
|
|
110
110
|
) => {
|
111
111
|
const canAccessUrl = request.url
|
112
112
|
.slice(1)
|
113
|
-
.split('?')[0]
|
113
|
+
.split('?', 1)[0]
|
114
114
|
.replace(new RegExp(`(${actionName})$`), 'canAccess');
|
115
115
|
|
116
116
|
if (!canAccessUrl.endsWith('/canAccess')) {
|
@@ -118,11 +118,11 @@ export const canRunAction = async (
|
|
118
118
|
}
|
119
119
|
|
120
120
|
const applicationApi = api[request.vocabulary];
|
121
|
-
if (
|
121
|
+
if (applicationApi == null) {
|
122
122
|
throw new BadRequestError(`Could not find model ${request.vocabulary}`);
|
123
123
|
}
|
124
124
|
|
125
|
-
const res = await
|
125
|
+
const res = await applicationApi.request({
|
126
126
|
method: 'POST',
|
127
127
|
url: canAccessUrl,
|
128
128
|
body: { action: actionName },
|
@@ -134,11 +134,11 @@ export const canRunAction = async (
|
|
134
134
|
|
135
135
|
const canAccessResourceId = (canAccessResponse: AnyObject): unknown => {
|
136
136
|
const item = canAccessResponse?.d?.[0];
|
137
|
-
if (
|
137
|
+
if (item == null || typeof item !== 'object') {
|
138
138
|
throw new UnauthorizedError();
|
139
139
|
}
|
140
140
|
const keys = Object.keys(item);
|
141
|
-
if (keys.length !== 1 ||
|
141
|
+
if (keys.length !== 1 || item[keys[0]] == null) {
|
142
142
|
throw new UnauthorizedError();
|
143
143
|
}
|
144
144
|
|