create-dovite 2.0.0 → 2.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.
@@ -0,0 +1,311 @@
1
+ import domo from "ryuu.js";
2
+ // import Download from "downloadjs";
3
+
4
+ const BASE_URL = "/domo/datastores/v1";
5
+
6
+ const GetCurrentUser = () => {
7
+ return domo
8
+ .get("/domo/environment/v1")
9
+ .then((user) => ({
10
+ ...user,
11
+ displayName: user.userName,
12
+ avatarKey: `/domo/avatars/v2/USER/${user.userId}`,
13
+ }))
14
+ .catch((error) => {
15
+ console.error("Error getting current user:", error);
16
+ throw error;
17
+ });
18
+ };
19
+
20
+ const GetAllUser = () => {
21
+ return domo
22
+ .get(`/domo/users/v1?limit={500}`)
23
+ .then((response) => response)
24
+ .catch((error) => {
25
+ console.error("Error getting All users:", error);
26
+ throw error;
27
+ });
28
+ };
29
+
30
+ const GetUser = (userId) => {
31
+ return domo
32
+ .get(`/domo/users/v1/${userId}?includeDetails=true`)
33
+ .then((user) => ({ ...user, userName: user.displayName }))
34
+ .catch((error) => {
35
+ console.error("Error getting user:", error);
36
+ throw error;
37
+ });
38
+ };
39
+
40
+ const CreateDocument = (collectionName, document) => {
41
+ console.log(document);
42
+ console.log(collectionName);
43
+
44
+ return domo
45
+ .post(`${BASE_URL}/collections/${collectionName}/documents/`, {
46
+ content: document,
47
+ })
48
+ .then((response) => response)
49
+ .catch((error) => {
50
+ console.error("Error creating document:", error);
51
+ throw error;
52
+ });
53
+ };
54
+
55
+ const ListDocuments = (collectionName) => {
56
+ return domo
57
+ .get(`${BASE_URL}/collections/${collectionName}/documents/`)
58
+ .then((response) => response)
59
+ .catch((error) => {
60
+ console.error("Error listing documents:", error);
61
+ throw error;
62
+ });
63
+ };
64
+
65
+ const GetDocument = (collectionName, documentId) => {
66
+ return domo
67
+ .get(`${BASE_URL}/collections/${collectionName}/documents/${documentId}`)
68
+ .then((response) => response)
69
+ .catch((error) => {
70
+ console.error("Error getting document:", error);
71
+ throw error;
72
+ });
73
+ };
74
+
75
+ const UpdateDocument = (collectionName, documentId, document) => {
76
+ return domo
77
+ .put(`${BASE_URL}/collections/${collectionName}/documents/${documentId}`, {
78
+ content: document,
79
+ })
80
+ .then((response) => response)
81
+ .catch((error) => {
82
+ console.error("Error updating document:", error);
83
+ throw error;
84
+ });
85
+ };
86
+ const queryDocumentsWithAggregations = (
87
+ collectionName,
88
+ query = {},
89
+ aggregations = {},
90
+ options = {}
91
+ ) => {
92
+ // Base URL for the query
93
+ let url = `${BASE_URL}/collections/${collectionName}/documents/query?`;
94
+
95
+ // Helper function to format aggregation parameters
96
+ const formatAggregationParams = (params) => {
97
+ return Object.entries(params)
98
+ .map(([property, alias]) => `${property} ${alias}`)
99
+ .join(", ");
100
+ };
101
+
102
+ // Append aggregation parameters to URL
103
+ if (aggregations.groupby) url += `groupby=${aggregations.groupby.join(",")}&`;
104
+ if (aggregations.count) url += `count=${aggregations.count}&`;
105
+ if (aggregations.avg)
106
+ url += `avg=${formatAggregationParams(aggregations.avg)}&`;
107
+ if (aggregations.min)
108
+ url += `min=${formatAggregationParams(aggregations.min)}&`;
109
+ if (aggregations.max)
110
+ url += `max=${formatAggregationParams(aggregations.max)}&`;
111
+ if (aggregations.sum)
112
+ url += `sum=${formatAggregationParams(aggregations.sum)}&`;
113
+ if (aggregations.unwind) url += `unwind=${aggregations.unwind.join(",")}&`;
114
+
115
+ // Append options to the URL
116
+ if (options.orderby) url += `orderby=${options.orderby}&`;
117
+ if (options.limit !== undefined) url += `limit=${options.limit}&`;
118
+ if (options.offset !== undefined) url += `offset=${options.offset}&`;
119
+
120
+ // Remove trailing "&" or "?" from the URL
121
+ url = url.replace(/[&?]$/, "");
122
+
123
+ return domo
124
+ .post(url, query)
125
+ .then((response) => {
126
+ console.log("Query successful:", response);
127
+ return response;
128
+ })
129
+ .catch((error) => {
130
+ console.error("Error querying documents with aggregations:", error);
131
+ throw error;
132
+ });
133
+ };
134
+
135
+ const DeleteDocument = (collectionName, documentId) => {
136
+ return domo
137
+ .delete(`${BASE_URL}/collections/${collectionName}/documents/${documentId}`)
138
+ .then((response) => response.data)
139
+ .catch((error) => {
140
+ console.error("Error deleting document:", error);
141
+ throw error;
142
+ });
143
+ };
144
+
145
+ const QueryDocument = (collectionName, query = {}, options = {}) => {
146
+ // Base URL for querying documents
147
+ let url = `${BASE_URL}/collections/${collectionName}/documents/query?`;
148
+
149
+ // Append optional parameters to the URL
150
+ if (options.limit !== undefined) url += `limit=${options.limit}&`;
151
+ if (options.offset !== undefined) url += `offset=${options.offset}&`;
152
+ if (options.orderby) url += `orderby=${options.orderby}&`;
153
+
154
+ // Remove trailing "&" or "?" from the URL
155
+ url = url.replace(/[&?]$/, "");
156
+
157
+ return domo
158
+ .post(url, query)
159
+ .then((response) => {
160
+ // console.log("Query successful:", response);
161
+ return response;
162
+ })
163
+ .catch((error) => {
164
+ console.error("Error querying documents:", error);
165
+ throw error;
166
+ });
167
+ };
168
+
169
+ // Query documents based on a specific date range
170
+ const queryDocumentsByDate = (collectionName, dateString, options = {}) => {
171
+ const query = {
172
+ "createdOn": {
173
+ "$lte": { "$date": dateString }
174
+ }
175
+ };
176
+ return QueryDocument(collectionName, query, options);
177
+ };
178
+
179
+ const BulkDeleteDocuments = (collectionName, ids) => {
180
+ return domo
181
+ .delete(
182
+ `${BASE_URL}/collections/${collectionName}/documents/bulk?ids=${ids}`
183
+ )
184
+ .then((response) => response)
185
+ .catch((error) => {
186
+ console.error("Error bulk deleting documents:", error);
187
+ throw error;
188
+ });
189
+ };
190
+
191
+ const UploadFile = (file, name, description = "", isPublic = false) => {
192
+ const formData = new FormData();
193
+ formData.append("file", file);
194
+ const url = `/domo/data-files/v1?name=
195
+ ${name}&description=${description}&public=${isPublic}`;
196
+ const options = { contentType: "multipart" };
197
+ return domo
198
+ .post(url, formData, options)
199
+ .then((response) => response)
200
+ .catch((err) => {
201
+ console.log(err);
202
+ throw err;
203
+ });
204
+ };
205
+
206
+ const UploadRevision = (file, fileId) => {
207
+ const formData = new FormData();
208
+ formData.append("file", file);
209
+ const url = `/domo/data-files/v1/${fileId}`;
210
+ const options = { contentType: "multipart" };
211
+ return domo
212
+ .put(url, formData, options)
213
+ .then((response) => response)
214
+ .catch((err) => {
215
+ console.log(err);
216
+ throw err;
217
+ });
218
+ };
219
+
220
+ // const DownloadFile = (fileId, filename, revisionId) => {
221
+ // const options = { responseType: "blob" };
222
+ // const url = `/domo/data-files/v1/${fileId}${
223
+ // revisionId ? `/revisions/${revisionId}` : ""
224
+ // }`;
225
+ // return domo
226
+ // .get(url, options)
227
+ // .then((data) => {
228
+ // Download(data, filename);
229
+ // })
230
+ // .then((response) => response)
231
+ // .catch((err) => {
232
+ // console.log(err);
233
+ // throw err;
234
+ // });
235
+ // };
236
+
237
+ const GetFile = (fileId, revisionId) => {
238
+ const options = { responseType: "blob" };
239
+ const url = `/domo/data-files/v1/${fileId}${
240
+ revisionId ? `/revisions/${revisionId}` : ""
241
+ }`;
242
+ return domo
243
+ .get(url, options)
244
+ .then((data) => data)
245
+ .catch((err) => {
246
+ console.log(err);
247
+ throw err;
248
+ });
249
+ };
250
+
251
+ const ListAllUsers = async (
252
+ includeDetails = false,
253
+ limit = 100,
254
+ offset = 0
255
+ ) => {
256
+ try {
257
+ const response = await domo.get(
258
+ `/domo/users/v1?includeDetails=${includeDetails}&limit=${limit}&offset=${offset}`
259
+ );
260
+ return response;
261
+ } catch (error) {
262
+ console.error("Error listing users:", error);
263
+ throw error;
264
+ }
265
+ };
266
+
267
+ const partialupdateDocument = (collectionName, query, operation) => {
268
+ const requestBody = {
269
+ query: query,
270
+ operation: operation,
271
+ };
272
+
273
+ console.log("Request body:", requestBody);
274
+
275
+ return domo
276
+ .put(
277
+ `${BASE_URL}/collections/${collectionName}/documents/update`,
278
+ requestBody
279
+ )
280
+ .then((response) => {
281
+ console.log("Document updated successfully:", response);
282
+ return response;
283
+ })
284
+ .catch((error) => {
285
+ console.error("Error updating document:", error);
286
+ throw error;
287
+ });
288
+ };
289
+
290
+ const DomoApi = {
291
+ GetCurrentUser,
292
+ GetAllUser,
293
+ GetUser,
294
+ CreateDocument,
295
+ ListDocuments,
296
+ DeleteDocument,
297
+ BulkDeleteDocuments,
298
+ GetDocument,
299
+ UpdateDocument,
300
+ QueryDocument,
301
+ queryDocumentsByDate,
302
+ UploadFile,
303
+ UploadRevision,
304
+ // DownloadFile,
305
+ GetFile,
306
+ queryDocumentsWithAggregations,
307
+ ListAllUsers,
308
+ partialupdateDocument,
309
+ };
310
+
311
+ export default DomoApi;
@@ -0,0 +1,13 @@
1
+ import { useState } from "react";
2
+ import { Button } from "./components/ui/button";
3
+ import "./App.css";
4
+ function App() {
5
+ const [count, setCount] = useState(0);
6
+ return (
7
+ <div className="App">
8
+ <Button onClick={() => setCount(count + 1)}>Count: {count}</Button>
9
+ </div>
10
+ );
11
+ }
12
+
13
+ export default App;
@@ -0,0 +1 @@
1
+ @import "tailwindcss";
@@ -0,0 +1,40 @@
1
+ import { defineConfig } from "vite";
2
+ import react from "@vitejs/plugin-react";
3
+ import path from "path";
4
+ import { Proxy } from "@domoinc/ryuu-proxy";
5
+ import manifest from "./public/manifest.json";
6
+ import tailwindcss from "@tailwindcss/vite";
7
+
8
+ const config = { manifest };
9
+ const proxy = new Proxy(config);
10
+
11
+ // https://vite.dev/config/
12
+ export default defineConfig({
13
+ plugins: [
14
+ react(),
15
+ tailwindcss(),
16
+ {
17
+ name: "ryuu-proxy",
18
+ configureServer(server) {
19
+ server.middlewares.use((req, res, next) => {
20
+ res.status = function (code) {
21
+ this.statusCode = code;
22
+ return this;
23
+ };
24
+ res.send = function (body) {
25
+ this.setHeader("Content-Type", "text/plain");
26
+ this.end(body);
27
+ };
28
+ next();
29
+ });
30
+ server.middlewares.use(proxy.express());
31
+ },
32
+ },
33
+ ],
34
+ define: { "process.env": {} },
35
+ resolve: {
36
+ alias: {
37
+ "@": path.resolve(__dirname, "./src"),
38
+ },
39
+ },
40
+ });
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "project-name",
3
+ "version": "0.0.1",
4
+ "size": {
5
+ "width": 3,
6
+ "height": 3
7
+ },
8
+ "mapping": [],
9
+ "collections": [],
10
+ "workflowMapping": [],
11
+ "packagesMapping": []
12
+ }
@@ -0,0 +1,66 @@
1
+ /* eslint-disable react/prop-types */
2
+ // @ts-ignore
3
+ import { createContext, useState, useEffect, ReactNode } from "react";
4
+ import DomoApi from "./domoAPI";
5
+
6
+ export interface UserContextType {
7
+ currentUser: string;
8
+ currentUserId: string;
9
+ avatarKey: string;
10
+ customer: string;
11
+ host: string;
12
+ }
13
+
14
+ export const UserContext = createContext<UserContextType | undefined>(
15
+ undefined
16
+ );
17
+
18
+ export const UserProvider = ({ children }: { children: ReactNode }) => {
19
+ const [currentUser, setCurrentUser] = useState<string>("");
20
+ const [currentUserId, setCurrentUserId] = useState<string>("");
21
+ const [avatarKey, setAvatarKey] = useState<string>("");
22
+ const [customer, setCustomer] = useState<string>("");
23
+ const [host, setHost] = useState<string>("");
24
+
25
+ useEffect(() => {
26
+ let isUserFetched = false;
27
+
28
+ DomoApi.GetCurrentUser().then((data: any) => {
29
+ // console.log("User Data",data);
30
+
31
+ if (!isUserFetched) {
32
+ const userId = data?.userId;
33
+ const displayName = data?.displayName;
34
+ const avatarKey = data?.avatarKey;
35
+ const customer = data?.customer;
36
+ const host = data?.host;
37
+
38
+ setCurrentUser(displayName || "");
39
+ setCurrentUserId(userId || "");
40
+ setAvatarKey(avatarKey || "");
41
+ setCustomer(customer || "");
42
+ setHost(host || "");
43
+
44
+ isUserFetched = true;
45
+ }
46
+ });
47
+
48
+ return () => {
49
+ isUserFetched = true;
50
+ };
51
+ }, []);
52
+
53
+ return (
54
+ <UserContext.Provider
55
+ value={{
56
+ currentUser,
57
+ currentUserId,
58
+ avatarKey,
59
+ customer,
60
+ host,
61
+ }}
62
+ >
63
+ {children}
64
+ </UserContext.Provider>
65
+ );
66
+ };