UNPKG

@mathrunet/masamune

Version:

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

136 lines 6.52 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 verifier = __importStar(require("../lib/functions/verify_ios")); const updater = __importStar(require("../lib/functions/update_wallet")); const firebase_loader_1 = require("../lib/src/firebase_loader"); /** * Performs a consumption-type in-app purchase. The value of the field in the document specified in [path] is added to [value]. * * 消費型のアプリ内課金を行います。[path]に指定したドキュメント内のフィールドの値を[value]に加算します。 * * @param process.env.PURCHASE_IOS_SHAREDSECRET * SharedSecret for AppStore, obtained from [Apps]->[App Info]->[Shared Secret for App] in the AppStore. * * AppStoreのSharedSecret。AppStoreの[アプリ]->[App情報]->[App用共有シークレット]から取得します。 * * @param path * The path, including the key, of the field in the document that stores the in-app wallet information. * * アプリ内ウォレット情報を保存するドキュメント内のフィールドのキーを含めたパス。 * * @param value * Value of the amount to be added. * * 加算する金額の値。 * * @param receiptData * Receipt data for purchases. * * 購入の際のレシートデータ。 */ 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, _b, _c; try { /* ==== IOS検証ここから ==== */ const res = yield verifier.verifyIOS({ receiptData: query.data.receiptData, password: (_a = process.env.PURCHASE_IOS_SHAREDSECRET) !== null && _a !== void 0 ? _a : "", transactionId: query.data.transactionId, storeKitVersion: (_b = query.data.storeKitVersion) !== null && _b !== void 0 ? _b : 1, }); const status = res["status"]; if (status !== 0) { throw new functions.https.HttpsError("unauthenticated", "Illegal receipt."); } /* ==== ここまでIOS検証 ==== */ const info = res["latest_receipt_info"]; if (!query.data.path || !query.data.value) { throw new functions.https.HttpsError("invalid-argument", `The required parameters are not set. path: ${query.data.path} value: ${query.data.value}`); } /* ==== Firestoreの更新ここから ==== */ let error = null; const firestoreDatabaseIds = (_c = options.firestoreDatabaseIds) !== null && _c !== void 0 ? _c : [""]; for (const databaseId of firestoreDatabaseIds) { try { const firestoreInstance = (0, firebase_loader_1.firestoreLoader)(databaseId); yield updater.updateWallet({ targetDocumentFieldPath: query.data.path, value: query.data.value, transactionId: info[info.length - 1]["original_transaction_id"], transactionData: info[info.length - 1], firestoreInstance: firestoreInstance, }); } catch (err) { error = err; } } if (error) { console.error(error); throw new functions.https.HttpsError("unknown", "Unknown error."); } /* ==== ここまでFirestoreの更新 ==== */ return res; } catch (err) { console.error(err); throw err; } })); }; //# sourceMappingURL=consumable_verify_ios.js.map