setting up workspaces structure, but not moving files

This commit is contained in:
Arjun Patel
2022-01-28 14:08:04 -08:00
parent 7f2ed61b4a
commit a3e6f7cf5e
258 changed files with 16 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
{
"projects": {
"default": "nirvana-for-business"
}
}
+66
View File
@@ -0,0 +1,66 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
firebase-debug.*.log*
# Firebase cache
.firebase/
# Firebase config
# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
+25
View File
@@ -0,0 +1,25 @@
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"predeploy": [
"npm --prefix functions run build",
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
],
"source": "functions"
},
"emulators": {
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"ui": {
"enabled": true
}
}
}
@@ -0,0 +1,83 @@
{
"indexes": [
{
"collectionGroup": "announcements",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "teamId",
"order": "ASCENDING"
},
{
"fieldPath": "createdDate",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "audioMessages",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "senderReceiver",
"arrayConfig": "CONTAINS"
},
{
"fieldPath": "createdDate",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "links",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "teamId",
"order": "ASCENDING"
},
{
"fieldPath": "createdDate",
"order": "DESCENDING"
}
]
},
{
"collectionGroup": "rooms",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "teamId",
"order": "ASCENDING"
},
{
"fieldPath": "type",
"order": "ASCENDING"
},
{
"fieldPath": "createdDate",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "rooms",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "teamId",
"order": "ASCENDING"
},
{
"fieldPath": "type",
"order": "ASCENDING"
},
{
"fieldPath": "scheduledDateTime",
"order": "ASCENDING"
}
]
}
],
"fieldOverrides": []
}
+9
View File
@@ -0,0 +1,9 @@
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2022, 2, 12);
}
}
}
@@ -0,0 +1,35 @@
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
// "eslint:recommended",
// "plugin:import/errors",
// "plugin:import/warnings",
// "plugin:import/typescript",
// "google",
// "plugin:@typescript-eslint/recommended",
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["tsconfig.json", "tsconfig.dev.json"],
sourceType: "module",
tsconfigRootDir: __dirname,
},
ignorePatterns: [
"/lib/**/*", // Ignore built files.
],
plugins: ["@typescript-eslint", "import"],
rules: {
quotes: ["error", "double"],
// "import/no-unresolved": 0,
"no-unused-vars": 0,
},
}
+9
View File
@@ -0,0 +1,9 @@
# Compiled JavaScript files
lib/**/*.js
lib/**/*.js.map
# TypeScript v1 declaration files
typings/
# Node.js dependency directory
node_modules/
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,34 @@
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "npm run lint && tsc",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"hotReload": "tsc --watch",
"copyModels": "cp -r ../../web/models ./models"
},
"engines": {
"node": "16"
},
"main": "lib/index.js",
"dependencies": {
"@sendgrid/mail": "^7.6.0",
"agora-access-token": "^2.0.4",
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^3.9.1",
"@typescript-eslint/parser": "^3.8.0",
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.22.0",
"firebase-functions-test": "^0.2.0",
"typescript": "^3.8.0"
},
"private": true
}
@@ -0,0 +1,43 @@
import * as functions from "firebase-functions";
export const agoraToken = functions.https.onCall((data, context) => {
console.log(data);
console.log("user's id: " + context.auth?.uid);
const channelName: string = data.channelName;
let token = getAgoraToken(channelName);
return { token };
});
import { RtcTokenBuilder, RtcRole } from "agora-access-token";
function getAgoraToken(channelName: string) {
// Rtc Examples
const appID = "c8dfd65deb5c4741bd564085627139d0";
const appCertificate = "aa57b809934b4efcb407cf30089d9f25";
const uid = 0; // no need to use this as we have authenticated this user
const role = RtcRole.PUBLISHER;
const expirationTimeInSeconds = 3600;
const currentTimestamp = Math.floor(Date.now() / 1000);
const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds;
// IMPORTANT! Build token with either the uid or with the user account. Comment out the option you do not want to use below.
// Build token with uid
const tokenA = RtcTokenBuilder.buildTokenWithUid(
appID,
appCertificate,
channelName,
uid,
role,
privilegeExpiredTs
);
console.log("Token With Integer Number Uid: " + tokenA);
return tokenA;
}
@@ -0,0 +1,18 @@
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
admin.initializeApp();
// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
export const helloWorld = functions.https.onRequest((request, response) => {
functions.logger.info("Hello no!", { structuredData: true });
response.send("Hello from woahhhhhh!");
})
import { agoraToken } from "./agora";
exports.agoraToken = agoraToken;
import { inviteUserToTeam } from "./notifications";
exports.inviteUserToTeam = inviteUserToTeam;
@@ -0,0 +1,103 @@
/* eslint-disable no-unused-vars */
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
import * as sgMail from "@sendgrid/mail";
import { MailDataRequired } from "@sendgrid/mail";
sgMail.setApiKey(
"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"
);
enum SendgridTemplateId {
inviteTeamMember = "d-4953372ac7b94d3fa9419bad4073840f",
}
const SENDER_EMAIL = "[email protected]"
// class SendGridEmailMessage {
// to: string;
// from: string = "[email protected]"
// templateId: SendgridTemplateId;
// dynamic_template_data: {};
// constructor(
// _to: string,
// _templateId: SendgridTemplateId,
// _templateData: {}
// ) {
// this.to = _to;
// this.templateId = _templateId;
// this.dynamic_template_data = _templateData;
// }
// }
type Team = {
id: string;
name: string;
status: string;
allowedUserCount: number;
companySite: string;
createdByUserId: string;
}
type TeamMember = {
id: string;
userId: string;
teamId: string;
inviteEmailAddress: string;
invitedByUserId: string;
role: string
status: string
}
// onCreate of team invite to a member -> email
export const inviteUserToTeam = functions.firestore
.document("teamMembers/{teamMemberId}")
.onCreate(async (snap, context) => {
const newTeamMember = snap.data() as TeamMember;
if (!newTeamMember || !newTeamMember.inviteEmailAddress) {
functions.logger.error("No team member email available")
return
}
// only if invited will be sending invite
if (newTeamMember.status == "invited") {
functions.logger.info(
"New team member invited...sending email" +
newTeamMember.inviteEmailAddress,
{ structuredData: true }
)
// get team information from team id
const snapshot = await admin.firestore().collection("teams").doc(newTeamMember.teamId).get()
if (!snapshot.exists) {
functions.logger.error("No team exists")
return
}
const team: Team = snapshot.data() as Team;
// send email to invited person, based on the email address
const message: MailDataRequired = {
from: SENDER_EMAIL,
to: newTeamMember.inviteEmailAddress,
templateId: SendgridTemplateId.inviteTeamMember,
dynamicTemplateData: {
teamName: team.name,
subject: "Your Team is On Nirvana - " + team.name,
joinTeamUrl: "https://usenirvana.com/teams/login",
landingPageUrl: "https://usenirvana.com"
}
}
return await sgMail.send(message)
}
return
})
@@ -0,0 +1,3 @@
{
"include": [".eslintrc.js"]
}
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
"strictNullChecks": true
},
"compileOnSave": true,
"include": ["src"]
}