drapcode-utility 1.9.0 → 1.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/utils/project-util.d.ts +4 -0
- package/build/utils/project-util.js +169 -0
- package/build/utils/util.js +15 -0
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from "./utils/uuid-generator";
|
|
|
14
14
|
export * from "./utils/check-error";
|
|
15
15
|
export * from "./utils/prepare-query";
|
|
16
16
|
export * from "./utils/s3-util";
|
|
17
|
+
export * from "./utils/project-util";
|
|
17
18
|
export * from "./encryption/index";
|
|
18
19
|
export * from "./encryption/utility";
|
|
19
20
|
export * from "./format-fields/index";
|
package/build/index.js
CHANGED
|
@@ -30,6 +30,7 @@ __exportStar(require("./utils/uuid-generator"), exports);
|
|
|
30
30
|
__exportStar(require("./utils/check-error"), exports);
|
|
31
31
|
__exportStar(require("./utils/prepare-query"), exports);
|
|
32
32
|
__exportStar(require("./utils/s3-util"), exports);
|
|
33
|
+
__exportStar(require("./utils/project-util"), exports);
|
|
33
34
|
__exportStar(require("./encryption/index"), exports);
|
|
34
35
|
__exportStar(require("./encryption/utility"), exports);
|
|
35
36
|
__exportStar(require("./format-fields/index"), exports);
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.removeProjectFromFile = exports.updateProjectInFile = exports.findProjectFromFile = exports.saveProjectToFile = void 0;
|
|
7
|
+
var fs_1 = require("fs");
|
|
8
|
+
var path_1 = __importDefault(require("path"));
|
|
9
|
+
var filePath = process.env.BUILD_FOLDER;
|
|
10
|
+
var saveProjectToFile = function (project) {
|
|
11
|
+
if (!project) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
console.log("Check path", filePath);
|
|
15
|
+
checkFolder(filePath);
|
|
16
|
+
var projectPath = path_1.default.join(filePath, "projects");
|
|
17
|
+
console.log("Check path", projectPath);
|
|
18
|
+
checkFolder(projectPath);
|
|
19
|
+
var uuid = project.uuid, seoName = project.seoName, apiDomainName = project.apiDomainName, domainName = project.domainName;
|
|
20
|
+
console.log("Create UUID JSON file");
|
|
21
|
+
createFile(path_1.default.join(projectPath, "".concat(uuid, ".json")), project);
|
|
22
|
+
console.log("Create SeoName JSON file");
|
|
23
|
+
createFile(path_1.default.join(projectPath, "".concat(seoName, ".json")), project);
|
|
24
|
+
if (apiDomainName) {
|
|
25
|
+
console.log("Create API Domain JSON file");
|
|
26
|
+
createFile(path_1.default.join(projectPath, "".concat(apiDomainName, ".json")), project);
|
|
27
|
+
}
|
|
28
|
+
if (domainName) {
|
|
29
|
+
console.log("Create Domain JSON file");
|
|
30
|
+
createFile(path_1.default.join(projectPath, "".concat(domainName, ".json")), project);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.saveProjectToFile = saveProjectToFile;
|
|
34
|
+
var findProjectFromFile = function (query) {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
console.log("query :>> ", query);
|
|
37
|
+
var isMainExists = verifyProjectsFolder();
|
|
38
|
+
if (!isMainExists) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
var projectPath = path_1.default.join(filePath, "projects");
|
|
42
|
+
console.log("projectPath :>> ", projectPath);
|
|
43
|
+
var or = query.or, apiDomainName = query.apiDomainName, seoName = query.seoName, domainName = query.domainName;
|
|
44
|
+
if (apiDomainName) {
|
|
45
|
+
//If api domain exists then please check with this no need of or
|
|
46
|
+
console.log("Checking for Project API Domain");
|
|
47
|
+
var project = readFile(path_1.default.join(projectPath, "".concat(apiDomainName, ".json")));
|
|
48
|
+
return project;
|
|
49
|
+
}
|
|
50
|
+
if (seoName) {
|
|
51
|
+
//IF api seo name exists then not need to check or
|
|
52
|
+
console.log("Checking for Project SEO Name");
|
|
53
|
+
var project = readFile(path_1.default.join(projectPath, "".concat(seoName, ".json")));
|
|
54
|
+
return project;
|
|
55
|
+
}
|
|
56
|
+
if (domainName) {
|
|
57
|
+
//IF api seo name exists then not need to check or
|
|
58
|
+
console.log("Checking for Project SEO Name");
|
|
59
|
+
var project = readFile(path_1.default.join(projectPath, "".concat(domainName, ".json")));
|
|
60
|
+
return project;
|
|
61
|
+
}
|
|
62
|
+
if (!or || or.length === 0) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
var pSeoName = (_a = extractDomainSeo(or, "seoName")) === null || _a === void 0 ? void 0 : _a["seoName"];
|
|
66
|
+
var pDomainName = (_b = extractDomainSeo(or, "domainName")) === null || _b === void 0 ? void 0 : _b["domainName"];
|
|
67
|
+
// Now check with pSeoName and domainName
|
|
68
|
+
console.log("pSeoName :>> ", pSeoName);
|
|
69
|
+
console.log("domainName :>> ", domainName);
|
|
70
|
+
if (pSeoName) {
|
|
71
|
+
//IF api seo name exists then not need to check or
|
|
72
|
+
console.log("Checking for Project SEO Name");
|
|
73
|
+
var project = readFile(path_1.default.join(projectPath, "".concat(pSeoName, ".json")));
|
|
74
|
+
return project;
|
|
75
|
+
}
|
|
76
|
+
if (pDomainName) {
|
|
77
|
+
//IF api seo name exists then not need to check or
|
|
78
|
+
console.log("Checking for Project Domain Name");
|
|
79
|
+
var project = readFile(path_1.default.join(projectPath, "".concat(pDomainName, ".json")));
|
|
80
|
+
return project;
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
};
|
|
84
|
+
exports.findProjectFromFile = findProjectFromFile;
|
|
85
|
+
var updateProjectInFile = function () { };
|
|
86
|
+
exports.updateProjectInFile = updateProjectInFile;
|
|
87
|
+
var removeProjectFromFile = function (project) {
|
|
88
|
+
//Check if projects folder exists in filePath or not
|
|
89
|
+
//Remove
|
|
90
|
+
if (!project) {
|
|
91
|
+
console.log("I do not have project");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
var isMainExists = verifyProjectsFolder();
|
|
95
|
+
console.log("Project Folder failed", isMainExists);
|
|
96
|
+
if (!isMainExists) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
var projectPath = "".concat(filePath, "projects");
|
|
100
|
+
console.log("Check path", projectPath);
|
|
101
|
+
var uuid = project.uuid, seoName = project.seoName, apiDomainName = project.apiDomainName, domainName = project.domainName;
|
|
102
|
+
console.log("Removing UUID JSON");
|
|
103
|
+
removeFile(path_1.default.join(projectPath, "".concat(uuid, ".json")));
|
|
104
|
+
console.log("Removing Seo Name JSON");
|
|
105
|
+
removeFile(path_1.default.join(projectPath, "".concat(seoName, ".json")));
|
|
106
|
+
if (apiDomainName) {
|
|
107
|
+
console.log("Removing API Domain JSON");
|
|
108
|
+
removeFile(path_1.default.join(projectPath, "".concat(apiDomainName, ".json")));
|
|
109
|
+
}
|
|
110
|
+
if (domainName) {
|
|
111
|
+
console.log("Removing Domain JSON");
|
|
112
|
+
removeFile(path_1.default.join(projectPath, "".concat(domainName, ".json")));
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
exports.removeProjectFromFile = removeProjectFromFile;
|
|
116
|
+
var checkFolder = function (path) {
|
|
117
|
+
if (!path) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (!(0, fs_1.existsSync)(path)) {
|
|
121
|
+
try {
|
|
122
|
+
(0, fs_1.mkdirSync)(path);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
console.error(error);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
var verifyProjectsFolder = function () {
|
|
130
|
+
var projectPath = path_1.default.join(filePath, "projects");
|
|
131
|
+
return (0, fs_1.existsSync)(filePath) && (0, fs_1.existsSync)(projectPath);
|
|
132
|
+
};
|
|
133
|
+
var createFile = function (filePath, content) {
|
|
134
|
+
try {
|
|
135
|
+
(0, fs_1.writeFileSync)(filePath, JSON.stringify(content));
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
console.log("error :>> ", error);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
var removeFile = function (filePath) {
|
|
142
|
+
console.log("removeFile filePath :>> ", filePath);
|
|
143
|
+
try {
|
|
144
|
+
(0, fs_1.existsSync)(filePath) && (0, fs_1.unlinkSync)(filePath);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.log("error :>> ", error);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
var readFile = function (filePath) {
|
|
151
|
+
try {
|
|
152
|
+
console.log("readFile filePath :>> ", filePath);
|
|
153
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
var content = (0, fs_1.readFileSync)(filePath, "utf8");
|
|
157
|
+
if (!content)
|
|
158
|
+
return null;
|
|
159
|
+
console.log("*******************************");
|
|
160
|
+
return JSON.parse(content);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
console.log("error :>> ", error);
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
function extractDomainSeo(or, key) {
|
|
168
|
+
return or.find(function (obj) { return Object.keys(obj)[0] === key; });
|
|
169
|
+
}
|
package/build/utils/util.js
CHANGED
|
@@ -298,28 +298,34 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
298
298
|
var _a;
|
|
299
299
|
var contentList = (_a = expression
|
|
300
300
|
.match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
|
|
301
|
+
console.log("1 replaceDataValueIntoExpression");
|
|
301
302
|
contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
|
|
302
303
|
var needle = "{{".concat(prop, "}}");
|
|
304
|
+
console.log("needle :>> ", needle);
|
|
303
305
|
var dataOfItem = "";
|
|
304
306
|
if (prop.includes("current_user")) {
|
|
307
|
+
console.log("Current User");
|
|
305
308
|
prop = prop.replace("current_user.", "");
|
|
306
309
|
if (Object.keys(user).length > 0) {
|
|
307
310
|
dataOfItem = (0, exports.parseValueFromData)(user, prop);
|
|
308
311
|
}
|
|
309
312
|
}
|
|
310
313
|
else if (prop.includes("current_tenant")) {
|
|
314
|
+
console.log("Current Tenant");
|
|
311
315
|
prop = prop.replace("current_tenant.", "");
|
|
312
316
|
if (Object.keys(tenant).length > 0) {
|
|
313
317
|
dataOfItem = (0, exports.parseValueFromData)(tenant, prop);
|
|
314
318
|
}
|
|
315
319
|
}
|
|
316
320
|
else if (prop.includes("current_settings")) {
|
|
321
|
+
console.log("Current Setting");
|
|
317
322
|
prop = prop.replace("current_settings.", "");
|
|
318
323
|
if (Object.keys(userSetting).length > 0) {
|
|
319
324
|
dataOfItem = (0, exports.parseValueFromData)(userSetting, prop);
|
|
320
325
|
}
|
|
321
326
|
}
|
|
322
327
|
else if (prop.includes("current_session")) {
|
|
328
|
+
console.log("Current Session");
|
|
323
329
|
prop = prop.replace("current_session.", "");
|
|
324
330
|
if (Object.keys(sessionValue).length > 0) {
|
|
325
331
|
//Session will contain multi level data
|
|
@@ -327,6 +333,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
327
333
|
}
|
|
328
334
|
}
|
|
329
335
|
else if (prop.includes("form_data_session")) {
|
|
336
|
+
console.log("Form Data Session");
|
|
330
337
|
prop = prop.replace("form_data_session.", "");
|
|
331
338
|
if (Object.keys(sessionFormValue).length > 0) {
|
|
332
339
|
//Form Session will contain multi level data
|
|
@@ -334,6 +341,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
334
341
|
}
|
|
335
342
|
}
|
|
336
343
|
else if (prop.includes("SESSION_STORAGE")) {
|
|
344
|
+
console.log("Session Storage");
|
|
337
345
|
prop = prop.replace("SESSION_STORAGE.", "");
|
|
338
346
|
if (Object.keys(sessionValue).length > 0) {
|
|
339
347
|
//Session will contain multi level data
|
|
@@ -341,6 +349,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
341
349
|
}
|
|
342
350
|
}
|
|
343
351
|
else if (prop.includes("LOCAL_STORAGE")) {
|
|
352
|
+
console.log("Local Storage");
|
|
344
353
|
prop = prop.replace("LOCAL_STORAGE.", "");
|
|
345
354
|
if (Object.keys(localStorageValue).length > 0) {
|
|
346
355
|
//Session will contain multi level data
|
|
@@ -348,6 +357,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
348
357
|
}
|
|
349
358
|
}
|
|
350
359
|
else if (prop.includes("COOKIES")) {
|
|
360
|
+
console.log("Cookies");
|
|
351
361
|
prop = prop.replace("COOKIES.", "");
|
|
352
362
|
if (Object.keys(cookiesValue).length > 0) {
|
|
353
363
|
//Session will contain multi level data
|
|
@@ -355,6 +365,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
355
365
|
}
|
|
356
366
|
}
|
|
357
367
|
else if (prop.includes("environment_variable")) {
|
|
368
|
+
console.log("Environment Variable");
|
|
358
369
|
prop = prop.replace("environment_variable.", "");
|
|
359
370
|
if (Object.keys(envConstants).length > 0) {
|
|
360
371
|
var selectedConstant = envConstants.find(function (constant) { return constant.name === prop; });
|
|
@@ -362,13 +373,16 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
362
373
|
}
|
|
363
374
|
}
|
|
364
375
|
else {
|
|
376
|
+
console.log("Nothing Matches");
|
|
365
377
|
if (Object.keys(data).length > 0) {
|
|
366
378
|
dataOfItem = (0, exports.parseValueFromData)(data, prop);
|
|
367
379
|
//TODO: Need better way
|
|
368
380
|
delete data[prop];
|
|
369
381
|
}
|
|
370
382
|
}
|
|
383
|
+
console.log("dataOfItem :>> ", dataOfItem);
|
|
371
384
|
expression = replaceValueInExpression(needle, dataOfItem, expression);
|
|
385
|
+
console.log("expression :>> ", expression);
|
|
372
386
|
});
|
|
373
387
|
return expression;
|
|
374
388
|
};
|
|
@@ -427,6 +441,7 @@ var parseValueFromData = function (data, fieldName) {
|
|
|
427
441
|
else {
|
|
428
442
|
value = data ? data[fieldName] : "";
|
|
429
443
|
}
|
|
444
|
+
console.log("value :>> ", value);
|
|
430
445
|
if (value && Array.isArray(value) && typeof value[0] === "string") {
|
|
431
446
|
return value.join(", ");
|
|
432
447
|
}
|