bajo-extra 2.0.0 → 2.2.0

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.
Files changed (49) hide show
  1. package/.github/FUNDING.yml +13 -0
  2. package/.github/workflows/repo-lockdown.yml +24 -0
  3. package/.jsdoc.conf.json +42 -0
  4. package/LICENSE +1 -1
  5. package/README.md +32 -6
  6. package/docs/BajoExtra.html +3 -0
  7. package/docs/data/search.json +1 -0
  8. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  9. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  10. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  11. package/docs/global.html +3 -0
  12. package/docs/index.html +3 -0
  13. package/docs/index.js.html +406 -0
  14. package/docs/scripts/core.js +725 -0
  15. package/docs/scripts/core.min.js +23 -0
  16. package/docs/scripts/resize.js +90 -0
  17. package/docs/scripts/search.js +265 -0
  18. package/docs/scripts/search.min.js +6 -0
  19. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  20. package/docs/scripts/third-party/fuse.js +9 -0
  21. package/docs/scripts/third-party/hljs-line-num-original.js +366 -0
  22. package/docs/scripts/third-party/hljs-line-num.js +1 -0
  23. package/docs/scripts/third-party/hljs-original.js +5164 -0
  24. package/docs/scripts/third-party/hljs.js +1 -0
  25. package/docs/scripts/third-party/popper.js +5 -0
  26. package/docs/scripts/third-party/tippy.js +1 -0
  27. package/docs/scripts/third-party/tocbot.js +671 -0
  28. package/docs/scripts/third-party/tocbot.min.js +1 -0
  29. package/docs/static/bitcoin.jpeg +0 -0
  30. package/docs/static/home.md +23 -0
  31. package/docs/static/logo-ecosystem.png +0 -0
  32. package/docs/static/logo.png +0 -0
  33. package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
  34. package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
  35. package/docs/styles/clean-jsdoc-theme-light.css +482 -0
  36. package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  37. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  38. package/docs/styles/clean-jsdoc-theme.min.css +1 -0
  39. package/extend/bajo/intl/en-US.json +0 -0
  40. package/extend/bajo/intl/id.json +0 -0
  41. package/extend/bajoCli/applet/download.js +2 -2
  42. package/extend/bajoCli/applet/hash.js +0 -0
  43. package/extend/bajoCli/applet.js +0 -0
  44. package/index.js +37 -18
  45. package/package.json +48 -42
  46. package/wiki/CHANGES.md +5 -0
  47. package/wiki/CONFIG.md +3 -0
  48. package/wiki/CONTRIBUTING.md +5 -0
  49. package/wiki/toc.json +5 -0
package/index.js CHANGED
@@ -1,17 +1,14 @@
1
- import bcrypt from 'bcrypt'
2
1
  import crypto from 'crypto'
3
2
  import { createGzip, createGunzip } from 'zlib'
4
3
  import path from 'path'
5
- import { fetch, Agent } from 'undici'
6
4
  import { Readable } from 'stream'
7
5
  import numbro from 'numbro'
8
- import { ShortCrypt } from 'short-crypt'
9
6
 
