@stackframe/stack-shared 2.5.0 → 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.
- package/CHANGELOG.md +7 -0
- package/dist/crud.d.ts +26 -15
- package/dist/crud.js +16 -0
- package/dist/interface/clientInterface.d.ts +4 -4
- package/dist/interface/clientInterface.js +4 -4
- package/dist/interface/crud/current-user.d.ts +98 -85
- package/dist/interface/crud/current-user.js +35 -17
- package/dist/interface/crud/oauth.d.ts +4 -4
- package/dist/interface/crud/oauth.js +1 -1
- package/dist/interface/crud/users.d.ts +144 -80
- package/dist/interface/crud/users.js +56 -24
- package/dist/known-errors.d.ts +139 -74
- package/dist/known-errors.js +121 -80
- package/dist/schema-fields.d.ts +43 -0
- package/dist/schema-fields.js +68 -0
- package/dist/utils/env.d.ts +3 -2
- package/dist/utils/env.js +6 -3
- package/dist/utils/errors.js +1 -1
- package/dist/utils/objects.d.ts +4 -1
- package/dist/utils/objects.js +32 -1
- package/dist/utils/strings.d.ts +4 -1
- package/dist/utils/strings.js +26 -17
- package/package.json +2 -2
- package/dist/interface/crud/fields.d.ts +0 -11
- package/dist/interface/crud/fields.js +0 -12
package/dist/utils/strings.js
CHANGED
|
@@ -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
|
-
|
|
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,
|
|
157
|
+
const nestedNicify = (newValue, newPath, keyInParent) => {
|
|
152
158
|
return nicify(newValue, {
|
|
153
159
|
...newOptions,
|
|
154
160
|
path: newPath,
|
|
155
|
-
currentIndent: currentIndent +
|
|
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
|
|
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 =
|
|
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}]`,
|
|
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}]`,
|
|
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) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackframe/stack-shared",
|
|
3
|
-
"version": "2.5.
|
|
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.5.
|
|
39
|
+
"@stackframe/stack-sc": "2.5.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"rimraf": "^5.0.5",
|
|
@@ -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' } } });
|