@aws-amplify/graphql-auth-transformer 2.1.13-alpha.7 → 2.1.13-test-tag-1.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/package.json +10 -10
  3. package/lib/accesscontrol/acm.d.ts +0 -35
  4. package/lib/accesscontrol/acm.d.ts.map +0 -1
  5. package/lib/accesscontrol/acm.js +0 -144
  6. package/lib/accesscontrol/acm.js.map +0 -1
  7. package/lib/accesscontrol/index.d.ts +0 -2
  8. package/lib/accesscontrol/index.d.ts.map +0 -1
  9. package/lib/accesscontrol/index.js +0 -6
  10. package/lib/accesscontrol/index.js.map +0 -1
  11. package/lib/graphql-auth-transformer.d.ts +0 -60
  12. package/lib/graphql-auth-transformer.d.ts.map +0 -1
  13. package/lib/graphql-auth-transformer.js +0 -907
  14. package/lib/graphql-auth-transformer.js.map +0 -1
  15. package/lib/index.d.ts +0 -6
  16. package/lib/index.d.ts.map +0 -1
  17. package/lib/index.js +0 -25
  18. package/lib/index.js.map +0 -1
  19. package/lib/resolvers/field.d.ts +0 -7
  20. package/lib/resolvers/field.d.ts.map +0 -1
  21. package/lib/resolvers/field.js +0 -109
  22. package/lib/resolvers/field.js.map +0 -1
  23. package/lib/resolvers/helpers.d.ts +0 -24
  24. package/lib/resolvers/helpers.d.ts.map +0 -1
  25. package/lib/resolvers/helpers.js +0 -210
  26. package/lib/resolvers/helpers.js.map +0 -1
  27. package/lib/resolvers/index.d.ts +0 -9
  28. package/lib/resolvers/index.d.ts.map +0 -1
  29. package/lib/resolvers/index.js +0 -25
  30. package/lib/resolvers/index.js.map +0 -1
  31. package/lib/resolvers/mutation.create.d.ts +0 -5
  32. package/lib/resolvers/mutation.create.d.ts.map +0 -1
  33. package/lib/resolvers/mutation.create.js +0 -172
  34. package/lib/resolvers/mutation.create.js.map +0 -1
  35. package/lib/resolvers/mutation.delete.d.ts +0 -4
  36. package/lib/resolvers/mutation.delete.d.ts.map +0 -1
  37. package/lib/resolvers/mutation.delete.js +0 -126
  38. package/lib/resolvers/mutation.delete.js.map +0 -1
  39. package/lib/resolvers/mutation.update.d.ts +0 -4
  40. package/lib/resolvers/mutation.update.d.ts.map +0 -1
  41. package/lib/resolvers/mutation.update.js +0 -181
  42. package/lib/resolvers/mutation.update.js.map +0 -1
  43. package/lib/resolvers/query.d.ts +0 -6
  44. package/lib/resolvers/query.d.ts.map +0 -1
  45. package/lib/resolvers/query.js +0 -302
  46. package/lib/resolvers/query.js.map +0 -1
  47. package/lib/resolvers/search.d.ts +0 -4
  48. package/lib/resolvers/search.d.ts.map +0 -1
  49. package/lib/resolvers/search.js +0 -184
  50. package/lib/resolvers/search.js.map +0 -1
  51. package/lib/resolvers/subscriptions.d.ts +0 -3
  52. package/lib/resolvers/subscriptions.d.ts.map +0 -1
  53. package/lib/resolvers/subscriptions.js +0 -83
  54. package/lib/resolvers/subscriptions.js.map +0 -1
  55. package/lib/utils/constants.d.ts +0 -28
  56. package/lib/utils/constants.d.ts.map +0 -1
  57. package/lib/utils/constants.js +0 -41
  58. package/lib/utils/constants.js.map +0 -1
  59. package/lib/utils/definitions.d.ts +0 -72
  60. package/lib/utils/definitions.d.ts.map +0 -1
  61. package/lib/utils/definitions.js +0 -42
  62. package/lib/utils/definitions.js.map +0 -1
  63. package/lib/utils/iam.d.ts +0 -6
  64. package/lib/utils/iam.d.ts.map +0 -1
  65. package/lib/utils/iam.js +0 -76
  66. package/lib/utils/iam.js.map +0 -1
  67. package/lib/utils/index.d.ts +0 -15
  68. package/lib/utils/index.d.ts.map +0 -1
  69. package/lib/utils/index.js +0 -147
  70. package/lib/utils/index.js.map +0 -1
  71. package/lib/utils/schema.d.ts +0 -31
  72. package/lib/utils/schema.d.ts.map +0 -1
  73. package/lib/utils/schema.js +0 -259
  74. package/lib/utils/schema.js.map +0 -1
  75. package/lib/utils/validations.d.ts +0 -8
  76. package/lib/utils/validations.d.ts.map +0 -1
  77. package/lib/utils/validations.js +0 -98
  78. package/lib/utils/validations.js.map +0 -1
  79. package/lib/utils/warnings.d.ts +0 -7
  80. package/lib/utils/warnings.d.ts.map +0 -1
  81. package/lib/utils/warnings.js +0 -61
  82. package/lib/utils/warnings.js.map +0 -1
