@supabase/gotrue-js 2.9.0 → 2.10.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.
@@ -149,3 +149,45 @@ export function decodeJWTPayload(token: string) {
149
149
  const base64Url = parts[1]
150
150
  return JSON.parse(decodeBase64URL(base64Url))
151
151
  }
152
+
153
+ /**
154
+ * Creates a promise that resolves to null after some time.
155
+ */
156
+ export function sleep(time: number): Promise<null> {
157
+ return new Promise((accept) => {
158
+ setTimeout(() => accept(null), time)
159
+ })
160
+ }
161
+
162
+ /**
163
+ * Converts the provided async function into a retryable function. Each result
164
+ * or thrown error is sent to the isRetryable function which should return true
165
+ * if the function should run again.
166
+ */
167
+ export function retryable<T>(
168
+ fn: (attempt: number) => Promise<T>,
169
+ isRetryable: (attempt: number, error: any | null, result?: T) => boolean
170
+ ): Promise<T> {
171
+ const promise = new Promise<T>((accept, reject) => {
172
+ // eslint-disable-next-line @typescript-eslint/no-extra-semi
173
+ ;(async () => {
174
+ for (let attempt = 0; attempt < Infinity; attempt++) {
175
+ try {
176
+ const result = await fn(attempt)
177
+
178
+ if (!isRetryable(attempt, null, result)) {
179
+ accept(result)
180
+ return
181
+ }
182
+ } catch (e: any) {
183
+ if (!isRetryable(attempt, e)) {
184
+ reject(e)
185
+ return
186
+ }
187
+ }
188
+ }
189
+ })()
190
+ })
191
+
192
+ return promise
193
+ }
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '2.9.0'
2
+ export const version = '2.10.0'