Compare commits
2 Commits
688619bd45
...
0be5cfe30c
| Author | SHA1 | Date | |
|---|---|---|---|
| 0be5cfe30c | |||
| 7d37e295fe |
1
functions/package-lock.json
generated
1
functions/package-lock.json
generated
@ -10,6 +10,7 @@
|
||||
"dependencies": {
|
||||
"@types/node-fetch": "^2.6.12",
|
||||
"axios": "^1.8.4",
|
||||
"cors": "^2.8.5",
|
||||
"firebase-admin": "^12.6.0",
|
||||
"firebase-functions": "^6.0.1",
|
||||
"form-data": "^4.0.1",
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
"dependencies": {
|
||||
"@types/node-fetch": "^2.6.12",
|
||||
"axios": "^1.8.4",
|
||||
"cors": "^2.8.5",
|
||||
"firebase-admin": "^12.6.0",
|
||||
"firebase-functions": "^6.0.1",
|
||||
"form-data": "^4.0.1",
|
||||
|
||||
@ -8,6 +8,7 @@ import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as https from 'https';
|
||||
import cors from 'cors';
|
||||
import axios from "axios";
|
||||
import { getStorage } from 'firebase-admin/storage';
|
||||
const formData = require('form-data');
|
||||
@ -19,9 +20,13 @@ const twilio = require('twilio');
|
||||
if (!admin.apps.length) {
|
||||
admin.initializeApp();
|
||||
}
|
||||
|
||||
const corsHandler = cors({ origin: true });
|
||||
|
||||
export const sendEmailWithAttachment = onRequest({
|
||||
region: '#{SERVICES_RGN}#'
|
||||
}, async (request: Request, response: express.Response) => {
|
||||
return corsHandler(request, response, async () => {
|
||||
try {
|
||||
const { toAddress, subject, message, fileUrl, fileName } = request.body;
|
||||
|
||||
@ -79,10 +84,13 @@ export const sendEmailWithAttachment = onRequest({
|
||||
response.status(500).json({ success: false, error: error instanceof Error ? error.message : String(error) });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
export const accessFile = onRequest({
|
||||
region: '#{SERVICES_RGN}#'
|
||||
}, async (request: Request, response: express.Response) => {
|
||||
return corsHandler(request, response, async () => {
|
||||
|
||||
try {
|
||||
const filePath = request.query.path as string;
|
||||
if (!filePath) {
|
||||
@ -114,10 +122,13 @@ export const accessFile = onRequest({
|
||||
response.status(500).send('Error accessing file');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
export const sendEmailMessage = onRequest({
|
||||
region: '#{SERVICES_RGN}#'
|
||||
}, (request: Request, response: express.Response) => {
|
||||
return corsHandler(request, response, async () => {
|
||||
|
||||
const mailgun = new Mailgun(formData);
|
||||
const mailGunClient = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY });
|
||||
|
||||
@ -143,10 +154,13 @@ export const sendEmailMessage = onRequest({
|
||||
response.send(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
export const sendSMSMessage = onRequest({
|
||||
region: '#{SERVICES_RGN}#'
|
||||
}, (request: Request, response: express.Response) => {
|
||||
return corsHandler(request, response, async () => {
|
||||
|
||||
const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
|
||||
const { to, body } = request.body;
|
||||
client.messages
|
||||
@ -164,6 +178,7 @@ export const sendSMSMessage = onRequest({
|
||||
response.status(500).json({ success: false, error: error.message });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
interface Invitation {
|
||||
email: string;
|
||||
@ -176,6 +191,7 @@ export const notifyInvitation = onDocumentCreated({
|
||||
document: 'notifications/{notificationId}',
|
||||
region: '#{SERVICES_RGN}#'
|
||||
}, async (event: any) => {
|
||||
|
||||
const invitation = event.data?.data() as Invitation;
|
||||
const invitationId = event.params.invitationId;
|
||||
|
||||
@ -245,6 +261,8 @@ export const notifyInvitation = onDocumentCreated({
|
||||
export const createCashfreeOrder = onRequest({
|
||||
region: '#{SERVICES_RGN}#'
|
||||
}, async (request: Request, response: express.Response) => {
|
||||
|
||||
return corsHandler(request, response, async () => {
|
||||
try {
|
||||
const authHeader = request.headers.authorization;
|
||||
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
||||
@ -332,10 +350,13 @@ export const createCashfreeOrder = onRequest({
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
export const verifyCashfreePayment = onRequest({
|
||||
region: '#{SERVICES_RGN}#'
|
||||
}, async (request: Request, response: express.Response) => {
|
||||
return corsHandler(request, response, async () => {
|
||||
|
||||
try {
|
||||
const orderId = request.body.order_id || request.query.order_id;
|
||||
|
||||
@ -388,3 +409,4 @@ export const verifyCashfreePayment = onRequest({
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user