@adventurelabs/scout-core 1.0.0

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.
Files changed (90) hide show
  1. package/README.md +90 -0
  2. package/dist/api_keys/actions.d.ts +2 -0
  3. package/dist/api_keys/actions.js +20 -0
  4. package/dist/api_keys/index.d.ts +1 -0
  5. package/dist/api_keys/index.js +1 -0
  6. package/dist/constants/annotator.d.ts +1 -0
  7. package/dist/constants/annotator.js +11 -0
  8. package/dist/constants/app.d.ts +2 -0
  9. package/dist/constants/app.js +2 -0
  10. package/dist/constants/index.d.ts +2 -0
  11. package/dist/constants/index.js +2 -0
  12. package/dist/helpers/auth.d.ts +1 -0
  13. package/dist/helpers/auth.js +8 -0
  14. package/dist/helpers/bounding_boxes.d.ts +5 -0
  15. package/dist/helpers/bounding_boxes.js +43 -0
  16. package/dist/helpers/db.d.ts +3 -0
  17. package/dist/helpers/db.js +22 -0
  18. package/dist/helpers/devices.d.ts +8 -0
  19. package/dist/helpers/devices.js +92 -0
  20. package/dist/helpers/email.d.ts +7 -0
  21. package/dist/helpers/email.js +22 -0
  22. package/dist/helpers/events.d.ts +6 -0
  23. package/dist/helpers/events.js +71 -0
  24. package/dist/helpers/finance.d.ts +9 -0
  25. package/dist/helpers/finance.js +16 -0
  26. package/dist/helpers/gps.d.ts +5 -0
  27. package/dist/helpers/gps.js +11 -0
  28. package/dist/helpers/herds.d.ts +9 -0
  29. package/dist/helpers/herds.js +80 -0
  30. package/dist/helpers/index.d.ts +17 -0
  31. package/dist/helpers/index.js +17 -0
  32. package/dist/helpers/location.d.ts +1 -0
  33. package/dist/helpers/location.js +3 -0
  34. package/dist/helpers/plans.d.ts +5 -0
  35. package/dist/helpers/plans.js +61 -0
  36. package/dist/helpers/tags.d.ts +7 -0
  37. package/dist/helpers/tags.js +158 -0
  38. package/dist/helpers/time.d.ts +3 -0
  39. package/dist/helpers/time.js +11 -0
  40. package/dist/helpers/ui.d.ts +4 -0
  41. package/dist/helpers/ui.js +12 -0
  42. package/dist/helpers/users.d.ts +6 -0
  43. package/dist/helpers/users.js +66 -0
  44. package/dist/helpers/web.d.ts +1 -0
  45. package/dist/helpers/web.js +7 -0
  46. package/dist/helpers/zones.d.ts +18 -0
  47. package/dist/helpers/zones.js +108 -0
  48. package/dist/hooks/index.d.ts +2 -0
  49. package/dist/hooks/index.js +2 -0
  50. package/dist/hooks/useScoutDbListener.d.ts +1 -0
  51. package/dist/hooks/useScoutDbListener.js +94 -0
  52. package/dist/hooks/useScoutRefresh.d.ts +7 -0
  53. package/dist/hooks/useScoutRefresh.js +45 -0
  54. package/dist/index.d.ts +38 -0
  55. package/dist/index.js +43 -0
  56. package/dist/providers/ScoutRefreshProvider.d.ts +1 -0
  57. package/dist/providers/ScoutRefreshProvider.js +8 -0
  58. package/dist/providers/index.d.ts +1 -0
  59. package/dist/providers/index.js +1 -0
  60. package/dist/store/hooks.d.ts +1 -0
  61. package/dist/store/hooks.js +3 -0
  62. package/dist/store/index.d.ts +1 -0
  63. package/dist/store/index.js +1 -0
  64. package/dist/store/scout.d.ts +103 -0
  65. package/dist/store/scout.js +196 -0
  66. package/dist/supabase/client.d.ts +1 -0
  67. package/dist/supabase/client.js +5 -0
  68. package/dist/supabase/index.d.ts +3 -0
  69. package/dist/supabase/index.js +3 -0
  70. package/dist/supabase/middleware.d.ts +2 -0
  71. package/dist/supabase/middleware.js +46 -0
  72. package/dist/supabase/server.d.ts +636 -0
  73. package/dist/supabase/server.js +22 -0
  74. package/dist/types/bounding_boxes.d.ts +27 -0
  75. package/dist/types/bounding_boxes.js +11 -0
  76. package/dist/types/db.d.ts +42 -0
  77. package/dist/types/db.js +15 -0
  78. package/dist/types/gps.d.ts +21 -0
  79. package/dist/types/gps.js +13 -0
  80. package/dist/types/herd_module.d.ts +31 -0
  81. package/dist/types/herd_module.js +82 -0
  82. package/dist/types/index.d.ts +6 -0
  83. package/dist/types/index.js +6 -0
  84. package/dist/types/requests.d.ts +18 -0
  85. package/dist/types/requests.js +25 -0
  86. package/dist/types/supabase.d.ts +754 -0
  87. package/dist/types/supabase.js +25 -0
  88. package/dist/types/ui.d.ts +7 -0
  89. package/dist/types/ui.js +8 -0
  90. package/package.json +52 -0
