@balena/pinejs 19.1.0-build-compile-auth-f615d178643e42fe5cd03afca19cef8d2867887d-2 → 19.1.0-build-compile-auth-dc02184d5b6c707f41953d4711369bda31db2955-2
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 getAuthCompiler for building permissions
|
3
|
-
hash:
|
3
|
+
hash: dc02184d5b6c707f41953d4711369bda31db2955
|
4
4
|
body: ""
|
5
5
|
footer:
|
6
6
|
Change-type: minor
|
@@ -9,7 +9,7 @@
|
|
9
9
|
nested: []
|
10
10
|
version: 19.1.0
|
11
11
|
title: ""
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-10-02T13:24:09.330Z
|
13
13
|
- commits:
|
14
14
|
- subject: Update dependency grunt-webpack to v7
|
15
15
|
hash: 178c06f03da15786e2447190ed7b2df36d5eb0d2
|
package/CHANGELOG.md
CHANGED
@@ -3,11 +3,5 @@ export declare const getAuthCompiler: <M extends { [key in keyof M]: Resource; }
|
|
3
3
|
pinejsClient: PinejsClientCore<M>;
|
4
4
|
modelName: string;
|
5
5
|
}) => {
|
6
|
-
compileAuth: <TResource extends string & keyof M>(
|
7
|
-
resource: TResource;
|
8
|
-
access: string;
|
9
|
-
options?: {
|
10
|
-
$filter: Filter<M[TResource]["Read"]>;
|
11
|
-
};
|
12
|
-
}) => string;
|
6
|
+
compileAuth: <TResource extends string & keyof M>(resource: TResource, access: string, $filter?: Filter<M[TResource]["Read"]>) => string;
|
13
7
|
};
|
@@ -1,10 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.getAuthCompiler = void 0;
|
4
|
-
const asPermission = (
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
const asPermission = (url) => {
|
5
|
+
const queryParamsIndex = url.indexOf('?');
|
6
|
+
if (queryParamsIndex === -1) {
|
7
|
+
throw new Error(`Failed to compile permissions for url: ${url}`);
|
8
|
+
}
|
9
|
+
const queryParams = new URLSearchParams(url.slice(queryParamsIndex + 1));
|
10
|
+
const compiledFilter = queryParams.get('$filter');
|
11
|
+
if (compiledFilter == null) {
|
12
|
+
throw new Error(`Failed to find $filter permissions for url: ${url}`);
|
13
|
+
}
|
14
|
+
return compiledFilter.replace(/Auth\.canAccess\(\)/g, 'canAccess()');
|
8
15
|
};
|
9
16
|
const getAuthCompiler = ({ pinejsClient, modelName, }) => {
|
10
17
|
if (pinejsClient == null) {
|
@@ -14,15 +21,20 @@ const getAuthCompiler = ({ pinejsClient, modelName, }) => {
|
|
14
21
|
throw new Error('The modelName must be specified.');
|
15
22
|
}
|
16
23
|
return {
|
17
|
-
compileAuth: (
|
24
|
+
compileAuth: (resource, access, $filter) => {
|
18
25
|
if (resource == null) {
|
19
26
|
throw new Error('The resource must be specified.');
|
20
27
|
}
|
21
28
|
if (typeof access !== 'string') {
|
22
29
|
throw new Error(`The access property must be a string.`);
|
23
30
|
}
|
24
|
-
const filter =
|
25
|
-
? `?${asPermission(
|
31
|
+
const filter = $filter != null
|
32
|
+
? `?${asPermission(pinejsClient.compile({
|
33
|
+
resource,
|
34
|
+
options: {
|
35
|
+
$filter,
|
36
|
+
},
|
37
|
+
}))}`
|
26
38
|
: '';
|
27
39
|
return `${modelName}.${resource}.${access}${filter}`;
|
28
40
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"compile-auth.js","sourceRoot":"","sources":["../../src/sbvr-api/compile-auth.ts"],"names":[],"mappings":";;;AAEA,MAAM,YAAY,GAAG,CAAC,
|
1
|
+
{"version":3,"file":"compile-auth.js","sourceRoot":"","sources":["../../src/sbvr-api/compile-auth.ts"],"names":[],"mappings":";;;AAEA,MAAM,YAAY,GAAG,CAAC,GAAW,EAAU,EAAE;IAC5C,MAAM,gBAAgB,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1C,IA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,CACF,EAAE;gBACJ,CAAC,CAAC,EAAE,CAAC;YACP,OAAO,GAAG,SAAS,IAAI,QAAQ,IAAI,MAAM,GAAG,MAAM,EAAE,CAAC;QACtD,CAAC;KACD,CAAC;AACH,CAAC,CAAC;AA3CW,QAAA,eAAe,mBA2C1B"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@balena/pinejs",
|
3
|
-
"version": "19.1.0-build-compile-auth-
|
3
|
+
"version": "19.1.0-build-compile-auth-dc02184d5b6c707f41953d4711369bda31db2955-2",
|
4
4
|
"main": "out/server-glue/module",
|
5
5
|
"type": "commonjs",
|
6
6
|
"repository": "git@github.com:balena-io/pinejs.git",
|
@@ -62,7 +62,7 @@
|
|
62
62
|
"express-session": "^1.18.0",
|
63
63
|
"lodash": "^4.17.21",
|
64
64
|
"memoizee": "^0.4.17",
|
65
|
-
"pinejs-client-core": "8.1.0-build-add-support-to-odata-fns-
|
65
|
+
"pinejs-client-core": "8.1.0-build-add-support-to-odata-fns-befd5b25dc3c8f2d663c138255c68e4108abf8c9-1",
|
66
66
|
"randomstring": "^1.3.0",
|
67
67
|
"typed-error": "^3.2.2"
|
68
68
|
},
|
@@ -147,6 +147,6 @@
|
|
147
147
|
"recursive": true
|
148
148
|
},
|
149
149
|
"versionist": {
|
150
|
-
"publishedAt": "2024-
|
150
|
+
"publishedAt": "2024-10-02T13:24:10.089Z"
|
151
151
|
}
|
152
152
|
}
|
@@ -1,9 +1,16 @@
|
|
1
1
|
import type { Filter, PinejsClientCore, Resource } from 'pinejs-client-core';
|
2
2
|
|
3
|
-
const asPermission = (
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
const asPermission = (url: string): string => {
|
4
|
+
const queryParamsIndex = url.indexOf('?');
|
5
|
+
if (queryParamsIndex === -1) {
|
6
|
+
throw new Error(`Failed to compile permissions for url: ${url}`);
|
7
|
+
}
|
8
|
+
const queryParams = new URLSearchParams(url.slice(queryParamsIndex + 1));
|
9
|
+
const compiledFilter = queryParams.get('$filter');
|
10
|
+
if (compiledFilter == null) {
|
11
|
+
throw new Error(`Failed to find $filter permissions for url: ${url}`);
|
12
|
+
}
|
13
|
+
return compiledFilter.replace(/Auth\.canAccess\(\)/g, 'canAccess()');
|
7
14
|
};
|
8
15
|
|
9
16
|
export const getAuthCompiler = <M extends { [key in keyof M]: Resource }>({
|
@@ -22,17 +29,11 @@ export const getAuthCompiler = <M extends { [key in keyof M]: Resource }>({
|
|
22
29
|
}
|
23
30
|
|
24
31
|
return {
|
25
|
-
compileAuth: <TResource extends string & keyof M>(
|
26
|
-
resource,
|
27
|
-
access,
|
28
|
-
|
29
|
-
|
30
|
-
resource: TResource;
|
31
|
-
access: string;
|
32
|
-
options?: {
|
33
|
-
$filter: Filter<M[TResource]['Read']>;
|
34
|
-
};
|
35
|
-
}): string => {
|
32
|
+
compileAuth: <TResource extends string & keyof M>(
|
33
|
+
resource: TResource,
|
34
|
+
access: string,
|
35
|
+
$filter?: Filter<M[TResource]['Read']>,
|
36
|
+
): string => {
|
36
37
|
if (resource == null) {
|
37
38
|
throw new Error('The resource must be specified.');
|
38
39
|
}
|
@@ -42,8 +43,15 @@ export const getAuthCompiler = <M extends { [key in keyof M]: Resource }>({
|
|
42
43
|
}
|
43
44
|
|
44
45
|
const filter =
|
45
|
-
|
46
|
-
? `?${asPermission(
|
46
|
+
$filter != null
|
47
|
+
? `?${asPermission(
|
48
|
+
pinejsClient.compile({
|
49
|
+
resource,
|
50
|
+
options: {
|
51
|
+
$filter,
|
52
|
+
},
|
53
|
+
}),
|
54
|
+
)}`
|
47
55
|
: '';
|
48
56
|
return `${modelName}.${resource}.${access}${filter}`;
|
49
57
|
},
|