@symbo.ls/fetch 2.11.16 → 2.11.26

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