@ttoss/relay-amplify 0.5.16 → 0.6.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/package.json +4 -4
- package/dist/index.d.mts +0 -19
- package/dist/index.js +0 -108
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/relay-amplify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"url": "https://github.com/ttoss/ttoss.git",
|
|
12
12
|
"directory": "packages/relay-amplify"
|
|
13
13
|
},
|
|
14
|
+
"type": "module",
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
17
|
"import": "./dist/esm/index.js",
|
|
17
|
-
"require": "./dist/index.js",
|
|
18
18
|
"types": "./dist/index.d.ts"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"jest": "^29.7.0",
|
|
34
34
|
"relay-runtime": "^16.2.0",
|
|
35
35
|
"tsup": "^8.2.4",
|
|
36
|
-
"@ttoss/config": "^1.32.
|
|
36
|
+
"@ttoss/config": "^1.32.9"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [],
|
|
39
39
|
"publishConfig": {
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsup",
|
|
45
|
-
"test": "jest"
|
|
45
|
+
"test": "jest --projects tests/unit"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/dist/index.d.mts
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 };
|
package/dist/index.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
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_relay_runtime = require("relay-runtime");
|
|
37
|
-
|
|
38
|
-
// src/encodeCredentials.ts
|
|
39
|
-
var encodeCredentials = credentials => {
|
|
40
|
-
return Buffer.from(JSON.stringify({
|
|
41
|
-
accessKeyId: credentials.accessKeyId,
|
|
42
|
-
secretAccessKey: credentials.secretAccessKey,
|
|
43
|
-
sessionToken: credentials.sessionToken
|
|
44
|
-
})).toString("base64");
|
|
45
|
-
};
|
|
46
|
-
var decodeCredentials = credentials => {
|
|
47
|
-
return JSON.parse(Buffer.from(credentials, "base64").toString("utf8"));
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// src/index.ts
|
|
51
|
-
var import_auth = require("aws-amplify/auth");
|
|
52
|
-
var import_api = require("aws-amplify/api");
|
|
53
|
-
var fetchQuery = async (operation, variables) => {
|
|
54
|
-
let credentials;
|
|
55
|
-
try {
|
|
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
|
-
}
|
|
67
|
-
} catch (err) {
|
|
68
|
-
console.error(err?.message);
|
|
69
|
-
credentials = void 0;
|
|
70
|
-
}
|
|
71
|
-
try {
|
|
72
|
-
const headers = {};
|
|
73
|
-
if (credentials) {
|
|
74
|
-
headers["x-credentials"] = credentials;
|
|
75
|
-
}
|
|
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
|
-
});
|
|
86
|
-
return response;
|
|
87
|
-
} catch (error) {
|
|
88
|
-
if (error.errors && error.errors.length > 0) {
|
|
89
|
-
throw error.errors[0];
|
|
90
|
-
}
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
var createEnvironment = ({
|
|
95
|
-
storeOptions
|
|
96
|
-
}) => {
|
|
97
|
-
return new import_relay_runtime.Environment({
|
|
98
|
-
network: import_relay_runtime.Network.create(fetchQuery),
|
|
99
|
-
store: new import_relay_runtime.Store(new import_relay_runtime.RecordSource(), storeOptions)
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
-
0 && (module.exports = {
|
|
104
|
-
createEnvironment,
|
|
105
|
-
decodeCredentials,
|
|
106
|
-
encodeCredentials,
|
|
107
|
-
fetchQuery
|
|
108
|
-
});
|