@aws-amplify/adapter-nextjs 0.0.2-server-generate-client.1e317a1.0 → 1.0.1-api-v6-models.c495d1b.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/internals/package.json +7 -0
- package/lib/api/createServerRunnerForAPI.d.ts +5 -0
- package/lib/api/createServerRunnerForAPI.js +17 -0
- package/lib/api/createServerRunnerForAPI.js.map +1 -0
- package/lib/api/generateServerClient.d.ts +33 -0
- package/lib/api/generateServerClient.js +80 -0
- package/lib/api/generateServerClient.js.map +1 -0
- package/lib/api/index.d.ts +1 -0
- package/lib/api/index.js +9 -0
- package/lib/api/index.js.map +1 -0
- package/lib/createServerRunner.d.ts +2 -0
- package/lib/createServerRunner.js +23 -0
- package/lib/createServerRunner.js.map +1 -0
- package/lib/index.d.ts +1 -2
- package/lib/index.js +3 -5
- package/lib/index.js.map +1 -1
- package/lib/internals/index.d.ts +2 -0
- package/lib/internals/index.js +8 -0
- package/lib/internals/index.js.map +1 -0
- package/lib/types/NextServer.d.ts +11 -0
- package/lib/utils/createCookieStorageAdapterFromNextServerContext.js +57 -69
- package/lib/utils/createCookieStorageAdapterFromNextServerContext.js.map +1 -1
- package/lib/utils/createRunWithAmplifyServerContext.d.ts +5 -0
- package/lib/utils/createRunWithAmplifyServerContext.js +35 -0
- package/lib/utils/createRunWithAmplifyServerContext.js.map +1 -0
- package/lib/utils/getAmplifyConfig.d.ts +2 -1
- package/lib/utils/getAmplifyConfig.js +4 -28
- package/lib/utils/getAmplifyConfig.js.map +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +3 -3
- package/lib/utils/index.js.map +1 -1
- package/lib-esm/api/createServerRunnerForAPI.d.ts +5 -0
- package/lib-esm/api/createServerRunnerForAPI.js +13 -0
- package/lib-esm/api/createServerRunnerForAPI.js.map +1 -0
- package/lib-esm/api/generateServerClient.d.ts +33 -0
- package/lib-esm/api/generateServerClient.js +75 -0
- package/lib-esm/api/generateServerClient.js.map +1 -0
- package/lib-esm/api/index.d.ts +1 -0
- package/lib-esm/api/index.js +4 -0
- package/lib-esm/api/index.js.map +1 -0
- package/lib-esm/createServerRunner.d.ts +2 -0
- package/lib-esm/createServerRunner.js +19 -0
- package/lib-esm/createServerRunner.js.map +1 -0
- package/lib-esm/index.d.ts +1 -2
- package/lib-esm/index.js +1 -2
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/internals/index.d.ts +2 -0
- package/lib-esm/internals/index.js +4 -0
- package/lib-esm/internals/index.js.map +1 -0
- package/lib-esm/types/NextServer.d.ts +11 -0
- package/lib-esm/utils/createCookieStorageAdapterFromNextServerContext.js +56 -68
- package/lib-esm/utils/createCookieStorageAdapterFromNextServerContext.js.map +1 -1
- package/lib-esm/utils/createRunWithAmplifyServerContext.d.ts +5 -0
- package/lib-esm/utils/createRunWithAmplifyServerContext.js +31 -0
- package/lib-esm/utils/createRunWithAmplifyServerContext.js.map +1 -0
- package/lib-esm/utils/getAmplifyConfig.d.ts +2 -1
- package/lib-esm/utils/getAmplifyConfig.js +3 -24
- package/lib-esm/utils/getAmplifyConfig.js.map +1 -1
- package/lib-esm/utils/index.d.ts +1 -1
- package/lib-esm/utils/index.js +1 -1
- package/lib-esm/utils/index.js.map +1 -1
- package/package.json +23 -15
- package/src/api/createServerRunnerForAPI.ts +21 -0
- package/src/api/generateServerClient.ts +110 -0
- package/src/api/index.ts +7 -0
- package/src/createServerRunner.ts +28 -0
- package/src/index.ts +1 -2
- package/src/internals/index.ts +5 -0
- package/src/types/NextServer.ts +14 -0
- package/src/utils/createRunWithAmplifyServerContext.ts +61 -0
- package/src/utils/getAmplifyConfig.ts +7 -29
- package/src/utils/index.ts +1 -1
- package/lib/generateServerClient.d.ts +0 -7
- package/lib/generateServerClient.js +0 -31
- package/lib/generateServerClient.js.map +0 -1
- package/lib/runWithAmplifyServerContext.d.ts +0 -45
- package/lib/runWithAmplifyServerContext.js +0 -118
- package/lib/runWithAmplifyServerContext.js.map +0 -1
- package/lib/withAmplify.d.ts +0 -12
- package/lib/withAmplify.js +0 -35
- package/lib/withAmplify.js.map +0 -1
- package/lib-esm/generateServerClient.d.ts +0 -7
- package/lib-esm/generateServerClient.js +0 -27
- package/lib-esm/generateServerClient.js.map +0 -1
- package/lib-esm/runWithAmplifyServerContext.d.ts +0 -45
- package/lib-esm/runWithAmplifyServerContext.js +0 -114
- package/lib-esm/runWithAmplifyServerContext.js.map +0 -1
- package/lib-esm/withAmplify.d.ts +0 -12
- package/lib-esm/withAmplify.js +0 -31
- package/lib-esm/withAmplify.js.map +0 -1
- package/src/generateServerClient.ts +0 -39
- package/src/runWithAmplifyServerContext.ts +0 -103
- package/src/withAmplify.ts +0 -36
- package/with-amplify/package.json +0 -7
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ResourcesConfig } from '@aws-amplify/core';
|
|
2
|
+
import { NextServer } from '../types';
|
|
3
|
+
export declare const createServerRunnerForAPI: ({ config, }: NextServer.CreateServerRunnerInput) => NextServer.CreateServerRunnerOutput & {
|
|
4
|
+
resourcesConfig: ResourcesConfig;
|
|
5
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.createServerRunnerForAPI = void 0;
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const createServerRunnerForAPI = ({ config, }) => {
|
|
8
|
+
const amplifyConfig = (0, utils_1.getAmplifyConfig)(config);
|
|
9
|
+
return {
|
|
10
|
+
runWithAmplifyServerContext: (0, utils_1.createRunWithAmplifyServerContext)({
|
|
11
|
+
config: amplifyConfig,
|
|
12
|
+
}),
|
|
13
|
+
resourcesConfig: amplifyConfig,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.createServerRunnerForAPI = createServerRunnerForAPI;
|
|
17
|
+
//# sourceMappingURL=createServerRunnerForAPI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createServerRunnerForAPI.js","sourceRoot":"","sources":["../../src/api/createServerRunnerForAPI.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAGtC,oCAA+E;AAGxE,MAAM,wBAAwB,GAAG,CAAC,EACxC,MAAM,GAC8B,EAEnC,EAAE;IACH,MAAM,aAAa,GAAG,IAAA,wBAAgB,EAAC,MAAM,CAAC,CAAC;IAE/C,OAAO;QACN,2BAA2B,EAAE,IAAA,yCAAiC,EAAC;YAC9D,MAAM,EAAE,aAAa;SACrB,CAAC;QACF,eAAe,EAAE,aAAa;KAC9B,CAAC;AACH,CAAC,CAAC;AAbW,QAAA,wBAAwB,4BAanC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { V6ClientSSRRequest, V6ClientSSRCookies } from '@aws-amplify/api-graphql';
|
|
2
|
+
import { NextServer } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Generates an API client that can be used inside a Next.js Server Component with Dynamic Rendering
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { cookies } from "next/headers"
|
|
9
|
+
*
|
|
10
|
+
* const client = generateServerClientUsingCookies({ cookies })
|
|
11
|
+
* const result = await client.graphql({query: listPosts})
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function generateServerClientUsingCookies<T extends Record<any, any> = never>({ config, cookies, }: NextServer.ServerComponentContext & NextServer.CreateServerRunnerInput): V6ClientSSRCookies<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Generates an API client that can be used with both Pages Router and App Router
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
*
|
|
21
|
+
* const client = generateServerClient()
|
|
22
|
+
*
|
|
23
|
+
* result = await runWithAmplifyServerContext({
|
|
24
|
+
nextServerContext: { request, response },
|
|
25
|
+
operation: async (contextSpec) => {
|
|
26
|
+
return await client.graphql(contextSpec, {
|
|
27
|
+
query: listPosts,
|
|
28
|
+
})
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function generateServerClientUsingReqRes<T extends Record<any, any> = never>({ config }: NextServer.CreateServerRunnerInput): V6ClientSSRRequest<T>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.generateServerClientUsingReqRes = exports.generateServerClientUsingCookies = void 0;
|
|
6
|
+
const server_1 = require("@aws-amplify/api/server");
|
|
7
|
+
const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
8
|
+
const api_graphql_1 = require("@aws-amplify/api-graphql");
|
|
9
|
+
const createServerRunnerForAPI_1 = require("./createServerRunnerForAPI");
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
/**
|
|
12
|
+
* Generates an API client that can be used inside a Next.js Server Component with Dynamic Rendering
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { cookies } from "next/headers"
|
|
17
|
+
*
|
|
18
|
+
* const client = generateServerClientUsingCookies({ cookies })
|
|
19
|
+
* const result = await client.graphql({query: listPosts})
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function generateServerClientUsingCookies({ config, cookies, }) {
|
|
23
|
+
if (typeof cookies !== 'function') {
|
|
24
|
+
throw new adapter_core_1.AmplifyServerContextError({
|
|
25
|
+
message: 'generateServerClientUsingCookies is only compatible with the `cookies` Dynamic Function available in Server Components.',
|
|
26
|
+
// TODO: link to docs
|
|
27
|
+
recoverySuggestion: 'use `generateServerClient` inside of `runWithAmplifyServerContext` with the `request` object.',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const { runWithAmplifyServerContext, resourcesConfig } = (0, createServerRunnerForAPI_1.createServerRunnerForAPI)({ config });
|
|
31
|
+
// This function reference gets passed down to InternalGraphQLAPI.ts.graphql
|
|
32
|
+
// where this._graphql is passed in as the `fn` argument
|
|
33
|
+
// causing it to always get invoked inside `runWithAmplifyServerContext`
|
|
34
|
+
const getAmplify = (fn) => runWithAmplifyServerContext({
|
|
35
|
+
nextServerContext: { cookies },
|
|
36
|
+
operation: contextSpec => fn((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify),
|
|
37
|
+
});
|
|
38
|
+
return (0, server_1.generateClient)({
|
|
39
|
+
amplify: getAmplify,
|
|
40
|
+
config: resourcesConfig,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.generateServerClientUsingCookies = generateServerClientUsingCookies;
|
|
44
|
+
/**
|
|
45
|
+
* Generates an API client that can be used with both Pages Router and App Router
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
*
|
|
50
|
+
* const client = generateServerClient()
|
|
51
|
+
*
|
|
52
|
+
* result = await runWithAmplifyServerContext({
|
|
53
|
+
nextServerContext: { request, response },
|
|
54
|
+
operation: async (contextSpec) => {
|
|
55
|
+
return await client.graphql(contextSpec, {
|
|
56
|
+
query: listPosts,
|
|
57
|
+
})
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
function generateServerClientUsingReqRes({ config }) {
|
|
63
|
+
const amplifyConfig = (0, utils_1.getAmplifyConfig)(config);
|
|
64
|
+
// passing `null` instance because each (future model) method must retrieve a valid instance
|
|
65
|
+
// from server context
|
|
66
|
+
const client = (0, server_1.generateClient)({
|
|
67
|
+
amplify: null,
|
|
68
|
+
config: amplifyConfig,
|
|
69
|
+
});
|
|
70
|
+
// TODO: improve this and the next type
|
|
71
|
+
const prevGraphql = client.graphql;
|
|
72
|
+
const wrappedGraphql = (contextSpec, options, additionalHeaders) => {
|
|
73
|
+
const amplifyInstance = (0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify;
|
|
74
|
+
return prevGraphql.call({ [api_graphql_1.__amplify]: amplifyInstance }, options, additionalHeaders);
|
|
75
|
+
};
|
|
76
|
+
client.graphql = wrappedGraphql;
|
|
77
|
+
return client;
|
|
78
|
+
}
|
|
79
|
+
exports.generateServerClientUsingReqRes = generateServerClientUsingReqRes;
|
|
80
|
+
//# sourceMappingURL=generateServerClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateServerClient.js","sourceRoot":"","sources":["../../src/api/generateServerClient.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAEtC,oDAAmF;AACnF,2EAGkD;AAClD,0DAMkC;AAElC,yEAAsE;AACtE,oCAA4C;AAE5C;;;;;;;;;;GAUG;AACH,SAAgB,gCAAgC,CAE9C,EACD,MAAM,EACN,OAAO,GAE2B;IAClC,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;QAClC,MAAM,IAAI,wCAAyB,CAAC;YACnC,OAAO,EACN,yHAAyH;YAC1H,qBAAqB;YACrB,kBAAkB,EACjB,+FAA+F;SAChG,CAAC,CAAC;KACH;IAED,MAAM,EAAE,2BAA2B,EAAE,eAAe,EAAE,GACrD,IAAA,mDAAwB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAEtC,4EAA4E;IAC5E,wDAAwD;IACxD,wEAAwE;IACxE,MAAM,UAAU,GAAG,CAAC,EAAkC,EAAE,EAAE,CACzD,2BAA2B,CAAC;QAC3B,iBAAiB,EAAE,EAAE,OAAO,EAAE;QAC9B,SAAS,EAAE,WAAW,CAAC,EAAE,CACxB,EAAE,CAAC,IAAA,sCAAuB,EAAC,WAAW,CAAC,CAAC,OAAO,CAAC;KACjD,CAAC,CAAC;IAEJ,OAAO,IAAA,uBAAsB,EAA2B;QACvD,OAAO,EAAE,UAAU;QACnB,MAAM,EAAE,eAAe;KACvB,CAAC,CAAC;AACJ,CAAC;AAlCD,4EAkCC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,+BAA+B,CAE7C,EAAE,MAAM,EAAsC;IAC/C,MAAM,aAAa,GAAG,IAAA,wBAAgB,EAAC,MAAM,CAAC,CAAC;IAC/C,4FAA4F;IAC5F,sBAAsB;IACtB,MAAM,MAAM,GAAG,IAAA,uBAAsB,EAA2B;QAC/D,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,aAAa;KACrB,CAAC,CAAC;IAEH,uCAAuC;IACvC,MAAM,WAAW,GAAG,MAAM,CAAC,OAAmC,CAAC;IAE/D,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,iBAAkB,EAAE,EAAE;QACnE,MAAM,eAAe,GAAG,IAAA,sCAAuB,EAAC,WAAW,CAAC,CAAC,OAAO,CAAC;QACrE,OAAO,WAAW,CAAC,IAAI,CACtB,EAAE,CAAC,uBAAS,CAAC,EAAE,eAAe,EAAE,EAChC,OAAO,EACP,iBAAwB,CACxB,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,CAAC,OAAO,GAAG,cAA6C,CAAC;IAC/D,OAAO,MAAM,CAAC;AACf,CAAC;AAzBD,0EAyBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateServerClientUsingReqRes, generateServerClientUsingCookies, } from './generateServerClient';
|
package/lib/api/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.generateServerClientUsingCookies = exports.generateServerClientUsingReqRes = void 0;
|
|
6
|
+
var generateServerClient_1 = require("./generateServerClient");
|
|
7
|
+
Object.defineProperty(exports, "generateServerClientUsingReqRes", { enumerable: true, get: function () { return generateServerClient_1.generateServerClientUsingReqRes; } });
|
|
8
|
+
Object.defineProperty(exports, "generateServerClientUsingCookies", { enumerable: true, get: function () { return generateServerClient_1.generateServerClientUsingCookies; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAEtC,+DAGgC;AAF/B,uIAAA,+BAA+B,OAAA;AAC/B,wIAAA,gCAAgC,OAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.createServerRunner = void 0;
|
|
6
|
+
const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
let amplifyConfig;
|
|
9
|
+
const createServerRunner = ({ config, }) => {
|
|
10
|
+
if (amplifyConfig) {
|
|
11
|
+
throw new adapter_core_1.AmplifyServerContextError({
|
|
12
|
+
message: '`createServerRunner` needs to be called only once.',
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
amplifyConfig = (0, utils_1.getAmplifyConfig)(config);
|
|
16
|
+
return {
|
|
17
|
+
runWithAmplifyServerContext: (0, utils_1.createRunWithAmplifyServerContext)({
|
|
18
|
+
config: amplifyConfig,
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.createServerRunner = createServerRunner;
|
|
23
|
+
//# sourceMappingURL=createServerRunner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createServerRunner.js","sourceRoot":"","sources":["../src/createServerRunner.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAItC,2EAAqF;AACrF,mCAA8E;AAG9E,IAAI,aAA0C,CAAC;AAExC,MAAM,kBAAkB,GAAkC,CAAC,EACjE,MAAM,GACN,EAAE,EAAE;IACJ,IAAI,aAAa,EAAE;QAClB,MAAM,IAAI,wCAAyB,CAAC;YACnC,OAAO,EAAE,oDAAoD;SAC7D,CAAC,CAAC;KACH;IAED,aAAa,GAAG,IAAA,wBAAgB,EAAC,MAAM,CAAC,CAAC;IAEzC,OAAO;QACN,2BAA2B,EAAE,IAAA,yCAAiC,EAAC;YAC9D,MAAM,EAAE,aAAa;SACrB,CAAC;KACF,CAAC;AACH,CAAC,CAAC;AAhBW,QAAA,kBAAkB,sBAgB7B"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { generateServerClient } from './generateServerClient';
|
|
1
|
+
export { createServerRunner } from './createServerRunner';
|
package/lib/index.js
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
var generateServerClient_1 = require("./generateServerClient");
|
|
9
|
-
Object.defineProperty(exports, "generateServerClient", { enumerable: true, get: function () { return generateServerClient_1.generateServerClient; } });
|
|
5
|
+
exports.createServerRunner = void 0;
|
|
6
|
+
var createServerRunner_1 = require("./createServerRunner");
|
|
7
|
+
Object.defineProperty(exports, "createServerRunner", { enumerable: true, get: function () { return createServerRunner_1.createServerRunner; } });
|
|
10
8
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAEtC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAEtC,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.getAmplifyConfig = void 0;
|
|
6
|
+
var utils_1 = require("../utils");
|
|
7
|
+
Object.defineProperty(exports, "getAmplifyConfig", { enumerable: true, get: function () { return utils_1.getAmplifyConfig; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAEtC,kCAA4C;AAAnC,yGAAA,gBAAgB,OAAA"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { GetServerSidePropsContext as NextGetServerSidePropsContext } from 'next';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
3
|
import { cookies } from 'next/headers';
|
|
4
|
+
import { LegacyConfig } from 'aws-amplify/adapter-core';
|
|
4
5
|
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
6
|
+
import { ResourcesConfig } from '@aws-amplify/core';
|
|
5
7
|
export declare namespace NextServer {
|
|
6
8
|
/**
|
|
7
9
|
* This context is normally available in the following:
|
|
@@ -56,4 +58,13 @@ export declare namespace NextServer {
|
|
|
56
58
|
interface RunOperationWithContext {
|
|
57
59
|
<OperationResult>(input: RunWithContextInput<OperationResult>): Promise<OperationResult>;
|
|
58
60
|
}
|
|
61
|
+
interface CreateServerRunnerInput {
|
|
62
|
+
config: ResourcesConfig | LegacyConfig;
|
|
63
|
+
}
|
|
64
|
+
interface CreateServerRunnerOutput {
|
|
65
|
+
runWithAmplifyServerContext: RunOperationWithContext;
|
|
66
|
+
}
|
|
67
|
+
interface CreateServerRunner {
|
|
68
|
+
(input: CreateServerRunnerInput): CreateServerRunnerOutput;
|
|
69
|
+
}
|
|
59
70
|
}
|
|
@@ -1,24 +1,13 @@
|
|
|
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 __assign = (this && this.__assign) || function () {
|
|
5
|
-
__assign = Object.assign || function(t) {
|
|
6
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
7
|
-
s = arguments[i];
|
|
8
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
9
|
-
t[p] = s[p];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
return __assign.apply(this, arguments);
|
|
14
|
-
};
|
|
15
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
5
|
exports.createCookieStorageAdapterFromNextServerContext = exports.DATE_IN_THE_PAST = void 0;
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
const server_1 = require("next/server");
|
|
7
|
+
const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
19
8
|
exports.DATE_IN_THE_PAST = new Date(0);
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
const createCookieStorageAdapterFromNextServerContext = (context) => {
|
|
10
|
+
const { request: req, response: res } = context;
|
|
22
11
|
// When the server context is from `getServerSideProps`, the `req` is an instance
|
|
23
12
|
// of IncomingMessage, and the `res` is an instance of ServerResponse.
|
|
24
13
|
// We cannot import these two classes here from `http` as it breaks in Next
|
|
@@ -30,7 +19,7 @@ var createCookieStorageAdapterFromNextServerContext = function (context) {
|
|
|
30
19
|
typeof res.setHeader === 'function') {
|
|
31
20
|
return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
|
|
32
21
|
}
|
|
33
|
-
|
|
22
|
+
const { request, response } = context;
|
|
34
23
|
// When the server context is from `middleware`, the `request` is an instance
|
|
35
24
|
// of `NextRequest`.
|
|
36
25
|
// When the server context is from a route handler, the `request` is an `Proxy`
|
|
@@ -45,7 +34,7 @@ var createCookieStorageAdapterFromNextServerContext = function (context) {
|
|
|
45
34
|
return createCookieStorageAdapterFromNextRequestAndHttpResponse(request, response);
|
|
46
35
|
}
|
|
47
36
|
}
|
|
48
|
-
|
|
37
|
+
const { cookies } = context;
|
|
49
38
|
if (typeof cookies === 'function') {
|
|
50
39
|
return createCookieStorageAdapterFromNextCookies(cookies);
|
|
51
40
|
}
|
|
@@ -55,54 +44,58 @@ var createCookieStorageAdapterFromNextServerContext = function (context) {
|
|
|
55
44
|
});
|
|
56
45
|
};
|
|
57
46
|
exports.createCookieStorageAdapterFromNextServerContext = createCookieStorageAdapterFromNextServerContext;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
47
|
+
const createCookieStorageAdapterFromNextRequestAndNextResponse = (request, response) => {
|
|
48
|
+
const readonlyCookieStore = request.cookies;
|
|
49
|
+
const mutableCookieStore = response.cookies;
|
|
61
50
|
return {
|
|
62
|
-
get
|
|
51
|
+
get(name) {
|
|
63
52
|
return readonlyCookieStore.get(ensureEncodedForJSCookie(name));
|
|
64
53
|
},
|
|
65
54
|
getAll: readonlyCookieStore.getAll.bind(readonlyCookieStore),
|
|
66
|
-
set
|
|
55
|
+
set(name, value, options) {
|
|
67
56
|
mutableCookieStore.set(ensureEncodedForJSCookie(name), value, options);
|
|
68
57
|
},
|
|
69
|
-
delete
|
|
58
|
+
delete(name) {
|
|
70
59
|
mutableCookieStore.delete(ensureEncodedForJSCookie(name));
|
|
71
60
|
},
|
|
72
61
|
};
|
|
73
62
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return
|
|
63
|
+
const createCookieStorageAdapterFromNextRequestAndHttpResponse = (request, response) => {
|
|
64
|
+
const readonlyCookieStore = request.cookies;
|
|
65
|
+
const mutableCookieStore = createMutableCookieStoreFromHeaders(response.headers);
|
|
66
|
+
return {
|
|
67
|
+
get(name) {
|
|
78
68
|
return readonlyCookieStore.get(ensureEncodedForJSCookie(name));
|
|
79
|
-
},
|
|
69
|
+
},
|
|
70
|
+
getAll: readonlyCookieStore.getAll.bind(readonlyCookieStore),
|
|
71
|
+
...mutableCookieStore,
|
|
72
|
+
};
|
|
80
73
|
};
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
const createCookieStorageAdapterFromNextCookies = (cookies) => {
|
|
75
|
+
const cookieStore = cookies();
|
|
83
76
|
// When Next cookies() is called in a server component, it returns a readonly
|
|
84
77
|
// cookie store. Hence calling set and delete throws an error. However,
|
|
85
78
|
// cookies() returns a mutable cookie store when called in a server action.
|
|
86
79
|
// We have no way to detect which one is returned, so we try to call set and delete
|
|
87
80
|
// and safely ignore the error if it is thrown.
|
|
88
|
-
|
|
81
|
+
const setFunc = (name, value, options) => {
|
|
89
82
|
try {
|
|
90
83
|
cookieStore.set(ensureEncodedForJSCookie(name), value, options);
|
|
91
84
|
}
|
|
92
|
-
catch
|
|
85
|
+
catch {
|
|
93
86
|
// no-op
|
|
94
87
|
}
|
|
95
88
|
};
|
|
96
|
-
|
|
89
|
+
const deleteFunc = name => {
|
|
97
90
|
try {
|
|
98
91
|
cookieStore.delete(ensureEncodedForJSCookie(name));
|
|
99
92
|
}
|
|
100
|
-
catch
|
|
93
|
+
catch {
|
|
101
94
|
// no-op
|
|
102
95
|
}
|
|
103
96
|
};
|
|
104
97
|
return {
|
|
105
|
-
get
|
|
98
|
+
get(name) {
|
|
106
99
|
return cookieStore.get(ensureEncodedForJSCookie(name));
|
|
107
100
|
},
|
|
108
101
|
getAll: cookieStore.getAll.bind(cookieStore),
|
|
@@ -110,65 +103,62 @@ var createCookieStorageAdapterFromNextCookies = function (cookies) {
|
|
|
110
103
|
delete: deleteFunc,
|
|
111
104
|
};
|
|
112
105
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
value: value,
|
|
120
|
-
});
|
|
121
|
-
});
|
|
106
|
+
const createCookieStorageAdapterFromGetServerSidePropsContext = (request, response) => {
|
|
107
|
+
const cookiesMap = { ...request.cookies };
|
|
108
|
+
const allCookies = Object.entries(cookiesMap).map(([name, value]) => ({
|
|
109
|
+
name,
|
|
110
|
+
value,
|
|
111
|
+
}));
|
|
122
112
|
return {
|
|
123
|
-
get
|
|
124
|
-
|
|
113
|
+
get(name) {
|
|
114
|
+
const value = cookiesMap[ensureEncodedForJSCookie(name)];
|
|
125
115
|
return value
|
|
126
116
|
? {
|
|
127
|
-
name
|
|
128
|
-
value
|
|
117
|
+
name,
|
|
118
|
+
value,
|
|
129
119
|
}
|
|
130
120
|
: undefined;
|
|
131
121
|
},
|
|
132
|
-
getAll
|
|
122
|
+
getAll() {
|
|
133
123
|
return allCookies;
|
|
134
124
|
},
|
|
135
|
-
set
|
|
136
|
-
response.setHeader('Set-Cookie',
|
|
125
|
+
set(name, value, options) {
|
|
126
|
+
response.setHeader('Set-Cookie', `${ensureEncodedForJSCookie(name)}=${value};${options ? serializeSetCookieOptions(options) : ''}`);
|
|
137
127
|
},
|
|
138
|
-
delete
|
|
139
|
-
response.setHeader('Set-Cookie',
|
|
128
|
+
delete(name) {
|
|
129
|
+
response.setHeader('Set-Cookie', `${ensureEncodedForJSCookie(name)}=;Expires=${exports.DATE_IN_THE_PAST.toUTCString()}`);
|
|
140
130
|
},
|
|
141
131
|
};
|
|
142
132
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
headers.append('Set-Cookie',
|
|
133
|
+
const createMutableCookieStoreFromHeaders = (headers) => {
|
|
134
|
+
const setFunc = (name, value, options) => {
|
|
135
|
+
headers.append('Set-Cookie', `${ensureEncodedForJSCookie(name)}=${value};${options ? serializeSetCookieOptions(options) : ''}`);
|
|
146
136
|
};
|
|
147
|
-
|
|
148
|
-
headers.append('Set-Cookie',
|
|
137
|
+
const deleteFunc = name => {
|
|
138
|
+
headers.append('Set-Cookie', `${ensureEncodedForJSCookie(name)}=;Expires=${exports.DATE_IN_THE_PAST.toUTCString()}`);
|
|
149
139
|
};
|
|
150
140
|
return {
|
|
151
141
|
set: setFunc,
|
|
152
142
|
delete: deleteFunc,
|
|
153
143
|
};
|
|
154
144
|
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
145
|
+
const serializeSetCookieOptions = (options) => {
|
|
146
|
+
const { expires, domain, httpOnly, sameSite, secure } = options;
|
|
147
|
+
const serializedOptions = [];
|
|
158
148
|
if (domain) {
|
|
159
|
-
serializedOptions.push(
|
|
149
|
+
serializedOptions.push(`Domain=${domain}`);
|
|
160
150
|
}
|
|
161
151
|
if (expires) {
|
|
162
|
-
serializedOptions.push(
|
|
152
|
+
serializedOptions.push(`Expires=${expires.toUTCString()}`);
|
|
163
153
|
}
|
|
164
154
|
if (httpOnly) {
|
|
165
|
-
serializedOptions.push(
|
|
155
|
+
serializedOptions.push(`HttpOnly`);
|
|
166
156
|
}
|
|
167
157
|
if (sameSite) {
|
|
168
|
-
serializedOptions.push(
|
|
158
|
+
serializedOptions.push(`SameSite=${sameSite}`);
|
|
169
159
|
}
|
|
170
160
|
if (secure) {
|
|
171
|
-
serializedOptions.push(
|
|
161
|
+
serializedOptions.push(`Secure`);
|
|
172
162
|
}
|
|
173
163
|
return serializedOptions.join(';');
|
|
174
164
|
};
|
|
@@ -178,7 +168,5 @@ var serializeSetCookieOptions = function (options) {
|
|
|
178
168
|
// https://github.com/js-cookie/js-cookie#encoding
|
|
179
169
|
// The implementation is borrowed from js-cookie without escaping `[()]` as
|
|
180
170
|
// we are not using those chars in the auth keys.
|
|
181
|
-
|
|
182
|
-
return encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent);
|
|
183
|
-
};
|
|
171
|
+
const ensureEncodedForJSCookie = (name) => encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent);
|
|
184
172
|
//# sourceMappingURL=createCookieStorageAdapterFromNextServerContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCookieStorageAdapterFromNextServerContext.js","sourceRoot":"","sources":["../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC
|
|
1
|
+
{"version":3,"file":"createCookieStorageAdapterFromNextServerContext.js","sourceRoot":"","sources":["../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAEtC,wCAAwD;AAExD,2EAGkD;AAErC,QAAA,gBAAgB,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;AAErC,MAAM,+CAA+C,GAAG,CAC9D,OAA2B,EACH,EAAE;IAC1B,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,GACpC,OAAwD,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,CAAC,KAAK,iBAAiB;QACjE,OAAO,GAAG,CAAC,SAAS,KAAK,UAAU,EAClC;QACD,OAAO,uDAAuD,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;KACzE;IAED,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAG7B,CAAC;IAEF,6EAA6E;IAC7E,oBAAoB;IACpB,+EAA+E;IAC/E,qBAAqB;IACrB,2EAA2E;IAC3E,6DAA6D;IAC7D,IAAI,OAAO,IAAI,QAAQ,EAAE;QACxB,IAAI,QAAQ,Y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0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.createRunWithAmplifyServerContext = void 0;
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const adapter_core_1 = require("aws-amplify/adapter-core");
|
|
8
|
+
const createCookieStorageAdapterFromNextServerContext_1 = require("./createCookieStorageAdapterFromNextServerContext");
|
|
9
|
+
const createRunWithAmplifyServerContext = ({ config: resourcesConfig, }) => {
|
|
10
|
+
const runWithAmplifyServerContext = async ({ nextServerContext, operation }) => {
|
|
11
|
+
// When the Auth config is presented, attempt to create a Amplify server
|
|
12
|
+
// context with token and credentials provider.
|
|
13
|
+
if (resourcesConfig.Auth) {
|
|
14
|
+
const keyValueStorage =
|
|
15
|
+
// When `null` is passed as the value of `nextServerContext`, opt-in
|
|
16
|
+
// unauthenticated role (primarily for static rendering). It's
|
|
17
|
+
// safe to use the singleton `MemoryKeyValueStorage` here, as the
|
|
18
|
+
// static rendering uses the same unauthenticated role cross-sever.
|
|
19
|
+
nextServerContext === null
|
|
20
|
+
? core_1.sharedInMemoryStorage
|
|
21
|
+
: (0, adapter_core_1.createKeyValueStorageFromCookieStorageAdapter)((0, createCookieStorageAdapterFromNextServerContext_1.createCookieStorageAdapterFromNextServerContext)(nextServerContext));
|
|
22
|
+
const credentialsProvider = (0, adapter_core_1.createAWSCredentialsAndIdentityIdProvider)(resourcesConfig.Auth, keyValueStorage);
|
|
23
|
+
const tokenProvider = (0, adapter_core_1.createUserPoolsTokenProvider)(resourcesConfig.Auth, keyValueStorage);
|
|
24
|
+
return (0, adapter_core_1.runWithAmplifyServerContext)(resourcesConfig, {
|
|
25
|
+
Auth: { credentialsProvider, tokenProvider },
|
|
26
|
+
}, operation);
|
|
27
|
+
}
|
|
28
|
+
// Otherwise it may be the case that auth is not used, e.g. API key.
|
|
29
|
+
// Omitting the `Auth` in the second parameter.
|
|
30
|
+
return (0, adapter_core_1.runWithAmplifyServerContext)(resourcesConfig, {}, operation);
|
|
31
|
+
};
|
|
32
|
+
return runWithAmplifyServerContext;
|
|
33
|
+
};
|
|
34
|
+
exports.createRunWithAmplifyServerContext = createRunWithAmplifyServerContext;
|
|
35
|
+
//# sourceMappingURL=createRunWithAmplifyServerContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRunWithAmplifyServerContext.js","sourceRoot":"","sources":["../../src/utils/createRunWithAmplifyServerContext.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAEtC,4CAA2E;AAC3E,2DAKkC;AAElC,uHAAoH;AAG7G,MAAM,iCAAiC,GAAG,CAAC,EACjD,MAAM,EAAE,eAAe,GAGvB,EAAE,EAAE;IACJ,MAAM,2BAA2B,GAChC,KAAK,EAAE,EAAE,iBAAiB,EAAE,SAAS,EAAE,EAAE,EAAE;QAC1C,wEAAwE;QACxE,+CAA+C;QAC/C,IAAI,eAAe,CAAC,IAAI,EAAE;YACzB,MAAM,eAAe;YACpB,oEAAoE;YACpE,8DAA8D;YAC9D,iEAAiE;YACjE,mEAAmE;YACnE,iBAAiB,KAAK,IAAI;gBACzB,CAAC,CAAC,4BAAqB;gBACvB,CAAC,CAAC,IAAA,4DAA6C,EAC7C,IAAA,iGAA+C,EAC9C,iBAAiB,CACjB,CACA,CAAC;YACN,MAAM,mBAAmB,GAAG,IAAA,wDAAyC,EACpE,eAAe,CAAC,IAAI,EACpB,eAAe,CACf,CAAC;YACF,MAAM,aAAa,GAAG,IAAA,2CAA4B,EACjD,eAAe,CAAC,IAAI,EACpB,eAAe,CACf,CAAC;YAEF,OAAO,IAAA,0CAA+B,EACrC,eAAe,EACf;gBACC,IAAI,EAAE,EAAE,mBAAmB,EAAE,aAAa,EAAE;aAC5C,EACD,SAAS,CACT,CAAC;SACF;QAED,oEAAoE;QACpE,+CAA+C;QAC/C,OAAO,IAAA,0CAA+B,EAAC,eAAe,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;IACxE,CAAC,CAAC;IAEH,OAAO,2BAA2B,CAAC;AACpC,CAAC,CAAC;AA9CW,QAAA,iCAAiC,qCA8C5C"}
|
|
@@ -1,35 +1,11 @@
|
|
|
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
|
-
};
|
|
7
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
5
|
exports.getAmplifyConfig = void 0;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var configStr = process.env.amplifyConfig;
|
|
14
|
-
// With a Next.js app that uses the Pages Router, the key-value pairs
|
|
15
|
-
// listed under the `env` field in the `next.config.js` is not accessible
|
|
16
|
-
// via process.env.<key> at some occasion. Using the following as a fallback
|
|
17
|
-
// See: https://github.com/vercel/next.js/issues/39299
|
|
18
|
-
if (!configStr) {
|
|
19
|
-
var serverRuntimeConfig = (0, config_1.default)().serverRuntimeConfig;
|
|
20
|
-
configStr = serverRuntimeConfig === null || serverRuntimeConfig === void 0 ? void 0 : serverRuntimeConfig.amplifyConfig;
|
|
21
|
-
}
|
|
22
|
-
if (!configStr) {
|
|
23
|
-
throw new adapter_core_1.AmplifyServerContextError({
|
|
24
|
-
message: 'Amplify configuration is missing from `process.env`.',
|
|
25
|
-
recoverySuggestion: 'Ensure to use `withAmplify` function in your `next.config.js`.',
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
var configObject = JSON.parse(configStr);
|
|
29
|
-
// TODO(HuiSF): adds ResourcesConfig validation when it has one.
|
|
30
|
-
return Object.keys(configObject).some(function (key) { return key.startsWith('aws_'); })
|
|
31
|
-
? (0, utils_1.parseAWSExports)(configObject)
|
|
32
|
-
: configObject;
|
|
33
|
-
};
|
|
6
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
const getAmplifyConfig = (config) => Object.keys(config).some(key => key.startsWith('aws_'))
|
|
8
|
+
? (0, utils_1.parseAWSExports)(config)
|
|
9
|
+
: config;
|
|
34
10
|
exports.getAmplifyConfig = getAmplifyConfig;
|
|
35
11
|
//# sourceMappingURL=getAmplifyConfig.js.map
|