@aws-amplify/api-graphql 4.0.24-unstable.962179b.0 → 4.0.24
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/dist/cjs/internals/APIClient.js +0 -13
- package/dist/cjs/internals/APIClient.js.map +1 -1
- package/dist/cjs/internals/InternalGraphQLAPI.js +38 -36
- package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
- package/dist/cjs/utils/errors/index.js +1 -3
- package/dist/cjs/utils/errors/index.js.map +1 -1
- package/dist/cjs/utils/errors/repackageAuthError.js +6 -6
- package/dist/cjs/utils/errors/repackageAuthError.js.map +1 -1
- package/dist/cjs/utils/resolveOwnerFields.js +4 -1
- package/dist/cjs/utils/resolveOwnerFields.js.map +1 -1
- package/dist/esm/internals/APIClient.mjs +0 -13
- package/dist/esm/internals/APIClient.mjs.map +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.mjs +40 -40
- package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
- package/dist/esm/types/index.d.ts +1 -2
- package/dist/esm/utils/errors/index.d.ts +0 -1
- package/dist/esm/utils/errors/index.mjs +0 -1
- package/dist/esm/utils/errors/index.mjs.map +1 -1
- package/dist/esm/utils/errors/repackageAuthError.d.ts +7 -3
- package/dist/esm/utils/errors/repackageAuthError.mjs +5 -5
- package/dist/esm/utils/errors/repackageAuthError.mjs.map +1 -1
- package/dist/esm/utils/resolveConfig.mjs +0 -1
- package/dist/esm/utils/resolveConfig.mjs.map +1 -1
- package/dist/esm/utils/resolveOwnerFields.mjs +4 -1
- package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -1
- package/package.json +5 -5
- package/src/internals/APIClient.ts +0 -19
- package/src/internals/InternalGraphQLAPI.ts +56 -50
- package/src/types/index.ts +0 -2
- package/src/utils/errors/index.ts +0 -1
- package/src/utils/errors/repackageAuthError.ts +10 -8
- package/src/utils/resolveOwnerFields.ts +4 -1
- package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js +0 -15
- package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js.map +0 -1
- package/dist/cjs/utils/errors/constants.js +0 -47
- package/dist/cjs/utils/errors/constants.js.map +0 -1
- package/dist/cjs/utils/errors/createGraphQLResultWithError.js +0 -15
- package/dist/cjs/utils/errors/createGraphQLResultWithError.js.map +0 -1
- package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.d.ts +0 -2
- package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs +0 -12
- package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs.map +0 -1
- package/dist/esm/utils/errors/constants.d.ts +0 -7
- package/dist/esm/utils/errors/constants.mjs +0 -46
- package/dist/esm/utils/errors/constants.mjs.map +0 -1
- package/dist/esm/utils/errors/createGraphQLResultWithError.d.ts +0 -2
- package/dist/esm/utils/errors/createGraphQLResultWithError.mjs +0 -13
- package/dist/esm/utils/errors/createGraphQLResultWithError.mjs.map +0 -1
- package/src/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.ts +0 -15
- package/src/utils/errors/constants.ts +0 -56
- package/src/utils/errors/createGraphQLResultWithError.ts +0 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InternalGraphQLAPI.mjs","sources":["../../../src/internals/InternalGraphQLAPI.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { parse, print, } from 'graphql';\nimport { catchError } from 'rxjs';\nimport { AmplifyUrl, getAmplifyUserAgent, } from '@aws-amplify/core/internals/utils';\nimport { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';\nimport { cancel as cancelREST, post, updateRequestToBeCancellable, } from '@aws-amplify/api-rest/internals';\nimport { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';\nimport { resolveConfig, resolveLibraryOptions } from '../utils';\nimport { repackageUnauthorizedError } from '../utils/errors/repackageAuthError';\nimport { NO_API_KEY, NO_AUTH_TOKEN_HEADER, NO_ENDPOINT, NO_SIGNED_IN_USER, NO_VALID_AUTH_TOKEN, NO_VALID_CREDENTIALS, } from '../utils/errors/constants';\nimport { GraphQLApiError, createGraphQLResultWithError } from '../utils/errors';\nimport { isGraphQLResponseWithErrors } from './utils/runtimeTypeGuards/isGraphQLResponseWithErrors';\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\nconst isAmplifyInstance = (amplify) => {\n return typeof amplify !== 'function';\n};\n/**\n * Export Cloud Logic APIs\n */\nexport class InternalGraphQLAPIClass {\n constructor() {\n /**\n * @private\n */\n this.appSyncRealTime = new AWSAppSyncRealTimeProvider();\n this._api = {\n post,\n cancelREST,\n isCancelErrorREST,\n updateRequestToBeCancellable,\n };\n }\n getModuleName() {\n return 'InternalGraphQLAPI';\n }\n async _headerBasedAuth(amplify, authMode, additionalHeaders = {}) {\n const { apiKey } = resolveConfig(amplify);\n let headers = {};\n switch (authMode) {\n case 'apiKey':\n if (!apiKey) {\n throw new GraphQLApiError(NO_API_KEY);\n }\n headers = {\n 'X-Api-Key': apiKey,\n };\n break;\n case 'iam': {\n const session = await amplify.Auth.fetchAuthSession();\n if (session.credentials === undefined) {\n throw new GraphQLApiError(NO_VALID_CREDENTIALS);\n }\n break;\n }\n case 'oidc':\n case 'userPool': {\n let token;\n try {\n token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();\n }\n catch (e) {\n // fetchAuthSession failed\n throw new GraphQLApiError({\n ...NO_SIGNED_IN_USER,\n underlyingError: e,\n });\n }\n // `fetchAuthSession()` succeeded but didn't return `tokens`.\n // This may happen when unauthenticated access is enabled and there is\n // no user signed in.\n if (!token) {\n throw new GraphQLApiError(NO_VALID_AUTH_TOKEN);\n }\n headers = {\n Authorization: token,\n };\n break;\n }\n case 'lambda':\n if (typeof additionalHeaders === 'object' &&\n !additionalHeaders.Authorization) {\n throw new GraphQLApiError(NO_AUTH_TOKEN_HEADER);\n }\n headers = {\n Authorization: additionalHeaders.Authorization,\n };\n break;\n case 'none':\n break;\n default:\n break;\n }\n return headers;\n }\n /**\n * to get the operation type\n * @param operation\n */\n getGraphqlOperationType(operation) {\n const doc = parse(operation);\n const definitions = doc.definitions;\n const [{ operation: operationType }] = definitions;\n return operationType;\n }\n /**\n * Executes a GraphQL operation\n *\n * @param options - GraphQL Options\n * @param [additionalHeaders] - headers to merge in after any `libraryConfigHeaders` set in the config\n * @returns An Observable if the query is a subscription query, else a promise of the graphql result.\n */\n graphql(amplify, { query: paramQuery, variables = {}, authMode, authToken }, additionalHeaders, customUserAgentDetails) {\n const query = typeof paramQuery === 'string'\n ? parse(paramQuery)\n : parse(print(paramQuery));\n const [operationDef = {}] = query.definitions.filter(def => def.kind === 'OperationDefinition');\n const { operation: operationType } = operationDef;\n const headers = additionalHeaders || {};\n switch (operationType) {\n case 'query':\n case 'mutation': {\n const abortController = new AbortController();\n let responsePromise;\n if (isAmplifyInstance(amplify)) {\n responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);\n }\n else {\n // NOTE: this wrapper function must be await-able so the Amplify server context manager can\n // destroy the context only after it completes\n const wrapper = async (amplifyInstance) => {\n const result = await this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);\n return result;\n };\n responsePromise = amplify(wrapper);\n }\n this._api.updateRequestToBeCancellable(responsePromise, abortController);\n return responsePromise;\n }\n case 'subscription':\n return this._graphqlSubscribe(amplify, { query, variables, authMode }, headers, customUserAgentDetails, authToken);\n default:\n throw new Error(`invalid operation type: ${operationType}`);\n }\n }\n async _graphql(amplify, { query, variables, authMode: explicitAuthMode }, additionalHeaders = {}, abortController, customUserAgentDetails, authToken) {\n const { region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, defaultAuthMode, } = resolveConfig(amplify);\n const authMode = explicitAuthMode || defaultAuthMode || 'iam';\n /**\n * Retrieve library options from Amplify configuration.\n * `customHeaders` here are from the Amplify configuration options,\n * and are for non-AppSync endpoints only. These are *not* the same as\n * `additionalHeaders`, which are custom headers that are either 1)\n * included when configuring the API client or 2) passed along with\n * individual requests.\n */\n const { headers: customHeaders, withCredentials } = resolveLibraryOptions(amplify);\n /**\n * Client or request-specific custom headers that may or may not be\n * returned by a function:\n */\n let additionalCustomHeaders;\n if (typeof additionalHeaders === 'function') {\n const requestOptions = {\n method: 'POST',\n url: new AmplifyUrl(customEndpoint || appSyncGraphqlEndpoint || '').toString(),\n queryString: print(query),\n };\n additionalCustomHeaders = await additionalHeaders(requestOptions);\n }\n else {\n additionalCustomHeaders = additionalHeaders;\n }\n // if an authorization header is set, have the explicit authToken take precedence\n if (authToken) {\n additionalCustomHeaders = {\n ...additionalCustomHeaders,\n Authorization: authToken,\n };\n }\n // TODO: Figure what we need to do to remove `!`'s.\n const headers = {\n ...(!customEndpoint &&\n (await this._headerBasedAuth(amplify, authMode, additionalCustomHeaders))),\n /**\n * Custom endpoint headers.\n * If there is both a custom endpoint and custom region present, we get the headers.\n * If there is a custom endpoint but no region, we return an empty object.\n * If neither are present, we return an empty object.\n */\n ...((customEndpoint &&\n (customEndpointRegion\n ? await this._headerBasedAuth(amplify, authMode, additionalCustomHeaders)\n : {})) ||\n {}),\n // Custom headers included in Amplify configuration options:\n ...(customHeaders &&\n (await customHeaders({\n query: print(query),\n variables,\n }))),\n // Custom headers from individual requests or API client configuration:\n ...additionalCustomHeaders,\n // User agent headers:\n ...(!customEndpoint && {\n [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),\n }),\n };\n const body = {\n query: print(query),\n variables: variables || null,\n };\n let signingServiceInfo;\n /**\n * We do not send the signing service info to the REST API under the\n * following conditions (i.e. it will not sign the request):\n * - there is a custom endpoint but no region\n * - the auth mode is `none`, or `apiKey`\n * - the auth mode is a type other than the types listed below\n */\n if ((customEndpoint && !customEndpointRegion) ||\n (authMode !== 'oidc' &&\n authMode !== 'userPool' &&\n authMode !== 'iam' &&\n authMode !== 'lambda')) {\n signingServiceInfo = undefined;\n }\n else {\n signingServiceInfo = {\n service: !customEndpointRegion ? 'appsync' : 'execute-api',\n region: !customEndpointRegion ? region : customEndpointRegion,\n };\n }\n const endpoint = customEndpoint || appSyncGraphqlEndpoint;\n if (!endpoint) {\n throw createGraphQLResultWithError(new GraphQLApiError(NO_ENDPOINT));\n }\n let response;\n try {\n // See the inline doc of the REST `post()` API for possible errors to be thrown.\n // As these errors are catastrophic they should be caught and handled by GraphQL\n // API consumers.\n const { body: responseBody } = await this._api.post(amplify, {\n url: new AmplifyUrl(endpoint),\n options: {\n headers,\n body,\n signingServiceInfo,\n withCredentials,\n },\n abortController,\n });\n response = await responseBody.json();\n }\n catch (error) {\n if (this.isCancelError(error)) {\n throw error;\n }\n response = createGraphQLResultWithError(error);\n }\n if (isGraphQLResponseWithErrors(response)) {\n throw repackageUnauthorizedError(response);\n }\n return response;\n }\n /**\n * Checks to see if an error thrown is from an api request cancellation\n * @param {any} error - Any error\n * @return {boolean} - A boolean indicating if the error was from an api request cancellation\n */\n isCancelError(error) {\n return this._api.isCancelErrorREST(error);\n }\n /**\n * Cancels an inflight request. Only applicable for graphql queries and mutations\n * @param {any} request - request to cancel\n * @returns - A boolean indicating if the request was cancelled\n */\n cancel(request, message) {\n return this._api.cancelREST(request, message);\n }\n _graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails, authToken) {\n const config = resolveConfig(amplify);\n /**\n * Retrieve library options from Amplify configuration.\n * `libraryConfigHeaders` are from the Amplify configuration options,\n * and will not be overwritten by other custom headers. These are *not*\n * the same as `additionalHeaders`, which are custom headers that are\n * either 1)included when configuring the API client or 2) passed along\n * with individual requests.\n */\n const { headers: libraryConfigHeaders } = resolveLibraryOptions(amplify);\n return this.appSyncRealTime\n .subscribe({\n query: print(query),\n variables,\n appSyncGraphqlEndpoint: config?.endpoint,\n region: config?.region,\n authenticationType: authMode || config?.defaultAuthMode,\n apiKey: config?.apiKey,\n additionalHeaders,\n authToken,\n libraryConfigHeaders,\n }, customUserAgentDetails)\n .pipe(catchError(e => {\n if (e.errors) {\n throw repackageUnauthorizedError(e);\n }\n throw e;\n }));\n }\n}\nexport const InternalGraphQLAPI = new InternalGraphQLAPIClass();\n"],"names":["cancelREST","isCancelErrorREST"],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AAYA,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC7C,MAAM,iBAAiB,GAAG,CAAC,OAAO,KAAK;AACvC,IAAI,OAAO,OAAO,OAAO,KAAK,UAAU,CAAC;AACzC,CAAC,CAAC;AACF;AACA;AACA;AACO,MAAM,uBAAuB,CAAC;AACrC,IAAI,WAAW,GAAG;AAClB;AACA;AACA;AACA,QAAQ,IAAI,CAAC,eAAe,GAAG,IAAI,0BAA0B,EAAE,CAAC;AAChE,QAAQ,IAAI,CAAC,IAAI,GAAG;AACpB,YAAY,IAAI;AAChB,wBAAYA,MAAU;AACtB,+BAAYC,aAAiB;AAC7B,YAAY,4BAA4B;AACxC,SAAS,CAAC;AACV,KAAK;AACL,IAAI,aAAa,GAAG;AACpB,QAAQ,OAAO,oBAAoB,CAAC;AACpC,KAAK;AACL,IAAI,MAAM,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,iBAAiB,GAAG,EAAE,EAAE;AACtE,QAAQ,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AAClD,QAAQ,IAAI,OAAO,GAAG,EAAE,CAAC;AACzB,QAAQ,QAAQ,QAAQ;AACxB,YAAY,KAAK,QAAQ;AACzB,gBAAgB,IAAI,CAAC,MAAM,EAAE;AAC7B,oBAAoB,MAAM,IAAI,eAAe,CAAC,UAAU,CAAC,CAAC;AAC1D,iBAAiB;AACjB,gBAAgB,OAAO,GAAG;AAC1B,oBAAoB,WAAW,EAAE,MAAM;AACvC,iBAAiB,CAAC;AACl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EAAE,QAAQ,EAAE,EAAE,iBAAiB,GAAG,EAAE,EAAE,sBAAsB,EAAE,SAAS,EAAE;AAC1H,QAAQ,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;AACjF,QAAQ,OAAO,IAAI,CAAC,eAAe;AACnC,aAAa,SAAS,CAAC;AACvB,YAAY,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;AAC/B,YAAY,SAAS;AACrB,YAAY,sBAAsB,EAAE,MAAM,EAAE,QAAQ;AACpD,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,kBAAkB,EAAE,QAAQ,IAAI,MAAM,EAAE,eAAe;AACnE,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,iBAAiB;AAC7B,YAAY,SAAS;AACrB,YAAY,oBAAoB;AAChC,SAAS,EAAE,sBAAsB,CAAC;AAClC,aAAa,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI;AAClC,YAAY,IAAI,CAAC,CAAC,MAAM,EAAE;AAC1B,gBAAgB,MAAM,0BAA0B,CAAC,CAAC,CAAC,CAAC;AACpD,aAAa;AACb,YAAY,MAAM,CAAC,CAAC;AACpB,SAAS,CAAC,CAAC,CAAC;AACZ,KAAK;AACL,CAAC;AACW,MAAC,kBAAkB,GAAG,IAAI,uBAAuB;;;;"}
|
|
1
|
+
{"version":3,"file":"InternalGraphQLAPI.mjs","sources":["../../../src/internals/InternalGraphQLAPI.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { GraphQLError, parse, print, } from 'graphql';\nimport { catchError } from 'rxjs';\nimport { AmplifyUrl, getAmplifyUserAgent, } from '@aws-amplify/core/internals/utils';\nimport { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';\nimport { cancel as cancelREST, post, updateRequestToBeCancellable, } from '@aws-amplify/api-rest/internals';\nimport { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';\nimport { GraphQLAuthError, } from '../types';\nimport { resolveConfig, resolveLibraryOptions } from '../utils';\nimport { repackageUnauthError } from '../utils/errors/repackageAuthError';\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\nconst isAmplifyInstance = (amplify) => {\n return typeof amplify !== 'function';\n};\n/**\n * Export Cloud Logic APIs\n */\nexport class InternalGraphQLAPIClass {\n constructor() {\n /**\n * @private\n */\n this.appSyncRealTime = new AWSAppSyncRealTimeProvider();\n this._api = {\n post,\n cancelREST,\n isCancelErrorREST,\n updateRequestToBeCancellable,\n };\n }\n getModuleName() {\n return 'InternalGraphQLAPI';\n }\n async _headerBasedAuth(amplify, authMode, additionalHeaders = {}) {\n const { apiKey } = resolveConfig(amplify);\n let headers = {};\n switch (authMode) {\n case 'apiKey':\n if (!apiKey) {\n throw new Error(GraphQLAuthError.NO_API_KEY);\n }\n headers = {\n 'X-Api-Key': apiKey,\n };\n break;\n case 'iam': {\n const session = await amplify.Auth.fetchAuthSession();\n if (session.credentials === undefined) {\n throw new Error(GraphQLAuthError.NO_CREDENTIALS);\n }\n break;\n }\n case 'oidc':\n case 'userPool':\n try {\n const token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();\n if (!token) {\n throw new Error(GraphQLAuthError.NO_FEDERATED_JWT);\n }\n headers = {\n Authorization: token,\n };\n }\n catch (e) {\n throw new Error(GraphQLAuthError.NO_CURRENT_USER);\n }\n break;\n case 'lambda':\n if (typeof additionalHeaders === 'object' &&\n !additionalHeaders.Authorization) {\n throw new Error(GraphQLAuthError.NO_AUTH_TOKEN);\n }\n headers = {\n Authorization: additionalHeaders.Authorization,\n };\n break;\n case 'none':\n break;\n default:\n break;\n }\n return headers;\n }\n /**\n * to get the operation type\n * @param operation\n */\n getGraphqlOperationType(operation) {\n const doc = parse(operation);\n const definitions = doc.definitions;\n const [{ operation: operationType }] = definitions;\n return operationType;\n }\n /**\n * Executes a GraphQL operation\n *\n * @param options - GraphQL Options\n * @param [additionalHeaders] - headers to merge in after any `libraryConfigHeaders` set in the config\n * @returns An Observable if the query is a subscription query, else a promise of the graphql result.\n */\n graphql(amplify, { query: paramQuery, variables = {}, authMode, authToken }, additionalHeaders, customUserAgentDetails) {\n const query = typeof paramQuery === 'string'\n ? parse(paramQuery)\n : parse(print(paramQuery));\n const [operationDef = {}] = query.definitions.filter(def => def.kind === 'OperationDefinition');\n const { operation: operationType } = operationDef;\n const headers = additionalHeaders || {};\n switch (operationType) {\n case 'query':\n case 'mutation': {\n const abortController = new AbortController();\n let responsePromise;\n if (isAmplifyInstance(amplify)) {\n responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);\n }\n else {\n // NOTE: this wrapper function must be await-able so the Amplify server context manager can\n // destroy the context only after it completes\n const wrapper = async (amplifyInstance) => {\n const result = await this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);\n return result;\n };\n responsePromise = amplify(wrapper);\n }\n this._api.updateRequestToBeCancellable(responsePromise, abortController);\n return responsePromise;\n }\n case 'subscription':\n return this._graphqlSubscribe(amplify, { query, variables, authMode }, headers, customUserAgentDetails, authToken);\n default:\n throw new Error(`invalid operation type: ${operationType}`);\n }\n }\n async _graphql(amplify, { query, variables, authMode: explicitAuthMode }, additionalHeaders = {}, abortController, customUserAgentDetails, authToken) {\n const { region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, defaultAuthMode, } = resolveConfig(amplify);\n const authMode = explicitAuthMode || defaultAuthMode || 'iam';\n /**\n * Retrieve library options from Amplify configuration.\n * `customHeaders` here are from the Amplify configuration options,\n * and are for non-AppSync endpoints only. These are *not* the same as\n * `additionalHeaders`, which are custom headers that are either 1)\n * included when configuring the API client or 2) passed along with\n * individual requests.\n */\n const { headers: customHeaders, withCredentials } = resolveLibraryOptions(amplify);\n /**\n * Client or request-specific custom headers that may or may not be\n * returned by a function:\n */\n let additionalCustomHeaders;\n if (typeof additionalHeaders === 'function') {\n const requestOptions = {\n method: 'POST',\n url: new AmplifyUrl(customEndpoint || appSyncGraphqlEndpoint || '').toString(),\n queryString: print(query),\n };\n additionalCustomHeaders = await additionalHeaders(requestOptions);\n }\n else {\n additionalCustomHeaders = additionalHeaders;\n }\n // if an authorization header is set, have the explicit authToken take precedence\n if (authToken) {\n additionalCustomHeaders = {\n ...additionalCustomHeaders,\n Authorization: authToken,\n };\n }\n // TODO: Figure what we need to do to remove `!`'s.\n const headers = {\n ...(!customEndpoint &&\n (await this._headerBasedAuth(amplify, authMode, additionalCustomHeaders))),\n /**\n * Custom endpoint headers.\n * If there is both a custom endpoint and custom region present, we get the headers.\n * If there is a custom endpoint but no region, we return an empty object.\n * If neither are present, we return an empty object.\n */\n ...((customEndpoint &&\n (customEndpointRegion\n ? await this._headerBasedAuth(amplify, authMode, additionalCustomHeaders)\n : {})) ||\n {}),\n // Custom headers included in Amplify configuration options:\n ...(customHeaders &&\n (await customHeaders({\n query: print(query),\n variables,\n }))),\n // Custom headers from individual requests or API client configuration:\n ...additionalCustomHeaders,\n // User agent headers:\n ...(!customEndpoint && {\n [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),\n }),\n };\n const body = {\n query: print(query),\n variables: variables || null,\n };\n let signingServiceInfo;\n /**\n * We do not send the signing service info to the REST API under the\n * following conditions (i.e. it will not sign the request):\n * - there is a custom endpoint but no region\n * - the auth mode is `none`, or `apiKey`\n * - the auth mode is a type other than the types listed below\n */\n if ((customEndpoint && !customEndpointRegion) ||\n (authMode !== 'oidc' &&\n authMode !== 'userPool' &&\n authMode !== 'iam' &&\n authMode !== 'lambda')) {\n signingServiceInfo = undefined;\n }\n else {\n signingServiceInfo = {\n service: !customEndpointRegion ? 'appsync' : 'execute-api',\n region: !customEndpointRegion ? region : customEndpointRegion,\n };\n }\n const endpoint = customEndpoint || appSyncGraphqlEndpoint;\n if (!endpoint) {\n const error = new GraphQLError('No graphql endpoint provided.');\n // TODO(Eslint): refactor this to throw an Error instead of a plain object\n // eslint-disable-next-line no-throw-literal\n throw {\n data: {},\n errors: [error],\n };\n }\n let response;\n try {\n const { body: responseBody } = await this._api.post(amplify, {\n url: new AmplifyUrl(endpoint),\n options: {\n headers,\n body,\n signingServiceInfo,\n withCredentials,\n },\n abortController,\n });\n const result = await responseBody.json();\n response = result;\n }\n catch (err) {\n // If the exception is because user intentionally\n // cancelled the request, do not modify the exception\n // so that clients can identify the exception correctly.\n if (this.isCancelError(err)) {\n throw err;\n }\n response = {\n data: {},\n errors: [\n new GraphQLError(err.message, null, null, null, null, err),\n ],\n };\n }\n const { errors } = response;\n if (errors && errors.length) {\n throw repackageUnauthError(response);\n }\n return response;\n }\n /**\n * Checks to see if an error thrown is from an api request cancellation\n * @param {any} error - Any error\n * @return {boolean} - A boolean indicating if the error was from an api request cancellation\n */\n isCancelError(error) {\n return this._api.isCancelErrorREST(error);\n }\n /**\n * Cancels an inflight request. Only applicable for graphql queries and mutations\n * @param {any} request - request to cancel\n * @returns - A boolean indicating if the request was cancelled\n */\n cancel(request, message) {\n return this._api.cancelREST(request, message);\n }\n _graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails, authToken) {\n const config = resolveConfig(amplify);\n /**\n * Retrieve library options from Amplify configuration.\n * `libraryConfigHeaders` are from the Amplify configuration options,\n * and will not be overwritten by other custom headers. These are *not*\n * the same as `additionalHeaders`, which are custom headers that are\n * either 1)included when configuring the API client or 2) passed along\n * with individual requests.\n */\n const { headers: libraryConfigHeaders } = resolveLibraryOptions(amplify);\n return this.appSyncRealTime\n .subscribe({\n query: print(query),\n variables,\n appSyncGraphqlEndpoint: config?.endpoint,\n region: config?.region,\n authenticationType: authMode || config?.defaultAuthMode,\n apiKey: config?.apiKey,\n additionalHeaders,\n authToken,\n libraryConfigHeaders,\n }, customUserAgentDetails)\n .pipe(catchError(e => {\n if (e.errors) {\n throw repackageUnauthError(e);\n }\n throw e;\n }));\n }\n}\nexport const InternalGraphQLAPI = new InternalGraphQLAPIClass();\n"],"names":["cancelREST","isCancelErrorREST"],"mappings":";;;;;;;;;;;AAAA;AACA;AAUA,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC7C,MAAM,iBAAiB,GAAG,CAAC,OAAO,KAAK;AACvC,IAAI,OAAO,OAAO,OAAO,KAAK,UAAU,CAAC;AACzC,CAAC,CAAC;AACF;AACA;AACA;AACO,MAAM,uBAAuB,CAAC;AACrC,IAAI,WAAW,GAAG;AAClB;AACA;AACA;AACA,QAAQ,IAAI,CAAC,eAAe,GAAG,IAAI,0BAA0B,EAAE,CAAC;AAChE,QAAQ,IAAI,CAAC,IAAI,GAAG;AACpB,YAAY,IAAI;AAChB,wBAAYA,MAAU;AACtB,+BAAYC,aAAiB;AAC7B,YAAY,4BAA4B;AACxC,SAAS,CAAC;AACV,KAAK;AACL,IAAI,aAAa,GAAG;AACpB,QAAQ,OAAO,oBAAoB,CAAC;AACpC,KAAK;AACL,IAAI,MAAM,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,iBAAiB,GAAG,EAAE,EAAE;AACtE,QAAQ,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AAClD,QAAQ,IAAI,OAAO,GAAG,EAAE,CAAC;AACzB,QAAQ,QAAQ,QAAQ;AACxB,YAAY,KAAK,QAAQ;AACzB,gBAAgB,IAAI,CAAC,MAAM,EAAE;AAC7B,oBAAoB,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;AACjE,iBAAiB;AACjB,gBAAgB,OAAO,GAAG;AAC1B,oBAAoB,WAAW,EAAE,MAAM;AACvC,iBAAiB,CAAC;AAClB,gBAAgB,MAAM;AACtB,YAAY,KAAK,KAAK,EAAE;AACxB,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-1,5 +1,5 @@
|
|
|
1
1
|
import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
|
|
2
|
-
import { CustomHeaders, CustomMutations, CustomQueries, CustomSubscriptions, EnumTypes,
|
|
2
|
+
import { CustomHeaders, CustomMutations, CustomQueries, CustomSubscriptions, EnumTypes, ModelTypes } from '@aws-amplify/data-schema-types';
|
|
3
3
|
import { DocumentNode, GraphQLError, Source } from 'graphql';
|
|
4
4
|
import { Observable } from 'rxjs';
|
|
5
5
|
import { DocumentType, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
@@ -338,7 +338,6 @@ export type QueryArgs = Record<string, unknown>;
|
|
|
338
338
|
export interface ListArgs extends Record<string, unknown> {
|
|
339
339
|
selectionSet?: string[];
|
|
340
340
|
filter?: Record<string, unknown>;
|
|
341
|
-
sortDirection?: ModelSortDirection;
|
|
342
341
|
headers?: CustomHeaders;
|
|
343
342
|
}
|
|
344
343
|
export interface AuthModeParams extends Record<string, unknown> {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { GraphQLApiError } from './GraphQLApiError';
|
|
2
2
|
export { assertValidationError } from './assertValidationError';
|
|
3
3
|
export { APIValidationErrorCode, validationErrorMap } from './validation';
|
|
4
|
-
export { createGraphQLResultWithError } from './createGraphQLResultWithError';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { GraphQLApiError } from './GraphQLApiError.mjs';
|
|
2
2
|
export { assertValidationError } from './assertValidationError.mjs';
|
|
3
3
|
export { APIValidationErrorCode, validationErrorMap } from './validation.mjs';
|
|
4
|
-
export { createGraphQLResultWithError } from './createGraphQLResultWithError.mjs';
|
|
5
4
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
|
|
2
|
+
interface ErrorObject {
|
|
3
|
+
errors: AmplifyErrorParams[];
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* Checks to see if the given response or subscription message contains an
|
|
4
|
-
*
|
|
7
|
+
* unauth error. If it does, it changes the error message to include instructions
|
|
5
8
|
* for the app developer.
|
|
6
9
|
*/
|
|
7
|
-
export declare function
|
|
10
|
+
export declare function repackageUnauthError<T extends ErrorObject>(content: T): T;
|
|
11
|
+
export {};
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
/**
|
|
4
4
|
* Checks to see if the given response or subscription message contains an
|
|
5
|
-
*
|
|
5
|
+
* unauth error. If it does, it changes the error message to include instructions
|
|
6
6
|
* for the app developer.
|
|
7
7
|
*/
|
|
8
|
-
function
|
|
8
|
+
function repackageUnauthError(content) {
|
|
9
9
|
if (content.errors && Array.isArray(content.errors)) {
|
|
10
10
|
content.errors.forEach(e => {
|
|
11
|
-
if (
|
|
11
|
+
if (isUnauthError(e)) {
|
|
12
12
|
e.message = 'Unauthorized';
|
|
13
13
|
e.recoverySuggestion =
|
|
14
14
|
`If you're calling an Amplify-generated API, make sure ` +
|
|
@@ -19,7 +19,7 @@ function repackageUnauthorizedError(content) {
|
|
|
19
19
|
}
|
|
20
20
|
return content;
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function isUnauthError(error) {
|
|
23
23
|
// Error pattern corresponding to appsync calls
|
|
24
24
|
if (error?.originalError?.name?.startsWith('UnauthorizedException')) {
|
|
25
25
|
return true;
|
|
@@ -32,5 +32,5 @@ function isUnauthorizedError(error) {
|
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export {
|
|
35
|
+
export { repackageUnauthError };
|
|
36
36
|
//# sourceMappingURL=repackageAuthError.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repackageAuthError.mjs","sources":["../../../../src/utils/errors/repackageAuthError.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Checks to see if the given response or subscription message contains an\n *
|
|
1
|
+
{"version":3,"file":"repackageAuthError.mjs","sources":["../../../../src/utils/errors/repackageAuthError.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Checks to see if the given response or subscription message contains an\n * unauth error. If it does, it changes the error message to include instructions\n * for the app developer.\n */\nexport function repackageUnauthError(content) {\n if (content.errors && Array.isArray(content.errors)) {\n content.errors.forEach(e => {\n if (isUnauthError(e)) {\n e.message = 'Unauthorized';\n e.recoverySuggestion =\n `If you're calling an Amplify-generated API, make sure ` +\n `to set the \"authMode\" in generateClient({ authMode: '...' }) to the backend authorization ` +\n `rule's auth provider ('apiKey', 'userPool', 'iam', 'oidc', 'lambda')`;\n }\n });\n }\n return content;\n}\nfunction isUnauthError(error) {\n // Error pattern corresponding to appsync calls\n if (error?.originalError?.name?.startsWith('UnauthorizedException')) {\n return true;\n }\n // Error pattern corresponding to appsync subscriptions\n if (error.message?.startsWith('Connection failed:') &&\n error.message?.includes('Permission denied')) {\n return true;\n }\n return false;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,oBAAoB,CAAC,OAAO,EAAE;AAC9C,IAAI,IAAI,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;AACzD,QAAQ,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI;AACpC,YAAY,IAAI,aAAa,CAAC,CAAC,CAAC,EAAE;AAClC,gBAAgB,CAAC,CAAC,OAAO,GAAG,cAAc,CAAC;AAC3C,gBAAgB,CAAC,CAAC,kBAAkB;AACpC,oBAAoB,CAAC,sDAAsD,CAAC;AAC5E,wBAAwB,CAAC,0FAA0F,CAAC;AACpH,wBAAwB,CAAC,oEAAoE,CAAC,CAAC;AAC/F,aAAa;AACb,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,OAAO,CAAC;AACnB,CAAC;AACD,SAAS,aAAa,CAAC,KAAK,EAAE;AAC9B;AACA,IAAI,IAAI,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,CAAC,uBAAuB,CAAC,EAAE;AACzE,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL;AACA,IAAI,IAAI,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,oBAAoB,CAAC;AACvD,QAAQ,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAAE;AACtD,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB;;;;"}
|
|
@@ -2,7 +2,6 @@ import { ConsoleLogger } from '@aws-amplify/core';
|
|
|
2
2
|
import '@aws-amplify/core/internals/utils';
|
|
3
3
|
import { assertValidationError } from './errors/assertValidationError.mjs';
|
|
4
4
|
import { APIValidationErrorCode } from './errors/validation.mjs';
|
|
5
|
-
import 'graphql';
|
|
6
5
|
|
|
7
6
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
8
7
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveConfig.mjs","sources":["../../../src/utils/resolveConfig.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger } from '@aws-amplify/core';\nimport { APIValidationErrorCode, assertValidationError } from './errors';\nconst logger = new ConsoleLogger('GraphQLAPI resolveConfig');\n/**\n * @internal\n */\nexport const resolveConfig = (amplify) => {\n const config = amplify.getConfig();\n if (!config.API?.GraphQL) {\n logger.warn('The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().');\n }\n const { apiKey, customEndpoint, customEndpointRegion, defaultAuthMode, endpoint, region, } = config.API?.GraphQL ?? {};\n // TODO: re-enable when working in all test environments:\n // assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);\n assertValidationError(!(!customEndpoint && customEndpointRegion), APIValidationErrorCode.NoCustomEndpoint);\n return {\n apiKey,\n customEndpoint,\n customEndpointRegion,\n defaultAuthMode,\n endpoint,\n region,\n };\n};\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolveConfig.mjs","sources":["../../../src/utils/resolveConfig.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger } from '@aws-amplify/core';\nimport { APIValidationErrorCode, assertValidationError } from './errors';\nconst logger = new ConsoleLogger('GraphQLAPI resolveConfig');\n/**\n * @internal\n */\nexport const resolveConfig = (amplify) => {\n const config = amplify.getConfig();\n if (!config.API?.GraphQL) {\n logger.warn('The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().');\n }\n const { apiKey, customEndpoint, customEndpointRegion, defaultAuthMode, endpoint, region, } = config.API?.GraphQL ?? {};\n // TODO: re-enable when working in all test environments:\n // assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);\n assertValidationError(!(!customEndpoint && customEndpointRegion), APIValidationErrorCode.NoCustomEndpoint);\n return {\n apiKey,\n customEndpoint,\n customEndpointRegion,\n defaultAuthMode,\n endpoint,\n region,\n };\n};\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAGA,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,0BAA0B,CAAC,CAAC;AAC7D;AACA;AACA;AACY,MAAC,aAAa,GAAG,CAAC,OAAO,KAAK;AAC1C,IAAI,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;AACvC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE;AAC9B,QAAQ,MAAM,CAAC,IAAI,CAAC,yHAAyH,CAAC,CAAC;AAC/I,KAAK;AACL,IAAI,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,oBAAoB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,EAAE,OAAO,IAAI,EAAE,CAAC;AAC3H;AACA;AACA,IAAI,qBAAqB,CAAC,EAAE,CAAC,cAAc,IAAI,oBAAoB,CAAC,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;AAC/G,IAAI,OAAO;AACX,QAAQ,MAAM;AACd,QAAQ,cAAc;AACtB,QAAQ,oBAAoB;AAC5B,QAAQ,eAAe;AACvB,QAAQ,QAAQ;AAChB,QAAQ,MAAM;AACd,KAAK,CAAC;AACN;;;;"}
|
|
@@ -12,7 +12,10 @@ function resolveOwnerFields(model) {
|
|
|
12
12
|
if (rule.allow === 'owner') {
|
|
13
13
|
ownerFields.add(rule.ownerField || 'owner');
|
|
14
14
|
}
|
|
15
|
-
else if (rule.allow === 'groups') {
|
|
15
|
+
else if (rule.allow === 'groups' && rule.groupsField !== undefined) {
|
|
16
|
+
// only valid for dynamic group(s)
|
|
17
|
+
// static group auth will have an array of predefined groups in the attribute, groups: string[]
|
|
18
|
+
// but `groupsField` will be undefined
|
|
16
19
|
ownerFields.add(rule.groupsField);
|
|
17
20
|
}
|
|
18
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveOwnerFields.mjs","sources":["../../../src/utils/resolveOwnerFields.ts"],"sourcesContent":["/**\n * Given an introspection schema model, returns all owner fields.\n *\n * @param model Model from an introspection schema\n * @returns List of owner field names\n */\nexport function resolveOwnerFields(model) {\n const ownerFields = new Set();\n for (const attr of model.attributes || []) {\n if (isAuthAttribute(attr)) {\n for (const rule of attr.properties.rules) {\n if (rule.allow === 'owner') {\n ownerFields.add(rule.ownerField || 'owner');\n }\n else if (rule.allow === 'groups') {\n ownerFields.add(rule.groupsField);\n }\n }\n }\n }\n return Array.from(ownerFields);\n}\n/**\n * Type guard that identifies an auth attribute with an attached rules list that\n * specifies an `allow` attribute at a minimum.\n *\n * @param attribute Any object. Ideally a model introspection schema model attribute\n * @returns True if given object is an auth attribute\n */\nfunction isAuthAttribute(attribute) {\n if (attribute?.type === 'auth') {\n if (typeof attribute?.properties === 'object') {\n if (Array.isArray(attribute?.properties?.rules)) {\n return (attribute?.properties?.rules).every(rule => !!rule.allow);\n }\n }\n }\n return false;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,KAAK,EAAE;AAC1C,IAAI,MAAM,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;AAClC,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,UAAU,IAAI,EAAE,EAAE;AAC/C,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;AACnC,YAAY,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;AACtD,gBAAgB,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE;AAC5C,oBAAoB,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,OAAO,CAAC,CAAC;AAChE,iBAAiB;AACjB,qBAAqB,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"resolveOwnerFields.mjs","sources":["../../../src/utils/resolveOwnerFields.ts"],"sourcesContent":["/**\n * Given an introspection schema model, returns all owner fields.\n *\n * @param model Model from an introspection schema\n * @returns List of owner field names\n */\nexport function resolveOwnerFields(model) {\n const ownerFields = new Set();\n for (const attr of model.attributes || []) {\n if (isAuthAttribute(attr)) {\n for (const rule of attr.properties.rules) {\n if (rule.allow === 'owner') {\n ownerFields.add(rule.ownerField || 'owner');\n }\n else if (rule.allow === 'groups' && rule.groupsField !== undefined) {\n // only valid for dynamic group(s)\n // static group auth will have an array of predefined groups in the attribute, groups: string[]\n // but `groupsField` will be undefined\n ownerFields.add(rule.groupsField);\n }\n }\n }\n }\n return Array.from(ownerFields);\n}\n/**\n * Type guard that identifies an auth attribute with an attached rules list that\n * specifies an `allow` attribute at a minimum.\n *\n * @param attribute Any object. Ideally a model introspection schema model attribute\n * @returns True if given object is an auth attribute\n */\nfunction isAuthAttribute(attribute) {\n if (attribute?.type === 'auth') {\n if (typeof attribute?.properties === 'object') {\n if (Array.isArray(attribute?.properties?.rules)) {\n return (attribute?.properties?.rules).every(rule => !!rule.allow);\n }\n }\n }\n return false;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,KAAK,EAAE;AAC1C,IAAI,MAAM,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;AAClC,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,UAAU,IAAI,EAAE,EAAE;AAC/C,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;AACnC,YAAY,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;AACtD,gBAAgB,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE;AAC5C,oBAAoB,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,OAAO,CAAC,CAAC;AAChE,iBAAiB;AACjB,qBAAqB,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS,EAAE;AACpF;AACA;AACA;AACA,oBAAoB,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACtD,iBAAiB;AACjB,aAAa;AACb,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACnC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe,CAAC,SAAS,EAAE;AACpC,IAAI,IAAI,SAAS,EAAE,IAAI,KAAK,MAAM,EAAE;AACpC,QAAQ,IAAI,OAAO,SAAS,EAAE,UAAU,KAAK,QAAQ,EAAE;AACvD,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE;AAC7D,gBAAgB,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClF,aAAa;AACb,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/api-graphql",
|
|
3
|
-
"version": "4.0.24
|
|
3
|
+
"version": "4.0.24",
|
|
4
4
|
"description": "Api-graphql category of aws-amplify",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -85,9 +85,9 @@
|
|
|
85
85
|
"server"
|
|
86
86
|
],
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@aws-amplify/api-rest": "4.0.24
|
|
89
|
-
"@aws-amplify/core": "6.0.24
|
|
90
|
-
"@aws-amplify/data-schema-types": "^0.7.
|
|
88
|
+
"@aws-amplify/api-rest": "4.0.24",
|
|
89
|
+
"@aws-amplify/core": "6.0.24",
|
|
90
|
+
"@aws-amplify/data-schema-types": "^0.7.11",
|
|
91
91
|
"@aws-sdk/types": "3.387.0",
|
|
92
92
|
"graphql": "15.8.0",
|
|
93
93
|
"rxjs": "^7.8.1",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"limit": "91.7 kB"
|
|
103
103
|
}
|
|
104
104
|
],
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "ab3120092b3607e9735444e45e7697acac9252f4"
|
|
106
106
|
}
|
|
@@ -732,15 +732,6 @@ export function generateGraphQLDocument(
|
|
|
732
732
|
graphQLArguments ??
|
|
733
733
|
(graphQLArguments = {
|
|
734
734
|
filter: `Model${name}FilterInput`,
|
|
735
|
-
sortDirection: 'ModelSortDirection',
|
|
736
|
-
...[primaryKeyFieldName, ...sortKeyFieldNames].reduce(
|
|
737
|
-
(acc: Record<string, any>, fieldName) => {
|
|
738
|
-
acc[fieldName] = `${fields[fieldName].type}`;
|
|
739
|
-
|
|
740
|
-
return acc;
|
|
741
|
-
},
|
|
742
|
-
[],
|
|
743
|
-
),
|
|
744
735
|
limit: 'Int',
|
|
745
736
|
nextToken: 'String',
|
|
746
737
|
});
|
|
@@ -754,7 +745,6 @@ export function generateGraphQLDocument(
|
|
|
754
745
|
(graphQLArguments = {
|
|
755
746
|
...indexQueryArgs!,
|
|
756
747
|
filter: `Model${name}FilterInput`,
|
|
757
|
-
sortDirection: 'ModelSortDirection',
|
|
758
748
|
limit: 'Int',
|
|
759
749
|
nextToken: 'String',
|
|
760
750
|
});
|
|
@@ -868,10 +858,6 @@ export function buildGraphQLVariables(
|
|
|
868
858
|
if (arg?.filter) {
|
|
869
859
|
variables.filter = arg.filter;
|
|
870
860
|
}
|
|
871
|
-
if (arg?.sortDirection) {
|
|
872
|
-
variables.sortDirection = arg.sortDirection;
|
|
873
|
-
variables[primaryKeyFieldName] = arg[primaryKeyFieldName];
|
|
874
|
-
}
|
|
875
861
|
if (arg?.nextToken) {
|
|
876
862
|
variables.nextToken = arg.nextToken;
|
|
877
863
|
}
|
|
@@ -891,11 +877,6 @@ export function buildGraphQLVariables(
|
|
|
891
877
|
if (arg?.filter) {
|
|
892
878
|
variables.filter = arg.filter;
|
|
893
879
|
}
|
|
894
|
-
|
|
895
|
-
if (arg?.sortDirection) {
|
|
896
|
-
variables.sortDirection = arg.sortDirection;
|
|
897
|
-
}
|
|
898
|
-
|
|
899
880
|
if (arg?.nextToken) {
|
|
900
881
|
variables.nextToken = arg.nextToken;
|
|
901
882
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import {
|
|
4
4
|
DocumentNode,
|
|
5
|
+
GraphQLError,
|
|
5
6
|
OperationDefinitionNode,
|
|
6
7
|
OperationTypeNode,
|
|
7
8
|
parse,
|
|
@@ -24,20 +25,14 @@ import {
|
|
|
24
25
|
import { CustomHeaders, RequestOptions } from '@aws-amplify/data-schema-types';
|
|
25
26
|
|
|
26
27
|
import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
|
|
27
|
-
import { GraphQLOperation, GraphQLOptions, GraphQLResult } from '../types';
|
|
28
|
-
import { resolveConfig, resolveLibraryOptions } from '../utils';
|
|
29
|
-
import { repackageUnauthorizedError } from '../utils/errors/repackageAuthError';
|
|
30
28
|
import {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} from '../utils/errors/
|
|
38
|
-
import { GraphQLApiError, createGraphQLResultWithError } from '../utils/errors';
|
|
39
|
-
|
|
40
|
-
import { isGraphQLResponseWithErrors } from './utils/runtimeTypeGuards/isGraphQLResponseWithErrors';
|
|
29
|
+
GraphQLAuthError,
|
|
30
|
+
GraphQLOperation,
|
|
31
|
+
GraphQLOptions,
|
|
32
|
+
GraphQLResult,
|
|
33
|
+
} from '../types';
|
|
34
|
+
import { resolveConfig, resolveLibraryOptions } from '../utils';
|
|
35
|
+
import { repackageUnauthError } from '../utils/errors/repackageAuthError';
|
|
41
36
|
|
|
42
37
|
const USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
43
38
|
|
|
@@ -81,7 +76,7 @@ export class InternalGraphQLAPIClass {
|
|
|
81
76
|
switch (authMode) {
|
|
82
77
|
case 'apiKey':
|
|
83
78
|
if (!apiKey) {
|
|
84
|
-
throw new
|
|
79
|
+
throw new Error(GraphQLAuthError.NO_API_KEY);
|
|
85
80
|
}
|
|
86
81
|
headers = {
|
|
87
82
|
'X-Api-Key': apiKey,
|
|
@@ -90,44 +85,33 @@ export class InternalGraphQLAPIClass {
|
|
|
90
85
|
case 'iam': {
|
|
91
86
|
const session = await amplify.Auth.fetchAuthSession();
|
|
92
87
|
if (session.credentials === undefined) {
|
|
93
|
-
throw new
|
|
88
|
+
throw new Error(GraphQLAuthError.NO_CREDENTIALS);
|
|
94
89
|
}
|
|
95
90
|
break;
|
|
96
91
|
}
|
|
97
92
|
case 'oidc':
|
|
98
|
-
case 'userPool':
|
|
99
|
-
let token: string | undefined;
|
|
100
|
-
|
|
93
|
+
case 'userPool':
|
|
101
94
|
try {
|
|
102
|
-
token = (
|
|
95
|
+
const token = (
|
|
103
96
|
await amplify.Auth.fetchAuthSession()
|
|
104
97
|
).tokens?.accessToken.toString();
|
|
105
|
-
} catch (e) {
|
|
106
|
-
// fetchAuthSession failed
|
|
107
|
-
throw new GraphQLApiError({
|
|
108
|
-
...NO_SIGNED_IN_USER,
|
|
109
|
-
underlyingError: e,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
98
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
99
|
+
if (!token) {
|
|
100
|
+
throw new Error(GraphQLAuthError.NO_FEDERATED_JWT);
|
|
101
|
+
}
|
|
102
|
+
headers = {
|
|
103
|
+
Authorization: token,
|
|
104
|
+
};
|
|
105
|
+
} catch (e) {
|
|
106
|
+
throw new Error(GraphQLAuthError.NO_CURRENT_USER);
|
|
118
107
|
}
|
|
119
|
-
|
|
120
|
-
headers = {
|
|
121
|
-
Authorization: token,
|
|
122
|
-
};
|
|
123
108
|
break;
|
|
124
|
-
}
|
|
125
109
|
case 'lambda':
|
|
126
110
|
if (
|
|
127
111
|
typeof additionalHeaders === 'object' &&
|
|
128
112
|
!additionalHeaders.Authorization
|
|
129
113
|
) {
|
|
130
|
-
throw new
|
|
114
|
+
throw new Error(GraphQLAuthError.NO_AUTH_TOKEN);
|
|
131
115
|
}
|
|
132
116
|
|
|
133
117
|
headers = {
|
|
@@ -366,15 +350,18 @@ export class InternalGraphQLAPIClass {
|
|
|
366
350
|
const endpoint = customEndpoint || appSyncGraphqlEndpoint;
|
|
367
351
|
|
|
368
352
|
if (!endpoint) {
|
|
369
|
-
|
|
353
|
+
const error = new GraphQLError('No graphql endpoint provided.');
|
|
354
|
+
// TODO(Eslint): refactor this to throw an Error instead of a plain object
|
|
355
|
+
// eslint-disable-next-line no-throw-literal
|
|
356
|
+
throw {
|
|
357
|
+
data: {},
|
|
358
|
+
errors: [error],
|
|
359
|
+
};
|
|
370
360
|
}
|
|
371
361
|
|
|
372
362
|
let response: any;
|
|
373
363
|
|
|
374
364
|
try {
|
|
375
|
-
// See the inline doc of the REST `post()` API for possible errors to be thrown.
|
|
376
|
-
// As these errors are catastrophic they should be caught and handled by GraphQL
|
|
377
|
-
// API consumers.
|
|
378
365
|
const { body: responseBody } = await this._api.post(amplify, {
|
|
379
366
|
url: new AmplifyUrl(endpoint),
|
|
380
367
|
options: {
|
|
@@ -386,20 +373,39 @@ export class InternalGraphQLAPIClass {
|
|
|
386
373
|
abortController,
|
|
387
374
|
});
|
|
388
375
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
376
|
+
const result = await responseBody.json();
|
|
377
|
+
|
|
378
|
+
response = result;
|
|
379
|
+
} catch (err) {
|
|
380
|
+
// If the exception is because user intentionally
|
|
381
|
+
// cancelled the request, do not modify the exception
|
|
382
|
+
// so that clients can identify the exception correctly.
|
|
383
|
+
if (this.isCancelError(err)) {
|
|
384
|
+
throw err;
|
|
393
385
|
}
|
|
394
386
|
|
|
395
|
-
response =
|
|
387
|
+
response = {
|
|
388
|
+
data: {},
|
|
389
|
+
errors: [
|
|
390
|
+
new GraphQLError(
|
|
391
|
+
(err as any).message,
|
|
392
|
+
null,
|
|
393
|
+
null,
|
|
394
|
+
null,
|
|
395
|
+
null,
|
|
396
|
+
err as any,
|
|
397
|
+
),
|
|
398
|
+
],
|
|
399
|
+
};
|
|
396
400
|
}
|
|
397
401
|
|
|
398
|
-
|
|
399
|
-
|
|
402
|
+
const { errors } = response;
|
|
403
|
+
|
|
404
|
+
if (errors && errors.length) {
|
|
405
|
+
throw repackageUnauthError(response);
|
|
400
406
|
}
|
|
401
407
|
|
|
402
|
-
return response
|
|
408
|
+
return response;
|
|
403
409
|
}
|
|
404
410
|
|
|
405
411
|
/**
|
|
@@ -457,7 +463,7 @@ export class InternalGraphQLAPIClass {
|
|
|
457
463
|
.pipe(
|
|
458
464
|
catchError(e => {
|
|
459
465
|
if (e.errors) {
|
|
460
|
-
throw
|
|
466
|
+
throw repackageUnauthError(e);
|
|
461
467
|
}
|
|
462
468
|
throw e;
|
|
463
469
|
}),
|
package/src/types/index.ts
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
CustomQueries,
|
|
8
8
|
CustomSubscriptions,
|
|
9
9
|
EnumTypes,
|
|
10
|
-
ModelSortDirection,
|
|
11
10
|
ModelTypes,
|
|
12
11
|
} from '@aws-amplify/data-schema-types';
|
|
13
12
|
import { DocumentNode, GraphQLError, Source } from 'graphql';
|
|
@@ -465,7 +464,6 @@ export type QueryArgs = Record<string, unknown>;
|
|
|
465
464
|
export interface ListArgs extends Record<string, unknown> {
|
|
466
465
|
selectionSet?: string[];
|
|
467
466
|
filter?: Record<string, unknown>;
|
|
468
|
-
sortDirection?: ModelSortDirection;
|
|
469
467
|
headers?: CustomHeaders;
|
|
470
468
|
}
|
|
471
469
|
|
|
@@ -4,4 +4,3 @@
|
|
|
4
4
|
export { GraphQLApiError } from './GraphQLApiError';
|
|
5
5
|
export { assertValidationError } from './assertValidationError';
|
|
6
6
|
export { APIValidationErrorCode, validationErrorMap } from './validation';
|
|
7
|
-
export { createGraphQLResultWithError } from './createGraphQLResultWithError';
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
|
|
5
|
+
|
|
6
|
+
interface ErrorObject {
|
|
7
|
+
errors: AmplifyErrorParams[];
|
|
8
|
+
}
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
11
|
* Checks to see if the given response or subscription message contains an
|
|
8
|
-
*
|
|
12
|
+
* unauth error. If it does, it changes the error message to include instructions
|
|
9
13
|
* for the app developer.
|
|
10
14
|
*/
|
|
11
|
-
export function
|
|
12
|
-
content: T,
|
|
13
|
-
): T {
|
|
15
|
+
export function repackageUnauthError<T extends ErrorObject>(content: T): T {
|
|
14
16
|
if (content.errors && Array.isArray(content.errors)) {
|
|
15
17
|
content.errors.forEach(e => {
|
|
16
|
-
if (
|
|
18
|
+
if (isUnauthError(e)) {
|
|
17
19
|
e.message = 'Unauthorized';
|
|
18
|
-
|
|
20
|
+
e.recoverySuggestion =
|
|
19
21
|
`If you're calling an Amplify-generated API, make sure ` +
|
|
20
22
|
`to set the "authMode" in generateClient({ authMode: '...' }) to the backend authorization ` +
|
|
21
23
|
`rule's auth provider ('apiKey', 'userPool', 'iam', 'oidc', 'lambda')`;
|
|
@@ -26,7 +28,7 @@ export function repackageUnauthorizedError<T extends GraphQLResult<any>>(
|
|
|
26
28
|
return content;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
function
|
|
31
|
+
function isUnauthError(error: any): boolean {
|
|
30
32
|
// Error pattern corresponding to appsync calls
|
|
31
33
|
if (error?.originalError?.name?.startsWith('UnauthorizedException')) {
|
|
32
34
|
return true;
|
|
@@ -42,7 +42,10 @@ export function resolveOwnerFields(model: Model): string[] {
|
|
|
42
42
|
for (const rule of attr.properties.rules) {
|
|
43
43
|
if (rule.allow === 'owner') {
|
|
44
44
|
ownerFields.add(rule.ownerField || 'owner');
|
|
45
|
-
} else if (rule.allow === 'groups') {
|
|
45
|
+
} else if (rule.allow === 'groups' && rule.groupsField !== undefined) {
|
|
46
|
+
// only valid for dynamic group(s)
|
|
47
|
+
// static group auth will have an array of predefined groups in the attribute, groups: string[]
|
|
48
|
+
// but `groupsField` will be undefined
|
|
46
49
|
ownerFields.add(rule.groupsField);
|
|
47
50
|
}
|
|
48
51
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isGraphQLResponseWithErrors = void 0;
|
|
7
|
-
function isGraphQLResponseWithErrors(response) {
|
|
8
|
-
if (!response) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
const r = response;
|
|
12
|
-
return Array.isArray(r.errors) && r.errors.length > 0;
|
|
13
|
-
}
|
|
14
|
-
exports.isGraphQLResponseWithErrors = isGraphQLResponseWithErrors;
|
|
15
|
-
//# sourceMappingURL=isGraphQLResponseWithErrors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isGraphQLResponseWithErrors.js","sources":["../../../../../src/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.isGraphQLResponseWithErrors = void 0;\nfunction isGraphQLResponseWithErrors(response) {\n if (!response) {\n return false;\n }\n const r = response;\n return Array.isArray(r.errors) && r.errors.length > 0;\n}\nexports.isGraphQLResponseWithErrors = isGraphQLResponseWithErrors;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,2BAA2B,GAAG,KAAK,CAAC,CAAC;AAC7C,SAAS,2BAA2B,CAAC,QAAQ,EAAE;AAC/C,IAAI,IAAI,CAAC,QAAQ,EAAE;AACnB,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC;AACvB,IAAI,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AAC1D,CAAC;AACD,OAAO,CAAC,2BAA2B,GAAG,2BAA2B;;"}
|