@aws-amplify/adapter-nextjs 0.0.2-console-preview.957cda4.0 → 0.0.2-console-preview.d7e0545.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/lib/utils/getAmplifyConfig.js +12 -0
- package/lib/utils/getAmplifyConfig.js.map +1 -1
- package/lib/withAmplify.js +3 -1
- package/lib/withAmplify.js.map +1 -1
- package/lib-esm/utils/getAmplifyConfig.js +9 -0
- package/lib-esm/utils/getAmplifyConfig.js.map +1 -1
- package/lib-esm/withAmplify.js +3 -1
- package/lib-esm/withAmplify.js.map +1 -1
- package/package.json +3 -3
- package/src/utils/getAmplifyConfig.ts +11 -1
- package/src/withAmplify.ts +7 -1
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
4
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
8
|
exports.getAmplifyConfig = void 0;
|
|
6
9
|
var adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
10
|
+
var config_1 = __importDefault(require("next/config"));
|
|
7
11
|
var getAmplifyConfig = function () {
|
|
8
12
|
var configStr = process.env.amplifyConfig;
|
|
13
|
+
// With a Next.js app that uses the Pages Router, the key-value pairs
|
|
14
|
+
// listed under the `env` field in the `next.config.js` is not accessible
|
|
15
|
+
// via process.env.<key> at some occasion. Using the following as a fallback
|
|
16
|
+
// See: https://github.com/vercel/next.js/issues/39299
|
|
17
|
+
if (!configStr) {
|
|
18
|
+
var serverRuntimeConfig = (0, config_1.default)().serverRuntimeConfig;
|
|
19
|
+
configStr = serverRuntimeConfig === null || serverRuntimeConfig === void 0 ? void 0 : serverRuntimeConfig.amplifyConfig;
|
|
20
|
+
}
|
|
9
21
|
if (!configStr) {
|
|
10
22
|
throw new adapter_core_1.AmplifyServerContextError({
|
|
11
23
|
message: 'Amplify configuration is missing from `process.env`.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAmplifyConfig.js","sourceRoot":"","sources":["../../src/utils/getAmplifyConfig.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC
|
|
1
|
+
{"version":3,"file":"getAmplifyConfig.js","sourceRoot":"","sources":["../../src/utils/getAmplifyConfig.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;AAGtC,yEAAqF;AACrF,uDAAoC;AAE7B,IAAM,gBAAgB,GAAG;IAC/B,IAAI,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IAE1C,qEAAqE;IACrE,yEAAyE;IACzE,4EAA4E;IAC5E,sDAAsD;IACtD,IAAI,CAAC,SAAS,EAAE;QACP,IAAA,mBAAmB,GAAK,IAAA,gBAAS,GAAE,oBAAhB,CAAiB;QAC5C,SAAS,GAAG,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,aAAa,CAAC;KAC/C;IAED,IAAI,CAAC,SAAS,EAAE;QACf,MAAM,IAAI,wCAAyB,CAAC;YACnC,OAAO,EAAE,sDAAsD;YAC/D,kBAAkB,EACjB,gEAAgE;SACjE,CAAC,CAAC;KACH;IAED,IAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE3C,gEAAgE;IAChE,OAAO,YAAY,CAAC;AACrB,CAAC,CAAC;AAxBW,QAAA,gBAAgB,oBAwB3B"}
|
package/lib/withAmplify.js
CHANGED
|
@@ -37,7 +37,9 @@ exports.withAmplify = void 0;
|
|
|
37
37
|
* @returns The updated `nextConfig`.
|
|
38
38
|
*/
|
|
39
39
|
var withAmplify = function (nextConfig, amplifyConfig) {
|
|
40
|
-
|
|
40
|
+
var configStr = JSON.stringify(amplifyConfig);
|
|
41
|
+
nextConfig.env = __assign(__assign({}, nextConfig.env), { amplifyConfig: configStr });
|
|
42
|
+
nextConfig.serverRuntimeConfig = __assign(__assign({}, nextConfig.serverRuntimeConfig), { amplifyConfig: configStr });
|
|
41
43
|
return nextConfig;
|
|
42
44
|
};
|
|
43
45
|
exports.withAmplify = withAmplify;
|
package/lib/withAmplify.js.map
CHANGED
|
@@ -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;;;;;;;;;;;;;;;;;;GAkBG;AACI,IAAM,WAAW,GAAG,UAC1B,UAAsB,EACtB,aAA8B;IAE9B,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG,KACjB,aAAa,EAAE,
|
|
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,IAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAChD,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG,KACjB,aAAa,EAAE,SAAS,GACxB,CAAC;IAEF,UAAU,CAAC,mBAAmB,yBAC1B,UAAU,CAAC,mBAAmB,KACjC,aAAa,EAAE,SAAS,GACxB,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AAhBW,QAAA,WAAW,eAgBtB"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { AmplifyServerContextError } from '@aws-amplify/core/internals/adapter-core';
|
|
4
|
+
import getConfig from 'next/config';
|
|
4
5
|
export var getAmplifyConfig = function () {
|
|
5
6
|
var configStr = process.env.amplifyConfig;
|
|
7
|
+
// With a Next.js app that uses the Pages Router, the key-value pairs
|
|
8
|
+
// listed under the `env` field in the `next.config.js` is not accessible
|
|
9
|
+
// via process.env.<key> at some occasion. Using the following as a fallback
|
|
10
|
+
// See: https://github.com/vercel/next.js/issues/39299
|
|
11
|
+
if (!configStr) {
|
|
12
|
+
var serverRuntimeConfig = getConfig().serverRuntimeConfig;
|
|
13
|
+
configStr = serverRuntimeConfig === null || serverRuntimeConfig === void 0 ? void 0 : serverRuntimeConfig.amplifyConfig;
|
|
14
|
+
}
|
|
6
15
|
if (!configStr) {
|
|
7
16
|
throw new AmplifyServerContextError({
|
|
8
17
|
message: 'Amplify configuration is missing from `process.env`.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAmplifyConfig.js","sourceRoot":"","sources":["../../src/utils/getAmplifyConfig.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;
|
|
1
|
+
{"version":3,"file":"getAmplifyConfig.js","sourceRoot":"","sources":["../../src/utils/getAmplifyConfig.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,SAAS,MAAM,aAAa,CAAC;AAEpC,MAAM,CAAC,IAAM,gBAAgB,GAAG;IAC/B,IAAI,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IAE1C,qEAAqE;IACrE,yEAAyE;IACzE,4EAA4E;IAC5E,sDAAsD;IACtD,IAAI,CAAC,SAAS,EAAE;QACP,IAAA,mBAAmB,GAAK,SAAS,EAAE,oBAAhB,CAAiB;QAC5C,SAAS,GAAG,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,aAAa,CAAC;KAC/C;IAED,IAAI,CAAC,SAAS,EAAE;QACf,MAAM,IAAI,yBAAyB,CAAC;YACnC,OAAO,EAAE,sDAAsD;YAC/D,kBAAkB,EACjB,gEAAgE;SACjE,CAAC,CAAC;KACH;IAED,IAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE3C,gEAAgE;IAChE,OAAO,YAAY,CAAC;AACrB,CAAC,CAAC"}
|
package/lib-esm/withAmplify.js
CHANGED
|
@@ -34,7 +34,9 @@ var __assign = (this && this.__assign) || function () {
|
|
|
34
34
|
* @returns The updated `nextConfig`.
|
|
35
35
|
*/
|
|
36
36
|
export var withAmplify = function (nextConfig, amplifyConfig) {
|
|
37
|
-
|
|
37
|
+
var configStr = JSON.stringify(amplifyConfig);
|
|
38
|
+
nextConfig.env = __assign(__assign({}, nextConfig.env), { amplifyConfig: configStr });
|
|
39
|
+
nextConfig.serverRuntimeConfig = __assign(__assign({}, nextConfig.serverRuntimeConfig), { amplifyConfig: configStr });
|
|
38
40
|
return nextConfig;
|
|
39
41
|
};
|
|
40
42
|
//# 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;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,IAAM,WAAW,GAAG,UAC1B,UAAsB,EACtB,aAA8B;IAE9B,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG,KACjB,aAAa,EAAE,
|
|
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,IAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAChD,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG,KACjB,aAAa,EAAE,SAAS,GACxB,CAAC;IAEF,UAAU,CAAC,mBAAmB,yBAC1B,UAAU,CAAC,mBAAmB,KACjC,aAAa,EAAE,SAAS,GACxB,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.
|
|
18
|
+
"aws-amplify": "6.0.1-console-preview.d7e0545.0+d7e0545",
|
|
19
19
|
"jest-fetch-mock": "3.0.3",
|
|
20
20
|
"next": ">= 13.4.0 < 14.0.0",
|
|
21
21
|
"typescript": "5.1.6"
|
|
@@ -107,6 +107,6 @@
|
|
|
107
107
|
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
|
|
108
108
|
},
|
|
109
109
|
"typings": "./lib-esm/index.d.ts",
|
|
110
|
-
"version": "0.0.2-console-preview.
|
|
111
|
-
"gitHead": "
|
|
110
|
+
"version": "0.0.2-console-preview.d7e0545.0+d7e0545",
|
|
111
|
+
"gitHead": "d7e0545d6fd84eb0e3a27b3cefbab5d2a4277c45"
|
|
112
112
|
}
|
|
@@ -3,9 +3,19 @@
|
|
|
3
3
|
|
|
4
4
|
import { ResourcesConfig } from 'aws-amplify';
|
|
5
5
|
import { AmplifyServerContextError } from '@aws-amplify/core/internals/adapter-core';
|
|
6
|
+
import getConfig from 'next/config';
|
|
6
7
|
|
|
7
8
|
export const getAmplifyConfig = (): ResourcesConfig => {
|
|
8
|
-
|
|
9
|
+
let configStr = process.env.amplifyConfig;
|
|
10
|
+
|
|
11
|
+
// With a Next.js app that uses the Pages Router, the key-value pairs
|
|
12
|
+
// listed under the `env` field in the `next.config.js` is not accessible
|
|
13
|
+
// via process.env.<key> at some occasion. Using the following as a fallback
|
|
14
|
+
// See: https://github.com/vercel/next.js/issues/39299
|
|
15
|
+
if (!configStr) {
|
|
16
|
+
const { serverRuntimeConfig } = getConfig();
|
|
17
|
+
configStr = serverRuntimeConfig?.amplifyConfig;
|
|
18
|
+
}
|
|
9
19
|
|
|
10
20
|
if (!configStr) {
|
|
11
21
|
throw new AmplifyServerContextError({
|
package/src/withAmplify.ts
CHANGED
|
@@ -31,9 +31,15 @@ export const withAmplify = (
|
|
|
31
31
|
nextConfig: NextConfig,
|
|
32
32
|
amplifyConfig: ResourcesConfig
|
|
33
33
|
) => {
|
|
34
|
+
const configStr = JSON.stringify(amplifyConfig);
|
|
34
35
|
nextConfig.env = {
|
|
35
36
|
...nextConfig.env,
|
|
36
|
-
amplifyConfig:
|
|
37
|
+
amplifyConfig: configStr,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
nextConfig.serverRuntimeConfig = {
|
|
41
|
+
...nextConfig.serverRuntimeConfig,
|
|
42
|
+
amplifyConfig: configStr,
|
|
37
43
|
};
|
|
38
44
|
|
|
39
45
|
return nextConfig;
|