@ttoss/relay-amplify 0.5.4 → 0.5.5

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/esm/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
 
3
3
  // src/index.ts
4
- import { API, Auth, graphqlOperation } from "aws-amplify";
5
4
  import { Environment, Network, RecordSource, Store } from "relay-runtime";
6
5
 
7
6
  // src/encodeCredentials.ts
@@ -17,11 +16,22 @@ var decodeCredentials = credentials => {
17
16
  };
18
17
 
19
18
  // src/index.ts
19
+ import { fetchAuthSession } from "aws-amplify/auth";
20
+ import { post } from "aws-amplify/api";
20
21
  var fetchQuery = async (operation, variables) => {
21
22
  let credentials;
22
23
  try {
23
- const currentCredentials = await Auth.currentCredentials();
24
- credentials = encodeCredentials(currentCredentials);
24
+ const authSession = await fetchAuthSession();
25
+ if (authSession.credentials && authSession.identityId && authSession.credentials?.sessionToken) {
26
+ credentials = encodeCredentials({
27
+ accessKeyId: authSession.credentials?.accessKeyId,
28
+ identityId: authSession.identityId,
29
+ sessionToken: authSession.credentials?.sessionToken,
30
+ secretAccessKey: authSession.credentials?.secretAccessKey,
31
+ expiration: authSession.credentials?.expiration,
32
+ authenticated: true
33
+ });
34
+ }
25
35
  } catch (err) {
26
36
  console.error(err?.message);
27
37
  credentials = void 0;
@@ -31,7 +41,16 @@ var fetchQuery = async (operation, variables) => {
31
41
  if (credentials) {
32
42
  headers["x-credentials"] = credentials;
33
43
  }
34
- const response = await API.graphql(graphqlOperation(operation.text, variables), headers);
44
+ const response = await post({
45
+ apiName: operation.name,
46
+ path: operation.text ?? "",
47
+ options: {
48
+ headers,
49
+ body: JSON.stringify({
50
+ variables
51
+ })
52
+ }
53
+ });
35
54
  return response;
36
55
  } catch (error) {
37
56
  if (error.errors && error.errors.length > 0) {
package/dist/index.js CHANGED
@@ -33,7 +33,6 @@ __export(src_exports, {
33
33
  fetchQuery: () => fetchQuery
34
34
  });
35
35
  module.exports = __toCommonJS(src_exports);
36
- var import_aws_amplify = require("aws-amplify");
37
36
  var import_relay_runtime = require("relay-runtime");
38
37
 
39
38
  // src/encodeCredentials.ts
@@ -49,11 +48,22 @@ var decodeCredentials = credentials => {
49
48
  };
50
49
 
51
50
  // src/index.ts
51
+ var import_auth = require("aws-amplify/auth");
52
+ var import_api = require("aws-amplify/api");
52
53
  var fetchQuery = async (operation, variables) => {
53
54
  let credentials;
54
55
  try {
55
- const currentCredentials = await import_aws_amplify.Auth.currentCredentials();
56
- credentials = encodeCredentials(currentCredentials);
56
+ const authSession = await (0, import_auth.fetchAuthSession)();
57
+ if (authSession.credentials && authSession.identityId && authSession.credentials?.sessionToken) {
58
+ credentials = encodeCredentials({
59
+ accessKeyId: authSession.credentials?.accessKeyId,
60
+ identityId: authSession.identityId,
61
+ sessionToken: authSession.credentials?.sessionToken,
62
+ secretAccessKey: authSession.credentials?.secretAccessKey,
63
+ expiration: authSession.credentials?.expiration,
64
+ authenticated: true
65
+ });
66
+ }
57
67
  } catch (err) {
58
68
  console.error(err?.message);
59
69
  credentials = void 0;
@@ -63,7 +73,16 @@ var fetchQuery = async (operation, variables) => {
63
73
  if (credentials) {
64
74
  headers["x-credentials"] = credentials;
65
75
  }
66
- const response = await import_aws_amplify.API.graphql((0, import_aws_amplify.graphqlOperation)(operation.text, variables), headers);
76
+ const response = await (0, import_api.post)({
77
+ apiName: operation.name,
78
+ path: operation.text ?? "",
79
+ options: {
80
+ headers,
81
+ body: JSON.stringify({
82
+ variables
83
+ })
84
+ }
85
+ });
67
86
  return response;
68
87
  } catch (error) {
69
88
  if (error.errors && error.errors.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/relay-amplify",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -20,12 +20,12 @@
20
20
  "sideEffects": false,
21
21
  "typings": "dist/index.d.ts",
22
22
  "peerDependencies": {
23
- "aws-amplify": "^5.0.0",
23
+ "aws-amplify": "^6.0.0",
24
24
  "relay-runtime": "^14.1.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/relay-runtime": "^14.1.19",
28
- "aws-amplify": "^5.3.11",
28
+ "aws-amplify": "^6.0.12",
29
29
  "jest": "^29.7.0",
30
30
  "relay-runtime": "^16.0.0",
31
31
  "tsup": "^8.0.1",
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { API, Auth, graphqlOperation } from 'aws-amplify';
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ // import { API, Auth, graphqlOperation } from 'aws-amplify';
2
3
  import {
3
4
  Environment,
4
5
  FetchFunction,
@@ -7,6 +8,8 @@ import {
7
8
  Store,
8
9
  } from 'relay-runtime';
9
10
  import { encodeCredentials } from './encodeCredentials';
11
+ import { fetchAuthSession } from 'aws-amplify/auth';
12
+ import { post } from 'aws-amplify/api';
10
13
 
11
14
  export {
12
15
  encodeCredentials,
@@ -18,9 +21,22 @@ export const fetchQuery: FetchFunction = async (operation, variables) => {
18
21
  let credentials: string | undefined;
19
22
 
20
23
  try {
21
- const currentCredentials = await Auth.currentCredentials();
24
+ const authSession = await fetchAuthSession();
22
25
 
23
- credentials = encodeCredentials(currentCredentials);
26
+ if (
27
+ authSession.credentials &&
28
+ authSession.identityId &&
29
+ authSession.credentials?.sessionToken
30
+ ) {
31
+ credentials = encodeCredentials({
32
+ accessKeyId: authSession.credentials?.accessKeyId,
33
+ identityId: authSession.identityId,
34
+ sessionToken: authSession.credentials?.sessionToken,
35
+ secretAccessKey: authSession.credentials?.secretAccessKey,
36
+ expiration: authSession.credentials?.expiration,
37
+ authenticated: true,
38
+ });
39
+ }
24
40
  } catch (err: any) {
25
41
  // eslint-disable-next-line no-console
26
42
  console.error(err?.message);
@@ -34,10 +50,14 @@ export const fetchQuery: FetchFunction = async (operation, variables) => {
34
50
  headers['x-credentials'] = credentials;
35
51
  }
36
52
 
37
- const response = await API.graphql(
38
- graphqlOperation(operation.text, variables),
39
- headers
40
- );
53
+ const response = await post({
54
+ apiName: operation.name,
55
+ path: operation.text ?? '',
56
+ options: {
57
+ headers,
58
+ body: JSON.stringify({ variables }),
59
+ },
60
+ });
41
61
 
42
62
  return response as any;
43
63
  } catch (error: any) {