@aws-amplify/adapter-nextjs 1.6.7-unstable.e5a8569.0 → 1.6.7

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 (67) hide show
  1. package/dist/cjs/api/generateServerClient.js.map +1 -1
  2. package/dist/cjs/api/index.js.map +1 -1
  3. package/dist/cjs/auth/createAuthRouteHandlersFactory.js.map +1 -1
  4. package/dist/cjs/auth/handleAuthApiRouteRequestForAppRouter.js.map +1 -1
  5. package/dist/cjs/auth/handleAuthApiRouteRequestForPagesRouter.js.map +1 -1
  6. package/dist/cjs/auth/handlers/handleSignInCallbackRequest.js.map +1 -1
  7. package/dist/cjs/auth/handlers/handleSignInCallbackRequestForPagesRouter.js.map +1 -1
  8. package/dist/cjs/auth/handlers/handleSignOutCallbackRequest.js.map +1 -1
  9. package/dist/cjs/auth/handlers/handleSignOutCallbackRequestForPagesRouter.js.map +1 -1
  10. package/dist/cjs/auth/handlers/index.js.map +1 -1
  11. package/dist/cjs/auth/index.js.map +1 -1
  12. package/dist/cjs/auth/utils/appendSetCookieHeaders.js.map +1 -1
  13. package/dist/cjs/auth/utils/appendSetCookieHeadersToNextApiResponse.js.map +1 -1
  14. package/dist/cjs/auth/utils/createErrorSearchParamsString.js.map +1 -1
  15. package/dist/cjs/auth/utils/createUrlSearchParams.js.map +1 -1
  16. package/dist/cjs/auth/utils/getCookieValuesFromNextApiRequest.js.map +1 -1
  17. package/dist/cjs/auth/utils/getCookieValuesFromRequest.js.map +1 -1
  18. package/dist/cjs/auth/utils/getSearchParamValueFromUrl.js.map +1 -1
  19. package/dist/cjs/auth/utils/hasActiveUserSession.js.map +1 -1
  20. package/dist/cjs/auth/utils/index.js.map +1 -1
  21. package/dist/cjs/auth/utils/origin.js.map +1 -1
  22. package/dist/cjs/auth/utils/predicates.js +16 -1
  23. package/dist/cjs/auth/utils/predicates.js.map +1 -1
  24. package/dist/cjs/auth/utils/resolveIdentityProviderFromUrl.js.map +1 -1
  25. package/dist/cjs/auth/utils/resolveRedirectUrl.js.map +1 -1
  26. package/dist/cjs/auth/utils/tokenCookies.js.map +1 -1
  27. package/dist/cjs/createServerRunner.js.map +1 -1
  28. package/dist/cjs/index.js.map +1 -1
  29. package/dist/cjs/utils/cookie/index.js.map +1 -1
  30. package/dist/cjs/utils/cookie/serializeCookie.js.map +1 -1
  31. package/dist/cjs/utils/createCookieStorageAdapterFromNextServerContext.js.map +1 -1
  32. package/dist/cjs/utils/createRunWithAmplifyServerContext.js.map +1 -1
  33. package/dist/cjs/utils/createTokenValidator.js.map +1 -1
  34. package/dist/cjs/utils/globalSettings.js.map +1 -1
  35. package/dist/cjs/utils/index.js.map +1 -1
  36. package/dist/cjs/utils/isValidCognitoToken.js.map +1 -1
  37. package/dist/esm/api/generateServerClient.mjs.map +1 -1
  38. package/dist/esm/auth/createAuthRouteHandlersFactory.mjs.map +1 -1
  39. package/dist/esm/auth/handleAuthApiRouteRequestForAppRouter.mjs.map +1 -1
  40. package/dist/esm/auth/handleAuthApiRouteRequestForPagesRouter.mjs.map +1 -1
  41. package/dist/esm/auth/handlers/handleSignInCallbackRequest.mjs.map +1 -1
  42. package/dist/esm/auth/handlers/handleSignInCallbackRequestForPagesRouter.mjs.map +1 -1
  43. package/dist/esm/auth/handlers/handleSignOutCallbackRequest.mjs.map +1 -1
  44. package/dist/esm/auth/handlers/handleSignOutCallbackRequestForPagesRouter.mjs.map +1 -1
  45. package/dist/esm/auth/utils/appendSetCookieHeaders.mjs.map +1 -1
  46. package/dist/esm/auth/utils/appendSetCookieHeadersToNextApiResponse.mjs.map +1 -1
  47. package/dist/esm/auth/utils/createErrorSearchParamsString.mjs.map +1 -1
  48. package/dist/esm/auth/utils/createUrlSearchParams.mjs.map +1 -1
  49. package/dist/esm/auth/utils/getCookieValuesFromNextApiRequest.mjs.map +1 -1
  50. package/dist/esm/auth/utils/getCookieValuesFromRequest.mjs.map +1 -1
  51. package/dist/esm/auth/utils/getSearchParamValueFromUrl.mjs.map +1 -1
  52. package/dist/esm/auth/utils/hasActiveUserSession.mjs.map +1 -1
  53. package/dist/esm/auth/utils/origin.mjs.map +1 -1
  54. package/dist/esm/auth/utils/predicates.mjs +16 -1
  55. package/dist/esm/auth/utils/predicates.mjs.map +1 -1
  56. package/dist/esm/auth/utils/resolveIdentityProviderFromUrl.mjs.map +1 -1
  57. package/dist/esm/auth/utils/resolveRedirectUrl.mjs.map +1 -1
  58. package/dist/esm/auth/utils/tokenCookies.mjs.map +1 -1
  59. package/dist/esm/createServerRunner.mjs.map +1 -1
  60. package/dist/esm/utils/cookie/serializeCookie.mjs.map +1 -1
  61. package/dist/esm/utils/createCookieStorageAdapterFromNextServerContext.mjs.map +1 -1
  62. package/dist/esm/utils/createRunWithAmplifyServerContext.mjs.map +1 -1
  63. package/dist/esm/utils/createTokenValidator.mjs.map +1 -1
  64. package/dist/esm/utils/globalSettings.mjs.map +1 -1
  65. package/dist/esm/utils/isValidCognitoToken.mjs.map +1 -1
  66. package/package.json +70 -70
  67. package/src/auth/utils/predicates.ts +19 -1