@@ -0,0 +1,38 @@
1
+ export * from "./constants/annotator";
2
+ export * from "./constants/app";
3
+ export * from "./types/db";
4
+ export * from "./types/herd_module";
5
+ export * from "./types/ui";
6
+ export * from "./types/requests";
7
+ export * from "./types/gps";
8
+ export * from "./types/supabase";
9
+ export * from "./types/bounding_boxes";
10
+ export * from "./helpers/auth";
11
+ export * from "./helpers/bounding_boxes";
12
+ export * from "./helpers/db";
13
+ export * from "./helpers/devices";
14
+ export * from "./helpers/email";
15
+ export * from "./helpers/events";
16
+ export * from "./helpers/finance";
17
+ export * from "./helpers/gps";
18
+ export * from "./helpers/herds";
19
+ export * from "./helpers/location";
20
+ export * from "./helpers/plans";
21
+ export * from "./helpers/tags";
22
+ export * from "./helpers/time";
23
+ export * from "./helpers/ui";
24
+ export * from "./helpers/users";
25
+ export * from "./helpers/web";
26
+ export * from "./helpers/zones";
27
+ export * from "./hooks/useScoutDbListener";
28
+ export * from "./hooks/useScoutRefresh";
29
+ export * from "./providers/ScoutRefreshProvider";
30
+ export * from "./store/scout";
31
+ export * from "./store/hooks";
32
+ export * from "./supabase/client";
33
+ export * from "./supabase/middleware";
34
+ export * from "./supabase/server";
35
+ export * from "./api_keys/actions";
36
+ export type { Database } from "./types/supabase";
37
+ export type { HerdModule, IHerdModule } from "./types/herd_module";
38
+ export type { IDevice, IEvent, IUser, IHerd, IEventWithTags, IZoneWithActions, IUserAndRole, IApiKeyScout, } from "./types/db";
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ // Constants
2
+ export * from "./constants/annotator";
3
+ export * from "./constants/app";
4
+ // Types
5
+ export * from "./types/db";
6
+ export * from "./types/herd_module";
7
+ export * from "./types/ui";
8
+ export * from "./types/requests";
9
+ export * from "./types/gps";
10
+ export * from "./types/supabase";
11
+ export * from "./types/bounding_boxes";
12
+ // Helpers
13
+ export * from "./helpers/auth";
14
+ export * from "./helpers/bounding_boxes";
15
+ export * from "./helpers/db";
16
+ export * from "./helpers/devices";
17
+ export * from "./helpers/email";
18
+ export * from "./helpers/events";
19
+ export * from "./helpers/finance";
20
+ export * from "./helpers/gps";
21
+ export * from "./helpers/herds";
22
+ export * from "./helpers/location";
23
+ export * from "./helpers/plans";
24
+ export * from "./helpers/tags";
25
+ export * from "./helpers/time";
26
+ export * from "./helpers/ui";
27
+ export * from "./helpers/users";
28
+ export * from "./helpers/web";
29
+ export * from "./helpers/zones";
30
+ // Hooks
31
+ export * from "./hooks/useScoutDbListener";
32
+ export * from "./hooks/useScoutRefresh";
33
+ // Providers
34
+ export * from "./providers/ScoutRefreshProvider";
35
+ // Store
36
+ export * from "./store/scout";
37
+ export * from "./store/hooks";
38
+ // Supabase
39
+ export * from "./supabase/client";
40
+ export * from "./supabase/middleware";
41
+ export * from "./supabase/server";
42
+ // API Keys
43
+ export * from "./api_keys/actions";
@@ -0,0 +1 @@
1
+ export default function ScoutRefreshProvider(): null;
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import { useScoutRefresh } from "../hooks/useScoutRefresh";
3
+ import { useScoutDbListener } from "../hooks/useScoutDbListener";
4
+ export default function ScoutRefreshProvider() {
5
+ useScoutDbListener();
6
+ useScoutRefresh();
7
+ return null; // This component doesn't render anything, it just provides the refresh functionality
8
+ }
@@ -0,0 +1 @@
1
+ export * from "./ScoutRefreshProvider";
@@ -0,0 +1 @@
1
+ export * from "./ScoutRefreshProvider";
@@ -0,0 +1 @@
1
+ export declare const useAppDispatch: <AppDispatch extends import("redux").Dispatch<import("redux").AnyAction> = import("redux").Dispatch<import("redux").AnyAction>>() => AppDispatch;
@@ -0,0 +1,3 @@
1
+ import { useDispatch } from "react-redux";
2
+ // Simple wrapper for useDispatch to maintain compatibility
3
+ export const useAppDispatch = useDispatch;
@@ -0,0 +1 @@
1
+ export * from "./scout";
@@ -0,0 +1 @@
1
+ export * from "./scout";
@@ -0,0 +1,103 @@
1
+ import { IUser } from "../types/db";
2
+ import { IHerdModule } from "../types/herd_module";
3
+ export declare enum EnumScoutStateStatus {
4
+ LOADING = "LOADING",
5
+ DONE_LOADING = "DONE_LOADING"
6
+ }
7
+ export interface ScoutState {
8
+ herd_modules: IHerdModule[];
9
+ status: EnumScoutStateStatus;
10
+ active_herd_id: string | null;
11
+ active_device_id: string | null;
12
+ lastRefreshed: number;
13
+ user: IUser | null;
14
+ }
15
+ export declare const scoutSlice: import("@reduxjs/toolkit").Slice<ScoutState, {
16
+ setHerdModules: (state: import("immer").WritableDraft<ScoutState>, action: {
17
+ payload: any;
18
+ type: string;
19
+ }) => void;
20
+ setStatus: (state: import("immer").WritableDraft<ScoutState>, action: {
21
+ payload: any;
22
+ type: string;
23
+ }) => void;
24
+ setActiveHerdId: (state: import("immer").WritableDraft<ScoutState>, action: {
25
+ payload: any;
26
+ type: string;
27
+ }) => void;
28
+ setActiveDeviceId: (state: import("immer").WritableDraft<ScoutState>, action: {
29
+ payload: any;
30
+ type: string;
31
+ }) => void;
32
+ replaceEventsForHerdModule: (state: import("immer").WritableDraft<ScoutState>, action: {
33
+ payload: any;
34
+ type: string;
35
+ }) => void;
36
+ appendEventsToHerdModule: (state: import("immer").WritableDraft<ScoutState>, action: {
37
+ payload: any;
38
+ type: string;
39
+ }) => void;
40
+ appendPlansToHerdModule: (state: import("immer").WritableDraft<ScoutState>, action: {
41
+ payload: any;
42
+ type: string;
43
+ }) => void;
44
+ updateDeviceForHerdModule: (state: import("immer").WritableDraft<ScoutState>, action: {
45
+ payload: any;
46
+ type: string;
47
+ }) => void;
48
+ addNewDeviceToHerdModule: (state: import("immer").WritableDraft<ScoutState>, action: {
49
+ payload: any;
50
+ type: string;
51
+ }) => void;
52
+ addTag(state: import("immer").WritableDraft<ScoutState>, action: {
53
+ payload: any;
54
+ type: string;
55
+ }): void;
56
+ deleteTag(state: import("immer").WritableDraft<ScoutState>, action: {
57
+ payload: any;
58
+ type: string;
59
+ }): void;
60
+ updateTag(state: import("immer").WritableDraft<ScoutState>, action: {
61
+ payload: any;
62
+ type: string;
63
+ }): void;
64
+ addDevice(state: import("immer").WritableDraft<ScoutState>, action: {
65
+ payload: any;
66
+ type: string;
67
+ }): void;
68
+ deleteDevice(state: import("immer").WritableDraft<ScoutState>, action: {
69
+ payload: any;
70
+ type: string;
71
+ }): void;
72
+ updateDevice(state: import("immer").WritableDraft<ScoutState>, action: {
73
+ payload: any;
74
+ type: string;
75
+ }): void;
76
+ addPlan(state: import("immer").WritableDraft<ScoutState>, action: {
77
+ payload: any;
78
+ type: string;
79
+ }): void;
80
+ deletePlan(state: import("immer").WritableDraft<ScoutState>, action: {
81
+ payload: any;
82
+ type: string;
83
+ }): void;
84
+ updatePlan(state: import("immer").WritableDraft<ScoutState>, action: {
85
+ payload: any;
86
+ type: string;
87
+ }): void;
88
+ updateEventValuesForHerdModule: (state: import("immer").WritableDraft<ScoutState>, action: {
89
+ payload: any;
90
+ type: string;
91
+ }) => void;
92
+ updatePageIndexForHerdModule: (state: import("immer").WritableDraft<ScoutState>, action: {
93
+ payload: any;
94
+ type: string;
95
+ }) => void;
96
+ setUser: (state: import("immer").WritableDraft<ScoutState>, action: {
97
+ payload: any;
98
+ type: string;
99
+ }) => void;
100
+ }, "scout", "scout", import("@reduxjs/toolkit").SliceSelectors<ScoutState>>;
101
+ export declare const setHerdModules: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setHerdModules">, setStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setStatus">, setActiveHerdId: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setActiveHerdId">, setActiveDeviceId: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setActiveDeviceId">, appendEventsToHerdModule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/appendEventsToHerdModule">, replaceEventsForHerdModule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/replaceEventsForHerdModule">, updateEventValuesForHerdModule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/updateEventValuesForHerdModule">, updatePageIndexForHerdModule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/updatePageIndexForHerdModule">, appendPlansToHerdModule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/appendPlansToHerdModule">, setUser: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setUser">, addTag: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/addTag">, deleteTag: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/deleteTag">, updateTag: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/updateTag">, addNewDeviceToHerdModule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/addNewDeviceToHerdModule">, updateDeviceForHerdModule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/updateDeviceForHerdModule">, addDevice: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/addDevice">, deleteDevice: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/deleteDevice">, updateDevice: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/updateDevice">, addPlan: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/addPlan">, deletePlan: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/deletePlan">, updatePlan: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/updatePlan">;
102
+ declare const _default: import("redux").Reducer<ScoutState>;
103
+ export default _default;
@@ -0,0 +1,196 @@
1
+ import { createSlice } from "@reduxjs/toolkit";
2
+ export var EnumScoutStateStatus;
3
+ (function (EnumScoutStateStatus) {
4
+ EnumScoutStateStatus["LOADING"] = "LOADING";
5
+ EnumScoutStateStatus["DONE_LOADING"] = "DONE_LOADING";
6
+ })(EnumScoutStateStatus || (EnumScoutStateStatus = {}));
7
+ const initialState = {
8
+ herd_modules: [],
9
+ status: EnumScoutStateStatus.LOADING,
10
+ lastRefreshed: 0,
11
+ active_herd_id: null,
12
+ active_device_id: null,
13
+ user: null,
14
+ };
15
+ export const scoutSlice = createSlice({
16
+ name: "scout",
17
+ initialState,
18
+ reducers: {
19
+ setHerdModules: (state, action) => {
20
+ state.herd_modules = action.payload;
21
+ state.lastRefreshed = Date.now();
22
+ },
23
+ setStatus: (state, action) => {
24
+ state.status = action.payload;
25
+ },
26
+ setActiveHerdId: (state, action) => {
27
+ state.active_herd_id = action.payload;
28
+ },
29
+ setActiveDeviceId: (state, action) => {
30
+ state.active_device_id = action.payload;
31
+ },
32
+ replaceEventsForHerdModule: (state, action) => {
33
+ const { herd_id, events } = action.payload;
34
+ const herd_module = state.herd_modules.find((hm) => hm.herd.id.toString() === herd_id);
35
+ if (herd_module) {
36
+ herd_module.events = events;
37
+ }
38
+ },
39
+ appendEventsToHerdModule: (state, action) => {
40
+ const { herd_id, events } = action.payload;
41
+ const herd_module = state.herd_modules.find((hm) => hm.herd.id.toString() === herd_id);
42
+ if (herd_module) {
43
+ herd_module.events = [...herd_module.events, ...events];
44
+ }
45
+ },
46
+ appendPlansToHerdModule: (state, action) => {
47
+ const { herd_id, plan } = action.payload;
48
+ const herd_module = state.herd_modules.find((hm) => hm.herd.id.toString() === herd_id);
49
+ if (herd_module) {
50
+ herd_module.plans = [...herd_module.plans, plan];
51
+ }
52
+ },
53
+ updateDeviceForHerdModule: (state, action) => {
54
+ const { herd_id, device } = action.payload;
55
+ const herd_module = state.herd_modules.find((hm) => hm.herd.id.toString() === herd_id);
56
+ if (herd_module) {
57
+ herd_module.devices = herd_module.devices.map((d) => d.id === device.id ? device : d);
58
+ }
59
+ },
60
+ // append device to herd module
61
+ addNewDeviceToHerdModule: (state, action) => {
62
+ const { herd_id, device } = action.payload;
63
+ const herd_module = state.herd_modules.find((hm) => hm.herd.id.toString() === herd_id);
64
+ if (herd_module) {
65
+ herd_module.devices = [...herd_module.devices, device];
66
+ }
67
+ },
68
+ addTag(state, action) {
69
+ for (const herd_module of state.herd_modules) {
70
+ for (const event of herd_module.events) {
71
+ if (event.id === action.payload.event_id && event.tags) {
72
+ event.tags.push(action.payload);
73
+ return;
74
+ }
75
+ }
76
+ }
77
+ },
78
+ deleteTag(state, action) {
79
+ for (const herd_module of state.herd_modules) {
80
+ for (const event of herd_module.events) {
81
+ if (!event.tags) {
82
+ continue;
83
+ }
84
+ for (const tag of event.tags) {
85
+ if (tag.id === action.payload.id) {
86
+ event.tags = event.tags.filter((t) => t.id !== tag.id);
87
+ return;
88
+ }
89
+ }
90
+ }
91
+ }
92
+ },
93
+ updateTag(state, action) {
94
+ for (const herd_module of state.herd_modules) {
95
+ for (const event of herd_module.events) {
96
+ if (!event.tags) {
97
+ continue;
98
+ }
99
+ for (const tag of event.tags) {
100
+ if (tag.id === action.payload.id) {
101
+ tag.x = action.payload.x;
102
+ tag.y = action.payload.y;
103
+ tag.width = action.payload.width;
104
+ tag.height = action.payload.height;
105
+ tag.conf = action.payload.conf;
106
+ tag.class_name = action.payload.class_name;
107
+ return;
108
+ }
109
+ }
110
+ }
111
+ }
112
+ },
113
+ addDevice(state, action) {
114
+ for (const herd_module of state.herd_modules) {
115
+ if (herd_module.herd.id === action.payload.herd_id) {
116
+ herd_module.devices.push(action.payload);
117
+ return;
118
+ }
119
+ }
120
+ },
121
+ deleteDevice(state, action) {
122
+ for (const herd_module of state.herd_modules) {
123
+ herd_module.devices = herd_module.devices.filter((device) => device.id !== action.payload.id);
124
+ }
125
+ },
126
+ updateDevice(state, action) {
127
+ for (const herd_module of state.herd_modules) {
128
+ for (const device of herd_module.devices) {
129
+ if (device.id === action.payload.id) {
130
+ device.name = action.payload.name;
131
+ device.id = action.payload.id;
132
+ device.device_type = action.payload.device_type;
133
+ device.altitude = action.payload.altitude;
134
+ device.latitude = action.payload.latitude;
135
+ device.longitude = action.payload.longitude;
136
+ device.domain_name = action.payload.domain_name;
137
+ return;
138
+ }
139
+ }
140
+ }
141
+ },
142
+ addPlan(state, action) {
143
+ for (const herd_module of state.herd_modules) {
144
+ if (herd_module.herd.id === action.payload.herd_id) {
145
+ herd_module.plans.push(action.payload);
146
+ return;
147
+ }
148
+ }
149
+ },
150
+ deletePlan(state, action) {
151
+ for (const herd_module of state.herd_modules) {
152
+ herd_module.plans = herd_module.plans.filter((plan) => plan.id !== action.payload.id);
153
+ }
154
+ },
155
+ updatePlan(state, action) {
156
+ for (const herd_module of state.herd_modules) {
157
+ for (const plan of herd_module.plans) {
158
+ if (plan.id === action.payload.id) {
159
+ plan.name = action.payload.name;
160
+ plan.instructions = action.payload.instructions;
161
+ plan.herd_id = action.payload.herd_id;
162
+ return;
163
+ }
164
+ }
165
+ }
166
+ },
167
+ // receive a payload with the herd_id and the events that we wish to update the values of
168
+ updateEventValuesForHerdModule: (state, action) => {
169
+ const { herd_id, events } = action.payload;
170
+ const herd_module = state.herd_modules.find((hm) => hm.herd.id.toString() === herd_id);
171
+ if (herd_module) {
172
+ herd_module.events = herd_module.events.map((event) => {
173
+ const updated_event = events.find((e) => e.id === event.id);
174
+ if (updated_event) {
175
+ return updated_event;
176
+ }
177
+ return event;
178
+ });
179
+ }
180
+ state.herd_modules = [...state.herd_modules];
181
+ },
182
+ updatePageIndexForHerdModule: (state, action) => {
183
+ const { herd_id, new_page_index } = action.payload;
184
+ const herd_module = state.herd_modules.find((hm) => hm.herd.id.toString() === herd_id);
185
+ if (herd_module) {
186
+ herd_module.events_page_index = new_page_index;
187
+ }
188
+ },
189
+ setUser: (state, action) => {
190
+ state.user = action.payload;
191
+ },
192
+ },
193
+ });
194
+ // Action creators are generated for each case reducer function
195
+ export const { setHerdModules, setStatus, setActiveHerdId, setActiveDeviceId, appendEventsToHerdModule, replaceEventsForHerdModule, updateEventValuesForHerdModule, updatePageIndexForHerdModule, appendPlansToHerdModule, setUser, addTag, deleteTag, updateTag, addNewDeviceToHerdModule, updateDeviceForHerdModule, addDevice, deleteDevice, updateDevice, addPlan, deletePlan, updatePlan, } = scoutSlice.actions;
196
+ export default scoutSlice.reducer;
@@ -0,0 +1 @@
1
+ export declare function newClient(): Promise<import("@supabase/supabase-js").SupabaseClient<any, "public", any>>;
@@ -0,0 +1,5 @@
1
+ import { createClient } from "@supabase/supabase-js";
2
+ export async function newClient() {
3
+ const client = await createClient(process.env.NEXT_PUBLIC_SUPABASE_URL, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY);
4
+ return client;
5
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./client";
2
+ export * from "./middleware";
3
+ export * from "./server";
@@ -0,0 +1,3 @@
1
+ export * from "./client";
2
+ export * from "./middleware";
3
+ export * from "./server";
@@ -0,0 +1,2 @@
1
+ import { NextResponse, type NextRequest } from "next/server";
2
+ export declare function updateSession(request: NextRequest): Promise<NextResponse<unknown>>;
@@ -0,0 +1,46 @@
1
+ import { createServerClient } from "@supabase/ssr";
2
+ import { NextResponse } from "next/server";
3
+ export async function updateSession(request) {
4
+ let supabaseResponse = NextResponse.next({
5
+ request,
6
+ });
7
+ const supabase = createServerClient(process.env.NEXT_PUBLIC_SUPABASE_URL, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY, {
8
+ cookies: {
9
+ getAll() {
10
+ return request.cookies.getAll();
11
+ },
12
+ setAll(cookiesToSet) {
13
+ cookiesToSet.forEach(({ name, value, options }) => request.cookies.set(name, value));
14
+ supabaseResponse = NextResponse.next({
15
+ request,
16
+ });
17
+ cookiesToSet.forEach(({ name, value, options }) => supabaseResponse.cookies.set(name, value, options));
18
+ },
19
+ },
20
+ });
21
+ // IMPORTANT: Avoid writing any logic between createServerClient and
22
+ // supabase.auth.getUser(). A simple mistake could make it very hard to debug
23
+ // issues with users being randomly logged out.
24
+ const { data: { user }, } = await supabase.auth.getUser();
25
+ if (!user &&
26
+ !request.nextUrl.pathname.startsWith("/auth/login") &&
27
+ !request.nextUrl.pathname.startsWith("/auth")) {
28
+ // no user, potentially respond by redirecting the user to the login page
29
+ const url = request.nextUrl.clone();
30
+ url.pathname = "/auth/login";
31
+ return NextResponse.redirect(url);
32
+ }
33
+ // IMPORTANT: You *must* return the supabaseResponse object as it is. If you're
34
+ // creating a new response object with NextResponse.next() make sure to:
35
+ // 1. Pass the request in it, like so:
36
+ // const myNewResponse = NextResponse.next({ request })
37
+ // 2. Copy over the cookies, like so:
38
+ // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())
39
+ // 3. Change the myNewResponse object to fit your needs, but avoid changing
40
+ // the cookies!
41
+ // 4. Finally:
42
+ // return myNewResponse
43
+ // If this is not done, you may be causing the browser and server to go out
44
+ // of sync and terminate the user's session prematurely!
45
+ return supabaseResponse;
46
+ }