@adventurelabs/scout-core 1.4.79 → 1.4.81
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/herd_roles.d.ts +5 -1
- package/dist/helpers/herd_roles.js +47 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/points_for_user.d.ts +11 -0
- package/dist/helpers/points_for_user.js +54 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/types/db.d.ts +12 -0
- package/dist/types/supabase.d.ts +78 -0
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
2
|
import { Database } from "../types/supabase";
|
|
3
|
-
import { IAbility, IHerdRole, IHerdRoleAbilityRow, IHerdRoleWithAbilities } from "../types/db";
|
|
3
|
+
import { IAbility, IHerdRole, IHerdRoleAbilityRow, IHerdRoleWithAbilities, IPlatformDefaultRoleAbilitiesGroup } from "../types/db";
|
|
4
4
|
import { IWebResponseCompatible } from "../types/requests";
|
|
5
5
|
export declare function server_list_abilities(supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IAbility[]>>;
|
|
6
|
+
export declare function server_get_abilities_by_ids(ids: number[], supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IAbility[]>>;
|
|
6
7
|
export declare function server_get_herd_roles(herd_id: number, supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdRole[]>>;
|
|
7
8
|
export declare function server_get_herd_roles_with_abilities(herd_id: number, supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdRoleWithAbilities[]>>;
|
|
8
9
|
export declare function server_get_herd_role_by_system_name(herd_id: number, system_name: string, supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdRole | null>>;
|
|
@@ -12,3 +13,6 @@ export declare function server_update_herd_role(herd_role_id: number, patch: {
|
|
|
12
13
|
}, supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdRole | null>>;
|
|
13
14
|
export declare function server_delete_herd_role(herd_role_id: number, supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<null>>;
|
|
14
15
|
export declare function server_set_herd_role_abilities(herd_role_id: number, ability_ids: number[], supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdRoleAbilityRow[]>>;
|
|
16
|
+
export declare function server_get_platform_default_role_abilities(supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IPlatformDefaultRoleAbilitiesGroup[]>>;
|
|
17
|
+
export declare function server_set_platform_default_role_abilities(system_name: string, ability_keys: string[], supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<null>>;
|
|
18
|
+
export declare function server_reset_herd_default_role_abilities(herd_id: number, supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<null>>;
|
|
@@ -12,6 +12,21 @@ export async function server_list_abilities(supabaseClient) {
|
|
|
12
12
|
}
|
|
13
13
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
14
14
|
}
|
|
15
|
+
export async function server_get_abilities_by_ids(ids, supabaseClient) {
|
|
16
|
+
if (ids.length === 0) {
|
|
17
|
+
return IWebResponse.success([]).to_compatible();
|
|
18
|
+
}
|
|
19
|
+
const supabase = supabaseClient ?? (await newServerClient());
|
|
20
|
+
const { data, error } = await supabase
|
|
21
|
+
.from("abilities")
|
|
22
|
+
.select("*")
|
|
23
|
+
.in("id", ids)
|
|
24
|
+
.order("key", { ascending: true });
|
|
25
|
+
if (error) {
|
|
26
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
27
|
+
}
|
|
28
|
+
return IWebResponse.success(data ?? []).to_compatible();
|
|
29
|
+
}
|
|
15
30
|
export async function server_get_herd_roles(herd_id, supabaseClient) {
|
|
16
31
|
const supabase = supabaseClient ?? (await newServerClient());
|
|
17
32
|
const { data, error } = await supabase
|
|
@@ -132,3 +147,35 @@ export async function server_set_herd_role_abilities(herd_role_id, ability_ids,
|
|
|
132
147
|
}
|
|
133
148
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
134
149
|
}
|
|
150
|
+
export async function server_get_platform_default_role_abilities(supabaseClient) {
|
|
151
|
+
const supabase = supabaseClient ?? (await newServerClient());
|
|
152
|
+
const { data, error } = await supabase.rpc("get_platform_default_role_abilities");
|
|
153
|
+
if (error) {
|
|
154
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
155
|
+
}
|
|
156
|
+
const groups = Array.isArray(data)
|
|
157
|
+
? data
|
|
158
|
+
: [];
|
|
159
|
+
return IWebResponse.success(groups).to_compatible();
|
|
160
|
+
}
|
|
161
|
+
export async function server_set_platform_default_role_abilities(system_name, ability_keys, supabaseClient) {
|
|
162
|
+
const supabase = supabaseClient ?? (await newServerClient());
|
|
163
|
+
const { error } = await supabase.rpc("set_platform_default_role_abilities", {
|
|
164
|
+
p_system_name: system_name,
|
|
165
|
+
p_ability_keys: ability_keys,
|
|
166
|
+
});
|
|
167
|
+
if (error) {
|
|
168
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
169
|
+
}
|
|
170
|
+
return IWebResponse.success(null).to_compatible();
|
|
171
|
+
}
|
|
172
|
+
export async function server_reset_herd_default_role_abilities(herd_id, supabaseClient) {
|
|
173
|
+
const supabase = supabaseClient ?? (await newServerClient());
|
|
174
|
+
const { error } = await supabase.rpc("reset_herd_default_role_abilities", {
|
|
175
|
+
p_herd_id: herd_id,
|
|
176
|
+
});
|
|
177
|
+
if (error) {
|
|
178
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
179
|
+
}
|
|
180
|
+
return IWebResponse.success(null).to_compatible();
|
|
181
|
+
}
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export * from "./versions_software";
|
|
|
31
31
|
export * from "./versions_software_server";
|
|
32
32
|
export * from "./artifacts";
|
|
33
33
|
export * from "./pins";
|
|
34
|
+
export * from "./points_for_user";
|
|
34
35
|
export * from "./pubsub_token";
|
|
35
36
|
export * from "./pubsub_token_server";
|
|
36
37
|
export * from "./client_abilities_token";
|
package/dist/helpers/index.js
CHANGED
|
@@ -31,6 +31,7 @@ export * from "./versions_software";
|
|
|
31
31
|
export * from "./versions_software_server";
|
|
32
32
|
export * from "./artifacts";
|
|
33
33
|
export * from "./pins";
|
|
34
|
+
export * from "./points_for_user";
|
|
34
35
|
export * from "./pubsub_token";
|
|
35
36
|
export * from "./pubsub_token_server";
|
|
36
37
|
export * from "./client_abilities_token";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { Database } from "../types/supabase";
|
|
3
|
+
import { IPointsForUser } from "../types/db";
|
|
4
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
5
|
+
export type PointsBalanceUpdateResult = {
|
|
6
|
+
balance: number;
|
|
7
|
+
entry: IPointsForUser | null;
|
|
8
|
+
};
|
|
9
|
+
export declare function get_points_for_user_by_user_id(client: SupabaseClient<Database>, user_id: string): Promise<IWebResponseCompatible<IPointsForUser[]>>;
|
|
10
|
+
export declare function get_points_balance_for_user_id(client: SupabaseClient<Database>, user_id: string): Promise<IWebResponseCompatible<number>>;
|
|
11
|
+
export declare function update_points_balance_for_user(client: SupabaseClient<Database>, user_id: string, balance: number, update_reason: string): Promise<IWebResponseCompatible<PointsBalanceUpdateResult | null>>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { EnumWebResponse, IWebResponse } from "../types/requests";
|
|
2
|
+
async function sum_points_for_user(client, user_id) {
|
|
3
|
+
const { data, error } = await client
|
|
4
|
+
.from("points_for_user")
|
|
5
|
+
.select("points")
|
|
6
|
+
.eq("user_id", user_id);
|
|
7
|
+
if (error) {
|
|
8
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
9
|
+
}
|
|
10
|
+
const balance = (data ?? []).reduce((sum, row) => sum + row.points, 0);
|
|
11
|
+
return IWebResponse.success(balance).to_compatible();
|
|
12
|
+
}
|
|
13
|
+
export async function get_points_for_user_by_user_id(client, user_id) {
|
|
14
|
+
const { data, error } = await client
|
|
15
|
+
.from("points_for_user")
|
|
16
|
+
.select("*")
|
|
17
|
+
.eq("user_id", user_id)
|
|
18
|
+
.order("inserted_at", { ascending: false });
|
|
19
|
+
if (error) {
|
|
20
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
21
|
+
}
|
|
22
|
+
return IWebResponse.success(data ?? []).to_compatible();
|
|
23
|
+
}
|
|
24
|
+
export async function get_points_balance_for_user_id(client, user_id) {
|
|
25
|
+
return sum_points_for_user(client, user_id);
|
|
26
|
+
}
|
|
27
|
+
export async function update_points_balance_for_user(client, user_id, balance, update_reason) {
|
|
28
|
+
if (!user_id) {
|
|
29
|
+
return IWebResponse.error("user_id is required").to_compatible();
|
|
30
|
+
}
|
|
31
|
+
if (!update_reason.trim()) {
|
|
32
|
+
return IWebResponse.error("update_reason is required").to_compatible();
|
|
33
|
+
}
|
|
34
|
+
const current = await sum_points_for_user(client, user_id);
|
|
35
|
+
if (current.status !== EnumWebResponse.SUCCESS || current.data == null) {
|
|
36
|
+
return IWebResponse.error(current.msg ?? "Failed to load points balance").to_compatible();
|
|
37
|
+
}
|
|
38
|
+
const delta = balance - current.data;
|
|
39
|
+
if (delta === 0) {
|
|
40
|
+
return IWebResponse.success({ balance: current.data, entry: null }).to_compatible();
|
|
41
|
+
}
|
|
42
|
+
const { data, error } = await client
|
|
43
|
+
.from("points_for_user")
|
|
44
|
+
.insert([{ user_id, points: delta, update_reason: update_reason.trim() }])
|
|
45
|
+
.select("*")
|
|
46
|
+
.single();
|
|
47
|
+
if (error) {
|
|
48
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
49
|
+
}
|
|
50
|
+
if (!data) {
|
|
51
|
+
return IWebResponse.error("Failed to update points balance").to_compatible();
|
|
52
|
+
}
|
|
53
|
+
return IWebResponse.success({ balance, entry: data }).to_compatible();
|
|
54
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export * from "./helpers/gps";
|
|
|
30
30
|
export * from "./helpers/herds";
|
|
31
31
|
export * from "./helpers/location";
|
|
32
32
|
export * from "./helpers/pins";
|
|
33
|
+
export * from "./helpers/points_for_user";
|
|
33
34
|
export * from "./helpers/plans";
|
|
34
35
|
export * from "./helpers/layers";
|
|
35
36
|
export * from "./helpers/sessions";
|
|
@@ -82,5 +83,5 @@ export * from "./supabase/middleware";
|
|
|
82
83
|
export * from "./supabase/server";
|
|
83
84
|
export * from "./api_keys/actions";
|
|
84
85
|
export type { HerdModule, IHerdModule } from "./types/herd_module";
|
|
85
|
-
export type { IDevice, IEvent, IUser, IHerd, IHerdPrettyLocation, IEventWithTags, IZoneWithActions, ICredential, CredentialInsert, CredentialUpdate, ICertificate, CertificateInsert, CertificateUpdate, IUserAndRole, IUserProfileRow, IHerdInvitation, IHerdInvitationWithHerdSlug, IHerdAllowedDomain, IUserRolePerHerd, IAbility, IHerdRole, IHerdRoleWithAbilities, HerdRoleSystemName, HerdInvitationStatus, IApiKeyScout, ILayer, IHeartbeat, IProvider, IConnectivity, ISession, ISessionWithCoordinates, IConnectivityWithCoordinates, IObservation, ObservationInsert, ObservationUpdate, IAnalysisJob, IAnalysisTask, AnalysisWorkStatus, } from "./types/db";
|
|
86
|
+
export type { IDevice, IEvent, IUser, IHerd, IHerdPrettyLocation, IEventWithTags, IZoneWithActions, ICredential, CredentialInsert, CredentialUpdate, IPointsForUser, PointsForUserInsert, PointsForUserUpdate, ICertificate, CertificateInsert, CertificateUpdate, IUserAndRole, IUserProfileRow, IHerdInvitation, IHerdInvitationWithHerdSlug, IHerdAllowedDomain, IUserRolePerHerd, IAbility, IHerdRole, IHerdRoleWithAbilities, HerdRoleSystemName, HerdInvitationStatus, IApiKeyScout, ILayer, IHeartbeat, IProvider, IConnectivity, ISession, ISessionWithCoordinates, IConnectivityWithCoordinates, IObservation, ObservationInsert, ObservationUpdate, IAnalysisJob, IAnalysisTask, AnalysisWorkStatus, } from "./types/db";
|
|
86
87
|
export { EnumSessionsVisibility } from "./types/events";
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ export * from "./helpers/gps";
|
|
|
33
33
|
export * from "./helpers/herds";
|
|
34
34
|
export * from "./helpers/location";
|
|
35
35
|
export * from "./helpers/pins";
|
|
36
|
+
export * from "./helpers/points_for_user";
|
|
36
37
|
export * from "./helpers/plans";
|
|
37
38
|
export * from "./helpers/layers";
|
|
38
39
|
export * from "./helpers/sessions";
|
package/dist/types/db.d.ts
CHANGED
|
@@ -33,6 +33,15 @@ export type IHerdRoleWithAbilities = IHerdRole & {
|
|
|
33
33
|
abilities: IAbility[];
|
|
34
34
|
ability_ids: number[];
|
|
35
35
|
};
|
|
36
|
+
export type IPlatformDefaultRoleAbilityRow = Database["public"]["Tables"]["platform_default_role_abilities"]["Row"];
|
|
37
|
+
/** One system role's default ability set from `get_platform_default_role_abilities`. */
|
|
38
|
+
export interface IPlatformDefaultRoleAbilitiesGroup {
|
|
39
|
+
system_name: string;
|
|
40
|
+
abilities: {
|
|
41
|
+
id: number;
|
|
42
|
+
key: string;
|
|
43
|
+
}[];
|
|
44
|
+
}
|
|
36
45
|
/** Stable machine id on `herd_roles` (e.g. admin, editor, viewer). Not `herds.slug`. */
|
|
37
46
|
export type HerdRoleSystemName = string;
|
|
38
47
|
export type IHerdInvitation = Database["public"]["Tables"]["herd_invitations"]["Row"];
|
|
@@ -48,6 +57,7 @@ export type IObservation = Database["public"]["Tables"]["observations"]["Row"];
|
|
|
48
57
|
export type IProvider = Database["public"]["Tables"]["providers"]["Row"];
|
|
49
58
|
export type IPart = Database["public"]["Tables"]["parts"]["Row"];
|
|
50
59
|
export type ICredential = Database["public"]["Tables"]["credentials"]["Row"];
|
|
60
|
+
export type IPointsForUser = Database["public"]["Tables"]["points_for_user"]["Row"];
|
|
51
61
|
export type ICertificate = Database["public"]["Tables"]["certificates"]["Row"];
|
|
52
62
|
export type IVersionsSoftware = Database["public"]["Tables"]["versions_software"]["Row"];
|
|
53
63
|
export type IArtifact = Database["public"]["Tables"]["artifacts"]["Row"];
|
|
@@ -90,6 +100,8 @@ export type ISessionUsageOverTime = Database["public"]["Functions"]["get_session
|
|
|
90
100
|
export type PartInsert = Database["public"]["Tables"]["parts"]["Insert"];
|
|
91
101
|
export type CredentialInsert = Database["public"]["Tables"]["credentials"]["Insert"];
|
|
92
102
|
export type CredentialUpdate = Database["public"]["Tables"]["credentials"]["Update"];
|
|
103
|
+
export type PointsForUserInsert = Database["public"]["Tables"]["points_for_user"]["Insert"];
|
|
104
|
+
export type PointsForUserUpdate = Database["public"]["Tables"]["points_for_user"]["Update"];
|
|
93
105
|
export type CertificateInsert = Database["public"]["Tables"]["certificates"]["Insert"];
|
|
94
106
|
export type CertificateUpdate = Database["public"]["Tables"]["certificates"]["Update"];
|
|
95
107
|
export type VersionsSoftwareInsert = Database["public"]["Tables"]["versions_software"]["Insert"];
|
package/dist/types/supabase.d.ts
CHANGED
|
@@ -1352,6 +1352,35 @@ export type Database = {
|
|
|
1352
1352
|
}
|
|
1353
1353
|
];
|
|
1354
1354
|
};
|
|
1355
|
+
platform_default_role_abilities: {
|
|
1356
|
+
Row: {
|
|
1357
|
+
ability_id: number;
|
|
1358
|
+
id: number;
|
|
1359
|
+
inserted_at: string;
|
|
1360
|
+
system_name: string;
|
|
1361
|
+
};
|
|
1362
|
+
Insert: {
|
|
1363
|
+
ability_id: number;
|
|
1364
|
+
id?: number;
|
|
1365
|
+
inserted_at?: string;
|
|
1366
|
+
system_name: string;
|
|
1367
|
+
};
|
|
1368
|
+
Update: {
|
|
1369
|
+
ability_id?: number;
|
|
1370
|
+
id?: number;
|
|
1371
|
+
inserted_at?: string;
|
|
1372
|
+
system_name?: string;
|
|
1373
|
+
};
|
|
1374
|
+
Relationships: [
|
|
1375
|
+
{
|
|
1376
|
+
foreignKeyName: "platform_default_role_abilities_ability_id_fkey";
|
|
1377
|
+
columns: ["ability_id"];
|
|
1378
|
+
isOneToOne: false;
|
|
1379
|
+
referencedRelation: "abilities";
|
|
1380
|
+
referencedColumns: ["id"];
|
|
1381
|
+
}
|
|
1382
|
+
];
|
|
1383
|
+
};
|
|
1355
1384
|
platform_superadmins: {
|
|
1356
1385
|
Row: {
|
|
1357
1386
|
inserted_at: string;
|
|
@@ -1375,6 +1404,38 @@ export type Database = {
|
|
|
1375
1404
|
}
|
|
1376
1405
|
];
|
|
1377
1406
|
};
|
|
1407
|
+
points_for_user: {
|
|
1408
|
+
Row: {
|
|
1409
|
+
id: number;
|
|
1410
|
+
inserted_at: string;
|
|
1411
|
+
points: number;
|
|
1412
|
+
update_reason: string;
|
|
1413
|
+
user_id: string;
|
|
1414
|
+
};
|
|
1415
|
+
Insert: {
|
|
1416
|
+
id?: number;
|
|
1417
|
+
inserted_at?: string;
|
|
1418
|
+
points: number;
|
|
1419
|
+
update_reason: string;
|
|
1420
|
+
user_id: string;
|
|
1421
|
+
};
|
|
1422
|
+
Update: {
|
|
1423
|
+
id?: number;
|
|
1424
|
+
inserted_at?: string;
|
|
1425
|
+
points?: number;
|
|
1426
|
+
update_reason?: string;
|
|
1427
|
+
user_id?: string;
|
|
1428
|
+
};
|
|
1429
|
+
Relationships: [
|
|
1430
|
+
{
|
|
1431
|
+
foreignKeyName: "points_for_user_user_id_fkey";
|
|
1432
|
+
columns: ["user_id"];
|
|
1433
|
+
isOneToOne: false;
|
|
1434
|
+
referencedRelation: "users";
|
|
1435
|
+
referencedColumns: ["id"];
|
|
1436
|
+
}
|
|
1437
|
+
];
|
|
1438
|
+
};
|
|
1378
1439
|
providers: {
|
|
1379
1440
|
Row: {
|
|
1380
1441
|
created_at: string;
|
|
@@ -2959,6 +3020,10 @@ export type Database = {
|
|
|
2959
3020
|
isSetofReturn: true;
|
|
2960
3021
|
};
|
|
2961
3022
|
};
|
|
3023
|
+
get_platform_default_role_abilities: {
|
|
3024
|
+
Args: never;
|
|
3025
|
+
Returns: Json;
|
|
3026
|
+
};
|
|
2962
3027
|
get_pubsub_jwt_public_keys: {
|
|
2963
3028
|
Args: never;
|
|
2964
3029
|
Returns: Json;
|
|
@@ -3406,6 +3471,12 @@ export type Database = {
|
|
|
3406
3471
|
isSetofReturn: false;
|
|
3407
3472
|
};
|
|
3408
3473
|
};
|
|
3474
|
+
reset_herd_default_role_abilities: {
|
|
3475
|
+
Args: {
|
|
3476
|
+
p_herd_id: number;
|
|
3477
|
+
};
|
|
3478
|
+
Returns: undefined;
|
|
3479
|
+
};
|
|
3409
3480
|
revoke_client_abilities_jwt_public_key: {
|
|
3410
3481
|
Args: {
|
|
3411
3482
|
p_kid: string;
|
|
@@ -3469,6 +3540,13 @@ export type Database = {
|
|
|
3469
3540
|
};
|
|
3470
3541
|
Returns: undefined;
|
|
3471
3542
|
};
|
|
3543
|
+
set_platform_default_role_abilities: {
|
|
3544
|
+
Args: {
|
|
3545
|
+
p_ability_keys: string[];
|
|
3546
|
+
p_system_name: string;
|
|
3547
|
+
};
|
|
3548
|
+
Returns: undefined;
|
|
3549
|
+
};
|
|
3472
3550
|
sync_orphan_session_links: {
|
|
3473
3551
|
Args: {
|
|
3474
3552
|
preview?: boolean;
|