@iotready/nextjs-components-library 1.0.0-preview21 → 1.0.0-preview23

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.
@@ -17,7 +17,7 @@ declare const TrendChart: ({ deviceId, measures1, annotationsDataFn, measures2,
17
17
  measures2?: Array<Measure>;
18
18
  enableDatePicker: boolean;
19
19
  handleGetInfluxData: (measure: string, timeStart: number, timeEnd: number, deviceId: string, timeGroup: string, raw: boolean, fill?: InfluxFillType, filterTag?: number, includeTag?: FilterTagMode) => Promise<any>;
20
- handleGetDwSlotsCB: (timeStart: number, timeEnd: number, deviceID: string) => Promise<any>;
20
+ handleGetDwSlotsCB?: (timeStart: number, timeEnd: number, deviceID: string) => Promise<any>;
21
21
  handleExportDataCB?: (measure: string, timeStart: number, timeEnd: number, deviceId: string) => Promise<any>;
22
22
  theme: Theme;
23
23
  initialTimeStart?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iotready/nextjs-components-library",
3
- "version": "1.0.0-preview21",
3
+ "version": "1.0.0-preview23",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "build": "rm -rf dist && tsc --project tsconfig.build.json && cp package.json dist/",
@@ -20,7 +20,7 @@
20
20
  "chartjs-plugin-annotation": "^3.1.0",
21
21
  "chartjs-plugin-zoom": "^2.0.1",
22
22
  "csv-parse": "^5.6.0",
23
- "firebase": "^10.13.1",
23
+ "firebase-admin": "^13.4.0",
24
24
  "leaflet": "^1.9.4",
25
25
  "leaflet-defaulticon-compatibility": "^0.1.2",
26
26
  "material-ui-confirm": "^3.0.16",
@@ -1,4 +1,4 @@
1
- import { FirebaseConfig } from "./types";
2
- export declare const getAnnotations: (firebaseConfig: FirebaseConfig, deviceID: number) => Promise<{
1
+ import { Firestore } from "firebase-admin/firestore";
2
+ export declare const getAnnotations: (db: Firestore, deviceID: number) => Promise<{
3
3
  id: string;
4
4
  }[]>;
@@ -1,14 +1,11 @@
1
1
  "use server";
2
- import { initializeApp } from "firebase/app";
3
- import { collection, query, orderBy, getDocs, where } from "@firebase/firestore";
4
- import { getFirestore } from "@firebase/firestore";
5
- export const getAnnotations = async (firebaseConfig, deviceID) => {
6
- // Initialize Firebase
7
- const app = initializeApp(firebaseConfig);
8
- const db = getFirestore(app);
9
- const annotationsQuery = query(collection(db, "annotations"), where("target", "==", deviceID), orderBy("createdAt", "desc"));
10
- const groupsSnapshot = await getDocs(annotationsQuery);
11
- return groupsSnapshot.docs.map((doc) => ({
2
+ export const getAnnotations = async (db, deviceID) => {
3
+ const annotationsRef = db.collection("annotations");
4
+ const snapshot = await annotationsRef
5
+ .where("target", "==", deviceID)
6
+ .orderBy("createdAt", "desc")
7
+ .get();
8
+ return snapshot.docs.map((doc) => ({
12
9
  id: doc.id,
13
10
  ...doc.data()
14
11
  }));
@@ -1,15 +1,15 @@
1
- import { FirebaseConfig } from "./types";
2
- export declare const getGroups: (firebaseConfig: FirebaseConfig, productID: number, userID?: string) => Promise<{
1
+ import { Firestore } from "firebase-admin/firestore";
2
+ export declare const getGroups: (db: Firestore, productID: number, userID?: string) => Promise<{
3
3
  id: string;
4
4
  }[]>;
5
- export declare const getGroupById: (firebaseConfig: FirebaseConfig, id: string) => Promise<{
5
+ export declare const getGroupById: (db: Firestore, id: string) => Promise<{
6
6
  id: string;
7
7
  }>;
8
- export declare const createGroup: (firebaseConfig: FirebaseConfig, group: any) => Promise<string>;
9
- export declare const updateGroup: (firebaseConfig: FirebaseConfig, id: string, group: any) => Promise<any>;
10
- export declare const deleteGroup: (firebaseConfig: FirebaseConfig, id: string) => Promise<void>;
11
- export declare const getUsersGroup: (firebaseConfig: FirebaseConfig, groupID: string) => Promise<{
8
+ export declare const createGroup: (db: Firestore, group: any) => Promise<string>;
9
+ export declare const updateGroup: (db: Firestore, id: string, group: any) => Promise<any>;
10
+ export declare const deleteGroup: (db: Firestore, id: string) => Promise<void>;
11
+ export declare const getUsersGroup: (db: Firestore, groupID: string) => Promise<{
12
12
  id: string;
13
13
  }[]>;
14
- export declare const addUsersGroup: (firebaseConfig: FirebaseConfig, groupID: string, userName: string, userID: string) => Promise<string>;
15
- export declare const removeUserGroup: (firebaseConfig: FirebaseConfig, groupID: string, userID: string) => Promise<string | undefined>;
14
+ export declare const addUsersGroup: (db: Firestore, groupID: string, userName: string, userID: string) => Promise<string>;
15
+ export declare const removeUserGroup: (db: Firestore, groupID: string, userID: string) => Promise<string | undefined>;
@@ -1,87 +1,74 @@
1
1
  "use server";
2
- import { initializeApp } from "firebase/app";
3
- import { getDoc, doc, updateDoc, deleteDoc, collection, query, orderBy, getDocs, where, addDoc } from "@firebase/firestore";
4
- import { getFirestore } from "@firebase/firestore";
5
- export const getGroups = async (firebaseConfig, productID, userID) => {
6
- // Initialize Firebase
7
- const app = initializeApp(firebaseConfig);
8
- const db = getFirestore(app);
9
- const groupsQuery = query(collection(db, "groups"), where("productID", "==", productID), orderBy("created", "desc"));
2
+ // 1. GET GROUPS
3
+ export const getGroups = async (db, productID, userID) => {
4
+ const groupsRef = db
5
+ .collection("groups")
6
+ .where("productID", "==", productID)
7
+ .orderBy("created", "desc");
10
8
  let groupIds = null;
11
9
  if (userID) {
12
- const usersGroupQuery = query(collection(db, "userGroups"), where("user.userId", "==", userID));
13
- const userSnapshot = await getDocs(usersGroupQuery);
14
- groupIds = userSnapshot.docs.map((ug) => ug.data().groupId);
10
+ const userGroupsSnapshot = await db
11
+ .collection("userGroups")
12
+ .where("user.userId", "==", userID)
13
+ .get();
14
+ groupIds = userGroupsSnapshot.docs.map((doc) => doc.data().groupId);
15
15
  }
16
- const groupsSnapshot = await getDocs(groupsQuery);
17
- if (groupIds) {
18
- return groupsSnapshot.docs
19
- .filter((entry) => groupIds?.includes(entry.id))
20
- .map((doc) => ({
21
- id: doc.id,
22
- ...doc.data()
23
- }));
24
- }
25
- return groupsSnapshot.docs.map((doc) => ({
16
+ const groupsSnapshot = await groupsRef.get();
17
+ return groupsSnapshot.docs
18
+ .filter((doc) => !groupIds || groupIds.includes(doc.id))
19
+ .map((doc) => ({
26
20
  id: doc.id,
27
21
  ...doc.data()
28
22
  }));
29
23
  };
30
- export const getGroupById = async (firebaseConfig, id) => {
31
- const app = initializeApp(firebaseConfig);
32
- const db = getFirestore(app);
33
- const groupSnapshot = await getDoc(doc(db, "groups", id));
24
+ // 2. GET GROUP BY ID
25
+ export const getGroupById = async (db, id) => {
26
+ const docSnapshot = await db.collection("groups").doc(id).get();
34
27
  return {
35
- id: groupSnapshot.id,
36
- ...groupSnapshot.data()
28
+ id: docSnapshot.id,
29
+ ...docSnapshot.data()
37
30
  };
38
31
  };
39
- export const createGroup = async (firebaseConfig, group) => {
40
- const created = new Date().toISOString();
32
+ // 3. CREATE GROUP
33
+ export const createGroup = async (db, group) => {
41
34
  const newGroup = {
42
35
  ...group,
43
- created
36
+ created: new Date().toISOString()
44
37
  };
45
- const app = initializeApp(firebaseConfig);
46
- const db = getFirestore(app);
47
- const docRef = await addDoc(collection(db, "groups"), newGroup);
38
+ const docRef = await db.collection("groups").add(newGroup);
48
39
  return docRef.id;
49
40
  };
50
- export const updateGroup = async (firebaseConfig, id, group) => {
51
- const app = initializeApp(firebaseConfig);
52
- const db = getFirestore(app);
53
- const groupRef = doc(db, "groups", id);
54
- await updateDoc(groupRef, group);
41
+ // 4. UPDATE GROUP
42
+ export const updateGroup = async (db, id, group) => {
43
+ await db.collection("groups").doc(id).update(group);
55
44
  return group;
56
45
  };
57
- export const deleteGroup = async (firebaseConfig, id) => {
58
- const app = initializeApp(firebaseConfig);
59
- const db = getFirestore(app);
60
- const usersGroupQuery = query(collection(db, "userGroups"), where("groupId", "==", id));
61
- const groupsSnapshot = await getDocs(usersGroupQuery);
62
- groupsSnapshot.docs.forEach(async (ug) => {
63
- const userGroupRef = doc(db, "userGroups", ug.id);
64
- await deleteDoc(userGroupRef);
46
+ // 5. DELETE GROUP
47
+ export const deleteGroup = async (db, id) => {
48
+ const userGroupsSnapshot = await db
49
+ .collection("userGroups")
50
+ .where("groupId", "==", id)
51
+ .get();
52
+ const batch = db.batch();
53
+ userGroupsSnapshot.docs.forEach((doc) => {
54
+ batch.delete(doc.ref);
65
55
  });
66
- const groupRef = doc(db, "groups", id);
67
- await deleteDoc(groupRef);
56
+ batch.delete(db.collection("groups").doc(id));
57
+ await batch.commit();
68
58
  };
69
- // USERS GROUPS
70
- export const getUsersGroup = async (firebaseConfig, groupID) => {
71
- // Initialize Firebase
72
- const app = initializeApp(firebaseConfig);
73
- const db = getFirestore(app);
74
- const usersGroupQuery = query(collection(db, "userGroups"), where("groupId", "==", groupID));
75
- const groupsSnapshot = await getDocs(usersGroupQuery);
76
- return groupsSnapshot.docs.map((doc) => ({
59
+ // 6. GET USERS GROUP
60
+ export const getUsersGroup = async (db, groupID) => {
61
+ const snapshot = await db
62
+ .collection("userGroups")
63
+ .where("groupId", "==", groupID)
64
+ .get();
65
+ return snapshot.docs.map((doc) => ({
77
66
  id: doc.id,
78
67
  ...doc.data()
79
68
  }));
80
69
  };
81
- export const addUsersGroup = async (firebaseConfig, groupID, userName, userID) => {
82
- // Initialize Firebase
83
- const app = initializeApp(firebaseConfig);
84
- const db = getFirestore(app);
70
+ // 7. ADD USER TO GROUP
71
+ export const addUsersGroup = async (db, groupID, userName, userID) => {
85
72
  const created = new Date().toISOString();
86
73
  const newUserGroup = {
87
74
  user: {
@@ -91,19 +78,19 @@ export const addUsersGroup = async (firebaseConfig, groupID, userName, userID) =
91
78
  groupId: groupID,
92
79
  created
93
80
  };
94
- const docRef = await addDoc(collection(db, "userGroups"), newUserGroup);
81
+ const docRef = await db.collection("userGroups").add(newUserGroup);
95
82
  return docRef.id;
96
83
  };
97
- export const removeUserGroup = async (firebaseConfig, groupID, userID) => {
98
- // Initialize Firebase
99
- const app = initializeApp(firebaseConfig);
100
- const db = getFirestore(app);
101
- const usersGroupQuery = query(collection(db, "userGroups"), where("groupId", "==", groupID), where("user.userId", "==", userID));
102
- const groupsSnapshot = await getDocs(usersGroupQuery);
103
- if (groupsSnapshot.docs[0]) {
104
- const userGroupId = groupsSnapshot.docs[0].id;
105
- const groupRef = doc(db, "userGroups", userGroupId);
106
- await deleteDoc(groupRef);
107
- return userGroupId;
84
+ // 8. REMOVE USER FROM GROUP
85
+ export const removeUserGroup = async (db, groupID, userID) => {
86
+ const snapshot = await db
87
+ .collection("userGroups")
88
+ .where("groupId", "==", groupID)
89
+ .where("user.userId", "==", userID)
90
+ .get();
91
+ const doc = snapshot.docs[0];
92
+ if (doc) {
93
+ await doc.ref.delete();
94
+ return doc.id;
108
95
  }
109
96
  };
@@ -1,11 +1,3 @@
1
- export type FirebaseConfig = {
2
- apiKey: string;
3
- authDomain: string;
4
- projectId: string;
5
- storageBucket: string;
6
- messagingSenderId: string;
7
- appId: string;
8
- };
9
1
  export type InfluxConfig = {
10
2
  url: string;
11
3
  accessToken: string;