@symbo.ls/fetch 0.0.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.
Files changed (2) hide show
  1. package/package.json +23 -0
  2. package/src/index.js +75 -0
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@symbo.ls/fetch",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "source": "src/index.js",
6
+ "main": "src/index.js",
7
+ "scripts": {
8
+ "watch": "parcel watch --no-cache",
9
+ "build": "parcel build --no-cache"
10
+ },
11
+ "author": "",
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
+ }
23
+ }
package/src/index.js ADDED
@@ -0,0 +1,75 @@
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
+ }