tango-app-api-store-zone 3.1.4 → 3.1.6
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/.eslintrc.cjs
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-store-zone",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.6",
|
|
4
4
|
"description": "zone",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -13,10 +13,12 @@
|
|
|
13
13
|
"author": "praveenraj",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"aws-sdk": "^2.
|
|
16
|
+
"aws-sdk": "^2.1607.0",
|
|
17
17
|
"dotenv": "^16.4.5",
|
|
18
18
|
"express": "^4.19.2",
|
|
19
|
-
"
|
|
19
|
+
"handlebars": "^4.7.8",
|
|
20
|
+
"joi-to-swagger": "^6.2.0",
|
|
21
|
+
"mongodb": "^6.5.0",
|
|
20
22
|
"nodemon": "^3.1.0",
|
|
21
23
|
"swagger-ui-express": "^5.0.0",
|
|
22
24
|
"tango-api-schema": "^2.0.104",
|
package/script-new.js
DELETED
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
const fs = require( 'fs' );
|
|
2
|
-
const path = require( 'path' );
|
|
3
|
-
const { execSync } = require( 'child_process' );
|
|
4
|
-
// Define folder structure
|
|
5
|
-
const createProjectStructure = async ( folderName ) => {
|
|
6
|
-
const folders = [
|
|
7
|
-
`src`,
|
|
8
|
-
`src/controllers`,
|
|
9
|
-
`src/routes`,
|
|
10
|
-
`config`,
|
|
11
|
-
`config/database`,
|
|
12
|
-
`config/response`,
|
|
13
|
-
`config/env`,
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
// Create folders
|
|
17
|
-
folders.forEach( ( folder ) => {
|
|
18
|
-
const folderPath = path.join( __dirname, folder );
|
|
19
|
-
fs.mkdirSync( folderPath, { recursive: true } );
|
|
20
|
-
} );
|
|
21
|
-
|
|
22
|
-
// Create index.js file
|
|
23
|
-
const indexjsContent = `
|
|
24
|
-
|
|
25
|
-
import { ${folderName}Router } from './src/routes/${folderName}.routes.js';
|
|
26
|
-
|
|
27
|
-
export { ${folderName}Router };
|
|
28
|
-
|
|
29
|
-
`;
|
|
30
|
-
fs.writeFileSync(
|
|
31
|
-
path.join( __dirname, `/`, 'index.js' ),
|
|
32
|
-
indexjsContent,
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
// Create app.js file
|
|
36
|
-
const appContent = `
|
|
37
|
-
import express from 'express';
|
|
38
|
-
import { ${folderName}Router } from './index.js';
|
|
39
|
-
|
|
40
|
-
import dotenv from 'dotenv';
|
|
41
|
-
import { logger } from 'tango-app-api-middleware';
|
|
42
|
-
import { connectdb } from './config/database/database.js';
|
|
43
|
-
import responseMiddleware from './config/response/response.js';
|
|
44
|
-
import errorMiddleware from './config/response/error.js';
|
|
45
|
-
import pkg from 'body-parser';
|
|
46
|
-
|
|
47
|
-
const { json, urlencoded } = pkg;
|
|
48
|
-
const env=dotenv.config();
|
|
49
|
-
|
|
50
|
-
const app = express();
|
|
51
|
-
const PORT = process.env.PORT || 3000;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
app.use( json( { limit: '500mb' } ) );
|
|
55
|
-
app.use(
|
|
56
|
-
urlencoded( {
|
|
57
|
-
extended: true,
|
|
58
|
-
} ),
|
|
59
|
-
);
|
|
60
|
-
app.use( responseMiddleware );
|
|
61
|
-
app.use( errorMiddleware );
|
|
62
|
-
|
|
63
|
-
if ( env.error ) {
|
|
64
|
-
logger.error( '.env not found' );
|
|
65
|
-
process.exit( 1 );
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
app.use(\`/\${folderName}\', ${folderName}Router);
|
|
70
|
-
|
|
71
|
-
app.listen(PORT, () => {
|
|
72
|
-
logger.info(\`server is running on port= \${PORT} \`);
|
|
73
|
-
connectdb();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
`;
|
|
77
|
-
fs.writeFileSync(
|
|
78
|
-
path.join( __dirname, `/`, 'app.js' ),
|
|
79
|
-
appContent,
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
// Create route.js file
|
|
83
|
-
const appJsContent = `
|
|
84
|
-
import express from 'express';
|
|
85
|
-
|
|
86
|
-
export const ${folderName}Router = express.Router();
|
|
87
|
-
|
|
88
|
-
${folderName}Router.get('/', (req, res) => {
|
|
89
|
-
res.send('Hello, world!');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
`;
|
|
94
|
-
fs.writeFileSync(
|
|
95
|
-
path.join( __dirname, `/src/routes`, `${folderName}.routes.js` ),
|
|
96
|
-
appJsContent,
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
// Create package.json file
|
|
100
|
-
const packageJsonContent = `
|
|
101
|
-
{
|
|
102
|
-
"name": "${folderName}",
|
|
103
|
-
"version": "1.0.0",
|
|
104
|
-
"description": "${folderName}",
|
|
105
|
-
"main": "app.js",
|
|
106
|
-
"type": "module",
|
|
107
|
-
"scripts": {
|
|
108
|
-
"start": "nodemon --exec \\"eslint --fix . && node app.js\\""
|
|
109
|
-
},
|
|
110
|
-
"engines": {
|
|
111
|
-
"node": ">=18.10.0"
|
|
112
|
-
},
|
|
113
|
-
"author": "praveenraj",
|
|
114
|
-
"license": "ISC"
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
`;
|
|
118
|
-
fs.writeFileSync(
|
|
119
|
-
path.join( __dirname, 'package.json' ),
|
|
120
|
-
packageJsonContent,
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
// Create .eslintrc.js file
|
|
124
|
-
const eslintrcContent = `
|
|
125
|
-
module.exports = {
|
|
126
|
-
'env': {
|
|
127
|
-
'es2021': true,
|
|
128
|
-
'node': true,
|
|
129
|
-
},
|
|
130
|
-
'extends': 'google',
|
|
131
|
-
'overrides': [
|
|
132
|
-
{
|
|
133
|
-
'env': {
|
|
134
|
-
'node': true,
|
|
135
|
-
},
|
|
136
|
-
'files': [
|
|
137
|
-
'.eslintrc.{js,cjs}',
|
|
138
|
-
],
|
|
139
|
-
'parserOptions': {
|
|
140
|
-
'sourceType': 'script',
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
],
|
|
144
|
-
'parserOptions': {
|
|
145
|
-
'ecmaVersion': 'latest',
|
|
146
|
-
'sourceType': 'module',
|
|
147
|
-
},
|
|
148
|
-
'rules': {
|
|
149
|
-
'linebreak-style': [ 'error', 'windows' ],
|
|
150
|
-
'require-jsdoc': 'off',
|
|
151
|
-
'arrow-spacing': 'error',
|
|
152
|
-
'key-spacing': [ 'error', { 'beforeColon': false, 'afterColon': true } ],
|
|
153
|
-
'object-curly-spacing': [ 'error', 'always' ],
|
|
154
|
-
'space-in-parens': [ 'error', 'always' ],
|
|
155
|
-
'keyword-spacing': 'error',
|
|
156
|
-
'array-bracket-spacing': [ 'error', 'always' ],
|
|
157
|
-
'spaced-comment': [ 'error', 'always' ],
|
|
158
|
-
'max-len': [ 'error', { 'code': 700 } ],
|
|
159
|
-
'no-unused-vars': 'error',
|
|
160
|
-
'new-cap': [ 'error', { 'newIsCap': true, 'capIsNew': false } ],
|
|
161
|
-
'prefer-const': 'off',
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
`;
|
|
166
|
-
fs.writeFileSync(
|
|
167
|
-
path.join( __dirname, '.eslintrc.cjs' ),
|
|
168
|
-
eslintrcContent,
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
// Create .env file
|
|
172
|
-
const envContent = `
|
|
173
|
-
PORT=3001
|
|
174
|
-
AWS_ACCESS_KEY_ID=AKIAQSSPN5BZSDAZHWB2
|
|
175
|
-
AWS_SECRET_ACCESS_KEY=WkkH2+s4mPbaM48EEHP+ZZHGdkixvNsHHAgS8rMT
|
|
176
|
-
|
|
177
|
-
mongo_username= tangoeye
|
|
178
|
-
mongo_password= SUTONQosEUijJKWC
|
|
179
|
-
|
|
180
|
-
ELASTIC_CLOUD_ID=
|
|
181
|
-
ELASTIC_USERNAME=
|
|
182
|
-
ELASTIC_PASSWORD=
|
|
183
|
-
ELASTIC_NODE=
|
|
184
|
-
|
|
185
|
-
`;
|
|
186
|
-
fs.writeFileSync( path.join( __dirname, '.env' ), envContent );
|
|
187
|
-
|
|
188
|
-
// Create database.js file
|
|
189
|
-
const databaseContent = `
|
|
190
|
-
import appConfig from '../../config/env/env.js';
|
|
191
|
-
import mongoose from 'mongoose';
|
|
192
|
-
import { logger } from 'tango-app-api-middleware';
|
|
193
|
-
|
|
194
|
-
export function getConnection() {
|
|
195
|
-
appConfig.database.mongo.username = process.env.mongo_username;
|
|
196
|
-
appConfig.database.mongo.password = process.env.mongo_password;
|
|
197
|
-
|
|
198
|
-
const options = {
|
|
199
|
-
useNewUrlParser: true,
|
|
200
|
-
useUnifiedTopology: true,
|
|
201
|
-
};
|
|
202
|
-
let connectionString;
|
|
203
|
-
|
|
204
|
-
if (appConfig.database.mongo.authSource) {
|
|
205
|
-
connectionString = \`\${appConfig.database.mongo.hostname}/\${appConfig.database.mongo.name}?\${appConfig.database.mongo.authSource}\`;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (appConfig.database.mongo.username && appConfig.database.mongo.password) {
|
|
209
|
-
connectionString = \`\${appConfig.database.mongo.username}:\${appConfig.database.mongo.password}@\${appConfig.database.mongo.hostname}/\${appConfig.database.mongo.name}\`;
|
|
210
|
-
} else {
|
|
211
|
-
connectionString = \`\${appConfig.database.mongo.hostname}/\${appConfig.database.mongo.name}\`;
|
|
212
|
-
}
|
|
213
|
-
if (appConfig.database.mongo.authSource) {
|
|
214
|
-
connectionString = \`mongodb+srv://\${connectionString}\`;
|
|
215
|
-
} else {
|
|
216
|
-
connectionString = \`mongodb://\${connectionString}\`;
|
|
217
|
-
}
|
|
218
|
-
return { uri: \`\${connectionString}\`, options };
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export function connectdb() {
|
|
222
|
-
const db = getConnection();
|
|
223
|
-
// Establish Connection
|
|
224
|
-
mongoose.connect(db.uri, db.options);
|
|
225
|
-
|
|
226
|
-
// Mongoose Events
|
|
227
|
-
mongoose.connection.on('connected', () => {
|
|
228
|
-
logger.info('Mongoose connected with MongoDB: ' + new Date().toISOString());
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
// Event: Disconnected
|
|
232
|
-
mongoose.connection.on('disconnected', () => {
|
|
233
|
-
logger.log('MongoDB Connection Closed: ' + new Date().toISOString());
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
// Event: Error
|
|
237
|
-
mongoose.connection.on('error', (error) => {
|
|
238
|
-
logger.error(error);
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
`;
|
|
242
|
-
|
|
243
|
-
fs.writeFileSync(
|
|
244
|
-
path.join( __dirname, `/config/database`, `database.js` ),
|
|
245
|
-
|
|
246
|
-
databaseContent,
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
// Create logger.js file
|
|
250
|
-
// const loggerContent = `
|
|
251
|
-
// import winston from 'winston';
|
|
252
|
-
// import DailyRotateFile from 'winston-daily-rotate-file';
|
|
253
|
-
|
|
254
|
-
// export const logger = winston.createLogger( {
|
|
255
|
-
// level: 'info',
|
|
256
|
-
// format: winston.format.combine(
|
|
257
|
-
// winston.format.errors( { stack: true } ),
|
|
258
|
-
// winston.format.timestamp(),
|
|
259
|
-
// winston.format.prettyPrint(),
|
|
260
|
-
// winston.format.colorize(),
|
|
261
|
-
// ),
|
|
262
|
-
// transports: [
|
|
263
|
-
// new DailyRotateFile( {
|
|
264
|
-
// filename: \`error-%DATE%.log\`,
|
|
265
|
-
// dirname: \`storage/logs/\`,
|
|
266
|
-
// datePattern: 'YYYY-MM-DD',
|
|
267
|
-
// zippedArchive: true,
|
|
268
|
-
// maxFiles: '2d',
|
|
269
|
-
// maxSize: '2g',
|
|
270
|
-
// level: 'error',
|
|
271
|
-
// } ),
|
|
272
|
-
// new DailyRotateFile( {
|
|
273
|
-
// filename: \`application-%DATE%.log\`,
|
|
274
|
-
// dirname: \`storage/logs/\`,
|
|
275
|
-
// datePattern: 'YYYY-MM-DD',
|
|
276
|
-
// zippedArchive: true,
|
|
277
|
-
// maxFiles: '2d',
|
|
278
|
-
// maxSize: '2g',
|
|
279
|
-
// } ),
|
|
280
|
-
// ],
|
|
281
|
-
// } );
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
// `;
|
|
285
|
-
// fs.writeFileSync(
|
|
286
|
-
// path.join( __dirname, `/config/logger`, `logger.js` ),
|
|
287
|
-
|
|
288
|
-
// loggerContent,
|
|
289
|
-
// );
|
|
290
|
-
// console.log( `Folder structure for ${folderName} created successfully.` );
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
// Create database.js file
|
|
294
|
-
const envjsContent = `
|
|
295
|
-
const appConfig = {
|
|
296
|
-
app: {
|
|
297
|
-
environment: 'development',
|
|
298
|
-
},
|
|
299
|
-
api: {
|
|
300
|
-
version: [ 'v3' ],
|
|
301
|
-
},
|
|
302
|
-
url: {
|
|
303
|
-
admin: '',
|
|
304
|
-
audit: '',
|
|
305
|
-
},
|
|
306
|
-
database: {
|
|
307
|
-
mongo: {
|
|
308
|
-
hostname: 'serverlessinstance-1.o0iqto1.mongodb.net',
|
|
309
|
-
name: 'tango-api-uat',
|
|
310
|
-
},
|
|
311
|
-
postgre: {},
|
|
312
|
-
},
|
|
313
|
-
cloud: {
|
|
314
|
-
aws: {
|
|
315
|
-
region: 'ap-south-1',
|
|
316
|
-
secertManager: 'tango-api-dev',
|
|
317
|
-
sqs: {
|
|
318
|
-
url: '',
|
|
319
|
-
},
|
|
320
|
-
bucket: {
|
|
321
|
-
name: '',
|
|
322
|
-
},
|
|
323
|
-
version: 'v4',
|
|
324
|
-
},
|
|
325
|
-
elasticSearch: {
|
|
326
|
-
cloud: {
|
|
327
|
-
id: process.env.ELASTIC_CLOUD_ID,
|
|
328
|
-
},
|
|
329
|
-
auth: {
|
|
330
|
-
username: process.env.ELASTIC_USERNAME,
|
|
331
|
-
password: process.env.ELASTIC_PASSWORD,
|
|
332
|
-
},
|
|
333
|
-
// node: process.env.ELASTIC_NODE,
|
|
334
|
-
},
|
|
335
|
-
},
|
|
336
|
-
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
export default appConfig;
|
|
340
|
-
|
|
341
|
-
`;
|
|
342
|
-
|
|
343
|
-
fs.writeFileSync(
|
|
344
|
-
path.join( __dirname, `/config/env`, `env.js` ),
|
|
345
|
-
envjsContent,
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
// Install specific dependencies
|
|
349
|
-
console.log( 'Installing dependencies...', {
|
|
350
|
-
cwd: path.join( __dirname ),
|
|
351
|
-
} );
|
|
352
|
-
try {
|
|
353
|
-
const gitignoreContent = [
|
|
354
|
-
'node_modules/',
|
|
355
|
-
'package-lock.json',
|
|
356
|
-
'storage/',
|
|
357
|
-
'config/',
|
|
358
|
-
'app.js',
|
|
359
|
-
'.env',
|
|
360
|
-
].join( '\r\n' ); // Use Windows-style line endings
|
|
361
|
-
|
|
362
|
-
// Write content to .gitignore
|
|
363
|
-
fs.writeFileSync( path.join( __dirname, '.gitignore' ), gitignoreContent );
|
|
364
|
-
|
|
365
|
-
// Install npm dependencies
|
|
366
|
-
const npmCommand = 'npm install express mongodb aws-sdk nodemon tango-api-schema tango-app-api-middleware winston winston-daily-rotate-file dotenv';
|
|
367
|
-
execSync( npmCommand, { cwd: path.join( __dirname ), stdio: 'inherit' } );
|
|
368
|
-
|
|
369
|
-
console.log( 'Dependencies installed successfully.' );
|
|
370
|
-
} catch ( error ) {
|
|
371
|
-
console.error( 'Error occurred while installing dependencies:', error );
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// Install specific dependencies as devDependencies
|
|
375
|
-
console.log( 'Installing devDependencies...' );
|
|
376
|
-
try {
|
|
377
|
-
await execSync(
|
|
378
|
-
' npm install --save-dev eslint eslint-config-google eslint-config-semistandard eslint-config-standard eslint-plugin-import eslint-plugin-promise',
|
|
379
|
-
{ cwd: path.join( __dirname ) },
|
|
380
|
-
);
|
|
381
|
-
console.log( 'devDependencies installed successfully.' );
|
|
382
|
-
} catch ( error ) {
|
|
383
|
-
console.error( 'Error occurred while installing devDependencies:', error );
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
// Usage: node createProjectStructure.js myapi
|
|
388
|
-
createProjectStructure( process.argv[2] );
|
|
File without changes
|