nitro-web 0.2.4 → 0.2.5

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": "nitro-web",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "repository": "github:boycce/nitro-web",
5
5
  "homepage": "https://boycce.github.io/nitro-web/",
6
6
  "description": "Nitro is a battle-tested, modular base project to turbocharge your projects, styled using Tailwind 🚀",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "peerDependencies": {
66
66
  "@stripe/stripe-js": "^1.34.0",
67
- "monastery": "^4.0.1",
67
+ "monastery": "^4.0.6",
68
68
  "stripe": "^9.16.0"
69
69
  },
70
70
  "_peers-are-packages-that-will-be-used-in-the-host-repo-too": "",
package/server/router.js CHANGED
@@ -9,7 +9,7 @@ import expressFileUpload from 'express-fileupload'
9
9
  import express from 'express'
10
10
  import bodyParser from 'body-parser'
11
11
  import sortRouteAddressesNodeps from 'sort-route-addresses-nodeps'
12
-
12
+ import { formatDuplicateKeyError } from 'monastery'
13
13
  import { sendEmail } from 'nitro-web/server'
14
14
  import * as util from 'nitro-web/util'
15
15
 
@@ -177,17 +177,6 @@ function setupErrorResponses (expressApp) {
177
177
  serverError: function(a, b) { error.call(this, a, b, 500) },
178
178
  })
179
179
 
180
- function duplicateKeyIndexAndValue(error) {
181
- // https://github.com/Automattic/mongoose/issues/2129#issuecomment-280507821
182
- // E.g. E11000 duplicate key error collection: anamata-production.person index:
183
- // email_1 dup key: { email: "person1@gmail.com" }
184
- let regex = /index: (?:.*\.)?\$?(?:([_a-z0-9]*)(?:_\d*)|([_a-z0-9]*))\s*dup key/i
185
- let match = error.message.match(regex)
186
- let index = match[1] || match[2]
187
- let value = (error.message.match(/.*{.*?: (.*) }/i)[1]||'').replace(/"/g, '')
188
- return [index, value]
189
- }
190
-
191
180
  function error(error, detail, status) {
192
181
  /**
193
182
  * Returns a formatted error
@@ -218,11 +207,15 @@ function setupErrorResponses (expressApp) {
218
207
  else errors = [{ detail: error || _detail }]
219
208
 
220
209
  // Mongo error
221
- } else if (util.isObject(error) && (error.name||'').match(/Mongo|BulkWriteError/)) {
222
- if (error.code == 11000) {
223
- let [name] = duplicateKeyIndexAndValue(error)
224
- if (name == 'email') errors = [{ title: 'email', detail: 'That email is already linked to an account.' }]
225
- else errors = [{ title: name, detail: `Cannot insert duplicate values for "${name}".` }]
210
+ } else if (util.isObject(error) && (error.name || '').match(/Mongo|BulkWriteError/)) {
211
+ // Below is thrown by Monastery if a custom message is not used, e.g. `{ ..., messages : { email: { unique: '...' } } }`
212
+ const formattedDuplicateKeyError = formatDuplicateKeyError(undefined, error)
213
+ if (formattedDuplicateKeyError) {
214
+ errors = formattedDuplicateKeyError
215
+ const hasRawMessage = errors[0].detail.includes('E11000 duplicate key')
216
+ // Add default messages if no custom message is used from definition.messages
217
+ if (hasRawMessage && errors[0].title == 'email') errors[0].detail = 'That email is already linked to an account.'
218
+ else if (hasRawMessage) errors[0].detail = `Cannot insert duplicate values for "${errors[0].title}".`
226
219
  } else {
227
220
  errors = [{ title: 'mongo', detail: error.message }]
228
221
  }
@@ -1 +1 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../server/router.js"],"names":[],"mappings":"AAoCA,uGAAuG;AACvG,0CADc,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,SAAS,EAAE,WAAW,CAAA;CAAE,CAAC,CA+HlG;AAyPD,+CAEC;AAED,kEAYC;AAzGD,+BAA+B;AAC/B,yBADW,gBAAgB,CAuF1B;sBA1YY,OAAO,CAAC,OAAO,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAoB,CAAC;CAC7B;uBACS,OAAO,CAAC,QAAQ,GAAG;IAC3B,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,MA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