@supabase/gotrue-js 2.40.0 → 2.41.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.
- package/dist/main/GoTrueClient.d.ts +13 -0
- package/dist/main/GoTrueClient.d.ts.map +1 -1
- package/dist/main/GoTrueClient.js +229 -180
- package/dist/main/GoTrueClient.js.map +1 -1
- package/dist/main/lib/helpers.d.ts +23 -0
- package/dist/main/lib/helpers.d.ts.map +1 -1
- package/dist/main/lib/helpers.js +94 -1
- package/dist/main/lib/helpers.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/module/GoTrueClient.d.ts +13 -0
- package/dist/module/GoTrueClient.d.ts.map +1 -1
- package/dist/module/GoTrueClient.js +230 -181
- package/dist/module/GoTrueClient.js.map +1 -1
- package/dist/module/lib/helpers.d.ts +23 -0
- package/dist/module/lib/helpers.d.ts.map +1 -1
- package/dist/module/lib/helpers.js +91 -0
- package/dist/module/lib/helpers.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.js +1 -1
- package/package.json +3 -3
- package/src/GoTrueClient.ts +280 -205
- package/src/lib/helpers.ts +111 -0
- package/src/lib/version.ts +1 -1
package/src/lib/helpers.ts
CHANGED
|
@@ -282,3 +282,114 @@ export async function generatePKCEChallenge(verifier: string) {
|
|
|
282
282
|
const hashed = await sha256(verifier)
|
|
283
283
|
return base64urlencode(hashed)
|
|
284
284
|
}
|
|
285
|
+
|
|
286
|
+
const STACK_GUARD_PREFIX = `__stack_guard__`
|
|
287
|
+
const STACK_GUARD_SUFFIX = `__`
|
|
288
|
+
|
|
289
|
+
// Firefox and WebKit based browsers encode the stack entry differently, but
|
|
290
|
+
// they all include the function name. So instead of trying to parse the entry,
|
|
291
|
+
// we're only looking for the special string `__stack_guard__${guardName}__`.
|
|
292
|
+
// Guard names can only be letters with dashes or underscores.
|
|
293
|
+
//
|
|
294
|
+
// Example Firefox stack trace:
|
|
295
|
+
// ```
|
|
296
|
+
// __stack_guard__EXAMPLE__@debugger eval code:1:55
|
|
297
|
+
// @debugger eval code:1:3
|
|
298
|
+
// ```
|
|
299
|
+
//
|
|
300
|
+
// Example WebKit/Chrome stack trace:
|
|
301
|
+
// ```
|
|
302
|
+
// Error
|
|
303
|
+
// at Object.__stack_guard__EXAMPLE__ (<anonymous>:1:55)
|
|
304
|
+
// at <anonymous>:1:13
|
|
305
|
+
// ```
|
|
306
|
+
//
|
|
307
|
+
const STACK_ENTRY_REGEX = /__stack_guard__([a-zA-Z0-9_-]+)__/
|
|
308
|
+
|
|
309
|
+
let STACK_GUARD_CHECKED = false
|
|
310
|
+
let STACK_GUARD_CHECK_FN: () => Promise<void> // eslint-disable-line prefer-const
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Checks if the current caller of the function is in a {@link
|
|
314
|
+
* #stackGuard} of the provided `name`. Works by looking through
|
|
315
|
+
* the stack trace of an `Error` object for a special function
|
|
316
|
+
* name (generated by {@link #stackGuard}).
|
|
317
|
+
*
|
|
318
|
+
* @param name The name of the stack guard to check for. Must be `[a-zA-Z0-9_-]` only.
|
|
319
|
+
*/
|
|
320
|
+
export function isInStackGuard(name: string): boolean {
|
|
321
|
+
STACK_GUARD_CHECK_FN()
|
|
322
|
+
|
|
323
|
+
let error: Error
|
|
324
|
+
|
|
325
|
+
try {
|
|
326
|
+
throw new Error()
|
|
327
|
+
} catch (e: any) {
|
|
328
|
+
error = e
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const stack = error.stack?.split('\n') ?? []
|
|
332
|
+
|
|
333
|
+
for (let i = 0; i < stack.length; i += 1) {
|
|
334
|
+
const entry = stack[i]
|
|
335
|
+
const match = entry.match(STACK_ENTRY_REGEX)
|
|
336
|
+
|
|
337
|
+
if (match && match[1] === name) {
|
|
338
|
+
return true
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return false
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Creates a minification resistant stack guard, i.e. if you
|
|
347
|
+
* call {@link #isInStackGuard} from within the `fn` parameter
|
|
348
|
+
* function, you will always get `true` otherwise it will be
|
|
349
|
+
* `false`.
|
|
350
|
+
*
|
|
351
|
+
* Works by dynamically defining a function name before calling
|
|
352
|
+
* into `fn`, which is then parsed from the stack trace on an
|
|
353
|
+
* `Error` object within {@link #isInStackGuard}.
|
|
354
|
+
*
|
|
355
|
+
* @param name The name of the stack guard. Must be `[a-zA-Z0-9_-]` only.
|
|
356
|
+
* @param fn The async/await function to be run within the stack guard.
|
|
357
|
+
*/
|
|
358
|
+
export async function stackGuard<R>(name: string, fn: () => Promise<R>): Promise<R> {
|
|
359
|
+
await STACK_GUARD_CHECK_FN()
|
|
360
|
+
|
|
361
|
+
const guardName = `${STACK_GUARD_PREFIX}${name}${STACK_GUARD_SUFFIX}`
|
|
362
|
+
|
|
363
|
+
const guardFunc: {
|
|
364
|
+
[funcName: string]: () => Promise<R>
|
|
365
|
+
} = {
|
|
366
|
+
// per ECMAScript rules, this defines a new function with the dynamic name
|
|
367
|
+
// contained in the `guardName` variable
|
|
368
|
+
// this function name shows up in stack traces and is resistant to mangling
|
|
369
|
+
// from minification processes as it is determined at runtime
|
|
370
|
+
[guardName]: async () => await fn(),
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return await guardFunc[guardName]()
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// In certain cases, if this file is transpiled using an ES2015 target, or is
|
|
377
|
+
// running in a JS engine that does not support async/await stack traces, this
|
|
378
|
+
// function will log a single warning message.
|
|
379
|
+
STACK_GUARD_CHECK_FN = async () => {
|
|
380
|
+
if (!STACK_GUARD_CHECKED) {
|
|
381
|
+
STACK_GUARD_CHECKED = true
|
|
382
|
+
|
|
383
|
+
await stackGuard('ENV_CHECK', async () => {
|
|
384
|
+
const result = isInStackGuard('ENV_CHECK')
|
|
385
|
+
|
|
386
|
+
if (!result) {
|
|
387
|
+
console.warn(
|
|
388
|
+
'@supabase/gotrue-js: Stack guards not supported in this environment. Generally not an issue but may point to a very conservative transpilation environment (use ES2017 or above) that implements async/await with generators, or this is a JavaScript engine that does not support async/await stack traces.'
|
|
389
|
+
)
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return result
|
|
393
|
+
})
|
|
394
|
+
}
|
|
395
|
+
}
|
package/src/lib/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '2.
|
|
2
|
+
export const version = '2.41.0'
|