@aws-amplify/adapter-nextjs 1.2.8 → 1.2.9-unstable.60a559f.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/utils/createCookieStorageAdapterFromNextServerContext.js +4 -1
- package/dist/cjs/utils/createCookieStorageAdapterFromNextServerContext.js.map +1 -1
- package/dist/esm/utils/createCookieStorageAdapterFromNextServerContext.mjs +4 -1
- package/dist/esm/utils/createCookieStorageAdapterFromNextServerContext.mjs.map +1 -1
- package/package.json +73 -73
- package/src/utils/createCookieStorageAdapterFromNextServerContext.ts +4 -1
|
@@ -144,7 +144,7 @@ const createMutableCookieStoreFromHeaders = (headers) => {
|
|
|
144
144
|
};
|
|
145
145
|
};
|
|
146
146
|
const serializeSetCookieOptions = (options) => {
|
|
147
|
-
const { expires, domain, httpOnly, sameSite, secure } = options;
|
|
147
|
+
const { expires, domain, httpOnly, sameSite, secure, path } = options;
|
|
148
148
|
const serializedOptions = [];
|
|
149
149
|
if (domain) {
|
|
150
150
|
serializedOptions.push(`Domain=${domain}`);
|
|
@@ -161,6 +161,9 @@ const serializeSetCookieOptions = (options) => {
|
|
|
161
161
|
if (secure) {
|
|
162
162
|
serializedOptions.push(`Secure`);
|
|
163
163
|
}
|
|
164
|
+
if (path) {
|
|
165
|
+
serializedOptions.push(`Path=${path}`);
|
|
166
|
+
}
|
|
164
167
|
return serializedOptions.join(';');
|
|
165
168
|
};
|
|
166
169
|
// Ensures the cookie names are encoded in order to look up the cookie store
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCookieStorageAdapterFromNextServerContext.js","sources":["../../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createCookieStorageAdapterFromNextServerContext = exports.DATE_IN_THE_PAST = void 0;\nconst server_js_1 = require(\"next/server.js\");\nconst adapter_core_1 = require(\"@aws-amplify/core/internals/adapter-core\");\nexports.DATE_IN_THE_PAST = new Date(0);\nconst createCookieStorageAdapterFromNextServerContext = (context) => {\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);\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 server_js_1.NextResponse) {\n return createCookieStorageAdapterFromNextRequestAndNextResponse(request, response);\n }\n else {\n return createCookieStorageAdapterFromNextRequestAndHttpResponse(request, response);\n }\n }\n const { cookies } = context;\n if (typeof cookies === 'function') {\n return createCookieStorageAdapterFromNextCookies(cookies);\n }\n // This should not happen normally.\n throw new adapter_core_1.AmplifyServerContextError({\n message: 'Attempted to create cookie storage adapter from an unsupported Next.js server context.',\n });\n};\nexports.createCookieStorageAdapterFromNextServerContext = createCookieStorageAdapterFromNextServerContext;\nconst createCookieStorageAdapterFromNextRequestAndNextResponse = (request, response) => {\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 mutableCookieStore.set(ensureEncodedForJSCookie(name), value, options);\n },\n delete(name) {\n mutableCookieStore.delete(ensureEncodedForJSCookie(name));\n },\n };\n};\nconst createCookieStorageAdapterFromNextRequestAndHttpResponse = (request, response) => {\n const readonlyCookieStore = request.cookies;\n const mutableCookieStore = createMutableCookieStoreFromHeaders(response.headers);\n return {\n get(name) {\n return readonlyCookieStore.get(ensureEncodedForJSCookie(name));\n },\n getAll: readonlyCookieStore.getAll.bind(readonlyCookieStore),\n ...mutableCookieStore,\n };\n};\nconst createCookieStorageAdapterFromNextCookies = (cookies) => {\n const cookieStore = 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 try {\n cookieStore.set(ensureEncodedForJSCookie(name), value, options);\n }\n catch {\n // no-op\n }\n };\n const deleteFunc = name => {\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) => {\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 response.appendHeader('Set-Cookie', `${ensureEncodedForJSCookie(name)}=${value};${options ? serializeSetCookieOptions(options) : ''}`);\n },\n delete(name) {\n response.appendHeader('Set-Cookie', `${ensureEncodedForJSCookie(name)}=;Expires=${exports.DATE_IN_THE_PAST.toUTCString()}`);\n },\n };\n};\nconst createMutableCookieStoreFromHeaders = (headers) => {\n const setFunc = (name, value, options) => {\n headers.append('Set-Cookie', `${ensureEncodedForJSCookie(name)}=${value};${options ? serializeSetCookieOptions(options) : ''}`);\n };\n const deleteFunc = name => {\n headers.append('Set-Cookie', `${ensureEncodedForJSCookie(name)}=;Expires=${exports.DATE_IN_THE_PAST.toUTCString()}`);\n };\n return {\n set: setFunc,\n delete: deleteFunc,\n };\n};\nconst serializeSetCookieOptions = (options) => {\n const { expires, domain, httpOnly, sameSite, secure } = 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 return serializedOptions.join(';');\n};\n// Ensures the cookie names are encoded in order to look up the cookie store\n// that is manipulated by js-cookie on the client side.\n// Details of the js-cookie encoding behavior see:\n// https://github.com/js-cookie/js-cookie#encoding\n// The implementation is borrowed from js-cookie without escaping `[()]` as\n// we are not using those chars in the auth keys.\nconst ensureEncodedForJSCookie = (name) => encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent);\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,+CAA+C,GAAG,OAAO,CAAC,gBAAgB,GAAG,KAAK,CAAC,CAAC;AAC5F,MAAM,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC9C,MAAM,cAAc,GAAG,OAAO,CAAC,0CAA0C,CAAC,CAAC;AAC3E,OAAO,CAAC,gBAAgB,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;AACvC,MAAM,+CAA+C,GAAG,CAAC,OAAO,KAAK;AACrE,IAAI,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;AACpD;AACA;AACA;AACA;AACA;AACA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KAAK,CAAC;AACN,CAAC,CAAC;AACF,MAAM,yBAAyB,GAAG,CAAC,OAAO,KAAK;AAC/C,IAAI,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;AACpE,IAAI,MAAM,iBAAiB,GAAG,EAAE,CAAC;AACjC,IAAI,IAAI,MAAM,EAAE;AAChB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AACnD,KAAK;AACL,IAAI,IAAI,OAAO,EAAE;AACjB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;AACnE,KAAK;AACL,IAAI,IAAI,QAAQ,EAAE;AAClB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC3C,KAAK;AACL,IAAI,IAAI,QAAQ,EAAE;AAClB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;AACvD,KAAK;AACL,IAAI,IAAI,MAAM,EAAE;AAChB,QAAQ,iBAAiB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AACzC,KAAK;AACL,IAAI,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACvC,CAAC,CAAC;AACF;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,wBAAwB,GAAG,CAAC,IAAI,KAAK,kBAAkB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,kBAAkB,CAAC;;"}
|
|
1
|
+
{"version":3,"file":"createCookieStorageAdapterFromNextServerContext.js","sources":["../../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createCookieStorageAdapterFromNextServerContext = exports.DATE_IN_THE_PAST = void 0;\nconst server_js_1 = require(\"next/server.js\");\nconst adapter_core_1 = require(\"@aws-amplify/core/internals/adapter-core\");\nexports.DATE_IN_THE_PAST = new Date(0);\nconst createCookieStorageAdapterFromNextServerContext = (context) => {\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);\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 server_js_1.NextResponse) {\n return createCookieStorageAdapterFromNextRequestAndNextResponse(request, response);\n }\n else {\n return createCookieStorageAdapterFromNextRequestAndHttpResponse(request, response);\n }\n }\n const { cookies } = context;\n if (typeof cookies === 'function') {\n return createCookieStorageAdapterFromNextCookies(cookies);\n }\n // This should not happen normally.\n throw new adapter_core_1.AmplifyServerContextError({\n message: 'Attempted to create cookie storage adapter from an unsupported Next.js server context.',\n });\n};\nexports.createCookieStorageAdapterFromNextServerContext = createCookieStorageAdapterFromNextServerContext;\nconst createCookieStorageAdapterFromNextRequestAndNextResponse = (request, response) => {\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 mutableCookieStore.set(ensureEncodedForJSCookie(name), value, options);\n },\n delete(name) {\n mutableCookieStore.delete(ensureEncodedForJSCookie(name));\n },\n };\n};\nconst createCookieStorageAdapterFromNextRequestAndHttpResponse = (request, response) => {\n const readonlyCookieStore = request.cookies;\n const mutableCookieStore = createMutableCookieStoreFromHeaders(response.headers);\n return {\n get(name) {\n return readonlyCookieStore.get(ensureEncodedForJSCookie(name));\n },\n getAll: readonlyCookieStore.getAll.bind(readonlyCookieStore),\n ...mutableCookieStore,\n };\n};\nconst createCookieStorageAdapterFromNextCookies = (cookies) => {\n const cookieStore = 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 try {\n cookieStore.set(ensureEncodedForJSCookie(name), value, options);\n }\n catch {\n // no-op\n }\n };\n const deleteFunc = name => {\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) => {\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 response.appendHeader('Set-Cookie', `${ensureEncodedForJSCookie(name)}=${value};${options ? serializeSetCookieOptions(options) : ''}`);\n },\n delete(name) {\n response.appendHeader('Set-Cookie', `${ensureEncodedForJSCookie(name)}=;Expires=${exports.DATE_IN_THE_PAST.toUTCString()}`);\n },\n };\n};\nconst createMutableCookieStoreFromHeaders = (headers) => {\n const setFunc = (name, value, options) => {\n headers.append('Set-Cookie', `${ensureEncodedForJSCookie(name)}=${value};${options ? serializeSetCookieOptions(options) : ''}`);\n };\n const deleteFunc = name => {\n headers.append('Set-Cookie', `${ensureEncodedForJSCookie(name)}=;Expires=${exports.DATE_IN_THE_PAST.toUTCString()}`);\n };\n return {\n set: setFunc,\n delete: deleteFunc,\n };\n};\nconst serializeSetCookieOptions = (options) => {\n const { expires, domain, httpOnly, sameSite, secure, path } = 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 return serializedOptions.join(';');\n};\n// Ensures the cookie names are encoded in order to look up the cookie store\n// that is manipulated by js-cookie on the client side.\n// Details of the js-cookie encoding behavior see:\n// https://github.com/js-cookie/js-cookie#encoding\n// The implementation is borrowed from js-cookie without escaping `[()]` as\n// we are not using those chars in the auth keys.\nconst ensureEncodedForJSCookie = (name) => encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent);\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,+CAA+C,GAAG,OAAO,CAAC,gBAAgB,GAAG,KAAK,CAAC,CAAC;AAC5F,MAAM,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC9C,MAAM,cAAc,GAAG,OAAO,CAAC,0CAA0C,CAAC,CAAC;AAC3E,OAAO,CAAC,gBAAgB,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;AACvC,MAAM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AACF;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,wBAAwB,GAAG,CAAC,IAAI,KAAK,kBAAkB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,kBAAkB,CAAC;;"}
|
|
@@ -140,7 +140,7 @@ const createMutableCookieStoreFromHeaders = (headers) => {
|
|
|
140
140
|
};
|
|
141
141
|
};
|
|
142
142
|
const serializeSetCookieOptions = (options) => {
|
|
143
|
-
const { expires, domain, httpOnly, sameSite, secure } = options;
|
|
143
|
+
const { expires, domain, httpOnly, sameSite, secure, path } = options;
|
|
144
144
|
const serializedOptions = [];
|
|
145
145
|
if (domain) {
|
|
146
146
|
serializedOptions.push(`Domain=${domain}`);
|
|
@@ -157,6 +157,9 @@ const serializeSetCookieOptions = (options) => {
|
|
|
157
157
|
if (secure) {
|
|
158
158
|
serializedOptions.push(`Secure`);
|
|
159
159
|
}
|
|
160
|
+
if (path) {
|
|
161
|
+
serializedOptions.push(`Path=${path}`);
|
|
162
|
+
}
|
|
160
163
|
return serializedOptions.join(';');
|
|
161
164
|
};
|
|
162
165
|
// Ensures the cookie names are encoded in order to look up the cookie store
|
|
@@ -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/core/internals/adapter-core';\nexport const DATE_IN_THE_PAST = new Date(0);\nexport const createCookieStorageAdapterFromNextServerContext = (context) => {\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);\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);\n }\n else {\n return createCookieStorageAdapterFromNextRequestAndHttpResponse(request, response);\n }\n }\n const { cookies } = context;\n if (typeof cookies === 'function') {\n return createCookieStorageAdapterFromNextCookies(cookies);\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) => {\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 mutableCookieStore.set(ensureEncodedForJSCookie(name), value, options);\n },\n delete(name) {\n mutableCookieStore.delete(ensureEncodedForJSCookie(name));\n },\n };\n};\nconst createCookieStorageAdapterFromNextRequestAndHttpResponse = (request, response) => {\n const readonlyCookieStore = request.cookies;\n const mutableCookieStore = createMutableCookieStoreFromHeaders(response.headers);\n return {\n get(name) {\n return readonlyCookieStore.get(ensureEncodedForJSCookie(name));\n },\n getAll: readonlyCookieStore.getAll.bind(readonlyCookieStore),\n ...mutableCookieStore,\n };\n};\nconst createCookieStorageAdapterFromNextCookies = (cookies) => {\n const cookieStore = 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 try {\n cookieStore.set(ensureEncodedForJSCookie(name), value, options);\n }\n catch {\n // no-op\n }\n };\n const deleteFunc = name => {\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) => {\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 response.appendHeader('Set-Cookie', `${ensureEncodedForJSCookie(name)}=${value};${options ? serializeSetCookieOptions(options) : ''}`);\n },\n delete(name) {\n response.appendHeader('Set-Cookie', `${ensureEncodedForJSCookie(name)}=;Expires=${DATE_IN_THE_PAST.toUTCString()}`);\n },\n };\n};\nconst createMutableCookieStoreFromHeaders = (headers) => {\n const setFunc = (name, value, options) => {\n headers.append('Set-Cookie', `${ensureEncodedForJSCookie(name)}=${value};${options ? serializeSetCookieOptions(options) : ''}`);\n };\n const deleteFunc = name => {\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 serializeSetCookieOptions = (options) => {\n const { expires, domain, httpOnly, sameSite, secure } = 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 return serializedOptions.join(';');\n};\n// Ensures the cookie names are encoded in order to look up the cookie store\n// that is manipulated by js-cookie on the client side.\n// Details of the js-cookie encoding behavior see:\n// https://github.com/js-cookie/js-cookie#encoding\n// The implementation is borrowed from js-cookie without escaping `[()]` as\n// we are not using those chars in the auth keys.\nconst ensureEncodedForJSCookie = (name) => encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent);\n"],"names":[],"mappings":";;;AAAA;AACA;AAGY,MAAC,gBAAgB,GAAG,IAAI,IAAI,CAAC,CAAC,EAAE;AAChC,MAAC,+CAA+C,GAAG,CAAC,OAAO,KAAK;AAC5E,IAAI,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;AACpD;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,CAAC,CAAC;AACjF,KAAK;AACL,IAAI,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,IAAI,OAAO,IAAI,QAAQ,EAAE;AAC7B,QAAQ,IAAI,QAAQ,YAAY,YAAY,EAAE;AAC9C,YAAY,OAAO,wDAAwD,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC/F,SAAS;AACT,aAAa;AACb,YAAY,OAAO,wDAAwD,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC/F,SAAS;AACT,KAAK;AACL,IAAI,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;AAChC,IAAI,IAAI,OAAO,OAA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CAAC,MAAM,CAAC,CAAC,CAAC;AACzC,KAAK;AACL,IAAI,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACvC,CAAC,CAAC;AACF;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,wBAAwB,GAAG,CAAC,IAAI,KAAK,kBAAkB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,kBAAkB,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/core/internals/adapter-core';\nexport const DATE_IN_THE_PAST = new Date(0);\nexport const createCookieStorageAdapterFromNextServerContext = (context) => {\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);\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);\n }\n else {\n return createCookieStorageAdapterFromNextRequestAndHttpResponse(request, response);\n }\n }\n const { cookies } = context;\n if (typeof cookies === 'function') {\n return createCookieStorageAdapterFromNextCookies(cookies);\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) => {\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 mutableCookieStore.set(ensureEncodedForJSCookie(name), value, options);\n },\n delete(name) {\n mutableCookieStore.delete(ensureEncodedForJSCookie(name));\n },\n };\n};\nconst createCookieStorageAdapterFromNextRequestAndHttpResponse = (request, response) => {\n const readonlyCookieStore = request.cookies;\n const mutableCookieStore = createMutableCookieStoreFromHeaders(response.headers);\n return {\n get(name) {\n return readonlyCookieStore.get(ensureEncodedForJSCookie(name));\n },\n getAll: readonlyCookieStore.getAll.bind(readonlyCookieStore),\n ...mutableCookieStore,\n };\n};\nconst createCookieStorageAdapterFromNextCookies = (cookies) => {\n const cookieStore = 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 try {\n cookieStore.set(ensureEncodedForJSCookie(name), value, options);\n }\n catch {\n // no-op\n }\n };\n const deleteFunc = name => {\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) => {\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 response.appendHeader('Set-Cookie', `${ensureEncodedForJSCookie(name)}=${value};${options ? serializeSetCookieOptions(options) : ''}`);\n },\n delete(name) {\n response.appendHeader('Set-Cookie', `${ensureEncodedForJSCookie(name)}=;Expires=${DATE_IN_THE_PAST.toUTCString()}`);\n },\n };\n};\nconst createMutableCookieStoreFromHeaders = (headers) => {\n const setFunc = (name, value, options) => {\n headers.append('Set-Cookie', `${ensureEncodedForJSCookie(name)}=${value};${options ? serializeSetCookieOptions(options) : ''}`);\n };\n const deleteFunc = name => {\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 serializeSetCookieOptions = (options) => {\n const { expires, domain, httpOnly, sameSite, secure, path } = 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 return serializedOptions.join(';');\n};\n// Ensures the cookie names are encoded in order to look up the cookie store\n// that is manipulated by js-cookie on the client side.\n// Details of the js-cookie encoding behavior see:\n// https://github.com/js-cookie/js-cookie#encoding\n// The implementation is borrowed from js-cookie without escaping `[()]` as\n// we are not using those chars in the auth keys.\nconst ensureEncodedForJSCookie = (name) => encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent);\n"],"names":[],"mappings":";;;AAAA;AACA;AAGY,MAAC,gBAAgB,GAAG,IAAI,IAAI,CAAC,CAAC,EAAE;AAChC,MAAC,+CAA+C,GAAG,CAAC,OAAO,KAAK;AAC5E,IAAI,MAAM,E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/package.json
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
2
|
+
"author": "Amazon Web Services",
|
|
3
|
+
"name": "@aws-amplify/adapter-nextjs",
|
|
4
|
+
"version": "1.2.9-unstable.60a559f.0+60a559f",
|
|
5
|
+
"description": "The adapter for the supporting of using Amplify APIs in Next.js.",
|
|
6
|
+
"peerDependencies": {
|
|
7
|
+
"aws-amplify": "6.4.2-unstable.60a559f.0+60a559f",
|
|
8
|
+
"next": ">=13.5.0 <15.0.0"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"aws-jwt-verify": "^4.0.1",
|
|
12
|
+
"cookie": "0.5.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/cookie": "0.5.1",
|
|
16
|
+
"@types/node": "^20.3.1",
|
|
17
|
+
"@types/react": "^18.2.13",
|
|
18
|
+
"@types/react-dom": "^18.2.6",
|
|
19
|
+
"aws-amplify": "6.4.2-unstable.60a559f.0+60a559f",
|
|
20
|
+
"jest-fetch-mock": "3.0.3",
|
|
21
|
+
"next": ">= 13.5.0 < 15.0.0",
|
|
22
|
+
"typescript": "5.0.2"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/aws/aws-amplify/issues"
|
|
29
|
+
},
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/esm/index.d.ts",
|
|
33
|
+
"import": "./dist/esm/index.mjs",
|
|
34
|
+
"require": "./dist/cjs/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./api": {
|
|
37
|
+
"types": "./dist/esm/api/index.d.ts",
|
|
38
|
+
"import": "./dist/esm/api/index.mjs",
|
|
39
|
+
"require": "./dist/cjs/api/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./data": {
|
|
42
|
+
"types": "./dist/esm/api/index.d.ts",
|
|
43
|
+
"import": "./dist/esm/api/index.mjs",
|
|
44
|
+
"require": "./dist/cjs/api/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./package.json": "./package.json"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist/cjs",
|
|
50
|
+
"dist/esm",
|
|
51
|
+
"src",
|
|
52
|
+
"api",
|
|
53
|
+
"data"
|
|
54
|
+
],
|
|
55
|
+
"homepage": "https://aws-amplify.github.io/",
|
|
56
|
+
"license": "Apache-2.0",
|
|
57
|
+
"main": "./dist/cjs/index.js",
|
|
58
|
+
"module": "./dist/esm/index.mjs",
|
|
59
|
+
"typings": "./dist/esm/index.d.ts",
|
|
60
|
+
"sideEffects": false,
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "npm run clean && npm run build:esm-cjs",
|
|
63
|
+
"build-with-test": "npm test && npm run build",
|
|
64
|
+
"build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
|
|
65
|
+
"build:watch": "npm run build:esm-cjs -- --watch",
|
|
66
|
+
"clean": "npm run clean:size && rimraf dist",
|
|
67
|
+
"clean:size": "rimraf dual-publish-tmp tmp*",
|
|
68
|
+
"format": "echo \"Not implemented\"",
|
|
69
|
+
"lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
|
|
70
|
+
"lint:fix": "eslint '**/*.{ts,tsx}' --fix",
|
|
71
|
+
"test": "npm run lint && jest -w 1 --coverage --logHeapUsage",
|
|
72
|
+
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
|
|
73
|
+
},
|
|
74
|
+
"gitHead": "60a559f612e092c76e1499f93547248312db46f2"
|
|
75
75
|
}
|
|
@@ -218,7 +218,7 @@ const createMutableCookieStoreFromHeaders = (
|
|
|
218
218
|
const serializeSetCookieOptions = (
|
|
219
219
|
options: CookieStorage.SetCookieOptions,
|
|
220
220
|
): string => {
|
|
221
|
-
const { expires, domain, httpOnly, sameSite, secure } = options;
|
|
221
|
+
const { expires, domain, httpOnly, sameSite, secure, path } = options;
|
|
222
222
|
const serializedOptions: string[] = [];
|
|
223
223
|
if (domain) {
|
|
224
224
|
serializedOptions.push(`Domain=${domain}`);
|
|
@@ -235,6 +235,9 @@ const serializeSetCookieOptions = (
|
|
|
235
235
|
if (secure) {
|
|
236
236
|
serializedOptions.push(`Secure`);
|
|
237
237
|
}
|
|
238
|
+
if (path) {
|
|
239
|
+
serializedOptions.push(`Path=${path}`);
|
|
240
|
+
}
|
|
238
241
|
|
|
239
242
|
return serializedOptions.join(';');
|
|
240
243
|
};
|