create-dovite 2.2.0 → 2.2.2

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,40 @@
1
+ import { defineConfig } from "vite";
2
+ import vue from "@vitejs/plugin-vue";
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
+ vue(),
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,76 @@
1
+ import {
2
+ ref,
3
+ provide,
4
+ inject,
5
+ onMounted,
6
+ type Ref,
7
+ type InjectionKey,
8
+ } from "vue";
9
+ import DomoApi from "./domoAPI";
10
+
11
+ // Define the user context interface
12
+ export interface UserContextType {
13
+ currentUser: Ref<string>;
14
+ currentUserId: Ref<string>;
15
+ avatarKey: Ref<string>;
16
+ customer: Ref<string>;
17
+ host: Ref<string>;
18
+ }
19
+
20
+ // Create a typed symbol for the injection key
21
+ export const UserContextKey: InjectionKey<UserContextType> =
22
+ Symbol("UserContext");
23
+
24
+ // Composable to provide user context
25
+ export function useUserProvider(): UserContextType {
26
+ const currentUser = ref<string>("");
27
+ const currentUserId = ref<string>("");
28
+ const avatarKey = ref<string>("");
29
+ const customer = ref<string>("");
30
+ const host = ref<string>("");
31
+
32
+ onMounted(() => {
33
+ let isUserFetched = false;
34
+
35
+ DomoApi.GetCurrentUser().then((data) => {
36
+ if (!isUserFetched) {
37
+ const userId = data?.userId;
38
+ const displayName = data?.displayName;
39
+ const avatar = data?.avatarKey;
40
+ const cust = data?.customer;
41
+ const hostVal = data?.host;
42
+
43
+ currentUser.value = displayName || "";
44
+ currentUserId.value = userId || "";
45
+ avatarKey.value = avatar || "";
46
+ customer.value = cust || "";
47
+ host.value = hostVal || "";
48
+
49
+ isUserFetched = true;
50
+ }
51
+ });
52
+ });
53
+
54
+ const userContext: UserContextType = {
55
+ currentUser,
56
+ currentUserId,
57
+ avatarKey,
58
+ customer,
59
+ host,
60
+ };
61
+
62
+ provide(UserContextKey, userContext);
63
+
64
+ return userContext;
65
+ }
66
+
67
+ // Composable to consume user context
68
+ export function useUserContext(): UserContextType {
69
+ const context = inject(UserContextKey);
70
+ if (!context) {
71
+ throw new Error(
72
+ "useUserContext must be used within a component that calls useUserProvider"
73
+ );
74
+ }
75
+ return context;
76
+ }
@@ -0,0 +1,284 @@
1
+ import domo from "ryuu.js";
2
+ import axios from "axios";
3
+
4
+ interface AIResponseBody {
5
+ input: string;
6
+ promptTemplate?: {
7
+ template: string;
8
+ };
9
+ parameters?: {
10
+ max_words: string;
11
+ };
12
+ }
13
+
14
+ interface SqlApiData {
15
+ columns: string[];
16
+ rows: any[][];
17
+ }
18
+
19
+ interface EmailData {
20
+ to: string;
21
+ subject: string;
22
+ body: string;
23
+ attachment?: any[];
24
+ }
25
+
26
+ interface DataflowData {
27
+ action: string;
28
+ dataflowId: string;
29
+ result: boolean;
30
+ }
31
+
32
+ export async function fetchAIData(
33
+ prompt: string,
34
+ template?: string,
35
+ maxWords?: number
36
+ ): Promise<string | undefined> {
37
+ try {
38
+ // Validate the required "prompt" parameter
39
+ if (!prompt || typeof prompt !== "string") {
40
+ throw new Error(
41
+ "The 'prompt' parameter is required and must be a string."
42
+ );
43
+ }
44
+
45
+ // Construct the body dynamically, including properties only if they are valid
46
+ const body: AIResponseBody = {
47
+ input: prompt,
48
+ ...(template &&
49
+ typeof template === "string" && {
50
+ promptTemplate: {
51
+ template,
52
+ },
53
+ }),
54
+ ...(maxWords &&
55
+ !isNaN(maxWords) && {
56
+ parameters: {
57
+ max_words: maxWords.toString(),
58
+ },
59
+ }),
60
+ };
61
+
62
+ // Send the POST request
63
+ const response = await domo.post(`/domo/ai/v1/text/generation`, body);
64
+ console.log("AI Response:", response.output);
65
+
66
+ return response?.output;
67
+ } catch (error) {
68
+ console.error("Error fetching data:", error);
69
+ throw error; // Re-throw the error for better upstream handling
70
+ }
71
+ }
72
+
73
+ export async function fetchData<T = any>(
74
+ dataset: string
75
+ ): Promise<T | undefined> {
76
+ try {
77
+ const response = await domo.get(`/data/v1/${dataset}`).then((data: T) => {
78
+ return data;
79
+ });
80
+ return response;
81
+ } catch (error) {
82
+ console.error("Error fetching data:", error);
83
+ }
84
+ }
85
+
86
+ export async function fetchSqlData<T = Record<string, any>>(
87
+ dataset: string,
88
+ query: string
89
+ ): Promise<T[]> {
90
+ // Ensure the query is a string
91
+ if (typeof query !== "string") {
92
+ throw new Error("Query must be a string");
93
+ }
94
+
95
+ try {
96
+ // Fetch data from the API
97
+ const apiData: SqlApiData = await domo
98
+ .post(`/sql/v1/${dataset}`, query, { contentType: "text/plain" })
99
+ .then((data: SqlApiData) => {
100
+ return data;
101
+ });
102
+
103
+ // Validate the fetched data
104
+ if (!apiData || !apiData.columns || !apiData.rows) {
105
+ throw new Error("Invalid data received from the API");
106
+ }
107
+
108
+ // Extract and clean column names
109
+ const cleanedColumns = apiData.columns.map((column: string) => {
110
+ return column
111
+ .replace(/`/g, "")
112
+ .replace(/T1\./g, "")
113
+ .replace(/avg\((.*?)\)/i, "$1")
114
+ .trim();
115
+ });
116
+
117
+ // Map rows to cleaned column names
118
+ const jsonResult = apiData.rows.map((row: any[]) => {
119
+ const jsonObject: Record<string, any> = {};
120
+ cleanedColumns.forEach((cleanedColumn: string, index: number) => {
121
+ jsonObject[cleanedColumn] = row[index];
122
+ });
123
+ return jsonObject as T;
124
+ });
125
+
126
+ return jsonResult;
127
+ } catch (error) {
128
+ console.error("Error fetching or processing data:", error);
129
+ throw error;
130
+ }
131
+ }
132
+
133
+ export async function sendEmail(
134
+ to: string,
135
+ subject: string,
136
+ body: string,
137
+ attachment?: any
138
+ ): Promise<void> {
139
+ const data: EmailData = {
140
+ to,
141
+ subject,
142
+ body,
143
+ ...(attachment && { attachment: [attachment] }),
144
+ };
145
+
146
+ if (data) {
147
+ try {
148
+ const response = await domo.post(
149
+ `/domo/workflow/v1/models/email/start`,
150
+ data
151
+ );
152
+ if (response) {
153
+ console.log("response", response);
154
+ }
155
+ } catch (err) {
156
+ console.error("Error sending email:", err);
157
+ }
158
+ }
159
+ }
160
+
161
+ // Dataflow
162
+ export const DataflowsActions = async (
163
+ action: string,
164
+ dataflowId: string
165
+ ): Promise<void> => {
166
+ const data: DataflowData = {
167
+ action,
168
+ dataflowId,
169
+ result: true,
170
+ };
171
+
172
+ if (data) {
173
+ try {
174
+ const response = await domo.post(
175
+ `/domo/workflow/v1/models/dataflow/start`,
176
+ data
177
+ );
178
+ if (response) {
179
+ console.log("response", response);
180
+ }
181
+ } catch (err) {
182
+ console.error("Error sending email:", err);
183
+ }
184
+ }
185
+ };
186
+
187
+ export const generateAccessToken = async (
188
+ clientId: string,
189
+ clientSecret: string
190
+ ): Promise<string> => {
191
+ const tokenUrl = "https://api.domo.com/oauth/token";
192
+ try {
193
+ const response = await axios.post(
194
+ tokenUrl,
195
+ new URLSearchParams({
196
+ grant_type: "client_credentials",
197
+ scope: "user",
198
+ }).toString(),
199
+ {
200
+ headers: {
201
+ "Content-Type": "application/x-www-form-urlencoded",
202
+ },
203
+ auth: {
204
+ username: clientId,
205
+ password: clientSecret,
206
+ },
207
+ }
208
+ );
209
+ console.log("Response:", response);
210
+ console.log("Access Token:", response.data.access_token);
211
+
212
+ return response.data.access_token;
213
+ } catch (err) {
214
+ console.error("Error:", err);
215
+ throw err;
216
+ }
217
+ };
218
+
219
+ // List Of Users
220
+ export const fetchUsers = async (
221
+ accessToken: string
222
+ ): Promise<any[] | undefined> => {
223
+ const userUrl = `https://api.domo.com/v1/users?limit=500`;
224
+ console.log("accessToken", accessToken);
225
+ try {
226
+ if (!accessToken) {
227
+ console.log("Access token not found");
228
+ return;
229
+ }
230
+ const response = await axios.get(userUrl, {
231
+ headers: {
232
+ Authorization: `Bearer ${accessToken}`,
233
+ },
234
+ });
235
+ console.log("List of users with access token", response.data);
236
+ return response.data;
237
+ } catch (err) {
238
+ console.error("Error fetching User details:", err);
239
+ }
240
+ };
241
+
242
+ // List Of Dataset
243
+ export const fetchDatasets = async (
244
+ accessToken: string
245
+ ): Promise<any[] | undefined> => {
246
+ const datasetUrl = `https://api.domo.com/v1/datasets`;
247
+
248
+ try {
249
+ if (!accessToken) {
250
+ await generateAccessToken("", "");
251
+ }
252
+ const response = await axios.get(datasetUrl, {
253
+ headers: {
254
+ Authorization: `Bearer ${accessToken}`,
255
+ },
256
+ });
257
+ return response.data;
258
+ } catch (err) {
259
+ console.error("Error fetching dataset details:", err);
260
+ }
261
+ };
262
+
263
+ // Particular Dataset Details
264
+ export const fetchDatasetDetails = async (
265
+ accessToken: string,
266
+ datasetId: string
267
+ ): Promise<any | undefined> => {
268
+ const datasetUrl = `https://api.domo.com/v1/datasets/${datasetId}`;
269
+
270
+ try {
271
+ if (!accessToken) {
272
+ await generateAccessToken("", "");
273
+ }
274
+
275
+ const response = await axios.get(datasetUrl, {
276
+ headers: {
277
+ Authorization: `Bearer ${accessToken}`,
278
+ },
279
+ });
280
+ return response.data;
281
+ } catch (err) {
282
+ console.error("Error fetching dataset details:", err);
283
+ }
284
+ };