"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateResolverKey = exports.generateAuthExpressionForSandboxMode = void 0;
const graphql_mapping_template_1 = require("graphql-mapping-template");
const API_KEY = 'API Key Authorization';
const IAM_AUTH_TYPE = 'IAM Authorization';
const generateAuthExpressionForSandboxMode = (isSandboxModeEnabled, genericIamAccessEnabled) => {
    const expressions = [];
    if (isSandboxModeEnabled) {
        expressions.push((0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.authType')), (0, graphql_mapping_template_1.str)(API_KEY)), (0, graphql_mapping_template_1.ret)((0, graphql_mapping_template_1.toJson)((0, graphql_mapping_template_1.obj)({})))));
    }
    if (genericIamAccessEnabled) {
        const isNonCognitoIAMPrincipal = (0, graphql_mapping_template_1.and)([
            (0, graphql_mapping_template_1.equals)((0, graphql_mapping_template_1.ref)('util.authType()'), (0, graphql_mapping_template_1.str)(IAM_AUTH_TYPE)),
            (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)('ctx.identity.cognitoIdentityPoolId')),
            (0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.isNull'), (0, graphql_mapping_template_1.ref)('ctx.identity.cognitoIdentityId')),
        ]);
        expressions.push((0, graphql_mapping_template_1.iff)(isNonCognitoIAMPrincipal, (0, graphql_mapping_template_1.ret)((0, graphql_mapping_template_1.toJson)((0, graphql_mapping_template_1.obj)({})))));
    }
    expressions.push((0, graphql_mapping_template_1.methodCall)((0, graphql_mapping_template_1.ref)('util.unauthorized')));
    return (0, graphql_mapping_template_1.printBlock)(`Sandbox Mode ${isSandboxModeEnabled ? 'Enabled' : 'Disabled'}`)((0, graphql_mapping_template_1.compoundExpression)([(0, graphql_mapping_template_1.iff)((0, graphql_mapping_template_1.not)((0, graphql_mapping_template_1.ref)('ctx.stash.get("hasAuth")')), (0, graphql_mapping_template_1.compoundExpression)(expressions)), (0, graphql_mapping_template_1.toJson)((0, graphql_mapping_template_1.obj)({}))]));
};
exports.generateAuthExpressionForSandboxMode = generateAuthExpressionForSandboxMode;
const generateResolverKey = (typeName, fieldName) => {
    return `${typeName}.${fieldName}`;
};
exports.generateResolverKey = generateResolverKey;
//# sourceMappingURL=common.js.map