UNPKG

@crowdin/app-project-module

Version:

Module that generates for you all common endpoints for serving standalone Crowdin App

45 lines (44 loc) 2.25 kB
"use strict"; 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.default = handle; const util_1 = require("../../../util"); const logger_1 = require("../../../util/logger"); function handle(inspector, moduleKey) { return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () { const body = req.body; (0, logger_1.log)(`Received advisor-inspector recheck nudge: ${JSON.stringify(body)}`); // Ack first — BE expects a fast 2xx; the callback runs after the response flushes. res.send({ data: { accepted: true } }); // Capture context locals BEFORE scheduling — Express may recycle `req` post-response. const projectId = body.projectId; const inspectorId = body.inspectorKey; const crowdinId = req.crowdinContext.crowdinId; const context = req.crowdinContext; const client = req.crowdinApiClient; // queueMicrotask is universal (works on Node AND Cloudflare Workers; setImmediate is Node-only). queueMicrotask(() => __awaiter(this, void 0, void 0, function* () { try { yield inspector.onRecheck({ projectId, moduleKey, inspectorId, crowdinId, client, context, }); } catch (e) { (0, logger_1.log)(`advisor-inspector onRecheck error: ${(0, logger_1.getErrorMessage)(e)}`); } })); })); }