lib/functions/firebase.js
async function publish(auth, rootPath) {
    // check if version does not exist yet
    // check if user is allowed to publish
    // check if version is larger than last version
    // names cant contain _- etc, maybe just stick to lowercase letters?
    // if projectKey, check that we can access the file?

    package = fs.readJsonSync(path.join(rootPath, constants.INCLUDE_FILE));
    code = fs.readJsonSync(path.join(rootPath, '.gas/publish.json'));

    const versionUrl = package.version.replace(/\./g, '_');
    // TODO
    // console.log(semver.valid(package.version));
    // console.log(versionUrl);

    try {
        const authenticated = await authWithFirebase(auth);
        const token = await firebase.auth().currentUser.getIdToken();
        const userId = firebase.auth().currentUser.uid;
        let url;
        let result;

        // Set a packageName to active
        url = `${constants.FIREBASE_DATABASE_URL}/packages/${package.name}.json?auth=${token}`;
        result = await request({
            url,
            method: "PATCH",
            json: true,
            headers: {
                "content-type": "application/json",
            },
            body: {
                status: 'active',
            },
        });

        // Patch users in a package
        url = `${constants.FIREBASE_DATABASE_URL}/package/${package.name}/userIds/${userId}.json?auth=${token}`;
        result = await request({
            url,
            method: "PATCH",
            json: true,
            headers: {
                "content-type": "application/json",
            },
            body: {
                status: 'active',
            },
        });

        // Set version of a package to active
        url = `${constants.FIREBASE_DATABASE_URL}/package/${package.name}/versions.json?auth=${token}`;
        result = await request({
            url,
            method: "PATCH",
            json: true,
            headers: {
                "content-type": "application/json",
            },
            body: {
                [versionUrl]: true,
            },
        });

        // Patch a version in a package
        url = `${constants.FIREBASE_DATABASE_URL}/package/${package.name}/version/${versionUrl}.json?auth=${token}`;
        result = await request({
            url,
            method: "PATCH",
            json: true,
            headers: {
                "content-type": "application/json",
            },
            body: {
                code,
                dependencies: package.dependencies,
                description: package.description,
                homepage: package.homepage,
                license: package.license,
                readme: 'README.md',
                repository: package.repository,
                projectKey: package.projectKey,
                timestamp: {
                    ".sv": "timestamp",
                },
                userId,
            },
        });

        return true;
    } catch (err) {
        err.origin = 'test';
        await error.log(err);
        return false;
    }
}
async function publish(auth, rootPath) {
    // check if version does not exist yet
    // check if user is allowed to publish
    // check if version is larger than last version
    // names cant contain _- etc, maybe just stick to lowercase letters?
    // if projectKey, check that we can access the file?

    package = fs.readJsonSync(path.join(rootPath, constants.INCLUDE_FILE));
    code = fs.readJsonSync(path.join(rootPath, '.gas/publish.json'));

    const versionUrl = package.version.replace(/\./g, '_');
    // TODO
    // console.log(semver.valid(package.version));
    // console.log(versionUrl);

    try {
        const authenticated = await authWithFirebase(auth);
        const token = await firebase.auth().currentUser.getIdToken();
        const userId = firebase.auth().currentUser.uid;
        let url;
        let result;

        // Set a packageName to active
        url = `${constants.FIREBASE_DATABASE_URL}/packages/${package.name}.json?auth=${token}`;
        result = await request({
            url,
            method: "PATCH",
            json: true,
            headers: {
                "content-type": "application/json",
            },
            body: {
                status: 'active',
            },
        });

        // Patch users in a package
        url = `${constants.FIREBASE_DATABASE_URL}/package/${package.name}/userIds/${userId}.json?auth=${token}`;
        result = await request({
            url,
            method: "PATCH",
            json: true,
            headers: {
                "content-type": "application/json",
            },
            body: {
                status: 'active',
            },
        });

        // Set version of a package to active
        url = `${constants.FIREBASE_DATABASE_URL}/package/${package.name}/versions.json?auth=${token}`;
        result = await request({
            url,
            method: "PATCH",
            json: true,
            headers: {
                "content-type": "application/json",
            },
            body: {
                [versionUrl]: true,
            },
        });

        // Patch a version in a package
        url = `${constants.FIREBASE_DATABASE_URL}/package/${package.name}/version/${versionUrl}.json?auth=${token}`;
        result = await request({
            url,
            method: "PATCH",
            json: true,
            headers: {
                "content-type": "application/json",
            },
            body: {
                code,
                dependencies: package.dependencies,
                description: package.description,
                homepage: package.homepage,
                license: package.license,
                readme: 'README.md',
                repository: package.repository,
                projectKey: package.projectKey,
                timestamp: {
                    ".sv": "timestamp",
                },
                userId,
            },
        });

        return true;
    } catch (err) {
        err.origin = 'test';
        await error.log(err);
        return false;
    }
}
async function publish ( auth , rootPath ) { // check if version does not exist yet // check if user is allowed to publish // check if version is larger than last version // names cant contain _- etc, maybe just stick to lowercase letters? // if projectKey, check that we can access the file? package = fs . readJsonSync ( path . join ( rootPath , constants . INCLUDE_FILE ) ) ; code = fs . readJsonSync ( path . join ( rootPath , '.gas/publish.json' ) ) ; const versionUrl = package . version . replace ( / \. / g , '_' ) ; // TODO // console.log(semver.valid(package.version)); // console.log(versionUrl); try { const authenticated = await authWithFirebase ( auth ) ; const token = await firebase . auth ( ) . currentUser . getIdToken ( ) ; const userId = firebase . auth ( ) . currentUser . uid ; let url ; let result ; // Set a packageName to active url = ` ${ constants . FIREBASE_DATABASE_URL } ${ package . name } ${ token } ` ; result = await request ( { url , method : "PATCH" , json : true , headers : { "content-type" : "application/json" , } , body : { status : 'active' , } , } ) ; // Patch users in a package url = ` ${ constants . FIREBASE_DATABASE_URL } ${ package . name } ${ userId } ${ token } ` ; result = await request ( { url , method : "PATCH" , json : true , headers : { "content-type" : "application/json" , } , body : { status : 'active' , } , } ) ; // Set version of a package to active url = ` ${ constants . FIREBASE_DATABASE_URL } ${ package . name } ${ token } ` ; result = await request ( { url , method : "PATCH" , json : true , headers : { "content-type" : "application/json" , } , body : { [ versionUrl ] : true , } , } ) ; // Patch a version in a package url = ` ${ constants . FIREBASE_DATABASE_URL } ${ package . name } ${ versionUrl } ${ token } ` ; result = await request ( { url , method : "PATCH" , json : true , headers : { "content-type" : "application/json" , } , body : { code , dependencies : package . dependencies , description : package . description , homepage : package . homepage , license : package . license , readme : 'README.md' , repository : package . repository , projectKey : package . projectKey , timestamp : { ".sv" : "timestamp" , } , userId , } , } ) ; return true ; } catch ( err ) { err . origin = 'test' ; await error . log ( err ) ; return false ; } }
Firebase test function

@param {google.auth.OAuth2} auth - An authorized OAuth2 client.
@return {Boolean} - true if test was succesful, false otherwise
Firebase test function