@@ -1,181 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateAuthExpressionForUpdate = void 0;
4
- const graphql_mapping_template_1 = require("graphql-mapping-template");
5
- const utils_1 = require("../utils");
6
- const helpers_1 = require("./helpers");
7
- const apiKeyExpression = (roles) => {
8
- const expression = new Array();
9
- if (roles.length === 0) {
10
- return (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('util.authType()'), (0, graphql_mapping_template_1.str)(utils_1.API_KEY_AUTH_TYPE)), (0, graphql_mapping_template_1.ref)('util.unauthorized()'));
11
- }
12
- if (roles[0].areAllFieldsAllowed && roles[0].areAllFieldsNullAllowed) {
13
- expression.push((0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(true)));
14
- }
15
- else {
16
- expression.push((0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${utils_1.ALLOWED_FIELDS}`), (0, graphql_mapping_template_1.raw)(JSON.stringify(roles[0].allowedFields))), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${utils_1.NULL_ALLOWED_FIELDS}`), (0, graphql_mapping_template_1.raw)(JSON.stringify(roles[0].nullAllowedFields))));
17
- }
18
- return (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('util.authType()'), (0, graphql_mapping_template_1.str)(utils_1.API_KEY_AUTH_TYPE)), (0, graphql_mapping_template_1.compoundExpression)(expression));
19
- };
20
- const lambdaExpression = (roles) => {
21
- const expression = new Array();
22
- if (roles.length === 0) {
23
- return (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('util.authType()'), (0, graphql_mapping_template_1.str)(utils_1.LAMBDA_AUTH_TYPE)), (0, graphql_mapping_template_1.ref)('util.unauthorized()'));
24
- }
25
- if (roles[0].areAllFieldsAllowed && roles[0].areAllFieldsNullAllowed) {
26
- expression.push((0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(true)));
27
- }
28
- else {
29
- expression.push((0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${utils_1.ALLOWED_FIELDS}`), (0, graphql_mapping_template_1.raw)(JSON.stringify(roles[0].allowedFields))), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${utils_1.NULL_ALLOWED_FIELDS}`), (0, graphql_mapping_template_1.raw)(JSON.stringify(roles[0].nullAllowedFields))));
30
- }
31
- return (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('util.authType()'), (0, graphql_mapping_template_1.str)(utils_1.LAMBDA_AUTH_TYPE)), (0, graphql_mapping_template_1.compoundExpression)(expression));
32
- };
33
- const iamExpression = (roles, hasAdminRolesEnabled = false, adminRoles = [], identityPoolId) => {
34
- const expression = new Array();
35
- if (hasAdminRolesEnabled) {
36
- expression.push((0, helpers_1.iamAdminRoleCheckExpression)(adminRoles));
37
- }
38
- if (roles.length > 0) {
39
- roles.forEach((role) => {
40
- if (role.areAllFieldsAllowed && role.areAllFieldsNullAllowed) {
41
- expression.push((0, helpers_1.iamCheck)(role.claim, (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(true)), identityPoolId));
42
- }
43
- else {
44
- expression.push((0, helpers_1.iamCheck)(role.claim, (0, graphql_mapping_template_1.compoundExpression)([
45
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${utils_1.ALLOWED_FIELDS}`), (0, graphql_mapping_template_1.raw)(JSON.stringify(role.allowedFields))),
46
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${utils_1.NULL_ALLOWED_FIELDS}`), (0, graphql_mapping_template_1.raw)(JSON.stringify(role.nullAllowedFields))),
47
- ]), identityPoolId));
48
- }
49
- });
50
- }
51
- else {
52
- expression.push((0, graphql_mapping_template_1.ref)('util.unauthorized()'));
53
- }
54
- return (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('util.authType()'), (0, graphql_mapping_template_1.str)(utils_1.IAM_AUTH_TYPE)), (0, graphql_mapping_template_1.compoundExpression)(expression));
55
- };
56
- const generateStaticRoleExpression = (roles) => {
57
- const staticRoleExpression = [];
58
- const privateRoleIdx = roles.findIndex((r) => r.strategy === 'private');
59
- if (privateRoleIdx > -1) {
60
- const privateRole = roles[privateRoleIdx];
61
- if (privateRole.areAllFieldsAllowed && privateRole.areAllFieldsNullAllowed) {
62
- staticRoleExpression.push((0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(true)));
63
- }
64
- else {
65
- staticRoleExpression.push((0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`${utils_1.ALLOWED_FIELDS}.addAll`), (0, graphql_mapping_template_1.raw)(JSON.stringify(privateRole.allowedFields)))), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`${utils_1.NULL_ALLOWED_FIELDS}.addAll`), (0, graphql_mapping_template_1.raw)(JSON.stringify(privateRole.nullAllowedFields)))));
66
- }
67
- roles.splice(privateRoleIdx, 1);
68
- }
69
- if (roles.length > 0) {
70
- staticRoleExpression.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG)), (0, graphql_mapping_template_1.compoundExpression)([
71
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('staticGroupRoles'), (0, graphql_mapping_template_1.raw)(JSON.stringify(roles.map((r) => ({
72
- claim: r.claim,
73
- entity: r.entity,
74
- allowedFields: r.allowedFields,
75
- nullAllowedFields: r.nullAllowedFields,
76
- isAuthorizedOnAllFields: r.areAllFieldsAllowed && r.areAllFieldsNullAllowed,
77
- }))))),
78
- (0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('groupRole'), (0, graphql_mapping_template_1.ref)('staticGroupRoles'), [
79
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('groupsInToken'), (0, helpers_1.getIdentityClaimExp)((0, graphql_mapping_template_1.ref)('groupRole.claim'), (0, graphql_mapping_template_1.list)([]))),
80
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('groupsInToken.contains'), (0, graphql_mapping_template_1.ref)('groupRole.entity')), addAllowedFieldsIfElse('groupRole.allowedFields', 'groupRole.nullAllowedFields', 'groupRole.isAuthorizedOnAllFields', true)),
81
- ]),
82
- ])));
83
- }
84
- return staticRoleExpression;
85
- };
86
- const dynamicGroupRoleExpression = (roles, fields) => {
87
- const ownerExpression = new Array();
88
- const dynamicGroupExpression = new Array();
89
- roles.forEach((role, idx) => {
90
- const entityIsList = (0, utils_1.fieldIsList)(fields, role.entity);
91
- if (role.strategy === 'owner') {
92
- ownerExpression.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG)), (0, graphql_mapping_template_1.compoundExpression)([
93
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`ownerEntity${idx}`), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.defaultIfNull'), (0, graphql_mapping_template_1.ref)(`ctx.result.${role.entity}`), entityIsList ? (0, graphql_mapping_template_1.list)([]) : (0, graphql_mapping_template_1.nul)())),
94
- (0, helpers_1.generateOwnerClaimExpression)(role.claim, `ownerClaim${idx}`),
95
- (0, graphql_mapping_template_1.iff)((0, helpers_1.generateInvalidClaimsCondition)(role.claim, `ownerClaim${idx}`), (0, graphql_mapping_template_1.compoundExpression)([
96
- (0, helpers_1.generateOwnerMultiClaimExpression)(role.claim, `ownerClaim${idx}`),
97
- (0, helpers_1.generateOwnerClaimListExpression)(role.claim, `ownerClaimsList${idx}`),
98
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`ownerAllowedFields${idx}`), (0, graphql_mapping_template_1.raw)(JSON.stringify(role.allowedFields))),
99
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`ownerNullAllowedFields${idx}`), (0, graphql_mapping_template_1.raw)(JSON.stringify(role.nullAllowedFields))),
100
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`isAuthorizedOnAllFields${idx}`), (0, graphql_mapping_template_1.bool)(role.areAllFieldsAllowed && role.areAllFieldsNullAllowed)),
101
- ...(entityIsList
102
- ? [
103
- (0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('allowedOwner'), (0, graphql_mapping_template_1.ref)(`ownerEntity${idx}`), [
104
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.or)([
105
- (0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('allowedOwner'), (0, graphql_mapping_template_1.ref)(`ownerClaim${idx}`)),
106
- (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`ownerClaimsList${idx}.contains`), (0, graphql_mapping_template_1.ref)('allowedOwner')),
107
- ]), addAllowedFieldsIfElse(`ownerAllowedFields${idx}`, `ownerNullAllowedFields${idx}`, `isAuthorizedOnAllFields${idx}`, true)),
108
- ]),
109
- ]
110
- : [
111
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.or)([
112
- (0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)(`ownerEntity${idx}`), (0, graphql_mapping_template_1.ref)(`ownerClaim${idx}`)),
113
- (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`ownerClaimsList${idx}.contains`), (0, graphql_mapping_template_1.ref)(`ownerEntity${idx}`)),
114
- ]), addAllowedFieldsIfElse(`ownerAllowedFields${idx}`, `ownerNullAllowedFields${idx}`, `isAuthorizedOnAllFields${idx}`)),
115
- ]),
116
- ])),
117
- ])));
118
- }
119
- if (role.strategy === 'groups') {
120
- dynamicGroupExpression.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG)), (0, graphql_mapping_template_1.compoundExpression)([
121
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`groupEntity${idx}`), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.defaultIfNull'), (0, graphql_mapping_template_1.ref)(`ctx.result.${role.entity}`), entityIsList ? (0, graphql_mapping_template_1.list)([]) : (0, graphql_mapping_template_1.nul)())),
122
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`groupClaim${idx}`), (0, helpers_1.getIdentityClaimExp)((0, graphql_mapping_template_1.str)(role.claim), (0, graphql_mapping_template_1.list)([]))),
123
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`groupAllowedFields${idx}`), (0, graphql_mapping_template_1.raw)(JSON.stringify(role.allowedFields))),
124
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`groupNullAllowedFields${idx}`), (0, graphql_mapping_template_1.raw)(JSON.stringify(role.nullAllowedFields))),
125
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`isAuthorizedOnAllFields${idx}`), (0, graphql_mapping_template_1.bool)(role.areAllFieldsAllowed && role.areAllFieldsNullAllowed)),
126
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isString'), (0, graphql_mapping_template_1.ref)(`groupClaim${idx}`)), (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isList'), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.parseJson'), (0, graphql_mapping_template_1.ref)(`groupClaim${idx}`))), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`groupClaim${idx}`), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.parseJson'), (0, graphql_mapping_template_1.ref)(`groupClaim${idx}`))), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`groupClaim${idx}`), (0, graphql_mapping_template_1.list)([(0, graphql_mapping_template_1.ref)(`groupClaim${idx}`)])))),
127
- (0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('userGroup'), (0, graphql_mapping_template_1.ref)(`groupClaim${idx}`), [
128
- (0, graphql_mapping_template_1.iff)(entityIsList
129
- ? (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`groupEntity${idx}.contains`), (0, graphql_mapping_template_1.ref)('userGroup'))
130
- : (0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)(`groupEntity${idx}`), (0, graphql_mapping_template_1.ref)('userGroup')), addAllowedFieldsIfElse(`groupAllowedFields${idx}`, `groupNullAllowedFields${idx}`, `isAuthorizedOnAllFields${idx}`, true)),
131
- ]),
132
- ])));
133
- }
134
- });
135
- return [...(ownerExpression.length > 0 ? ownerExpression : []), ...(dynamicGroupExpression.length > 0 ? dynamicGroupExpression : [])];
136
- };
137
- const generateAuthExpressionForUpdate = (providers, roles, fields) => {
138
- const { cognitoStaticRoles, cognitoDynamicRoles, oidcStaticRoles, oidcDynamicRoles, apiKeyRoles, iamRoles, lambdaRoles } = (0, utils_1.splitRoles)(roles);
139
- const totalAuthExpressions = [
140
- helpers_1.setHasAuthExpression,
141
- (0, helpers_1.responseCheckForErrors)(),
142
- (0, helpers_1.getInputFields)(),
143
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(false)),
144
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${utils_1.ALLOWED_FIELDS}`), (0, graphql_mapping_template_1.list)([])),
145
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${utils_1.NULL_ALLOWED_FIELDS}`), (0, graphql_mapping_template_1.list)([])),
146
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${utils_1.DENIED_FIELDS}`), (0, graphql_mapping_template_1.obj)({})),
147
- ];
148
- if (providers.hasApiKey) {
149
- totalAuthExpressions.push(apiKeyExpression(apiKeyRoles));
150
- }
151
- if (providers.hasLambda) {
152
- totalAuthExpressions.push(lambdaExpression(lambdaRoles));
153
- }
154
- if (providers.hasIAM) {
155
- totalAuthExpressions.push(iamExpression(iamRoles, providers.hasAdminRolesEnabled, providers.adminRoles, providers.identityPoolId));
156
- }
157
- if (providers.hasUserPools) {
158
- totalAuthExpressions.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('util.authType()'), (0, graphql_mapping_template_1.str)(utils_1.COGNITO_AUTH_TYPE)), (0, graphql_mapping_template_1.compoundExpression)([
159
- ...generateStaticRoleExpression(cognitoStaticRoles),
160
- ...dynamicGroupRoleExpression(cognitoDynamicRoles, fields),
161
- ])));
162
- }
163
- if (providers.hasOIDC) {
164
- totalAuthExpressions.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('util.authType()'), (0, graphql_mapping_template_1.str)(utils_1.OIDC_AUTH_TYPE)), (0, graphql_mapping_template_1.compoundExpression)([...generateStaticRoleExpression(oidcStaticRoles), ...dynamicGroupRoleExpression(oidcDynamicRoles, fields)])));
165
- }
166
- totalAuthExpressions.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.and)([(0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG)), (0, graphql_mapping_template_1.ref)(`${utils_1.ALLOWED_FIELDS}.isEmpty()`), (0, graphql_mapping_template_1.ref)(`${utils_1.NULL_ALLOWED_FIELDS}.isEmpty()`)]), (0, graphql_mapping_template_1.ref)('util.unauthorized()')), (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG)), (0, graphql_mapping_template_1.compoundExpression)([
167
- (0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('entry'), (0, graphql_mapping_template_1.ref)('util.map.copyAndRetainAllKeys($ctx.args.input, $inputFields).entrySet()'), [
168
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.and)([(0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)('entry.value')), (0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(`${utils_1.NULL_ALLOWED_FIELDS}.contains($entry.key)`))]), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`${utils_1.DENIED_FIELDS}.put`), (0, graphql_mapping_template_1.ref)('entry.key'), (0, graphql_mapping_template_1.str)('')))),
169
- ]),
170
- (0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('deniedField'), (0, graphql_mapping_template_1.ref)(`util.list.copyAndRemoveAll($inputFields, $${utils_1.ALLOWED_FIELDS})`), [
171
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`${utils_1.DENIED_FIELDS}.put`), (0, graphql_mapping_template_1.ref)('deniedField'), (0, graphql_mapping_template_1.str)(''))),
172
- ]),
173
- ])), (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.ref)(`${utils_1.DENIED_FIELDS}.keySet().size() > 0`), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.error'), (0, graphql_mapping_template_1.str)(`Unauthorized on \${${utils_1.DENIED_FIELDS}.keySet()}`), (0, graphql_mapping_template_1.str)('Unauthorized'))));
174
- return (0, graphql_mapping_template_1.printBlock)('Authorization Steps')((0, graphql_mapping_template_1.compoundExpression)([...totalAuthExpressions, (0, graphql_mapping_template_1.toJson)((0, graphql_mapping_template_1.obj)({}))]));
175
- };
176
- exports.generateAuthExpressionForUpdate = generateAuthExpressionForUpdate;
177
- const addAllowedFieldsIfElse = (allowedFieldsKey, nullAllowedFieldsKey, condition, breakLoop = false) => (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.ref)(condition), (0, graphql_mapping_template_1.compoundExpression)([(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(true)), ...(breakLoop ? [(0, graphql_mapping_template_1.raw)('#break')] : [])]), (0, graphql_mapping_template_1.compoundExpression)([
178
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`${utils_1.ALLOWED_FIELDS}.addAll`), (0, graphql_mapping_template_1.ref)(allowedFieldsKey))),
179
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`${utils_1.NULL_ALLOWED_FIELDS}.addAll`), (0, graphql_mapping_template_1.ref)(nullAllowedFieldsKey))),
180
- ]));
181
- //# sourceMappingURL=mutation.update.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mutation.update.js","sourceRoot":"","sources":["../../src/resolvers/mutation.update.ts"],"names":[],"mappings":";;;AACA,uEAsBkC;AAClC,oC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AoB,EAAE,IAAA,iCAAM,EAAC,IAAA,8BAAG,EAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3G,CAAC,CAAC;AAtEW,QAAA,+BAA+B,mCAsE1C;AAEF,MAAM,sBAAsB,GAAG,CAAC,gBAAwB,EAAE,oBAA4B,EAAE,SAAiB,EAAE,SAAS,GAAG,KAAK,EAAc,EAAE,CAC1I,IAAA,iCAAM,EACJ,IAAA,8BAAG,EAAC,SAAS,CAAC,EACd,IAAA,6CAAkB,EAAC,CAAC,IAAA,8BAAG,EAAC,IAAA,8BAAG,EAAC,0BAAkB,CAAC,EAAE,IAAA,+BAAI,EAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAA,8BAAG,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EACrG,IAAA,6CAAkB,EAAC;IACjB,IAAA,+BAAI,EAAC,IAAA,qCAAU,EAAC,IAAA,8BAAG,EAAC,GAAG,sBAAc,SAAS,CAAC,EAAE,IAAA,8BAAG,EAAC,gBAAgB,CAAC,CAAC,CAAC;IACxE,IAAA,+BAAI,EAAC,IAAA,qCAAU,EAAC,IAAA,8BAAG,EAAC,GAAG,2BAAmB,SAAS,CAAC,EAAE,IAAA,8BAAG,EAAC,oBAAoB,CAAC,CAAC,CAAC;CAClF,CAAC,CACH,CAAC"}
@@ -1,6 +0,0 @@
1
- import { FieldDefinitionNode } from 'graphql';
2
- import { RoleDefinition, ConfiguredAuthProviders, RelationalPrimaryMapConfig } from '../utils';
3
- import { aws_dynamodb as dynamodb } from 'aws-cdk-lib';
4
- export declare const generateAuthExpressionForQueries: (providers: ConfiguredAuthProviders, roles: Array<RoleDefinition>, fields: ReadonlyArray<FieldDefinitionNode>, keySchema: dynamodb.CfnTable.KeySchemaProperty[], isIndexQuery?: boolean, primaryKey?: string | undefined) => string;
5
- export declare const generateAuthExpressionForRelationQuery: (providers: ConfiguredAuthProviders, roles: Array<RoleDefinition>, fields: ReadonlyArray<FieldDefinitionNode>, primaryFieldMap: RelationalPrimaryMapConfig) => string;
6
- //# sourceMappingURL=query.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/resolvers/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAsC9C,OAAO,EAGL,cAAc,EAEd,uBAAuB,EAGvB,0BAA0B,EAE3B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AA6dvD,eAAO,MAAM,gCAAgC,cAChC,uBAAuB,SAC3B,MAAM,cAAc,CAAC,UACpB,cAAc,mBAAmB,CAAC,aAC/B,SAAS,QAAQ,CAAC,iBAAiB,EAAE,uCAEpC,MAAM,GAAG,SAAS,KAC7B,MAiDF,CAAC;AAKF,eAAO,MAAM,sCAAsC,cACtC,uBAAuB,SAC3B,MAAM,cAAc,CAAC,UACpB,cAAc,mBAAmB,CAAC,kDAEzC,MA2CF,CAAC"}
@@ -1,302 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateAuthExpressionForRelationQuery = exports.generateAuthExpressionForQueries = void 0;
4
- const graphql_mapping_template_1 = require("graphql-mapping-template");
5
- const helpers_1 = require("./helpers");
6
- const utils_1 = require("../utils");
7
- const generateStaticRoleExpression = (roles) => {
8
- const staticRoleExpression = [];
9
- const privateRoleIdx = roles.findIndex((r) => r.strategy === 'private');
10
- if (privateRoleIdx > -1) {
11
- staticRoleExpression.push((0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(true)));
12
- roles.splice(privateRoleIdx, 1);
13
- }
14
- if (roles.length > 0) {
15
- staticRoleExpression.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG)), (0, graphql_mapping_template_1.compoundExpression)([
16
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('staticGroupRoles'), (0, graphql_mapping_template_1.raw)(JSON.stringify(roles.map((r) => ({ claim: r.claim, entity: r.entity }))))),
17
- (0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('groupRole'), (0, graphql_mapping_template_1.ref)('staticGroupRoles'), [
18
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('groupsInToken'), (0, helpers_1.getIdentityClaimExp)((0, graphql_mapping_template_1.ref)('groupRole.claim'), (0, graphql_mapping_template_1.list)([]))),
19
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('groupsInToken.contains'), (0, graphql_mapping_template_1.ref)('groupRole.entity')), (0, graphql_mapping_template_1.compoundExpression)([(0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(true)), (0, graphql_mapping_template_1.raw)('#break')])),
20
- ]),
21
- ])));
22
- }
23
- return staticRoleExpression;
24
- };
25
- const generateAuthOnRelationalModelQueryExpression = (roles, primaryFieldMap) => {
26
- const modelQueryExpression = new Array();
27
- const primaryRoles = roles.filter((r) => primaryFieldMap.has(r.entity));
28
- if (primaryRoles.length > 0) {
29
- primaryRoles.forEach((role, idx) => {
30
- const { claim, field } = primaryFieldMap.get(role.entity);
31
- modelQueryExpression.push((0, helpers_1.generateOwnerClaimExpression)(role.claim, `primaryRole${idx}`), (0, graphql_mapping_template_1.iff)((0, helpers_1.generateInvalidClaimsCondition)(role.claim, `primaryRole${idx}`), (0, graphql_mapping_template_1.compoundExpression)([
32
- (0, helpers_1.generateOwnerMultiClaimExpression)(role.claim, `primaryRole${idx}`),
33
- (0, helpers_1.generateOwnerClaimListExpression)(role.claim, `ownerClaimsList${idx}`),
34
- (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.and)([
35
- (0, graphql_mapping_template_1.parens)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(`util.isNull($ctx.${claim}.${field})`))),
36
- (0, graphql_mapping_template_1.parens)((0, graphql_mapping_template_1.or)([
37
- (0, graphql_mapping_template_1.parens)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)(`ctx.${claim}.${field}`), (0, graphql_mapping_template_1.ref)(`primaryRole${idx}`))),
38
- (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`ownerClaimsList${idx}.contains`), (0, graphql_mapping_template_1.ref)(`ctx.${claim}.${field}`)),
39
- ])),
40
- ]), (0, graphql_mapping_template_1.compoundExpression)([
41
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(true)),
42
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('ctx.stash.put'), (0, graphql_mapping_template_1.str)('authFilter'), (0, graphql_mapping_template_1.nul)())),
43
- ]), (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.and)([(0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG)), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)('ctx.stash.authFilter'))]), (0, graphql_mapping_template_1.compoundExpression)([
44
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)(claim === 'source' ? (0, graphql_mapping_template_1.ref)(`ctx.stash.connectionAttributes.put`) : (0, graphql_mapping_template_1.ref)(`ctx.${claim}.put`), (0, graphql_mapping_template_1.str)(field), (0, graphql_mapping_template_1.ref)(`primaryRole${idx}`))),
45
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(true)),
46
- ]))),
47
- ])));
48
- });
49
- return [(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG)), (0, graphql_mapping_template_1.compoundExpression)(modelQueryExpression))];
50
- }
51
- return modelQueryExpression;
52
- };
53
- const generateAuthOnModelQueryExpression = (roles, primaryFields, isIndexQuery = false, primaryKey = undefined, sortKeyFields) => {
54
- const modelQueryExpression = new Array();
55
- const primaryRoles = roles.filter((r) => primaryFields.includes(r.entity));
56
- if (primaryRoles.length > 0) {
57
- if (isIndexQuery) {
58
- primaryRoles.forEach((role, idx) => {
59
- const claims = role.claim.split(utils_1.IDENTITY_CLAIM_DELIMITER);
60
- const hasMultiClaims = claims.length > 1;
61
- modelQueryExpression.push((0, helpers_1.generateOwnerClaimExpression)(role.claim, `${role.entity}Claim`), (0, graphql_mapping_template_1.iff)((0, helpers_1.generateInvalidClaimsCondition)(role.claim, `${role.entity}Claim`), (0, graphql_mapping_template_1.compoundExpression)([
62
- (0, helpers_1.generateOwnerMultiClaimExpression)(role.claim, `${role.entity}Claim`),
63
- (0, helpers_1.generateOwnerClaimListExpression)(role.claim, `ownerClaimsList${idx}`),
64
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isString'), (0, graphql_mapping_template_1.ref)(`${role.entity}Claim`)), (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isList'), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.parseJson'), (0, graphql_mapping_template_1.ref)(`${role.entity}Claim`))), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${role.entity}Claim`), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.parseJson'), (0, graphql_mapping_template_1.ref)(`${role.entity}Claim`))), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${role.entity}Claim`), (0, graphql_mapping_template_1.list)([(0, graphql_mapping_template_1.ref)(`${role.entity}Claim`)])))),
65
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`ownerClaimsList${idx}.addAll`), (0, graphql_mapping_template_1.ref)(`${role.entity}Claim`))),
66
- (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(`util.isNull($ctx.args.${role.entity})`)), (0, graphql_mapping_template_1.compoundExpression)([
67
- (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.ref)(`util.isString($ctx.args.${role.entity})`), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${role.entity}Condition`), (0, graphql_mapping_template_1.parens)((0, graphql_mapping_template_1.or)([
68
- (0, graphql_mapping_template_1.parens)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)(`${role.entity}Claim`), (0, graphql_mapping_template_1.ref)(`ctx.args.${role.entity}`))),
69
- (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`ownerClaimsList${idx}.contains`), (0, graphql_mapping_template_1.ref)(`ctx.args.${role.entity}`)),
70
- ]))), (0, graphql_mapping_template_1.compoundExpression)([
71
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${role.entity}Condition`), (0, graphql_mapping_template_1.parens)((0, graphql_mapping_template_1.or)([
72
- (0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)(`${role.entity}Claim`), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.defaultIfNull'), (0, graphql_mapping_template_1.raw)(`$ctx.args.${role.entity}.get("eq")`), (0, graphql_mapping_template_1.nul)())),
73
- (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`ownerClaimsList${idx}.contains`), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.defaultIfNull'), (0, graphql_mapping_template_1.raw)(`$ctx.args.${role.entity}.get("eq")`), (0, graphql_mapping_template_1.nul)())),
74
- ]))),
75
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(`${role.entity}Condition`)), (0, graphql_mapping_template_1.compoundExpression)([
76
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('entityValues'), (0, graphql_mapping_template_1.raw)('0')),
77
- (0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)(`argEntity`), (0, graphql_mapping_template_1.ref)(`ctx.args.${role.entity}.get("eq")`), [
78
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`ownerClaimsList${idx}.contains`), (0, graphql_mapping_template_1.ref)('argEntity')), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('entityValues'), (0, graphql_mapping_template_1.raw)('$entityValues + 1'))),
79
- ]),
80
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('entityValues'), (0, graphql_mapping_template_1.ref)(`ctx.args.${role.entity}.get("eq").size()`)), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${role.entity}Condition`), (0, graphql_mapping_template_1.bool)(true))),
81
- ])),
82
- ])),
83
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.ref)(`${role.entity}Condition`), (0, graphql_mapping_template_1.compoundExpression)([
84
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(true)),
85
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('ctx.stash.put'), (0, graphql_mapping_template_1.str)('authFilter'), (0, graphql_mapping_template_1.nul)())),
86
- ])),
87
- ]), hasMultiClaims
88
- ? (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('primaryFieldMap.put'), (0, graphql_mapping_template_1.str)(role.entity), (0, graphql_mapping_template_1.ref)(`ownerClaimsList${idx}`)))
89
- : (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('primaryFieldMap.put'), (0, graphql_mapping_template_1.str)(role.entity), (0, graphql_mapping_template_1.ref)(`${role.entity}Claim`)))),
90
- ])));
91
- });
92
- modelQueryExpression.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.and)([
93
- (0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG)),
94
- (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)('ctx.stash.authFilter')),
95
- (0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)('primaryFieldMap.isEmpty()')),
96
- ]), (0, graphql_mapping_template_1.compoundExpression)([
97
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('sortKeyFields'), (0, graphql_mapping_template_1.list)(sortKeyFields.map((sk) => (0, graphql_mapping_template_1.str)(sk)))),
98
- (0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('entry'), (0, graphql_mapping_template_1.ref)('primaryFieldMap.entrySet()'), [
99
- (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('sortKeyFields.contains'), (0, graphql_mapping_template_1.ref)('entry.key')), (0, graphql_mapping_template_1.compoundExpression)([
100
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('entryVal'), (0, graphql_mapping_template_1.ref)('entry.value')),
101
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('lastIdx'), (0, graphql_mapping_template_1.ref)('entryVal.size() - 1')),
102
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('lastItem'), (0, graphql_mapping_template_1.ref)('entryVal.get($lastIdx)')),
103
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('ctx.args.put'), (0, graphql_mapping_template_1.ref)('entry.key'), (0, graphql_mapping_template_1.obj)({ eq: (0, graphql_mapping_template_1.ref)('lastItem') }))),
104
- ]), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('ctx.args.put'), (0, graphql_mapping_template_1.ref)('entry.key'), (0, graphql_mapping_template_1.ref)('entry.value')))),
105
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(true)),
106
- ]),
107
- ])));
108
- }
109
- else {
110
- primaryRoles.forEach((role, idx) => {
111
- const claims = role.claim.split(utils_1.IDENTITY_CLAIM_DELIMITER);
112
- const hasMultiClaims = claims.length > 1;
113
- modelQueryExpression.push((0, helpers_1.generateOwnerClaimExpression)(role.claim, `${role.entity}Claim`), (0, graphql_mapping_template_1.iff)((0, helpers_1.generateInvalidClaimsCondition)(role.claim, `${role.entity}Claim`), (0, graphql_mapping_template_1.compoundExpression)([
114
- (0, helpers_1.generateOwnerMultiClaimExpression)(role.claim, `${role.entity}Claim`),
115
- (0, helpers_1.generateOwnerClaimListExpression)(role.claim, `ownerClaimsList${idx}`),
116
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isString'), (0, graphql_mapping_template_1.ref)(`${role.entity}Claim`)), (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isList'), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.parseJson'), (0, graphql_mapping_template_1.ref)(`${role.entity}Claim`))), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${role.entity}Claim`), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.parseJson'), (0, graphql_mapping_template_1.ref)(`${role.entity}Claim`))), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${role.entity}Claim`), (0, graphql_mapping_template_1.list)([(0, graphql_mapping_template_1.ref)(`${role.entity}Claim`)])))),
117
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`ownerClaimsList${idx}.addAll`), (0, graphql_mapping_template_1.ref)(`${role.entity}Claim`))),
118
- (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(`util.isNull($ctx.args.${role.entity})`)), (0, graphql_mapping_template_1.compoundExpression)([
119
- (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.ref)(`util.isString($ctx.args.${role.entity})`), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${role.entity}Condition`), (0, graphql_mapping_template_1.parens)((0, graphql_mapping_template_1.or)([
120
- (0, graphql_mapping_template_1.parens)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)(`${role.entity}Claim`), (0, graphql_mapping_template_1.ref)(`ctx.args.${role.entity}`))),
121
- (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`ownerClaimsList${idx}.contains`), (0, graphql_mapping_template_1.ref)(`ctx.args.${role.entity}`)),
122
- ]))), (0, graphql_mapping_template_1.compoundExpression)([
123
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${role.entity}Condition`), (0, graphql_mapping_template_1.parens)((0, graphql_mapping_template_1.or)([
124
- (0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)(`${role.entity}Claim`), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.defaultIfNull'), (0, graphql_mapping_template_1.raw)(`$ctx.args.${role.entity}.get("eq")`), (0, graphql_mapping_template_1.nul)())),
125
- (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`ownerClaimsList${idx}.contains`), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.defaultIfNull'), (0, graphql_mapping_template_1.raw)(`$ctx.args.${role.entity}.get("eq")`), (0, graphql_mapping_template_1.nul)())),
126
- ]))),
127
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(`${role.entity}Condition`)), (0, graphql_mapping_template_1.compoundExpression)([
128
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('entityValues'), (0, graphql_mapping_template_1.raw)('0')),
129
- (0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)(`argEntity`), (0, graphql_mapping_template_1.ref)(`ctx.args.${role.entity}.get("eq")`), [
130
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`ownerClaimsList${idx}.contains`), (0, graphql_mapping_template_1.ref)('argEntity')), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('entityValues'), (0, graphql_mapping_template_1.raw)('$entityValues + 1'))),
131
- ]),
132
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('entityValues'), (0, graphql_mapping_template_1.ref)(`ctx.args.${role.entity}.get("eq").size()`)), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`${role.entity}Condition`), (0, graphql_mapping_template_1.bool)(true))),
133
- ])),
134
- ])),
135
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.ref)(`${role.entity}Condition`), (0, graphql_mapping_template_1.compoundExpression)([
136
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(true)),
137
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('ctx.stash.put'), (0, graphql_mapping_template_1.str)('authFilter'), (0, graphql_mapping_template_1.nul)())),
138
- ])),
139
- ]), hasMultiClaims
140
- ? (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('primaryFieldMap.put'), (0, graphql_mapping_template_1.str)(role.entity), (0, graphql_mapping_template_1.ref)(`ownerClaimsList${idx}`)))
141
- : (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('primaryFieldMap.put'), (0, graphql_mapping_template_1.str)(role.entity), (0, graphql_mapping_template_1.ref)(`${role.entity}Claim`)))),
142
- ])));
143
- });
144
- modelQueryExpression.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.and)([(0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG)), (0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)('primaryFieldMap.isEmpty()'))]), (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)(`ctx.args.${primaryKey}`)), (0, graphql_mapping_template_1.compoundExpression)([
145
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('authFilter'), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.defaultIfNull'), (0, graphql_mapping_template_1.ref)('ctx.stash.get("authFilter").get("or")'), (0, graphql_mapping_template_1.list)([]))),
146
- (0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('entry'), (0, graphql_mapping_template_1.ref)('primaryFieldMap.entrySet()'), [
147
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('filterMap'), (0, graphql_mapping_template_1.obj)({})),
148
- (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isList'), (0, graphql_mapping_template_1.ref)('entry.value')), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('filterMap.put'), (0, graphql_mapping_template_1.ref)('entry.key'), (0, graphql_mapping_template_1.raw)('{ "in": $entry.value }'))), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('filterMap.put'), (0, graphql_mapping_template_1.ref)('entry.key'), (0, graphql_mapping_template_1.raw)('{ "eq": $entry.value }')))),
149
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('authFilter.add'), (0, graphql_mapping_template_1.ref)('filterMap'))),
150
- ]),
151
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('ctx.stash.put'), (0, graphql_mapping_template_1.str)('authFilter'), (0, graphql_mapping_template_1.raw)('{ "or": $authFilter }'))),
152
- ]), (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)('ctx.stash.authFilter')), (0, graphql_mapping_template_1.compoundExpression)([
153
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('modelQueryExpression'), (0, graphql_mapping_template_1.ref)('ctx.stash.modelQueryExpression')),
154
- (0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('entry'), (0, graphql_mapping_template_1.ref)('primaryFieldMap.entrySet()'), [
155
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('modelQueryExpression.expression'), (0, graphql_mapping_template_1.str)('${modelQueryExpression.expression} AND #${entry.key} = :${entry.key}')),
156
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.ref)('modelQueryExpression.expressionNames.put("#${entry.key}", $entry.key)')),
157
- (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isList'), (0, graphql_mapping_template_1.ref)('entry.value')), (0, graphql_mapping_template_1.compoundExpression)([
158
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('lastClaim'), (0, graphql_mapping_template_1.raw)('$entry.value.size() - 1')),
159
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.ref)('modelQueryExpression.expressionValues.put(":${entry.key}", $util.dynamodb.toDynamoDB($entry.value[$lastClaim]))')),
160
- ]), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.ref)('modelQueryExpression.expressionValues.put(":${entry.key}", $util.dynamodb.toDynamoDB($entry.value))'))),
161
- ]),
162
- (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('ctx.stash.put'), (0, graphql_mapping_template_1.str)('modelQueryExpression'), (0, graphql_mapping_template_1.ref)('modelQueryExpression'))),
163
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(true)),
164
- ])))));
165
- }
166
- return modelQueryExpression;
167
- }
168
- return [];
169
- };
170
- const generateAuthFilter = (roles, fields) => {
171
- const authCollectionExp = new Array();
172
- const groupMap = new Map();
173
- const groupContainsExpression = new Array();
174
- if (!(roles.length > 0))
175
- return [];
176
- roles.forEach((role, idx) => {
177
- const entityIsList = (0, utils_1.fieldIsList)(fields, role.entity);
178
- if (role.strategy === 'owner') {
179
- const claims = role.claim.split(utils_1.IDENTITY_CLAIM_DELIMITER);
180
- const hasMultiClaims = claims.length > 1;
181
- const ownerCondition = entityIsList ? 'contains' : 'eq';
182
- if (hasMultiClaims) {
183
- authCollectionExp.push(...[
184
- (0, helpers_1.generateOwnerClaimExpression)(role.claim, `ownerClaim${idx}`),
185
- (0, graphql_mapping_template_1.iff)((0, helpers_1.generateInvalidClaimsCondition)(role.claim, `ownerClaim${idx}`), (0, graphql_mapping_template_1.compoundExpression)([
186
- (0, helpers_1.generateOwnerMultiClaimExpression)(role.claim, `ownerClaim${idx}`),
187
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)(`ownerClaim${idx}`))), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('authFilter.add'), (0, graphql_mapping_template_1.raw)(`{"${role.entity}": { "${ownerCondition}": $ownerClaim${idx} }}`)))),
188
- ])),
189
- ]);
190
- claims.forEach((claim, secIdx) => {
191
- authCollectionExp.push(...[
192
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`role${idx}_${secIdx}`), (0, helpers_1.getOwnerClaim)(claim)),
193
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)(`role${idx}_${secIdx}`))), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('authFilter.add'), (0, graphql_mapping_template_1.raw)(`{"${role.entity}": { "${ownerCondition}": $role${idx}_${secIdx} }}`)))),
194
- ]);
195
- });
196
- }
197
- else {
198
- authCollectionExp.push(...[
199
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`role${idx}`), (0, helpers_1.getOwnerClaim)(role.claim)),
200
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)(`role${idx}`))), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('authFilter.add'), (0, graphql_mapping_template_1.raw)(`{"${role.entity}": { "${ownerCondition}": $role${idx} }}`)))),
201
- ]);
202
- }
203
- }
204
- else if (role.strategy === 'groups') {
205
- if (entityIsList) {
206
- if (groupMap.has(role.claim)) {
207
- groupMap.get(role.claim).push(role.entity);
208
- }
209
- else {
210
- groupMap.set(role.claim, [role.entity]);
211
- }
212
- }
213
- else {
214
- authCollectionExp.push(...[
215
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`role${idx}`), (0, helpers_1.getIdentityClaimExp)((0, graphql_mapping_template_1.str)(role.claim), (0, graphql_mapping_template_1.list)([]))),
216
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isString'), (0, graphql_mapping_template_1.ref)(`role${idx}`)), (0, graphql_mapping_template_1.ifElse)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isList'), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.parseJson'), (0, graphql_mapping_template_1.ref)(`role${idx}`))), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`role${idx}`), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.parseJson'), (0, graphql_mapping_template_1.ref)(`role${idx}`))), (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(`role${idx}`), (0, graphql_mapping_template_1.list)([(0, graphql_mapping_template_1.ref)(`role${idx}`)])))),
217
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)(`role${idx}.isEmpty`))), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('authFilter.add'), (0, graphql_mapping_template_1.raw)(`{ "${role.entity}": { "in": $role${idx} } }`)))),
218
- ]);
219
- }
220
- }
221
- });
222
- groupMap.forEach((fieldList, groupClaim) => {
223
- groupContainsExpression.push((0, graphql_mapping_template_1.forEach)((0, graphql_mapping_template_1.ref)('group'), (0, graphql_mapping_template_1.ref)(`util.defaultIfNull($ctx.identity.claims.get("${groupClaim}"), [])`), fieldList.map((field) => (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('group.isEmpty'))), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('authFilter.add'), (0, graphql_mapping_template_1.raw)(`{"${field}": { "contains": $group }}`)))))));
224
- });
225
- return [
226
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG)), (0, graphql_mapping_template_1.compoundExpression)([
227
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('authFilter'), (0, graphql_mapping_template_1.list)([])),
228
- ...authCollectionExp,
229
- ...groupContainsExpression,
230
- (0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('authFilter.isEmpty'))), (0, graphql_mapping_template_1.qref)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('ctx.stash.put'), (0, graphql_mapping_template_1.str)('authFilter'), (0, graphql_mapping_template_1.raw)('{ "or": $authFilter }')))),
231
- ])),
232
- ];
233
- };
234
- const generateAuthExpressionForQueries = (providers, roles, fields, keySchema, isIndexQuery = false, primaryKey = undefined) => {
235
- const { cognitoStaticRoles, cognitoDynamicRoles, oidcStaticRoles, oidcDynamicRoles, apiKeyRoles, iamRoles, lambdaRoles } = (0, utils_1.splitRoles)(roles);
236
- const primaryFields = keySchema.map((att) => att.attributeName);
237
- const sortKeyFields = keySchema.filter((att) => att.keyType === 'RANGE').map((att) => att.attributeName);
238
- const getNonPrimaryFieldRoles = (rolesToFilter) => rolesToFilter.filter((role) => !primaryFields.includes(role.entity));
239
- const totalAuthExpressions = [
240
- helpers_1.setHasAuthExpression,
241
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(false)),
242
- (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)('primaryFieldMap'), (0, graphql_mapping_template_1.obj)({})),
243
- ];
244
- if (providers.hasApiKey) {
245
- totalAuthExpressions.push((0, helpers_1.apiKeyExpression)(apiKeyRoles));
246
- }
247
- if (providers.hasLambda) {
248
- totalAuthExpressions.push((0, helpers_1.lambdaExpression)(lambdaRoles));
249
- }
250
- if (providers.hasIAM) {
251
- totalAuthExpressions.push((0, helpers_1.iamExpression)(iamRoles, providers.hasAdminRolesEnabled, providers.adminRoles, providers.identityPoolId));
252
- }
253
- if (providers.hasUserPools) {
254
- totalAuthExpressions.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('util.authType()'), (0, graphql_mapping_template_1.str)(utils_1.COGNITO_AUTH_TYPE)), (0, graphql_mapping_template_1.compoundExpression)([
255
- ...generateStaticRoleExpression(cognitoStaticRoles),
256
- ...generateAuthFilter(getNonPrimaryFieldRoles(cognitoDynamicRoles), fields),
257
- ...generateAuthOnModelQueryExpression(cognitoDynamicRoles, primaryFields, isIndexQuery, primaryKey, sortKeyFields),
258
- ])));
259
- }
260
- if (providers.hasOIDC) {
261
- totalAuthExpressions.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('util.authType()'), (0, graphql_mapping_template_1.str)(utils_1.OIDC_AUTH_TYPE)), (0, graphql_mapping_template_1.compoundExpression)([
262
- ...generateStaticRoleExpression(oidcStaticRoles),
263
- ...generateAuthFilter(getNonPrimaryFieldRoles(oidcDynamicRoles), fields),
264
- ...generateAuthOnModelQueryExpression(oidcDynamicRoles, primaryFields, isIndexQuery, primaryKey, sortKeyFields),
265
- ])));
266
- }
267
- totalAuthExpressions.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.and)([(0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG)), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)('ctx.stash.authFilter'))]), (0, graphql_mapping_template_1.ref)('util.unauthorized()')));
268
- return (0, graphql_mapping_template_1.printBlock)('Authorization Steps')((0, graphql_mapping_template_1.compoundExpression)([...totalAuthExpressions, helpers_1.emptyPayload]));
269
- };
270
- exports.generateAuthExpressionForQueries = generateAuthExpressionForQueries;
271
- const generateAuthExpressionForRelationQuery = (providers, roles, fields, primaryFieldMap) => {
272
- const { cognitoStaticRoles, cognitoDynamicRoles, oidcStaticRoles, oidcDynamicRoles, apiKeyRoles, iamRoles, lambdaRoles } = (0, utils_1.splitRoles)(roles);
273
- const getNonPrimaryFieldRoles = (rolesToFilter) => rolesToFilter.filter((role) => !primaryFieldMap.has(role.entity));
274
- const totalAuthExpressions = [helpers_1.setHasAuthExpression, (0, graphql_mapping_template_1.set)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG), (0, graphql_mapping_template_1.bool)(false))];
275
- if (providers.hasApiKey) {
276
- totalAuthExpressions.push((0, helpers_1.apiKeyExpression)(apiKeyRoles));
277
- }
278
- if (providers.hasLambda) {
279
- totalAuthExpressions.push((0, helpers_1.lambdaExpression)(lambdaRoles));
280
- }
281
- if (providers.hasIAM) {
282
- totalAuthExpressions.push((0, helpers_1.iamExpression)(iamRoles, providers.hasAdminRolesEnabled, providers.adminRoles, providers.identityPoolId));
283
- }
284
- if (providers.hasUserPools) {
285
- totalAuthExpressions.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('util.authType()'), (0, graphql_mapping_template_1.str)(utils_1.COGNITO_AUTH_TYPE)), (0, graphql_mapping_template_1.compoundExpression)([
286
- ...generateStaticRoleExpression(cognitoStaticRoles),
287
- ...generateAuthFilter(getNonPrimaryFieldRoles(cognitoDynamicRoles), fields),
288
- ...generateAuthOnRelationalModelQueryExpression(cognitoDynamicRoles, primaryFieldMap),
289
- ])));
290
- }
291
- if (providers.hasOIDC) {
292
- totalAuthExpressions.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('util.authType()'), (0, graphql_mapping_template_1.str)(utils_1.OIDC_AUTH_TYPE)), (0, graphql_mapping_template_1.compoundExpression)([
293
- ...generateStaticRoleExpression(oidcStaticRoles),
294
- ...generateAuthFilter(getNonPrimaryFieldRoles(oidcDynamicRoles), fields),
295
- ...generateAuthOnRelationalModelQueryExpression(oidcDynamicRoles, primaryFieldMap),
296
- ])));
297
- }
298
- totalAuthExpressions.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.and)([(0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)(utils_1.IS_AUTHORIZED_FLAG)), (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)('ctx.stash.authFilter'))]), (0, graphql_mapping_template_1.ref)('util.unauthorized()')));
299
- return (0, graphql_mapping_template_1.printBlock)('Authorization Steps')((0, graphql_mapping_template_1.compoundExpression)([...totalAuthExpressions, helpers_1.emptyPayload]));
300
- };
301
- exports.generateAuthExpressionForRelationQuery = generateAuthExpressionForRelationQuery;
302
- //# sourceMappingURL=query.js.map