1 |
|
2 |
|
3 |
|
4 | import { Cookie } from '@azure/functions';
|
5 | import { RpcHttpCookie, RpcHttpCookieSameSite } from '@azure/functions-core';
|
6 | import { toNullableBool, toNullableDouble, toNullableString, toNullableTimestamp, toRpcString } from './toRpcNullable';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export function toRpcHttpCookie(inputCookie: Cookie): RpcHttpCookie {
|
13 |
|
14 | let rpcSameSite: RpcHttpCookieSameSite = 'none';
|
15 | if (inputCookie && inputCookie.sameSite) {
|
16 | const sameSite = inputCookie.sameSite.toLocaleLowerCase();
|
17 | if (sameSite === 'lax') {
|
18 | rpcSameSite = 'lax';
|
19 | } else if (sameSite === 'strict') {
|
20 | rpcSameSite = 'strict';
|
21 | } else if (sameSite === 'none') {
|
22 | rpcSameSite = 'explicitNone';
|
23 | }
|
24 | }
|
25 |
|
26 | const rpcCookie: RpcHttpCookie = {
|
27 | name: inputCookie && toRpcString(inputCookie.name, 'cookie.name'),
|
28 | value: inputCookie && toRpcString(inputCookie.value, 'cookie.value'),
|
29 | domain: toNullableString(inputCookie && inputCookie.domain, 'cookie.domain'),
|
30 | path: toNullableString(inputCookie && inputCookie.path, 'cookie.path'),
|
31 | expires: toNullableTimestamp(inputCookie && inputCookie.expires, 'cookie.expires'),
|
32 | secure: toNullableBool(inputCookie && inputCookie.secure, 'cookie.secure'),
|
33 | httpOnly: toNullableBool(inputCookie && inputCookie.httpOnly, 'cookie.httpOnly'),
|
34 | sameSite: rpcSameSite,
|
35 | maxAge: toNullableDouble(inputCookie && inputCookie.maxAge, 'cookie.maxAge'),
|
36 | };
|
37 |
|
38 | return rpcCookie;
|
39 | }
|