@stackframe/stack-shared 2.8.36 → 2.8.39

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/config/schema.d.mts +91 -15
  3. package/dist/config/schema.d.ts +91 -15
  4. package/dist/config/schema.js +24 -4
  5. package/dist/config/schema.js.map +1 -1
  6. package/dist/esm/config/schema.js +24 -4
  7. package/dist/esm/config/schema.js.map +1 -1
  8. package/dist/esm/helpers/vault/server-side.js +5 -1
  9. package/dist/esm/helpers/vault/server-side.js.map +1 -1
  10. package/dist/esm/interface/admin-interface.js +53 -2
  11. package/dist/esm/interface/admin-interface.js.map +1 -1
  12. package/dist/esm/interface/client-interface.js +29 -26
  13. package/dist/esm/interface/client-interface.js.map +1 -1
  14. package/dist/esm/interface/crud/oauth-providers.js +2 -0
  15. package/dist/esm/interface/crud/oauth-providers.js.map +1 -1
  16. package/dist/esm/interface/crud/transactions.js +21 -0
  17. package/dist/esm/interface/crud/transactions.js.map +1 -0
  18. package/dist/esm/interface/server-interface.js +5 -7
  19. package/dist/esm/interface/server-interface.js.map +1 -1
  20. package/dist/esm/known-errors.js +21 -1
  21. package/dist/esm/known-errors.js.map +1 -1
  22. package/dist/esm/schema-fields.js +6 -3
  23. package/dist/esm/schema-fields.js.map +1 -1
  24. package/dist/esm/utils/arrays.js +25 -0
  25. package/dist/esm/utils/arrays.js.map +1 -1
  26. package/dist/esm/utils/esbuild.js +63 -6
  27. package/dist/esm/utils/esbuild.js.map +1 -1
  28. package/dist/esm/utils/jwt.js +16 -1
  29. package/dist/esm/utils/jwt.js.map +1 -1
  30. package/dist/esm/utils/numbers.js +14 -9
  31. package/dist/esm/utils/numbers.js.map +1 -1
  32. package/dist/esm/utils/promises.js +2 -1
  33. package/dist/esm/utils/promises.js.map +1 -1
  34. package/dist/esm/utils/types.js.map +1 -1
  35. package/dist/helpers/vault/server-side.js +5 -1
  36. package/dist/helpers/vault/server-side.js.map +1 -1
  37. package/dist/index.d.mts +3 -1
  38. package/dist/index.d.ts +3 -1
  39. package/dist/interface/admin-interface.d.mts +34 -3
  40. package/dist/interface/admin-interface.d.ts +34 -3
  41. package/dist/interface/admin-interface.js +53 -2
  42. package/dist/interface/admin-interface.js.map +1 -1
  43. package/dist/interface/client-interface.d.mts +5 -21
  44. package/dist/interface/client-interface.d.ts +5 -21
  45. package/dist/interface/client-interface.js +29 -26
  46. package/dist/interface/client-interface.js.map +1 -1
  47. package/dist/interface/crud/oauth-providers.d.mts +8 -0
  48. package/dist/interface/crud/oauth-providers.d.ts +8 -0
  49. package/dist/interface/crud/oauth-providers.js +1 -0
  50. package/dist/interface/crud/oauth-providers.js.map +1 -1
  51. package/dist/interface/crud/transactions.d.mts +56 -0
  52. package/dist/interface/crud/transactions.d.ts +56 -0
  53. package/dist/interface/crud/transactions.js +46 -0
  54. package/dist/interface/crud/transactions.js.map +1 -0
  55. package/dist/interface/server-interface.d.mts +8 -43
  56. package/dist/interface/server-interface.d.ts +8 -43
  57. package/dist/interface/server-interface.js +5 -7
  58. package/dist/interface/server-interface.js.map +1 -1
  59. package/dist/known-errors.d.mts +6 -0
  60. package/dist/known-errors.d.ts +6 -0
  61. package/dist/known-errors.js +21 -1
  62. package/dist/known-errors.js.map +1 -1
  63. package/dist/schema-fields.d.mts +3 -2
  64. package/dist/schema-fields.d.ts +3 -2
  65. package/dist/schema-fields.js +7 -3
  66. package/dist/schema-fields.js.map +1 -1
  67. package/dist/utils/arrays.d.mts +6 -1
  68. package/dist/utils/arrays.d.ts +6 -1
  69. package/dist/utils/arrays.js +30 -0
  70. package/dist/utils/arrays.js.map +1 -1
  71. package/dist/utils/esbuild.d.mts +1 -0
  72. package/dist/utils/esbuild.d.ts +1 -0
  73. package/dist/utils/esbuild.js +63 -6
  74. package/dist/utils/esbuild.js.map +1 -1
  75. package/dist/utils/jwt.d.mts +34 -1
  76. package/dist/utils/jwt.d.ts +34 -1
  77. package/dist/utils/jwt.js +16 -0
  78. package/dist/utils/jwt.js.map +1 -1
  79. package/dist/utils/numbers.js +14 -9
  80. package/dist/utils/numbers.js.map +1 -1
  81. package/dist/utils/promises.d.mts +1 -1
  82. package/dist/utils/promises.d.ts +1 -1
  83. package/dist/utils/promises.js +2 -1
  84. package/dist/utils/promises.js.map +1 -1
  85. package/dist/utils/types.d.mts +10 -1
  86. package/dist/utils/types.d.ts +10 -1
  87. package/dist/utils/types.js.map +1 -1
  88. package/package.json +3 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema-fields.ts"],"sourcesContent":["import * as yup from \"yup\";\nimport { KnownErrors } from \".\";\nimport { isBase64 } from \"./utils/bytes\";\nimport { type Currency, type MoneyAmount, SUPPORTED_CURRENCIES } from \"./utils/currency-constants\";\nimport { DayInterval, Interval } from \"./utils/dates\";\nimport { StackAssertionError, throwErr } from \"./utils/errors\";\nimport { decodeBasicAuthorizationHeader } from \"./utils/http\";\nimport { allProviders } from \"./utils/oauth\";\nimport { deepPlainClone, omit, typedFromEntries } from \"./utils/objects\";\nimport { deindent } from \"./utils/strings\";\nimport { isValidHostnameWithWildcards, isValidUrl } from \"./utils/urls\";\nimport { isUuid } from \"./utils/uuids\";\n\nconst MAX_IMAGE_SIZE_BASE64_BYTES = 1_000_000; // 1MB\n\ndeclare module \"yup\" {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface StringSchema<TType, TContext, TDefault, TFlags> {\n nonEmpty(message?: string): StringSchema<TType, TContext, TDefault, TFlags>,\n empty(): StringSchema<TType, TContext, TDefault, TFlags>,\n }\n\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Schema<TType, TContext, TDefault, TFlags> {\n hasNested<K extends keyof NonNullable<TType>>(path: K): boolean,\n getNested<K extends keyof NonNullable<TType>>(path: K): yup.Schema<NonNullable<TType>[K], TContext, TDefault, TFlags>,\n\n // the default types for concat kinda suck, so let's fix that\n concat<U extends yup.AnySchema>(schema: U): yup.Schema<Omit<NonNullable<TType>, keyof yup.InferType<U>> & yup.InferType<U> | (TType & (null | undefined)), TContext, Omit<NonNullable<TDefault>, keyof U['__default']> & U['__default'] | (TDefault & (null | undefined)), TFlags>,\n }\n\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n export interface CustomSchemaMetadata {\n stackSchemaInfo?:\n | {\n type: \"object\" | \"array\" | \"string\" | \"number\" | \"boolean\" | \"date\" | \"mixed\" | \"never\",\n }\n | {\n type: \"tuple\",\n items: yup.AnySchema[],\n }\n | {\n type: \"union\",\n items: yup.AnySchema[],\n }\n | {\n type: \"record\",\n keySchema: yup.StringSchema<any>,\n valueSchema: yup.AnySchema,\n },\n }\n}\n\n// eslint-disable-next-line no-restricted-syntax\nyup.addMethod(yup.string, \"nonEmpty\", function (message?: string) {\n return this.test(\n \"non-empty\",\n message ?? (({ path }) => `${path} must not be empty`),\n (value) => {\n return value !== \"\";\n }\n );\n});\n\nyup.addMethod(yup.Schema, \"hasNested\", function (path: any) {\n if (!path.match(/^[a-zA-Z0-9_$:-]+$/)) throw new StackAssertionError(`yupSchema.hasNested can currently only be used with alphanumeric keys, underscores, dollar signs, colons, and hyphens. Fix this in the future. Provided key: ${JSON.stringify(path)}`);\n const schemaInfo = this.meta()?.stackSchemaInfo as any;\n if (schemaInfo?.type === \"record\") {\n return schemaInfo.keySchema.isValidSync(path);\n } else if (schemaInfo?.type === \"union\") {\n return schemaInfo.items.some((s: any) => s.hasNested(path));\n } else {\n try {\n yup.reach(this, path);\n return true as any;\n } catch (e) {\n if (e instanceof Error && e.message.includes(\"The schema does not contain the path\")) {\n return false as any;\n }\n throw e;\n }\n }\n});\n\nyup.addMethod(yup.Schema, \"getNested\", function (path: any) {\n if (!path.match(/^[a-zA-Z0-9_$:-]+$/)) throw new StackAssertionError(`yupSchema.getNested can currently only be used with alphanumeric keys, underscores, dollar signs, colons, and hyphens. Fix this in the future. Provided key: ${path}`);\n\n if (!this.hasNested(path as never)) throw new StackAssertionError(`Tried to call yupSchema.getNested, but key is not present in the schema. Provided key: ${path}`, { path, schema: this });\n\n const schemaInfo = this.meta()?.stackSchemaInfo;\n if (schemaInfo?.type === \"record\") {\n return schemaInfo.valueSchema;\n } else if (schemaInfo?.type === \"union\") {\n const schemasWithNested = schemaInfo.items.filter((s: any) => s.hasNested(path));\n return yupUnion(...schemasWithNested.map(s => s.getNested(path)));\n } else {\n return yup.reach(this, path) as any;\n }\n});\n\nundefined?.test(\"hasNested\", ({ expect }) => {\n expect(yupObject({ a: yupString() }).hasNested(\"a\")).toBe(true);\n expect(yupObject({}).hasNested(\"a\" as never)).toBe(false);\n expect(yupRecord(yupString(), yupString()).hasNested(\"a\")).toBe(true);\n expect(yupRecord(yupString().oneOf([\"a\"]), yupString()).hasNested(\"b\")).toBe(false);\n expect(yupUnion(yupString(), yupNumber()).hasNested(\"a\" as any)).toBe(false);\n expect(yupUnion(yupString(), yupObject({ b: yupNumber() })).hasNested(\"a\" as never)).toBe(false);\n expect(yupUnion(yupString(), yupObject({ a: yupNumber() })).hasNested(\"a\" as never)).toBe(true);\n});\nundefined?.test(\"getNested\", ({ expect }) => {\n expect(yupObject({ a: yupNumber() }).getNested(\"a\").describe().type).toEqual(\"number\");\n expect(() => yupObject({}).getNested(\"a\" as never)).toThrow();\n expect(() => yupObject({ a: yupObject({ b: yupString() }) }).getNested(\"a.b\" as never)).toThrow();\n expect(yupRecord(yupString().oneOf([\"a\"]), yupNumber()).getNested(\"a\").describe().type).toEqual(\"number\");\n expect(() => yupRecord(yupString().oneOf([\"a\"]), yupString()).getNested(\"b\" as never)).toThrow();\n expect(yupUnion(yupString(), yupObject({ a: yupNumber() })).getNested(\"a\" as never).describe().type).toEqual(\"mixed\");\n expect(yupUnion(yupObject({ a: yupString() }), yupObject({ a: yupNumber() })).getNested(\"a\").describe().type).toEqual(\"mixed\");\n});\n\nexport async function yupValidate<S extends yup.ISchema<any>>(\n schema: S,\n obj: unknown,\n options?: yup.ValidateOptions & { currentUserId?: string | null }\n): Promise<yup.InferType<S>> {\n try {\n return await schema.validate(obj, {\n ...omit(options ?? {}, ['currentUserId']),\n context: {\n ...options?.context,\n stackAllowUserIdMe: options?.currentUserId !== undefined,\n },\n });\n } catch (error) {\n if (error instanceof ReplaceFieldWithOwnUserId) {\n const currentUserId = options?.currentUserId;\n if (!currentUserId) throw new KnownErrors.CannotGetOwnUserWithoutUser();\n\n // parse yup path\n let pathRemaining = error.path;\n const fieldPath = [];\n while (pathRemaining.length > 0) {\n if (pathRemaining.startsWith(\"[\")) {\n const index = pathRemaining.indexOf(\"]\");\n if (index < 0) throw new StackAssertionError(\"Invalid path\");\n fieldPath.push(JSON.parse(pathRemaining.slice(1, index)));\n pathRemaining = pathRemaining.slice(index + 1);\n } else {\n let dotIndex = pathRemaining.indexOf(\".\");\n if (dotIndex === -1) dotIndex = pathRemaining.length;\n fieldPath.push(pathRemaining.slice(0, dotIndex));\n pathRemaining = pathRemaining.slice(dotIndex + 1);\n }\n }\n\n const newObj = deepPlainClone(obj);\n let it = newObj;\n for (const field of fieldPath.slice(0, -1)) {\n if (!Object.prototype.hasOwnProperty.call(it, field)) {\n throw new StackAssertionError(`Segment ${field} of path ${error.path} not found in object`);\n }\n it = (it as any)[field];\n }\n (it as any)[fieldPath[fieldPath.length - 1]] = currentUserId;\n\n return await yupValidate(schema, newObj, options);\n }\n throw error;\n }\n}\n\nconst _idDescription = (identify: string) => `The unique identifier of the ${identify}`;\nconst _displayNameDescription = (identify: string) => `Human-readable ${identify} display name. This is not a unique identifier.`;\nconst _clientMetaDataDescription = (identify: string) => `Client metadata. Used as a data store, accessible from the client side. Do not store information that should not be exposed to the client.`;\nconst _clientReadOnlyMetaDataDescription = (identify: string) => `Client read-only, server-writable metadata. Used as a data store, accessible from the client side. Do not store information that should not be exposed to the client. The client can read this data, but cannot modify it. This is useful for things like subscription status.`;\nconst _profileImageUrlDescription = (identify: string) => `URL of the profile image for ${identify}. Can be a Base64 encoded image. Must be smaller than 100KB. Please compress and crop to a square before passing in.`;\nconst _serverMetaDataDescription = (identify: string) => `Server metadata. Used as a data store, only accessible from the server side. You can store secret information related to the ${identify} here.`;\nconst _atMillisDescription = (identify: string) => `(the number of milliseconds since epoch, January 1, 1970, UTC)`;\nconst _createdAtMillisDescription = (identify: string) => `The time the ${identify} was created ${_atMillisDescription(identify)}`;\nconst _signedUpAtMillisDescription = `The time the user signed up ${_atMillisDescription}`;\nconst _lastActiveAtMillisDescription = `The time the user was last active ${_atMillisDescription}`;\n\n\ndeclare const StackAdaptSentinel: unique symbol;\nexport type StackAdaptSentinel = typeof StackAdaptSentinel;\n\n// Built-in replacements\nexport function yupString<A extends string, B extends yup.Maybe<yup.AnyObject> = yup.AnyObject>(...args: Parameters<typeof yup.string<A, B>>) {\n // eslint-disable-next-line no-restricted-syntax\n return yup.string(...args).meta({ stackSchemaInfo: { type: \"string\" } });\n}\nexport function yupNumber<A extends number, B extends yup.Maybe<yup.AnyObject> = yup.AnyObject>(...args: Parameters<typeof yup.number<A, B>>) {\n // eslint-disable-next-line no-restricted-syntax\n return yup.number(...args).meta({ stackSchemaInfo: { type: \"number\" } });\n}\nexport function yupBoolean<A extends boolean, B extends yup.Maybe<yup.AnyObject> = yup.AnyObject>(...args: Parameters<typeof yup.boolean<A, B>>) {\n // eslint-disable-next-line no-restricted-syntax\n return yup.boolean(...args).meta({ stackSchemaInfo: { type: \"boolean\" } });\n}\n/**\n * @deprecated, use number of milliseconds since epoch instead\n */\nexport function yupDate<A extends Date, B extends yup.Maybe<yup.AnyObject> = yup.AnyObject>(...args: Parameters<typeof yup.date<A, B>>) {\n // eslint-disable-next-line no-restricted-syntax\n return yup.date(...args).meta({ stackSchemaInfo: { type: \"date\" } });\n}\nfunction _yupMixedInternal<A extends {}>(...args: Parameters<typeof yup.mixed<A>>) {\n // eslint-disable-next-line no-restricted-syntax\n return yup.mixed(...args);\n}\nexport function yupMixed<A extends {}>(...args: Parameters<typeof yup.mixed<A>>) {\n return _yupMixedInternal(...args).meta({ stackSchemaInfo: { type: \"mixed\" } });\n}\nexport function yupArray<A extends yup.Maybe<yup.AnyObject> = yup.AnyObject, B = any>(...args: Parameters<typeof yup.array<A, B>>) {\n // eslint-disable-next-line no-restricted-syntax\n return yup.array(...args).meta({ stackSchemaInfo: { type: \"array\" } });\n}\nexport function yupTuple<T extends [unknown, ...unknown[]]>(schemas: { [K in keyof T]: yup.Schema<T[K]> }) {\n if (schemas.length === 0) throw new Error('yupTuple must have at least one schema');\n // eslint-disable-next-line no-restricted-syntax\n return yup.tuple<T>(schemas as any).meta({ stackSchemaInfo: { type: \"tuple\", items: schemas } });\n}\nexport function yupObjectWithAutoDefault<A extends yup.Maybe<yup.AnyObject>, B extends yup.ObjectShape>(...args: Parameters<typeof yup.object<A, B>>) {\n // eslint-disable-next-line no-restricted-syntax\n const object = yup.object(...args).test(\n 'no-unknown-object-properties',\n ({ path }) => `${path} contains unknown properties`,\n (value: any, context) => {\n if (context.options.context?.noUnknownPathPrefixes?.some((prefix: string) => context.path.startsWith(prefix))) {\n if (context.schema.spec.noUnknown !== false) {\n const availableKeys = new Set(Object.keys(context.schema.fields));\n const unknownKeys = Object.keys(value ?? {}).filter(key => !availableKeys.has(key));\n if (unknownKeys.length > 0) {\n // TODO \"did you mean XYZ\"\n return context.createError({\n message: `${context.path || \"Object\"} contains unknown properties: ${unknownKeys.join(', ')}`,\n path: context.path,\n params: { unknownKeys, availableKeys },\n });\n }\n }\n }\n return true;\n },\n ).meta({ stackSchemaInfo: { type: \"object\" } });\n return object;\n}\nexport function yupObject<A extends yup.Maybe<yup.AnyObject>, B extends yup.ObjectShape>(...args: Parameters<typeof yup.object<A, B>>) {\n // we don't want to update the type of `object` to have a default flag\n const object = yupObjectWithAutoDefault(...args);\n return object.default(undefined) as any as typeof object;\n}\n\nexport function yupNever(): yup.MixedSchema<never> {\n return _yupMixedInternal().meta({ stackSchemaInfo: { type: \"never\" } }).test('never', 'This value should never be reached', () => false) as any;\n}\n\nexport function yupUnion<T extends yup.AnySchema[]>(...args: T): yup.MixedSchema<yup.InferType<T[number]>> {\n if (args.length === 0) throw new Error('yupUnion must have at least one schema');\n\n return _yupMixedInternal().meta({ stackSchemaInfo: { type: \"union\", items: args } }).test('is-one-of', 'Invalid value', async (value, context) => {\n if (value == null) return true;\n const errors = [];\n for (const schema of args) {\n try {\n await yupValidate(schema, value, context.options);\n return true;\n } catch (e) {\n errors.push(e);\n }\n }\n return context.createError({\n message: deindent`\n ${context.path} is not matched by any of the provided schemas:\n ${errors.map((e: any, i) => deindent`\n Schema ${i}:\n ${e.errors.join('\\n')}\n `).join('\\n')}`,\n path: context.path,\n });\n });\n}\n\nexport function yupRecord<K extends yup.StringSchema, T extends yup.AnySchema>(\n keySchema: K,\n valueSchema: T,\n): yup.MixedSchema<Record<yup.InferType<K> & string, yup.InferType<T>>> {\n return yupObject().meta({ stackSchemaInfo: { type: \"record\", keySchema, valueSchema } }).unknown(true).test(\n 'record',\n '${path} must be a record of valid values',\n async function (value: unknown, context: yup.TestContext) {\n if (value == null) return true;\n const { path, createError } = this as any;\n if (typeof value !== 'object') {\n return createError({ message: `${path} must be an object` });\n }\n\n // Validate each property using the provided valueSchema\n for (const key of Object.keys(value)) {\n // Validate the key\n await yupValidate(keySchema, key, context.options);\n\n // Validate the value\n try {\n await yupValidate(valueSchema, (value as Record<string, unknown>)[key], {\n ...context.options,\n context: {\n ...context.options.context,\n path: path ? `${path}.${key}` : key,\n },\n });\n } catch (e: any) {\n return createError({\n path: path ? `${path}.${key}` : key,\n message: e.message,\n });\n }\n }\n\n return true;\n },\n ) as any;\n}\n\nexport function ensureObjectSchema<T extends yup.AnyObject>(schema: yup.Schema<T>): yup.ObjectSchema<T> & typeof schema {\n if (!(schema instanceof yup.ObjectSchema)) throw new StackAssertionError(`assertObjectSchema: schema is not an ObjectSchema: ${schema.describe().type}`);\n return schema as any;\n}\n\n// Common\nexport const adaptSchema = yupMixed<StackAdaptSentinel>();\n/**\n * Yup's URL schema does not recognize some URLs (including `http://localhost`) as a valid URL. This schema is a workaround for that.\n */\nexport const urlSchema = yupString().test({\n name: 'no-spaces',\n message: (params) => `${params.path} contains spaces`,\n test: (value) => value == null || !value.includes(' ')\n}).test({\n name: 'url',\n message: (params) => `${params.path} is not a valid URL`,\n test: (value) => value == null || isValidUrl(value)\n});\n/**\n * URL schema that supports wildcard patterns in hostnames (e.g., \"https://*.example.com\", \"http://*:8080\")\n */\nexport const wildcardUrlSchema = yupString().test({\n name: 'no-spaces',\n message: (params) => `${params.path} contains spaces`,\n test: (value) => value == null || !value.includes(' ')\n}).test({\n name: 'wildcard-url',\n message: (params) => `${params.path} is not a valid URL or wildcard URL pattern`,\n test: (value) => {\n if (value == null) return true;\n\n // If it doesn't contain wildcards, use the regular URL validation\n if (!value.includes('*')) {\n return isValidUrl(value);\n }\n\n // For wildcard URLs, validate the structure by replacing wildcards with placeholders\n try {\n const PLACEHOLDER = 'wildcard-placeholder';\n // Replace wildcards with valid placeholders for URL parsing\n const normalizedUrl = value.replace(/\\*/g, PLACEHOLDER);\n const url = new URL(normalizedUrl);\n\n // Only allow wildcards in the hostname; reject anywhere else\n if (\n url.username.includes(PLACEHOLDER) ||\n url.password.includes(PLACEHOLDER) ||\n url.pathname.includes(PLACEHOLDER) ||\n url.search.includes(PLACEHOLDER) ||\n url.hash.includes(PLACEHOLDER)\n ) {\n return false;\n }\n\n // Only http/https are acceptable\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n return false;\n }\n\n // Extract original hostname pattern from the input\n const hostPattern = url.hostname.split(PLACEHOLDER).join('*');\n\n // Validate the wildcard hostname pattern using the existing function\n return isValidHostnameWithWildcards(hostPattern);\n } catch (e) {\n return false;\n }\n }\n});\nexport const jsonSchema = yupMixed().nullable().defined().transform((value) => JSON.parse(JSON.stringify(value)));\nexport const jsonStringSchema = yupString().test(\"json\", (params) => `${params.path} is not valid JSON`, (value) => {\n if (value == null) return true;\n try {\n JSON.parse(value);\n return true;\n } catch (error) {\n return false;\n }\n});\nexport const jsonStringOrEmptySchema = yupString().test(\"json\", (params) => `${params.path} is not valid JSON`, (value) => {\n if (!value) return true;\n try {\n JSON.parse(value);\n return true;\n } catch (error) {\n return false;\n }\n});\nexport const base64Schema = yupString().test(\"is-base64\", (params) => `${params.path} is not valid base64`, (value) => {\n if (value == null) return true;\n return isBase64(value);\n});\nexport const passwordSchema = yupString().max(70);\nexport const intervalSchema = yupTuple<Interval>([yupNumber().min(0).integer().defined(), yupString().oneOf(['millisecond', 'second', 'minute', 'hour', 'day', 'week', 'month', 'year']).defined()]);\nexport const dayIntervalSchema = yupTuple<DayInterval>([yupNumber().min(0).integer().defined(), yupString().oneOf(['day', 'week', 'month', 'year']).defined()]);\nexport const intervalOrNeverSchema = yupUnion(intervalSchema.defined(), yupString().oneOf(['never']).defined());\nexport const dayIntervalOrNeverSchema = yupUnion(dayIntervalSchema.defined(), yupString().oneOf(['never']).defined());\n/**\n * This schema is useful for fields where the user can specify the ID, such as price IDs. It is particularly common\n * for IDs in the config schema.\n */\nexport const userSpecifiedIdSchema = (idName: `${string}Id`) => yupString().matches(/^[a-zA-Z_][a-zA-Z0-9_-]*$/, `${idName} must start with a letter or underscore and contain only letters, numbers, underscores, and hyphens`);\nexport const moneyAmountSchema = (currency: Currency) => yupString<MoneyAmount>().test('money-amount', 'Invalid money amount', (value, context) => {\n if (value == null) return true;\n const regex = /^([0-9]+)(\\.([0-9]+))?$/;\n const match = value.match(regex);\n if (!match) return context.createError({ message: 'Money amount must be in the format of <number> or <number>.<number>' });\n const whole = match[1];\n const decimals = match[3];\n if (decimals && decimals.length > currency.decimals) return context.createError({ message: `Too many decimals; ${currency.code} only has ${currency.decimals} decimals` });\n if (whole !== '0' && whole.startsWith('0')) return context.createError({ message: 'Money amount must not have leading zeros' });\n return true;\n});\n\n\n/**\n * A stricter email schema that does some additional checks for UX input. (Some emails are allowed by the spec, for\n * example `test@localhost` or `abc@gmail`, but almost certainly a user input error.)\n *\n * Note that some users in the DB have an email that doesn't match this regex, so most of the time you should use\n * `emailSchema` instead until we do the DB migration.\n */\n// eslint-disable-next-line no-restricted-syntax\nexport const strictEmailSchema = (message: string | undefined) => yupString().email(message).matches(/^[^.]+(\\.[^.]+)*@.*\\.[^.][^.]+$/, message);\n// eslint-disable-next-line no-restricted-syntax\nexport const emailSchema = yupString().email();\n\nundefined?.test('strictEmailSchema', ({ expect }) => {\n const validEmails = [\n \"a@example.com\",\n \"abc@example.com\",\n \"a.b@example.com\",\n \"throwaway.mail+token@example.com\",\n \"email-alt-dash@demo-mail.com\",\n \"test-account@weird-domain.net\",\n \"%!~&+{}=|`#@domain.test\",\n \"admin@a.longtldexample\",\n ];\n for (const email of validEmails) {\n expect(strictEmailSchema(undefined).validateSync(email)).toBe(email);\n }\n const invalidEmails = [\n \"test@localhost\",\n \"test@gmail\",\n \"test@gmail.com.a\",\n \"test@gmail.a\",\n \"test.@example.com\",\n \"test..test@example.com\",\n \".test@example.com\",\n ];\n for (const email of invalidEmails) {\n expect(() => strictEmailSchema(undefined).validateSync(email)).toThrow();\n }\n});\n\n// Request auth\nexport const clientOrHigherAuthTypeSchema = yupString().oneOf(['client', 'server', 'admin']).defined();\nexport const serverOrHigherAuthTypeSchema = yupString().oneOf(['server', 'admin']).defined();\nexport const adminAuthTypeSchema = yupString().oneOf(['admin']).defined();\n\n// Projects\nexport const projectIdSchema = yupString().test((v) => v === undefined || v === \"internal\" || isUuid(v)).meta({ openapiField: { description: _idDescription('project'), exampleValue: 'e0b52f4d-dece-408c-af49-d23061bb0f8d' } });\nexport const projectBranchIdSchema = yupString().nonEmpty().max(255).meta({ openapiField: { description: _idDescription('project branch'), exampleValue: 'main' } });\nexport const projectDisplayNameSchema = yupString().meta({ openapiField: { description: _displayNameDescription('project'), exampleValue: 'MyMusic' } });\nexport const projectLogoUrlSchema = urlSchema.max(MAX_IMAGE_SIZE_BASE64_BYTES).meta({ openapiField: { description: 'URL of the logo for the project. This is usually a close to 1:1 image of the company logo.', exampleValue: 'https://example.com/logo.png' } });\nexport const projectFullLogoUrlSchema = urlSchema.max(MAX_IMAGE_SIZE_BASE64_BYTES).meta({ openapiField: { description: 'URL of the full logo for the project. This is usually a vertical image with the logo and the company name.', exampleValue: 'https://example.com/full-logo.png' } });\nexport const projectDescriptionSchema = yupString().nullable().meta({ openapiField: { description: 'A human readable description of the project', exampleValue: 'A music streaming service' } });\nexport const projectCreatedAtMillisSchema = yupNumber().meta({ openapiField: { description: _createdAtMillisDescription('project'), exampleValue: 1630000000000 } });\nexport const projectIsProductionModeSchema = yupBoolean().meta({ openapiField: { description: 'Whether the project is in production mode', exampleValue: true } });\n// Project config\nexport const projectConfigIdSchema = yupString().meta({ openapiField: { description: _idDescription('project config'), exampleValue: 'd09201f0-54f5-40bd-89ff-6d1815ddad24' } });\nexport const projectAllowLocalhostSchema = yupBoolean().meta({ openapiField: { description: 'Whether localhost is allowed as a domain for this project. Should only be allowed in development mode', exampleValue: true } });\nexport const projectCreateTeamOnSignUpSchema = yupBoolean().meta({ openapiField: { description: 'Whether a team should be created for each user that signs up', exampleValue: true } });\nexport const projectMagicLinkEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether magic link authentication is enabled for this project', exampleValue: true } });\nexport const projectPasskeyEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether passkey authentication is enabled for this project', exampleValue: true } });\nexport const projectClientTeamCreationEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether client users can create teams', exampleValue: true } });\nexport const projectClientUserDeletionEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether client users can delete their own account from the client', exampleValue: true } });\nexport const projectSignUpEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether users can sign up new accounts, or whether they are only allowed to sign in to existing accounts. Regardless of this option, the server API can always create new users with the `POST /users` endpoint.', exampleValue: true } });\nexport const projectCredentialEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether email password authentication is enabled for this project', exampleValue: true } });\n// Project OAuth config\nexport const oauthIdSchema = yupString().oneOf(allProviders).meta({ openapiField: { description: `OAuth provider ID, one of ${allProviders.map(x => `\\`${x}\\``).join(', ')}`, exampleValue: 'google' } });\nexport const oauthEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether the OAuth provider is enabled. If an provider is first enabled, then disabled, it will be shown in the list but with enabled=false', exampleValue: true } });\nexport const oauthTypeSchema = yupString().oneOf(['shared', 'standard']).meta({ openapiField: { description: 'OAuth provider type, one of shared, standard. \"shared\" uses Stack shared OAuth keys and it is only meant for development. \"standard\" uses your own OAuth keys and will show your logo and company name when signing in with the provider.', exampleValue: 'standard' } });\nexport const oauthClientIdSchema = yupString().meta({ openapiField: { description: 'OAuth client ID. Needs to be specified when using type=\"standard\"', exampleValue: 'google-oauth-client-id' } });\nexport const oauthClientSecretSchema = yupString().meta({ openapiField: { description: 'OAuth client secret. Needs to be specified when using type=\"standard\"', exampleValue: 'google-oauth-client-secret' } });\nexport const oauthFacebookConfigIdSchema = yupString().meta({ openapiField: { description: 'The configuration id for Facebook business login (for things like ads and marketing). This is only required if you are using the standard OAuth with Facebook and you are using Facebook business login.' } });\nexport const oauthMicrosoftTenantIdSchema = yupString().meta({ openapiField: { description: 'The Microsoft tenant id for Microsoft directory. This is only required if you are using the standard OAuth with Microsoft and you have an Azure AD tenant.' } });\nexport const oauthAccountMergeStrategySchema = yupString().oneOf(['link_method', 'raise_error', 'allow_duplicates']).meta({ openapiField: { description: 'Determines how to handle OAuth logins that match an existing user by email. `link_method` adds the OAuth method to the existing user. `raise_error` rejects the login with an error. `allow_duplicates` creates a new user.', exampleValue: 'link_method' } });\n// Project email config\nexport const emailTypeSchema = yupString().oneOf(['shared', 'standard']).meta({ openapiField: { description: 'Email provider type, one of shared, standard. \"shared\" uses Stack shared email provider and it is only meant for development. \"standard\" uses your own email server and will have your email address as the sender.', exampleValue: 'standard' } });\nexport const emailSenderNameSchema = yupString().meta({ openapiField: { description: 'Email sender name. Needs to be specified when using type=\"standard\"', exampleValue: 'Stack' } });\nexport const emailHostSchema = yupString().meta({ openapiField: { description: 'Email host. Needs to be specified when using type=\"standard\"', exampleValue: 'smtp.your-domain.com' } });\nexport const emailPortSchema = yupNumber().min(0).max(65535).meta({ openapiField: { description: 'Email port. Needs to be specified when using type=\"standard\"', exampleValue: 587 } });\nexport const emailUsernameSchema = yupString().meta({ openapiField: { description: 'Email username. Needs to be specified when using type=\"standard\"', exampleValue: 'smtp-email' } });\nexport const emailSenderEmailSchema = emailSchema.meta({ openapiField: { description: 'Email sender email. Needs to be specified when using type=\"standard\"', exampleValue: 'example@your-domain.com' } });\nexport const emailPasswordSchema = passwordSchema.meta({ openapiField: { description: 'Email password. Needs to be specified when using type=\"standard\"', exampleValue: 'your-email-password' } });\n// Project domain config\nexport const handlerPathSchema = yupString().test('is-handler-path', 'Handler path must start with /', (value) => value?.startsWith('/')).meta({ openapiField: { description: 'Handler path. If you did not setup a custom handler path, it should be \"/handler\" by default. It needs to start with /', exampleValue: '/handler' } });\n// Project email theme config\nexport const emailThemeSchema = yupString().meta({ openapiField: { description: 'Email theme id for the project. Determines the visual style of emails sent by the project.' } });\nexport const emailThemeListSchema = yupRecord(\n yupString().uuid(),\n yupObject({\n displayName: yupString().meta({ openapiField: { description: 'Email theme name', exampleValue: 'Default Light' } }).defined(),\n tsxSource: yupString().meta({ openapiField: { description: 'Email theme source code tsx component' } }).defined(),\n })\n).meta({ openapiField: { description: 'Record of email theme IDs to their display name and source code' } });\nexport const templateThemeIdSchema = yupMixed<string | false>().test((v: any) => v === undefined || v === false || v === null || (typeof v === 'string' && isUuid(v))).meta({ openapiField: { description: 'Email theme id for the template' } }).optional();\nexport const emailTemplateListSchema = yupRecord(\n yupString().uuid(),\n yupObject({\n displayName: yupString().meta({ openapiField: { description: 'Email template name', exampleValue: 'Email Verification' } }).defined(),\n tsxSource: yupString().meta({ openapiField: { description: 'Email template source code tsx component' } }).defined(),\n // themeId can be one of three values:\n // 1. A valid theme id\n // 2. false, which means the template uses no theme\n // 3. undefined/not given, which means the template uses the project's active theme\n themeId: templateThemeIdSchema,\n })\n).meta({ openapiField: { description: 'Record of email template IDs to their display name and source code' } });\n\n// Payments\nexport const customerTypeSchema = yupString().oneOf(['user', 'team', 'custom']);\nconst validateHasAtLeastOneSupportedCurrency = (value: Record<string, unknown>, context: any) => {\n const currencies = Object.keys(value).filter(key => SUPPORTED_CURRENCIES.some(c => c.code === key));\n if (currencies.length === 0) {\n return context.createError({ message: \"At least one currency is required\" });\n }\n return true;\n};\nexport const offerPriceSchema = yupObject({\n ...typedFromEntries(SUPPORTED_CURRENCIES.map(currency => [currency.code, moneyAmountSchema(currency).optional()])),\n interval: dayIntervalSchema.optional(),\n serverOnly: yupBoolean(),\n freeTrial: dayIntervalSchema.optional(),\n}).test(\"at-least-one-currency\", (value, context) => validateHasAtLeastOneSupportedCurrency(value, context));\nexport const priceOrIncludeByDefaultSchema = yupUnion(\n yupString().oneOf(['include-by-default']).meta({ openapiField: { description: 'Makes this item free and includes it by default for all customers.', exampleValue: 'include-by-default' } }),\n yupRecord(\n userSpecifiedIdSchema(\"priceId\"),\n offerPriceSchema,\n ),\n);\nexport const offerSchema = yupObject({\n displayName: yupString(),\n groupId: userSpecifiedIdSchema(\"groupId\").optional().meta({ openapiField: { description: 'The ID of the group this offer belongs to. Within a group, all offers are mutually exclusive unless they are an add-on to another offer in the group.', exampleValue: 'group-id' } }),\n isAddOnTo: yupUnion(\n yupBoolean().isFalse(),\n yupRecord(\n userSpecifiedIdSchema(\"offerId\"),\n yupBoolean().isTrue().defined(),\n ),\n ).optional().meta({ openapiField: { description: 'The offers that this offer is an add-on to. If this is set, the customer must already have one of the offers in the record to be able to purchase this offer.', exampleValue: { \"offer-id\": true } } }),\n customerType: customerTypeSchema.defined(),\n freeTrial: dayIntervalSchema.optional(),\n serverOnly: yupBoolean(),\n stackable: yupBoolean(),\n prices: priceOrIncludeByDefaultSchema.defined(),\n includedItems: yupRecord(\n userSpecifiedIdSchema(\"itemId\"),\n yupObject({\n quantity: yupNumber().defined(),\n repeat: dayIntervalOrNeverSchema.optional(),\n expires: yupString().oneOf(['never', 'when-purchase-expires', 'when-repeated']).optional(),\n }),\n ),\n});\nexport const inlineOfferSchema = yupObject({\n display_name: yupString().defined(),\n customer_type: customerTypeSchema.defined(),\n free_trial: dayIntervalSchema.optional(),\n server_only: yupBoolean().oneOf([true]).default(true),\n prices: yupRecord(\n userSpecifiedIdSchema(\"priceId\"),\n yupObject({\n ...typedFromEntries(SUPPORTED_CURRENCIES.map(currency => [currency.code, moneyAmountSchema(currency).optional()])),\n interval: dayIntervalSchema.optional(),\n free_trial: dayIntervalSchema.optional(),\n }).test(\"at-least-one-currency\", (value, context) => validateHasAtLeastOneSupportedCurrency(value, context)),\n ),\n included_items: yupRecord(\n userSpecifiedIdSchema(\"itemId\"),\n yupObject({\n quantity: yupNumber(),\n repeat: dayIntervalOrNeverSchema.optional(),\n expires: yupString().oneOf(['never', 'when-purchase-expires', 'when-repeated']).optional(),\n }),\n ),\n});\n\n// Users\nexport class ReplaceFieldWithOwnUserId extends Error {\n constructor(public readonly path: string) {\n super(`This error should be caught by whoever validated the schema, and the field in the path '${path}' should be replaced with the current user's id. This is a workaround to yup not providing access to the context inside the transform function.`);\n }\n}\nconst userIdMeSentinelUuid = \"cad564fd-f81b-43f4-b390-98abf3fcc17e\";\nexport const userIdOrMeSchema = yupString().uuid().transform(v => {\n if (v === \"me\") return userIdMeSentinelUuid;\n else return v;\n}).test((v, context) => {\n if (!(\"stackAllowUserIdMe\" in (context.options.context ?? {}))) throw new StackAssertionError('userIdOrMeSchema is not allowed in this context. Make sure you\\'re using yupValidate from schema-fields.ts to validate, instead of schema.validate(...).');\n if (!context.options.context?.stackAllowUserIdMe) throw new StackAssertionError('userIdOrMeSchema is not allowed in this context. Make sure you\\'re passing in the currentUserId option in yupValidate.');\n if (v === userIdMeSentinelUuid) throw new ReplaceFieldWithOwnUserId(context.path);\n return true;\n}).meta({ openapiField: { description: 'The ID of the user, or the special value `me` for the currently authenticated user', exampleValue: '3241a285-8329-4d69-8f3d-316e08cf140c' } });\nexport const userIdSchema = yupString().uuid().meta({ openapiField: { description: _idDescription('user'), exampleValue: '3241a285-8329-4d69-8f3d-316e08cf140c' } });\nexport const primaryEmailSchema = emailSchema.meta({ openapiField: { description: 'Primary email', exampleValue: 'johndoe@example.com' } });\nexport const primaryEmailAuthEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether the primary email is used for authentication. If this is set to `false`, the user will not be able to sign in with the primary email with password or OTP', exampleValue: true } });\nexport const primaryEmailVerifiedSchema = yupBoolean().meta({ openapiField: { description: 'Whether the primary email has been verified to belong to this user', exampleValue: true } });\nexport const userDisplayNameSchema = yupString().nullable().meta({ openapiField: { description: _displayNameDescription('user'), exampleValue: 'John Doe' } });\nexport const selectedTeamIdSchema = yupString().uuid().meta({ openapiField: { description: 'ID of the team currently selected by the user', exampleValue: 'team-id' } });\nexport const profileImageUrlSchema = urlSchema.max(MAX_IMAGE_SIZE_BASE64_BYTES).meta({ openapiField: { description: _profileImageUrlDescription('user'), exampleValue: 'https://example.com/image.jpg' } });\nexport const signedUpAtMillisSchema = yupNumber().meta({ openapiField: { description: _signedUpAtMillisDescription, exampleValue: 1630000000000 } });\nexport const userClientMetadataSchema = jsonSchema.meta({ openapiField: { description: _clientMetaDataDescription('user'), exampleValue: { key: 'value' } } });\nexport const userClientReadOnlyMetadataSchema = jsonSchema.meta({ openapiField: { description: _clientReadOnlyMetaDataDescription('user'), exampleValue: { key: 'value' } } });\nexport const userServerMetadataSchema = jsonSchema.meta({ openapiField: { description: _serverMetaDataDescription('user'), exampleValue: { key: 'value' } } });\nexport const userOAuthProviderSchema = yupObject({\n id: yupString().defined(),\n type: yupString().oneOf(allProviders).defined(),\n provider_user_id: yupString().defined(),\n});\nexport const userLastActiveAtMillisSchema = yupNumber().nullable().meta({ openapiField: { description: _lastActiveAtMillisDescription, exampleValue: 1630000000000 } });\nexport const userPasskeyAuthEnabledSchema = yupBoolean().meta({ openapiField: { hidden: true, description: 'Whether the user has passkeys enabled', exampleValue: false } });\nexport const userOtpAuthEnabledSchema = yupBoolean().meta({ openapiField: { hidden: true, description: 'Whether the user has OTP/magic link enabled. ', exampleValue: true } });\nexport const userOtpAuthEnabledMutationSchema = yupBoolean().meta({ openapiField: { hidden: true, description: 'Whether the user has OTP/magic link enabled. Note that only accounts with verified emails can sign-in with OTP.', exampleValue: true } });\nexport const userHasPasswordSchema = yupBoolean().meta({ openapiField: { hidden: true, description: 'Whether the user has a password set. If the user does not have a password set, they will not be able to sign in with email/password.', exampleValue: true } });\nexport const userPasswordMutationSchema = passwordSchema.nullable().meta({ openapiField: { description: 'Sets the user\\'s password. Doing so revokes all current sessions.', exampleValue: 'my-new-password' } }).max(70);\nexport const userPasswordHashMutationSchema = yupString()\n .nonEmpty()\n .meta({ openapiField: { description: 'If `password` is not given, sets the user\\'s password hash to the given string in Modular Crypt Format (ex.: `$2a$10$VIhIOofSMqGdGlL4wzE//e.77dAQGqNtF/1dT7bqCrVtQuInWy2qi`). Doing so revokes all current sessions.' } }); // we don't set an exampleValue here because it's exclusive with the password field and having both would break the generated example\nexport const userTotpSecretMutationSchema = base64Schema.nullable().meta({ openapiField: { description: 'Enables 2FA and sets a TOTP secret for the user. Set to null to disable 2FA.', exampleValue: 'dG90cC1zZWNyZXQ=' } });\n\n// Auth\nexport const signInEmailSchema = strictEmailSchema(undefined).meta({ openapiField: { description: 'The email to sign in with.', exampleValue: 'johndoe@example.com' } });\nexport const emailOtpSignInCallbackUrlSchema = urlSchema.meta({ openapiField: { description: 'The base callback URL to construct the magic link from. A query parameter `code` with the verification code will be appended to it. The page should then make a request to the `/auth/otp/sign-in` endpoint.', exampleValue: 'https://example.com/handler/magic-link-callback' } });\nexport const emailVerificationCallbackUrlSchema = urlSchema.meta({ openapiField: { description: 'The base callback URL to construct a verification link for the verification e-mail. A query parameter `code` with the verification code will be appended to it. The page should then make a request to the `/contact-channels/verify` endpoint.', exampleValue: 'https://example.com/handler/email-verification' } });\nexport const accessTokenResponseSchema = yupString().meta({ openapiField: { description: 'Short-lived access token that can be used to authenticate the user', exampleValue: 'eyJhmMiJB2TO...diI4QT' } });\nexport const refreshTokenResponseSchema = yupString().meta({ openapiField: { description: 'Long-lived refresh token that can be used to obtain a new access token', exampleValue: 'i8ns3aq2...14y' } });\nexport const signInResponseSchema = yupObject({\n refresh_token: refreshTokenResponseSchema.defined(),\n access_token: accessTokenResponseSchema.defined(),\n is_new_user: yupBoolean().meta({ openapiField: { description: 'Whether the user is a new user', exampleValue: true } }).defined(),\n user_id: userIdSchema.defined(),\n});\n\n// Permissions\nexport const teamSystemPermissions = [\n '$update_team',\n '$delete_team',\n '$read_members',\n '$remove_members',\n '$invite_members',\n '$manage_api_keys',\n] as const;\nexport const permissionDefinitionIdSchema = yupString()\n .matches(/^\\$?[a-z0-9_:]+$/, 'Only lowercase letters, numbers, \":\", \"_\" and optional \"$\" at the beginning are allowed')\n .test('is-system-permission', 'System permissions must start with a dollar sign', (value, ctx) => {\n if (!value) return true;\n if (value.startsWith('$') && !teamSystemPermissions.includes(value as any)) {\n return ctx.createError({ message: 'Invalid system permission' });\n }\n return true;\n })\n .meta({ openapiField: { description: `The permission ID used to uniquely identify a permission. Can either be a custom permission with lowercase letters, numbers, \\`:\\`, and \\`_\\` characters, or one of the system permissions: ${teamSystemPermissions.map(x => `\\`${x}\\``).join(', ')}`, exampleValue: 'read_secret_info' } });\nexport const customPermissionDefinitionIdSchema = yupString()\n .matches(/^[a-z0-9_:]+$/, 'Only lowercase letters, numbers, \":\", \"_\" are allowed')\n .meta({ openapiField: { description: 'The permission ID used to uniquely identify a permission. Can only contain lowercase letters, numbers, \":\", and \"_\" characters', exampleValue: 'read_secret_info' } });\nexport const teamPermissionDescriptionSchema = yupString().meta({ openapiField: { description: 'A human-readable description of the permission', exampleValue: 'Read secret information' } });\nexport const containedPermissionIdsSchema = yupArray(permissionDefinitionIdSchema.defined()).meta({ openapiField: { description: 'The IDs of the permissions that are contained in this permission', exampleValue: ['read_public_info'] } });\n\n// Teams\nexport const teamIdSchema = yupString().uuid().meta({ openapiField: { description: _idDescription('team'), exampleValue: 'ad962777-8244-496a-b6a2-e0c6a449c79e' } });\nexport const teamDisplayNameSchema = yupString().meta({ openapiField: { description: _displayNameDescription('team'), exampleValue: 'My Team' } });\nexport const teamProfileImageUrlSchema = urlSchema.max(1000000).meta({ openapiField: { description: _profileImageUrlDescription('team'), exampleValue: 'https://example.com/image.jpg' } });\nexport const teamClientMetadataSchema = jsonSchema.meta({ openapiField: { description: _clientMetaDataDescription('team'), exampleValue: { key: 'value' } } });\nexport const teamClientReadOnlyMetadataSchema = jsonSchema.meta({ openapiField: { description: _clientReadOnlyMetaDataDescription('team'), exampleValue: { key: 'value' } } });\nexport const teamServerMetadataSchema = jsonSchema.meta({ openapiField: { description: _serverMetaDataDescription('team'), exampleValue: { key: 'value' } } });\nexport const teamCreatedAtMillisSchema = yupNumber().meta({ openapiField: { description: _createdAtMillisDescription('team'), exampleValue: 1630000000000 } });\nexport const teamInvitationEmailSchema = emailSchema.meta({ openapiField: { description: 'The email of the user to invite.', exampleValue: 'johndoe@example.com' } });\nexport const teamInvitationCallbackUrlSchema = urlSchema.meta({ openapiField: { description: 'The base callback URL to construct an invite link with. A query parameter `code` with the verification code will be appended to it. The page should then make a request to the `/team-invitations/accept` endpoint.', exampleValue: 'https://example.com/handler/team-invitation' } });\nexport const teamCreatorUserIdSchema = userIdOrMeSchema.meta({ openapiField: { description: 'The ID of the creator of the team. If not specified, the user will not be added to the team. Can be either \"me\" or the ID of the user. Only used on the client side.', exampleValue: 'me' } });\n\n// Team member profiles\nexport const teamMemberDisplayNameSchema = yupString().meta({ openapiField: { description: _displayNameDescription('team member') + ' Note that this is separate from the display_name of the user.', exampleValue: 'John Doe' } });\nexport const teamMemberProfileImageUrlSchema = urlSchema.max(1000000).meta({ openapiField: { description: _profileImageUrlDescription('team member'), exampleValue: 'https://example.com/image.jpg' } });\n\n// Contact channels\nexport const contactChannelIdSchema = yupString().uuid().meta({ openapiField: { description: _idDescription('contact channel'), exampleValue: 'b3d396b8-c574-4c80-97b3-50031675ceb2' } });\nexport const contactChannelTypeSchema = yupString().oneOf(['email']).meta({ openapiField: { description: `The type of the contact channel. Currently only \"email\" is supported.`, exampleValue: 'email' } });\nexport const contactChannelValueSchema = yupString().when('type', {\n is: 'email',\n then: (schema) => schema.email(),\n}).meta({ openapiField: { description: 'The value of the contact channel. For email, this should be a valid email address.', exampleValue: 'johndoe@example.com' } });\nexport const contactChannelUsedForAuthSchema = yupBoolean().meta({ openapiField: { description: 'Whether the contact channel is used for authentication. If this is set to `true`, the user will be able to sign in with the contact channel with password or OTP.', exampleValue: true } });\nexport const contactChannelIsVerifiedSchema = yupBoolean().meta({ openapiField: { description: 'Whether the contact channel has been verified. If this is set to `true`, the contact channel has been verified to belong to the user.', exampleValue: true } });\nexport const contactChannelIsPrimarySchema = yupBoolean().meta({ openapiField: { description: 'Whether the contact channel is the primary contact channel. If this is set to `true`, it will be used for authentication and notifications by default.', exampleValue: true } });\n\n// OAuth providers\nexport const oauthProviderIdSchema = yupString().uuid().meta({ openapiField: { description: _idDescription('OAuth provider'), exampleValue: 'b3d396b8-c574-4c80-97b3-50031675ceb2' } });\nexport const oauthProviderEmailSchema = emailSchema.meta({ openapiField: { description: 'Email of the OAuth provider. This is used to display and identify the OAuth provider in the UI.', exampleValue: 'test@gmail.com' } });\nexport const oauthProviderTypeSchema = yupString().oneOf(allProviders).meta({ openapiField: { description: `OAuth provider type, one of ${allProviders.map(x => `\\`${x}\\``).join(', ')}`, exampleValue: 'google' } });\nexport const oauthProviderAllowSignInSchema = yupBoolean().meta({ openapiField: { description: 'Whether the user can use this OAuth provider to sign in. Only one OAuth provider per type can have this set to `true`.', exampleValue: true } });\nexport const oauthProviderAllowConnectedAccountsSchema = yupBoolean().meta({ openapiField: { description: 'Whether the user can use this OAuth provider as connected account. Multiple OAuth providers per type can have this set to `true`.', exampleValue: true } });\nexport const oauthProviderAccountIdSchema = yupString().meta({ openapiField: { description: 'Account ID of the OAuth provider. This uniquely identifies the account on the provider side.', exampleValue: 'google-account-id-12345' } });\n\n// Headers\nexport const basicAuthorizationHeaderSchema = yupString().test('is-basic-authorization-header', 'Authorization header must be in the format \"Basic <base64>\"', (value) => {\n if (!value) return true;\n return decodeBasicAuthorizationHeader(value) !== null;\n});\n\n// Neon integration\nexport const neonAuthorizationHeaderSchema = basicAuthorizationHeaderSchema.test('is-authorization-header', 'Invalid client_id:client_secret values; did you use the correct values for the integration?', (value) => {\n if (!value) return true;\n const [clientId, clientSecret] = decodeBasicAuthorizationHeader(value) ?? throwErr(`Authz header invalid? This should've been validated by basicAuthorizationHeaderSchema: ${value}`);\n for (const neonClientConfig of JSON.parse(process.env.STACK_INTEGRATION_CLIENTS_CONFIG || '[]')) {\n if (clientId === neonClientConfig.client_id && clientSecret === neonClientConfig.client_secret) return true;\n }\n return false;\n});\n\n// Utils\nexport function yupDefinedWhen<S extends yup.AnyObject>(\n schema: S,\n triggers: Record<string, any>,\n): S {\n const entries = Object.entries(triggers);\n return schema.when(entries.map(([key]) => key), {\n is: (...values: any[]) => entries.every(([key, value], index) => value === values[index]),\n then: (schema: S) => schema.defined(),\n otherwise: (schema: S) => schema.optional()\n });\n}\n\nexport function yupDefinedAndNonEmptyWhen<S extends yup.StringSchema>(\n schema: S,\n triggers: Record<string, any>,\n): S {\n const entries = Object.entries(triggers);\n return schema.when(entries.map(([key]) => key), {\n is: (...values: any[]) => entries.every(([key, value], index) => value === values[index]),\n then: (schema: S) => schema.defined().nonEmpty(),\n otherwise: (schema: S) => schema.optional()\n });\n}\n"],"mappings":";AAAA,YAAY,SAAS;AACrB,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AACzB,SAA0C,4BAA4B;AAEtE,SAAS,qBAAqB,gBAAgB;AAC9C,SAAS,sCAAsC;AAC/C,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB,MAAM,wBAAwB;AACvD,SAAS,gBAAgB;AACzB,SAAS,8BAA8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K,KAAK,GAAG,UAAU,UAAU,OAAO,KAAK,CAAC;AAAA,IACxF,MAAM,CAACA,YAAcA,QAAO,QAAQ,EAAE,SAAS;AAAA,IAC/C,WAAW,CAACA,YAAcA,QAAO,SAAS;AAAA,EAC5C,CAAC;AACH;","names":["object","schema"]}
