-
Notifications
You must be signed in to change notification settings - Fork 934
Add httpsCallableFromURL #6162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add httpsCallableFromURL #6162
Changes from 6 commits
f7d06bc
8fec94c
a5108a6
cdd1221
95b26f8
a9fb73b
87e21de
724f9a7
24e82d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@firebase/functions-compat": patch | ||
"@firebase/functions": patch | ||
"firebase-size-analysis": patch | ||
--- | ||
|
||
Add httpsCallableFromURL |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,52 @@ | ||
## API Report File for "@firebase/functions" | ||
|
||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). | ||
|
||
```ts | ||
|
||
import { FirebaseApp } from '@firebase/app'; | ||
import { FirebaseError } from '@firebase/util'; | ||
|
||
// @public | ||
export function connectFunctionsEmulator(functionsInstance: Functions, host: string, port: number): void; | ||
|
||
// @public | ||
export interface Functions { | ||
app: FirebaseApp; | ||
customDomain: string | null; | ||
region: string; | ||
} | ||
|
||
// @public | ||
export interface FunctionsError extends FirebaseError { | ||
readonly code: FunctionsErrorCode; | ||
readonly details?: unknown; | ||
} | ||
|
||
// @public | ||
export 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'; | ||
|
||
// @public | ||
export function getFunctions(app?: FirebaseApp, regionOrCustomDomain?: string): Functions; | ||
|
||
// @public | ||
export type HttpsCallable<RequestData = unknown, ResponseData = unknown> = (data?: RequestData | null) => Promise<HttpsCallableResult<ResponseData>>; | ||
|
||
// @public | ||
export function httpsCallable<RequestData = unknown, ResponseData = unknown>(functionsInstance: Functions, name: string, options?: HttpsCallableOptions): HttpsCallable<RequestData, ResponseData>; | ||
|
||
// @public | ||
export interface HttpsCallableOptions { | ||
timeout?: number; | ||
} | ||
|
||
// @public | ||
export interface HttpsCallableResult<ResponseData = unknown> { | ||
readonly data: ResponseData; | ||
} | ||
|
||
|
||
``` | ||
## API Report File for "@firebase/functions" | ||
|
||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). | ||
|
||
```ts | ||
|
||
import { FirebaseApp } from '@firebase/app'; | ||
import { FirebaseError } from '@firebase/util'; | ||
|
||
// @public | ||
export function connectFunctionsEmulator(functionsInstance: Functions, host: string, port: number): void; | ||
|
||
// @public | ||
export interface Functions { | ||
app: FirebaseApp; | ||
customDomain: string | null; | ||
region: string; | ||
} | ||
|
||
// @public | ||
export interface FunctionsError extends FirebaseError { | ||
readonly code: FunctionsErrorCode; | ||
readonly details?: unknown; | ||
} | ||
|
||
// @public | ||
export 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'; | ||
|
||
// @public | ||
export function getFunctions(app?: FirebaseApp, regionOrCustomDomain?: string): Functions; | ||
|
||
// @public | ||
export type HttpsCallable<RequestData = unknown, ResponseData = unknown> = (data?: RequestData | null) => Promise<HttpsCallableResult<ResponseData>>; | ||
|
||
// @public | ||
export function httpsCallable<RequestData = unknown, ResponseData = unknown>(functionsInstance: Functions, name: string, options?: HttpsCallableOptions): HttpsCallable<RequestData, ResponseData>; | ||
|
||
// @public | ||
export function httpsCallableFromURL<RequestData = unknown, ResponseData = unknown>(functionsInstance: Functions, url: string, options?: HttpsCallableOptions): HttpsCallable<RequestData, ResponseData>; | ||
|
||
// @public | ||
export interface HttpsCallableOptions { | ||
timeout?: number; | ||
} | ||
|
||
// @public | ||
export interface HttpsCallableResult<ResponseData = unknown> { | ||
readonly data: ResponseData; | ||
} | ||
|
||
|
||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,11 +118,28 @@ async function authLogout(app) { | |
*/ | ||
async function callFunctions(app) { | ||
console.log('[FUNCTIONS] start'); | ||
const functions = getFunctions(app); | ||
const callTest = httpsCallable(functions, 'callTest'); | ||
let functions = getFunctions(app); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
let callTest = httpsCallable(functions, 'callTest'); | ||
try { | ||
const result = await callTest({ data: 'blah' }); | ||
console.log('[FUNCTIONS] result:', result.data); | ||
console.log('[FUNCTIONS] result (by name):', result.data); | ||
} catch (e) { | ||
if (e.message.includes('Unauthenticated')) { | ||
console.warn( | ||
'Functions blocked by App Check. ' + | ||
'Activate app check with a live sitekey to allow Functions calls' | ||
); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
callTest = httpsCallableByUrl( | ||
functions, | ||
`https://us-central-${app.options.projectId}.cloudfunctions.net/callTest` | ||
); | ||
try { | ||
const result = await callTest({ data: 'blah' }); | ||
console.log('[FUNCTIONS] result (by URL):', result.data); | ||
} catch (e) { | ||
if (e.message.includes('Unauthenticated')) { | ||
console.warn( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,8 @@ import { | |
FunctionsService, | ||
DEFAULT_REGION, | ||
connectFunctionsEmulator as _connectFunctionsEmulator, | ||
httpsCallable as _httpsCallable | ||
httpsCallable as _httpsCallable, | ||
httpsCallableFromURL as _httpsCallableFromURL | ||
} from './service'; | ||
import { getModularInstance } from '@firebase/util'; | ||
|
||
|
@@ -90,3 +91,23 @@ export function httpsCallable<RequestData = unknown, ResponseData = unknown>( | |
options | ||
); | ||
} | ||
|
||
/** | ||
* Returns a reference to the callable HTTPS trigger with the given name. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "given name" => "specified URL"? |
||
* @param url - The url of the trigger. | ||
* @public | ||
*/ | ||
export function httpsCallableFromURL< | ||
RequestData = unknown, | ||
ResponseData = unknown | ||
>( | ||
functionsInstance: Functions, | ||
url: string, | ||
options?: HttpsCallableOptions | ||
): HttpsCallable<RequestData, ResponseData> { | ||
return _httpsCallableFromURL<RequestData, ResponseData>( | ||
getModularInstance<FunctionsService>(functionsInstance as FunctionsService), | ||
url, | ||
options | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,12 @@ | |
"path": "functions", | ||
"imports": [ | ||
"getFunctions", | ||
"httpsCallable" | ||
"httpsCallable", | ||
"httpsCallableFromURL" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't need to be added here, this represents a typical bundle of imports for a use case and it's not a common case that a developer would use httpsCallable and httpsCallableFromURL in the same app. In any case, since httpsCallable wraps the core code of httpsCallableFromURL, the bundle size should be about the same. |
||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It still thinks there's a whitespace change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dunno why my formatter keeps on insisting on this. Edited in vim to avoid stripping the newline. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
firebase-size-analysis
can be removed, it's in the ignored changesets list. Actually, the change to that file seems unneeded (see below) so also for that reason.