@symbo.ls/fetch 2.8.4 → 2.9.6

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.
Files changed (3) hide show
  1. package/.eslintrc.js +9 -0
  2. package/index.js +14 -115
  3. package/package.json +5 -9
package/.eslintrc.js ADDED
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ "extends": "standard",
3
+ "env": {
4
+ "es6": true,
5
+ "browser": true,
6
+ "node": true,
7
+ "jest": true
8
+ }
9
+ }
package/index.js CHANGED
@@ -1,118 +1,17 @@
1
1
  'use strict'
2
2
 
3
- import { client, fetch, set } from '@symbo.ls/based'
4
- import { deepMerge, isObject } from '@domql/utils'
5
- import { setCookie } from '@domql/cookie'
6
-
7
- import TMP_DATA from '@symbo.ls/temp-db'
8
- import CONFIG_DEFAULT from '@symbo.ls/default-config'
9
-
10
- export const fetchIcon = async (el, s, { icon }) => {
11
- await client.observe({
12
- $id: icon,
13
- $all: true
14
- }, async (data) => {
15
- await client.set({
16
- $id: s.projectId,
17
- icon
18
- }, d => console.log('d', d))
19
- s.update({ icon: data })
20
- })
21
- }
22
-
23
- export const syncSystem = (data, el, s) => {
24
- let temporaryProject = TMP_DATA[s.appKey]
25
- if (!temporaryProject) temporaryProject = {}
26
- const { SYSTEM, STATE } = temporaryProject
27
- let { system, state } = data
28
-
29
- const defObjs = {
30
- system: SYSTEM || CONFIG_DEFAULT,
31
- state: STATE || {}
32
- }
33
-
34
- if (isObject(system)) {
35
- deepMerge(system, defObjs.system)
36
- } else {
37
- system = defObjs.system
38
- // set({ $id: s.projectId, system: defObjs.system })
39
- }
40
-
41
- if (isObject(state)) {
42
- deepMerge(state, defObjs.state)
43
- } else {
44
- state = defObjs.state
45
- // set({ $id: s.projectId, state: defObjs.state })
46
- }
47
-
48
- // deepMerge(s.PROJECT_SYSTEM, system)
49
- // deepMerge(s.PROJECT_STATE, state)
50
- s.PROJECT_SYSTEM = system
51
- s.PROJECT_STATE = state
52
- s.update({ loading: false })
53
- }
54
-
55
- export const publishSystem = (el, s, changes) => {
56
- if (changes.PROJECT_SYSTEM) {
57
- set({ $id: s.projectId, system: s.PROJECT_SYSTEM })
58
- } if (changes.PROJECT_STATE) {
59
- set({ $id: s.projectId, state: s.PROJECT_STATE })
60
- }
61
- }
62
-
63
- export const fetchProject = (el, s, { userName, projectId, activeProject, ...options }) => {
64
- fetch({
65
- $id: projectId,
66
- $all: true,
67
- icon: {
68
- src: true
69
- }
70
- }, data => {
71
- const { key, name, icon } = data
72
-
73
- setCookie('appKey', key)
74
- setCookie('activeProject', activeProject)
75
-
76
- s.update({
77
- appKey: key,
78
- projectName: name,
79
- projectId: projectId,
80
- icon,
81
- activeProject
82
- }, options)
83
-
84
- syncSystem(data, el, s)
3
+ const BACKEND_URL = window.location
4
+ .host.includes('local')
5
+ ? 'localhost:13335'
6
+ : 'api.symbols.app'
7
+
8
+ export const fetch = async (key, route) => {
9
+ let data = {}
10
+ await window.fetch(`https://${BACKEND_URL}/${route || ''}`, {
11
+ method: 'GET',
12
+ headers: { 'Content-Type': 'application/json', 'X-AppKey': key }
13
+ }).then((response) => {
14
+ return response.json().then(d => data = d)
85
15
  })
86
- }
87
-
88
- export const fetchUser = (el, s, options) => {
89
- const { userName, projectId, activeProject } = s
90
- if (!userName || !projectId) {
91
- fetch({
92
- $id: s.userId,
93
- name: true,
94
- projects: {
95
- id: true,
96
- name: true,
97
- key: true,
98
- icon: {
99
- src: true
100
- },
101
- $list: true
102
- }
103
- }, data => {
104
- const { projects } = data
105
- const userName = data.name
106
- if (projects) {
107
- s.update({ userName, projects })
108
- const activeProjectData = projects[s.activeProject || 0]
109
- const projectId = activeProjectData && activeProjectData.id
110
- fetchProject(el, s, { userName, projectId, activeProject, ...options })
111
- }
112
- })
113
- } else {
114
- fetchProject(el, s, {
115
- userName, projectId, activeProject, ...options
116
- })
117
- }
118
- }
16
+ return data
17
+ }
package/package.json CHANGED
@@ -1,13 +1,9 @@
1
1
  {
2
2
  "name": "@symbo.ls/fetch",
3
- "version": "2.8.4",
3
+ "version": "2.9.6",
4
+ "license": "MIT",
5
+ "gitHead": "6378f05ba88065ef932810a1582f45e0384feafc",
6
+ "source": "index.js",
4
7
  "main": "index.js",
5
- "dependencies": {
6
- "@domql/cookie": "latest",
7
- "@domql/utils": "latest",
8
- "@symbo.ls/based": "latest",
9
- "@symbo.ls/default-config": "latest",
10
- "@symbo.ls/temp-db": "latest"
11
- },
12
- "gitHead": "ae50e3a533b6e94ef7136cda4b2f674d40f70086"
8
+ "dependencies": {}
13
9
  }