@@ -1 +1 @@
1
- {"version":3,"file":"createUrlSearchParams.mjs","sources":["../../../../src/auth/utils/createUrlSearchParams.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { resolveIdentityProviderFromUrl } from './resolveIdentityProviderFromUrl';\nimport { resolveRedirectSignInUrl } from './resolveRedirectUrl';\nimport { getSearchParamValueFromUrl } from './getSearchParamValueFromUrl';\nexport const createUrlSearchParamsForSignInSignUp = ({ url, oAuthConfig, userPoolClientId, state, origin, codeVerifier, }) => {\n const resolvedProvider = resolveIdentityProviderFromUrl(url);\n const lang = getSearchParamValueFromUrl(url, 'lang');\n const redirectUrlSearchParams = new URLSearchParams({\n redirect_uri: resolveRedirectSignInUrl(origin, oAuthConfig),\n response_type: oAuthConfig.responseType,\n client_id: userPoolClientId,\n scope: oAuthConfig.scopes.join(' '),\n state,\n code_challenge: codeVerifier.toCodeChallenge(),\n code_challenge_method: codeVerifier.method,\n });\n if (resolvedProvider) {\n redirectUrlSearchParams.append('identity_provider', resolvedProvider);\n }\n if (lang) {\n redirectUrlSearchParams.append('lang', lang);\n }\n return redirectUrlSearchParams;\n};\nexport const createUrlSearchParamsForTokenExchange = (input) => new URLSearchParams(input);\nexport const createUrlSearchParamsForTokenRevocation = (input) => new URLSearchParams(input);\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIY,MAAC,oCAAoC,GAAG,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,GAAG,KAAK;AAC9H,IAAI,MAAM,gBAAgB,GAAG,8BAA8B,CAAC,GAAG,CAAC;AAChE,IAAI,MAAM,IAAI,GAAG,0BAA0B,CAAC,GAAG,EAAE,MAAM,CAAC;AACxD,IAAI,MAAM,uBAAuB,GAAG,IAAI,eAAe,CAAC;AACxD,QAAQ,YAAY,EAAE,wBAAwB,CAAC,MAAM,EAAE,WAAW,CAAC;AACnE,QAAQ,aAAa,EAAE,WAAW,CAAC,YAAY;AAC/C,QAAQ,SAAS,EAAE,gBAAgB;AACnC,QAAQ,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;AAC3C,QAAQ,KAAK;AACb,QAAQ,cAAc,EAAE,YAAY,CAAC,eAAe,EAAE;AACtD,QAAQ,qBAAqB,EAAE,YAAY,CAAC,MAAM;AAClD,KAAK,CAAC;AACN,IAAI,IAAI,gBAAgB,EAAE;AAC1B,QAAQ,uBAAuB,CAAC,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,CAAC;AAC7E;AACA,IAAI,IAAI,IAAI,EAAE;AACd,QAAQ,uBAAuB,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;AACpD;AACA,IAAI,OAAO,uBAAuB;AAClC;AACY,MAAC,qCAAqC,GAAG,CAAC,KAAK,KAAK,IAAI,eAAe,CAAC,KAAK;AAC7E,MAAC,uCAAuC,GAAG,CAAC,KAAK,KAAK,IAAI,eAAe,CAAC,KAAK;;;;"}
1
+ {"version":3,"file":"createUrlSearchParams.mjs","sources":["../../../../src/auth/utils/createUrlSearchParams.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { resolveIdentityProviderFromUrl } from './resolveIdentityProviderFromUrl';\nimport { resolveRedirectSignInUrl } from './resolveRedirectUrl';\nimport { getSearchParamValueFromUrl } from './getSearchParamValueFromUrl';\nexport const createUrlSearchParamsForSignInSignUp = ({ url, oAuthConfig, userPoolClientId, state, origin, codeVerifier, }) => {\n const resolvedProvider = resolveIdentityProviderFromUrl(url);\n const lang = getSearchParamValueFromUrl(url, 'lang');\n const redirectUrlSearchParams = new URLSearchParams({\n redirect_uri: resolveRedirectSignInUrl(origin, oAuthConfig),\n response_type: oAuthConfig.responseType,\n client_id: userPoolClientId,\n scope: oAuthConfig.scopes.join(' '),\n state,\n code_challenge: codeVerifier.toCodeChallenge(),\n code_challenge_method: codeVerifier.method,\n });\n if (resolvedProvider) {\n redirectUrlSearchParams.append('identity_provider', resolvedProvider);\n }\n if (lang) {\n redirectUrlSearchParams.append('lang', lang);\n }\n return redirectUrlSearchParams;\n};\nexport const createUrlSearchParamsForTokenExchange = (input) => new URLSearchParams(input);\nexport const createUrlSearchParamsForTokenRevocation = (input) => new URLSearchParams(input);\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIY,MAAC,oCAAoC,GAAG,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,GAAG,KAAK;AAC9H,IAAI,MAAM,gBAAgB,GAAG,8BAA8B,CAAC,GAAG,CAAC;AAChE,IAAI,MAAM,IAAI,GAAG,0BAA0B,CAAC,GAAG,EAAE,MAAM,CAAC;AACxD,IAAI,MAAM,uBAAuB,GAAG,IAAI,eAAe,CAAC;AACxD,QAAQ,YAAY,EAAE,wBAAwB,CAAC,MAAM,EAAE,WAAW,CAAC;AACnE,QAAQ,aAAa,EAAE,WAAW,CAAC,YAAY;AAC/C,QAAQ,SAAS,EAAE,gBAAgB;AACnC,QAAQ,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;AAC3C,QAAQ,KAAK;AACb,QAAQ,cAAc,EAAE,YAAY,CAAC,eAAe,EAAE;AACtD,QAAQ,qBAAqB,EAAE,YAAY,CAAC,MAAM;AAClD,KAAK,CAAC;AACN,IAAI,IAAI,gBAAgB,EAAE;AAC1B,QAAQ,uBAAuB,CAAC,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,CAAC;AAC7E,IAAI;AACJ,IAAI,IAAI,IAAI,EAAE;AACd,QAAQ,uBAAuB,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;AACpD,IAAI;AACJ,IAAI,OAAO,uBAAuB;AAClC;AACY,MAAC,qCAAqC,GAAG,CAAC,KAAK,KAAK,IAAI,eAAe,CAAC,KAAK;AAC7E,MAAC,uCAAuC,GAAG,CAAC,KAAK,KAAK,IAAI,eAAe,CAAC,KAAK;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"getCookieValuesFromNextApiRequest.mjs","sources":["../../../../src/auth/utils/getCookieValuesFromNextApiRequest.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const getCookieValuesFromNextApiRequest = (request, cookieNames) => {\n const result = {};\n for (const cookieName of cookieNames) {\n result[cookieName] = request.cookies[cookieName];\n }\n return result;\n};\n"],"names":[],"mappings":"AAAA;AACA;AACY,MAAC,iCAAiC,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK;AAC3E,IAAI,MAAM,MAAM,GAAG,EAAE;AACrB,IAAI,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;AAC1C,QAAQ,MAAM,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;AACxD;AACA,IAAI,OAAO,MAAM;AACjB;;;;"}
1
+ {"version":3,"file":"getCookieValuesFromNextApiRequest.mjs","sources":["../../../../src/auth/utils/getCookieValuesFromNextApiRequest.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const getCookieValuesFromNextApiRequest = (request, cookieNames) => {\n const result = {};\n for (const cookieName of cookieNames) {\n result[cookieName] = request.cookies[cookieName];\n }\n return result;\n};\n"],"names":[],"mappings":"AAAA;AACA;AACY,MAAC,iCAAiC,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK;AAC3E,IAAI,MAAM,MAAM,GAAG,EAAE;AACrB,IAAI,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;AAC1C,QAAQ,MAAM,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;AACxD,IAAI;AACJ,IAAI,OAAO,MAAM;AACjB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"getCookieValuesFromRequest.mjs","sources":["../../../../src/auth/utils/getCookieValuesFromRequest.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const getCookieValuesFromRequest = (request, cookieNames) => {\n const cookieHeader = request.headers.get('Cookie');\n if (!cookieHeader) {\n return {};\n }\n const cookieValues = cookieHeader\n .split(';')\n .map(cookie => cookie.trim().split('='))\n .reduce((result, [key, value]) => {\n result[key] = value;\n return result;\n }, {});\n const result = {};\n for (const cookieName of cookieNames) {\n result[cookieName] = cookieValues[cookieName];\n }\n return result;\n};\n"],"names":[],"mappings":"AAAA;AACA;AACY,MAAC,0BAA0B,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK;AACpE,IAAI,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;AACtD,IAAI,IAAI,CAAC,YAAY,EAAE;AACvB,QAAQ,OAAO,EAAE;AACjB;AACA,IAAI,MAAM,YAAY,GAAG;AACzB,SAAS,KAAK,CAAC,GAAG;AAClB,SAAS,GAAG,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC;AAC/C,SAAS,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;AAC1C,QAAQ,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK;AAC3B,QAAQ,OAAO,MAAM;AACrB,KAAK,EAAE,EAAE,CAAC;AACV,IAAI,MAAM,MAAM,GAAG,EAAE;AACrB,IAAI,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;AAC1C,QAAQ,MAAM,CAAC,UAAU,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC;AACrD;AACA,IAAI,OAAO,MAAM;AACjB;;;;"}
1
+ {"version":3,"file":"getCookieValuesFromRequest.mjs","sources":["../../../../src/auth/utils/getCookieValuesFromRequest.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const getCookieValuesFromRequest = (request, cookieNames) => {\n const cookieHeader = request.headers.get('Cookie');\n if (!cookieHeader) {\n return {};\n }\n const cookieValues = cookieHeader\n .split(';')\n .map(cookie => cookie.trim().split('='))\n .reduce((result, [key, value]) => {\n result[key] = value;\n return result;\n }, {});\n const result = {};\n for (const cookieName of cookieNames) {\n result[cookieName] = cookieValues[cookieName];\n }\n return result;\n};\n"],"names":[],"mappings":"AAAA;AACA;AACY,MAAC,0BAA0B,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK;AACpE,IAAI,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;AACtD,IAAI,IAAI,CAAC,YAAY,EAAE;AACvB,QAAQ,OAAO,EAAE;AACjB,IAAI;AACJ,IAAI,MAAM,YAAY,GAAG;AACzB,SAAS,KAAK,CAAC,GAAG;AAClB,SAAS,GAAG,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC;AAC/C,SAAS,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;AAC1C,QAAQ,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK;AAC3B,QAAQ,OAAO,MAAM;AACrB,IAAI,CAAC,EAAE,EAAE,CAAC;AACV,IAAI,MAAM,MAAM,GAAG,EAAE;AACrB,IAAI,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;AAC1C,QAAQ,MAAM,CAAC,UAAU,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC;AACrD,IAAI;AACJ,IAAI,OAAO,MAAM;AACjB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"getSearchParamValueFromUrl.mjs","sources":["../../../../src/auth/utils/getSearchParamValueFromUrl.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const getSearchParamValueFromUrl = (urlStr, paramName) => {\n if (urlStr.includes('?')) {\n const queryParams = urlStr.split('?')[1];\n if (queryParams) {\n return new URLSearchParams(queryParams).get(paramName);\n }\n }\n return null;\n};\n"],"names":[],"mappings":"AAAA;AACA;AACY,MAAC,0BAA0B,GAAG,CAAC,MAAM,EAAE,SAAS,KAAK;AACjE,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AAC9B,QAAQ,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAChD,QAAQ,IAAI,WAAW,EAAE;AACzB,YAAY,OAAO,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC;AAClE;AACA;AACA,IAAI,OAAO,IAAI;AACf;;;;"}
1
+ {"version":3,"file":"getSearchParamValueFromUrl.mjs","sources":["../../../../src/auth/utils/getSearchParamValueFromUrl.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const getSearchParamValueFromUrl = (urlStr, paramName) => {\n if (urlStr.includes('?')) {\n const queryParams = urlStr.split('?')[1];\n if (queryParams) {\n return new URLSearchParams(queryParams).get(paramName);\n }\n }\n return null;\n};\n"],"names":[],"mappings":"AAAA;AACA;AACY,MAAC,0BAA0B,GAAG,CAAC,MAAM,EAAE,SAAS,KAAK;AACjE,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AAC9B,QAAQ,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAChD,QAAQ,IAAI,WAAW,EAAE;AACzB,YAAY,OAAO,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC;AAClE,QAAQ;AACR,IAAI;AACJ,IAAI,OAAO,IAAI;AACf;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"hasActiveUserSession.mjs","sources":["../../../../src/auth/utils/hasActiveUserSession.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { getCurrentUser } from 'aws-amplify/auth/server';\nexport const hasActiveUserSessionWithAppRouter = async ({ request, runWithAmplifyServerContext, }) => {\n const dummyResponse = new Response();\n try {\n await runWithAmplifyServerContext({\n nextServerContext: { request, response: dummyResponse },\n operation(contextSpec) {\n return getCurrentUser(contextSpec);\n },\n });\n return true;\n }\n catch (_) {\n // `getCurrentUser()` throws if there is no valid token\n return false;\n }\n};\nexport const hasActiveUserSessionWithPagesRouter = async ({ request, response, runWithAmplifyServerContext, }) => {\n try {\n await runWithAmplifyServerContext({\n nextServerContext: { request, response },\n operation(contextSpec) {\n return getCurrentUser(contextSpec);\n },\n });\n return true;\n }\n catch (_) {\n // `getCurrentUser()` throws if there is no valid token\n return false;\n }\n};\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,iCAAiC,GAAG,OAAO,EAAE,OAAO,EAAE,2BAA2B,GAAG,KAAK;AACtG,IAAI,MAAM,aAAa,GAAG,IAAI,QAAQ,EAAE;AACxC,IAAI,IAAI;AACR,QAAQ,MAAM,2BAA2B,CAAC;AAC1C,YAAY,iBAAiB,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE;AACnE,YAAY,SAAS,CAAC,WAAW,EAAE;AACnC,gBAAgB,OAAO,cAAc,CAAC,WAAW,CAAC;AAClD,aAAa;AACb,SAAS,CAAC;AACV,QAAQ,OAAO,IAAI;AACnB;AACA,IAAI,OAAO,CAAC,EAAE;AACd;AACA,QAAQ,OAAO,KAAK;AACpB;AACA;AACY,MAAC,mCAAmC,GAAG,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,2BAA2B,GAAG,KAAK;AAClH,IAAI,IAAI;AACR,QAAQ,MAAM,2BAA2B,CAAC;AAC1C,YAAY,iBAAiB,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE;AACpD,YAAY,SAAS,CAAC,WAAW,EAAE;AACnC,gBAAgB,OAAO,cAAc,CAAC,WAAW,CAAC;AAClD,aAAa;AACb,SAAS,CAAC;AACV,QAAQ,OAAO,IAAI;AACnB;AACA,IAAI,OAAO,CAAC,EAAE;AACd;AACA,QAAQ,OAAO,KAAK;AACpB;AACA;;;;"}
1
+ {"version":3,"file":"hasActiveUserSession.mjs","sources":["../../../../src/auth/utils/hasActiveUserSession.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { getCurrentUser } from 'aws-amplify/auth/server';\nexport const hasActiveUserSessionWithAppRouter = async ({ request, runWithAmplifyServerContext, }) => {\n const dummyResponse = new Response();\n try {\n await runWithAmplifyServerContext({\n nextServerContext: { request, response: dummyResponse },\n operation(contextSpec) {\n return getCurrentUser(contextSpec);\n },\n });\n return true;\n }\n catch (_) {\n // `getCurrentUser()` throws if there is no valid token\n return false;\n }\n};\nexport const hasActiveUserSessionWithPagesRouter = async ({ request, response, runWithAmplifyServerContext, }) => {\n try {\n await runWithAmplifyServerContext({\n nextServerContext: { request, response },\n operation(contextSpec) {\n return getCurrentUser(contextSpec);\n },\n });\n return true;\n }\n catch (_) {\n // `getCurrentUser()` throws if there is no valid token\n return false;\n }\n};\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,iCAAiC,GAAG,OAAO,EAAE,OAAO,EAAE,2BAA2B,GAAG,KAAK;AACtG,IAAI,MAAM,aAAa,GAAG,IAAI,QAAQ,EAAE;AACxC,IAAI,IAAI;AACR,QAAQ,MAAM,2BAA2B,CAAC;AAC1C,YAAY,iBAAiB,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE;AACnE,YAAY,SAAS,CAAC,WAAW,EAAE;AACnC,gBAAgB,OAAO,cAAc,CAAC,WAAW,CAAC;AAClD,YAAY,CAAC;AACb,SAAS,CAAC;AACV,QAAQ,OAAO,IAAI;AACnB,IAAI;AACJ,IAAI,OAAO,CAAC,EAAE;AACd;AACA,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ;AACY,MAAC,mCAAmC,GAAG,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,2BAA2B,GAAG,KAAK;AAClH,IAAI,IAAI;AACR,QAAQ,MAAM,2BAA2B,CAAC;AAC1C,YAAY,iBAAiB,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE;AACpD,YAAY,SAAS,CAAC,WAAW,EAAE;AACnC,gBAAgB,OAAO,cAAc,CAAC,WAAW,CAAC;AAClD,YAAY,CAAC;AACb,SAAS,CAAC;AACV,QAAQ,OAAO,IAAI;AACnB,IAAI;AACJ,IAAI,OAAO,CAAC,EAAE;AACd;AACA,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"origin.mjs","sources":["../../../../src/auth/utils/origin.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n// a regular expression that validates the origin string to be any valid origin, and allowing local development localhost\nconst originRegex = /^(http:\\/\\/localhost(:\\d{1,5})?)|(https?:\\/\\/[a-z0-9-]+(\\.[a-z0-9-]+)*(:\\d{1,5})?)$/;\nexport const isValidOrigin = (origin) => {\n const url = createUrlObjectOrUndefined(origin);\n if (!url) {\n return false;\n }\n if (url.protocol === 'http:' &&\n url.hostname !== 'localhost' &&\n url.hostname !== '127.0.0.1') {\n // eslint-disable-next-line no-console\n console.warn('HTTP origin detected. This is insecure and should only be used for local development.');\n }\n return url.protocol === 'http:' || url.protocol === 'https:';\n};\nexport const isSSLOrigin = (origin) => {\n const url = createUrlObjectOrUndefined(origin);\n if (!url) {\n return false;\n }\n return url.protocol === 'https:';\n};\nconst createUrlObjectOrUndefined = (url) => {\n if (!url) {\n return undefined;\n }\n // we don't allow format such as `https://localhost:` (without the port number) which is valid in URL constructor\n if (!originRegex.test(url)) {\n return undefined;\n }\n // the `originRegex` ensured a string that can be parsed by URL constructor\n return new URL(url);\n};\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA,MAAM,WAAW,GAAG,qFAAqF;AAC7F,MAAC,aAAa,GAAG,CAAC,MAAM,KAAK;AACzC,IAAI,MAAM,GAAG,GAAG,0BAA0B,CAAC,MAAM,CAAC;AAClD,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,QAAQ,OAAO,KAAK;AACpB;AACA,IAAI,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO;AAChC,QAAQ,GAAG,CAAC,QAAQ,KAAK,WAAW;AACpC,QAAQ,GAAG,CAAC,QAAQ,KAAK,WAAW,EAAE;AACtC;AACA,QAAQ,OAAO,CAAC,IAAI,CAAC,uFAAuF,CAAC;AAC7G;AACA,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ;AAChE;AACY,MAAC,WAAW,GAAG,CAAC,MAAM,KAAK;AACvC,IAAI,MAAM,GAAG,GAAG,0BAA0B,CAAC,MAAM,CAAC;AAClD,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,QAAQ,OAAO,KAAK;AACpB;AACA,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ;AACpC;AACA,MAAM,0BAA0B,GAAG,CAAC,GAAG,KAAK;AAC5C,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,QAAQ,OAAO,SAAS;AACxB;AACA;AACA,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;AAChC,QAAQ,OAAO,SAAS;AACxB;AACA;AACA,IAAI,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC;AACvB,CAAC;;;;"}
1
+ {"version":3,"file":"origin.mjs","sources":["../../../../src/auth/utils/origin.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n// a regular expression that validates the origin string to be any valid origin, and allowing local development localhost\nconst originRegex = /^(http:\\/\\/localhost(:\\d{1,5})?)|(https?:\\/\\/[a-z0-9-]+(\\.[a-z0-9-]+)*(:\\d{1,5})?)$/;\nexport const isValidOrigin = (origin) => {\n const url = createUrlObjectOrUndefined(origin);\n if (!url) {\n return false;\n }\n if (url.protocol === 'http:' &&\n url.hostname !== 'localhost' &&\n url.hostname !== '127.0.0.1') {\n // eslint-disable-next-line no-console\n console.warn('HTTP origin detected. This is insecure and should only be used for local development.');\n }\n return url.protocol === 'http:' || url.protocol === 'https:';\n};\nexport const isSSLOrigin = (origin) => {\n const url = createUrlObjectOrUndefined(origin);\n if (!url) {\n return false;\n }\n return url.protocol === 'https:';\n};\nconst createUrlObjectOrUndefined = (url) => {\n if (!url) {\n return undefined;\n }\n // we don't allow format such as `https://localhost:` (without the port number) which is valid in URL constructor\n if (!originRegex.test(url)) {\n return undefined;\n }\n // the `originRegex` ensured a string that can be parsed by URL constructor\n return new URL(url);\n};\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA,MAAM,WAAW,GAAG,qFAAqF;AAC7F,MAAC,aAAa,GAAG,CAAC,MAAM,KAAK;AACzC,IAAI,MAAM,GAAG,GAAG,0BAA0B,CAAC,MAAM,CAAC;AAClD,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ,IAAI,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO;AAChC,QAAQ,GAAG,CAAC,QAAQ,KAAK,WAAW;AACpC,QAAQ,GAAG,CAAC,QAAQ,KAAK,WAAW,EAAE;AACtC;AACA,QAAQ,OAAO,CAAC,IAAI,CAAC,uFAAuF,CAAC;AAC7G,IAAI;AACJ,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ;AAChE;AACY,MAAC,WAAW,GAAG,CAAC,MAAM,KAAK;AACvC,IAAI,MAAM,GAAG,GAAG,0BAA0B,CAAC,MAAM,CAAC;AAClD,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ;AACpC;AACA,MAAM,0BAA0B,GAAG,CAAC,GAAG,KAAK;AAC5C,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,QAAQ,OAAO,SAAS;AACxB,IAAI;AACJ;AACA,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;AAChC,QAAQ,OAAO,SAAS;AACxB,IAAI;AACJ;AACA,IAAI,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC;AACvB,CAAC;;;;"}
@@ -4,7 +4,22 @@
4
4
  function isNextRequest(request) {
5
5
  // NextRequest extends the Web Request API with additional convenience methods.
6
6
  // Details: https://nextjs.org/docs/app/api-reference/functions/next-request#nexturl
7
- return request instanceof Request && 'nextUrl' in request;
7
+ //
8
+ // Use duck typing instead of instanceof to handle Lambda/serverless environments
9
+ // where Request constructor references may differ between invocations
10
+ return (typeof request === 'object' &&
11
+ request !== null &&
12
+ // NextRequest-specific properties
13
+ 'nextUrl' in request &&
14
+ typeof request.nextUrl === 'object' &&
15
+ request.nextUrl !== null &&
16
+ 'cookies' in request &&
17
+ // Basic Request API properties
18
+ 'url' in request &&
19
+ typeof request.url === 'string' &&
20
+ 'headers' in request &&
21
+ 'method' in request &&
22
+ typeof request.method === 'string');
8
23
  }
9
24
  // AuthRoutesHandlersContext is the 2nd parameter type for the API route handlers in the App Router
10
25
  function isAuthRoutesHandlersContext(context) {
@@ -1 +1 @@
1
- {"version":3,"file":"predicates.mjs","sources":["../../../../src/auth/utils/predicates.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n// NextRequest is the 1st parameter type for the API route handlers in the App Router\nexport function isNextRequest(request) {\n // NextRequest extends the Web Request API with additional convenience methods.\n // Details: https://nextjs.org/docs/app/api-reference/functions/next-request#nexturl\n return request instanceof Request && 'nextUrl' in request;\n}\n// AuthRoutesHandlersContext is the 2nd parameter type for the API route handlers in the App Router\nexport function isAuthRoutesHandlersContext(context) {\n return ('params' in context &&\n context.params !== undefined &&\n context.params !== null);\n}\n// NextApiRequest is the 1st parameter type for the API route handlers in the Pages Router\nexport function isNextApiRequest(request) {\n // Can't use `IncomingMessage` to validate the request is an instance of `NextApiRequest`\n // as `import from 'http'` breaks the Next.js build.\n // The `query` property is a convenience method added to the underlying `IncomingMessage`.\n return ('query' in request &&\n Object.prototype.toString.call(request.query) === '[object Object]');\n}\n// NextApiResponse is the 2nd parameter type for the API route handlers in the Pages Router\nexport function isNextApiResponse(response) {\n // Can't use `ServerResponse` to validate the request is an instance of `NextApiResponse`\n // as `import from 'http'` breaks the Next.js build.\n // The `redirect` method is a convenience method added to the underlying `ServerResponse`.\n return 'redirect' in response && typeof response.redirect === 'function';\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACO,SAAS,aAAa,CAAC,OAAO,EAAE;AACvC;AACA;AACA,IAAI,OAAO,OAAO,YAAY,OAAO,IAAI,SAAS,IAAI,OAAO;AAC7D;AACA;AACO,SAAS,2BAA2B,CAAC,OAAO,EAAE;AACrD,IAAI,QAAQ,QAAQ,IAAI,OAAO;AAC/B,QAAQ,OAAO,CAAC,MAAM,KAAK,SAAS;AACpC,QAAQ,OAAO,CAAC,MAAM,KAAK,IAAI;AAC/B;AACA;AACO,SAAS,gBAAgB,CAAC,OAAO,EAAE;AAC1C;AACA;AACA;AACA,IAAI,QAAQ,OAAO,IAAI,OAAO;AAC9B,QAAQ,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,iBAAiB;AAC3E;AACA;AACO,SAAS,iBAAiB,CAAC,QAAQ,EAAE;AAC5C;AACA;AACA;AACA,IAAI,OAAO,UAAU,IAAI,QAAQ,IAAI,OAAO,QAAQ,CAAC,QAAQ,KAAK,UAAU;AAC5E;;;;"}
1
+ {"version":3,"file":"predicates.mjs","sources":["../../../../src/auth/utils/predicates.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n// NextRequest is the 1st parameter type for the API route handlers in the App Router\nexport function isNextRequest(request) {\n // NextRequest extends the Web Request API with additional convenience methods.\n // Details: https://nextjs.org/docs/app/api-reference/functions/next-request#nexturl\n //\n // Use duck typing instead of instanceof to handle Lambda/serverless environments\n // where Request constructor references may differ between invocations\n return (typeof request === 'object' &&\n request !== null &&\n // NextRequest-specific properties\n 'nextUrl' in request &&\n typeof request.nextUrl === 'object' &&\n request.nextUrl !== null &&\n 'cookies' in request &&\n // Basic Request API properties\n 'url' in request &&\n typeof request.url === 'string' &&\n 'headers' in request &&\n 'method' in request &&\n typeof request.method === 'string');\n}\n// AuthRoutesHandlersContext is the 2nd parameter type for the API route handlers in the App Router\nexport function isAuthRoutesHandlersContext(context) {\n return ('params' in context &&\n context.params !== undefined &&\n context.params !== null);\n}\n// NextApiRequest is the 1st parameter type for the API route handlers in the Pages Router\nexport function isNextApiRequest(request) {\n // Can't use `IncomingMessage` to validate the request is an instance of `NextApiRequest`\n // as `import from 'http'` breaks the Next.js build.\n // The `query` property is a convenience method added to the underlying `IncomingMessage`.\n return ('query' in request &&\n Object.prototype.toString.call(request.query) === '[object Object]');\n}\n// NextApiResponse is the 2nd parameter type for the API route handlers in the Pages Router\nexport function isNextApiResponse(response) {\n // Can't use `ServerResponse` to validate the request is an instance of `NextApiResponse`\n // as `import from 'http'` breaks the Next.js build.\n // The `redirect` method is a convenience method added to the underlying `ServerResponse`.\n return 'redirect' in response && typeof response.redirect === 'function';\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACO,SAAS,aAAa,CAAC,OAAO,EAAE;AACvC;AACA;AACA;AACA;AACA;AACA,IAAI,QAAQ,OAAO,OAAO,KAAK,QAAQ;AACvC,QAAQ,OAAO,KAAK,IAAI;AACxB;AACA,QAAQ,SAAS,IAAI,OAAO;AAC5B,QAAQ,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ;AAC3C,QAAQ,OAAO,CAAC,OAAO,KAAK,IAAI;AAChC,QAAQ,SAAS,IAAI,OAAO;AAC5B;AACA,QAAQ,KAAK,IAAI,OAAO;AACxB,QAAQ,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ;AACvC,QAAQ,SAAS,IAAI,OAAO;AAC5B,QAAQ,QAAQ,IAAI,OAAO;AAC3B,QAAQ,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;AAC1C;AACA;AACO,SAAS,2BAA2B,CAAC,OAAO,EAAE;AACrD,IAAI,QAAQ,QAAQ,IAAI,OAAO;AAC/B,QAAQ,OAAO,CAAC,MAAM,KAAK,SAAS;AACpC,QAAQ,OAAO,CAAC,MAAM,KAAK,IAAI;AAC/B;AACA;AACO,SAAS,gBAAgB,CAAC,OAAO,EAAE;AAC1C;AACA;AACA;AACA,IAAI,QAAQ,OAAO,IAAI,OAAO;AAC9B,QAAQ,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,iBAAiB;AAC3E;AACA;AACO,SAAS,iBAAiB,CAAC,QAAQ,EAAE;AAC5C;AACA;AACA;AACA,IAAI,OAAO,UAAU,IAAI,QAAQ,IAAI,OAAO,QAAQ,CAAC,QAAQ,KAAK,UAAU;AAC5E;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolveIdentityProviderFromUrl.mjs","sources":["../../../../src/auth/utils/resolveIdentityProviderFromUrl.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { COGNITO_IDENTITY_PROVIDERS } from '../constant';\nimport { getSearchParamValueFromUrl } from './getSearchParamValueFromUrl';\nexport const resolveIdentityProviderFromUrl = (urlStr) => resolveProvider(getSearchParamValueFromUrl(urlStr, 'provider'));\nconst resolveProvider = (provider) => {\n if (!provider) {\n return null;\n }\n return COGNITO_IDENTITY_PROVIDERS[capitalize(provider)] ?? provider;\n};\nconst capitalize = (value) => `${value[0].toUpperCase()}${value.substring(1).toLowerCase()}`;\n"],"names":[],"mappings":";;;AAAA;AACA;AAGY,MAAC,8BAA8B,GAAG,CAAC,MAAM,KAAK,eAAe,CAAC,0BAA0B,CAAC,MAAM,EAAE,UAAU,CAAC;AACxH,MAAM,eAAe,GAAG,CAAC,QAAQ,KAAK;AACtC,IAAI,IAAI,CAAC,QAAQ,EAAE;AACnB,QAAQ,OAAO,IAAI;AACnB;AACA,IAAI,OAAO,0BAA0B,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,IAAI,QAAQ;AACvE,CAAC;AACD,MAAM,UAAU,GAAG,CAAC,KAAK,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"resolveIdentityProviderFromUrl.mjs","sources":["../../../../src/auth/utils/resolveIdentityProviderFromUrl.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { COGNITO_IDENTITY_PROVIDERS } from '../constant';\nimport { getSearchParamValueFromUrl } from './getSearchParamValueFromUrl';\nexport const resolveIdentityProviderFromUrl = (urlStr) => resolveProvider(getSearchParamValueFromUrl(urlStr, 'provider'));\nconst resolveProvider = (provider) => {\n if (!provider) {\n return null;\n }\n return COGNITO_IDENTITY_PROVIDERS[capitalize(provider)] ?? provider;\n};\nconst capitalize = (value) => `${value[0].toUpperCase()}${value.substring(1).toLowerCase()}`;\n"],"names":[],"mappings":";;;AAAA;AACA;AAGY,MAAC,8BAA8B,GAAG,CAAC,MAAM,KAAK,eAAe,CAAC,0BAA0B,CAAC,MAAM,EAAE,UAAU,CAAC;AACxH,MAAM,eAAe,GAAG,CAAC,QAAQ,KAAK;AACtC,IAAI,IAAI,CAAC,QAAQ,EAAE;AACnB,QAAQ,OAAO,IAAI;AACnB,IAAI;AACJ,IAAI,OAAO,0BAA0B,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,IAAI,QAAQ;AACvE,CAAC;AACD,MAAM,UAAU,GAAG,CAAC,KAAK,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolveRedirectUrl.mjs","sources":["../../../../src/auth/utils/resolveRedirectUrl.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AmplifyServerContextError, } from 'aws-amplify/adapter-core/internals';\nexport const resolveRedirectSignInUrl = (origin, oAuthConfig) => {\n const redirectUrl = oAuthConfig.redirectSignIn.find(url => url.startsWith(origin));\n if (!redirectUrl) {\n throw createError('redirectSignIn');\n }\n return redirectUrl;\n};\nexport const resolveRedirectSignOutUrl = (origin, oAuthConfig) => {\n const redirectUrl = oAuthConfig.redirectSignOut.find(url => url.startsWith(origin));\n if (!redirectUrl) {\n throw createError('redirectSignOut');\n }\n return redirectUrl;\n};\nconst createError = (urlType) => new AmplifyServerContextError({\n message: `No valid ${urlType} url found in the OAuth config.`,\n recoverySuggestion: `Check the OAuth config and ensure the ${urlType} url is valid.`,\n});\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,wBAAwB,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK;AACjE,IAAI,MAAM,WAAW,GAAG,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACtF,IAAI,IAAI,CAAC,WAAW,EAAE;AACtB,QAAQ,MAAM,WAAW,CAAC,gBAAgB,CAAC;AAC3C;AACA,IAAI,OAAO,WAAW;AACtB;AACY,MAAC,yBAAyB,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK;AAClE,IAAI,MAAM,WAAW,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACvF,IAAI,IAAI,CAAC,WAAW,EAAE;AACtB,QAAQ,MAAM,WAAW,CAAC,iBAAiB,CAAC;AAC5C;AACA,IAAI,OAAO,WAAW;AACtB;AACA,MAAM,WAAW,GAAG,CAAC,OAAO,KAAK,IAAI,yBAAyB,CAAC;AAC/D,IAAI,OAAO,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,+BAA+B,CAAC;AACjE,IAAI,kBAAkB,EAAE,CAAC,sCAAsC,EAAE,OAAO,CAAC,cAAc,CAAC;AACxF,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"resolveRedirectUrl.mjs","sources":["../../../../src/auth/utils/resolveRedirectUrl.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AmplifyServerContextError, } from 'aws-amplify/adapter-core/internals';\nexport const resolveRedirectSignInUrl = (origin, oAuthConfig) => {\n const redirectUrl = oAuthConfig.redirectSignIn.find(url => url.startsWith(origin));\n if (!redirectUrl) {\n throw createError('redirectSignIn');\n }\n return redirectUrl;\n};\nexport const resolveRedirectSignOutUrl = (origin, oAuthConfig) => {\n const redirectUrl = oAuthConfig.redirectSignOut.find(url => url.startsWith(origin));\n if (!redirectUrl) {\n throw createError('redirectSignOut');\n }\n return redirectUrl;\n};\nconst createError = (urlType) => new AmplifyServerContextError({\n message: `No valid ${urlType} url found in the OAuth config.`,\n recoverySuggestion: `Check the OAuth config and ensure the ${urlType} url is valid.`,\n});\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,wBAAwB,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK;AACjE,IAAI,MAAM,WAAW,GAAG,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACtF,IAAI,IAAI,CAAC,WAAW,EAAE;AACtB,QAAQ,MAAM,WAAW,CAAC,gBAAgB,CAAC;AAC3C,IAAI;AACJ,IAAI,OAAO,WAAW;AACtB;AACY,MAAC,yBAAyB,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK;AAClE,IAAI,MAAM,WAAW,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACvF,IAAI,IAAI,CAAC,WAAW,EAAE;AACtB,QAAQ,MAAM,WAAW,CAAC,iBAAiB,CAAC;AAC5C,IAAI;AACJ,IAAI,OAAO,WAAW;AACtB;AACA,MAAM,WAAW,GAAG,CAAC,OAAO,KAAK,IAAI,yBAAyB,CAAC;AAC/D,IAAI,OAAO,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,+BAA+B,CAAC;AACjE,IAAI,kBAAkB,EAAE,CAAC,sCAAsC,EAAE,OAAO,CAAC,cAAc,CAAC;AACxF,CAAC,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"tokenCookies.mjs","sources":["../../../../src/auth/utils/tokenCookies.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AUTH_KEY_PREFIX, DEFAULT_AUTH_TOKEN_COOKIES_MAX_AGE, createKeysForAuthStorage, } from 'aws-amplify/adapter-core';\nimport { REMOVE_COOKIE_MAX_AGE, SERVER_AUTH_ALLOWED_AMPLIFY_AUTH_KEY_SUFFIX, } from '../constant';\nimport { getAccessTokenUsername } from './getAccessTokenUsername';\nimport { isSSLOrigin } from './origin';\nexport const createTokenCookies = ({ tokensPayload, userPoolClientId, }) => {\n const { access_token, id_token, refresh_token } = tokensPayload;\n const username = getAccessTokenUsername(access_token);\n const authCookiesKeys = createKeysForAuthStorage(AUTH_KEY_PREFIX, `${userPoolClientId}.${username}`);\n return [\n {\n name: authCookiesKeys.accessToken,\n value: access_token,\n },\n {\n name: authCookiesKeys.idToken,\n value: id_token,\n },\n {\n name: authCookiesKeys.refreshToken,\n value: refresh_token,\n },\n {\n name: `${AUTH_KEY_PREFIX}.${userPoolClientId}.LastAuthUser`,\n value: username,\n },\n ];\n};\nexport const createTokenRemoveCookies = (keys) => keys.map(key => ({ name: key, value: '' }));\nexport const createTokenCookiesSetOptions = ({ domain, sameSite, expires, maxAge }, origin) => {\n const result = {\n domain,\n path: '/',\n httpOnly: true,\n secure: isSSLOrigin(origin),\n sameSite: sameSite ?? 'strict',\n expires,\n maxAge,\n };\n // when expires and maxAge both are not specified, we set a default maxAge\n if (!result.expires && !result.maxAge) {\n result.maxAge = DEFAULT_AUTH_TOKEN_COOKIES_MAX_AGE;\n }\n return result;\n};\nexport const createTokenCookiesRemoveOptions = (setCookieOptions) => ({\n domain: setCookieOptions?.domain,\n path: '/',\n maxAge: REMOVE_COOKIE_MAX_AGE, // Expire immediately (remove the cookie)\n});\nexport const isServerSideAuthAllowedCookie = (cookieName) => SERVER_AUTH_ALLOWED_AMPLIFY_AUTH_KEY_SUFFIX.some(suffix => cookieName.endsWith(suffix));\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAKY,MAAC,kBAAkB,GAAG,CAAC,EAAE,aAAa,EAAE,gBAAgB,GAAG,KAAK;AAC5E,IAAI,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,aAAa;AACnE,IAAI,MAAM,QAAQ,GAAG,sBAAsB,CAAC,YAAY,CAAC;AACzD,IAAI,MAAM,eAAe,GAAG,wBAAwB,CAAC,eAAe,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;AACxG,IAAI,OAAO;AACX,QAAQ;AACR,YAAY,IAAI,EAAE,eAAe,CAAC,WAAW;AAC7C,YAAY,KAAK,EAAE,YAAY;AAC/B,SAAS;AACT,QAAQ;AACR,YAAY,IAAI,EAAE,eAAe,CAAC,OAAO;AACzC,YAAY,KAAK,EAAE,QAAQ;AAC3B,SAAS;AACT,QAAQ;AACR,YAAY,IAAI,EAAE,eAAe,CAAC,YAAY;AAC9C,YAAY,KAAK,EAAE,aAAa;AAChC,SAAS;AACT,QAAQ;AACR,YAAY,IAAI,EAAE,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC;AACvE,YAAY,KAAK,EAAE,QAAQ;AAC3B,SAAS;AACT,KAAK;AACL;AACY,MAAC,wBAAwB,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;AAChF,MAAC,4BAA4B,GAAG,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,MAAM,KAAK;AAC/F,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,MAAM;AACd,QAAQ,IAAI,EAAE,GAAG;AACjB,QAAQ,QAAQ,EAAE,IAAI;AACtB,QAAQ,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;AACnC,QAAQ,QAAQ,EAAE,QAAQ,IAAI,QAAQ;AACtC,QAAQ,OAAO;AACf,QAAQ,MAAM;AACd,KAAK;AACL;AACA,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;AAC3C,QAAQ,MAAM,CAAC,MAAM,GAAG,kCAAkC;AAC1D;AACA,IAAI,OAAO,MAAM;AACjB;AACY,MAAC,+BAA+B,GAAG,CAAC,gBAAgB,MAAM;AACtE,IAAI,MAAM,EAAE,gBAAgB,EAAE,MAAM;AACpC,IAAI,IAAI,EAAE,GAAG;AACb,IAAI,MAAM,EAAE,qBAAqB;AACjC,CAAC;AACW,MAAC,6BAA6B,GAAG,CAAC,UAAU,KAAK,2CAA2C,CAAC,IAAI,CAAC,MAAM,IAAI,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC;;;;"}
1
+ {"version":3,"file":"tokenCookies.mjs","sources":["../../../../src/auth/utils/tokenCookies.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AUTH_KEY_PREFIX, DEFAULT_AUTH_TOKEN_COOKIES_MAX_AGE, createKeysForAuthStorage, } from 'aws-amplify/adapter-core';\nimport { REMOVE_COOKIE_MAX_AGE, SERVER_AUTH_ALLOWED_AMPLIFY_AUTH_KEY_SUFFIX, } from '../constant';\nimport { getAccessTokenUsername } from './getAccessTokenUsername';\nimport { isSSLOrigin } from './origin';\nexport const createTokenCookies = ({ tokensPayload, userPoolClientId, }) => {\n const { access_token, id_token, refresh_token } = tokensPayload;\n const username = getAccessTokenUsername(access_token);\n const authCookiesKeys = createKeysForAuthStorage(AUTH_KEY_PREFIX, `${userPoolClientId}.${username}`);\n return [\n {\n name: authCookiesKeys.accessToken,\n value: access_token,\n },\n {\n name: authCookiesKeys.idToken,\n value: id_token,\n },\n {\n name: authCookiesKeys.refreshToken,\n value: refresh_token,\n },\n {\n name: `${AUTH_KEY_PREFIX}.${userPoolClientId}.LastAuthUser`,\n value: username,\n },\n ];\n};\nexport const createTokenRemoveCookies = (keys) => keys.map(key => ({ name: key, value: '' }));\nexport const createTokenCookiesSetOptions = ({ domain, sameSite, expires, maxAge }, origin) => {\n const result = {\n domain,\n path: '/',\n httpOnly: true,\n secure: isSSLOrigin(origin),\n sameSite: sameSite ?? 'strict',\n expires,\n maxAge,\n };\n // when expires and maxAge both are not specified, we set a default maxAge\n if (!result.expires && !result.maxAge) {\n result.maxAge = DEFAULT_AUTH_TOKEN_COOKIES_MAX_AGE;\n }\n return result;\n};\nexport const createTokenCookiesRemoveOptions = (setCookieOptions) => ({\n domain: setCookieOptions?.domain,\n path: '/',\n maxAge: REMOVE_COOKIE_MAX_AGE, // Expire immediately (remove the cookie)\n});\nexport const isServerSideAuthAllowedCookie = (cookieName) => SERVER_AUTH_ALLOWED_AMPLIFY_AUTH_KEY_SUFFIX.some(suffix => cookieName.endsWith(suffix));\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAKY,MAAC,kBAAkB,GAAG,CAAC,EAAE,aAAa,EAAE,gBAAgB,GAAG,KAAK;AAC5E,IAAI,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,GA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,EAAE;AAC3C,QAAQ,MAAM,CAAC,MAAM,GAAG,kCAAkC;AAC1D,IAAI;AACJ,IAAI,OAAO,MAAM;AACjB;AACY,MAAC,+BAA+B,GAAG,CAAC,gBAAgB,MAAM;AACtE,IAAI,MAAM,EAAE,gBAAgB,EAAE,MAAM;AACpC,IAAI,IAAI,EAAE,GAAG;AACb,IAAI,MAAM,EAAE,qBAAqB;AACjC,CAAC;AACW,MAAC,6BAA6B,GAAG,CAAC,UAAU,KAAK,2CAA2C,CAAC,IAAI,CAAC,MAAM,IAAI,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"createServerRunner.mjs","sources":["../../src/createServerRunner.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { parseAmplifyConfig } from 'aws-amplify/utils';\nimport { createRunWithAmplifyServerContext, globalSettings } from './utils';\nimport { createTokenValidator } from './utils/createTokenValidator';\nimport { createAuthRouteHandlersFactory } from './auth';\nimport { isSSLOrigin, isValidOrigin } from './auth/utils';\n/**\n * Creates the `runWithAmplifyServerContext` function to run Amplify server side APIs in an isolated request context.\n *\n * @remarks\n * This function should be called only once; you can use the returned `runWithAmplifyServerContext` across\n * your codebase.\n *\n * @param input The input used to create the `runWithAmplifyServerContext` function.\n * @param input.config The {@link ResourcesConfig} imported from the `amplifyconfiguration.json` file or manually\n * created.\n * @returns An object that contains the `runWithAmplifyServerContext` function.\n *\n * @example\n * import { createServerRunner } from '@aws-amplify/adapter-nextjs';\n * import config from './amplifyconfiguration.json';\n *\n * export const { runWithAmplifyServerContext } = createServerRunner({ config })\n */\nexport const createServerRunner = ({ config, runtimeOptions, }) => {\n const amplifyConfig = parseAmplifyConfig(config);\n const amplifyAppOrigin = process.env.AMPLIFY_APP_ORIGIN;\n globalSettings.setRuntimeOptions(runtimeOptions ?? {});\n if (isValidOrigin(amplifyAppOrigin)) {\n globalSettings.setIsSSLOrigin(isSSLOrigin(amplifyAppOrigin));\n // update the isServerSideAuthEnabled flag of the globalSettings to true\n globalSettings.enableServerSideAuth();\n }\n let tokenValidator;\n if (amplifyConfig?.Auth) {\n const { Cognito } = amplifyConfig.Auth;\n tokenValidator = createTokenValidator({\n userPoolId: Cognito?.userPoolId,\n userPoolClientId: Cognito?.userPoolClientId,\n });\n }\n const runWithAmplifyServerContext = createRunWithAmplifyServerContext({\n config: amplifyConfig,\n tokenValidator,\n globalSettings,\n });\n return {\n runWithAmplifyServerContext,\n createAuthRouteHandlers: createAuthRouteHandlersFactory({\n config: amplifyConfig,\n amplifyAppOrigin,\n globalSettings,\n runWithAmplifyServerContext,\n }),\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,kBAAkB,GAAG,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,KAAK;AACnE,IAAI,MAAM,aAAa,GAAG,kBAAkB,CAAC,MAAM,CAAC;AACpD,IAAI,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB;AAC3D,IAAI,cAAc,CAAC,iBAAiB,CAAC,cAAc,IAAI,EAAE,CAAC;AAC1D,IAAI,IAAI,aAAa,CAAC,gBAAgB,CAAC,EAAE;AACzC,QAAQ,cAAc,CAAC,cAAc,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;AACpE;AACA,QAAQ,cAAc,CAAC,oBAAoB,EAAE;AAC7C;AACA,IAAI,IAAI,cAAc;AACtB,IAAI,IAAI,aAAa,EAAE,IAAI,EAAE;AAC7B,QAAQ,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC,IAAI;AAC9C,QAAQ,cAAc,GAAG,oBAAoB,CAAC;AAC9C,YAAY,UAAU,EAAE,OAAO,EAAE,UAAU;AAC3C,YAAY,gBAAgB,EAAE,OAAO,EAAE,gBAAgB;AACvD,SAAS,CAAC;AACV;AACA,IAAI,MAAM,2BAA2B,GAAG,iCAAiC,CAAC;AAC1E,QAAQ,MAAM,EAAE,aAAa;AAC7B,QAAQ,cAAc;AACtB,QAAQ,cAAc;AACtB,KAAK,CAAC;AACN,IAAI,OAAO;AACX,QAAQ,2BAA2B;AACnC,QAAQ,uBAAuB,EAAE,8BAA8B,CAAC;AAChE,YAAY,MAAM,EAAE,aAAa;AACjC,YAAY,gBAAgB;AAC5B,YAAY,cAAc;AAC1B,YAAY,2BAA2B;AACvC,SAAS,CAAC;AACV,KAAK;AACL;;;;"}
1
+ {"version":3,"file":"createServerRunner.mjs","sources":["../../src/createServerRunner.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { parseAmplifyConfig } from 'aws-amplify/utils';\nimport { createRunWithAmplifyServerContext, globalSettings } from './utils';\nimport { createTokenValidator } from './utils/createTokenValidator';\nimport { createAuthRouteHandlersFactory } from './auth';\nimport { isSSLOrigin, isValidOrigin } from './auth/utils';\n/**\n * Creates the `runWithAmplifyServerContext` function to run Amplify server side APIs in an isolated request context.\n *\n * @remarks\n * This function should be called only once; you can use the returned `runWithAmplifyServerContext` across\n * your codebase.\n *\n * @param input The input used to create the `runWithAmplifyServerContext` function.\n * @param input.config The {@link ResourcesConfig} imported from the `amplifyconfiguration.json` file or manually\n * created.\n * @returns An object that contains the `runWithAmplifyServerContext` function.\n *\n * @example\n * import { createServerRunner } from '@aws-amplify/adapter-nextjs';\n * import config from './amplifyconfiguration.json';\n *\n * export const { runWithAmplifyServerContext } = createServerRunner({ config })\n */\nexport const createServerRunner = ({ config, runtimeOptions, }) => {\n const amplifyConfig = parseAmplifyConfig(config);\n const amplifyAppOrigin = process.env.AMPLIFY_APP_ORIGIN;\n globalSettings.setRuntimeOptions(runtimeOptions ?? {});\n if (isValidOrigin(amplifyAppOrigin)) {\n globalSettings.setIsSSLOrigin(isSSLOrigin(amplifyAppOrigin));\n // update the isServerSideAuthEnabled flag of the globalSettings to true\n globalSettings.enableServerSideAuth();\n }\n let tokenValidator;\n if (amplifyConfig?.Auth) {\n const { Cognito } = amplifyConfig.Auth;\n tokenValidator = createTokenValidator({\n userPoolId: Cognito?.userPoolId,\n userPoolClientId: Cognito?.userPoolClientId,\n });\n }\n const runWithAmplifyServerContext = createRunWithAmplifyServerContext({\n config: amplifyConfig,\n tokenValidator,\n globalSettings,\n });\n return {\n runWithAmplifyServerContext,\n createAuthRouteHandlers: createAuthRouteHandlersFactory({\n config: amplifyConfig,\n amplifyAppOrigin,\n globalSettings,\n runWithAmplifyServerContext,\n }),\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,kBAAkB,GAAG,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,KAAK;AACnE,IAAI,MAAM,aAAa,GAAG,kBAAkB,CAAC,MAAM,CAAC;AACpD,IAAI,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB;AAC3D,IAAI,cAAc,CAAC,iBAAiB,CAAC,cAAc,IAAI,EAAE,CAAC;AAC1D,IAAI,IAAI,aAAa,CAAC,gBAAgB,CAAC,EAAE;AACzC,QAAQ,cAAc,CAAC,cAAc,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;AACpE;AACA,QAAQ,cAAc,CAAC,oBAAoB,EAAE;AAC7C,IAAI;AACJ,IAAI,IAAI,cAAc;AACtB,IAAI,IAAI,aAAa,EAAE,IAAI,EAAE;AAC7B,QAAQ,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC,IAAI;AAC9C,QAAQ,cAAc,GAAG,oBAAoB,CAAC;AAC9C,YAAY,UAAU,EAAE,OAAO,EAAE,UAAU;AAC3C,YAAY,gBAAgB,EAAE,OAAO,EAAE,gBAAgB;AACvD,SAAS,CAAC;AACV,IAAI;AACJ,IAAI,MAAM,2BAA2B,GAAG,iCAAiC,CAAC;AAC1E,QAAQ,MAAM,EAAE,aAAa;AAC7B,QAAQ,cAAc;AACtB,QAAQ,cAAc;AACtB,KAAK,CAAC;AACN,IAAI,OAAO;AACX,QAAQ,2BAA2B;AACnC,QAAQ,uBAAuB,EAAE,8BAA8B,CAAC;AAChE,YAAY,MAAM,EAAE,aAAa;AACjC,YAAY,gBAAgB;AAC5B,YAAY,cAAc;AAC1B,YAAY,2BAA2B;AACvC,SAAS,CAAC;AACV,KAAK;AACL;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"serializeCookie.mjs","sources":["../../../../src/utils/cookie/serializeCookie.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const serializeCookie = (name, value, options) => `${name}=${value};${options ? serializeSetCookieOptions(options) : ''}`;\nconst serializeSetCookieOptions = (options) => {\n const { expires, domain, httpOnly, sameSite, secure, path, maxAge } = options;\n const serializedOptions = [];\n if (domain) {\n serializedOptions.push(`Domain=${domain}`);\n }\n if (expires) {\n serializedOptions.push(`Expires=${expires.toUTCString()}`);\n }\n if (httpOnly) {\n serializedOptions.push(`HttpOnly`);\n }\n if (sameSite) {\n serializedOptions.push(`SameSite=${sameSite}`);\n }\n if (secure) {\n serializedOptions.push(`Secure`);\n }\n if (path) {\n serializedOptions.push(`Path=${path}`);\n }\n if (maxAge) {\n serializedOptions.push(`Max-Age=${maxAge}`);\n }\n return serializedOptions.join(';');\n};\n"],"names":[],"mappings":"AAAA;AACA;AACY,MAAC,eAAe,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;AAC/H,MAAM,yBAAyB,GAAG,CAAC,OAAO,KAAK;AAC/C,IAAI,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO;AACjF,IAAI,MAAM,iBAAiB,GAAG,EAAE;AAChC,IAAI,IAAI,MAAM,EAAE;AAChB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AAClD;AACA,IAAI,IAAI,OAAO,EAAE;AACjB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;AAClE;AACA,IAAI,IAAI,QAAQ,EAAE;AAClB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC1C;AACA,IAAI,IAAI,QAAQ,EAAE;AAClB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AACtD;AACA,IAAI,IAAI,MAAM,EAAE;AAChB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;AACxC;AACA,IAAI,IAAI,IAAI,EAAE;AACd,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAC9C;AACA,IAAI,IAAI,MAAM,EAAE;AAChB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AACnD;AACA,IAAI,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC;AACtC,CAAC;;;;"}
1
+ {"version":3,"file":"serializeCookie.mjs","sources":["../../../../src/utils/cookie/serializeCookie.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const serializeCookie = (name, value, options) => `${name}=${value};${options ? serializeSetCookieOptions(options) : ''}`;\nconst serializeSetCookieOptions = (options) => {\n const { expires, domain, httpOnly, sameSite, secure, path, maxAge } = options;\n const serializedOptions = [];\n if (domain) {\n serializedOptions.push(`Domain=${domain}`);\n }\n if (expires) {\n serializedOptions.push(`Expires=${expires.toUTCString()}`);\n }\n if (httpOnly) {\n serializedOptions.push(`HttpOnly`);\n }\n if (sameSite) {\n serializedOptions.push(`SameSite=${sameSite}`);\n }\n if (secure) {\n serializedOptions.push(`Secure`);\n }\n if (path) {\n serializedOptions.push(`Path=${path}`);\n }\n if (maxAge) {\n serializedOptions.push(`Max-Age=${maxAge}`);\n }\n return serializedOptions.join(';');\n};\n"],"names":[],"mappings":"AAAA;AACA;AACY,MAAC,eAAe,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;AAC/H,MAAM,yBAAyB,GAAG,CAAC,OAAO,KAAK;AAC/C,IAAI,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO;AACjF,IAAI,MAAM,iBAAiB,GAAG,EAAE;AAChC,IAAI,IAAI,MAAM,EAAE;AAChB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AAClD,IAAI;AACJ,IAAI,IAAI,OAAO,EAAE;AACjB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;AAClE,IAAI;AACJ,IAAI,IAAI,QAAQ,EAAE;AAClB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC1C,IAAI;AACJ,IAAI,IAAI,QAAQ,EAAE;AAClB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AACtD,IAAI;AACJ,IAAI,IAAI,MAAM,EAAE;AAChB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;AACxC,IAAI;AACJ,IAAI,IAAI,IAAI,EAAE;AACd,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAC9C,IAAI;AACJ,IAAI,IAAI,MAAM,EAAE;AAChB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AACnD,IAAI;AACJ,IAAI,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC;AACtC,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"createCookieStorageAdapterFromNextServerContext.mjs","sources":["../../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { NextResponse } from 'next/server.js';\nimport { AmplifyServerContextError, } from 'aws-amplify/adapter-core/internals';\nimport { isServerSideAuthAllowedCookie } from '../auth/utils';\nimport { ensureEncodedForJSCookie, serializeCookie } from './cookie';\nexport const DATE_IN_THE_PAST = new Date(0);\nexport const createCookieStorageAdapterFromNextServerContext = async (context, ignoreNonServerSideCookies = false) => {\n const { request: req, response: res } = context;\n // When the server context is from `getServerSideProps`, the `req` is an instance\n // of IncomingMessage, and the `res` is an instance of ServerResponse.\n // We cannot import these two classes here from `http` as it breaks in Next\n // Edge Runtime. Hence, we check the methods that we need to use for creating\n // cookie adapter.\n if (req &&\n res &&\n Object.prototype.toString.call(req.cookies) === '[object Object]' &&\n typeof res.setHeader === 'function') {\n return createCookieStorageAdapterFromGetServerSidePropsContext(req, res, ignoreNonServerSideCookies);\n }\n const { request, response } = context;\n // When the server context is from `middleware`, the `request` is an instance\n // of `NextRequest`.\n // When the server context is from a route handler, the `request` is an `Proxy`\n // wrapped `Request`.\n // The `NextRequest` and the `Proxy` are sharing the same interface by Next\n // implementation. So we don't need to detect the difference.\n if (request && response) {\n if (response instanceof NextResponse) {\n return createCookieStorageAdapterFromNextRequestAndNextResponse(request, response, ignoreNonServerSideCookies);\n }\n else {\n return createCookieStorageAdapterFromNextRequestAndHttpResponse(request, response, ignoreNonServerSideCookies);\n }\n }\n const { cookies } = context;\n if (typeof cookies === 'function') {\n return createCookieStorageAdapterFromNextCookies(cookies, ignoreNonServerSideCookies);\n }\n // This should not happen normally.\n throw new AmplifyServerContextError({\n message: 'Attempted to create cookie storage adapter from an unsupported Next.js server context.',\n });\n};\nconst createCookieStorageAdapterFromNextRequestAndNextResponse = (request, response, ignoreNonServerSideCookies) => {\n const readonlyCookieStore = request.cookies;\n const mutableCookieStore = response.cookies;\n return {\n get(name) {\n return readonlyCookieStore.get(ensureEncodedForJSCookie(name));\n },\n getAll: readonlyCookieStore.getAll.bind(readonlyCookieStore),\n set(name, value, options) {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n mutableCookieStore.set(ensureEncodedForJSCookie(name), value, options);\n },\n delete(name) {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n mutableCookieStore.delete(ensureEncodedForJSCookie(name));\n },\n };\n};\nconst createCookieStorageAdapterFromNextRequestAndHttpResponse = (request, response, ignoreNonServerSideCookies) => {\n const readonlyCookieStore = request.cookies;\n const mutableCookieStore = createMutableCookieStoreFromHeaders(response.headers, ignoreNonServerSideCookies);\n return {\n get(name) {\n return readonlyCookieStore.get(ensureEncodedForJSCookie(name));\n },\n getAll: readonlyCookieStore.getAll.bind(readonlyCookieStore),\n ...mutableCookieStore,\n };\n};\nconst createCookieStorageAdapterFromNextCookies = async (cookies, ignoreNonServerSideCookies) => {\n const cookieStore = await cookies();\n // When Next cookies() is called in a server component, it returns a readonly\n // cookie store. Hence calling set and delete throws an error. However,\n // cookies() returns a mutable cookie store when called in a server action.\n // We have no way to detect which one is returned, so we try to call set and delete\n // and safely ignore the error if it is thrown.\n const setFunc = (name, value, options) => {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n try {\n cookieStore.set(ensureEncodedForJSCookie(name), value, options);\n }\n catch {\n // no-op\n }\n };\n const deleteFunc = name => {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n try {\n cookieStore.delete(ensureEncodedForJSCookie(name));\n }\n catch {\n // no-op\n }\n };\n return {\n get(name) {\n return cookieStore.get(ensureEncodedForJSCookie(name));\n },\n getAll: cookieStore.getAll.bind(cookieStore),\n set: setFunc,\n delete: deleteFunc,\n };\n};\nconst createCookieStorageAdapterFromGetServerSidePropsContext = (request, response, ignoreNonServerSideCookies) => {\n const cookiesMap = { ...request.cookies };\n const allCookies = Object.entries(cookiesMap).map(([name, value]) => ({\n name,\n value,\n }));\n return {\n get(name) {\n const value = cookiesMap[ensureEncodedForJSCookie(name)];\n return value\n ? {\n name,\n value,\n }\n : undefined;\n },\n getAll() {\n return allCookies;\n },\n set(name, value, options) {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n const encodedName = ensureEncodedForJSCookie(name);\n const existingValues = getExistingSetCookieValues(response.getHeader('Set-Cookie'));\n // if the cookies have already been set, we don't need to set them again.\n if (existingValues.findIndex(cookieValue => cookieValue.startsWith(`${encodedName}=`) &&\n !cookieValue.startsWith(`${encodedName}=;`)) > -1) {\n return;\n }\n response.appendHeader('Set-Cookie', serializeCookie(encodedName, value, options));\n },\n delete(name) {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n const encodedName = ensureEncodedForJSCookie(name);\n const setCookieValue = `${encodedName}=;Expires=${DATE_IN_THE_PAST.toUTCString()}`;\n const existingValues = getExistingSetCookieValues(response.getHeader('Set-Cookie'));\n // if the value for cookie deletion is already in the Set-Cookie header, we\n // don't need to add the deletion value again.\n if (existingValues.includes(setCookieValue)) {\n return;\n }\n response.appendHeader('Set-Cookie', setCookieValue);\n },\n };\n};\nconst createMutableCookieStoreFromHeaders = (headers, ignoreNonServerSideCookies) => {\n const setFunc = (name, value, options) => {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n headers.append('Set-Cookie', serializeCookie(ensureEncodedForJSCookie(name), value, options));\n };\n const deleteFunc = name => {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n headers.append('Set-Cookie', `${ensureEncodedForJSCookie(name)}=;Expires=${DATE_IN_THE_PAST.toUTCString()}`);\n };\n return {\n set: setFunc,\n delete: deleteFunc,\n };\n};\nconst getExistingSetCookieValues = (values) => values === undefined ? [] : Array.isArray(values) ? values : [String(values)];\nconst shouldIgnoreCookie = (ignoreNonServerSideCookies, cookieName) => ignoreNonServerSideCookies && !isServerSideAuthAllowedCookie(cookieName);\n"],"names":[],"mappings":";;;;;;;;AAAA;AACA;AAKY,MAAC,gBAAgB,GAAG,IAAI,IAAI,CAAC,CAAC;AAC9B,MAAC,+CAA+C,GAAG,OAAO,OAAO,EAAE,0BAA0B,GAAG,KAAK,KAAK;AACtH,IAAI,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,OAAO;AACnD;AACA;AACA;AACA;AACA;AACA,IAAI,IAAI,GAAG;AACX,QAAQ,GAAG;AACX,QAAQ,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,iBAAiB;AACzE,QAAQ,OAAO,GAAG,CAAC,SAAS,KAAK,UAAU,EAAE;AAC7C,QAAQ,OAAO,uDAAuD,CAAC,GAAG,EAAE,GAAG,EAAE,0BAA0B,CAAC;AAC5G;AACA,IAAI,MA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OAAO,KAAK;AAC9C,QAAQ,IAAI,kBAAkB,CAAC,0BAA0B,EAAE,IAAI,CAAC,EAAE;AAClE,YAAY;AACZ;AACA,QAAQ,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,wBAAwB,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACrG,KAAK;AACL,IAAI,MAAM,UAAU,GAAG,IAAI,IAAI;AAC/B,QAAQ,IAAI,kBAAkB,CAAC,0BAA0B,EAAE,IAAI,CAAC,EAAE;AAClE,YAAY;AACZ;AACA,QAAQ,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,EAAE,wBAAwB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,gBAAgB,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;AACpH,KAAK;AACL,IAAI,OAAO;AACX,QAAQ,GAAG,EAAE,OAAO;AACpB,QAAQ,MAAM,EAAE,UAAU;AAC1B,KAAK;AACL,CAAC;AACD,MAAM,0BAA0B,GAAG,CAAC,MAAM,KAAK,MAAM,KAAK,SAAS,GAAG,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC5H,MAAM,kBAAkB,GAAG,CAAC,0BAA0B,EAAE,UAAU,KAAK,0BAA0B,IAAI,CAAC,6BAA6B,CAAC,UAAU,CAAC;;;;"}
1
+ {"version":3,"file":"createCookieStorageAdapterFromNextServerContext.mjs","sources":["../../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { NextResponse } from 'next/server.js';\nimport { AmplifyServerContextError, } from 'aws-amplify/adapter-core/internals';\nimport { isServerSideAuthAllowedCookie } from '../auth/utils';\nimport { ensureEncodedForJSCookie, serializeCookie } from './cookie';\nexport const DATE_IN_THE_PAST = new Date(0);\nexport const createCookieStorageAdapterFromNextServerContext = async (context, ignoreNonServerSideCookies = false) => {\n const { request: req, response: res } = context;\n // When the server context is from `getServerSideProps`, the `req` is an instance\n // of IncomingMessage, and the `res` is an instance of ServerResponse.\n // We cannot import these two classes here from `http` as it breaks in Next\n // Edge Runtime. Hence, we check the methods that we need to use for creating\n // cookie adapter.\n if (req &&\n res &&\n Object.prototype.toString.call(req.cookies) === '[object Object]' &&\n typeof res.setHeader === 'function') {\n return createCookieStorageAdapterFromGetServerSidePropsContext(req, res, ignoreNonServerSideCookies);\n }\n const { request, response } = context;\n // When the server context is from `middleware`, the `request` is an instance\n // of `NextRequest`.\n // When the server context is from a route handler, the `request` is an `Proxy`\n // wrapped `Request`.\n // The `NextRequest` and the `Proxy` are sharing the same interface by Next\n // implementation. So we don't need to detect the difference.\n if (request && response) {\n if (response instanceof NextResponse) {\n return createCookieStorageAdapterFromNextRequestAndNextResponse(request, response, ignoreNonServerSideCookies);\n }\n else {\n return createCookieStorageAdapterFromNextRequestAndHttpResponse(request, response, ignoreNonServerSideCookies);\n }\n }\n const { cookies } = context;\n if (typeof cookies === 'function') {\n return createCookieStorageAdapterFromNextCookies(cookies, ignoreNonServerSideCookies);\n }\n // This should not happen normally.\n throw new AmplifyServerContextError({\n message: 'Attempted to create cookie storage adapter from an unsupported Next.js server context.',\n });\n};\nconst createCookieStorageAdapterFromNextRequestAndNextResponse = (request, response, ignoreNonServerSideCookies) => {\n const readonlyCookieStore = request.cookies;\n const mutableCookieStore = response.cookies;\n return {\n get(name) {\n return readonlyCookieStore.get(ensureEncodedForJSCookie(name));\n },\n getAll: readonlyCookieStore.getAll.bind(readonlyCookieStore),\n set(name, value, options) {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n mutableCookieStore.set(ensureEncodedForJSCookie(name), value, options);\n },\n delete(name) {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n mutableCookieStore.delete(ensureEncodedForJSCookie(name));\n },\n };\n};\nconst createCookieStorageAdapterFromNextRequestAndHttpResponse = (request, response, ignoreNonServerSideCookies) => {\n const readonlyCookieStore = request.cookies;\n const mutableCookieStore = createMutableCookieStoreFromHeaders(response.headers, ignoreNonServerSideCookies);\n return {\n get(name) {\n return readonlyCookieStore.get(ensureEncodedForJSCookie(name));\n },\n getAll: readonlyCookieStore.getAll.bind(readonlyCookieStore),\n ...mutableCookieStore,\n };\n};\nconst createCookieStorageAdapterFromNextCookies = async (cookies, ignoreNonServerSideCookies) => {\n const cookieStore = await cookies();\n // When Next cookies() is called in a server component, it returns a readonly\n // cookie store. Hence calling set and delete throws an error. However,\n // cookies() returns a mutable cookie store when called in a server action.\n // We have no way to detect which one is returned, so we try to call set and delete\n // and safely ignore the error if it is thrown.\n const setFunc = (name, value, options) => {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n try {\n cookieStore.set(ensureEncodedForJSCookie(name), value, options);\n }\n catch {\n // no-op\n }\n };\n const deleteFunc = name => {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n try {\n cookieStore.delete(ensureEncodedForJSCookie(name));\n }\n catch {\n // no-op\n }\n };\n return {\n get(name) {\n return cookieStore.get(ensureEncodedForJSCookie(name));\n },\n getAll: cookieStore.getAll.bind(cookieStore),\n set: setFunc,\n delete: deleteFunc,\n };\n};\nconst createCookieStorageAdapterFromGetServerSidePropsContext = (request, response, ignoreNonServerSideCookies) => {\n const cookiesMap = { ...request.cookies };\n const allCookies = Object.entries(cookiesMap).map(([name, value]) => ({\n name,\n value,\n }));\n return {\n get(name) {\n const value = cookiesMap[ensureEncodedForJSCookie(name)];\n return value\n ? {\n name,\n value,\n }\n : undefined;\n },\n getAll() {\n return allCookies;\n },\n set(name, value, options) {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n const encodedName = ensureEncodedForJSCookie(name);\n const existingValues = getExistingSetCookieValues(response.getHeader('Set-Cookie'));\n // if the cookies have already been set, we don't need to set them again.\n if (existingValues.findIndex(cookieValue => cookieValue.startsWith(`${encodedName}=`) &&\n !cookieValue.startsWith(`${encodedName}=;`)) > -1) {\n return;\n }\n response.appendHeader('Set-Cookie', serializeCookie(encodedName, value, options));\n },\n delete(name) {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n const encodedName = ensureEncodedForJSCookie(name);\n const setCookieValue = `${encodedName}=;Expires=${DATE_IN_THE_PAST.toUTCString()}`;\n const existingValues = getExistingSetCookieValues(response.getHeader('Set-Cookie'));\n // if the value for cookie deletion is already in the Set-Cookie header, we\n // don't need to add the deletion value again.\n if (existingValues.includes(setCookieValue)) {\n return;\n }\n response.appendHeader('Set-Cookie', setCookieValue);\n },\n };\n};\nconst createMutableCookieStoreFromHeaders = (headers, ignoreNonServerSideCookies) => {\n const setFunc = (name, value, options) => {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n headers.append('Set-Cookie', serializeCookie(ensureEncodedForJSCookie(name), value, options));\n };\n const deleteFunc = name => {\n if (shouldIgnoreCookie(ignoreNonServerSideCookies, name)) {\n return;\n }\n headers.append('Set-Cookie', `${ensureEncodedForJSCookie(name)}=;Expires=${DATE_IN_THE_PAST.toUTCString()}`);\n };\n return {\n set: setFunc,\n delete: deleteFunc,\n };\n};\nconst getExistingSetCookieValues = (values) => values === undefined ? [] : Array.isArray(values) ? values : [String(values)];\nconst shouldIgnoreCookie = (ignoreNonServerSideCookies, cookieName) => ignoreNonServerSideCookies && !isServerSideAuthAllowedCookie(cookieName);\n"],"names":[],"mappings":";;;;;;;;AAAA;AACA;AAKY,MAAC,gBAAgB,GAAG,IAAI,IAAI,CAAC,CAAC;AAC9B,MAAC,+CAA+C,GAAG,OAAO,OAAO,EAAE,0BAA0B,GAAG,KAAK,KAAK;AACtH,IAAI,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG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GAAG,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC5H,MAAM,kBAAkB,GAAG,CAAC,0BAA0B,EAAE,UAAU,KAAK,0BAA0B,IAAI,CAAC,6BAA6B,CAAC,UAAU,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"createRunWithAmplifyServerContext.mjs","sources":["../../../src/utils/createRunWithAmplifyServerContext.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { sharedInMemoryStorage } from 'aws-amplify/utils';\nimport { createAWSCredentialsAndIdentityIdProvider, createKeyValueStorageFromCookieStorageAdapter, createUserPoolsTokenProvider, runWithAmplifyServerContext as runWithAmplifyServerContextCore, } from 'aws-amplify/adapter-core';\nimport { DEFAULT_SERVER_SIDE_AUTH_SET_COOKIE_OPTIONS, ENFORCED_SERVER_SIDE_AUTH_SET_COOKIE_OPTIONS, } from '../auth/constant';\nimport { createCookieStorageAdapterFromNextServerContext } from './createCookieStorageAdapterFromNextServerContext';\nexport const createRunWithAmplifyServerContext = ({ config: resourcesConfig, tokenValidator, globalSettings, }) => {\n const isServerSideAuthEnabled = globalSettings.isServerSideAuthEnabled();\n const isSSLOrigin = globalSettings.isSSLOrigin();\n const setCookieOptions = globalSettings.getRuntimeOptions().cookies ?? {};\n const mergedSetCookieOptions = {\n // default options when not specified\n ...(isServerSideAuthEnabled && DEFAULT_SERVER_SIDE_AUTH_SET_COOKIE_OPTIONS),\n // user-specified options\n ...setCookieOptions,\n // enforced options when server-side auth is enabled\n ...(isServerSideAuthEnabled && {\n ...ENFORCED_SERVER_SIDE_AUTH_SET_COOKIE_OPTIONS,\n secure: isSSLOrigin,\n }),\n // only support root path\n path: '/',\n };\n const runWithAmplifyServerContext = async ({ nextServerContext, operation }) => {\n // When the Auth config is presented, attempt to create a Amplify server\n // context with token and credentials provider.\n if (resourcesConfig.Auth) {\n const keyValueStorage = \n // When `null` is passed as the value of `nextServerContext`, opt-in\n // unauthenticated role (primarily for static rendering). It's\n // safe to use the singleton `MemoryKeyValueStorage` here, as the\n // static rendering uses the same unauthenticated role cross-sever.\n nextServerContext === null\n ? sharedInMemoryStorage\n : createKeyValueStorageFromCookieStorageAdapter(await createCookieStorageAdapterFromNextServerContext(nextServerContext, isServerSideAuthEnabled), tokenValidator, mergedSetCookieOptions);\n const credentialsProvider = createAWSCredentialsAndIdentityIdProvider(resourcesConfig.Auth, keyValueStorage);\n const tokenProvider = createUserPoolsTokenProvider(resourcesConfig.Auth, keyValueStorage);\n return runWithAmplifyServerContextCore(resourcesConfig, {\n Auth: { credentialsProvider, tokenProvider },\n }, operation);\n }\n // Otherwise it may be the case that auth is not used, e.g. API key.\n // Omitting the `Auth` in the second parameter.\n return runWithAmplifyServerContextCore(resourcesConfig, {}, operation);\n };\n return runWithAmplifyServerContext;\n};\n"],"names":["runWithAmplifyServerContext","runWithAmplifyServerContextCore"],"mappings":";;;;;AAAA;AACA;AAKY,MAAC,iCAAiC,GAAG,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,GAAG,KAAK;AACnH,IAAI,MAAM,uBAAuB,GAAG,cAAc,CAAC,uBAAuB,EAAE;AAC5E,IAAI,MAAM,WAAW,GAAG,cAAc,CAAC,WAAW,EAAE;AACpD,IAAI,MAAM,gBAAgB,GAAG,cAAc,CAAC,iBAAiB,EAAE,CAAC,OAAO,IAAI,EAAE;AAC7E,IAAI,MAAM,sBAAsB,GAAG;AACnC;AACA,QAAQ,IAAI,uBAAuB,IAAI,2CAA2C,CAAC;AACnF;AACA,QAAQ,GAAG,gBAAgB;AAC3B;AACA,QAAQ,IAAI,uBAAuB,IAAI;AACvC,YAAY,GAAG,4CAA4C;AAC3D,YAAY,MAAM,EAAE,WAAW;AAC/B,SAAS,CAAC;AACV;AACA,QAAQ,IAAI,EAAE,GAAG;AACjB,KAAK;AACL,IAAI,MAAMA,6BAA2B,GAAG,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,KAAK;AACpF;AACA;AACA,QAAQ,IAAI,eAAe,CAAC,IAAI,EAAE;AAClC,YAAY,MAAM,eAAe;AACjC;AACA;AACA;AACA;AACA,YAAY,iBAAiB,KAAK;AAClC,kBAAkB;AAClB,kBAAkB,6CAA6C,CAAC,MAAM,+CAA+C,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,EAAE,cAAc,EAAE,sBAAsB,CAAC;AAC1M,YAAY,MAAM,mBAAmB,GAAG,yCAAyC,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC;AACxH,YAAY,MAAM,aAAa,GAAG,4BAA4B,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC;AACrG,YAAY,OAAOC,2BAA+B,CAAC,eAAe,EAAE;AACpE,gBAAgB,IAAI,EAAE,EAAE,mBAAmB,EAAE,aAAa,EAAE;AAC5D,aAAa,EAAE,SAAS,CAAC;AACzB;AACA;AACA;AACA,QAAQ,OAAOA,2BAA+B,CAAC,eAAe,EAAE,EAAE,EAAE,SAAS,CAAC;AAC9E,KAAK;AACL,IAAI,OAAOD,6BAA2B;AACtC;;;;"}
1
+ {"version":3,"file":"createRunWithAmplifyServerContext.mjs","sources":["../../../src/utils/createRunWithAmplifyServerContext.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { sharedInMemoryStorage } from 'aws-amplify/utils';\nimport { createAWSCredentialsAndIdentityIdProvider, createKeyValueStorageFromCookieStorageAdapter, createUserPoolsTokenProvider, runWithAmplifyServerContext as runWithAmplifyServerContextCore, } from 'aws-amplify/adapter-core';\nimport { DEFAULT_SERVER_SIDE_AUTH_SET_COOKIE_OPTIONS, ENFORCED_SERVER_SIDE_AUTH_SET_COOKIE_OPTIONS, } from '../auth/constant';\nimport { createCookieStorageAdapterFromNextServerContext } from './createCookieStorageAdapterFromNextServerContext';\nexport const createRunWithAmplifyServerContext = ({ config: resourcesConfig, tokenValidator, globalSettings, }) => {\n const isServerSideAuthEnabled = globalSettings.isServerSideAuthEnabled();\n const isSSLOrigin = globalSettings.isSSLOrigin();\n const setCookieOptions = globalSettings.getRuntimeOptions().cookies ?? {};\n const mergedSetCookieOptions = {\n // default options when not specified\n ...(isServerSideAuthEnabled && DEFAULT_SERVER_SIDE_AUTH_SET_COOKIE_OPTIONS),\n // user-specified options\n ...setCookieOptions,\n // enforced options when server-side auth is enabled\n ...(isServerSideAuthEnabled && {\n ...ENFORCED_SERVER_SIDE_AUTH_SET_COOKIE_OPTIONS,\n secure: isSSLOrigin,\n }),\n // only support root path\n path: '/',\n };\n const runWithAmplifyServerContext = async ({ nextServerContext, operation }) => {\n // When the Auth config is presented, attempt to create a Amplify server\n // context with token and credentials provider.\n if (resourcesConfig.Auth) {\n const keyValueStorage = \n // When `null` is passed as the value of `nextServerContext`, opt-in\n // unauthenticated role (primarily for static rendering). It's\n // safe to use the singleton `MemoryKeyValueStorage` here, as the\n // static rendering uses the same unauthenticated role cross-sever.\n nextServerContext === null\n ? sharedInMemoryStorage\n : createKeyValueStorageFromCookieStorageAdapter(await createCookieStorageAdapterFromNextServerContext(nextServerContext, isServerSideAuthEnabled), tokenValidator, mergedSetCookieOptions);\n const credentialsProvider = createAWSCredentialsAndIdentityIdProvider(resourcesConfig.Auth, keyValueStorage);\n const tokenProvider = createUserPoolsTokenProvider(resourcesConfig.Auth, keyValueStorage);\n return runWithAmplifyServerContextCore(resourcesConfig, {\n Auth: { credentialsProvider, tokenProvider },\n }, operation);\n }\n // Otherwise it may be the case that auth is not used, e.g. API key.\n // Omitting the `Auth` in the second parameter.\n return runWithAmplifyServerContextCore(resourcesConfig, {}, operation);\n };\n return runWithAmplifyServerContext;\n};\n"],"names":["runWithAmplifyServerContext","runWithAmplifyServerContextCore"],"mappings":";;;;;AAAA;AACA;AAKY,MAAC,iCAAiC,GA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eAAe,EAAE,EAAE,EAAE,SAAS,CAAC;AAC9E,IAAI,CAAC;AACL,IAAI,OAAOD,6BAA2B;AACtC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"createTokenValidator.mjs","sources":["../../../src/utils/createTokenValidator.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { CognitoJwtVerifier } from 'aws-jwt-verify';\nimport { isValidCognitoToken } from './isValidCognitoToken';\n/**\n * Creates a validator object for validating methods in a KeyValueStorage.\n */\nexport const createTokenValidator = ({ userPoolId, userPoolClientId: clientId, }) => {\n let idTokenVerifier;\n let accessTokenVerifier;\n return {\n // validate access, id tokens\n getItem: async (key, value) => {\n const isAccessToken = key.includes('.accessToken');\n const isIdToken = key.includes('.idToken');\n if (!isAccessToken && !isIdToken) {\n return true;\n }\n if (!userPoolId || !clientId) {\n return false;\n }\n if (isAccessToken && !accessTokenVerifier) {\n accessTokenVerifier = CognitoJwtVerifier.create({\n userPoolId,\n tokenUse: 'access',\n clientId,\n });\n }\n if (isIdToken && !idTokenVerifier) {\n idTokenVerifier = CognitoJwtVerifier.create({\n userPoolId,\n tokenUse: 'id',\n clientId,\n });\n }\n return isValidCognitoToken({\n token: value,\n verifier: isAccessToken ? accessTokenVerifier : idTokenVerifier,\n });\n },\n };\n};\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACY,MAAC,oBAAoB,GAAG,CAAC,EAAE,UAAU,EAAE,gBAAgB,EAAE,QAAQ,GAAG,KAAK;AACrF,IAAI,IAAI,eAAe;AACvB,IAAI,IAAI,mBAAmB;AAC3B,IAAI,OAAO;AACX;AACA,QAAQ,OAAO,EAAE,OAAO,GAAG,EAAE,KAAK,KAAK;AACvC,YAAY,MAAM,aAAa,GAAG,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC;AAC9D,YAAY,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC;AACtD,YAAY,IAAI,CAAC,aAAa,IAAI,CAAC,SAAS,EAAE;AAC9C,gBAAgB,OAAO,IAAI;AAC3B;AACA,YAAY,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,EAAE;AAC1C,gBAAgB,OAAO,KAAK;AAC5B;AACA,YAAY,IAAI,aAAa,IAAI,CAAC,mBAAmB,EAAE;AACvD,gBAAgB,mBAAmB,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAChE,oBAAoB,UAAU;AAC9B,oBAAoB,QAAQ,EAAE,QAAQ;AACtC,oBAAoB,QAAQ;AAC5B,iBAAiB,CAAC;AAClB;AACA,YAAY,IAAI,SAAS,IAAI,CAAC,eAAe,EAAE;AAC/C,gBAAgB,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC5D,oBAAoB,UAAU;AAC9B,oBAAoB,QAAQ,EAAE,IAAI;AAClC,oBAAoB,QAAQ;AAC5B,iBAAiB,CAAC;AAClB;AACA,YAAY,OAAO,mBAAmB,CAAC;AACvC,gBAAgB,KAAK,EAAE,KAAK;AAC5B,gBAAgB,QAAQ,EAAE,aAAa,GAAG,mBAAmB,GAAG,eAAe;AAC/E,aAAa,CAAC;AACd,SAAS;AACT,KAAK;AACL;;;;"}
1
+ {"version":3,"file":"createTokenValidator.mjs","sources":["../../../src/utils/createTokenValidator.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { CognitoJwtVerifier } from 'aws-jwt-verify';\nimport { isValidCognitoToken } from './isValidCognitoToken';\n/**\n * Creates a validator object for validating methods in a KeyValueStorage.\n */\nexport const createTokenValidator = ({ userPoolId, userPoolClientId: clientId, }) => {\n let idTokenVerifier;\n let accessTokenVerifier;\n return {\n // validate access, id tokens\n getItem: async (key, value) => {\n const isAccessToken = key.includes('.accessToken');\n const isIdToken = key.includes('.idToken');\n if (!isAccessToken && !isIdToken) {\n return true;\n }\n if (!userPoolId || !clientId) {\n return false;\n }\n if (isAccessToken && !accessTokenVerifier) {\n accessTokenVerifier = CognitoJwtVerifier.create({\n userPoolId,\n tokenUse: 'access',\n clientId,\n });\n }\n if (isIdToken && !idTokenVerifier) {\n idTokenVerifier = CognitoJwtVerifier.create({\n userPoolId,\n tokenUse: 'id',\n clientId,\n });\n }\n return isValidCognitoToken({\n token: value,\n verifier: isAccessToken ? accessTokenVerifier : idTokenVerifier,\n });\n },\n };\n};\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACY,MAAC,oBAAoB,GAAG,CAAC,EAAE,UAAU,EAAE,gBAAgB,EAAE,QAAQ,GAAG,KAAK;AACrF,IAAI,IAAI,eAAe;AACvB,IAAI,IAAI,mBAAmB;AAC3B,IAAI,OAAO;AACX;AACA,QAAQ,OAAO,EAAE,OAAO,GAAG,EAAE,KAAK,KAAK;AACvC,YAAY,MAAM,aAAa,GAAG,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC;AAC9D,YAAY,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC;AACtD,YAAY,IAAI,CAAC,aAAa,IAAI,CAAC,SAAS,EAAE;AAC9C,gBAAgB,OAAO,IAAI;AAC3B,YAAY;AACZ,YAAY,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,EAAE;AAC1C,gBAAgB,OAAO,KAAK;AAC5B,YAAY;AACZ,YAAY,IAAI,aAAa,IAAI,CAAC,mBAAmB,EAAE;AACvD,gBAAgB,mBAAmB,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAChE,oBAAoB,UAAU;AAC9B,oBAAoB,QAAQ,EAAE,QAAQ;AACtC,oBAAoB,QAAQ;AAC5B,iBAAiB,CAAC;AAClB,YAAY;AACZ,YAAY,IAAI,SAAS,IAAI,CAAC,eAAe,EAAE;AAC/C,gBAAgB,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC5D,oBAAoB,UAAU;AAC9B,oBAAoB,QAAQ,EAAE,IAAI;AAClC,oBAAoB,QAAQ;AAC5B,iBAAiB,CAAC;AAClB,YAAY;AACZ,YAAY,OAAO,mBAAmB,CAAC;AACvC,gBAAgB,KAAK,EAAE,KAAK;AAC5B,gBAAgB,QAAQ,EAAE,aAAa,GAAG,mBAAmB,GAAG,eAAe;AAC/E,aAAa,CAAC;AACd,QAAQ,CAAC;AACT,KAAK;AACL;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"globalSettings.mjs","sources":["../../../src/utils/globalSettings.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nlet isServerSideAuthEnabled = false;\nlet runtimeOptions = {};\nlet isSSLOrigin = false;\nexport const globalSettings = {\n enableServerSideAuth() {\n isServerSideAuthEnabled = true;\n },\n isServerSideAuthEnabled() {\n return isServerSideAuthEnabled;\n },\n setRuntimeOptions(options) {\n // make a copy instead of set the reference\n runtimeOptions = structuredClone(options);\n },\n getRuntimeOptions() {\n return runtimeOptions;\n },\n setIsSSLOrigin(value) {\n isSSLOrigin = value;\n },\n isSSLOrigin() {\n return isSSLOrigin;\n },\n};\n"],"names":[],"mappings":"AAAA;AACA;AACA,IAAI,uBAAuB,GAAG,KAAK;AACnC,IAAI,cAAc,GAAG,EAAE;AACvB,IAAI,WAAW,GAAG,KAAK;AACX,MAAC,cAAc,GAAG;AAC9B,IAAI,oBAAoB,GAAG;AAC3B,QAAQ,uBAAuB,GAAG,IAAI;AACtC,KAAK;AACL,IAAI,uBAAuB,GAAG;AAC9B,QAAQ,OAAO,uBAAuB;AACtC,KAAK;AACL,IAAI,iBAAiB,CAAC,OAAO,EAAE;AAC/B;AACA,QAAQ,cAAc,GAAG,eAAe,CAAC,OAAO,CAAC;AACjD,KAAK;AACL,IAAI,iBAAiB,GAAG;AACxB,QAAQ,OAAO,cAAc;AAC7B,KAAK;AACL,IAAI,cAAc,CAAC,KAAK,EAAE;AAC1B,QAAQ,WAAW,GAAG,KAAK;AAC3B,KAAK;AACL,IAAI,WAAW,GAAG;AAClB,QAAQ,OAAO,WAAW;AAC1B,KAAK;AACL;;;;"}
1
+ {"version":3,"file":"globalSettings.mjs","sources":["../../../src/utils/globalSettings.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nlet isServerSideAuthEnabled = false;\nlet runtimeOptions = {};\nlet isSSLOrigin = false;\nexport const globalSettings = {\n enableServerSideAuth() {\n isServerSideAuthEnabled = true;\n },\n isServerSideAuthEnabled() {\n return isServerSideAuthEnabled;\n },\n setRuntimeOptions(options) {\n // make a copy instead of set the reference\n runtimeOptions = structuredClone(options);\n },\n getRuntimeOptions() {\n return runtimeOptions;\n },\n setIsSSLOrigin(value) {\n isSSLOrigin = value;\n },\n isSSLOrigin() {\n return isSSLOrigin;\n },\n};\n"],"names":[],"mappings":"AAAA;AACA;AACA,IAAI,uBAAuB,GAAG,KAAK;AACnC,IAAI,cAAc,GAAG,EAAE;AACvB,IAAI,WAAW,GAAG,KAAK;AACX,MAAC,cAAc,GAAG;AAC9B,IAAI,oBAAoB,GAAG;AAC3B,QAAQ,uBAAuB,GAAG,IAAI;AACtC,IAAI,CAAC;AACL,IAAI,uBAAuB,GAAG;AAC9B,QAAQ,OAAO,uBAAuB;AACtC,IAAI,CAAC;AACL,IAAI,iBAAiB,CAAC,OAAO,EAAE;AAC/B;AACA,QAAQ,cAAc,GAAG,eAAe,CAAC,OAAO,CAAC;AACjD,IAAI,CAAC;AACL,IAAI,iBAAiB,GAAG;AACxB,QAAQ,OAAO,cAAc;AAC7B,IAAI,CAAC;AACL,IAAI,cAAc,CAAC,KAAK,EAAE;AAC1B,QAAQ,WAAW,GAAG,KAAK;AAC3B,IAAI,CAAC;AACL,IAAI,WAAW,GAAG;AAClB,QAAQ,OAAO,WAAW;AAC1B,IAAI,CAAC;AACL;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"isValidCognitoToken.mjs","sources":["../../../src/utils/isValidCognitoToken.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { JwtExpiredError } from 'aws-jwt-verify/error';\n/**\n * Verifies a Cognito JWT token for its validity.\n *\n * @param input - An object containing:\n * - token: The JWT token as a string that needs to be verified.\n * - verifier: The JWT verifier which will verify the token.\n * @internal\n */\nexport const isValidCognitoToken = async (input) => {\n const { token, verifier } = input;\n try {\n await verifier.verify(token);\n return true;\n }\n catch (error) {\n // When `JwtExpiredError` is thrown, the token should have valid signature\n // but expired. So, we can consider it as a valid token.\n // Reference https://github.com/awslabs/aws-jwt-verify/blob/8d8f714d7281913ecd660147f5c30311479601c1/src/jwt-rsa.ts#L290-L301\n if (error instanceof JwtExpiredError) {\n return true;\n }\n // TODO (ashwinkumar6): surface invalid cognito token error to customer\n // TODO: clear invalid tokens from Storage\n return false;\n }\n};\n"],"names":[],"mappings":";;AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,mBAAmB,GAAG,OAAO,KAAK,KAAK;AACpD,IAAI,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK;AACrC,IAAI,IAAI;AACR,QAAQ,MAAM,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC;AACpC,QAAQ,OAAO,IAAI;AACnB;AACA,IAAI,OAAO,KAAK,EAAE;AAClB;AACA;AACA;AACA,QAAQ,IAAI,KAAK,YAAY,eAAe,EAAE;AAC9C,YAAY,OAAO,IAAI;AACvB;AACA;AACA;AACA,QAAQ,OAAO,KAAK;AACpB;AACA;;;;"}
1
+ {"version":3,"file":"isValidCognitoToken.mjs","sources":["../../../src/utils/isValidCognitoToken.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { JwtExpiredError } from 'aws-jwt-verify/error';\n/**\n * Verifies a Cognito JWT token for its validity.\n *\n * @param input - An object containing:\n * - token: The JWT token as a string that needs to be verified.\n * - verifier: The JWT verifier which will verify the token.\n * @internal\n */\nexport const isValidCognitoToken = async (input) => {\n const { token, verifier } = input;\n try {\n await verifier.verify(token);\n return true;\n }\n catch (error) {\n // When `JwtExpiredError` is thrown, the token should have valid signature\n // but expired. So, we can consider it as a valid token.\n // Reference https://github.com/awslabs/aws-jwt-verify/blob/8d8f714d7281913ecd660147f5c30311479601c1/src/jwt-rsa.ts#L290-L301\n if (error instanceof JwtExpiredError) {\n return true;\n }\n // TODO (ashwinkumar6): surface invalid cognito token error to customer\n // TODO: clear invalid tokens from Storage\n return false;\n }\n};\n"],"names":[],"mappings":";;AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,mBAAmB,GAAG,OAAO,KAAK,KAAK;AACpD,IAAI,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK;AACrC,IAAI,IAAI;AACR,QAAQ,MAAM,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC;AACpC,QAAQ,OAAO,IAAI;AACnB,IAAI;AACJ,IAAI,OAAO,KAAK,EAAE;AAClB;AACA;AACA;AACA,QAAQ,IAAI,KAAK,YAAY,eAAe,EAAE;AAC9C,YAAY,OAAO,IAAI;AACvB,QAAQ;AACR;AACA;AACA,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ;;;;"}
package/package.json CHANGED
@@ -1,72 +1,72 @@
1
1
  {
2
- "author": "Amazon Web Services",
3
- "name": "@aws-amplify/adapter-nextjs",
4
- "version": "1.6.7-unstable.e5a8569.0+e5a8569",
5
- "description": "The adapter for the supporting of using Amplify APIs in Next.js.",
6
- "peerDependencies": {
7
- "aws-amplify": "6.15.4-unstable.e5a8569.0+e5a8569",
8
- "next": ">=13.5.0 <16.0.0"
9
- },
10
- "dependencies": {
11
- "aws-jwt-verify": "^4.0.1"
12
- },
13
- "devDependencies": {
14
- "@types/node": "^20.3.1",
15
- "@types/react": "^18.2.13",
16
- "@types/react-dom": "^18.2.6",
17
- "aws-amplify": "6.15.4-unstable.e5a8569.0+e5a8569",
18
- "jest-fetch-mock": "3.0.3",
19
- "next": ">= 13.5.0 < 15.0.0"
20
- },
21
- "publishConfig": {
22
- "access": "public"
23
- },
24
- "bugs": {
25
- "url": "https://github.com/aws/aws-amplify/issues"
26
- },
27
- "exports": {
28
- ".": {
29
- "types": "./dist/esm/index.d.ts",
30
- "import": "./dist/esm/index.mjs",
31
- "require": "./dist/cjs/index.js"
32
- },
33
- "./api": {
34
- "types": "./dist/esm/api/index.d.ts",
35
- "import": "./dist/esm/api/index.mjs",
36
- "require": "./dist/cjs/api/index.js"
37
- },
38
- "./data": {
39
- "types": "./dist/esm/api/index.d.ts",
40
- "import": "./dist/esm/api/index.mjs",
41
- "require": "./dist/cjs/api/index.js"
42
- },
43
- "./package.json": "./package.json"
44
- },
45
- "files": [
46
- "dist/cjs",
47
- "dist/esm",
48
- "src",
49
- "api",
50
- "data"
51
- ],
52
- "homepage": "https://aws-amplify.github.io/",
53
- "license": "Apache-2.0",
54
- "main": "./dist/cjs/index.js",
55
- "module": "./dist/esm/index.mjs",
56
- "typings": "./dist/esm/index.d.ts",
57
- "sideEffects": false,
58
- "scripts": {
59
- "build": "npm run clean && npm run build:esm-cjs",
60
- "build-with-test": "npm test && npm run build",
61
- "build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
62
- "build:watch": "npm run build:esm-cjs -- --watch",
63
- "clean": "npm run clean:size && rimraf dist",
64
- "clean:size": "rimraf dual-publish-tmp tmp*",
65
- "format": "echo \"Not implemented\"",
66
- "lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
67
- "lint:fix": "eslint '**/*.{ts,tsx}' --fix",
68
- "test": "npm run lint && jest -w 1 --coverage --logHeapUsage",
69
- "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
70
- },
71
- "gitHead": "e5a85697101735c21548e397832fab12d001a5dc"
2
+ "author": "Amazon Web Services",
3
+ "name": "@aws-amplify/adapter-nextjs",
4
+ "version": "1.6.7",
5
+ "description": "The adapter for the supporting of using Amplify APIs in Next.js.",
6
+ "peerDependencies": {
7
+ "aws-amplify": "^6.13.1",
8
+ "next": ">=13.5.0 <16.0.0"
9
+ },
10
+ "dependencies": {
11
+ "aws-jwt-verify": "^4.0.1"
12
+ },
13
+ "devDependencies": {
14
+ "@types/node": "^20.3.1",
15
+ "@types/react": "^18.2.13",
16
+ "@types/react-dom": "^18.2.6",
17
+ "aws-amplify": "6.15.4",
18
+ "jest-fetch-mock": "3.0.3",
19
+ "next": ">= 13.5.0 < 15.0.0"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/aws/aws-amplify/issues"
26
+ },
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/esm/index.d.ts",
30
+ "import": "./dist/esm/index.mjs",
31
+ "require": "./dist/cjs/index.js"
32
+ },
33
+ "./api": {
34
+ "types": "./dist/esm/api/index.d.ts",
35
+ "import": "./dist/esm/api/index.mjs",
36
+ "require": "./dist/cjs/api/index.js"
37
+ },
38
+ "./data": {
39
+ "types": "./dist/esm/api/index.d.ts",
40
+ "import": "./dist/esm/api/index.mjs",
41
+ "require": "./dist/cjs/api/index.js"
42
+ },
43
+ "./package.json": "./package.json"
44
+ },
45
+ "files": [
46
+ "dist/cjs",
47
+ "dist/esm",
48
+ "src",
49
+ "api",
50
+ "data"
51
+ ],
52
+ "homepage": "https://aws-amplify.github.io/",
53
+ "license": "Apache-2.0",
54
+ "main": "./dist/cjs/index.js",
55
+ "module": "./dist/esm/index.mjs",
56
+ "typings": "./dist/esm/index.d.ts",
57
+ "sideEffects": false,
58
+ "scripts": {
59
+ "build": "npm run clean && npm run build:esm-cjs",
60
+ "build-with-test": "npm test && npm run build",
61
+ "build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
62
+ "build:watch": "npm run build:esm-cjs -- --watch",
63
+ "clean": "npm run clean:size && rimraf dist",
64
+ "clean:size": "rimraf dual-publish-tmp tmp*",
65
+ "format": "echo \"Not implemented\"",
66
+ "lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
67
+ "lint:fix": "eslint '**/*.{ts,tsx}' --fix",
68
+ "test": "npm run lint && jest -w 1 --coverage --logHeapUsage",
69
+ "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
70
+ },
71
+ "gitHead": "4c55a0bc68f5ea90c93e50c652964c74393e847a"
72
72
  }
@@ -10,7 +10,25 @@ import { AuthRoutesHandlerContext } from '../types';
10
10
  export function isNextRequest(request: object): request is NextRequest {
11
11
  // NextRequest extends the Web Request API with additional convenience methods.
12
12
  // Details: https://nextjs.org/docs/app/api-reference/functions/next-request#nexturl
13
- return request instanceof Request && 'nextUrl' in request;
13
+ //
14
+ // Use duck typing instead of instanceof to handle Lambda/serverless environments
15
+ // where Request constructor references may differ between invocations
16
+
17
+ return (
18
+ typeof request === 'object' &&
19
+ request !== null &&
20
+ // NextRequest-specific properties
21
+ 'nextUrl' in request &&
22
+ typeof request.nextUrl === 'object' &&
23
+ request.nextUrl !== null &&
24
+ 'cookies' in request &&
25
+ // Basic Request API properties
26
+ 'url' in request &&
27
+ typeof request.url === 'string' &&
28
+ 'headers' in request &&
29
+ 'method' in request &&
30
+ typeof request.method === 'string'
31
+ );
14
32
  }
15
33
 
16
34
  // AuthRoutesHandlersContext is the 2nd parameter type for the API route handlers in the App Router