UNPKG

6.21 kBTypeScriptView Raw
1/**
2 * Cloud Functions for Firebase
3 *
4 * @packageDocumentation
5 */
6
7import { FirebaseApp } from '@firebase/app';
8import { FirebaseError } from '@firebase/util';
9
10/**
11 * Modify this instance to communicate with the Cloud Functions emulator.
12 *
13 * Note: this must be called before this instance has been used to do any operations.
14 *
15 * @param host - The emulator host (ex: localhost)
16 * @param port - The emulator port (ex: 5001)
17 * @public
18 */
19export declare function connectFunctionsEmulator(functionsInstance: Functions, host: string, port: number): void;
20
21/**
22 * A `Functions` instance.
23 * @public
24 */
25export declare interface Functions {
26 /**
27 * The {@link @firebase/app#FirebaseApp} this `Functions` instance is associated with.
28 */
29 app: FirebaseApp;
30 /**
31 * The region the callable Cloud Functions are located in.
32 * Default is `us-central-1`.
33 */
34 region: string;
35 /**
36 * A custom domain hosting the callable Cloud Functions.
37 * ex: https://mydomain.com
38 */
39 customDomain: string | null;
40}
41
42/**
43 * An error returned by the Firebase Functions client SDK.
44 * @public
45 */
46export declare interface FunctionsError extends FirebaseError {
47 /**
48 * A standard error code that will be returned to the client. This also
49 * determines the HTTP status code of the response, as defined in code.proto.
50 */
51 readonly code: FunctionsErrorCode;
52 /**
53 * Extra data to be converted to JSON and included in the error response.
54 */
55 readonly details?: unknown;
56}
57
58/**
59 * The set of Firebase Functions status codes. The codes are the same at the
60 * ones exposed by gRPC here:
61 * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
62 *
63 * Possible values:
64 * - 'cancelled': The operation was cancelled (typically by the caller).
65 * - 'unknown': Unknown error or an error from a different error domain.
66 * - 'invalid-argument': Client specified an invalid argument. Note that this
67 * differs from 'failed-precondition'. 'invalid-argument' indicates
68 * arguments that are problematic regardless of the state of the system
69 * (e.g. an invalid field name).
70 * - 'deadline-exceeded': Deadline expired before operation could complete.
71 * For operations that change the state of the system, this error may be
72 * returned even if the operation has completed successfully. For example,
73 * a successful response from a server could have been delayed long enough
74 * for the deadline to expire.
75 * - 'not-found': Some requested document was not found.
76 * - 'already-exists': Some document that we attempted to create already
77 * exists.
78 * - 'permission-denied': The caller does not have permission to execute the
79 * specified operation.
80 * - 'resource-exhausted': Some resource has been exhausted, perhaps a
81 * per-user quota, or perhaps the entire file system is out of space.
82 * - 'failed-precondition': Operation was rejected because the system is not
83 * in a state required for the operation's execution.
84 * - 'aborted': The operation was aborted, typically due to a concurrency
85 * issue like transaction aborts, etc.
86 * - 'out-of-range': Operation was attempted past the valid range.
87 * - 'unimplemented': Operation is not implemented or not supported/enabled.
88 * - 'internal': Internal errors. Means some invariants expected by
89 * underlying system has been broken. If you see one of these errors,
90 * something is very broken.
91 * - 'unavailable': The service is currently unavailable. This is most likely
92 * a transient condition and may be corrected by retrying with a backoff.
93 * - 'data-loss': Unrecoverable data loss or corruption.
94 * - 'unauthenticated': The request does not have valid authentication
95 * credentials for the operation.
96 * @public
97 */
98export declare type FunctionsErrorCode = 'ok' | 'cancelled' | 'unknown' | 'invalid-argument' | 'deadline-exceeded' | 'not-found' | 'already-exists' | 'permission-denied' | 'resource-exhausted' | 'failed-precondition' | 'aborted' | 'out-of-range' | 'unimplemented' | 'internal' | 'unavailable' | 'data-loss' | 'unauthenticated';
99
100/**
101 * Returns a {@link Functions} instance for the given app.
102 * @param app - The {@link @firebase/app#FirebaseApp} to use.
103 * @param regionOrCustomDomain - one of:
104 * a) The region the callable functions are located in (ex: us-central1)
105 * b) A custom domain hosting the callable functions (ex: https://mydomain.com)
106 * @public
107 */
108export declare function getFunctions(app?: FirebaseApp, regionOrCustomDomain?: string): Functions;
109
110/**
111 * A reference to a "callable" HTTP trigger in Google Cloud Functions.
112 * @param data - Data to be passed to callable function.
113 * @public
114 */
115export declare type HttpsCallable<RequestData = unknown, ResponseData = unknown> = (data?: RequestData | null) => Promise<HttpsCallableResult<ResponseData>>;
116
117/**
118 * Returns a reference to the callable HTTPS trigger with the given name.
119 * @param name - The name of the trigger.
120 * @public
121 */
122export declare function httpsCallable<RequestData = unknown, ResponseData = unknown>(functionsInstance: Functions, name: string, options?: HttpsCallableOptions): HttpsCallable<RequestData, ResponseData>;
123
124/**
125 * Returns a reference to the callable HTTPS trigger with the specified url.
126 * @param url - The url of the trigger.
127 * @public
128 */
129export declare function httpsCallableFromURL<RequestData = unknown, ResponseData = unknown>(functionsInstance: Functions, url: string, options?: HttpsCallableOptions): HttpsCallable<RequestData, ResponseData>;
130
131/**
132 * An interface for metadata about how calls should be executed.
133 * @public
134 */
135export declare interface HttpsCallableOptions {
136 /**
137 * Time in milliseconds after which to cancel if there is no response.
138 * Default is 70000.
139 */
140 timeout?: number;
141}
142
143/**
144 * An `HttpsCallableResult` wraps a single result from a function call.
145 * @public
146 */
147export declare interface HttpsCallableResult<ResponseData = unknown> {
148 /**
149 * Data returned from callable function.
150 */
151 readonly data: ResponseData;
152}
153
154export { }