@axinom/mosaic-id-guard 0.26.0-rc.4 → 0.26.0-rc.5
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.
- package/dist/graphql/ax-guard-plugin.d.ts +7 -3
- package/dist/graphql/ax-guard-plugin.d.ts.map +1 -1
- package/dist/graphql/ax-guard-plugin.js +10 -3
- package/dist/graphql/ax-guard-plugin.js.map +1 -1
- package/dist/graphql/generate-permissions-file-plugin.d.ts +8 -0
- package/dist/graphql/generate-permissions-file-plugin.d.ts.map +1 -0
- package/dist/graphql/generate-permissions-file-plugin.js +47 -0
- package/dist/graphql/generate-permissions-file-plugin.js.map +1 -0
- package/package.json +6 -6
- package/src/graphql/ax-guard-plugin.ts +16 -6
- package/src/graphql/generate-permissions-file-plugin.ts +50 -0
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { Plugin } from 'graphile-build';
|
|
1
2
|
/**
|
|
2
|
-
* AxGuard plugin is created by combining
|
|
3
|
-
* and `
|
|
3
|
+
* AxGuard plugin is created by combining three plugins - `QueryMutationGuardPlugin`,
|
|
4
|
+
* `SubscriptionGuardPlugin` and `PermissionDefinitionExporterPlugin`.
|
|
4
5
|
*
|
|
5
6
|
* This plugin handles authorization for GraphQL resources exposed by the APIs.
|
|
6
7
|
* For Queries and Mutations an error is thrown if the authorization fails.
|
|
7
8
|
*
|
|
9
|
+
* In addition, the `PermissionDefinitionExporterPlugin` exports the permission definition
|
|
10
|
+
* for the respective service to a file as given by the `permissionDefinitionExportPath` parameter.
|
|
11
|
+
*
|
|
8
12
|
* For subscriptions, if the JWT token expires while subscription events are emitted,
|
|
9
13
|
* the websocket connection is closed with `4403` code, allowing the client to automatically
|
|
10
14
|
* re-establish the connection.
|
|
@@ -19,5 +23,5 @@
|
|
|
19
23
|
*
|
|
20
24
|
* @returns
|
|
21
25
|
*/
|
|
22
|
-
export declare const AxGuardPlugin:
|
|
26
|
+
export declare const AxGuardPlugin: (permissionDefinitionExportPath?: string) => Plugin;
|
|
23
27
|
//# sourceMappingURL=ax-guard-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ax-guard-plugin.d.ts","sourceRoot":"","sources":["../../src/graphql/ax-guard-plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ax-guard-plugin.d.ts","sourceRoot":"","sources":["../../src/graphql/ax-guard-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAMxC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,aAAa,oCACS,MAAM,KACtC,MAMF,CAAC"}
|
|
@@ -2,15 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AxGuardPlugin = void 0;
|
|
4
4
|
const graphile_utils_1 = require("graphile-utils");
|
|
5
|
+
const generate_permissions_file_plugin_1 = require("./generate-permissions-file-plugin");
|
|
5
6
|
const query_mutation_guard_plugin_1 = require("./query-mutation-guard-plugin");
|
|
6
7
|
const subscription_guard_plugin_1 = require("./subscription-guard-plugin");
|
|
7
8
|
/**
|
|
8
|
-
* AxGuard plugin is created by combining
|
|
9
|
-
* and `
|
|
9
|
+
* AxGuard plugin is created by combining three plugins - `QueryMutationGuardPlugin`,
|
|
10
|
+
* `SubscriptionGuardPlugin` and `PermissionDefinitionExporterPlugin`.
|
|
10
11
|
*
|
|
11
12
|
* This plugin handles authorization for GraphQL resources exposed by the APIs.
|
|
12
13
|
* For Queries and Mutations an error is thrown if the authorization fails.
|
|
13
14
|
*
|
|
15
|
+
* In addition, the `PermissionDefinitionExporterPlugin` exports the permission definition
|
|
16
|
+
* for the respective service to a file as given by the `permissionDefinitionExportPath` parameter.
|
|
17
|
+
*
|
|
14
18
|
* For subscriptions, if the JWT token expires while subscription events are emitted,
|
|
15
19
|
* the websocket connection is closed with `4403` code, allowing the client to automatically
|
|
16
20
|
* re-establish the connection.
|
|
@@ -25,5 +29,8 @@ const subscription_guard_plugin_1 = require("./subscription-guard-plugin");
|
|
|
25
29
|
*
|
|
26
30
|
* @returns
|
|
27
31
|
*/
|
|
28
|
-
|
|
32
|
+
const AxGuardPlugin = (permissionDefinitionExportPath) => {
|
|
33
|
+
return (0, graphile_utils_1.makePluginByCombiningPlugins)((0, generate_permissions_file_plugin_1.PermissionDefinitionExporterPlugin)(permissionDefinitionExportPath), query_mutation_guard_plugin_1.QueryMutationGuardPlugin, subscription_guard_plugin_1.SubscriptionGuardPlugin);
|
|
34
|
+
};
|
|
35
|
+
exports.AxGuardPlugin = AxGuardPlugin;
|
|
29
36
|
//# sourceMappingURL=ax-guard-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ax-guard-plugin.js","sourceRoot":"","sources":["../../src/graphql/ax-guard-plugin.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"ax-guard-plugin.js","sourceRoot":"","sources":["../../src/graphql/ax-guard-plugin.ts"],"names":[],"mappings":";;;AACA,mDAA8D;AAC9D,yFAAwF;AACxF,+EAAyE;AACzE,2EAAsE;AAEtE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,aAAa,GAAG,CAC3B,8BAAuC,EAC/B,EAAE;IACV,OAAO,IAAA,6CAA4B,EACjC,IAAA,qEAAkC,EAAC,8BAA8B,CAAC,EAClE,sDAAwB,EACxB,mDAAuB,CACxB,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,aAAa,iBAQxB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Plugin } from 'postgraphile';
|
|
2
|
+
/**
|
|
3
|
+
* Exports the permissions definition to a file.
|
|
4
|
+
* @param permissionDefinitionExportPath
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function PermissionDefinitionExporterPlugin(permissionDefinitionExportPath?: string): Plugin;
|
|
8
|
+
//# sourceMappingURL=generate-permissions-file-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-permissions-file-plugin.d.ts","sourceRoot":"","sources":["../../src/graphql/generate-permissions-file-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;;;;GAIG;AACH,wBAAgB,kCAAkC,CAChD,8BAA8B,CAAC,EAAE,MAAM,GACtC,MAAM,CAmBR"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PermissionDefinitionExporterPlugin = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
/**
|
|
10
|
+
* Exports the permissions definition to a file.
|
|
11
|
+
* @param permissionDefinitionExportPath
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
function PermissionDefinitionExporterPlugin(permissionDefinitionExportPath) {
|
|
15
|
+
return (builder, options) => {
|
|
16
|
+
// Write permissions to file when the schema is built.
|
|
17
|
+
builder.hook('finalize', (schema, _build, _context) => {
|
|
18
|
+
if (permissionDefinitionExportPath !== undefined) {
|
|
19
|
+
if (options.permissionDefinition === undefined) {
|
|
20
|
+
throw new Error('When a permissionDefinitionExportPath is provided to AxGuard Plugin, permissionDefinition must be defined in the Postgraphile options.');
|
|
21
|
+
}
|
|
22
|
+
writeSourceFile(permissionDefinitionExportPath, JSON.stringify(options.permissionDefinition, null, 2));
|
|
23
|
+
}
|
|
24
|
+
return schema;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.PermissionDefinitionExporterPlugin = PermissionDefinitionExporterPlugin;
|
|
29
|
+
/**
|
|
30
|
+
* Writes generated source code to file but compares with the content of the existing file first to avoid triggering compilation in watch mode.
|
|
31
|
+
* @param outPath - Path where to write the source file.
|
|
32
|
+
* @param contents - Contents of the source file.
|
|
33
|
+
*/
|
|
34
|
+
function writeSourceFile(outPath, contents) {
|
|
35
|
+
if (!fs_1.default.existsSync(path_1.default.dirname(outPath))) {
|
|
36
|
+
fs_1.default.mkdirSync(path_1.default.dirname(outPath), { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
// Don't write file if the contents are the same, avoid triggering a build in watch mode.
|
|
39
|
+
if (fs_1.default.existsSync(outPath)) {
|
|
40
|
+
const currentContents = fs_1.default.readFileSync(outPath, { encoding: 'utf-8' });
|
|
41
|
+
if (currentContents.toString() === contents) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
fs_1.default.writeFileSync(outPath, contents, 'utf-8');
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=generate-permissions-file-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-permissions-file-plugin.js","sourceRoot":"","sources":["../../src/graphql/generate-permissions-file-plugin.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAGxB;;;;GAIG;AACH,SAAgB,kCAAkC,CAChD,8BAAuC;IAEvC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1B,sDAAsD;QACtD,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE;YACpD,IAAI,8BAA8B,KAAK,SAAS,EAAE;gBAChD,IAAI,OAAO,CAAC,oBAAoB,KAAK,SAAS,EAAE;oBAC9C,MAAM,IAAI,KAAK,CACb,wIAAwI,CACzI,CAAC;iBACH;gBACD,eAAe,CACb,8BAA8B,EAC9B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,EAAE,CAAC,CAAC,CACtD,CAAC;aACH;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AArBD,gFAqBC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,OAAe,EAAE,QAAgB;IACxD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE;QACzC,YAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;KAC1D;IACD,yFAAyF;IACzF,IAAI,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QAC1B,MAAM,eAAe,GAAG,YAAE,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QACxE,IAAI,eAAe,CAAC,QAAQ,EAAE,KAAK,QAAQ,EAAE;YAC3C,OAAO;SACR;KACF;IACD,YAAE,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-id-guard",
|
|
3
|
-
"version": "0.26.0-rc.
|
|
3
|
+
"version": "0.26.0-rc.5",
|
|
4
4
|
"description": "Authentication and authorization helpers for Axinom Mosaic services",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"lint": "eslint . --ext .ts,.tsx,.js --color --cache"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@axinom/mosaic-id-utils": "^0.15.11-rc.
|
|
32
|
-
"@axinom/mosaic-message-bus": "^0.21.0-rc.
|
|
33
|
-
"@axinom/mosaic-service-common": "^0.43.0-rc.
|
|
34
|
-
"@axinom/mosaic-transactional-inbox-outbox": "^0.3.0-rc.
|
|
31
|
+
"@axinom/mosaic-id-utils": "^0.15.11-rc.5",
|
|
32
|
+
"@axinom/mosaic-message-bus": "^0.21.0-rc.5",
|
|
33
|
+
"@axinom/mosaic-service-common": "^0.43.0-rc.5",
|
|
34
|
+
"@axinom/mosaic-transactional-inbox-outbox": "^0.3.0-rc.5",
|
|
35
35
|
"amqplib": "^0.10.3",
|
|
36
36
|
"express": "^4.17.1",
|
|
37
37
|
"express-bearer-token": "^2.4.0",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "6f103880206b41eb793b69a31c83e99dcf3b128d"
|
|
67
67
|
}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
+
import { Plugin } from 'graphile-build';
|
|
1
2
|
import { makePluginByCombiningPlugins } from 'graphile-utils';
|
|
3
|
+
import { PermissionDefinitionExporterPlugin } from './generate-permissions-file-plugin';
|
|
2
4
|
import { QueryMutationGuardPlugin } from './query-mutation-guard-plugin';
|
|
3
5
|
import { SubscriptionGuardPlugin } from './subscription-guard-plugin';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
* AxGuard plugin is created by combining
|
|
7
|
-
* and `
|
|
8
|
+
* AxGuard plugin is created by combining three plugins - `QueryMutationGuardPlugin`,
|
|
9
|
+
* `SubscriptionGuardPlugin` and `PermissionDefinitionExporterPlugin`.
|
|
8
10
|
*
|
|
9
11
|
* This plugin handles authorization for GraphQL resources exposed by the APIs.
|
|
10
12
|
* For Queries and Mutations an error is thrown if the authorization fails.
|
|
11
13
|
*
|
|
14
|
+
* In addition, the `PermissionDefinitionExporterPlugin` exports the permission definition
|
|
15
|
+
* for the respective service to a file as given by the `permissionDefinitionExportPath` parameter.
|
|
16
|
+
*
|
|
12
17
|
* For subscriptions, if the JWT token expires while subscription events are emitted,
|
|
13
18
|
* the websocket connection is closed with `4403` code, allowing the client to automatically
|
|
14
19
|
* re-establish the connection.
|
|
@@ -23,7 +28,12 @@ import { SubscriptionGuardPlugin } from './subscription-guard-plugin';
|
|
|
23
28
|
*
|
|
24
29
|
* @returns
|
|
25
30
|
*/
|
|
26
|
-
export const AxGuardPlugin =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
export const AxGuardPlugin = (
|
|
32
|
+
permissionDefinitionExportPath?: string,
|
|
33
|
+
): Plugin => {
|
|
34
|
+
return makePluginByCombiningPlugins(
|
|
35
|
+
PermissionDefinitionExporterPlugin(permissionDefinitionExportPath),
|
|
36
|
+
QueryMutationGuardPlugin,
|
|
37
|
+
SubscriptionGuardPlugin,
|
|
38
|
+
);
|
|
39
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { Plugin } from 'postgraphile';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Exports the permissions definition to a file.
|
|
7
|
+
* @param permissionDefinitionExportPath
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export function PermissionDefinitionExporterPlugin(
|
|
11
|
+
permissionDefinitionExportPath?: string,
|
|
12
|
+
): Plugin {
|
|
13
|
+
return (builder, options) => {
|
|
14
|
+
// Write permissions to file when the schema is built.
|
|
15
|
+
builder.hook('finalize', (schema, _build, _context) => {
|
|
16
|
+
if (permissionDefinitionExportPath !== undefined) {
|
|
17
|
+
if (options.permissionDefinition === undefined) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
'When a permissionDefinitionExportPath is provided to AxGuard Plugin, permissionDefinition must be defined in the Postgraphile options.',
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
writeSourceFile(
|
|
23
|
+
permissionDefinitionExportPath,
|
|
24
|
+
JSON.stringify(options.permissionDefinition, null, 2),
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return schema;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Writes generated source code to file but compares with the content of the existing file first to avoid triggering compilation in watch mode.
|
|
35
|
+
* @param outPath - Path where to write the source file.
|
|
36
|
+
* @param contents - Contents of the source file.
|
|
37
|
+
*/
|
|
38
|
+
function writeSourceFile(outPath: string, contents: string): void {
|
|
39
|
+
if (!fs.existsSync(path.dirname(outPath))) {
|
|
40
|
+
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
41
|
+
}
|
|
42
|
+
// Don't write file if the contents are the same, avoid triggering a build in watch mode.
|
|
43
|
+
if (fs.existsSync(outPath)) {
|
|
44
|
+
const currentContents = fs.readFileSync(outPath, { encoding: 'utf-8' });
|
|
45
|
+
if (currentContents.toString() === contents) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
fs.writeFileSync(outPath, contents, 'utf-8');
|
|
50
|
+
}
|