@stackframe/stack-shared 2.4.28 → 2.5.1

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.
@@ -104,6 +104,12 @@ export function mergeScopeStrings(...scopes) {
104
104
  const allScope = scopes.map((s) => extractScopes(s)).flat().join(" ");
105
105
  return extractScopes(allScope).join(" ");
106
106
  }
107
+ export function snakeCaseToCamelCase(snakeCase) {
108
+ return snakeCase.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
109
+ }
110
+ export function camelCaseToSnakeCase(camelCase) {
111
+ return camelCase.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
112
+ }
107
113
  /**
108
114
  * Some classes have different constructor names in different environments (eg. `Headers` is sometimes called `_Headers`,
109
115
  * so we create an object of overrides to handle these cases.
@@ -122,21 +128,20 @@ export function nicify(value, options = {}) {
122
128
  parent: null,
123
129
  overrides: () => null,
124
130
  keyInParent: null,
131
+ hideFields: [],
125
132
  ...filterUndefined(options),
126
133
  };
127
- const { maxDepth, currentIndent, lineIndent, multiline, refs, path, overrides, } = fullOptions;
134
+ const { maxDepth, currentIndent, lineIndent, multiline, refs, path, overrides, hideFields, } = fullOptions;
128
135
  const nl = `\n${currentIndent}`;
129
- if (["function", "object", "symbol"].includes(typeof value)) {
136
+ const overrideResult = overrides(value, options);
137
+ if (overrideResult !== null)
138
+ return overrideResult;
139
+ if (["function", "object", "symbol"].includes(typeof value) && value !== null) {
130
140
  if (refs.has(value)) {
131
141
  return `Ref<${refs.get(value)}>`;
132
142
  }
133
143
  refs.set(value, path);
134
144
  }
135
- const overrideResult = overrides(value, options);
136
- if (overrideResult?.[0] === "result")
137
- return overrideResult[1];
138
- else if (overrideResult?.[0] === "replace")
139
- return nicify(overrideResult[1], options);
140
145
  const newOptions = {
141
146
  maxDepth: maxDepth - 1,
142
147
  currentIndent,
@@ -147,12 +152,13 @@ export function nicify(value, options = {}) {
147
152
  overrides,
148
153
  parent: { value, options: fullOptions },
149
154
  keyInParent: null,
155
+ hideFields: [],
150
156
  };
151
- const nestedNicify = (newValue, newPath, indent, keyInParent) => {
157
+ const nestedNicify = (newValue, newPath, keyInParent) => {
152
158
  return nicify(newValue, {
153
159
  ...newOptions,
154
160
  path: newPath,
155
- currentIndent: currentIndent + (indent ? lineIndent : ""),
161
+ currentIndent: currentIndent + lineIndent,
156
162
  keyInParent,
157
163
  });
158
164
  };
@@ -184,11 +190,11 @@ export function nicify(value, options = {}) {
184
190
  const resValueLength = value.length + extraLines.length;
185
191
  if (maxDepth <= 0 && resValueLength === 0)
186
192
  return "[...]";
187
- const shouldIndent = multiline && resValueLength > 1;
188
- const resValues = value.map((v, i) => nestedNicify(v, `${path}[${i}]`, shouldIndent, i));
193
+ const resValues = value.map((v, i) => nestedNicify(v, `${path}[${i}]`, i));
189
194
  resValues.push(...extraLines);
190
195
  if (resValues.length !== resValueLength)
191
196
  throw new StackAssertionError("nicify of object: resValues.length !== resValueLength", { value, resValues, resValueLength });
197
+ const shouldIndent = resValues.length > 1 || resValues.some(x => x.includes("\n"));
192
198
  if (shouldIndent) {
193
199
  return `[${nl}${resValues.map(x => `${lineIndent}${x},${nl}`).join("")}]`;
194
200
  }
@@ -196,29 +202,32 @@ export function nicify(value, options = {}) {
196
202
  return `[${resValues.join(", ")}]`;
197
203
  }
198
204
  }
199
- const constructorName = [null, Object].includes(Object.getPrototypeOf(value)) ? null : (nicifiableClassNameOverrides.get(value.constructor) ?? value.constructor.name);
205
+ const constructorName = [null, Object.prototype].includes(Object.getPrototypeOf(value)) ? null : (nicifiableClassNameOverrides.get(value.constructor) ?? value.constructor.name);
200
206
  const constructorString = constructorName ? `${nicifyPropertyString(constructorName)} ` : "";
201
- const entries = getNicifiableEntries(value);
202
- const extraLines = getNicifiedObjectExtraLines(value);
207
+ const entries = getNicifiableEntries(value).filter(([k]) => !hideFields.includes(k));
208
+ const extraLines = [
209
+ ...getNicifiedObjectExtraLines(value),
210
+ ...hideFields.length > 0 ? [`<some fields may have been hidden>`] : [],
211
+ ];
203
212
  const resValueLength = entries.length + extraLines.length;
204
213
  if (resValueLength === 0)
205
214
  return `${constructorString}{}`;
206
215
  if (maxDepth <= 0)
207
216
  return `${constructorString}{ ... }`;
208
- const shouldIndent = multiline && resValueLength > 1;
209
217
  const resValues = entries.map(([k, v], keyIndex) => {
210
- const keyNicified = nestedNicify(k, `Object.keys(${path})[${keyIndex}]`, shouldIndent, null);
218
+ const keyNicified = nestedNicify(k, `Object.keys(${path})[${keyIndex}]`, null);
211
219
  const keyInObjectLiteral = typeof k === "string" ? JSON.stringify(k) : `[${keyNicified}]`;
212
220
  if (typeof v === "function" && v.name === k) {
213
221
  return `${keyInObjectLiteral}(...): { ... }`;
214
222
  }
215
223
  else {
216
- return `${keyInObjectLiteral}: ${nestedNicify(v, `${path}[${keyNicified}]`, shouldIndent, k)}`;
224
+ return `${keyInObjectLiteral}: ${nestedNicify(v, `${path}[${keyNicified}]`, k)}`;
217
225
  }
218
226
  });
219
227
  resValues.push(...extraLines);
220
228
  if (resValues.length !== resValueLength)
221
229
  throw new StackAssertionError("nicify of object: resValues.length !== resValueLength", { value, resValues, resValueLength });
230
+ const shouldIndent = resValues.length > 1 || resValues.some(x => x.includes("\n"));
222
231
  if (resValues.length === 0)
223
232
  return `${constructorString}{}`;
224
233
  if (shouldIndent) {
@@ -233,6 +242,9 @@ export function nicify(value, options = {}) {
233
242
  }
234
243
  }
235
244
  }
245
+ export function replaceAll(input, searchValue, replaceValue) {
246
+ return input.split(searchValue).join(replaceValue);
247
+ }
236
248
  function nicifyPropertyString(str) {
237
249
  if (/^[_a-zA-Z][_a-zA-Z0-9]*$/.test(str))
238
250
  return str;
@@ -1,2 +1,3 @@
1
1
  import * as yup from "yup";
2
2
  export declare const yupJson: yup.MixedSchema<{} | null, yup.AnyObject, undefined, "">;
3
+ export declare const yupJsonValidator: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
package/dist/utils/yup.js CHANGED
@@ -1,2 +1,13 @@
1
1
  import * as yup from "yup";
2
2
  export const yupJson = yup.mixed().nullable().defined().transform((value) => JSON.parse(JSON.stringify(value)));
3
+ export const yupJsonValidator = yup.string().test("json", "Invalid JSON format", (value) => {
4
+ if (!value)
5
+ return true;
6
+ try {
7
+ JSON.parse(value);
8
+ return true;
9
+ }
10
+ catch (error) {
11
+ return false;
12
+ }
13
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackframe/stack-shared",
3
- "version": "2.4.28",
3
+ "version": "2.5.1",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -36,7 +36,7 @@
36
36
  "jose": "^5.2.2",
37
37
  "oauth4webapi": "^2.10.3",
38
38
  "uuid": "^9.0.1",
39
- "@stackframe/stack-sc": "2.4.28"
39
+ "@stackframe/stack-sc": "2.5.1"
40
40
  },
41
41
  "devDependencies": {
42
42
  "rimraf": "^5.0.5",
@@ -1 +0,0 @@
1
- export declare function useTrigger(callback: () => void): () => void;
@@ -1,10 +0,0 @@
1
- import * as React from "react";
2
- export function useTrigger(callback) {
3
- const [hasTriggered, setHasTriggered] = React.useState(false);
4
- React.useEffect(() => {
5
- if (hasTriggered) {
6
- callback();
7
- }
8
- }, [hasTriggered]);
9
- return () => setHasTriggered(true);
10
- }
@@ -1,11 +0,0 @@
1
- import * as yup from "yup";
2
- export declare const projectIdSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
3
- export declare const userIdSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
4
- export declare const primaryEmailSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
5
- export declare const primaryEmailVerifiedSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
6
- export declare const userDisplayNameSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
7
- export declare const selectedTeamIdSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
8
- export declare const profileImageUrlSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
9
- export declare const signedUpAtMillisSchema: yup.NumberSchema<number | undefined, yup.AnyObject, undefined, "">;
10
- export declare const userClientMetadataSchema: yup.MixedSchema<{} | null, yup.AnyObject, undefined, "">;
11
- export declare const userServerMetadataSchema: yup.MixedSchema<{} | null, yup.AnyObject, undefined, "">;
@@ -1,12 +0,0 @@
1
- import * as yup from "yup";
2
- import { yupJson } from "../../utils/yup";
3
- export const projectIdSchema = yup.string().meta({ openapi: { description: 'Stack dashboard project ID', exampleValue: 'project-id' } });
4
- export const userIdSchema = yup.string().meta({ openapi: { description: 'Unique user identifier', exampleValue: 'user-id' } });
5
- export const primaryEmailSchema = yup.string().meta({ openapi: { description: 'Primary email', exampleValue: 'johndoe@example.com' } });
6
- export const primaryEmailVerifiedSchema = yup.boolean().meta({ openapi: { description: 'Whether the primary email has been verified to belong to this user', exampleValue: true } });
7
- export const userDisplayNameSchema = yup.string().meta({ openapi: { description: 'Human-readable display name', exampleValue: 'John Doe' } });
8
- export const selectedTeamIdSchema = yup.string().meta({ openapi: { description: 'ID of the team currently selected by the user', exampleValue: 'team-id' } });
9
- export const profileImageUrlSchema = yup.string().meta({ openapi: { description: 'Profile image URL', exampleValue: 'https://example.com/image.jpg' } });
10
- export const signedUpAtMillisSchema = yup.number().meta({ openapi: { description: 'Signed up at milliseconds', exampleValue: 1630000000000 } });
11
- export const userClientMetadataSchema = yupJson.meta({ openapi: { description: 'Client metadata. Used as a data store, accessible from the client side', exampleValue: { key: 'value' } } });
12
- export const userServerMetadataSchema = yupJson.meta({ openapi: { description: 'Server metadata. Used as a data store, only accessible from the server side', exampleValue: { key: 'value' } } });