UNPKG

@mathrunet/masamune

Version:

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

150 lines 5.45 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 }); exports.updateSubscription = updateSubscription; const path = __importStar(require("path")); const utils = __importStar(require("../utils")); /** * Processes subscription updates. * * サブスクリプションのアップデート処理を行います。 * * @param {String} targetCollectionPath * Specify the path of the collection to be updated. * * アップデートを行うコレクションのパスを指定します。 * * @param {String} targetDocumentId * Specifies the ID of the document to be updated. * * アップデートを行うドキュメントのIDを指定します。 * * @param {[key: string]: any} data * Document data to be updated. * * 更新するドキュメントデータ。 * * @param {[key: string]: any} additionalData * Additional documentation data. * * 追加のドキュメントデータ。 * * @param {String} userId * ID of the user who purchased the subscription. * * サブスクリプションを購入したユーザーのID。 * * @param {String} platform * Subscription-based platform. * * サブスクリプションを利用するプラットフォーム。 * * @param {String} orderId * Subscription Order ID. * * サブスクリプションの注文ID。 * * @param {String} productId Product ID. * Subscription product ID. * * サブスクリプションのプロダクトID。 * * @param {String} purchaseId * Subscription purchase ID. * * サブスクリプションの購入ID。 * * @param {String} packageName * The package name of the application. * * アプリケーションのパッケージ名。 * * @param {String} token * Token issued at the time of purchase. * * 購入時に発行されたトークン。 * * @param {number} expiryDate * Subscription expiration date. * * サブスクリプションの有効期限。 */ function updateSubscription(_a) { return __awaiter(this, arguments, void 0, function* ({ targetCollectionPath, targetDocumentId, data, additionalData, userId, platform, orderId, productId, purchaseId, packageName, token, expiryDate, firestoreInstance, }) { const update = {}; for (const key in data) { if (!data[key]) { continue; } update[key] = utils.parse(data[key]); } if (additionalData) { for (const key in additionalData) { if (!additionalData[key]) { continue; } update[key] = utils.parse(additionalData[key]); } } targetCollectionPath = `${targetCollectionPath}/${targetDocumentId}`; update["expired"] = false; update["paused"] = false; update["token"] = token; update["platform"] = platform; update["productId"] = productId; update["purchaseId"] = purchaseId; update["packageName"] = packageName; update["expiredTime"] = expiryDate; update["orderId"] = orderId; if (userId) { update["userId"] = userId; } update["@time"] = new Date(); update["@uid"] = path.basename(targetCollectionPath); yield firestoreInstance.doc(targetCollectionPath).set(update, { merge: true, }); }); } //# sourceMappingURL=update_subscription.js.map