@adventurelabs/scout-core 1.4.67 → 1.4.69
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/index.d.ts +3 -0
- package/dist/helpers/index.js +3 -0
- package/dist/helpers/lifecycle.d.ts +14 -0
- package/dist/helpers/lifecycle.js +74 -0
- package/dist/helpers/parts.d.ts +19 -13
- package/dist/helpers/parts.js +51 -47
- package/dist/helpers/pubsub_token.d.ts +5 -0
- package/dist/helpers/pubsub_token.js +14 -0
- package/dist/helpers/pubsub_token_server.d.ts +7 -0
- package/dist/helpers/pubsub_token_server.js +7 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/providers/ScoutRefreshProvider.d.ts +208 -15
- package/dist/types/db.d.ts +2 -0
- package/dist/types/pubsub_token.d.ts +7 -0
- package/dist/types/supabase.d.ts +217 -17
- package/dist/types/supabase.js +2 -2
- package/package.json +1 -1
- package/dist/helpers/components.d.ts +0 -14
- package/dist/helpers/components.js +0 -155
- package/dist/helpers/operator.d.ts +0 -5
- package/dist/helpers/operator.js +0 -64
- package/dist/hooks/useHerdData.d.ts +0 -167
- package/dist/hooks/useHerdData.js +0 -153
- package/dist/hooks/useScoutBrowserClient.d.ts +0 -11
- package/dist/hooks/useScoutBrowserClient.js +0 -17
- package/dist/hooks/useScoutDbListener.d.ts +0 -3
- package/dist/hooks/useScoutDbListener.js +0 -134
- package/dist/hooks/useScoutRealtimeConnectivity copy.d.ts +0 -3
- package/dist/hooks/useScoutRealtimeConnectivity copy.js +0 -159
- package/dist/hooks/useScoutRealtimeDevices copy.d.ts +0 -3
- package/dist/hooks/useScoutRealtimeDevices copy.js +0 -55
- package/dist/types/data.d.ts +0 -4
- /package/dist/types/{data.js → pubsub_token.js} +0 -0
package/dist/helpers/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./health_metrics";
|
|
|
13
13
|
export * from "./heartbeats";
|
|
14
14
|
export * from "./herds";
|
|
15
15
|
export * from "./location";
|
|
16
|
+
export * from "./lifecycle";
|
|
16
17
|
export * from "./plans";
|
|
17
18
|
export * from "./sessions";
|
|
18
19
|
export * from "./segmentations_sam3";
|
|
@@ -30,4 +31,6 @@ export * from "./versions_software";
|
|
|
30
31
|
export * from "./versions_software_server";
|
|
31
32
|
export * from "./artifacts";
|
|
32
33
|
export * from "./pins";
|
|
34
|
+
export * from "./pubsub_token";
|
|
35
|
+
export * from "./pubsub_token_server";
|
|
33
36
|
export * from "./storagePath";
|
package/dist/helpers/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./health_metrics";
|
|
|
13
13
|
export * from "./heartbeats";
|
|
14
14
|
export * from "./herds";
|
|
15
15
|
export * from "./location";
|
|
16
|
+
export * from "./lifecycle";
|
|
16
17
|
export * from "./plans";
|
|
17
18
|
export * from "./sessions";
|
|
18
19
|
export * from "./segmentations_sam3";
|
|
@@ -30,4 +31,6 @@ export * from "./versions_software";
|
|
|
30
31
|
export * from "./versions_software_server";
|
|
31
32
|
export * from "./artifacts";
|
|
32
33
|
export * from "./pins";
|
|
34
|
+
export * from "./pubsub_token";
|
|
35
|
+
export * from "./pubsub_token_server";
|
|
33
36
|
export * from "./storagePath";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { Database } from "../types/supabase";
|
|
3
|
+
import { EntityLifecycle, IArtifact, IDeviceRow, IEvent, IPart, ISession, IUserProfileRow } from "../types/db";
|
|
4
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
5
|
+
export interface LifecycleUpdateOptions {
|
|
6
|
+
lifecycle_reason?: string | null;
|
|
7
|
+
lifecycle_changed_by?: string | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function update_user_lifecycle(client: SupabaseClient<Database>, user_id: string, lifecycle: EntityLifecycle, options?: LifecycleUpdateOptions): Promise<IWebResponseCompatible<IUserProfileRow | null>>;
|
|
10
|
+
export declare function update_device_lifecycle(client: SupabaseClient<Database>, device_id: number, lifecycle: EntityLifecycle, options?: LifecycleUpdateOptions): Promise<IWebResponseCompatible<IDeviceRow | null>>;
|
|
11
|
+
export declare function update_session_lifecycle(client: SupabaseClient<Database>, session_id: number, lifecycle: EntityLifecycle, options?: LifecycleUpdateOptions): Promise<IWebResponseCompatible<ISession | null>>;
|
|
12
|
+
export declare function update_part_lifecycle(client: SupabaseClient<Database>, part_id: number, lifecycle: EntityLifecycle, options?: LifecycleUpdateOptions): Promise<IWebResponseCompatible<IPart | null>>;
|
|
13
|
+
export declare function update_event_lifecycle(client: SupabaseClient<Database>, event_id: number, lifecycle: EntityLifecycle, options?: LifecycleUpdateOptions): Promise<IWebResponseCompatible<IEvent | null>>;
|
|
14
|
+
export declare function update_artifact_lifecycle(client: SupabaseClient<Database>, artifact_id: number, lifecycle: EntityLifecycle, options?: LifecycleUpdateOptions): Promise<IWebResponseCompatible<IArtifact | null>>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { IWebResponse } from "../types/requests";
|
|
2
|
+
function build_lifecycle_patch(lifecycle, options) {
|
|
3
|
+
const patch = { lifecycle };
|
|
4
|
+
if (options && "lifecycle_reason" in options) {
|
|
5
|
+
patch.lifecycle_reason = options.lifecycle_reason ?? null;
|
|
6
|
+
}
|
|
7
|
+
if (options && "lifecycle_changed_by" in options) {
|
|
8
|
+
patch.lifecycle_changed_by = options.lifecycle_changed_by ?? null;
|
|
9
|
+
}
|
|
10
|
+
return patch;
|
|
11
|
+
}
|
|
12
|
+
function lifecycle_result(data, error, not_found_msg) {
|
|
13
|
+
if (error) {
|
|
14
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
15
|
+
}
|
|
16
|
+
if (!data) {
|
|
17
|
+
return IWebResponse.error(not_found_msg).to_compatible();
|
|
18
|
+
}
|
|
19
|
+
return IWebResponse.success(data).to_compatible();
|
|
20
|
+
}
|
|
21
|
+
export async function update_user_lifecycle(client, user_id, lifecycle, options) {
|
|
22
|
+
const { data, error } = await client
|
|
23
|
+
.from("users")
|
|
24
|
+
.update(build_lifecycle_patch(lifecycle, options))
|
|
25
|
+
.eq("id", user_id)
|
|
26
|
+
.select("*")
|
|
27
|
+
.single();
|
|
28
|
+
return lifecycle_result(data, error, "User not found or lifecycle update failed");
|
|
29
|
+
}
|
|
30
|
+
export async function update_device_lifecycle(client, device_id, lifecycle, options) {
|
|
31
|
+
const { data, error } = await client
|
|
32
|
+
.from("devices")
|
|
33
|
+
.update(build_lifecycle_patch(lifecycle, options))
|
|
34
|
+
.eq("id", device_id)
|
|
35
|
+
.select("*")
|
|
36
|
+
.single();
|
|
37
|
+
return lifecycle_result(data, error, "Device not found or lifecycle update failed");
|
|
38
|
+
}
|
|
39
|
+
export async function update_session_lifecycle(client, session_id, lifecycle, options) {
|
|
40
|
+
const { data, error } = await client
|
|
41
|
+
.from("sessions")
|
|
42
|
+
.update(build_lifecycle_patch(lifecycle, options))
|
|
43
|
+
.eq("id", session_id)
|
|
44
|
+
.select("*")
|
|
45
|
+
.single();
|
|
46
|
+
return lifecycle_result(data, error, "Session not found or lifecycle update failed");
|
|
47
|
+
}
|
|
48
|
+
export async function update_part_lifecycle(client, part_id, lifecycle, options) {
|
|
49
|
+
const { data, error } = await client
|
|
50
|
+
.from("parts")
|
|
51
|
+
.update(build_lifecycle_patch(lifecycle, options))
|
|
52
|
+
.eq("id", part_id)
|
|
53
|
+
.select("*")
|
|
54
|
+
.single();
|
|
55
|
+
return lifecycle_result(data, error, "Part not found or lifecycle update failed");
|
|
56
|
+
}
|
|
57
|
+
export async function update_event_lifecycle(client, event_id, lifecycle, options) {
|
|
58
|
+
const { data, error } = await client
|
|
59
|
+
.from("events")
|
|
60
|
+
.update(build_lifecycle_patch(lifecycle, options))
|
|
61
|
+
.eq("id", event_id)
|
|
62
|
+
.select("*")
|
|
63
|
+
.single();
|
|
64
|
+
return lifecycle_result(data, error, "Event not found or lifecycle update failed");
|
|
65
|
+
}
|
|
66
|
+
export async function update_artifact_lifecycle(client, artifact_id, lifecycle, options) {
|
|
67
|
+
const { data, error } = await client
|
|
68
|
+
.from("artifacts")
|
|
69
|
+
.update(build_lifecycle_patch(lifecycle, options))
|
|
70
|
+
.eq("id", artifact_id)
|
|
71
|
+
.select("*")
|
|
72
|
+
.single();
|
|
73
|
+
return lifecycle_result(data, error, "Artifact not found or lifecycle update failed");
|
|
74
|
+
}
|
package/dist/helpers/parts.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Database } from "../types/supabase";
|
|
2
|
-
import { IPart, PartInsert } from "../types/db";
|
|
2
|
+
import { EntityLifecycle, IPart, PartInsert } from "../types/db";
|
|
3
3
|
import { IWebResponseCompatible } from "../types/requests";
|
|
4
4
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
5
|
+
import { LifecycleUpdateOptions } from "./lifecycle";
|
|
5
6
|
/**
|
|
6
7
|
* Retrieves all active parts for a specific device
|
|
7
8
|
* @param client - Supabase client instance
|
|
@@ -27,11 +28,13 @@ export declare function get_parts_by_serial_number(client: SupabaseClient<Databa
|
|
|
27
28
|
*/
|
|
28
29
|
export declare function get_parts_by_product_number(client: SupabaseClient<Database>, product_number: string): Promise<IWebResponseCompatible<IPart[]>>;
|
|
29
30
|
/**
|
|
30
|
-
* Retrieves all
|
|
31
|
+
* Retrieves all parts with a specific lifecycle state
|
|
31
32
|
* @param client - Supabase client instance
|
|
32
|
-
* @param
|
|
33
|
+
* @param lifecycle - Lifecycle state to filter by
|
|
33
34
|
*/
|
|
34
|
-
export declare function
|
|
35
|
+
export declare function get_parts_by_lifecycle(client: SupabaseClient<Database>, lifecycle: EntityLifecycle): Promise<IWebResponseCompatible<IPart[]>>;
|
|
36
|
+
/** @deprecated Use get_parts_by_lifecycle */
|
|
37
|
+
export declare const get_parts_by_status: typeof get_parts_by_lifecycle;
|
|
35
38
|
/**
|
|
36
39
|
* Creates a new part with validation
|
|
37
40
|
* @param client - Supabase client instance
|
|
@@ -46,18 +49,20 @@ export declare function create_part(client: SupabaseClient<Database>, newPart: P
|
|
|
46
49
|
*/
|
|
47
50
|
export declare function update_part(client: SupabaseClient<Database>, part_id: number, updatedPart: Partial<PartInsert>): Promise<IWebResponseCompatible<IPart | null>>;
|
|
48
51
|
/**
|
|
49
|
-
*
|
|
52
|
+
* Marks an active part as deleted (lifecycle)
|
|
50
53
|
* @param client - Supabase client instance
|
|
51
54
|
* @param part_id - ID of the part to delete
|
|
55
|
+
* @param options - Optional lifecycle metadata
|
|
52
56
|
*/
|
|
53
|
-
export declare function delete_part(client: SupabaseClient<Database>, part_id: number): Promise<IWebResponseCompatible<IPart | null>>;
|
|
57
|
+
export declare function delete_part(client: SupabaseClient<Database>, part_id: number, options?: LifecycleUpdateOptions): Promise<IWebResponseCompatible<IPart | null>>;
|
|
54
58
|
/**
|
|
55
|
-
* Updates the
|
|
59
|
+
* Updates the lifecycle of a specific part
|
|
56
60
|
* @param client - Supabase client instance
|
|
57
61
|
* @param part_id - ID of the part to update
|
|
58
|
-
* @param
|
|
62
|
+
* @param lifecycle - New lifecycle state
|
|
63
|
+
* @param options - Optional lifecycle metadata
|
|
59
64
|
*/
|
|
60
|
-
export declare function update_part_status(client: SupabaseClient<Database>, part_id: number,
|
|
65
|
+
export declare function update_part_status(client: SupabaseClient<Database>, part_id: number, lifecycle: EntityLifecycle, options?: LifecycleUpdateOptions): Promise<IWebResponseCompatible<IPart | null>>;
|
|
61
66
|
/**
|
|
62
67
|
* Retrieves all active parts associated with a certificate
|
|
63
68
|
* @param client - Supabase client instance
|
|
@@ -71,19 +76,20 @@ export declare function get_parts_by_certificate_id(client: SupabaseClient<Datab
|
|
|
71
76
|
*/
|
|
72
77
|
export declare function get_parts_by_herd_id(client: SupabaseClient<Database>, herd_id: number): Promise<IWebResponseCompatible<IPart[]>>;
|
|
73
78
|
/**
|
|
74
|
-
* Restores a
|
|
79
|
+
* Restores a deleted part to active lifecycle
|
|
75
80
|
* @param client - Supabase client instance
|
|
76
81
|
* @param part_id - ID of the part to restore
|
|
82
|
+
* @param options - Optional lifecycle metadata
|
|
77
83
|
*/
|
|
78
|
-
export declare function restore_part(client: SupabaseClient<Database>, part_id: number): Promise<IWebResponseCompatible<IPart | null>>;
|
|
84
|
+
export declare function restore_part(client: SupabaseClient<Database>, part_id: number, options?: LifecycleUpdateOptions): Promise<IWebResponseCompatible<IPart | null>>;
|
|
79
85
|
/**
|
|
80
|
-
* Permanently deletes a
|
|
86
|
+
* Permanently deletes a part that is already in deleted lifecycle
|
|
81
87
|
* @param client - Supabase client instance
|
|
82
88
|
* @param part_id - ID of the part to permanently delete
|
|
83
89
|
*/
|
|
84
90
|
export declare function hard_delete_part(client: SupabaseClient<Database>, part_id: number): Promise<IWebResponseCompatible<IPart | null>>;
|
|
85
91
|
/**
|
|
86
|
-
* Retrieves all
|
|
92
|
+
* Retrieves all deleted parts for a specific device
|
|
87
93
|
* @param client - Supabase client instance
|
|
88
94
|
* @param device_id - ID of the device to get deleted parts for
|
|
89
95
|
*/
|
package/dist/helpers/parts.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IWebResponse } from "../types/requests";
|
|
2
|
+
import { update_part_lifecycle } from "./lifecycle";
|
|
2
3
|
/**
|
|
3
4
|
* Retrieves all active parts for a specific device
|
|
4
5
|
* @param client - Supabase client instance
|
|
@@ -9,7 +10,7 @@ export async function get_parts_by_device_id(client, device_id) {
|
|
|
9
10
|
.from("parts")
|
|
10
11
|
.select("*")
|
|
11
12
|
.eq("device_id", device_id)
|
|
12
|
-
.
|
|
13
|
+
.eq("lifecycle", "active")
|
|
13
14
|
.order("created_at", { ascending: false });
|
|
14
15
|
if (error) {
|
|
15
16
|
return IWebResponse.error(error.message).to_compatible();
|
|
@@ -29,7 +30,7 @@ export async function get_part_by_id(client, part_id) {
|
|
|
29
30
|
.from("parts")
|
|
30
31
|
.select("*")
|
|
31
32
|
.eq("id", part_id)
|
|
32
|
-
.
|
|
33
|
+
.eq("lifecycle", "active")
|
|
33
34
|
.single();
|
|
34
35
|
if (error) {
|
|
35
36
|
return IWebResponse.error(error.message).to_compatible();
|
|
@@ -49,7 +50,7 @@ export async function get_parts_by_serial_number(client, serial_number) {
|
|
|
49
50
|
.from("parts")
|
|
50
51
|
.select("*")
|
|
51
52
|
.eq("serial_number", serial_number)
|
|
52
|
-
.
|
|
53
|
+
.eq("lifecycle", "active")
|
|
53
54
|
.order("created_at", { ascending: false });
|
|
54
55
|
if (error) {
|
|
55
56
|
return IWebResponse.error(error.message).to_compatible();
|
|
@@ -69,7 +70,7 @@ export async function get_parts_by_product_number(client, product_number) {
|
|
|
69
70
|
.from("parts")
|
|
70
71
|
.select("*")
|
|
71
72
|
.eq("product_number", product_number)
|
|
72
|
-
.
|
|
73
|
+
.eq("lifecycle", "active")
|
|
73
74
|
.order("created_at", { ascending: false });
|
|
74
75
|
if (error) {
|
|
75
76
|
return IWebResponse.error(error.message).to_compatible();
|
|
@@ -80,25 +81,26 @@ export async function get_parts_by_product_number(client, product_number) {
|
|
|
80
81
|
return IWebResponse.success(data).to_compatible();
|
|
81
82
|
}
|
|
82
83
|
/**
|
|
83
|
-
* Retrieves all
|
|
84
|
+
* Retrieves all parts with a specific lifecycle state
|
|
84
85
|
* @param client - Supabase client instance
|
|
85
|
-
* @param
|
|
86
|
+
* @param lifecycle - Lifecycle state to filter by
|
|
86
87
|
*/
|
|
87
|
-
export async function
|
|
88
|
+
export async function get_parts_by_lifecycle(client, lifecycle) {
|
|
88
89
|
const { data, error } = await client
|
|
89
90
|
.from("parts")
|
|
90
91
|
.select("*")
|
|
91
|
-
.eq("
|
|
92
|
-
.is("deleted_at", null)
|
|
92
|
+
.eq("lifecycle", lifecycle)
|
|
93
93
|
.order("created_at", { ascending: false });
|
|
94
94
|
if (error) {
|
|
95
95
|
return IWebResponse.error(error.message).to_compatible();
|
|
96
96
|
}
|
|
97
97
|
if (!data) {
|
|
98
|
-
return IWebResponse.error(`No parts found with
|
|
98
|
+
return IWebResponse.error(`No parts found with lifecycle: ${lifecycle}`).to_compatible();
|
|
99
99
|
}
|
|
100
100
|
return IWebResponse.success(data).to_compatible();
|
|
101
101
|
}
|
|
102
|
+
/** @deprecated Use get_parts_by_lifecycle */
|
|
103
|
+
export const get_parts_by_status = get_parts_by_lifecycle;
|
|
102
104
|
/**
|
|
103
105
|
* Creates a new part with validation
|
|
104
106
|
* @param client - Supabase client instance
|
|
@@ -154,17 +156,25 @@ export async function update_part(client, part_id, updatedPart) {
|
|
|
154
156
|
return IWebResponse.success(data).to_compatible();
|
|
155
157
|
}
|
|
156
158
|
/**
|
|
157
|
-
*
|
|
159
|
+
* Marks an active part as deleted (lifecycle)
|
|
158
160
|
* @param client - Supabase client instance
|
|
159
161
|
* @param part_id - ID of the part to delete
|
|
162
|
+
* @param options - Optional lifecycle metadata
|
|
160
163
|
*/
|
|
161
|
-
export async function delete_part(client, part_id) {
|
|
162
|
-
// Soft delete by setting deleted_at timestamp
|
|
164
|
+
export async function delete_part(client, part_id, options) {
|
|
163
165
|
const { data, error } = await client
|
|
164
166
|
.from("parts")
|
|
165
|
-
.update({
|
|
167
|
+
.update({
|
|
168
|
+
lifecycle: "deleted",
|
|
169
|
+
...(options?.lifecycle_reason !== undefined && {
|
|
170
|
+
lifecycle_reason: options.lifecycle_reason,
|
|
171
|
+
}),
|
|
172
|
+
...(options?.lifecycle_changed_by !== undefined && {
|
|
173
|
+
lifecycle_changed_by: options.lifecycle_changed_by,
|
|
174
|
+
}),
|
|
175
|
+
})
|
|
166
176
|
.eq("id", part_id)
|
|
167
|
-
.
|
|
177
|
+
.eq("lifecycle", "active")
|
|
168
178
|
.select("*")
|
|
169
179
|
.single();
|
|
170
180
|
if (error) {
|
|
@@ -176,26 +186,14 @@ export async function delete_part(client, part_id) {
|
|
|
176
186
|
return IWebResponse.success(data).to_compatible();
|
|
177
187
|
}
|
|
178
188
|
/**
|
|
179
|
-
* Updates the
|
|
189
|
+
* Updates the lifecycle of a specific part
|
|
180
190
|
* @param client - Supabase client instance
|
|
181
191
|
* @param part_id - ID of the part to update
|
|
182
|
-
* @param
|
|
192
|
+
* @param lifecycle - New lifecycle state
|
|
193
|
+
* @param options - Optional lifecycle metadata
|
|
183
194
|
*/
|
|
184
|
-
export async function update_part_status(client, part_id,
|
|
185
|
-
|
|
186
|
-
.from("parts")
|
|
187
|
-
.update({ status })
|
|
188
|
-
.eq("id", part_id)
|
|
189
|
-
.is("deleted_at", null)
|
|
190
|
-
.select("*")
|
|
191
|
-
.single();
|
|
192
|
-
if (error) {
|
|
193
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
194
|
-
}
|
|
195
|
-
if (!data) {
|
|
196
|
-
return IWebResponse.error("Part not found or status update failed").to_compatible();
|
|
197
|
-
}
|
|
198
|
-
return IWebResponse.success(data).to_compatible();
|
|
195
|
+
export async function update_part_status(client, part_id, lifecycle, options) {
|
|
196
|
+
return update_part_lifecycle(client, part_id, lifecycle, options);
|
|
199
197
|
}
|
|
200
198
|
/**
|
|
201
199
|
* Retrieves all active parts associated with a certificate
|
|
@@ -207,7 +205,7 @@ export async function get_parts_by_certificate_id(client, certificate_id) {
|
|
|
207
205
|
.from("parts")
|
|
208
206
|
.select("*")
|
|
209
207
|
.eq("certificate_id", certificate_id)
|
|
210
|
-
.
|
|
208
|
+
.eq("lifecycle", "active")
|
|
211
209
|
.order("created_at", { ascending: false });
|
|
212
210
|
if (error) {
|
|
213
211
|
return IWebResponse.error(error.message).to_compatible();
|
|
@@ -230,7 +228,7 @@ export async function get_parts_by_herd_id(client, herd_id) {
|
|
|
230
228
|
devices!parts_device_id_fkey(herd_id)
|
|
231
229
|
`)
|
|
232
230
|
.eq("devices.herd_id", herd_id)
|
|
233
|
-
.
|
|
231
|
+
.eq("lifecycle", "active")
|
|
234
232
|
.order("created_at", { ascending: false });
|
|
235
233
|
if (error) {
|
|
236
234
|
return IWebResponse.error(error.message).to_compatible();
|
|
@@ -241,17 +239,25 @@ export async function get_parts_by_herd_id(client, herd_id) {
|
|
|
241
239
|
return IWebResponse.success(data).to_compatible();
|
|
242
240
|
}
|
|
243
241
|
/**
|
|
244
|
-
* Restores a
|
|
242
|
+
* Restores a deleted part to active lifecycle
|
|
245
243
|
* @param client - Supabase client instance
|
|
246
244
|
* @param part_id - ID of the part to restore
|
|
245
|
+
* @param options - Optional lifecycle metadata
|
|
247
246
|
*/
|
|
248
|
-
export async function restore_part(client, part_id) {
|
|
249
|
-
// Restore soft deleted part by setting deleted_at to null
|
|
247
|
+
export async function restore_part(client, part_id, options) {
|
|
250
248
|
const { data, error } = await client
|
|
251
249
|
.from("parts")
|
|
252
|
-
.update({
|
|
250
|
+
.update({
|
|
251
|
+
lifecycle: "active",
|
|
252
|
+
...(options?.lifecycle_reason !== undefined && {
|
|
253
|
+
lifecycle_reason: options.lifecycle_reason,
|
|
254
|
+
}),
|
|
255
|
+
...(options?.lifecycle_changed_by !== undefined && {
|
|
256
|
+
lifecycle_changed_by: options.lifecycle_changed_by,
|
|
257
|
+
}),
|
|
258
|
+
})
|
|
253
259
|
.eq("id", part_id)
|
|
254
|
-
.
|
|
260
|
+
.eq("lifecycle", "deleted")
|
|
255
261
|
.select("*")
|
|
256
262
|
.single();
|
|
257
263
|
if (error) {
|
|
@@ -263,17 +269,16 @@ export async function restore_part(client, part_id) {
|
|
|
263
269
|
return IWebResponse.success(data).to_compatible();
|
|
264
270
|
}
|
|
265
271
|
/**
|
|
266
|
-
* Permanently deletes a
|
|
272
|
+
* Permanently deletes a part that is already in deleted lifecycle
|
|
267
273
|
* @param client - Supabase client instance
|
|
268
274
|
* @param part_id - ID of the part to permanently delete
|
|
269
275
|
*/
|
|
270
276
|
export async function hard_delete_part(client, part_id) {
|
|
271
|
-
// Permanently delete the part (only use for already soft-deleted parts)
|
|
272
277
|
const { data, error } = await client
|
|
273
278
|
.from("parts")
|
|
274
279
|
.delete()
|
|
275
280
|
.eq("id", part_id)
|
|
276
|
-
.
|
|
281
|
+
.eq("lifecycle", "deleted")
|
|
277
282
|
.select("*")
|
|
278
283
|
.single();
|
|
279
284
|
if (error) {
|
|
@@ -285,7 +290,7 @@ export async function hard_delete_part(client, part_id) {
|
|
|
285
290
|
return IWebResponse.success(data).to_compatible();
|
|
286
291
|
}
|
|
287
292
|
/**
|
|
288
|
-
* Retrieves all
|
|
293
|
+
* Retrieves all deleted parts for a specific device
|
|
289
294
|
* @param client - Supabase client instance
|
|
290
295
|
* @param device_id - ID of the device to get deleted parts for
|
|
291
296
|
*/
|
|
@@ -294,8 +299,8 @@ export async function get_deleted_parts_by_device_id(client, device_id) {
|
|
|
294
299
|
.from("parts")
|
|
295
300
|
.select("*")
|
|
296
301
|
.eq("device_id", device_id)
|
|
297
|
-
.
|
|
298
|
-
.order("
|
|
302
|
+
.eq("lifecycle", "deleted")
|
|
303
|
+
.order("lifecycle_changed_at", { ascending: false });
|
|
299
304
|
if (error) {
|
|
300
305
|
return IWebResponse.error(error.message).to_compatible();
|
|
301
306
|
}
|
|
@@ -311,13 +316,12 @@ export async function get_deleted_parts_by_device_id(client, device_id) {
|
|
|
311
316
|
* @param serial_number - Serial number to search for
|
|
312
317
|
*/
|
|
313
318
|
export async function get_parts_by_product_and_serial(client, product_number, serial_number) {
|
|
314
|
-
// Get part by the composite unique constraint
|
|
315
319
|
const { data, error } = await client
|
|
316
320
|
.from("parts")
|
|
317
321
|
.select("*")
|
|
318
322
|
.eq("product_number", product_number)
|
|
319
323
|
.eq("serial_number", serial_number)
|
|
320
|
-
.
|
|
324
|
+
.eq("lifecycle", "active")
|
|
321
325
|
.single();
|
|
322
326
|
if (error) {
|
|
323
327
|
return IWebResponse.error(error.message).to_compatible();
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { Database } from "../types/supabase";
|
|
3
|
+
import { IPubsubTokenMint } from "../types/pubsub_token";
|
|
4
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
5
|
+
export declare function mint_pubsub_token(client: SupabaseClient<Database>): Promise<IWebResponseCompatible<IPubsubTokenMint>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IWebResponse } from "../types/requests";
|
|
2
|
+
export async function mint_pubsub_token(client) {
|
|
3
|
+
const { data, error } = await client.functions.invoke("mint-pubsub-token", {
|
|
4
|
+
method: "POST",
|
|
5
|
+
});
|
|
6
|
+
if (error) {
|
|
7
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
8
|
+
}
|
|
9
|
+
const mint = data;
|
|
10
|
+
if (!mint?.token) {
|
|
11
|
+
return IWebResponse.error("mint-pubsub-token returned no token").to_compatible();
|
|
12
|
+
}
|
|
13
|
+
return IWebResponse.success(mint).to_compatible();
|
|
14
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { Database } from "../types/supabase";
|
|
3
|
+
import { IPubsubTokenMint } from "../types/pubsub_token";
|
|
4
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
5
|
+
export declare function server_mint_pubsub_token(options?: {
|
|
6
|
+
client?: SupabaseClient<Database>;
|
|
7
|
+
}): Promise<IWebResponseCompatible<IPubsubTokenMint>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { newServerClient } from "../supabase/server";
|
|
3
|
+
import { mint_pubsub_token } from "./pubsub_token";
|
|
4
|
+
export async function server_mint_pubsub_token(options) {
|
|
5
|
+
const client = options?.client ?? (await newServerClient());
|
|
6
|
+
return mint_pubsub_token(client);
|
|
7
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./types/supabase";
|
|
|
10
10
|
export * from "./types/bounding_boxes";
|
|
11
11
|
export * from "./types/events";
|
|
12
12
|
export * from "./types/connectivity";
|
|
13
|
+
export * from "./types/pubsub_token";
|
|
13
14
|
export * from "./helpers/analysis_usage";
|
|
14
15
|
export * from "./helpers/artifacts";
|
|
15
16
|
export * from "./helpers/auth";
|
|
@@ -43,6 +44,8 @@ export * from "./helpers/cache";
|
|
|
43
44
|
export * from "./helpers/health_metrics";
|
|
44
45
|
export * from "./helpers/heartbeats";
|
|
45
46
|
export * from "./helpers/providers";
|
|
47
|
+
export * from "./helpers/pubsub_token";
|
|
48
|
+
export * from "./helpers/pubsub_token_server";
|
|
46
49
|
export * from "./helpers/observations";
|
|
47
50
|
export * from "./helpers/operators";
|
|
48
51
|
export * from "./helpers/versions_software";
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ export * from "./types/supabase";
|
|
|
12
12
|
export * from "./types/bounding_boxes";
|
|
13
13
|
export * from "./types/events";
|
|
14
14
|
export * from "./types/connectivity";
|
|
15
|
+
export * from "./types/pubsub_token";
|
|
15
16
|
// Helpers
|
|
16
17
|
export * from "./helpers/analysis_usage";
|
|
17
18
|
export * from "./helpers/artifacts";
|
|
@@ -46,6 +47,8 @@ export * from "./helpers/cache";
|
|
|
46
47
|
export * from "./helpers/health_metrics";
|
|
47
48
|
export * from "./helpers/heartbeats";
|
|
48
49
|
export * from "./helpers/providers";
|
|
50
|
+
export * from "./helpers/pubsub_token";
|
|
51
|
+
export * from "./helpers/pubsub_token_server";
|
|
49
52
|
export * from "./helpers/observations";
|
|
50
53
|
export * from "./helpers/operators";
|
|
51
54
|
export * from "./helpers/versions_software";
|