@symbo.ls/fetch 0.0.1 → 2.4.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/index.js +45 -0
- package/package.json +5 -19
- package/src/index.js +0 -75
package/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { client, fetch } from '@symbo.ls/based'
|
|
4
|
+
|
|
5
|
+
export const fetchIcon = async (el, s, { icon }) => {
|
|
6
|
+
await client.observe({
|
|
7
|
+
$id: icon,
|
|
8
|
+
$all: true
|
|
9
|
+
}, (data) => {
|
|
10
|
+
s.update({ icon: data })
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const fetchProject = (el, s, { userName, projectId }) => {
|
|
15
|
+
fetch({
|
|
16
|
+
$id: projectId,
|
|
17
|
+
$all: true
|
|
18
|
+
}, async data => {
|
|
19
|
+
console.log(data)
|
|
20
|
+
const { key, name, state, icon, system } = data
|
|
21
|
+
|
|
22
|
+
if (system) s.SYSTEM = { ...system }
|
|
23
|
+
if (state) s.STATE = { ...state }
|
|
24
|
+
|
|
25
|
+
s.update({
|
|
26
|
+
appKey: key,
|
|
27
|
+
projectName: name,
|
|
28
|
+
userName,
|
|
29
|
+
projectId
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
fetchIcon(el, s, { icon })
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const fetchUser = (el, s) => {
|
|
37
|
+
fetch({ $id: s.userId, name: true, projects: true }, data => {
|
|
38
|
+
const { projects } = data
|
|
39
|
+
const userName = data.name
|
|
40
|
+
if (projects) {
|
|
41
|
+
const projectId = projects[0]
|
|
42
|
+
fetchProject(el, s, { userName, projectId })
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/fetch",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"scripts": {
|
|
8
|
-
"watch": "parcel watch --no-cache",
|
|
9
|
-
"build": "parcel build --no-cache"
|
|
3
|
+
"version": "2.4.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@symbo.ls/based": "latest"
|
|
10
7
|
},
|
|
11
|
-
"
|
|
12
|
-
"license": "ISC",
|
|
13
|
-
"dependencies": {},
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
"@babel/core": "^7.11.5",
|
|
16
|
-
"babel-eslint": "^10.0.3",
|
|
17
|
-
"eslint": "^6.1.0",
|
|
18
|
-
"standard": "^13.1.0"
|
|
19
|
-
},
|
|
20
|
-
"standard": {
|
|
21
|
-
"parser": "babel-eslint"
|
|
22
|
-
}
|
|
8
|
+
"devDependencies": {}
|
|
23
9
|
}
|
package/src/index.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
export const API_URL = 'https://api.symbols.app/v1/graphql'
|
|
4
|
-
|
|
5
|
-
export const READ_WAITLIST_USER = (email) => `
|
|
6
|
-
query {
|
|
7
|
-
waitlist(where: {email: {_eq: "${email}"}}) {
|
|
8
|
-
full_name
|
|
9
|
-
role_id
|
|
10
|
-
ui_framework_id
|
|
11
|
-
design_tool_id
|
|
12
|
-
company_name
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
`
|
|
16
|
-
|
|
17
|
-
export const READ_COMPANY = (email) => `
|
|
18
|
-
query {
|
|
19
|
-
companies {
|
|
20
|
-
design_tool_id
|
|
21
|
-
id
|
|
22
|
-
name
|
|
23
|
-
state_json
|
|
24
|
-
theme_id
|
|
25
|
-
ui_framework_id
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
`
|
|
29
|
-
|
|
30
|
-
export const CREATE_WAITLIST_USER_QUERY = (s) => `
|
|
31
|
-
mutation {
|
|
32
|
-
insert_waitlist(objects: {full_name: "${s.full_name}", email: "${s.email}", company_name: "${s.company_name || ''}", role_id: ${s.role_id || null}, ui_framework_id: ${s.ui_framework_id || null}, design_tool_id: ${s.design_tool_id || null}}) {
|
|
33
|
-
returning {
|
|
34
|
-
id
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
`
|
|
39
|
-
|
|
40
|
-
export const UPDATE_WAITLIST_USER_QUERY = (id, key, value) => `
|
|
41
|
-
mutation {
|
|
42
|
-
update_waitlist(where: {id: {_eq: "${id}"}}, _set: {${key}: "${value}"}) {
|
|
43
|
-
returning {
|
|
44
|
-
id
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
`
|
|
49
|
-
|
|
50
|
-
export const fetch = (query, fallback) => {
|
|
51
|
-
window.fetch(API_URL, {
|
|
52
|
-
method: 'POST',
|
|
53
|
-
headers: {
|
|
54
|
-
Accept: 'application/json',
|
|
55
|
-
'Content-Type': 'application/json'
|
|
56
|
-
},
|
|
57
|
-
body: JSON.stringify({ query })
|
|
58
|
-
})
|
|
59
|
-
.then(r => r.json())
|
|
60
|
-
.then(data => fallback(data))
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export const fetchAuth = async (token, query, fallback) => {
|
|
64
|
-
window.fetch(API_URL, {
|
|
65
|
-
method: 'POST',
|
|
66
|
-
headers: {
|
|
67
|
-
Accept: 'application/json',
|
|
68
|
-
'Content-Type': 'application/json',
|
|
69
|
-
Authorization: `Bearer ${token}`
|
|
70
|
-
},
|
|
71
|
-
body: JSON.stringify({ query })
|
|
72
|
-
})
|
|
73
|
-
.then(r => r.json())
|
|
74
|
-
.then(data => fallback(data))
|
|
75
|
-
}
|