10
7
  async function fetching ({ url, opts, bulk, spin }) {
11
8
  const { setImmediate, print } = this.app.bajo
12
- const { isEmpty, isFunction, has } = this.lib._
9
+ const { isEmpty, isFunction, has } = this.app.lib._
13
10
  const { validationErrorMessage } = this.app.bajoDb
14
- const resp = await this.fetch(url, opts ?? {})
11
+ const resp = await this.fetchUrl(url, opts ?? {})
15
12
  if (isEmpty(resp)) {
16
13
  spin.fatal('noServerResponse')
17
14
  return -1
@@ -57,7 +54,7 @@ async function fetching ({ url, opts, bulk, spin }) {
57
54
  }
58
55
 
59
56
  async function handler (rec, bulk) {
60
- const { isFunction, set } = this.lib._
57
+ const { isFunction, set } = this.app.lib._
61
58
  const { recordCreate, recordFind, recordUpdate } = this.app.bajoDb
62
59
  const save = bulk.save ?? {}
63
60
  const current = save.current ?? {}
@@ -108,13 +105,23 @@ async function handler (rec, bulk) {
108
105
  return method
109
106
  }
110
107
 
108
+ /**
109
+ * Plugin factory
110
+ *
111
+ * @param {string} pkgName - NPM package name
112
+ * @returns {class}
113
+ */
111
114
  async function factory (pkgName) {
112
115
  const me = this
113
116
 
114
- return class BajoExtra extends this.lib.Plugin {
117
+ /**
118
+ * BajoExtra class
119
+ *
120
+ * @class
121
+ */
122
+ class BajoExtra extends this.app.baseClass.Base {
115
123
  constructor () {
116
124
  super(pkgName, me.app)
117
- this.alias = 'extra'
118
125
  this.config = {
119
126
  secret: 'hxKY8Eh63Op9js6ovU25qmq2DmCE9dIB',
120
127
  fetch: {
@@ -155,7 +162,7 @@ async function factory (pkgName) {
155
162
 
156
163
  // taken from: https://stackoverflow.com/a/41439945
157
164
  countFileLines = async (file) => {
158
- const { fs } = this.lib
165
+ const { fs } = this.app.lib
159
166
  return new Promise((resolve, reject) => {
160
167
  let lineCount = 0
161
168
  fs.createReadStream(file)
@@ -175,9 +182,11 @@ async function factory (pkgName) {
175
182
  }
176
183
 
177
184
  download = async (url, opts = {}, extra = {}) => {
178
- const { getPluginDataDir, importPkg, generateId } = this.app.bajo
179
- const { fs } = this.lib
180
- const { isFunction, merge } = this.lib._
185
+ const { getPluginDataDir, importPkg } = this.app.bajo
186
+ const { generateId } = this.app.lib.aneka
187
+ const { fetch } = await importPkg('bajoExtra:undici')
188
+ const { fs } = this.app.lib
189
+ const { isFunction, merge } = this.app.lib._
181
190
  if (typeof opts === 'string') extra = { dir: opts }
182
191
  const increment = await importPkg('bajo:add-filename-increment')
183
192
  if (!extra.dir) {
@@ -254,9 +263,11 @@ async function factory (pkgName) {
254
263
  }
255
264
 
256
265
  fetchUrl = async (url, opts = {}, extra = {}) => {
257
- const { isSet } = this.lib.aneka
258
- const { fs } = this.lib
259
- const { isEmpty, has, isArray, isPlainObject, isString, cloneDeep, merge } = this.lib._
266
+ const { importPkg } = this.app.bajo
267
+ const { fetch, Agent } = await importPkg('bajoExtra:undici')
268
+ const { isSet } = this.app.lib.aneka
269
+ const { fs } = this.app.lib
270
+ const { isEmpty, has, isArray, isPlainObject, isString, cloneDeep, merge } = this.app.lib._
260
271
  if (isPlainObject(url)) {
261
272
  extra = cloneDeep(opts)
262
273
  opts = cloneDeep(url)
@@ -311,7 +322,7 @@ async function factory (pkgName) {
311
322
  }
312
323
 
313
324
  gzip = async (file, deleteOld, expand) => {
314
- const { fs } = this.lib
325
+ const { fs } = this.app.lib
315
326
  return new Promise((resolve, reject) => {
316
327
  const newFile = expand ? file.slice(0, file.length - 3) : (file + '.gz')
317
328
  const reader = fs.createReadStream(file)
@@ -328,6 +339,8 @@ async function factory (pkgName) {
328
339
  }
329
340
 
330
341
  hash = async (text, type = 'md5', options = {}) => {
342
+ const { importPkg } = this.app.bajo
343
+ const bcrypt = await importPkg('bajoExtra:bcrypt')
331
344
  options.digest = options.digest ?? 'hex'
332
345
  options.salt = options.hash ?? 10
333
346
  if (typeof text !== 'string') text = JSON.stringify(text)
@@ -349,6 +362,8 @@ async function factory (pkgName) {
349
362
  }
350
363
 
351
364
  encrypt = async (text, { type = 'short', subType = 'qr' } = {}) => {
365
+ const { importPkg } = this.app.bajo
366
+ const { ShortCrypt } = await importPkg('bajoExtra:short-crypt')
352
367
  const short = (item) => {
353
368
  const sc = new ShortCrypt(this.config.secret)
354
369
  const method = subType === 'qr' ? 'encryptToQRCodeAlphanumeric' : 'encryptToURLComponent'
@@ -357,10 +372,12 @@ async function factory (pkgName) {
357
372
  switch (type) {
358
373
  case 'short': return short(text)
359
374
  }
360
- throw this.error('invalid%s%s', this.print.write('encryption type'), type)
375
+ throw this.error('invalid%s%s', this.t('encryption type'), type)
361
376
  }
362
377
 
363
378
  decrypt = async (cipher, { type = 'short', subType = 'qr' } = {}) => {
379
+ const { importPkg } = this.app.bajo
380
+ const { ShortCrypt } = await importPkg('bajoExtra:short-crypt')
364
381
  const short = (item) => {
365
382
  const sc = new ShortCrypt(this.config.secret)
366
383
  const method = subType === 'qr' ? 'decryptToQRCodeAlphanumeric' : 'decryptToURLComponent'
@@ -369,7 +386,7 @@ async function factory (pkgName) {
369
386
  switch (type) {
370
387
  case 'short': return short(cipher)
371
388
  }
372
- throw this.error('invalid%s%s', this.print.write('decryption type'), type)
389
+ throw this.error('invalid%s%s', this.t('decryption type'), type)
373
390
  }
374
391
 
375
392
  randomRange = (min, max, alpha) => {
@@ -378,6 +395,8 @@ async function factory (pkgName) {
378
395
  return String.fromCharCode(96 + num)
379
396
  }
380
397
  }
398
+
399
+ return BajoExtra
381
400
  }
382
401
 
383
402
  export default factory
package/package.json CHANGED
@@ -1,42 +1,48 @@
1
- {
2
- "name": "bajo-extra",
3
- "version": "2.0.0",
4
- "description": "Extra package for Bajo Framework",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "type": "module",
10
- "bajo": {
11
- "type": "plugin"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/ardhi/bajo-extra.git"
16
- },
17
- "keywords": [
18
- "bajo",
19
- "extra",
20
- "nodejs",
21
- "modular",
22
- "module",
23
- "package"
24
- ],
25
- "author": "Ardhi Lukianto <ardhi@lukianto.com>",
26
- "license": "MIT",
27
- "bugs": {
28
- "url": "https://github.com/ardhi/bajo-extra/issues"
29
- },
30
- "homepage": "https://github.com/ardhi/bajo-extra#readme",
31
- "dependencies": {
32
- "async": "^3.2.6",
33
- "bcrypt": "^5.1.1",
34
- "cheerio": "^1.1.0",
35
- "fast-jwt": "^5.0.2",
36
- "fast-xml-parser": "^4.5.1",
37
- "numbro": "^2.5.0",
38
- "performant-array-to-tree": "^1.11.0",
39
- "short-crypt": "^4.0.0",
40
- "undici": "^7.2.1"
41
- }
42
- }
1
+ {
2
+ "name": "bajo-extra",
3
+ "version": "2.2.0",
4
+ "description": "Extra package for Bajo Framework",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "build-doc": "jsdoc -c .jsdoc.conf.json",
8
+ "test": "mocha"
9
+ },
10
+ "type": "module",
11
+ "bajo": {
12
+ "type": "plugin",
13
+ "alias": "extra"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/ardhi/bajo-extra.git"
18
+ },
19
+ "keywords": [
20
+ "bajo",
21
+ "extra",
22
+ "nodejs",
23
+ "modular",
24
+ "module",
25
+ "package"
26
+ ],
27
+ "author": "Ardhi Lukianto <ardhi@lukianto.com>",
28
+ "license": "MIT",
29
+ "bugs": {
30
+ "url": "https://github.com/ardhi/bajo-extra/issues"
31
+ },
32
+ "homepage": "https://github.com/ardhi/bajo-extra#readme",
33
+ "dependencies": {
34
+ "async": "^3.2.6",
35
+ "bcrypt": "^6.0.0",
36
+ "cheerio": "^1.1.2",
37
+ "fast-jwt": "^6.1.0",
38
+ "fast-xml-parser": "^5.3.3",
39
+ "numbro": "^2.5.0",
40
+ "performant-array-to-tree": "^1.11.0",
41
+ "short-crypt": "^4.0.0",
42
+ "undici": "^7.16.0"
43
+ },
44
+ "devDependencies": {
45
+ "clean-jsdoc-theme": "^4.3.0",
46
+ "jsdoc-plugin-intersection": "^1.0.4"
47
+ }
48
+ }
@@ -0,0 +1,5 @@
1
+ # Changes
2
+
3
+ ## 2025-12-28
4
+
5
+ - [2.1.0] Ported to ```bajo@2.2.x``` specs
package/wiki/CONFIG.md ADDED
@@ -0,0 +1,3 @@
1
+ # Config Object
2
+
3
+ TBD
@@ -0,0 +1,5 @@
1
+ # Contributing
2
+
3
+ Thanks very much to everyone who wants to join as a contributor, but I have committed to devoting 100% of my time to this project. Therefore, I'm currently unable to accept pull requests from anyone until the project is large enough for me to manage it independently.
4
+
5
+ However, I am available if you encounter any bugs that require immediate fixes. Please report your issues in a GitHub issue, and I'll try to address them promptly. I'm also open to criticism and suggestions for improvements or requests for new features.
package/wiki/toc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "00-config": {
3
+ "title": "Config Object"
4
+ }
5
+ }