@stackframe/stack-shared 2.6.36 → 2.6.37

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @stackframe/stack-shared
2
2
 
3
+ ## 2.6.37
4
+
5
+ ### Patch Changes
6
+
7
+ - Various changes
8
+ - @stackframe/stack-sc@2.6.37
9
+
3
10
  ## 2.6.36
4
11
 
5
12
  ### Patch Changes
@@ -28,6 +28,7 @@ export declare class StackAssertionError extends Error {
28
28
  readonly extraData?: (Record<string, any> & ErrorOptions) | undefined;
29
29
  constructor(message: string, extraData?: (Record<string, any> & ErrorOptions) | undefined);
30
30
  }
31
+ export declare function errorToNiceString(error: unknown): string;
31
32
  export declare function registerErrorSink(sink: (location: string, error: unknown) => void): void;
32
33
  export declare function captureError(location: string, error: unknown): void;
33
34
  type Status = {
@@ -64,6 +64,15 @@ export class StackAssertionError extends Error {
64
64
  }
65
65
  }
66
66
  StackAssertionError.prototype.name = "StackAssertionError";
67
+ export function errorToNiceString(error) {
68
+ if (!(error instanceof Error))
69
+ return `${typeof error}<${error}>`;
70
+ const stack = error.stack ?? "";
71
+ const toString = error.toString();
72
+ if (stack.startsWith(toString))
73
+ return stack;
74
+ return `${toString}\n${stack}`;
75
+ }
67
76
  const errorSinks = new Set();
68
77
  export function registerErrorSink(sink) {
69
78
  if (errorSinks.has(sink)) {
@@ -80,7 +89,10 @@ registerErrorSink((location, error, ...extraArgs) => {
80
89
  });
81
90
  export function captureError(location, error) {
82
91
  for (const sink of errorSinks) {
83
- sink(location, error, ...error && (typeof error === 'object' || typeof error === 'function') && "customCaptureExtraArgs" in error && Array.isArray(error.customCaptureExtraArgs) ? error.customCaptureExtraArgs : []);
92
+ sink(location,
93
+ // HACK: Log a nicified version of the error instead of statusError to get around buggy Next.js pretty-printing
94
+ // https://www.reddit.com/r/nextjs/comments/1gkxdqe/comment/m19kxgn/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
95
+ errorToNiceString(error), ...error && (typeof error === 'object' || typeof error === 'function') && "customCaptureExtraArgs" in error && Array.isArray(error.customCaptureExtraArgs) ? error.customCaptureExtraArgs : []);
84
96
  }
85
97
  }
86
98
  export class StatusError extends Error {
@@ -69,7 +69,7 @@ declare class RetryError extends AggregateError {
69
69
  constructor(errors: unknown[]);
70
70
  get retries(): number;
71
71
  }
72
- declare function retry<T>(fn: (attempt: number) => Result<T> | Promise<Result<T>>, retries: number, { exponentialDelayBase }?: {
72
+ declare function retry<T>(fn: (attempt: number) => Result<T> | Promise<Result<T>>, totalAttempts: number, { exponentialDelayBase }?: {
73
73
  exponentialDelayBase?: number | undefined;
74
74
  }): Promise<Result<T, RetryError>>;
75
75
  export {};
@@ -98,7 +98,7 @@ class RetryError extends AggregateError {
98
98
  const strings = errors.map(e => String(e));
99
99
  const isAllSame = strings.length > 1 && strings.every(s => s === strings[0]);
100
100
  super(errors, deindent `
101
- Error after retrying ${errors.length} times.
101
+ Error after ${errors.length} attempts.
102
102
 
103
103
  ${isAllSame ? deindent `
104
104
  Attempts 1-${errors.length}:
@@ -116,16 +116,16 @@ class RetryError extends AggregateError {
116
116
  }
117
117
  }
118
118
  RetryError.prototype.name = "RetryError";
119
- async function retry(fn, retries, { exponentialDelayBase = 1000 } = {}) {
119
+ async function retry(fn, totalAttempts, { exponentialDelayBase = 1000 } = {}) {
120
120
  const errors = [];
121
- for (let i = 0; i < retries; i++) {
121
+ for (let i = 0; i < totalAttempts; i++) {
122
122
  const res = await fn(i);
123
123
  if (res.status === "ok") {
124
124
  return Result.ok(res.data);
125
125
  }
126
126
  else {
127
127
  errors.push(res.error);
128
- if (i < retries - 1) {
128
+ if (i < totalAttempts - 1) {
129
129
  await wait((Math.random() + 0.5) * exponentialDelayBase * (2 ** i));
130
130
  }
131
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackframe/stack-shared",
3
- "version": "2.6.36",
3
+ "version": "2.6.37",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -50,7 +50,7 @@
50
50
  "oauth4webapi": "^2.10.3",
51
51
  "semver": "^7.6.3",
52
52
  "uuid": "^9.0.1",
53
- "@stackframe/stack-sc": "2.6.36"
53
+ "@stackframe/stack-sc": "2.6.37"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@simplewebauthn/types": "^11.0.0",