@ttoss/aws-appsync-nodejs 1.7.4 → 1.8.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.
package/README.md CHANGED
@@ -5,7 +5,7 @@ This package implements a AWS AppSync client for Node.js. We've followed the [AW
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- yarn add @ttoss/aws-appsync-nodejs
8
+ pnpm add @ttoss/aws-appsync-nodejs
9
9
  ```
10
10
 
11
11
  ## Quickstart
@@ -14,7 +14,7 @@ yarn add @ttoss/aws-appsync-nodejs
14
14
  import { appSyncClient } from '@ttoss/aws-appsync-nodejs';
15
15
 
16
16
  appSyncClient.setConfig({
17
- apiEndpoint: 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
17
+ endpoint: 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
18
18
  apiKey: 'da2-xxxxxxxxxxxxxxxxxxxxxxxxxx',
19
19
  });
20
20
 
@@ -34,13 +34,13 @@ appSyncClient.query(query, { id: '1' }).then((result) => {
34
34
 
35
35
  ## Config
36
36
 
37
- You need to configure the client with `apiEndpoint` (required), `apiKey` (optional) and `awsCredentials` (optional).
37
+ You need to configure the client with `endpoint` (required), `apiKey` (optional) and `credentials` (optional).
38
38
 
39
- 1. If you don't provide `apiKey` or `awsCredentials`, the client will try to use the AWS credentials from the environment variables of your system—local computer, AWS Lambda, EC2.
39
+ 1. If you don't provide `apiKey` or `credentials`, the client will try to use the AWS credentials from the environment variables of your system—local computer, AWS Lambda, EC2.
40
40
 
41
41
  ```typescript
42
42
  appSyncClient.setConfig({
43
- apiEndpoint: 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
43
+ endpoint: 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
44
44
  });
45
45
  ```
46
46
 
@@ -48,17 +48,31 @@ appSyncClient.setConfig({
48
48
 
49
49
  ```typescript
50
50
  appSyncClient.setConfig({
51
- apiEndpoint: 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
51
+ endpoint: 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
52
52
  apiKey: 'da2-xxxxxxxxxxxxxxxxxxxxxxxxxx',
53
53
  });
54
54
  ```
55
55
 
56
- 3. If you provide `awsCredentials`, the client will use the credentials to authenticate.
56
+ 3. If you provide `credentials`, the client will use the credentials to authenticate.
57
57
 
58
58
  ```typescript
