@aws-amplify/api-graphql 4.0.26 → 4.0.27-unstable.68a9f28.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 (45) hide show
  1. package/dist/cjs/internals/APIClient.js +14 -0
  2. package/dist/cjs/internals/APIClient.js.map +1 -1
  3. package/dist/cjs/internals/InternalGraphQLAPI.js +36 -38
  4. package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
  5. package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js +15 -0
  6. package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js.map +1 -0
  7. package/dist/cjs/utils/errors/constants.js +47 -0
  8. package/dist/cjs/utils/errors/constants.js.map +1 -0
  9. package/dist/cjs/utils/errors/createGraphQLResultWithError.js +15 -0
  10. package/dist/cjs/utils/errors/createGraphQLResultWithError.js.map +1 -0
  11. package/dist/cjs/utils/errors/index.js +3 -1
  12. package/dist/cjs/utils/errors/index.js.map +1 -1
  13. package/dist/cjs/utils/errors/repackageAuthError.js +6 -6
  14. package/dist/cjs/utils/errors/repackageAuthError.js.map +1 -1
  15. package/dist/esm/internals/APIClient.mjs +14 -0
  16. package/dist/esm/internals/APIClient.mjs.map +1 -1
  17. package/dist/esm/internals/InternalGraphQLAPI.mjs +40 -40
  18. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  19. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.d.ts +2 -0
  20. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs +12 -0
  21. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs.map +1 -0
  22. package/dist/esm/types/index.d.ts +2 -1
  23. package/dist/esm/utils/errors/constants.d.ts +7 -0
  24. package/dist/esm/utils/errors/constants.mjs +46 -0
  25. package/dist/esm/utils/errors/constants.mjs.map +1 -0
  26. package/dist/esm/utils/errors/createGraphQLResultWithError.d.ts +2 -0
  27. package/dist/esm/utils/errors/createGraphQLResultWithError.mjs +13 -0
  28. package/dist/esm/utils/errors/createGraphQLResultWithError.mjs.map +1 -0
  29. package/dist/esm/utils/errors/index.d.ts +1 -0
  30. package/dist/esm/utils/errors/index.mjs +1 -0
  31. package/dist/esm/utils/errors/index.mjs.map +1 -1
  32. package/dist/esm/utils/errors/repackageAuthError.d.ts +3 -7
  33. package/dist/esm/utils/errors/repackageAuthError.mjs +5 -5
  34. package/dist/esm/utils/errors/repackageAuthError.mjs.map +1 -1
  35. package/dist/esm/utils/resolveConfig.mjs +1 -0
  36. package/dist/esm/utils/resolveConfig.mjs.map +1 -1
  37. package/package.json +5 -5
  38. package/src/internals/APIClient.ts +20 -0
  39. package/src/internals/InternalGraphQLAPI.ts +50 -56
  40. package/src/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.ts +15 -0
  41. package/src/types/index.ts +2 -0
  42. package/src/utils/errors/constants.ts +56 -0
  43. package/src/utils/errors/createGraphQLResultWithError.ts +15 -0
  44. package/src/utils/errors/index.ts +1 -0
  45. package/src/utils/errors/repackageAuthError.ts +8 -10
