Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/rowyio/rowyRun into main
Browse files Browse the repository at this point in the history
  • Loading branch information
shamsmosowi committed Sep 15, 2021
2 parents 9c380b8 + 737636d commit 885b9fc
Show file tree
Hide file tree
Showing 39 changed files with 1,029 additions and 919 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.yarn
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@
"@types/node": "^16.6.1",
"firebase-tools": "^9.18.0",
"google-auth-library": "^7.0.0",
"husky": "^4.2.5",
"husky": "^4.3.8",
"js-beautify": "^1.13.0",
"mocha": "^9.0.0",
"nodemon": "^2.0.12",
"prettier": "^2.1.1",
"pretty-quick": "^3.0.0",
"prettier": "^2.4.0",
"pretty-quick": "^3.1.1",
"supertest": "^6.0.0",
"ts-node": "^9.1.1",
"tslint": "^6.1.0",
"typescript": "^4.2.3"
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
}
}
2 changes: 0 additions & 2 deletions src/actionScripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ export const actionScript = async (req: Request, res: Response) => {
if (!requiredRoles || requiredRoles.length === 0) {
throw Error(`You need to specify at least one role to run this script`);
}
console.log(`requiredRoles: ${requiredRoles}`);
console.log(`userRoles: ${user.customClaims.roles}`);
if (!requiredRoles.some((role) => user.customClaims.roles.includes(role))) {
throw Error(`You don't have the required roles permissions`);
}
Expand Down
9 changes: 5 additions & 4 deletions src/constants/Collections.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export const rowyUsers = '_rowy_/userManagement/users'
export const rowyUsersImpersonationLogs = '_rowy_/userManagement/impersonationLogs'
export const rowyUsers = "_rowy_/userManagement/users";
export const rowyUsersImpersonationLogs =
"_rowy_/userManagement/impersonationLogs";

export default {
rowyUsers,
rowyUsersImpersonationLogs
}
rowyUsersImpersonationLogs,
};
8 changes: 4 additions & 4 deletions src/firebaseConfig.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Initialize Firebase Admin
import * as admin from "firebase-admin";

const credential = process.env.DEV ?
admin.credential.cert(require(`../firebase-adminsdk.json`))
:admin.credential.applicationDefault()
const credential = process.env.DEV
? admin.credential.cert(require(`../firebase-adminsdk.json`))
: admin.credential.applicationDefault();
admin.initializeApp({
credential
credential,
});
const db = admin.firestore();
const auth = admin.auth();
Expand Down
29 changes: 14 additions & 15 deletions src/firestore/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@

import { db, admin } from '../firebaseConfig'
import { Request, Response } from 'express';
export const listCollections =async (req: Request) => {
import { db, admin } from "../firebaseConfig";
import { Request, Response } from "express";
export const listCollections = async (req: Request) => {
const { path } = req.query;
if (path) {
const collections = await db.doc(decodeURIComponent(path as string)).listCollections()
return collections.map(collection => collection.id)

const collections = await db
.doc(decodeURIComponent(path as string))
.listCollections();
return collections.map((collection) => collection.id);
} else {
const collections = await db.listCollections()
return collections.map(collection => collection.id)
const collections = await db.listCollections();
return collections.map((collection) => collection.id);
}
}

};

export const getFirestoreRules = async () => {
const securityRules = admin.securityRules()
const firestoreRules = await securityRules.getFirestoreRuleset()
return firestoreRules
}
const securityRules = admin.securityRules();
const firestoreRules = await securityRules.getFirestoreRuleset();
return firestoreRules;
};
105 changes: 53 additions & 52 deletions src/functionBuilder/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,64 @@ export default async function generateConfig(
user: admin.auth.UserRecord,
streamLogger
) {
return await generateConfigOfTriggerPath(
triggerPath,
streamLogger
).then(async () => {
await streamLogger.info(`generateConfigFromTableSchema done`);
const configFile = fs.readFileSync(
path.resolve(__dirname, "../functions/src/functionConfig.ts"),
"utf-8"
);
await streamLogger.info(`configFile: ${JSON.stringify(configFile)}`);
const requiredDependencies = configFile.match(
/(?<=(require\(("|'))).*?(?=("|')\))/g
);
if (requiredDependencies) {
const packgesAdded = await addPackages(
requiredDependencies.map((p: any) => ({ name: p })),
user,
streamLogger
return await generateConfigOfTriggerPath(triggerPath, streamLogger).then(
async () => {
await streamLogger.info(`generateConfigFromTableSchema done`);
const configFile = fs.readFileSync(
path.resolve(__dirname, "../functions/src/functionConfig.ts"),
"utf-8"
);
if (!packgesAdded) {
return false;
await streamLogger.info(`configFile: ${JSON.stringify(configFile)}`);
const requiredDependencies = configFile.match(
/(?<=(require\(("|'))).*?(?=("|')\))/g
);
if (requiredDependencies) {
const packgesAdded = await addPackages(
requiredDependencies.map((p: any) => ({ name: p })),
user,
streamLogger
);
if (!packgesAdded) {
return false;
}
}
}
await streamLogger.info(
`requiredDependencies: ${JSON.stringify(requiredDependencies)}`
);
await streamLogger.info(
`requiredDependencies: ${JSON.stringify(requiredDependencies)}`
);

const isFunctionConfigValid = await asyncExecute(
"cd build/functionBuilder/functions/src; tsc functionConfig.ts",
commandErrorHandler(
{
user,
functionConfigTs: configFile,
description: `Invalid compiled functionConfig.ts`,
},
streamLogger
)
);
await streamLogger.info(
`isFunctionConfigValid: ${JSON.stringify(isFunctionConfigValid)}`
);
if (!isFunctionConfigValid) {
return false;
}
const isFunctionConfigValid = await asyncExecute(
"cd build/functionBuilder/functions/src; tsc functionConfig.ts",
commandErrorHandler(
{
user,
functionConfigTs: configFile,
description: `Invalid compiled functionConfig.ts`,
},
streamLogger
)
);
await streamLogger.info(
`isFunctionConfigValid: ${JSON.stringify(isFunctionConfigValid)}`
);
if (!isFunctionConfigValid) {
return false;
}

const { extensionsConfig } = require("../functions/src/functionConfig.js");
const requiredExtensions = extensionsConfig.map((s: any) => s.type);
await streamLogger.info(
`requiredExtensions: ${JSON.stringify(requiredExtensions)}`
);
const {
extensionsConfig,
} = require("../functions/src/functionConfig.js");
const requiredExtensions = extensionsConfig.map((s: any) => s.type);
await streamLogger.info(
`requiredExtensions: ${JSON.stringify(requiredExtensions)}`
);

for (const lib of requiredExtensions) {
const success = await addExtensionLib(lib, user, streamLogger);
if (!success) {
return false;
for (const lib of requiredExtensions) {
const success = await addExtensionLib(lib, user, streamLogger);
if (!success) {
return false;
}
}
return true;
}
return true;
});
);
}
Loading

0 comments on commit 885b9fc

Please sign in to comment.