@aws-amplify/graphql-auth-transformer 0.9.2 → 0.10.0-sub-username-identity-claim.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.
- package/CHANGELOG.md +59 -0
- package/lib/accesscontrol/acm.d.ts +2 -2
- package/lib/accesscontrol/acm.d.ts.map +1 -1
- package/lib/accesscontrol/acm.js +22 -25
- package/lib/accesscontrol/acm.js.map +1 -1
- package/lib/graphql-auth-transformer.d.ts.map +1 -1
- package/lib/graphql-auth-transformer.js +35 -25
- package/lib/graphql-auth-transformer.js.map +1 -1
- package/lib/resolvers/helpers.d.ts.map +1 -1
- package/lib/resolvers/helpers.js +12 -10
- package/lib/resolvers/helpers.js.map +1 -1
- package/lib/resolvers/mutation.create.js +1 -1
- package/lib/resolvers/mutation.create.js.map +1 -1
- package/lib/resolvers/mutation.delete.js +1 -1
- package/lib/resolvers/mutation.delete.js.map +1 -1
- package/lib/resolvers/mutation.update.js +1 -1
- package/lib/resolvers/mutation.update.js.map +1 -1
- package/lib/resolvers/query.d.ts.map +1 -1
- package/lib/resolvers/query.js +4 -1
- package/lib/resolvers/query.js.map +1 -1
- package/lib/utils/constants.d.ts +1 -0
- package/lib/utils/constants.d.ts.map +1 -1
- package/lib/utils/constants.js +3 -2
- package/lib/utils/constants.js.map +1 -1
- package/lib/utils/definitions.d.ts +2 -3
- package/lib/utils/definitions.d.ts.map +1 -1
- package/lib/utils/definitions.js +5 -0
- package/lib/utils/definitions.js.map +1 -1
- package/lib/utils/index.d.ts +2 -2
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +68 -34
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/schema.d.ts.map +1 -1
- package/lib/utils/schema.js +13 -22
- package/lib/utils/schema.js.map +1 -1
- package/package.json +13 -11
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,65 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.10.0-sub-username-identity-claim.2](https://github.com/aws-amplify/amplify-category-api/compare/@aws-amplify/graphql-auth-transformer@0.9.3...@aws-amplify/graphql-auth-transformer@0.10.0-sub-username-identity-claim.2) (2022-06-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* handle return value of set of owners to return user for sub::username identity claim ([623b24d](https://github.com/aws-amplify/amplify-category-api/commit/623b24d556fc145f1e3be6e8ff91309510f7a925))
|
|
12
|
+
* use concatenated identity claim for primary key queries ([eafc412](https://github.com/aws-amplify/amplify-category-api/commit/eafc412d1a9c799077cd631c3d9c75edb43f524c))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **graphql-auth-transformer:** [@auth](https://github.com/auth) allow more granular access rights for read ([#23](https://github.com/aws-amplify/amplify-category-api/issues/23)) ([041fb80](https://github.com/aws-amplify/amplify-category-api/commit/041fb808e380d04f2c4913cef1037c3d87e98d22))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# [0.10.0-sub-username-identity-claim.1](https://github.com/aws-amplify/amplify-category-api/compare/@aws-amplify/graphql-auth-transformer@0.9.3...@aws-amplify/graphql-auth-transformer@0.10.0-sub-username-identity-claim.1) (2022-06-08)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* handle return value of set of owners to return user for sub::username identity claim ([623b24d](https://github.com/aws-amplify/amplify-category-api/commit/623b24d556fc145f1e3be6e8ff91309510f7a925))
|
|
29
|
+
* use concatenated identity claim for primary key queries ([eafc412](https://github.com/aws-amplify/amplify-category-api/commit/eafc412d1a9c799077cd631c3d9c75edb43f524c))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Features
|
|
33
|
+
|
|
34
|
+
* **graphql-auth-transformer:** [@auth](https://github.com/auth) allow more granular access rights for read ([#23](https://github.com/aws-amplify/amplify-category-api/issues/23)) ([041fb80](https://github.com/aws-amplify/amplify-category-api/commit/041fb808e380d04f2c4913cef1037c3d87e98d22))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# [0.10.0-sub-username-identity-claim.0](https://github.com/aws-amplify/amplify-category-api/compare/@aws-amplify/graphql-auth-transformer@0.9.3...@aws-amplify/graphql-auth-transformer@0.10.0-sub-username-identity-claim.0) (2022-06-08)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### Bug Fixes
|
|
44
|
+
|
|
45
|
+
* handle return value of set of owners to return user for sub::username identity claim ([623b24d](https://github.com/aws-amplify/amplify-category-api/commit/623b24d556fc145f1e3be6e8ff91309510f7a925))
|
|
46
|
+
* use concatenated identity claim for primary key queries ([eafc412](https://github.com/aws-amplify/amplify-category-api/commit/eafc412d1a9c799077cd631c3d9c75edb43f524c))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Features
|
|
50
|
+
|
|
51
|
+
* **graphql-auth-transformer:** [@auth](https://github.com/auth) allow more granular access rights for read ([#23](https://github.com/aws-amplify/amplify-category-api/issues/23)) ([041fb80](https://github.com/aws-amplify/amplify-category-api/commit/041fb808e380d04f2c4913cef1037c3d87e98d22))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## [0.9.3](https://github.com/aws-amplify/amplify-category-api/compare/@aws-amplify/graphql-auth-transformer@0.9.0...@aws-amplify/graphql-auth-transformer@0.9.3) (2022-06-07)
|
|
58
|
+
|
|
59
|
+
**Note:** Version bump only for package @aws-amplify/graphql-auth-transformer
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
6
65
|
## [0.9.2](https://github.com/aws-amplify/amplify-category-api/compare/@aws-amplify/graphql-auth-transformer@0.9.0...@aws-amplify/graphql-auth-transformer@0.9.2) (2022-05-31)
|
|
7
66
|
|
|
8
67
|
**Note:** Version bump only for package @aws-amplify/graphql-auth-transformer
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ModelOperation } from '../utils';
|
|
1
|
+
import { ModelOperation } from '../utils/definitions';
|
|
2
2
|
declare type ACMConfig = {
|
|
3
3
|
resources: string[];
|
|
4
4
|
operations: ModelOperation[];
|
|
@@ -26,7 +26,7 @@ export declare class AccessControlMatrix {
|
|
|
26
26
|
isAllowed(role: string, resource: string, operation: ModelOperation): boolean;
|
|
27
27
|
resetAccessForResource(resource: string): void;
|
|
28
28
|
getRolesPerOperation(operation: ModelOperation, fullAccess?: boolean): Array<string>;
|
|
29
|
-
getAcmPerRole(): Map<string,
|
|
29
|
+
getAcmPerRole(): Map<string, unknown>;
|
|
30
30
|
private validate;
|
|
31
31
|
private getResourceOperationMatrix;
|
|
32
32
|
private getOperationList;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acm.d.ts","sourceRoot":"","sources":["../../src/accesscontrol/acm.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"acm.d.ts","sourceRoot":"","sources":["../../src/accesscontrol/acm.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,aAAK,SAAS,GAAG;IACf,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,aAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAqBF,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,UAAU,CAAwB;IAC1C,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,MAAM,CAA+B;gBAEjC,MAAM,EAAE,SAAS;IAWtB,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAuBlC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAO9B,OAAO,IAAI,MAAM;IAOjB,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC;IAOzB,YAAY,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAOvC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAOtC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,GAAG,OAAO;IAW7E,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAe9C,oBAAoB,CAAC,SAAS,EAAE,cAAc,EAAE,UAAU,UAAQ,GAAG,KAAK,CAAC,MAAM,CAAC;IAsBlF,aAAa,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAmB5C,OAAO,CAAC,QAAQ;IAuBhB,OAAO,CAAC,0BAA0B;IAyBlC,OAAO,CAAC,gBAAgB;CAOzB"}
|
package/lib/accesscontrol/acm.js
CHANGED
|
@@ -11,11 +11,11 @@ class AccessControlMatrix {
|
|
|
11
11
|
this.name = config.name;
|
|
12
12
|
this.operations = config.operations;
|
|
13
13
|
this.resources = config.resources;
|
|
14
|
-
this.matrix =
|
|
15
|
-
this.roles =
|
|
14
|
+
this.matrix = [];
|
|
15
|
+
this.roles = [];
|
|
16
16
|
}
|
|
17
17
|
setRole(input) {
|
|
18
|
-
const { role, resource, operations, allowRoleOverwrite = false } = input;
|
|
18
|
+
const { role, resource, operations, allowRoleOverwrite = false, } = input;
|
|
19
19
|
this.validate({ resource, operations });
|
|
20
20
|
let allowedVector;
|
|
21
21
|
if (!this.roles.includes(role)) {
|
|
@@ -58,43 +58,39 @@ class AccessControlMatrix {
|
|
|
58
58
|
resetAccessForResource(resource) {
|
|
59
59
|
this.validate({ resource });
|
|
60
60
|
const resourceIndex = this.resources.indexOf(resource);
|
|
61
|
-
|
|
61
|
+
this.roles.forEach((_, i) => {
|
|
62
62
|
this.matrix[i][resourceIndex] = new Array(this.operations.length).fill(false);
|
|
63
|
-
}
|
|
63
|
+
});
|
|
64
64
|
}
|
|
65
65
|
getRolesPerOperation(operation, fullAccess = false) {
|
|
66
66
|
this.validate({ operations: [operation] });
|
|
67
67
|
const operationIndex = this.operations.indexOf(operation);
|
|
68
68
|
const roles = new Array();
|
|
69
|
-
|
|
69
|
+
this.roles.forEach((_, x) => {
|
|
70
70
|
let hasOperation = false;
|
|
71
71
|
if (fullAccess) {
|
|
72
|
-
hasOperation = this.resources.every((
|
|
73
|
-
return this.matrix[x][idx][operationIndex];
|
|
74
|
-
});
|
|
72
|
+
hasOperation = this.resources.every((_, idx) => this.matrix[x][idx][operationIndex]);
|
|
75
73
|
}
|
|
76
74
|
else {
|
|
77
|
-
hasOperation = this.resources.some((
|
|
78
|
-
return this.matrix[x][idx][operationIndex];
|
|
79
|
-
});
|
|
75
|
+
hasOperation = this.resources.some((_, idx) => this.matrix[x][idx][operationIndex]);
|
|
80
76
|
}
|
|
81
77
|
if (hasOperation)
|
|
82
78
|
roles.push(this.roles[x]);
|
|
83
|
-
}
|
|
79
|
+
});
|
|
84
80
|
return roles;
|
|
85
81
|
}
|
|
86
82
|
getAcmPerRole() {
|
|
87
83
|
const acmPerRole = new Map();
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
this.matrix.forEach((_, i) => {
|
|
85
|
+
const tableObj = {};
|
|
86
|
+
this.matrix[i].forEach((_, y) => {
|
|
91
87
|
tableObj[this.resources[y]] = this.matrix[i][y].reduce((prev, resource, index) => {
|
|
92
88
|
prev[this.operations[index]] = resource;
|
|
93
89
|
return prev;
|
|
94
90
|
}, {});
|
|
95
|
-
}
|
|
91
|
+
});
|
|
96
92
|
acmPerRole.set(this.roles[i], tableObj);
|
|
97
|
-
}
|
|
93
|
+
});
|
|
98
94
|
return acmPerRole;
|
|
99
95
|
}
|
|
100
96
|
validate(input) {
|
|
@@ -106,15 +102,16 @@ class AccessControlMatrix {
|
|
|
106
102
|
}
|
|
107
103
|
if (input.operations) {
|
|
108
104
|
input.operations.forEach(operation => {
|
|
109
|
-
if (this.operations.indexOf(operation) === -1)
|
|
105
|
+
if (this.operations.indexOf(operation) === -1) {
|
|
110
106
|
throw new graphql_transformer_core_1.TransformerContractError(`Operation: ${operation} does not exist in the ACM.`);
|
|
107
|
+
}
|
|
111
108
|
});
|
|
112
109
|
}
|
|
113
110
|
}
|
|
114
111
|
getResourceOperationMatrix(input) {
|
|
115
112
|
const { operations, resource, role } = input;
|
|
116
113
|
let fieldAllowVector = [];
|
|
117
|
-
|
|
114
|
+
const operationList = this.getOperationList(operations);
|
|
118
115
|
if (role && resource) {
|
|
119
116
|
const roleIndex = this.roles.indexOf(role);
|
|
120
117
|
const resourceIndex = this.resources.indexOf(resource);
|
|
@@ -122,7 +119,7 @@ class AccessControlMatrix {
|
|
|
122
119
|
fieldAllowVector[resourceIndex] = operationList;
|
|
123
120
|
return fieldAllowVector;
|
|
124
121
|
}
|
|
125
|
-
|
|
122
|
+
this.resources.forEach((_, i) => {
|
|
126
123
|
if (resource) {
|
|
127
124
|
if (this.resources.indexOf(resource) === i) {
|
|
128
125
|
fieldAllowVector.push(operationList);
|
|
@@ -134,14 +131,14 @@ class AccessControlMatrix {
|
|
|
134
131
|
else {
|
|
135
132
|
fieldAllowVector.push(operationList);
|
|
136
133
|
}
|
|
137
|
-
}
|
|
134
|
+
});
|
|
138
135
|
return fieldAllowVector;
|
|
139
136
|
}
|
|
140
137
|
getOperationList(operations) {
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
const operationList = [];
|
|
139
|
+
this.operations.forEach(operation => {
|
|
143
140
|
operationList.push(operations.includes(operation));
|
|
144
|
-
}
|
|
141
|
+
});
|
|
145
142
|
return operationList;
|
|
146
143
|
}
|
|
147
144
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acm.js","sourceRoot":"","sources":["../../src/accesscontrol/acm.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,oFAAwG;AAmCxG,MAAa,mBAAmB;IAO9B,YAAY,MAAiB;QAC3B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"acm.js","sourceRoot":"","sources":["../../src/accesscontrol/acm.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,oFAAwG;AAmCxG,MAAa,mBAAmB;IAO9B,YAAY,MAAiB;QAC3B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;IAKM,OAAO,CAAC,KAAmB;QAChC,MAAM,EACJ,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,kBAAkB,GAAG,KAAK,GACvD,GAAG,KAAK,CAAC;QACV,IAAI,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QACxC,IAAI,aAAoC,CAAC;QACzC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YAC9B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KACzB,IAAI,CASL;IAKF,MAAM,CAAC,4BAA4B,CACjC,eAAe,EAAE,wBAAwB,EAAE,EAC3C,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,GAAG,EAAE,wBAAwB,EAC7B,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,GACzB,IAAI;IAuBP,+BAA+B,QAAS,0BAA0B,iBAAiB,IAAI,MAAM,CAAC,KAAG,IAAI,CAGnG;CACH"}
|
|
@@ -33,6 +33,7 @@ const iam = __importStar(require("@aws-cdk/aws-iam"));
|
|
|
33
33
|
const cdk = __importStar(require("@aws-cdk/core"));
|
|
34
34
|
const graphql_relational_transformer_1 = require("@aws-amplify/graphql-relational-transformer");
|
|
35
35
|
const resolvers_1 = require("./resolvers");
|
|
36
|
+
const field_1 = require("./resolvers/field");
|
|
36
37
|
const accesscontrol_1 = require("./accesscontrol");
|
|
37
38
|
const utils_1 = require("./utils");
|
|
38
39
|
const warnings_1 = require("./utils/warnings");
|
|
@@ -90,7 +91,7 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
90
91
|
const modelDirective = (_a = parent.directives) === null || _a === void 0 ? void 0 : _a.find(dir => dir.name.value === 'model');
|
|
91
92
|
const typeName = parent.name.value;
|
|
92
93
|
const fieldName = field.name.value;
|
|
93
|
-
const rules = (0, utils_1.getAuthDirectiveRules)(new graphql_transformer_core_1.DirectiveWrapper(directive));
|
|
94
|
+
const rules = (0, utils_1.getAuthDirectiveRules)(new graphql_transformer_core_1.DirectiveWrapper(directive), true);
|
|
94
95
|
(0, utils_1.validateFieldRules)(new graphql_transformer_core_1.DirectiveWrapper(directive), isParentTypeBuiltinType, modelDirective !== undefined, field.name.value);
|
|
95
96
|
(0, utils_1.validateRules)(rules, this.configuredAuthProviders, field.name.value);
|
|
96
97
|
this.setAuthPolicyFlag(rules);
|
|
@@ -118,10 +119,10 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
118
119
|
const typeFieldName = `${typeName}:${fieldName}`;
|
|
119
120
|
const acm = new accesscontrol_1.AccessControlMatrix({
|
|
120
121
|
name: typeFieldName,
|
|
121
|
-
operations: ['
|
|
122
|
+
operations: ['list', 'get', 'search', 'listen', 'sync'],
|
|
122
123
|
resources: [typeFieldName],
|
|
123
124
|
});
|
|
124
|
-
this.convertRulesToRoles(acm, staticRules, false, typeFieldName, ['
|
|
125
|
+
this.convertRulesToRoles(acm, staticRules, false, typeFieldName, ['list', 'get', 'search', 'listen', 'sync']);
|
|
125
126
|
this.authNonModelConfig.set(typeFieldName, acm);
|
|
126
127
|
}
|
|
127
128
|
};
|
|
@@ -170,8 +171,6 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
170
171
|
const def = context.output.getObject(modelName);
|
|
171
172
|
const modelNameConfig = this.modelDirectiveConfig.get(modelName);
|
|
172
173
|
const searchableDirective = def.directives.find(dir => dir.name.value === 'searchable');
|
|
173
|
-
const readRoles = acm.getRolesPerOperation('read');
|
|
174
|
-
const roleDefinitions = readRoles.map(role => this.roleMap.get(role));
|
|
175
174
|
const queryFields = (0, utils_1.getQueryFieldNames)(this.modelDirectiveConfig.get(modelName));
|
|
176
175
|
queryFields.forEach(query => {
|
|
177
176
|
switch (query.type) {
|
|
@@ -198,11 +197,13 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
198
197
|
const config = (0, utils_1.getSearchableConfig)(searchableDirective, modelName);
|
|
199
198
|
this.protectSearchResolver(context, def, context.output.getQueryTypeName(), config.queries.search, acm);
|
|
200
199
|
}
|
|
201
|
-
const
|
|
200
|
+
const readRoles = [...new Set(...utils_1.READ_MODEL_OPERATIONS.map(op => acm.getRolesPerOperation(op)))];
|
|
201
|
+
const roleDefinitions = readRoles.map(role => this.roleMap.get(role));
|
|
202
|
+
const modelFields = (_b = (_a = def.fields) === null || _a === void 0 ? void 0 : _a.filter((f) => acm.hasResource(f.name.value))) !== null && _b !== void 0 ? _b : [];
|
|
202
203
|
const errorFields = new Array();
|
|
203
|
-
modelFields.forEach(field => {
|
|
204
|
+
modelFields.forEach((field) => {
|
|
204
205
|
const fieldReadRoles = (0, utils_1.getReadRolesForField)(acm, readRoles, field.name.value);
|
|
205
|
-
const allowedRoles = fieldReadRoles.filter(r => acm.isAllowed(r, field.name.value,
|
|
206
|
+
const allowedRoles = fieldReadRoles.filter(r => utils_1.READ_MODEL_OPERATIONS.some(op => acm.isAllowed(r, field.name.value, op)));
|
|
206
207
|
const needsFieldResolver = allowedRoles.length < fieldReadRoles.length;
|
|
207
208
|
if (needsFieldResolver && field.type.kind === graphql_1.Kind.NON_NULL_TYPE) {
|
|
208
209
|
errorFields.push(field.name.value);
|
|
@@ -235,7 +236,9 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
235
236
|
}
|
|
236
237
|
});
|
|
237
238
|
const subscriptionFieldNames = (0, utils_1.getSubscriptionFieldNames)(this.modelDirectiveConfig.get(modelName));
|
|
238
|
-
const subscriptionRoles =
|
|
239
|
+
const subscriptionRoles = acm
|
|
240
|
+
.getRolesPerOperation('listen')
|
|
241
|
+
.map(role => this.roleMap.get(role))
|
|
239
242
|
.filter(roleDef => { var _a; return (roleDef.strategy === 'owner' && !(0, utils_1.fieldIsList)((_a = def.fields) !== null && _a !== void 0 ? _a : [], roleDef.entity)) || roleDef.static; });
|
|
240
243
|
subscriptionFieldNames.forEach(subscription => {
|
|
241
244
|
this.protectSubscriptionResolver(context, subscription.typeName, subscription.fieldName, subscriptionRoles);
|
|
@@ -285,42 +288,43 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
285
288
|
this.addOperationToResourceReferences(typeName, operationName, acm.getRoles());
|
|
286
289
|
}
|
|
287
290
|
};
|
|
288
|
-
addServiceDirective(ctx.output.getQueryTypeName(), '
|
|
289
|
-
addServiceDirective(ctx.output.getQueryTypeName(), '
|
|
290
|
-
addServiceDirective(ctx.output.getQueryTypeName(), '
|
|
291
|
+
addServiceDirective(ctx.output.getQueryTypeName(), 'get', (_a = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.queries) === null || _a === void 0 ? void 0 : _a.get);
|
|
292
|
+
addServiceDirective(ctx.output.getQueryTypeName(), 'list', (_b = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.queries) === null || _b === void 0 ? void 0 : _b.list);
|
|
293
|
+
addServiceDirective(ctx.output.getQueryTypeName(), 'sync', (_c = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.queries) === null || _c === void 0 ? void 0 : _c.sync);
|
|
291
294
|
addServiceDirective(ctx.output.getMutationTypeName(), 'create', (_d = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _d === void 0 ? void 0 : _d.create);
|
|
292
295
|
addServiceDirective(ctx.output.getMutationTypeName(), 'update', (_e = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _e === void 0 ? void 0 : _e.update);
|
|
293
296
|
addServiceDirective(ctx.output.getMutationTypeName(), 'delete', (_f = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _f === void 0 ? void 0 : _f.delete);
|
|
294
297
|
if (ctx.metadata.has(indexKeyName)) {
|
|
295
298
|
ctx.metadata.get(indexKeyName).forEach(index => {
|
|
296
|
-
addServiceDirective(ctx.output.getQueryTypeName(), '
|
|
299
|
+
addServiceDirective(ctx.output.getQueryTypeName(), 'list', index.split(':')[1]);
|
|
300
|
+
addServiceDirective(ctx.output.getQueryTypeName(), 'get', index.split(':')[1]);
|
|
297
301
|
});
|
|
298
302
|
}
|
|
299
303
|
if (searchableDirective) {
|
|
300
304
|
const config = (0, utils_1.getSearchableConfig)(searchableDirective, def.name.value);
|
|
301
|
-
addServiceDirective(ctx.output.getQueryTypeName(), '
|
|
305
|
+
addServiceDirective(ctx.output.getQueryTypeName(), 'search', config.queries.search);
|
|
302
306
|
}
|
|
303
307
|
const subscriptions = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.subscriptions;
|
|
304
308
|
if ((subscriptions === null || subscriptions === void 0 ? void 0 : subscriptions.level) === graphql_model_transformer_1.SubscriptionLevel.on) {
|
|
305
309
|
const subscriptionArguments = acm
|
|
306
|
-
.getRolesPerOperation('
|
|
310
|
+
.getRolesPerOperation('listen')
|
|
307
311
|
.map(role => this.roleMap.get(role))
|
|
308
312
|
.filter(roleDef => { var _a; return roleDef.strategy === 'owner' && !(0, utils_1.fieldIsList)((_a = def.fields) !== null && _a !== void 0 ? _a : [], roleDef.entity); });
|
|
309
313
|
if (subscriptions.onCreate && ((_g = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _g === void 0 ? void 0 : _g.create)) {
|
|
310
314
|
subscriptions.onCreate.forEach(onCreateSub => {
|
|
311
|
-
addServiceDirective(ctx.output.getSubscriptionTypeName(), '
|
|
315
|
+
addServiceDirective(ctx.output.getSubscriptionTypeName(), 'listen', onCreateSub);
|
|
312
316
|
(0, utils_1.addSubscriptionArguments)(ctx, onCreateSub, subscriptionArguments);
|
|
313
317
|
});
|
|
314
318
|
}
|
|
315
319
|
if (subscriptions.onUpdate && ((_h = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _h === void 0 ? void 0 : _h.update)) {
|
|
316
320
|
subscriptions.onUpdate.forEach(onUpdateSub => {
|
|
317
|
-
addServiceDirective(ctx.output.getSubscriptionTypeName(), '
|
|
321
|
+
addServiceDirective(ctx.output.getSubscriptionTypeName(), 'listen', onUpdateSub);
|
|
318
322
|
(0, utils_1.addSubscriptionArguments)(ctx, onUpdateSub, subscriptionArguments);
|
|
319
323
|
});
|
|
320
324
|
}
|
|
321
325
|
if (subscriptions.onDelete && ((_j = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _j === void 0 ? void 0 : _j.delete)) {
|
|
322
326
|
subscriptions.onDelete.forEach(onDeleteSub => {
|
|
323
|
-
addServiceDirective(ctx.output.getSubscriptionTypeName(), '
|
|
327
|
+
addServiceDirective(ctx.output.getSubscriptionTypeName(), 'listen', onDeleteSub);
|
|
324
328
|
(0, utils_1.addSubscriptionArguments)(ctx, onDeleteSub, subscriptionArguments);
|
|
325
329
|
});
|
|
326
330
|
}
|
|
@@ -329,7 +333,7 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
329
333
|
this.protectGetResolver = (ctx, def, typeName, fieldName, acm) => {
|
|
330
334
|
var _a;
|
|
331
335
|
const resolver = ctx.resolvers.getResolver(typeName, fieldName);
|
|
332
|
-
const roleDefinitions = acm.getRolesPerOperation('
|
|
336
|
+
const roleDefinitions = acm.getRolesPerOperation('get').map(r => this.roleMap.get(r));
|
|
333
337
|
const tableKeySchema = (0, graphql_transformer_core_1.getTable)(ctx, def).keySchema;
|
|
334
338
|
const primaryFields = tableKeySchema.map(att => att.attributeName);
|
|
335
339
|
const primaryKey = (0, utils_1.getPartitionKey)(tableKeySchema);
|
|
@@ -339,7 +343,7 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
339
343
|
this.protectListResolver = (ctx, def, typeName, fieldName, acm, indexName) => {
|
|
340
344
|
var _a;
|
|
341
345
|
const resolver = ctx.resolvers.getResolver(typeName, fieldName);
|
|
342
|
-
const roleDefinitions = acm.getRolesPerOperation('
|
|
346
|
+
const roleDefinitions = acm.getRolesPerOperation('list').map(r => this.roleMap.get(r));
|
|
343
347
|
let primaryFields;
|
|
344
348
|
let partitionKey;
|
|
345
349
|
const table = (0, graphql_transformer_core_1.getTable)(ctx, def);
|
|
@@ -365,12 +369,18 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
365
369
|
const relatedModelObject = AuthTransformer.getRelatedModelObject(ctx, (0, graphql_transformer_common_1.getBaseType)(field.type));
|
|
366
370
|
if (this.authModelConfig.has(relatedModelObject.name.value)) {
|
|
367
371
|
const acm = this.authModelConfig.get(relatedModelObject.name.value);
|
|
368
|
-
const roleDefinitions =
|
|
372
|
+
const roleDefinitions = [...new Set([
|
|
373
|
+
...acm.getRolesPerOperation('get'),
|
|
374
|
+
...acm.getRolesPerOperation('list'),
|
|
375
|
+
...acm.getRolesPerOperation('sync'),
|
|
376
|
+
...acm.getRolesPerOperation('search'),
|
|
377
|
+
...acm.getRolesPerOperation('listen'),
|
|
378
|
+
])].map(r => this.roleMap.get(r));
|
|
369
379
|
const relationalPrimaryMap = (0, utils_1.getRelationalPrimaryMap)(ctx, def, field, relatedModelObject);
|
|
370
380
|
relatedAuthExpression = (0, resolvers_1.generateAuthExpressionForRelationQuery)(this.configuredAuthProviders, roleDefinitions, (_a = relatedModelObject.fields) !== null && _a !== void 0 ? _a : [], relationalPrimaryMap);
|
|
371
381
|
}
|
|
372
382
|
else {
|
|
373
|
-
relatedAuthExpression = (0,
|
|
383
|
+
relatedAuthExpression = (0, field_1.generateSandboxExpressionForField)(ctx.sandboxModeEnabled);
|
|
374
384
|
}
|
|
375
385
|
if (fieldRoles) {
|
|
376
386
|
const roleDefinitions = fieldRoles.map(r => this.roleMap.get(r));
|
|
@@ -390,7 +400,7 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
390
400
|
var _a;
|
|
391
401
|
if (ctx.isProjectUsingDataStore()) {
|
|
392
402
|
const resolver = ctx.resolvers.getResolver(typeName, fieldName);
|
|
393
|
-
const roleDefinitions = acm.getRolesPerOperation('
|
|
403
|
+
const roleDefinitions = acm.getRolesPerOperation('sync').map(r => this.roleMap.get(r));
|
|
394
404
|
const primaryFields = (0, graphql_transformer_core_1.getTable)(ctx, def).keySchema.map(att => att.attributeName);
|
|
395
405
|
const authExpression = (0, resolvers_1.generateAuthExpressionForQueries)(this.configuredAuthProviders, roleDefinitions, (_a = def.fields) !== null && _a !== void 0 ? _a : [], primaryFields);
|
|
396
406
|
resolver.addToSlot('auth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(authExpression, `${typeName}.${fieldName}.{slotName}.{slotIndex}.req.vtl`));
|
|
@@ -403,8 +413,8 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
403
413
|
const allowedAggFields = modelFields.map(f => f.name.value).filter(f => !acmFields.includes(f));
|
|
404
414
|
let leastAllowedFields = acmFields;
|
|
405
415
|
const resolver = ctx.resolvers.getResolver(typeName, fieldName);
|
|
406
|
-
const readRoleDefinitions = acm.getRolesPerOperation('
|
|
407
|
-
const allowedFields = acmFields.filter(resource => acm.isAllowed(role, resource, '
|
|
416
|
+
const readRoleDefinitions = acm.getRolesPerOperation('search').map(role => {
|
|
417
|
+
const allowedFields = acmFields.filter(resource => acm.isAllowed(role, resource, 'search'));
|
|
408
418
|
const roleDefinition = this.roleMap.get(role);
|
|
409
419
|
if (allowedFields.length !== acmFields.length || !roleDefinition.static) {
|
|
410
420
|
roleDefinition.allowedFields = allowedFields;
|