@aws-amplify/adapter-nextjs 0.0.2-console-preview.9e7dd78.0 → 0.0.2-console-preview.957cda4.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.
@@ -51,12 +51,13 @@ var runWithAmplifyServerContext = function (_a) {
51
51
  // When the Auth config is presented, attempt to create a Amplify server
52
52
  // context with token and credentials provider.
53
53
  if (amplifyConfig.Auth) {
54
- keyValueStorage = nextServerContext === null
55
- ? // When `null` is passed as the value of `nextServerContext`, opt-in
56
- // unauthenticated role (primarily for static rendering). It's
57
- // safe to use the singleton `MemoryKeyValueStorage` here, as the
58
- // static rendering uses the same unauthenticated role cross-sever.
59
- core_1.MemoryKeyValueStorage
54
+ keyValueStorage =
55
+ // When `null` is passed as the value of `nextServerContext`, opt-in
56
+ // unauthenticated role (primarily for static rendering). It's
57
+ // safe to use the singleton `MemoryKeyValueStorage` here, as the
58
+ // static rendering uses the same unauthenticated role cross-sever.
59
+ nextServerContext === null
60
+ ? core_1.MemoryKeyValueStorage
60
61
  : (0, adapter_core_1.createKeyValueStorageFromCookieStorageAdapter)((0, utils_1.createCookieStorageAdapterFromNextServerContext)(nextServerContext));
61
62
  credentialsProvider = (0, adapter_core_1.createAWSCredentialsAndIdentityIdProvider)(amplifyConfig.Auth, keyValueStorage);
62
63
  tokenProvider = (0, adapter_core_1.createUserPoolsTokenProvider)(amplifyConfig.Auth, keyValueStorage);
@@ -1 +1 @@
1
- {"version":3,"file":"runWithAmplifyServerContext.js","sourceRoot":"","sources":["../src/runWithAmplifyServerContext.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtC,iCAGiB;AACjB,0CAA0D;AAC1D,mEAK4C;AAErC,IAAM,2BAA2B,GACvC,UAAO,EAAgC;QAA9B,iBAAiB,uBAAA,EAAE,SAAS,eAAA;;;;YAM9B,aAAa,GAAG,IAAA,wBAAgB,GAAE,CAAC;YAEzC,wEAAwE;YACxE,+CAA+C;YAC/C,IAAI,aAAa,CAAC,IAAI,EAAE;gBACjB,eAAe,GACpB,iBAAiB,KAAK,IAAI;oBACzB,CAAC,CAAC,oEAAoE;wBACpE,8DAA8D;wBAC9D,iEAAiE;wBACjE,mEAAmE;wBACnE,4BAAqB;oBACvB,CAAC,CAAC,IAAA,4DAA6C,EAC7C,IAAA,uDAA+C,EAAC,iBAAiB,CAAC,CACjE,CAAC;gBACA,mBAAmB,GAAG,IAAA,wDAAyC,EACpE,aAAa,CAAC,IAAI,EAClB,eAAe,CACf,CAAC;gBACI,aAAa,GAAG,IAAA,2CAA4B,EACjD,aAAa,CAAC,IAAI,EAClB,eAAe,CACf,CAAC;gBAEF,sBAAO,IAAA,0CAA+B,EACrC,aAAa,EACb;wBACC,IAAI,EAAE,EAAE,mBAAmB,qBAAA,EAAE,aAAa,eAAA,EAAE;qBAC5C,EACD,SAAS,CACT,EAAC;aACF;YAED,oEAAoE;YACpE,+CAA+C;YAC/C,sBAAO,IAAA,0CAA+B,EAAC,aAAa,EAAE,EAAE,EAAE,SAAS,CAAC,EAAC;;;CACrE,CAAC;AA3CU,QAAA,2BAA2B,+BA2CrC"}
1
+ {"version":3,"file":"runWithAmplifyServerContext.js","sourceRoot":"","sources":["../src/runWithAmplifyServerContext.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtC,iCAGiB;AACjB,0CAA0D;AAC1D,mEAK4C;AAErC,IAAM,2BAA2B,GACvC,UAAO,EAAgC;QAA9B,iBAAiB,uBAAA,EAAE,SAAS,eAAA;;;;YAM9B,aAAa,GAAG,IAAA,wBAAgB,GAAE,CAAC;YAEzC,wEAAwE;YACxE,+CAA+C;YAC/C,IAAI,aAAa,CAAC,IAAI,EAAE;gBACjB,eAAe;gBACpB,oEAAoE;gBACpE,8DAA8D;gBAC9D,iEAAiE;gBACjE,mEAAmE;gBACnE,iBAAiB,KAAK,IAAI;oBACzB,CAAC,CAAC,4BAAqB;oBACvB,CAAC,CAAC,IAAA,4DAA6C,EAC7C,IAAA,uDAA+C,EAAC,iBAAiB,CAAC,CACjE,CAAC;gBACA,mBAAmB,GAAG,IAAA,wDAAyC,EACpE,aAAa,CAAC,IAAI,EAClB,eAAe,CACf,CAAC;gBACI,aAAa,GAAG,IAAA,2CAA4B,EACjD,aAAa,CAAC,IAAI,EAClB,eAAe,CACf,CAAC;gBAEF,sBAAO,IAAA,0CAA+B,EACrC,aAAa,EACb;wBACC,IAAI,EAAE,EAAE,mBAAmB,qBAAA,EAAE,aAAa,eAAA,EAAE;qBAC5C,EACD,SAAS,CACT,EAAC;aACF;YAED,oEAAoE;YACpE,+CAA+C;YAC/C,sBAAO,IAAA,0CAA+B,EAAC,aAAa,EAAE,EAAE,EAAE,SAAS,CAAC,EAAC;;;CACrE,CAAC;AA3CU,QAAA,2BAA2B,+BA2CrC"}
@@ -16,11 +16,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.createCookieStorageAdapterFromNextServerContext = exports.DATE_IN_THE_PAST = void 0;
17
17
  var server_1 = require("next/server");
18
18
  var adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
19
- var http_1 = require("http");
20
19
  exports.DATE_IN_THE_PAST = new Date(0);
21
20
  var createCookieStorageAdapterFromNextServerContext = function (context) {
22
- var _a = context, request = _a.request, response = _a.response;
23
- if (request instanceof server_1.NextRequest && response) {
21
+ var _a = context, req = _a.request, res = _a.response;
22
+ // When the server context is from `getServerSideProps`, the `req` is an instance
23
+ // of IncomingMessage, and the `res` is an instance of ServerResponse.
24
+ // We cannot import these two classes here from `http` as it breaks in Next
25
+ // Edge Runtime. Hence, we check the methods that we need to use for creating
26
+ // cookie adapter.
27
+ if (req &&
28
+ res &&
29
+ Object.prototype.toString.call(req.cookies) === '[object Object]' &&
30
+ typeof res.setHeader === 'function') {
31
+ return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
32
+ }
33
+ var _b = context, request = _b.request, response = _b.response;
34
+ // When the server context is from `middleware`, the `request` is an instance
35
+ // of `NextRequest`.
36
+ // When the server context is from a route handler, the `request` is an `Proxy`
37
+ // wrapped `Request`.
38
+ // The `NextRequest` and the `Proxy` are sharing the same interface by Next
39
+ // implementation. So we don't need to detect the difference.
40
+ if (request && response) {
24
41
  if (response instanceof server_1.NextResponse) {
25
42
  return createCookieStorageAdapterFromNextRequestAndNextResponse(request, response);
26
43
  }
@@ -32,10 +49,6 @@ var createCookieStorageAdapterFromNextServerContext = function (context) {
32
49
  if (typeof cookies === 'function') {
33
50
  return createCookieStorageAdapterFromNextCookies(cookies);
34
51
  }
35
- var _b = context, req = _b.request, res = _b.response;
36
- if (req instanceof http_1.IncomingMessage && res instanceof http_1.ServerResponse) {
37
- return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
38
- }
39
52
  // This should not happen normally.
40
53
  throw new adapter_core_1.AmplifyServerContextError({
41
54
  message: 'Attempted to create cookie storage adapter from an unsupported Next.js server context.',
@@ -1 +1 @@
1
- {"version":3,"file":"createCookieStorageAdapterFromNextServerContext.js","sourceRoot":"","sources":["../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;AAEtC,sCAAwD;AAExD,yEAGkD;AAClD,6BAAuD;AAE1C,QAAA,gBAAgB,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;AAErC,IAAM,+CAA+C,GAAG,UAC9D,OAA2B;IAErB,IAAA,KAAwB,OAEa,EAFnC,OAAO,aAAA,EAAE,QAAQ,cAEkB,CAAC;IAE5C,IAAI,OAAO,YAAY,oBAAW,IAAI,QAAQ,EAAE;QAC/C,IAAI,QAAQ,YAAY,qBAAY,EAAE;YACrC,OAAO,wDAAwD,CAC9D,OAAO,EACP,QAAQ,CACR,CAAC;SACF;aAAM;YACN,OAAO,wDAAwD,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AAO,OAAhD,EAAE,MAAM,GAAiC,OAAO,OAAxC,EAAE,QAAQ,GAAuB,OAAO,SAA9B,EAAE,QAAQ,GAAa,OAAO,SAApB,EAAE,MAAM,GAAK,OAAO,OAAZ,CAAa;IACxE,IAAM,iBAAiB,GAAa,EAAE,CAAC;IACvC,IAAI,MAAM,EAAE;QACX,iBAAiB,CAAC,IAAI,CAAC,iBAAU,MAAM,CAAE,CAAC,CAAC;KAC3C;IACD,IAAI,OAAO,EAAE;QACZ,iBAAiB,CAAC,IAAI,CAAC,kBAAW,OAAO,CAAC,WAAW,EAAE,CAAE,CAAC,CAAC;KAC3D;IACD,IAAI,QAAQ,EAAE;QACb,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KACnC;IACD,IAAI,QAAQ,EAAE;QACb,iBAAiB,CAAC,IAAI,CAAC,mBAAY,QAAQ,CAAE,CAAC,CAAC;KAC/C;IACD,IAAI,MAAM,EAAE;QACX,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KACjC;IACD,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC,CAAC"}
1
+ {"version":3,"file":"createCookieStorageAdapterFromNextServerContext.js","sourceRoot":"","sources":["../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;AAEtC,sCAAwD;AAExD,yEAGkD;AAErC,QAAA,gBAAgB,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;AAErC,IAAM,+CAA+C,GAAG,UAC9D,OAA2B;IAErB,IAAA,KACL,OAAwD,EADxC,GAAG,aAAA,EAAY,GAAG,cACsB,CAAC;IAE1D,iFAAiF;IACjF,sEAAsE;IACtE,2EAA2E;IAC3E,6EAA6E;IAC7E,kBAAkB;IAClB,IACC,GAAG;QACH,GAAG;QACH,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,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YAAY,EACZ,UAAG,IAAI,uBAAa,wBAAgB,CAAC,WAAW,EAAE,CAAE,CACpD,CAAC;IACH,CAAC,CAAC;IACF,OAAO;QACN,GAAG,EAAE,OAAO;QACZ,MAAM,EAAE,UAAU;KAClB,CAAC;AACH,CAAC,CAAC;AAEF,IAAM,yBAAyB,GAAG,UACjC,OAAuC;IAE/B,IAAA,OAAO,GAAiD,OAAO,QAAxD,EAAE,MAAM,GAAyC,OAAO,OAAhD,EAAE,MAAM,GAAiC,OAAO,OAAxC,EAAE,QAAQ,GAAuB,OAAO,SAA9B,EAAE,QAAQ,GAAa,OAAO,SAApB,EAAE,MAAM,GAAK,OAAO,OAAZ,CAAa;IACxE,IAAM,iBAAiB,GAAa,EAAE,CAAC;IACvC,IAAI,MAAM,EAAE;QACX,iBAAiB,CAAC,IAAI,CAAC,iBAAU,MAAM,CAAE,CAAC,CAAC;KAC3C;IACD,IAAI,OAAO,EAAE;QACZ,iBAAiB,CAAC,IAAI,CAAC,kBAAW,OAAO,CAAC,WAAW,EAAE,CAAE,CAAC,CAAC;KAC3D;IACD,IAAI,QAAQ,EAAE;QACb,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KACnC;IACD,IAAI,QAAQ,EAAE;QACb,iBAAiB,CAAC,IAAI,CAAC,mBAAY,QAAQ,CAAE,CAAC,CAAC;KAC/C;IACD,IAAI,MAAM,EAAE;QACX,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KACjC;IACD,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC,CAAC"}
@@ -1,2 +1,2 @@
1
- import { ResourcesConfig } from '@aws-amplify/core';
1
+ import { ResourcesConfig } from 'aws-amplify';
2
2
  export declare const getAmplifyConfig: () => ResourcesConfig;
@@ -1,9 +1,22 @@
1
- import { ResourcesConfig } from '@aws-amplify/core';
1
+ import { ResourcesConfig } from 'aws-amplify';
2
2
  import { NextConfig } from 'next';
3
3
  /**
4
4
  * Merges the `amplifyConfig` into the `nextConfig.env`.
5
+ *
5
6
  * @param nextConfig The next config for a Next.js app.
6
- * @param amplifyConfig
7
+ * @param amplifyConfig The Amplify configuration.
8
+ *
9
+ * **NOTE**: If you are using Amplify CLI to generate the `aws-exports.js`
10
+ * file, you need to use {@link parseAmplifyConfig} to reformat the configuration.
11
+ * E.g.
12
+ * ```javascript
13
+ * const { parseAmplifyConfig } = require('aws-amplify');
14
+ * const { withAmplify } = require('@aws-amplify/adapter-nextjs/with-amplify');
15
+ * const config = require('./src/aws-exports');
16
+ *
17
+ * const nextConfig = {};
18
+ * module.exports = withAmplify(nextConfig, parseAmplifyConfig(config));
19
+ * ```
7
20
  * @returns The updated `nextConfig`.
8
21
  */
9
22
  export declare const withAmplify: (nextConfig: NextConfig, amplifyConfig: ResourcesConfig) => NextConfig;
@@ -19,14 +19,25 @@ exports.withAmplify = void 0;
19
19
  // is not being transpiled by Next.js.
20
20
  /**
21
21
  * Merges the `amplifyConfig` into the `nextConfig.env`.
22
+ *
22
23
  * @param nextConfig The next config for a Next.js app.
23
- * @param amplifyConfig
24
+ * @param amplifyConfig The Amplify configuration.
25
+ *
26
+ * **NOTE**: If you are using Amplify CLI to generate the `aws-exports.js`
27
+ * file, you need to use {@link parseAmplifyConfig} to reformat the configuration.
28
+ * E.g.
29
+ * ```javascript
30
+ * const { parseAmplifyConfig } = require('aws-amplify');
31
+ * const { withAmplify } = require('@aws-amplify/adapter-nextjs/with-amplify');
32
+ * const config = require('./src/aws-exports');
33
+ *
34
+ * const nextConfig = {};
35
+ * module.exports = withAmplify(nextConfig, parseAmplifyConfig(config));
36
+ * ```
24
37
  * @returns The updated `nextConfig`.
25
38
  */
26
39
  var withAmplify = function (nextConfig, amplifyConfig) {
27
- nextConfig.env = __assign(__assign({}, nextConfig.env), {
28
- // TODO(Hui): follow up the validation of the amplifyConfig.
29
- amplifyConfig: JSON.stringify(amplifyConfig) });
40
+ nextConfig.env = __assign(__assign({}, nextConfig.env), { amplifyConfig: JSON.stringify(amplifyConfig) });
30
41
  return nextConfig;
31
42
  };
32
43
  exports.withAmplify = withAmplify;
@@ -1 +1 @@
1
- {"version":3,"file":"withAmplify.js","sourceRoot":"","sources":["../src/withAmplify.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;AAKtC,oEAAoE;AACpE,2EAA2E;AAC3E,sCAAsC;AAEtC;;;;;GAKG;AACI,IAAM,WAAW,GAAG,UAC1B,UAAsB,EACtB,aAA8B;IAE9B,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG;QACjB,4DAA4D;QAC5D,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAC5C,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AAXW,QAAA,WAAW,eAWtB"}
1
+ {"version":3,"file":"withAmplify.js","sourceRoot":"","sources":["../src/withAmplify.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;AAKtC,oEAAoE;AACpE,2EAA2E;AAC3E,sCAAsC;AAEtC;;;;;;;;;;;;;;;;;;GAkBG;AACI,IAAM,WAAW,GAAG,UAC1B,UAAsB,EACtB,aAA8B;IAE9B,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG,KACjB,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAC5C,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AAVW,QAAA,WAAW,eAUtB"}
@@ -48,12 +48,13 @@ export var runWithAmplifyServerContext = function (_a) {
48
48
  // When the Auth config is presented, attempt to create a Amplify server
49
49
  // context with token and credentials provider.
50
50
  if (amplifyConfig.Auth) {
51
- keyValueStorage = nextServerContext === null
52
- ? // When `null` is passed as the value of `nextServerContext`, opt-in
53
- // unauthenticated role (primarily for static rendering). It's
54
- // safe to use the singleton `MemoryKeyValueStorage` here, as the
55
- // static rendering uses the same unauthenticated role cross-sever.
56
- MemoryKeyValueStorage
51
+ keyValueStorage =
52
+ // When `null` is passed as the value of `nextServerContext`, opt-in
53
+ // unauthenticated role (primarily for static rendering). It's
54
+ // safe to use the singleton `MemoryKeyValueStorage` here, as the
55
+ // static rendering uses the same unauthenticated role cross-sever.
56
+ nextServerContext === null
57
+ ? MemoryKeyValueStorage
57
58
  : createKeyValueStorageFromCookieStorageAdapter(createCookieStorageAdapterFromNextServerContext(nextServerContext));
58
59
  credentialsProvider = createAWSCredentialsAndIdentityIdProvider(amplifyConfig.Auth, keyValueStorage);
59
60
  tokenProvider = createUserPoolsTokenProvider(amplifyConfig.Auth, keyValueStorage);
@@ -1 +1 @@
1
- {"version":3,"file":"runWithAmplifyServerContext.js","sourceRoot":"","sources":["../src/runWithAmplifyServerContext.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtC,OAAO,EACN,+CAA+C,EAC/C,gBAAgB,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EACN,yCAAyC,EACzC,6CAA6C,EAC7C,4BAA4B,EAC5B,2BAA2B,IAAI,+BAA+B,GAC9D,MAAM,oCAAoC,CAAC;AAE5C,MAAM,CAAC,IAAM,2BAA2B,GACvC,UAAO,EAAgC;QAA9B,iBAAiB,uBAAA,EAAE,SAAS,eAAA;;;;YAM9B,aAAa,GAAG,gBAAgB,EAAE,CAAC;YAEzC,wEAAwE;YACxE,+CAA+C;YAC/C,IAAI,aAAa,CAAC,IAAI,EAAE;gBACjB,eAAe,GACpB,iBAAiB,KAAK,IAAI;oBACzB,CAAC,CAAC,oEAAoE;wBACpE,8DAA8D;wBAC9D,iEAAiE;wBACjE,mEAAmE;wBACnE,qBAAqB;oBACvB,CAAC,CAAC,6CAA6C,CAC7C,+CAA+C,CAAC,iBAAiB,CAAC,CACjE,CAAC;gBACA,mBAAmB,GAAG,yCAAyC,CACpE,aAAa,CAAC,IAAI,EAClB,eAAe,CACf,CAAC;gBACI,aAAa,GAAG,4BAA4B,CACjD,aAAa,CAAC,IAAI,EAClB,eAAe,CACf,CAAC;gBAEF,sBAAO,+BAA+B,CACrC,aAAa,EACb;wBACC,IAAI,EAAE,EAAE,mBAAmB,qBAAA,EAAE,aAAa,eAAA,EAAE;qBAC5C,EACD,SAAS,CACT,EAAC;aACF;YAED,oEAAoE;YACpE,+CAA+C;YAC/C,sBAAO,+BAA+B,CAAC,aAAa,EAAE,EAAE,EAAE,SAAS,CAAC,EAAC;;;CACrE,CAAC"}
1
+ {"version":3,"file":"runWithAmplifyServerContext.js","sourceRoot":"","sources":["../src/runWithAmplifyServerContext.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtC,OAAO,EACN,+CAA+C,EAC/C,gBAAgB,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EACN,yCAAyC,EACzC,6CAA6C,EAC7C,4BAA4B,EAC5B,2BAA2B,IAAI,+BAA+B,GAC9D,MAAM,oCAAoC,CAAC;AAE5C,MAAM,CAAC,IAAM,2BAA2B,GACvC,UAAO,EAAgC;QAA9B,iBAAiB,uBAAA,EAAE,SAAS,eAAA;;;;YAM9B,aAAa,GAAG,gBAAgB,EAAE,CAAC;YAEzC,wEAAwE;YACxE,+CAA+C;YAC/C,IAAI,aAAa,CAAC,IAAI,EAAE;gBACjB,eAAe;gBACpB,oEAAoE;gBACpE,8DAA8D;gBAC9D,iEAAiE;gBACjE,mEAAmE;gBACnE,iBAAiB,KAAK,IAAI;oBACzB,CAAC,CAAC,qBAAqB;oBACvB,CAAC,CAAC,6CAA6C,CAC7C,+CAA+C,CAAC,iBAAiB,CAAC,CACjE,CAAC;gBACA,mBAAmB,GAAG,yCAAyC,CACpE,aAAa,CAAC,IAAI,EAClB,eAAe,CACf,CAAC;gBACI,aAAa,GAAG,4BAA4B,CACjD,aAAa,CAAC,IAAI,EAClB,eAAe,CACf,CAAC;gBAEF,sBAAO,+BAA+B,CACrC,aAAa,EACb;wBACC,IAAI,EAAE,EAAE,mBAAmB,qBAAA,EAAE,aAAa,eAAA,EAAE;qBAC5C,EACD,SAAS,CACT,EAAC;aACF;YAED,oEAAoE;YACpE,+CAA+C;YAC/C,sBAAO,+BAA+B,CAAC,aAAa,EAAE,EAAE,EAAE,SAAS,CAAC,EAAC;;;CACrE,CAAC"}
@@ -11,13 +11,30 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  return __assign.apply(this, arguments);
13
13
  };
14
- import { NextRequest, NextResponse } from 'next/server';
14
+ import { NextResponse } from 'next/server';
15
15
  import { AmplifyServerContextError, } from '@aws-amplify/core/internals/adapter-core';
16
- import { IncomingMessage, ServerResponse } from 'http';
17
16
  export var DATE_IN_THE_PAST = new Date(0);
18
17
  export var createCookieStorageAdapterFromNextServerContext = function (context) {
19
- var _a = context, request = _a.request, response = _a.response;
20
- if (request instanceof NextRequest && response) {
18
+ var _a = context, req = _a.request, res = _a.response;
19
+ // When the server context is from `getServerSideProps`, the `req` is an instance
20
+ // of IncomingMessage, and the `res` is an instance of ServerResponse.
21
+ // We cannot import these two classes here from `http` as it breaks in Next
22
+ // Edge Runtime. Hence, we check the methods that we need to use for creating
23
+ // cookie adapter.
24
+ if (req &&
25
+ res &&
26
+ Object.prototype.toString.call(req.cookies) === '[object Object]' &&
27
+ typeof res.setHeader === 'function') {
28
+ return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
29
+ }
30
+ var _b = context, request = _b.request, response = _b.response;
31
+ // When the server context is from `middleware`, the `request` is an instance
32
+ // of `NextRequest`.
33
+ // When the server context is from a route handler, the `request` is an `Proxy`
34
+ // wrapped `Request`.
35
+ // The `NextRequest` and the `Proxy` are sharing the same interface by Next
36
+ // implementation. So we don't need to detect the difference.
37
+ if (request && response) {
21
38
  if (response instanceof NextResponse) {
22
39
  return createCookieStorageAdapterFromNextRequestAndNextResponse(request, response);
23
40
  }
@@ -29,10 +46,6 @@ export var createCookieStorageAdapterFromNextServerContext = function (context)
29
46
  if (typeof cookies === 'function') {
30
47
  return createCookieStorageAdapterFromNextCookies(cookies);
31
48
  }
32
- var _b = context, req = _b.request, res = _b.response;
33
- if (req instanceof IncomingMessage && res instanceof ServerResponse) {
34
- return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
35
- }
36
49
  // This should not happen normally.
37
50
  throw new AmplifyServerContextError({
38
51
  message: 'Attempted to create cookie storage adapter from an unsupported Next.js server context.',
@@ -1 +1 @@
1
- {"version":3,"file":"createCookieStorageAdapterFromNextServerContext.js","sourceRoot":"","sources":["../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;AAEtC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EACN,yBAAyB,GAEzB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAEvD,MAAM,CAAC,IAAM,gBAAgB,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;AAE5C,MAAM,CAAC,IAAM,+CAA+C,GAAG,UAC9D,OAA2B;IAErB,IAAA,KAAwB,OAEa,EAFnC,OAAO,aAAA,EAAE,QAAQ,cAEkB,CAAC;IAE5C,IAAI,OAAO,YAAY,WAAW,IAAI,QAAQ,EAAE;QAC/C,IAAI,QAAQ,YAAY,YAAY,EAAE;YACrC,OAAO,wDAAwD,CAC9D,OAAO,EACP,QAAQ,CACR,CAAC;SACF;aAAM;YACN,OAAO,wDAAwD,CAC9D,OAAO,EACP,QAAQ,CACR,CAAC;SACF;KACD;IAEO,IAAA,OAAO,GAAK,OAEa,QAFlB,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AAM,GAAK,OAAO,OAAZ,CAAa;IACxE,IAAM,iBAAiB,GAAa,EAAE,CAAC;IACvC,IAAI,MAAM,EAAE;QACX,iBAAiB,CAAC,IAAI,CAAC,iBAAU,MAAM,CAAE,CAAC,CAAC;KAC3C;IACD,IAAI,OAAO,EAAE;QACZ,iBAAiB,CAAC,IAAI,CAAC,kBAAW,OAAO,CAAC,WAAW,EAAE,CAAE,CAAC,CAAC;KAC3D;IACD,IAAI,QAAQ,EAAE;QACb,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KACnC;IACD,IAAI,QAAQ,EAAE;QACb,iBAAiB,CAAC,IAAI,CAAC,mBAAY,QAAQ,CAAE,CAAC,CAAC;KAC/C;IACD,IAAI,MAAM,EAAE;QACX,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KACjC;IACD,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC,CAAC"}
1
+ {"version":3,"file":"createCookieStorageAdapterFromNextServerContext.js","sourceRoot":"","sources":["../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;AAEtC,OAAO,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EACN,yBAAyB,GAEzB,MAAM,0CAA0C,CAAC;AAElD,MAAM,CAAC,IAAM,gBAAgB,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;AAE5C,MAAM,CAAC,IAAM,+CAA+C,GAAG,UAC9D,OAA2B;IAErB,IAAA,KACL,OAAwD,EADxC,GAAG,aAAA,EAAY,GAAG,cACsB,CAAC;IAE1D,iFAAiF;IACjF,sEAAsE;IACtE,2EAA2E;IAC3E,6EAA6E;IAC7E,kBAAkB;IAClB,IACC,GAAG;QACH,GAAG;QACH,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAA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AE,CAAE,CACpD,CAAC;IACH,CAAC,CAAC;IACF,OAAO;QACN,GAAG,EAAE,OAAO;QACZ,MAAM,EAAE,UAAU;KAClB,CAAC;AACH,CAAC,CAAC;AAEF,IAAM,yBAAyB,GAAG,UACjC,OAAuC;IAE/B,IAAA,OAAO,GAAiD,OAAO,QAAxD,EAAE,MAAM,GAAyC,OAAO,OAAhD,EAAE,MAAM,GAAiC,OAAO,OAAxC,EAAE,QAAQ,GAAuB,OAAO,SAA9B,EAAE,QAAQ,GAAa,OAAO,SAApB,EAAE,MAAM,GAAK,OAAO,OAAZ,CAAa;IACxE,IAAM,iBAAiB,GAAa,EAAE,CAAC;IACvC,IAAI,MAAM,EAAE;QACX,iBAAiB,CAAC,IAAI,CAAC,iBAAU,MAAM,CAAE,CAAC,CAAC;KAC3C;IACD,IAAI,OAAO,EAAE;QACZ,iBAAiB,CAAC,IAAI,CAAC,kBAAW,OAAO,CAAC,WAAW,EAAE,CAAE,CAAC,CAAC;KAC3D;IACD,IAAI,QAAQ,EAAE;QACb,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KACnC;IACD,IAAI,QAAQ,EAAE;QACb,iBAAiB,CAAC,IAAI,CAAC,mBAAY,QAAQ,CAAE,CAAC,CAAC;KAC/C;IACD,IAAI,MAAM,EAAE;QACX,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KACjC;IACD,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC,CAAC"}
@@ -1,2 +1,2 @@
1
- import { ResourcesConfig } from '@aws-amplify/core';
1
+ import { ResourcesConfig } from 'aws-amplify';
2
2
  export declare const getAmplifyConfig: () => ResourcesConfig;
@@ -1,9 +1,22 @@
1
- import { ResourcesConfig } from '@aws-amplify/core';
1
+ import { ResourcesConfig } from 'aws-amplify';
2
2
  import { NextConfig } from 'next';
3
3
  /**
4
4
  * Merges the `amplifyConfig` into the `nextConfig.env`.
5
+ *
5
6
  * @param nextConfig The next config for a Next.js app.
6
- * @param amplifyConfig
7
+ * @param amplifyConfig The Amplify configuration.
8
+ *
9
+ * **NOTE**: If you are using Amplify CLI to generate the `aws-exports.js`
10
+ * file, you need to use {@link parseAmplifyConfig} to reformat the configuration.
11
+ * E.g.
12
+ * ```javascript
13
+ * const { parseAmplifyConfig } = require('aws-amplify');
14
+ * const { withAmplify } = require('@aws-amplify/adapter-nextjs/with-amplify');
15
+ * const config = require('./src/aws-exports');
16
+ *
17
+ * const nextConfig = {};
18
+ * module.exports = withAmplify(nextConfig, parseAmplifyConfig(config));
19
+ * ```
7
20
  * @returns The updated `nextConfig`.
8
21
  */
9
22
  export declare const withAmplify: (nextConfig: NextConfig, amplifyConfig: ResourcesConfig) => NextConfig;
@@ -16,14 +16,25 @@ var __assign = (this && this.__assign) || function () {
16
16
  // is not being transpiled by Next.js.
17
17
  /**
18
18
  * Merges the `amplifyConfig` into the `nextConfig.env`.
19
+ *
19
20
  * @param nextConfig The next config for a Next.js app.
20
- * @param amplifyConfig
21
+ * @param amplifyConfig The Amplify configuration.
22
+ *
23
+ * **NOTE**: If you are using Amplify CLI to generate the `aws-exports.js`
24
+ * file, you need to use {@link parseAmplifyConfig} to reformat the configuration.
25
+ * E.g.
26
+ * ```javascript
27
+ * const { parseAmplifyConfig } = require('aws-amplify');
28
+ * const { withAmplify } = require('@aws-amplify/adapter-nextjs/with-amplify');
29
+ * const config = require('./src/aws-exports');
30
+ *
31
+ * const nextConfig = {};
32
+ * module.exports = withAmplify(nextConfig, parseAmplifyConfig(config));
33
+ * ```
21
34
  * @returns The updated `nextConfig`.
22
35
  */
23
36
  export var withAmplify = function (nextConfig, amplifyConfig) {
24
- nextConfig.env = __assign(__assign({}, nextConfig.env), {
25
- // TODO(Hui): follow up the validation of the amplifyConfig.
26
- amplifyConfig: JSON.stringify(amplifyConfig) });
37
+ nextConfig.env = __assign(__assign({}, nextConfig.env), { amplifyConfig: JSON.stringify(amplifyConfig) });
27
38
  return nextConfig;
28
39
  };
29
40
  //# sourceMappingURL=withAmplify.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"withAmplify.js","sourceRoot":"","sources":["../src/withAmplify.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;AAKtC,oEAAoE;AACpE,2EAA2E;AAC3E,sCAAsC;AAEtC;;;;;GAKG;AACH,MAAM,CAAC,IAAM,WAAW,GAAG,UAC1B,UAAsB,EACtB,aAA8B;IAE9B,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG;QACjB,4DAA4D;QAC5D,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAC5C,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC"}
1
+ {"version":3,"file":"withAmplify.js","sourceRoot":"","sources":["../src/withAmplify.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;AAKtC,oEAAoE;AACpE,2EAA2E;AAC3E,sCAAsC;AAEtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,IAAM,WAAW,GAAG,UAC1B,UAAsB,EACtB,aAA8B;IAE9B,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG,KACjB,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAC5C,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC"}
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "@types/node": "^20.3.1",
16
16
  "@types/react": "^18.2.13",
17
17
  "@types/react-dom": "^18.2.6",
18
- "aws-amplify": "6.0.1-console-preview.9e7dd78.0+9e7dd78",
18
+ "aws-amplify": "6.0.1-console-preview.957cda4.0+957cda4",
19
19
  "jest-fetch-mock": "3.0.3",
20
20
  "next": ">= 13.4.0 < 14.0.0",
21
21
  "typescript": "5.1.6"
@@ -91,6 +91,7 @@
91
91
  "license": "Apache-2.0",
92
92
  "main": "./lib/index.js",
93
93
  "module": "./lib-esm/index.js",
94
+ "sideEffects": false,
94
95
  "scripts": {
95
96
  "build": "npm run clean && npm run build:esm && npm run build:cjs",
96
97
  "build-with-test": "npm test && npm run build",
@@ -106,6 +107,6 @@
106
107
  "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
107
108
  },
108
109
  "typings": "./lib-esm/index.d.ts",
109
- "version": "0.0.2-console-preview.9e7dd78.0+9e7dd78",
110
- "gitHead": "9e7dd781153ee752b028aaafc777bef8e0cc4528"
110
+ "version": "0.0.2-console-preview.957cda4.0+957cda4",
111
+ "gitHead": "957cda4161ffdf663890650e52d032f64197b67a"
111
112
  }
@@ -27,12 +27,12 @@ export const runWithAmplifyServerContext: NextServer.RunOperationWithContext =
27
27
  // context with token and credentials provider.
28
28
  if (amplifyConfig.Auth) {
29
29
  const keyValueStorage =
30
+ // When `null` is passed as the value of `nextServerContext`, opt-in
31
+ // unauthenticated role (primarily for static rendering). It's
32
+ // safe to use the singleton `MemoryKeyValueStorage` here, as the
33
+ // static rendering uses the same unauthenticated role cross-sever.
30
34
  nextServerContext === null
31
- ? // When `null` is passed as the value of `nextServerContext`, opt-in
32
- // unauthenticated role (primarily for static rendering). It's
33
- // safe to use the singleton `MemoryKeyValueStorage` here, as the
34
- // static rendering uses the same unauthenticated role cross-sever.
35
- MemoryKeyValueStorage
35
+ ? MemoryKeyValueStorage
36
36
  : createKeyValueStorageFromCookieStorageAdapter(
37
37
  createCookieStorageAdapterFromNextServerContext(nextServerContext)
38
38
  );
@@ -7,18 +7,41 @@ import {
7
7
  AmplifyServerContextError,
8
8
  CookieStorage,
9
9
  } from '@aws-amplify/core/internals/adapter-core';
10
- import { IncomingMessage, ServerResponse } from 'http';
11
10
 
12
11
  export const DATE_IN_THE_PAST = new Date(0);
13
12
 
14
13
  export const createCookieStorageAdapterFromNextServerContext = (
15
14
  context: NextServer.Context
16
15
  ): CookieStorage.Adapter => {
17
- const { request, response } = context as
18
- | NextServer.NextRequestAndNextResponseContext
19
- | NextServer.NextRequestAndResponseContext;
16
+ const { request: req, response: res } =
17
+ context as Partial<NextServer.GetServerSidePropsContext>;
18
+
19
+ // When the server context is from `getServerSideProps`, the `req` is an instance
20
+ // of IncomingMessage, and the `res` is an instance of ServerResponse.
21
+ // We cannot import these two classes here from `http` as it breaks in Next
22
+ // Edge Runtime. Hence, we check the methods that we need to use for creating
23
+ // cookie adapter.
24
+ if (
25
+ req &&
26
+ res &&
27
+ Object.prototype.toString.call(req.cookies) === '[object Object]' &&
28
+ typeof res.setHeader === 'function'
29
+ ) {
30
+ return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
31
+ }
20
32
 
21
- if (request instanceof NextRequest && response) {
33
+ const { request, response } = context as Partial<
34
+ | NextServer.NextRequestAndNextResponseContext
35
+ | NextServer.NextRequestAndResponseContext
36
+ >;
37
+
38
+ // When the server context is from `middleware`, the `request` is an instance
39
+ // of `NextRequest`.
40
+ // When the server context is from a route handler, the `request` is an `Proxy`
41
+ // wrapped `Request`.
42
+ // The `NextRequest` and the `Proxy` are sharing the same interface by Next
43
+ // implementation. So we don't need to detect the difference.
44
+ if (request && response) {
22
45
  if (response instanceof NextResponse) {
23
46
  return createCookieStorageAdapterFromNextRequestAndNextResponse(
24
47
  request,
@@ -32,21 +55,14 @@ export const createCookieStorageAdapterFromNextServerContext = (
32
55
  }
33
56
  }
34
57
 
35
- const { cookies } = context as
36
- | NextServer.ServerComponentContext
37
- | NextServer.ServerActionContext;
58
+ const { cookies } = context as Partial<
59
+ NextServer.ServerComponentContext | NextServer.ServerActionContext
60
+ >;
38
61
 
39
62
  if (typeof cookies === 'function') {
40
63
  return createCookieStorageAdapterFromNextCookies(cookies);
41
64
  }
42
65
 
43
- const { request: req, response: res } =
44
- context as NextServer.GetServerSidePropsContext;
45
-
46
- if (req instanceof IncomingMessage && res instanceof ServerResponse) {
47
- return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
48
- }
49
-
50
66
  // This should not happen normally.
51
67
  throw new AmplifyServerContextError({
52
68
  message:
@@ -1,7 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { ResourcesConfig } from '@aws-amplify/core';
4
+ import { ResourcesConfig } from 'aws-amplify';
5
5
  import { AmplifyServerContextError } from '@aws-amplify/core/internals/adapter-core';
6
6
 
7
7
  export const getAmplifyConfig = (): ResourcesConfig => {
@@ -1,7 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { ResourcesConfig } from '@aws-amplify/core';
4
+ import { ResourcesConfig, parseAmplifyConfig } from 'aws-amplify';
5
5
  import { NextConfig } from 'next';
6
6
 
7
7
  // NOTE: this function is exported from the subpath `/with-amplify`.
@@ -10,8 +10,21 @@ import { NextConfig } from 'next';
10
10
 
11
11
  /**
12
12
  * Merges the `amplifyConfig` into the `nextConfig.env`.
13
+ *
13
14
  * @param nextConfig The next config for a Next.js app.
14
- * @param amplifyConfig
15
+ * @param amplifyConfig The Amplify configuration.
16
+ *
17
+ * **NOTE**: If you are using Amplify CLI to generate the `aws-exports.js`
18
+ * file, you need to use {@link parseAmplifyConfig} to reformat the configuration.
19
+ * E.g.
20
+ * ```javascript
21
+ * const { parseAmplifyConfig } = require('aws-amplify');
22
+ * const { withAmplify } = require('@aws-amplify/adapter-nextjs/with-amplify');
23
+ * const config = require('./src/aws-exports');
24
+ *
25
+ * const nextConfig = {};
26
+ * module.exports = withAmplify(nextConfig, parseAmplifyConfig(config));
27
+ * ```
15
28
  * @returns The updated `nextConfig`.
16
29
  */
17
30
  export const withAmplify = (
@@ -20,7 +33,6 @@ export const withAmplify = (
20
33
  ) => {
21
34
  nextConfig.env = {
22
35
  ...nextConfig.env,
23
- // TODO(Hui): follow up the validation of the amplifyConfig.
24
36
  amplifyConfig: JSON.stringify(amplifyConfig),
25
37
  };
26
38