Skip to content

Remove usage of the NODE_ADMIN global in RTDB #3736

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

Merged
merged 6 commits into from
Sep 9, 2020

Conversation

samtstern
Copy link
Contributor

@samtstern samtstern commented Sep 3, 2020

Discussion

The NODE_ADMIN global means that the RTDB Admin and Client SDKs cannot coexist, whichever is initialized first will control the behavior.

This is a problem for testing, where clients want to use the Admin SDK to do privileged actions but then test the behavior of the Client SDK with low privileges.

Testing

  • New unit test in rules-unit-testing

API Changes

N/A

@changeset-bot
Copy link

changeset-bot bot commented Sep 3, 2020

🦋 Changeset is good to go

Latest commit: 6a0270a

We got this.

This PR includes changesets to release 6 packages
Name Type
@firebase/database Patch
@firebase/rules-unit-testing Patch
firebase Patch
@firebase/testing Patch
firebase-namespace-integration-test Patch
firebase-messaging-integration-test Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@samtstern samtstern requested a review from yuchenshi September 3, 2020 13:37
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 3, 2020

Size Analysis Report

Affected Products

@firebase/installations-exp

  • deleteInstallations

    Size

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    size ? 8.90 kB ? (?)
    size_with_ext_deps ? 17.3 kB ? (?)

    Dependencies

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    functions ?
    Click to show 52 depsbroadcastFidChange
    bufferToBase64UrlSafe
    callFidChangeCallbacks
    clearTimedOutRequest
    closeBroadcastChannel
    completeInstallationRegistration
    createInstallationRequest
    deleteInstallationRequest
    deleteInstallations
    encode
    extractAppConfig
    extractAuthTokenInfoFromResponse
    fetchAuthTokenFromServer
    fidChanged
    generateAuthTokenRequest
    generateFid
    getAuthorizationHeader
    getBroadcastChannel
    getDbPromise
    getDeleteEndpoint
    getErrorFromResponse
    getExpiresInFromResponseExpiresIn
    getGenerateAuthTokenEndpoint
    getHeaders
    getHeadersWithAuth
    getId
    getInstallationEntry
    getInstallationsEndpoint
    getKey
    getMissingValueError
    getToken
    hasAuthTokenRequestTimedOut
    hasInstallationRequestTimedOut
    isAuthTokenExpired
    isAuthTokenValid
    isEntryRegistered
    isServerError
    makeAuthTokenRequestInProgressEntry
    refreshAuthToken
    registerInstallation
    registerInstallations
    remove
    retryIfServerError
    set
    sleep
    triggerRegistrationIfNecessary
    update
    updateAuthTokenRequest
    updateInstallationRequest
    updateOrCreateInstallationEntry
    waitUntilAuthTokenRequest
    waitUntilFidRegistration
    ?
    variables ?
    Click to show 23 depsDATABASE_NAME
    DATABASE_VERSION
    ERROR_DESCRIPTION_MAP
    ERROR_FACTORY
    INSTALLATIONS_API_URL
    INSTALLATIONS_NAME
    INSTALLATIONS_NAME_INTERNAL
    INTERNAL_AUTH_VERSION
    INVALID_FID
    OBJECT_STORE_NAME
    PACKAGE_VERSION
    PENDING_TIMEOUT_MS
    SERVICE
    SERVICE_NAME
    TOKEN_EXPIRATION_BUFFER
    VALID_FID_PATTERN
    broadcastChannel
    dbPromise
    fidChangeCallbacks
    internalFactory
    name
    publicFactory
    version
    ?

    External Dependencies

    Module Base (d90ddd7) Head (fb1f1e2) Diff
    @firebase/util ? ErrorFactory
    FirebaseError
    ?
    idb ? openDb ?
    @firebase/app-exp ? _getProvider
    _registerComponent
    registerVersion
    ?
    @firebase/component ? Component ?
  • getId

    Size

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    size ? 8.34 kB ? (?)
    size_with_ext_deps ? 16.8 kB ? (?)

    Dependencies

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    functions ?
    Click to show 49 depsbroadcastFidChange
    bufferToBase64UrlSafe
    callFidChangeCallbacks
    clearTimedOutRequest
    closeBroadcastChannel
    completeInstallationRegistration
    createInstallationRequest
    encode
    extractAppConfig
    extractAuthTokenInfoFromResponse
    fetchAuthTokenFromServer
    fidChanged
    generateAuthTokenRequest
    generateFid
    getAuthorizationHeader
    getBroadcastChannel
    getDbPromise
    getErrorFromResponse
    getExpiresInFromResponseExpiresIn
    getGenerateAuthTokenEndpoint
    getHeaders
    getHeadersWithAuth
    getId
    getInstallationEntry
    getInstallationsEndpoint
    getKey
    getMissingValueError
    getToken
    hasAuthTokenRequestTimedOut
    hasInstallationRequestTimedOut
    isAuthTokenExpired
    isAuthTokenValid
    isEntryRegistered
    isServerError
    makeAuthTokenRequestInProgressEntry
    refreshAuthToken
    registerInstallation
    registerInstallations
    remove
    retryIfServerError
    set
    sleep
    triggerRegistrationIfNecessary
    update
    updateAuthTokenRequest
    updateInstallationRequest
    updateOrCreateInstallationEntry
    waitUntilAuthTokenRequest
    waitUntilFidRegistration
    ?
    variables ?
    Click to show 23 depsDATABASE_NAME
    DATABASE_VERSION
    ERROR_DESCRIPTION_MAP
    ERROR_FACTORY
    INSTALLATIONS_API_URL
    INSTALLATIONS_NAME
    INSTALLATIONS_NAME_INTERNAL
    INTERNAL_AUTH_VERSION
    INVALID_FID
    OBJECT_STORE_NAME
    PACKAGE_VERSION
    PENDING_TIMEOUT_MS
    SERVICE
    SERVICE_NAME
    TOKEN_EXPIRATION_BUFFER
    VALID_FID_PATTERN
    broadcastChannel
    dbPromise
    fidChangeCallbacks
    internalFactory
    name
    publicFactory
    version
    ?

    External Dependencies

    Module Base (d90ddd7) Head (fb1f1e2) Diff
    @firebase/util ? ErrorFactory
    FirebaseError
    ?
    idb ? openDb ?
    @firebase/app-exp ? _getProvider
    _registerComponent
    registerVersion
    ?
    @firebase/component ? Component ?
  • getInstallations

    Size

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    size ? 8.43 kB ? (?)
    size_with_ext_deps ? 16.9 kB ? (?)

    Dependencies

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    functions ?
    Click to show 50 depsbroadcastFidChange
    bufferToBase64UrlSafe
    callFidChangeCallbacks
    clearTimedOutRequest
    closeBroadcastChannel
    completeInstallationRegistration
    createInstallationRequest
    encode
    extractAppConfig
    extractAuthTokenInfoFromResponse
    fetchAuthTokenFromServer
    fidChanged
    generateAuthTokenRequest
    generateFid
    getAuthorizationHeader
    getBroadcastChannel
    getDbPromise
    getErrorFromResponse
    getExpiresInFromResponseExpiresIn
    getGenerateAuthTokenEndpoint
    getHeaders
    getHeadersWithAuth
    getId
    getInstallationEntry
    getInstallations
    getInstallationsEndpoint
    getKey
    getMissingValueError
    getToken
    hasAuthTokenRequestTimedOut
    hasInstallationRequestTimedOut
    isAuthTokenExpired
    isAuthTokenValid
    isEntryRegistered
    isServerError
    makeAuthTokenRequestInProgressEntry
    refreshAuthToken
    registerInstallation
    registerInstallations
    remove
    retryIfServerError
    set
    sleep
    triggerRegistrationIfNecessary
    update
    updateAuthTokenRequest
    updateInstallationRequest
    updateOrCreateInstallationEntry
    waitUntilAuthTokenRequest
    waitUntilFidRegistration
    ?
    variables ?
    Click to show 23 depsDATABASE_NAME
    DATABASE_VERSION
    ERROR_DESCRIPTION_MAP
    ERROR_FACTORY
    INSTALLATIONS_API_URL
    INSTALLATIONS_NAME
    INSTALLATIONS_NAME_INTERNAL
    INTERNAL_AUTH_VERSION
    INVALID_FID
    OBJECT_STORE_NAME
    PACKAGE_VERSION
    PENDING_TIMEOUT_MS
    SERVICE
    SERVICE_NAME
    TOKEN_EXPIRATION_BUFFER
    VALID_FID_PATTERN
    broadcastChannel
    dbPromise
    fidChangeCallbacks
    internalFactory
    name
    publicFactory
    version
    ?

    External Dependencies

    Module Base (d90ddd7) Head (fb1f1e2) Diff
    @firebase/util ? ErrorFactory
    FirebaseError
    ?
    idb ? openDb ?
    @firebase/app-exp ? _getProvider
    _registerComponent
    registerVersion
    ?
    @firebase/component ? Component ?
  • getToken

    Size

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    size ? 8.35 kB ? (?)
    size_with_ext_deps ? 16.8 kB ? (?)

    Dependencies

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    functions ?
    Click to show 49 depsbroadcastFidChange
    bufferToBase64UrlSafe
    callFidChangeCallbacks
    clearTimedOutRequest
    closeBroadcastChannel
    completeInstallationRegistration
    createInstallationRequest
    encode
    extractAppConfig
    extractAuthTokenInfoFromResponse
    fetchAuthTokenFromServer
    fidChanged
    generateAuthTokenRequest
    generateFid
    getAuthorizationHeader
    getBroadcastChannel
    getDbPromise
    getErrorFromResponse
    getExpiresInFromResponseExpiresIn
    getGenerateAuthTokenEndpoint
    getHeaders
    getHeadersWithAuth
    getId
    getInstallationEntry
    getInstallationsEndpoint
    getKey
    getMissingValueError
    getToken
    hasAuthTokenRequestTimedOut
    hasInstallationRequestTimedOut
    isAuthTokenExpired
    isAuthTokenValid
    isEntryRegistered
    isServerError
    makeAuthTokenRequestInProgressEntry
    refreshAuthToken
    registerInstallation
    registerInstallations
    remove
    retryIfServerError
    set
    sleep
    triggerRegistrationIfNecessary
    update
    updateAuthTokenRequest
    updateInstallationRequest
    updateOrCreateInstallationEntry
    waitUntilAuthTokenRequest
    waitUntilFidRegistration
    ?
    variables ?
    Click to show 23 depsDATABASE_NAME
    DATABASE_VERSION
    ERROR_DESCRIPTION_MAP
    ERROR_FACTORY
    INSTALLATIONS_API_URL
    INSTALLATIONS_NAME
    INSTALLATIONS_NAME_INTERNAL
    INTERNAL_AUTH_VERSION
    INVALID_FID
    OBJECT_STORE_NAME
    PACKAGE_VERSION
    PENDING_TIMEOUT_MS
    SERVICE
    SERVICE_NAME
    TOKEN_EXPIRATION_BUFFER
    VALID_FID_PATTERN
    broadcastChannel
    dbPromise
    fidChangeCallbacks
    internalFactory
    name
    publicFactory
    version
    ?

    External Dependencies

    Module Base (d90ddd7) Head (fb1f1e2) Diff
    @firebase/util ? ErrorFactory
    FirebaseError
    ?
    idb ? openDb ?
    @firebase/app-exp ? _getProvider
    _registerComponent
    registerVersion
    ?
    @firebase/component ? Component ?
  • onIdChange

    Size

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    size ? 8.60 kB ? (?)
    size_with_ext_deps ? 17.0 kB ? (?)

    Dependencies

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    functions ?
    Click to show 52 depsaddCallback
    broadcastFidChange
    bufferToBase64UrlSafe
    callFidChangeCallbacks
    clearTimedOutRequest
    closeBroadcastChannel
    completeInstallationRegistration
    createInstallationRequest
    encode
    extractAppConfig
    extractAuthTokenInfoFromResponse
    fetchAuthTokenFromServer
    fidChanged
    generateAuthTokenRequest
    generateFid
    getAuthorizationHeader
    getBroadcastChannel
    getDbPromise
    getErrorFromResponse
    getExpiresInFromResponseExpiresIn
    getGenerateAuthTokenEndpoint
    getHeaders
    getHeadersWithAuth
    getId
    getInstallationEntry
    getInstallationsEndpoint
    getKey
    getMissingValueError
    getToken
    hasAuthTokenRequestTimedOut
    hasInstallationRequestTimedOut
    isAuthTokenExpired
    isAuthTokenValid
    isEntryRegistered
    isServerError
    makeAuthTokenRequestInProgressEntry
    onIdChange
    refreshAuthToken
    registerInstallation
    registerInstallations
    remove
    removeCallback
    retryIfServerError
    set
    sleep
    triggerRegistrationIfNecessary
    update
    updateAuthTokenRequest
    updateInstallationRequest
    updateOrCreateInstallationEntry
    waitUntilAuthTokenRequest
    waitUntilFidRegistration
    ?
    variables ?
    Click to show 23 depsDATABASE_NAME
    DATABASE_VERSION
    ERROR_DESCRIPTION_MAP
    ERROR_FACTORY
    INSTALLATIONS_API_URL
    INSTALLATIONS_NAME
    INSTALLATIONS_NAME_INTERNAL
    INTERNAL_AUTH_VERSION
    INVALID_FID
    OBJECT_STORE_NAME
    PACKAGE_VERSION
    PENDING_TIMEOUT_MS
    SERVICE
    SERVICE_NAME
    TOKEN_EXPIRATION_BUFFER
    VALID_FID_PATTERN
    broadcastChannel
    dbPromise
    fidChangeCallbacks
    internalFactory
    name
    publicFactory
    version
    ?

    External Dependencies

    Module Base (d90ddd7) Head (fb1f1e2) Diff
    @firebase/util ? ErrorFactory
    FirebaseError
    ?
    idb ? openDb ?
    @firebase/app-exp ? _getProvider
    _registerComponent
    registerVersion
    ?
    @firebase/component ? Component ?

