Skip to content

Commit c5b3263

Browse files
stern-shawndkundel
authored andcommitted
docs(runtime-types): adds TSDoc comments to TwilioResponse methods
1 parent 8ba1166 commit c5b3263

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed

packages/serverless-runtime-types/types.d.ts

+152
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,163 @@ export type AssetResourceMap = {
2222
};
2323

2424
export interface TwilioResponse {
25+
/**
26+
* Set the status code of the response.
27+
* @param code - Integer value of the status code
28+
* @returns This Response object to enable method chaining
29+
*
30+
* @see https://www.twilio.com/docs/runtime/functions/invocation#twilio-response-methods
31+
*
32+
* Example usage of Response.setStatusCode():
33+
* ```ts
34+
* exports.handler = (context, event, callback) => {
35+
* const response = new Twilio.Response();
36+
* // Set the status code to 204 Not Content
37+
* response.setStatusCode(204);
38+
*
39+
* return callback(null, response);
40+
* };
41+
* ```
42+
*
43+
*/
2544
setStatusCode(code: number): TwilioResponse;
45+
/**
46+
* Set the body of the response. Takes either a string or an object.
47+
* @param body - The body of the response
48+
* @returns This Response object to enable method chaining
49+
*
50+
* @see https://www.twilio.com/docs/runtime/functions/invocation#twilio-response-methods
51+
*
52+
* Example usage of Response.setBody() with a string
53+
* ```ts
54+
* exports.handler = (context, event, callback) => {
55+
* const response = new Twilio.Response();
56+
* // Set the response body
57+
* response.setBody('Everything is fine');
58+
*
59+
* return callback(null, response);
60+
* };
61+
* ```
62+
*
63+
* Example usage of Response.setBody() with an object
64+
* ```ts
65+
* exports.handler = (context, event, callback) => {
66+
* const response = new Twilio.Response();
67+
* // Set the response body
68+
* response.setBody({ everything: 'is fine' });
69+
*
70+
* return callback(null, response);
71+
* };
72+
* ```
73+
*/
2674
setBody(body: string | object): TwilioResponse;
75+
/**
76+
* Adds a header to the HTTP response. The first argument specifies the header name and the second argument the header value.
77+
*
78+
* If Response.appendHeader is called with the name of a header that already exists on this Response object, that header will be converted from a string to an array, and the provided value will be concatenated to that array of values.
79+
*
80+
* @param key - The name of the header
81+
* @param value - The value of the header
82+
* @returns This Response object to enable method chaining
83+
*
84+
* @see https://www.twilio.com/docs/runtime/functions/headers-and-cookies/setting-and-modifying#responseappendheaderkey-value
85+
*
86+
* Example usage of Response.appendHeader()
87+
* ```ts
88+
* exports.handler = (context, event, callback) => {
89+
* const response = new Twilio.Response();
90+
* response
91+
* .appendHeader('content-type', 'application/json')
92+
* // You can append a multi-value header by passing a list of strings
93+
* .appendHeader('yes', ['no', 'maybe', 'so'])
94+
* // Instead of setting the header to an array, it's also valid to
95+
* // pass a comma-separated string of values
96+
* .appendHeader('cache-control', 'no-store, max-age=0');
97+
* .appendHeader('never', 'gonna')
98+
* // Appending a header that already exists will convert that header to
99+
* // a multi-value header and concatenate the new value
100+
* .appendHeader('never', 'give')
101+
* .appendHeader('never', 'you')
102+
* .appendHeader('never', 'up');
103+
* // The header is now `'never': ['gonna', 'give', 'you', 'up']`
104+
*
105+
* return callback(null, response);
106+
* };
107+
* ```
108+
*/
27109
appendHeader(key: string, value: string): TwilioResponse;
110+
/**
111+
* Set multiple headers on the HTTP response in one method call. Accepts an object of key-value pairs of headers and their corresponding values. You may also set multi-value headers by making the intended header an array.
112+
*
113+
* @param headers - An object of headers to append to the response. Can include set-cookie
114+
* @returns This Response object to enable method chaining
115+
*
116+
* @see https://www.twilio.com/docs/runtime/functions/headers-and-cookies/setting-and-modifying#responsesetheadersheaders
117+
*
118+
* Example usage of Response.setHeaders()
119+
* ```ts
120+
* exports.handler = (context, event, callback) => {
121+
* const response = new Twilio.Response();
122+
* response.setHeaders({
123+
* // Set a single header
124+
* 'content-type': 'application/json',
125+
* // You can set a header with multiple values by providing an array
126+
* 'cache-control': ['no-cache', 'private'],
127+
* // You may also optionally set cookies via the "Set-Cookie" key
128+
* 'set-cookie': 'Foo=Bar',
129+
* });
130+
*
131+
* return callback(null, response);
132+
* };
133+
* ```
134+
*/
28135
setHeaders(headers: { [key: string]: string }): TwilioResponse;
136+
/**
137+
* Add a cookie to the HTTP response. Accepts the name of the cookie, its value, and any optional attributes to be assigned to the cookie
138+
*
139+
* @param key - The name of the cookie to be set
140+
* @param value - The value of the cookie
141+
* @param attributes - Optional attributes to assign to the cookie
142+
* @returns This Response object to enable method chaining
143+
*
144+
* @see https://www.twilio.com/docs/runtime/functions/headers-and-cookies/setting-and-modifying#responsesetcookiekey-value-attributes
145+
*
146+
* Example usage of Response.setCookie()
147+
* ```ts
148+
* exports.handler = (context, event, callback) => {
149+
* const response = new Twilio.Response();
150+
* response
151+
* .setCookie('has_recent_activity', 'true')
152+
* .setCookie('tz', 'America/Los_Angeles', [
153+
* 'HttpOnly',
154+
* 'Secure',
155+
* 'SameSite=Strict',
156+
* 'Max-Age=86400',
157+
* ]);
158+
*
159+
* return callback(null, response);
160+
* };
161+
* ```
162+
*/
29163
setCookie(key: string, value: string, attributes?: string[]): TwilioResponse;
164+
/**
165+
* Effectively remove a specific cookie from the HTTP response. Accepts the name of the cookie to be removed, and sets the Max-Age attribute of the cookie equal to 0 so that clients and browsers will remove the cookie upon receiving the response.
166+
*
167+
* @param key - The name of the cookie to be removed
168+
* @returns This Response object to enable method chaining
169+
*
170+
* @see https://www.twilio.com/docs/runtime/functions/headers-and-cookies/setting-and-modifying#responseremovecookiekey
171+
*
172+
* Example usage of Response.removeCookie()
173+
* ```ts
174+
* exports.handler = (context, event, callback) => {
175+
* const response = new Twilio.Response();
176+
* response.removeCookie('tz');
177+
*
178+
* return callback(null, response);
179+
* };
180+
* ```
181+
*/
30182
removeCookie(key: string): TwilioResponse;
31183
}
32184

0 commit comments

Comments
 (0)