@aws-amplify/core 6.0.5-unstable.fe5afe6.0 → 6.0.6-unstable.f2b7a8d.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Platform/version.js +1 -1
- package/dist/cjs/Platform/version.js.map +1 -1
- package/dist/cjs/adapterCore/serverContext/serverContext.js +25 -1
- package/dist/cjs/adapterCore/serverContext/serverContext.js.map +1 -1
- package/dist/cjs/clients/middleware/signing/signer/signatureV4/signRequest.js +2 -1
- package/dist/cjs/clients/middleware/signing/signer/signatureV4/signRequest.js.map +1 -1
- package/dist/esm/Platform/version.d.ts +1 -1
- package/dist/esm/Platform/version.mjs +1 -1
- package/dist/esm/Platform/version.mjs.map +1 -1
- package/dist/esm/adapterCore/serverContext/serverContext.mjs +25 -1
- package/dist/esm/adapterCore/serverContext/serverContext.mjs.map +1 -1
- package/dist/esm/clients/middleware/signing/signer/signatureV4/signRequest.mjs +2 -1
- package/dist/esm/clients/middleware/signing/signer/signatureV4/signRequest.mjs.map +1 -1
- package/package.json +3 -3
- package/src/Cache/types/index.ts +4 -4
- package/src/Hub/index.ts +4 -4
- package/src/Hub/types/HubTypes.ts +3 -3
- package/src/Platform/version.ts +1 -1
- package/src/adapterCore/serverContext/serverContext.ts +33 -3
- package/src/clients/internal/composeServiceApi.ts +1 -1
- package/src/clients/internal/composeTransferHandler.ts +15 -15
- package/src/clients/middleware/signing/signer/signatureV4/signRequest.ts +2 -3
- package/src/clients/types/core.ts +2 -2
- package/src/global.d.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sources":["../../../src/Platform/version.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.version = void 0;\n// generated by genversion\nexports.version = '6.0.
|
|
1
|
+
{"version":3,"file":"version.js","sources":["../../../src/Platform/version.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.version = void 0;\n// generated by genversion\nexports.version = '6.0.6-unstable.f2b7a8d.0+f2b7a8d';\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC;AACzB;AACA,OAAO,CAAC,OAAO,GAAG,kCAAkC;;"}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.destroyAmplifyServerContext = exports.getAmplifyServerContext = exports.createAmplifyServerContext = void 0;
|
|
7
7
|
const serverContextRegistry_1 = require("./serverContextRegistry");
|
|
8
8
|
const singleton_1 = require("../../singleton");
|
|
9
|
+
const error_1 = require("../error");
|
|
9
10
|
/**
|
|
10
11
|
* Creates an Amplify server context.
|
|
11
12
|
* @param amplifyConfig The Amplify resource config.
|
|
@@ -26,11 +27,15 @@ exports.createAmplifyServerContext = createAmplifyServerContext;
|
|
|
26
27
|
* @returns The Amplify server context.
|
|
27
28
|
*/
|
|
28
29
|
const getAmplifyServerContext = (contextSpec) => {
|
|
30
|
+
assertContextSpec(contextSpec);
|
|
29
31
|
const context = serverContextRegistry_1.serverContextRegistry.get(contextSpec);
|
|
30
32
|
if (context) {
|
|
31
33
|
return context;
|
|
32
34
|
}
|
|
33
|
-
throw new
|
|
35
|
+
throw new error_1.AmplifyServerContextError({
|
|
36
|
+
message: 'Attempted to get the Amplify Server Context that may have been destroyed.',
|
|
37
|
+
recoverySuggestion: 'Ensure always call Amplify APIs within `runWithAmplifyServerContext` function, and do not attempt to reuse `contextSpec` object.',
|
|
38
|
+
});
|
|
34
39
|
};
|
|
35
40
|
exports.getAmplifyServerContext = getAmplifyServerContext;
|
|
36
41
|
/**
|
|
@@ -41,4 +46,23 @@ const destroyAmplifyServerContext = (contextSpec) => {
|
|
|
41
46
|
serverContextRegistry_1.serverContextRegistry.deregister(contextSpec);
|
|
42
47
|
};
|
|
43
48
|
exports.destroyAmplifyServerContext = destroyAmplifyServerContext;
|
|
49
|
+
const assertContextSpec = (contextSpec) => {
|
|
50
|
+
let invalid = false;
|
|
51
|
+
if (!Object.prototype.hasOwnProperty.call(contextSpec, 'token')) {
|
|
52
|
+
invalid = true;
|
|
53
|
+
}
|
|
54
|
+
else if (!Object.prototype.hasOwnProperty.call(contextSpec.token, 'value')) {
|
|
55
|
+
invalid = true;
|
|
56
|
+
}
|
|
57
|
+
else if (Object.prototype.toString.call(contextSpec.token.value) !==
|
|
58
|
+
'[object Symbol]') {
|
|
59
|
+
invalid = true;
|
|
60
|
+
}
|
|
61
|
+
if (invalid) {
|
|
62
|
+
throw new error_1.AmplifyServerContextError({
|
|
63
|
+
message: 'Invalid `contextSpec`.',
|
|
64
|
+
recoverySuggestion: 'Ensure to use the `contextSpec` object injected by `runWithAmplifyServerContext` function.',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
44
68
|
//# sourceMappingURL=serverContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverContext.js","sources":["../../../../src/adapterCore/serverContext/serverContext.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.destroyAmplifyServerContext = exports.getAmplifyServerContext = exports.createAmplifyServerContext = void 0;\nconst serverContextRegistry_1 = require(\"./serverContextRegistry\");\nconst singleton_1 = require(\"../../singleton\");\n/**\n * Creates an Amplify server context.\n * @param amplifyConfig The Amplify resource config.\n * @param libraryOptions The Amplify library options.\n * @returns The Amplify server context spec.\n */\nconst createAmplifyServerContext = (amplifyConfig, libraryOptions) => {\n const amplify = new singleton_1.AmplifyClass();\n amplify.configure(amplifyConfig, libraryOptions);\n return serverContextRegistry_1.serverContextRegistry.register({\n amplify,\n });\n};\nexports.createAmplifyServerContext = createAmplifyServerContext;\n/**\n * Returns an Amplify server context.\n * @param contextSpec The context spec used to get the Amplify server context.\n * @returns The Amplify server context.\n */\nconst getAmplifyServerContext = (contextSpec) => {\n const context = serverContextRegistry_1.serverContextRegistry.get(contextSpec);\n if (context) {\n return context;\n }\n throw new
|
|
1
|
+
{"version":3,"file":"serverContext.js","sources":["../../../../src/adapterCore/serverContext/serverContext.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.destroyAmplifyServerContext = exports.getAmplifyServerContext = exports.createAmplifyServerContext = void 0;\nconst serverContextRegistry_1 = require(\"./serverContextRegistry\");\nconst singleton_1 = require(\"../../singleton\");\nconst error_1 = require(\"../error\");\n/**\n * Creates an Amplify server context.\n * @param amplifyConfig The Amplify resource config.\n * @param libraryOptions The Amplify library options.\n * @returns The Amplify server context spec.\n */\nconst createAmplifyServerContext = (amplifyConfig, libraryOptions) => {\n const amplify = new singleton_1.AmplifyClass();\n amplify.configure(amplifyConfig, libraryOptions);\n return serverContextRegistry_1.serverContextRegistry.register({\n amplify,\n });\n};\nexports.createAmplifyServerContext = createAmplifyServerContext;\n/**\n * Returns an Amplify server context.\n * @param contextSpec The context spec used to get the Amplify server context.\n * @returns The Amplify server context.\n */\nconst getAmplifyServerContext = (contextSpec) => {\n assertContextSpec(contextSpec);\n const context = serverContextRegistry_1.serverContextRegistry.get(contextSpec);\n if (context) {\n return context;\n }\n throw new error_1.AmplifyServerContextError({\n message: 'Attempted to get the Amplify Server Context that may have been destroyed.',\n recoverySuggestion: 'Ensure always call Amplify APIs within `runWithAmplifyServerContext` function, and do not attempt to reuse `contextSpec` object.',\n });\n};\nexports.getAmplifyServerContext = getAmplifyServerContext;\n/**\n * Destroys an Amplify server context.\n * @param contextSpec The context spec used to destroy the Amplify server context.\n */\nconst destroyAmplifyServerContext = (contextSpec) => {\n serverContextRegistry_1.serverContextRegistry.deregister(contextSpec);\n};\nexports.destroyAmplifyServerContext = destroyAmplifyServerContext;\nconst assertContextSpec = (contextSpec) => {\n let invalid = false;\n if (!Object.prototype.hasOwnProperty.call(contextSpec, 'token')) {\n invalid = true;\n }\n else if (!Object.prototype.hasOwnProperty.call(contextSpec.token, 'value')) {\n invalid = true;\n }\n else if (Object.prototype.toString.call(contextSpec.token.value) !==\n '[object Symbol]') {\n invalid = true;\n }\n if (invalid) {\n throw new error_1.AmplifyServerContextError({\n message: 'Invalid `contextSpec`.',\n recoverySuggestion: 'Ensure to use the `contextSpec` object injected by `runWithAmplifyServerContext` function.',\n });\n }\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,2BAA2B,GAAG,OAAO,CAAC,uBAAuB,GAAG,OAAO,CAAC,0BAA0B,GAAG,KAAK,CAAC,CAAC;AACpH,MAAM,uBAAuB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AACnE,MAAM,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,0BAA0B,GAAG,CAAC,aAAa,EAAE,cAAc,KAAK;AACtE,IAAI,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,YAAY,EAAE,CAAC;AACnD,IAAI,OAAO,CAAC,SAAS,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;AACrD,IAAI,OAAO,uBAAuB,CAAC,qBAAqB,CAAC,QAAQ,CAAC;AAClE,QAAQ,OAAO;AACf,KAAK,CAAC,CAAC;AACP,CAAC,CAAC;AACF,OAAO,CAAC,0BAA0B,GAAG,0BAA0B,CAAC;AAChE;AACA;AACA;AACA;AACA;AACA,MAAM,uBA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IAAI,IAAI,OAAO,EAAE;AACjB,QAAQ,MAAM,IAAI,OAAO,CAAC,yBAAyB,CAAC;AACpD,YAAY,OAAO,EAAE,wBAAwB;AAC7C,YAAY,kBAAkB,EAAE,4FAA4F;AAC5H,SAAS,CAAC,CAAC;AACX,KAAK;AACL,CAAC;;"}
|
|
@@ -31,7 +31,8 @@ const signRequest = (request, options) => {
|
|
|
31
31
|
const credentialEntry = `Credential=${accessKeyId}/${credentialScope}`;
|
|
32
32
|
const signedHeadersEntry = `SignedHeaders=${(0, getSignedHeaders_1.getSignedHeaders)(headers)}`;
|
|
33
33
|
const signatureEntry = `Signature=${signature}`;
|
|
34
|
-
headers[constants_1.AUTH_HEADER] =
|
|
34
|
+
headers[constants_1.AUTH_HEADER] =
|
|
35
|
+
`${constants_1.SHA256_ALGORITHM_IDENTIFIER} ${credentialEntry}, ${signedHeadersEntry}, ${signatureEntry}`;
|
|
35
36
|
return requestToSign;
|
|
36
37
|
};
|
|
37
38
|
exports.signRequest = signRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signRequest.js","sources":["../../../../../../../src/clients/middleware/signing/signer/signatureV4/signRequest.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.signRequest = void 0;\nconst getSignedHeaders_1 = require(\"./utils/getSignedHeaders\");\nconst getSigningValues_1 = require(\"./utils/getSigningValues\");\nconst constants_1 = require(\"./constants\");\nconst getSignature_1 = require(\"./utils/getSignature\");\n/**\n * Given a `HttpRequest`, returns a Signature Version 4 signed `HttpRequest`.\n *\n * @param request `HttpRequest` to be signed.\n * @param signRequestOptions `SignRequestOptions` object containing values used to construct the signature.\n * @returns A `HttpRequest` with authentication headers which can grant temporary access to AWS resources.\n */\nconst signRequest = (request, options) => {\n const signingValues = (0, getSigningValues_1.getSigningValues)(options);\n const { accessKeyId, credentialScope, longDate, sessionToken } = signingValues;\n // create the request to sign\n const headers = { ...request.headers };\n headers[constants_1.HOST_HEADER] = request.url.host;\n headers[constants_1.AMZ_DATE_HEADER] = longDate;\n if (sessionToken) {\n headers[constants_1.TOKEN_HEADER] = sessionToken;\n }\n const requestToSign = { ...request, headers };\n // calculate and add the signature to the request\n const signature = (0, getSignature_1.getSignature)(requestToSign, signingValues);\n const credentialEntry = `Credential=${accessKeyId}/${credentialScope}`;\n const signedHeadersEntry = `SignedHeaders=${(0, getSignedHeaders_1.getSignedHeaders)(headers)}`;\n const signatureEntry = `Signature=${signature}`;\n headers[constants_1.AUTH_HEADER]
|
|
1
|
+
{"version":3,"file":"signRequest.js","sources":["../../../../../../../src/clients/middleware/signing/signer/signatureV4/signRequest.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.signRequest = void 0;\nconst getSignedHeaders_1 = require(\"./utils/getSignedHeaders\");\nconst getSigningValues_1 = require(\"./utils/getSigningValues\");\nconst constants_1 = require(\"./constants\");\nconst getSignature_1 = require(\"./utils/getSignature\");\n/**\n * Given a `HttpRequest`, returns a Signature Version 4 signed `HttpRequest`.\n *\n * @param request `HttpRequest` to be signed.\n * @param signRequestOptions `SignRequestOptions` object containing values used to construct the signature.\n * @returns A `HttpRequest` with authentication headers which can grant temporary access to AWS resources.\n */\nconst signRequest = (request, options) => {\n const signingValues = (0, getSigningValues_1.getSigningValues)(options);\n const { accessKeyId, credentialScope, longDate, sessionToken } = signingValues;\n // create the request to sign\n const headers = { ...request.headers };\n headers[constants_1.HOST_HEADER] = request.url.host;\n headers[constants_1.AMZ_DATE_HEADER] = longDate;\n if (sessionToken) {\n headers[constants_1.TOKEN_HEADER] = sessionToken;\n }\n const requestToSign = { ...request, headers };\n // calculate and add the signature to the request\n const signature = (0, getSignature_1.getSignature)(requestToSign, signingValues);\n const credentialEntry = `Credential=${accessKeyId}/${credentialScope}`;\n const signedHeadersEntry = `SignedHeaders=${(0, getSignedHeaders_1.getSignedHeaders)(headers)}`;\n const signatureEntry = `Signature=${signature}`;\n headers[constants_1.AUTH_HEADER] =\n `${constants_1.SHA256_ALGORITHM_IDENTIFIER} ${credentialEntry}, ${signedHeadersEntry}, ${signatureEntry}`;\n return requestToSign;\n};\nexports.signRequest = signRequest;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,CAAC;AAC7B,MAAM,kBAAkB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAC/D,MAAM,kBAAkB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAC/D,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAC3C,MAAM,cAAc,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK;AAC1C,IAAI,MAAM,aAAa,GAAG,IAAI,kBAAkB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAC5E,IAAI,MAAM,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,aAAa,CAAC;AACnF;AACA,IAAI,MAAM,OAAO,GAAG,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;AAC3C,IAAI,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;AACxD,IAAI,OAAO,CAAC,WAAW,CAAC,eAAe,CAAC,GAAG,QAAQ,CAAC;AACpD,IAAI,IAAI,YAAY,EAAE;AACtB,QAAQ,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;AACzD,KAAK;AACL,IAAI,MAAM,aAAa,GAAG,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC;AAClD;AACA,IAAI,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,YAAY,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;AACrF,IAAI,MAAM,eAAe,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;AAC3E,IAAI,MAAM,kBAAkB,GAAG,CAAC,cAAc,EAAE,IAAI,kBAAkB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AACpG,IAAI,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC;AACpD,IAAI,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC;AACpC,QAAQ,CAAC,EAAE,WAAW,CAAC,2BAA2B,CAAC,CAAC,EAAE,eAAe,CAAC,EAAE,EAAE,kBAAkB,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC,CAAC;AAClH,IAAI,OAAO,aAAa,CAAC;AACzB,CAAC,CAAC;AACF,OAAO,CAAC,WAAW,GAAG,WAAW;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "6.0.
|
|
1
|
+
export declare const version = "6.0.6-unstable.f2b7a8d.0+f2b7a8d";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.mjs","sources":["../../../src/Platform/version.ts"],"sourcesContent":["// generated by genversion\nexport const version = '6.0.
|
|
1
|
+
{"version":3,"file":"version.mjs","sources":["../../../src/Platform/version.ts"],"sourcesContent":["// generated by genversion\nexport const version = '6.0.6-unstable.f2b7a8d.0+f2b7a8d';\n"],"names":[],"mappings":"AAAA;AACY,MAAC,OAAO,GAAG;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { serverContextRegistry } from './serverContextRegistry.mjs';
|
|
2
2
|
import { AmplifyClass } from '../../singleton/Amplify.mjs';
|
|
3
|
+
import { AmplifyServerContextError } from '../error/AmplifyServerContextError.mjs';
|
|
3
4
|
|
|
4
5
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
6
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -22,11 +23,15 @@ const createAmplifyServerContext = (amplifyConfig, libraryOptions) => {
|
|
|
22
23
|
* @returns The Amplify server context.
|
|
23
24
|
*/
|
|
24
25
|
const getAmplifyServerContext = (contextSpec) => {
|
|
26
|
+
assertContextSpec(contextSpec);
|
|
25
27
|
const context = serverContextRegistry.get(contextSpec);
|
|
26
28
|
if (context) {
|
|
27
29
|
return context;
|
|
28
30
|
}
|
|
29
|
-
throw new
|
|
31
|
+
throw new AmplifyServerContextError({
|
|
32
|
+
message: 'Attempted to get the Amplify Server Context that may have been destroyed.',
|
|
33
|
+
recoverySuggestion: 'Ensure always call Amplify APIs within `runWithAmplifyServerContext` function, and do not attempt to reuse `contextSpec` object.',
|
|
34
|
+
});
|
|
30
35
|
};
|
|
31
36
|
/**
|
|
32
37
|
* Destroys an Amplify server context.
|
|
@@ -35,6 +40,25 @@ const getAmplifyServerContext = (contextSpec) => {
|
|
|
35
40
|
const destroyAmplifyServerContext = (contextSpec) => {
|
|
36
41
|
serverContextRegistry.deregister(contextSpec);
|
|
37
42
|
};
|
|
43
|
+
const assertContextSpec = (contextSpec) => {
|
|
44
|
+
let invalid = false;
|
|
45
|
+
if (!Object.prototype.hasOwnProperty.call(contextSpec, 'token')) {
|
|
46
|
+
invalid = true;
|
|
47
|
+
}
|
|
48
|
+
else if (!Object.prototype.hasOwnProperty.call(contextSpec.token, 'value')) {
|
|
49
|
+
invalid = true;
|
|
50
|
+
}
|
|
51
|
+
else if (Object.prototype.toString.call(contextSpec.token.value) !==
|
|
52
|
+
'[object Symbol]') {
|
|
53
|
+
invalid = true;
|
|
54
|
+
}
|
|
55
|
+
if (invalid) {
|
|
56
|
+
throw new AmplifyServerContextError({
|
|
57
|
+
message: 'Invalid `contextSpec`.',
|
|
58
|
+
recoverySuggestion: 'Ensure to use the `contextSpec` object injected by `runWithAmplifyServerContext` function.',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
38
62
|
|
|
39
63
|
export { createAmplifyServerContext, destroyAmplifyServerContext, getAmplifyServerContext };
|
|
40
64
|
//# sourceMappingURL=serverContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverContext.mjs","sources":["../../../../src/adapterCore/serverContext/serverContext.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { serverContextRegistry } from './serverContextRegistry';\nimport { AmplifyClass } from '../../singleton';\n/**\n * Creates an Amplify server context.\n * @param amplifyConfig The Amplify resource config.\n * @param libraryOptions The Amplify library options.\n * @returns The Amplify server context spec.\n */\nexport const createAmplifyServerContext = (amplifyConfig, libraryOptions) => {\n const amplify = new AmplifyClass();\n amplify.configure(amplifyConfig, libraryOptions);\n return serverContextRegistry.register({\n amplify,\n });\n};\n/**\n * Returns an Amplify server context.\n * @param contextSpec The context spec used to get the Amplify server context.\n * @returns The Amplify server context.\n */\nexport const getAmplifyServerContext = (contextSpec) => {\n const context = serverContextRegistry.get(contextSpec);\n if (context) {\n return context;\n }\n throw new
|
|
1
|
+
{"version":3,"file":"serverContext.mjs","sources":["../../../../src/adapterCore/serverContext/serverContext.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { serverContextRegistry } from './serverContextRegistry';\nimport { AmplifyClass } from '../../singleton';\nimport { AmplifyServerContextError } from '../error';\n/**\n * Creates an Amplify server context.\n * @param amplifyConfig The Amplify resource config.\n * @param libraryOptions The Amplify library options.\n * @returns The Amplify server context spec.\n */\nexport const createAmplifyServerContext = (amplifyConfig, libraryOptions) => {\n const amplify = new AmplifyClass();\n amplify.configure(amplifyConfig, libraryOptions);\n return serverContextRegistry.register({\n amplify,\n });\n};\n/**\n * Returns an Amplify server context.\n * @param contextSpec The context spec used to get the Amplify server context.\n * @returns The Amplify server context.\n */\nexport const getAmplifyServerContext = (contextSpec) => {\n assertContextSpec(contextSpec);\n const context = serverContextRegistry.get(contextSpec);\n if (context) {\n return context;\n }\n throw new AmplifyServerContextError({\n message: 'Attempted to get the Amplify Server Context that may have been destroyed.',\n recoverySuggestion: 'Ensure always call Amplify APIs within `runWithAmplifyServerContext` function, and do not attempt to reuse `contextSpec` object.',\n });\n};\n/**\n * Destroys an Amplify server context.\n * @param contextSpec The context spec used to destroy the Amplify server context.\n */\nexport const destroyAmplifyServerContext = (contextSpec) => {\n serverContextRegistry.deregister(contextSpec);\n};\nconst assertContextSpec = (contextSpec) => {\n let invalid = false;\n if (!Object.prototype.hasOwnProperty.call(contextSpec, 'token')) {\n invalid = true;\n }\n else if (!Object.prototype.hasOwnProperty.call(contextSpec.token, 'value')) {\n invalid = true;\n }\n else if (Object.prototype.toString.call(contextSpec.token.value) !==\n '[object Symbol]') {\n invalid = true;\n }\n if (invalid) {\n throw new AmplifyServerContextError({\n message: 'Invalid `contextSpec`.',\n recoverySuggestion: 'Ensure to use the `contextSpec` object injected by `runWithAmplifyServerContext` function.',\n });\n }\n};\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,0BAA0B,GAAG,CAAC,aAAa,EAAE,cAAc,KAAK;AAC7E,IAAI,MAAM,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;AACvC,IAAI,OAAO,CAAC,SAAS,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;AACrD,IAAI,OAAO,qBAAqB,CAAC,QAAQ,CAAC;AAC1C,QAAQ,OAAO;AACf,KAAK,CAAC,CAAC;AACP,EAAE;AACF;AACA;AACA;AACA;AACA;AACY,MAAC,uBAAuB,GAAG,CAAC,WAAW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;AACL,CAAC;;;;"}
|
|
@@ -28,7 +28,8 @@ const signRequest = (request, options) => {
|
|
|
28
28
|
const credentialEntry = `Credential=${accessKeyId}/${credentialScope}`;
|
|
29
29
|
const signedHeadersEntry = `SignedHeaders=${getSignedHeaders(headers)}`;
|
|
30
30
|
const signatureEntry = `Signature=${signature}`;
|
|
31
|
-
headers[AUTH_HEADER] =
|
|
31
|
+
headers[AUTH_HEADER] =
|
|
32
|
+
`${SHA256_ALGORITHM_IDENTIFIER} ${credentialEntry}, ${signedHeadersEntry}, ${signatureEntry}`;
|
|
32
33
|
return requestToSign;
|
|
33
34
|
};
|
|
34
35
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signRequest.mjs","sources":["../../../../../../../src/clients/middleware/signing/signer/signatureV4/signRequest.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { getSignedHeaders } from './utils/getSignedHeaders';\nimport { getSigningValues } from './utils/getSigningValues';\nimport { AMZ_DATE_HEADER, AUTH_HEADER, HOST_HEADER, SHA256_ALGORITHM_IDENTIFIER, TOKEN_HEADER, } from './constants';\nimport { getSignature } from './utils/getSignature';\n/**\n * Given a `HttpRequest`, returns a Signature Version 4 signed `HttpRequest`.\n *\n * @param request `HttpRequest` to be signed.\n * @param signRequestOptions `SignRequestOptions` object containing values used to construct the signature.\n * @returns A `HttpRequest` with authentication headers which can grant temporary access to AWS resources.\n */\nexport const signRequest = (request, options) => {\n const signingValues = getSigningValues(options);\n const { accessKeyId, credentialScope, longDate, sessionToken } = signingValues;\n // create the request to sign\n const headers = { ...request.headers };\n headers[HOST_HEADER] = request.url.host;\n headers[AMZ_DATE_HEADER] = longDate;\n if (sessionToken) {\n headers[TOKEN_HEADER] = sessionToken;\n }\n const requestToSign = { ...request, headers };\n // calculate and add the signature to the request\n const signature = getSignature(requestToSign, signingValues);\n const credentialEntry = `Credential=${accessKeyId}/${credentialScope}`;\n const signedHeadersEntry = `SignedHeaders=${getSignedHeaders(headers)}`;\n const signatureEntry = `Signature=${signature}`;\n headers[AUTH_HEADER]
|
|
1
|
+
{"version":3,"file":"signRequest.mjs","sources":["../../../../../../../src/clients/middleware/signing/signer/signatureV4/signRequest.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { getSignedHeaders } from './utils/getSignedHeaders';\nimport { getSigningValues } from './utils/getSigningValues';\nimport { AMZ_DATE_HEADER, AUTH_HEADER, HOST_HEADER, SHA256_ALGORITHM_IDENTIFIER, TOKEN_HEADER, } from './constants';\nimport { getSignature } from './utils/getSignature';\n/**\n * Given a `HttpRequest`, returns a Signature Version 4 signed `HttpRequest`.\n *\n * @param request `HttpRequest` to be signed.\n * @param signRequestOptions `SignRequestOptions` object containing values used to construct the signature.\n * @returns A `HttpRequest` with authentication headers which can grant temporary access to AWS resources.\n */\nexport const signRequest = (request, options) => {\n const signingValues = getSigningValues(options);\n const { accessKeyId, credentialScope, longDate, sessionToken } = signingValues;\n // create the request to sign\n const headers = { ...request.headers };\n headers[HOST_HEADER] = request.url.host;\n headers[AMZ_DATE_HEADER] = longDate;\n if (sessionToken) {\n headers[TOKEN_HEADER] = sessionToken;\n }\n const requestToSign = { ...request, headers };\n // calculate and add the signature to the request\n const signature = getSignature(requestToSign, signingValues);\n const credentialEntry = `Credential=${accessKeyId}/${credentialScope}`;\n const signedHeadersEntry = `SignedHeaders=${getSignedHeaders(headers)}`;\n const signatureEntry = `Signature=${signature}`;\n headers[AUTH_HEADER] =\n `${SHA256_ALGORITHM_IDENTIFIER} ${credentialEntry}, ${signedHeadersEntry}, ${signatureEntry}`;\n return requestToSign;\n};\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK;AACjD,IAAI,MAAM,aAAa,GAAG,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Core category of aws-amplify",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"uuid": "^9.0.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@aws-amplify/react-native": "1.0.
|
|
63
|
+
"@aws-amplify/react-native": "1.0.6-unstable.f2b7a8d.0+f2b7a8d",
|
|
64
64
|
"@rollup/plugin-typescript": "11.1.5",
|
|
65
65
|
"@types/js-cookie": "3.0.2",
|
|
66
66
|
"genversion": "^2.2.0",
|
|
@@ -234,5 +234,5 @@
|
|
|
234
234
|
"dist"
|
|
235
235
|
]
|
|
236
236
|
},
|
|
237
|
-
"gitHead": "
|
|
237
|
+
"gitHead": "f2b7a8d78058af2e1c04f7d507525641def667c3"
|
|
238
238
|
}
|
package/src/Cache/types/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
export * from './cache';
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export * from './cache';
|
package/src/Hub/index.ts
CHANGED
|
@@ -51,7 +51,7 @@ export class HubClass {
|
|
|
51
51
|
*/
|
|
52
52
|
private _remove<
|
|
53
53
|
Channel extends AmplifyChannel | string = string,
|
|
54
|
-
EventData extends EventDataMap = EventDataMap
|
|
54
|
+
EventData extends EventDataMap = EventDataMap,
|
|
55
55
|
>(channel: Channel, listener: HubCallback<Channel, EventData>) {
|
|
56
56
|
const holder = this.listeners.get(channel);
|
|
57
57
|
if (!holder) {
|
|
@@ -89,7 +89,7 @@ export class HubClass {
|
|
|
89
89
|
|
|
90
90
|
dispatch<
|
|
91
91
|
Channel extends AmplifyChannel | string,
|
|
92
|
-
EventData extends EventDataMap = EventDataMap
|
|
92
|
+
EventData extends EventDataMap = EventDataMap,
|
|
93
93
|
>(
|
|
94
94
|
channel: Channel | string,
|
|
95
95
|
payload: HubPayload<EventData>,
|
|
@@ -134,7 +134,7 @@ export class HubClass {
|
|
|
134
134
|
*/
|
|
135
135
|
listen<
|
|
136
136
|
Channel extends AmplifyChannel,
|
|
137
|
-
EventData extends EventDataMap = EventDataMap
|
|
137
|
+
EventData extends EventDataMap = EventDataMap,
|
|
138
138
|
>(
|
|
139
139
|
channel: Channel,
|
|
140
140
|
callback: HubCallback<Channel, AmplifyEventData[Channel]>,
|
|
@@ -149,7 +149,7 @@ export class HubClass {
|
|
|
149
149
|
|
|
150
150
|
listen<
|
|
151
151
|
Channel extends AmplifyChannel | string = string,
|
|
152
|
-
EventData extends EventDataMap = EventDataMap
|
|
152
|
+
EventData extends EventDataMap = EventDataMap,
|
|
153
153
|
>(
|
|
154
154
|
channel: Channel,
|
|
155
155
|
callback: HubCallback<Channel, EventData>,
|
|
@@ -5,7 +5,7 @@ import { AuthHubEventData } from './AuthTypes';
|
|
|
5
5
|
|
|
6
6
|
export type IListener<
|
|
7
7
|
Channel extends string = AmplifyChannel | string,
|
|
8
|
-
EventData extends EventDataMap = EventDataMap
|
|
8
|
+
EventData extends EventDataMap = EventDataMap,
|
|
9
9
|
> = {
|
|
10
10
|
name: string;
|
|
11
11
|
callback: HubCallback<Channel, EventData>;
|
|
@@ -23,7 +23,7 @@ export type StopListenerCallback = () => void;
|
|
|
23
23
|
|
|
24
24
|
export type HubCapsule<
|
|
25
25
|
Channel extends string,
|
|
26
|
-
EventData extends EventDataMap
|
|
26
|
+
EventData extends EventDataMap,
|
|
27
27
|
> = {
|
|
28
28
|
channel: Channel;
|
|
29
29
|
payload: HubPayload<EventData>;
|
|
@@ -33,7 +33,7 @@ export type HubCapsule<
|
|
|
33
33
|
|
|
34
34
|
export type HubCallback<
|
|
35
35
|
Channel extends string = string,
|
|
36
|
-
EventData extends EventDataMap = EventDataMap
|
|
36
|
+
EventData extends EventDataMap = EventDataMap,
|
|
37
37
|
> = (capsule: HubCapsule<Channel, EventData>) => void;
|
|
38
38
|
|
|
39
39
|
export type HubPayload<EventData extends EventDataMap = EventDataMap> =
|
package/src/Platform/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '6.0.
|
|
2
|
+
export const version = '6.0.6-unstable.f2b7a8d.0+f2b7a8d';
|
|
@@ -5,6 +5,7 @@ import { AmplifyServer } from './types';
|
|
|
5
5
|
import { serverContextRegistry } from './serverContextRegistry';
|
|
6
6
|
import { AmplifyClass } from '../../singleton';
|
|
7
7
|
import { LibraryOptions, ResourcesConfig } from '../../singleton/types';
|
|
8
|
+
import { AmplifyServerContextError } from '../error';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Creates an Amplify server context.
|
|
@@ -32,15 +33,19 @@ export const createAmplifyServerContext = (
|
|
|
32
33
|
export const getAmplifyServerContext = (
|
|
33
34
|
contextSpec: AmplifyServer.ContextSpec
|
|
34
35
|
): AmplifyServer.Context => {
|
|
36
|
+
assertContextSpec(contextSpec);
|
|
35
37
|
const context = serverContextRegistry.get(contextSpec);
|
|
36
38
|
|
|
37
39
|
if (context) {
|
|
38
40
|
return context;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
throw new
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
throw new AmplifyServerContextError({
|
|
44
|
+
message:
|
|
45
|
+
'Attempted to get the Amplify Server Context that may have been destroyed.',
|
|
46
|
+
recoverySuggestion:
|
|
47
|
+
'Ensure always call Amplify APIs within `runWithAmplifyServerContext` function, and do not attempt to reuse `contextSpec` object.',
|
|
48
|
+
});
|
|
44
49
|
};
|
|
45
50
|
|
|
46
51
|
/**
|
|
@@ -52,3 +57,28 @@ export const destroyAmplifyServerContext = (
|
|
|
52
57
|
): void => {
|
|
53
58
|
serverContextRegistry.deregister(contextSpec);
|
|
54
59
|
};
|
|
60
|
+
|
|
61
|
+
const assertContextSpec = (contextSpec: AmplifyServer.ContextSpec) => {
|
|
62
|
+
let invalid = false;
|
|
63
|
+
|
|
64
|
+
if (!Object.prototype.hasOwnProperty.call(contextSpec, 'token')) {
|
|
65
|
+
invalid = true;
|
|
66
|
+
} else if (
|
|
67
|
+
!Object.prototype.hasOwnProperty.call(contextSpec.token, 'value')
|
|
68
|
+
) {
|
|
69
|
+
invalid = true;
|
|
70
|
+
} else if (
|
|
71
|
+
Object.prototype.toString.call(contextSpec.token.value) !==
|
|
72
|
+
'[object Symbol]'
|
|
73
|
+
) {
|
|
74
|
+
invalid = true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (invalid) {
|
|
78
|
+
throw new AmplifyServerContextError({
|
|
79
|
+
message: 'Invalid `contextSpec`.',
|
|
80
|
+
recoverySuggestion:
|
|
81
|
+
'Ensure to use the `contextSpec` object injected by `runWithAmplifyServerContext` function.',
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
@@ -26,7 +26,7 @@ export const composeTransferHandler =
|
|
|
26
26
|
Request,
|
|
27
27
|
Response,
|
|
28
28
|
any
|
|
29
|
-
> = TransferHandler<Request, Response, {}
|
|
29
|
+
> = TransferHandler<Request, Response, {}>,
|
|
30
30
|
>(
|
|
31
31
|
coreHandler: CoreHandler,
|
|
32
32
|
middleware: OptionToMiddleware<Request, Response, MiddlewareOptionsArr>
|
|
@@ -56,34 +56,34 @@ export const composeTransferHandler =
|
|
|
56
56
|
type OptionToMiddleware<
|
|
57
57
|
Request extends RequestBase,
|
|
58
58
|
Response extends ResponseBase,
|
|
59
|
-
Options extends any[]
|
|
59
|
+
Options extends any[],
|
|
60
60
|
> = Options extends []
|
|
61
61
|
? []
|
|
62
62
|
: Options extends [infer LastOption]
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
? [Middleware<Request, Response, LastOption>]
|
|
64
|
+
: Options extends [infer FirstOption, ...infer RestOptions]
|
|
65
|
+
? [
|
|
66
|
+
Middleware<Request, Response, FirstOption>,
|
|
67
|
+
...OptionToMiddleware<Request, Response, RestOptions>,
|
|
68
|
+
]
|
|
69
|
+
: never;
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
72
|
* Type to intersect multiple types if they have no conflict keys.
|
|
73
73
|
*/
|
|
74
74
|
type MergeNoConflictKeys<Options extends any[]> = Options extends [
|
|
75
|
-
infer OnlyOption
|
|
75
|
+
infer OnlyOption,
|
|
76
76
|
]
|
|
77
77
|
? OnlyOption
|
|
78
78
|
: Options extends [infer FirstOption, infer SecondOption]
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
? FirstOption & SecondOption
|
|
80
|
+
: Options extends [infer FirstOption, ...infer RestOptions]
|
|
81
|
+
? FirstOption & MergeNoConflictKeys<RestOptions>
|
|
82
|
+
: never;
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* Type to infer the option type of a transfer handler type.
|
|
86
86
|
*/
|
|
87
87
|
type InferOptionTypeFromTransferHandler<
|
|
88
|
-
T extends TransferHandler<any, any, any
|
|
88
|
+
T extends TransferHandler<any, any, any>,
|
|
89
89
|
> = Parameters<T>[1];
|
|
@@ -43,9 +43,8 @@ export const signRequest = (
|
|
|
43
43
|
const credentialEntry = `Credential=${accessKeyId}/${credentialScope}`;
|
|
44
44
|
const signedHeadersEntry = `SignedHeaders=${getSignedHeaders(headers)}`;
|
|
45
45
|
const signatureEntry = `Signature=${signature}`;
|
|
46
|
-
headers[
|
|
47
|
-
|
|
48
|
-
] = `${SHA256_ALGORITHM_IDENTIFIER} ${credentialEntry}, ${signedHeadersEntry}, ${signatureEntry}`;
|
|
46
|
+
headers[AUTH_HEADER] =
|
|
47
|
+
`${SHA256_ALGORITHM_IDENTIFIER} ${credentialEntry}, ${signedHeadersEntry}, ${signatureEntry}`;
|
|
49
48
|
|
|
50
49
|
return requestToSign;
|
|
51
50
|
};
|
|
@@ -16,7 +16,7 @@ export interface Response {
|
|
|
16
16
|
export interface TransferHandler<
|
|
17
17
|
Input extends Request,
|
|
18
18
|
Output extends Response,
|
|
19
|
-
TransferOptions
|
|
19
|
+
TransferOptions,
|
|
20
20
|
> {
|
|
21
21
|
(request: Input, options: TransferOptions): Promise<Output>;
|
|
22
22
|
}
|
|
@@ -49,7 +49,7 @@ type ConfiguredMiddleware<Input extends Request, Output extends Response> = (
|
|
|
49
49
|
export type Middleware<
|
|
50
50
|
Input extends Request,
|
|
51
51
|
Output extends Response,
|
|
52
|
-
MiddlewareOptions
|
|
52
|
+
MiddlewareOptions,
|
|
53
53
|
> = (options: MiddlewareOptions) => ConfiguredMiddleware<Input, Output>;
|
|
54
54
|
|
|
55
55
|
export interface Endpoint {
|