@ttoss/relay-amplify 0.4.5 → 0.4.6
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 +51 -0
- package/dist/index.js +89 -0
- package/package.json +3 -3
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { API, Auth, graphqlOperation } from "aws-amplify";
|
|
5
|
+
import { Environment, Network, RecordSource, Store } from "relay-runtime";
|
|
6
|
+
|
|
7
|
+
// src/encodeCredentials.ts
|
|
8
|
+
var encodeCredentials = credentials => {
|
|
9
|
+
return Buffer.from(JSON.stringify({
|
|
10
|
+
accessKeyId: credentials.accessKeyId,
|
|
11
|
+
secretAccessKey: credentials.secretAccessKey,
|
|
12
|
+
sessionToken: credentials.sessionToken
|
|
13
|
+
})).toString("base64");
|
|
14
|
+
};
|
|
15
|
+
var decodeCredentials = credentials => {
|
|
16
|
+
return JSON.parse(Buffer.from(credentials, "base64").toString("utf8"));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var fetchQuery = async (operation, variables) => {
|
|
21
|
+
let credentials;
|
|
22
|
+
try {
|
|
23
|
+
const currentCredentials = await Auth.currentCredentials();
|
|
24
|
+
credentials = encodeCredentials(currentCredentials);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.error(err?.message);
|
|
27
|
+
credentials = void 0;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const headers = {};
|
|
31
|
+
if (credentials) {
|
|
32
|
+
headers["x-credentials"] = credentials;
|
|
33
|
+
}
|
|
34
|
+
const response = await API.graphql(graphqlOperation(operation.text, variables), headers);
|
|
35
|
+
return response;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (error.errors && error.errors.length > 0) {
|
|
38
|
+
throw error.errors[0];
|
|
39
|
+
}
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var createEnvironment = ({
|
|
44
|
+
storeOptions
|
|
45
|
+
}) => {
|
|
46
|
+
return new Environment({
|
|
47
|
+
network: Network.create(fetchQuery),
|
|
48
|
+
store: new Store(new RecordSource(), storeOptions)
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
export { createEnvironment, decodeCredentials, encodeCredentials, fetchQuery };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
24
|
+
value: true
|
|
25
|
+
}), mod);
|
|
26
|
+
|
|
27
|
+
// src/index.ts
|
|
28
|
+
var src_exports = {};
|
|
29
|
+
__export(src_exports, {
|
|
30
|
+
createEnvironment: () => createEnvironment,
|
|
31
|
+
decodeCredentials: () => decodeCredentials,
|
|
32
|
+
encodeCredentials: () => encodeCredentials,
|
|
33
|
+
fetchQuery: () => fetchQuery
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
var import_aws_amplify = require("aws-amplify");
|
|
37
|
+
var import_relay_runtime = require("relay-runtime");
|
|
38
|
+
|
|
39
|
+
// src/encodeCredentials.ts
|
|
40
|
+
var encodeCredentials = credentials => {
|
|
41
|
+
return Buffer.from(JSON.stringify({
|
|
42
|
+
accessKeyId: credentials.accessKeyId,
|
|
43
|
+
secretAccessKey: credentials.secretAccessKey,
|
|
44
|
+
sessionToken: credentials.sessionToken
|
|
45
|
+
})).toString("base64");
|
|
46
|
+
};
|
|
47
|
+
var decodeCredentials = credentials => {
|
|
48
|
+
return JSON.parse(Buffer.from(credentials, "base64").toString("utf8"));
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/index.ts
|
|
52
|
+
var fetchQuery = async (operation, variables) => {
|
|
53
|
+
let credentials;
|
|
54
|
+
try {
|
|
55
|
+
const currentCredentials = await import_aws_amplify.Auth.currentCredentials();
|
|
56
|
+
credentials = encodeCredentials(currentCredentials);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
console.error(err?.message);
|
|
59
|
+
credentials = void 0;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const headers = {};
|
|
63
|
+
if (credentials) {
|
|
64
|
+
headers["x-credentials"] = credentials;
|
|
65
|
+
}
|
|
66
|
+
const response = await import_aws_amplify.API.graphql((0, import_aws_amplify.graphqlOperation)(operation.text, variables), headers);
|
|
67
|
+
return response;
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error.errors && error.errors.length > 0) {
|
|
70
|
+
throw error.errors[0];
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var createEnvironment = ({
|
|
76
|
+
storeOptions
|
|
77
|
+
}) => {
|
|
78
|
+
return new import_relay_runtime.Environment({
|
|
79
|
+
network: import_relay_runtime.Network.create(fetchQuery),
|
|
80
|
+
store: new import_relay_runtime.Store(new import_relay_runtime.RecordSource(), storeOptions)
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
createEnvironment,
|
|
86
|
+
decodeCredentials,
|
|
87
|
+
encodeCredentials,
|
|
88
|
+
fetchQuery
|
|
89
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/relay-amplify",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"relay-runtime": "^14.1.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@ttoss/config": "^1.29.
|
|
27
|
+
"@ttoss/config": "^1.29.5",
|
|
28
28
|
"@types/relay-runtime": "^14.1.10",
|
|
29
29
|
"aws-amplify": "^5.0.25",
|
|
30
30
|
"jest": "^29.5.0",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "f30779a5ea50d60cf3099e5fde712e1ef7b7882c"
|
|
39
39
|
}
|