@iotready/nextjs-components-library 1.0.0-preview3 → 1.0.0-preview30

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iotready/nextjs-components-library",
3
- "version": "1.0.0-preview3",
3
+ "version": "1.0.0-preview30",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "build": "rm -rf dist && tsc --project tsconfig.build.json && cp package.json dist/",
@@ -19,9 +19,11 @@
19
19
  "chartjs-adapter-moment": "^1.0.1",
20
20
  "chartjs-plugin-annotation": "^3.1.0",
21
21
  "chartjs-plugin-zoom": "^2.0.1",
22
- "firebase": "^10.13.1",
22
+ "csv-parse": "^5.6.0",
23
+ "firebase-admin": "^13.4.0",
23
24
  "leaflet": "^1.9.4",
24
25
  "leaflet-defaulticon-compatibility": "^0.1.2",
26
+ "lodash.debounce": "^4.0.8",
25
27
  "material-ui-confirm": "^3.0.16",
26
28
  "moment": "^2.30.1",
27
29
  "next": "^14.2.9",
@@ -34,6 +36,7 @@
34
36
  },
35
37
  "devDependencies": {
36
38
  "@types/leaflet": "^1.9.13",
39
+ "@types/lodash.debounce": "^4.0.9",
37
40
  "@types/node": "^20",
38
41
  "@types/react": "^18",
39
42
  "@types/react-csv": "^1.1.10",
@@ -42,4 +45,4 @@
42
45
  "eslint-config-next": "14.2.9",
43
46
  "typescript": "^5"
44
47
  }
45
- }
48
+ }
@@ -0,0 +1,4 @@
1
+ import { Firestore } from "firebase-admin/firestore";
2
+ export declare const getAnnotations: (db: Firestore, deviceID: number) => Promise<{
3
+ id: string;
4
+ }[]>;
@@ -0,0 +1,12 @@
1
+ "use server";
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) => ({
9
+ id: doc.id,
10
+ ...doc.data()
11
+ }));
12
+ };
@@ -1,22 +1,18 @@
1
- export type FirebaseConfig = {
2
- apiKey: string;
3
- authDomain: string;
4
- projectId: string;
5
- storageBucket: string;
6
- messagingSenderId: string;
7
- appId: string;
8
- };
9
- 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, assetID?: string) => Promise<{
10
3
  id: string;
11
4
  }[]>;
12
- export declare const getGroupById: (firebaseConfig: FirebaseConfig, id: string) => Promise<{
5
+ export declare const getGroupById: (db: Firestore, id: string) => Promise<{
13
6
  id: string;
14
7
  }>;
15
- export declare const createGroup: (firebaseConfig: FirebaseConfig, group: any) => Promise<string>;
16
- export declare const updateGroup: (firebaseConfig: FirebaseConfig, id: string, group: any) => Promise<any>;
17
- export declare const deleteGroup: (firebaseConfig: FirebaseConfig, id: string) => Promise<void>;
18
- 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<{
19
12
  id: string;
20
13
  }[]>;
21
- export declare const addUsersGroup: (firebaseConfig: FirebaseConfig, groupID: string, userName: string, userID: string) => Promise<string>;
22
- export declare const removeUserGroup: (firebaseConfig: FirebaseConfig, groupID: string, userID: string) => Promise<string | undefined>;
14
+ export declare const getGroupsUser: (db: Firestore, userID: string) => Promise<{
15
+ id: string;
16
+ }[]>;
17
+ export declare const addUsersGroup: (db: Firestore, groupID: string, userName: string, userID: string) => Promise<string>;
18
+ export declare const removeUserGroup: (db: Firestore, groupID: string, userID: string) => Promise<string | undefined>;
@@ -1,87 +1,86 @@
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, assetID) => {
4
+ let groupsRef = db.collection("groups").where("productID", "==", productID);
5
+ if (assetID) {
6
+ groupsRef = groupsRef.where("assets", "array-contains", assetID);
7
+ }
8
+ groupsRef = groupsRef.orderBy("created", "desc");
10
9
  let groupIds = null;
11
10
  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);
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
- }));
11
+ const userGroupsSnapshot = await db
12
+ .collection("userGroups")
13
+ .where("user.userId", "==", userID)
14
+ .get();
15
+ groupIds = userGroupsSnapshot.docs.map((doc) => doc.data().groupId);
24
16
  }
25
- return groupsSnapshot.docs.map((doc) => ({
17
+ const groupsSnapshot = await groupsRef.get();
18
+ return groupsSnapshot.docs
19
+ .filter((doc) => !groupIds || groupIds.includes(doc.id))
20
+ .map((doc) => ({
26
21
  id: doc.id,
27
22
  ...doc.data()
28
23
  }));
29
24
  };
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));
25
+ // 2. GET GROUP BY ID
26
+ export const getGroupById = async (db, id) => {
27
+ const docSnapshot = await db.collection("groups").doc(id).get();
34
28
  return {
35
- id: groupSnapshot.id,
36
- ...groupSnapshot.data()
29
+ id: docSnapshot.id,
30
+ ...docSnapshot.data()
37
31
  };
38
32
  };
