@prefabs.tech/fastify-firebase 0.89.2 → 0.90.1
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/dist/prefabs-tech-fastify-firebase.cjs +68 -0
- package/dist/prefabs-tech-fastify-firebase.js +137 -172
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/model/notification/handlers/index.d.ts +1 -1
- package/dist/types/model/notification/handlers/sendNotification.d.ts +1 -1
- package/dist/types/model/notification/handlers/sendNotification.d.ts.map +1 -1
- package/dist/types/model/notification/schema.d.ts +2 -36
- package/dist/types/model/notification/schema.d.ts.map +1 -1
- package/dist/types/model/userDevice/handlers/addUserDevice.d.ts +1 -1
- package/dist/types/model/userDevice/handlers/addUserDevice.d.ts.map +1 -1
- package/dist/types/model/userDevice/handlers/index.d.ts +2 -2
- package/dist/types/model/userDevice/handlers/removeUserDevice.d.ts +1 -1
- package/dist/types/model/userDevice/handlers/removeUserDevice.d.ts.map +1 -1
- package/dist/types/model/userDevice/schema.d.ts +4 -72
- package/dist/types/model/userDevice/schema.d.ts.map +1 -1
- package/dist/types/types.d.ts +1 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +11 -9
- package/dist/prefabs-tech-fastify-firebase.umd.cjs +0 -68
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
sendNotification: (request: import("supertokens-node/framework/fastify").SessionRequest, reply: import("fastify").FastifyReply) => Promise<
|
|
2
|
+
sendNotification: (request: import("supertokens-node/framework/fastify").SessionRequest, reply: import("fastify").FastifyReply) => Promise<void>;
|
|
3
3
|
};
|
|
4
4
|
export default _default;
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FastifyReply } from "fastify";
|
|
2
2
|
import type { SessionRequest } from "supertokens-node/framework/fastify";
|
|
3
|
-
declare const testPushNotification: (request: SessionRequest, reply: FastifyReply) => Promise<
|
|
3
|
+
declare const testPushNotification: (request: SessionRequest, reply: FastifyReply) => Promise<void>;
|
|
4
4
|
export default testPushNotification;
|
|
5
5
|
//# sourceMappingURL=sendNotification.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendNotification.d.ts","sourceRoot":"","sources":["../../../../../src/model/notification/handlers/sendNotification.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,QAAA,MAAM,oBAAoB,GACxB,SAAS,cAAc,EACvB,OAAO,YAAY,
|
|
1
|
+
{"version":3,"file":"sendNotification.d.ts","sourceRoot":"","sources":["../../../../../src/model/notification/handlers/sendNotification.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,QAAA,MAAM,oBAAoB,GACxB,SAAS,cAAc,EACvB,OAAO,YAAY,kBA4DpB,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -29,45 +29,11 @@ export declare const sendNotificationSchema: {
|
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
401: {
|
|
32
|
-
type: string;
|
|
33
|
-
properties: {
|
|
34
|
-
code: {
|
|
35
|
-
type: string;
|
|
36
|
-
};
|
|
37
|
-
error: {
|
|
38
|
-
type: string;
|
|
39
|
-
};
|
|
40
|
-
message: {
|
|
41
|
-
type: string;
|
|
42
|
-
};
|
|
43
|
-
statusCode: {
|
|
44
|
-
type: string;
|
|
45
|
-
};
|
|
46
|
-
status: {
|
|
47
|
-
type: string;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
32
|
description: string;
|
|
33
|
+
$ref: string;
|
|
51
34
|
};
|
|
52
35
|
500: {
|
|
53
|
-
|
|
54
|
-
properties: {
|
|
55
|
-
code: {
|
|
56
|
-
type: string;
|
|
57
|
-
};
|
|
58
|
-
error: {
|
|
59
|
-
type: string;
|
|
60
|
-
};
|
|
61
|
-
message: {
|
|
62
|
-
type: string;
|
|
63
|
-
};
|
|
64
|
-
statusCode: {
|
|
65
|
-
type: string;
|
|
66
|
-
};
|
|
67
|
-
status: {
|
|
68
|
-
type: string;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
36
|
+
$ref: string;
|
|
71
37
|
};
|
|
72
38
|
};
|
|
73
39
|
tags: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/model/notification/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/model/notification/schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BlC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FastifyReply } from "fastify";
|
|
2
2
|
import type { SessionRequest } from "supertokens-node/framework/fastify";
|
|
3
|
-
declare const addUserDevice: (request: SessionRequest, reply: FastifyReply) => Promise<
|
|
3
|
+
declare const addUserDevice: (request: SessionRequest, reply: FastifyReply) => Promise<void>;
|
|
4
4
|
export default addUserDevice;
|
|
5
5
|
//# sourceMappingURL=addUserDevice.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addUserDevice.d.ts","sourceRoot":"","sources":["../../../../../src/model/userDevice/handlers/addUserDevice.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,QAAA,MAAM,aAAa,GAAU,SAAS,cAAc,EAAE,OAAO,YAAY,
|
|
1
|
+
{"version":3,"file":"addUserDevice.d.ts","sourceRoot":"","sources":["../../../../../src/model/userDevice/handlers/addUserDevice.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,QAAA,MAAM,aAAa,GAAU,SAAS,cAAc,EAAE,OAAO,YAAY,kBAYxE,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
addUserDevice: (request: import("supertokens-node/framework/fastify").SessionRequest, reply: import("fastify").FastifyReply) => Promise<
|
|
3
|
-
removeUserDevice: (request: import("supertokens-node/framework/fastify").SessionRequest, reply: import("fastify").FastifyReply) => Promise<
|
|
2
|
+
addUserDevice: (request: import("supertokens-node/framework/fastify").SessionRequest, reply: import("fastify").FastifyReply) => Promise<void>;
|
|
3
|
+
removeUserDevice: (request: import("supertokens-node/framework/fastify").SessionRequest, reply: import("fastify").FastifyReply) => Promise<void>;
|
|
4
4
|
};
|
|
5
5
|
export default _default;
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FastifyReply } from "fastify";
|
|
2
2
|
import type { SessionRequest } from "supertokens-node/framework/fastify";
|
|
3
|
-
declare const removeUserDevice: (request: SessionRequest, reply: FastifyReply) => Promise<
|
|
3
|
+
declare const removeUserDevice: (request: SessionRequest, reply: FastifyReply) => Promise<void>;
|
|
4
4
|
export default removeUserDevice;
|
|
5
5
|
//# sourceMappingURL=removeUserDevice.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeUserDevice.d.ts","sourceRoot":"","sources":["../../../../../src/model/userDevice/handlers/removeUserDevice.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,QAAA,MAAM,gBAAgB,GACpB,SAAS,cAAc,EACvB,OAAO,YAAY,
|
|
1
|
+
{"version":3,"file":"removeUserDevice.d.ts","sourceRoot":"","sources":["../../../../../src/model/userDevice/handlers/removeUserDevice.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,QAAA,MAAM,gBAAgB,GACpB,SAAS,cAAc,EACvB,OAAO,YAAY,kBA6BpB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -31,45 +31,11 @@ export declare const deleteUserDeviceSchema: {
|
|
|
31
31
|
required: string[];
|
|
32
32
|
};
|
|
33
33
|
401: {
|
|
34
|
-
type: string;
|
|
35
|
-
properties: {
|
|
36
|
-
code: {
|
|
37
|
-
type: string;
|
|
38
|
-
};
|
|
39
|
-
error: {
|
|
40
|
-
type: string;
|
|
41
|
-
};
|
|
42
|
-
message: {
|
|
43
|
-
type: string;
|
|
44
|
-
};
|
|
45
|
-
statusCode: {
|
|
46
|
-
type: string;
|
|
47
|
-
};
|
|
48
|
-
status: {
|
|
49
|
-
type: string;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
34
|
description: string;
|
|
35
|
+
$ref: string;
|
|
53
36
|
};
|
|
54
37
|
500: {
|
|
55
|
-
|
|
56
|
-
properties: {
|
|
57
|
-
code: {
|
|
58
|
-
type: string;
|
|
59
|
-
};
|
|
60
|
-
error: {
|
|
61
|
-
type: string;
|
|
62
|
-
};
|
|
63
|
-
message: {
|
|
64
|
-
type: string;
|
|
65
|
-
};
|
|
66
|
-
statusCode: {
|
|
67
|
-
type: string;
|
|
68
|
-
};
|
|
69
|
-
status: {
|
|
70
|
-
type: string;
|
|
71
|
-
};
|
|
72
|
-
};
|
|
38
|
+
$ref: string;
|
|
73
39
|
};
|
|
74
40
|
};
|
|
75
41
|
tags: string[];
|
|
@@ -107,45 +73,11 @@ export declare const postUserDeviceSchema: {
|
|
|
107
73
|
required: string[];
|
|
108
74
|
};
|
|
109
75
|
401: {
|
|
110
|
-
type: string;
|
|
111
|
-
properties: {
|
|
112
|
-
code: {
|
|
113
|
-
type: string;
|
|
114
|
-
};
|
|
115
|
-
error: {
|
|
116
|
-
type: string;
|
|
117
|
-
};
|
|
118
|
-
message: {
|
|
119
|
-
type: string;
|
|
120
|
-
};
|
|
121
|
-
statusCode: {
|
|
122
|
-
type: string;
|
|
123
|
-
};
|
|
124
|
-
status: {
|
|
125
|
-
type: string;
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
76
|
description: string;
|
|
77
|
+
$ref: string;
|
|
129
78
|
};
|
|
130
79
|
500: {
|
|
131
|
-
|
|
132
|
-
properties: {
|
|
133
|
-
code: {
|
|
134
|
-
type: string;
|
|
135
|
-
};
|
|
136
|
-
error: {
|
|
137
|
-
type: string;
|
|
138
|
-
};
|
|
139
|
-
message: {
|
|
140
|
-
type: string;
|
|
141
|
-
};
|
|
142
|
-
statusCode: {
|
|
143
|
-
type: string;
|
|
144
|
-
};
|
|
145
|
-
status: {
|
|
146
|
-
type: string;
|
|
147
|
-
};
|
|
148
|
-
};
|
|
80
|
+
$ref: string;
|
|
149
81
|
};
|
|
150
82
|
};
|
|
151
83
|
tags: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/model/userDevice/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/model/userDevice/schema.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwBlC,CAAC;AAEF,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwBhC,CAAC"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,IAAI;IACZ,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE;QACL,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACvB,CAAC;CACH;AAED,KAAK,qBAAqB,GAAG,OAAO,CAClC,IAAI,CAAC,UAAU,EAAE,WAAW,GAAG,WAAW,CAAC,CAC5C,CAAC;AAEF,KAAK,qBAAqB,GAAG,OAAO,CAClC,IAAI,CAAC,UAAU,EAAE,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAC,CACvD,CAAC;AAEF,YAAY,EACV,qBAAqB,EACrB,IAAI,EACJ,UAAU,EACV,qBAAqB,EACrB,qBAAqB,GACtB,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,qCAAqC,CAAC;AAC7C,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,IAAI;IACZ,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE;QACL,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACvB,CAAC;CACH;AAED,KAAK,qBAAqB,GAAG,OAAO,CAClC,IAAI,CAAC,UAAU,EAAE,WAAW,GAAG,WAAW,CAAC,CAC5C,CAAC;AAEF,KAAK,qBAAqB,GAAG,OAAO,CAClC,IAAI,CAAC,UAAU,EAAE,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAC,CACvD,CAAC;AAEF,YAAY,EACV,qBAAqB,EACrB,IAAI,EACJ,UAAU,EACV,qBAAqB,EACrB,qBAAqB,GACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prefabs.tech/fastify-firebase",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.90.1",
|
|
4
4
|
"description": "Fastify firebase plugin",
|
|
5
5
|
"homepage": "https://github.com/prefabs-tech/fastify/tree/main/packages/firebase#readme",
|
|
6
6
|
"repository": {
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
15
|
"import": "./dist/prefabs-tech-fastify-firebase.js",
|
|
16
|
-
"require": "./dist/prefabs-tech-fastify-firebase.
|
|
16
|
+
"require": "./dist/prefabs-tech-fastify-firebase.cjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
-
"main": "./dist/prefabs-tech-fastify-firebase.
|
|
19
|
+
"main": "./dist/prefabs-tech-fastify-firebase.cjs",
|
|
20
20
|
"module": "./dist/prefabs-tech-fastify-firebase.js",
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
22
22
|
"files": [
|
|
@@ -28,9 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@prefabs.tech/eslint-config": "0.2.0",
|
|
31
|
-
"@prefabs.tech/fastify-config": "0.
|
|
32
|
-
"@prefabs.tech/fastify-
|
|
33
|
-
"@prefabs.tech/fastify-
|
|
31
|
+
"@prefabs.tech/fastify-config": "0.90.1",
|
|
32
|
+
"@prefabs.tech/fastify-error-handler": "0.90.1",
|
|
33
|
+
"@prefabs.tech/fastify-graphql": "0.90.1",
|
|
34
|
+
"@prefabs.tech/fastify-slonik": "0.90.1",
|
|
34
35
|
"@prefabs.tech/tsconfig": "0.2.0",
|
|
35
36
|
"@types/node": "20.19.9",
|
|
36
37
|
"@typescript-eslint/eslint-plugin": "8.38.0",
|
|
@@ -57,9 +58,10 @@
|
|
|
57
58
|
"vitest": "3.2.4"
|
|
58
59
|
},
|
|
59
60
|
"peerDependencies": {
|
|
60
|
-
"@prefabs.tech/fastify-config": "0.
|
|
61
|
-
"@prefabs.tech/fastify-
|
|
62
|
-
"@prefabs.tech/fastify-
|
|
61
|
+
"@prefabs.tech/fastify-config": "0.90.1",
|
|
62
|
+
"@prefabs.tech/fastify-error-handler": "0.90.1",
|
|
63
|
+
"@prefabs.tech/fastify-graphql": "0.90.1",
|
|
64
|
+
"@prefabs.tech/fastify-slonik": "0.90.1",
|
|
63
65
|
"fastify": ">=5.2.1",
|
|
64
66
|
"fastify-plugin": ">=5.0.1",
|
|
65
67
|
"mercurius": ">=16.1.0",
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
(function(i,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("fastify-plugin"),require("firebase-admin"),require("slonik"),require("@prefabs.tech/fastify-slonik"),require("mercurius"),require("@prefabs.tech/fastify-graphql")):typeof define=="function"&&define.amd?define(["exports","fastify-plugin","firebase-admin","slonik","@prefabs.tech/fastify-slonik","mercurius","@prefabs.tech/fastify-graphql"],g):(i=typeof globalThis<"u"?globalThis:i||self,g(i.PrefabsTechFastifyFirebase={},i.FastifyPlugin,i.FirebaseAdmin,i.Slonik,i.PrefabsTechFastifySlonik,i.mercurius,i.PrefabsTechFastifyGraphql))})(this,function(i,g,h,p,w,c,y){"use strict";const U=(e,r)=>{if(!(h.apps.length>0)){if(e.firebase?.enabled!==!1&&!e.firebase.credentials){r.log.error("Firebase credentials are missing");return}try{h.initializeApp({credential:h.credential.cert({projectId:e.firebase.credentials?.projectId,privateKey:e.firebase.credentials?.privateKey.replaceAll(String.raw`\n`,`
|
|
2
|
-
`),clientEmail:e.firebase.credentials?.clientEmail})})}catch(t){r.log.error("Failed to initialize firebase"),r.log.error(t)}}},m=async e=>{await h.messaging().sendEachForMulticast(e)},I="/send-notification",N="/user-device",R="/user-device",D="user_devices",k=e=>{const r=e.firebase.table?.userDevices?.name||D;return p.sql.unsafe`
|
|
3
|
-
DO $$
|
|
4
|
-
BEGIN
|
|
5
|
-
CREATE TABLE IF NOT EXISTS ${p.sql.identifier([r])} (
|
|
6
|
-
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
|
7
|
-
user_id VARCHAR(255) NOT NULL,
|
|
8
|
-
device_token VARCHAR(255) NOT NULL,
|
|
9
|
-
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
10
|
-
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
CREATE INDEX IF NOT EXISTS idx_user_id_device_token ON ${p.sql.identifier([r])} (user_id, device_token);
|
|
14
|
-
END $$;
|
|
15
|
-
`},M=async(e,r)=>{await e.connect(async t=>{await t.query(k(r))})};class $ extends w.DefaultSqlFactory{static TABLE=D;getDeleteExistingTokenSql(r){return p.sql.type(this.validationSchema)`
|
|
16
|
-
DELETE
|
|
17
|
-
FROM ${this.tableFragment}
|
|
18
|
-
${this.getWhereFragment({filterFragment:p.sql.fragment`device_token = ${r}`})}
|
|
19
|
-
RETURNING *;
|
|
20
|
-
`}getFindByUserIdSql(r){return p.sql.type(this.validationSchema)`
|
|
21
|
-
SELECT *
|
|
22
|
-
FROM ${this.tableFragment}
|
|
23
|
-
${this.getWhereFragment({filterFragment:p.sql.fragment`user_id = ${r}`})};
|
|
24
|
-
`}get table(){return this.config.firebase.table?.userDevices?.name||super.table}}class v extends w.BaseService{async getByUserId(r){const t=this.factory.getFindByUserIdSql(r);return await this.database.connect(n=>n.any(t))}async removeByDeviceToken(r){const t=this.factory.getDeleteExistingTokenSql(r);return await this.database.connect(n=>n.maybeOne(t))}get factory(){return super.factory}get sqlFactoryClass(){return $}async preCreate(r){const{deviceToken:t}=r;return await this.removeByDeviceToken(t),r}}const q={sendNotification:async(e,r)=>{if(!e.user)return r.status(401).send({error:"Unauthorized",message:"unauthorized",statusCode:401});const{body:o,title:n,data:a,userId:u}=e.body;if(!u)throw e.log.error("receiver id is not defined"),new Error("Oops, Please provide a receiver id");const s=await new v(e.config,e.slonik,e.dbSchema).getByUserId(u);if(!s||s.length===0)throw e.log.error("no device found for the receiver"),new Error("Unable to find device for the receiver");const l=s.map(E=>E.deviceToken),f={android:{priority:"high",notification:{sound:"default"}},apns:{payload:{aps:{sound:"default"}}},tokens:l,notification:{title:n,body:o},data:{...a,title:n,body:o}};await m(f),r.send({message:"Notification sent successfully"})}},F={type:"object",properties:{code:{type:"string"},error:{type:"object"},message:{type:"string"},statusCode:{type:"number"},status:{type:"string"}}},B={description:"Send a notification to a specific user",operationId:"sendNotification",body:{type:"object",properties:{title:{type:"string"},message:{type:"string"},userId:{type:"string"}},required:["title","message","userId"]},response:{200:{type:"object",properties:{success:{type:"boolean"},message:{type:"string"}}},401:{description:"Unauthorized",...F},500:{...F}},tags:["notifications"]},T=e=>async()=>{if(e.config.firebase.enabled===!1)throw new Error("Firebase is not enabled")},_=async e=>{const r=e.config.firebase.handlers?.userDevice,t=e.config.firebase.notification;t?.test?.enabled&&e.post(t.test.path||I,{preHandler:[e.verifySession(),T(e)],schema:B},r?.addUserDevice||q.sendNotification)},O={addUserDevice:async(e,r)=>{const{body:t,config:o,dbSchema:n,log:a,slonik:u,user:d}=e;if(!d)return r.status(401).send({error:"Unauthorized",message:"unauthorized",statusCode:401});const{deviceToken:s}=t;if(!s)throw a.error("device token is not defined"),new Error("Oops, Something went wrong");const l=new v(o,u,n);r.send(await l.create({userId:d.id,deviceToken:s}))},removeUserDevice:async(e,r)=>{const t=e.user;if(!t)return r.status(401).send({error:"Unauthorized",message:"unauthorized",statusCode:401});const{deviceToken:o}=e.body;if(!o)throw e.log.error("device token is not defined"),new Error("Oops, Something went wrong");const n=new v(e.config,e.slonik,e.dbSchema),a=await n.getByUserId(t.id);if(!a||a.length===0)throw e.log.error("No devices found for user"),new Error("Oops, Something went wrong");if(!a.find(d=>d.deviceToken===o))throw e.log.error("device requested to delete not owned by user"),new Error("Oops, Something went wrong");r.send(await n.removeByDeviceToken(o))}},b={type:"object",properties:{code:{type:"string"},error:{type:"object"},message:{type:"string"},statusCode:{type:"number"},status:{type:"string"}}},A={type:"object",properties:{userId:{type:"string"},deviceToken:{type:"string"},createdAt:{type:"number"},updatedAt:{type:"number"}},required:["userId","deviceToken","createdAt","updatedAt"]},L={description:"Delete a user device by device token",operationId:"deleteUserDevice",body:{type:"object",properties:{deviceToken:{type:"string"}},required:["deviceToken"]},response:{200:{...A,nullable:!0},401:{description:"Unauthorized",...b},500:{...b}},tags:["user-devices"]},z={description:"Register a new user device",operationId:"postUserDevice",body:{type:"object",properties:{deviceToken:{type:"string"}},required:["deviceToken"]},response:{200:{...A,nullable:!0},401:{description:"Unauthorized",...b},500:{...b}},tags:["user-devices"]},P=async e=>{const r=e.config.firebase.handlers?.userDevice;e.post(N,{preHandler:[e.verifySession(),T(e)],schema:z},r?.addUserDevice||O.addUserDevice),e.delete(R,{preHandler:[e.verifySession(),T(e)],schema:L},r?.removeUserDevice||O.removeUserDevice)},W=g(async e=>{const{config:r,slonik:t,log:o}=e;r.firebase.enabled===!1?o.info("fastify-firebase plugin is not enabled"):(o.info("Registering fastify-firebase plugin"),await M(t,r),U(r,e));const{routePrefix:n,routes:a}=r.firebase;a?.notifications?.disabled||await e.register(_,{prefix:n}),a?.userDevices?.disabled||await e.register(P,{prefix:n})}),j={Mutation:{sendNotification:async(e,r,t)=>{const{app:o,config:n,dbSchema:a,database:u,user:d}=t;if(!d)return new c.mercurius.ErrorWithProps("unauthorized",{},401);if(n.firebase.enabled===!1)return new c.mercurius.ErrorWithProps("Firebase is not enabled",{},404);try{const{userId:s,title:l,body:f,data:E}=r.data;if(!s)return new c.mercurius.ErrorWithProps("Receiver id is required",{},400);const S=await new v(n,u,a).getByUserId(s);if(!S||S.length===0)return new c.mercurius.ErrorWithProps("Receiver device not found",{},404);const K={tokens:S.map(X=>X.deviceToken),notification:{title:l,body:f},data:E};return await m(K),{message:"Notification sent successfully"}}catch(s){return o.log.error(s),new c.mercurius.ErrorWithProps("Oops, Something went wrong",{},500)}}},Query:{}},V={Mutation:{addUserDevice:async(e,r,t)=>{const{app:o,config:n,dbSchema:a,database:u,user:d}=t;if(n.firebase.enabled===!1)return new c.mercurius.ErrorWithProps("Firebase is not enabled",{},404);if(!d)return new c.mercurius.ErrorWithProps("unauthorized",{},401);try{const{deviceToken:s}=r.data;return await new v(n,u,a).create({userId:d.id,deviceToken:s})}catch(s){return o.log.error(s),new c.mercurius.ErrorWithProps("Oops, Something went wrong",{},500)}},removeUserDevice:async(e,r,t)=>{const{app:o,config:n,dbSchema:a,database:u,user:d}=t;if(n.firebase.enabled===!1)return new c.mercurius.ErrorWithProps("Firebase is not enabled",{},404);if(!d)return new c.mercurius.ErrorWithProps("unauthorized",{},401);try{const{deviceToken:s}=r.data,l=new v(n,u,a),f=await l.getByUserId(d.id);return!f||f.length===0?new c.mercurius.ErrorWithProps("No devices found for user",{},403):f.find(C=>C.deviceToken===s)?await l.removeByDeviceToken(s):new c.mercurius.ErrorWithProps("Device requested to delete not owned by user",{},403)}catch(s){return o.log.error(s),new c.mercurius.ErrorWithProps("Oops, Something went wrong",{},500)}}},Query:{}},Q=y.gql`
|
|
25
|
-
type SendNotificationResponse {
|
|
26
|
-
message: String!
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
input SendNotificationInput {
|
|
30
|
-
userId: String!
|
|
31
|
-
title: String!
|
|
32
|
-
body: String!
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type Mutation {
|
|
36
|
-
sendNotification(data: SendNotificationInput): SendNotificationResponse
|
|
37
|
-
@auth
|
|
38
|
-
}
|
|
39
|
-
`,H=y.gql`
|
|
40
|
-
type UserDevice {
|
|
41
|
-
id: Int!
|
|
42
|
-
userId: String!
|
|
43
|
-
deviceToken: String!
|
|
44
|
-
createdAt: Float!
|
|
45
|
-
updatedAt: Float!
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type UserDevices {
|
|
49
|
-
data: [UserDevice]!
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
input UserDeviceCreateInput {
|
|
53
|
-
deviceToken: String!
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
input UserDeviceUpdateInput {
|
|
57
|
-
deviceToken: String!
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
input UserDeviceRemoveInput {
|
|
61
|
-
deviceToken: String!
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
type Mutation {
|
|
65
|
-
addUserDevice(data: UserDeviceCreateInput): UserDevice @auth
|
|
66
|
-
removeUserDevice(data: UserDeviceRemoveInput): UserDevice @auth
|
|
67
|
-
}
|
|
68
|
-
`,Y=y.mergeTypeDefs([y.baseSchema,Q,H]);i.ROUTE_SEND_NOTIFICATION=I,i.ROUTE_USER_DEVICE_ADD=N,i.ROUTE_USER_DEVICE_REMOVE=R,i.TABLE_USER_DEVICES=D,i.UserDeviceService=v,i.createUserDevicesTableQuery=k,i.default=W,i.firebaseSchema=Y,i.initializeFirebase=U,i.notificationResolver=j,i.notificationRoutes=_,i.sendPushNotification=m,i.userDeviceResolver=V,i.userDeviceRoutes=P,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|