@@ -0,0 +1,56 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
5
+
6
+ import { GraphQLAuthError } from '../../types';
7
+
8
+ export const NO_API_KEY: AmplifyErrorParams = {
9
+ name: 'NoApiKey',
10
+ // ideal: No API key configured.
11
+ message: GraphQLAuthError.NO_API_KEY,
12
+ recoverySuggestion:
13
+ 'The API request was made with `authMode: "apiKey"` but no API Key was passed into `Amplify.configure()`. Review if your API key is passed into the `Amplify.configure()` function.',
14
+ };
15
+
16
+ export const NO_VALID_CREDENTIALS: AmplifyErrorParams = {
17
+ name: 'NoCredentials',
18
+ // ideal: No auth credentials available.
19
+ message: GraphQLAuthError.NO_CREDENTIALS,
20
+ recoverySuggestion: `The API request was made with \`authMode: "iam"\` but no authentication credentials are available.
21
+
22
+ If you intended to make a request using an authenticated role, review if your user is signed in before making the request.
23
+
24
+ If you intend to make a request using an unauthenticated role or also known as "guest access", verify if "Auth.Cognito.allowGuestAccess" is set to "true" in the \`Amplify.configure()\` function.`,
25
+ };
26
+
27
+ export const NO_VALID_AUTH_TOKEN: AmplifyErrorParams = {
28
+ name: 'NoValidAuthTokens',
29
+ // ideal: No valid JWT auth token provided to make the API request..
30
+ message: GraphQLAuthError.NO_FEDERATED_JWT,
31
+ recoverySuggestion:
32
+ 'If you intended to make an authenticated API request, review if the current user is signed in.',
33
+ };
34
+
35
+ export const NO_SIGNED_IN_USER: AmplifyErrorParams = {
36
+ name: 'NoSignedUser',
37
+ // ideal: Couldn't retrieve authentication credentials to make the API request.
38
+ message: GraphQLAuthError.NO_CURRENT_USER,
39
+ recoverySuggestion:
40
+ 'Review the underlying exception field for more details. If you intended to make an authenticated API request, review if the current user is signed in.',
41
+ };
42
+
43
+ export const NO_AUTH_TOKEN_HEADER: AmplifyErrorParams = {
44
+ name: 'NoAuthorizationHeader',
45
+ // ideal: Authorization header not specified.
46
+ message: GraphQLAuthError.NO_AUTH_TOKEN,
47
+ recoverySuggestion:
48
+ 'The API request was made with `authMode: "lambda"` but no `authToken` is set. Review if a valid authToken is passed into the request options or in the `Amplify.configure()` function.',
49
+ };
50
+
51
+ export const NO_ENDPOINT: AmplifyErrorParams = {
52
+ name: 'NoEndpoint',
53
+ message: 'No GraphQL endpoint configured in `Amplify.configure()`.',
54
+ recoverySuggestion:
55
+ 'Review if the GraphQL API endpoint is set in the `Amplify.configure()` function.',
56
+ };
@@ -0,0 +1,15 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { GraphQLError } from 'graphql';
5
+
6
+ import { GraphQLResult } from '../../types';
7
+
8
+ export const createGraphQLResultWithError = <T>(
9
+ error: Error,
10
+ ): GraphQLResult<T> => {
11
+ return {
12
+ data: {} as T,
13
+ errors: [new GraphQLError(error.message, null, null, null, null, error)],
14
+ };
15
+ };
@@ -4,3 +4,4 @@
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,23 +1,21 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
5
-
6
- interface ErrorObject {
7
- errors: AmplifyErrorParams[];
8
- }
4
+ import { GraphQLResult } from '../../types';
9
5
 
10
6
  /**
11
7
  * Checks to see if the given response or subscription message contains an
12
- * unauth error. If it does, it changes the error message to include instructions
8
+ * Unauthorized error. If it does, it changes the error message to include instructions
13
9
  * for the app developer.
14
10
  */
15
- export function repackageUnauthError<T extends ErrorObject>(content: T): T {
11
+ export function repackageUnauthorizedError<T extends GraphQLResult<any>>(
12
+ content: T,
13
+ ): T {
16
14
  if (content.errors && Array.isArray(content.errors)) {
17
15
  content.errors.forEach(e => {
18
- if (isUnauthError(e)) {
16
+ if (isUnauthorizedError(e)) {
19
17
  e.message = 'Unauthorized';
20
- e.recoverySuggestion =
18
+ (e as any).recoverySuggestion =
21
19
  `If you're calling an Amplify-generated API, make sure ` +
22
20
  `to set the "authMode" in generateClient({ authMode: '...' }) to the backend authorization ` +
23
21
  `rule's auth provider ('apiKey', 'userPool', 'iam', 'oidc', 'lambda')`;
@@ -28,7 +26,7 @@ export function repackageUnauthError<T extends ErrorObject>(content: T): T {
28
26
  return content;
29
27
  }
30
28
 
31
- function isUnauthError(error: any): boolean {
29
+ function isUnauthorizedError(error: any): boolean {
32
30
  // Error pattern corresponding to appsync calls
33
31
  if (error?.originalError?.name?.startsWith('UnauthorizedException')) {
34
32
  return true;