@aws-amplify/adapter-nextjs 0.0.2-ui-preview.1aa6ecb.0 → 1.0.1-api-v6-models.6a7a338.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 -1
- package/lib/index.js +3 -3
- 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 +17 -0
- package/lib/utils/createCookieStorageAdapterFromNextServerContext.js +92 -72
- 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 +3 -2
- package/lib/utils/getAmplifyConfig.js +4 -13
- 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 -1
- package/lib-esm/index.js +1 -1
- 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 +17 -0
- package/lib-esm/utils/createCookieStorageAdapterFromNextServerContext.js +92 -72
- 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 +3 -2
- package/lib-esm/utils/getAmplifyConfig.js +4 -13
- 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 +123 -109
- 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 -1
- package/src/internals/index.ts +5 -0
- package/src/types/NextServer.ts +20 -0
- package/src/utils/createCookieStorageAdapterFromNextServerContext.ts +71 -28
- package/src/utils/createRunWithAmplifyServerContext.ts +61 -0
- package/src/utils/getAmplifyConfig.ts +10 -19
- package/src/utils/index.ts +1 -1
- package/lib/runWithAmplifyServerContext.d.ts +0 -2
- package/lib/runWithAmplifyServerContext.js +0 -74
- package/lib/runWithAmplifyServerContext.js.map +0 -1
- package/lib/withAmplify.d.ts +0 -9
- package/lib/withAmplify.js +0 -33
- package/lib/withAmplify.js.map +0 -1
- package/lib-esm/runWithAmplifyServerContext.d.ts +0 -2
- package/lib-esm/runWithAmplifyServerContext.js +0 -70
- package/lib-esm/runWithAmplifyServerContext.js.map +0 -1
- package/lib-esm/withAmplify.d.ts +0 -9
- package/lib-esm/withAmplify.js +0 -29
- package/lib-esm/withAmplify.js.map +0 -1
- package/src/runWithAmplifyServerContext.ts +0 -60
- package/src/withAmplify.ts +0 -28
|
@@ -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 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createServerRunner } from './createServerRunner';
|
package/lib/index.js
CHANGED
|
@@ -2,7 +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, "
|
|
5
|
+
exports.createServerRunner = void 0;
|
|
6
|
+
var createServerRunner_1 = require("./createServerRunner");
|
|
7
|
+
Object.defineProperty(exports, "createServerRunner", { enumerable: true, get: function () { return createServerRunner_1.createServerRunner; } });
|
|
8
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:
|
|
@@ -42,7 +44,13 @@ export declare namespace NextServer {
|
|
|
42
44
|
request: NextGetServerSidePropsContext['req'];
|
|
43
45
|
response: NextGetServerSidePropsContext['res'];
|
|
44
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* The union of possible Next.js app server context types.
|
|
49
|
+
*/
|
|
45
50
|
type Context = NextRequestAndNextResponseContext | NextRequestAndResponseContext | ServerComponentContext | GetServerSidePropsContext;
|
|
51
|
+
/**
|
|
52
|
+
* The interface of the input of {@link RunOperationWithContext}.
|
|
53
|
+
*/
|
|
46
54
|
interface RunWithContextInput<OperationResult> {
|
|
47
55
|
nextServerContext: Context | null;
|
|
48
56
|
operation: (contextSpec: AmplifyServer.ContextSpec) => OperationResult | Promise<OperationResult>;
|
|
@@ -50,4 +58,13 @@ export declare namespace NextServer {
|
|
|
50
58
|
interface RunOperationWithContext {
|
|
51
59
|
<OperationResult>(input: RunWithContextInput<OperationResult>): Promise<OperationResult>;
|
|
52
60
|
}
|
|
61
|
+
interface CreateServerRunnerInput {
|
|
62
|
+
config: ResourcesConfig | LegacyConfig;
|
|
63
|
+
}
|
|
64
|
+
interface CreateServerRunnerOutput {
|
|
65
|
+
runWithAmplifyServerContext: RunOperationWithContext;
|
|
66
|
+
}
|
|
67
|
+
interface CreateServerRunner {
|
|
68
|
+
(input: CreateServerRunnerInput): CreateServerRunnerOutput;
|
|
69
|
+
}
|
|
53
70
|
}
|
|
@@ -1,26 +1,32 @@
|
|
|
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
|
-
|
|
19
|
-
var http_1 = require("http");
|
|
6
|
+
const server_1 = require("next/server");
|
|
7
|
+
const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
20
8
|
exports.DATE_IN_THE_PAST = new Date(0);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
const createCookieStorageAdapterFromNextServerContext = (context) => {
|
|
10
|
+
const { request: req, response: res } = context;
|
|
11
|
+
// When the server context is from `getServerSideProps`, the `req` is an instance
|
|
12
|
+
// of IncomingMessage, and the `res` is an instance of ServerResponse.
|
|
13
|
+
// We cannot import these two classes here from `http` as it breaks in Next
|
|
14
|
+
// Edge Runtime. Hence, we check the methods that we need to use for creating
|
|
15
|
+
// cookie adapter.
|
|
16
|
+
if (req &&
|
|
17
|
+
res &&
|
|
18
|
+
Object.prototype.toString.call(req.cookies) === '[object Object]' &&
|
|
19
|
+
typeof res.setHeader === 'function') {
|
|
20
|
+
return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
|
|
21
|
+
}
|
|
22
|
+
const { request, response } = context;
|
|
23
|
+
// When the server context is from `middleware`, the `request` is an instance
|
|
24
|
+
// of `NextRequest`.
|
|
25
|
+
// When the server context is from a route handler, the `request` is an `Proxy`
|
|
26
|
+
// wrapped `Request`.
|
|
27
|
+
// The `NextRequest` and the `Proxy` are sharing the same interface by Next
|
|
28
|
+
// implementation. So we don't need to detect the difference.
|
|
29
|
+
if (request && response) {
|
|
24
30
|
if (response instanceof server_1.NextResponse) {
|
|
25
31
|
return createCookieStorageAdapterFromNextRequestAndNextResponse(request, response);
|
|
26
32
|
}
|
|
@@ -28,125 +34,139 @@ var createCookieStorageAdapterFromNextServerContext = function (context) {
|
|
|
28
34
|
return createCookieStorageAdapterFromNextRequestAndHttpResponse(request, response);
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
|
-
|
|
37
|
+
const { cookies } = context;
|
|
32
38
|
if (typeof cookies === 'function') {
|
|
33
39
|
return createCookieStorageAdapterFromNextCookies(cookies);
|
|
34
40
|
}
|
|
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
41
|
// This should not happen normally.
|
|
40
42
|
throw new adapter_core_1.AmplifyServerContextError({
|
|
41
43
|
message: 'Attempted to create cookie storage adapter from an unsupported Next.js server context.',
|
|
42
44
|
});
|
|
43
45
|
};
|
|
44
46
|
exports.createCookieStorageAdapterFromNextServerContext = createCookieStorageAdapterFromNextServerContext;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
const createCookieStorageAdapterFromNextRequestAndNextResponse = (request, response) => {
|
|
48
|
+
const readonlyCookieStore = request.cookies;
|
|
49
|
+
const mutableCookieStore = response.cookies;
|
|
48
50
|
return {
|
|
49
|
-
get
|
|
51
|
+
get(name) {
|
|
52
|
+
return readonlyCookieStore.get(ensureEncodedForJSCookie(name));
|
|
53
|
+
},
|
|
50
54
|
getAll: readonlyCookieStore.getAll.bind(readonlyCookieStore),
|
|
51
|
-
set
|
|
52
|
-
|
|
55
|
+
set(name, value, options) {
|
|
56
|
+
mutableCookieStore.set(ensureEncodedForJSCookie(name), value, options);
|
|
57
|
+
},
|
|
58
|
+
delete(name) {
|
|
59
|
+
mutableCookieStore.delete(ensureEncodedForJSCookie(name));
|
|
60
|
+
},
|
|
53
61
|
};
|
|
54
62
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return
|
|
63
|
+
const createCookieStorageAdapterFromNextRequestAndHttpResponse = (request, response) => {
|
|
64
|
+
const readonlyCookieStore = request.cookies;
|
|
65
|
+
const mutableCookieStore = createMutableCookieStoreFromHeaders(response.headers);
|
|
66
|
+
return {
|
|
67
|
+
get(name) {
|
|
68
|
+
return readonlyCookieStore.get(ensureEncodedForJSCookie(name));
|
|
69
|
+
},
|
|
70
|
+
getAll: readonlyCookieStore.getAll.bind(readonlyCookieStore),
|
|
71
|
+
...mutableCookieStore,
|
|
72
|
+
};
|
|
59
73
|
};
|
|
60
|
-
|
|
61
|
-
|
|
74
|
+
const createCookieStorageAdapterFromNextCookies = (cookies) => {
|
|
75
|
+
const cookieStore = cookies();
|
|
62
76
|
// When Next cookies() is called in a server component, it returns a readonly
|
|
63
77
|
// cookie store. Hence calling set and delete throws an error. However,
|
|
64
78
|
// cookies() returns a mutable cookie store when called in a server action.
|
|
65
79
|
// We have no way to detect which one is returned, so we try to call set and delete
|
|
66
80
|
// and safely ignore the error if it is thrown.
|
|
67
|
-
|
|
81
|
+
const setFunc = (name, value, options) => {
|
|
68
82
|
try {
|
|
69
|
-
cookieStore.set(name, value, options);
|
|
83
|
+
cookieStore.set(ensureEncodedForJSCookie(name), value, options);
|
|
70
84
|
}
|
|
71
|
-
catch
|
|
85
|
+
catch {
|
|
72
86
|
// no-op
|
|
73
87
|
}
|
|
74
88
|
};
|
|
75
|
-
|
|
89
|
+
const deleteFunc = name => {
|
|
76
90
|
try {
|
|
77
|
-
cookieStore.delete(name);
|
|
91
|
+
cookieStore.delete(ensureEncodedForJSCookie(name));
|
|
78
92
|
}
|
|
79
|
-
catch
|
|
93
|
+
catch {
|
|
80
94
|
// no-op
|
|
81
95
|
}
|
|
82
96
|
};
|
|
83
97
|
return {
|
|
84
|
-
get
|
|
98
|
+
get(name) {
|
|
99
|
+
return cookieStore.get(ensureEncodedForJSCookie(name));
|
|
100
|
+
},
|
|
85
101
|
getAll: cookieStore.getAll.bind(cookieStore),
|
|
86
102
|
set: setFunc,
|
|
87
103
|
delete: deleteFunc,
|
|
88
104
|
};
|
|
89
105
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
value: value,
|
|
97
|
-
});
|
|
98
|
-
});
|
|
106
|
+
const createCookieStorageAdapterFromGetServerSidePropsContext = (request, response) => {
|
|
107
|
+
const cookiesMap = { ...request.cookies };
|
|
108
|
+
const allCookies = Object.entries(cookiesMap).map(([name, value]) => ({
|
|
109
|
+
name,
|
|
110
|
+
value,
|
|
111
|
+
}));
|
|
99
112
|
return {
|
|
100
|
-
get
|
|
101
|
-
|
|
113
|
+
get(name) {
|
|
114
|
+
const value = cookiesMap[ensureEncodedForJSCookie(name)];
|
|
102
115
|
return value
|
|
103
116
|
? {
|
|
104
|
-
name
|
|
105
|
-
value
|
|
117
|
+
name,
|
|
118
|
+
value,
|
|
106
119
|
}
|
|
107
120
|
: undefined;
|
|
108
121
|
},
|
|
109
|
-
getAll
|
|
122
|
+
getAll() {
|
|
110
123
|
return allCookies;
|
|
111
124
|
},
|
|
112
|
-
set
|
|
113
|
-
response.setHeader('Set-Cookie',
|
|
125
|
+
set(name, value, options) {
|
|
126
|
+
response.setHeader('Set-Cookie', `${ensureEncodedForJSCookie(name)}=${value};${options ? serializeSetCookieOptions(options) : ''}`);
|
|
114
127
|
},
|
|
115
|
-
delete
|
|
116
|
-
response.setHeader('Set-Cookie',
|
|
128
|
+
delete(name) {
|
|
129
|
+
response.setHeader('Set-Cookie', `${ensureEncodedForJSCookie(name)}=;Expires=${exports.DATE_IN_THE_PAST.toUTCString()}`);
|
|
117
130
|
},
|
|
118
131
|
};
|
|
119
132
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
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) : ''}`);
|
|
123
136
|
};
|
|
124
|
-
|
|
125
|
-
headers.append('Set-Cookie',
|
|
137
|
+
const deleteFunc = name => {
|
|
138
|
+
headers.append('Set-Cookie', `${ensureEncodedForJSCookie(name)}=;Expires=${exports.DATE_IN_THE_PAST.toUTCString()}`);
|
|
126
139
|
};
|
|
127
140
|
return {
|
|
128
141
|
set: setFunc,
|
|
129
142
|
delete: deleteFunc,
|
|
130
143
|
};
|
|
131
144
|
};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
145
|
+
const serializeSetCookieOptions = (options) => {
|
|
146
|
+
const { expires, domain, httpOnly, sameSite, secure } = options;
|
|
147
|
+
const serializedOptions = [];
|
|
135
148
|
if (domain) {
|
|
136
|
-
serializedOptions.push(
|
|
149
|
+
serializedOptions.push(`Domain=${domain}`);
|
|
137
150
|
}
|
|
138
151
|
if (expires) {
|
|
139
|
-
serializedOptions.push(
|
|
152
|
+
serializedOptions.push(`Expires=${expires.toUTCString()}`);
|
|
140
153
|
}
|
|
141
154
|
if (httpOnly) {
|
|
142
|
-
serializedOptions.push(
|
|
155
|
+
serializedOptions.push(`HttpOnly`);
|
|
143
156
|
}
|
|
144
157
|
if (sameSite) {
|
|
145
|
-
serializedOptions.push(
|
|
158
|
+
serializedOptions.push(`SameSite=${sameSite}`);
|
|
146
159
|
}
|
|
147
160
|
if (secure) {
|
|
148
|
-
serializedOptions.push(
|
|
161
|
+
serializedOptions.push(`Secure`);
|
|
149
162
|
}
|
|
150
163
|
return serializedOptions.join(';');
|
|
151
164
|
};
|
|
165
|
+
// Ensures the cookie names are encoded in order to look up the cookie store
|
|
166
|
+
// that is manipulated by js-cookie on the client side.
|
|
167
|
+
// Details of the js-cookie encoding behavior see:
|
|
168
|
+
// https://github.com/js-cookie/js-cookie#encoding
|
|
169
|
+
// The implementation is borrowed from js-cookie without escaping `[()]` as
|
|
170
|
+
// we are not using those chars in the auth keys.
|
|
171
|
+
const ensureEncodedForJSCookie = (name) => encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent);
|
|
152
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,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IACD,IAAI,OAAO,EAAE;QACZ,iBAAiB,CAAC,IAAI,CAAC,WAAW,OAAO,CAAC,WAAW,EAAE,EAAE,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,YAAY,QAAQ,EAAE,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;AAEF,4EAA4E;AAC5E,uDAAuD;AACvD,kDAAkD;AAClD,kDAAkD;AAClD,2EAA2E;AAC3E,iDAAiD;AACjD,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAU,EAAE,CACzD,kBAAkB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,kBAAkB,CAAC,CAAC"}
|
|
@@ -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,2 +1,3 @@
|
|
|
1
|
-
import { ResourcesConfig } from '
|
|
2
|
-
|
|
1
|
+
import { ResourcesConfig } from 'aws-amplify';
|
|
2
|
+
import { LegacyConfig } from 'aws-amplify/adapter-core';
|
|
3
|
+
export declare const getAmplifyConfig: (config: ResourcesConfig | LegacyConfig) => ResourcesConfig;
|