1
+ {"version":3,"sources":["../../src/schema-fields.ts"],"sourcesContent":["import * as yup from \"yup\";\nimport { KnownErrors } from \".\";\nimport { isBase64 } from \"./utils/bytes\";\nimport { SUPPORTED_CURRENCIES, type Currency, type MoneyAmount } from \"./utils/currency-constants\";\nimport { DayInterval, Interval } from \"./utils/dates\";\nimport { StackAssertionError, throwErr } from \"./utils/errors\";\nimport { decodeBasicAuthorizationHeader } from \"./utils/http\";\nimport { allProviders } from \"./utils/oauth\";\nimport { deepPlainClone, omit, typedFromEntries } from \"./utils/objects\";\nimport { deindent } from \"./utils/strings\";\nimport { isValidHostnameWithWildcards, isValidUrl } from \"./utils/urls\";\nimport { isUuid } from \"./utils/uuids\";\n\nconst MAX_IMAGE_SIZE_BASE64_BYTES = 1_000_000; // 1MB\n\ndeclare module \"yup\" {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface StringSchema<TType, TContext, TDefault, TFlags> {\n nonEmpty(message?: string): StringSchema<TType, TContext, TDefault, TFlags>,\n empty(): StringSchema<TType, TContext, TDefault, TFlags>,\n }\n\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Schema<TType, TContext, TDefault, TFlags> {\n hasNested<K extends keyof NonNullable<TType>>(path: K): boolean,\n getNested<K extends keyof NonNullable<TType>>(path: K): yup.Schema<NonNullable<TType>[K], TContext, TDefault, TFlags>,\n\n // the default types for concat kinda suck, so let's fix that\n concat<U extends yup.AnySchema>(schema: U): yup.Schema<Omit<NonNullable<TType>, keyof yup.InferType<U>> & yup.InferType<U> | (TType & (null | undefined)), TContext, Omit<NonNullable<TDefault>, keyof U['__default']> & U['__default'] | (TDefault & (null | undefined)), TFlags>,\n }\n\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n export interface CustomSchemaMetadata {\n stackSchemaInfo?:\n | {\n type: \"object\" | \"array\" | \"string\" | \"number\" | \"boolean\" | \"date\" | \"mixed\" | \"never\",\n }\n | {\n type: \"tuple\",\n items: yup.AnySchema[],\n }\n | {\n type: \"union\",\n items: yup.AnySchema[],\n }\n | {\n type: \"record\",\n keySchema: yup.StringSchema<any>,\n valueSchema: yup.AnySchema,\n },\n }\n}\n\n// eslint-disable-next-line no-restricted-syntax\nyup.addMethod(yup.string, \"nonEmpty\", function (message?: string) {\n return this.test(\n \"non-empty\",\n message ?? (({ path }) => `${path} must not be empty`),\n (value) => {\n return value !== \"\";\n }\n );\n});\n\nyup.addMethod(yup.Schema, \"hasNested\", function (path: any) {\n if (!path.match(/^[a-zA-Z0-9_$:-]+$/)) throw new StackAssertionError(`yupSchema.hasNested can currently only be used with alphanumeric keys, underscores, dollar signs, colons, and hyphens. Fix this in the future. Provided key: ${JSON.stringify(path)}`);\n const schemaInfo = this.meta()?.stackSchemaInfo as any;\n if (schemaInfo?.type === \"record\") {\n return schemaInfo.keySchema.isValidSync(path);\n } else if (schemaInfo?.type === \"union\") {\n return schemaInfo.items.some((s: any) => s.hasNested(path));\n } else {\n try {\n yup.reach(this, path);\n return true as any;\n } catch (e) {\n if (e instanceof Error && e.message.includes(\"The schema does not contain the path\")) {\n return false as any;\n }\n throw e;\n }\n }\n});\n\nyup.addMethod(yup.Schema, \"getNested\", function (path: any) {\n if (!path.match(/^[a-zA-Z0-9_$:-]+$/)) throw new StackAssertionError(`yupSchema.getNested can currently only be used with alphanumeric keys, underscores, dollar signs, colons, and hyphens. Fix this in the future. Provided key: ${path}`);\n\n if (!this.hasNested(path as never)) throw new StackAssertionError(`Tried to call yupSchema.getNested, but key is not present in the schema. Provided key: ${path}`, { path, schema: this });\n\n const schemaInfo = this.meta()?.stackSchemaInfo;\n if (schemaInfo?.type === \"record\") {\n return schemaInfo.valueSchema;\n } else if (schemaInfo?.type === \"union\") {\n const schemasWithNested = schemaInfo.items.filter((s: any) => s.hasNested(path));\n return yupUnion(...schemasWithNested.map(s => s.getNested(path)));\n } else {\n return yup.reach(this, path) as any;\n }\n});\n\nundefined?.test(\"hasNested\", ({ expect }) => {\n expect(yupObject({ a: yupString() }).hasNested(\"a\")).toBe(true);\n expect(yupObject({}).hasNested(\"a\" as never)).toBe(false);\n expect(yupRecord(yupString(), yupString()).hasNested(\"a\")).toBe(true);\n expect(yupRecord(yupString().oneOf([\"a\"]), yupString()).hasNested(\"b\")).toBe(false);\n expect(yupUnion(yupString(), yupNumber()).hasNested(\"a\" as any)).toBe(false);\n expect(yupUnion(yupString(), yupObject({ b: yupNumber() })).hasNested(\"a\" as never)).toBe(false);\n expect(yupUnion(yupString(), yupObject({ a: yupNumber() })).hasNested(\"a\" as never)).toBe(true);\n});\nundefined?.test(\"getNested\", ({ expect }) => {\n expect(yupObject({ a: yupNumber() }).getNested(\"a\").describe().type).toEqual(\"number\");\n expect(() => yupObject({}).getNested(\"a\" as never)).toThrow();\n expect(() => yupObject({ a: yupObject({ b: yupString() }) }).getNested(\"a.b\" as never)).toThrow();\n expect(yupRecord(yupString().oneOf([\"a\"]), yupNumber()).getNested(\"a\").describe().type).toEqual(\"number\");\n expect(() => yupRecord(yupString().oneOf([\"a\"]), yupString()).getNested(\"b\" as never)).toThrow();\n expect(yupUnion(yupString(), yupObject({ a: yupNumber() })).getNested(\"a\" as never).describe().type).toEqual(\"mixed\");\n expect(yupUnion(yupObject({ a: yupString() }), yupObject({ a: yupNumber() })).getNested(\"a\").describe().type).toEqual(\"mixed\");\n});\n\nexport async function yupValidate<S extends yup.ISchema<any>>(\n schema: S,\n obj: unknown,\n options?: yup.ValidateOptions & { currentUserId?: string | null }\n): Promise<yup.InferType<S>> {\n try {\n return await schema.validate(obj, {\n ...omit(options ?? {}, ['currentUserId']),\n context: {\n ...options?.context,\n stackAllowUserIdMe: options?.currentUserId !== undefined,\n },\n });\n } catch (error) {\n if (error instanceof ReplaceFieldWithOwnUserId) {\n const currentUserId = options?.currentUserId;\n if (!currentUserId) throw new KnownErrors.CannotGetOwnUserWithoutUser();\n\n // parse yup path\n let pathRemaining = error.path;\n const fieldPath = [];\n while (pathRemaining.length > 0) {\n if (pathRemaining.startsWith(\"[\")) {\n const index = pathRemaining.indexOf(\"]\");\n if (index < 0) throw new StackAssertionError(\"Invalid path\");\n fieldPath.push(JSON.parse(pathRemaining.slice(1, index)));\n pathRemaining = pathRemaining.slice(index + 1);\n } else {\n let dotIndex = pathRemaining.indexOf(\".\");\n if (dotIndex === -1) dotIndex = pathRemaining.length;\n fieldPath.push(pathRemaining.slice(0, dotIndex));\n pathRemaining = pathRemaining.slice(dotIndex + 1);\n }\n }\n\n const newObj = deepPlainClone(obj);\n let it = newObj;\n for (const field of fieldPath.slice(0, -1)) {\n if (!Object.prototype.hasOwnProperty.call(it, field)) {\n throw new StackAssertionError(`Segment ${field} of path ${error.path} not found in object`);\n }\n it = (it as any)[field];\n }\n (it as any)[fieldPath[fieldPath.length - 1]] = currentUserId;\n\n return await yupValidate(schema, newObj, options);\n }\n throw error;\n }\n}\n\nconst _idDescription = (identify: string) => `The unique identifier of the ${identify}`;\nconst _displayNameDescription = (identify: string) => `Human-readable ${identify} display name. This is not a unique identifier.`;\nconst _clientMetaDataDescription = (identify: string) => `Client metadata. Used as a data store, accessible from the client side. Do not store information that should not be exposed to the client.`;\nconst _clientReadOnlyMetaDataDescription = (identify: string) => `Client read-only, server-writable metadata. Used as a data store, accessible from the client side. Do not store information that should not be exposed to the client. The client can read this data, but cannot modify it. This is useful for things like subscription status.`;\nconst _profileImageUrlDescription = (identify: string) => `URL of the profile image for ${identify}. Can be a Base64 encoded image. Must be smaller than 100KB. Please compress and crop to a square before passing in.`;\nconst _serverMetaDataDescription = (identify: string) => `Server metadata. Used as a data store, only accessible from the server side. You can store secret information related to the ${identify} here.`;\nconst _atMillisDescription = (identify: string) => `(the number of milliseconds since epoch, January 1, 1970, UTC)`;\nconst _createdAtMillisDescription = (identify: string) => `The time the ${identify} was created ${_atMillisDescription(identify)}`;\nconst _signedUpAtMillisDescription = `The time the user signed up ${_atMillisDescription}`;\nconst _lastActiveAtMillisDescription = `The time the user was last active ${_atMillisDescription}`;\n\n\ndeclare const StackAdaptSentinel: unique symbol;\nexport type StackAdaptSentinel = typeof StackAdaptSentinel;\n\n// Built-in replacements\nexport function yupString<A extends string, B extends yup.Maybe<yup.AnyObject> = yup.AnyObject>(...args: Parameters<typeof yup.string<A, B>>) {\n // eslint-disable-next-line no-restricted-syntax\n return yup.string(...args).meta({ stackSchemaInfo: { type: \"string\" } });\n}\nexport function yupNumber<A extends number, B extends yup.Maybe<yup.AnyObject> = yup.AnyObject>(...args: Parameters<typeof yup.number<A, B>>) {\n // eslint-disable-next-line no-restricted-syntax\n return yup.number(...args).meta({ stackSchemaInfo: { type: \"number\" } });\n}\nexport function yupBoolean<A extends boolean, B extends yup.Maybe<yup.AnyObject> = yup.AnyObject>(...args: Parameters<typeof yup.boolean<A, B>>) {\n // eslint-disable-next-line no-restricted-syntax\n return yup.boolean(...args).meta({ stackSchemaInfo: { type: \"boolean\" } });\n}\n/**\n * @deprecated, use number of milliseconds since epoch instead\n */\nexport function yupDate<A extends Date, B extends yup.Maybe<yup.AnyObject> = yup.AnyObject>(...args: Parameters<typeof yup.date<A, B>>) {\n // eslint-disable-next-line no-restricted-syntax\n return yup.date(...args).meta({ stackSchemaInfo: { type: \"date\" } });\n}\nfunction _yupMixedInternal<A extends {}>(...args: Parameters<typeof yup.mixed<A>>) {\n // eslint-disable-next-line no-restricted-syntax\n return yup.mixed(...args);\n}\nexport function yupMixed<A extends {}>(...args: Parameters<typeof yup.mixed<A>>) {\n return _yupMixedInternal(...args).meta({ stackSchemaInfo: { type: \"mixed\" } });\n}\nexport function yupArray<A extends yup.Maybe<yup.AnyObject> = yup.AnyObject, B = any>(...args: Parameters<typeof yup.array<A, B>>) {\n // eslint-disable-next-line no-restricted-syntax\n return yup.array(...args).meta({ stackSchemaInfo: { type: \"array\" } });\n}\nexport function yupTuple<T extends [unknown, ...unknown[]]>(schemas: { [K in keyof T]: yup.Schema<T[K]> }) {\n if (schemas.length === 0) throw new Error('yupTuple must have at least one schema');\n // eslint-disable-next-line no-restricted-syntax\n return yup.tuple<T>(schemas as any).meta({ stackSchemaInfo: { type: \"tuple\", items: schemas } });\n}\nexport function yupObjectWithAutoDefault<A extends yup.Maybe<yup.AnyObject>, B extends yup.ObjectShape>(...args: Parameters<typeof yup.object<A, B>>) {\n // eslint-disable-next-line no-restricted-syntax\n const object = yup.object(...args).test(\n 'no-unknown-object-properties',\n ({ path }) => `${path} contains unknown properties`,\n (value: any, context) => {\n if (context.options.context?.noUnknownPathPrefixes?.some((prefix: string) => context.path.startsWith(prefix))) {\n if (context.schema.spec.noUnknown !== false) {\n const availableKeys = new Set(Object.keys(context.schema.fields));\n const unknownKeys = Object.keys(value ?? {}).filter(key => !availableKeys.has(key));\n if (unknownKeys.length > 0) {\n // TODO \"did you mean XYZ\"\n return context.createError({\n message: `${context.path || \"Object\"} contains unknown properties: ${unknownKeys.join(', ')}`,\n path: context.path,\n params: { unknownKeys, availableKeys },\n });\n }\n }\n }\n return true;\n },\n ).meta({ stackSchemaInfo: { type: \"object\" } });\n return object;\n}\nexport function yupObject<A extends yup.Maybe<yup.AnyObject>, B extends yup.ObjectShape>(...args: Parameters<typeof yup.object<A, B>>) {\n // we don't want to update the type of `object` to have a default flag\n const object = yupObjectWithAutoDefault(...args);\n return object.default(undefined) as any as typeof object;\n}\n\nexport function yupNever(): yup.MixedSchema<never> {\n return _yupMixedInternal().meta({ stackSchemaInfo: { type: \"never\" } }).test('never', 'This value should never be reached', () => false) as any;\n}\n\nexport function yupUnion<T extends yup.AnySchema[]>(...args: T): yup.MixedSchema<yup.InferType<T[number]>> {\n if (args.length === 0) throw new Error('yupUnion must have at least one schema');\n\n return _yupMixedInternal().meta({ stackSchemaInfo: { type: \"union\", items: args } }).test('is-one-of', 'Invalid value', async (value, context) => {\n if (value == null) return true;\n const errors = [];\n for (const schema of args) {\n try {\n await yupValidate(schema, value, context.options);\n return true;\n } catch (e) {\n errors.push(e);\n }\n }\n return context.createError({\n message: deindent`\n ${context.path} is not matched by any of the provided schemas:\n ${errors.map((e: any, i) => deindent`\n Schema ${i}:\n ${e.errors.join('\\n')}\n `).join('\\n')}`,\n path: context.path,\n });\n });\n}\n\nexport function yupRecord<K extends yup.StringSchema, T extends yup.AnySchema>(\n keySchema: K,\n valueSchema: T,\n): yup.MixedSchema<Record<yup.InferType<K> & string, yup.InferType<T>>> {\n return yupObject().meta({ stackSchemaInfo: { type: \"record\", keySchema, valueSchema } }).unknown(true).test(\n 'record',\n '${path} must be a record of valid values',\n async function (value: unknown, context: yup.TestContext) {\n if (value == null) return true;\n const { path, createError } = this as any;\n if (typeof value !== 'object') {\n return createError({ message: `${path} must be an object` });\n }\n\n // Validate each property using the provided valueSchema\n for (const key of Object.keys(value)) {\n // Validate the key\n await yupValidate(keySchema, key, context.options);\n\n // Validate the value\n try {\n await yupValidate(valueSchema, (value as Record<string, unknown>)[key], {\n ...context.options,\n context: {\n ...context.options.context,\n path: path ? `${path}.${key}` : key,\n },\n });\n } catch (e: any) {\n return createError({\n path: path ? `${path}.${key}` : key,\n message: e.message,\n });\n }\n }\n\n return true;\n },\n ) as any;\n}\n\nexport function ensureObjectSchema<T extends yup.AnyObject>(schema: yup.Schema<T>): yup.ObjectSchema<T> & typeof schema {\n if (!(schema instanceof yup.ObjectSchema)) throw new StackAssertionError(`assertObjectSchema: schema is not an ObjectSchema: ${schema.describe().type}`);\n return schema as any;\n}\n\n// Common\nexport const adaptSchema = yupMixed<StackAdaptSentinel>();\n/**\n * Yup's URL schema does not recognize some URLs (including `http://localhost`) as a valid URL. This schema is a workaround for that.\n */\nexport const urlSchema = yupString().test({\n name: 'no-spaces',\n message: (params) => `${params.path} contains spaces`,\n test: (value) => value == null || !value.includes(' ')\n}).test({\n name: 'url',\n message: (params) => `${params.path} is not a valid URL`,\n test: (value) => value == null || isValidUrl(value)\n});\n/**\n * URL schema that supports wildcard patterns in hostnames (e.g., \"https://*.example.com\", \"http://*:8080\")\n */\nexport const wildcardUrlSchema = yupString().test({\n name: 'no-spaces',\n message: (params) => `${params.path} contains spaces`,\n test: (value) => value == null || !value.includes(' ')\n}).test({\n name: 'wildcard-url',\n message: (params) => `${params.path} is not a valid URL or wildcard URL pattern`,\n test: (value) => {\n if (value == null) return true;\n\n // If it doesn't contain wildcards, use the regular URL validation\n if (!value.includes('*')) {\n return isValidUrl(value);\n }\n\n // For wildcard URLs, validate the structure by replacing wildcards with placeholders\n try {\n const PLACEHOLDER = 'wildcard-placeholder';\n // Replace wildcards with valid placeholders for URL parsing\n const normalizedUrl = value.replace(/\\*/g, PLACEHOLDER);\n const url = new URL(normalizedUrl);\n\n // Only allow wildcards in the hostname; reject anywhere else\n if (\n url.username.includes(PLACEHOLDER) ||\n url.password.includes(PLACEHOLDER) ||\n url.pathname.includes(PLACEHOLDER) ||\n url.search.includes(PLACEHOLDER) ||\n url.hash.includes(PLACEHOLDER)\n ) {\n return false;\n }\n\n // Only http/https are acceptable\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n return false;\n }\n\n // Extract original hostname pattern from the input\n const hostPattern = url.hostname.split(PLACEHOLDER).join('*');\n\n // Validate the wildcard hostname pattern using the existing function\n return isValidHostnameWithWildcards(hostPattern);\n } catch (e) {\n return false;\n }\n }\n});\nexport const jsonSchema = yupMixed().nullable().defined().transform((value) => JSON.parse(JSON.stringify(value)));\nexport const jsonStringSchema = yupString().test(\"json\", (params) => `${params.path} is not valid JSON`, (value) => {\n if (value == null) return true;\n try {\n JSON.parse(value);\n return true;\n } catch (error) {\n return false;\n }\n});\nexport const jsonStringOrEmptySchema = yupString().test(\"json\", (params) => `${params.path} is not valid JSON`, (value) => {\n if (!value) return true;\n try {\n JSON.parse(value);\n return true;\n } catch (error) {\n return false;\n }\n});\nexport const base64Schema = yupString().test(\"is-base64\", (params) => `${params.path} is not valid base64`, (value) => {\n if (value == null) return true;\n return isBase64(value);\n});\nexport const passwordSchema = yupString().max(70);\nexport const intervalSchema = yupTuple<Interval>([yupNumber().min(0).integer().defined(), yupString().oneOf(['millisecond', 'second', 'minute', 'hour', 'day', 'week', 'month', 'year']).defined()]);\nexport const dayIntervalSchema = yupTuple<DayInterval>([yupNumber().min(0).integer().defined(), yupString().oneOf(['day', 'week', 'month', 'year']).defined()]);\nexport const intervalOrNeverSchema = yupUnion(intervalSchema.defined(), yupString().oneOf(['never']).defined());\nexport const dayIntervalOrNeverSchema = yupUnion(dayIntervalSchema.defined(), yupString().oneOf(['never']).defined());\n/**\n * This schema is useful for fields where the user can specify the ID, such as price IDs. It is particularly common\n * for IDs in the config schema.\n */\nexport const userSpecifiedIdSchema = (idName: `${string}Id`) => yupString().max(63).matches(/^[a-zA-Z_][a-zA-Z0-9_-]*$/, `${idName} must start with a letter, underscore, or number, and contain only letters, numbers, underscores, and hyphens`);\nexport const moneyAmountSchema = (currency: Currency) => yupString<MoneyAmount>().test('money-amount', 'Invalid money amount', (value, context) => {\n if (value == null) return true;\n const regex = /^([0-9]+)(\\.([0-9]+))?$/;\n const match = value.match(regex);\n if (!match) return context.createError({ message: 'Money amount must be in the format of <number> or <number>.<number>' });\n const whole = match[1];\n const decimals = match[3];\n if (decimals && decimals.length > currency.decimals) return context.createError({ message: `Too many decimals; ${currency.code} only has ${currency.decimals} decimals` });\n if (whole !== '0' && whole.startsWith('0')) return context.createError({ message: 'Money amount must not have leading zeros' });\n return true;\n});\n\n\n/**\n * A stricter email schema that does some additional checks for UX input. (Some emails are allowed by the spec, for\n * example `test@localhost` or `abc@gmail`, but almost certainly a user input error.)\n *\n * Note that some users in the DB have an email that doesn't match this regex, so most of the time you should use\n * `emailSchema` instead until we do the DB migration.\n */\n// eslint-disable-next-line no-restricted-syntax\nexport const strictEmailSchema = (message: string | undefined) => yupString().email(message).max(256).matches(/^[^.]+(\\.[^.]+)*@.*\\.[^.][^.]+$/, message);\n// eslint-disable-next-line no-restricted-syntax\nexport const emailSchema = yupString().email();\n\nundefined?.test('strictEmailSchema', ({ expect }) => {\n const validEmails = [\n \"a@example.com\",\n \"abc@example.com\",\n \"a.b@example.com\",\n \"throwaway.mail+token@example.com\",\n \"email-alt-dash@demo-mail.com\",\n \"test-account@weird-domain.net\",\n \"%!~&+{}=|`#@domain.test\",\n \"admin@a.longtldexample\",\n ];\n for (const email of validEmails) {\n expect(strictEmailSchema(undefined).validateSync(email)).toBe(email);\n }\n const invalidEmails = [\n \"test@localhost\",\n \"test@gmail\",\n \"test@gmail.com.a\",\n \"test@gmail.a\",\n \"test.@example.com\",\n \"test..test@example.com\",\n \".test@example.com\",\n ];\n for (const email of invalidEmails) {\n expect(() => strictEmailSchema(undefined).validateSync(email)).toThrow();\n }\n});\n\n// Request auth\nexport const clientOrHigherAuthTypeSchema = yupString().oneOf(['client', 'server', 'admin']).defined();\nexport const serverOrHigherAuthTypeSchema = yupString().oneOf(['server', 'admin']).defined();\nexport const adminAuthTypeSchema = yupString().oneOf(['admin']).defined();\n\n// Projects\nexport const projectIdSchema = yupString().test((v) => v === undefined || v === \"internal\" || isUuid(v)).meta({ openapiField: { description: _idDescription('project'), exampleValue: 'e0b52f4d-dece-408c-af49-d23061bb0f8d' } });\nexport const projectBranchIdSchema = yupString().nonEmpty().max(255).meta({ openapiField: { description: _idDescription('project branch'), exampleValue: 'main' } });\nexport const projectDisplayNameSchema = yupString().meta({ openapiField: { description: _displayNameDescription('project'), exampleValue: 'MyMusic' } });\nexport const projectLogoUrlSchema = urlSchema.max(MAX_IMAGE_SIZE_BASE64_BYTES).meta({ openapiField: { description: 'URL of the logo for the project. This is usually a close to 1:1 image of the company logo.', exampleValue: 'https://example.com/logo.png' } });\nexport const projectFullLogoUrlSchema = urlSchema.max(MAX_IMAGE_SIZE_BASE64_BYTES).meta({ openapiField: { description: 'URL of the full logo for the project. This is usually a vertical image with the logo and the company name.', exampleValue: 'https://example.com/full-logo.png' } });\nexport const projectDescriptionSchema = yupString().nullable().meta({ openapiField: { description: 'A human readable description of the project', exampleValue: 'A music streaming service' } });\nexport const projectCreatedAtMillisSchema = yupNumber().meta({ openapiField: { description: _createdAtMillisDescription('project'), exampleValue: 1630000000000 } });\nexport const projectIsProductionModeSchema = yupBoolean().meta({ openapiField: { description: 'Whether the project is in production mode', exampleValue: true } });\n// Project config\nexport const projectConfigIdSchema = yupString().meta({ openapiField: { description: _idDescription('project config'), exampleValue: 'd09201f0-54f5-40bd-89ff-6d1815ddad24' } });\nexport const projectAllowLocalhostSchema = yupBoolean().meta({ openapiField: { description: 'Whether localhost is allowed as a domain for this project. Should only be allowed in development mode', exampleValue: true } });\nexport const projectCreateTeamOnSignUpSchema = yupBoolean().meta({ openapiField: { description: 'Whether a team should be created for each user that signs up', exampleValue: true } });\nexport const projectMagicLinkEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether magic link authentication is enabled for this project', exampleValue: true } });\nexport const projectPasskeyEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether passkey authentication is enabled for this project', exampleValue: true } });\nexport const projectClientTeamCreationEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether client users can create teams', exampleValue: true } });\nexport const projectClientUserDeletionEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether client users can delete their own account from the client', exampleValue: true } });\nexport const projectSignUpEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether users can sign up new accounts, or whether they are only allowed to sign in to existing accounts. Regardless of this option, the server API can always create new users with the `POST /users` endpoint.', exampleValue: true } });\nexport const projectCredentialEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether email password authentication is enabled for this project', exampleValue: true } });\n// Project OAuth config\nexport const oauthIdSchema = yupString().oneOf(allProviders).meta({ openapiField: { description: `OAuth provider ID, one of ${allProviders.map(x => `\\`${x}\\``).join(', ')}`, exampleValue: 'google' } });\nexport const oauthEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether the OAuth provider is enabled. If an provider is first enabled, then disabled, it will be shown in the list but with enabled=false', exampleValue: true } });\nexport const oauthTypeSchema = yupString().oneOf(['shared', 'standard']).meta({ openapiField: { description: 'OAuth provider type, one of shared, standard. \"shared\" uses Stack shared OAuth keys and it is only meant for development. \"standard\" uses your own OAuth keys and will show your logo and company name when signing in with the provider.', exampleValue: 'standard' } });\nexport const oauthClientIdSchema = yupString().meta({ openapiField: { description: 'OAuth client ID. Needs to be specified when using type=\"standard\"', exampleValue: 'google-oauth-client-id' } });\nexport const oauthClientSecretSchema = yupString().meta({ openapiField: { description: 'OAuth client secret. Needs to be specified when using type=\"standard\"', exampleValue: 'google-oauth-client-secret' } });\nexport const oauthFacebookConfigIdSchema = yupString().meta({ openapiField: { description: 'The configuration id for Facebook business login (for things like ads and marketing). This is only required if you are using the standard OAuth with Facebook and you are using Facebook business login.' } });\nexport const oauthMicrosoftTenantIdSchema = yupString().meta({ openapiField: { description: 'The Microsoft tenant id for Microsoft directory. This is only required if you are using the standard OAuth with Microsoft and you have an Azure AD tenant.' } });\nexport const oauthAccountMergeStrategySchema = yupString().oneOf(['link_method', 'raise_error', 'allow_duplicates']).meta({ openapiField: { description: 'Determines how to handle OAuth logins that match an existing user by email. `link_method` adds the OAuth method to the existing user. `raise_error` rejects the login with an error. `allow_duplicates` creates a new user.', exampleValue: 'link_method' } });\n// Project email config\nexport const emailTypeSchema = yupString().oneOf(['shared', 'standard']).meta({ openapiField: { description: 'Email provider type, one of shared, standard. \"shared\" uses Stack shared email provider and it is only meant for development. \"standard\" uses your own email server and will have your email address as the sender.', exampleValue: 'standard' } });\nexport const emailSenderNameSchema = yupString().meta({ openapiField: { description: 'Email sender name. Needs to be specified when using type=\"standard\"', exampleValue: 'Stack' } });\nexport const emailHostSchema = yupString().meta({ openapiField: { description: 'Email host. Needs to be specified when using type=\"standard\"', exampleValue: 'smtp.your-domain.com' } });\nexport const emailPortSchema = yupNumber().min(0).max(65535).meta({ openapiField: { description: 'Email port. Needs to be specified when using type=\"standard\"', exampleValue: 587 } });\nexport const emailUsernameSchema = yupString().meta({ openapiField: { description: 'Email username. Needs to be specified when using type=\"standard\"', exampleValue: 'smtp-email' } });\nexport const emailSenderEmailSchema = emailSchema.meta({ openapiField: { description: 'Email sender email. Needs to be specified when using type=\"standard\"', exampleValue: 'example@your-domain.com' } });\nexport const emailPasswordSchema = passwordSchema.meta({ openapiField: { description: 'Email password. Needs to be specified when using type=\"standard\"', exampleValue: 'your-email-password' } });\n// Project domain config\nexport const handlerPathSchema = yupString().test('is-handler-path', 'Handler path must start with /', (value) => value?.startsWith('/')).meta({ openapiField: { description: 'Handler path. If you did not setup a custom handler path, it should be \"/handler\" by default. It needs to start with /', exampleValue: '/handler' } });\n// Project email theme config\nexport const emailThemeSchema = yupString().meta({ openapiField: { description: 'Email theme id for the project. Determines the visual style of emails sent by the project.' } });\nexport const emailThemeListSchema = yupRecord(\n yupString().uuid(),\n yupObject({\n displayName: yupString().meta({ openapiField: { description: 'Email theme name', exampleValue: 'Default Light' } }).defined(),\n tsxSource: yupString().meta({ openapiField: { description: 'Email theme source code tsx component' } }).defined(),\n })\n).meta({ openapiField: { description: 'Record of email theme IDs to their display name and source code' } });\nexport const templateThemeIdSchema = yupMixed<string | false>().test((v: any) => v === undefined || v === false || v === null || (typeof v === 'string' && isUuid(v))).meta({ openapiField: { description: 'Email theme id for the template' } }).optional();\nexport const emailTemplateListSchema = yupRecord(\n yupString().uuid(),\n yupObject({\n displayName: yupString().meta({ openapiField: { description: 'Email template name', exampleValue: 'Email Verification' } }).defined(),\n tsxSource: yupString().meta({ openapiField: { description: 'Email template source code tsx component' } }).defined(),\n // themeId can be one of three values:\n // 1. A valid theme id\n // 2. false, which means the template uses no theme\n // 3. undefined/not given, which means the template uses the project's active theme\n themeId: templateThemeIdSchema,\n })\n).meta({ openapiField: { description: 'Record of email template IDs to their display name and source code' } });\n\n// Payments\nexport const customerTypeSchema = yupString().oneOf(['user', 'team', 'custom']);\nconst validateHasAtLeastOneSupportedCurrency = (value: Record<string, unknown> | null, context: any) => {\n if (!value) return true;\n const currencies = Object.keys(value).filter(key => SUPPORTED_CURRENCIES.some(c => c.code === key));\n if (currencies.length === 0) {\n return context.createError({ message: \"At least one currency is required\" });\n }\n return true;\n};\nexport const offerPriceSchema = yupObject({\n ...typedFromEntries(SUPPORTED_CURRENCIES.map(currency => [currency.code, moneyAmountSchema(currency).optional()])),\n interval: dayIntervalSchema.optional(),\n serverOnly: yupBoolean(),\n freeTrial: dayIntervalSchema.optional(),\n}).test(\"at-least-one-currency\", (value, context) => validateHasAtLeastOneSupportedCurrency(value, context));\nexport const priceOrIncludeByDefaultSchema = yupUnion(\n yupString().oneOf(['include-by-default']).meta({ openapiField: { description: 'Makes this item free and includes it by default for all customers.', exampleValue: 'include-by-default' } }),\n yupRecord(\n userSpecifiedIdSchema(\"priceId\"),\n offerPriceSchema,\n ),\n);\nexport const offerSchema = yupObject({\n displayName: yupString(),\n groupId: userSpecifiedIdSchema(\"groupId\").optional().meta({ openapiField: { description: 'The ID of the group this offer belongs to. Within a group, all offers are mutually exclusive unless they are an add-on to another offer in the group.', exampleValue: 'group-id' } }),\n isAddOnTo: yupUnion(\n yupBoolean().isFalse(),\n yupRecord(\n userSpecifiedIdSchema(\"offerId\"),\n yupBoolean().isTrue().defined(),\n ),\n ).optional().meta({ openapiField: { description: 'The offers that this offer is an add-on to. If this is set, the customer must already have one of the offers in the record to be able to purchase this offer.', exampleValue: { \"offer-id\": true } } }),\n customerType: customerTypeSchema.defined(),\n freeTrial: dayIntervalSchema.optional(),\n serverOnly: yupBoolean(),\n stackable: yupBoolean(),\n prices: priceOrIncludeByDefaultSchema.defined(),\n includedItems: yupRecord(\n userSpecifiedIdSchema(\"itemId\"),\n yupObject({\n quantity: yupNumber().defined(),\n repeat: dayIntervalOrNeverSchema.optional(),\n expires: yupString().oneOf(['never', 'when-purchase-expires', 'when-repeated']).optional(),\n }),\n ),\n});\nexport const inlineOfferSchema = yupObject({\n display_name: yupString().defined(),\n customer_type: customerTypeSchema.defined(),\n free_trial: dayIntervalSchema.optional(),\n server_only: yupBoolean().oneOf([true]).default(true),\n prices: yupRecord(\n userSpecifiedIdSchema(\"priceId\"),\n yupObject({\n ...typedFromEntries(SUPPORTED_CURRENCIES.map(currency => [currency.code, moneyAmountSchema(currency).optional()])),\n interval: dayIntervalSchema.optional(),\n free_trial: dayIntervalSchema.optional(),\n }).test(\"at-least-one-currency\", (value, context) => validateHasAtLeastOneSupportedCurrency(value, context)),\n ),\n included_items: yupRecord(\n userSpecifiedIdSchema(\"itemId\"),\n yupObject({\n quantity: yupNumber(),\n repeat: dayIntervalOrNeverSchema.optional(),\n expires: yupString().oneOf(['never', 'when-purchase-expires', 'when-repeated']).optional(),\n }),\n ),\n});\n\n// Users\nexport class ReplaceFieldWithOwnUserId extends Error {\n constructor(public readonly path: string) {\n super(`This error should be caught by whoever validated the schema, and the field in the path '${path}' should be replaced with the current user's id. This is a workaround to yup not providing access to the context inside the transform function.`);\n }\n}\nconst userIdMeSentinelUuid = \"cad564fd-f81b-43f4-b390-98abf3fcc17e\";\nexport const userIdOrMeSchema = yupString().uuid().transform(v => {\n if (v === \"me\") return userIdMeSentinelUuid;\n else return v;\n}).test((v, context) => {\n if (!(\"stackAllowUserIdMe\" in (context.options.context ?? {}))) throw new StackAssertionError('userIdOrMeSchema is not allowed in this context. Make sure you\\'re using yupValidate from schema-fields.ts to validate, instead of schema.validate(...).');\n if (!context.options.context?.stackAllowUserIdMe) throw new StackAssertionError('userIdOrMeSchema is not allowed in this context. Make sure you\\'re passing in the currentUserId option in yupValidate.');\n if (v === userIdMeSentinelUuid) throw new ReplaceFieldWithOwnUserId(context.path);\n return true;\n}).meta({ openapiField: { description: 'The ID of the user, or the special value `me` for the currently authenticated user', exampleValue: '3241a285-8329-4d69-8f3d-316e08cf140c' } });\nexport const userIdSchema = yupString().uuid().meta({ openapiField: { description: _idDescription('user'), exampleValue: '3241a285-8329-4d69-8f3d-316e08cf140c' } });\nexport const primaryEmailSchema = emailSchema.meta({ openapiField: { description: 'Primary email', exampleValue: 'johndoe@example.com' } });\nexport const primaryEmailAuthEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether the primary email is used for authentication. If this is set to `false`, the user will not be able to sign in with the primary email with password or OTP', exampleValue: true } });\nexport const primaryEmailVerifiedSchema = yupBoolean().meta({ openapiField: { description: 'Whether the primary email has been verified to belong to this user', exampleValue: true } });\nexport const userDisplayNameSchema = yupString().nullable().max(256).meta({ openapiField: { description: _displayNameDescription('user'), exampleValue: 'John Doe' } });\nexport const selectedTeamIdSchema = yupString().uuid().meta({ openapiField: { description: 'ID of the team currently selected by the user', exampleValue: 'team-id' } });\nexport const profileImageUrlSchema = urlSchema.max(MAX_IMAGE_SIZE_BASE64_BYTES).meta({ openapiField: { description: _profileImageUrlDescription('user'), exampleValue: 'https://example.com/image.jpg' } });\nexport const signedUpAtMillisSchema = yupNumber().meta({ openapiField: { description: _signedUpAtMillisDescription, exampleValue: 1630000000000 } });\nexport const userClientMetadataSchema = jsonSchema.meta({ openapiField: { description: _clientMetaDataDescription('user'), exampleValue: { key: 'value' } } });\nexport const userClientReadOnlyMetadataSchema = jsonSchema.meta({ openapiField: { description: _clientReadOnlyMetaDataDescription('user'), exampleValue: { key: 'value' } } });\nexport const userServerMetadataSchema = jsonSchema.meta({ openapiField: { description: _serverMetaDataDescription('user'), exampleValue: { key: 'value' } } });\nexport const userOAuthProviderSchema = yupObject({\n id: yupString().defined(),\n type: yupString().oneOf(allProviders).defined(),\n provider_user_id: yupString().defined(),\n});\nexport const userLastActiveAtMillisSchema = yupNumber().nullable().meta({ openapiField: { description: _lastActiveAtMillisDescription, exampleValue: 1630000000000 } });\nexport const userPasskeyAuthEnabledSchema = yupBoolean().meta({ openapiField: { hidden: true, description: 'Whether the user has passkeys enabled', exampleValue: false } });\nexport const userOtpAuthEnabledSchema = yupBoolean().meta({ openapiField: { hidden: true, description: 'Whether the user has OTP/magic link enabled. ', exampleValue: true } });\nexport const userOtpAuthEnabledMutationSchema = yupBoolean().meta({ openapiField: { hidden: true, description: 'Whether the user has OTP/magic link enabled. Note that only accounts with verified emails can sign-in with OTP.', exampleValue: true } });\nexport const userHasPasswordSchema = yupBoolean().meta({ openapiField: { hidden: true, description: 'Whether the user has a password set. If the user does not have a password set, they will not be able to sign in with email/password.', exampleValue: true } });\nexport const userPasswordMutationSchema = passwordSchema.nullable().meta({ openapiField: { description: 'Sets the user\\'s password. Doing so revokes all current sessions.', exampleValue: 'my-new-password' } }).max(70);\nexport const userPasswordHashMutationSchema = yupString()\n .nonEmpty()\n .meta({ openapiField: { description: 'If `password` is not given, sets the user\\'s password hash to the given string in Modular Crypt Format (ex.: `$2a$10$VIhIOofSMqGdGlL4wzE//e.77dAQGqNtF/1dT7bqCrVtQuInWy2qi`). Doing so revokes all current sessions.' } }); // we don't set an exampleValue here because it's exclusive with the password field and having both would break the generated example\nexport const userTotpSecretMutationSchema = base64Schema.nullable().meta({ openapiField: { description: 'Enables 2FA and sets a TOTP secret for the user. Set to null to disable 2FA.', exampleValue: 'dG90cC1zZWNyZXQ=' } });\n\n// Auth\nexport const signInEmailSchema = strictEmailSchema(undefined).meta({ openapiField: { description: 'The email to sign in with.', exampleValue: 'johndoe@example.com' } });\nexport const emailOtpSignInCallbackUrlSchema = urlSchema.meta({ openapiField: { description: 'The base callback URL to construct the magic link from. A query parameter `code` with the verification code will be appended to it. The page should then make a request to the `/auth/otp/sign-in` endpoint.', exampleValue: 'https://example.com/handler/magic-link-callback' } });\nexport const emailVerificationCallbackUrlSchema = urlSchema.meta({ openapiField: { description: 'The base callback URL to construct a verification link for the verification e-mail. A query parameter `code` with the verification code will be appended to it. The page should then make a request to the `/contact-channels/verify` endpoint.', exampleValue: 'https://example.com/handler/email-verification' } });\nexport const accessTokenResponseSchema = yupString().meta({ openapiField: { description: 'Short-lived access token that can be used to authenticate the user', exampleValue: 'eyJhmMiJB2TO...diI4QT' } });\nexport const refreshTokenResponseSchema = yupString().meta({ openapiField: { description: 'Long-lived refresh token that can be used to obtain a new access token', exampleValue: 'i8ns3aq2...14y' } });\nexport const signInResponseSchema = yupObject({\n refresh_token: refreshTokenResponseSchema.defined(),\n access_token: accessTokenResponseSchema.defined(),\n is_new_user: yupBoolean().meta({ openapiField: { description: 'Whether the user is a new user', exampleValue: true } }).defined(),\n user_id: userIdSchema.defined(),\n});\n\n// Permissions\nexport const teamSystemPermissions = [\n '$update_team',\n '$delete_team',\n '$read_members',\n '$remove_members',\n '$invite_members',\n '$manage_api_keys',\n] as const;\nexport const permissionDefinitionIdSchema = yupString()\n .matches(/^\\$?[a-z0-9_:]+$/, 'Only lowercase letters, numbers, \":\", \"_\" and optional \"$\" at the beginning are allowed')\n .test('is-system-permission', 'System permissions must start with a dollar sign', (value, ctx) => {\n if (!value) return true;\n if (value.startsWith('$') && !teamSystemPermissions.includes(value as any)) {\n return ctx.createError({ message: 'Invalid system permission' });\n }\n return true;\n })\n .meta({ openapiField: { description: `The permission ID used to uniquely identify a permission. Can either be a custom permission with lowercase letters, numbers, \\`:\\`, and \\`_\\` characters, or one of the system permissions: ${teamSystemPermissions.map(x => `\\`${x}\\``).join(', ')}`, exampleValue: 'read_secret_info' } });\nexport const customPermissionDefinitionIdSchema = yupString()\n .matches(/^[a-z0-9_:]+$/, 'Only lowercase letters, numbers, \":\", \"_\" are allowed')\n .meta({ openapiField: { description: 'The permission ID used to uniquely identify a permission. Can only contain lowercase letters, numbers, \":\", and \"_\" characters', exampleValue: 'read_secret_info' } });\nexport const teamPermissionDescriptionSchema = yupString().meta({ openapiField: { description: 'A human-readable description of the permission', exampleValue: 'Read secret information' } });\nexport const containedPermissionIdsSchema = yupArray(permissionDefinitionIdSchema.defined()).meta({ openapiField: { description: 'The IDs of the permissions that are contained in this permission', exampleValue: ['read_public_info'] } });\n\n// Teams\nexport const teamIdSchema = yupString().uuid().meta({ openapiField: { description: _idDescription('team'), exampleValue: 'ad962777-8244-496a-b6a2-e0c6a449c79e' } });\nexport const teamDisplayNameSchema = yupString().meta({ openapiField: { description: _displayNameDescription('team'), exampleValue: 'My Team' } });\nexport const teamProfileImageUrlSchema = urlSchema.max(1000000).meta({ openapiField: { description: _profileImageUrlDescription('team'), exampleValue: 'https://example.com/image.jpg' } });\nexport const teamClientMetadataSchema = jsonSchema.meta({ openapiField: { description: _clientMetaDataDescription('team'), exampleValue: { key: 'value' } } });\nexport const teamClientReadOnlyMetadataSchema = jsonSchema.meta({ openapiField: { description: _clientReadOnlyMetaDataDescription('team'), exampleValue: { key: 'value' } } });\nexport const teamServerMetadataSchema = jsonSchema.meta({ openapiField: { description: _serverMetaDataDescription('team'), exampleValue: { key: 'value' } } });\nexport const teamCreatedAtMillisSchema = yupNumber().meta({ openapiField: { description: _createdAtMillisDescription('team'), exampleValue: 1630000000000 } });\nexport const teamInvitationEmailSchema = emailSchema.meta({ openapiField: { description: 'The email of the user to invite.', exampleValue: 'johndoe@example.com' } });\nexport const teamInvitationCallbackUrlSchema = urlSchema.meta({ openapiField: { description: 'The base callback URL to construct an invite link with. A query parameter `code` with the verification code will be appended to it. The page should then make a request to the `/team-invitations/accept` endpoint.', exampleValue: 'https://example.com/handler/team-invitation' } });\nexport const teamCreatorUserIdSchema = userIdOrMeSchema.meta({ openapiField: { description: 'The ID of the creator of the team. If not specified, the user will not be added to the team. Can be either \"me\" or the ID of the user. Only used on the client side.', exampleValue: 'me' } });\n\n// Team member profiles\nexport const teamMemberDisplayNameSchema = yupString().meta({ openapiField: { description: _displayNameDescription('team member') + ' Note that this is separate from the display_name of the user.', exampleValue: 'John Doe' } });\nexport const teamMemberProfileImageUrlSchema = urlSchema.max(1000000).meta({ openapiField: { description: _profileImageUrlDescription('team member'), exampleValue: 'https://example.com/image.jpg' } });\n\n// Contact channels\nexport const contactChannelIdSchema = yupString().uuid().meta({ openapiField: { description: _idDescription('contact channel'), exampleValue: 'b3d396b8-c574-4c80-97b3-50031675ceb2' } });\nexport const contactChannelTypeSchema = yupString().oneOf(['email']).meta({ openapiField: { description: `The type of the contact channel. Currently only \"email\" is supported.`, exampleValue: 'email' } });\nexport const contactChannelValueSchema = yupString().when('type', {\n is: 'email',\n then: (schema) => schema.email(),\n}).meta({ openapiField: { description: 'The value of the contact channel. For email, this should be a valid email address.', exampleValue: 'johndoe@example.com' } });\nexport const contactChannelUsedForAuthSchema = yupBoolean().meta({ openapiField: { description: 'Whether the contact channel is used for authentication. If this is set to `true`, the user will be able to sign in with the contact channel with password or OTP.', exampleValue: true } });\nexport const contactChannelIsVerifiedSchema = yupBoolean().meta({ openapiField: { description: 'Whether the contact channel has been verified. If this is set to `true`, the contact channel has been verified to belong to the user.', exampleValue: true } });\nexport const contactChannelIsPrimarySchema = yupBoolean().meta({ openapiField: { description: 'Whether the contact channel is the primary contact channel. If this is set to `true`, it will be used for authentication and notifications by default.', exampleValue: true } });\n\n// OAuth providers\nexport const oauthProviderIdSchema = yupString().uuid().meta({ openapiField: { description: _idDescription('OAuth provider'), exampleValue: 'b3d396b8-c574-4c80-97b3-50031675ceb2' } });\nexport const oauthProviderEmailSchema = emailSchema.meta({ openapiField: { description: 'Email of the OAuth provider. This is used to display and identify the OAuth provider in the UI.', exampleValue: 'test@gmail.com' } });\nexport const oauthProviderTypeSchema = yupString().oneOf(allProviders).meta({ openapiField: { description: `OAuth provider type, one of ${allProviders.map(x => `\\`${x}\\``).join(', ')}`, exampleValue: 'google' } });\nexport const oauthProviderAllowSignInSchema = yupBoolean().meta({ openapiField: { description: 'Whether the user can use this OAuth provider to sign in. Only one OAuth provider per type can have this set to `true`.', exampleValue: true } });\nexport const oauthProviderAllowConnectedAccountsSchema = yupBoolean().meta({ openapiField: { description: 'Whether the user can use this OAuth provider as connected account. Multiple OAuth providers per type can have this set to `true`.', exampleValue: true } });\nexport const oauthProviderAccountIdSchema = yupString().meta({ openapiField: { description: 'Account ID of the OAuth provider. This uniquely identifies the account on the provider side.', exampleValue: 'google-account-id-12345' } });\nexport const oauthProviderProviderConfigIdSchema = yupString().meta({ openapiField: { description: 'Provider config ID of the OAuth provider. This uniquely identifies the provider config on config.json file', exampleValue: 'google' } });\n\n// Headers\nexport const basicAuthorizationHeaderSchema = yupString().test('is-basic-authorization-header', 'Authorization header must be in the format \"Basic <base64>\"', (value) => {\n if (!value) return true;\n return decodeBasicAuthorizationHeader(value) !== null;\n});\n\n// Neon integration\nexport const neonAuthorizationHeaderSchema = basicAuthorizationHeaderSchema.test('is-authorization-header', 'Invalid client_id:client_secret values; did you use the correct values for the integration?', (value) => {\n if (!value) return true;\n const [clientId, clientSecret] = decodeBasicAuthorizationHeader(value) ?? throwErr(`Authz header invalid? This should've been validated by basicAuthorizationHeaderSchema: ${value}`);\n for (const neonClientConfig of JSON.parse(process.env.STACK_INTEGRATION_CLIENTS_CONFIG || '[]')) {\n if (clientId === neonClientConfig.client_id && clientSecret === neonClientConfig.client_secret) return true;\n }\n return false;\n});\n\n// Utils\nexport function yupDefinedWhen<S extends yup.AnyObject>(\n schema: S,\n triggers: Record<string, any>,\n): S {\n const entries = Object.entries(triggers);\n return schema.when(entries.map(([key]) => key), {\n is: (...values: any[]) => entries.every(([key, value], index) => value === values[index]),\n then: (schema: S) => schema.defined(),\n otherwise: (schema: S) => schema.optional()\n });\n}\n\nexport function yupDefinedAndNonEmptyWhen<S extends yup.StringSchema>(\n schema: S,\n triggers: Record<string, any>,\n): S {\n const entries = Object.entries(triggers);\n return schema.when(entries.map(([key]) => key), {\n is: (...values: any[]) => entries.every(([key, value], index) => value === values[index]),\n then: (schema: S) => schema.defined().nonEmpty(),\n otherwise: (schema: S) => schema.optional()\n });\n}\n"],"mappings":";AAAA,YAAY,SAAS;AACrB,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AACzB,SAAS,4BAA6D;AAEtE,SAAS,qBAAqB,gBAAgB;AAC9C,SAAS,sCAAsC;AAC/C,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB,MAAM,wBAAwB;AACvD,SAAS,gBAAgB;AACzB,SAAS,8BAA8B,kBAA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G;AACH,QAAM,UAAU,OAAO,QAAQ,QAAQ;AACvC,SAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,CAAC,GAAG,MAAM,GAAG,GAAG;AAAA,IAC9C,IAAI,IAAI,WAAkB,QAAQ,MAAM,CAAC,CAAC,KAAK,KAAK,GAAG,UAAU,UAAU,OAAO,KAAK,CAAC;AAAA,IACxF,MAAM,CAACA,YAAcA,QAAO,QAAQ,EAAE,SAAS;AAAA,IAC/C,WAAW,CAACA,YAAcA,QAAO,SAAS;AAAA,EAC5C,CAAC;AACH;","names":["object","schema"]}
@@ -62,11 +62,36 @@ function outerProduct(arr1, arr2) {
62
62
  function unique(arr) {
63
63
  return [...new Set(arr)];
64
64
  }
65
+ function getChunks(arr, size) {
66
+ const result = [];
67
+ if (size <= 0) return result;
68
+ for (let i = 0; i < arr.length; i += size) {
69
+ result.push(arr.slice(i, i + size));
70
+ }
71
+ return result;
72
+ }
73
+ function isStringArray(arr) {
74
+ return Array.isArray(arr) && arr.every((item) => typeof item === "string");
75
+ }
76
+ function isNumberArray(arr) {
77
+ return Array.isArray(arr) && arr.every((item) => typeof item === "number");
78
+ }
79
+ function isBooleanArray(arr) {
80
+ return Array.isArray(arr) && arr.every((item) => typeof item === "boolean");
81
+ }
82
+ function isObjectArray(arr) {
83
+ return Array.isArray(arr) && arr.every((item) => typeof item === "object" && item !== null);
84
+ }
65
85
  export {
66
86
  enumerate,
67
87
  findLastIndex,
88
+ getChunks,
68
89
  groupBy,
90
+ isBooleanArray,
91
+ isNumberArray,
92
+ isObjectArray,
69
93
  isShallowEqual,
94
+ isStringArray,
70
95
  outerProduct,
71
96
  range,
72
97
  rotateLeft,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/arrays.tsx"],"sourcesContent":["import { remainder } from \"./math\";\n\nexport function typedIncludes<T extends readonly any[]>(arr: T, item: unknown): item is T[number] {\n return arr.includes(item);\n}\nundefined?.test(\"typedIncludes\", ({ expect }) => {\n const arr = [1, 2, 3] as const;\n expect(typedIncludes(arr, 1)).toBe(true);\n expect(typedIncludes(arr, 4)).toBe(false);\n expect(typedIncludes(arr, \"1\")).toBe(false);\n\n const strArr = [\"a\", \"b\", \"c\"] as const;\n expect(typedIncludes(strArr, \"a\")).toBe(true);\n expect(typedIncludes(strArr, \"d\")).toBe(false);\n});\n\nexport function enumerate<T extends readonly any[]>(arr: T): [number, T[number]][] {\n return arr.map((item, index) => [index, item]);\n}\nundefined?.test(\"enumerate\", ({ expect }) => {\n expect(enumerate([])).toEqual([]);\n expect(enumerate([1, 2, 3])).toEqual([[0, 1], [1, 2], [2, 3]]);\n expect(enumerate([\"a\", \"b\", \"c\"])).toEqual([[0, \"a\"], [1, \"b\"], [2, \"c\"]]);\n});\n\nexport function isShallowEqual(a: readonly any[], b: readonly any[]): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\nundefined?.test(\"isShallowEqual\", ({ expect }) => {\n expect(isShallowEqual([], [])).toBe(true);\n expect(isShallowEqual([1, 2, 3], [1, 2, 3])).toBe(true);\n expect(isShallowEqual([1, 2, 3], [1, 2, 4])).toBe(false);\n expect(isShallowEqual([1, 2, 3], [1, 2])).toBe(false);\n expect(isShallowEqual([1, 2], [1, 2, 3])).toBe(false);\n // Test with objects (reference equality)\n const obj1 = { a: 1 };\n const obj2 = { a: 1 };\n expect(isShallowEqual([obj1], [obj1])).toBe(true);\n expect(isShallowEqual([obj1], [obj2])).toBe(false);\n});\n\n/**\n * Ponyfill for ES2023's findLastIndex.\n */\nexport function findLastIndex<T>(arr: readonly T[], predicate: (item: T) => boolean): number {\n for (let i = arr.length - 1; i >= 0; i--) {\n if (predicate(arr[i])) return i;\n }\n return -1;\n}\nundefined?.test(\"findLastIndex\", ({ expect }) => {\n expect(findLastIndex([], () => true)).toBe(-1);\n expect(findLastIndex([1, 2, 3, 4, 5], x => x % 2 === 0)).toBe(3); // 4 is at index 3\n expect(findLastIndex([1, 2, 3, 4, 5], x => x > 10)).toBe(-1);\n expect(findLastIndex([1, 2, 3, 2, 1], x => x === 2)).toBe(3);\n expect(findLastIndex([1, 2, 3], x => x === 1)).toBe(0);\n});\n\nexport function groupBy<T extends any, K>(\n arr: Iterable<T>,\n key: (item: T) => K,\n): Map<K, T[]> {\n const result = new Map<K, T[]>;\n for (const item of arr) {\n const k = key(item);\n if (result.get(k) === undefined) result.set(k, []);\n result.get(k)!.push(item);\n }\n return result;\n}\nundefined?.test(\"groupBy\", ({ expect }) => {\n expect(groupBy([], (x) => x)).toEqual(new Map());\n\n const numbers = [1, 2, 3, 4, 5, 6];\n const grouped = groupBy(numbers, (n) => n % 2 === 0 ? \"even\" : \"odd\");\n expect(grouped.get(\"even\")).toEqual([2, 4, 6]);\n expect(grouped.get(\"odd\")).toEqual([1, 3, 5]);\n\n // Check the actual lengths of the words to ensure our test is correct\n const words = [\"apple\", \"banana\", \"cherry\", \"date\", \"elderberry\"];\n\n const byLength = groupBy(words, (w) => w.length);\n // Adjust expectations based on actual word lengths\n expect(byLength.get(5)).toEqual([\"apple\"]);\n expect(byLength.get(6)).toEqual([\"banana\", \"cherry\"]);\n expect(byLength.get(4)).toEqual([\"date\"]);\n expect(byLength.get(10)).toEqual([\"elderberry\"]);\n});\n\nexport function range(endExclusive: number): number[];\nexport function range(startInclusive: number, endExclusive: number): number[];\nexport function range(startInclusive: number, endExclusive: number, step: number): number[];\nexport function range(startInclusive: number, endExclusive?: number, step?: number): number[] {\n if (endExclusive === undefined) {\n endExclusive = startInclusive;\n startInclusive = 0;\n }\n if (step === undefined) step = 1;\n\n const result = [];\n for (let i = startInclusive; step > 0 ? (i < endExclusive) : (i > endExclusive); i += step) {\n result.push(i);\n }\n return result;\n}\nundefined?.test(\"range\", ({ expect }) => {\n expect(range(5)).toEqual([0, 1, 2, 3, 4]);\n expect(range(2, 5)).toEqual([2, 3, 4]);\n expect(range(1, 10, 2)).toEqual([1, 3, 5, 7, 9]);\n expect(range(5, 0, -1)).toEqual([5, 4, 3, 2, 1]);\n expect(range(0, 0)).toEqual([]);\n expect(range(0, 10, 3)).toEqual([0, 3, 6, 9]);\n});\n\n\nexport function rotateLeft(arr: readonly any[], n: number): any[] {\n if (arr.length === 0) return [];\n const index = remainder(n, arr.length);\n return [...arr.slice(index), ...arr.slice(0, index)];\n}\nundefined?.test(\"rotateLeft\", ({ expect }) => {\n expect(rotateLeft([], 1)).toEqual([]);\n expect(rotateLeft([1, 2, 3, 4, 5], 0)).toEqual([1, 2, 3, 4, 5]);\n expect(rotateLeft([1, 2, 3, 4, 5], 1)).toEqual([2, 3, 4, 5, 1]);\n expect(rotateLeft([1, 2, 3, 4, 5], 3)).toEqual([4, 5, 1, 2, 3]);\n expect(rotateLeft([1, 2, 3, 4, 5], 5)).toEqual([1, 2, 3, 4, 5]);\n expect(rotateLeft([1, 2, 3, 4, 5], 6)).toEqual([2, 3, 4, 5, 1]);\n});\n\nexport function rotateRight(arr: readonly any[], n: number): any[] {\n return rotateLeft(arr, -n);\n}\nundefined?.test(\"rotateRight\", ({ expect }) => {\n expect(rotateRight([], 1)).toEqual([]);\n expect(rotateRight([1, 2, 3, 4, 5], 0)).toEqual([1, 2, 3, 4, 5]);\n expect(rotateRight([1, 2, 3, 4, 5], 1)).toEqual([5, 1, 2, 3, 4]);\n expect(rotateRight([1, 2, 3, 4, 5], 3)).toEqual([3, 4, 5, 1, 2]);\n expect(rotateRight([1, 2, 3, 4, 5], 5)).toEqual([1, 2, 3, 4, 5]);\n expect(rotateRight([1, 2, 3, 4, 5], 6)).toEqual([5, 1, 2, 3, 4]);\n});\n\n\nexport function shuffle<T>(arr: readonly T[]): T[] {\n const result = [...arr];\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n [result[i], result[j]] = [result[j], result[i]];\n }\n return result;\n}\nundefined?.test(\"shuffle\", ({ expect }) => {\n // Test empty array\n expect(shuffle([])).toEqual([]);\n\n // Test single element array\n expect(shuffle([1])).toEqual([1]);\n\n // Test that shuffle returns a new array\n const original = [1, 2, 3, 4, 5];\n const shuffled = shuffle(original);\n expect(shuffled).not.toBe(original);\n\n // Test that all elements are preserved\n expect(shuffled.sort((a, b) => a - b)).toEqual(original);\n\n // Test with a larger array to ensure randomness\n // This is a probabilistic test, but it's very unlikely to fail\n const large = Array.from({ length: 100 }, (_, i) => i);\n const shuffledLarge = shuffle(large);\n expect(shuffledLarge).not.toEqual(large);\n expect(shuffledLarge.sort((a, b) => a - b)).toEqual(large);\n});\n\n\nexport function outerProduct<T, U>(arr1: readonly T[], arr2: readonly U[]): [T, U][] {\n return arr1.flatMap((item1) => arr2.map((item2) => [item1, item2] as [T, U]));\n}\nundefined?.test(\"outerProduct\", ({ expect }) => {\n expect(outerProduct([], [])).toEqual([]);\n expect(outerProduct([1], [])).toEqual([]);\n expect(outerProduct([], [1])).toEqual([]);\n expect(outerProduct([1], [2])).toEqual([[1, 2]]);\n expect(outerProduct([1, 2], [3, 4])).toEqual([[1, 3], [1, 4], [2, 3], [2, 4]]);\n expect(outerProduct([\"a\", \"b\"], [1, 2])).toEqual([[\"a\", 1], [\"a\", 2], [\"b\", 1], [\"b\", 2]]);\n});\n\nexport function unique<T>(arr: readonly T[]): T[] {\n return [...new Set(arr)];\n}\nundefined?.test(\"unique\", ({ expect }) => {\n expect(unique([])).toEqual([]);\n expect(unique([1, 2, 3])).toEqual([1, 2, 3]);\n expect(unique([1, 2, 2, 3, 1, 3])).toEqual([1, 2, 3]);\n // Test with objects (reference equality)\n const obj = { a: 1 };\n expect(unique([obj, obj])).toEqual([obj]);\n // Test with different types\n expect(unique([1, \"1\", true, 1, \"1\", true])).toEqual([1, \"1\", true]);\n});\n"],"mappings":";AAAA,SAAS,iBAAiB;AAEnB,SAAS,cAAwC,KAAQ,MAAkC;AAChG,SAAO,IAAI,SAAS,IAAI;AAC1B;AAYO,SAAS,UAAoC,KAA+B;AACjF,SAAO,IAAI,IAAI,CAAC,MAAM,UAAU,CAAC,OAA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,QAAW,KAAwB;AACjD,QAAM,SAAS,CAAC,GAAG,GAAG;AACtB,WAAS,IAAI,OAAO,SAAS,GAAG,IAAI,GAAG,KAAK;AAC1C,UAAM,IAAI,KAAK,MAAM,KAAK,OAAO,KAAK,IAAI,EAAE;AAC5C,KAAC,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC;AAAA,EAChD;AACA,SAAO;AACT;AAyBO,SAAS,aAAmB,MAAoB,MAA8B;AACnF,SAAO,KAAK,QAAQ,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAC,OAAO,KAAK,CAAW,CAAC;AAC9E;AAUO,SAAS,OAAU,KAAwB;AAChD,SAAO,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC;AACzB;","names":[]}
