@adventurelabs/scout-core 1.0.118 → 1.0.119
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/dist/helpers/components.d.ts +14 -0
- package/dist/helpers/components.js +155 -0
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.js +2 -0
- package/dist/helpers/versions_software.d.ts +10 -0
- package/dist/helpers/versions_software.js +91 -0
- package/dist/types/db.d.ts +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Database } from "../types/supabase";
|
|
2
|
+
import { IComponent, ComponentInsert } from "../types/db";
|
|
3
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
4
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
5
|
+
export declare function get_components_by_device_id(client: SupabaseClient<Database>, device_id: number): Promise<IWebResponseCompatible<IComponent[]>>;
|
|
6
|
+
export declare function get_component_by_id(client: SupabaseClient<Database>, component_id: number): Promise<IWebResponseCompatible<IComponent | null>>;
|
|
7
|
+
export declare function get_components_by_serial_number(client: SupabaseClient<Database>, serial_number: string): Promise<IWebResponseCompatible<IComponent[]>>;
|
|
8
|
+
export declare function get_components_by_product_number(client: SupabaseClient<Database>, product_number: string): Promise<IWebResponseCompatible<IComponent[]>>;
|
|
9
|
+
export declare function get_components_by_status(client: SupabaseClient<Database>, status: Database["public"]["Enums"]["component_status"]): Promise<IWebResponseCompatible<IComponent[]>>;
|
|
10
|
+
export declare function create_component(client: SupabaseClient<Database>, newComponent: ComponentInsert): Promise<IWebResponseCompatible<IComponent | null>>;
|
|
11
|
+
export declare function update_component(client: SupabaseClient<Database>, component_id: number, updatedComponent: Partial<ComponentInsert>): Promise<IWebResponseCompatible<IComponent | null>>;
|
|
12
|
+
export declare function delete_component(client: SupabaseClient<Database>, component_id: number): Promise<IWebResponseCompatible<IComponent | null>>;
|
|
13
|
+
export declare function update_component_status(client: SupabaseClient<Database>, component_id: number, status: Database["public"]["Enums"]["component_status"]): Promise<IWebResponseCompatible<IComponent | null>>;
|
|
14
|
+
export declare function get_components_by_certificate_id(client: SupabaseClient<Database>, certificate_id: number): Promise<IWebResponseCompatible<IComponent[]>>;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { IWebResponse } from "../types/requests";
|
|
2
|
+
export async function get_components_by_device_id(client, device_id) {
|
|
3
|
+
const { data, error } = await client
|
|
4
|
+
.from("components")
|
|
5
|
+
.select("*")
|
|
6
|
+
.eq("device_id", device_id)
|
|
7
|
+
.order("created_at", { ascending: false });
|
|
8
|
+
if (error) {
|
|
9
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
10
|
+
}
|
|
11
|
+
if (!data) {
|
|
12
|
+
return IWebResponse.error("No components found for device").to_compatible();
|
|
13
|
+
}
|
|
14
|
+
return IWebResponse.success(data).to_compatible();
|
|
15
|
+
}
|
|
16
|
+
export async function get_component_by_id(client, component_id) {
|
|
17
|
+
const { data, error } = await client
|
|
18
|
+
.from("components")
|
|
19
|
+
.select("*")
|
|
20
|
+
.eq("id", component_id)
|
|
21
|
+
.single();
|
|
22
|
+
if (error) {
|
|
23
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
24
|
+
}
|
|
25
|
+
if (!data) {
|
|
26
|
+
return IWebResponse.error("Component not found").to_compatible();
|
|
27
|
+
}
|
|
28
|
+
return IWebResponse.success(data).to_compatible();
|
|
29
|
+
}
|
|
30
|
+
export async function get_components_by_serial_number(client, serial_number) {
|
|
31
|
+
const { data, error } = await client
|
|
32
|
+
.from("components")
|
|
33
|
+
.select("*")
|
|
34
|
+
.eq("serial_number", serial_number)
|
|
35
|
+
.order("created_at", { ascending: false });
|
|
36
|
+
if (error) {
|
|
37
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
38
|
+
}
|
|
39
|
+
if (!data) {
|
|
40
|
+
return IWebResponse.error(`No components found with serial number: ${serial_number}`).to_compatible();
|
|
41
|
+
}
|
|
42
|
+
return IWebResponse.success(data).to_compatible();
|
|
43
|
+
}
|
|
44
|
+
export async function get_components_by_product_number(client, product_number) {
|
|
45
|
+
const { data, error } = await client
|
|
46
|
+
.from("components")
|
|
47
|
+
.select("*")
|
|
48
|
+
.eq("product_number", product_number)
|
|
49
|
+
.order("created_at", { ascending: false });
|
|
50
|
+
if (error) {
|
|
51
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
52
|
+
}
|
|
53
|
+
if (!data) {
|
|
54
|
+
return IWebResponse.error(`No components found with product number: ${product_number}`).to_compatible();
|
|
55
|
+
}
|
|
56
|
+
return IWebResponse.success(data).to_compatible();
|
|
57
|
+
}
|
|
58
|
+
export async function get_components_by_status(client, status) {
|
|
59
|
+
const { data, error } = await client
|
|
60
|
+
.from("components")
|
|
61
|
+
.select("*")
|
|
62
|
+
.eq("status", status)
|
|
63
|
+
.order("created_at", { ascending: false });
|
|
64
|
+
if (error) {
|
|
65
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
66
|
+
}
|
|
67
|
+
if (!data) {
|
|
68
|
+
return IWebResponse.error(`No components found with status: ${status}`).to_compatible();
|
|
69
|
+
}
|
|
70
|
+
return IWebResponse.success(data).to_compatible();
|
|
71
|
+
}
|
|
72
|
+
export async function create_component(client, newComponent) {
|
|
73
|
+
// Validate required fields
|
|
74
|
+
if (!newComponent.device_id) {
|
|
75
|
+
return IWebResponse.error("Device ID is required").to_compatible();
|
|
76
|
+
}
|
|
77
|
+
if (!newComponent.serial_number) {
|
|
78
|
+
return IWebResponse.error("Serial number is required").to_compatible();
|
|
79
|
+
}
|
|
80
|
+
const { data, error } = await client
|
|
81
|
+
.from("components")
|
|
82
|
+
.insert([newComponent])
|
|
83
|
+
.select("*")
|
|
84
|
+
.single();
|
|
85
|
+
if (error) {
|
|
86
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
87
|
+
}
|
|
88
|
+
if (!data) {
|
|
89
|
+
return IWebResponse.error("Failed to create component").to_compatible();
|
|
90
|
+
}
|
|
91
|
+
return IWebResponse.success(data).to_compatible();
|
|
92
|
+
}
|
|
93
|
+
export async function update_component(client, component_id, updatedComponent) {
|
|
94
|
+
// Remove fields that shouldn't be updated
|
|
95
|
+
const updateData = { ...updatedComponent };
|
|
96
|
+
delete updateData.id;
|
|
97
|
+
delete updateData.created_at;
|
|
98
|
+
const { data, error } = await client
|
|
99
|
+
.from("components")
|
|
100
|
+
.update(updateData)
|
|
101
|
+
.eq("id", component_id)
|
|
102
|
+
.select("*")
|
|
103
|
+
.single();
|
|
104
|
+
if (error) {
|
|
105
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
106
|
+
}
|
|
107
|
+
if (!data) {
|
|
108
|
+
return IWebResponse.error("Component not found or update failed").to_compatible();
|
|
109
|
+
}
|
|
110
|
+
return IWebResponse.success(data).to_compatible();
|
|
111
|
+
}
|
|
112
|
+
export async function delete_component(client, component_id) {
|
|
113
|
+
const { data, error } = await client
|
|
114
|
+
.from("components")
|
|
115
|
+
.delete()
|
|
116
|
+
.eq("id", component_id)
|
|
117
|
+
.select("*")
|
|
118
|
+
.single();
|
|
119
|
+
if (error) {
|
|
120
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
121
|
+
}
|
|
122
|
+
if (!data) {
|
|
123
|
+
return IWebResponse.error("Component not found or deletion failed").to_compatible();
|
|
124
|
+
}
|
|
125
|
+
return IWebResponse.success(data).to_compatible();
|
|
126
|
+
}
|
|
127
|
+
export async function update_component_status(client, component_id, status) {
|
|
128
|
+
const { data, error } = await client
|
|
129
|
+
.from("components")
|
|
130
|
+
.update({ status })
|
|
131
|
+
.eq("id", component_id)
|
|
132
|
+
.select("*")
|
|
133
|
+
.single();
|
|
134
|
+
if (error) {
|
|
135
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
136
|
+
}
|
|
137
|
+
if (!data) {
|
|
138
|
+
return IWebResponse.error("Component not found or status update failed").to_compatible();
|
|
139
|
+
}
|
|
140
|
+
return IWebResponse.success(data).to_compatible();
|
|
141
|
+
}
|
|
142
|
+
export async function get_components_by_certificate_id(client, certificate_id) {
|
|
143
|
+
const { data, error } = await client
|
|
144
|
+
.from("components")
|
|
145
|
+
.select("*")
|
|
146
|
+
.eq("certificate_id", certificate_id)
|
|
147
|
+
.order("created_at", { ascending: false });
|
|
148
|
+
if (error) {
|
|
149
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
150
|
+
}
|
|
151
|
+
if (!data) {
|
|
152
|
+
return IWebResponse.error(`No components found with certificate ID: ${certificate_id}`).to_compatible();
|
|
153
|
+
}
|
|
154
|
+
return IWebResponse.success(data).to_compatible();
|
|
155
|
+
}
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Database } from "../types/supabase";
|
|
2
|
+
import { IVersionsSoftware, VersionsSoftwareInsert } from "../types/db";
|
|
3
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
4
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
5
|
+
export declare function get_versions_software(client: SupabaseClient<Database>): Promise<IWebResponseCompatible<IVersionsSoftware[]>>;
|
|
6
|
+
export declare function get_versions_software_by_system(client: SupabaseClient<Database>, system: string): Promise<IWebResponseCompatible<IVersionsSoftware[]>>;
|
|
7
|
+
export declare function create_version_software(client: SupabaseClient<Database>, newVersionSoftware: VersionsSoftwareInsert): Promise<IWebResponseCompatible<IVersionsSoftware | null>>;
|
|
8
|
+
export declare function update_version_software(client: SupabaseClient<Database>, version_id: number, updatedVersionSoftware: Partial<VersionsSoftwareInsert>): Promise<IWebResponseCompatible<IVersionsSoftware | null>>;
|
|
9
|
+
export declare function delete_version_software(client: SupabaseClient<Database>, version_id: number): Promise<IWebResponseCompatible<IVersionsSoftware | null>>;
|
|
10
|
+
export declare function get_versions_software_by_created_by(client: SupabaseClient<Database>, user_id: string): Promise<IWebResponseCompatible<IVersionsSoftware[]>>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { IWebResponse } from "../types/requests";
|
|
2
|
+
export async function get_versions_software(client) {
|
|
3
|
+
const { data, error } = await client
|
|
4
|
+
.from("versions_software")
|
|
5
|
+
.select("*")
|
|
6
|
+
.order("created_at", { ascending: false });
|
|
7
|
+
if (error) {
|
|
8
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
9
|
+
}
|
|
10
|
+
if (!data) {
|
|
11
|
+
return IWebResponse.error("No software versions found").to_compatible();
|
|
12
|
+
}
|
|
13
|
+
return IWebResponse.success(data).to_compatible();
|
|
14
|
+
}
|
|
15
|
+
export async function get_versions_software_by_system(client, system) {
|
|
16
|
+
const { data, error } = await client
|
|
17
|
+
.from("versions_software")
|
|
18
|
+
.select("*")
|
|
19
|
+
.eq("system", system)
|
|
20
|
+
.order("created_at", { ascending: false });
|
|
21
|
+
if (error) {
|
|
22
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
23
|
+
}
|
|
24
|
+
if (!data) {
|
|
25
|
+
return IWebResponse.error(`No software versions found for system: ${system}`).to_compatible();
|
|
26
|
+
}
|
|
27
|
+
return IWebResponse.success(data).to_compatible();
|
|
28
|
+
}
|
|
29
|
+
export async function create_version_software(client, newVersionSoftware) {
|
|
30
|
+
const { data, error } = await client
|
|
31
|
+
.from("versions_software")
|
|
32
|
+
.insert([newVersionSoftware])
|
|
33
|
+
.select("*")
|
|
34
|
+
.single();
|
|
35
|
+
if (error) {
|
|
36
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
37
|
+
}
|
|
38
|
+
if (!data) {
|
|
39
|
+
return IWebResponse.error("Failed to create software version").to_compatible();
|
|
40
|
+
}
|
|
41
|
+
return IWebResponse.success(data).to_compatible();
|
|
42
|
+
}
|
|
43
|
+
export async function update_version_software(client, version_id, updatedVersionSoftware) {
|
|
44
|
+
// Remove fields that shouldn't be updated
|
|
45
|
+
const updateData = { ...updatedVersionSoftware };
|
|
46
|
+
delete updateData.id;
|
|
47
|
+
delete updateData.created_at;
|
|
48
|
+
delete updateData.created_by; // Only original creator can modify due to RLS
|
|
49
|
+
const { data, error } = await client
|
|
50
|
+
.from("versions_software")
|
|
51
|
+
.update(updateData)
|
|
52
|
+
.eq("id", version_id)
|
|
53
|
+
.select("*")
|
|
54
|
+
.single();
|
|
55
|
+
if (error) {
|
|
56
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
57
|
+
}
|
|
58
|
+
if (!data) {
|
|
59
|
+
return IWebResponse.error("Software version not found or update failed").to_compatible();
|
|
60
|
+
}
|
|
61
|
+
return IWebResponse.success(data).to_compatible();
|
|
62
|
+
}
|
|
63
|
+
export async function delete_version_software(client, version_id) {
|
|
64
|
+
const { data, error } = await client
|
|
65
|
+
.from("versions_software")
|
|
66
|
+
.delete()
|
|
67
|
+
.eq("id", version_id)
|
|
68
|
+
.select("*")
|
|
69
|
+
.single();
|
|
70
|
+
if (error) {
|
|
71
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
72
|
+
}
|
|
73
|
+
if (!data) {
|
|
74
|
+
return IWebResponse.error("Software version not found or deletion failed").to_compatible();
|
|
75
|
+
}
|
|
76
|
+
return IWebResponse.success(data).to_compatible();
|
|
77
|
+
}
|
|
78
|
+
export async function get_versions_software_by_created_by(client, user_id) {
|
|
79
|
+
const { data, error } = await client
|
|
80
|
+
.from("versions_software")
|
|
81
|
+
.select("*")
|
|
82
|
+
.eq("created_by", user_id)
|
|
83
|
+
.order("created_at", { ascending: false });
|
|
84
|
+
if (error) {
|
|
85
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
86
|
+
}
|
|
87
|
+
if (!data) {
|
|
88
|
+
return IWebResponse.error("No software versions found for user").to_compatible();
|
|
89
|
+
}
|
|
90
|
+
return IWebResponse.success(data).to_compatible();
|
|
91
|
+
}
|
package/dist/types/db.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ export type IConnectivity = Database["public"]["Tables"]["connectivity"]["Row"];
|
|
|
24
24
|
export type IHeartbeat = Database["public"]["Tables"]["heartbeats"]["Row"];
|
|
25
25
|
export type IOperator = Database["public"]["Tables"]["operators"]["Row"];
|
|
26
26
|
export type IProvider = Database["public"]["Tables"]["providers"]["Row"];
|
|
27
|
+
export type IComponent = Database["public"]["Tables"]["components"]["Row"];
|
|
28
|
+
export type IVersionsSoftware = Database["public"]["Tables"]["versions_software"]["Row"];
|
|
29
|
+
export type ComponentInsert = Database["public"]["Tables"]["components"]["Insert"];
|
|
30
|
+
export type VersionsSoftwareInsert = Database["public"]["Tables"]["versions_software"]["Insert"];
|
|
27
31
|
export type IEventWithTags = Database["public"]["CompositeTypes"]["event_with_tags"] & {
|
|
28
32
|
earthranger_url: string | null;
|
|
29
33
|
file_path: string | null;
|