39
- export const createGroup = async (firebaseConfig, group) => {
40
- const created = new Date().toISOString();
33
+ // 3. CREATE GROUP
34
+ export const createGroup = async (db, group) => {
41
35
  const newGroup = {
42
36
  ...group,
43
- created
37
+ created: new Date().toISOString()
44
38
  };
45
- const app = initializeApp(firebaseConfig);
46
- const db = getFirestore(app);
47
- const docRef = await addDoc(collection(db, "groups"), newGroup);
39
+ const docRef = await db.collection("groups").add(newGroup);
48
40
  return docRef.id;
49
41
  };
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);
42
+ // 4. UPDATE GROUP
43
+ export const updateGroup = async (db, id, group) => {
44
+ await db.collection("groups").doc(id).update(group);
55
45
  return group;
56
46
  };
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);
47
+ // 5. DELETE GROUP
48
+ export const deleteGroup = async (db, id) => {
49
+ const userGroupsSnapshot = await db
50
+ .collection("userGroups")
51
+ .where("groupId", "==", id)
52
+ .get();
53
+ const batch = db.batch();
54
+ userGroupsSnapshot.docs.forEach((doc) => {
55
+ batch.delete(doc.ref);
65
56
  });
66
- const groupRef = doc(db, "groups", id);
67
- await deleteDoc(groupRef);
57
+ batch.delete(db.collection("groups").doc(id));
58
+ await batch.commit();
59
+ };
60
+ // 6. GET USERS GROUP
61
+ export const getUsersGroup = async (db, groupID) => {
62
+ const snapshot = await db
63
+ .collection("userGroups")
64
+ .where("groupId", "==", groupID)
65
+ .get();
66
+ return snapshot.docs.map((doc) => ({
67
+ id: doc.id,
68
+ ...doc.data()
69
+ }));
68
70
  };
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) => ({
71
+ // 6b. GET GROUPS USER
72
+ export const getGroupsUser = async (db, userID) => {
73
+ const snapshot = await db
74
+ .collection("userGroups")
75
+ .where("user.userId", "==", userID)
76
+ .get();
77
+ return snapshot.docs.map((doc) => ({
77
78
  id: doc.id,
78
79
  ...doc.data()
79
80
  }));
80
81
  };
81
- export const addUsersGroup = async (firebaseConfig, groupID, userName, userID) => {
82
- // Initialize Firebase
83
- const app = initializeApp(firebaseConfig);
84
- const db = getFirestore(app);
82
+ // 7. ADD USER TO GROUP
83
+ export const addUsersGroup = async (db, groupID, userName, userID) => {
85
84
  const created = new Date().toISOString();
86
85
  const newUserGroup = {
87
86
  user: {
@@ -91,19 +90,19 @@ export const addUsersGroup = async (firebaseConfig, groupID, userName, userID) =
91
90
  groupId: groupID,
92
91
  created
93
92
  };
94
- const docRef = await addDoc(collection(db, "userGroups"), newUserGroup);
93
+ const docRef = await db.collection("userGroups").add(newUserGroup);
95
94
  return docRef.id;
96
95
  };
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;
96
+ // 8. REMOVE USER FROM GROUP
97
+ export const removeUserGroup = async (db, groupID, userID) => {
98
+ const snapshot = await db
99
+ .collection("userGroups")
100
+ .where("groupId", "==", groupID)
101
+ .where("user.userId", "==", userID)
102
+ .get();
103
+ const doc = snapshot.docs[0];
104
+ if (doc) {
105
+ await doc.ref.delete();
106
+ return doc.id;
108
107
  }
109
108
  };
@@ -2,3 +2,4 @@ export * from "./groups";
2
2
  export * from "./influx";
3
3
  export * from "./logto";
4
4
  export * from "./trackle";
5
+ export * from "./annotations";
@@ -3,3 +3,4 @@ export * from "./groups";
3
3
  export * from "./influx";
4
4
  export * from "./logto";
5
5
  export * from "./trackle";
6
+ export * from "./annotations";
@@ -1,13 +1,17 @@
1
- export type InfluxConfig = {
2
- url: string;
3
- accessToken: string;
4
- bucket: string;
5
- orgId: string;
6
- measurement: string;
7
- dbName: string;
8
- username: string;
9
- password: string;
10
- };
11
- export declare function getInfluxDataV1(influxConfig: InfluxConfig, field: string, timeStart: number, timeEnd: number, deviceID: string, timeGroup: string, raw: boolean): Promise<any>;
12
- export declare function getManyMeasuresV1(influxConfig: InfluxConfig, fields: string[], limit: number, offset: number, sort: any, deviceID: string, timeStart?: number, timeEnd?: number): Promise<any>;
13
- export declare function getFirstTimestamp(influxConfig: InfluxConfig, deviceID: string): Promise<any>;
1
+ import { FilterTagMode, InfluxConfig, InfluxFillType } from "./types";
2
+ export declare function getInfluxAlerts(influxConfig: InfluxConfig, fields: string[], limit: number, offset: number, sort: any, filter: {
3
+ field: string;
4
+ value: string;
5
+ }, timeStart: number, timeEnd: number, aggregate?: boolean): Promise<any>;
6
+ export declare function getDwSlots(influxConfig: InfluxConfig, timeStart: number, timeEnd: number, filter: {
7
+ field: string;
8
+ value: string;
9
+ }): Promise<any>;
10
+ export declare function getInfluxDataV1(influxConfig: InfluxConfig, field: string, timeStart: number, timeEnd: number, filter: {
11
+ field: string;
12
+ value: string;
13
+ }, timeGroup: string, raw: boolean, fill?: InfluxFillType, filterTag?: number, tagInclude?: FilterTagMode): Promise<any>;
14
+ export declare function exportDataV1(influxConfig: InfluxConfig, field: string, timeStart: number, timeEnd: number, filter: {
15
+ field: string;
16
+ value: string;
17
+ }): Promise<any>;