1
+ {"version":3,"sources":["../../../src/utils/arrays.tsx"],"sourcesContent":["import { remainder } from \"./math\";\n\nexport function typedIncludes<T extends readonly any[]>(arr: T, item: unknown): item is T[number] {\n return arr.includes(item);\n}\nundefined?.test(\"typedIncludes\", ({ expect }) => {\n const arr = [1, 2, 3] as const;\n expect(typedIncludes(arr, 1)).toBe(true);\n expect(typedIncludes(arr, 4)).toBe(false);\n expect(typedIncludes(arr, \"1\")).toBe(false);\n\n const strArr = [\"a\", \"b\", \"c\"] as const;\n expect(typedIncludes(strArr, \"a\")).toBe(true);\n expect(typedIncludes(strArr, \"d\")).toBe(false);\n});\n\nexport function enumerate<T extends readonly any[]>(arr: T): [number, T[number]][] {\n return arr.map((item, index) => [index, item]);\n}\nundefined?.test(\"enumerate\", ({ expect }) => {\n expect(enumerate([])).toEqual([]);\n expect(enumerate([1, 2, 3])).toEqual([[0, 1], [1, 2], [2, 3]]);\n expect(enumerate([\"a\", \"b\", \"c\"])).toEqual([[0, \"a\"], [1, \"b\"], [2, \"c\"]]);\n});\n\nexport function isShallowEqual(a: readonly any[], b: readonly any[]): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\nundefined?.test(\"isShallowEqual\", ({ expect }) => {\n expect(isShallowEqual([], [])).toBe(true);\n expect(isShallowEqual([1, 2, 3], [1, 2, 3])).toBe(true);\n expect(isShallowEqual([1, 2, 3], [1, 2, 4])).toBe(false);\n expect(isShallowEqual([1, 2, 3], [1, 2])).toBe(false);\n expect(isShallowEqual([1, 2], [1, 2, 3])).toBe(false);\n // Test with objects (reference equality)\n const obj1 = { a: 1 };\n const obj2 = { a: 1 };\n expect(isShallowEqual([obj1], [obj1])).toBe(true);\n expect(isShallowEqual([obj1], [obj2])).toBe(false);\n});\n\n/**\n * Ponyfill for ES2023's findLastIndex.\n */\nexport function findLastIndex<T>(arr: readonly T[], predicate: (item: T) => boolean): number {\n for (let i = arr.length - 1; i >= 0; i--) {\n if (predicate(arr[i])) return i;\n }\n return -1;\n}\nundefined?.test(\"findLastIndex\", ({ expect }) => {\n expect(findLastIndex([], () => true)).toBe(-1);\n expect(findLastIndex([1, 2, 3, 4, 5], x => x % 2 === 0)).toBe(3); // 4 is at index 3\n expect(findLastIndex([1, 2, 3, 4, 5], x => x > 10)).toBe(-1);\n expect(findLastIndex([1, 2, 3, 2, 1], x => x === 2)).toBe(3);\n expect(findLastIndex([1, 2, 3], x => x === 1)).toBe(0);\n});\n\nexport function groupBy<T extends any, K>(\n arr: Iterable<T>,\n key: (item: T) => K,\n): Map<K, T[]> {\n const result = new Map<K, T[]>;\n for (const item of arr) {\n const k = key(item);\n if (result.get(k) === undefined) result.set(k, []);\n result.get(k)!.push(item);\n }\n return result;\n}\nundefined?.test(\"groupBy\", ({ expect }) => {\n expect(groupBy([], (x) => x)).toEqual(new Map());\n\n const numbers = [1, 2, 3, 4, 5, 6];\n const grouped = groupBy(numbers, (n) => n % 2 === 0 ? \"even\" : \"odd\");\n expect(grouped.get(\"even\")).toEqual([2, 4, 6]);\n expect(grouped.get(\"odd\")).toEqual([1, 3, 5]);\n\n // Check the actual lengths of the words to ensure our test is correct\n const words = [\"apple\", \"banana\", \"cherry\", \"date\", \"elderberry\"];\n\n const byLength = groupBy(words, (w) => w.length);\n // Adjust expectations based on actual word lengths\n expect(byLength.get(5)).toEqual([\"apple\"]);\n expect(byLength.get(6)).toEqual([\"banana\", \"cherry\"]);\n expect(byLength.get(4)).toEqual([\"date\"]);\n expect(byLength.get(10)).toEqual([\"elderberry\"]);\n});\n\nexport function range(endExclusive: number): number[];\nexport function range(startInclusive: number, endExclusive: number): number[];\nexport function range(startInclusive: number, endExclusive: number, step: number): number[];\nexport function range(startInclusive: number, endExclusive?: number, step?: number): number[] {\n if (endExclusive === undefined) {\n endExclusive = startInclusive;\n startInclusive = 0;\n }\n if (step === undefined) step = 1;\n\n const result = [];\n for (let i = startInclusive; step > 0 ? (i < endExclusive) : (i > endExclusive); i += step) {\n result.push(i);\n }\n return result;\n}\nundefined?.test(\"range\", ({ expect }) => {\n expect(range(5)).toEqual([0, 1, 2, 3, 4]);\n expect(range(2, 5)).toEqual([2, 3, 4]);\n expect(range(1, 10, 2)).toEqual([1, 3, 5, 7, 9]);\n expect(range(5, 0, -1)).toEqual([5, 4, 3, 2, 1]);\n expect(range(0, 0)).toEqual([]);\n expect(range(0, 10, 3)).toEqual([0, 3, 6, 9]);\n});\n\n\nexport function rotateLeft(arr: readonly any[], n: number): any[] {\n if (arr.length === 0) return [];\n const index = remainder(n, arr.length);\n return [...arr.slice(index), ...arr.slice(0, index)];\n}\nundefined?.test(\"rotateLeft\", ({ expect }) => {\n expect(rotateLeft([], 1)).toEqual([]);\n expect(rotateLeft([1, 2, 3, 4, 5], 0)).toEqual([1, 2, 3, 4, 5]);\n expect(rotateLeft([1, 2, 3, 4, 5], 1)).toEqual([2, 3, 4, 5, 1]);\n expect(rotateLeft([1, 2, 3, 4, 5], 3)).toEqual([4, 5, 1, 2, 3]);\n expect(rotateLeft([1, 2, 3, 4, 5], 5)).toEqual([1, 2, 3, 4, 5]);\n expect(rotateLeft([1, 2, 3, 4, 5], 6)).toEqual([2, 3, 4, 5, 1]);\n});\n\nexport function rotateRight(arr: readonly any[], n: number): any[] {\n return rotateLeft(arr, -n);\n}\nundefined?.test(\"rotateRight\", ({ expect }) => {\n expect(rotateRight([], 1)).toEqual([]);\n expect(rotateRight([1, 2, 3, 4, 5], 0)).toEqual([1, 2, 3, 4, 5]);\n expect(rotateRight([1, 2, 3, 4, 5], 1)).toEqual([5, 1, 2, 3, 4]);\n expect(rotateRight([1, 2, 3, 4, 5], 3)).toEqual([3, 4, 5, 1, 2]);\n expect(rotateRight([1, 2, 3, 4, 5], 5)).toEqual([1, 2, 3, 4, 5]);\n expect(rotateRight([1, 2, 3, 4, 5], 6)).toEqual([5, 1, 2, 3, 4]);\n});\n\n\nexport function shuffle<T>(arr: readonly T[]): T[] {\n const result = [...arr];\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n [result[i], result[j]] = [result[j], result[i]];\n }\n return result;\n}\nundefined?.test(\"shuffle\", ({ expect }) => {\n // Test empty array\n expect(shuffle([])).toEqual([]);\n\n // Test single element array\n expect(shuffle([1])).toEqual([1]);\n\n // Test that shuffle returns a new array\n const original = [1, 2, 3, 4, 5];\n const shuffled = shuffle(original);\n expect(shuffled).not.toBe(original);\n\n // Test that all elements are preserved\n expect(shuffled.sort((a, b) => a - b)).toEqual(original);\n\n // Test with a larger array to ensure randomness\n // This is a probabilistic test, but it's very unlikely to fail\n const large = Array.from({ length: 100 }, (_, i) => i);\n const shuffledLarge = shuffle(large);\n expect(shuffledLarge).not.toEqual(large);\n expect(shuffledLarge.sort((a, b) => a - b)).toEqual(large);\n});\n\n\nexport function outerProduct<T, U>(arr1: readonly T[], arr2: readonly U[]): [T, U][] {\n return arr1.flatMap((item1) => arr2.map((item2) => [item1, item2] as [T, U]));\n}\nundefined?.test(\"outerProduct\", ({ expect }) => {\n expect(outerProduct([], [])).toEqual([]);\n expect(outerProduct([1], [])).toEqual([]);\n expect(outerProduct([], [1])).toEqual([]);\n expect(outerProduct([1], [2])).toEqual([[1, 2]]);\n expect(outerProduct([1, 2], [3, 4])).toEqual([[1, 3], [1, 4], [2, 3], [2, 4]]);\n expect(outerProduct([\"a\", \"b\"], [1, 2])).toEqual([[\"a\", 1], [\"a\", 2], [\"b\", 1], [\"b\", 2]]);\n});\n\nexport function unique<T>(arr: readonly T[]): T[] {\n return [...new Set(arr)];\n}\nundefined?.test(\"unique\", ({ expect }) => {\n expect(unique([])).toEqual([]);\n expect(unique([1, 2, 3])).toEqual([1, 2, 3]);\n expect(unique([1, 2, 2, 3, 1, 3])).toEqual([1, 2, 3]);\n // Test with objects (reference equality)\n const obj = { a: 1 };\n expect(unique([obj, obj])).toEqual([obj]);\n // Test with different types\n expect(unique([1, \"1\", true, 1, \"1\", true])).toEqual([1, \"1\", true]);\n});\n\n\nexport function getChunks<T>(arr: readonly T[], size: number): T[][] {\n const result: T[][] = [];\n if (size <= 0) return result;\n for (let i = 0; i < arr.length; i += size) {\n result.push(arr.slice(i, i + size));\n }\n return result;\n}\nundefined?.test(\"getChunks\", ({ expect }) => {\n expect(getChunks([], 2)).toEqual([]);\n expect(getChunks([1], 2)).toEqual([[1]]);\n expect(getChunks([1, 2], 2)).toEqual([[1, 2]]);\n expect(getChunks([1, 2, 3], 2)).toEqual([[1, 2], [3]]);\n expect(getChunks([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);\n expect(getChunks([1, 2, 3, 4], 3)).toEqual([[1, 2, 3], [4]]);\n expect(getChunks([1, 2, 3], 0)).toEqual([]);\n expect(getChunks([1, 2, 3], -1)).toEqual([]);\n});\n\nexport function isStringArray(arr: unknown): arr is string[] {\n return Array.isArray(arr) && arr.every((item) => typeof item === \"string\");\n}\nexport function isNumberArray(arr: unknown): arr is number[] {\n return Array.isArray(arr) && arr.every((item) => typeof item === \"number\");\n}\nexport function isBooleanArray(arr: unknown): arr is boolean[] {\n return Array.isArray(arr) && arr.every((item) => typeof item === \"boolean\");\n}\nexport function isObjectArray(arr: unknown): arr is object[] {\n return Array.isArray(arr) && arr.every((item) => typeof item === \"object\" && item !== null);\n}\nundefined?.test(\"is<Type>Array\", ({ expect }) => {\n expect(isStringArray([])).toBe(true);\n expect(isNumberArray([1, 2, 3])).toBe(true);\n expect(isBooleanArray([true, false, true])).toBe(true);\n expect(isObjectArray([{ a: 1 }, { b: 2 }, { c: 3 }])).toBe(true);\n expect(isStringArray([1, 2, 3])).toBe(false);\n expect(isNumberArray([\"a\", \"b\", \"c\"])).toBe(false);\n expect(isBooleanArray([1, 2, 3])).toBe(false);\n expect(isObjectArray([1, 2, 3])).toBe(false);\n expect(isObjectArray([{ a: 1 }, null, { b: 2 }])).toBe(false);\n expect(isObjectArray([{ a: 1 }, undefined, { b: 2 }])).toBe(false);\n});\n"],"mappings":";AAAA,SAAS,iBAAiB;AAEnB,SAAS,cAAwC,KAAQ,MAAkC;AAChG,SAAO,IAAI,SAAS,IAAI;AAC1B;AAYO,SAAS,UAAoC,KAA+B;AACjF,SAAO,IAAI,IAAI,CAAC,MAAM,UAAU,CAAC,OAAO,IAAI,CAAC;AAC/C;AAOO,SAAS,eAAe,GAAmB,GAA4B;AAC5E,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,QAAI,EAAE,CAAC,MAAM,EAAE,CAAC,EAAG,QAAO;AAAA,EAC5B;AACA,SAAO;AACT;AAiBO,SAAS,cAAiB,KAAmB,WAAyC;AAC3F,WAAS,IAAI,IAAI,SAAS,GAAG,KAAK,GAAG,KAAK;AACxC,QAAI,UAAU,IAAI,CAAC,CAAC,EAAG,QAAO;AAAA,EAChC;AACA,SAAO;AACT;AASO,SAAS,QACd,KACA,KACa;AACb,QAAM,SAAS,oBAAI;AACnB,aAAW,QAAQ,KAAK;AACtB,UAAM,IAAI,IAAI,IAAI;AAClB,QAAI,OAAO,IAAI,CAAC,MAAM,OAAW,QAAO,IA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gB,CAAC;AACvB,MAAI,QAAQ,EAAG,QAAO;AACtB,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK,MAAM;AACzC,WAAO,KAAK,IAAI,MAAM,GAAG,IAAI,IAAI,CAAC;AAAA,EACpC;AACA,SAAO;AACT;AAYO,SAAS,cAAc,KAA+B;AAC3D,SAAO,MAAM,QAAQ,GAAG,KAAK,IAAI,MAAM,CAAC,SAAS,OAAO,SAAS,QAAQ;AAC3E;AACO,SAAS,cAAc,KAA+B;AAC3D,SAAO,MAAM,QAAQ,GAAG,KAAK,IAAI,MAAM,CAAC,SAAS,OAAO,SAAS,QAAQ;AAC3E;AACO,SAAS,eAAe,KAAgC;AAC7D,SAAO,MAAM,QAAQ,GAAG,KAAK,IAAI,MAAM,CAAC,SAAS,OAAO,SAAS,SAAS;AAC5E;AACO,SAAS,cAAc,KAA+B;AAC3D,SAAO,MAAM,QAAQ,GAAG,KAAK,IAAI,MAAM,CAAC,SAAS,OAAO,SAAS,YAAY,SAAS,IAAI;AAC5F;","names":[]}
@@ -11,12 +11,26 @@ globalThis.self ??= globalThis;
11
11
  function initializeEsbuild() {
12
12
  if (!esbuildInitializePromise) {
13
13
  esbuildInitializePromise = withTraceSpan("initializeEsbuild", async () => {
14
- await esbuild.initialize(isBrowserLike() ? {
15
- wasmURL: esbuildWasmUrl
16
- } : {
17
- wasmModule: await fetch(esbuildWasmUrl).then((wasm) => wasm.arrayBuffer()).then((wasm) => new WebAssembly.Module(wasm)),
18
- worker: false
19
- });
14
+ if (isBrowserLike()) {
15
+ await esbuild.initialize({
16
+ wasmURL: esbuildWasmUrl
17
+ });
18
+ } else {
19
+ const esbuildWasmResponse = await fetch(esbuildWasmUrl);
20
+ if (!esbuildWasmResponse.ok) {
21
+ throw new StackAssertionError(`Failed to fetch esbuild.wasm: ${esbuildWasmResponse.status} ${esbuildWasmResponse.statusText}: ${await esbuildWasmResponse.text()}`);
22
+ }
23
+ const esbuildWasm = await esbuildWasmResponse.arrayBuffer();
24
+ const esbuildWasmArray = new Uint8Array(esbuildWasm);
25
+ if (esbuildWasmArray[0] !== 0 || esbuildWasmArray[1] !== 97 || esbuildWasmArray[2] !== 115 || esbuildWasmArray[3] !== 109) {
26
+ throw new StackAssertionError(`Invalid esbuild.wasm file: ${new TextDecoder().decode(esbuildWasmArray)}`);
27
+ }
28
+ const esbuildWasmModule = new WebAssembly.Module(esbuildWasm);
29
+ await esbuild.initialize({
30
+ wasmModule: esbuildWasmModule,
31
+ worker: false
32
+ });
33
+ }
20
34
  })();
21
35
  }
22
36
  return esbuildInitializePromise;
@@ -26,6 +40,7 @@ async function bundleJavaScript(sourceFiles, options = {}) {
26
40
  const sourceFilesMap = new Map(Object.entries(sourceFiles));
27
41
  const externalPackagesMap = new Map(Object.entries(options.externalPackages ?? {}));
28
42
  const keepAsImports = options.keepAsImports ?? [];
43
+ const httpImportCache = /* @__PURE__ */ new Map();
29
44
  const extToLoader = /* @__PURE__ */ new Map([
30
45
  ["tsx", "tsx"],
31
46
  ["ts", "ts"],
@@ -47,6 +62,48 @@ async function bundleJavaScript(sourceFiles, options = {}) {
47
62
  sourcemap: options.sourcemap ?? "inline",
48
63
  external: keepAsImports,
49
64
  plugins: [
65
+ ...options.allowHttpImports ? [{
66
+ name: "esm-sh-only",
67
+ setup(build2) {
68
+ build2.onResolve({ filter: /.*/ }, (args) => {
69
+ const isHttp = args.path.startsWith("http://") || args.path.startsWith("https://");
70
+ const fromEsmNs = args.namespace === "esm-sh";
71
+ if (!isHttp && !fromEsmNs) return null;
72
+ const url = new URL(args.path, fromEsmNs ? args.importer : void 0);
73
+ if (url.protocol !== "https:" || url.host !== "esm.sh") {
74
+ throw new Error(`Blocked non-esm.sh URL import: ${url.href}`);
75
+ }
76
+ return { path: url.href, namespace: "esm-sh" };
77
+ });
78
+ build2.onLoad({ filter: /.*/, namespace: "esm-sh" }, async (args) => {
79
+ if (httpImportCache.has(args.path)) return httpImportCache.get(args.path);
80
+ const res = await fetch(args.path, { redirect: "follow" });
81
+ if (!res.ok) throw new Error(`Fetch ${res.status} ${res.statusText} for ${args.path}`);
82
+ const finalUrl = new URL(res.url);
83
+ if (finalUrl.host !== "esm.sh") {
84
+ throw new Error(`Redirect escaped esm.sh: ${finalUrl.href}`);
85
+ }
86
+ const ct = (res.headers.get("content-type") || "").toLowerCase();
87
+ let loader = ct.includes("css") ? "css" : ct.includes("json") ? "json" : ct.includes("typescript") ? "ts" : ct.includes("jsx") ? "jsx" : ct.includes("tsx") ? "tsx" : "js";
88
+ const p = finalUrl.pathname;
89
+ if (p.endsWith(".css")) loader = "css";
90
+ else if (p.endsWith(".json")) loader = "json";
91
+ else if (p.endsWith(".ts")) loader = "ts";
92
+ else if (p.endsWith(".tsx")) loader = "tsx";
93
+ else if (p.endsWith(".jsx")) loader = "jsx";
94
+ const contents = await res.text();
95
+ const result2 = {
96
+ contents,
97
+ loader,
98
+ // Ensures relative imports inside that module resolve against the file’s URL
99
+ resolveDir: new URL(".", finalUrl.href).toString(),
100
+ watchFiles: [finalUrl.href]
101
+ };
102
+ httpImportCache.set(args.path, result2);
103
+ return result2;
104
+ });
105
+ }
106
+ }] : [],
50
107
  {
51
108
  name: "replace-packages-with-globals",
52
109
  setup(build2) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/esbuild.tsx"],"sourcesContent":["import * as esbuild from 'esbuild-wasm/lib/browser.js';\nimport { join } from 'path';\nimport { isBrowserLike } from './env';\nimport { StackAssertionError, throwErr } from \"./errors\";\nimport { Result } from \"./results\";\nimport { traceSpan, withTraceSpan } from './telemetry';\n\nconst esbuildWasmUrl = `https://unpkg.com/esbuild-wasm@${esbuild.version}/esbuild.wasm`;\n\nlet esbuildInitializePromise: Promise<void> | null = null;\n// esbuild requires self property to be set, and it is not set by default in nodejs\n(globalThis.self as any) ??= globalThis as any;\n\nexport function initializeEsbuild(): Promise<void> {\n if (!esbuildInitializePromise) {\n esbuildInitializePromise = withTraceSpan('initializeEsbuild', async () => {\n await esbuild.initialize(isBrowserLike() ? {\n wasmURL: esbuildWasmUrl,\n } : {\n wasmModule: (\n await fetch(esbuildWasmUrl)\n .then(wasm => wasm.arrayBuffer())\n .then(wasm => new WebAssembly.Module(wasm))\n ),\n worker: false,\n });\n })();\n }\n\n return esbuildInitializePromise;\n}\n\nexport async function bundleJavaScript(sourceFiles: Record<string, string> & { '/entry.js': string }, options: {\n format?: 'iife' | 'esm' | 'cjs',\n externalPackages?: Record<string, string>,\n keepAsImports?: string[],\n sourcemap?: false | 'inline',\n} = {}): Promise<Result<string, string>> {\n await initializeEsbuild();\n\n const sourceFilesMap = new Map(Object.entries(sourceFiles));\n const externalPackagesMap = new Map(Object.entries(options.externalPackages ?? {}));\n const keepAsImports = options.keepAsImports ?? [];\n\n const extToLoader: Map<string, esbuild.Loader> = new Map([\n ['tsx', 'tsx'],\n ['ts', 'ts'],\n ['js', 'js'],\n ['jsx', 'jsx'],\n ['json', 'json'],\n ['css', 'css'],\n ]);\n let result;\n try {\n result = await traceSpan('bundleJavaScript', async () => await esbuild.build({\n entryPoints: ['/entry.js'],\n bundle: true,\n write: false,\n format: options.format ?? 'iife',\n platform: 'browser',\n target: 'es2015',\n jsx: 'automatic',\n sourcemap: options.sourcemap ?? 'inline',\n external: keepAsImports,\n plugins: [\n {\n name: 'replace-packages-with-globals',\n setup(build) {\n build.onResolve({ filter: /.*/ }, args => {\n // Skip packages that should remain external (not be shimmed)\n if (keepAsImports.includes(args.path)) {\n return undefined;\n }\n if (externalPackagesMap.has(args.path)) {\n return { path: args.path, namespace: 'package-shim' };\n }\n return undefined;\n });\n\n build.onLoad({ filter: /.*/, namespace: 'package-shim' }, (args) => {\n const contents = externalPackagesMap.get(args.path);\n if (contents == null) throw new StackAssertionError(`esbuild requested file ${args.path} that is not in the virtual file system`);\n\n return { contents, loader: 'ts' };\n });\n },\n },\n {\n name: 'virtual-fs',\n setup(build) {\n build.onResolve({ filter: /.*/ }, args => {\n const absolutePath = join(\"/\", args.path);\n if (sourceFilesMap.has(absolutePath)) {\n return { path: absolutePath, namespace: 'virtual' };\n }\n return undefined;\n });\n\n /* 2️⃣ Load the module from the map */\n build.onLoad({ filter: /.*/, namespace: 'virtual' }, args => {\n const contents = sourceFilesMap.get(args.path);\n if (contents == null) throw new StackAssertionError(`esbuild requested file ${args.path} that is not in the virtual file system`);\n\n const ext = args.path.split('.').pop() ?? '';\n const loader = extToLoader.get(ext) ?? throwErr(`esbuild requested file ${args.path} with unknown extension ${ext}`);\n\n return { contents, loader };\n });\n },\n },\n ],\n }));\n } catch (e) {\n if (e instanceof Error && e.message.startsWith(\"Build failed with \")) {\n return Result.error(e.message);\n }\n throw e;\n }\n\n if (result.errors.length > 0) {\n return Result.error(result.errors.map(e => e.text).join('\\n'));\n }\n\n if (result.outputFiles.length > 0) {\n return Result.ok(result.outputFiles[0].text);\n }\n return throwErr(\"No output generated??\");\n}\n"],"mappings":";AAAA,YAAY,aAAa;AACzB,SAAS,YAAY;AACrB,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB,gBAAgB;AAC9C,SAAS,cAAc;AACvB,SAAS,WAAW,qBAAqB;AAEzC,IAAM,iBAAiB,kCAA0C,eAAO;AAExE,IAAI,2BAAiD;AAEpD,WAAW,SAAiB;AAEtB,SAAS,oBAAmC;AACjD,MAAI,CAAC,0BAA0B;AAC7B,+BAA2B,cAAc,qBAAqB,YAAY;AACxE,YAAc,mBAAW,cAAc,IAAI;AAAA,QACzC,SAAS;AAAA,MACX,IAAI;AAAA,QACF,YACE,MAAM,MAAM,cAAc,EACvB,KAAK,UAAQ,KAAK,YAAY,CAAC,EAC/B,KAAK,UAAQ,IAAI,YAAY,OAAO,IAAI,CAAC;AAAA,QAE9C,QAAQ;AAAA,MACV,CAAC;AAAA,IACH,CAAC,EAAE;AAAA,EACL;AAEA,SAAO;AACT;AAEA,eAAsB,iBAAiB,aAA+D,UAKlG,CAAC,GAAoC;AACvC,QAAM,kBAAkB;AAExB,QAAM,iBAAiB,IAAI,IAAI,OA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esbuild-wasm/lib/browser.js';\nimport { join } from 'path';\nimport { isBrowserLike } from './env';\nimport { StackAssertionError, throwErr } from \"./errors\";\nimport { Result } from \"./results\";\nimport { traceSpan, withTraceSpan } from './telemetry';\n\nconst esbuildWasmUrl = `https://unpkg.com/esbuild-wasm@${esbuild.version}/esbuild.wasm`;\n\nlet esbuildInitializePromise: Promise<void> | null = null;\n// esbuild requires self property to be set, and it is not set by default in nodejs\n(globalThis.self as any) ??= globalThis as any;\n\nexport function initializeEsbuild(): Promise<void> {\n if (!esbuildInitializePromise) {\n esbuildInitializePromise = withTraceSpan('initializeEsbuild', async () => {\n if (isBrowserLike()) {\n await esbuild.initialize({\n wasmURL: esbuildWasmUrl,\n });\n } else {\n const esbuildWasmResponse = await fetch(esbuildWasmUrl);\n if (!esbuildWasmResponse.ok) {\n throw new StackAssertionError(`Failed to fetch esbuild.wasm: ${esbuildWasmResponse.status} ${esbuildWasmResponse.statusText}: ${await esbuildWasmResponse.text()}`);\n }\n const esbuildWasm = await esbuildWasmResponse.arrayBuffer();\n const esbuildWasmArray = new Uint8Array(esbuildWasm);\n if (esbuildWasmArray[0] !== 0x00 || esbuildWasmArray[1] !== 0x61 || esbuildWasmArray[2] !== 0x73 || esbuildWasmArray[3] !== 0x6d) {\n throw new StackAssertionError(`Invalid esbuild.wasm file: ${new TextDecoder().decode(esbuildWasmArray)}`);\n }\n const esbuildWasmModule = new WebAssembly.Module(esbuildWasm);\n await esbuild.initialize({\n wasmModule: esbuildWasmModule,\n worker: false,\n });\n }\n })();\n }\n\n return esbuildInitializePromise;\n}\n\nexport async function bundleJavaScript(sourceFiles: Record<string, string> & { '/entry.js': string }, options: {\n format?: 'iife' | 'esm' | 'cjs',\n externalPackages?: Record<string, string>,\n keepAsImports?: string[],\n sourcemap?: false | 'inline',\n allowHttpImports?: boolean,\n} = {}): Promise<Result<string, string>> {\n await initializeEsbuild();\n\n const sourceFilesMap = new Map(Object.entries(sourceFiles));\n const externalPackagesMap = new Map(Object.entries(options.externalPackages ?? {}));\n const keepAsImports = options.keepAsImports ?? [];\n\n const httpImportCache = new Map<string, { contents: string, loader: esbuild.Loader, resolveDir: string }>();\n\n const extToLoader: Map<string, esbuild.Loader> = new Map([\n ['tsx', 'tsx'],\n ['ts', 'ts'],\n ['js', 'js'],\n ['jsx', 'jsx'],\n ['json', 'json'],\n ['css', 'css'],\n ]);\n let result;\n try {\n result = await traceSpan('bundleJavaScript', async () => await esbuild.build({\n entryPoints: ['/entry.js'],\n bundle: true,\n write: false,\n format: options.format ?? 'iife',\n platform: 'browser',\n target: 'es2015',\n jsx: 'automatic',\n sourcemap: options.sourcemap ?? 'inline',\n external: keepAsImports,\n plugins: [\n ...options.allowHttpImports ? [{\n name: \"esm-sh-only\",\n setup(build: esbuild.PluginBuild) {\n // Handle absolute URLs and relative imports from esm.sh modules.\n build.onResolve({ filter: /.*/ }, (args) => {\n // Only touch absolute http(s) specifiers or children of our own namespace\n const isHttp = args.path.startsWith(\"http://\") || args.path.startsWith(\"https://\");\n const fromEsmNs = args.namespace === \"esm-sh\";\n\n if (!isHttp && !fromEsmNs) return null; // Let other plugins handle bare/relative/local\n\n // Resolve relative URLs inside esm.sh-fetched modules\n const url = new URL(args.path, fromEsmNs ? args.importer : undefined);\n\n if (url.protocol !== \"https:\" || url.host !== \"esm.sh\") {\n throw new Error(`Blocked non-esm.sh URL import: ${url.href}`);\n }\n\n return { path: url.href, namespace: \"esm-sh\" };\n });\n\n build.onLoad({ filter: /.*/, namespace: \"esm-sh\" }, async (args) => {\n if (httpImportCache.has(args.path)) return httpImportCache.get(args.path)!;\n\n const res = await fetch(args.path, { redirect: \"follow\" });\n if (!res.ok) throw new Error(`Fetch ${res.status} ${res.statusText} for ${args.path}`);\n const finalUrl = new URL(res.url);\n // Defensive: follow shouldn’t leave esm.sh, but re-check.\n if (finalUrl.host !== \"esm.sh\") {\n throw new Error(`Redirect escaped esm.sh: ${finalUrl.href}`);\n }\n\n const ct = (res.headers.get(\"content-type\") || \"\").toLowerCase();\n let loader: esbuild.Loader =\n ct.includes(\"css\") ? \"css\" :\n ct.includes(\"json\") ? \"json\" :\n ct.includes(\"typescript\") ? \"ts\" :\n ct.includes(\"jsx\") ? \"jsx\" :\n ct.includes(\"tsx\") ? \"tsx\" :\n \"js\";\n\n // Fallback by extension (esm.sh sometimes omits CT)\n const p = finalUrl.pathname;\n if (p.endsWith(\".css\")) loader = \"css\";\n else if (p.endsWith(\".json\")) loader = \"json\";\n else if (p.endsWith(\".ts\")) loader = \"ts\";\n else if (p.endsWith(\".tsx\")) loader = \"tsx\";\n else if (p.endsWith(\".jsx\")) loader = \"jsx\";\n\n const contents = await res.text();\n const result = {\n contents,\n loader,\n // Ensures relative imports inside that module resolve against the file’s URL\n resolveDir: new URL(\".\", finalUrl.href).toString(),\n watchFiles: [finalUrl.href],\n };\n httpImportCache.set(args.path, result);\n return result;\n });\n },\n } as esbuild.Plugin] : [],\n {\n name: 'replace-packages-with-globals',\n setup(build) {\n build.onResolve({ filter: /.*/ }, args => {\n // Skip packages that should remain external (not be shimmed)\n if (keepAsImports.includes(args.path)) {\n return undefined;\n }\n if (externalPackagesMap.has(args.path)) {\n return { path: args.path, namespace: 'package-shim' };\n }\n return undefined;\n });\n\n build.onLoad({ filter: /.*/, namespace: 'package-shim' }, (args) => {\n const contents = externalPackagesMap.get(args.path);\n if (contents == null) throw new StackAssertionError(`esbuild requested file ${args.path} that is not in the virtual file system`);\n\n return { contents, loader: 'ts' };\n });\n },\n },\n {\n name: 'virtual-fs',\n setup(build) {\n build.onResolve({ filter: /.*/ }, args => {\n const absolutePath = join(\"/\", args.path);\n if (sourceFilesMap.has(absolutePath)) {\n return { path: absolutePath, namespace: 'virtual' };\n }\n return undefined;\n });\n\n /* 2️⃣ Load the module from the map */\n build.onLoad({ filter: /.*/, namespace: 'virtual' }, args => {\n const contents = sourceFilesMap.get(args.path);\n if (contents == null) throw new StackAssertionError(`esbuild requested file ${args.path} that is not in the virtual file system`);\n\n const ext = args.path.split('.').pop() ?? '';\n const loader = extToLoader.get(ext) ?? throwErr(`esbuild requested file ${args.path} with unknown extension ${ext}`);\n\n return { contents, loader };\n });\n },\n },\n ],\n }));\n } catch (e) {\n if (e instanceof Error && e.message.startsWith(\"Build failed with \")) {\n return Result.error(e.message);\n }\n throw e;\n }\n\n if (result.errors.length > 0) {\n return Result.error(result.errors.map(e => e.text).join('\\n'));\n }\n\n if (result.outputFiles.length > 0) {\n return Result.ok(result.outputFiles[0].text);\n }\n return throwErr(\"No output generated??\");\n}\n"],"mappings":";AAAA,YAAY,aAAa;AACzB,SAAS,YAAY;AACrB,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB,gBAAgB;AAC9C,SAAS,cAAc;AACvB,SAAS,WAAW,qBAAqB;AAEzC,IAAM,iBAAiB,kCAA0C,eAAO;AAExE,IAAI,2BAAiD;AAEpD,WAAW,SAAiB;AAEtB,SAAS,oBAAmC;AACjD,MAAI,CAAC,0BAA0B;AAC7B,+BAA2B,cAAc,qBAAqB,YAAY;AACxE,UAAI,cAAc,GAAG;AACnB,cAAc,mBAAW;AAAA,UACvB,SAAS;AAAA,QACX,CAAC;AAAA,MACH,OAAO;AACL,cAAM,sBAAsB,MAAM,MAAM,cAAc;AACtD,YAAI,CAAC,oBAAoB,IAAI;AAC3B,gBAAM,IAAI,oBAAoB,iCAAiC,oBAAoB,MAAM,IAAI,oBAAoB,UAAU,KAAK,MAAM,oBAAoB,KAAK,CAAC,EAAE;AAAA,QACpK;AACA,cAAM,cAAc,MAAM,oBAAoB,YAAY;AAC1D,cAAM,mBAAmB,IAAI,WAAW,WAAW;AACnD,YAAI,iBAAiB,CAAC,MAAM,KAAQ,iBAAiB,CAAC,MAAM,MAAQ,iBAAiB,CAAC,MAAM,OAAQ,iBAAiB,CAAC,MAAM,KAAM;AAChI,gBAAM,IAAI,oBAAoB,8BAA8B,IAAI,YAAY,EAAE,OAAO,gBAAgB,CAAC,EAAE;AAAA,QAC1G;AACA,cAAM,oBAAoB,IA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