mosquito-transport 1.6.2 → 1.6.3

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/README.md CHANGED
@@ -888,10 +888,10 @@ export const install = {
888
888
  };
889
889
  ```
890
890
 
891
- <!-- ## Platform using MosquitoTransport in production
892
- - [Heavenya - christian events](https://heavenya.com)
893
- - [Inspire - christian audio](https://inspire.com)
894
- - [ExamJoint - learn, study and prepare for exam](https://examjoint.com) -->
891
+ ## Platform using MosquitoTransport in production
892
+ - [ExamJoint - learn, study and prepare for exam](https://examjoint.com)
893
+ <!-- - [Heavenya - christian events](https://heavenya.com)
894
+ - [Inspire - christian audio](https://inspire.com) -->
895
895
 
896
896
  ## Contributing
897
897
 
@@ -86,7 +86,7 @@ export const ERRORS = {
86
86
  ACCOUNT_NO_PASSWORD: simplifyError('incorrect_password', 'The provided password for this account is incorrect'),
87
87
  UID_ALREADY_EXISTS: uid => simplifyError('uid_already_exists', `This userId (${uid}) for this account has already been taken`),
88
88
  ACCOUNT_DISABLED: simplifyError('account_disabled', 'You cannot sign into this account because it has been disabled'),
89
- TOKEN_MISMATCH: simplifyError('token_mismatch', 'The accessToken and refreshToken are not meant for eachother'),
89
+ TOKEN_MISMATCH: simplifyError('token_mismatch', 'The accessToken and refreshToken are not meant for each other'),
90
90
  ENTITY_MISMATCH: simplifyError('entity_mismatch', 'This accessToken does not belong to the provided refreshToken'),
91
91
  TOKEN_USER_NOT_FOUND: simplifyError('token_user_not_found', 'The user that owns this token was not found on our database records'),
92
92
  TOKEN_ACCOUNT_DISABLED: simplifyError('token_account_disabled', 'You cannot refresh token for this account because it has been disabled'),
@@ -105,5 +105,6 @@ export const ERRORS = {
105
105
  // apis
106
106
  ENCRYPTION_REQUIRED: simplifyError('encryption_required', 'All request sent to this endpoint must be encrypted'),
107
107
  UNAUTHORIZED_ACCESS: simplifyError('unauthorize_access', 'Only authorized users can access this request'),
108
- UNVERIFIED_EMAIL: simplifyError('unverified_email', 'User email is not verified, Please verify and try again')
108
+ UNVERIFIED_EMAIL: simplifyError('unverified_email', 'User email is not verified, Please verify and try again'),
109
+ DISABLED_AUTH_ACCESS: simplifyError('disabled_auth', 'This request does not accept disabled auth')
109
110
  };
package/lib/index.d.ts CHANGED
@@ -26,7 +26,12 @@ interface PureHttpRequest extends express.Request {
26
26
  }
27
27
 
28
28
  interface StorageRulesSnapshot {
29
-
29
+ headers?: IncomingHttpHeaders;
30
+ auth?: JWTAuthData | undefined;
31
+ endpoint: 'serveFile' | '_uploadFile' | '_deleteFile' | '_deleteFolder';
32
+ prescription: {
33
+ path: string;
34
+ }
30
35
  }
31
36
 
32
37
  type WriteScope = 'setOne' | 'setMany' | 'updateOne' | 'updateMany' | 'mergeOne' | 'mergeMany' | 'deleteOne' | 'deleteMany' | 'replaceOne' | 'putOne';
@@ -653,7 +658,7 @@ interface MosquitoHttpOptions {
653
658
  */
654
659
  enforceUser?: boolean;
655
660
  /**
656
- * admits all request that doesn't have a token or have a token that is valid
661
+ * admits request that doesn't have a token or have a token that is valid
657
662
  */
658
663
  validateUser?: boolean;
659
664
  /**
@@ -664,8 +669,16 @@ interface MosquitoHttpOptions {
664
669
  * disable all internal adds-on such as token validation, end-to-end encryption
665
670
  *
666
671
  * this is basically identical to calling `MtInstance.express.use((req, res, next)=> { })`
672
+ *
673
+ * @default false
667
674
  */
668
675
  rawEntry?: boolean;
676
+ /**
677
+ * `true` to accept disabled token
678
+ *
679
+ * @default false
680
+ */
681
+ allowDisabledAuth?: boolean;
669
682
  }
670
683
 
671
684
  interface DatabaseListenerOption {
package/lib/index.js CHANGED
@@ -792,6 +792,8 @@ export default class MosquitoTransportServer {
792
792
 
793
793
  if (authToken && (enforceUser || options?.validateUser)) {
794
794
  auth = await validateJWT(authToken, this.projectName);
795
+ if (!options?.allowDisabledAuth && auth.disabled)
796
+ throw ERRORS.DISABLED_AUTH_ACCESS;
795
797
  } else if (enforceUser) throw ERRORS.UNAUTHORIZED_ACCESS;
796
798
 
797
799
  if (options?.enforceVerifiedUser && !auth?.emailVerified)
@@ -1013,12 +1015,12 @@ export default class MosquitoTransportServer {
1013
1015
  if (typeof uid !== 'string' || !uid.trim()) throw 'uid requires a string value';
1014
1016
 
1015
1017
  const updateSet = Object.fromEntries(
1016
- Object.entries(metadata).map(([k, v]) =>
1018
+ Object.entries(claims).map(([k, v]) =>
1017
1019
  v !== undefined && [`claims.${k}`, v]
1018
1020
  ).filter(v => v)
1019
1021
  );
1020
1022
  const updateUnset = Object.fromEntries(
1021
- Object.entries(metadata).map(([k, v]) =>
1023
+ Object.entries(claims).map(([k, v]) =>
1022
1024
  v === undefined && [`claims.${k}`, true]
1023
1025
  ).filter(v => v)
1024
1026
  );
@@ -195,7 +195,7 @@ export const refreshToken = async ({ token, refToken }, projectName) => {
195
195
  entityOf: refAuth.tokenID
196
196
  };
197
197
 
198
- if (disabled) throw ERRORS.TOKEN_ACCOUNT_DISABLED;
198
+ // if (disabled) throw ERRORS.TOKEN_ACCOUNT_DISABLED;
199
199
 
200
200
  const tokenx = await signJWT({ ...tokenData }, projectName);
201
201
 
@@ -1,5 +1,5 @@
1
1
  import express from "express";
2
- import { niceTry, normalizeRoute } from "../../helpers/utils";
2
+ import { encodeBinary, niceTry, normalizeRoute } from "../../helpers/utils";
3
3
  import { Scoped } from "../../helpers/variables";
4
4
  import { validateJWT } from "../auth/tokenizer";
5
5
  import { EngineRoutes, ERRORS, one_mb, STORAGE_DIRS, STORAGE_ROUTE } from "../../helpers/values";
@@ -22,14 +22,17 @@ export const storageRouteName = [
22
22
  _deleteFolder
23
23
  ];
24
24
 
25
- export const storageRoutes = ({ projectName, externalAddress, logger, maxUploadBufferSize = one_mb * 1024, ddosMap, internals }) => storageRouteName.map(route =>
25
+ export const storageRoutes = ({ projectName, externalAddress, logger, maxUploadBufferSize = one_mb * 1024, ddosMap, internals, enforceE2E_Encryption }) => [
26
+ ...enforceE2E_Encryption ? [] : storageRouteName.map(v => ({ mroute: v, route: v })),
27
+ ...storageRouteName.map(v => ({ mroute: `e2e/${encodeBinary(v)}`, route: v, ugly: true }))
28
+ ].map(({ route, mroute }) =>
26
29
  express.Router({ caseSensitive: true })[
27
30
  {
28
31
  [_uploadFile]: 'post',
29
32
  [_deleteFile]: 'delete',
30
33
  [_deleteFolder]: 'delete'
31
34
  }[route] || 'get'
32
- ](`/${route}`, async (req, res) => {
35
+ ](`/${mroute}`, async (req, res) => {
33
36
  const hasLogger = logger.includes('all') || logger.includes('storage'),
34
37
  now = Date.now();
35
38
 
@@ -58,7 +61,6 @@ export const storageRoutes = ({ projectName, externalAddress, logger, maxUploadB
58
61
  const rulesObj = {
59
62
  headers: { ...req.headers },
60
63
  ...resolvedAuth ? { auth: { ...resolvedAuth, token: authToken } } : {},
61
- request: req,
62
64
  endpoint: route,
63
65
  prescription: {
64
66
  path: path || destination
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mosquito-transport",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "MosquitoTransport is a powerful tool that helps persist and synchronize data between your MongoDB database and frontend applications",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -40,7 +40,7 @@
40
40
  "buffer": "^6.0.3",
41
41
  "compression": "^1.7.4",
42
42
  "cors": "^2.8.5",
43
- "entity-serializer": "^1.0.1",
43
+ "entity-serializer": "^1.0.2",
44
44
  "express": "^4.18.2",
45
45
  "google-auth-library": "^8.8.0",
46
46
  "guard-object": "^1.1.3",