Test Logs

@samtstern samtstern marked this pull request as ready for review September 3, 2020 16:06
/**
* This should allow the firebase-admin package to provide a custom version
* to the backend
*/
CONSTANTS.NODE_ADMIN = true;
CONSTANTS.NODE_ADMIN = nodeAdmin;
Copy link
Member

Choose a reason for hiding this comment

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

We can remove this constant since RTDB is the only consumer of it. If any other JS SDKs were used by the admin SDK in the future, they should not rely on this constant either.

Copy link
Member

Choose a reason for hiding this comment

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

We should hold off on this. firebase-admin does not pin its dependency against @firebase/database, so we can only remove this in a major version bump to avoid breaking customers.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I think I misunderstood -- this is all internal in this package and utils

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Feiyang1 so I still want isNodeSdk() to work ... where does NODE_ADMIN actually come from when it's not set in initStandalone? Is it set in part of the build process?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not comfortable removing this at the moment ... it's used within isNodeSdk() which is used in many places including one place where module.exports is redefined. I think removing this is likely to break something I don't understand. Maybe someone from JSCore feels confident enough to do it as a follow up.

Copy link
Member

Choose a reason for hiding this comment

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

The check for CONSTANTS.NODE_ADMIN is unnecessary in isNodeSdk() because CONSTANTS.NODE_CLIENT will be always true when CONSTANTS.NODE_ADMIN is true. Sure, I will do a follow up PR for this.

