session-sync-auth-site 0.5.10 → 3.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "session-sync-auth-site",
3
- "version": "0.5.10",
3
+ "version": "3.0.0",
4
4
  "main": "src/index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -47,6 +47,6 @@
47
47
  "dependencies": {
48
48
  "connection-string": "^4.3.2",
49
49
  "jsonwebtoken": "^8.5.1",
50
- "mysql": "^2.18.1"
50
+ "mysql2": "^3.16.0"
51
51
  }
52
52
  }
@@ -54,7 +54,7 @@ const authenticate = ({
54
54
  const sessionTableUserId = (sessionTableColNameMap.user_id || 'user_id').replace(/`/g, '')
55
55
  const sessionTableAccessToken = (sessionTableColNameMap.access_token || 'access_token').replace(/`/g, '')
56
56
 
57
- req.user = (await global.sessionSyncAuthSiteConnection.asyncQuery(
57
+ req.user = (await global.sessionSyncAuthSiteConnection.query(
58
58
  `
59
59
 
60
60
  SELECT
@@ -81,8 +81,10 @@ const authenticate = ({
81
81
 
82
82
  `,
83
83
  {
84
- ...extraUserTableSelectValues,
85
- accessToken,
84
+ replacements: {
85
+ ...extraUserTableSelectValues,
86
+ accessToken,
87
+ },
86
88
  },
87
89
  ))[0]
88
90
 
@@ -24,7 +24,7 @@ const setUpConnection = require('./setUpConnection')
24
24
 
25
25
  setUpConnection({ connectionStr })
26
26
 
27
- await global.sessionSyncAuthSiteConnection.asyncQuery(
27
+ await global.sessionSyncAuthSiteConnection.query(
28
28
  `
29
29
 
30
30
  CREATE TABLE \`${userTableName}\` (
@@ -49,7 +49,6 @@ const setUpConnection = require('./setUpConnection')
49
49
  ) CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
50
50
 
51
51
  `,
52
- {},
53
52
  )
54
53
 
55
54
  console.log(``)
@@ -1,34 +1,17 @@
1
- const mysql = require('mysql')
2
- const SqlString = require('mysql/lib/protocol/SqlString')
1
+ const mysql = require('mysql2/promise')
3
2
  const { ConnectionString } = require('connection-string')
4
- const util = require('util')
5
3
 
6
- const setUpConnection = ({
4
+ const setUpConnection = async ({
7
5
  connectionStr=`mysql://root@localhost/SessionSyncAuthSite`,
8
6
  connectionObj,
9
7
  }={}) => {
10
8
 
11
9
  connectionObj = connectionObj || new ConnectionString(connectionStr)
12
10
 
13
- global.sessionSyncAuthSiteConnection = mysql.createConnection({
11
+ global.sessionSyncAuthSiteConnection = await mysql.createConnection({
14
12
  multipleStatements: true,
15
13
  dateStrings: true,
16
14
  charset : 'utf8mb4',
17
- queryFormat: function (query, values) {
18
- if(!values) return query
19
-
20
- if(/\:(\w+)/.test(query)) {
21
- return query.replace(/\:(\w+)/g, (txt, key) => {
22
- if(values.hasOwnProperty(key)) {
23
- return this.escape(values[key])
24
- }
25
- return txt
26
- })
27
-
28
- } else {
29
- return SqlString.format(query, values, this.config.stringifyObjects, this.config.timezone)
30
- }
31
- },
32
15
  // debug: true,
33
16
  host: connectionObj.host || connectionObj.hosts[0].name,
34
17
  user: connectionObj.user || connectionObj.username,
@@ -37,8 +20,6 @@ const setUpConnection = ({
37
20
  port: connectionObj.port,
38
21
  })
39
22
 
40
- global.sessionSyncAuthSiteConnection.asyncQuery = util.promisify(global.sessionSyncAuthSiteConnection.query).bind(global.sessionSyncAuthSiteConnection)
41
-
42
23
  }
43
24
 
44
25
  module.exports = setUpConnection
@@ -229,9 +229,11 @@ const setUpSessionSyncAuthRoutes = ({
229
229
 
230
230
  })
231
231
 
232
- await global.sessionSyncAuthSiteConnection.asyncQuery(
232
+ await global.sessionSyncAuthSiteConnection.query(
233
233
  queries.join(';'),
234
- variables,
234
+ {
235
+ replacements: variables,
236
+ },
235
237
  )
236
238
 
237
239
  }
@@ -244,14 +246,16 @@ const setUpSessionSyncAuthRoutes = ({
244
246
  if(!id) throw "Invalid payload. Item in `payload.usersToDelete` missing `id` key."
245
247
  if(!email) throw "Invalid payload. Item in `payload.usersToDelete` missing `email` key."
246
248
 
247
- const [ userRow ] = await global.sessionSyncAuthSiteConnection.asyncQuery(
249
+ const [ userRow ] = await global.sessionSyncAuthSiteConnection.query(
248
250
  `
249
251
  SELECT \`${(userTableColNameMap.email || `email`).replace(/`/g, '')}\` AS email
250
252
  FROM \`${userTableName}\`
251
253
  WHERE \`${(userTableColNameMap.id || `id`).replace(/`/g, '')}\` = :userId
252
254
  `,
253
255
  {
254
- userId: id,
256
+ replacements: {
257
+ userId: id,
258
+ },
255
259
  },
256
260
  )
257
261
 
@@ -269,7 +273,7 @@ const setUpSessionSyncAuthRoutes = ({
269
273
  if(deleteUser) {
270
274
  await deleteUser({ id, isAfterAMerge: !!mergeToUserId, req })
271
275
  } else {
272
- await global.sessionSyncAuthSiteConnection.asyncQuery(
276
+ await global.sessionSyncAuthSiteConnection.query(
273
277
  `
274
278
  DELETE FROM \`${sessionTableName}\`
275
279
  WHERE \`${(sessionTableColNameMap.user_id || `user_id`).replace(/`/g, '')}\` = :userId
@@ -279,7 +283,9 @@ const setUpSessionSyncAuthRoutes = ({
279
283
  WHERE \`${(userTableColNameMap.id || `id`).replace(/`/g, '')}\` = :userId
280
284
  `,
281
285
  {
282
- userId: id,
286
+ replacements: {
287
+ userId: id,
288
+ },
283
289
  },
284
290
  )
285
291
  }