@1auth/store-sql 0.0.0-alpha.46 → 0.0.0-alpha.48
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/index.js +10 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const options = {
|
|
2
2
|
log: undefined,
|
|
3
3
|
query: undefined, // async (sql, parameters) => {}
|
|
4
|
+
// number of seconds after expire before removal
|
|
5
|
+
// 10d chosen based on EFF DNT Policy
|
|
6
|
+
timeToLiveExpireOffset: 10 * 24 * 60 * 60,
|
|
7
|
+
timeToLiveKey: 'remove',
|
|
4
8
|
// mode:
|
|
5
9
|
// ?: use `?` for variables, ie sqlite
|
|
6
10
|
// $: use `$1` for variables, ie postgres
|
|
@@ -66,6 +70,10 @@ export const insert = async (table, values = {}) => {
|
|
|
66
70
|
if (options.log) {
|
|
67
71
|
options.log('@1auth/store-sql insert(', table, values, ')')
|
|
68
72
|
}
|
|
73
|
+
if (values.expire && options.timeToLiveKey) {
|
|
74
|
+
values[options.timeToLiveKey] =
|
|
75
|
+
values.expire + options.timeToLiveExpireOffset
|
|
76
|
+
}
|
|
69
77
|
values = structuredClone(values)
|
|
70
78
|
normalizeValues(values)
|
|
71
79
|
const { insert, parameters } = makeSqlParts({}, values)
|
|
@@ -124,6 +132,7 @@ const normalizeValues = (values) => {
|
|
|
124
132
|
values.verify &&= new Date(values.verify * 1000).toISOString()
|
|
125
133
|
values.lastused &&= new Date(values.lastused * 1000).toISOString()
|
|
126
134
|
values.expire &&= new Date(values.expire * 1000).toISOString()
|
|
135
|
+
values.remove &&= new Date(values.remove * 1000).toISOString()
|
|
127
136
|
}
|
|
128
137
|
|
|
129
138
|
const parseValues = (values) => {
|
|
@@ -133,6 +142,7 @@ const parseValues = (values) => {
|
|
|
133
142
|
values.verify &&= Date.parse(values.verify) / 1000
|
|
134
143
|
values.lastused &&= Date.parse(values.lastused) / 1000
|
|
135
144
|
values.expire &&= Date.parse(values.expire) / 1000
|
|
145
|
+
values.remove &&= Date.parse(values.remove) / 1000
|
|
136
146
|
}
|
|
137
147
|
|
|
138
148
|
// export for testing
|