not-node 6.5.2 → 6.5.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "6.5.2",
3
+ "version": "6.5.4",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,4 +1,26 @@
1
1
  const { ACTION_SIGNATURES } = require("../auth/const");
2
+
3
+ module.exports.rootAdmin = Object.freeze({
4
+ [ACTION_SIGNATURES.CREATE]: ["root", "admin"],
5
+ [ACTION_SIGNATURES.READ]: ["root", "admin"],
6
+ [ACTION_SIGNATURES.UPDATE]: ["root", "admin"],
7
+ [ACTION_SIGNATURES.DELETE]: ["root", "admin"],
8
+ });
9
+
10
+ module.exports.rootAdminCRUD_ownerR = Object.freeze({
11
+ [ACTION_SIGNATURES.CREATE]: ["root", "admin"],
12
+ [ACTION_SIGNATURES.READ]: ["root", "admin", "@owner"],
13
+ [ACTION_SIGNATURES.UPDATE]: ["root", "admin"],
14
+ [ACTION_SIGNATURES.DELETE]: ["root", "admin"],
15
+ });
16
+
17
+ module.exports.rootAdminCRUD_allR = Object.freeze({
18
+ [ACTION_SIGNATURES.CREATE]: ["root", "admin"],
19
+ [ACTION_SIGNATURES.READ]: ["root", "admin", "@*"],
20
+ [ACTION_SIGNATURES.UPDATE]: ["root", "admin"],
21
+ [ACTION_SIGNATURES.DELETE]: ["root", "admin"],
22
+ });
23
+
2
24
  /**
3
25
  * owner can manage own documents
4
26
  * root, admin - any own and any of client, user, guest
@@ -31,6 +53,13 @@ module.exports.systemManageable = Object.freeze({
31
53
  [ACTION_SIGNATURES.DELETE]: ["@system"],
32
54
  });
33
55
 
56
+ module.exports.systemManageableSecret = Object.freeze({
57
+ [ACTION_SIGNATURES.CREATE]: ["@system"],
58
+ [ACTION_SIGNATURES.READ]: ["@system"],
59
+ [ACTION_SIGNATURES.UPDATE]: ["@system"],
60
+ [ACTION_SIGNATURES.DELETE]: ["@system"],
61
+ });
62
+
34
63
  /**
35
64
  * anyone could read, public readable data
36
65
  */
package/src/init/index.js CHANGED
@@ -13,25 +13,59 @@ const STANDART_INIT_SEQUENCE = require("./sequence.standart.js");
13
13
 
14
14
  /**
15
15
  * @example <caption>Application initialization</caption>
16
- * let App = new notApp({
17
- * mongoose: mongooseLink
18
- * modulesCollectionPaths: [__dirname + '/modules'], //each path to folder with modules
19
- * modulesPaths: [], //each path to module
20
- * modules: {
21
- * filestore: require('not-filestore') //each npm not-* module with custom overriden name as key
22
- * }
23
- * })
24
- * .importModuleFrom(__dirname+'/anotherModule', 'anotherCustomModuleName') //import module from path
25
- * .importModulesFrom(__dirname+'/directoryOfUsefullessModules')
26
- * .importModule(require('notModule'), 'notModule')
27
- * .expose(ExpressApp);
16
+ *
17
+ * const sharp = require("sharp");
18
+ * const InitIdentityTokens = require("not-user").InitIdentityTokens;
19
+ *
20
+ * const notNode = require("not-node"),
21
+ * Init = notNode.Init,
22
+ * path = require("path"),
23
+ * manifest = require("./../../project.manifest.json")
24
+ *
25
+ * const options = {
26
+ * pathToApp: path.join(__dirname),
27
+ * pathToNPM: path.join(__dirname, "../../node_modules"),
28
+ * routesPath: path.join(__dirname, "./routes"),
29
+ * indexRoute: require("./routes/site.js").index,
30
+ * };
31
+ * //fix error on some images
32
+ * sharp.simd(false);
33
+ * notNode.Env.set("extractVariants", 1);
34
+ * const additional = {
35
+ * pre({ initSequence }) {
36
+ * initSequence.remove("InitMonitoring"); //no resource usage monitoring needed, removing initializer by its class name
37
+ * initSequence.insert(InitIdentityTokens); //initializing usage of identity tokens
38
+ * },
39
+ * };
40
+ * //starting everything
41
+ * await Init.run({ options, manifest, additional });
42
+ * //sending message to error reporting server that we restarted
43
+ * Init.notApp.reporter.report(new Error("server started"));
28
44
  **/
