UNPKG

phx-react

Version:

PHX REACT

45 lines 2.41 kB
"use strict"; exports.__esModule = true; var tslib_1 = require("tslib"); var read_env_config_1 = require("../../read-env-config"); var constants_1 = require("../../utils/constants"); function PHXClientMutation(mutationName, option, customHeaders, isDelay) { if (isDelay === void 0) { isDelay = true; } return tslib_1.__awaiter(this, void 0, void 0, function () { var startTime, env, uri, fullUrl, headers, mutationResult, endTime, duration; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: startTime = performance.now(); env = (0, read_env_config_1.getEnv)('NEXT_PUBLIC_ENV', process.env.NEXT_PUBLIC_ENV); uri = (0, read_env_config_1.getEnv)('NEXT_PUBLIC_API', process.env.NEXT_PUBLIC_API); fullUrl = typeof window === 'undefined' ? '' : window.location.href; headers = tslib_1.__assign(tslib_1.__assign({}, customHeaders), { 'Full-Url': fullUrl }); if (!(env === 'local')) return [3 /*break*/, 2]; return [4 /*yield*/, mutationName(tslib_1.__assign(tslib_1.__assign({}, option), { context: { uri: uri, headers: headers } }))]; case 1: mutationResult = _a.sent(); return [3 /*break*/, 4]; case 2: return [4 /*yield*/, mutationName(tslib_1.__assign(tslib_1.__assign({}, option), { context: { uri: "".concat(uri, "/graphql/ms/v1/graphql"), headers: headers } }))]; case 3: mutationResult = _a.sent(); _a.label = 4; case 4: endTime = performance.now(); duration = endTime - startTime; if (!(duration < constants_1.requestMaxDuration && isDelay)) return [3 /*break*/, 6]; console.info('promise delay...'); return [4 /*yield*/, new Promise(function (r) { return setTimeout(r, 100); })]; case 5: _a.sent(); _a.label = 6; case 6: return [2 /*return*/, mutationResult]; } }); }); } exports["default"] = PHXClientMutation; //# sourceMappingURL=clientMutationV2.js.map