prostgles-server 4.2.227 → 4.2.229
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/.eslintrc.json +1 -0
- package/dist/Auth/AuthHandler.d.ts +3 -4
- package/dist/Auth/AuthHandler.d.ts.map +1 -1
- package/dist/Auth/AuthHandler.js +9 -11
- package/dist/Auth/AuthHandler.js.map +1 -1
- package/dist/Auth/AuthTypes.d.ts +27 -23
- package/dist/Auth/AuthTypes.d.ts.map +1 -1
- package/dist/Auth/endpoints/setCatchAllRequestHandler.d.ts.map +1 -1
- package/dist/Auth/endpoints/setCatchAllRequestHandler.js +4 -4
- package/dist/Auth/endpoints/setCatchAllRequestHandler.js.map +1 -1
- package/dist/Auth/endpoints/setLoginRequestHandler.d.ts +2 -1
- package/dist/Auth/endpoints/setLoginRequestHandler.d.ts.map +1 -1
- package/dist/Auth/endpoints/setMagicLinkOrOTPRequestHandler.d.ts.map +1 -1
- package/dist/Auth/endpoints/setMagicLinkOrOTPRequestHandler.js +8 -6
- package/dist/Auth/endpoints/setMagicLinkOrOTPRequestHandler.js.map +1 -1
- package/dist/Auth/endpoints/setRegisterRequestHandler.d.ts +2 -2
- package/dist/Auth/endpoints/setRegisterRequestHandler.d.ts.map +1 -1
- package/dist/Auth/endpoints/setRegisterRequestHandler.js +4 -4
- package/dist/Auth/endpoints/setRegisterRequestHandler.js.map +1 -1
- package/dist/Auth/getClientAuth.d.ts.map +1 -1
- package/dist/Auth/getClientAuth.js +1 -1
- package/dist/Auth/getClientAuth.js.map +1 -1
- package/dist/Auth/setupAuthRoutes.d.ts.map +1 -1
- package/dist/Auth/setupAuthRoutes.js +2 -4
- package/dist/Auth/setupAuthRoutes.js.map +1 -1
- package/dist/DBSchemaBuilder.js +9 -9
- package/dist/DBSchemaBuilder.js.map +1 -1
- package/dist/DboBuilder/DboBuilder.d.ts +1 -1
- package/dist/DboBuilder/DboBuilder.js +1 -1
- package/dist/DboBuilder/DboBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryStreamer.js +9 -9
- package/dist/DboBuilder/QueryStreamer.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/find.js +1 -1
- package/dist/DboBuilder/ViewHandler/find.js.map +1 -1
- package/dist/FileManager/upload.d.ts.map +1 -1
- package/dist/FileManager/upload.js +1 -1
- package/dist/FileManager/upload.js.map +1 -1
- package/dist/FileManager/uploadStream.d.ts.map +1 -1
- package/dist/FileManager/uploadStream.js +1 -1
- package/dist/FileManager/uploadStream.js.map +1 -1
- package/dist/PostgresNotifListenManager.js +3 -3
- package/dist/PostgresNotifListenManager.js.map +1 -1
- package/dist/Prostgles.js +1 -1
- package/dist/Prostgles.js.map +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.js +5 -5
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/dist/PubSubManager/addSub.js +3 -3
- package/dist/PubSubManager/addSub.js.map +1 -1
- package/dist/PubSubManager/addSync.js +5 -5
- package/dist/PubSubManager/addSync.js.map +1 -1
- package/dist/PubSubManager/notifListener.js +5 -5
- package/dist/PubSubManager/notifListener.js.map +1 -1
- package/dist/PubSubManager/pushSubData.js +1 -1
- package/dist/PubSubManager/pushSubData.js.map +1 -1
- package/dist/SchemaWatch/SchemaWatch.js +2 -2
- package/dist/SchemaWatch/SchemaWatch.js.map +1 -1
- package/dist/SyncReplication.js +2 -2
- package/dist/SyncReplication.js.map +1 -1
- package/dist/TableConfig/initTableConfig.js +4 -4
- package/dist/TableConfig/initTableConfig.js.map +1 -1
- package/dist/initProstgles.js +1 -1
- package/dist/initProstgles.js.map +1 -1
- package/dist/onSocketConnected.js +3 -3
- package/dist/onSocketConnected.js.map +1 -1
- package/dist/typeTests/dboTypeCheck.js +3 -3
- package/dist/typeTests/dboTypeCheck.js.map +1 -1
- package/lib/Auth/AuthHandler.ts +16 -14
- package/lib/Auth/AuthTypes.ts +32 -24
- package/lib/Auth/endpoints/setCatchAllRequestHandler.ts +5 -4
- package/lib/Auth/endpoints/setLoginRequestHandler.ts +3 -3
- package/lib/Auth/endpoints/setMagicLinkOrOTPRequestHandler.ts +23 -9
- package/lib/Auth/endpoints/setRegisterRequestHandler.ts +6 -6
- package/lib/Auth/getClientAuth.ts +6 -2
- package/lib/Auth/setupAuthRoutes.ts +3 -5
- package/lib/DBSchemaBuilder.ts +9 -9
- package/lib/DboBuilder/DboBuilder.ts +1 -1
- package/lib/DboBuilder/QueryStreamer.ts +9 -9
- package/lib/DboBuilder/ViewHandler/find.ts +1 -1
- package/lib/FileManager/upload.ts +3 -8
- package/lib/FileManager/uploadStream.ts +6 -8
- package/lib/PostgresNotifListenManager.ts +3 -3
- package/lib/Prostgles.ts +1 -1
- package/lib/PubSubManager/PubSubManager.ts +5 -5
- package/lib/PubSubManager/addSub.ts +3 -3
- package/lib/PubSubManager/addSync.ts +3 -3
- package/lib/PubSubManager/notifListener.ts +5 -5
- package/lib/PubSubManager/pushSubData.ts +1 -1
- package/lib/SchemaWatch/SchemaWatch.ts +2 -2
- package/lib/SyncReplication.ts +2 -2
- package/lib/TableConfig/initTableConfig.ts +4 -4
- package/lib/initProstgles.ts +1 -1
- package/lib/onSocketConnected.ts +3 -3
- package/lib/typeTests/dboTypeCheck.ts +11 -11
- package/package.json +2 -2
- package/dist/Auth/endpoints/setConfirmEmailRequestHandler.d.ts +0 -5
- package/dist/Auth/endpoints/setConfirmEmailRequestHandler.d.ts.map +0 -1
- package/dist/Auth/endpoints/setConfirmEmailRequestHandler.js +0 -52
- package/dist/Auth/endpoints/setConfirmEmailRequestHandler.js.map +0 -1
- package/lib/Auth/endpoints/setConfirmEmailRequestHandler.ts +0 -65
|
@@ -194,7 +194,7 @@ export class PubSubManager {
|
|
|
194
194
|
private constructor(dboBuilder: DboBuilder) {
|
|
195
195
|
this.dboBuilder = dboBuilder;
|
|
196
196
|
|
|
197
|
-
this._log({
|
|
197
|
+
void this._log({
|
|
198
198
|
type: "syncOrSub",
|
|
199
199
|
command: "postgresNotifListenManager.create",
|
|
200
200
|
duration: 0,
|
|
@@ -207,13 +207,13 @@ export class PubSubManager {
|
|
|
207
207
|
appCheck?: ReturnType<typeof setInterval>;
|
|
208
208
|
|
|
209
209
|
destroyed = false;
|
|
210
|
-
destroy = () => {
|
|
210
|
+
destroy = async () => {
|
|
211
211
|
this.destroyed = true;
|
|
212
212
|
if (this.appCheck) {
|
|
213
213
|
clearInterval(this.appCheck);
|
|
214
214
|
}
|
|
215
|
-
this.postgresNotifListenManager?.destroy();
|
|
216
|
-
this._log({
|
|
215
|
+
await this.postgresNotifListenManager?.destroy();
|
|
216
|
+
await this._log({
|
|
217
217
|
type: "syncOrSub",
|
|
218
218
|
command: "postgresNotifListenManager.destroy",
|
|
219
219
|
duration: 0,
|
|
@@ -393,7 +393,7 @@ export class PubSubManager {
|
|
|
393
393
|
|
|
394
394
|
delete this.sockets[socket.id];
|
|
395
395
|
|
|
396
|
-
this._log({
|
|
396
|
+
void this._log({
|
|
397
397
|
type: "sync",
|
|
398
398
|
command: "upsertSocket.disconnect",
|
|
399
399
|
tableName: "",
|
|
@@ -111,7 +111,7 @@ export async function addSub(
|
|
|
111
111
|
* Socket clients are not affected as they need to confirm they are ready to receive data
|
|
112
112
|
*/
|
|
113
113
|
result.sendFirstData = () => {
|
|
114
|
-
this.pushSubData(newSub);
|
|
114
|
+
void this.pushSubData(newSub);
|
|
115
115
|
};
|
|
116
116
|
} else if (socket) {
|
|
117
117
|
const removeListeners = () => {
|
|
@@ -122,7 +122,7 @@ export async function addSub(
|
|
|
122
122
|
removeListeners();
|
|
123
123
|
|
|
124
124
|
socket.once(result.channelNameReady, () => {
|
|
125
|
-
this.pushSubData(newSub);
|
|
125
|
+
void this.pushSubData(newSub);
|
|
126
126
|
});
|
|
127
127
|
socket.once(result.channelNameUnsubscribe, (_data: any, cb: BasicCallback) => {
|
|
128
128
|
const res = "ok";
|
|
@@ -130,7 +130,7 @@ export async function addSub(
|
|
|
130
130
|
const isMatch = s.socket?.id === socket.id && s.channel_name === channel_name;
|
|
131
131
|
return !isMatch;
|
|
132
132
|
});
|
|
133
|
-
this._log({
|
|
133
|
+
void this._log({
|
|
134
134
|
type: "syncOrSub",
|
|
135
135
|
command: "unsubscribe",
|
|
136
136
|
channel_name,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { find, tryCatchV2 } from "prostgles-types
|
|
1
|
+
import { find, tryCatchV2 } from "prostgles-types";
|
|
2
2
|
import {
|
|
3
3
|
AddSyncParams,
|
|
4
4
|
BasicCallback,
|
|
@@ -69,7 +69,7 @@ export async function addSync(
|
|
|
69
69
|
const unsyncChn = channelName + "unsync";
|
|
70
70
|
socket.removeAllListeners(unsyncChn);
|
|
71
71
|
socket.once(unsyncChn, (_data: any, cb: BasicCallback) => {
|
|
72
|
-
this._log({
|
|
72
|
+
void this._log({
|
|
73
73
|
type: "sync",
|
|
74
74
|
command: "unsync",
|
|
75
75
|
socketId: socket.id,
|
|
@@ -113,7 +113,7 @@ export async function addSync(
|
|
|
113
113
|
*/
|
|
114
114
|
|
|
115
115
|
if (data.onSyncRequest) {
|
|
116
|
-
this.syncData(newSync, data.onSyncRequest, "client");
|
|
116
|
+
void this.syncData(newSync, data.onSyncRequest, "client");
|
|
117
117
|
} else {
|
|
118
118
|
console.error("Unexpected sync request data from client: ", data);
|
|
119
119
|
}
|
|
@@ -94,7 +94,7 @@ export async function notifListener(this: PubSubManager, data: { payload: string
|
|
|
94
94
|
tableTriggerConditions.map(({ condition }) => {
|
|
95
95
|
const subs = this.getTriggerSubs(table_name, condition);
|
|
96
96
|
subs.map((s) => {
|
|
97
|
-
this.pushSubData(s, pref + ". Check server logs. Schema might have changed");
|
|
97
|
+
void this.pushSubData(s, pref + ". Check server logs. Schema might have changed");
|
|
98
98
|
});
|
|
99
99
|
});
|
|
100
100
|
|
|
@@ -129,7 +129,7 @@ export async function notifListener(this: PubSubManager, data: { payload: string
|
|
|
129
129
|
[table_name, orphanedTableConditions, this.appId]
|
|
130
130
|
)
|
|
131
131
|
.then(() => {
|
|
132
|
-
this.refreshTriggers();
|
|
132
|
+
return this.refreshTriggers();
|
|
133
133
|
})
|
|
134
134
|
.catch((e) => {
|
|
135
135
|
console.error("Error deleting orphaned triggers", e);
|
|
@@ -144,7 +144,7 @@ export async function notifListener(this: PubSubManager, data: { payload: string
|
|
|
144
144
|
);
|
|
145
145
|
|
|
146
146
|
syncs.map((s) => {
|
|
147
|
-
this.syncData(s, undefined, "trigger");
|
|
147
|
+
void this.syncData(s, undefined, "trigger");
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
/* Throttle the subscriptions */
|
|
@@ -162,14 +162,14 @@ export async function notifListener(this: PubSubManager, data: { payload: string
|
|
|
162
162
|
sub.last_throttled = Date.now();
|
|
163
163
|
|
|
164
164
|
/* It is assumed the policy was checked before this point */
|
|
165
|
-
this.pushSubData(sub);
|
|
165
|
+
void this.pushSubData(sub);
|
|
166
166
|
} else if (!sub.is_throttling) {
|
|
167
167
|
log("throttling sub");
|
|
168
168
|
sub.is_throttling = setTimeout(() => {
|
|
169
169
|
log("throttling finished. pushSubData...");
|
|
170
170
|
sub.is_throttling = null;
|
|
171
171
|
sub.last_throttled = Date.now();
|
|
172
|
-
this.pushSubData(sub);
|
|
172
|
+
void this.pushSubData(sub);
|
|
173
173
|
}, throttle);
|
|
174
174
|
}
|
|
175
175
|
});
|
|
@@ -8,7 +8,7 @@ export async function pushSubData(this: PubSubManager, sub: Subscription, err?:
|
|
|
8
8
|
const onLog = (
|
|
9
9
|
state: Extract<EventTypes.SyncOrSub, { type: "syncOrSub"; command: "pushSubData" }>["state"]
|
|
10
10
|
) => {
|
|
11
|
-
this._log({
|
|
11
|
+
void this._log({
|
|
12
12
|
type: "syncOrSub",
|
|
13
13
|
command: "pushSubData",
|
|
14
14
|
channel_name: sub.channel_name,
|
|
@@ -69,7 +69,7 @@ export class SchemaWatch {
|
|
|
69
69
|
log("Schema changed");
|
|
70
70
|
const { query, command } = event;
|
|
71
71
|
|
|
72
|
-
this.dboBuilder.cacheDBTypes(true);
|
|
72
|
+
void this.dboBuilder.cacheDBTypes(true);
|
|
73
73
|
if (typeof watchSchema === "function") {
|
|
74
74
|
/* Only call the provided func */
|
|
75
75
|
watchSchema(event);
|
|
@@ -84,7 +84,7 @@ export class SchemaWatch {
|
|
|
84
84
|
} else {
|
|
85
85
|
/* Full re-init. Sockets must reconnect */
|
|
86
86
|
console.log("watchSchema: Full re-initialisation", { query });
|
|
87
|
-
this.dboBuilder.prostgles.init(onReady as any, {
|
|
87
|
+
void this.dboBuilder.prostgles.init(onReady as any, {
|
|
88
88
|
type: "schema change",
|
|
89
89
|
query,
|
|
90
90
|
command,
|
package/lib/SyncReplication.ts
CHANGED
|
@@ -572,7 +572,7 @@ export async function syncData(
|
|
|
572
572
|
/**
|
|
573
573
|
* After all data was inserted request SyncInfo from client and sync again if necessary
|
|
574
574
|
*/
|
|
575
|
-
this.syncData(sync, undefined, source);
|
|
575
|
+
void this.syncData(sync, undefined, source);
|
|
576
576
|
},
|
|
577
577
|
});
|
|
578
578
|
}
|
|
@@ -584,7 +584,7 @@ export async function syncData(
|
|
|
584
584
|
this.syncTimeout = setTimeout(() => {
|
|
585
585
|
this.syncTimeout = undefined;
|
|
586
586
|
// console.log("SYNC FROM TIMEOUT")
|
|
587
|
-
this.syncData(sync, undefined, source);
|
|
587
|
+
void this.syncData(sync, undefined, source);
|
|
588
588
|
}, throttle);
|
|
589
589
|
}
|
|
590
590
|
// console.log("SYNC THROTTLE")
|
|
@@ -27,7 +27,7 @@ export const initTableConfig = async function (this: TableConfigurator<any>) {
|
|
|
27
27
|
}
|
|
28
28
|
q = `/* ${PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID} */ \n\n` + q;
|
|
29
29
|
queryHistory.push(q);
|
|
30
|
-
this.prostgles.opts.onLog?.({
|
|
30
|
+
await this.prostgles.opts.onLog?.({
|
|
31
31
|
type: "debug",
|
|
32
32
|
command: "TableConfig.runQueries.start",
|
|
33
33
|
data: { q },
|
|
@@ -39,7 +39,7 @@ export const initTableConfig = async function (this: TableConfigurator<any>) {
|
|
|
39
39
|
failedQueries.push({ query: q, error: err });
|
|
40
40
|
return Promise.reject(err);
|
|
41
41
|
});
|
|
42
|
-
this.prostgles.opts.onLog?.({
|
|
42
|
+
await this.prostgles.opts.onLog?.({
|
|
43
43
|
type: "debug",
|
|
44
44
|
command: "TableConfig.runQueries.end",
|
|
45
45
|
duration: Date.now() - now,
|
|
@@ -377,7 +377,7 @@ export const initTableConfig = async function (this: TableConfigurator<any>) {
|
|
|
377
377
|
if (!this.prevInitQueryHistory) {
|
|
378
378
|
this.prevInitQueryHistory = queryHistory;
|
|
379
379
|
} else if (this.prevInitQueryHistory.join() !== queryHistory.join()) {
|
|
380
|
-
this.prostgles.init(this.prostgles.opts.onReady as any, {
|
|
380
|
+
void this.prostgles.init(this.prostgles.opts.onReady as any, {
|
|
381
381
|
type: "TableConfig",
|
|
382
382
|
});
|
|
383
383
|
} else {
|
|
@@ -389,5 +389,5 @@ export const initTableConfig = async function (this: TableConfigurator<any>) {
|
|
|
389
389
|
}
|
|
390
390
|
|
|
391
391
|
await this.prostgles.refreshDBO();
|
|
392
|
-
this.setTableOnMounts();
|
|
392
|
+
await this.setTableOnMounts();
|
|
393
393
|
};
|
package/lib/initProstgles.ts
CHANGED
|
@@ -237,7 +237,7 @@ export const initProstgles = async function (
|
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
this.fileManager?.destroy();
|
|
240
|
-
this.dboBuilder.destroy();
|
|
240
|
+
await this.dboBuilder.destroy();
|
|
241
241
|
this.authHandler?.destroy();
|
|
242
242
|
await this.tableConfigurator?.destroy();
|
|
243
243
|
this.dbo = undefined;
|
package/lib/onSocketConnected.ts
CHANGED
|
@@ -72,7 +72,7 @@ export async function onSocketConnected(this: Prostgles, socket: PRGLIOSocket) {
|
|
|
72
72
|
this.dbEventsManager?.removeNotify(undefined, socket);
|
|
73
73
|
this.connectedSockets = this.connectedSockets.filter((s) => s.id !== socket.id);
|
|
74
74
|
this.dboBuilder.queryStreamer.onDisconnect(socket.id);
|
|
75
|
-
this.opts.onLog?.({
|
|
75
|
+
void this.opts.onLog?.({
|
|
76
76
|
type: "disconnect",
|
|
77
77
|
sid: this.authHandler?.getSID({ socket }),
|
|
78
78
|
socketId: socket.id,
|
|
@@ -84,7 +84,7 @@ export async function onSocketConnected(this: Prostgles, socket: PRGLIOSocket) {
|
|
|
84
84
|
if (!this.authHandler) throw "authHandler missing";
|
|
85
85
|
return await this.authHandler.getSidAndUserFromRequest({ socket });
|
|
86
86
|
};
|
|
87
|
-
this.opts.onSocketDisconnect({ socket, dbo: dbo as DBOFullyTyped, db, getUser });
|
|
87
|
+
void this.opts.onSocketDisconnect({ socket, dbo: dbo as DBOFullyTyped, db, getUser });
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
|
|
@@ -116,7 +116,7 @@ export async function onSocketConnected(this: Prostgles, socket: PRGLIOSocket) {
|
|
|
116
116
|
}
|
|
117
117
|
);
|
|
118
118
|
|
|
119
|
-
this.pushSocketSchema(socket);
|
|
119
|
+
await this.pushSocketSchema(socket);
|
|
120
120
|
} catch (e) {
|
|
121
121
|
console.trace("setSocketEvents: ", e);
|
|
122
122
|
}
|
|
@@ -37,7 +37,7 @@ export const testDboTypes = () => {
|
|
|
37
37
|
orderBy: {
|
|
38
38
|
id: 1,
|
|
39
39
|
},
|
|
40
|
-
}
|
|
40
|
+
}
|
|
41
41
|
);
|
|
42
42
|
|
|
43
43
|
r[0]?.id;
|
|
@@ -46,34 +46,34 @@ export const testDboTypes = () => {
|
|
|
46
46
|
r[0]?.bad_col;
|
|
47
47
|
|
|
48
48
|
const tr2 = {} as ViewHandler<DBSchema2["tr2"]["columns"], DBSchema2>;
|
|
49
|
-
tr2.find(
|
|
49
|
+
void tr2.find(
|
|
50
50
|
{},
|
|
51
51
|
{
|
|
52
52
|
select: { id: 1 },
|
|
53
53
|
orderBy: { tr1_id: 1 },
|
|
54
|
-
}
|
|
54
|
+
}
|
|
55
55
|
);
|
|
56
56
|
|
|
57
|
-
tr2.find(
|
|
57
|
+
void tr2.find(
|
|
58
58
|
{},
|
|
59
59
|
{
|
|
60
60
|
//@ts-expect-error
|
|
61
61
|
select: { bad_col: 1 },
|
|
62
|
-
}
|
|
62
|
+
}
|
|
63
63
|
);
|
|
64
64
|
|
|
65
|
-
tr2.find(
|
|
65
|
+
void tr2.find(
|
|
66
66
|
{},
|
|
67
67
|
{
|
|
68
68
|
//@ts-expect-error
|
|
69
69
|
orderBy: { bad_col: 1 },
|
|
70
|
-
}
|
|
70
|
+
}
|
|
71
71
|
);
|
|
72
72
|
|
|
73
|
-
(await db.items2.find(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
)
|
|
73
|
+
(await db.items2.find({}, { select: { items_id: 1 }, returnType: "values" })) satisfies (
|
|
74
|
+
| number
|
|
75
|
+
| null
|
|
76
|
+
)[];
|
|
77
77
|
|
|
78
78
|
const publish: Publish<DBGeneratedSchema> = {
|
|
79
79
|
items: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.229",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"pg": "^8.11.5",
|
|
57
57
|
"pg-cursor": "^2.11.0",
|
|
58
58
|
"pg-promise": "^11.9.1",
|
|
59
|
-
"prostgles-types": "^4.0.
|
|
59
|
+
"prostgles-types": "^4.0.145"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/express": "^4.17.21",
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import e from "express";
|
|
2
|
-
import { AuthHandler } from "../AuthHandler";
|
|
3
|
-
import { SignupWithEmailAndPassword } from "../AuthTypes";
|
|
4
|
-
export declare function setConfirmEmailRequestHandler(this: AuthHandler, emailAuthConfig: SignupWithEmailAndPassword, app: e.Express): void;
|
|
5
|
-
//# sourceMappingURL=setConfirmEmailRequestHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setConfirmEmailRequestHandler.d.ts","sourceRoot":"","sources":["../../../lib/Auth/endpoints/setConfirmEmailRequestHandler.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,SAAS,CAAC;AAExB,OAAO,EAA0B,WAAW,EAAmB,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAI1D,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,WAAW,EACjB,eAAe,EAAE,0BAA0B,EAC3C,GAAG,EAAE,CAAC,CAAC,OAAO,QAqDf"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setConfirmEmailRequestHandler = void 0;
|
|
4
|
-
const AuthHandler_1 = require("../AuthHandler");
|
|
5
|
-
const getClientRequestIPsInfo_1 = require("../utils/getClientRequestIPsInfo");
|
|
6
|
-
const throttledReject_1 = require("../utils/throttledReject");
|
|
7
|
-
function setConfirmEmailRequestHandler(emailAuthConfig, app) {
|
|
8
|
-
const requestHandler = async (req, res) => {
|
|
9
|
-
const { email, code } = req.query;
|
|
10
|
-
try {
|
|
11
|
-
if (!email || typeof email !== "string") {
|
|
12
|
-
return res.send({
|
|
13
|
-
success: false,
|
|
14
|
-
code: "something-went-wrong",
|
|
15
|
-
message: "Email query param missing/invalid",
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
if (!code || typeof code !== "string") {
|
|
19
|
-
return res.send({
|
|
20
|
-
success: false,
|
|
21
|
-
code: "something-went-wrong",
|
|
22
|
-
message: "Email confirmation code query param missing/invalid",
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
const clientInfo = (0, getClientRequestIPsInfo_1.getClientRequestIPsInfo)({ httpReq: req });
|
|
26
|
-
const response = await (0, throttledReject_1.throttledAuthCall)(async () => emailAuthConfig.onEmailConfirmation({
|
|
27
|
-
code,
|
|
28
|
-
email,
|
|
29
|
-
clientInfo,
|
|
30
|
-
req,
|
|
31
|
-
}));
|
|
32
|
-
if (!response.success) {
|
|
33
|
-
return res.status(AuthHandler_1.HTTP_FAIL_CODES.BAD_REQUEST).json(response);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* This approach requires correct handling in setCatchAllRequestHandler to not redirect user.type=public res.redirect("/");
|
|
37
|
-
*/
|
|
38
|
-
if (response.redirect_to) {
|
|
39
|
-
return res.redirect(response.redirect_to);
|
|
40
|
-
}
|
|
41
|
-
res.json(response);
|
|
42
|
-
}
|
|
43
|
-
catch (_e) {
|
|
44
|
-
res
|
|
45
|
-
.status(AuthHandler_1.HTTP_FAIL_CODES.BAD_REQUEST)
|
|
46
|
-
.json({ success: false, code: "server-error", message: "Failed to confirm email" });
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
app.get(AuthHandler_1.AUTH_ROUTES_AND_PARAMS.confirmEmail, requestHandler);
|
|
50
|
-
}
|
|
51
|
-
exports.setConfirmEmailRequestHandler = setConfirmEmailRequestHandler;
|
|
52
|
-
//# sourceMappingURL=setConfirmEmailRequestHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setConfirmEmailRequestHandler.js","sourceRoot":"","sources":["../../../lib/Auth/endpoints/setConfirmEmailRequestHandler.ts"],"names":[],"mappings":";;;AAGA,gDAAsF;AAEtF,8EAA2E;AAC3E,8DAA6D;AAE7D,SAAgB,6BAA6B,CAE3C,eAA2C,EAC3C,GAAc;IAEd,MAAM,cAAc,GAAG,KAAK,EAC1B,GAAY,EACZ,GAGC,EACD,EAAE;QACF,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC;QAClC,IAAI,CAAC;YACH,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBACxC,OAAO,GAAG,CAAC,IAAI,CAAC;oBACd,OAAO,EAAE,KAAK;oBACd,IAAI,EAAE,sBAAsB;oBAC5B,OAAO,EAAE,mCAAmC;iBAC7C,CAAC,CAAC;YACL,CAAC;YACD,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACtC,OAAO,GAAG,CAAC,IAAI,CAAC;oBACd,OAAO,EAAE,KAAK;oBACd,IAAI,EAAE,sBAAsB;oBAC5B,OAAO,EAAE,qDAAqD;iBAC/D,CAAC,CAAC;YACL,CAAC;YACD,MAAM,UAAU,GAAG,IAAA,iDAAuB,EAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;YAC7D,MAAM,QAAQ,GAAG,MAAM,IAAA,mCAAiB,EAAC,KAAK,IAAI,EAAE,CAClD,eAAe,CAAC,mBAAmB,CAAC;gBAClC,IAAI;gBACJ,KAAK;gBACL,UAAU;gBACV,GAAG;aACJ,CAAC,CACH,CAAC;YACF,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;gBACtB,OAAO,GAAG,CAAC,MAAM,CAAC,6BAAe,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAChE,CAAC;YAED;;eAEG;YACH,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;gBACzB,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;YAC5C,CAAC;YACD,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrB,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,GAAG;iBACA,MAAM,CAAC,6BAAe,CAAC,WAAW,CAAC;iBACnC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,yBAAyB,EAAE,CAAC,CAAC;QACxF,CAAC;IACH,CAAC,CAAC;IAEF,GAAG,CAAC,GAAG,CAAC,oCAAsB,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;AAC/D,CAAC;AAxDD,sEAwDC"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { Request, Response } from "express";
|
|
2
|
-
import e from "express";
|
|
3
|
-
import { AuthResponse } from "prostgles-types";
|
|
4
|
-
import { AUTH_ROUTES_AND_PARAMS, AuthHandler, HTTP_FAIL_CODES } from "../AuthHandler";
|
|
5
|
-
import { SignupWithEmailAndPassword } from "../AuthTypes";
|
|
6
|
-
import { getClientRequestIPsInfo } from "../utils/getClientRequestIPsInfo";
|
|
7
|
-
import { throttledAuthCall } from "../utils/throttledReject";
|
|
8
|
-
|
|
9
|
-
export function setConfirmEmailRequestHandler(
|
|
10
|
-
this: AuthHandler,
|
|
11
|
-
emailAuthConfig: SignupWithEmailAndPassword,
|
|
12
|
-
app: e.Express
|
|
13
|
-
) {
|
|
14
|
-
const requestHandler = async (
|
|
15
|
-
req: Request,
|
|
16
|
-
res: Response<
|
|
17
|
-
| AuthResponse.PasswordRegisterEmailConfirmationSuccess
|
|
18
|
-
| AuthResponse.PasswordRegisterEmailConfirmationFailure
|
|
19
|
-
>
|
|
20
|
-
) => {
|
|
21
|
-
const { email, code } = req.query;
|
|
22
|
-
try {
|
|
23
|
-
if (!email || typeof email !== "string") {
|
|
24
|
-
return res.send({
|
|
25
|
-
success: false,
|
|
26
|
-
code: "something-went-wrong",
|
|
27
|
-
message: "Email query param missing/invalid",
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
if (!code || typeof code !== "string") {
|
|
31
|
-
return res.send({
|
|
32
|
-
success: false,
|
|
33
|
-
code: "something-went-wrong",
|
|
34
|
-
message: "Email confirmation code query param missing/invalid",
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
const clientInfo = getClientRequestIPsInfo({ httpReq: req });
|
|
38
|
-
const response = await throttledAuthCall(async () =>
|
|
39
|
-
emailAuthConfig.onEmailConfirmation({
|
|
40
|
-
code,
|
|
41
|
-
email,
|
|
42
|
-
clientInfo,
|
|
43
|
-
req,
|
|
44
|
-
})
|
|
45
|
-
);
|
|
46
|
-
if (!response.success) {
|
|
47
|
-
return res.status(HTTP_FAIL_CODES.BAD_REQUEST).json(response);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* This approach requires correct handling in setCatchAllRequestHandler to not redirect user.type=public res.redirect("/");
|
|
52
|
-
*/
|
|
53
|
-
if (response.redirect_to) {
|
|
54
|
-
return res.redirect(response.redirect_to);
|
|
55
|
-
}
|
|
56
|
-
res.json(response);
|
|
57
|
-
} catch (_e) {
|
|
58
|
-
res
|
|
59
|
-
.status(HTTP_FAIL_CODES.BAD_REQUEST)
|
|
60
|
-
.json({ success: false, code: "server-error", message: "Failed to confirm email" });
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
app.get(AUTH_ROUTES_AND_PARAMS.confirmEmail, requestHandler);
|
|
65
|
-
}
|