@webiny/aws-helpers 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9
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/LICENSE +2 -7
- package/README.md +11 -0
- package/cloudfrontFunctions/cookies.d.ts +1 -1
- package/cloudfrontFunctions/cookies.js +18 -27
- package/cloudfrontFunctions/cookies.js.map +1 -1
- package/cloudfrontFunctions/headers.d.ts +1 -1
- package/cloudfrontFunctions/headers.js +22 -23
- package/cloudfrontFunctions/headers.js.map +1 -1
- package/cloudfrontFunctions/index.d.ts +6 -6
- package/cloudfrontFunctions/index.js +6 -6
- package/cloudfrontFunctions/querystring.d.ts +1 -1
- package/cloudfrontFunctions/querystring.js +16 -33
- package/cloudfrontFunctions/querystring.js.map +1 -1
- package/cloudfrontFunctions/redirect.d.ts +1 -1
- package/cloudfrontFunctions/redirect.js +19 -21
- package/cloudfrontFunctions/redirect.js.map +1 -1
- package/cloudfrontFunctions/types.d.ts +6 -6
- package/cloudfrontFunctions/types.js +0 -1
- package/cloudfrontFunctions/utils.d.ts +1 -1
- package/cloudfrontFunctions/utils.js +8 -19
- package/cloudfrontFunctions/utils.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lambdaEdge/cookies.d.ts +1 -1
- package/lambdaEdge/cookies.js +20 -23
- package/lambdaEdge/cookies.js.map +1 -1
- package/lambdaEdge/headers.d.ts +1 -1
- package/lambdaEdge/headers.js +9 -6
- package/lambdaEdge/headers.js.map +1 -1
- package/lambdaEdge/index.d.ts +7 -7
- package/lambdaEdge/index.js +7 -7
- package/lambdaEdge/redirect.d.ts +1 -1
- package/lambdaEdge/redirect.js +29 -29
- package/lambdaEdge/redirect.js.map +1 -1
- package/lambdaEdge/request.d.ts +1 -1
- package/lambdaEdge/request.js +26 -19
- package/lambdaEdge/request.js.map +1 -1
- package/lambdaEdge/response.d.ts +1 -1
- package/lambdaEdge/response.js +10 -7
- package/lambdaEdge/response.js.map +1 -1
- package/lambdaEdge/types.d.ts +8 -8
- package/lambdaEdge/types.js +0 -1
- package/lambdaEdge/utils.d.ts +1 -1
- package/lambdaEdge/utils.js +8 -5
- package/lambdaEdge/utils.js.map +1 -1
- package/package.json +11 -8
- package/rslib-runtime.js +14 -0
- package/rslib-runtime.js.map +1 -0
- package/stagedRollouts/functions/adminOriginRequest.js +24 -27
- package/stagedRollouts/functions/adminOriginRequest.js.map +1 -1
- package/stagedRollouts/functions/configOriginRequest.js +48 -48
- package/stagedRollouts/functions/configOriginRequest.js.map +1 -1
- package/stagedRollouts/functions/originRequest.js +15 -14
- package/stagedRollouts/functions/originRequest.js.map +1 -1
- package/stagedRollouts/functions/viewerRequest.js +20 -40
- package/stagedRollouts/functions/viewerRequest.js.map +1 -1
- package/stagedRollouts/functions/viewerResponse.js +12 -16
- package/stagedRollouts/functions/viewerResponse.js.map +1 -1
- package/stagedRollouts/utils/common.js +8 -5
- package/stagedRollouts/utils/common.js.map +1 -1
- package/stagedRollouts/utils/headerBlacklist.js +30 -12
- package/stagedRollouts/utils/headerBlacklist.js.map +1 -1
- package/stagedRollouts/utils/loadOriginPage.d.ts +1 -1
- package/stagedRollouts/utils/loadOriginPage.js +75 -98
- package/stagedRollouts/utils/loadOriginPage.js.map +1 -1
- package/stagedRollouts/utils/loadTrafficSplittingConfig.d.ts +2 -2
- package/stagedRollouts/utils/loadTrafficSplittingConfig.js +39 -57
- package/stagedRollouts/utils/loadTrafficSplittingConfig.js.map +1 -1
- package/stagedRollouts/utils/loadVariantOrigin.d.ts +2 -2
- package/stagedRollouts/utils/loadVariantOrigin.js +45 -77
- package/stagedRollouts/utils/loadVariantOrigin.js.map +1 -1
- package/stagedRollouts/utils/log.js +6 -7
- package/stagedRollouts/utils/log.js.map +1 -1
- package/cloudfrontFunctions/index.js.map +0 -1
- package/cloudfrontFunctions/types.js.map +0 -1
- package/index.js.map +0 -1
- package/lambdaEdge/index.js.map +0 -1
- package/lambdaEdge/types.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* All content that resides under the "enterprise/" directories of this repository, is licensed under the license defined in their respective "enterprise/LICENSE" file.
|
|
6
|
-
* All content that resides under the "packages/" sub-directories of this repository, is licensed under the license defined in their respective "packages/*/LICENSE" file.
|
|
7
|
-
* All third party components incorporated into the Webiny Software are licensed under the original license provided by the owner of the applicable component.
|
|
8
|
-
* Content outside of the above mentioned directories or restrictions above is available under the "MIT" license as defined below.
|
|
3
|
+
Copyright (c) Webiny
|
|
9
4
|
|
|
10
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @webiny/aws-helpers
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
6
|
+
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
|
@@ -1,28 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// It DOES make sense to set the same cookie multiple times,
|
|
16
|
-
// for example when dealing with SameSite issue (https://web.dev/samesite-cookies-explained/)
|
|
17
|
-
const multivalue = current.multivalue ?? (current.multivalue = []);
|
|
18
|
-
multivalue.push({
|
|
19
|
-
value: cookie.value,
|
|
20
|
-
attributes: attrs
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
cookies[cookie.name] = {
|
|
24
|
-
value: cookie.value,
|
|
25
|
-
attributes: attrs
|
|
1
|
+
function setResponseCookie(response, cookie) {
|
|
2
|
+
const cookies = response.cookies || (response.cookies = {});
|
|
3
|
+
const current = cookies[cookie.name];
|
|
4
|
+
let attrs = "Secure; Path=/;";
|
|
5
|
+
if (cookie.maxAge) attrs += ` Max-Age=${cookie.maxAge};`;
|
|
6
|
+
if (current) {
|
|
7
|
+
const multivalue = current.multivalue ?? (current.multivalue = []);
|
|
8
|
+
multivalue.push({
|
|
9
|
+
value: cookie.value,
|
|
10
|
+
attributes: attrs
|
|
11
|
+
});
|
|
12
|
+
} else cookies[cookie.name] = {
|
|
13
|
+
value: cookie.value,
|
|
14
|
+
attributes: attrs
|
|
26
15
|
};
|
|
27
|
-
|
|
28
|
-
}
|
|
16
|
+
}
|
|
17
|
+
export { setResponseCookie };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=cookies.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"cloudfrontFunctions/cookies.js","sources":["../../src/cloudfrontFunctions/cookies.ts"],"sourcesContent":["import type { CloudFrontResponse } from \"./types.js\";\n\nexport interface CookieParams {\n name: string;\n value: string;\n maxAge?: number;\n}\n\n/** Sets cookie for the HTTP response */\nexport function setResponseCookie(response: CloudFrontResponse, cookie: CookieParams) {\n const cookies = response.cookies || (response.cookies = {});\n\n const current = cookies[cookie.name];\n let attrs = `Secure; Path=/;`;\n\n if (cookie.maxAge) {\n attrs += ` Max-Age=${cookie.maxAge};`;\n }\n\n if (current) {\n // If there is already the same cookie set in a response,\n // we add another entry using `multivalue`.\n // This is how you set multiple same cookies in CloudFront Functions.\n // It DOES make sense to set the same cookie multiple times,\n // for example when dealing with SameSite issue (https://web.dev/samesite-cookies-explained/)\n const multivalue = current.multivalue ?? (current.multivalue = []);\n multivalue.push({\n value: cookie.value,\n attributes: attrs\n });\n } else {\n cookies[cookie.name] = {\n value: cookie.value,\n attributes: attrs\n };\n }\n}\n"],"names":["setResponseCookie","response","cookie","cookies","current","attrs","multivalue"],"mappings":"AASO,SAASA,kBAAkBC,QAA4B,EAAEC,MAAoB;IAChF,MAAMC,UAAUF,SAAS,OAAO,IAAKA,CAAAA,SAAS,OAAO,GAAG,CAAC;IAEzD,MAAMG,UAAUD,OAAO,CAACD,OAAO,IAAI,CAAC;IACpC,IAAIG,QAAQ;IAEZ,IAAIH,OAAO,MAAM,EACbG,SAAS,CAAC,SAAS,EAAEH,OAAO,MAAM,CAAC,CAAC,CAAC;IAGzC,IAAIE,SAAS;QAMT,MAAME,aAAaF,QAAQ,UAAU,IAAKA,CAAAA,QAAQ,UAAU,GAAG,EAAC;QAChEE,WAAW,IAAI,CAAC;YACZ,OAAOJ,OAAO,KAAK;YACnB,YAAYG;QAChB;IACJ,OACIF,OAAO,CAACD,OAAO,IAAI,CAAC,GAAG;QACnB,OAAOA,OAAO,KAAK;QACnB,YAAYG;IAChB;AAER"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CloudFrontHeaders, Header } from "./types";
|
|
1
|
+
import type { CloudFrontHeaders, Header } from "./types.js";
|
|
2
2
|
export declare function getHeader(headers: CloudFrontHeaders, header: string): string | undefined;
|
|
3
3
|
export declare function setHeader(headers: CloudFrontHeaders, header: Header): void;
|
|
4
4
|
export declare function setHeaders(headers: CloudFrontHeaders, headersToSet: Header[]): void;
|
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function getHeader(headers, header) {
|
|
2
|
+
return headers[header]?.value;
|
|
3
|
+
}
|
|
4
|
+
function setHeader(headers, header) {
|
|
5
|
+
headers[header.key] = {
|
|
6
|
+
value: header.value
|
|
7
|
+
};
|
|
5
8
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
value: header.value
|
|
9
|
-
};
|
|
9
|
+
function setHeaders(headers, headersToSet) {
|
|
10
|
+
for(let i = 0; i < headersToSet.length; i++)setHeader(headers, headersToSet[i]);
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
function setNoCacheHeaders(headers) {
|
|
13
|
+
headers["cache-control"] = {
|
|
14
|
+
value: "no-cache, no-store, must-revalidate"
|
|
15
|
+
};
|
|
16
|
+
headers["pragma"] = {
|
|
17
|
+
value: "no-cache"
|
|
18
|
+
};
|
|
19
|
+
headers["expires"] = {
|
|
20
|
+
value: "0"
|
|
21
|
+
};
|
|
15
22
|
}
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
headers["pragma"] = {
|
|
21
|
-
value: "no-cache"
|
|
22
|
-
};
|
|
23
|
-
headers["expires"] = {
|
|
24
|
-
value: "0"
|
|
25
|
-
};
|
|
26
|
-
}
|
|
23
|
+
export { getHeader, setHeader, setHeaders, setNoCacheHeaders };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=headers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"cloudfrontFunctions/headers.js","sources":["../../src/cloudfrontFunctions/headers.ts"],"sourcesContent":["import type { CloudFrontHeaders, Header } from \"./types.js\";\n\nexport function getHeader(headers: CloudFrontHeaders, header: string) {\n return headers[header]?.value;\n}\n\nexport function setHeader(headers: CloudFrontHeaders, header: Header) {\n headers[header.key] = {\n value: header.value\n };\n}\n\nexport function setHeaders(headers: CloudFrontHeaders, headersToSet: Header[]) {\n for (let i = 0; i < headersToSet.length; i++) {\n setHeader(headers, headersToSet[i]);\n }\n}\n\nexport function setNoCacheHeaders(headers: CloudFrontHeaders) {\n headers[\"cache-control\"] = { value: \"no-cache, no-store, must-revalidate\" };\n headers[\"pragma\"] = { value: \"no-cache\" };\n headers[\"expires\"] = { value: \"0\" };\n}\n"],"names":["getHeader","headers","header","setHeader","setHeaders","headersToSet","i","setNoCacheHeaders"],"mappings":"AAEO,SAASA,UAAUC,OAA0B,EAAEC,MAAc;IAChE,OAAOD,OAAO,CAACC,OAAO,EAAE;AAC5B;AAEO,SAASC,UAAUF,OAA0B,EAAEC,MAAc;IAChED,OAAO,CAACC,OAAO,GAAG,CAAC,GAAG;QAClB,OAAOA,OAAO,KAAK;IACvB;AACJ;AAEO,SAASE,WAAWH,OAA0B,EAAEI,YAAsB;IACzE,IAAK,IAAIC,IAAI,GAAGA,IAAID,aAAa,MAAM,EAAEC,IACrCH,UAAUF,SAASI,YAAY,CAACC,EAAE;AAE1C;AAEO,SAASC,kBAAkBN,OAA0B;IACxDA,OAAO,CAAC,gBAAgB,GAAG;QAAE,OAAO;IAAsC;IAC1EA,OAAO,CAAC,SAAS,GAAG;QAAE,OAAO;IAAW;IACxCA,OAAO,CAAC,UAAU,GAAG;QAAE,OAAO;IAAI;AACtC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./cookies";
|
|
2
|
-
export * from "./headers";
|
|
3
|
-
export * from "./querystring";
|
|
4
|
-
export * from "./redirect";
|
|
5
|
-
export * from "./types";
|
|
6
|
-
export * from "./utils";
|
|
1
|
+
export * from "./cookies.js";
|
|
2
|
+
export * from "./headers.js";
|
|
3
|
+
export * from "./querystring.js";
|
|
4
|
+
export * from "./redirect.js";
|
|
5
|
+
export * from "./types.js";
|
|
6
|
+
export * from "./utils.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./cookies";
|
|
2
|
-
export * from "./headers";
|
|
3
|
-
export * from "./querystring";
|
|
4
|
-
export * from "./redirect";
|
|
5
|
-
export * from "./types";
|
|
6
|
-
export * from "./utils";
|
|
1
|
+
export * from "./cookies.js";
|
|
2
|
+
export * from "./headers.js";
|
|
3
|
+
export * from "./querystring.js";
|
|
4
|
+
export * from "./redirect.js";
|
|
5
|
+
export * from "./types.js";
|
|
6
|
+
export * from "./utils.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CloudFrontQuery } from "./types";
|
|
1
|
+
import type { CloudFrontQuery } from "./types.js";
|
|
2
2
|
export declare function stringifyQuery(query: CloudFrontQuery): string;
|
|
@@ -1,38 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
qs = appendQueryString(qs, key, value === null || value === void 0 ? void 0 : value.value);
|
|
12
|
-
|
|
13
|
-
if (value.multivalue) {
|
|
14
|
-
for (let i = 0; i < value.multivalue.length; i++) {
|
|
15
|
-
qs = appendQueryString(qs, key, value.multivalue[i].value);
|
|
16
|
-
}
|
|
1
|
+
function stringifyQuery(query) {
|
|
2
|
+
let qs = "";
|
|
3
|
+
for (const key of Object.keys(query)){
|
|
4
|
+
const value = query[key];
|
|
5
|
+
if (value) {
|
|
6
|
+
qs = appendQueryString(qs, key, value?.value);
|
|
7
|
+
if (value.multivalue) for(let i = 0; i < value.multivalue.length; i++)qs = appendQueryString(qs, key, value.multivalue[i].value);
|
|
8
|
+
}
|
|
17
9
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (qs) {
|
|
21
|
-
qs = "?" + qs;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return qs;
|
|
10
|
+
if (qs) qs = "?" + qs;
|
|
11
|
+
return qs;
|
|
25
12
|
}
|
|
26
|
-
|
|
27
13
|
function appendQueryString(qs, key, value) {
|
|
28
|
-
|
|
14
|
+
if (null === value) return qs;
|
|
15
|
+
if (qs.length) qs += "&";
|
|
16
|
+
qs += `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
29
17
|
return qs;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (qs.length) {
|
|
33
|
-
qs += "&";
|
|
34
|
-
}
|
|
18
|
+
}
|
|
19
|
+
export { stringifyQuery };
|
|
35
20
|
|
|
36
|
-
|
|
37
|
-
return qs;
|
|
38
|
-
}
|
|
21
|
+
//# sourceMappingURL=querystring.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"cloudfrontFunctions/querystring.js","sources":["../../src/cloudfrontFunctions/querystring.ts"],"sourcesContent":["import type { CloudFrontQuery } from \"./types.js\";\n\nexport function stringifyQuery(query: CloudFrontQuery) {\n let qs = \"\";\n\n for (const key of Object.keys(query)) {\n const value = query[key];\n if (!value) {\n continue;\n }\n\n qs = appendQueryString(qs, key, value?.value);\n\n if (value.multivalue) {\n for (let i = 0; i < value.multivalue.length; i++) {\n qs = appendQueryString(qs, key, value.multivalue[i].value);\n }\n }\n }\n\n if (qs) {\n qs = \"?\" + qs;\n }\n\n return qs;\n}\n\nfunction appendQueryString(qs: string, key: string, value: string | null) {\n if (value === null) {\n return qs;\n }\n\n if (qs.length) {\n qs += \"&\";\n }\n\n qs += `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;\n\n return qs;\n}\n"],"names":["stringifyQuery","query","qs","key","Object","value","appendQueryString","i","encodeURIComponent"],"mappings":"AAEO,SAASA,eAAeC,KAAsB;IACjD,IAAIC,KAAK;IAET,KAAK,MAAMC,OAAOC,OAAO,IAAI,CAACH,OAAQ;QAClC,MAAMI,QAAQJ,KAAK,CAACE,IAAI;QACxB,IAAKE;YAILH,KAAKI,kBAAkBJ,IAAIC,KAAKE,OAAO;YAEvC,IAAIA,MAAM,UAAU,EAChB,IAAK,IAAIE,IAAI,GAAGA,IAAIF,MAAM,UAAU,CAAC,MAAM,EAAEE,IACzCL,KAAKI,kBAAkBJ,IAAIC,KAAKE,MAAM,UAAU,CAACE,EAAE,CAAC,KAAK;;IAGrE;IAEA,IAAIL,IACAA,KAAK,MAAMA;IAGf,OAAOA;AACX;AAEA,SAASI,kBAAkBJ,EAAU,EAAEC,GAAW,EAAEE,KAAoB;IACpE,IAAIA,AAAU,SAAVA,OACA,OAAOH;IAGX,IAAIA,GAAG,MAAM,EACTA,MAAM;IAGVA,MAAM,GAAGM,mBAAmBL,KAAK,CAAC,EAAEK,mBAAmBH,QAAQ;IAE/D,OAAOH;AACX"}
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import { setNoCacheHeaders } from "./headers";
|
|
2
|
-
import { stringifyQuery } from "./querystring";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { setNoCacheHeaders } from "./headers.js";
|
|
2
|
+
import { stringifyQuery } from "./querystring.js";
|
|
3
|
+
function redirectResponse(params) {
|
|
4
|
+
const query = params.query ? stringifyQuery(params.query) : "";
|
|
5
|
+
const permanent = 301 === params.status;
|
|
6
|
+
const response = {
|
|
7
|
+
statusCode: params.status || 302,
|
|
8
|
+
statusDescription: 301 === params.status ? "Moved permanently" : "Found",
|
|
9
|
+
headers: {
|
|
10
|
+
location: {
|
|
11
|
+
value: params.url + query
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
if (!permanent) setNoCacheHeaders(response.headers);
|
|
16
|
+
return response;
|
|
17
|
+
}
|
|
18
|
+
export { redirectResponse };
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
// For temporary redirects make sure they won't be cached.
|
|
18
|
-
setNoCacheHeaders(response.headers);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return response;
|
|
22
|
-
}
|
|
20
|
+
//# sourceMappingURL=redirect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"cloudfrontFunctions/redirect.js","sources":["../../src/cloudfrontFunctions/redirect.ts"],"sourcesContent":["import type { CloudFrontQuery, CloudFrontResponse } from \"./types.js\";\nimport { setNoCacheHeaders } from \"./headers.js\";\nimport { stringifyQuery } from \"./querystring.js\";\n\ninterface RedirectParams {\n url: string;\n query?: CloudFrontQuery;\n status?: number;\n}\n\nexport function redirectResponse(params: RedirectParams) {\n const query = params.query ? stringifyQuery(params.query) : \"\";\n const permanent = params.status === 301;\n\n const response: CloudFrontResponse = {\n statusCode: params.status || 302,\n statusDescription: params.status === 301 ? \"Moved permanently\" : \"Found\",\n headers: {\n location: { value: params.url + query }\n }\n };\n\n if (!permanent) {\n // For temporary redirects make sure they won't be cached.\n setNoCacheHeaders(response.headers);\n }\n\n return response;\n}\n"],"names":["redirectResponse","params","query","stringifyQuery","permanent","response","setNoCacheHeaders"],"mappings":";;AAUO,SAASA,iBAAiBC,MAAsB;IACnD,MAAMC,QAAQD,OAAO,KAAK,GAAGE,eAAeF,OAAO,KAAK,IAAI;IAC5D,MAAMG,YAAYH,AAAkB,QAAlBA,OAAO,MAAM;IAE/B,MAAMI,WAA+B;QACjC,YAAYJ,OAAO,MAAM,IAAI;QAC7B,mBAAmBA,AAAkB,QAAlBA,OAAO,MAAM,GAAW,sBAAsB;QACjE,SAAS;YACL,UAAU;gBAAE,OAAOA,OAAO,GAAG,GAAGC;YAAM;QAC1C;IACJ;IAEA,IAAI,CAACE,WAEDE,kBAAkBD,SAAS,OAAO;IAGtC,OAAOA;AACX"}
|
|
@@ -11,15 +11,15 @@ export interface ResponseCookie extends SingleValue {
|
|
|
11
11
|
* In principle you may have multiple same headers and cookies in one request or response.
|
|
12
12
|
* This is a wrapper interface for simpler use.
|
|
13
13
|
*/
|
|
14
|
-
export
|
|
14
|
+
export type MultiValue<T> = T & {
|
|
15
15
|
/** Additional values for the same item (for example multiple values for the same cookie.) */
|
|
16
16
|
multivalue?: T[];
|
|
17
17
|
};
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
18
|
+
export type MultiValueDictionary<T> = Record<string, MultiValue<T> | undefined>;
|
|
19
|
+
export type CloudFrontHeaders = MultiValueDictionary<SingleValue>;
|
|
20
|
+
export type CloudFrontRequestCookies = MultiValueDictionary<SingleValue>;
|
|
21
|
+
export type CloudFrontResponseCookies = MultiValueDictionary<ResponseCookie>;
|
|
22
|
+
export type CloudFrontQuery = MultiValueDictionary<SingleValue>;
|
|
23
23
|
/**
|
|
24
24
|
* Interface type for request in CloudFront Functions
|
|
25
25
|
* see: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-event-structure.html
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Lambdas use exports, but CloudFront Functions use a global `handler` variable.
|
|
5
|
-
* This way you only have to run the function within your handler script,
|
|
6
|
-
* and you are provided with working handler and full typing.
|
|
7
|
-
**/
|
|
8
|
-
export function defineCloudfrontFunctionRequestHandler(handler) {
|
|
9
|
-
global.handler = handler;
|
|
1
|
+
import { __webpack_require__ } from "../rslib-runtime.js";
|
|
2
|
+
function defineCloudfrontFunctionRequestHandler(handler) {
|
|
3
|
+
__webpack_require__.g.handler = handler;
|
|
10
4
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* This way you only have to run the function within your handler script,
|
|
16
|
-
* and you are provided with working handler and full typing.
|
|
17
|
-
**/
|
|
5
|
+
function defineCloudfrontFunctionResponseHandler(handler) {
|
|
6
|
+
__webpack_require__.g.handler = handler;
|
|
7
|
+
}
|
|
8
|
+
export { defineCloudfrontFunctionRequestHandler, defineCloudfrontFunctionResponseHandler };
|
|
18
9
|
|
|
19
|
-
|
|
20
|
-
global.handler = handler;
|
|
21
|
-
}
|
|
10
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"cloudfrontFunctions/utils.js","sources":["../../src/cloudfrontFunctions/utils.ts"],"sourcesContent":["import type { CloudFrontRequestHandler, CloudFrontResponseHandler } from \"./types.js\";\n\ndeclare const global: typeof globalThis & {\n handler: CloudFrontRequestHandler | CloudFrontResponseHandler;\n};\n\n/**\n * Helper function to easier define CloudFront Function request handler.\n *\n * Lambdas use exports, but CloudFront Functions use a global `handler` variable.\n * This way you only have to run the function within your handler script,\n * and you are provided with working handler and full typing.\n **/\nexport function defineCloudfrontFunctionRequestHandler(handler: CloudFrontRequestHandler) {\n global.handler = handler;\n}\n\n/**\n * Helper function to easier define CloudFront Function response handler.\n *\n * Lambdas use exports, but CloudFront Functions use a global `handler` variable.\n * This way you only have to run the function within your handler script,\n * and you are provided with working handler and full typing.\n **/\nexport function defineCloudfrontFunctionResponseHandler(handler: CloudFrontResponseHandler) {\n global.handler = handler;\n}\n"],"names":["defineCloudfrontFunctionRequestHandler","handler","global","defineCloudfrontFunctionResponseHandler"],"mappings":";AAaO,SAASA,uCAAuCC,OAAiC;IACpFC,oBAAAA,CAAMA,CAAC,OAAO,GAAGD;AACrB;AASO,SAASE,wCAAwCF,OAAkC;IACtFC,oBAAAA,CAAMA,CAAC,OAAO,GAAGD;AACrB"}
|
package/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./lambdaEdge";
|
|
1
|
+
export * from "./lambdaEdge/index.js";
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./lambdaEdge";
|
|
1
|
+
export * from "./lambdaEdge/index.js";
|
package/lambdaEdge/cookies.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { CloudFrontRequest, CloudFrontResponse } from "./types";
|
|
1
|
+
import type { CloudFrontRequest, CloudFrontResponse } from "./types.js";
|
|
2
2
|
export declare function getRequestCookies(request: CloudFrontRequest): Record<string, string | undefined>;
|
|
3
3
|
export declare function setResponseCookie(response: CloudFrontResponse, cookie: string): void;
|
package/lambdaEdge/cookies.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
import { getHeader } from "./headers";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { getHeader } from "./headers.js";
|
|
2
|
+
function getRequestCookies(request) {
|
|
3
|
+
const header = getHeader(request.headers, "cookie");
|
|
4
|
+
const cookies = {};
|
|
5
|
+
if (!header) return cookies;
|
|
6
|
+
const cookiesArray = decodeURIComponent(header).split(";");
|
|
7
|
+
for (const cookie of cookiesArray){
|
|
8
|
+
const [name, value] = cookie.trim().split("=");
|
|
9
|
+
cookies[name] = value;
|
|
10
|
+
}
|
|
7
11
|
return cookies;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const cookiesArray = decodeURIComponent(header).split(";");
|
|
11
|
-
|
|
12
|
-
for (const cookie of cookiesArray) {
|
|
13
|
-
const [name, value] = cookie.trim().split("=");
|
|
14
|
-
cookies[name] = value;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return cookies;
|
|
18
12
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
13
|
+
function setResponseCookie(response, cookie) {
|
|
14
|
+
const headers = response.headers;
|
|
15
|
+
const cookies = headers["set-cookie"] || (headers["set-cookie"] = []);
|
|
16
|
+
cookies.push({
|
|
17
|
+
value: cookie
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export { getRequestCookies, setResponseCookie };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=cookies.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"lambdaEdge/cookies.js","sources":["../../src/lambdaEdge/cookies.ts"],"sourcesContent":["import { getHeader } from \"./headers.js\";\nimport type { CloudFrontRequest, CloudFrontResponse } from \"./types.js\";\n\nexport function getRequestCookies(request: CloudFrontRequest) {\n const header = getHeader(request.headers, \"cookie\");\n const cookies: Record<string, string | undefined> = {};\n\n if (!header) {\n return cookies;\n }\n\n const cookiesArray = decodeURIComponent(header).split(\";\");\n\n for (const cookie of cookiesArray) {\n const [name, value] = cookie.trim().split(\"=\");\n cookies[name] = value;\n }\n\n return cookies;\n}\n\nexport function setResponseCookie(response: CloudFrontResponse, cookie: string) {\n const headers = response.headers;\n const cookies = headers[\"set-cookie\"] || (headers[\"set-cookie\"] = []);\n\n cookies.push({\n value: cookie\n });\n}\n"],"names":["getRequestCookies","request","header","getHeader","cookies","cookiesArray","decodeURIComponent","cookie","name","value","setResponseCookie","response","headers"],"mappings":";AAGO,SAASA,kBAAkBC,OAA0B;IACxD,MAAMC,SAASC,UAAUF,QAAQ,OAAO,EAAE;IAC1C,MAAMG,UAA8C,CAAC;IAErD,IAAI,CAACF,QACD,OAAOE;IAGX,MAAMC,eAAeC,mBAAmBJ,QAAQ,KAAK,CAAC;IAEtD,KAAK,MAAMK,UAAUF,aAAc;QAC/B,MAAM,CAACG,MAAMC,MAAM,GAAGF,OAAO,IAAI,GAAG,KAAK,CAAC;QAC1CH,OAAO,CAACI,KAAK,GAAGC;IACpB;IAEA,OAAOL;AACX;AAEO,SAASM,kBAAkBC,QAA4B,EAAEJ,MAAc;IAC1E,MAAMK,UAAUD,SAAS,OAAO;IAChC,MAAMP,UAAUQ,OAAO,CAAC,aAAa,IAAKA,CAAAA,OAAO,CAAC,aAAa,GAAG,EAAC;IAEnER,QAAQ,IAAI,CAAC;QACT,OAAOG;IACX;AACJ"}
|
package/lambdaEdge/headers.d.ts
CHANGED
package/lambdaEdge/headers.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
function setHeader(headers, header) {
|
|
2
|
+
headers[header.key] = [
|
|
3
|
+
header
|
|
4
|
+
];
|
|
3
5
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
function getHeader(headers, header) {
|
|
7
|
+
return headers?.[header]?.[0].value;
|
|
8
|
+
}
|
|
9
|
+
export { getHeader, setHeader };
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
}
|
|
11
|
+
//# sourceMappingURL=headers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"lambdaEdge/headers.js","sources":["../../src/lambdaEdge/headers.ts"],"sourcesContent":["import type { CloudFrontHeaders } from \"./types.js\";\n\nexport function setHeader(headers: CloudFrontHeaders, header: { key: string; value: string }) {\n headers[header.key] = [header];\n}\n\nexport function getHeader(headers: CloudFrontHeaders | undefined, header: string) {\n return headers?.[header]?.[0].value;\n}\n"],"names":["setHeader","headers","header","getHeader"],"mappings":"AAEO,SAASA,UAAUC,OAA0B,EAAEC,MAAsC;IACxFD,OAAO,CAACC,OAAO,GAAG,CAAC,GAAG;QAACA;KAAO;AAClC;AAEO,SAASC,UAAUF,OAAsC,EAAEC,MAAc;IAC5E,OAAOD,SAAS,CAACC,OAAO,EAAE,CAAC,EAAE,CAAC;AAClC"}
|
package/lambdaEdge/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./cookies";
|
|
2
|
-
export * from "./headers";
|
|
3
|
-
export * from "./redirect";
|
|
4
|
-
export * from "./request";
|
|
5
|
-
export * from "./response";
|
|
6
|
-
export * from "./types";
|
|
7
|
-
export * from "./utils";
|
|
1
|
+
export * from "./cookies.js";
|
|
2
|
+
export * from "./headers.js";
|
|
3
|
+
export * from "./redirect.js";
|
|
4
|
+
export * from "./request.js";
|
|
5
|
+
export * from "./response.js";
|
|
6
|
+
export * from "./types.js";
|
|
7
|
+
export * from "./utils.js";
|
package/lambdaEdge/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./cookies";
|
|
2
|
-
export * from "./headers";
|
|
3
|
-
export * from "./redirect";
|
|
4
|
-
export * from "./request";
|
|
5
|
-
export * from "./response";
|
|
6
|
-
export * from "./types";
|
|
7
|
-
export * from "./utils";
|
|
1
|
+
export * from "./cookies.js";
|
|
2
|
+
export * from "./headers.js";
|
|
3
|
+
export * from "./redirect.js";
|
|
4
|
+
export * from "./request.js";
|
|
5
|
+
export * from "./response.js";
|
|
6
|
+
export * from "./types.js";
|
|
7
|
+
export * from "./utils.js";
|
package/lambdaEdge/redirect.d.ts
CHANGED