29
45
  class Init {
30
- static options = false;
46
+ /**
47
+ * @type {Object}
48
+ *
49
+ * @static
50
+ * @memberof Init
51
+ */
52
+ static options = null;
31
53
  static manifest = false;
32
- static config = false;
54
+ /**
55
+ * @type {Object}
56
+ *
57
+ * @static
58
+ * @memberof Init
59
+ */
60
+ static config = null;
33
61
  static mongoose = false;
34
- static notApp = false;
62
+ /**
63
+ * @type {import('../app.js')|null}
64
+ *
65
+ * @static
66
+ * @memberof Init
67
+ */
68
+ static notApp = null;
35
69
  static server = false;
36
70
  static httpServer = false;
37
71
  static WSServer = false;
@@ -107,7 +141,7 @@ class Init {
107
141
 
108
142
  static printOutManifest = () => {
109
143
  log?.debug("Manifest:");
110
- log?.debug(JSON.stringify(Init.notApp.getManifest(), null, 4));
144
+ log?.debug(JSON.stringify(Init.notApp?.getManifest(), null, 4));
111
145
  };
112
146
 
113
147
  /**
@@ -131,6 +165,7 @@ class Init {
131
165
  manifest,
132
166
  additional,
133
167
  initSequence, //giving a chance to change init sequence
168
+ log,
134
169
  });
135
170
  //setting basic resources
136
171
  Init.options = options; // pathToApp, pathToNPM
@@ -143,6 +178,7 @@ class Init {
143
178
  options, //options
144
179
  master: Init, //this class
145
180
  emit: ADDS.run.bind(ADDS),
181
+ log,
146
182
  };
147
183
  //running all prepared initalizers with current context
148
184
  await initSequence.run(context);
@@ -151,8 +187,9 @@ class Init {
151
187
  options,
152
188
  manifest,
153
189
  master: Init,
190
+ log,
154
191
  });
155
- log.info("Application initalization finished");
192
+ log?.info("Application initalization finished");
156
193
  } catch (e) {
157
194
  Init.throwError(e.message, 1);
158
195
  }
@@ -13,19 +13,19 @@ module.exports = class InitSequence {
13
13
  * Insert initalizator after and before specified modules or at the end
14
14
  * @param {Object} what initializator class constructor
15
15
  * @param {Object} where specification where to insert
16
- * @param {Array.String} where.after list of constructor names of
16
+ * @param {string} where.after list of constructor names of
17
17
  * initalizators after which item should be inserted
18
- * @param {Array.String} where.before list of constructor names of
18
+ * @param {string} where.before list of constructor names of
19
19
  * initalizators before which item should be inserted
20
20
  **/
21
- insert(what, where = {}) {
21
+ insert(what, where = { after: "", before: "" }) {
22
22
  if (where && this.list.length > 0) {
23
23
  let start = -1,
24
24
  end = this.list.length;
25
- if (objHas(where, "after")) {
25
+ if (objHas(where, "after") && where.after) {
26
26
  start = this.highestPos(where.after);
27
27
  }
28
- if (objHas(where, "before")) {
28
+ if (objHas(where, "before") && where.before) {
29
29
  end = this.lowestPos(where.before);
30
30
  }
31
31
  if (start > end) {
package/src/metas.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const Auth = require("./auth"),
2
2
  notAppIdentity = require("./identity"),
3
3
  notStyler = require("./styler"),
4
- config = require("not-config").createReader();
4
+ notEnv = require("./env");
5
5
 
6
6
  function getRole(req) {
7
7
  const identity = new notAppIdentity(req);
@@ -14,7 +14,7 @@ function getRole(req) {
14
14
 
15
15
  const DEFAULT_STYLER = (req, res) => {
16
16
  const role = getRole(req);
17
- const host = config.get("fullServerName");
17
+ const host = notEnv.get("fullServerName");
18
18
  const canonical = host + req.originalUrl;
19
19
 
20
20
  return {
@@ -22,6 +22,7 @@ const DEFAULT_STYLER = (req, res) => {
22
22
  desription: res?.options?.APP_DESCRIPTION,
23
23
  canonical,
24
24
  rand: Math.random(),
25
+ env: process.env.NODE_ENV,
25
26
  host,
26
27
  role,
27
28
  authenticated: role !== Auth.DEFAULT_USER_ROLE_FOR_GUEST,
package/test/notInit.js CHANGED
@@ -158,6 +158,7 @@ describe("initialization", function () {
158
158
  "manifest",
159
159
  "additional",
160
160
  "initSequence",
161
+ "log",
161
162
  ]);
162
163
  expect(params.config).to.be.deep.equal(config);
163
164
  expect(params.options).to.be.deep.equal(options);
@@ -188,6 +189,7 @@ describe("initialization", function () {
188
189
  "manifest",
189
190
  "additional",
190
191
  "initSequence",
192
+ "log",
191
193
  ]);
192
194
  expect(params.config).to.be.deep.equal(config);
193
195
  expect(params.options).to.be.deep.equal(options);