@quillsql/node 0.1.7 → 0.1.8

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/index.ts +92 -35
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -11,13 +11,52 @@ interface QuillConfig {
11
11
  stagingDatabaseConnectionString?: string;
12
12
  }
13
13
 
14
+ type FieldFormat =
15
+ | "whole_number"
16
+ | "one_decimal_place"
17
+ | "two_decimal_places"
18
+ | "dollar_amount"
19
+ | "MMM_yyyy"
20
+ | "MMM_dd_yyyy"
21
+ | "MMM_dd-MMM_dd"
22
+ | "MMM_dd_hh:mm_ap_pm"
23
+ | "hh_ap_pm"
24
+ | "percent"
25
+ | "string";
26
+
27
+ interface FormattedColumn {
28
+ label: string;
29
+ field: string;
30
+ chartType: string;
31
+ format: FieldFormat;
32
+ }
33
+
34
+ interface QuillRequestMetadata {
35
+ task: string;
36
+ // a query to be run
37
+ query?: string;
38
+ // a report to be fetched
39
+ id?: string;
40
+ filters?: any[];
41
+ // dashboard item fields
42
+ name?: string;
43
+ xAxisField?: string;
44
+ yAxisFields?: FormattedColumn[];
45
+ xAxisLabel?: string;
46
+ xAxisFormat?: FieldFormat;
47
+ yAxisLabel?: string;
48
+ chartType?: string;
49
+ dashboardName?: string;
50
+ columns?: FormattedColumn[];
51
+ dateField?: { table: string; field: string };
52
+ }
53
+
14
54
  interface QuillQueryParams {
15
55
  orgId: string;
16
- task: string;
17
56
  query?: string;
18
57
  filters?: any[];
19
58
  id?: string;
20
- data?: object;
59
+ metadata: QuillRequestMetadata;
21
60
  environment?: string;
22
61
  }
23
62
 
@@ -39,17 +78,17 @@ module.exports = ({
39
78
  orgId,
40
79
  query,
41
80
  filters,
42
- task,
43
81
  id,
44
- data,
82
+ metadata,
45
83
  environment,
46
84
  }: QuillQueryParams) => {
47
85
  const targetPool = environment === "STAGING" ? stagingPool : pool;
86
+ const { task } = metadata;
48
87
 
49
88
  if (task === "query") {
50
89
  const response = await axios.post(
51
90
  "https://quill-344421.uc.r.appspot.com/validate",
52
- { query },
91
+ { query: metadata?.query },
53
92
  {
54
93
  params: {
55
94
  publicKey,
@@ -75,26 +114,38 @@ module.exports = ({
75
114
 
76
115
  if (task === "config") {
77
116
  const response = await axios.get(
78
- "https://quill-344421.uc.r.appspot.com/dashconfig",
117
+ "https://quill-344421.uc.r.appspot.com/config",
79
118
  {
80
119
  params: {
81
120
  publicKey,
82
121
  orgId,
83
122
  // @ts-ignore
84
- name: data?.name,
123
+ name: metadata?.name,
85
124
  },
86
125
  headers: {
87
126
  Authorization: `Bearer ${privateKey}`,
88
127
  },
89
128
  }
90
129
  );
91
- return response.data;
130
+ let dashConfig = response.data;
131
+ if (dashConfig.filters.length) {
132
+ for (let i = 0; i < dashConfig.filters.length; i++) {
133
+ // parse query
134
+ // run query
135
+ const queryResult = await targetPool.query(
136
+ dashConfig.filters[i].query
137
+ );
138
+ const { rows } = queryResult;
139
+ dashConfig = { options: rows };
140
+ }
141
+ }
142
+ return dashConfig;
92
143
  }
93
144
 
94
145
  if (task === "create") {
95
146
  const response = await axios.post(
96
147
  "https://quill-344421.uc.r.appspot.com/item",
97
- { data },
148
+ { ...metadata },
98
149
  {
99
150
  params: {
100
151
  publicKey,
@@ -109,41 +160,47 @@ module.exports = ({
109
160
  }
110
161
 
111
162
  if (task === "item") {
112
- const response = await axios.get(
113
- "https://quill-344421.uc.r.appspot.com/validateitem",
114
- {
115
- params:
116
- filters && filters.length
117
- ? {
118
- publicKey,
119
- orgId,
120
- filters,
121
- }
122
- : { publicKey, orgId },
123
- headers: {
124
- Authorization: `Bearer ${privateKey}`,
125
- },
126
- }
127
- );
128
- const queryResult = await targetPool.query(response.data.query);
129
- const resp = await axios.get(
130
- "https://quill-344421.uc.r.appspot.com/selfhostitem",
163
+ const response = await axios.post(
164
+ "https://quill-344421.uc.r.appspot.com/validate",
165
+ { query: metadata?.query },
131
166
  {
132
167
  params: {
133
- id,
134
- orgId,
135
168
  publicKey,
169
+ orgId,
136
170
  },
137
171
  headers: {
138
172
  Authorization: `Bearer ${privateKey}`,
139
173
  },
140
174
  }
141
175
  );
142
- return {
143
- ...resp.data,
144
- rows: queryResult.rows,
145
- fields: queryResult.fields,
146
- };
176
+ try {
177
+ const queryResult = await targetPool.query(response.data.query);
178
+ const resp = await axios.get(
179
+ "https://quill-344421.uc.r.appspot.com/selfhostitem",
180
+ {
181
+ params: {
182
+ id,
183
+ orgId,
184
+ publicKey,
185
+ },
186
+ headers: {
187
+ Authorization: `Bearer ${privateKey}`,
188
+ },
189
+ }
190
+ );
191
+ return {
192
+ ...resp.data,
193
+ rows: queryResult.rows,
194
+ fields: queryResult.fields,
195
+ };
196
+ } catch (err) {
197
+ return {
198
+ // @ts-ignore
199
+ ...err,
200
+ // @ts-ignore
201
+ errorMessage: err && err.message ? err.message : "",
202
+ };
203
+ }
147
204
  }
148
205
  },
149
206
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quillsql/node",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Quill SDK for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {