@stackframe/stack-shared 2.8.10 → 2.8.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/config/{schema.d.cts → schema.d.mts} +38 -33
- package/dist/config/schema.d.ts +37 -32
- package/dist/config/schema.js +5 -3
- package/dist/config/schema.js.map +1 -1
- package/dist/{crud.d.cts → crud.d.mts} +1 -1
- package/dist/esm/config/schema.js +5 -3
- package/dist/esm/config/schema.js.map +1 -1
- package/dist/esm/interface/clientInterface.js +8 -6
- package/dist/esm/interface/clientInterface.js.map +1 -1
- package/dist/esm/interface/crud/project-api-keys.js +20 -15
- package/dist/esm/interface/crud/project-api-keys.js.map +1 -1
- package/dist/esm/interface/crud/projects.js +5 -12
- package/dist/esm/interface/crud/projects.js.map +1 -1
- package/dist/esm/interface/serverInterface.js +28 -2
- package/dist/esm/interface/serverInterface.js.map +1 -1
- package/dist/esm/known-errors.js +43 -1
- package/dist/esm/known-errors.js.map +1 -1
- package/dist/esm/schema-fields.js +2 -0
- package/dist/esm/schema-fields.js.map +1 -1
- package/dist/esm/utils/errors.js +4 -0
- package/dist/esm/utils/errors.js.map +1 -1
- package/dist/esm/utils/hashes.js +1 -1
- package/dist/esm/utils/hashes.js.map +1 -1
- package/dist/esm/utils/objects.js +24 -0
- package/dist/esm/utils/objects.js.map +1 -1
- package/dist/esm/utils/promises.js +1 -1
- package/dist/esm/utils/promises.js.map +1 -1
- package/dist/esm/utils/strings.js +1 -0
- package/dist/esm/utils/strings.js.map +1 -1
- package/dist/helpers/password.d.mts +11 -0
- package/dist/helpers/{production-mode.d.cts → production-mode.d.mts} +3 -3
- package/dist/hooks/use-async-callback.js +1 -1
- package/dist/hooks/{use-async-external-store.d.cts → use-async-external-store.d.mts} +1 -1
- package/dist/index.d.mts +30 -0
- package/dist/interface/{adminInterface.d.cts → adminInterface.d.mts} +26 -26
- package/dist/interface/{clientInterface.d.cts → clientInterface.d.mts} +18 -18
- package/dist/interface/clientInterface.js +8 -6
- package/dist/interface/clientInterface.js.map +1 -1
- package/dist/interface/crud/{contact-channels.d.cts → contact-channels.d.mts} +2 -2
- package/dist/interface/crud/{current-user.d.cts → current-user.d.mts} +2 -2
- package/dist/interface/crud/{email-templates.d.cts → email-templates.d.mts} +2 -2
- package/dist/interface/crud/{emails.d.cts → emails.d.mts} +2 -2
- package/dist/interface/crud/emails.js +1 -1
- package/dist/interface/crud/{internal-api-keys.d.cts → internal-api-keys.d.mts} +2 -2
- package/dist/interface/crud/{oauth.d.cts → oauth.d.mts} +2 -2
- package/dist/interface/crud/{project-api-keys.d.cts → project-api-keys.d.mts} +14 -4
- package/dist/interface/crud/project-api-keys.d.ts +12 -2
- package/dist/interface/crud/project-api-keys.js +20 -15
- package/dist/interface/crud/project-api-keys.js.map +1 -1
- package/dist/interface/crud/{project-permissions.d.cts → project-permissions.d.mts} +2 -2
- package/dist/interface/crud/project-permissions.js +1 -1
- package/dist/interface/crud/{projects.d.cts → projects.d.mts} +9 -22
- package/dist/interface/crud/projects.d.ts +7 -20
- package/dist/interface/crud/projects.js +6 -13
- package/dist/interface/crud/projects.js.map +1 -1
- package/dist/interface/crud/{sessions.d.cts → sessions.d.mts} +2 -2
- package/dist/interface/crud/{svix-token.d.cts → svix-token.d.mts} +2 -2
- package/dist/interface/crud/{team-invitation-details.d.cts → team-invitation-details.d.mts} +2 -2
- package/dist/interface/crud/team-invitation-details.js +1 -1
- package/dist/interface/crud/{team-invitation.d.cts → team-invitation.d.mts} +2 -2
- package/dist/interface/crud/team-invitation.js +1 -1
- package/dist/interface/crud/{team-member-profiles.d.cts → team-member-profiles.d.mts} +2 -2
- package/dist/interface/crud/team-member-profiles.js +1 -1
- package/dist/interface/crud/{team-memberships.d.cts → team-memberships.d.mts} +2 -2
- package/dist/interface/crud/{team-permissions.d.cts → team-permissions.d.mts} +2 -2
- package/dist/interface/crud/team-permissions.js +1 -1
- package/dist/interface/crud/{teams.d.cts → teams.d.mts} +2 -2
- package/dist/interface/crud/teams.js +1 -1
- package/dist/interface/crud/{users.d.cts → users.d.mts} +2 -2
- package/dist/interface/crud/users.js +1 -1
- package/dist/interface/{serverInterface.d.cts → serverInterface.d.mts} +23 -21
- package/dist/interface/serverInterface.d.ts +2 -0
- package/dist/interface/serverInterface.js +28 -2
- package/dist/interface/serverInterface.js.map +1 -1
- package/dist/{known-errors.d.cts → known-errors.d.mts} +14 -3
- package/dist/known-errors.d.ts +11 -0
- package/dist/known-errors.js +43 -1
- package/dist/known-errors.js.map +1 -1
- package/dist/{schema-fields.d.cts → schema-fields.d.mts} +2 -1
- package/dist/schema-fields.d.ts +2 -1
- package/dist/schema-fields.js +4 -1
- package/dist/schema-fields.js.map +1 -1
- package/dist/sessions.js +1 -1
- package/dist/utils/api-keys.js +1 -1
- package/dist/utils/{caches.d.cts → caches.d.mts} +2 -2
- package/dist/utils/{errors.d.cts → errors.d.mts} +4 -2
- package/dist/utils/errors.d.ts +2 -0
- package/dist/utils/errors.js +4 -0
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/fs.js +2 -2
- package/dist/utils/hashes.js +6 -6
- package/dist/utils/hashes.js.map +1 -1
- package/dist/utils/ips.js +1 -1
- package/dist/utils/{json.d.cts → json.d.mts} +1 -1
- package/dist/utils/jwt.js +3 -3
- package/dist/utils/{objects.d.cts → objects.d.mts} +9 -5
- package/dist/utils/objects.d.ts +9 -5
- package/dist/utils/objects.js +28 -0
- package/dist/utils/objects.js.map +1 -1
- package/dist/utils/{promises.d.cts → promises.d.mts} +1 -1
- package/dist/utils/promises.js +1 -1
- package/dist/utils/promises.js.map +1 -1
- package/dist/utils/react.js +1 -1
- package/dist/utils/{stores.d.cts → stores.d.mts} +3 -3
- package/dist/utils/strings.js +1 -0
- package/dist/utils/strings.js.map +1 -1
- package/package.json +9 -6
- package/dist/helpers/password.d.cts +0 -11
- package/dist/index.d.cts +0 -30
- /package/dist/config/{format.d.cts → format.d.mts} +0 -0
- /package/dist/{global.d.d.cts → global.d.d.mts} +0 -0
- /package/dist/hooks/{use-async-callback.d.cts → use-async-callback.d.mts} +0 -0
- /package/dist/hooks/{use-hash.d.cts → use-hash.d.mts} +0 -0
- /package/dist/hooks/{use-strict-memo.d.cts → use-strict-memo.d.mts} +0 -0
- /package/dist/interface/{webhooks.d.cts → webhooks.d.mts} +0 -0
- /package/dist/{sessions.d.cts → sessions.d.mts} +0 -0
- /package/dist/utils/{api-keys.d.cts → api-keys.d.mts} +0 -0
- /package/dist/utils/{arrays.d.cts → arrays.d.mts} +0 -0
- /package/dist/utils/{base64.d.cts → base64.d.mts} +0 -0
- /package/dist/utils/{booleans.d.cts → booleans.d.mts} +0 -0
- /package/dist/utils/{browser-compat.d.cts → browser-compat.d.mts} +0 -0
- /package/dist/utils/{bytes.d.cts → bytes.d.mts} +0 -0
- /package/dist/utils/{compile-time.d.cts → compile-time.d.mts} +0 -0
- /package/dist/utils/{crypto.d.cts → crypto.d.mts} +0 -0
- /package/dist/utils/{dates.d.cts → dates.d.mts} +0 -0
- /package/dist/utils/{dom.d.cts → dom.d.mts} +0 -0
- /package/dist/utils/{env.d.cts → env.d.mts} +0 -0
- /package/dist/utils/{fs.d.cts → fs.d.mts} +0 -0
- /package/dist/utils/{functions.d.cts → functions.d.mts} +0 -0
- /package/dist/utils/{geo.d.cts → geo.d.mts} +0 -0
- /package/dist/utils/{globals.d.cts → globals.d.mts} +0 -0
- /package/dist/utils/{hashes.d.cts → hashes.d.mts} +0 -0
- /package/dist/utils/{html.d.cts → html.d.mts} +0 -0
- /package/dist/utils/{http.d.cts → http.d.mts} +0 -0
- /package/dist/utils/{ips.d.cts → ips.d.mts} +0 -0
- /package/dist/utils/{jwt.d.cts → jwt.d.mts} +0 -0
- /package/dist/utils/{locks.d.cts → locks.d.mts} +0 -0
- /package/dist/utils/{maps.d.cts → maps.d.mts} +0 -0
- /package/dist/utils/{math.d.cts → math.d.mts} +0 -0
- /package/dist/utils/{node-http.d.cts → node-http.d.mts} +0 -0
- /package/dist/utils/{numbers.d.cts → numbers.d.mts} +0 -0
- /package/dist/utils/{oauth.d.cts → oauth.d.mts} +0 -0
- /package/dist/utils/{passkey.d.cts → passkey.d.mts} +0 -0
- /package/dist/utils/{proxies.d.cts → proxies.d.mts} +0 -0
- /package/dist/utils/{react.d.cts → react.d.mts} +0 -0
- /package/dist/utils/{results.d.cts → results.d.mts} +0 -0
- /package/dist/utils/{sentry.d.cts → sentry.d.mts} +0 -0
- /package/dist/utils/{strings.d.cts → strings.d.mts} +0 -0
- /package/dist/utils/{strings.nicify.test.d.cts → strings.nicify.test.d.mts} +0 -0
- /package/dist/utils/{types.d.cts → types.d.mts} +0 -0
- /package/dist/utils/{unicode.d.cts → unicode.d.mts} +0 -0
- /package/dist/utils/{urls.d.cts → urls.d.mts} +0 -0
- /package/dist/utils/{uuids.d.cts → uuids.d.mts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config/schema.ts"],"sourcesContent":["import * as yup from \"yup\";\nimport * as schemaFields from \"../schema-fields\";\nimport { yupBoolean, yupObject, yupRecord, yupString } from \"../schema-fields\";\nimport { allProviders } from \"../utils/oauth\";\nimport { DeepMerge, get, has, isObjectLike, set } from \"../utils/objects\";\nimport { PrettifyType } from \"../utils/types\";\nimport { NormalizesTo } from \"./format\";\n\n// NOTE: The validation schemas in here are all schematic validators, not sanity-check validators.\n// For more info, see ./README.md\n\n\nexport const configLevels = ['project', 'branch', 'environment', 'organization'] as const;\nexport type ConfigLevel = typeof configLevels[number];\nconst permissionRegex = /^\\$?[a-z0-9_:]+$/;\n\n/**\n * All fields that can be overridden at this level.\n */\nexport const projectConfigSchema = yupObject({});\n\n// --- NEW RBAC Schema ---\nconst branchRbacDefaultPermissions = yupRecord(\n yupString().optional().matches(permissionRegex),\n yupBoolean().isTrue().optional(),\n).optional();\n\nconst branchRbacSchema = yupObject({\n permissions: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupObject({\n description: yupString().optional(),\n scope: yupString().oneOf(['team', 'project']).optional(),\n containedPermissionIds: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupBoolean().isTrue().optional()\n ).optional(),\n }).optional(),\n ).optional(),\n defaultPermissions: yupObject({\n teamCreator: branchRbacDefaultPermissions,\n teamMember: branchRbacDefaultPermissions,\n signUp: branchRbacDefaultPermissions,\n }).optional(),\n}).optional();\n// --- END NEW RBAC Schema ---\n\n// --- NEW API Keys Schema ---\nconst branchApiKeysSchema = yupObject({\n enabled: yupObject({\n team: yupBoolean().optional(),\n user: yupBoolean().optional(),\n }).optional(),\n}).optional();\n// --- END NEW API Keys Schema ---\n\n\nconst branchAuthSchema = yupObject({\n allowSignUp: yupBoolean().optional(),\n password: yupObject({\n allowSignIn: yupBoolean().optional(),\n }).optional(),\n otp: yupObject({\n allowSignIn: yupBoolean().optional(),\n }).optional(),\n passkey: yupObject({\n allowSignIn: yupBoolean().optional(),\n }).optional(),\n oauth: yupObject({\n accountMergeStrategy: yupString().oneOf(['link_method', 'raise_error', 'allow_duplicates']).optional(),\n providers: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupObject({\n type: yupString().oneOf(allProviders).optional(),\n allowSignIn: yupBoolean().optional(),\n allowConnectedAccounts: yupBoolean().optional(),\n }).defined(),\n ).optional(),\n }).optional(),\n}).optional();\n\nconst branchDomain = yupObject({\n allowLocalhost: yupBoolean().optional(),\n}).optional();\n\nexport const branchConfigSchema = projectConfigSchema.concat(yupObject({\n rbac: branchRbacSchema,\n\n teams: yupObject({\n createPersonalTeamOnSignUp: yupBoolean().optional(),\n allowClientTeamCreation: yupBoolean().optional(),\n }).optional(),\n\n users: yupObject({\n allowClientUserDeletion: yupBoolean().optional(),\n }).optional(),\n\n apiKeys: branchApiKeysSchema,\n\n domains: branchDomain,\n\n auth: branchAuthSchema,\n\n emails: yupObject({}),\n}));\n\n\nexport const environmentConfigSchema = branchConfigSchema.concat(yupObject({\n auth: branchConfigSchema.getNested(\"auth\").concat(yupObject({\n oauth: branchConfigSchema.getNested(\"auth\").getNested(\"oauth\").concat(yupObject({\n providers: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupObject({\n type: yupString().oneOf(allProviders).optional(),\n isShared: yupBoolean().optional(),\n clientId: schemaFields.oauthClientIdSchema.optional(),\n clientSecret: schemaFields.oauthClientSecretSchema.optional(),\n facebookConfigId: schemaFields.oauthFacebookConfigIdSchema.optional(),\n microsoftTenantId: schemaFields.oauthMicrosoftTenantIdSchema.optional(),\n allowSignIn: yupBoolean().optional(),\n allowConnectedAccounts: yupBoolean().optional(),\n }),\n ).optional(),\n }).optional()),\n })),\n\n emails: branchConfigSchema.getNested(\"emails\").concat(yupObject({\n server: yupObject({\n isShared: yupBoolean().optional(),\n host: schemaFields.emailHostSchema.optional().nonEmpty(),\n port: schemaFields.emailPortSchema.optional(),\n username: schemaFields.emailUsernameSchema.optional().nonEmpty(),\n password: schemaFields.emailPasswordSchema.optional().nonEmpty(),\n senderName: schemaFields.emailSenderNameSchema.optional().nonEmpty(),\n senderEmail: schemaFields.emailSenderEmailSchema.optional().nonEmpty(),\n }),\n }).optional()),\n\n domains: branchConfigSchema.getNested(\"domains\").concat(yupObject({\n trustedDomains: yupRecord(\n yupString().uuid().optional(),\n yupObject({\n baseUrl: schemaFields.urlSchema.optional(),\n handlerPath: schemaFields.handlerPathSchema.optional(),\n }),\n ).optional(),\n })),\n}));\n\nexport const organizationConfigSchema = environmentConfigSchema.concat(yupObject({}));\n\n\n// Defaults\n// these are objects that are merged together to form the rendered config (see ./README.md)\n// Wherever an object could be used as a value, a function can instead be used to generate the default values on a per-key basis\nexport const projectConfigDefaults = {} satisfies DeepReplaceAllowFunctionsForObjects<ProjectConfigStrippedNormalizedOverride>;\n\nexport const branchConfigDefaults = {} satisfies DeepReplaceAllowFunctionsForObjects<BranchConfigStrippedNormalizedOverride>;\n\nexport const environmentConfigDefaults = {} satisfies DeepReplaceAllowFunctionsForObjects<EnvironmentConfigStrippedNormalizedOverride>;\n\nexport const organizationConfigDefaults = {\n rbac: {\n permissions: (key: string) => ({}),\n defaultPermissions: {\n teamCreator: {},\n teamMember: {},\n signUp: {},\n },\n },\n\n apiKeys: {\n enabled: {\n team: false,\n user: false,\n },\n },\n\n teams: {\n createPersonalTeamOnSignUp: false,\n allowClientTeamCreation: false,\n },\n\n users: {\n allowClientUserDeletion: false,\n },\n\n domains: {\n allowLocalhost: false,\n trustedDomains: (key: string) => ({\n handlerPath: '/handler',\n }),\n },\n\n auth: {\n allowSignUp: true,\n password: {\n allowSignIn: false,\n },\n otp: {\n allowSignIn: false,\n },\n passkey: {\n allowSignIn: false,\n },\n oauth: {\n accountMergeStrategy: 'link_method',\n providers: (key: string) => ({\n allowSignIn: false,\n allowConnectedAccounts: false,\n }),\n },\n },\n\n emails: {\n server: {\n isShared: true,\n },\n },\n} satisfies DeepReplaceAllowFunctionsForObjects<OrganizationConfigStrippedNormalizedOverride>;\n\nexport type DeepReplaceAllowFunctionsForObjects<T> = T extends object ? { [K in keyof T]: DeepReplaceAllowFunctionsForObjects<T[K]> } | ((arg: keyof T) => DeepReplaceAllowFunctionsForObjects<T[keyof T]>) : T;\nexport type DeepReplaceFunctionsWithObjects<T> = T extends (arg: infer K extends string) => infer R ? DeepReplaceFunctionsWithObjects<Record<K, R>> : (T extends object ? { [K in keyof T]: DeepReplaceFunctionsWithObjects<T[K]> } : T);\nexport type ApplyDefaults<D extends object | ((key: string) => unknown), C extends object> = DeepMerge<DeepReplaceFunctionsWithObjects<D>, C>;\nexport function applyDefaults<D extends object | ((key: string) => unknown), C extends object>(defaults: D, config: C): ApplyDefaults<D, C> {\n const res: any = { ...typeof defaults === 'function' ? {} : defaults };\n for (const [key, mergeValue] of Object.entries(config)) {\n const baseValue = typeof defaults === 'function' ? defaults(key) : (has(defaults, key as any) ? get(defaults, key as any) : undefined);\n if (baseValue !== undefined) {\n if (isObjectLike(baseValue) && isObjectLike(mergeValue)) {\n set(res, key, applyDefaults(baseValue, mergeValue));\n continue;\n }\n }\n set(res, key, mergeValue);\n }\n return res as any;\n}\nundefined?.test(\"applyDefaults\", ({ expect }) => {\n expect(applyDefaults({ a: 1 }, { a: 2 })).toEqual({ a: 2 });\n expect(applyDefaults({ a: { b: 1 } }, { a: { c: 2 } })).toEqual({ a: { b: 1, c: 2 } });\n expect(applyDefaults((key: string) => ({ b: key }), { a: {} })).toEqual({ a: { b: \"a\" } });\n expect(applyDefaults({ a: (key: string) => ({ b: key }) }, { a: { c: { d: 1 } } })).toEqual({ a: { c: { b: \"c\", d: 1 } } });\n});\n\n// Normalized overrides\nexport type ProjectConfigNormalizedOverride = yup.InferType<typeof projectConfigSchema>;\nexport type BranchConfigNormalizedOverride = yup.InferType<typeof branchConfigSchema>;\nexport type EnvironmentConfigNormalizedOverride = yup.InferType<typeof environmentConfigSchema>;\nexport type OrganizationConfigNormalizedOverride = yup.InferType<typeof organizationConfigSchema>;\n\n// Normalized overrides, without the properties that may be overridden still\nexport type ProjectConfigStrippedNormalizedOverride = Omit<ProjectConfigNormalizedOverride,\n | keyof BranchConfigNormalizedOverride\n | keyof EnvironmentConfigNormalizedOverride\n | keyof OrganizationConfigNormalizedOverride\n>;\nexport type BranchConfigStrippedNormalizedOverride = Omit<BranchConfigNormalizedOverride,\n | keyof EnvironmentConfigNormalizedOverride\n | keyof OrganizationConfigNormalizedOverride\n>;\nexport type EnvironmentConfigStrippedNormalizedOverride = Omit<EnvironmentConfigNormalizedOverride,\n | keyof OrganizationConfigNormalizedOverride\n>;\nexport type OrganizationConfigStrippedNormalizedOverride = OrganizationConfigNormalizedOverride;\n\n// Overrides\nexport type ProjectConfigOverride = NormalizesTo<ProjectConfigNormalizedOverride>;\nexport type BranchConfigOverride = NormalizesTo<BranchConfigNormalizedOverride>;\nexport type EnvironmentConfigOverride = NormalizesTo<EnvironmentConfigNormalizedOverride>;\nexport type OrganizationConfigOverride = NormalizesTo<OrganizationConfigNormalizedOverride>;\n\n// Incomplete configs\nexport type ProjectIncompleteConfig = ProjectConfigNormalizedOverride;\nexport type BranchIncompleteConfig = ProjectIncompleteConfig & BranchConfigNormalizedOverride;\nexport type EnvironmentIncompleteConfig = BranchIncompleteConfig & EnvironmentConfigNormalizedOverride;\nexport type OrganizationIncompleteConfig = EnvironmentIncompleteConfig & OrganizationConfigNormalizedOverride;\n\n// Rendered configs\nexport type ProjectRenderedConfig = PrettifyType<ApplyDefaults<typeof projectConfigDefaults, ProjectConfigStrippedNormalizedOverride>>;\nexport type BranchRenderedConfig = PrettifyType<ProjectRenderedConfig & ApplyDefaults<typeof branchConfigDefaults, BranchConfigStrippedNormalizedOverride>>;\nexport type EnvironmentRenderedConfig = PrettifyType<BranchRenderedConfig & ApplyDefaults<typeof environmentConfigDefaults, EnvironmentConfigStrippedNormalizedOverride>>;\nexport type OrganizationRenderedConfig = PrettifyType<EnvironmentRenderedConfig & ApplyDefaults<typeof organizationConfigDefaults, OrganizationConfigStrippedNormalizedOverride>>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA8B;AAC9B,2BAA4D;AAC5D,mBAA6B;AAC7B,qBAAuD;AAQhD,IAAM,eAAe,CAAC,WAAW,UAAU,eAAe,cAAc;AAE/E,IAAM,kBAAkB;AAKjB,IAAM,0BAAsB,gCAAU,CAAC,CAAC;AAG/C,IAAM,mCAA+B;AAAA,MACnC,gCAAU,EAAE,SAAS,EAAE,QAAQ,eAAe;AAAA,MAC9C,iCAAW,EAAE,OAAO,EAAE,SAAS;AACjC,EAAE,SAAS;AAEX,IAAM,uBAAmB,gCAAU;AAAA,EACjC,iBAAa;AAAA,QACX,gCAAU,EAAE,SAAS,EAAE,QAAQ,eAAe;AAAA,QAC9C,gCAAU;AAAA,MACR,iBAAa,gCAAU,EAAE,SAAS;AAAA,MAClC,WAAO,gCAAU,EAAE,MAAM,CAAC,QAAQ,SAAS,CAA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C3B;AAAA,EAEA,OAAO;AAAA,IACL,yBAAyB;AAAA,EAC3B;AAAA,EAEA,SAAS;AAAA,IACP,gBAAgB;AAAA,IAChB,gBAAgB,CAAC,SAAiB;AAAA,MAChC,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EAEA,MAAM;AAAA,IACJ,aAAa;AAAA,IACb,UAAU;AAAA,MACR,aAAa;AAAA,IACf;AAAA,IACA,KAAK;AAAA,MACH,aAAa;AAAA,IACf;AAAA,IACA,SAAS;AAAA,MACP,aAAa;AAAA,IACf;AAAA,IACA,OAAO;AAAA,MACL,sBAAsB;AAAA,MACtB,WAAW,CAAC,SAAiB;AAAA,QAC3B,aAAa;AAAA,QACb,wBAAwB;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAQ;AAAA,IACN,QAAQ;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,EACF;AACF;AAKO,SAAS,cAA+E,UAAa,QAAgC;AAC1I,QAAM,MAAW,EAAE,GAAG,OAAO,aAAa,aAAa,CAAC,IAAI,SAAS;AACrE,aAAW,CAAC,KAAK,UAAU,KAAK,OAAO,QAAQ,MAAM,GAAG;AACtD,UAAM,YAAY,OAAO,aAAa,aAAa,SAAS,GAAG,QAAK,oBAAI,UAAU,GAAU,QAAI,oBAAI,UAAU,GAAU,IAAI;AAC5H,QAAI,cAAc,QAAW;AAC3B,cAAI,6BAAa,SAAS,SAAK,6BAAa,UAAU,GAAG;AACvD,gCAAI,KAAK,KAAK,cAAc,WAAW,UAAU,CAAC;AAClD;AAAA,MACF;AAAA,IACF;AACA,4BAAI,KAAK,KAAK,UAAU;AAAA,EAC1B;AACA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/config/schema.ts"],"sourcesContent":["import * as yup from \"yup\";\nimport * as schemaFields from \"../schema-fields\";\nimport { yupBoolean, yupObject, yupRecord, yupString } from \"../schema-fields\";\nimport { allProviders } from \"../utils/oauth\";\nimport { DeepMerge, DeepPartial, get, has, isObjectLike, mapValues, set } from \"../utils/objects\";\nimport { PrettifyType } from \"../utils/types\";\nimport { Config, NormalizesTo } from \"./format\";\n\n// NOTE: The validation schemas in here are all schematic validators, not sanity-check validators.\n// For more info, see ./README.md\n\n\nexport const configLevels = ['project', 'branch', 'environment', 'organization'] as const;\nexport type ConfigLevel = typeof configLevels[number];\nconst permissionRegex = /^\\$?[a-z0-9_:]+$/;\nconst customPermissionRegex = /^[a-z0-9_:]+$/;\n\n/**\n * All fields that can be overridden at this level.\n */\nexport const projectConfigSchema = yupObject({});\n\n// --- NEW RBAC Schema ---\nconst branchRbacDefaultPermissions = yupRecord(\n yupString().optional().matches(permissionRegex),\n yupBoolean().isTrue().optional(),\n).optional();\n\nconst branchRbacSchema = yupObject({\n permissions: yupRecord(\n yupString().optional().matches(customPermissionRegex),\n yupObject({\n description: yupString().optional(),\n scope: yupString().oneOf(['team', 'project']).optional(),\n containedPermissionIds: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupBoolean().isTrue().optional()\n ).optional(),\n }).optional(),\n ).optional(),\n defaultPermissions: yupObject({\n teamCreator: branchRbacDefaultPermissions,\n teamMember: branchRbacDefaultPermissions,\n signUp: branchRbacDefaultPermissions,\n }).optional(),\n}).optional();\n// --- END NEW RBAC Schema ---\n\n// --- NEW API Keys Schema ---\nconst branchApiKeysSchema = yupObject({\n enabled: yupObject({\n team: yupBoolean().optional(),\n user: yupBoolean().optional(),\n }).optional(),\n}).optional();\n// --- END NEW API Keys Schema ---\n\n\nconst branchAuthSchema = yupObject({\n allowSignUp: yupBoolean().optional(),\n password: yupObject({\n allowSignIn: yupBoolean().optional(),\n }).optional(),\n otp: yupObject({\n allowSignIn: yupBoolean().optional(),\n }).optional(),\n passkey: yupObject({\n allowSignIn: yupBoolean().optional(),\n }).optional(),\n oauth: yupObject({\n accountMergeStrategy: yupString().oneOf(['link_method', 'raise_error', 'allow_duplicates']).optional(),\n providers: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupObject({\n type: yupString().oneOf(allProviders).optional(),\n allowSignIn: yupBoolean().optional(),\n allowConnectedAccounts: yupBoolean().optional(),\n }).defined(),\n ).optional(),\n }).optional(),\n}).optional();\n\nconst branchDomain = yupObject({\n allowLocalhost: yupBoolean().optional(),\n}).optional();\n\nexport const branchConfigSchema = projectConfigSchema.concat(yupObject({\n rbac: branchRbacSchema,\n\n teams: yupObject({\n createPersonalTeamOnSignUp: yupBoolean().optional(),\n allowClientTeamCreation: yupBoolean().optional(),\n }).optional(),\n\n users: yupObject({\n allowClientUserDeletion: yupBoolean().optional(),\n }).optional(),\n\n apiKeys: branchApiKeysSchema,\n\n domains: branchDomain,\n\n auth: branchAuthSchema,\n\n emails: yupObject({}),\n}));\n\n\nexport const environmentConfigSchema = branchConfigSchema.concat(yupObject({\n auth: branchConfigSchema.getNested(\"auth\").concat(yupObject({\n oauth: branchConfigSchema.getNested(\"auth\").getNested(\"oauth\").concat(yupObject({\n providers: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupObject({\n type: yupString().oneOf(allProviders).optional(),\n isShared: yupBoolean().optional(),\n clientId: schemaFields.oauthClientIdSchema.optional(),\n clientSecret: schemaFields.oauthClientSecretSchema.optional(),\n facebookConfigId: schemaFields.oauthFacebookConfigIdSchema.optional(),\n microsoftTenantId: schemaFields.oauthMicrosoftTenantIdSchema.optional(),\n allowSignIn: yupBoolean().optional(),\n allowConnectedAccounts: yupBoolean().optional(),\n }),\n ).optional(),\n }).optional()),\n })),\n\n emails: branchConfigSchema.getNested(\"emails\").concat(yupObject({\n server: yupObject({\n isShared: yupBoolean().optional(),\n host: schemaFields.emailHostSchema.optional().nonEmpty(),\n port: schemaFields.emailPortSchema.optional(),\n username: schemaFields.emailUsernameSchema.optional().nonEmpty(),\n password: schemaFields.emailPasswordSchema.optional().nonEmpty(),\n senderName: schemaFields.emailSenderNameSchema.optional().nonEmpty(),\n senderEmail: schemaFields.emailSenderEmailSchema.optional().nonEmpty(),\n }),\n }).optional()),\n\n domains: branchConfigSchema.getNested(\"domains\").concat(yupObject({\n trustedDomains: yupRecord(\n yupString().uuid().optional(),\n yupObject({\n baseUrl: schemaFields.urlSchema.optional(),\n handlerPath: schemaFields.handlerPathSchema.optional(),\n }),\n ).optional(),\n })),\n}));\n\nexport const organizationConfigSchema = environmentConfigSchema.concat(yupObject({}));\n\n\n// Defaults\n// these are objects that are merged together to form the rendered config (see ./README.md)\n// Wherever an object could be used as a value, a function can instead be used to generate the default values on a per-key basis\nexport const projectConfigDefaults = {} satisfies DeepReplaceAllowFunctionsForObjects<ProjectConfigStrippedNormalizedOverride>;\n\nexport const branchConfigDefaults = {} satisfies DeepReplaceAllowFunctionsForObjects<BranchConfigStrippedNormalizedOverride>;\n\nexport const environmentConfigDefaults = {} satisfies DeepReplaceAllowFunctionsForObjects<EnvironmentConfigStrippedNormalizedOverride>;\n\nexport const organizationConfigDefaults = {\n rbac: {\n permissions: (key: string) => ({}),\n defaultPermissions: {\n teamCreator: {},\n teamMember: {},\n signUp: {},\n },\n },\n\n apiKeys: {\n enabled: {\n team: false,\n user: false,\n },\n },\n\n teams: {\n createPersonalTeamOnSignUp: false,\n allowClientTeamCreation: false,\n },\n\n users: {\n allowClientUserDeletion: false,\n },\n\n domains: {\n allowLocalhost: false,\n trustedDomains: (key: string) => ({\n handlerPath: '/handler',\n }),\n },\n\n auth: {\n allowSignUp: true,\n password: {\n allowSignIn: false,\n },\n otp: {\n allowSignIn: false,\n },\n passkey: {\n allowSignIn: false,\n },\n oauth: {\n accountMergeStrategy: 'link_method',\n providers: (key: string) => ({\n isShared: true,\n allowSignIn: false,\n allowConnectedAccounts: false,\n }),\n },\n },\n\n emails: {\n server: {\n isShared: true,\n },\n },\n} satisfies DeepReplaceAllowFunctionsForObjects<OrganizationConfigStrippedNormalizedOverride>;\n\nexport type DeepReplaceAllowFunctionsForObjects<T> = T extends object ? { [K in keyof T]: DeepReplaceAllowFunctionsForObjects<T[K]> } | ((arg: keyof T) => DeepReplaceAllowFunctionsForObjects<T[keyof T]>) : T;\nexport type DeepReplaceFunctionsWithObjects<T> = T extends (arg: infer K extends string) => infer R ? DeepReplaceFunctionsWithObjects<Record<K, R>> : (T extends object ? { [K in keyof T]: DeepReplaceFunctionsWithObjects<T[K]> } : T);\nexport type ApplyDefaults<D extends object | ((key: string) => unknown), C extends object> = DeepMerge<DeepReplaceFunctionsWithObjects<D>, C>;\nexport function applyDefaults<D extends object | ((key: string) => unknown), C extends object>(defaults: D, config: C): ApplyDefaults<D, C> {\n const res: any = typeof defaults === 'function' ? {} : mapValues(defaults, v => typeof v === 'function' ? {} : (typeof v === 'object' ? applyDefaults(v as any, {}) : v));\n for (const [key, mergeValue] of Object.entries(config)) {\n const baseValue = typeof defaults === 'function' ? defaults(key) : (has(defaults, key as any) ? get(defaults, key as any) : undefined);\n if (baseValue !== undefined) {\n if (isObjectLike(baseValue) && isObjectLike(mergeValue)) {\n set(res, key, applyDefaults(baseValue, mergeValue));\n continue;\n }\n }\n set(res, key, mergeValue);\n }\n return res as any;\n}\nundefined?.test(\"applyDefaults\", ({ expect }) => {\n expect(applyDefaults({ a: 1 }, { a: 2 })).toEqual({ a: 2 });\n expect(applyDefaults({ a: { b: 1 } }, { a: { c: 2 } })).toEqual({ a: { b: 1, c: 2 } });\n expect(applyDefaults((key: string) => ({ b: key }), { a: {} })).toEqual({ a: { b: \"a\" } });\n expect(applyDefaults({ a: (key: string) => ({ b: key }) }, { a: { c: { d: 1 } } })).toEqual({ a: { c: { b: \"c\", d: 1 } } });\n expect(applyDefaults({ a: (key: string) => ({ b: key }) }, {})).toEqual({ a: {} });\n expect(applyDefaults({ a: { b: (key: string) => ({ b: key }) } }, {})).toEqual({ a: { b: {} } });\n});\n\n// Normalized overrides\nexport type ProjectConfigNormalizedOverride = yup.InferType<typeof projectConfigSchema>;\nexport type BranchConfigNormalizedOverride = yup.InferType<typeof branchConfigSchema>;\nexport type EnvironmentConfigNormalizedOverride = yup.InferType<typeof environmentConfigSchema>;\nexport type OrganizationConfigNormalizedOverride = yup.InferType<typeof organizationConfigSchema>;\n\n// Normalized overrides, without the properties that may be overridden still\nexport type ProjectConfigStrippedNormalizedOverride = Omit<ProjectConfigNormalizedOverride,\n | keyof BranchConfigNormalizedOverride\n | keyof EnvironmentConfigNormalizedOverride\n | keyof OrganizationConfigNormalizedOverride\n>;\nexport type BranchConfigStrippedNormalizedOverride = Omit<BranchConfigNormalizedOverride,\n | keyof EnvironmentConfigNormalizedOverride\n | keyof OrganizationConfigNormalizedOverride\n>;\nexport type EnvironmentConfigStrippedNormalizedOverride = Omit<EnvironmentConfigNormalizedOverride,\n | keyof OrganizationConfigNormalizedOverride\n>;\nexport type OrganizationConfigStrippedNormalizedOverride = OrganizationConfigNormalizedOverride;\n\n// Overrides\nexport type ProjectConfigOverride = NormalizesTo<ProjectConfigNormalizedOverride>;\nexport type BranchConfigOverride = NormalizesTo<BranchConfigNormalizedOverride>;\nexport type EnvironmentConfigOverride = NormalizesTo<EnvironmentConfigNormalizedOverride>;\nexport type OrganizationConfigOverride = NormalizesTo<OrganizationConfigNormalizedOverride>;\n\n// Override overrides (used to update the overrides)\nexport type ProjectConfigOverrideOverride = Config & DeepPartial<ProjectConfigOverride>;\nexport type BranchConfigOverrideOverride = Config & DeepPartial<BranchConfigOverride>;\nexport type EnvironmentConfigOverrideOverride = Config & DeepPartial<EnvironmentConfigOverride>;\nexport type OrganizationConfigOverrideOverride = Config & DeepPartial<OrganizationConfigOverride>;\n\n// Incomplete configs\nexport type ProjectIncompleteConfig = ProjectConfigNormalizedOverride;\nexport type BranchIncompleteConfig = ProjectIncompleteConfig & BranchConfigNormalizedOverride;\nexport type EnvironmentIncompleteConfig = BranchIncompleteConfig & EnvironmentConfigNormalizedOverride;\nexport type OrganizationIncompleteConfig = EnvironmentIncompleteConfig & OrganizationConfigNormalizedOverride;\n\n// Rendered configs\nexport type ProjectRenderedConfig = PrettifyType<ApplyDefaults<typeof projectConfigDefaults, ProjectConfigStrippedNormalizedOverride>>;\nexport type BranchRenderedConfig = PrettifyType<ProjectRenderedConfig & ApplyDefaults<typeof branchConfigDefaults, BranchConfigStrippedNormalizedOverride>>;\nexport type EnvironmentRenderedConfig = PrettifyType<BranchRenderedConfig & ApplyDefaults<typeof environmentConfigDefaults, EnvironmentConfigStrippedNormalizedOverride>>;\nexport type OrganizationRenderedConfig = PrettifyType<EnvironmentRenderedConfig & ApplyDefaults<typeof organizationConfigDefaults, OrganizationConfigStrippedNormalizedOverride>>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA8B;AAC9B,2BAA4D;AAC5D,mBAA6B;AAC7B,qBAA+E;AAQxE,IAAM,eAAe,CAAC,WAAW,UAAU,eAAe,cAAc;AAE/E,IAAM,kBAAkB;AACxB,IAAM,wBAAwB;AAKvB,IAAM,0BAAsB,gCAAU,CAAC,CAAC;AAG/C,IAAM,mCAA+B;AAAA,MACnC,gCAAU,EAAE,SAAS,EAAE,QAAQ,eAAe;AAAA,MAC9C,iCAAW,EAAE,OAAO,EAAE,SAAS;AACjC,EAAE,SAAS;AAEX,IAAM,uBAAmB,gCAAU;AAAA,EACjC,iBAAa;AAAA,QACX,gCAAU,EAAE,SAAS,EAAE,QAAQ,qBAAqB;AAAA,QACpD,gCAAU;AAAA,MACR,iBAAa,gCAAU,EAAE,SAAS;AAAA,MAClC,WAAO,gCAAU,EAAE,MAAM,CAAC,QAAQ,SAAS,CAAC,EAAE,SAAS;AAAA,MACvD,4BAAwB;AAAA,YACtB,gCAAU,EAAE,SAAS,EAAE,QAAQ,eAAe;AAAA,YAC9C,iCAAW,EAAE,OAAO,EAAE,SAAS;AAAA,MACjC,EAAE,SAAS;AAAA,IACb,CAAC,EAAE,SAAS;AAAA,EACd,EAAE,SAAS;AAAA,EACX,wBAAoB,gCAAU;AAAA,IAC5B,aAAa;AAAA,IACb,YAA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AA,MACH,aAAa;AAAA,IACf;AAAA,IACA,SAAS;AAAA,MACP,aAAa;AAAA,IACf;AAAA,IACA,OAAO;AAAA,MACL,sBAAsB;AAAA,MACtB,WAAW,CAAC,SAAiB;AAAA,QAC3B,UAAU;AAAA,QACV,aAAa;AAAA,QACb,wBAAwB;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAQ;AAAA,IACN,QAAQ;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,EACF;AACF;AAKO,SAAS,cAA+E,UAAa,QAAgC;AAC1I,QAAM,MAAW,OAAO,aAAa,aAAa,CAAC,QAAI,0BAAU,UAAU,OAAK,OAAO,MAAM,aAAa,CAAC,IAAK,OAAO,MAAM,WAAW,cAAc,GAAU,CAAC,CAAC,IAAI,CAAE;AACxK,aAAW,CAAC,KAAK,UAAU,KAAK,OAAO,QAAQ,MAAM,GAAG;AACtD,UAAM,YAAY,OAAO,aAAa,aAAa,SAAS,GAAG,QAAK,oBAAI,UAAU,GAAU,QAAI,oBAAI,UAAU,GAAU,IAAI;AAC5H,QAAI,cAAc,QAAW;AAC3B,cAAI,6BAAa,SAAS,SAAK,6BAAa,UAAU,GAAG;AACvD,gCAAI,KAAK,KAAK,cAAc,WAAW,UAAU,CAAC;AAClD;AAAA,MACF;AAAA,IACF;AACA,4BAAI,KAAK,KAAK,UAAU;AAAA,EAC1B;AACA,SAAO;AACT;","names":[]}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
import * as schemaFields from "../schema-fields";
|
|
3
3
|
import { yupBoolean, yupObject, yupRecord, yupString } from "../schema-fields";
|
|
4
4
|
import { allProviders } from "../utils/oauth";
|
|
5
|
-
import { get, has, isObjectLike, set } from "../utils/objects";
|
|
5
|
+
import { get, has, isObjectLike, mapValues, set } from "../utils/objects";
|
|
6
6
|
var configLevels = ["project", "branch", "environment", "organization"];
|
|
7
7
|
var permissionRegex = /^\$?[a-z0-9_:]+$/;
|
|
8
|
+
var customPermissionRegex = /^[a-z0-9_:]+$/;
|
|
8
9
|
var projectConfigSchema = yupObject({});
|
|
9
10
|
var branchRbacDefaultPermissions = yupRecord(
|
|
10
11
|
yupString().optional().matches(permissionRegex),
|
|
@@ -12,7 +13,7 @@ var branchRbacDefaultPermissions = yupRecord(
|
|
|
12
13
|
).optional();
|
|
13
14
|
var branchRbacSchema = yupObject({
|
|
14
15
|
permissions: yupRecord(
|
|
15
|
-
yupString().optional().matches(
|
|
16
|
+
yupString().optional().matches(customPermissionRegex),
|
|
16
17
|
yupObject({
|
|
17
18
|
description: yupString().optional(),
|
|
18
19
|
scope: yupString().oneOf(["team", "project"]).optional(),
|
|
@@ -159,6 +160,7 @@ var organizationConfigDefaults = {
|
|
|
159
160
|
oauth: {
|
|
160
161
|
accountMergeStrategy: "link_method",
|
|
161
162
|
providers: (key) => ({
|
|
163
|
+
isShared: true,
|
|
162
164
|
allowSignIn: false,
|
|
163
165
|
allowConnectedAccounts: false
|
|
164
166
|
})
|
|
@@ -171,7 +173,7 @@ var organizationConfigDefaults = {
|
|
|
171
173
|
}
|
|
172
174
|
};
|
|
173
175
|
function applyDefaults(defaults, config) {
|
|
174
|
-
const res =
|
|
176
|
+
const res = typeof defaults === "function" ? {} : mapValues(defaults, (v) => typeof v === "function" ? {} : typeof v === "object" ? applyDefaults(v, {}) : v);
|
|
175
177
|
for (const [key, mergeValue] of Object.entries(config)) {
|
|
176
178
|
const baseValue = typeof defaults === "function" ? defaults(key) : has(defaults, key) ? get(defaults, key) : void 0;
|
|
177
179
|
if (baseValue !== void 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/schema.ts"],"sourcesContent":["import * as yup from \"yup\";\nimport * as schemaFields from \"../schema-fields\";\nimport { yupBoolean, yupObject, yupRecord, yupString } from \"../schema-fields\";\nimport { allProviders } from \"../utils/oauth\";\nimport { DeepMerge, get, has, isObjectLike, set } from \"../utils/objects\";\nimport { PrettifyType } from \"../utils/types\";\nimport { NormalizesTo } from \"./format\";\n\n// NOTE: The validation schemas in here are all schematic validators, not sanity-check validators.\n// For more info, see ./README.md\n\n\nexport const configLevels = ['project', 'branch', 'environment', 'organization'] as const;\nexport type ConfigLevel = typeof configLevels[number];\nconst permissionRegex = /^\\$?[a-z0-9_:]+$/;\n\n/**\n * All fields that can be overridden at this level.\n */\nexport const projectConfigSchema = yupObject({});\n\n// --- NEW RBAC Schema ---\nconst branchRbacDefaultPermissions = yupRecord(\n yupString().optional().matches(permissionRegex),\n yupBoolean().isTrue().optional(),\n).optional();\n\nconst branchRbacSchema = yupObject({\n permissions: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupObject({\n description: yupString().optional(),\n scope: yupString().oneOf(['team', 'project']).optional(),\n containedPermissionIds: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupBoolean().isTrue().optional()\n ).optional(),\n }).optional(),\n ).optional(),\n defaultPermissions: yupObject({\n teamCreator: branchRbacDefaultPermissions,\n teamMember: branchRbacDefaultPermissions,\n signUp: branchRbacDefaultPermissions,\n }).optional(),\n}).optional();\n// --- END NEW RBAC Schema ---\n\n// --- NEW API Keys Schema ---\nconst branchApiKeysSchema = yupObject({\n enabled: yupObject({\n team: yupBoolean().optional(),\n user: yupBoolean().optional(),\n }).optional(),\n}).optional();\n// --- END NEW API Keys Schema ---\n\n\nconst branchAuthSchema = yupObject({\n allowSignUp: yupBoolean().optional(),\n password: yupObject({\n allowSignIn: yupBoolean().optional(),\n }).optional(),\n otp: yupObject({\n allowSignIn: yupBoolean().optional(),\n }).optional(),\n passkey: yupObject({\n allowSignIn: yupBoolean().optional(),\n }).optional(),\n oauth: yupObject({\n accountMergeStrategy: yupString().oneOf(['link_method', 'raise_error', 'allow_duplicates']).optional(),\n providers: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupObject({\n type: yupString().oneOf(allProviders).optional(),\n allowSignIn: yupBoolean().optional(),\n allowConnectedAccounts: yupBoolean().optional(),\n }).defined(),\n ).optional(),\n }).optional(),\n}).optional();\n\nconst branchDomain = yupObject({\n allowLocalhost: yupBoolean().optional(),\n}).optional();\n\nexport const branchConfigSchema = projectConfigSchema.concat(yupObject({\n rbac: branchRbacSchema,\n\n teams: yupObject({\n createPersonalTeamOnSignUp: yupBoolean().optional(),\n allowClientTeamCreation: yupBoolean().optional(),\n }).optional(),\n\n users: yupObject({\n allowClientUserDeletion: yupBoolean().optional(),\n }).optional(),\n\n apiKeys: branchApiKeysSchema,\n\n domains: branchDomain,\n\n auth: branchAuthSchema,\n\n emails: yupObject({}),\n}));\n\n\nexport const environmentConfigSchema = branchConfigSchema.concat(yupObject({\n auth: branchConfigSchema.getNested(\"auth\").concat(yupObject({\n oauth: branchConfigSchema.getNested(\"auth\").getNested(\"oauth\").concat(yupObject({\n providers: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupObject({\n type: yupString().oneOf(allProviders).optional(),\n isShared: yupBoolean().optional(),\n clientId: schemaFields.oauthClientIdSchema.optional(),\n clientSecret: schemaFields.oauthClientSecretSchema.optional(),\n facebookConfigId: schemaFields.oauthFacebookConfigIdSchema.optional(),\n microsoftTenantId: schemaFields.oauthMicrosoftTenantIdSchema.optional(),\n allowSignIn: yupBoolean().optional(),\n allowConnectedAccounts: yupBoolean().optional(),\n }),\n ).optional(),\n }).optional()),\n })),\n\n emails: branchConfigSchema.getNested(\"emails\").concat(yupObject({\n server: yupObject({\n isShared: yupBoolean().optional(),\n host: schemaFields.emailHostSchema.optional().nonEmpty(),\n port: schemaFields.emailPortSchema.optional(),\n username: schemaFields.emailUsernameSchema.optional().nonEmpty(),\n password: schemaFields.emailPasswordSchema.optional().nonEmpty(),\n senderName: schemaFields.emailSenderNameSchema.optional().nonEmpty(),\n senderEmail: schemaFields.emailSenderEmailSchema.optional().nonEmpty(),\n }),\n }).optional()),\n\n domains: branchConfigSchema.getNested(\"domains\").concat(yupObject({\n trustedDomains: yupRecord(\n yupString().uuid().optional(),\n yupObject({\n baseUrl: schemaFields.urlSchema.optional(),\n handlerPath: schemaFields.handlerPathSchema.optional(),\n }),\n ).optional(),\n })),\n}));\n\nexport const organizationConfigSchema = environmentConfigSchema.concat(yupObject({}));\n\n\n// Defaults\n// these are objects that are merged together to form the rendered config (see ./README.md)\n// Wherever an object could be used as a value, a function can instead be used to generate the default values on a per-key basis\nexport const projectConfigDefaults = {} satisfies DeepReplaceAllowFunctionsForObjects<ProjectConfigStrippedNormalizedOverride>;\n\nexport const branchConfigDefaults = {} satisfies DeepReplaceAllowFunctionsForObjects<BranchConfigStrippedNormalizedOverride>;\n\nexport const environmentConfigDefaults = {} satisfies DeepReplaceAllowFunctionsForObjects<EnvironmentConfigStrippedNormalizedOverride>;\n\nexport const organizationConfigDefaults = {\n rbac: {\n permissions: (key: string) => ({}),\n defaultPermissions: {\n teamCreator: {},\n teamMember: {},\n signUp: {},\n },\n },\n\n apiKeys: {\n enabled: {\n team: false,\n user: false,\n },\n },\n\n teams: {\n createPersonalTeamOnSignUp: false,\n allowClientTeamCreation: false,\n },\n\n users: {\n allowClientUserDeletion: false,\n },\n\n domains: {\n allowLocalhost: false,\n trustedDomains: (key: string) => ({\n handlerPath: '/handler',\n }),\n },\n\n auth: {\n allowSignUp: true,\n password: {\n allowSignIn: false,\n },\n otp: {\n allowSignIn: false,\n },\n passkey: {\n allowSignIn: false,\n },\n oauth: {\n accountMergeStrategy: 'link_method',\n providers: (key: string) => ({\n allowSignIn: false,\n allowConnectedAccounts: false,\n }),\n },\n },\n\n emails: {\n server: {\n isShared: true,\n },\n },\n} satisfies DeepReplaceAllowFunctionsForObjects<OrganizationConfigStrippedNormalizedOverride>;\n\nexport type DeepReplaceAllowFunctionsForObjects<T> = T extends object ? { [K in keyof T]: DeepReplaceAllowFunctionsForObjects<T[K]> } | ((arg: keyof T) => DeepReplaceAllowFunctionsForObjects<T[keyof T]>) : T;\nexport type DeepReplaceFunctionsWithObjects<T> = T extends (arg: infer K extends string) => infer R ? DeepReplaceFunctionsWithObjects<Record<K, R>> : (T extends object ? { [K in keyof T]: DeepReplaceFunctionsWithObjects<T[K]> } : T);\nexport type ApplyDefaults<D extends object | ((key: string) => unknown), C extends object> = DeepMerge<DeepReplaceFunctionsWithObjects<D>, C>;\nexport function applyDefaults<D extends object | ((key: string) => unknown), C extends object>(defaults: D, config: C): ApplyDefaults<D, C> {\n const res: any = { ...typeof defaults === 'function' ? {} : defaults };\n for (const [key, mergeValue] of Object.entries(config)) {\n const baseValue = typeof defaults === 'function' ? defaults(key) : (has(defaults, key as any) ? get(defaults, key as any) : undefined);\n if (baseValue !== undefined) {\n if (isObjectLike(baseValue) && isObjectLike(mergeValue)) {\n set(res, key, applyDefaults(baseValue, mergeValue));\n continue;\n }\n }\n set(res, key, mergeValue);\n }\n return res as any;\n}\nundefined?.test(\"applyDefaults\", ({ expect }) => {\n expect(applyDefaults({ a: 1 }, { a: 2 })).toEqual({ a: 2 });\n expect(applyDefaults({ a: { b: 1 } }, { a: { c: 2 } })).toEqual({ a: { b: 1, c: 2 } });\n expect(applyDefaults((key: string) => ({ b: key }), { a: {} })).toEqual({ a: { b: \"a\" } });\n expect(applyDefaults({ a: (key: string) => ({ b: key }) }, { a: { c: { d: 1 } } })).toEqual({ a: { c: { b: \"c\", d: 1 } } });\n});\n\n// Normalized overrides\nexport type ProjectConfigNormalizedOverride = yup.InferType<typeof projectConfigSchema>;\nexport type BranchConfigNormalizedOverride = yup.InferType<typeof branchConfigSchema>;\nexport type EnvironmentConfigNormalizedOverride = yup.InferType<typeof environmentConfigSchema>;\nexport type OrganizationConfigNormalizedOverride = yup.InferType<typeof organizationConfigSchema>;\n\n// Normalized overrides, without the properties that may be overridden still\nexport type ProjectConfigStrippedNormalizedOverride = Omit<ProjectConfigNormalizedOverride,\n | keyof BranchConfigNormalizedOverride\n | keyof EnvironmentConfigNormalizedOverride\n | keyof OrganizationConfigNormalizedOverride\n>;\nexport type BranchConfigStrippedNormalizedOverride = Omit<BranchConfigNormalizedOverride,\n | keyof EnvironmentConfigNormalizedOverride\n | keyof OrganizationConfigNormalizedOverride\n>;\nexport type EnvironmentConfigStrippedNormalizedOverride = Omit<EnvironmentConfigNormalizedOverride,\n | keyof OrganizationConfigNormalizedOverride\n>;\nexport type OrganizationConfigStrippedNormalizedOverride = OrganizationConfigNormalizedOverride;\n\n// Overrides\nexport type ProjectConfigOverride = NormalizesTo<ProjectConfigNormalizedOverride>;\nexport type BranchConfigOverride = NormalizesTo<BranchConfigNormalizedOverride>;\nexport type EnvironmentConfigOverride = NormalizesTo<EnvironmentConfigNormalizedOverride>;\nexport type OrganizationConfigOverride = NormalizesTo<OrganizationConfigNormalizedOverride>;\n\n// Incomplete configs\nexport type ProjectIncompleteConfig = ProjectConfigNormalizedOverride;\nexport type BranchIncompleteConfig = ProjectIncompleteConfig & BranchConfigNormalizedOverride;\nexport type EnvironmentIncompleteConfig = BranchIncompleteConfig & EnvironmentConfigNormalizedOverride;\nexport type OrganizationIncompleteConfig = EnvironmentIncompleteConfig & OrganizationConfigNormalizedOverride;\n\n// Rendered configs\nexport type ProjectRenderedConfig = PrettifyType<ApplyDefaults<typeof projectConfigDefaults, ProjectConfigStrippedNormalizedOverride>>;\nexport type BranchRenderedConfig = PrettifyType<ProjectRenderedConfig & ApplyDefaults<typeof branchConfigDefaults, BranchConfigStrippedNormalizedOverride>>;\nexport type EnvironmentRenderedConfig = PrettifyType<BranchRenderedConfig & ApplyDefaults<typeof environmentConfigDefaults, EnvironmentConfigStrippedNormalizedOverride>>;\nexport type OrganizationRenderedConfig = PrettifyType<EnvironmentRenderedConfig & ApplyDefaults<typeof organizationConfigDefaults, OrganizationConfigStrippedNormalizedOverride>>;\n"],"mappings":";AACA,YAAY,kBAAkB;AAC9B,SAAS,YAAY,WAAW,WAAW,iBAAiB;AAC5D,SAAS,oBAAoB;AAC7B,SAAoB,KAAK,KAAK,cAAc,WAAW;AAQhD,IAAM,eAAe,CAAC,WAAW,UAAU,eAAe,cAAc;AAE/E,IAAM,kBAAkB;AAKjB,IAAM,sBAAsB,UAAU,CAAC,CAA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F;AAAA,IACF;AACA,QAAI,KAAK,KAAK,UAAU;AAAA,EAC1B;AACA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/config/schema.ts"],"sourcesContent":["import * as yup from \"yup\";\nimport * as schemaFields from \"../schema-fields\";\nimport { yupBoolean, yupObject, yupRecord, yupString } from \"../schema-fields\";\nimport { allProviders } from \"../utils/oauth\";\nimport { DeepMerge, DeepPartial, get, has, isObjectLike, mapValues, set } from \"../utils/objects\";\nimport { PrettifyType } from \"../utils/types\";\nimport { Config, NormalizesTo } from \"./format\";\n\n// NOTE: The validation schemas in here are all schematic validators, not sanity-check validators.\n// For more info, see ./README.md\n\n\nexport const configLevels = ['project', 'branch', 'environment', 'organization'] as const;\nexport type ConfigLevel = typeof configLevels[number];\nconst permissionRegex = /^\\$?[a-z0-9_:]+$/;\nconst customPermissionRegex = /^[a-z0-9_:]+$/;\n\n/**\n * All fields that can be overridden at this level.\n */\nexport const projectConfigSchema = yupObject({});\n\n// --- NEW RBAC Schema ---\nconst branchRbacDefaultPermissions = yupRecord(\n yupString().optional().matches(permissionRegex),\n yupBoolean().isTrue().optional(),\n).optional();\n\nconst branchRbacSchema = yupObject({\n permissions: yupRecord(\n yupString().optional().matches(customPermissionRegex),\n yupObject({\n description: yupString().optional(),\n scope: yupString().oneOf(['team', 'project']).optional(),\n containedPermissionIds: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupBoolean().isTrue().optional()\n ).optional(),\n }).optional(),\n ).optional(),\n defaultPermissions: yupObject({\n teamCreator: branchRbacDefaultPermissions,\n teamMember: branchRbacDefaultPermissions,\n signUp: branchRbacDefaultPermissions,\n }).optional(),\n}).optional();\n// --- END NEW RBAC Schema ---\n\n// --- NEW API Keys Schema ---\nconst branchApiKeysSchema = yupObject({\n enabled: yupObject({\n team: yupBoolean().optional(),\n user: yupBoolean().optional(),\n }).optional(),\n}).optional();\n// --- END NEW API Keys Schema ---\n\n\nconst branchAuthSchema = yupObject({\n allowSignUp: yupBoolean().optional(),\n password: yupObject({\n allowSignIn: yupBoolean().optional(),\n }).optional(),\n otp: yupObject({\n allowSignIn: yupBoolean().optional(),\n }).optional(),\n passkey: yupObject({\n allowSignIn: yupBoolean().optional(),\n }).optional(),\n oauth: yupObject({\n accountMergeStrategy: yupString().oneOf(['link_method', 'raise_error', 'allow_duplicates']).optional(),\n providers: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupObject({\n type: yupString().oneOf(allProviders).optional(),\n allowSignIn: yupBoolean().optional(),\n allowConnectedAccounts: yupBoolean().optional(),\n }).defined(),\n ).optional(),\n }).optional(),\n}).optional();\n\nconst branchDomain = yupObject({\n allowLocalhost: yupBoolean().optional(),\n}).optional();\n\nexport const branchConfigSchema = projectConfigSchema.concat(yupObject({\n rbac: branchRbacSchema,\n\n teams: yupObject({\n createPersonalTeamOnSignUp: yupBoolean().optional(),\n allowClientTeamCreation: yupBoolean().optional(),\n }).optional(),\n\n users: yupObject({\n allowClientUserDeletion: yupBoolean().optional(),\n }).optional(),\n\n apiKeys: branchApiKeysSchema,\n\n domains: branchDomain,\n\n auth: branchAuthSchema,\n\n emails: yupObject({}),\n}));\n\n\nexport const environmentConfigSchema = branchConfigSchema.concat(yupObject({\n auth: branchConfigSchema.getNested(\"auth\").concat(yupObject({\n oauth: branchConfigSchema.getNested(\"auth\").getNested(\"oauth\").concat(yupObject({\n providers: yupRecord(\n yupString().optional().matches(permissionRegex),\n yupObject({\n type: yupString().oneOf(allProviders).optional(),\n isShared: yupBoolean().optional(),\n clientId: schemaFields.oauthClientIdSchema.optional(),\n clientSecret: schemaFields.oauthClientSecretSchema.optional(),\n facebookConfigId: schemaFields.oauthFacebookConfigIdSchema.optional(),\n microsoftTenantId: schemaFields.oauthMicrosoftTenantIdSchema.optional(),\n allowSignIn: yupBoolean().optional(),\n allowConnectedAccounts: yupBoolean().optional(),\n }),\n ).optional(),\n }).optional()),\n })),\n\n emails: branchConfigSchema.getNested(\"emails\").concat(yupObject({\n server: yupObject({\n isShared: yupBoolean().optional(),\n host: schemaFields.emailHostSchema.optional().nonEmpty(),\n port: schemaFields.emailPortSchema.optional(),\n username: schemaFields.emailUsernameSchema.optional().nonEmpty(),\n password: schemaFields.emailPasswordSchema.optional().nonEmpty(),\n senderName: schemaFields.emailSenderNameSchema.optional().nonEmpty(),\n senderEmail: schemaFields.emailSenderEmailSchema.optional().nonEmpty(),\n }),\n }).optional()),\n\n domains: branchConfigSchema.getNested(\"domains\").concat(yupObject({\n trustedDomains: yupRecord(\n yupString().uuid().optional(),\n yupObject({\n baseUrl: schemaFields.urlSchema.optional(),\n handlerPath: schemaFields.handlerPathSchema.optional(),\n }),\n ).optional(),\n })),\n}));\n\nexport const organizationConfigSchema = environmentConfigSchema.concat(yupObject({}));\n\n\n// Defaults\n// these are objects that are merged together to form the rendered config (see ./README.md)\n// Wherever an object could be used as a value, a function can instead be used to generate the default values on a per-key basis\nexport const projectConfigDefaults = {} satisfies DeepReplaceAllowFunctionsForObjects<ProjectConfigStrippedNormalizedOverride>;\n\nexport const branchConfigDefaults = {} satisfies DeepReplaceAllowFunctionsForObjects<BranchConfigStrippedNormalizedOverride>;\n\nexport const environmentConfigDefaults = {} satisfies DeepReplaceAllowFunctionsForObjects<EnvironmentConfigStrippedNormalizedOverride>;\n\nexport const organizationConfigDefaults = {\n rbac: {\n permissions: (key: string) => ({}),\n defaultPermissions: {\n teamCreator: {},\n teamMember: {},\n signUp: {},\n },\n },\n\n apiKeys: {\n enabled: {\n team: false,\n user: false,\n },\n },\n\n teams: {\n createPersonalTeamOnSignUp: false,\n allowClientTeamCreation: false,\n },\n\n users: {\n allowClientUserDeletion: false,\n },\n\n domains: {\n allowLocalhost: false,\n trustedDomains: (key: string) => ({\n handlerPath: '/handler',\n }),\n },\n\n auth: {\n allowSignUp: true,\n password: {\n allowSignIn: false,\n },\n otp: {\n allowSignIn: false,\n },\n passkey: {\n allowSignIn: false,\n },\n oauth: {\n accountMergeStrategy: 'link_method',\n providers: (key: string) => ({\n isShared: true,\n allowSignIn: false,\n allowConnectedAccounts: false,\n }),\n },\n },\n\n emails: {\n server: {\n isShared: true,\n },\n },\n} satisfies DeepReplaceAllowFunctionsForObjects<OrganizationConfigStrippedNormalizedOverride>;\n\nexport type DeepReplaceAllowFunctionsForObjects<T> = T extends object ? { [K in keyof T]: DeepReplaceAllowFunctionsForObjects<T[K]> } | ((arg: keyof T) => DeepReplaceAllowFunctionsForObjects<T[keyof T]>) : T;\nexport type DeepReplaceFunctionsWithObjects<T> = T extends (arg: infer K extends string) => infer R ? DeepReplaceFunctionsWithObjects<Record<K, R>> : (T extends object ? { [K in keyof T]: DeepReplaceFunctionsWithObjects<T[K]> } : T);\nexport type ApplyDefaults<D extends object | ((key: string) => unknown), C extends object> = DeepMerge<DeepReplaceFunctionsWithObjects<D>, C>;\nexport function applyDefaults<D extends object | ((key: string) => unknown), C extends object>(defaults: D, config: C): ApplyDefaults<D, C> {\n const res: any = typeof defaults === 'function' ? {} : mapValues(defaults, v => typeof v === 'function' ? {} : (typeof v === 'object' ? applyDefaults(v as any, {}) : v));\n for (const [key, mergeValue] of Object.entries(config)) {\n const baseValue = typeof defaults === 'function' ? defaults(key) : (has(defaults, key as any) ? get(defaults, key as any) : undefined);\n if (baseValue !== undefined) {\n if (isObjectLike(baseValue) && isObjectLike(mergeValue)) {\n set(res, key, applyDefaults(baseValue, mergeValue));\n continue;\n }\n }\n set(res, key, mergeValue);\n }\n return res as any;\n}\nundefined?.test(\"applyDefaults\", ({ expect }) => {\n expect(applyDefaults({ a: 1 }, { a: 2 })).toEqual({ a: 2 });\n expect(applyDefaults({ a: { b: 1 } }, { a: { c: 2 } })).toEqual({ a: { b: 1, c: 2 } });\n expect(applyDefaults((key: string) => ({ b: key }), { a: {} })).toEqual({ a: { b: \"a\" } });\n expect(applyDefaults({ a: (key: string) => ({ b: key }) }, { a: { c: { d: 1 } } })).toEqual({ a: { c: { b: \"c\", d: 1 } } });\n expect(applyDefaults({ a: (key: string) => ({ b: key }) }, {})).toEqual({ a: {} });\n expect(applyDefaults({ a: { b: (key: string) => ({ b: key }) } }, {})).toEqual({ a: { b: {} } });\n});\n\n// Normalized overrides\nexport type ProjectConfigNormalizedOverride = yup.InferType<typeof projectConfigSchema>;\nexport type BranchConfigNormalizedOverride = yup.InferType<typeof branchConfigSchema>;\nexport type EnvironmentConfigNormalizedOverride = yup.InferType<typeof environmentConfigSchema>;\nexport type OrganizationConfigNormalizedOverride = yup.InferType<typeof organizationConfigSchema>;\n\n// Normalized overrides, without the properties that may be overridden still\nexport type ProjectConfigStrippedNormalizedOverride = Omit<ProjectConfigNormalizedOverride,\n | keyof BranchConfigNormalizedOverride\n | keyof EnvironmentConfigNormalizedOverride\n | keyof OrganizationConfigNormalizedOverride\n>;\nexport type BranchConfigStrippedNormalizedOverride = Omit<BranchConfigNormalizedOverride,\n | keyof EnvironmentConfigNormalizedOverride\n | keyof OrganizationConfigNormalizedOverride\n>;\nexport type EnvironmentConfigStrippedNormalizedOverride = Omit<EnvironmentConfigNormalizedOverride,\n | keyof OrganizationConfigNormalizedOverride\n>;\nexport type OrganizationConfigStrippedNormalizedOverride = OrganizationConfigNormalizedOverride;\n\n// Overrides\nexport type ProjectConfigOverride = NormalizesTo<ProjectConfigNormalizedOverride>;\nexport type BranchConfigOverride = NormalizesTo<BranchConfigNormalizedOverride>;\nexport type EnvironmentConfigOverride = NormalizesTo<EnvironmentConfigNormalizedOverride>;\nexport type OrganizationConfigOverride = NormalizesTo<OrganizationConfigNormalizedOverride>;\n\n// Override overrides (used to update the overrides)\nexport type ProjectConfigOverrideOverride = Config & DeepPartial<ProjectConfigOverride>;\nexport type BranchConfigOverrideOverride = Config & DeepPartial<BranchConfigOverride>;\nexport type EnvironmentConfigOverrideOverride = Config & DeepPartial<EnvironmentConfigOverride>;\nexport type OrganizationConfigOverrideOverride = Config & DeepPartial<OrganizationConfigOverride>;\n\n// Incomplete configs\nexport type ProjectIncompleteConfig = ProjectConfigNormalizedOverride;\nexport type BranchIncompleteConfig = ProjectIncompleteConfig & BranchConfigNormalizedOverride;\nexport type EnvironmentIncompleteConfig = BranchIncompleteConfig & EnvironmentConfigNormalizedOverride;\nexport type OrganizationIncompleteConfig = EnvironmentIncompleteConfig & OrganizationConfigNormalizedOverride;\n\n// Rendered configs\nexport type ProjectRenderedConfig = PrettifyType<ApplyDefaults<typeof projectConfigDefaults, ProjectConfigStrippedNormalizedOverride>>;\nexport type BranchRenderedConfig = PrettifyType<ProjectRenderedConfig & ApplyDefaults<typeof branchConfigDefaults, BranchConfigStrippedNormalizedOverride>>;\nexport type EnvironmentRenderedConfig = PrettifyType<BranchRenderedConfig & ApplyDefaults<typeof environmentConfigDefaults, EnvironmentConfigStrippedNormalizedOverride>>;\nexport type OrganizationRenderedConfig = PrettifyType<EnvironmentRenderedConfig & ApplyDefaults<typeof organizationConfigDefaults, OrganizationConfigStrippedNormalizedOverride>>;\n"],"mappings":";AACA,YAAY,kBAAkB;AAC9B,SAAS,YAAY,WAAW,WAAW,iBAAiB;AAC5D,SAAS,oBAAoB;AAC7B,SAAiC,KAAK,KAAK,cAAc,WAAW,WAAW;AAQxE,IAAM,eAAe,CAAC,WAAW,UAAU,eAAe,cAAc;AAE/E,IAAM,kBAAkB;AACxB,IAAM,wBAAwB;AAKvB,IAAM,sBAAsB,UAAU,CAAC,CAAC;AAG/C,IAAM,+BAA+B;AAAA,EACnC,UAAU,EAAE,SAAS,EAAE,QAAQ,eAAe;AAAA,EAC9C,WAAW,EAAE,OAAO,EAAE,SAAS;AACjC,EAAE,SAAS;AAEX,IAAM,mBAAmB,UAAU;AAAA,EACjC,aAAa;AAAA,IACX,UAAU,EAAE,SAAS,EAAE,QAAQ,qBAAqB;AAAA,IACpD,UAAU;AAAA,MACR,aAAa,UAAU,EAAE,SAAS;AAAA,MAClC,OAAO,UAAU,EAAE,MAAM,CAAC,QAAQ,SAAS,CAAC,EAAE,SAAS;AAAA,MACvD,wBAAwB;AAAA,QACtB,UAAU,EAAE,SAAS,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MAChC,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EAEA,MAAM;AAAA,IACJ,aAAa;AAAA,IACb,UAAU;AAAA,MACR,aAAa;AAAA,IACf;AAAA,IACA,KAAK;AAAA,MACH,aAAa;AAAA,IACf;AAAA,IACA,SAAS;AAAA,MACP,aAAa;AAAA,IACf;AAAA,IACA,OAAO;AAAA,MACL,sBAAsB;AAAA,MACtB,WAAW,CAAC,SAAiB;AAAA,QAC3B,UAAU;AAAA,QACV,aAAa;AAAA,QACb,wBAAwB;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAQ;AAAA,IACN,QAAQ;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,EACF;AACF;AAKO,SAAS,cAA+E,UAAa,QAAgC;AAC1I,QAAM,MAAW,OAAO,aAAa,aAAa,CAAC,IAAI,UAAU,UAAU,OAAK,OAAO,MAAM,aAAa,CAAC,IAAK,OAAO,MAAM,WAAW,cAAc,GAAU,CAAC,CAAC,IAAI,CAAE;AACxK,aAAW,CAAC,KAAK,UAAU,KAAK,OAAO,QAAQ,MAAM,GAAG;AACtD,UAAM,YAAY,OAAO,aAAa,aAAa,SAAS,GAAG,IAAK,IAAI,UAAU,GAAU,IAAI,IAAI,UAAU,GAAU,IAAI;AAC5H,QAAI,cAAc,QAAW;AAC3B,UAAI,aAAa,SAAS,KAAK,aAAa,UAAU,GAAG;AACvD,YAAI,KAAK,KAAK,cAAc,WAAW,UAAU,CAAC;AAClD;AAAA,MACF;AAAA,IACF;AACA,QAAI,KAAK,KAAK,UAAU;AAAA,EAC1B;AACA,SAAO;AACT;","names":[]}
|
|
@@ -953,7 +953,7 @@ var StackClientInterface = class {
|
|
|
953
953
|
const response = await this._processResponse(rawResponse);
|
|
954
954
|
if (response.status === "error") {
|
|
955
955
|
const error = response.error;
|
|
956
|
-
if (
|
|
956
|
+
if (KnownErrors.RefreshTokenError.isInstance(error)) {
|
|
957
957
|
return null;
|
|
958
958
|
}
|
|
959
959
|
throw error;
|
|
@@ -993,7 +993,7 @@ var StackClientInterface = class {
|
|
|
993
993
|
return Result.ok(await this.sendClientRequest(path, requestOptions, tokenStoreOrNull));
|
|
994
994
|
} catch (e) {
|
|
995
995
|
for (const errorType of errorsToCatch) {
|
|
996
|
-
if (e
|
|
996
|
+
if (errorType.isInstance(e)) {
|
|
997
997
|
return Result.error(e);
|
|
998
998
|
}
|
|
999
999
|
}
|
|
@@ -1050,6 +1050,8 @@ var StackClientInterface = class {
|
|
|
1050
1050
|
* the case (I haven't actually tested.)
|
|
1051
1051
|
*/
|
|
1052
1052
|
"X-Stack-Random-Nonce": generateSecureRandomString(),
|
|
1053
|
+
// don't show a warning when proxying the API through ngrok (only relevant if the API url is an ngrok site)
|
|
1054
|
+
"ngrok-skip-browser-warning": "true",
|
|
1053
1055
|
...this.options.extraRequestHeaders,
|
|
1054
1056
|
...options.headers
|
|
1055
1057
|
},
|
|
@@ -1075,14 +1077,14 @@ var StackClientInterface = class {
|
|
|
1075
1077
|
}
|
|
1076
1078
|
const processedRes = await this._processResponse(rawRes);
|
|
1077
1079
|
if (processedRes.status === "error") {
|
|
1078
|
-
if (processedRes.error
|
|
1080
|
+
if (KnownErrors.InvalidAccessToken.isInstance(processedRes.error)) {
|
|
1079
1081
|
if (!tokenObj) {
|
|
1080
1082
|
throw new StackAssertionError("Received invalid access token, but session is not logged in", { tokenObj, processedRes });
|
|
1081
1083
|
}
|
|
1082
1084
|
session.markAccessTokenExpired(tokenObj.accessToken);
|
|
1083
1085
|
return Result.error(processedRes.error);
|
|
1084
1086
|
}
|
|
1085
|
-
if (adminSession && (
|
|
1087
|
+
if (adminSession && (KnownErrors.InvalidAdminAccessToken.isInstance(processedRes.error) || KnownErrors.ApiKeyNotFound.isInstance(processedRes.error))) {
|
|
1086
1088
|
if (!adminTokenObj) {
|
|
1087
1089
|
throw new StackAssertionError("Received invalid admin access token, but admin session is not logged in", { adminTokenObj, processedRes });
|
|
1088
1090
|
}
|
|
@@ -1615,7 +1617,7 @@ var StackClientInterface = class {
|
|
|
1615
1617
|
[KnownErrors.RefreshTokenError]
|
|
1616
1618
|
);
|
|
1617
1619
|
if (resOrError.status === "error") {
|
|
1618
|
-
if (resOrError.error
|
|
1620
|
+
if (KnownErrors.RefreshTokenError.isInstance(resOrError.error)) {
|
|
1619
1621
|
} else {
|
|
1620
1622
|
throw new StackAssertionError("Unexpected error", { error: resOrError.error });
|
|
1621
1623
|
}
|
|
@@ -1632,7 +1634,7 @@ var StackClientInterface = class {
|
|
|
1632
1634
|
[KnownErrors.CannotGetOwnUserWithoutUser]
|
|
1633
1635
|
);
|
|
1634
1636
|
if (responseOrError.status === "error") {
|
|
1635
|
-
if (responseOrError.error
|
|
1637
|
+
if (KnownErrors.CannotGetOwnUserWithoutUser.isInstance(responseOrError.error)) {
|
|
1636
1638
|
return null;
|
|
1637
1639
|
} else {
|
|
1638
1640
|
throw new StackAssertionError("Unexpected uncaught error", { cause: responseOrError.error });
|