@arena-ui/services 1.0.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/get_service.js ADDED
@@ -0,0 +1,9 @@
1
+ import { SERVICES } from "./load_services.js";
2
+
3
+ const get_service = (name) => {
4
+ let config = SERVICES[name];
5
+
6
+ return config;
7
+ };
8
+
9
+ export default get_service;
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import get_service from "./get_service";
2
+ import load_services from "./load_services";
3
+ import post_request from "./post_request";
4
+
5
+ export { post_request, get_service, load_services };
@@ -0,0 +1,10 @@
1
+ const SERVICES = {};
2
+
3
+ const load_services = async (config) => {
4
+ for (let service in config) {
5
+ SERVICES[service] = config[service];
6
+ }
7
+ };
8
+
9
+ export default load_services;
10
+ export { SERVICES };
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@arena-ui/services",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "license": "ISC",
6
+ "author": "Savvy",
7
+ "type": "module",
8
+ "main": "index.js",
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ }
12
+ }
@@ -0,0 +1,48 @@
1
+ import { PROD } from "@env";
2
+ import get_service from "./get_service.js";
3
+
4
+ const post_request = async (url, body) => {
5
+ let response;
6
+
7
+ if (url.startsWith("$")) {
8
+ url = url.split("$");
9
+ url = [url[0], url.slice(1).join("$")];
10
+
11
+ let config = get_service(url[0]);
12
+
13
+ let domain = config.url || {};
14
+
15
+ domain = domain[PROD ? "prod" : "dev"];
16
+
17
+ if (!domain) {
18
+ return {
19
+ ok: false,
20
+ message: "Missing Domain Name.",
21
+ };
22
+ }
23
+ url = `${domain}/${url[1]}`;
24
+ }
25
+
26
+ try {
27
+ let ftch = await fetch(url, {
28
+ method: "POST",
29
+ headers: {
30
+ "Content-Type": "application/json",
31
+ Accept: "application/json",
32
+ },
33
+ body: JSON.stringify(body),
34
+ });
35
+
36
+ response = await ftch.json();
37
+ } catch (e) {
38
+ console.log(e);
39
+ response = {
40
+ ok: false,
41
+ message: e.message,
42
+ };
43
+ }
44
+
45
+ return response;
46
+ };
47
+
48
+ export default post_request;