59
59
  appSyncClient.setConfig({
60
- apiEndpoint,
61
- awsCredentials: {
60
+ endpoint,
61
+ credentials: {
62
+ accessKeyId: // access key id,
63
+ secretAccessKey: // secret access key,
64
+ sessionToken: // optional session token,
65
+ },
66
+ });
67
+ ```
68
+
69
+ If you provide the default endpoint (`https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql`), the client will retrieve the region from the endpoint. If you provide the endpoint with the custom domain (`https://custom-domain.com`), you need to provide the region as well.
70
+
71
+ ```typescript
72
+ appSyncClient.setConfig({
73
+ endpoint: 'https://custom-domain.com',
74
+ region: 'us-east-1',
75
+ credentials: {
62
76
  accessKeyId: // access key id,
63
77
  secretAccessKey: // secret access key,
64
78
  sessionToken: // optional session token,
package/dist/esm/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
 
3
3
  // src/index.ts
4
- import { HttpRequest } from "@aws-sdk/protocol-http";
4
+ import { HttpRequest } from "@smithy/protocol-http";
5
5
  import { Sha256 } from "@aws-crypto/sha256-js";
6
- import { SignatureV4 } from "@aws-sdk/signature-v4";
6
+ import { SignatureV4 } from "@smithy/signature-v4";
7
7
  import { defaultProvider } from "@aws-sdk/credential-provider-node";
8
8
  var _config;
9
9
  var setConfig = config => {
@@ -11,7 +11,7 @@ var setConfig = config => {
11
11
  };
12
12
  var queryWithApiKey = async (query2, variables) => {
13
13
  const {
14
- apiEndpoint,
14
+ endpoint,
15
15
  apiKey
16
16
  } = _config;
17
17
  if (!apiKey) {
@@ -27,7 +27,7 @@ var queryWithApiKey = async (query2, variables) => {
27
27
  variables
28
28
  })
29
29
  };
30
- const request = new Request(apiEndpoint, options);
30
+ const request = new Request(endpoint, options);
31
31
  const response = await fetch(request);
32
32
  const body = await response.json();
33
33
  return body;
@@ -42,14 +42,10 @@ var getRegionFromEndpoint = endpoint => {
42
42
  return region;
43
43
  };
44
44
  var queryWithCredentials = async (query2, variables) => {
45
- const {
46
- apiEndpoint,
47
- awsCredentials
48
- } = _config;
49
- const endpoint = new URL(apiEndpoint);
50
- const region = getRegionFromEndpoint(apiEndpoint);
45
+ const endpoint = new URL(_config.endpoint);
46
+ const region = _config.region || getRegionFromEndpoint(_config.endpoint);
51
47
  const signer = new SignatureV4({
52
- credentials: awsCredentials || defaultProvider(),
48
+ credentials: _config.credentials || defaultProvider(),
53
49
  region,
54
50
  service: "appsync",
55
51
  sha256: Sha256
@@ -65,7 +61,8 @@ var queryWithCredentials = async (query2, variables) => {
65
61
  query: query2,
66
62
  variables
67
63
  }),
68
- path: endpoint.pathname
64
+ path: endpoint.pathname,
65
+ protocol: endpoint.protocol
69
66
  });
70
67
  const signed = await signer.sign(requestToBeSigned);
71
68
  const request = new Request(endpoint, signed);
package/dist/index.d.mts CHANGED
@@ -6,11 +6,12 @@ import { AwsCredentialIdentity } from '@aws-sdk/types';
6
6
  */
7
7
 
8
8
  type Config = {
9
- apiEndpoint: string;
9
+ endpoint: string;
10
+ region?: string;
10
11
  apiKey?: string;
11
- awsCredentials?: AwsCredentialIdentity;
12
+ credentials?: AwsCredentialIdentity;
12
13
  };
13
- type Query = (query: string, variables: Record<string, unknown>) => Promise<{
14
+ type Query = (query: string, variables?: Record<string, unknown>) => Promise<{
14
15
  data: Record<string, unknown> | null;
15
16
  errors?: {
16
17
  message: string;
package/dist/index.d.ts CHANGED
@@ -6,11 +6,12 @@ import { AwsCredentialIdentity } from '@aws-sdk/types';
6
6
  */
7
7
 
8
8
  type Config = {
9
- apiEndpoint: string;
9
+ endpoint: string;
10
+ region?: string;
10
11
  apiKey?: string;
11
- awsCredentials?: AwsCredentialIdentity;
12
+ credentials?: AwsCredentialIdentity;
12
13
  };
13
- type Query = (query: string, variables: Record<string, unknown>) => Promise<{
14
+ type Query = (query: string, variables?: Record<string, unknown>) => Promise<{
14
15
  data: Record<string, unknown> | null;
15
16
  errors?: {
16
17
  message: string;
package/dist/index.js CHANGED
@@ -30,9 +30,9 @@ __export(src_exports, {
30
30
  appSyncClient: () => appSyncClient
31
31
  });
32
32
  module.exports = __toCommonJS(src_exports);
33
- var import_protocol_http = require("@aws-sdk/protocol-http");
33
+ var import_protocol_http = require("@smithy/protocol-http");
34
34
  var import_sha256_js = require("@aws-crypto/sha256-js");
35
- var import_signature_v4 = require("@aws-sdk/signature-v4");
35
+ var import_signature_v4 = require("@smithy/signature-v4");
36
36
  var import_credential_provider_node = require("@aws-sdk/credential-provider-node");
37
37
  var _config;
38
38
  var setConfig = config => {
@@ -40,7 +40,7 @@ var setConfig = config => {
40
40
  };
41
41
  var queryWithApiKey = async (query2, variables) => {
42
42
  const {
43
- apiEndpoint,
43
+ endpoint,
44
44
  apiKey
45
45
  } = _config;
46
46
  if (!apiKey) {
@@ -56,7 +56,7 @@ var queryWithApiKey = async (query2, variables) => {
56
56
  variables
57
57
  })
58
58
  };
59
- const request = new Request(apiEndpoint, options);
59
+ const request = new Request(endpoint, options);
60
60
  const response = await fetch(request);
61
61
  const body = await response.json();
62
62
  return body;
@@ -71,14 +71,10 @@ var getRegionFromEndpoint = endpoint => {
71
71
  return region;
72
72
  };
73
73
  var queryWithCredentials = async (query2, variables) => {
74
- const {
75
- apiEndpoint,
76
- awsCredentials
77
- } = _config;
78
- const endpoint = new URL(apiEndpoint);
79
- const region = getRegionFromEndpoint(apiEndpoint);
74
+ const endpoint = new URL(_config.endpoint);
75
+ const region = _config.region || getRegionFromEndpoint(_config.endpoint);
80
76
  const signer = new import_signature_v4.SignatureV4({
81
- credentials: awsCredentials || (0, import_credential_provider_node.defaultProvider)(),
77
+ credentials: _config.credentials || (0, import_credential_provider_node.defaultProvider)(),
82
78
  region,
83
79
  service: "appsync",
84
80
  sha256: import_sha256_js.Sha256
@@ -94,7 +90,8 @@ var queryWithCredentials = async (query2, variables) => {
94
90
  query: query2,
95
91
  variables
96
92
  }),
97
- path: endpoint.pathname
93
+ path: endpoint.pathname,
94
+ protocol: endpoint.protocol
98
95
  });
99
96
  const signed = await signer.sign(requestToBeSigned);
100
97
  const request = new Request(endpoint, signed);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/aws-appsync-nodejs",
3
- "version": "1.7.4",
3
+ "version": "1.8.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "ttoss",
@@ -18,12 +18,12 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "@aws-crypto/sha256-js": "^5.2.0",
21
- "@aws-sdk/credential-provider-node": "^3.460.0",
22
- "@aws-sdk/protocol-http": "^3.370.0",
23
- "@aws-sdk/signature-v4": "^3.370.0"
21
+ "@aws-sdk/credential-provider-node": "^3.503.1",
22
+ "@smithy/protocol-http": "^3.1.1",
23
+ "@smithy/signature-v4": "^2.1.1"
24
24
  },
25
25
  "devDependencies": {
26
- "@aws-sdk/types": "^3.460.0",
26
+ "@aws-sdk/types": "^3.502.0",
27
27
  "@types/jest": "^29.5.11",
28
28
  "jest": "^29.7.0",
29
29
  "tsup": "^8.0.1",