payload 3.40.0-internal.9e8d70e → 3.40.0
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/dist/auth/cookies.d.ts +1 -1
- package/dist/auth/cookies.d.ts.map +1 -1
- package/dist/auth/cookies.js +39 -16
- package/dist/auth/cookies.js.map +1 -1
- package/dist/auth/cookies.spec.js +33 -0
- package/dist/auth/cookies.spec.js.map +1 -0
- package/dist/auth/executeAuthStrategies.js +1 -1
- package/dist/auth/executeAuthStrategies.js.map +1 -1
- package/dist/auth/operations/auth.d.ts +3 -3
- package/dist/auth/operations/auth.d.ts.map +1 -1
- package/dist/auth/operations/auth.js +2 -2
- package/dist/auth/operations/auth.js.map +1 -1
- package/dist/auth/operations/local/auth.js +1 -1
- package/dist/auth/operations/local/auth.js.map +1 -1
- package/dist/auth/operations/local/resetPassword.d.ts +1 -1
- package/dist/auth/operations/local/resetPassword.d.ts.map +1 -1
- package/dist/auth/operations/local/resetPassword.js.map +1 -1
- package/dist/auth/operations/resetPassword.d.ts +2 -1
- package/dist/auth/operations/resetPassword.d.ts.map +1 -1
- package/dist/auth/operations/resetPassword.js +22 -1
- package/dist/auth/operations/resetPassword.js.map +1 -1
- package/dist/auth/types.d.ts +3 -3
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/bin/migrate.d.ts.map +1 -1
- package/dist/bin/migrate.js +1 -0
- package/dist/bin/migrate.js.map +1 -1
- package/dist/collections/config/types.d.ts +1 -1
- package/dist/collections/config/types.d.ts.map +1 -1
- package/dist/collections/config/types.js.map +1 -1
- package/dist/collections/operations/utils.d.ts +6 -0
- package/dist/collections/operations/utils.d.ts.map +1 -1
- package/dist/collections/operations/utils.js.map +1 -1
- package/dist/exports/shared.d.ts +1 -0
- package/dist/exports/shared.d.ts.map +1 -1
- package/dist/exports/shared.js +1 -0
- package/dist/exports/shared.js.map +1 -1
- package/dist/utilities/createPayloadRequest.d.ts +2 -1
- package/dist/utilities/createPayloadRequest.d.ts.map +1 -1
- package/dist/utilities/createPayloadRequest.js +2 -1
- package/dist/utilities/createPayloadRequest.js.map +1 -1
- package/dist/utilities/getRequestLanguage.js.map +1 -1
- package/dist/utilities/getSafeRedirect.d.ts +6 -0
- package/dist/utilities/getSafeRedirect.d.ts.map +1 -0
- package/dist/utilities/getSafeRedirect.js +25 -0
- package/dist/utilities/getSafeRedirect.js.map +1 -0
- package/dist/utilities/getSafeRedirect.spec.js +83 -0
- package/dist/utilities/getSafeRedirect.spec.js.map +1 -0
- package/dist/utilities/handleEndpoints.js +1 -0
- package/dist/utilities/handleEndpoints.js.map +1 -1
- package/dist/utilities/parseCookies.js +2 -3
- package/dist/utilities/parseCookies.js.map +1 -1
- package/package.json +2 -2
package/dist/auth/cookies.d.ts
CHANGED
|
@@ -35,6 +35,6 @@ type GeneratePayloadCookieArgs = {
|
|
|
35
35
|
};
|
|
36
36
|
export declare const generatePayloadCookie: <T extends GeneratePayloadCookieArgs>({ collectionAuthConfig, cookiePrefix, returnCookieAsObject, token, }: T) => T["returnCookieAsObject"] extends true ? CookieObject : string;
|
|
37
37
|
export declare const generateExpiredPayloadCookie: <T extends Omit<GeneratePayloadCookieArgs, "token">>({ collectionAuthConfig, cookiePrefix, returnCookieAsObject, }: T) => T["returnCookieAsObject"] extends true ? CookieObject : string;
|
|
38
|
-
export declare
|
|
38
|
+
export declare function parseCookies(headers: Request['headers']): Map<string, string>;
|
|
39
39
|
export {};
|
|
40
40
|
//# sourceMappingURL=cookies.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../src/auth/cookies.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAA;AAEjF,KAAK,aAAa,GAAG;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,QAAQ,C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AAG,MAiFrD,CAAA;AACD,KAAK,uBAAuB,GAAG;IAK7B,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AACD,eAAO,MAAM,mBAAmB,gBAAwB,uBAAuB,SAI9E,CAAA;AAED,KAAK,yBAAyB,GAAG;IAE/B,oBAAoB,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAA;IAEvD,YAAY,EAAE,MAAM,CAAA;IAEpB,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAE9B,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AACD,eAAO,MAAM,qBAAqB,GAAI,CAAC,SAAS,yBAAyB,wEAKtE,CAAC,KAAG,CAAC,CAAC,sBAAsB,CAAC,SAAS,IAAI,GAAG,YAAY,GAAG,MAmB9D,CAAA;AAED,eAAO,MAAM,4BAA4B,GAAI,CAAC,SAAS,IAAI,CAAC,yBAAyB,EAAE,OAAO,CAAC,iEAI5F,CAAC,KAAG,CAAC,CAAC,sBAAsB,CAAC,SAAS,IAAI,GAAG,YAAY,GAAG,MAoB9D,CAAA;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,uBA8CvD"}
|
package/dist/auth/cookies.js
CHANGED
|
@@ -93,23 +93,46 @@ export const generateExpiredPayloadCookie = ({ collectionAuthConfig, cookiePrefi
|
|
|
93
93
|
secure: collectionAuthConfig.cookies.secure
|
|
94
94
|
});
|
|
95
95
|
};
|
|
96
|
-
export
|
|
97
|
-
|
|
96
|
+
export function parseCookies(headers) {
|
|
97
|
+
// Taken from https://github.com/vercel/edge-runtime/blob/main/packages/cookies/src/serialize.ts
|
|
98
|
+
/*
|
|
99
|
+
The MIT License (MIT)
|
|
100
|
+
|
|
101
|
+
Copyright (c) 2024 Vercel, Inc.
|
|
102
|
+
|
|
103
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
104
|
+
|
|
105
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
106
|
+
|
|
107
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
108
|
+
*/ const map = new Map();
|
|
98
109
|
const cookie = headers.get('Cookie');
|
|
99
|
-
if (cookie) {
|
|
100
|
-
|
|
101
|
-
const parts = cookie.split('=');
|
|
102
|
-
const key = parts.shift()?.trim();
|
|
103
|
-
const encodedValue = parts.join('=');
|
|
104
|
-
try {
|
|
105
|
-
const decodedValue = decodeURI(encodedValue);
|
|
106
|
-
cookieMap.set(key, decodedValue);
|
|
107
|
-
} catch (ignore) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
110
|
+
if (!cookie) {
|
|
111
|
+
return map;
|
|
111
112
|
}
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
for (const pair of cookie.split(/; */)){
|
|
114
|
+
if (!pair) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const splitAt = pair.indexOf('=');
|
|
118
|
+
// If the attribute doesn't have a value, set it to 'true'.
|
|
119
|
+
if (splitAt === -1) {
|
|
120
|
+
map.set(pair, 'true');
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
// Otherwise split it into key and value and trim the whitespace on the
|
|
124
|
+
// value.
|
|
125
|
+
const [key, value] = [
|
|
126
|
+
pair.slice(0, splitAt),
|
|
127
|
+
pair.slice(splitAt + 1)
|
|
128
|
+
];
|
|
129
|
+
try {
|
|
130
|
+
map.set(key, decodeURIComponent(value ?? 'true'));
|
|
131
|
+
} catch {
|
|
132
|
+
// ignore invalid encoded values
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return map;
|
|
136
|
+
}
|
|
114
137
|
|
|
115
138
|
//# sourceMappingURL=cookies.js.map
|
package/dist/auth/cookies.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/cookies.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { SanitizedCollectionConfig } from './../collections/config/types.js'\n\ntype CookieOptions = {\n domain?: string\n expires?: Date\n httpOnly?: boolean\n maxAge?: number\n name: string\n path?: string\n returnCookieAsObject: boolean\n sameSite?: 'Lax' | 'None' | 'Strict'\n secure?: boolean\n value?: string\n}\n\ntype CookieObject = {\n domain?: string\n expires?: string\n httpOnly?: boolean\n maxAge?: number\n name: string\n path?: string\n sameSite?: 'Lax' | 'None' | 'Strict'\n secure?: boolean\n value: string | undefined\n}\n\nexport const generateCookie = <ReturnCookieAsObject = boolean>(\n args: CookieOptions,\n): ReturnCookieAsObject extends true ? CookieObject : string => {\n const {\n name,\n domain,\n expires,\n httpOnly,\n maxAge,\n path,\n returnCookieAsObject,\n sameSite,\n secure: secureArg,\n value,\n } = args\n\n let cookieString = `${name}=${value || ''}`\n const cookieObject: CookieObject = {\n name,\n value,\n }\n\n const secure = secureArg || sameSite === 'None'\n\n if (expires) {\n if (returnCookieAsObject) {\n cookieObject.expires = expires.toUTCString()\n } else {\n cookieString += `; Expires=${expires.toUTCString()}`\n }\n }\n\n if (maxAge) {\n if (returnCookieAsObject) {\n cookieObject.maxAge = maxAge\n } else {\n cookieString += `; Max-Age=${maxAge.toString()}`\n }\n }\n\n if (domain) {\n if (returnCookieAsObject) {\n cookieObject.domain = domain\n } else {\n cookieString += `; Domain=${domain}`\n }\n }\n\n if (path) {\n if (returnCookieAsObject) {\n cookieObject.path = path\n } else {\n cookieString += `; Path=${path}`\n }\n }\n\n if (secure) {\n if (returnCookieAsObject) {\n cookieObject.secure = secure\n } else {\n cookieString += `; Secure=${secure}`\n }\n }\n\n if (httpOnly) {\n if (returnCookieAsObject) {\n cookieObject.httpOnly = httpOnly\n } else {\n cookieString += `; HttpOnly=${httpOnly}`\n }\n }\n\n if (sameSite) {\n if (returnCookieAsObject) {\n cookieObject.sameSite = sameSite\n } else {\n cookieString += `; SameSite=${sameSite}`\n }\n }\n\n return (returnCookieAsObject ? cookieObject : cookieString) as ReturnCookieAsObject extends true\n ? CookieObject\n : string\n}\ntype GetCookieExpirationArgs = {\n /*\n The number of seconds until the cookie expires\n @default 7200 seconds (2 hours)\n */\n seconds: number\n}\nexport const getCookieExpiration = ({ seconds = 7200 }: GetCookieExpirationArgs) => {\n const currentTime = new Date()\n currentTime.setSeconds(currentTime.getSeconds() + seconds)\n return currentTime\n}\n\ntype GeneratePayloadCookieArgs = {\n /* The auth collection config */\n collectionAuthConfig: SanitizedCollectionConfig['auth']\n /* Prefix to scope the cookie */\n cookiePrefix: string\n /* The returnAs value */\n returnCookieAsObject?: boolean\n /* The token to be stored in the cookie */\n token: string\n}\nexport const generatePayloadCookie = <T extends GeneratePayloadCookieArgs>({\n collectionAuthConfig,\n cookiePrefix,\n returnCookieAsObject = false,\n token,\n}: T): T['returnCookieAsObject'] extends true ? CookieObject : string => {\n const sameSite =\n typeof collectionAuthConfig.cookies.sameSite === 'string'\n ? collectionAuthConfig.cookies.sameSite\n : collectionAuthConfig.cookies.sameSite\n ? 'Strict'\n : undefined\n\n return generateCookie<T['returnCookieAsObject']>({\n name: `${cookiePrefix}-token`,\n domain: collectionAuthConfig.cookies.domain ?? undefined,\n expires: getCookieExpiration({ seconds: collectionAuthConfig.tokenExpiration }),\n httpOnly: true,\n path: '/',\n returnCookieAsObject,\n sameSite,\n secure: collectionAuthConfig.cookies.secure,\n value: token,\n })\n}\n\nexport const generateExpiredPayloadCookie = <T extends Omit<GeneratePayloadCookieArgs, 'token'>>({\n collectionAuthConfig,\n cookiePrefix,\n returnCookieAsObject = false,\n}: T): T['returnCookieAsObject'] extends true ? CookieObject : string => {\n const sameSite =\n typeof collectionAuthConfig.cookies.sameSite === 'string'\n ? collectionAuthConfig.cookies.sameSite\n : collectionAuthConfig.cookies.sameSite\n ? 'Strict'\n : undefined\n\n const expires = new Date(Date.now() - 1000)\n\n return generateCookie<T['returnCookieAsObject']>({\n name: `${cookiePrefix}-token`,\n domain: collectionAuthConfig.cookies.domain ?? undefined,\n expires,\n httpOnly: true,\n path: '/',\n returnCookieAsObject,\n sameSite,\n secure: collectionAuthConfig.cookies.secure,\n })\n}\n\nexport const parseCookies = (headers: Request['headers']): Map<string, string> => {\n const cookieMap = new Map<string, string>()\n const cookie = headers.get('Cookie')\n\n if (cookie) {\n cookie.split(';').forEach((cookie) => {\n const parts = cookie.split('=')\n const key = parts.shift()?.trim()\n const encodedValue = parts.join('=')\n\n try {\n const decodedValue = decodeURI(encodedValue)\n cookieMap.set(key, decodedValue)\n } catch (ignore) {\n return null\n }\n })\n }\n\n return cookieMap\n}\n"],"names":["generateCookie","args","name","domain","expires","httpOnly","maxAge","path","returnCookieAsObject","sameSite","secure","secureArg","value","cookieString","cookieObject","toUTCString","toString","getCookieExpiration","seconds","currentTime","Date","setSeconds","getSeconds","generatePayloadCookie","collectionAuthConfig","cookiePrefix","token","cookies","undefined","tokenExpiration","generateExpiredPayloadCookie","now","parseCookies","headers","cookieMap","Map","cookie","get","split","forEach","parts","key","shift","trim","encodedValue","join","decodedValue","decodeURI","set","ignore"],"mappings":"AAAA,oBAAoB;AA4BpB,OAAO,MAAMA,iBAAiB,CAC5BC;IAEA,MAAM,EACJC,IAAI,EACJC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACRC,MAAM,EACNC,IAAI,EACJC,oBAAoB,EACpBC,QAAQ,EACRC,QAAQC,SAAS,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MC,SAASH,QAAQI,GAAG,CAAC;IAE3B,IAAID,QAAQ;QACVA,OAAOE,KAAK,CAAC,KAAKC,OAAO,CAAC,CAACH;YACzB,MAAMI,QAAQJ,OAAOE,KAAK,CAAC;YAC3B,MAAMG,MAAMD,MAAME,KAAK,IAAIC;YAC3B,MAAMC,eAAeJ,MAAMK,IAAI,CAAC;YAEhC,IAAI;gBACF,MAAMC,eAAeC,UAAUH;gBAC/BV,UAAUc,GAAG,CAACP,KAAKK;YACrB,EAAE,OAAOG,QAAQ;gBACf,OAAO;YACT;QACF;IACF;IAEA,OAAOf;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/auth/cookies.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { SanitizedCollectionConfig } from './../collections/config/types.js'\n\ntype CookieOptions = {\n domain?: string\n expires?: Date\n httpOnly?: boolean\n maxAge?: number\n name: string\n path?: string\n returnCookieAsObject: boolean\n sameSite?: 'Lax' | 'None' | 'Strict'\n secure?: boolean\n value?: string\n}\n\ntype CookieObject = {\n domain?: string\n expires?: string\n httpOnly?: boolean\n maxAge?: number\n name: string\n path?: string\n sameSite?: 'Lax' | 'None' | 'Strict'\n secure?: boolean\n value: string | undefined\n}\n\nexport const generateCookie = <ReturnCookieAsObject = boolean>(\n args: CookieOptions,\n): ReturnCookieAsObject extends true ? CookieObject : string => {\n const {\n name,\n domain,\n expires,\n httpOnly,\n maxAge,\n path,\n returnCookieAsObject,\n sameSite,\n secure: secureArg,\n value,\n } = args\n\n let cookieString = `${name}=${value || ''}`\n const cookieObject: CookieObject = {\n name,\n value,\n }\n\n const secure = secureArg || sameSite === 'None'\n\n if (expires) {\n if (returnCookieAsObject) {\n cookieObject.expires = expires.toUTCString()\n } else {\n cookieString += `; Expires=${expires.toUTCString()}`\n }\n }\n\n if (maxAge) {\n if (returnCookieAsObject) {\n cookieObject.maxAge = maxAge\n } else {\n cookieString += `; Max-Age=${maxAge.toString()}`\n }\n }\n\n if (domain) {\n if (returnCookieAsObject) {\n cookieObject.domain = domain\n } else {\n cookieString += `; Domain=${domain}`\n }\n }\n\n if (path) {\n if (returnCookieAsObject) {\n cookieObject.path = path\n } else {\n cookieString += `; Path=${path}`\n }\n }\n\n if (secure) {\n if (returnCookieAsObject) {\n cookieObject.secure = secure\n } else {\n cookieString += `; Secure=${secure}`\n }\n }\n\n if (httpOnly) {\n if (returnCookieAsObject) {\n cookieObject.httpOnly = httpOnly\n } else {\n cookieString += `; HttpOnly=${httpOnly}`\n }\n }\n\n if (sameSite) {\n if (returnCookieAsObject) {\n cookieObject.sameSite = sameSite\n } else {\n cookieString += `; SameSite=${sameSite}`\n }\n }\n\n return (returnCookieAsObject ? cookieObject : cookieString) as ReturnCookieAsObject extends true\n ? CookieObject\n : string\n}\ntype GetCookieExpirationArgs = {\n /*\n The number of seconds until the cookie expires\n @default 7200 seconds (2 hours)\n */\n seconds: number\n}\nexport const getCookieExpiration = ({ seconds = 7200 }: GetCookieExpirationArgs) => {\n const currentTime = new Date()\n currentTime.setSeconds(currentTime.getSeconds() + seconds)\n return currentTime\n}\n\ntype GeneratePayloadCookieArgs = {\n /* The auth collection config */\n collectionAuthConfig: SanitizedCollectionConfig['auth']\n /* Prefix to scope the cookie */\n cookiePrefix: string\n /* The returnAs value */\n returnCookieAsObject?: boolean\n /* The token to be stored in the cookie */\n token: string\n}\nexport const generatePayloadCookie = <T extends GeneratePayloadCookieArgs>({\n collectionAuthConfig,\n cookiePrefix,\n returnCookieAsObject = false,\n token,\n}: T): T['returnCookieAsObject'] extends true ? CookieObject : string => {\n const sameSite =\n typeof collectionAuthConfig.cookies.sameSite === 'string'\n ? collectionAuthConfig.cookies.sameSite\n : collectionAuthConfig.cookies.sameSite\n ? 'Strict'\n : undefined\n\n return generateCookie<T['returnCookieAsObject']>({\n name: `${cookiePrefix}-token`,\n domain: collectionAuthConfig.cookies.domain ?? undefined,\n expires: getCookieExpiration({ seconds: collectionAuthConfig.tokenExpiration }),\n httpOnly: true,\n path: '/',\n returnCookieAsObject,\n sameSite,\n secure: collectionAuthConfig.cookies.secure,\n value: token,\n })\n}\n\nexport const generateExpiredPayloadCookie = <T extends Omit<GeneratePayloadCookieArgs, 'token'>>({\n collectionAuthConfig,\n cookiePrefix,\n returnCookieAsObject = false,\n}: T): T['returnCookieAsObject'] extends true ? CookieObject : string => {\n const sameSite =\n typeof collectionAuthConfig.cookies.sameSite === 'string'\n ? collectionAuthConfig.cookies.sameSite\n : collectionAuthConfig.cookies.sameSite\n ? 'Strict'\n : undefined\n\n const expires = new Date(Date.now() - 1000)\n\n return generateCookie<T['returnCookieAsObject']>({\n name: `${cookiePrefix}-token`,\n domain: collectionAuthConfig.cookies.domain ?? undefined,\n expires,\n httpOnly: true,\n path: '/',\n returnCookieAsObject,\n sameSite,\n secure: collectionAuthConfig.cookies.secure,\n })\n}\n\nexport function parseCookies(headers: Request['headers']) {\n // Taken from https://github.com/vercel/edge-runtime/blob/main/packages/cookies/src/serialize.ts\n\n /*\n The MIT License (MIT)\n\n Copyright (c) 2024 Vercel, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n const map = new Map<string, string>()\n\n const cookie = headers.get('Cookie')\n\n if (!cookie) {\n return map\n }\n\n for (const pair of cookie.split(/; */)) {\n if (!pair) {\n continue\n }\n\n const splitAt = pair.indexOf('=')\n\n // If the attribute doesn't have a value, set it to 'true'.\n if (splitAt === -1) {\n map.set(pair, 'true')\n continue\n }\n\n // Otherwise split it into key and value and trim the whitespace on the\n // value.\n const [key, value] = [pair.slice(0, splitAt), pair.slice(splitAt + 1)]\n try {\n map.set(key, decodeURIComponent(value ?? 'true'))\n } catch {\n // ignore invalid encoded values\n }\n }\n\n return map\n}\n"],"names":["generateCookie","args","name","domain","expires","httpOnly","maxAge","path","returnCookieAsObject","sameSite","secure","secureArg","value","cookieString","cookieObject","toUTCString","toString","getCookieExpiration","seconds","currentTime","Date","setSeconds","getSeconds","generatePayloadCookie","collectionAuthConfig","cookiePrefix","token","cookies","undefined","tokenExpiration","generateExpiredPayloadCookie","now","parseCookies","headers","map","Map","cookie","get","pair","split","splitAt","indexOf","set","key","slice","decodeURIComponent"],"mappings":"AAAA,oBAAoB;AA4BpB,OAAO,MAAMA,iBAAiB,CAC5BC;IAEA,MAAM,EACJC,IAAI,EACJC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACRC,MAAM,EACNC,IAAI,EACJC,oBAAoB,EACpBC,QAAQ,EACRC,QAAQC,SAAS,EACjBC,KAAK,EACN,GAAGX;IAEJ,IAAIY,eAAe,GAAGX,KAAK,CAAC,EAAEU,SAAS,IAAI;IAC3C,MAAME,eAA6B;QACjCZ;QACAU;IACF;IAEA,MAAMF,SAASC,aAAaF,aAAa;IAEzC,IAAIL,SAAS;QACX,IAAII,sBAAsB;YACxBM,aAAaV,OAAO,GAAGA,QAAQW,WAAW;QAC5C,OAAO;YACLF,gBAAgB,CAAC,UAAU,EAAET,QAAQW,WAAW,IAAI;QACtD;IACF;IAEA,IAAIT,QAAQ;QACV,IAAIE,sBAAsB;YACxBM,aAAaR,MAAM,GAAGA;QACxB,OAAO;Y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C0B,KAAKM,KAAK,CAAC,GAAGJ;YAAUF,KAAKM,KAAK,CAACJ,UAAU;SAAG;QACtE,IAAI;YACFN,IAAIQ,GAAG,CAACC,KAAKE,mBAAmBjC,SAAS;QAC3C,EAAE,OAAM;QACN,gCAAgC;QAClC;IACF;IAEA,OAAOsB;AACT"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { parseCookies } from './cookies.js';
|
|
2
|
+
describe('parseCookies', ()=>{
|
|
3
|
+
it('parses cookie attributes without values', ()=>{
|
|
4
|
+
const fakeHeaders = new Map();
|
|
5
|
+
fakeHeaders.set('Cookie', 'my_value=true; Secure; HttpOnly');
|
|
6
|
+
const parsed = parseCookies(fakeHeaders);
|
|
7
|
+
expect(parsed.get('my_value')).toBe('true');
|
|
8
|
+
expect(parsed.get('Secure')).toBe('true');
|
|
9
|
+
expect(parsed.get('HttpOnly')).toBe('true');
|
|
10
|
+
expect(parsed.size).toBe(3);
|
|
11
|
+
});
|
|
12
|
+
it('strips whitespace', ()=>{
|
|
13
|
+
const fakeHeaders = new Map();
|
|
14
|
+
fakeHeaders.set('Cookie', 'my_value=true; ');
|
|
15
|
+
const parsed = parseCookies(fakeHeaders);
|
|
16
|
+
expect(parsed.get('my_value')).toBe('true');
|
|
17
|
+
expect(parsed.size).toBe(1);
|
|
18
|
+
});
|
|
19
|
+
it('ensure invalid cookies are ignored', ()=>{
|
|
20
|
+
const fakeHeaders = new Map();
|
|
21
|
+
fakeHeaders.set('Cookie', 'my_value=true; invalid_cookie=%E0%A4%A');
|
|
22
|
+
const parsed = parseCookies(fakeHeaders);
|
|
23
|
+
expect(parsed.get('my_value')).toBe('true');
|
|
24
|
+
expect(parsed.size).toBe(1);
|
|
25
|
+
});
|
|
26
|
+
it('ensure empty map is returned if there are no cookies', ()=>{
|
|
27
|
+
const fakeHeaders = new Map();
|
|
28
|
+
const parsed = parseCookies(fakeHeaders);
|
|
29
|
+
expect(parsed.size).toBe(0);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=cookies.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/cookies.spec.ts"],"sourcesContent":["import { parseCookies } from './cookies.js'\n\ndescribe('parseCookies', () => {\n it('parses cookie attributes without values', () => {\n const fakeHeaders = new Map()\n fakeHeaders.set('Cookie', 'my_value=true; Secure; HttpOnly')\n\n const parsed = parseCookies(fakeHeaders as unknown as Request['headers'])\n\n expect(parsed.get('my_value')).toBe('true')\n expect(parsed.get('Secure')).toBe('true')\n expect(parsed.get('HttpOnly')).toBe('true')\n expect(parsed.size).toBe(3)\n })\n it('strips whitespace', () => {\n const fakeHeaders = new Map()\n fakeHeaders.set('Cookie', 'my_value=true; ')\n\n const parsed = parseCookies(fakeHeaders as unknown as Request['headers'])\n\n expect(parsed.get('my_value')).toBe('true')\n expect(parsed.size).toBe(1)\n })\n\n it('ensure invalid cookies are ignored', () => {\n const fakeHeaders = new Map()\n fakeHeaders.set('Cookie', 'my_value=true; invalid_cookie=%E0%A4%A')\n\n const parsed = parseCookies(fakeHeaders as unknown as Request['headers'])\n\n expect(parsed.get('my_value')).toBe('true')\n expect(parsed.size).toBe(1)\n })\n\n it('ensure empty map is returned if there are no cookies', () => {\n const fakeHeaders = new Map()\n\n const parsed = parseCookies(fakeHeaders as unknown as Request['headers'])\n\n expect(parsed.size).toBe(0)\n })\n})\n"],"names":["parseCookies","describe","it","fakeHeaders","Map","set","parsed","expect","get","toBe","size"],"mappings":"AAAA,SAASA,YAAY,QAAQ,eAAc;AAE3CC,SAAS,gBAAgB;IACvBC,GAAG,2CAA2C;QAC5C,MAAMC,cAAc,IAAIC;QACxBD,YAAYE,GAAG,CAAC,UAAU;QAE1B,MAAMC,SAASN,aAAaG;QAE5BI,OAAOD,OAAOE,GAAG,CAAC,aAAaC,IAAI,CAAC;QACpCF,OAAOD,OAAOE,GAAG,CAAC,WAAWC,IAAI,CAAC;QAClCF,OAAOD,OAAOE,GAAG,CAAC,aAAaC,IAAI,CAAC;QACpCF,OAAOD,OAAOI,IAAI,EAAED,IAAI,CAAC;IAC3B;IACAP,GAAG,qBAAqB;QACtB,MAAMC,cAAc,IAAIC;QACxBD,YAAYE,GAAG,CAAC,UAAU;QAE1B,MAAMC,SAASN,aAAaG;QAE5BI,OAAOD,OAAOE,GAAG,CAAC,aAAaC,IAAI,CAAC;QACpCF,OAAOD,OAAOI,IAAI,EAAED,IAAI,CAAC;IAC3B;IAEAP,GAAG,sCAAsC;QACvC,MAAMC,cAAc,IAAIC;QACxBD,YAAYE,GAAG,CAAC,UAAU;QAE1B,MAAMC,SAASN,aAAaG;QAE5BI,OAAOD,OAAOE,GAAG,CAAC,aAAaC,IAAI,CAAC;QACpCF,OAAOD,OAAOI,IAAI,EAAED,IAAI,CAAC;IAC3B;IAEAP,GAAG,wDAAwD;QACzD,MAAMC,cAAc,IAAIC;QAExB,MAAME,SAASN,aAAaG;QAE5BI,OAAOD,OAAOI,IAAI,EAAED,IAAI,CAAC;IAC3B;AACF"}
|
|
@@ -11,7 +11,7 @@ export const executeAuthStrategies = async (args)=>{
|
|
|
11
11
|
// add the configured AuthStrategy `name` to the strategy function args
|
|
12
12
|
args.strategyName = strategy.name;
|
|
13
13
|
args.isGraphQL = Boolean(args.isGraphQL);
|
|
14
|
-
args.
|
|
14
|
+
args.canSetHeaders = Boolean(args.canSetHeaders);
|
|
15
15
|
try {
|
|
16
16
|
const authResult = await strategy.authenticate(args);
|
|
17
17
|
if (authResult.responseHeaders) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/executeAuthStrategies.ts"],"sourcesContent":["import type { AuthStrategyFunctionArgs, AuthStrategyResult } from './index.js'\n\nimport { logError } from '../utilities/logError.js'\nimport { mergeHeaders } from '../utilities/mergeHeaders.js'\nexport const executeAuthStrategies = async (\n args: AuthStrategyFunctionArgs,\n): Promise<AuthStrategyResult> => {\n let result: AuthStrategyResult = { user: null }\n\n if (!args.payload.authStrategies?.length) {\n return result\n }\n\n for (const strategy of args.payload.authStrategies) {\n // add the configured AuthStrategy `name` to the strategy function args\n args.strategyName = strategy.name\n args.isGraphQL = Boolean(args.isGraphQL)\n args.
|
|
1
|
+
{"version":3,"sources":["../../src/auth/executeAuthStrategies.ts"],"sourcesContent":["import type { AuthStrategyFunctionArgs, AuthStrategyResult } from './index.js'\n\nimport { logError } from '../utilities/logError.js'\nimport { mergeHeaders } from '../utilities/mergeHeaders.js'\nexport const executeAuthStrategies = async (\n args: AuthStrategyFunctionArgs,\n): Promise<AuthStrategyResult> => {\n let result: AuthStrategyResult = { user: null }\n\n if (!args.payload.authStrategies?.length) {\n return result\n }\n\n for (const strategy of args.payload.authStrategies) {\n // add the configured AuthStrategy `name` to the strategy function args\n args.strategyName = strategy.name\n args.isGraphQL = Boolean(args.isGraphQL)\n args.canSetHeaders = Boolean(args.canSetHeaders)\n\n try {\n const authResult = await strategy.authenticate(args)\n if (authResult.responseHeaders) {\n authResult.responseHeaders = mergeHeaders(\n result.responseHeaders || new Headers(),\n authResult.responseHeaders || new Headers(),\n )\n }\n result = authResult\n } catch (err) {\n logError({ err, payload: args.payload })\n }\n\n if (result.user) {\n return result\n }\n }\n return result\n}\n"],"names":["logError","mergeHeaders","executeAuthStrategies","args","result","user","payload","authStrategies","length","strategy","strategyName","name","isGraphQL","Boolean","canSetHeaders","authResult","authenticate","responseHeaders","Headers","err"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,YAAY,QAAQ,+BAA8B;AAC3D,OAAO,MAAMC,wBAAwB,OACnCC;IAEA,IAAIC,SAA6B;QAAEC,MAAM;IAAK;IAE9C,IAAI,CAACF,KAAKG,OAAO,CAACC,cAAc,EAAEC,QAAQ;QACxC,OAAOJ;IACT;IAEA,KAAK,MAAMK,YAAYN,KAAKG,OAAO,CAACC,cAAc,CAAE;QAClD,uEAAuE;QACvEJ,KAAKO,YAAY,GAAGD,SAASE,IAAI;QACjCR,KAAKS,SAAS,GAAGC,QAAQV,KAAKS,SAAS;QACvCT,KAAKW,aAAa,GAAGD,QAAQV,KAAKW,aAAa;QAE/C,IAAI;YACF,MAAMC,aAAa,MAAMN,SAASO,YAAY,CAACb;YAC/C,IAAIY,WAAWE,eAAe,EAAE;gBAC9BF,WAAWE,eAAe,GAAGhB,aAC3BG,OAAOa,eAAe,IAAI,IAAIC,WAC9BH,WAAWE,eAAe,IAAI,IAAIC;YAEtC;YACAd,SAASW;QACX,EAAE,OAAOI,KAAK;YACZnB,SAAS;gBAAEmB;gBAAKb,SAASH,KAAKG,OAAO;YAAC;QACxC;QAEA,IAAIF,OAAOC,IAAI,EAAE;YACf,OAAOD;QACT;IACF;IACA,OAAOA;AACT,EAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { SanitizedPermissions, TypedUser } from '../../index.js';
|
|
2
2
|
import type { PayloadRequest } from '../../types/index.js';
|
|
3
3
|
export type AuthArgs = {
|
|
4
|
-
headers: Request['headers'];
|
|
5
4
|
/**
|
|
6
|
-
* Specify if
|
|
5
|
+
* Specify if it's possible for auth strategies to set headers within this operation.
|
|
7
6
|
*/
|
|
8
|
-
|
|
7
|
+
canSetHeaders?: boolean;
|
|
8
|
+
headers: Request['headers'];
|
|
9
9
|
req?: Omit<PayloadRequest, 'user'>;
|
|
10
10
|
};
|
|
11
11
|
export type AuthResult = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAM1D,MAAM,MAAM,QAAQ,GAAG;IACrB,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAM1D,MAAM,MAAM,QAAQ,GAAG;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IAC3B,GAAG,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;CACnC,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE,oBAAoB,CAAA;IACjC,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,IAAI,EAAE,IAAI,GAAG,SAAS,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,IAAI,SAAgB,QAAQ,CAAC,QAAQ,CAAC,KAAG,OAAO,CAAC,UAAU,CA4BvE,CAAA"}
|
|
@@ -2,13 +2,13 @@ import { killTransaction } from '../../utilities/killTransaction.js';
|
|
|
2
2
|
import { executeAuthStrategies } from '../executeAuthStrategies.js';
|
|
3
3
|
import { getAccessResults } from '../getAccessResults.js';
|
|
4
4
|
export const auth = async (args)=>{
|
|
5
|
-
const {
|
|
5
|
+
const { canSetHeaders, headers } = args;
|
|
6
6
|
const req = args.req;
|
|
7
7
|
const { payload } = req;
|
|
8
8
|
try {
|
|
9
9
|
const { responseHeaders, user } = await executeAuthStrategies({
|
|
10
|
+
canSetHeaders,
|
|
10
11
|
headers,
|
|
11
|
-
isAdmin,
|
|
12
12
|
payload
|
|
13
13
|
});
|
|
14
14
|
req.user = user;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/auth/operations/auth.ts"],"sourcesContent":["import type { SanitizedPermissions, TypedUser } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { executeAuthStrategies } from '../executeAuthStrategies.js'\nimport { getAccessResults } from '../getAccessResults.js'\n\nexport type AuthArgs = {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/operations/auth.ts"],"sourcesContent":["import type { SanitizedPermissions, TypedUser } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { executeAuthStrategies } from '../executeAuthStrategies.js'\nimport { getAccessResults } from '../getAccessResults.js'\n\nexport type AuthArgs = {\n /**\n * Specify if it's possible for auth strategies to set headers within this operation.\n */\n canSetHeaders?: boolean\n headers: Request['headers']\n req?: Omit<PayloadRequest, 'user'>\n}\n\nexport type AuthResult = {\n permissions: SanitizedPermissions\n responseHeaders?: Headers\n user: null | TypedUser\n}\n\nexport const auth = async (args: Required<AuthArgs>): Promise<AuthResult> => {\n const { canSetHeaders, headers } = args\n const req = args.req as PayloadRequest\n const { payload } = req\n\n try {\n const { responseHeaders, user } = await executeAuthStrategies({\n canSetHeaders,\n headers,\n payload,\n })\n\n req.user = user\n req.responseHeaders = responseHeaders\n\n const permissions = await getAccessResults({\n req,\n })\n\n return {\n permissions,\n responseHeaders,\n user,\n }\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["killTransaction","executeAuthStrategies","getAccessResults","auth","args","canSetHeaders","headers","req","payload","responseHeaders","user","permissions","error"],"mappings":"AAGA,SAASA,eAAe,QAAQ,qCAAoC;AACpE,SAASC,qBAAqB,QAAQ,8BAA6B;AACnE,SAASC,gBAAgB,QAAQ,yBAAwB;AAiBzD,OAAO,MAAMC,OAAO,OAAOC;IACzB,MAAM,EAAEC,aAAa,EAAEC,OAAO,EAAE,GAAGF;IACnC,MAAMG,MAAMH,KAAKG,GAAG;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,IAAI;QACF,MAAM,EAAEE,eAAe,EAAEC,IAAI,EAAE,GAAG,MAAMT,sBAAsB;YAC5DI;YACAC;YACAE;QACF;QAEAD,IAAIG,IAAI,GAAGA;QACXH,IAAIE,eAAe,GAAGA;QAEtB,MAAME,cAAc,MAAMT,iBAAiB;YACzCK;QACF;QAEA,OAAO;YACLI;YACAF;YACAC;QACF;IACF,EAAE,OAAOE,OAAgB;QACvB,MAAMZ,gBAAgBO;QACtB,MAAMK;IACR;AACF,EAAC"}
|
|
@@ -3,8 +3,8 @@ import { auth as authOperation } from '../auth.js';
|
|
|
3
3
|
export const auth = async (payload, options)=>{
|
|
4
4
|
const { headers, req } = options;
|
|
5
5
|
return await authOperation({
|
|
6
|
+
canSetHeaders: Boolean(options.canSetHeaders),
|
|
6
7
|
headers,
|
|
7
|
-
isAdmin: Boolean(options.isAdmin),
|
|
8
8
|
req: await createLocalReq({
|
|
9
9
|
req
|
|
10
10
|
}, payload)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/auth/operations/local/auth.ts"],"sourcesContent":["import type { Payload } from '../../../index.js'\nimport type { AuthArgs, AuthResult } from '../auth.js'\n\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { auth as authOperation } from '../auth.js'\n\nexport const auth = async (payload: Payload, options: AuthArgs): Promise<AuthResult> => {\n const { headers, req } = options\n\n return await authOperation({\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/auth/operations/local/auth.ts"],"sourcesContent":["import type { Payload } from '../../../index.js'\nimport type { AuthArgs, AuthResult } from '../auth.js'\n\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { auth as authOperation } from '../auth.js'\n\nexport const auth = async (payload: Payload, options: AuthArgs): Promise<AuthResult> => {\n const { headers, req } = options\n\n return await authOperation({\n canSetHeaders: Boolean(options.canSetHeaders),\n headers,\n req: await createLocalReq({ req }, payload),\n })\n}\n"],"names":["createLocalReq","auth","authOperation","payload","options","headers","req","canSetHeaders","Boolean"],"mappings":"AAGA,SAASA,cAAc,QAAQ,uCAAsC;AACrE,SAASC,QAAQC,aAAa,QAAQ,aAAY;AAElD,OAAO,MAAMD,OAAO,OAAOE,SAAkBC;IAC3C,MAAM,EAAEC,OAAO,EAAEC,GAAG,EAAE,GAAGF;IAEzB,OAAO,MAAMF,cAAc;QACzBK,eAAeC,QAAQJ,QAAQG,aAAa;QAC5CF;QACAC,KAAK,MAAMN,eAAe;YAAEM;QAAI,GAAGH;IACrC;AACF,EAAC"}
|
|
@@ -11,7 +11,7 @@ export type Options<T extends CollectionSlug> = {
|
|
|
11
11
|
overrideAccess: boolean;
|
|
12
12
|
req?: Partial<PayloadRequest>;
|
|
13
13
|
};
|
|
14
|
-
declare function localResetPassword<
|
|
14
|
+
declare function localResetPassword<TSlug extends CollectionSlug>(payload: Payload, options: Options<TSlug>): Promise<Result>;
|
|
15
15
|
export declare const resetPassword: typeof localResetPassword;
|
|
16
16
|
export {};
|
|
17
17
|
//# sourceMappingURL=resetPassword.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resetPassword.d.ts","sourceRoot":"","sources":["../../../../src/auth/operations/local/resetPassword.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAMjD,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,cAAc,IAAI;IAC9C,UAAU,EAAE,CAAC,CAAA;IACb,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,IAAI,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAA;QAChB,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;CAC9B,CAAA;AAED,iBAAe,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"resetPassword.d.ts","sourceRoot":"","sources":["../../../../src/auth/operations/local/resetPassword.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAMjD,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,cAAc,IAAI;IAC9C,UAAU,EAAE,CAAC,CAAA;IACb,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,IAAI,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAA;QAChB,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;CAC9B,CAAA;AAED,iBAAe,kBAAkB,CAAC,KAAK,SAAS,cAAc,EAC5D,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,GACtB,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAED,eAAO,MAAM,aAAa,2BAAqB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/auth/operations/local/resetPassword.ts"],"sourcesContent":["import type { CollectionSlug, Payload, RequestContext } from '../../../index.js'\nimport type { PayloadRequest } from '../../../types/index.js'\nimport type { Result } from '../resetPassword.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { resetPasswordOperation } from '../resetPassword.js'\n\nexport type Options<T extends CollectionSlug> = {\n collection: T\n context?: RequestContext\n data: {\n password: string\n token: string\n }\n overrideAccess: boolean\n req?: Partial<PayloadRequest>\n}\n\nasync function localResetPassword<
|
|
1
|
+
{"version":3,"sources":["../../../../src/auth/operations/local/resetPassword.ts"],"sourcesContent":["import type { CollectionSlug, Payload, RequestContext } from '../../../index.js'\nimport type { PayloadRequest } from '../../../types/index.js'\nimport type { Result } from '../resetPassword.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { resetPasswordOperation } from '../resetPassword.js'\n\nexport type Options<T extends CollectionSlug> = {\n collection: T\n context?: RequestContext\n data: {\n password: string\n token: string\n }\n overrideAccess: boolean\n req?: Partial<PayloadRequest>\n}\n\nasync function localResetPassword<TSlug extends CollectionSlug>(\n payload: Payload,\n options: Options<TSlug>,\n): Promise<Result> {\n const { collection: collectionSlug, data, overrideAccess } = options\n\n const collection = payload.collections[collectionSlug]\n\n if (!collection) {\n throw new APIError(\n `The collection with slug ${String(\n collectionSlug,\n )} can't be found. Reset Password Operation.`,\n )\n }\n\n const result = await resetPasswordOperation<TSlug>({\n collection,\n data,\n overrideAccess,\n req: await createLocalReq(options, payload),\n })\n\n if (collection.config.auth.removeTokenFromResponses) {\n delete result.token\n }\n\n return result\n}\n\nexport const resetPassword = localResetPassword\n"],"names":["APIError","createLocalReq","resetPasswordOperation","localResetPassword","payload","options","collection","collectionSlug","data","overrideAccess","collections","String","result","req","config","auth","removeTokenFromResponses","token","resetPassword"],"mappings":"AAIA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,sBAAsB,QAAQ,sBAAqB;AAa5D,eAAeC,mBACbC,OAAgB,EAChBC,OAAuB;IAEvB,MAAM,EAAEC,YAAYC,cAAc,EAAEC,IAAI,EAAEC,cAAc,EAAE,GAAGJ;IAE7D,MAAMC,aAAaF,QAAQM,WAAW,CAACH,eAAe;IAEtD,IAAI,CAACD,YAAY;QACf,MAAM,IAAIN,SACR,CAAC,yBAAyB,EAAEW,OAC1BJ,gBACA,0CAA0C,CAAC;IAEjD;IAEA,MAAMK,SAAS,MAAMV,uBAA8B;QACjDI;QACAE;QACAC;QACAI,KAAK,MAAMZ,eAAeI,SAASD;IACrC;IAEA,IAAIE,WAAWQ,MAAM,CAACC,IAAI,CAACC,wBAAwB,EAAE;QACnD,OAAOJ,OAAOK,KAAK;IACrB;IAEA,OAAOL;AACT;AAEA,OAAO,MAAMM,gBAAgBf,mBAAkB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Collection } from '../../collections/config/types.js';
|
|
2
|
+
import type { CollectionSlug } from '../../index.js';
|
|
2
3
|
import type { PayloadRequest } from '../../types/index.js';
|
|
3
4
|
export type Result = {
|
|
4
5
|
token?: string;
|
|
@@ -14,5 +15,5 @@ export type Arguments = {
|
|
|
14
15
|
overrideAccess?: boolean;
|
|
15
16
|
req: PayloadRequest;
|
|
16
17
|
};
|
|
17
|
-
export declare const resetPasswordOperation: (args: Arguments) => Promise<Result>;
|
|
18
|
+
export declare const resetPasswordOperation: <TSlug extends CollectionSlug>(args: Arguments) => Promise<Result>;
|
|
18
19
|
//# sourceMappingURL=resetPassword.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resetPassword.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/resetPassword.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"resetPassword.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/resetPassword.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,mCAAmC,CAAA;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAY1D,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,cAAc,QACjE,SAAS,KACd,OAAO,CAAC,MAAM,CAuJhB,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { status as httpStatus } from 'http-status';
|
|
2
|
+
import { buildAfterOperation } from '../../collections/operations/utils.js';
|
|
2
3
|
import { APIError, Forbidden } from '../../errors/index.js';
|
|
3
4
|
import { commitTransaction } from '../../utilities/commitTransaction.js';
|
|
4
5
|
import { initTransaction } from '../../utilities/initTransaction.js';
|
|
@@ -17,6 +18,17 @@ export const resetPasswordOperation = async (args)=>{
|
|
|
17
18
|
}
|
|
18
19
|
try {
|
|
19
20
|
const shouldCommit = await initTransaction(req);
|
|
21
|
+
if (args.collection.config.hooks?.beforeOperation?.length) {
|
|
22
|
+
for (const hook of args.collection.config.hooks.beforeOperation){
|
|
23
|
+
args = await hook({
|
|
24
|
+
args,
|
|
25
|
+
collection: args.collection?.config,
|
|
26
|
+
context: args.req.context,
|
|
27
|
+
operation: 'resetPassword',
|
|
28
|
+
req: args.req
|
|
29
|
+
}) || args;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
20
32
|
// /////////////////////////////////////
|
|
21
33
|
// Reset Password
|
|
22
34
|
// /////////////////////////////////////
|
|
@@ -98,10 +110,19 @@ export const resetPasswordOperation = async (args)=>{
|
|
|
98
110
|
fullUser.collection = collectionConfig.slug;
|
|
99
111
|
fullUser._strategy = 'local-jwt';
|
|
100
112
|
}
|
|
101
|
-
|
|
113
|
+
let result = {
|
|
102
114
|
token,
|
|
103
115
|
user: fullUser
|
|
104
116
|
};
|
|
117
|
+
// /////////////////////////////////////
|
|
118
|
+
// afterOperation - Collection
|
|
119
|
+
// /////////////////////////////////////
|
|
120
|
+
result = await buildAfterOperation({
|
|
121
|
+
args,
|
|
122
|
+
collection: args.collection?.config,
|
|
123
|
+
operation: 'resetPassword',
|
|
124
|
+
result
|
|
125
|
+
});
|
|
105
126
|
return result;
|
|
106
127
|
} catch (error) {
|
|
107
128
|
await killTransaction(req);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/auth/operations/resetPassword.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { Collection } from '../../collections/config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { APIError, Forbidden } from '../../errors/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { jwtSign } from '../jwt.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 (args: Arguments): Promise<Result> => {\n const {\n collection: { config: collectionConfig },\n data,\n depth,\n overrideAccess,\n req: {\n payload: { secret },\n payload,\n },\n req,\n } = args\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 try {\n const shouldCommit = await initTransaction(req)\n\n // /////////////////////////////////////\n // Reset Password\n // /////////////////////////////////////\n\n const user = await payload.db.findOne<any>({\n collection: collectionConfig.slug,\n req,\n where: {\n resetPasswordExpiration: { greater_than: new Date().toISOString() },\n resetPasswordToken: { equals: data.token },\n },\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.verify) {\n user._verified = Boolean(user._verified)\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 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 const fieldsToSign = getFieldsToSign({\n collectionConfig,\n email: user.email,\n user,\n })\n\n const { token } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n const fullUser = await payload.findByID({\n id: user.id,\n collection: collectionConfig.slug,\n depth,\n overrideAccess,\n req,\n })\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n if (fullUser) {\n fullUser.collection = collectionConfig.slug\n fullUser._strategy = 'local-jwt'\n }\n\n
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/operations/resetPassword.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { Collection, DataFromCollectionSlug } from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utils.js'\nimport { APIError, Forbidden } from '../../errors/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { jwtSign } from '../jwt.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 CollectionSlug>(\n args: Arguments,\n): Promise<Result> => {\n const {\n collection: { config: collectionConfig },\n data,\n depth,\n overrideAccess,\n req: {\n payload: { secret },\n payload,\n },\n req,\n } = args\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 try {\n const shouldCommit = await initTransaction(req)\n\n if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection?.config,\n context: args.req.context,\n operation: 'resetPassword',\n req: args.req,\n })) || args\n }\n }\n\n // /////////////////////////////////////\n // Reset Password\n // /////////////////////////////////////\n\n const user = await payload.db.findOne<any>({\n collection: collectionConfig.slug,\n req,\n where: {\n resetPasswordExpiration: { greater_than: new Date().toISOString() },\n resetPasswordToken: { equals: data.token },\n },\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.verify) {\n user._verified = Boolean(user._verified)\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 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 const fieldsToSign = getFieldsToSign({\n collectionConfig,\n email: user.email,\n user,\n })\n\n const { token } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n const fullUser = await payload.findByID({\n id: user.id,\n collection: collectionConfig.slug,\n depth,\n overrideAccess,\n req,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n if (fullUser) {\n fullUser.collection = collectionConfig.slug\n fullUser._strategy = 'local-jwt'\n }\n\n let result: { user: DataFromCollectionSlug<TSlug> } & Result = {\n token,\n user: fullUser,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'resetPassword',\n result,\n })\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["status","httpStatus","buildAfterOperation","APIError","Forbidden","commitTransaction","initTransaction","killTransaction","getFieldsToSign","jwtSign","authenticateLocalStrategy","generatePasswordSaltHash","resetPasswordOperation","args","collection","config","collectionConfig","data","depth","overrideAccess","req","payload","secret","Object","prototype","hasOwnProperty","call","BAD_REQUEST","auth","disableLocalStrategy","t","shouldCommit","hooks","beforeOperation","length","hook","context","operation","user","db","findOne","slug","where","resetPasswordExpiration","greater_than","Date","toISOString","resetPasswordToken","equals","token","FORBIDDEN","hash","salt","password","verify","_verified","Boolean","beforeValidate","doc","updateOne","id","fieldsToSign","email","tokenExpiration","fullUser","findByID","_strategy","result","error"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa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MV,0BAA0B;YAAEgD;YAAKL,UAAUpC,KAAKoC,QAAQ;QAAC;QAE/D,MAAMQ,eAAerD,gBAAgB;YACnCQ;YACA8C,OAAOxB,KAAKwB,KAAK;YACjBxB;QACF;QAEA,MAAM,EAAEW,KAAK,EAAE,GAAG,MAAMxC,QAAQ;YAC9BoD;YACAvC;YACAyC,iBAAiB/C,iBAAiBY,IAAI,CAACmC,eAAe;QACxD;QAEA,MAAMC,WAAW,MAAM3C,QAAQ4C,QAAQ,CAAC;YACtCL,IAAItB,KAAKsB,EAAE;YACX9C,YAAYE,iBAAiByB,IAAI;YACjCvB;YACAC;YACAC;QACF;QAEA,IAAIW,cAAc;YAChB,MAAM1B,kBAAkBe;QAC1B;QAEA,IAAI4C,UAAU;YACZA,SAASlD,UAAU,GAAGE,iBAAiByB,IAAI;YAC3CuB,SAASE,SAAS,GAAG;QACvB;QAEA,IAAIC,SAA2D;YAC7DlB;YACAX,MAAM0B;QACR;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCG,SAAS,MAAMjE,oBAAoB;YACjCW;YACAC,YAAYD,KAAKC,UAAU,EAAEC;YAC7BsB,WAAW;YACX8B;QACF;QAEA,OAAOA;IACT,EAAE,OAAOC,OAAgB;QACvB,MAAM7D,gBAAgBa;QACtB,MAAMgD;IACR;AACF,EAAC"}
|
package/dist/auth/types.d.ts
CHANGED
|
@@ -124,11 +124,11 @@ type GenerateForgotPasswordEmailSubject<TUser = any> = (args?: {
|
|
|
124
124
|
user?: TUser;
|
|
125
125
|
}) => Promise<string> | string;
|
|
126
126
|
export type AuthStrategyFunctionArgs = {
|
|
127
|
-
headers: Request['headers'];
|
|
128
127
|
/**
|
|
129
|
-
*
|
|
128
|
+
* Specifies whether or not response headers can be set from this strategy.
|
|
130
129
|
*/
|
|
131
|
-
|
|
130
|
+
canSetHeaders?: boolean;
|
|
131
|
+
headers: Request['headers'];
|
|
132
132
|
isGraphQL?: boolean;
|
|
133
133
|
payload: Payload;
|
|
134
134
|
/**
|
package/dist/auth/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAE9D;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,UAAU,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAAA;CACtC,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,UAAU,CAAA;IAClB,MAAM,EAAE,iBAAiB,CAAA;IACzB,IAAI,EAAE,UAAU,CAAA;IAChB,MAAM,EAAE,UAAU,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,yBAAyB,GACjC;IACE,MAAM,EAAE,0BAA0B,CAAA;CACnC,GACD,IAAI,CAAA;AAER,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAAA;CACtC,CAAA;AAED,MAAM,MAAM,0BAA0B,GAClC;IACE,CAAC,SAAS,EAAE,MAAM,GAAG,yBAAyB,CAAA;CAC/C,GACD,IAAI,CAAA;AAER,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,MAAM,EAAE,UAAU,CAAA;IAClB,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,IAAI,EAAE,UAAU,CAAA;IAChB,MAAM,EAAE,UAAU,CAAA;CACnB,CAAA;AAED,M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C;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,KAAK,GAAG,MAAM,IAAI,KAAK,CAE7E"}
|
package/dist/auth/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/types.ts"],"sourcesContent":["import type { DeepRequired } from 'ts-essentials'\n\nimport type { CollectionSlug, GlobalSlug, Payload } from '../index.js'\nimport type { PayloadRequest, Where } from '../types/index.js'\n\n/**\n * A permission object that can be used to determine if a user has access to a specific operation.\n */\nexport type Permission = {\n permission: boolean\n where?: Where\n}\n\nexport type FieldsPermissions = {\n [fieldName: string]: FieldPermissions\n}\n\nexport type BlockPermissions = {\n create: Permission\n fields: FieldsPermissions\n read: Permission\n update: Permission\n}\n\nexport type SanitizedBlockPermissions =\n | {\n fields: SanitizedFieldsPermissions\n }\n | true\n\nexport type BlocksPermissions = {\n [blockSlug: string]: BlockPermissions\n}\n\nexport type SanitizedBlocksPermissions =\n | {\n [blockSlug: string]: SanitizedBlockPermissions\n }\n | true\n\nexport type FieldPermissions = {\n blocks?: BlocksPermissions\n create: Permission\n fields?: FieldsPermissions\n read: Permission\n update: Permission\n}\n\nexport type SanitizedFieldPermissions =\n | {\n blocks?: SanitizedBlocksPermissions\n create: true\n fields?: SanitizedFieldsPermissions\n read: true\n update: true\n }\n | true\n\nexport type SanitizedFieldsPermissions =\n | {\n [fieldName: string]: SanitizedFieldPermissions\n }\n | true\n\nexport type CollectionPermission = {\n create: Permission\n delete: Permission\n fields: FieldsPermissions\n read: Permission\n readVersions?: Permission\n update: Permission\n}\n\nexport type SanitizedCollectionPermission = {\n create?: true\n delete?: true\n fields: SanitizedFieldsPermissions\n read?: true\n readVersions?: true\n update?: true\n}\n\nexport type GlobalPermission = {\n fields: FieldsPermissions\n read: Permission\n readVersions?: Permission\n update: Permission\n}\n\nexport type SanitizedGlobalPermission = {\n fields: SanitizedFieldsPermissions\n read?: true\n readVersions?: true\n update?: true\n}\n\nexport type DocumentPermissions = CollectionPermission | GlobalPermission\n\nexport type SanitizedDocumentPermissions = SanitizedCollectionPermission | SanitizedGlobalPermission\n\nexport type Permissions = {\n canAccessAdmin: boolean\n collections?: Record<CollectionSlug, CollectionPermission>\n globals?: Record<GlobalSlug, GlobalPermission>\n}\n\nexport type SanitizedPermissions = {\n canAccessAdmin?: boolean\n collections?: {\n [collectionSlug: string]: SanitizedCollectionPermission\n }\n globals?: {\n [globalSlug: string]: SanitizedGlobalPermission\n }\n}\n\ntype BaseUser = {\n collection: string\n email?: string\n id: number | string\n username?: string\n}\n\nexport type User = {\n [key: string]: any\n} & BaseUser\n\n/**\n * `collection` is not available one the client. It's only available on the server (req.user)\n * On the client, you can access the collection via config.admin.user. Config can be accessed using the useConfig() hook\n */\nexport type ClientUser = {\n [key: string]: any\n} & BaseUser\n\ntype GenerateVerifyEmailHTML<TUser = any> = (args: {\n req: PayloadRequest\n token: string\n user: TUser\n}) => Promise<string> | string\n\ntype GenerateVerifyEmailSubject<TUser = any> = (args: {\n req: PayloadRequest\n token: string\n user: TUser\n}) => Promise<string> | string\n\ntype GenerateForgotPasswordEmailHTML<TUser = any> = (args?: {\n req?: PayloadRequest\n token?: string\n user?: TUser\n}) => Promise<string> | string\n\ntype GenerateForgotPasswordEmailSubject<TUser = any> = (args?: {\n req?: PayloadRequest\n token?: string\n user?: TUser\n}) => Promise<string> | string\n\nexport type AuthStrategyFunctionArgs = {\n
|
|
1
|
+
{"version":3,"sources":["../../src/auth/types.ts"],"sourcesContent":["import type { DeepRequired } from 'ts-essentials'\n\nimport type { CollectionSlug, GlobalSlug, Payload } from '../index.js'\nimport type { PayloadRequest, Where } from '../types/index.js'\n\n/**\n * A permission object that can be used to determine if a user has access to a specific operation.\n */\nexport type Permission = {\n permission: boolean\n where?: Where\n}\n\nexport type FieldsPermissions = {\n [fieldName: string]: FieldPermissions\n}\n\nexport type BlockPermissions = {\n create: Permission\n fields: FieldsPermissions\n read: Permission\n update: Permission\n}\n\nexport type SanitizedBlockPermissions =\n | {\n fields: SanitizedFieldsPermissions\n }\n | true\n\nexport type BlocksPermissions = {\n [blockSlug: string]: BlockPermissions\n}\n\nexport type SanitizedBlocksPermissions =\n | {\n [blockSlug: string]: SanitizedBlockPermissions\n }\n | true\n\nexport type FieldPermissions = {\n blocks?: BlocksPermissions\n create: Permission\n fields?: FieldsPermissions\n read: Permission\n update: Permission\n}\n\nexport type SanitizedFieldPermissions =\n | {\n blocks?: SanitizedBlocksPermissions\n create: true\n fields?: SanitizedFieldsPermissions\n read: true\n update: true\n }\n | true\n\nexport type SanitizedFieldsPermissions =\n | {\n [fieldName: string]: SanitizedFieldPermissions\n }\n | true\n\nexport type CollectionPermission = {\n create: Permission\n delete: Permission\n fields: FieldsPermissions\n read: Permission\n readVersions?: Permission\n update: Permission\n}\n\nexport type SanitizedCollectionPermission = {\n create?: true\n delete?: true\n fields: SanitizedFieldsPermissions\n read?: true\n readVersions?: true\n update?: true\n}\n\nexport type GlobalPermission = {\n fields: FieldsPermissions\n read: Permission\n readVersions?: Permission\n update: Permission\n}\n\nexport type SanitizedGlobalPermission = {\n fields: SanitizedFieldsPermissions\n read?: true\n readVersions?: true\n update?: true\n}\n\nexport type DocumentPermissions = CollectionPermission | GlobalPermission\n\nexport type SanitizedDocumentPermissions = SanitizedCollectionPermission | SanitizedGlobalPermission\n\nexport type Permissions = {\n canAccessAdmin: boolean\n collections?: Record<CollectionSlug, CollectionPermission>\n globals?: Record<GlobalSlug, GlobalPermission>\n}\n\nexport type SanitizedPermissions = {\n canAccessAdmin?: boolean\n collections?: {\n [collectionSlug: string]: SanitizedCollectionPermission\n }\n globals?: {\n [globalSlug: string]: SanitizedGlobalPermission\n }\n}\n\ntype BaseUser = {\n collection: string\n email?: string\n id: number | string\n username?: string\n}\n\nexport type User = {\n [key: string]: any\n} & BaseUser\n\n/**\n * `collection` is not available one the client. It's only available on the server (req.user)\n * On the client, you can access the collection via config.admin.user. Config can be accessed using the useConfig() hook\n */\nexport type ClientUser = {\n [key: string]: any\n} & BaseUser\n\ntype GenerateVerifyEmailHTML<TUser = any> = (args: {\n req: PayloadRequest\n token: string\n user: TUser\n}) => Promise<string> | string\n\ntype GenerateVerifyEmailSubject<TUser = any> = (args: {\n req: PayloadRequest\n token: string\n user: TUser\n}) => Promise<string> | string\n\ntype GenerateForgotPasswordEmailHTML<TUser = any> = (args?: {\n req?: PayloadRequest\n token?: string\n user?: TUser\n}) => Promise<string> | string\n\ntype GenerateForgotPasswordEmailSubject<TUser = any> = (args?: {\n req?: PayloadRequest\n token?: string\n user?: TUser\n}) => Promise<string> | string\n\nexport type AuthStrategyFunctionArgs = {\n /**\n * Specifies whether or not response headers can be set from this strategy.\n */\n canSetHeaders?: boolean\n headers: Request['headers']\n isGraphQL?: boolean\n payload: Payload\n /**\n * The AuthStrategy name property from the payload config.\n */\n strategyName?: string\n}\n\nexport type AuthStrategyResult = {\n responseHeaders?: Headers\n user:\n | ({\n _strategy?: string\n collection?: string\n } & User)\n | null\n}\n\nexport type AuthStrategyFunction = (\n args: AuthStrategyFunctionArgs,\n) => AuthStrategyResult | Promise<AuthStrategyResult>\nexport type AuthStrategy = {\n authenticate: AuthStrategyFunction\n name: string\n}\n\nexport type LoginWithUsernameOptions =\n | {\n allowEmailLogin?: false\n requireEmail?: boolean\n // If `allowEmailLogin` is false, `requireUsername` must be true (default: true)\n requireUsername?: true\n }\n | {\n allowEmailLogin?: true\n requireEmail?: boolean\n requireUsername?: boolean\n }\n\nexport interface IncomingAuthType {\n /**\n * Set cookie options, including secure, sameSite, and domain. For advanced users.\n */\n cookies?: {\n domain?: string\n sameSite?: 'Lax' | 'None' | 'Strict' | boolean\n secure?: boolean\n }\n /**\n * How many levels deep a user document should be populated when creating the JWT and binding the user to the req. Defaults to 0 and should only be modified if absolutely necessary, as this will affect performance.\n * @default 0\n */\n depth?: number\n /**\n * Advanced - disable Payload's built-in local auth strategy. Only use this property if you have replaced Payload's auth mechanisms with your own.\n */\n disableLocalStrategy?:\n | {\n /**\n * Include auth fields on the collection even though the local strategy is disabled.\n * Useful when you do not want the database or types to vary depending on the auth configuration.\n */\n enableFields?: true\n optionalPassword?: true\n }\n | true\n /**\n * Customize the way that the forgotPassword operation functions.\n * @link https://payloadcms.com/docs/authentication/email#forgot-password\n */\n forgotPassword?: {\n /**\n * The number of milliseconds that the forgot password token should be valid for.\n * @default 3600000 // 1 hour\n */\n expiration?: number\n generateEmailHTML?: GenerateForgotPasswordEmailHTML\n generateEmailSubject?: GenerateForgotPasswordEmailSubject\n }\n /**\n * Set the time (in milliseconds) that a user should be locked out if they fail authentication more times than maxLoginAttempts allows for.\n */\n lockTime?: number\n /**\n * Ability to allow users to login with username/password.\n *\n * @link https://payloadcms.com/docs/authentication/overview#login-with-username\n */\n loginWithUsername?: boolean | LoginWithUsernameOptions\n /**\n * Only allow a user to attempt logging in X amount of times. Automatically locks out a user from authenticating if this limit is passed. Set to 0 to disable.\n */\n maxLoginAttempts?: number\n /***\n * Set to true if you want to remove the token from the returned authentication API responses such as login or refresh.\n */\n removeTokenFromResponses?: true\n /**\n * Advanced - an array of custom authentification strategies to extend this collection's authentication with.\n * @link https://payloadcms.com/docs/authentication/custom-strategies\n */\n strategies?: AuthStrategy[]\n /**\n * Controls how many seconds the token will be valid for. Default is 2 hours.\n * @default 7200\n * @link https://payloadcms.com/docs/authentication/overview#config-options\n */\n tokenExpiration?: number\n /**\n * Payload Authentication provides for API keys to be set on each user within an Authentication-enabled Collection.\n * @default false\n * @link https://payloadcms.com/docs/authentication/api-keys\n */\n useAPIKey?: boolean\n /**\n * Set to true or pass an object with verification options to require users to verify by email before they are allowed to log into your app.\n * @link https://payloadcms.com/docs/authentication/email#email-verification\n */\n verify?:\n | {\n generateEmailHTML?: GenerateVerifyEmailHTML\n generateEmailSubject?: GenerateVerifyEmailSubject\n }\n | boolean\n}\n\nexport type VerifyConfig = {\n generateEmailHTML?: GenerateVerifyEmailHTML\n generateEmailSubject?: GenerateVerifyEmailSubject\n}\n\nexport interface Auth\n extends Omit<DeepRequired<IncomingAuthType>, 'forgotPassword' | 'loginWithUsername' | 'verify'> {\n forgotPassword?: {\n expiration?: number\n generateEmailHTML?: GenerateForgotPasswordEmailHTML\n generateEmailSubject?: GenerateForgotPasswordEmailSubject\n }\n loginWithUsername: false | LoginWithUsernameOptions\n verify?: boolean | VerifyConfig\n}\n\nexport function hasWhereAccessResult(result: boolean | Where): result is Where {\n return result && typeof result === 'object'\n}\n"],"names":["hasWhereAccessResult","result"],"mappings":"AAmTA,OAAO,SAASA,qBAAqBC,MAAuB;IAC1D,OAAOA,UAAU,OAAOA,WAAW;AACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/bin/migrate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAczD,eAAO,MAAM,iBAAiB,UAQ7B,CAAA;AAID,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,OAAO,2BAAkC,IAAI,KAAG,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/bin/migrate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAczD,eAAO,MAAM,iBAAiB,UAQ7B,CAAA;AAID,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,OAAO,2BAAkC,IAAI,KAAG,OAAO,CAAC,IAAI,CA4FxE,CAAA"}
|
package/dist/bin/migrate.js
CHANGED
package/dist/bin/migrate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bin/migrate.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { ParsedArgs } from 'minimist'\n\nimport type { SanitizedConfig } from '../config/types.js'\n\nimport payload from '../index.js'\nimport { prettySyncLoggerDestination } from '../utilities/logger.js'\n\n/**\n * The default logger's options did not allow for forcing sync logging\n * Using these options, to force both pretty print and sync logging\n */\nconst prettySyncLogger = {\n loggerDestination: prettySyncLoggerDestination,\n loggerOptions: {},\n}\n\nexport const availableCommands = [\n 'migrate',\n 'migrate:create',\n 'migrate:down',\n 'migrate:refresh',\n 'migrate:reset',\n 'migrate:status',\n 'migrate:fresh',\n]\n\nconst availableCommandsMsg = `Available commands: ${availableCommands.join(', ')}`\n\ntype Args = {\n config: SanitizedConfig\n parsedArgs: ParsedArgs\n}\n\nexport const migrate = async ({ config, parsedArgs }: Args): Promise<void> => {\n const { _: args, file, forceAcceptWarning: forceAcceptFromProps, help } = parsedArgs\n\n const formattedArgs = Object.keys(parsedArgs)\n .map((key) => {\n const formattedKey = key.replace(/^[-_]+/, '')\n if (!formattedKey) {\n return null\n }\n\n return formattedKey\n .split('-')\n .map((word, index) =>\n index === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1),\n )\n .join('')\n })\n .filter(Boolean)\n\n const forceAcceptWarning = forceAcceptFromProps || formattedArgs.includes('forceAcceptWarning')\n const skipEmpty = formattedArgs.includes('skipEmpty')\n\n if (help) {\n // eslint-disable-next-line no-console\n console.log(`\\n\\n${availableCommandsMsg}\\n`) // Avoid having to init payload to get the logger\n process.exit(0)\n }\n\n process.env.PAYLOAD_MIGRATING = 'true'\n\n // Barebones instance to access database adapter\n await payload.init({\n config,\n disableOnInit: true,\n ...prettySyncLogger,\n })\n\n const adapter = payload.db\n\n if (!adapter) {\n throw new Error('No database adapter found')\n }\n\n if (!args.length) {\n payload.logger.error({\n msg: `No migration command provided. ${availableCommandsMsg}`,\n })\n process.exit(1)\n }\n\n switch (args[0]) {\n case 'migrate':\n await adapter.migrate()\n break\n case 'migrate:create':\n try {\n await adapter.createMigration({\n file,\n forceAcceptWarning,\n migrationName: args[1],\n payload,\n skipEmpty,\n })\n } catch (err) {\n throw new Error(`Error creating migration: ${err.message}`)\n }\n break\n case 'migrate:down':\n await adapter.migrateDown()\n break\n case 'migrate:fresh':\n await adapter.migrateFresh({ forceAcceptWarning })\n break\n case 'migrate:refresh':\n await adapter.migrateRefresh()\n break\n case 'migrate:reset':\n await adapter.migrateReset()\n break\n case 'migrate:status':\n await adapter.migrateStatus()\n break\n\n default:\n payload.logger.error({\n msg: `Unknown migration command: ${args[0]}. ${availableCommandsMsg}`,\n })\n process.exit(1)\n }\n\n payload.logger.info('Done.')\n}\n"],"names":["payload","prettySyncLoggerDestination","prettySyncLogger","loggerDestination","loggerOptions","availableCommands","availableCommandsMsg","join","migrate","config","parsedArgs","_","args","file","forceAcceptWarning","forceAcceptFromProps","help","formattedArgs","Object","keys","map","key","formattedKey","replace","split","word","index","toLowerCase","charAt","toUpperCase","slice","filter","Boolean","includes","skipEmpty","console","log","process","exit","env","PAYLOAD_MIGRATING","init","disableOnInit","adapter","db","Error","length","logger","error","msg","createMigration","migrationName","err","message","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","info"],"mappings":"AAAA,oBAAoB;AAKpB,OAAOA,aAAa,cAAa;AACjC,SAASC,2BAA2B,QAAQ,yBAAwB;AAEpE;;;CAGC,GACD,MAAMC,mBAAmB;IACvBC,mBAAmBF;IACnBG,eAAe,CAAC;AAClB;AAEA,OAAO,MAAMC,oBAAoB;IAC/B;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED,MAAMC,uBAAuB,CAAC,oBAAoB,EAAED,kBAAkBE,IAAI,CAAC,OAAO;AAOlF,OAAO,MAAMC,UAAU,OAAO,EAAEC,MAAM,EAAEC,UAAU,EAAQ;IACxD,MAAM,EAAEC,GAAGC,IAAI,EAAEC,IAAI,EAAEC,oBAAoBC,oBAAoB,EAAEC,IAAI,EAAE,GAAGN;IAE1E,MAAMO,gBAAgBC,OAAOC,IAAI,CAACT,YAC/BU,GAAG,CAAC,CAACC;QACJ,MAAMC,eAAeD,IAAIE,OAAO,CAAC,UAAU;QAC3C,IAAI,CAACD,cAAc;YACjB,OAAO;QACT;QAEA,OAAOA,aACJE,KAAK,CAAC,KACNJ,GAAG,CAAC,CAACK,MAAMC,QACVA,UAAU,IAAID,KAAKE,WAAW,KAAKF,KAAKG,MAAM,CAAC,GAAGC,WAAW,KAAKJ,KAAKK,KAAK,CAAC,IAE9EvB,IAAI,CAAC;IACV,GACCwB,MAAM,CAACC;IAEV,MAAMlB,qBAAqBC,wBAAwBE,cAAcgB,QAAQ,CAAC;IAC1E,MAAMC,YAAYjB,cAAcgB,QAAQ,CAAC;IAEzC,IAAIjB,MAAM;QACR,sCAAsC;QACtCmB,QAAQC,GAAG,CAAC,CAAC,IAAI,EAAE9B,qBAAqB,EAAE,CAAC,EAAE,iDAAiD;;QAC9F+B,QAAQC,IAAI,CAAC;IACf;IAEAD,QAAQE,GAAG,CAACC,iBAAiB,GAAG;IAEhC,gDAAgD;IAChD,MAAMxC,QAAQyC,IAAI,CAAC;QACjBhC;QACAiC,eAAe;QACf,
|
|
1
|
+
{"version":3,"sources":["../../src/bin/migrate.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { ParsedArgs } from 'minimist'\n\nimport type { SanitizedConfig } from '../config/types.js'\n\nimport payload from '../index.js'\nimport { prettySyncLoggerDestination } from '../utilities/logger.js'\n\n/**\n * The default logger's options did not allow for forcing sync logging\n * Using these options, to force both pretty print and sync logging\n */\nconst prettySyncLogger = {\n loggerDestination: prettySyncLoggerDestination,\n loggerOptions: {},\n}\n\nexport const availableCommands = [\n 'migrate',\n 'migrate:create',\n 'migrate:down',\n 'migrate:refresh',\n 'migrate:reset',\n 'migrate:status',\n 'migrate:fresh',\n]\n\nconst availableCommandsMsg = `Available commands: ${availableCommands.join(', ')}`\n\ntype Args = {\n config: SanitizedConfig\n parsedArgs: ParsedArgs\n}\n\nexport const migrate = async ({ config, parsedArgs }: Args): Promise<void> => {\n const { _: args, file, forceAcceptWarning: forceAcceptFromProps, help } = parsedArgs\n\n const formattedArgs = Object.keys(parsedArgs)\n .map((key) => {\n const formattedKey = key.replace(/^[-_]+/, '')\n if (!formattedKey) {\n return null\n }\n\n return formattedKey\n .split('-')\n .map((word, index) =>\n index === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1),\n )\n .join('')\n })\n .filter(Boolean)\n\n const forceAcceptWarning = forceAcceptFromProps || formattedArgs.includes('forceAcceptWarning')\n const skipEmpty = formattedArgs.includes('skipEmpty')\n\n if (help) {\n // eslint-disable-next-line no-console\n console.log(`\\n\\n${availableCommandsMsg}\\n`) // Avoid having to init payload to get the logger\n process.exit(0)\n }\n\n process.env.PAYLOAD_MIGRATING = 'true'\n\n // Barebones instance to access database adapter\n await payload.init({\n config,\n disableDBConnect: args[0] === 'migrate:create',\n disableOnInit: true,\n ...prettySyncLogger,\n })\n\n const adapter = payload.db\n\n if (!adapter) {\n throw new Error('No database adapter found')\n }\n\n if (!args.length) {\n payload.logger.error({\n msg: `No migration command provided. ${availableCommandsMsg}`,\n })\n process.exit(1)\n }\n\n switch (args[0]) {\n case 'migrate':\n await adapter.migrate()\n break\n case 'migrate:create':\n try {\n await adapter.createMigration({\n file,\n forceAcceptWarning,\n migrationName: args[1],\n payload,\n skipEmpty,\n })\n } catch (err) {\n throw new Error(`Error creating migration: ${err.message}`)\n }\n break\n case 'migrate:down':\n await adapter.migrateDown()\n break\n case 'migrate:fresh':\n await adapter.migrateFresh({ forceAcceptWarning })\n break\n case 'migrate:refresh':\n await adapter.migrateRefresh()\n break\n case 'migrate:reset':\n await adapter.migrateReset()\n break\n case 'migrate:status':\n await adapter.migrateStatus()\n break\n\n default:\n payload.logger.error({\n msg: `Unknown migration command: ${args[0]}. ${availableCommandsMsg}`,\n })\n process.exit(1)\n }\n\n payload.logger.info('Done.')\n}\n"],"names":["payload","prettySyncLoggerDestination","prettySyncLogger","loggerDestination","loggerOptions","availableCommands","availableCommandsMsg","join","migrate","config","parsedArgs","_","args","file","forceAcceptWarning","forceAcceptFromProps","help","formattedArgs","Object","keys","map","key","formattedKey","replace","split","word","index","toLowerCase","charAt","toUpperCase","slice","filter","Boolean","includes","skipEmpty","console","log","process","exit","env","PAYLOAD_MIGRATING","init","disableDBConnect","disableOnInit","adapter","db","Error","length","logger","error","msg","createMigration","migrationName","err","message","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","info"],"mappings":"AAAA,oBAAoB;AAKpB,OAAOA,aAAa,cAAa;AACjC,SAASC,2BAA2B,QAAQ,yBAAwB;AAEpE;;;CAGC,GACD,MAAMC,mBAAmB;IACvBC,mBAAmBF;IACnBG,eAAe,CAAC;AAClB;AAEA,OAAO,MAAMC,oBAAoB;IAC/B;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED,MAAMC,uBAAuB,CAAC,oBAAoB,EAAED,kBAAkBE,IAAI,CAAC,OAAO;AAOlF,OAAO,MAAMC,UAAU,OAAO,EAAEC,MAAM,EAAEC,UAAU,EAAQ;IACxD,MAAM,EAAEC,GAAGC,IAAI,EAAEC,IAAI,EAAEC,oBAAoBC,oBAAoB,EAAEC,IAAI,EAAE,GAAGN;IAE1E,MAAMO,gBAAgBC,OAAOC,IAAI,CAACT,YAC/BU,GAAG,CAAC,CAACC;QACJ,MAAMC,eAAeD,IAAIE,OAAO,CAAC,UAAU;QAC3C,IAAI,CAACD,cAAc;YACjB,OAAO;QACT;QAEA,OAAOA,aACJE,KAAK,CAAC,KACNJ,GAAG,CAAC,CAACK,MAAMC,QACVA,UAAU,IAAID,KAAKE,WAAW,KAAKF,KAAKG,MAAM,CAAC,GAAGC,WAAW,KAAKJ,KAAKK,KAAK,CAAC,IAE9EvB,IAAI,CAAC;IACV,GACCwB,MAAM,CAACC;IA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,aAAa;YAC3B;QAEF;YACE3D,QAAQgD,MAAM,CAACC,KAAK,CAAC;gBACnBC,KAAK,CAAC,2BAA2B,EAAEtC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAEN,sBAAsB;YACvE;YACA+B,QAAQC,IAAI,CAAC;IACjB;IAEAtC,QAAQgD,MAAM,CAACY,IAAI,CAAC;AACtB,EAAC"}
|
|
@@ -18,7 +18,7 @@ export type SelectFromCollectionSlug<TSlug extends CollectionSlug> = TypedCollec
|
|
|
18
18
|
export type AuthOperationsFromCollectionSlug<TSlug extends CollectionSlug> = TypedAuthOperations[TSlug];
|
|
19
19
|
export type RequiredDataFromCollection<TData extends JsonObject> = MarkOptional<TData, 'createdAt' | 'id' | 'sizes' | 'updatedAt'>;
|
|
20
20
|
export type RequiredDataFromCollectionSlug<TSlug extends CollectionSlug> = RequiredDataFromCollection<DataFromCollectionSlug<TSlug>>;
|
|
21
|
-
export type HookOperationType = 'autosave' | 'count' | 'countVersions' | 'create' | 'delete' | 'forgotPassword' | 'login' | 'read' | 'refresh' | 'update';
|
|
21
|
+
export type HookOperationType = 'autosave' | 'count' | 'countVersions' | 'create' | 'delete' | 'forgotPassword' | 'login' | 'read' | 'refresh' | 'resetPassword' | 'update';
|
|
22
22
|
type CreateOrUpdateOperation = Extract<HookOperationType, 'create' | 'update'>;
|
|
23
23
|
export type BeforeOperationHook = (args: {
|
|
24
24
|
args?: any;
|