@ttoss/relay-amplify 0.6.1 → 0.6.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/relay-amplify",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -33,7 +33,7 @@
33
33
  "jest": "^29.7.0",
34
34
  "relay-runtime": "^16.2.0",
35
35
  "tsup": "^8.3.0",
36
- "@ttoss/config": "^1.32.10"
36
+ "@ttoss/config": "^1.33.0"
37
37
  },
38
38
  "keywords": [],
39
39
  "publishConfig": {
package/dist/esm/index.js DELETED
@@ -1,70 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
-
3
- // src/index.ts
4
- import { Environment, Network, RecordSource, Store } from "relay-runtime";
5
-
6
- // src/encodeCredentials.ts
7
- var encodeCredentials = credentials => {
8
- return Buffer.from(JSON.stringify({
9
- accessKeyId: credentials.accessKeyId,
10
- secretAccessKey: credentials.secretAccessKey,
11
- sessionToken: credentials.sessionToken
12
- })).toString("base64");
13
- };
14
- var decodeCredentials = credentials => {
15
- return JSON.parse(Buffer.from(credentials, "base64").toString("utf8"));
16
- };
17
-
18
- // src/index.ts
19
- import { fetchAuthSession } from "aws-amplify/auth";
20
- import { post } from "aws-amplify/api";
21
- var fetchQuery = async (operation, variables) => {
22
- let credentials;
23
- try {
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
- }
35
- } catch (err) {
36
- console.error(err?.message);
37
- credentials = void 0;
38
- }
39
- try {
40
- const headers = {};
41
- if (credentials) {
42
- headers["x-credentials"] = credentials;
43
- }
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
- });
54
- return response;
55
- } catch (error) {
56
- if (error.errors && error.errors.length > 0) {
57
- throw error.errors[0];
58
- }
59
- throw error;
60
- }
61
- };
62
- var createEnvironment = ({
63
- storeOptions
64
- }) => {
65
- return new Environment({
66
- network: Network.create(fetchQuery),
67
- store: new Store(new RecordSource(), storeOptions)
68
- });
69
- };
70
- export { createEnvironment, decodeCredentials, encodeCredentials, fetchQuery };
package/dist/index.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import { FetchFunction, Environment } from 'relay-runtime';
2
-
3
- interface ICredentials {
4
- accessKeyId: string;
5
- sessionToken: string;
6
- secretAccessKey: string;
7
- identityId: string;
8
- authenticated: boolean;
9
- expiration?: Date;
10
- }
11
- declare const encodeCredentials: (credentials: ICredentials) => string;
12
- declare const decodeCredentials: (credentials: string) => any;
13
-
14
- declare const fetchQuery: FetchFunction;
15
- declare const createEnvironment: ({ storeOptions }: {
16
- storeOptions?: any;
17
- }) => Environment;
18
-
19
- export { type ICredentials, createEnvironment, decodeCredentials, encodeCredentials, fetchQuery };