@samtstern
Copy link
Contributor Author

@schmidt-sebastian I need your codeowners review on this!

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

Basically LGTM, though I wonder if we can simplify this a bit: https://gist.github.com/schmidt-sebastian/08c74a0160809165fed81e31088cf8ce

If not, we can merge as is.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 9, 2020

Binary Size Report

Affected SDKs

  • @firebase/analytics

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    esm2017 ? 18.4 kB ? (?)
    main ? 23.3 kB ? (?)
    module ? 22.8 kB ? (?)
  • @firebase/app

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    browser ? 11.1 kB ? (?)
    esm2017 ? 9.46 kB ? (?)
    lite ? 9.11 kB ? (?)
    lite-esm2017 ? 7.75 kB ? (?)
    main ? 10.2 kB ? (?)
    module ? 11.0 kB ? (?)
    react-native ? 9.87 kB ? (?)
  • @firebase/auth

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    browser ? 177 kB ? (?)
    main ? 177 kB ? (?)
    module ? 177 kB ? (?)
  • @firebase/component

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    browser ? 5.30 kB ? (?)
    esm2017 ? 3.98 kB ? (?)
    main ? 5.30 kB ? (?)
    module ? 5.18 kB ? (?)
  • @firebase/database

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    browser ? 270 kB ? (?)
    esm2017 ? 236 kB ? (?)
    main ? 270 kB ? (?)
    module ? 268 kB ? (?)
  • @firebase/firestore

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    browser ? 248 kB ? (?)
    esm2017 ? 196 kB ? (?)
    main ? 482 kB ? (?)
    module ? 246 kB ? (?)
    react-native ? 196 kB ? (?)
  • @firebase/firestore/exp

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    browser ? 189 kB ? (?)
    main ? 474 kB ? (?)
    module ? 189 kB ? (?)
    react-native ? 189 kB ? (?)
  • @firebase/firestore/lite

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    browser ? 64.3 kB ? (?)
    main ? 142 kB ? (?)
    module ? 64.3 kB ? (?)
    react-native ? 64.6 kB ? (?)
  • @firebase/firestore/memory

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    browser ? 186 kB ? (?)
    esm2017 ? 147 kB ? (?)
    main ? 356 kB ? (?)
    module ? 184 kB ? (?)
    react-native ? 147 kB ? (?)
  • @firebase/functions

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    browser ? 9.73 kB ? (?)
    esm2017 ? 7.31 kB ? (?)
    main ? 9.77 kB ? (?)
    module ? 9.46 kB ? (?)
  • @firebase/installations

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    esm2017 ? 16.5 kB ? (?)
    main ? 22.1 kB ? (?)
    module ? 21.5 kB ? (?)
  • @firebase/logger

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    esm2017 ? 3.25 kB ? (?)
    main ? 5.14 kB ? (?)
    module ? 4.83 kB ? (?)
  • @firebase/messaging

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    esm2017 ? 25.9 kB ? (?)
    main ? 34.7 kB ? (?)
    module ? 34.2 kB ? (?)
  • @firebase/performance

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    browser ? 27.4 kB ? (?)
    esm2017 ? 25.4 kB ? (?)
    main ? 27.4 kB ? (?)
    module ? 27.1 kB ? (?)
  • @firebase/polyfill

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    main ? 775 B ? (?)
    module ? 705 B ? (?)
  • @firebase/remote-config

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    browser ? 22.8 kB ? (?)
    esm2017 ? 17.4 kB ? (?)
    main ? 22.8 kB ? (?)
    module ? 22.4 kB ? (?)
  • @firebase/rules-unit-testing

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    main ? 7.28 kB ? (?)
  • @firebase/storage

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    esm2017 ? 54.9 kB ? (?)
    main ? 61.4 kB ? (?)
    module ? 61.1 kB ? (?)
  • @firebase/testing

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    main ? 6.35 kB ? (?)
  • @firebase/util

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    browser ? 21.1 kB ? (?)
    esm2017 ? 18.8 kB ? (?)
    main ? 21.2 kB ? (?)
    module ? 20.1 kB ? (?)
  • @firebase/webchannel-wrapper

    Type Base (d90ddd7) Head (fb1f1e2) Diff
    esm2017 ? 39.4 kB ? (?)
    main ? 41.0 kB ? (?)
    module ? 40.6 kB ? (?)
  • firebase

    Click to show 15 binary size changes.
    Type Base (d90ddd7) Head (fb1f1e2) Diff
    firebase-analytics.js ? 35.8 kB ? (?)
    firebase-app.js ? 20.2 kB ? (?)
    firebase-auth.js ? 174 kB ? (?)
    firebase-database.js ? 187 kB ? (?)
    firebase-firestore.js ? 286 kB ? (?)
    firebase-firestore.memory.js ? 226 kB ? (?)
    firebase-functions.js ? 9.93 kB ? (?)
    firebase-installations.js ? 19.2 kB ? (?)
    firebase-messaging.js ? 41.0 kB ? (?)
    firebase-performance-standalone.es2017.js ? 71.3 kB ? (?)
    firebase-performance-standalone.js ? 48.0 kB ? (?)
    firebase-performance.js ? 38.4 kB ? (?)
    firebase-remote-config.js ? 37.1 kB ? (?)
    firebase-storage.js ? 39.9 kB ? (?)
    firebase.js ? 830 kB ? (?)

Test Logs

@samtstern
Copy link
Contributor Author

@hsubox76 says I can merge over this error, so merging!

@samtstern samtstern merged commit 3d9b5a5 into master Sep 9, 2020
@google-oss-bot google-oss-bot mentioned this pull request Sep 15, 2020
@firebase firebase locked and limited conversation to collaborators Oct 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants