Skip to content

Commit 4825fb4

Browse files
authored
Docs review for v2.https (#1109)
* Docs review for v2.https * PR fixes * pr feedback * pr feedback
1 parent bba43ab commit 4825fb4

File tree

2 files changed

+81
-19
lines changed

2 files changed

+81
-19
lines changed

src/common/providers/https.ts

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const JWT_REGEX = /^[a-zA-Z0-9\-_=]+?\.[a-zA-Z0-9\-_=]+?\.([a-zA-Z0-9\-_=]+)?$/;
3636

3737
/** @hidden */
3838
export interface Request extends express.Request {
39+
/** The wire format representation of the request body. */
3940
rawBody: Buffer;
4041
}
4142

@@ -176,37 +177,53 @@ export interface CallableRequest<T = any> {
176177
* https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
177178
*
178179
* Possible values:
179-
* - 'cancelled': The operation was cancelled (typically by the caller).
180-
* - 'unknown': Unknown error or an error from a different error domain.
181-
* - 'invalid-argument': Client specified an invalid argument. Note that this
182-
* differs from 'failed-precondition'. 'invalid-argument' indicates
180+
*
181+
* - `cancelled`: The operation was cancelled (typically by the caller).
182+
*
183+
* - `unknown`: Unknown error or an error from a different error domain.
184+
*
185+
* - `invalid-argument`: Client specified an invalid argument. Note that this
186+
* differs from `failed-precondition`. `invalid-argument` indicates
183187
* arguments that are problematic regardless of the state of the system
184188
* (e.g. an invalid field name).
185-
* - 'deadline-exceeded': Deadline expired before operation could complete.
189+
*
190+
* - `deadline-exceeded`: Deadline expired before operation could complete.
186191
* For operations that change the state of the system, this error may be
187192
* returned even if the operation has completed successfully. For example,
188193
* a successful response from a server could have been delayed long enough
189194
* for the deadline to expire.
190-
* - 'not-found': Some requested document was not found.
191-
* - 'already-exists': Some document that we attempted to create already
195+
*
196+
* - `not-found`: Some requested document was not found.
197+
*
198+
* - `already-exists`: Some document that we attempted to create already
192199
* exists.
193-
* - 'permission-denied': The caller does not have permission to execute the
200+
*
201+
* - `permission-denied`: The caller does not have permission to execute the
194202
* specified operation.
195-
* - 'resource-exhausted': Some resource has been exhausted, perhaps a
203+
*
204+
* - `resource-exhausted`: Some resource has been exhausted, perhaps a
196205
* per-user quota, or perhaps the entire file system is out of space.
197-
* - 'failed-precondition': Operation was rejected because the system is not
206+
*
207+
* - `failed-precondition`: Operation was rejected because the system is not
198208
* in a state required for the operation's execution.
199-
* - 'aborted': The operation was aborted, typically due to a concurrency
209+
*
210+
* - `aborted`: The operation was aborted, typically due to a concurrency
200211
* issue like transaction aborts, etc.
201-
* - 'out-of-range': Operation was attempted past the valid range.
202-
* - 'unimplemented': Operation is not implemented or not supported/enabled.
203-
* - 'internal': Internal errors. Means some invariants expected by
212+
*
213+
* - `out-of-range`: Operation was attempted past the valid range.
214+
*
215+
* - `unimplemented`: Operation is not implemented or not supported/enabled.
216+
*
217+
* - `internal`: Internal errors. Means some invariants expected by
204218
* underlying system has been broken. If you see one of these errors,
205219
* something is very broken.
206-
* - 'unavailable': The service is currently unavailable. This is most likely
220+
*
221+
* - `unavailable`: The service is currently unavailable. This is most likely
207222
* a transient condition and may be corrected by retrying with a backoff.
208-
* - 'data-loss': Unrecoverable data loss or corruption.
209-
* - 'unauthenticated': The request does not have valid authentication
223+
*
224+
* - `data-loss`: Unrecoverable data loss or corruption.
225+
*
226+
* - `unauthenticated`: The request does not have valid authentication
210227
* credentials for the operation.
211228
*/
212229
export type FunctionsErrorCode =
@@ -326,6 +343,9 @@ export class HttpsError extends Error {
326343
this.httpErrorCode = errorCodeMap[code];
327344
}
328345

346+
/**
347+
* Returns a JSON-serializable representation of this object.
348+
*/
329349
public toJSON(): HttpErrorWireFormat {
330350
const {
331351
details,

src/v2/providers/https.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,62 @@ import { GlobalOptions, SupportedRegion } from '../options';
3838
export { Request, CallableRequest, FunctionsErrorCode, HttpsError };
3939

4040
/**
41-
* Options that can be set on an individual HTTPS Cloud Function.
41+
* Options that can be set on an individual HTTPS function.
4242
*/
4343
export interface HttpsOptions extends Omit<GlobalOptions, 'region'> {
44-
/* HTTP functions can override and specify more than one regions. */
44+
/** HTTP functions can override global options and can specify multiple regions to deploy to. */
4545
region?: SupportedRegion | string | Array<SupportedRegion | string>;
46+
/** If true, allows CORS on requests to this function.
47+
* If this is a `string` or `RegExp`, allows requests from domains that match the provided value.
48+
* If this is an `Array`, allows requests from domains matching at least one entry of the array.
49+
* Defaults to true for {@link CallableFunction}s and false otherwise.
50+
*/
4651
cors?: string | boolean | RegExp | Array<string | RegExp>;
4752
}
4853

54+
/**
55+
* Handles HTTPS requests.
56+
*/
4957
export type HttpsFunction = ((
58+
/** An Express request object representing the HTTPS call to the function. */
5059
req: Request,
60+
/** An Express response object, for this function to respond to callers. */
5161
res: express.Response
5262
) => void | Promise<void>) & {
63+
/** @alpha */
5364
__trigger?: unknown;
65+
/** @alpha */
5466
__endpoint: ManifestEndpoint;
5567
};
68+
69+
/**
70+
* Creates a callable method for clients to call using a Firebase SDK.
71+
*/
5672
export interface CallableFunction<T, Return> extends HttpsFunction {
73+
/** Executes the handler function with the provided data as input. Used for unit testing.
74+
* @param data - An input for the handler function.
75+
* @returns The output of the handler function.
76+
*/
5777
run(data: CallableRequest<T>): Return;
5878
}
79+
/**
80+
* Handles HTTPS requests.
81+
* @param opts - Options to set on this function
82+
* @param handler - A function that takes a {@link Request} and response object, same signature as an Express app.
83+
* @returns A function that you can export and deploy.
84+
*/
5985
export function onRequest(
6086
opts: HttpsOptions,
6187
handler: (
6288
request: Request,
6389
response: express.Response
6490
) => void | Promise<void>
6591
): HttpsFunction;
92+
/**
93+
* Handles HTTPS requests.
94+
* @param handler - A function that takes a {@link Request} and response object, same signature as an Express app.
95+
* @returns A function that you can export and deploy.
96+
*/
6697
export function onRequest(
6798
handler: (
6899
request: Request,
@@ -160,10 +191,21 @@ export function onRequest(
160191
return handler as HttpsFunction;
161192
}
162193

194+
/**
195+
* Declares a callable method for clients to call using a Firebase SDK.
196+
* @param opts - Options to set on this function.
197+
* @param handler - A function that takes a {@link CallableRequest}.
198+
* @returns A function that you can export and deploy.
199+
*/
163200
export function onCall<T = any, Return = any | Promise<any>>(
164201
opts: HttpsOptions,
165202
handler: (request: CallableRequest<T>) => Return
166203
): CallableFunction<T, Return>;
204+
/**
205+
* Declares a callable method for clients to call using a Firebase SDK.
206+
* @param handler - A function that takes a {@link CallableRequest}.
207+
* @returns A function that you can export and deploy.
208+
*/
167209
export function onCall<T = any, Return = any | Promise<any>>(
168210
handler: (request: CallableRequest<T>) => Return
169211
): CallableFunction<T, Return>;

0 commit comments

Comments
 (0)