This commit is contained in:
Luiz H. R. Silva 2024-06-22 21:21:39 -03:00
parent ceab73c21c
commit 2325b4a2a8
16 changed files with 345 additions and 1 deletions

3
dist-require/NPS/index.d.ts vendored Normal file
View file

@ -0,0 +1,3 @@
import type { tipo_proxima_avaliacao } from "./tipos_nps";
export declare const abrirNps: (emDesenvolvimento: boolean) => (parametros: tipo_proxima_avaliacao["parametros"]) => Promise<void>;
export type { tipo_proxima_avaliacao };

152
dist-require/NPS/index.js Normal file
View file

@ -0,0 +1,152 @@
"use strict";
// npm run build produz um arquivo abrirNps.js que é copiado para a pasta public
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());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.abrirNps = void 0;
var p_respostas_1 = require("p-respostas");
// exibe o iframe em tela cheia
var abrirNps = function (emDesenvolvimento) {
return function (parametros) { return __awaiter(void 0, void 0, void 0, function () {
var base_site, base_api, sistema, codigo_organizacao, codigo_usuario, nome_local_storage_proxima, proxima_avaliacao, url_proxima_avaliacao, _a, _b, _c, chave, valor, response, proxima_avaliacao_1, abrir_modal, urlIfrma, _d, _e, _f, chave, valor, iframe;
var e_1, _g, e_2, _h;
return __generator(this, function (_j) {
switch (_j.label) {
case 0:
base_site = emDesenvolvimento
? "http://localhost:5040/nps"
: "https://carro-de-boi.idz.one/nps";
base_api = "".concat(base_site, "/api");
sistema = parametros.sistema, codigo_organizacao = parametros.codigo_organizacao, codigo_usuario = parametros.codigo_usuario;
nome_local_storage_proxima = "nps_".concat(sistema, "_").concat(codigo_usuario, "_").concat(codigo_organizacao, "_0");
proxima_avaliacao = localStorage.getItem(nome_local_storage_proxima);
if (!!proxima_avaliacao) return [3 /*break*/, 2];
url_proxima_avaliacao = new URL("".concat(base_api, "/").concat(sistema, "/proxima_avaliacao"));
try {
for (_a = __values(Object.entries(parametros)), _b = _a.next(); !_b.done; _b = _a.next()) {
_c = __read(_b.value, 2), chave = _c[0], valor = _c[1];
url_proxima_avaliacao.searchParams.append(chave, valor);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
}
finally { if (e_1) throw e_1.error; }
}
return [4 /*yield*/, fetch(url_proxima_avaliacao.href)
.then(function (resposta) {
return resposta.json();
})
.catch(function (error) { return p_respostas_1.respostaComuns.erro(error.message); })];
case 1:
response = _j.sent();
proxima_avaliacao_1 = response.valor;
proxima_avaliacao_1 &&
localStorage.setItem(nome_local_storage_proxima, proxima_avaliacao_1);
_j.label = 2;
case 2:
abrir_modal = proxima_avaliacao &&
new Date().toISOString().slice(0, 10) >= proxima_avaliacao;
if (!abrir_modal) {
return [2 /*return*/];
}
localStorage.removeItem(nome_local_storage_proxima);
urlIfrma = new URL(base_site);
try {
for (_d = __values(Object.entries(parametros)), _e = _d.next(); !_e.done; _e = _d.next()) {
_f = __read(_e.value, 2), chave = _f[0], valor = _f[1];
urlIfrma.searchParams.append(chave, valor);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_e && !_e.done && (_h = _d.return)) _h.call(_d);
}
finally { if (e_2) throw e_2.error; }
}
iframe = document.createElement("iframe");
iframe.src = urlIfrma.href;
iframe.style.position = "fixed";
iframe.style.top = "0";
iframe.style.left = "0";
iframe.style.width = "100%";
iframe.style.height = "100%";
iframe.style.border = "none";
iframe.style.zIndex = "999999";
document.body.appendChild(iframe);
// receber mensagem do iframe
window.addEventListener("message", function (event) {
if (event.data === "fechar") {
document.body.removeChild(iframe);
}
});
return [2 /*return*/];
}
});
}); };
};
exports.abrirNps = abrirNps;

13
dist-require/NPS/tipos_nps.d.ts vendored Normal file
View file

@ -0,0 +1,13 @@
import type { tipoResposta } from "p-respostas";
export type tipo_proxima_avaliacao = {
parametros: {
sistema: string;
codigo_organizacao: string;
codigo_usuario: string;
nome_organizacao: string;
nome_usuario: string;
contatos_usuario: string;
data_criacao_conta: string;
};
retorno: tipoResposta<string>;
};

View file

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });