UNPKG

@mathrunet/masamune

Version:

Manages packages for the server portion (NodeJS) of the Masamune framework.

196 lines 7.87 kB
"use strict"; 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 send_notification_1 = require("../lib/functions/send_notification"); const firebase_loader_1 = require("../lib/src/firebase_loader"); /** * Define the process for PUSH notification. * * PUSH通知を行うための処理を定義します。 * * @param title * The title of the notice should be listed. * * 通知タイトルを記載します。 * * @param body * The contents of the notice will be described. * * 通知内容を記載します。 * * @param channel_id * Describe ChannelId for Android. * * Android向けのChannelIdを記載します。 * * @param data * Specify the data to be placed on the notification. * * 通知に乗せるデータを指定します。 * * @param badgeCount * Specifies the badge count of the notification. * * 通知のバッジカウントを指定します。 * * @param sound * Specifies the sound of the notification. * * 通知のサウンドを指定します。 * * @param targetToken * Specifies the FCM token. * * FCMトークンを指定します。 * * @param targetTopic * Specifies the topic of the FCM. * * FCMのトピックを指定します。 * * @param targetCollectionPath * Specifies the path of the collection to be notified. * * 通知対象のコレクションのパスを指定します。 * * @param targetTokenField * Specifies the key of the field used to retrieve the token to be notified. * * 通知対象のトークンを取得する際のフィールドのキーを指定します。 * * @param targetWheres * Specify the conditions for retrieving the collections to be notified. * * 通知対象のコレクションを取得する際の条件を指定します。 * * @param targetConditions * Specify the conditions under which data is to be notified. * * データを通知対象とする条件を指定します。 * * @param responseTokenList * Specifies whether to return the token list for debugging. * * デバッグ用にトークンリストを返すかどうかを指定します。 */ 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* () { var _a; try { const results = []; const title = query.data.title; const body = query.data.body; const channelId = query.data.channel_id; const data = query.data.data; const sound = query.data.sound; const badgeCount = query.data.badgeCount; const targetToken = query.data.targetToken; const targetTopic = query.data.targetTopic; const targetCollectionPath = query.data.targetCollectionPath; const targetTokenField = query.data.targetTokenField; const targetWheres = query.data.targetWheres; const targetConditions = query.data.targetConditions; const responseTokenList = query.data.responseTokenList; if (!title || !body) { throw new functions.https.HttpsError("invalid-argument", "Query parameter is invalid."); } let error = null; const firestoreDatabaseIds = (_a = options.firestoreDatabaseIds) !== null && _a !== void 0 ? _a : [""]; for (const databaseId of firestoreDatabaseIds) { try { const firestoreInstance = (0, firebase_loader_1.firestoreLoader)(databaseId); const resItem = yield (0, send_notification_1.sendNotification)({ title: title, body: body, channelId: channelId, data: data, badgeCount: badgeCount, sound: sound, targetToken: targetToken, targetTopic: targetTopic, targetCollectionPath: targetCollectionPath, targetTokenField: targetTokenField, targetWheres: targetWheres, targetConditions: targetConditions, responseTokenList: responseTokenList, firestoreInstance: firestoreInstance, }); if (resItem.results) { for (const result of resItem.results) { results.push(result); } } } catch (err) { error = err; } } if (error) { console.error(error); throw new functions.https.HttpsError("unknown", "Unknown error."); } return { success: true, results: results, }; } catch (err) { console.log(err); throw err; } })); }; //# sourceMappingURL=send_notification.js.map