@aws-amplify/graphql-auth-transformer 0.10.0-sub-username-identity-claim.2 → 0.10.0
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 +4 -36
- package/lib/accesscontrol/acm.d.ts +2 -2
- package/lib/accesscontrol/acm.d.ts.map +1 -1
- package/lib/accesscontrol/acm.js +25 -22
- package/lib/accesscontrol/acm.js.map +1 -1
- package/lib/graphql-auth-transformer.d.ts.map +1 -1
- package/lib/graphql-auth-transformer.js +25 -35
- package/lib/graphql-auth-transformer.js.map +1 -1
- package/lib/resolvers/helpers.d.ts.map +1 -1
- package/lib/resolvers/helpers.js +10 -12
- 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 +1 -4
- package/lib/resolvers/query.js.map +1 -1
- package/lib/utils/constants.d.ts +0 -1
- package/lib/utils/constants.d.ts.map +1 -1
- package/lib/utils/constants.js +2 -3
- package/lib/utils/constants.js.map +1 -1
- package/lib/utils/definitions.d.ts +3 -2
- package/lib/utils/definitions.d.ts.map +1 -1
- package/lib/utils/definitions.js +0 -5
- 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 +34 -68
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/schema.d.ts.map +1 -1
- package/lib/utils/schema.js +22 -13
- package/lib/utils/schema.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -3,52 +3,20 @@
|
|
|
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
|
|
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))
|
|
6
|
+
# [0.10.0](https://github.com/aws-amplify/amplify-category-api/compare/@aws-amplify/graphql-auth-transformer@0.9.4...@aws-amplify/graphql-auth-transformer@0.10.0) (2022-06-10)
|
|
13
7
|
|
|
14
8
|
|
|
15
9
|
### Features
|
|
16
10
|
|
|
17
|
-
* **
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
* **amplify-category-api:** update descriptions to properly publish ([f685bbe](https://github.com/aws-amplify/amplify-category-api/commit/f685bbe52fd2d364e34c0ecb45c8a903555de3fe))
|
|
21
12
|
|
|
22
13
|
|
|
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
14
|
|
|
25
15
|
|
|
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
16
|
|
|
17
|
+
## [0.9.4](https://github.com/aws-amplify/amplify-category-api/compare/@aws-amplify/graphql-auth-transformer@0.9.3...@aws-amplify/graphql-auth-transformer@0.9.4) (2022-06-10)
|
|
36
18
|
|
|
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))
|
|
19
|
+
**Note:** Version bump only for package @aws-amplify/graphql-auth-transformer
|
|
52
20
|
|
|
53
21
|
|
|
54
22
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ModelOperation } from '../utils
|
|
1
|
+
import { ModelOperation } from '../utils';
|
|
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, Object>;
|
|
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,UAAU,CAAC;AAE1C,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;IAQtB,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAkBlC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B,OAAO,IAAI,MAAM;IAIjB,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC;IAIzB,YAAY,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAIvC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAItC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,GAAG,OAAO;IAQ7E,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAe9C,oBAAoB,CAAC,SAAS,EAAE,cAAc,EAAE,UAAU,GAAE,OAAe,GAAG,KAAK,CAAC,MAAM,CAAC;IAwB3F,aAAa,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAkB3C,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 = new Array();
|
|
15
|
+
this.roles = new Array();
|
|
16
16
|
}
|
|
17
17
|
setRole(input) {
|
|
18
|
-
const { role, resource, operations, allowRoleOverwrite = false
|
|
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,39 +58,43 @@ class AccessControlMatrix {
|
|
|
58
58
|
resetAccessForResource(resource) {
|
|
59
59
|
this.validate({ resource });
|
|
60
60
|
const resourceIndex = this.resources.indexOf(resource);
|
|
61
|
-
this.roles.
|
|
61
|
+
for (let i = 0; i < this.roles.length; 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
|
-
this.roles.
|
|
69
|
+
for (let x = 0; x < this.roles.length; x++) {
|
|
70
70
|
let hasOperation = false;
|
|
71
71
|
if (fullAccess) {
|
|
72
|
-
hasOperation = this.resources.every((
|
|
72
|
+
hasOperation = this.resources.every((resource, idx) => {
|
|
73
|
+
return this.matrix[x][idx][operationIndex];
|
|
74
|
+
});
|
|
73
75
|
}
|
|
74
76
|
else {
|
|
75
|
-
hasOperation = this.resources.some((
|
|
77
|
+
hasOperation = this.resources.some((resource, idx) => {
|
|
78
|
+
return this.matrix[x][idx][operationIndex];
|
|
79
|
+
});
|
|
76
80
|
}
|
|
77
81
|
if (hasOperation)
|
|
78
82
|
roles.push(this.roles[x]);
|
|
79
|
-
}
|
|
83
|
+
}
|
|
80
84
|
return roles;
|
|
81
85
|
}
|
|
82
86
|
getAcmPerRole() {
|
|
83
87
|
const acmPerRole = new Map();
|
|
84
|
-
this.matrix.
|
|
85
|
-
|
|
86
|
-
this.matrix[i].
|
|
88
|
+
for (let i = 0; i < this.matrix.length; i++) {
|
|
89
|
+
let tableObj = {};
|
|
90
|
+
for (let y = 0; y < this.matrix[i].length; y++) {
|
|
87
91
|
tableObj[this.resources[y]] = this.matrix[i][y].reduce((prev, resource, index) => {
|
|
88
92
|
prev[this.operations[index]] = resource;
|
|
89
93
|
return prev;
|
|
90
94
|
}, {});
|
|
91
|
-
}
|
|
95
|
+
}
|
|
92
96
|
acmPerRole.set(this.roles[i], tableObj);
|
|
93
|
-
}
|
|
97
|
+
}
|
|
94
98
|
return acmPerRole;
|
|
95
99
|
}
|
|
96
100
|
validate(input) {
|
|
@@ -102,16 +106,15 @@ class AccessControlMatrix {
|
|
|
102
106
|
}
|
|
103
107
|
if (input.operations) {
|
|
104
108
|
input.operations.forEach(operation => {
|
|
105
|
-
if (this.operations.indexOf(operation) === -1)
|
|
109
|
+
if (this.operations.indexOf(operation) === -1)
|
|
106
110
|
throw new graphql_transformer_core_1.TransformerContractError(`Operation: ${operation} does not exist in the ACM.`);
|
|
107
|
-
}
|
|
108
111
|
});
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
114
|
getResourceOperationMatrix(input) {
|
|
112
115
|
const { operations, resource, role } = input;
|
|
113
116
|
let fieldAllowVector = [];
|
|
114
|
-
|
|
117
|
+
let operationList = this.getOperationList(operations);
|
|
115
118
|
if (role && resource) {
|
|
116
119
|
const roleIndex = this.roles.indexOf(role);
|
|
117
120
|
const resourceIndex = this.resources.indexOf(resource);
|
|
@@ -119,7 +122,7 @@ class AccessControlMatrix {
|
|
|
119
122
|
fieldAllowVector[resourceIndex] = operationList;
|
|
120
123
|
return fieldAllowVector;
|
|
121
124
|
}
|
|
122
|
-
this.resources.
|
|
125
|
+
for (let i = 0; i < this.resources.length; i++) {
|
|
123
126
|
if (resource) {
|
|
124
127
|
if (this.resources.indexOf(resource) === i) {
|
|
125
128
|
fieldAllowVector.push(operationList);
|
|
@@ -131,14 +134,14 @@ class AccessControlMatrix {
|
|
|
131
134
|
else {
|
|
132
135
|
fieldAllowVector.push(operationList);
|
|
133
136
|
}
|
|
134
|
-
}
|
|
137
|
+
}
|
|
135
138
|
return fieldAllowVector;
|
|
136
139
|
}
|
|
137
140
|
getOperationList(operations) {
|
|
138
|
-
|
|
139
|
-
this.operations
|
|
141
|
+
let operationList = new Array();
|
|
142
|
+
for (let operation of this.operations) {
|
|
140
143
|
operationList.push(operations.includes(operation));
|
|
141
|
-
}
|
|
144
|
+
}
|
|
142
145
|
return operationList;
|
|
143
146
|
}
|
|
144
147
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acm.js","sourceRoot":"","sources":["../../src/accesscontrol/acm.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,oFAAwG;AAmCxG,MAAa,mBA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G,CAAC,MAAM,CAAC,GACzB,IAAI;IAuBP,+BAA+B,QAAS,0BAA0B,iBAAiB,IAAI,MAAM,CAAC,KAAG,IAAI,CAGnG;CACH"}
|
|
@@ -33,7 +33,6 @@ 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");
|
|
37
36
|
const accesscontrol_1 = require("./accesscontrol");
|
|
38
37
|
const utils_1 = require("./utils");
|
|
39
38
|
const warnings_1 = require("./utils/warnings");
|
|
@@ -91,7 +90,7 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
91
90
|
const modelDirective = (_a = parent.directives) === null || _a === void 0 ? void 0 : _a.find(dir => dir.name.value === 'model');
|
|
92
91
|
const typeName = parent.name.value;
|
|
93
92
|
const fieldName = field.name.value;
|
|
94
|
-
const rules = (0, utils_1.getAuthDirectiveRules)(new graphql_transformer_core_1.DirectiveWrapper(directive)
|
|
93
|
+
const rules = (0, utils_1.getAuthDirectiveRules)(new graphql_transformer_core_1.DirectiveWrapper(directive));
|
|
95
94
|
(0, utils_1.validateFieldRules)(new graphql_transformer_core_1.DirectiveWrapper(directive), isParentTypeBuiltinType, modelDirective !== undefined, field.name.value);
|
|
96
95
|
(0, utils_1.validateRules)(rules, this.configuredAuthProviders, field.name.value);
|
|
97
96
|
this.setAuthPolicyFlag(rules);
|
|
@@ -119,10 +118,10 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
119
118
|
const typeFieldName = `${typeName}:${fieldName}`;
|
|
120
119
|
const acm = new accesscontrol_1.AccessControlMatrix({
|
|
121
120
|
name: typeFieldName,
|
|
122
|
-
operations: ['
|
|
121
|
+
operations: ['read'],
|
|
123
122
|
resources: [typeFieldName],
|
|
124
123
|
});
|
|
125
|
-
this.convertRulesToRoles(acm, staticRules, false, typeFieldName, ['
|
|
124
|
+
this.convertRulesToRoles(acm, staticRules, false, typeFieldName, ['read'], context);
|
|
126
125
|
this.authNonModelConfig.set(typeFieldName, acm);
|
|
127
126
|
}
|
|
128
127
|
};
|
|
@@ -171,6 +170,8 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
171
170
|
const def = context.output.getObject(modelName);
|
|
172
171
|
const modelNameConfig = this.modelDirectiveConfig.get(modelName);
|
|
173
172
|
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));
|
|
174
175
|
const queryFields = (0, utils_1.getQueryFieldNames)(this.modelDirectiveConfig.get(modelName));
|
|
175
176
|
queryFields.forEach(query => {
|
|
176
177
|
switch (query.type) {
|
|
@@ -197,13 +198,11 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
197
198
|
const config = (0, utils_1.getSearchableConfig)(searchableDirective, modelName);
|
|
198
199
|
this.protectSearchResolver(context, def, context.output.getQueryTypeName(), config.queries.search, acm);
|
|
199
200
|
}
|
|
200
|
-
const
|
|
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 : [];
|
|
201
|
+
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 : [];
|
|
203
202
|
const errorFields = new Array();
|
|
204
|
-
modelFields.forEach(
|
|
203
|
+
modelFields.forEach(field => {
|
|
205
204
|
const fieldReadRoles = (0, utils_1.getReadRolesForField)(acm, readRoles, field.name.value);
|
|
206
|
-
const allowedRoles = fieldReadRoles.filter(r =>
|
|
205
|
+
const allowedRoles = fieldReadRoles.filter(r => acm.isAllowed(r, field.name.value, 'read'));
|
|
207
206
|
const needsFieldResolver = allowedRoles.length < fieldReadRoles.length;
|
|
208
207
|
if (needsFieldResolver && field.type.kind === graphql_1.Kind.NON_NULL_TYPE) {
|
|
209
208
|
errorFields.push(field.name.value);
|
|
@@ -236,9 +235,7 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
236
235
|
}
|
|
237
236
|
});
|
|
238
237
|
const subscriptionFieldNames = (0, utils_1.getSubscriptionFieldNames)(this.modelDirectiveConfig.get(modelName));
|
|
239
|
-
const subscriptionRoles =
|
|
240
|
-
.getRolesPerOperation('listen')
|
|
241
|
-
.map(role => this.roleMap.get(role))
|
|
238
|
+
const subscriptionRoles = roleDefinitions
|
|
242
239
|
.filter(roleDef => { var _a; return (roleDef.strategy === 'owner' && !(0, utils_1.fieldIsList)((_a = def.fields) !== null && _a !== void 0 ? _a : [], roleDef.entity)) || roleDef.static; });
|
|
243
240
|
subscriptionFieldNames.forEach(subscription => {
|
|
244
241
|
this.protectSubscriptionResolver(context, subscription.typeName, subscription.fieldName, subscriptionRoles);
|
|
@@ -288,43 +285,42 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
288
285
|
this.addOperationToResourceReferences(typeName, operationName, acm.getRoles());
|
|
289
286
|
}
|
|
290
287
|
};
|
|
291
|
-
addServiceDirective(ctx.output.getQueryTypeName(), '
|
|
292
|
-
addServiceDirective(ctx.output.getQueryTypeName(), '
|
|
293
|
-
addServiceDirective(ctx.output.getQueryTypeName(), '
|
|
288
|
+
addServiceDirective(ctx.output.getQueryTypeName(), 'read', (_a = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.queries) === null || _a === void 0 ? void 0 : _a.get);
|
|
289
|
+
addServiceDirective(ctx.output.getQueryTypeName(), 'read', (_b = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.queries) === null || _b === void 0 ? void 0 : _b.list);
|
|
290
|
+
addServiceDirective(ctx.output.getQueryTypeName(), 'read', (_c = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.queries) === null || _c === void 0 ? void 0 : _c.sync);
|
|
294
291
|
addServiceDirective(ctx.output.getMutationTypeName(), 'create', (_d = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _d === void 0 ? void 0 : _d.create);
|
|
295
292
|
addServiceDirective(ctx.output.getMutationTypeName(), 'update', (_e = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _e === void 0 ? void 0 : _e.update);
|
|
296
293
|
addServiceDirective(ctx.output.getMutationTypeName(), 'delete', (_f = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _f === void 0 ? void 0 : _f.delete);
|
|
297
294
|
if (ctx.metadata.has(indexKeyName)) {
|
|
298
295
|
ctx.metadata.get(indexKeyName).forEach(index => {
|
|
299
|
-
addServiceDirective(ctx.output.getQueryTypeName(), '
|
|
300
|
-
addServiceDirective(ctx.output.getQueryTypeName(), 'get', index.split(':')[1]);
|
|
296
|
+
addServiceDirective(ctx.output.getQueryTypeName(), 'read', index.split(':')[1]);
|
|
301
297
|
});
|
|
302
298
|
}
|
|
303
299
|
if (searchableDirective) {
|
|
304
300
|
const config = (0, utils_1.getSearchableConfig)(searchableDirective, def.name.value);
|
|
305
|
-
addServiceDirective(ctx.output.getQueryTypeName(), '
|
|
301
|
+
addServiceDirective(ctx.output.getQueryTypeName(), 'read', config.queries.search);
|
|
306
302
|
}
|
|
307
303
|
const subscriptions = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.subscriptions;
|
|
308
304
|
if ((subscriptions === null || subscriptions === void 0 ? void 0 : subscriptions.level) === graphql_model_transformer_1.SubscriptionLevel.on) {
|
|
309
305
|
const subscriptionArguments = acm
|
|
310
|
-
.getRolesPerOperation('
|
|
306
|
+
.getRolesPerOperation('read')
|
|
311
307
|
.map(role => this.roleMap.get(role))
|
|
312
308
|
.filter(roleDef => { var _a; return roleDef.strategy === 'owner' && !(0, utils_1.fieldIsList)((_a = def.fields) !== null && _a !== void 0 ? _a : [], roleDef.entity); });
|
|
313
309
|
if (subscriptions.onCreate && ((_g = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _g === void 0 ? void 0 : _g.create)) {
|
|
314
310
|
subscriptions.onCreate.forEach(onCreateSub => {
|
|
315
|
-
addServiceDirective(ctx.output.getSubscriptionTypeName(), '
|
|
311
|
+
addServiceDirective(ctx.output.getSubscriptionTypeName(), 'read', onCreateSub);
|
|
316
312
|
(0, utils_1.addSubscriptionArguments)(ctx, onCreateSub, subscriptionArguments);
|
|
317
313
|
});
|
|
318
314
|
}
|
|
319
315
|
if (subscriptions.onUpdate && ((_h = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _h === void 0 ? void 0 : _h.update)) {
|
|
320
316
|
subscriptions.onUpdate.forEach(onUpdateSub => {
|
|
321
|
-
addServiceDirective(ctx.output.getSubscriptionTypeName(), '
|
|
317
|
+
addServiceDirective(ctx.output.getSubscriptionTypeName(), 'read', onUpdateSub);
|
|
322
318
|
(0, utils_1.addSubscriptionArguments)(ctx, onUpdateSub, subscriptionArguments);
|
|
323
319
|
});
|
|
324
320
|
}
|
|
325
321
|
if (subscriptions.onDelete && ((_j = modelConfig === null || modelConfig === void 0 ? void 0 : modelConfig.mutations) === null || _j === void 0 ? void 0 : _j.delete)) {
|
|
326
322
|
subscriptions.onDelete.forEach(onDeleteSub => {
|
|
327
|
-
addServiceDirective(ctx.output.getSubscriptionTypeName(), '
|
|
323
|
+
addServiceDirective(ctx.output.getSubscriptionTypeName(), 'read', onDeleteSub);
|
|
328
324
|
(0, utils_1.addSubscriptionArguments)(ctx, onDeleteSub, subscriptionArguments);
|
|
329
325
|
});
|
|
330
326
|
}
|
|
@@ -333,7 +329,7 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
333
329
|
this.protectGetResolver = (ctx, def, typeName, fieldName, acm) => {
|
|
334
330
|
var _a;
|
|
335
331
|
const resolver = ctx.resolvers.getResolver(typeName, fieldName);
|
|
336
|
-
const roleDefinitions = acm.getRolesPerOperation('
|
|
332
|
+
const roleDefinitions = acm.getRolesPerOperation('read').map(r => this.roleMap.get(r));
|
|
337
333
|
const tableKeySchema = (0, graphql_transformer_core_1.getTable)(ctx, def).keySchema;
|
|
338
334
|
const primaryFields = tableKeySchema.map(att => att.attributeName);
|
|
339
335
|
const primaryKey = (0, utils_1.getPartitionKey)(tableKeySchema);
|
|
@@ -343,7 +339,7 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
343
339
|
this.protectListResolver = (ctx, def, typeName, fieldName, acm, indexName) => {
|
|
344
340
|
var _a;
|
|
345
341
|
const resolver = ctx.resolvers.getResolver(typeName, fieldName);
|
|
346
|
-
const roleDefinitions = acm.getRolesPerOperation('
|
|
342
|
+
const roleDefinitions = acm.getRolesPerOperation('read').map(r => this.roleMap.get(r));
|
|
347
343
|
let primaryFields;
|
|
348
344
|
let partitionKey;
|
|
349
345
|
const table = (0, graphql_transformer_core_1.getTable)(ctx, def);
|
|
@@ -369,18 +365,12 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
369
365
|
const relatedModelObject = AuthTransformer.getRelatedModelObject(ctx, (0, graphql_transformer_common_1.getBaseType)(field.type));
|
|
370
366
|
if (this.authModelConfig.has(relatedModelObject.name.value)) {
|
|
371
367
|
const acm = this.authModelConfig.get(relatedModelObject.name.value);
|
|
372
|
-
const roleDefinitions =
|
|
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));
|
|
368
|
+
const roleDefinitions = acm.getRolesPerOperation('read').map(r => this.roleMap.get(r));
|
|
379
369
|
const relationalPrimaryMap = (0, utils_1.getRelationalPrimaryMap)(ctx, def, field, relatedModelObject);
|
|
380
370
|
relatedAuthExpression = (0, resolvers_1.generateAuthExpressionForRelationQuery)(this.configuredAuthProviders, roleDefinitions, (_a = relatedModelObject.fields) !== null && _a !== void 0 ? _a : [], relationalPrimaryMap);
|
|
381
371
|
}
|
|
382
372
|
else {
|
|
383
|
-
relatedAuthExpression = (0,
|
|
373
|
+
relatedAuthExpression = (0, resolvers_1.generateSandboxExpressionForField)(ctx.sandboxModeEnabled);
|
|
384
374
|
}
|
|
385
375
|
if (fieldRoles) {
|
|
386
376
|
const roleDefinitions = fieldRoles.map(r => this.roleMap.get(r));
|
|
@@ -400,7 +390,7 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
400
390
|
var _a;
|
|
401
391
|
if (ctx.isProjectUsingDataStore()) {
|
|
402
392
|
const resolver = ctx.resolvers.getResolver(typeName, fieldName);
|
|
403
|
-
const roleDefinitions = acm.getRolesPerOperation('
|
|
393
|
+
const roleDefinitions = acm.getRolesPerOperation('read').map(r => this.roleMap.get(r));
|
|
404
394
|
const primaryFields = (0, graphql_transformer_core_1.getTable)(ctx, def).keySchema.map(att => att.attributeName);
|
|
405
395
|
const authExpression = (0, resolvers_1.generateAuthExpressionForQueries)(this.configuredAuthProviders, roleDefinitions, (_a = def.fields) !== null && _a !== void 0 ? _a : [], primaryFields);
|
|
406
396
|
resolver.addToSlot('auth', graphql_transformer_core_1.MappingTemplate.s3MappingTemplateFromString(authExpression, `${typeName}.${fieldName}.{slotName}.{slotIndex}.req.vtl`));
|
|
@@ -413,8 +403,8 @@ class AuthTransformer extends graphql_transformer_core_1.TransformerAuthBase {
|
|
|
413
403
|
const allowedAggFields = modelFields.map(f => f.name.value).filter(f => !acmFields.includes(f));
|
|
414
404
|
let leastAllowedFields = acmFields;
|
|
415
405
|
const resolver = ctx.resolvers.getResolver(typeName, fieldName);
|
|
416
|
-
const readRoleDefinitions = acm.getRolesPerOperation('
|
|
417
|
-
const allowedFields = acmFields.filter(resource => acm.isAllowed(role, resource, '
|
|
406
|
+
const readRoleDefinitions = acm.getRolesPerOperation('read').map(role => {
|
|
407
|
+
const allowedFields = acmFields.filter(resource => acm.isAllowed(role, resource, 'read'));
|
|
418
408
|
const roleDefinition = this.roleMap.get(role);
|
|
419
409
|
if (allowedFields.length !== acmFields.length || !roleDefinition.static) {
|
|
420
410
|
roleDefinition.allowedFields = allowedFields;
|