bpm-core 0.0.127 → 0.0.129

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.
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Logger = void 0;
30
+ exports.runCommand = runCommand;
31
+ exports.parseEnv = parseEnv;
32
+ const child_process_1 = require("child_process");
33
+ const chalk_1 = __importDefault(require("chalk"));
34
+ const readline = __importStar(require("readline"));
35
+ function runCommand(command, pathToRunIn) {
36
+ return new Promise((resolve, reject) => {
37
+ const child = (0, child_process_1.spawn)(command, {
38
+ stdio: ['inherit', 'pipe', 'pipe'],
39
+ shell: true,
40
+ cwd: pathToRunIn
41
+ });
42
+ let stderrData = '';
43
+ let stdoutData = '';
44
+ child.stdout && child.stdout.on('data', data => {
45
+ stdoutData += data.toString();
46
+ });
47
+ child.stderr && child.stderr.on('data', (data) => {
48
+ stderrData += data.toString();
49
+ });
50
+ child.on('exit', function (code, signal) {
51
+ const isBundleExceededError = stderrData.includes('bundle initial exceeded maximum budget');
52
+ if (code === 0 || isBundleExceededError) {
53
+ resolve();
54
+ }
55
+ else {
56
+ reject(new Error(`Failed to run command "${command}" on path "${pathToRunIn}"`, { cause: stderrData }));
57
+ }
58
+ });
59
+ child.on('error', (err) => {
60
+ reject(new Error(`Failed to run command "${command}" on path "${pathToRunIn}"`, { cause: stderrData }));
61
+ });
62
+ });
63
+ }
64
+ function parseEnv(env) {
65
+ const allEnvs = ['dev', 'sit', 'bat'];
66
+ if (typeof env === 'string' && allEnvs.includes(env.toLowerCase())) {
67
+ return env.toLowerCase();
68
+ }
69
+ throw new Error(`Invalid environment: ${env}. Valid options are: ${allEnvs.join(', ')}.`);
70
+ }
71
+ class Logger {
72
+ loading(msg) {
73
+ this.currentLoadingMsg = msg;
74
+ const spinnerChars = ['|', '/', '-', '\\'];
75
+ let current = 0;
76
+ this.intervalId = setInterval(() => {
77
+ process.stdout.write(`\r${spinnerChars[current]} ${chalk_1.default.yellow(msg)}`);
78
+ current = (current + 1) % spinnerChars.length;
79
+ }, 100);
80
+ }
81
+ log(msg, useDefaultColor = true) {
82
+ this.stopLoading();
83
+ console.log(useDefaultColor ? chalk_1.default.dim(msg) : msg);
84
+ this.loading(this.currentLoadingMsg);
85
+ }
86
+ success(msg) {
87
+ this.stopLoading();
88
+ process.stdout.write(`${chalk_1.default.bold.green('✔ ' + msg)}\n`);
89
+ }
90
+ error(msg) {
91
+ this.stopLoading();
92
+ process.stdout.write(`${chalk_1.default.bold.red('X ' + msg)}\n`);
93
+ }
94
+ asyncLog(loadingMsg) {
95
+ this.loading(loadingMsg);
96
+ return async (promise, successMsg, failedMsg) => {
97
+ try {
98
+ await promise;
99
+ this.success(successMsg);
100
+ }
101
+ catch (err) {
102
+ this.error(failedMsg);
103
+ throw err;
104
+ }
105
+ };
106
+ }
107
+ stopLoading() {
108
+ readline.clearLine(process.stdout, 0);
109
+ readline.cursorTo(process.stdout, 0);
110
+ if (this.intervalId)
111
+ clearInterval(this.intervalId);
112
+ }
113
+ }
114
+ exports.Logger = Logger;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCommand = void 0;
4
+ const commander_1 = require("commander");
5
+ const mock_1 = require("./mock");
6
+ exports.generateCommand = new commander_1.Command('generate');
7
+ exports.generateCommand.alias('g');
8
+ exports.generateCommand.addCommand(mock_1.generateMockDataCommand);
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ControlNode = exports.GroupNode = void 0;
4
+ const lov_1 = require("./lov");
5
+ const randomNumber = () => Math.floor(Math.random() * 100);
6
+ const CONTROL_MOCK_MAP = {
7
+ 'app-input': () => `Sample text ${randomNumber()}`,
8
+ 'app-textarea': () => `Multiline ${randomNumber()}\nText ${randomNumber()}\nHere ${randomNumber()}`,
9
+ 'app-datepicker': () => new Date().toISOString(),
10
+ 'app-input-number': () => randomNumber().toString(),
11
+ 'app-custom-searchable': (control) => {
12
+ const lovName = control.options?.options?.match(/lov\??\.(?<lovName>\w+?)\??\.options/)?.groups?.lovName || control.name;
13
+ return (0, lov_1.getLOVFieldValue)(lovName);
14
+ },
15
+ 'app-checkbox': () => "false",
16
+ 'app-search-employee': () => ({
17
+ "personName": "Jehad Saleh A Alluhayd",
18
+ "personEmail": "jsalluhayd@stc.com.sa"
19
+ }),
20
+ 'app-file-uploader': (control) => {
21
+ const attachment = () => ({
22
+ "fileName": `ajm_location_issue_${randomNumber()}.png`,
23
+ "attachmentId": `b7d2915d-930e-4e93-930e-3675a5959ba8${randomNumber()}`,
24
+ "mimeType": "image\/png"
25
+ });
26
+ control.options?.multiple === 'true' ? [attachment(), attachment()] : attachment();
27
+ },
28
+ 'app-input-currency': () => '123' + randomNumber().toString(),
29
+ 'app-attachment-section': () => {
30
+ const attachment = () => ({
31
+ "fileDescription": "desc " + randomNumber(),
32
+ "attachmentcomment": "comm " + randomNumber(),
33
+ "fileComments": "comm " + randomNumber(),
34
+ "fileName": `dummy_${randomNumber()}.pdf`,
35
+ "attachmentId": "idd_40910B7B-0000-CE16-BD92-EC800D2FDFC6" + randomNumber(),
36
+ "mimeType": "application/pdf"
37
+ });
38
+ return [attachment(), attachment()];
39
+ },
40
+ 'app-radio': (control) => {
41
+ const lovName = control.options?.options?.match(/lov\??\.(?<lovName>\w+?)\??\.options/)?.groups?.lovName || control.name;
42
+ return (0, lov_1.getLOVFieldValue)(lovName);
43
+ },
44
+ };
45
+ class FormNode {
46
+ }
47
+ class GroupNode extends FormNode {
48
+ constructor(name, children = {}) {
49
+ super();
50
+ this.name = name;
51
+ this.children = children;
52
+ }
53
+ getValue() {
54
+ const output = {};
55
+ for (const key in this.children) {
56
+ output[key] = this.children[key].getValue();
57
+ }
58
+ return output;
59
+ }
60
+ addChild(child) {
61
+ this.children[child.name] = child;
62
+ }
63
+ }
64
+ exports.GroupNode = GroupNode;
65
+ class ControlNode extends FormNode {
66
+ constructor(name, tag, options) {
67
+ super();
68
+ this.name = name;
69
+ this.tag = tag;
70
+ this.options = options;
71
+ }
72
+ getValue() {
73
+ const generator = CONTROL_MOCK_MAP[this.tag] || (() => 'Unknown');
74
+ return generator(this);
75
+ }
76
+ }
77
+ exports.ControlNode = ControlNode;
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.generateMockDataCommand = void 0;
27
+ const fs = __importStar(require("fs"));
28
+ const path = __importStar(require("path"));
29
+ const cheerio = __importStar(require("cheerio"));
30
+ const commander_1 = require("commander");
31
+ const form_node_1 = require("./form-node");
32
+ const lov_1 = require("./lov");
33
+ exports.generateMockDataCommand = new commander_1.Command('mock');
34
+ exports.generateMockDataCommand.alias('m');
35
+ exports.generateMockDataCommand.action((options) => {
36
+ main();
37
+ });
38
+ const projectRoot = process.cwd();
39
+ const serviceName = path.basename(projectRoot);
40
+ const configDir = path.join(projectRoot, 'src', 'app', 'config');
41
+ const configFile = path.join(configDir, 'segment-dynamic-loader.config.ts');
42
+ function extractComponentPaths(configContent) {
43
+ const importRegex = /import\s*{\s*(?<name>\w+)\s*}\s+from\s+['"](?<path>.+?)['"]/g;
44
+ const imports = [...configContent.matchAll(importRegex)].reduce((prev, curr) => {
45
+ prev.push(curr.groups);
46
+ return prev;
47
+ }, []);
48
+ const exportRegex = /roleToApprovalSectionMapping\s*:\s*{([^}]+)}/s;
49
+ const exportMatch = configContent.match(exportRegex);
50
+ const body = exportMatch[1];
51
+ const usageRegex = /\s*(?<role>\w+)\s*:\s*(?<name>\w+)/g;
52
+ const roleToCompClassName = [...body.matchAll(usageRegex)].reduce((prev, curr) => {
53
+ prev.push(curr.groups);
54
+ return prev;
55
+ }, []);
56
+ const roleToRealCompPath = roleToCompClassName.reduce((prev, curr) => {
57
+ const importPathInConfigFile = imports.find((imp) => imp.name === curr.name).path;
58
+ const realPath = path.join(configDir, importPathInConfigFile + '.ts');
59
+ prev.push({ role: curr.role, path: realPath });
60
+ return prev;
61
+ }, []);
62
+ return roleToRealCompPath;
63
+ }
64
+ function getTemplatePath(componentTsPath) {
65
+ if (!fs.existsSync(componentTsPath))
66
+ return null;
67
+ const content = fs.readFileSync(componentTsPath, 'utf-8');
68
+ const match = content.match(/templateUrl\s*:\s*['"](.+?)['"]/);
69
+ if (!match)
70
+ return null;
71
+ return path.resolve(path.dirname(componentTsPath), match[1]);
72
+ }
73
+ function parseAttributesWithoutBinding(attributes) {
74
+ const attrAsString = JSON.stringify(attributes);
75
+ const output = [...attrAsString.matchAll(/"\[?(?<name>[^"]+?)\]?"\s*?:\s*?"(?<value>[^"]+?)"/g)].reduce((prev, curr) => {
76
+ prev[curr.groups.name] = curr.groups.value;
77
+ return prev;
78
+ }, {});
79
+ return output;
80
+ }
81
+ function parseFormControls($, $el, groupNode) {
82
+ $el.children().each((_, child) => {
83
+ const tagName = child.tagName.toLowerCase();
84
+ const formGroup = child.attribs?.formgroupname;
85
+ const formControl = child.attribs?.formcontrolname;
86
+ if (formGroup) {
87
+ const childGroup = new form_node_1.GroupNode(formGroup);
88
+ groupNode.addChild(childGroup);
89
+ parseFormControls($, $(child), childGroup);
90
+ }
91
+ if (formControl) {
92
+ const options = parseAttributesWithoutBinding(child.attribs);
93
+ groupNode.addChild(new form_node_1.ControlNode(formControl, tagName, options));
94
+ }
95
+ });
96
+ return groupNode;
97
+ }
98
+ function getTemplateMockData(templatePath) {
99
+ if (!fs.existsSync(templatePath)) {
100
+ throw new Error(`Template not found: ${templatePath}`);
101
+ }
102
+ const html = fs.readFileSync(templatePath, 'utf-8');
103
+ const $ = cheerio.load(html);
104
+ const $form = $('form');
105
+ const controlsTree = parseFormControls($, $form, new form_node_1.GroupNode(''));
106
+ return controlsTree.getValue();
107
+ }
108
+ function buildPayloadWithMockData(roleToStageMockMap, requestMock) {
109
+ const workflowSteps = Object.entries(roleToStageMockMap).map(([role, stageMock]) => {
110
+ return {
111
+ "actor": {
112
+ "delegate": null,
113
+ "recipient": {
114
+ "role": role.toUpperCase(),
115
+ "name": "Sami Sulaiman M Alfayez",
116
+ "shortName": null,
117
+ "email": "sfayez@stc.com.sa",
118
+ "employeeNumber": null
119
+ },
120
+ "email": "sfayez@stc.com.sa",
121
+ "status": "COMPLETED"
122
+ },
123
+ "date": "2025-07-31T13:11:28.584+03:00",
124
+ "details": {
125
+ ...stageMock,
126
+ "decision": {
127
+ "value": "Pending",
128
+ "key": "PENDING"
129
+ }
130
+ }
131
+ };
132
+ });
133
+ const output = {
134
+ "data": {
135
+ "requester": {
136
+ "departmentName": "Enterprise HR Business Partner Section_Private",
137
+ "directManagerName": "Hissah Ibrahim M Bin Zuayr",
138
+ "generalDepartmentName": "",
139
+ "generalDepartmentCode": "",
140
+ "onBehalfAuthorized": "false",
141
+ "employeeEmail": "iimran@stc.com.sa",
142
+ "fullName": "Ibrahim A. Alimran",
143
+ "employeeId": "",
144
+ "sectorName": "",
145
+ "seniorSectorName": "",
146
+ "humanResourceLocation": "",
147
+ "jobPosition": "",
148
+ "nationality": "",
149
+ "businessPhone": "966555008873"
150
+ },
151
+ workflowSteps,
152
+ "request": {
153
+ "details": requestMock
154
+ },
155
+ "form": {
156
+ "formId": `${serviceName.toUpperCase()}5000015`,
157
+ "currentActor": {
158
+ "name": "Ibrahim Ahmed M Alimran",
159
+ "email": "iimran@stc.com.sa"
160
+ },
161
+ "formName": serviceName.toUpperCase(),
162
+ "formStatus": {
163
+ "value": "Pending",
164
+ "key": "PENDING"
165
+ },
166
+ "readOnly": "false",
167
+ "formStep": workflowSteps[workflowSteps.length - 1].actor.recipient.role,
168
+ "creationDate": "2025-07-28T20:13:11.650+03:00"
169
+ }
170
+ },
171
+ "meta": {
172
+ "decision": {
173
+ "options": [
174
+ {
175
+ "description": "Submit to Account manager",
176
+ "value": "SUBMIT_TO_ACCOUNT_MANAGER",
177
+ },
178
+ {
179
+ "description": "Send Back",
180
+ "value": "SENDBACK",
181
+ }
182
+ ],
183
+ "type": "button"
184
+ },
185
+ ...(0, lov_1.getLOVs)()
186
+ }
187
+ };
188
+ return output;
189
+ }
190
+ function main() {
191
+ if (!fs.existsSync(configFile)) {
192
+ throw new Error(`Config file not found: ${configFile}`);
193
+ }
194
+ const configContent = fs.readFileSync(configFile, 'utf-8');
195
+ const componentPaths = extractComponentPaths(configContent);
196
+ const stageMocks = {};
197
+ for (const { role, path: tsPath } of componentPaths) {
198
+ const templatePath = getTemplatePath(tsPath);
199
+ stageMocks[role] = getTemplateMockData(templatePath);
200
+ }
201
+ const requestTemplatePath = path.join(projectRoot, '/src/app/page-components/request-details-section/request-details-section.component.html');
202
+ const requestMock = getTemplateMockData(requestTemplatePath);
203
+ const payload = buildPayloadWithMockData(stageMocks, requestMock);
204
+ const outputPath = projectRoot + '/mock-output.json';
205
+ fs.writeFileSync(outputPath, JSON.stringify(payload, null, 2), 'utf-8');
206
+ console.log(`Mock data written to: ${outputPath}`);
207
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLOVFieldValue = getLOVFieldValue;
4
+ exports.getLOVs = getLOVs;
5
+ const lovs = {};
6
+ function getLOVFieldValue(lovName) {
7
+ if (!lovs[lovName]) {
8
+ const randomNumber = () => Math.floor(Math.random() * 100);
9
+ lovs[lovName] = {
10
+ type: 'combo',
11
+ options: Array.from({ length: 5 }).map((_, index) => ({ description: `Op_${index + 1} ${randomNumber()}`, value: (index + 1).toString() }))
12
+ };
13
+ }
14
+ return { key: lovs[lovName].options[0].value, value: lovs[lovName].options[0].description };
15
+ }
16
+ function getLOVs() {
17
+ return lovs;
18
+ }
package/cli/index.js ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commander_1 = require("commander");
5
+ const deploy_1 = require("./deploy");
6
+ const generate_1 = require("./generate");
7
+ const program = new commander_1.Command();
8
+ program
9
+ .name("bpm-core")
10
+ .description("BPM Core CLI tool.")
11
+ .version("1.0.0");
12
+ program.addCommand(deploy_1.deployCommand);
13
+ program.addCommand(generate_1.generateCommand);
14
+ program.parse(process.argv);