@mathrunet/masamune
Version:
Manages packages for the server portion (NodeJS) of the Masamune framework.
117 lines • 5.03 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const functions = __importStar(require("firebase-functions/v2"));
const gmail = __importStar(require("../lib/functions/gmail"));
/**
* Send email via Gmail.
*
* Gmailでメールを送信します。
*
* @param {string} process.env.MAIL_GMAIL_ID
* Gmail user ID. Follow the steps below to obtain a Gmail user ID.
* 1. Press your icon in the upper right corner of the Google top screen and open "Manage Google Account".
* 2. open "Security" on the left side of the screen and open "App Password
* GmailのユーザーID。下記の手順で取得します。
* 1. Googleのトップ画面の画面右上の自分のアイコンを押下し、「Google アカウントを管理」を開く
* 2. 画面左の「セキュリティ」を開き、「アプリ パスワード」を開く
*
* @param {string} process.env.MAIL_GMAIL_PASSWORD
* Gmail user password. Enter the password obtained in the above procedure.
* Gmailのユーザーパスワード。上記の手順で取得したパスワードを入力します。
*
* @param {string} from
* Sender's email address.
* 送信元メールアドレス。
*
* @param {string} to
* Email address to be sent to.
* 送信先メールアドレス。
*
* @param {string} title
* Email Title.
* メールタイトル。
*
* @param {string} content
* Email content.
* メール本文。
*/
module.exports = (regions, options, data) => {
var _a, _b, _c, _d;
return functions.https.onCall({
region: (_a = options.region) !== null && _a !== void 0 ? _a : regions,
timeoutSeconds: options.timeoutSeconds,
memory: options.memory,
minInstances: options.minInstances,
concurrency: options.concurrency,
maxInstances: options.maxInstances,
serviceAccount: (_b = options === null || options === void 0 ? void 0 : options.serviceAccount) !== null && _b !== void 0 ? _b : undefined,
enforceAppCheck: (_c = options.enforceAppCheck) !== null && _c !== void 0 ? _c : undefined,
consumeAppCheckToken: (_d = options.consumeAppCheckToken) !== null && _d !== void 0 ? _d : undefined,
}, (query) => __awaiter(void 0, void 0, void 0, function* () {
try {
const from = query.data.from;
const to = query.data.to;
const title = query.data.title;
const content = query.data.content;
if (!from || !to || !title || !content) {
throw new functions.https.HttpsError("invalid-argument", "Query parameter is invalid.");
}
yield gmail.send({
from: from,
to: to,
title: title,
content: content,
});
return {
success: true,
};
}
catch (err) {
console.log(err);
throw err;
}
}));
};
//# sourceMappingURL=gmail.js.map