@symbo.ls/fetch 2.11.475 → 2.25.1

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