@symbo.ls/fetch 2.11.475 → 2.11.511
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 +72 -0
- package/package.json +19 -11
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as utils from "@domql/utils";
|
|
2
|
+
import * as globals from "@domql/globals";
|
|
3
|
+
const { overwriteDeep, deepDestringify } = utils;
|
|
4
|
+
const { window } = globals;
|
|
5
|
+
const IS_DEVELOPMENT = window && window.location ? window.location.host.includes("dev.") : true;
|
|
6
|
+
const SERVER_URL = IS_DEVELOPMENT ? "http://localhost:13335/get" : "https://api.symbols.app/get";
|
|
7
|
+
const defaultOptions = {
|
|
8
|
+
endpoint: SERVER_URL
|
|
9
|
+
};
|
|
10
|
+
const fetch = globalThis.fetch;
|
|
11
|
+
const fetchRemote = async (key, options = defaultOptions) => {
|
|
12
|
+
const baseUrl = options.endpoint || SERVER_URL;
|
|
13
|
+
const route = options.serviceRoute ? utils.isArray(options.serviceRoute) ? options.serviceRoute.map((v) => v.toLowerCase() + "=true").join("&") : options.serviceRoute : "";
|
|
14
|
+
let response;
|
|
15
|
+
try {
|
|
16
|
+
response = await fetch(baseUrl + "/?" + route, {
|
|
17
|
+
method: "GET",
|
|
18
|
+
headers: { "Content-Type": "application/json", "X-AppKey": key, "X-Metadata": options.metadata }
|
|
19
|
+
});
|
|
20
|
+
return await response.json();
|
|
21
|
+
} catch (e) {
|
|
22
|
+
if (utils.isFunction(options.onError))
|
|
23
|
+
return options.onError(e);
|
|
24
|
+
else
|
|
25
|
+
console.error(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const fetchProject = async (key, options) => {
|
|
29
|
+
const { editor } = options;
|
|
30
|
+
if (editor && editor.remote) {
|
|
31
|
+
const data = await fetchRemote(key, editor);
|
|
32
|
+
const evalData = IS_DEVELOPMENT || options.isDevelopment ? deepDestringify(data) : deepDestringify(data.releases[0]);
|
|
33
|
+
if (editor.serviceRoute) {
|
|
34
|
+
if (utils.isArray(editor.serviceRoute)) {
|
|
35
|
+
editor.serviceRoute.forEach((route) => {
|
|
36
|
+
overwriteDeep(options[route], evalData[route.toLowerCase()]);
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
overwriteDeep(options[editor.serviceRoute], evalData);
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
[
|
|
43
|
+
"state",
|
|
44
|
+
"designSystem",
|
|
45
|
+
"components",
|
|
46
|
+
"snippets",
|
|
47
|
+
"pages",
|
|
48
|
+
"utils",
|
|
49
|
+
"files",
|
|
50
|
+
"packages",
|
|
51
|
+
"functions"
|
|
52
|
+
].forEach((key2) => {
|
|
53
|
+
overwriteDeep(options[key2], evalData[key2.toLowerCase()]);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return options;
|
|
58
|
+
};
|
|
59
|
+
const fetchProjectAsync = async (key, options, callback) => {
|
|
60
|
+
const { editor } = options;
|
|
61
|
+
if (editor && editor.remote) {
|
|
62
|
+
const data = await fetchRemote(key, editor);
|
|
63
|
+
const evalData = IS_DEVELOPMENT || options.isDevelopment ? deepDestringify(data) : deepDestringify(data.releases[0]);
|
|
64
|
+
callback(evalData);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
export {
|
|
68
|
+
fetch,
|
|
69
|
+
fetchProject,
|
|
70
|
+
fetchProjectAsync,
|
|
71
|
+
fetchRemote
|
|
72
|
+
};
|
package/package.json
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/fetch",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.511",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"gitHead": "
|
|
5
|
+
"gitHead": "6906b1d6a1aa7c7d9468d76895062144ffde2cc6",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"module": "index.js",
|
|
8
8
|
"main": "index.js",
|
|
9
|
-
"
|
|
9
|
+
"unpkg": "dist/iife/index.js",
|
|
10
|
+
"jsdelivr": "dist/iife/index.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"default": "./dist/esm/index.js",
|
|
14
|
+
"import": "./dist/esm/index.js",
|
|
15
|
+
"require": "./dist/cjs/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
10
18
|
"source": "index.js",
|
|
11
19
|
"files": [
|
|
12
20
|
"*.js",
|
|
13
21
|
"dist"
|
|
14
22
|
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
25
|
+
"build:esm": "npx esbuild *.js --target=es2017 --format=esm --outdir=dist/esm",
|
|
26
|
+
"build:cjs": "npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs",
|
|
27
|
+
"build:iife": "npx esbuild *.js --target=node16 --format=iife --outdir=dist/iife",
|
|
28
|
+
"build": "rimraf -I dist; npm run build:cjs; npm run build:esm",
|
|
29
|
+
"prepublish": "npm run build; npm run copy:package:cjs"
|
|
30
|
+
},
|
|
15
31
|
"dependencies": {
|
|
16
32
|
"@domql/globals": "latest",
|
|
17
33
|
"@domql/utils": "^2.5.0"
|
|
18
|
-
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
21
|
-
"build:esm": "npx esbuild ./index.js --target=es2017 --format=esm --outdir=dist/esm",
|
|
22
|
-
"build:cjs": "npx esbuild ./index.js --target=node16 --format=cjs --outdir=dist/cjs",
|
|
23
|
-
"build:iife": "npx esbuild ./index.js --target=es2017 --format=iife --outdir=dist/iife --bundle --minify",
|
|
24
|
-
"build": "npm run build:cjs && npm run copy:package:cjs",
|
|
25
|
-
"prepublish": "rimraf -I dist && npm run build"
|
|
26
34
|
}
|
|
27
35
|
}
|