@uservitals/import
Version:
Import helpers for uploading feedback to UserVitals
1,085 lines (1,061 loc) • 106 kB
JavaScript
'use strict';
var chalk = require('chalk');
var inquirer = require('inquirer');
var csv = require('csvtojson');
var TurndownService = require('turndown');
var axios = require('axios');
var _ = require('lodash');
var promises = require('fs/promises');
var Parser = require('rss-parser');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
var inquirer__namespace = /*#__PURE__*/_interopNamespace(inquirer);
var csv__default = /*#__PURE__*/_interopDefaultLegacy(csv);
var TurndownService__default = /*#__PURE__*/_interopDefaultLegacy(TurndownService);
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
var Parser__default = /*#__PURE__*/_interopDefaultLegacy(Parser);
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __awaiter(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());
});
}
function __generator(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 (_) 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 };
}
}
function __values(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.");
}
function __read(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;
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
var BASE_PATH = process.cwd();
var pathQuestion = {
basePath: BASE_PATH,
type: "filePath",
name: "filePath",
message: "Select your exported CSV file",
};
var genericQuestion = [pathQuestion];
var trelloQuestions = [
pathQuestion,
{
type: "list",
message: "Would you like to map Trello columns to statuses in your workspace? or set them as your default status of Open?",
name: "columnMapAnswer",
choices: [
{
name: "Yes (Start mapping)",
value: "yes",
},
{
name: "No (Assigned cards to default status)",
value: "no",
},
],
},
];
var productBoardQuestions = [
{
type: "list",
message: "Pick the type of file to be imported:",
name: "importType",
choices: [
{
name: "Feature Export",
value: "features",
},
{
name: "Notes Export",
value: "notes",
},
],
},
pathQuestion,
];
var changelogQuestions = [
pathQuestion,
{
type: "list",
message: "Choose the status of the newly imported changelogs",
name: "status",
choices: [
{
name: "Published",
value: "PUBLISHED",
},
{
name: "Draft",
value: "DRAFT",
},
],
},
];
var headwayQuestions = [
{
type: "input",
name: "filePath",
message: "Please enter the Headway RSS URL that you would like to import",
},
{
type: "list",
message: "Choose the status of the newly imported changelogs",
name: "status",
choices: [
{
name: "Published",
value: "PUBLISHED",
},
{
name: "Draft",
value: "DRAFT",
},
],
},
];
var beamerQuestions = [
{
type: "input",
name: "beamerAPI",
message: "Please enter the Beamer API key that you would like to import",
},
{
type: "list",
message: "Choose the status of the newly imported changelogs",
name: "status",
choices: [
{
name: "Published",
value: "PUBLISHED",
},
{
name: "Draft",
value: "DRAFT",
},
],
},
];
var uvStoryStatusQuestion = [
{
type: "list",
message: "Which UserVitals status would you like this column mapped to?",
name: "uvStoryStatus",
choices: [
{
name: "Skip column",
value: "Skip column",
},
{
name: "Open",
value: "Open",
},
{
name: "Under Review",
value: "UnderReview",
},
{
name: "Planned",
value: "Planned",
},
{
name: "In Progress",
value: "InProgress",
},
{
name: "Completed",
value: "Completed",
},
{
name: "Closed",
value: "Closed",
},
],
},
];
var confirmMapQuestion = [
{
type: "list",
name: "confirmMap",
message: "Do you wish to import Trello cards based on the mapped columns above?",
choices: [
{
name: "Yes, continue.",
value: "Yes",
},
{
name: "No, I am not finished mapping.",
value: "No",
},
],
},
];
var confirmDefaultImport = [
{
type: "list",
name: "confirmMap",
message: "Do you wish to import Trello cards with the default status?",
choices: [
{
name: "Yes, continue.",
value: "Yes",
},
{
name: "No, exit.",
value: "No",
},
],
},
];
/**
* Import issues from a Generic CSV export.
* @param filePath Path to CSV file
* @prarm sdk API
*/
var GenericCsvImporter = /** @class */ (function () {
function GenericCsvImporter(filePath) {
var _this = this;
this.import = function () { return __awaiter(_this, void 0, void 0, function () {
var csvData, data, data_1, data_1_1, row;
var e_1, _a;
var _b, _c, _d, _e;
return __generator(this, function (_f) {
switch (_f.label) {
case 0:
csvData = {
messages: [],
insights: [],
stories: [],
changelogs: [],
changelogLabels: {},
labels: {},
categories: {},
contacts: {},
};
return [4 /*yield*/, csv__default["default"]().fromFile(this.filePath)];
case 1:
data = (_f.sent());
if (data.length < 1) {
return [2 /*return*/, Promise.reject(new Error("No data found in CSV file."))];
}
try {
for (data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
row = data_1_1.value;
csvData.insights.push({
text: row.Text,
type: row.Type,
source: row.Source,
integration: row.Integration,
story: row.Name,
contactEmail: row["Contact Email"],
contactName: row["Contact Name"],
contactId: "",
});
csvData.stories.push({
name: row.Name,
desc: row.Description,
privDesc: row["Private Description"],
contactId: "",
contactName: row["Created By Name"],
contactEmail: row["Created By Email"],
status: row.Status,
visibility: row.Visibility,
category: row.Category,
labels: (_c = (_b = row === null || row === void 0 ? void 0 : row.Labels) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.split(","),
});
csvData.labels[(_d = row.Labels) === null || _d === void 0 ? void 0 : _d.trim()] = {
name: (_e = row.Labels) === null || _e === void 0 ? void 0 : _e.trim(),
};
csvData.contacts[row["Contact Email"]] = {
name: row["Contact Name"],
email: row["Contact Email"],
role: "CUSTOMER",
};
csvData.contacts[row["Created By Email"]] = {
name: row["Created By Name"],
email: row["Created By Email"],
role: "ADMIN",
};
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
}
finally { if (e_1) throw e_1.error; }
}
// remove duplicates
csvData.stories = __spreadArray([], __read(new Set(csvData.stories)), false);
console.log(chalk__default["default"].green("Insight CSV Data Parsed"));
return [2 /*return*/, csvData];
}
});
}); };
this.filePath = filePath;
}
Object.defineProperty(GenericCsvImporter.prototype, "name", {
get: function () {
return "Generic (CSV)";
},
enumerable: false,
configurable: true
});
Object.defineProperty(GenericCsvImporter.prototype, "defaultTeamName", {
get: function () {
return "Generic";
},
enumerable: false,
configurable: true
});
return GenericCsvImporter;
}());
var genericCsvImporter = function () { return __awaiter(void 0, void 0, void 0, function () {
var answers, genericImporter;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, inquirer__namespace.prompt(genericQuestion)];
case 1:
answers = _a.sent();
genericImporter = new GenericCsvImporter(answers.filePath);
return [2 /*return*/, genericImporter];
}
});
}); };
/**
* Import issues from a Generic CSV export.
* @param filePath Path to CSV file
* @prarm sdk API
*/
var GenericChangelogCsvImporter = /** @class */ (function () {
function GenericChangelogCsvImporter(filePath, status) {
var _this = this;
this.import = function () { return __awaiter(_this, void 0, void 0, function () {
var csvData, data, turndownService, data_1, data_1_1, row, markdown;
var e_1, _a;
var _b, _c, _d, _e;
return __generator(this, function (_f) {
switch (_f.label) {
case 0:
csvData = {
messages: [],
insights: [],
stories: [],
labels: {},
categories: {},
changelogs: [],
changelogLabels: {},
contacts: {},
};
return [4 /*yield*/, csv__default["default"]().fromFile(this.filePath)];
case 1:
data = (_f.sent());
if (data.length < 1) {
return [2 /*return*/, Promise.reject(new Error("No data found in CSV file."))];
}
turndownService = new TurndownService__default["default"]();
try {
for (data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
row = data_1_1.value;
markdown = row.content_html ? turndownService.turndown(row.content_html) : '';
csvData.changelogs.push({
title: row.title,
desc: markdown,
labels: (_c = (_b = row === null || row === void 0 ? void 0 : row.labels) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.split(","),
status: this.status,
});
csvData.changelogLabels[(_d = row.labels) === null || _d === void 0 ? void 0 : _d.trim()] = {
name: (_e = row.labels) === null || _e === void 0 ? void 0 : _e.trim(),
};
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
}
finally { if (e_1) throw e_1.error; }
}
console.log(chalk__default["default"].green("Insight CSV Data Parsed"));
csvData.changelogLabels[""];
return [2 /*return*/, csvData];
}
});
}); };
this.filePath = filePath;
this.status = status;
}
Object.defineProperty(GenericChangelogCsvImporter.prototype, "name", {
get: function () {
return "Generic (CSV)";
},
enumerable: false,
configurable: true
});
Object.defineProperty(GenericChangelogCsvImporter.prototype, "defaultTeamName", {
get: function () {
return "Generic";
},
enumerable: false,
configurable: true
});
return GenericChangelogCsvImporter;
}());
var genericChangelogCsvImporter = function () { return __awaiter(void 0, void 0, void 0, function () {
var answers, genericImporter;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, inquirer__namespace.prompt(changelogQuestions)];
case 1:
answers = _a.sent();
genericImporter = new GenericChangelogCsvImporter(answers.filePath, answers.status);
return [2 /*return*/, genericImporter];
}
});
}); };
/**
* Import issues from a Generic CSV export.
* @param filePath Path to CSV file
* @prarm sdk API
*/
var CannyCsvImporter = /** @class */ (function () {
function CannyCsvImporter(filePath) {
var _this = this;
// convert to UserVitals format
this.statusMap = {
"under review": "UnderReview",
planned: "Planned",
"in progress": "InProgress",
complete: "Completed",
closed: "Closed",
open: "Open",
};
this.import = function () { return __awaiter(_this, void 0, void 0, function () {
var csvData, data, duplicate, data_1, data_1_1, row;
var e_1, _a;
var _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
csvData = {
stories: [],
insights: [],
messages: [],
changelogs: [],
changelogLabels: {},
labels: {},
categories: {},
contacts: {},
};
return [4 /*yield*/, csv__default["default"]().fromFile(this.filePath)];
case 1:
data = (_c.sent());
if (data.length < 1) {
return [2 /*return*/, Promise.reject(new Error("No data found in CSV file."))];
}
duplicate = new Set();
try {
for (data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
row = data_1_1.value;
csvData.stories.push({
name: row.title,
desc: row.details,
privDesc: "",
status: this.statusMap[row.status],
category: row.category,
labels: (_b = row === null || row === void 0 ? void 0 : row.tags) === null || _b === void 0 ? void 0 : _b.split(","),
visibility: "VISIBLE",
contactId: row.authorEmail,
contactEmail: row.authorEmail,
contactName: row.authorName,
});
csvData.labels[row.tags] = {
name: row.tags,
};
csvData.categories[row.category] = {
name: row.category,
};
csvData.contacts[row.authorEmail] = {
name: row.authorName,
email: row.authorEmail,
role: "ADMIN",
};
duplicate.add(row.title);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
}
finally { if (e_1) throw e_1.error; }
}
console.log(chalk__default["default"].green("Insight CSV Data Parsed"));
// Check for duplicate titles in stories
if (csvData.stories.length !== duplicate.size) {
console.log(chalk__default["default"].red("Duplicate titles found in CSV file"));
console.log(chalk__default["default"].red(csvData.stories.length + " entries with " + duplicate.size + " unique titles"));
return [2 /*return*/, Promise.reject(new Error("Duplicate titles found in CSV file"))];
}
return [2 /*return*/, csvData];
}
});
}); };
this.filePath = filePath;
}
Object.defineProperty(CannyCsvImporter.prototype, "name", {
get: function () {
return "Canny (CSV)";
},
enumerable: false,
configurable: true
});
Object.defineProperty(CannyCsvImporter.prototype, "defaultTeamName", {
get: function () {
return "Canny";
},
enumerable: false,
configurable: true
});
return CannyCsvImporter;
}());
var cannyCsvImporter = function () { return __awaiter(void 0, void 0, void 0, function () {
var answers, genericImporter;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, inquirer__namespace.prompt(genericQuestion)];
case 1:
answers = _a.sent();
genericImporter = new CannyCsvImporter(answers.filePath);
return [2 /*return*/, genericImporter];
}
});
}); };
/**
* Import issues from a Generic CSV export.
* @param filePath Path to CSV file
* @prarm sdk API
*/
var ProductboardCsvImporter = /** @class */ (function () {
function ProductboardCsvImporter(filePath, importType) {
var _this = this;
// convert to UserVitals format
this.featureStatusMap = {
"Under review": "UnderReview",
Planned: "Planned",
"In progress": "InProgress",
Open: "Open",
};
// public messageStatusMap = {
// 'Unprocessed': 'UNREVIEWED'
// };
this.import = function () { return __awaiter(_this, void 0, void 0, function () {
var csvData, data, isFeature, duplicate, data_1, data_1_1, row, state, turndownService, markdown, containsDuplicates;
var e_1, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
csvData = {
stories: [],
insights: [],
messages: [],
changelogs: [],
changelogLabels: {},
labels: {},
categories: {},
contacts: {},
};
return [4 /*yield*/, csv__default["default"]().fromFile(this.filePath)];
case 1:
data = (_b.sent());
if (data.length < 1) {
return [2 /*return*/, Promise.reject(new Error("No data found in CSV file."))];
}
isFeature = this.importType === "features";
duplicate = new Set();
try {
for (data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
row = data_1_1.value;
state = this.featureStatusMap[row.state_name] ? this.featureStatusMap[row.state_name] : "Open";
turndownService = new TurndownService__default["default"]();
markdown = "";
isFeature
? (csvData.stories.push({
name: row.name,
desc: row.description,
privDesc: "",
status: state,
category: row.feature_type,
labels: [],
contactId: '',
contactEmail: '',
contactName: '',
visibility: "VISIBLE",
}),
duplicate.add(row.name),
(csvData.categories[row.feature_type] = {
name: row.feature_type,
}))
: (markdown = turndownService.turndown(row.note_text)),
(row.note_text !== undefined ? csvData.messages.push({
title: row.note_title,
status: row.state === "Unprocessed" ? "UNREVIEWED" : "REVIEWED",
sourceUrl: row.source_url,
content: markdown,
contactEmail: row.user_email,
contactName: row.user_email,
creatorName: row.creator_name,
creatorEmail: row.creator_email,
contactId: '',
creatorId: '',
labels: [],
}) : null,
csvData.contacts[row.creator_email] = {
name: row.creator_name,
email: row.creator_email,
role: 'ADMIN',
},
csvData.contacts[row.user_email] = {
name: row.user_name,
email: row.user_email,
role: 'CUSTOMER',
});
duplicate.add(row.note_text);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
}
finally { if (e_1) throw e_1.error; }
}
console.log(chalk__default["default"].green("Insight CSV Data Parsed"));
duplicate.delete(undefined); // remove undefined
containsDuplicates = isFeature
? csvData.stories.length !== duplicate.size
: csvData.messages.length !== duplicate.size;
if (containsDuplicates) {
console.log(chalk__default["default"].red("Duplicate titles found in CSV file"));
console.log(chalk__default["default"].red(csvData.stories.length + " entries with " + duplicate.size + " unique titles"));
return [2 /*return*/, Promise.reject(new Error("Duplicate titles found in CSV file"))];
}
return [2 /*return*/, csvData];
}
});
}); };
this.filePath = filePath;
this.importType = importType;
}
Object.defineProperty(ProductboardCsvImporter.prototype, "name", {
get: function () {
return "Canny (CSV)";
},
enumerable: false,
configurable: true
});
Object.defineProperty(ProductboardCsvImporter.prototype, "defaultTeamName", {
get: function () {
return "Canny";
},
enumerable: false,
configurable: true
});
return ProductboardCsvImporter;
}());
var productboardCsvImporter = function () { return __awaiter(void 0, void 0, void 0, function () {
var answers, genericImporter;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, inquirer__namespace.prompt(productBoardQuestions)];
case 1:
answers = _a.sent();
genericImporter = new ProductboardCsvImporter(answers.filePath, answers.importType);
return [2 /*return*/, genericImporter];
}
});
}); };
var UservitalsClient = /** @class */ (function () {
function UservitalsClient(apiKey) {
var _this = this;
this.baseApiPath = process.env.DEV_BUILD ? process.env.UV_API_PATH : "https://api.uservitalshq.com";
this.myTeamMembers = function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client({
data: {
query: "\n query myTeamMembers {\n myTeamMembers {\n user {\n email\n name\n }\n id\n } \n }\n ",
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
// Get team info
this.team = function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client({
data: {
query: "\n query myTeam {\n myTeam {\n id\n name\n } \n }\n ",
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
// Gets all story labels
this.teamLabels = function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client({
data: {
query: "\n query myTeamLabels {\n myTeamLabels {\n id\n name\n } \n }\n ",
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
// Gets all story labels
this.teamCategories = function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client({
data: {
query: "\n query myTeamCategories {\n myTeamCategories {\n id\n name\n } \n }\n ",
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
this.changelogLabels = function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client({
data: {
query: "\n query myTeamChangelogLabels {\n myTeamChangelogLabels {\n id\n name\n } \n }\n ",
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
// Used to create insights and stories from a flat csv file
this.createInsight = function (input) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client({
data: {
query: "\n mutation createInsight( $input: InsightCreateInput!) {\n createInsight(input: $input) {\n id\n }\n }\n ",
variables: {
input: {
text: input.text,
sourceUrl: input.source,
integration: input.integration,
type: input.type,
storyId: input.story,
contactId: input.contactId,
},
},
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
// Creates a message in UserVtials
this.createMessage = function (input) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client({
data: {
query: "\n mutation createMessage( $input: MessageCreateInput!) {\n createMessage(input: $input) {\n id\n } \n }\n ",
variables: {
input: {
title: input.title,
content: input.content,
status: input.status,
sourceUrl: input.sourceUrl,
labels: input.labels,
contactId: input.contactId,
creatorId: input.creatorId,
},
},
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
// Creates a story in UserVtials
this.createStory = function (input) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client({
data: {
query: "\n mutation createStory( $input: StoryCreateInput!) {\n createStory(input: $input) {\n id\n } \n }\n ",
variables: {
input: {
name: input.name,
desc: input.desc,
privDesc: input.privDesc,
contactId: input.contactId,
status: input.status,
category: input.category,
labels: input.labels,
},
},
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
// Creates a story label for a team in UserVtials
this.createStoryLabel = function (name) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client({
data: {
query: "\n mutation createStoryLabel($name: String!) {\n createStoryLabel(name: $name) {\n id\n } \n }\n ",
variables: {
name: name,
},
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
// Creates a Changelog label for a team in UserVtials
this.createChangelogLabel = function (name) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client({
data: {
query: "\n mutation createChangelogLabel($name: String!) {\n createChangelogLabel(name: $name) {\n id\n } \n }\n ",
variables: {
name: name,
},
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
// Creates a story category for a team in UserVtials
this.createStoryCategory = function (name) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client({
data: {
query: "\n mutation createStoryCategory($name: String!) {\n createStoryCategory(name: $name) {\n id\n } \n }\n ",
variables: {
name: name,
},
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
// Creates a changelog in UserVtials
this.createChangelog = function (input) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client({
data: {
query: "\n mutation createChangelog( $input: ChangelogCreateInput!) {\n createChangelog(input: $input) {\n title\n } \n }\n ",
variables: {
input: {
title: input.title,
desc: input.desc,
labels: input.labels,
status: input.status,
},
},
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
// Creates a message in UserVtials
this.createMembership = function (input) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client({
data: {
query: "\n mutation createMembership( $input: UserInput!) {\n createMembership(input: $input) {\n id\n user {\n email\n name\n }\n } \n }\n ",
variables: {
input: {
name: input.name,
email: input.email,
role: input.role,
},
},
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
this.client = axios__default["default"].create({
method: "POST",
baseURL: this.baseApiPath + "/v1/",
headers: {
Authorization: "Bearer " + apiKey,
"auth-provider": "custom",
"content-type": "application/json",
"user-agent": "UserVitals Importer",
},
});
}
return UservitalsClient;
}());
// eslint-disable-next-line @typescript-eslint/no-var-requires
require("dotenv").config();
var importItems = function (apiKey, importer) { return __awaiter(void 0, void 0, void 0, function () {
var client, importData, labelMapping, existingLabelMap, myTeamLabelsQuery, myTeamLabels, myTeamLabels_1, myTeamLabels_1_1, label, labelName, _a, _b, labelId, label, labelName, labelArray, labelArray_1, labelArray_1_1, nameOfLabel, actualLabelId, labelResponse, labelData, e_1_1, e_2_1, categoryMapping, categoryQuery, categories, existingCategoryMap, categories_1, categories_1_1, catergory, categoryName, _c, _d, cat, catName, actualCatId, catResponse, catData, e_3_1, contactMapping, existingContactMap, teamMemberQuery, teamMembers, teamMembers_1, teamMembers_1_1, member, contactEmail, _e, _f, contact, contactEmail, user, actualContactId, contactResponse, contactData, e_4_1, storyMapping, _g, _h, story, storyLabelIds, response, storyData, e_5_1, _j, _k, insight, e_6_1, _l, _m, message, e_7_1, changelogLabelQuery, myTeamChangelogLabels, existingChangelogLabelMap, myTeamChangelogLabels_1, myTeamChangelogLabels_1_1, label, labelName, changelogLabelMapping_1, _o, _p, labelId, label, labelName, labelArray, labelArray_2, labelArray_2_1, nameOfLabel, actualLabelId, labelResponse, labelData, e_8_1, e_9_1, _q, _r, changelog, storyLabelIds, e_10_1;
var e_11, _s, e_2, _t, e_1, _u, e_12, _v, e_3, _w, e_13, _x, e_4, _y, e_5, _z, e_6, _0, e_7, _1, e_14, _2, e_9, _3, e_8, _4, e_10, _5;
var _6, _7, _8, _9, _10, _11, _12, _13;
return __generator(this, function (_14) {
switch (_14.label) {
case 0:
client = new UservitalsClient(apiKey);
return [4 /*yield*/, importer.import()];
case 1:
importData = _14.sent();
labelMapping = {};
existingLabelMap = {};
if (!(Object.keys(importData.labels).length !== 0)) return [3 /*break*/, 17];
return [4 /*yield*/, client.teamLabels()];
case 2:
myTeamLabelsQuery = (_14.sent()) || [];
myTeamLabels = (_7 = (_6 = myTeamLabelsQuery === null || myTeamLabelsQuery === void 0 ? void 0 : myTeamLabelsQuery.data) === null || _6 === void 0 ? void 0 : _6.data) === null || _7 === void 0 ? void 0 : _7.myTeamLabels;
try {
for (myTeamLabels_1 = __values(myTeamLabels), myTeamLabels_1_1 = myTeamLabels_1.next(); !myTeamLabels_1_1.done; myTeamLabels_1_1 = myTeamLabels_1.next()) {
label = myTeamLabels_1_1.value;
labelName = (_8 = label.name) === null || _8 === void 0 ? void 0 : _8.toLowerCase().trim();
existingLabelMap[labelName] = label.id;
}
}
catch (e_11_1) { e_11 = { error: e_11_1 }; }
finally {
try {
if (myTeamLabels_1_1 && !myTeamLabels_1_1.done && (_s = myTeamLabels_1.return)) _s.call(myTeamLabels_1);
}
finally { if (e_11) throw e_11.error; }
}
_14.label = 3;
case 3:
_14.trys.push([3, 15, 16, 17]);
_a = __values(Object.keys(importData.labels)), _b = _a.next();
_14.label = 4;
case 4:
if (!!_b.done) return [3 /*break*/, 14];
labelId = _b.value;
label = importData.labels[labelId];
labelName = ___default["default"].truncate((_9 = label === null || label === void 0 ? void 0 : label.name) === null || _9 === void 0 ? void 0 : _9.trim(), { length: 20 });
labelArray = labelName.split(",");
_14.label = 5;
case 5:
_14.tr