payload 4.0.0-beta.4 → 4.0.0-beta.6

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 (32) hide show
  1. package/dist/auth/operations/resetPassword.d.ts.map +1 -1
  2. package/dist/auth/operations/resetPassword.js +50 -1
  3. package/dist/auth/operations/resetPassword.js.map +1 -1
  4. package/dist/cli/runtime/exitCodeHandlers.d.ts +14 -0
  5. package/dist/cli/runtime/exitCodeHandlers.d.ts.map +1 -0
  6. package/dist/cli/runtime/exitCodeHandlers.js +30 -0
  7. package/dist/cli/runtime/exitCodeHandlers.js.map +1 -0
  8. package/dist/cli/runtime/output.d.ts.map +1 -1
  9. package/dist/cli/runtime/output.js +4 -1
  10. package/dist/cli/runtime/output.js.map +1 -1
  11. package/dist/config/definePlugin.js +3 -1
  12. package/dist/config/definePlugin.js.map +1 -1
  13. package/dist/exports/internal.d.ts +1 -1
  14. package/dist/exports/internal.d.ts.map +1 -1
  15. package/dist/exports/internal.js +1 -1
  16. package/dist/exports/internal.js.map +1 -1
  17. package/dist/index.bundled.d.ts +21 -4
  18. package/dist/index.d.ts +2 -0
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +1 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/uploads/clientUploadReceipt.d.ts +15 -1
  23. package/dist/uploads/clientUploadReceipt.d.ts.map +1 -1
  24. package/dist/uploads/clientUploadReceipt.js +35 -6
  25. package/dist/uploads/clientUploadReceipt.js.map +1 -1
  26. package/dist/uploads/getFileFromUploadInstructions.d.ts.map +1 -1
  27. package/dist/uploads/getFileFromUploadInstructions.js +42 -0
  28. package/dist/uploads/getFileFromUploadInstructions.js.map +1 -1
  29. package/dist/uploads/types.d.ts +5 -1
  30. package/dist/uploads/types.d.ts.map +1 -1
  31. package/dist/uploads/types.js.map +1 -1
  32. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"resetPassword.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/resetPassword.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,mCAAmC,CAAA;AAC3F,OAAO,KAAK,EAAE,kBAAkB,EAAqB,MAAM,gBAAgB,CAAA;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAkB1D,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAA;QAChB,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAU,KAAK,SAAS,kBAAkB,QACrE,SAAS,KACd,OAAO,CAAC,MAAM,CAyOhB,CAAA"}
1
+ {"version":3,"file":"resetPassword.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/resetPassword.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAGX,MAAM,mCAAmC,CAAA;AAE1C,OAAO,KAAK,EAAE,kBAAkB,EAAqB,MAAM,gBAAgB,CAAA;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAkB1D,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAA;QAChB,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAU,KAAK,SAAS,kBAAkB,QACrE,SAAS,KACd,OAAO,CAAC,MAAM,CAiPhB,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { buildAfterOperation } from '../../collections/operations/utilities/buildAfterOperation.js';
2
2
  import { buildBeforeOperation } from '../../collections/operations/utilities/buildBeforeOperation.js';
3
- import { APIError, Forbidden } from '../../errors/index.js';
3
+ import { APIError, Forbidden, ValidationError } from '../../errors/index.js';
4
4
  import { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js';
5
5
  import { assertNoValidationWrite } from '../../utilities/assertNoValidationWrite.js';
6
6
  import { commitTransaction } from '../../utilities/commitTransaction.js';
@@ -55,6 +55,13 @@ export const resetPasswordOperation = async (args)=>{
55
55
  if (!user) {
56
56
  throw new APIError('Token is either invalid or has expired.', httpStatus.FORBIDDEN);
57
57
  }
58
+ await validatePasswordField({
59
+ collectionConfig,
60
+ overrideAccess,
61
+ password: data.password,
62
+ req,
63
+ user
64
+ });
58
65
  // TODO: replace this method
59
66
  const { hash, salt } = await generatePasswordSaltHash({
60
67
  collection: collectionConfig,
@@ -198,5 +205,47 @@ export const resetPasswordOperation = async (args)=>{
198
205
  throw error;
199
206
  }
200
207
  };
208
+ /**
209
+ * Runs the `password` field override's validation, which `payload.db.updateOne` skips.
210
+ */ async function validatePasswordField({ collectionConfig, overrideAccess, password, req, user }) {
211
+ const passwordField = collectionConfig.flattenedFields.find((field)=>field.name === 'password');
212
+ if (!passwordField || !('validate' in passwordField) || !passwordField.validate) {
213
+ return;
214
+ }
215
+ const validate = passwordField.validate;
216
+ const dataToValidate = {
217
+ ...user,
218
+ password
219
+ };
220
+ const validationResult = await validate(password, {
221
+ ...passwordField,
222
+ id: user.id,
223
+ blockData: {},
224
+ collectionSlug: collectionConfig.slug,
225
+ data: dataToValidate,
226
+ event: 'submit',
227
+ operation: 'update',
228
+ overrideAccess,
229
+ path: [
230
+ 'password'
231
+ ],
232
+ preferences: {
233
+ fields: {}
234
+ },
235
+ req,
236
+ siblingData: dataToValidate
237
+ });
238
+ if (typeof validationResult === 'string') {
239
+ throw new ValidationError({
240
+ collection: collectionConfig.slug,
241
+ errors: [
242
+ {
243
+ message: validationResult,
244
+ path: 'password'
245
+ }
246
+ ]
247
+ });
248
+ }
249
+ }
201
250
 
202
251
  //# sourceMappingURL=resetPassword.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/auth/operations/resetPassword.ts"],"sourcesContent":["import type { Collection, DataFromCollectionSlug } from '../../collections/config/types.js'\nimport type { AuthCollectionSlug, AuthenticatedUser } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from '../../collections/operations/utilities/buildBeforeOperation.js'\nimport { APIError, Forbidden } from '../../errors/index.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { assertNoValidationWrite } from '../../utilities/assertNoValidationWrite.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { httpStatus } from '../../utilities/httpStatus.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { applyUserReadAccess } from '../applyUserReadAccess.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { jwtSign } from '../jwt.js'\nimport { addSessionToUser, revokeSession } from '../sessions.js'\nimport { authenticateLocalStrategy } from '../strategies/local/authenticate.js'\nimport { generatePasswordSaltHash } from '../strategies/local/generatePasswordSaltHash.js'\n\nexport type Result = {\n token?: string\n user: Record<string, unknown>\n}\n\nexport type Arguments = {\n collection: Collection\n data: {\n password: string\n token: string\n }\n depth?: number\n overrideAccess?: boolean\n req: PayloadRequest\n}\n\nexport const resetPasswordOperation = async <TSlug extends AuthCollectionSlug>(\n args: Arguments,\n): Promise<Result> => {\n const {\n collection: { config: collectionConfig },\n data,\n depth,\n overrideAccess = false,\n req: {\n payload: { secret },\n payload,\n },\n req,\n } = args\n\n assertNoValidationWrite(req)\n\n if (\n !Object.prototype.hasOwnProperty.call(data, 'token') ||\n !Object.prototype.hasOwnProperty.call(data, 'password')\n ) {\n throw new APIError('Missing required data.', httpStatus.BAD_REQUEST)\n }\n\n if (collectionConfig.auth.disableLocalStrategy) {\n throw new Forbidden(req.t)\n }\n\n let sid: string | undefined\n let sessionUser: AuthenticatedUser | null = null\n\n try {\n const shouldCommit = await initTransaction(req)\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'resetPassword',\n overrideAccess,\n })\n\n // /////////////////////////////////////\n // Reset Password\n // /////////////////////////////////////\n\n const where = appendNonTrashedFilter({\n enableTrash: Boolean(collectionConfig.trash),\n trash: false,\n where: {\n resetPasswordExpiration: { greater_than: new Date().toISOString() },\n resetPasswordToken: { equals: data.token },\n },\n })\n\n let user = await payload.db.findOne<AuthenticatedUser>({\n collection: collectionConfig.slug,\n req,\n where,\n })\n\n if (!user) {\n throw new APIError('Token is either invalid or has expired.', httpStatus.FORBIDDEN)\n }\n\n // TODO: replace this method\n const { hash, salt } = await generatePasswordSaltHash({\n collection: collectionConfig,\n password: data.password,\n req,\n })\n\n user.salt = salt\n user.hash = hash\n\n user.resetPasswordExpiration = new Date().toISOString()\n\n if (collectionConfig.auth.maxLoginAttempts > 0) {\n user.lockUntil = null\n user.loginAttempts = 0\n }\n\n if (collectionConfig.auth.verify) {\n user._verified = Boolean(user._verified)\n }\n\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n await hook({\n collection: args.collection?.config,\n context: req.context,\n data: user,\n operation: 'update',\n req,\n })\n }\n }\n\n // /////////////////////////////////////\n // Update new password\n // /////////////////////////////////////\n\n // Ensure updatedAt date is always updated\n user.updatedAt = new Date().toISOString()\n\n if (collectionConfig.auth.useSessions) {\n user.sessions = []\n }\n\n const doc = await payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n })\n\n await authenticateLocalStrategy({ doc, password: data.password })\n\n user = doc as AuthenticatedUser\n user.collection = collectionConfig.slug\n user._strategy = 'local-jwt'\n\n const fieldsToSignArgs: Parameters<typeof getFieldsToSign>[0] = {\n collectionConfig,\n email: user.email!,\n user,\n }\n\n const session = await addSessionToUser({\n collectionConfig,\n payload,\n req,\n user,\n })\n\n sessionUser = user\n sid = session.sid\n\n if (sid) {\n fieldsToSignArgs.sid = sid\n }\n\n const fieldsToSign = getFieldsToSign(fieldsToSignArgs)\n\n // /////////////////////////////////////\n // beforeLogin - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeLogin?.length) {\n for (const hook of collectionConfig.hooks.beforeLogin) {\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n user,\n })) || user\n }\n }\n\n const { token } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n req.user = user\n\n // /////////////////////////////////////\n // afterLogin - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterLogin?.length) {\n for (const hook of collectionConfig.hooks.afterLogin) {\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n token,\n user,\n })) || user\n }\n }\n\n user!.collection = collectionConfig.slug\n user!._strategy = 'local-jwt'\n\n const userWithReadAccess = await applyUserReadAccess({\n collection: collectionConfig,\n depth: depth!,\n overrideAccess,\n req,\n showHiddenFields: false,\n user: user!,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n let result: { user: DataFromCollectionSlug<TSlug> } & Result = {\n token,\n user: userWithReadAccess,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'resetPassword',\n overrideAccess,\n result,\n })\n\n return result\n } catch (error: unknown) {\n if (sid) {\n await revokeSession({\n collectionConfig,\n payload,\n req,\n sid,\n user: sessionUser,\n })\n }\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["buildAfterOperation","buildBeforeOperation","APIError","Forbidden","appendNonTrashedFilter","assertNoValidationWrite","commitTransaction","httpStatus","initTransaction","killTransaction","applyUserReadAccess","getFieldsToSign","jwtSign","addSessionToUser","revokeSession","authenticateLocalStrategy","generatePasswordSaltHash","resetPasswordOperation","args","collection","config","collectionConfig","data","depth","overrideAccess","req","payload","secret","Object","prototype","hasOwnProperty","call","BAD_REQUEST","auth","disableLocalStrategy","t","sid","sessionUser","shouldCommit","operation","where","enableTrash","Boolean","trash","resetPasswordExpiration","greater_than","Date","toISOString","resetPasswordToken","equals","token","user","db","findOne","slug","FORBIDDEN","hash","salt","password","maxLoginAttempts","lockUntil","loginAttempts","verify","_verified","hooks","beforeValidate","length","hook","context","updatedAt","useSessions","sessions","doc","updateOne","id","_strategy","fieldsToSignArgs","email","session","fieldsToSign","beforeLogin","tokenExpiration","afterLogin","userWithReadAccess","showHiddenFields","result","error"],"mappings":"AAIA,SAASA,mBAAmB,QAAQ,gEAA+D;AACnG,SAASC,oBAAoB,QAAQ,iEAAgE;AACrG,SAASC,QAAQ,EAAEC,SAAS,QAAQ,wBAAuB;AAC3D,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,uBAAuB,QAAQ,6CAA4C;AACpF,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,UAAU,QAAQ,gCAA+B;AAC1D,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,mBAAmB,QAAQ,4BAA2B;AAC/D,SAASC,eAAe,QAAQ,wBAAuB;AACvD,S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O,GAAG;oBACbyB;oBACAC;gBACF,MAAOA;YACX;QACF;QAEAA,KAAMhC,UAAU,GAAGE,iBAAiBiC,IAAI;QACxCH,KAAMwB,SAAS,GAAG;QAElB,MAAMQ,qBAAqB,MAAMzE,oBAAoB;YACnDS,YAAYE;YACZE,OAAOA;YACPC;YACAC;YACA2D,kBAAkB;YAClBjC,MAAMA;QACR;QAEA,IAAIb,cAAc;YAChB,MAAMhC,kBAAkBmB;QAC1B;QAEA,IAAI4D,SAA2D;YAC7DnC;YACAC,MAAMgC;QACR;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCE,SAAS,MAAMrF,oBAAoB;YACjCkB;YACAC,YAAYD,KAAKC,UAAU,EAAEC;YAC7BmB,WAAW;YACXf;YACA6D;QACF;QAEA,OAAOA;IACT,EAAE,OAAOC,OAAgB;QACvB,IAAIlD,KAAK;YACP,MAAMtB,cAAc;gBAClBO;gBACAK;gBACAD;gBACAW;gBACAe,MAAMd;YACR;QACF;QACA,MAAM5B,gBAAgBgB;QACtB,MAAM6D;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/auth/operations/resetPassword.ts"],"sourcesContent":["import type {\n Collection,\n DataFromCollectionSlug,\n SanitizedCollectionConfig,\n} from '../../collections/config/types.js'\nimport type { Validate } from '../../fields/config/types.js'\nimport type { AuthCollectionSlug, AuthenticatedUser } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from '../../collections/operations/utilities/buildBeforeOperation.js'\nimport { APIError, Forbidden, ValidationError } from '../../errors/index.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { assertNoValidationWrite } from '../../utilities/assertNoValidationWrite.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { httpStatus } from '../../utilities/httpStatus.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { applyUserReadAccess } from '../applyUserReadAccess.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { jwtSign } from '../jwt.js'\nimport { addSessionToUser, revokeSession } from '../sessions.js'\nimport { authenticateLocalStrategy } from '../strategies/local/authenticate.js'\nimport { generatePasswordSaltHash } from '../strategies/local/generatePasswordSaltHash.js'\n\nexport type Result = {\n token?: string\n user: Record<string, unknown>\n}\n\nexport type Arguments = {\n collection: Collection\n data: {\n password: string\n token: string\n }\n depth?: number\n overrideAccess?: boolean\n req: PayloadRequest\n}\n\nexport const resetPasswordOperation = async <TSlug extends AuthCollectionSlug>(\n args: Arguments,\n): Promise<Result> => {\n const {\n collection: { config: collectionConfig },\n data,\n depth,\n overrideAccess = false,\n req: {\n payload: { secret },\n payload,\n },\n req,\n } = args\n\n assertNoValidationWrite(req)\n\n if (\n !Object.prototype.hasOwnProperty.call(data, 'token') ||\n !Object.prototype.hasOwnProperty.call(data, 'password')\n ) {\n throw new APIError('Missing required data.', httpStatus.BAD_REQUEST)\n }\n\n if (collectionConfig.auth.disableLocalStrategy) {\n throw new Forbidden(req.t)\n }\n\n let sid: string | undefined\n let sessionUser: AuthenticatedUser | null = null\n\n try {\n const shouldCommit = await initTransaction(req)\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'resetPassword',\n overrideAccess,\n })\n\n // /////////////////////////////////////\n // Reset Password\n // /////////////////////////////////////\n\n const where = appendNonTrashedFilter({\n enableTrash: Boolean(collectionConfig.trash),\n trash: false,\n where: {\n resetPasswordExpiration: { greater_than: new Date().toISOString() },\n resetPasswordToken: { equals: data.token },\n },\n })\n\n let user = await payload.db.findOne<AuthenticatedUser>({\n collection: collectionConfig.slug,\n req,\n where,\n })\n\n if (!user) {\n throw new APIError('Token is either invalid or has expired.', httpStatus.FORBIDDEN)\n }\n\n await validatePasswordField({\n collectionConfig,\n overrideAccess,\n password: data.password,\n req,\n user,\n })\n\n // TODO: replace this method\n const { hash, salt } = await generatePasswordSaltHash({\n collection: collectionConfig,\n password: data.password,\n req,\n })\n\n user.salt = salt\n user.hash = hash\n\n user.resetPasswordExpiration = new Date().toISOString()\n\n if (collectionConfig.auth.maxLoginAttempts > 0) {\n user.lockUntil = null\n user.loginAttempts = 0\n }\n\n if (collectionConfig.auth.verify) {\n user._verified = Boolean(user._verified)\n }\n\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n await hook({\n collection: args.collection?.config,\n context: req.context,\n data: user,\n operation: 'update',\n req,\n })\n }\n }\n\n // /////////////////////////////////////\n // Update new password\n // /////////////////////////////////////\n\n // Ensure updatedAt date is always updated\n user.updatedAt = new Date().toISOString()\n\n if (collectionConfig.auth.useSessions) {\n user.sessions = []\n }\n\n const doc = await payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n })\n\n await authenticateLocalStrategy({ doc, password: data.password })\n\n user = doc as AuthenticatedUser\n user.collection = collectionConfig.slug\n user._strategy = 'local-jwt'\n\n const fieldsToSignArgs: Parameters<typeof getFieldsToSign>[0] = {\n collectionConfig,\n email: user.email!,\n user,\n }\n\n const session = await addSessionToUser({\n collectionConfig,\n payload,\n req,\n user,\n })\n\n sessionUser = user\n sid = session.sid\n\n if (sid) {\n fieldsToSignArgs.sid = sid\n }\n\n const fieldsToSign = getFieldsToSign(fieldsToSignArgs)\n\n // /////////////////////////////////////\n // beforeLogin - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeLogin?.length) {\n for (const hook of collectionConfig.hooks.beforeLogin) {\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n user,\n })) || user\n }\n }\n\n const { token } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n req.user = user\n\n // /////////////////////////////////////\n // afterLogin - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterLogin?.length) {\n for (const hook of collectionConfig.hooks.afterLogin) {\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n token,\n user,\n })) || user\n }\n }\n\n user!.collection = collectionConfig.slug\n user!._strategy = 'local-jwt'\n\n const userWithReadAccess = await applyUserReadAccess({\n collection: collectionConfig,\n depth: depth!,\n overrideAccess,\n req,\n showHiddenFields: false,\n user: user!,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n let result: { user: DataFromCollectionSlug<TSlug> } & Result = {\n token,\n user: userWithReadAccess,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'resetPassword',\n overrideAccess,\n result,\n })\n\n return result\n } catch (error: unknown) {\n if (sid) {\n await revokeSession({\n collectionConfig,\n payload,\n req,\n sid,\n user: sessionUser,\n })\n }\n await killTransaction(req)\n throw error\n }\n}\n\n/**\n * Runs the `password` field override's validation, which `payload.db.updateOne` skips.\n */\nasync function validatePasswordField({\n collectionConfig,\n overrideAccess,\n password,\n req,\n user,\n}: {\n collectionConfig: SanitizedCollectionConfig\n overrideAccess: boolean\n password: string\n req: PayloadRequest\n user: AuthenticatedUser\n}): Promise<void> {\n const passwordField = collectionConfig.flattenedFields.find((field) => field.name === 'password')\n\n if (!passwordField || !('validate' in passwordField) || !passwordField.validate) {\n return\n }\n\n const validate = passwordField.validate as Validate<string>\n const dataToValidate = { ...user, password }\n\n const validationResult = await validate(password, {\n ...passwordField,\n id: user.id,\n blockData: {},\n collectionSlug: collectionConfig.slug,\n data: dataToValidate,\n event: 'submit',\n operation: 'update',\n overrideAccess,\n path: ['password'],\n preferences: { fields: {} },\n req,\n siblingData: dataToValidate,\n })\n\n if (typeof validationResult === 'string') {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ message: validationResult, path: 'password' }],\n })\n }\n}\n"],"names":["buildAfterOperation","buildBeforeOperation","APIError","Forbidden","ValidationError","appendNonTrashedFilter","assertNoValidationWrite","commitTransaction","httpStatus","initTransaction","killTransaction","applyUserReadAccess","getFieldsToSign","jwtSign","addSessionToUser","revokeSession","authenticateLocalStrategy","generatePasswordSaltHash","resetPasswordOperation","args","collection","config","collectionConfig","data","depth","overrideAccess","req","payload","secret","Object","prototype","hasOwnProperty","call","BAD_REQUEST","auth","disableLocalStrategy","t","sid","sessionUser","shouldCommit","operation","where","enableTrash","Boolean","trash","resetPasswordExpiration","greater_than","Date","toISOString","resetPasswordToken","equals","token","user","db","findOne","slug","FORBIDDEN","validatePasswordField","password","hash","salt","maxLoginAttempts","lockUntil","loginAttempts","verify","_verified","hooks","beforeValidate","length","hook","context","updatedAt","useSessions","sessions","doc","updateOne","id","_strategy","fieldsToSignArgs","email","session","fieldsToSign","beforeLogin","tokenExpiration","afterLogin","userWithReadAccess","showHiddenFields","result","error","passwordField","flattenedFields","find","field","name","validate","dataToValidate","validationResult","blockData","collectionSlug","event","path","preferences","fields","siblingData","errors","message"],"mappings":"AASA,SAASA,mBAAmB,QAAQ,gEAA+D;AACnG,SAASC,oBAAoB,QAAQ,iEAAgE;AACrG,SAASC,QAAQ,EAAEC,SAAS,EAAEC,eAAe,QAAQ,wBAAuB;AAC5E,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,uBAAuB,QAAQ,6CAA4C;AACpF,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,UAAU,QAAQ,gCAA+B;AAC1D,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,mBAAmB,QAAQ,4BAA2B;AAC/D,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,OAAO,QAAQ,YAAW;AACnC,SAASC,gBAAgB,EAAEC,aAAa,QAAQ,iBAAgB;AAChE,SAASC,yBAAyB,QAAQ,sCAAqC;AAC/E,SAASC,wBAAw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MAAM;YAAC;SAAW;QAClBC,aAAa;YAAEC,QAAQ,CAAC;QAAE;QAC1B5E;QACA6E,aAAaR;IACf;IAEA,IAAI,OAAOC,qBAAqB,UAAU;QACxC,MAAM,IAAI5F,gBAAgB;YACxBgB,YAAYE,iBAAiBiC,IAAI;YACjCiD,QAAQ;gBAAC;oBAAEC,SAAST;oBAAkBI,MAAM;gBAAW;aAAE;QAC3D;IACF;AACF"}
@@ -0,0 +1,14 @@
1
+ export type CLIExitCodeHandler = (error: unknown) => number | undefined;
2
+ /**
3
+ * Register a classifier before loading config that may throw custom errors.
4
+ * The first handler returning an integer from 1 through 255 chooses the CLI's
5
+ * failure exit code. Return undefined for errors the handler does not recognize.
6
+ * Handlers that throw are ignored. The returned function removes this registration.
7
+ */
8
+ export declare const registerCLIExitCodeHandler: ({ handler, }: {
9
+ handler: CLIExitCodeHandler;
10
+ }) => (() => void);
11
+ export declare const getCLIErrorExitCode: ({ error }: {
12
+ error: unknown;
13
+ }) => number;
14
+ //# sourceMappingURL=exitCodeHandlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exitCodeHandlers.d.ts","sourceRoot":"","sources":["../../../src/cli/runtime/exitCodeHandlers.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,CAAA;AAIvE;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,iBAEpC;IACD,OAAO,EAAE,kBAAkB,CAAA;CAC5B,KAAG,CAAC,MAAM,IAAI,CAQd,CAAA;AAED,eAAO,MAAM,mBAAmB,cAAe;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,KAAG,MAmBnE,CAAA"}
@@ -0,0 +1,30 @@
1
+ const handlers = new Set();
2
+ /**
3
+ * Register a classifier before loading config that may throw custom errors.
4
+ * The first handler returning an integer from 1 through 255 chooses the CLI's
5
+ * failure exit code. Return undefined for errors the handler does not recognize.
6
+ * Handlers that throw are ignored. The returned function removes this registration.
7
+ */ export const registerCLIExitCodeHandler = ({ handler })=>{
8
+ const registration = {
9
+ handler
10
+ };
11
+ handlers.add(registration);
12
+ return ()=>{
13
+ handlers.delete(registration);
14
+ };
15
+ };
16
+ export const getCLIErrorExitCode = ({ error })=>{
17
+ for (const { handler } of handlers){
18
+ try {
19
+ const exitCode = handler(error);
20
+ if (exitCode !== undefined && Number.isInteger(exitCode) && exitCode >= 1 && exitCode <= 255) {
21
+ return exitCode;
22
+ }
23
+ } catch {
24
+ // A classifier must not prevent reporting the original CLI error.
25
+ }
26
+ }
27
+ return 1;
28
+ };
29
+
30
+ //# sourceMappingURL=exitCodeHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/cli/runtime/exitCodeHandlers.ts"],"sourcesContent":["export type CLIExitCodeHandler = (error: unknown) => number | undefined\n\nconst handlers = new Set<{ handler: CLIExitCodeHandler }>()\n\n/**\n * Register a classifier before loading config that may throw custom errors.\n * The first handler returning an integer from 1 through 255 chooses the CLI's\n * failure exit code. Return undefined for errors the handler does not recognize.\n * Handlers that throw are ignored. The returned function removes this registration.\n */\nexport const registerCLIExitCodeHandler = ({\n handler,\n}: {\n handler: CLIExitCodeHandler\n}): (() => void) => {\n const registration = { handler }\n\n handlers.add(registration)\n\n return () => {\n handlers.delete(registration)\n }\n}\n\nexport const getCLIErrorExitCode = ({ error }: { error: unknown }): number => {\n for (const { handler } of handlers) {\n try {\n const exitCode = handler(error)\n\n if (\n exitCode !== undefined &&\n Number.isInteger(exitCode) &&\n exitCode >= 1 &&\n exitCode <= 255\n ) {\n return exitCode\n }\n } catch {\n // A classifier must not prevent reporting the original CLI error.\n }\n }\n\n return 1\n}\n"],"names":["handlers","Set","registerCLIExitCodeHandler","handler","registration","add","delete","getCLIErrorExitCode","error","exitCode","undefined","Number","isInteger"],"mappings":"AAEA,MAAMA,WAAW,IAAIC;AAErB;;;;;CAKC,GACD,OAAO,MAAMC,6BAA6B,CAAC,EACzCC,OAAO,EAGR;IACC,MAAMC,eAAe;QAAED;IAAQ;IAE/BH,SAASK,GAAG,CAACD;IAEb,OAAO;QACLJ,SAASM,MAAM,CAACF;IAClB;AACF,EAAC;AAED,OAAO,MAAMG,sBAAsB,CAAC,EAAEC,KAAK,EAAsB;IAC/D,KAAK,MAAM,EAAEL,OAAO,EAAE,IAAIH,SAAU;QAClC,IAAI;YACF,MAAMS,WAAWN,QAAQK;YAEzB,IACEC,aAAaC,aACbC,OAAOC,SAAS,CAACH,aACjBA,YAAY,KACZA,YAAY,KACZ;gBACA,OAAOA;YACT;QACF,EAAE,OAAM;QACN,kEAAkE;QACpE;IACF;IAEA,OAAO;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../src/cli/runtime/output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAkB,MAAM,WAAW,CAAA;AAIxD,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACrC,MAAM,CAAC,EAAE,aAAa,EAAE,CAAA;IAExB,YAAY,EACV,KAAK,EACL,IAAuB,EACvB,OAAO,EACP,WAAW,EACX,MAAM,EACN,OAAO,GACR,EAAE;QACD,KAAK,CAAC,EAAE,OAAO,CAAA;QACf,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACrC,MAAM,CAAC,EAAE,aAAa,EAAE,CAAA;QACxB,OAAO,EAAE,MAAM,CAAA;KAChB,EAOA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CLIErrorExitCode } from './exitCodeHandlers.js';
2
3
  import { redirectOutputToStderr, writeToCLIStdout } from './redirectOutputToStderr.js';
3
4
  export class CLICommandError extends Error {
4
5
  code;
@@ -95,7 +96,9 @@ export const getCLIErrorOutput = ({ command, error })=>{
95
96
  * are not printed again. Other errors are printed in full in human-readable mode to preserve
96
97
  * their stack trace.
97
98
  */ export const handleCLIError = ({ cli, error })=>{
98
- const exitCode = error instanceof CommanderError ? error.exitCode : 1;
99
+ const exitCode = error instanceof CommanderError ? error.exitCode : getCLIErrorExitCode({
100
+ error: error instanceof CLICommandError ? error.cause ?? error : error
101
+ });
99
102
  const shouldOutputJSON = isJSONOutput(cli);
100
103
  if (shouldOutputJSON && exitCode !== 0) {
101
104
  writeCLIJSON({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/cli/runtime/output.ts"],"sourcesContent":["import { type Command, CommanderError } from 'commander'\n\nimport { redirectOutputToStderr, writeToCLIStdout } from './redirectOutputToStderr.js'\n\nexport type CLIErrorIssue = {\n message: string\n path?: string\n}\n\nexport class CLICommandError extends Error {\n code: string\n command?: string\n inputSchema?: Record<string, unknown>\n issues?: CLIErrorIssue[]\n\n constructor({\n cause,\n code = 'COMMAND_FAILED',\n command,\n inputSchema,\n issues,\n message,\n }: {\n cause?: unknown\n code?: string\n command?: string\n inputSchema?: Record<string, unknown>\n issues?: CLIErrorIssue[]\n message: string\n }) {\n super(message, { cause })\n this.name = 'CLICommandError'\n this.code = code\n this.command = command\n this.inputSchema = inputSchema\n this.issues = issues\n }\n}\n\nexport const isJSONOutput = (command?: Command): boolean => {\n if (command?.getOptionValueSourceWithGlobals('json') === 'cli') {\n return Boolean(command.optsWithGlobals<{ json?: boolean }>().json)\n }\n\n const separatorPosition = process.argv.indexOf('--', 2)\n const payloadArguments = process.argv.slice(\n 2,\n separatorPosition === -1 ? process.argv.length : separatorPosition,\n )\n const jsonPosition = payloadArguments.lastIndexOf('--json')\n const noJSONPosition = payloadArguments.lastIndexOf('--no-json')\n\n if (jsonPosition !== -1 || noJSONPosition !== -1) {\n return jsonPosition > noJSONPosition\n }\n\n return process.env.PAYLOAD_CLI_JSON !== undefined\n}\n\n/**\n * Runs CLI work with one effective output mode, then restores the previous process state.\n * JSON mode redirects diagnostic output and sets `PAYLOAD_CLI_JSON` so Payload loggers use stderr.\n */\nexport const withCLIOutputMode = async <T>({\n isJSON,\n run,\n}: {\n isJSON: boolean\n run: () => Promise<T> | T\n}): Promise<T> => {\n const previousJSONSetting = process.env.PAYLOAD_CLI_JSON\n const restoreOutput = isJSON ? redirectOutputToStderr() : undefined\n\n if (isJSON) {\n process.env.PAYLOAD_CLI_JSON = '1'\n } else {\n delete process.env.PAYLOAD_CLI_JSON\n }\n\n try {\n return await run()\n } finally {\n restoreOutput?.()\n\n if (previousJSONSetting === undefined) {\n delete process.env.PAYLOAD_CLI_JSON\n } else {\n process.env.PAYLOAD_CLI_JSON = previousJSONSetting\n }\n }\n}\n\nexport const writeCLIJSON = ({ command, value }: { command?: Command; value: unknown }): void => {\n const output = `${JSON.stringify(value, (_key, item) =>\n typeof item === 'bigint' ? item.toString() : item,\n )}\\n`\n const outputConfiguration = command?.configureOutput()\n\n writeToCLIStdout({\n output,\n write: outputConfiguration?.writeOut\n ? (value) => outputConfiguration.writeOut?.(value)\n : undefined,\n })\n}\n\nexport const getCLIErrorOutput = ({\n command,\n error,\n}: {\n command?: string\n error: unknown\n}): Record<string, unknown> => {\n if (error instanceof CLICommandError) {\n return {\n command: error.command ?? command,\n error: {\n code: error.code,\n message: error.message,\n ...(error.issues ? { issues: error.issues } : {}),\n ...(error.inputSchema ? { inputSchema: error.inputSchema } : {}),\n },\n success: false,\n }\n }\n\n const errorWithDetails = error as { code?: unknown; message?: unknown }\n\n return {\n ...(command ? { command } : {}),\n error: {\n code: typeof errorWithDetails?.code === 'string' ? errorWithDetails.code : 'COMMAND_FAILED',\n message:\n typeof errorWithDetails?.message === 'string'\n ? errorWithDetails.message\n : typeof error === 'string'\n ? error\n : 'Unknown error',\n },\n success: false,\n }\n}\n\n/**\n * Formats a CLI failure and sets its exit code.\n *\n * Commander prints its own human-readable errors before throwing a `CommanderError`, so they\n * are not printed again. Other errors are printed in full in human-readable mode to preserve\n * their stack trace.\n */\nexport const handleCLIError = ({ cli, error }: { cli?: Command; error: unknown }): void => {\n const exitCode = error instanceof CommanderError ? error.exitCode : 1\n const shouldOutputJSON = isJSONOutput(cli)\n\n if (shouldOutputJSON && exitCode !== 0) {\n writeCLIJSON({\n command: cli,\n value: getCLIErrorOutput({ command: cli?.args[0], error }),\n })\n } else if (!(error instanceof CommanderError)) {\n // eslint-disable-next-line no-console\n console.error(error)\n }\n\n process.exitCode = exitCode\n}\n\n/** Wraps the CLI entry point so every failure uses the same output and exits cleanly. */\nexport const withErrorHandling =\n (run: () => Promise<void>): (() => Promise<void>) =>\n async () => {\n try {\n await run()\n } catch (error) {\n handleCLIError({ error })\n process.exit(process.exitCode ?? 1)\n }\n }\n"],"names":["CommanderError","redirectOutputToStderr","writeToCLIStdout","CLICommandError","Error","code","command","inputSchema","issues","cause","message","name","isJSONOutput","getOptionValueSourceWithGlobals","Boolean","optsWithGlobals","json","separatorPosition","process","argv","indexOf","payloadArguments","slice","length","jsonPosition","lastIndexOf","noJSONPosition","env","PAYLOAD_CLI_JSON","undefined","withCLIOutputMode","isJSON","run","previousJSONSetting","restoreOutput","writeCLIJSON","value","output","JSON","stringify","_key","item","toString","outputConfiguration","configureOutput","write","writeOut","getCLIErrorOutput","error","success","errorWithDetails","handleCLIError","cli","exitCode","shouldOutputJSON","args","console","withErrorHandling","exit"],"mappings":"AAAA,SAAuBA,cAAc,QAAQ,YAAW;AAExD,SAASC,sBAAsB,EAAEC,gBAAgB,QAAQ,8BAA6B;AAOtF,OAAO,MAAMC,wBAAwBC;IACnCC,KAAY;IACZC,QAAgB;IAChBC,YAAqC;IACrCC,OAAwB;IAExB,YAAY,EACVC,KAAK,EACLJ,OAAO,gBAAgB,EACvBC,OAAO,EACPC,W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MK,QAAQ,GAAG;IACpE,MAAMC,mBAAmB1C,aAAawC;IAEtC,IAAIE,oBAAoBD,aAAa,GAAG;QACtClB,aAAa;YACX7B,SAAS8C;YACThB,OAAOW,kBAAkB;gBAAEzC,SAAS8C,KAAKG,IAAI,CAAC,EAAE;gBAAEP;YAAM;QAC1D;IACF,OAAO,IAAI,CAAEA,CAAAA,iBAAiBhD,cAAa,GAAI;QAC7C,sCAAsC;QACtCwD,QAAQR,KAAK,CAACA;IAChB;IAEA9B,QAAQmC,QAAQ,GAAGA;AACrB,EAAC;AAED,uFAAuF,GACvF,OAAO,MAAMI,oBACX,CAACzB,MACD;QACE,IAAI;YACF,MAAMA;QACR,EAAE,OAAOgB,OAAO;YACdG,eAAe;gBAAEH;YAAM;YACvB9B,QAAQwC,IAAI,CAACxC,QAAQmC,QAAQ,IAAI;QACnC;IACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/cli/runtime/output.ts"],"sourcesContent":["import { type Command, CommanderError } from 'commander'\n\nimport { getCLIErrorExitCode } from './exitCodeHandlers.js'\nimport { redirectOutputToStderr, writeToCLIStdout } from './redirectOutputToStderr.js'\n\nexport type CLIErrorIssue = {\n message: string\n path?: string\n}\n\nexport class CLICommandError extends Error {\n code: string\n command?: string\n inputSchema?: Record<string, unknown>\n issues?: CLIErrorIssue[]\n\n constructor({\n cause,\n code = 'COMMAND_FAILED',\n command,\n inputSchema,\n issues,\n message,\n }: {\n cause?: unknown\n code?: string\n command?: string\n inputSchema?: Record<string, unknown>\n issues?: CLIErrorIssue[]\n message: string\n }) {\n super(message, { cause })\n this.name = 'CLICommandError'\n this.code = code\n this.command = command\n this.inputSchema = inputSchema\n this.issues = issues\n }\n}\n\nexport const isJSONOutput = (command?: Command): boolean => {\n if (command?.getOptionValueSourceWithGlobals('json') === 'cli') {\n return Boolean(command.optsWithGlobals<{ json?: boolean }>().json)\n }\n\n const separatorPosition = process.argv.indexOf('--', 2)\n const payloadArguments = process.argv.slice(\n 2,\n separatorPosition === -1 ? process.argv.length : separatorPosition,\n )\n const jsonPosition = payloadArguments.lastIndexOf('--json')\n const noJSONPosition = payloadArguments.lastIndexOf('--no-json')\n\n if (jsonPosition !== -1 || noJSONPosition !== -1) {\n return jsonPosition > noJSONPosition\n }\n\n return process.env.PAYLOAD_CLI_JSON !== undefined\n}\n\n/**\n * Runs CLI work with one effective output mode, then restores the previous process state.\n * JSON mode redirects diagnostic output and sets `PAYLOAD_CLI_JSON` so Payload loggers use stderr.\n */\nexport const withCLIOutputMode = async <T>({\n isJSON,\n run,\n}: {\n isJSON: boolean\n run: () => Promise<T> | T\n}): Promise<T> => {\n const previousJSONSetting = process.env.PAYLOAD_CLI_JSON\n const restoreOutput = isJSON ? redirectOutputToStderr() : undefined\n\n if (isJSON) {\n process.env.PAYLOAD_CLI_JSON = '1'\n } else {\n delete process.env.PAYLOAD_CLI_JSON\n }\n\n try {\n return await run()\n } finally {\n restoreOutput?.()\n\n if (previousJSONSetting === undefined) {\n delete process.env.PAYLOAD_CLI_JSON\n } else {\n process.env.PAYLOAD_CLI_JSON = previousJSONSetting\n }\n }\n}\n\nexport const writeCLIJSON = ({ command, value }: { command?: Command; value: unknown }): void => {\n const output = `${JSON.stringify(value, (_key, item) =>\n typeof item === 'bigint' ? item.toString() : item,\n )}\\n`\n const outputConfiguration = command?.configureOutput()\n\n writeToCLIStdout({\n output,\n write: outputConfiguration?.writeOut\n ? (value) => outputConfiguration.writeOut?.(value)\n : undefined,\n })\n}\n\nexport const getCLIErrorOutput = ({\n command,\n error,\n}: {\n command?: string\n error: unknown\n}): Record<string, unknown> => {\n if (error instanceof CLICommandError) {\n return {\n command: error.command ?? command,\n error: {\n code: error.code,\n message: error.message,\n ...(error.issues ? { issues: error.issues } : {}),\n ...(error.inputSchema ? { inputSchema: error.inputSchema } : {}),\n },\n success: false,\n }\n }\n\n const errorWithDetails = error as { code?: unknown; message?: unknown }\n\n return {\n ...(command ? { command } : {}),\n error: {\n code: typeof errorWithDetails?.code === 'string' ? errorWithDetails.code : 'COMMAND_FAILED',\n message:\n typeof errorWithDetails?.message === 'string'\n ? errorWithDetails.message\n : typeof error === 'string'\n ? error\n : 'Unknown error',\n },\n success: false,\n }\n}\n\n/**\n * Formats a CLI failure and sets its exit code.\n *\n * Commander prints its own human-readable errors before throwing a `CommanderError`, so they\n * are not printed again. Other errors are printed in full in human-readable mode to preserve\n * their stack trace.\n */\nexport const handleCLIError = ({ cli, error }: { cli?: Command; error: unknown }): void => {\n const exitCode =\n error instanceof CommanderError\n ? error.exitCode\n : getCLIErrorExitCode({\n error: error instanceof CLICommandError ? (error.cause ?? error) : error,\n })\n const shouldOutputJSON = isJSONOutput(cli)\n\n if (shouldOutputJSON && exitCode !== 0) {\n writeCLIJSON({\n command: cli,\n value: getCLIErrorOutput({ command: cli?.args[0], error }),\n })\n } else if (!(error instanceof CommanderError)) {\n // eslint-disable-next-line no-console\n console.error(error)\n }\n\n process.exitCode = exitCode\n}\n\n/** Wraps the CLI entry point so every failure uses the same output and exits cleanly. */\nexport const withErrorHandling =\n (run: () => Promise<void>): (() => Promise<void>) =>\n async () => {\n try {\n await run()\n } catch (error) {\n handleCLIError({ error })\n process.exit(process.exitCode ?? 1)\n }\n }\n"],"names":["CommanderError","getCLIErrorExitCode","redirectOutputToStderr","writeToCLIStdout","CLICommandError","Error","code","command","inputSchema","issues","cause","message","name","isJSONOutput","getOptionValueSourceWithGlobals","Boolean","optsWithGlobals","json","separatorPosition","process","argv","indexOf","payloadArguments","slice","length","jsonPosition","lastIndexOf","noJSONPosition","env","PAYLOAD_CLI_JSON","undefined","withCLIOutputMode","isJSON","run","previousJSONSetting","restoreOutput","writeCLIJSON","value","output","JSON","stringify","_key","item","toString","outputConfiguration","configureOutput","write","writeOut","getCLIErrorOutput","error","success","errorWithDetails","handleCLIError","cli","exitCode","shouldOutputJSON","args","console","withErrorHandling","exit"],"mappings":"AAAA,SAAuBA,cAAc,QAAQ,YAAW;AAExD,SAASC,mBAAmB,QAAQ,wBAAuB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iBxC,OAAO,GACxB,OAAOsC,UAAU,WACfA,QACA;QACV;QACAC,SAAS;IACX;AACF,EAAC;AAED;;;;;;CAMC,GACD,OAAO,MAAME,iBAAiB,CAAC,EAAEC,GAAG,EAAEJ,KAAK,EAAqC;IAC9E,MAAMK,WACJL,iBAAiBjD,iBACbiD,MAAMK,QAAQ,GACdrD,oBAAoB;QAClBgD,OAAOA,iBAAiB7C,kBAAmB6C,MAAMvC,KAAK,IAAIuC,QAASA;IACrE;IACN,MAAMM,mBAAmB1C,aAAawC;IAEtC,IAAIE,oBAAoBD,aAAa,GAAG;QACtClB,aAAa;YACX7B,SAAS8C;YACThB,OAAOW,kBAAkB;gBAAEzC,SAAS8C,KAAKG,IAAI,CAAC,EAAE;gBAAEP;YAAM;QAC1D;IACF,OAAO,IAAI,CAAEA,CAAAA,iBAAiBjD,cAAa,GAAI;QAC7C,sCAAsC;QACtCyD,QAAQR,KAAK,CAACA;IAChB;IAEA9B,QAAQmC,QAAQ,GAAGA;AACrB,EAAC;AAED,uFAAuF,GACvF,OAAO,MAAMI,oBACX,CAACzB,MACD;QACE,IAAI;YACF,MAAMA;QACR,EAAE,OAAOgB,OAAO;YACdG,eAAe;gBAAEH;YAAM;YACvB9B,QAAQwC,IAAI,CAACxC,QAAQmC,QAAQ,IAAI;QACnC;IACF,EAAC"}
@@ -11,9 +11,11 @@ function buildPluginsMap(plugins) {
11
11
  }
12
12
  export function definePlugin(descriptor) {
13
13
  return (options)=>{
14
+ // Read `pluginFn.options` when the plugin runs, so other plugins can edit or replace it, even
15
+ // when the plugin was registered without options
14
16
  const pluginFn = (config)=>descriptor.plugin({
15
17
  config,
16
- options: options,
18
+ options: pluginFn.options,
17
19
  plugins: buildPluginsMap(config.plugins)
18
20
  });
19
21
  if (options !== undefined) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config/definePlugin.ts"],"sourcesContent":["import type { Config, Plugin, PluginsMap } from './types.js'\n\nfunction buildPluginsMap(plugins: Plugin[] | undefined): PluginsMap {\n const map: Record<string, Plugin | undefined> = {}\n if (plugins) {\n for (const p of plugins) {\n if (p.slug) {\n map[p.slug] = p\n }\n }\n }\n return map\n}\n\n/**\n * Helper for authoring plugins with order, slug, and typed options.\n * Eliminates boilerplate and ensures metadata is always set consistently.\n *\n * The `plugin` function receives `config`, `plugins` (a slug-keyed map of other\n * plugins), and the user-provided `options`.\n *\n * @experimental\n *\n * @example\n * // With options:\n * export const seoPlugin = definePlugin<SEOPluginConfig>({\n * slug: 'plugin-seo',\n * plugin: ({ config, options }) => ({ ...config }),\n * })\n *\n * // Without options:\n * export const myPlugin = definePlugin({\n * slug: 'my-plugin',\n * plugin: ({ config }) => ({ ...config }),\n * })\n */\nexport function definePlugin(descriptor: {\n order?: number\n plugin: (args: { config: Config; plugins: PluginsMap }) => Config | Promise<Config>\n slug: string\n}): () => Plugin\nexport function definePlugin<TOptions>(descriptor: {\n order?: number\n plugin: (args: {\n config: Config\n options: TOptions\n plugins: PluginsMap\n }) => Config | Promise<Config>\n slug: string\n}): undefined extends TOptions ? (options?: TOptions) => Plugin : (options: TOptions) => Plugin\nexport function definePlugin<TOptions>(descriptor: {\n order?: number\n plugin: (args: {\n config: Config\n options: TOptions\n plugins: PluginsMap\n }) => Config | Promise<Config>\n slug: string\n}): (options: TOptions) => Plugin {\n return (options?: TOptions): Plugin => {\n const pluginFn: Plugin = (config) =>\n descriptor.plugin({\n config,\n options: options as TOptions,\n plugins: buildPluginsMap(config.plugins),\n })\n\n if (options !== undefined) {\n pluginFn.options = options as Record<string, unknown>\n }\n pluginFn.slug = descriptor.slug\n if (descriptor.order !== undefined) {\n pluginFn.order = descriptor.order\n }\n\n return pluginFn\n }\n}\n"],"names":["buildPluginsMap","plugins","map","p","slug","definePlugin","descriptor","options","pluginFn","config","plugin","undefined","order"],"mappings":"AAEA,SAASA,gBAAgBC,OAA6B;IACpD,MAAMC,MAA0C,CAAC;IACjD,IAAID,SAAS;QACX,KAAK,MAAME,KAAKF,QAAS;YACvB,IAAIE,EAAEC,IAAI,EAAE;gBACVF,GAAG,CAACC,EAAEC,IAAI,CAAC,GAAGD;YAChB;QACF;IACF;IACA,OAAOD;AACT;AAsCA,OAAO,SAASG,aAAuBC,UAQtC;IACC,OAAO,CAACC;QACN,MAAMC,WAAmB,CAACC,SACxBH,WAAWI,MAAM,CAAC;gBAChBD;gBACAF,SAASA;gBACTN,SAASD,gBAAgBS,OAAOR,OAAO;YACzC;QAEF,IAAIM,YAAYI,WAAW;YACzBH,SAASD,OAAO,GAAGA;QACrB;QACAC,SAASJ,IAAI,GAAGE,WAAWF,IAAI;QAC/B,IAAIE,WAAWM,KAAK,KAAKD,WAAW;YAClCH,SAASI,KAAK,GAAGN,WAAWM,KAAK;QACnC;QAEA,OAAOJ;IACT;AACF"}
1
+ {"version":3,"sources":["../../src/config/definePlugin.ts"],"sourcesContent":["import type { Config, Plugin, PluginsMap } from './types.js'\n\nfunction buildPluginsMap(plugins: Plugin[] | undefined): PluginsMap {\n const map: Record<string, Plugin | undefined> = {}\n if (plugins) {\n for (const p of plugins) {\n if (p.slug) {\n map[p.slug] = p\n }\n }\n }\n return map\n}\n\n/**\n * Helper for authoring plugins with order, slug, and typed options.\n * Eliminates boilerplate and ensures metadata is always set consistently.\n *\n * The `plugin` function receives `config`, `plugins` (a slug-keyed map of other\n * plugins), and the user-provided `options`.\n *\n * @experimental\n *\n * @example\n * // With options:\n * export const seoPlugin = definePlugin<SEOPluginConfig>({\n * slug: 'plugin-seo',\n * plugin: ({ config, options }) => ({ ...config }),\n * })\n *\n * // Without options:\n * export const myPlugin = definePlugin({\n * slug: 'my-plugin',\n * plugin: ({ config }) => ({ ...config }),\n * })\n */\nexport function definePlugin(descriptor: {\n order?: number\n plugin: (args: { config: Config; plugins: PluginsMap }) => Config | Promise<Config>\n slug: string\n}): () => Plugin\nexport function definePlugin<TOptions>(descriptor: {\n order?: number\n plugin: (args: {\n config: Config\n options: TOptions\n plugins: PluginsMap\n }) => Config | Promise<Config>\n slug: string\n}): undefined extends TOptions ? (options?: TOptions) => Plugin : (options: TOptions) => Plugin\nexport function definePlugin<TOptions>(descriptor: {\n order?: number\n plugin: (args: {\n config: Config\n options: TOptions\n plugins: PluginsMap\n }) => Config | Promise<Config>\n slug: string\n}): (options: TOptions) => Plugin {\n return (options?: TOptions): Plugin => {\n // Read `pluginFn.options` when the plugin runs, so other plugins can edit or replace it, even\n // when the plugin was registered without options\n const pluginFn: Plugin = (config) =>\n descriptor.plugin({\n config,\n options: pluginFn.options as TOptions,\n plugins: buildPluginsMap(config.plugins),\n })\n\n if (options !== undefined) {\n pluginFn.options = options as Record<string, unknown>\n }\n pluginFn.slug = descriptor.slug\n if (descriptor.order !== undefined) {\n pluginFn.order = descriptor.order\n }\n\n return pluginFn\n }\n}\n"],"names":["buildPluginsMap","plugins","map","p","slug","definePlugin","descriptor","options","pluginFn","config","plugin","undefined","order"],"mappings":"AAEA,SAASA,gBAAgBC,OAA6B;IACpD,MAAMC,MAA0C,CAAC;IACjD,IAAID,SAAS;QACX,KAAK,MAAME,KAAKF,QAAS;YACvB,IAAIE,EAAEC,IAAI,EAAE;gBACVF,GAAG,CAACC,EAAEC,IAAI,CAAC,GAAGD;YAChB;QACF;IACF;IACA,OAAOD;AACT;AAsCA,OAAO,SAASG,aAAuBC,UAQtC;IACC,OAAO,CAACC;QACN,8FAA8F;QAC9F,iDAAiD;QACjD,MAAMC,WAAmB,CAACC,SACxBH,WAAWI,MAAM,CAAC;gBAChBD;gBACAF,SAASC,SAASD,OAAO;gBACzBN,SAASD,gBAAgBS,OAAOR,OAAO;YACzC;QAEF,IAAIM,YAAYI,WAAW;YACzBH,SAASD,OAAO,GAAGA;QACrB;QACAC,SAASJ,IAAI,GAAGE,WAAWF,IAAI;QAC/B,IAAIE,WAAWM,KAAK,KAAKD,WAAW;YAClCH,SAASI,KAAK,GAAGN,WAAWM,KAAK;QACnC;QAEA,OAAOJ;IACT;AACF"}
@@ -10,7 +10,7 @@ export type { SchemaBuildContext } from '../database/createSchemaBuildContext.js
10
10
  export { getLLMInstructions } from '../llm-instructions/getInstructions.js';
11
11
  export { assertClientUploadAccess } from '../uploads/assertClientUploadAccess.js';
12
12
  export { assertClientUploadAllowed } from '../uploads/assertClientUploadAllowed.js';
13
- export { createClientUploadReceipt, verifyClientUploadReceipt, } from '../uploads/clientUploadReceipt.js';
13
+ export { createClientUploadReceipt, resignClientUploadReceipt, verifyClientUploadReceipt, } from '../uploads/clientUploadReceipt.js';
14
14
  export { downloadFileToBuffer } from '../uploads/downloadFileToBuffer.js';
15
15
  export { getUploadInstructions } from '../uploads/endpoints/uploadInstructions.js';
16
16
  export { getOriginalFilename } from '../uploads/fileVersioning/naming.js';
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/exports/internal.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,KAAK,iBAAiB,EACtB,gBAAgB,EAChB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAA;AAClF,YAAY,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAA;AACjF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAA;AACnF,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4CAA4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B,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,oDAAoD,CAAA;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAA;AACvF,OAAO,EACL,eAAe,EACf,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,GAC1B,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2DAA2D,CAAA;AAChG,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA"}
@@ -8,7 +8,7 @@ export { createSchemaBuildContext } from '../database/createSchemaBuildContext.j
8
8
  export { getLLMInstructions } from '../llm-instructions/getInstructions.js';
9
9
  export { assertClientUploadAccess } from '../uploads/assertClientUploadAccess.js';
10
10
  export { assertClientUploadAllowed } from '../uploads/assertClientUploadAllowed.js';
11
- export { createClientUploadReceipt, verifyClientUploadReceipt } from '../uploads/clientUploadReceipt.js';
11
+ export { createClientUploadReceipt, resignClientUploadReceipt, verifyClientUploadReceipt } from '../uploads/clientUploadReceipt.js';
12
12
  export { downloadFileToBuffer } from '../uploads/downloadFileToBuffer.js';
13
13
  export { getUploadInstructions } from '../uploads/endpoints/uploadInstructions.js';
14
14
  export { getOriginalFilename } from '../uploads/fileVersioning/naming.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exports/internal.ts"],"sourcesContent":["/**\n * Modules exported here are not part of the public API and are subject to change without notice and without a major version bump.\n */\n\nexport {\n type AdminContextCache,\n initAdminContext,\n type InitAdminContextArgs,\n type PartialAdminContext,\n} from '../admin/initAdminContext.js'\nexport { applyUserReadAccess } from '../auth/applyUserReadAccess.js'\nexport { createCLI } from '../cli/index.js'\nexport { getCommandInput } from '../cli/runtime/getCommandInput.js'\nexport { createSchemaBuildContext } from '../database/createSchemaBuildContext.js'\nexport type { SchemaBuildContext } from '../database/createSchemaBuildContext.js'\nexport { getLLMInstructions } from '../llm-instructions/getInstructions.js'\nexport { assertClientUploadAccess } from '../uploads/assertClientUploadAccess.js'\nexport { assertClientUploadAllowed } from '../uploads/assertClientUploadAllowed.js'\nexport {\n createClientUploadReceipt,\n verifyClientUploadReceipt,\n} from '../uploads/clientUploadReceipt.js'\nexport { downloadFileToBuffer } from '../uploads/downloadFileToBuffer.js'\nexport { getUploadInstructions } from '../uploads/endpoints/uploadInstructions.js'\nexport { getOriginalFilename } from '../uploads/fileVersioning/naming.js'\nexport { getFileFromUploadInstructions } from '../uploads/getFileFromUploadInstructions.js'\nexport { isXmlMimeType } from '../uploads/getFileTypeIdentity.js'\nexport { getRangeRequestInfo } from '../uploads/getRangeRequestInfo.js'\nexport { getSafeFileName, incrementName } from '../uploads/getSafeFilename.js'\nexport { parseRangeHeader } from '../uploads/parseRangeHeader.js'\nexport { externalURLInputSchema, resolveURLUploadInput } from '../uploads/resolveURLUploadInput.js'\nexport type { ExternalURLInput } from '../uploads/resolveURLUploadInput.js'\nexport {\n getUploadFilePath,\n getUploadTransformerInternal,\n setUploadFilePath,\n uploadTransformerInternal,\n} from '../uploads/transformers/uploadTransformerBridge.js'\nexport type {\n PreparedUploadTransformation,\n TransformerWithInternalBridge,\n UploadTransformerInternal,\n UploadTransformTask,\n} from '../uploads/transformers/uploadTransformerBridge.js'\nexport { uploadContentSecurityPolicy } from '../uploads/uploadContentSecurityPolicy.js'\nexport {\n batchProcessing,\n type BatchProcessingOptions,\n type BatchProcessorResult,\n} from '../utilities/batchProcessing.js'\nexport { getEntityPermissions } from '../utilities/getEntityPermissions/getEntityPermissions.js'\nexport { httpStatus } from '../utilities/httpStatus.js'\nexport { isURLAllowed } from '../utilities/isURLAllowed.js'\nexport { sanitizePermissions } from '../utilities/sanitizePermissions.js'\nexport { sendTelemetryEvent } from '../utilities/telemetry/index.js'\n"],"names":["initAdminContext","applyUserReadAccess","createCLI","getCommandInput","createSchemaBuildContext","getLLMInstructions","assertClientUploadAccess","assertClientUploadAllowed","createClientUploadReceipt","verifyClientUploadReceipt","downloadFileToBuffer","getUploadInstructions","getOriginalFilename","getFileFromUploadInstructions","isXmlMimeType","getRangeRequestInfo","getSafeFileName","incrementName","parseRangeHeader","externalURLInputSchema","resolveURLUploadInput","getUploadFilePath","getUploadTransformerInternal","setUploadFilePath","uploadTransformerInternal","uploadContentSecurityPolicy","batchProcessing","getEntityPermissions","httpStatus","isURLAllowed","sanitizePermissions","sendTelemetryEvent"],"mappings":"AAAA;;CAEC,GAED,SAEEA,gBAAgB,QAGX,+BAA8B;AACrC,SAASC,mBAAmB,QAAQ,iCAAgC;AACpE,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,eAAe,QAAQ,oCAAmC;AACnE,SAASC,wBAAwB,QAAQ,0CAAyC;AAElF,SAASC,kBAAkB,QAAQ,yCAAwC;AAC3E,SAASC,wBAAwB,QAAQ,yCAAwC;AACjF,SAASC,yBAAyB,QAAQ,0CAAyC;AACnF,SACEC,yBAAyB,EACzBC,yBAAyB,QACpB,oCAAmC;AAC1C,SAASC,oBAAoB,QAAQ,qCAAoC;AACzE,SAASC,qBAAqB,QAAQ,6CAA4C;AAClF,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,6BAA6B,QAAQ,8CAA6C;AAC3F,SAASC,aAAa,QAAQ,oCAAmC;AACjE,SAASC,mBAAmB,QAAQ,oCAAmC;AACvE,SAASC,eAAe,EAAEC,aAAa,QAAQ,gCAA+B;AAC9E,SAASC,gBAAgB,QAAQ,iCAAgC;AACjE,SAASC,sBAAsB,EAAEC,qBAAqB,QAAQ,sCAAqC;AAEnG,SACEC,iBAAiB,EACjBC,4BAA4B,EAC5BC,iBAAiB,EACjBC,yBAAyB,QACpB,qDAAoD;AAO3D,SAASC,2BAA2B,QAAQ,4CAA2C;AACvF,SACEC,eAAe,QAGV,kCAAiC;AACxC,SAASC,oBAAoB,QAAQ,4DAA2D;AAChG,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,YAAY,QAAQ,+BAA8B;AAC3D,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,kBAAkB,QAAQ,kCAAiC"}
1
+ {"version":3,"sources":["../../src/exports/internal.ts"],"sourcesContent":["/**\n * Modules exported here are not part of the public API and are subject to change without notice and without a major version bump.\n */\n\nexport {\n type AdminContextCache,\n initAdminContext,\n type InitAdminContextArgs,\n type PartialAdminContext,\n} from '../admin/initAdminContext.js'\nexport { applyUserReadAccess } from '../auth/applyUserReadAccess.js'\nexport { createCLI } from '../cli/index.js'\nexport { getCommandInput } from '../cli/runtime/getCommandInput.js'\nexport { createSchemaBuildContext } from '../database/createSchemaBuildContext.js'\nexport type { SchemaBuildContext } from '../database/createSchemaBuildContext.js'\nexport { getLLMInstructions } from '../llm-instructions/getInstructions.js'\nexport { assertClientUploadAccess } from '../uploads/assertClientUploadAccess.js'\nexport { assertClientUploadAllowed } from '../uploads/assertClientUploadAllowed.js'\nexport {\n createClientUploadReceipt,\n resignClientUploadReceipt,\n verifyClientUploadReceipt,\n} from '../uploads/clientUploadReceipt.js'\nexport { downloadFileToBuffer } from '../uploads/downloadFileToBuffer.js'\nexport { getUploadInstructions } from '../uploads/endpoints/uploadInstructions.js'\nexport { getOriginalFilename } from '../uploads/fileVersioning/naming.js'\nexport { getFileFromUploadInstructions } from '../uploads/getFileFromUploadInstructions.js'\nexport { isXmlMimeType } from '../uploads/getFileTypeIdentity.js'\nexport { getRangeRequestInfo } from '../uploads/getRangeRequestInfo.js'\nexport { getSafeFileName, incrementName } from '../uploads/getSafeFilename.js'\nexport { parseRangeHeader } from '../uploads/parseRangeHeader.js'\nexport { externalURLInputSchema, resolveURLUploadInput } from '../uploads/resolveURLUploadInput.js'\nexport type { ExternalURLInput } from '../uploads/resolveURLUploadInput.js'\nexport {\n getUploadFilePath,\n getUploadTransformerInternal,\n setUploadFilePath,\n uploadTransformerInternal,\n} from '../uploads/transformers/uploadTransformerBridge.js'\nexport type {\n PreparedUploadTransformation,\n TransformerWithInternalBridge,\n UploadTransformerInternal,\n UploadTransformTask,\n} from '../uploads/transformers/uploadTransformerBridge.js'\nexport { uploadContentSecurityPolicy } from '../uploads/uploadContentSecurityPolicy.js'\nexport {\n batchProcessing,\n type BatchProcessingOptions,\n type BatchProcessorResult,\n} from '../utilities/batchProcessing.js'\nexport { getEntityPermissions } from '../utilities/getEntityPermissions/getEntityPermissions.js'\nexport { httpStatus } from '../utilities/httpStatus.js'\nexport { isURLAllowed } from '../utilities/isURLAllowed.js'\nexport { sanitizePermissions } from '../utilities/sanitizePermissions.js'\nexport { sendTelemetryEvent } from '../utilities/telemetry/index.js'\n"],"names":["initAdminContext","applyUserReadAccess","createCLI","getCommandInput","createSchemaBuildContext","getLLMInstructions","assertClientUploadAccess","assertClientUploadAllowed","createClientUploadReceipt","resignClientUploadReceipt","verifyClientUploadReceipt","downloadFileToBuffer","getUploadInstructions","getOriginalFilename","getFileFromUploadInstructions","isXmlMimeType","getRangeRequestInfo","getSafeFileName","incrementName","parseRangeHeader","externalURLInputSchema","resolveURLUploadInput","getUploadFilePath","getUploadTransformerInternal","setUploadFilePath","uploadTransformerInternal","uploadContentSecurityPolicy","batchProcessing","getEntityPermissions","httpStatus","isURLAllowed","sanitizePermissions","sendTelemetryEvent"],"mappings":"AAAA;;CAEC,GAED,SAEEA,gBAAgB,QAGX,+BAA8B;AACrC,SAASC,mBAAmB,QAAQ,iCAAgC;AACpE,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,eAAe,QAAQ,oCAAmC;AACnE,SAASC,wBAAwB,QAAQ,0CAAyC;AAElF,SAASC,kBAAkB,QAAQ,yCAAwC;AAC3E,SAASC,wBAAwB,QAAQ,yCAAwC;AACjF,SAASC,yBAAyB,QAAQ,0CAAyC;AACnF,SACEC,yBAAyB,EACzBC,yBAAyB,EACzBC,yBAAyB,QACpB,oCAAmC;AAC1C,SAASC,oBAAoB,QAAQ,qCAAoC;AACzE,SAASC,qBAAqB,QAAQ,6CAA4C;AAClF,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,6BAA6B,QAAQ,8CAA6C;AAC3F,SAASC,aAAa,QAAQ,oCAAmC;AACjE,SAASC,mBAAmB,QAAQ,oCAAmC;AACvE,SAASC,eAAe,EAAEC,aAAa,QAAQ,gCAA+B;AAC9E,SAASC,gBAAgB,QAAQ,iCAAgC;AACjE,SAASC,sBAAsB,EAAEC,qBAAqB,QAAQ,sCAAqC;AAEnG,SACEC,iBAAiB,EACjBC,4BAA4B,EAC5BC,iBAAiB,EACjBC,yBAAyB,QACpB,qDAAoD;AAO3D,SAASC,2BAA2B,QAAQ,4CAA2C;AACvF,SACEC,eAAe,QAGV,kCAAiC;AACxC,SAASC,oBAAoB,QAAQ,4DAA2D;AAChG,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,YAAY,QAAQ,+BAA8B;AAC3D,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,kBAAkB,QAAQ,kCAAiC"}