@symbo.ls/fetch 2.11.16 → 2.11.32
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/cjs/index.js +7 -5
- package/index.js +23 -8
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -38,14 +38,15 @@ var utils = __toESM(require("@domql/utils"), 1);
|
|
|
38
38
|
var globals = __toESM(require("@domql/globals"), 1);
|
|
39
39
|
const { overwriteDeep, deepDestringify, isObject } = utils;
|
|
40
40
|
const { window } = globals;
|
|
41
|
-
const
|
|
41
|
+
const IS_DEVELOPMENT = window && window.location ? window.location.host.includes("dev") || window.location.host.includes("symbo.ls") : true;
|
|
42
|
+
const SERVER_URL = IS_DEVELOPMENT ? "localhost:13335" : "https://api.symbols.dev";
|
|
42
43
|
const defaultOptions = {
|
|
43
44
|
endpoint: SERVER_URL
|
|
44
45
|
};
|
|
45
46
|
const fetch = globalThis.fetch;
|
|
46
47
|
const fetchRemote = async (key, options = defaultOptions) => {
|
|
47
|
-
const baseUrl = `https://${options.endpoint
|
|
48
|
-
const route = options.serviceRoute
|
|
48
|
+
const baseUrl = options.endpoint ? options.endpoint.includes("http") ? options.endpoint : `https://${options.endpoint}/` : SERVER_URL;
|
|
49
|
+
const route = options.serviceRoute ? utils.isArray(options.serviceRoute) ? options.serviceRoute.join(",") : options.serviceRoute : "";
|
|
49
50
|
let response;
|
|
50
51
|
try {
|
|
51
52
|
response = await fetch(baseUrl + route, {
|
|
@@ -61,7 +62,7 @@ const fetchProject = async (key, options) => {
|
|
|
61
62
|
const { editor } = options;
|
|
62
63
|
if (editor && editor.remote) {
|
|
63
64
|
const data = await fetchRemote(key, editor);
|
|
64
|
-
const evalData = deepDestringify(data);
|
|
65
|
+
const evalData = IS_DEVELOPMENT ? deepDestringify(data) : deepDestringify(data.releases[0]);
|
|
65
66
|
if (editor.serviceRoute) {
|
|
66
67
|
overwriteDeep(evalData, options[editor.serviceRoute]);
|
|
67
68
|
} else {
|
|
@@ -76,7 +77,8 @@ const fetchStateAsync = async (key, options, callback) => {
|
|
|
76
77
|
const { editor } = options;
|
|
77
78
|
if (editor && editor.remote) {
|
|
78
79
|
const data = await fetchRemote(key, editor);
|
|
79
|
-
const
|
|
80
|
+
const evalData = IS_DEVELOPMENT ? deepDestringify(data) : deepDestringify(data.releases[0]);
|
|
81
|
+
const state = editor.serviceRoute === "state" ? evalData.state : evalData;
|
|
80
82
|
if (isObject(state))
|
|
81
83
|
callback(state);
|
|
82
84
|
}
|
package/index.js
CHANGED
|
@@ -6,11 +6,13 @@ import * as globals from '@domql/globals'
|
|
|
6
6
|
const { overwriteDeep, deepDestringify, isObject } = utils
|
|
7
7
|
const { window } = globals
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
window.location.host.includes('
|
|
9
|
+
const IS_DEVELOPMENT = window && window.location
|
|
10
|
+
? window.location.host.includes('dev') || window.location.host.includes('symbo.ls')
|
|
11
|
+
: process.env.NODE_ENV === 'development'
|
|
12
|
+
|
|
13
|
+
const SERVER_URL = IS_DEVELOPMENT
|
|
11
14
|
? 'localhost:13335'
|
|
12
|
-
: 'https://api.symbols.dev'
|
|
13
|
-
'https://api.symbols.dev'
|
|
15
|
+
: 'https://api.symbols.dev'
|
|
14
16
|
|
|
15
17
|
const defaultOptions = {
|
|
16
18
|
endpoint: SERVER_URL
|
|
@@ -19,8 +21,16 @@ const defaultOptions = {
|
|
|
19
21
|
export const fetch = globalThis.fetch
|
|
20
22
|
|
|
21
23
|
export const fetchRemote = async (key, options = defaultOptions) => {
|
|
22
|
-
const baseUrl =
|
|
23
|
-
|
|
24
|
+
const baseUrl = options.endpoint
|
|
25
|
+
? options.endpoint.includes('http')
|
|
26
|
+
? options.endpoint
|
|
27
|
+
: `https://${options.endpoint}/`
|
|
28
|
+
: SERVER_URL
|
|
29
|
+
const route = options.serviceRoute
|
|
30
|
+
? utils.isArray(options.serviceRoute)
|
|
31
|
+
? options.serviceRoute.join(',')
|
|
32
|
+
: options.serviceRoute
|
|
33
|
+
: ''
|
|
24
34
|
|
|
25
35
|
let response
|
|
26
36
|
try {
|
|
@@ -40,7 +50,9 @@ export const fetchProject = async (key, options) => {
|
|
|
40
50
|
|
|
41
51
|
if (editor && editor.remote) {
|
|
42
52
|
const data = await fetchRemote(key, editor)
|
|
43
|
-
const evalData =
|
|
53
|
+
const evalData = IS_DEVELOPMENT
|
|
54
|
+
? deepDestringify(data)
|
|
55
|
+
: deepDestringify(data.releases[0])
|
|
44
56
|
|
|
45
57
|
if (editor.serviceRoute) {
|
|
46
58
|
overwriteDeep(evalData, options[editor.serviceRoute])
|
|
@@ -59,7 +71,10 @@ export const fetchStateAsync = async (key, options, callback) => {
|
|
|
59
71
|
|
|
60
72
|
if (editor && editor.remote) {
|
|
61
73
|
const data = await fetchRemote(key, editor)
|
|
62
|
-
const
|
|
74
|
+
const evalData = IS_DEVELOPMENT
|
|
75
|
+
? deepDestringify(data)
|
|
76
|
+
: deepDestringify(data.releases[0])
|
|
77
|
+
const state = editor.serviceRoute === 'state' ? evalData.state : evalData
|
|
63
78
|
if (isObject(state)) callback(state)
|
|
64
79
|
}
|
|
65
80
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/fetch",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.32",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"gitHead": "
|
|
5
|
+
"gitHead": "cd6537b696e8dbb935e5334947a378038bd3770e",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"module": "index.js",
|
|
8
8
|
"main": "index.js",
|