@glowlabs-org/utils 0.2.25 → 0.2.26

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.
@@ -6,6 +6,10 @@ import type {
6
6
  RegionWithMetadata,
7
7
  ActivationConfig,
8
8
  CreateRegionPayload,
9
+ CreateKickstarterPayload,
10
+ Kickstarter,
11
+ ActivationEvent,
12
+ KickstarterCreateResponse,
9
13
  } from "../types";
10
14
 
11
15
  // ---------------------------------------------------------------------------
@@ -41,6 +45,7 @@ export function RegionRouter(baseUrl: string) {
41
45
  let cachedRegions: Region[] = [];
42
46
  let isLoading = false;
43
47
  let isCreatingRegion = false;
48
+ let isCreatingKickstarter = false;
44
49
 
45
50
  // -------------------------------------------------------------------------
46
51
  // Queries
@@ -70,6 +75,20 @@ export function RegionRouter(baseUrl: string) {
70
75
  }
71
76
  };
72
77
 
78
+ const fetchActivationEvents = async (
79
+ regionId?: number
80
+ ): Promise<ActivationEvent[]> => {
81
+ try {
82
+ const query = typeof regionId === "number" ? `?regionId=${regionId}` : "";
83
+ const data = await request<{ events: ActivationEvent[] }>(
84
+ `/regions/activation-events${query}`
85
+ );
86
+ return data.events ?? [];
87
+ } catch (error) {
88
+ throw new Error(parseApiError(error));
89
+ }
90
+ };
91
+
73
92
  // -------------------------------------------------------------------------
74
93
  // Mutations
75
94
  // -------------------------------------------------------------------------
@@ -90,6 +109,40 @@ export function RegionRouter(baseUrl: string) {
90
109
  }
91
110
  };
92
111
 
112
+ const createKickstarter = async (
113
+ payload: CreateKickstarterPayload
114
+ ): Promise<KickstarterCreateResponse> => {
115
+ isCreatingKickstarter = true;
116
+ try {
117
+ const data = await request<KickstarterCreateResponse>(
118
+ `/regions/kickstarters`,
119
+ {
120
+ method: "POST",
121
+ headers: { "Content-Type": "application/json" },
122
+ body: JSON.stringify(payload),
123
+ }
124
+ );
125
+ // A new region may have been created; refresh regions cache
126
+ await fetchRegions();
127
+ return data;
128
+ } catch (error) {
129
+ throw new Error(parseApiError(error));
130
+ } finally {
131
+ isCreatingKickstarter = false;
132
+ }
133
+ };
134
+
135
+ const fetchKickstarter = async (idOrSlug: string): Promise<Kickstarter> => {
136
+ try {
137
+ const data = await request<{ kickstarter: Kickstarter }>(
138
+ `/regions/kickstarters/${encodeURIComponent(idOrSlug)}`
139
+ );
140
+ return data.kickstarter;
141
+ } catch (error) {
142
+ throw new Error(parseApiError(error));
143
+ }
144
+ };
145
+
93
146
  // -------------------------------------------------------------------------
94
147
  // Helpers (derived)
95
148
  // -------------------------------------------------------------------------
@@ -136,8 +189,11 @@ export function RegionRouter(baseUrl: string) {
136
189
  // Data access
137
190
  fetchRegions,
138
191
  fetchActivationConfig,
192
+ fetchActivationEvents,
193
+ fetchKickstarter,
139
194
  getRegionByCode,
140
195
  createRegion,
196
+ createKickstarter,
141
197
 
142
198
  // Cached data & flags
143
199
  get regions() {
@@ -149,5 +205,8 @@ export function RegionRouter(baseUrl: string) {
149
205
  get isCreatingRegion() {
150
206
  return isCreatingRegion;
151
207
  },
208
+ get isCreatingKickstarter() {
209
+ return isCreatingKickstarter;
210
+ },
152
211
  } as const;
153
212
  }
@@ -152,6 +152,70 @@ export interface RegionMetadata {
152
152
  flag?: string;
153
153
  }
154
154
 
155
+ // ----------------------------- Kickstarters ---------------------------------
156
+ export type KickstarterStatus =
157
+ | "draft"
158
+ | "awaiting-kickoff"
159
+ | "collecting-support"
160
+ | "ready-to-activate"
161
+ | "completed"
162
+ | "expired"
163
+ | "cancelled"
164
+ | "suspended";
165
+
166
+ export interface CreateKickstarterPayload {
167
+ creatorWallet: string;
168
+ regionName: string;
169
+ isUs?: boolean;
170
+ title: string;
171
+ description: string;
172
+ stakeTargetGctl: string; // decimal string
173
+ requiredFarmCount?: number; // defaults server-side
174
+ requiredInstallerCount?: number; // defaults server-side
175
+ }
176
+
177
+ export interface KickstarterCreateResponse {
178
+ success: true;
179
+ id: string;
180
+ }
181
+
182
+ export interface Kickstarter {
183
+ id: string;
184
+ regionId: number;
185
+ creatorWallet: string;
186
+ title: string;
187
+ description: string;
188
+ slug: string;
189
+ status: KickstarterStatus | string;
190
+ createdAt: string; // ISO 8601
191
+ updatedAt: string; // ISO 8601
192
+ publishedAt?: string; // ISO 8601
193
+ completedAt?: string; // ISO 8601
194
+ cancelledAt?: string; // ISO 8601
195
+ expiredAt?: string; // ISO 8601
196
+ deadline: string; // ISO 8601
197
+ stakeTargetGctl: string; // decimal string
198
+ requiredFarmCount: number;
199
+ requiredInstallerCount: number;
200
+ stakeContributed: boolean;
201
+ farmProvided: boolean;
202
+ installerCertified: boolean;
203
+ kickoffTransferTxId?: string;
204
+ kickoffMintTxId?: string;
205
+ kickoffStakeEventId?: string;
206
+ }
207
+
208
+ export interface ActivationEvent {
209
+ id: string;
210
+ regionId: number;
211
+ epoch: number;
212
+ stakeThresholdMet: boolean;
213
+ solarFarmRequirementMet: boolean;
214
+ installerRequirementMet: boolean;
215
+ activated: boolean;
216
+ ts: string; // ISO 8601
217
+ }
218
+
155
219
  // ---------------------------------------------------------------------------
156
220
  // Barrel exports (convenience)
157
221
  // ---------------------------------------------------------------------------