UNPKG

5.32 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2018 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * An HttpsCallableResult wraps a single result from a function call.
20 */
21export interface HttpsCallableResult {
22 readonly data: any;
23}
24
25/**
26 * An HttpsCallable is a reference to a "callable" http trigger in
27 * Google Cloud Functions.
28 */
29export interface HttpsCallable {
30 (data?: {} | null): Promise<HttpsCallableResult>;
31}
32
33/**
34 * HttpsCallableOptions specify metadata about how calls should be executed.
35 */
36export interface HttpsCallableOptions {
37 timeout?: number; // in millis
38}
39
40/**
41 * `FirebaseFunctions` represents a Functions app, and is the entry point for
42 * all Functions operations.
43 */
44export class FirebaseFunctions {
45 private constructor();
46
47 /**
48 * Gets an `HttpsCallable` instance that refers to the function with the given
49 * name.
50 *
51 * @param name The name of the https callable function.
52 * @return The `HttpsCallable` instance.
53 */
54 httpsCallable(name: string, options?: HttpsCallableOptions): HttpsCallable;
55
56 /**
57 * Modify this instance to communicate with the Cloud Functions emulator.
58 *
59 * Note: this must be called before this instance has been used to do any operations.
60 *
61 * @param host The emulator host (ex: localhost)
62 * @param port The emulator port (ex: 5001)
63 */
64 useEmulator(host: string, port: number): void;
65
66 /**
67 * Changes this instance to point to a Cloud Functions emulator running
68 * locally. See https://firebase.google.com/docs/functions/local-emulator
69 *
70 * @deprecated Prefer the useEmulator(host, port) method.
71 * @param origin The origin of the local emulator, such as
72 * "http://localhost:5005".
73 */
74 useFunctionsEmulator(origin: string): void;
75}
76
77/**
78 * The set of Firebase Functions status codes. The codes are the same at the
79 * ones exposed by gRPC here:
80 * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
81 *
82 * Possible values:
83 * - 'cancelled': The operation was cancelled (typically by the caller).
84 * - 'unknown': Unknown error or an error from a different error domain.
85 * - 'invalid-argument': Client specified an invalid argument. Note that this
86 * differs from 'failed-precondition'. 'invalid-argument' indicates
87 * arguments that are problematic regardless of the state of the system
88 * (e.g. an invalid field name).
89 * - 'deadline-exceeded': Deadline expired before operation could complete.
90 * For operations that change the state of the system, this error may be
91 * returned even if the operation has completed successfully. For example,
92 * a successful response from a server could have been delayed long enough
93 * for the deadline to expire.
94 * - 'not-found': Some requested document was not found.
95 * - 'already-exists': Some document that we attempted to create already
96 * exists.
97 * - 'permission-denied': The caller does not have permission to execute the
98 * specified operation.
99 * - 'resource-exhausted': Some resource has been exhausted, perhaps a
100 * per-user quota, or perhaps the entire file system is out of space.
101 * - 'failed-precondition': Operation was rejected because the system is not
102 * in a state required for the operation's execution.
103 * - 'aborted': The operation was aborted, typically due to a concurrency
104 * issue like transaction aborts, etc.
105 * - 'out-of-range': Operation was attempted past the valid range.
106 * - 'unimplemented': Operation is not implemented or not supported/enabled.
107 * - 'internal': Internal errors. Means some invariants expected by
108 * underlying system has been broken. If you see one of these errors,
109 * something is very broken.
110 * - 'unavailable': The service is currently unavailable. This is most likely
111 * a transient condition and may be corrected by retrying with a backoff.
112 * - 'data-loss': Unrecoverable data loss or corruption.
113 * - 'unauthenticated': The request does not have valid authentication
114 * credentials for the operation.
115 */
116export type FunctionsErrorCode =
117 | 'ok'
118 | 'cancelled'
119 | 'unknown'
120 | 'invalid-argument'
121 | 'deadline-exceeded'
122 | 'not-found'
123 | 'already-exists'
124 | 'permission-denied'
125 | 'resource-exhausted'
126 | 'failed-precondition'
127 | 'aborted'
128 | 'out-of-range'
129 | 'unimplemented'
130 | 'internal'
131 | 'unavailable'
132 | 'data-loss'
133 | 'unauthenticated';
134
135export interface HttpsError extends Error {
136 /**
137 * A standard error code that will be returned to the client. This also
138 * determines the HTTP status code of the response, as defined in code.proto.
139 */
140 readonly code: FunctionsErrorCode;
141
142 /**
143 * Extra data to be converted to JSON and included in the error response.
144 */
145 readonly details?: any;
146}
147
148declare module '@firebase/component' {
149 interface NameServiceMapping {
150 'functions-compat': FirebaseFunctions;
151 }
152}