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Q,GACJ,IAAK,IAML,QACI,OAAO,eAAA,cAAc,OALzB,IAAK,IACD,OAAO,eAAA,cAAc,OACzB,IAAK,IACD,OAAO,eAAA,cAAc,OAIjC,CAEQ,qBAAA,CAAsB,GAC1B,OAAQ,GACJ,IAAK,MAML,QACI,OAAO,eAAA,eAAe,IAL1B,IAAK,UACD,OAAO,eAAA,eAAe,QAC1B,IAAK,YACD,OAAO,eAAA,eAAe,UAIlC,EAzOJ,QAAA","file":"/npm/aws-cdk-appsync-transformer@1.63.0-rc.3/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/aws-cdk-appsync-transformer@1.63.0-rc.3/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { Construct, NestedStack, CfnOutput } from '@aws-cdk/core';\nimport { GraphqlApi, AuthorizationType, FieldLogLevel, MappingTemplate, CfnDataSource, Resolver, AuthorizationConfig, Schema } from '@aws-cdk/aws-appsync';\nimport { Table, AttributeType, ProjectionType, BillingMode } from '@aws-cdk/aws-dynamodb';\nimport { Effect, PolicyStatement } from '@aws-cdk/aws-iam'\n\nimport { SchemaTransformer } from './transformer/schema-transformer';\n\n/**\n * Properties for AppSyncTransformer Construct\n * @param schemaPath Relative path where schema.graphql exists.\n * @param authorizationConfig {@link AuthorizationConfig} type defining authorization for AppSync GraphqlApi. Defaults to API_KEY\n * @param apiName Optional string value representing the api name\n * @param syncEnabled Optional boolean to enable DataStore Sync Tables\n * @param fieldLogLevel {@link FieldLogLevel} type for AppSync GraphqlApi log level\n */\nexport interface AppSyncTransformerProps {\n    /**\n     * Required. Relative path where schema.graphql exists\n     */\n    readonly schemaPath: string\n\n    /**\n     * Optional. {@link AuthorizationConfig} type defining authorization for AppSync GraphqlApi. Defaults to API_KEY\n     * @default API_KEY authorization config\n     */\n    readonly authorizationConfig?: AuthorizationConfig\n\n    /**\n     * Optional. String value representing the api name\n     * @default `${id}-api`\n     */\n    readonly apiName?: string\n\n    /**\n     * Optional. Boolean to enable DataStore Sync Tables\n     * @default false\n     */\n    readonly syncEnabled?: boolean\n\n    /**\n     * Optional. {@link FieldLogLevel} type for AppSync GraphqlApi log level\n     * @default FieldLogLevel.NONE\n     */\n    readonly fieldLogLevel?: FieldLogLevel\n}\n\nconst defaultAuthorizationConfig: AuthorizationConfig = {\n    defaultAuthorization: {\n        authorizationType: AuthorizationType.API_KEY,\n        apiKeyConfig: {\n            description: \"Auto generated API Key from construct\",\n            name: \"dev\"\n        }\n    }\n}\n\n/**\n * AppSyncTransformer Construct\n */\nexport class AppSyncTransformer extends Construct {\n    public readonly appsyncAPI: GraphqlApi\n    public readonly nestedAppsyncStack: NestedStack;\n    public readonly tableNameMap: any;\n    public readonly outputs: any;\n    public readonly resolvers: any;\n\n    private isSyncEnabled: boolean\n    private syncTable: Table | undefined\n\n    constructor(scope: Construct, id: string, props: AppSyncTransformerProps) {\n        super(scope, id);\n\n        this.isSyncEnabled = props.syncEnabled ? props.syncEnabled : false;\n\n        const transformerConfiguration = {\n            schemaPath: props.schemaPath,\n            syncEnabled: props.syncEnabled || false\n        }\n\n        const transformer = new SchemaTransformer(transformerConfiguration);\n        const outputs = transformer.transform();\n        const resolvers = transformer.getResolvers();\n\n        this.outputs = outputs;\n\n        this.outputs.FUNCTION_RESOLVERS.forEach((resolver: any) => {\n            switch (resolver.typeName) {\n                case 'Query':\n                    delete resolvers[resolver.fieldName]\n                    break;\n                case 'Mutation':\n                    delete resolvers[resolver.fieldName]\n                    break;\n                case 'Subscription':\n                    delete resolvers[resolver.fieldName]\n                    break;\n            }\n        })\n\n        this.resolvers = resolvers;\n\n        this.nestedAppsyncStack = new NestedStack(this, `appsync-nested-stack`);\n\n        // AppSync\n        this.appsyncAPI = new GraphqlApi(this.nestedAppsyncStack, `${id}-api`, {\n            name: props.apiName ? props.apiName : `${id}-api`,\n            authorizationConfig: props.authorizationConfig ? props.authorizationConfig : defaultAuthorizationConfig,\n            logConfig: {\n                fieldLogLevel: props.fieldLogLevel ? props.fieldLogLevel : FieldLogLevel.NONE,\n            },\n            schema: Schema.fromAsset('./appsync/schema.graphql')\n        })\n\n        let tableData = outputs.CDK_TABLES;\n\n        // Check to see if sync is enabled\n        if (tableData['DataStore']) {\n            this.isSyncEnabled = true\n            this.syncTable = this.createSyncTable(tableData['DataStore']);\n            delete tableData['DataStore'] // We don't want to create this again below so remove it from the tableData map\n        }\n\n        this.tableNameMap = this.createTablesAndResolvers(tableData, resolvers);\n        this.createNoneDataSourceAndResolvers(outputs.NONE, resolvers);\n\n        // Outputs so we can generate exports\n        new CfnOutput(scope, 'appsyncGraphQLEndpointOutput', {\n            value: this.appsyncAPI.graphqlUrl,\n            description: 'Output for aws_appsync_graphqlEndpoint'\n        })\n    }\n\n    private createNoneDataSourceAndResolvers(none: any, resolvers: any) {\n        const noneDataSource = this.appsyncAPI.addNoneDataSource('NONE');\n\n        Object.keys(none).forEach((resolverKey: any) => {\n            let resolver = resolvers[resolverKey];\n\n            new Resolver(this.nestedAppsyncStack, `${resolver.typeName}-${resolver.fieldName}-resolver`, {\n                api: this.appsyncAPI,\n                typeName: resolver.typeName,\n                fieldName: resolver.fieldName,\n                dataSource: noneDataSource,\n                requestMappingTemplate: MappingTemplate.fromFile(resolver.requestMappingTemplate),\n                responseMappingTemplate: MappingTemplate.fromFile(resolver.responseMappingTemplate),\n            })\n        })\n    }\n\n    private createTablesAndResolvers(tableData: any, resolvers: any) {\n        const tableNameMap: any = {};\n\n        Object.keys(tableData).forEach((tableKey: any) => {\n            const table = this.createTable(tableData[tableKey]);\n            const dataSource = this.appsyncAPI.addDynamoDbDataSource(tableKey, table);\n\n            // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-datasource-deltasyncconfig.html\n\n            if (this.isSyncEnabled && this.syncTable) {\n                //@ts-ignore - ds is the base CfnDataSource and the db config needs to be versioned - see CfnDataSource\n                dataSource.ds.dynamoDbConfig.versioned = true\n\n                //@ts-ignore - ds is the base CfnDataSource - see CfnDataSource\n                dataSource.ds.dynamoDbConfig.deltaSyncConfig = {\n                    baseTableTtl: '43200', // Got this value from amplify - 30 days in minutes\n                    deltaSyncTableName: this.syncTable.tableName,\n                    deltaSyncTableTtl: '30' // Got this value from amplify - 30 minutes\n                }\n\n                // Need to add permission for our datasource service role to access the sync table\n                dataSource.grantPrincipal.addToPolicy(new PolicyStatement({\n                    effect: Effect.ALLOW,\n                    actions: [\n                        'dynamodb:*'\n                    ],\n                    resources: [\n                        this.syncTable.tableArn\n                    ]\n                }))\n            }\n\n            const dynamoDbConfig = dataSource.ds.dynamoDbConfig as CfnDataSource.DynamoDBConfigProperty;\n            tableNameMap[tableKey] = dynamoDbConfig.tableName;\n\n            // Loop the basic resolvers\n            tableData[tableKey].Resolvers.forEach((resolverKey: any) => {\n                let resolver = resolvers[resolverKey];\n                new Resolver(this.nestedAppsyncStack, `${resolver.typeName}-${resolver.fieldName}-resolver`, {\n                    api: this.appsyncAPI,\n                    typeName: resolver.typeName,\n                    fieldName: resolver.fieldName,\n                    dataSource: dataSource,\n                    requestMappingTemplate: MappingTemplate.fromFile(resolver.requestMappingTemplate),\n                    responseMappingTemplate: MappingTemplate.fromFile(resolver.responseMappingTemplate),\n                })\n            });\n\n            // Loop the gsi resolvers\n            tableData[tableKey].GSIResolvers.forEach((resolverKey: any) => {\n                let resolver = resolvers['gsi'][resolverKey];\n                new Resolver(this.nestedAppsyncStack, `${resolver.typeName}-${resolver.fieldName}-resolver`, {\n                    api: this.appsyncAPI,\n                    typeName: resolver.typeName,\n                    fieldName: resolver.fieldName,\n                    dataSource: dataSource,\n                    requestMappingTemplate: MappingTemplate.fromFile(resolver.requestMappingTemplate),\n                    responseMappingTemplate: MappingTemplate.fromFile(resolver.responseMappingTemplate),\n                })\n            });\n        });\n\n        return tableNameMap;\n    }\n\n    private createTable(tableData: any) {\n        let tableProps: any = {\n            billingMode: BillingMode.PAY_PER_REQUEST,\n            partitionKey: {\n                name: tableData.PartitionKey.name,\n                type: this.convertAttributeType(tableData.PartitionKey.type)\n            }\n        };\n\n        if (tableData.SortKey && tableData.SortKey.name) {\n            tableProps.sortKey = {\n                name: tableData.SortKey.name,\n                type: this.convertAttributeType(tableData.SortKey.type)\n            };\n        };\n\n        if (tableData.TTL && tableData.TTL.Enabled) {\n            tableProps.timeToLiveAttribute = tableData.TTL.AttributeName;\n        }\n\n        let table = new Table(this.nestedAppsyncStack, tableData.TableName, tableProps);\n\n        if (tableData.GlobalSecondaryIndexes && tableData.GlobalSecondaryIndexes.length > 0) {\n            tableData.GlobalSecondaryIndexes.forEach((gsi: any) => {\n                table.addGlobalSecondaryIndex({\n                    indexName: gsi.IndexName,\n                    partitionKey: {\n                        name: gsi.PartitionKey.name,\n                        type: this.convertAttributeType(gsi.PartitionKey.type)\n                    },\n                    projectionType: this.convertProjectionType(gsi.Projection.ProjectionType)\n                })\n            })\n        }\n\n        return table;\n    }\n\n    // https://docs.aws.amazon.com/appsync/latest/devguide/conflict-detection-and-sync.html\n    private createSyncTable(tableData: any) {\n        return new Table(this, 'appsync-api-sync-table', {\n            billingMode: BillingMode.PAY_PER_REQUEST,\n            partitionKey: {\n                name: tableData.PartitionKey.name,\n                type: this.convertAttributeType(tableData.PartitionKey.type)\n            },\n            sortKey: {\n                name: tableData.SortKey.name,\n                type: this.convertAttributeType(tableData.SortKey.type)\n            },\n            timeToLiveAttribute: tableData.TTL?.AttributeName || '_ttl'\n        })\n    }\n\n    private convertAttributeType(type: string) {\n        switch (type) {\n            case 'S':\n                return AttributeType.STRING\n            case 'N':\n                return AttributeType.NUMBER\n            case 'B':\n                return AttributeType.BINARY\n            default:\n                return AttributeType.STRING\n        }\n    }\n\n    private convertProjectionType(type: string) {\n        switch (type) {\n            case 'ALL':\n                return ProjectionType.ALL\n            case 'INCLUDE':\n                return ProjectionType.INCLUDE\n            case 'KEYS_ONLY':\n                return ProjectionType.KEYS_ONLY\n            default:\n                return ProjectionType.ALL\n        }\n    }\n}"]}