Skip to content

Moves most of https pacakge into /common/providers/https.#915

Merged
inlined merged 5 commits intomasterfrom
inlined.common-http
Jul 14, 2021
Merged

Moves most of https pacakge into /common/providers/https.#915
inlined merged 5 commits intomasterfrom
inlined.common-http

Conversation

@inlined
Copy link
Copy Markdown
Member

@inlined inlined commented Jul 13, 2021

The actual encoding/decoding/error logic etc. of callable functions
will stay the same between v1 and v2, so they should be in a /common
file.

The rest of /v1 is about trigger options, cors, etc.

I tried to get GitHub to pick up that most of this change is a cut + paste, but it doesn't seem to want to take the hint. We may just need to trust that much of the code can be glossed over.

onCall's CORS options are part of the v1 namespace because v2 adds
a "cors" option to HttpsOptions. In the v2 API, we will default
to "cors": true, but a customer could say "cors": "my.firebase.app"
and we will respect it.

I started this change while writing the v2 namespace as a whole and pulled in a few diffs from that. One notable change in behavior is that we set __trigger.serviceAccount to null when the option default was provided. This is a bugfix because previously setting default would do nothing to __trigger.serviceAccount and we wouldn't ever update the function accordingly on deploy. firebase-tools now has meaningful nulls and setting serviceAccount to null will cause it to be included in the update field mask, which will cause the value to be reset to the server-side default.

The actual encoding/decoding/error logic etc. of callable functions
will stay the same between v1 and v2, so they should be in a /common
file.

The rest of /v1 is about trigger options, cors, etc.

onCall's CORS options are part of the v1 namespace because v2 adds
a "cors" option to HttpsOptions. In the v2 API, we will default
to `"cors": true`, but a customer could say `"cors": "my.firebase.app"`
and we will respsect it.

I wish there was a way to make this diff not so noisy. Most of this
is cut & paste.
@inlined inlined requested a review from mbleigh July 13, 2021 23:37
@google-cla google-cla bot added the cla: yes label Jul 13, 2021
Copy link
Copy Markdown
Contributor

@mbleigh mbleigh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some changes needed, but nothing that I have to see the result of before submitting.

}
}

export function renameIfPresent<Src, Dest>(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about transformIfPresent or convertIfPresent since your use here with failurePolicy doesn't actually rename the field.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using convertIfPresent

});

it('should not set a serviceAccountEmail if service account is set to `default`', () => {
it('should set a null serviceAccountEmail if service account is set to `default`', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? If serviceAccountEmail is null (vs. not set on the wire) does that imply something different?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous behavior did nothing if the user specified "default". We dropped it on the floor and never restored the default on the backend. Using null causes us to specify the field in our update mask and causes the backend to correctly restore the default on UpdateFunction.

}

// Returns true if req is a properly formatted callable request.
function isValidRequest(req: Request): req is HttpRequest {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please re-add @hidden on all unexported functions, since typedoc is bad.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

/** @internal */
export let onCallHandler = (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for export let vs. export const? Also why not just export function?

Lastly, I wonder if this should be a factory instead onCallHandler({cors: Corsoptions}), that way a critical piece of functionality (making the request pass cors) can't be accidentally forgotten in a future version.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export const is correct. I used lambadas instead of functions because only the former supports currying syntax. I'll make another helper that does this correctly with CORS.

dest[destField] = converter(src[srcField]);
}

export function serviceAccountFromShorthand(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't really have anything to do with protos, so I wonder if this should be elsewhere or the file should be named something else.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make this something like encoding.ts. Just used proto.ts to copy a poorly named but much beloved grab bag in the CLI.

@inlined inlined merged commit e88a15a into master Jul 14, 2021
inlined added a commit that referenced this pull request Jul 15, 2021
Builds upon #915

Creates the first bits of v2/

setGlobalOptions allows customers to set options that will be preserved
across any function written in the v2 API.

v2/https has webhook and callable function support. In addition to
previous features, customers can now specifiy `cors` as a shorthand for
using CORS middleware.

We will probably eventually support scheduled functions in the HTTPS
namespace but that will have to wait for another day.
inlined added a commit that referenced this pull request Jul 15, 2021
Builds upon #915

Creates the first bits of v2/

setGlobalOptions allows customers to set options that will be preserved
across any function written in the v2 API.

v2/https has webhook and callable function support. In addition to
previous features, customers can now specifiy `cors` as a shorthand for
using CORS middleware.

We will probably eventually support scheduled functions in the HTTPS
namespace but that will have to wait for another day.
inlined added a commit that referenced this pull request Jul 15, 2021
Builds upon #915

Creates the first bits of v2/

setGlobalOptions allows customers to set options that will be preserved
across any function written in the v2 API.

v2/https has webhook and callable function support. In addition to
previous features, customers can now specifiy `cors` as a shorthand for
using CORS middleware.

We will probably eventually support scheduled functions in the HTTPS
namespace but that will have to wait for another day.
@inlined inlined deleted the inlined.common-http branch July 15, 2021 18:16
inlined added a commit that referenced this pull request Jul 19, 2021
* Moves most of https pacakge into /common/providers/https.

The actual encoding/decoding/error logic etc. of callable functions
will stay the same between v1 and v2, so they should be in a /common
file.

The rest of /v1 is about trigger options, cors, etc.

onCall's CORS options are part of the v1 namespace because v2 adds
a "cors" option to HttpsOptions. In the v2 API, we will default
to `"cors": true`, but a customer could say `"cors": "my.firebase.app"`
and we will respsect it.

I wish there was a way to make this diff not so noisy. Most of this
is cut & paste.

* Finish refactor of HTTPS code

Builds upon #915

Creates the first bits of v2/

setGlobalOptions allows customers to set options that will be preserved
across any function written in the v2 API.

v2/https has webhook and callable function support. In addition to
previous features, customers can now specifiy `cors` as a shorthand for
using CORS middleware.

We will probably eventually support scheduled functions in the HTTPS
namespace but that will have to wait for another day.

* Export logger

* run formatter

* Revert pacakge-lock.json
taeold added a commit that referenced this pull request Oct 28, 2021
…tained a function (#1000)

In #915, we replaced use of `_.isObject(data)` with `typeof data === 'object'`. 

Turns out that `_.isObject` returns `true` for functions ([code](https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/isObject.js#L26)). We update the condition to match the previous behavior.

Fixes #964
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants