Skip to content

Commit e82622d

Browse files
npm run npm-pull
1 parent ef83998 commit e82622d

File tree

2 files changed

+83
-83
lines changed

2 files changed

+83
-83
lines changed

deep.json

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
{
22
"package": {
33
"name": "@deep-foundation/firebase-push-notification",
4-
"version": "14.0.3-dev.0"
4+
"version": "14.0.4"
55
},
66
"data": [
77
{
88
"package": {
99
"dependencyId": 0,
10-
"containValue": "Type"
10+
"containValue": "Handler"
1111
},
1212
"id": 1
1313
},
1414
{
1515
"package": {
1616
"dependencyId": 0,
17-
"containValue": "Value"
17+
"containValue": "dockerSupportsJs"
1818
},
1919
"id": 2
2020
},
2121
{
2222
"package": {
2323
"dependencyId": 0,
24-
"containValue": "Object"
24+
"containValue": "Value"
2525
},
2626
"id": 3
2727
},
2828
{
2929
"package": {
3030
"dependencyId": 0,
31-
"containValue": "User"
31+
"containValue": "String"
3232
},
3333
"id": 4
3434
},
3535
{
3636
"package": {
3737
"dependencyId": 0,
38-
"containValue": "String"
38+
"containValue": "Type"
3939
},
4040
"id": 5
4141
},
@@ -63,7 +63,7 @@
6363
{
6464
"package": {
6565
"dependencyId": 0,
66-
"containValue": "Tree"
66+
"containValue": "HandleInsert"
6767
},
6868
"id": 9
6969
},
@@ -84,88 +84,68 @@
8484
{
8585
"package": {
8686
"dependencyId": 0,
87-
"containValue": "SyncTextFile"
87+
"containValue": "HandleUpdate"
8888
},
8989
"id": 12
9090
},
9191
{
9292
"package": {
93-
"dependencyId": 0,
94-
"containValue": "Handler"
93+
"dependencyId": 3,
94+
"containValue": "UpdateHandler"
9595
},
9696
"id": 13
9797
},
9898
{
9999
"package": {
100100
"dependencyId": 0,
101-
"containValue": "dockerSupportsJs"
101+
"containValue": "Object"
102102
},
103103
"id": 14
104104
},
105105
{
106106
"package": {
107107
"dependencyId": 0,
108-
"containValue": "HandleInsert"
108+
"containValue": "User"
109109
},
110110
"id": 15
111111
},
112112
{
113113
"package": {
114114
"dependencyId": 0,
115-
"containValue": "HandleUpdate"
115+
"containValue": "SyncTextFile"
116116
},
117117
"id": 16
118118
},
119119
{
120120
"package": {
121-
"dependencyId": 3,
122-
"containValue": "UpdateHandler"
121+
"dependencyId": 0,
122+
"containValue": "Tree"
123123
},
124124
"id": 17
125125
},
126126
{
127-
"id": "ServiceAccount",
128-
"type": 1
129-
},
130-
{
131-
"id": "TypeOfValueOfServiceAccount",
132-
"type": 2,
133-
"from": "ServiceAccount",
134-
"to": 3
135-
},
136-
{
137-
"id": "UsesServiceAccount",
138-
"type": 1,
139-
"from": 4,
140-
"to": "ServiceAccount"
141-
},
142-
{
143-
"id": "PushNotification",
144-
"type": 1
145-
},
146-
{
147-
"id": "PushNotificationBody",
127+
"id": "PushNotificationNotifyInsertHandler",
148128
"type": 1,
149-
"from": "PushNotification",
150-
"to": "PushNotification"
129+
"from": 2,
130+
"to": "PushNotificationNotifyInsertHandlerCode"
151131
},
152132
{
153133
"id": "TypeOfValueOfPushNotificationBody",
154-
"type": 2,
134+
"type": 3,
155135
"from": "PushNotificationBody",
156-
"to": 5
136+
"to": 4
157137
},
158138
{
159139
"id": "PushNotificationTitle",
160-
"type": 1,
140+
"type": 5,
161141
"from": "PushNotification",
162142
"to": "PushNotification"
163143
},
164144
{
165145
"id": "TypeOfValueOfPushNotificationTitle",
166-
"type": 2,
146+
"type": 3,
167147
"from": "PushNotificationTitle",
168-
"to": 5
148+
"to": 4
169149
},
170150
{
171151
"id": "Notify",
@@ -180,28 +160,10 @@
180160
"to": 7
181161
},
182162
{
183-
"id": "WebPushCertificate",
184-
"type": 1
185-
},
186-
{
187-
"id": "UsesWebPushCertificate",
188-
"type": 1,
189-
"from": 4,
190-
"to": "WebPushCertificate"
191-
},
192-
{
193-
"id": "TypeOfValueOfWebPushCertificate",
194-
"type": 2,
195-
"from": "WebPushCertificate",
196-
"to": 5
197-
},
198-
{
199-
"id": "DeviceRegistrationToken",
200-
"type": 1
201-
},
202-
{
203-
"id": "PushNotificationTree",
204-
"type": 9
163+
"id": "HandlePushNotificationNotifyInsert",
164+
"type": 9,
165+
"from": "Notify",
166+
"to": "PushNotificationNotifyInsertHandler"
205167
},
206168
{
207169
"id": "TreeIncludeFromCurrentPushNotificationBody",
@@ -222,35 +184,73 @@
222184
"to": "PushNotification"
223185
},
224186
{
225-
"id": "PushNotificationNotifyInsertHandlerCode",
187+
"id": "HandleUpdateOfPushNotification",
226188
"type": 12,
227-
"value": {
228-
"value": "async ({ require, deep, data: { newLink: notifyLink, triggeredByLinkId } }) => {\n const firebaseAdmin = require('firebase-admin');\n\n const notificationLinkId = notifyLink.from_id;\n const deviceLinkId = notifyLink.to_id;\n\n const containTypeLinkId = await deep.id('@deep-foundation/core', 'Contain');\n\n const serviceAccount = await getServiceAccount({\n containTypeLinkId,\n triggeredByLinkId,\n });\n\n const firebaseApplication = await getFirebaseApplication({\n firebaseAdmin,\n serviceAccount,\n });\n const deviceRegistrationToken = await getDeviceRegistrationToken({\n containTypeLinkId,\n deviceLinkId,\n });\n const pushNotificationData = await getPushNotificationData({\n containTypeLinkId,\n deviceRegistrationToken,\n notificationLinkId,\n });\n\n await firebaseAdmin.messaging(firebaseApplication).send(pushNotificationData);\n await deep.insert({\n type_id: await deep.id(deep.linkId, 'Notified'),\n in: {\n data: {\n type_id: containTypeLinkId,\n from_id: triggeredByLinkId,\n },\n },\n from_id: notifyLink.id,\n to_id: deviceLinkId,\n });\n\n async function getServiceAccount({ containTypeLinkId, triggeredByLinkId }) {\n const serviceAccountTypeLinkId = await deep.id(\n deep.linkId,\n 'ServiceAccount'\n );\n const usesServiceAccountTypeLinkId = await deep.id(\n deep.linkId,\n 'UsesServiceAccount'\n );\n const selectData = {\n _or: [\n {\n type_id: serviceAccountTypeLinkId,\n in: {\n type_id: containTypeLinkId,\n from_id: triggeredByLinkId,\n },\n },\n {\n type_id: usesServiceAccountTypeLinkId,\n from_id: triggeredByLinkId,\n },\n ],\n };\n const { data } = await deep.select(selectData);\n if (data.length === 0) {\n throw new Error(\n `Select with data ${JSON.stringify(selectData)} returned empty result`\n );\n }\n let serviceAccountLink;\n const usesServiceAccountLinks = data.filter(\n (link) => link.type_id === usesServiceAccountTypeLinkId\n );\n if (usesServiceAccountLinks.length > 1) {\n throw new Error(\n `There must be only one link of type ${usesServiceAccountTypeLinkId} and from ${triggeredByLinkId}, instead there are ${usesServiceAccountLinks\n .map((link) => `##${link.id}`)\n .join(', ')}`\n );\n } else if (usesServiceAccountLinks.length === 1) {\n const usesServiceAccountLink = usesServiceAccountLinks[0];\n serviceAccountLink = data.find(\n (link) => link.id === usesServiceAccountLink.to_id\n );\n } else if (usesServiceAccountLinks.length === 0) {\n const serviceAccountLinks = data.filter(\n (link) => link.type_id === serviceAccountTypeLinkId\n );\n if (serviceAccountLinks.length > 1) {\n throw new Error(\n `There must be only one link of type ##${serviceAccountTypeLinkId} and contained by ##${triggeredByLinkId}, instead there are ${serviceAccountLinks\n .map((link) => `##${link.id}`)\n .join(', ')}`\n );\n } else if (serviceAccountLinks.length === 1) {\n serviceAccountLink = serviceAccountLinks[0];\n } else if (serviceAccountLinks.length === 0) {\n throw new Error(\n `A link of type ##${serviceAccountTypeLinkId} and contained by ##${triggeredByLinkId} is not found`\n );\n }\n }\n if (!serviceAccountLink) {\n throw new Error(\n `A link of type ##${usesServiceAccountTypeLinkId} and from ##${triggeredByLinkId} is not found`\n );\n }\n if (!serviceAccountLink.value?.value) {\n throw new Error(`##${serviceAccountLink.id} must have value`);\n }\n return serviceAccountLink.value.value;\n }\n\n async function getDeviceRegistrationToken({\n containTypeLinkId,\n deviceLinkId,\n }) {\n const deviceRegistrationTokenTypeLinkId = await deep.id(\n deep.linkId,\n 'DeviceRegistrationToken'\n );\n const selectData = {\n type_id: deviceRegistrationTokenTypeLinkId,\n in: {\n type_id: containTypeLinkId,\n from_id: deviceLinkId,\n },\n };\n const {\n data: [deviceRegistrationTokenLink],\n } = await deep.select(selectData);\n if (!deviceRegistrationTokenLink) {\n throw new Error(\n `##${deviceLinkId} must have contained a link of type ##${deviceRegistrationTokenTypeLinkId}. Select with data ${JSON.stringify(\n selectData\n )} returned empty result`\n );\n }\n if (!deviceRegistrationTokenLink.value?.value) {\n throw new Error(`##${deviceRegistrationTokenLink.id} must have value`);\n }\n return deviceRegistrationTokenLink.value.value;\n }\n\n async function getPushNotificationImageUrl({\n containTypeLinkId,\n notificationLinkId,\n }) {\n const notificationImageUrlTypeLinkId = await deep.id(\n deep.linkId,\n 'PushNotificationImageUrl'\n );\n const selectData = {\n type_id: notificationImageUrlTypeLinkId,\n in: {\n type_id: containTypeLinkId,\n from_id: notificationLinkId,\n },\n };\n const {\n data: [linkWithPushNotificationImageUrlString],\n } = await deep.select(selectData);\n if (!linkWithPushNotificationImageUrlString) {\n return undefined;\n }\n if (!linkWithPushNotificationImageUrlString.value?.value) {\n throw new Error(\n `##${linkWithPushNotificationImageUrlString.id} must have value`\n );\n }\n return linkWithPushNotificationImageUrlString.value.value;\n }\n\n async function getPushNotificationBody({ notificationLinkId }) {\n const notificationBodyTypeLinkId = await deep.id(\n deep.linkId,\n 'PushNotificationBody'\n );\n const selectData = {\n in: {\n type_id: notificationBodyTypeLinkId,\n from_id: notificationLinkId,\n },\n };\n const {\n data: [linkWithPushNotificationBodyString],\n } = await deep.select(selectData);\n if (!linkWithPushNotificationBodyString) {\n throw new Error(\n `A link of type ##${notificationBodyTypeLinkId} must exist`\n );\n }\n if (!linkWithPushNotificationBodyString.value?.value) {\n throw new Error(\n `##${linkWithPushNotificationBodyString.id} must have value`\n );\n }\n return linkWithPushNotificationBodyString.value.value;\n }\n\n async function getPushNotificationTitle({ notificationLinkId }) {\n const notificationTitleTypeLinkId = await deep.id(\n deep.linkId,\n 'PushNotificationTitle'\n );\n const selectData = {\n in: {\n type_id: {\n _eq: notificationTitleTypeLinkId,\n },\n from_id: {\n _eq: notificationLinkId,\n },\n },\n };\n const {\n data: [linkWithPushNotificationTitleString],\n } = await deep.select(selectData);\n if (!linkWithPushNotificationTitleString) {\n throw new Error(\n `A link of type ${notificationTitleTypeLinkId} must exist`\n );\n }\n if (!linkWithPushNotificationTitleString.value?.value) {\n throw new Error(\n `##${linkWithPushNotificationTitleString.id} must have value`\n );\n }\n return linkWithPushNotificationTitleString.value.value;\n }\n\n async function getPushNotificationData({\n notificationLinkId,\n containTypeLinkId,\n deviceRegistrationToken,\n }) {\n const pushNotificationData = {\n token: deviceRegistrationToken,\n notification: {\n title: await getPushNotificationTitle({ notificationLinkId }),\n body: await getPushNotificationBody({ notificationLinkId }),\n },\n };\n const imageUrl = await getPushNotificationImageUrl({\n containTypeLinkId,\n notificationLinkId,\n });\n if (imageUrl) {\n pushNotificationData.imageUrl = imageUrl;\n }\n return pushNotificationData;\n }\n\n async function getFirebaseApplication({ firebaseAdmin, serviceAccount }) {\n return firebaseAdmin.apps.length === 0\n ? firebaseAdmin.initializeApp({\n credential: firebaseAdmin.credential.cert(serviceAccount),\n })\n : firebaseAdmin.app();\n }\n};\n"
229-
}
189+
"from": "PushNotification",
190+
"to": 13
230191
},
231192
{
232-
"id": "PushNotificationNotifyInsertHandler",
233-
"type": 13,
234-
"from": 14,
235-
"to": "PushNotificationNotifyInsertHandlerCode"
193+
"id": "ServiceAccount",
194+
"type": 5
236195
},
237196
{
238-
"id": "HandlePushNotificationNotifyInsert",
239-
"type": 15,
240-
"from": "Notify",
241-
"to": "PushNotificationNotifyInsertHandler"
197+
"id": "TypeOfValueOfServiceAccount",
198+
"type": 3,
199+
"from": "ServiceAccount",
200+
"to": 14
242201
},
243202
{
244-
"id": "HandleUpdateOfPushNotification",
245-
"type": 16,
203+
"id": "UsesServiceAccount",
204+
"type": 5,
205+
"from": 15,
206+
"to": "ServiceAccount"
207+
},
208+
{
209+
"id": "PushNotification",
210+
"type": 5
211+
},
212+
{
213+
"id": "PushNotificationBody",
214+
"type": 5,
246215
"from": "PushNotification",
247-
"to": 17
216+
"to": "PushNotification"
248217
},
249218
{
250219
"id": "TypeOfValueOfPushNotification",
251-
"type": 2,
220+
"type": 3,
252221
"from": "PushNotification",
253-
"to": 3
222+
"to": 14
223+
},
224+
{
225+
"id": "WebPushCertificate",
226+
"type": 5
227+
},
228+
{
229+
"id": "UsesWebPushCertificate",
230+
"type": 5,
231+
"from": 15,
232+
"to": "WebPushCertificate"
233+
},
234+
{
235+
"id": "TypeOfValueOfWebPushCertificate",
236+
"type": 3,
237+
"from": "WebPushCertificate",
238+
"to": 4
239+
},
240+
{
241+
"id": "DeviceRegistrationToken",
242+
"type": 5
243+
},
244+
{
245+
"id": "PushNotificationNotifyInsertHandlerCode",
246+
"type": 16,
247+
"value": {
248+
"value": "async ({ require, deep, data: { newLink: notifyLink, triggeredByLinkId } }) => {\n const firebaseAdmin = require('firebase-admin');\n\n const notificationLinkId = notifyLink.from_id;\n const {data: [notificationLink]} = await deep.select(notificationLinkId)\n if(!notificationLink.value?.value) {\n throw new Error(`##${notificationLinkId} must have value`)\n }\n const title = notificationLink.value.value.title;\n if(!title) {\n throw new Error(`Object value of ##${notificationLinkId} must have title property`)\n }\n \n const body = notificationLink.value.value.body;\n if(!body) {\n throw new Error(`Object value of ##${notificationLinkId} must have body property`)\n }\n\n const deviceLinkId = notifyLink.to_id;\n\n const containTypeLinkId = await deep.id('@deep-foundation/core', 'Contain');\n\n const serviceAccount = await getServiceAccount({\n containTypeLinkId,\n triggeredByLinkId,\n });\n\n const firebaseApplication = await getFirebaseApplication({\n firebaseAdmin,\n serviceAccount,\n });\n\n const deviceRegistrationToken = await getDeviceRegistrationToken({\n containTypeLinkId,\n deviceLinkId,\n });\n \n const pushNotificationData = {\n token: deviceRegistrationToken,\n notification: {\n title: title,\n body: body,\n },\n };\n\n await firebaseAdmin.messaging(firebaseApplication).send(pushNotificationData);\n await deep.insert({\n type_id: await deep.id(deep.linkId, 'Notified'),\n in: {\n data: {\n type_id: containTypeLinkId,\n from_id: triggeredByLinkId,\n },\n },\n from_id: notifyLink.id,\n to_id: deviceLinkId,\n });\n\n async function getServiceAccount({ containTypeLinkId, triggeredByLinkId }) {\n const serviceAccountTypeLinkId = await deep.id(\n deep.linkId,\n 'ServiceAccount'\n );\n const usesServiceAccountTypeLinkId = await deep.id(\n deep.linkId,\n 'UsesServiceAccount'\n );\n const selectData = {\n _or: [\n {\n type_id: serviceAccountTypeLinkId,\n in: {\n type_id: containTypeLinkId,\n from_id: triggeredByLinkId,\n },\n },\n {\n type_id: usesServiceAccountTypeLinkId,\n from_id: triggeredByLinkId,\n },\n ],\n };\n const { data } = await deep.select(selectData);\n if (data.length === 0) {\n throw new Error(\n `Select with data ${JSON.stringify(selectData)} returned empty result`\n );\n }\n let serviceAccountLink;\n const usesServiceAccountLinks = data.filter(\n (link) => link.type_id === usesServiceAccountTypeLinkId\n );\n if (usesServiceAccountLinks.length > 1) {\n throw new Error(\n `There must be only one link of type ${usesServiceAccountTypeLinkId} and from ${triggeredByLinkId}, instead there are ${usesServiceAccountLinks\n .map((link) => `##${link.id}`)\n .join(', ')}`\n );\n } else if (usesServiceAccountLinks.length === 1) {\n const usesServiceAccountLink = usesServiceAccountLinks[0];\n serviceAccountLink = data.find(\n (link) => link.id === usesServiceAccountLink.to_id\n );\n } else if (usesServiceAccountLinks.length === 0) {\n const serviceAccountLinks = data.filter(\n (link) => link.type_id === serviceAccountTypeLinkId\n );\n if (serviceAccountLinks.length > 1) {\n throw new Error(\n `There must be only one link of type ##${serviceAccountTypeLinkId} and contained by ##${triggeredByLinkId}, instead there are ${serviceAccountLinks\n .map((link) => `##${link.id}`)\n .join(', ')}`\n );\n } else if (serviceAccountLinks.length === 1) {\n serviceAccountLink = serviceAccountLinks[0];\n } else if (serviceAccountLinks.length === 0) {\n throw new Error(\n `A link of type ##${serviceAccountTypeLinkId} and contained by ##${triggeredByLinkId} is not found`\n );\n }\n }\n if (!serviceAccountLink) {\n throw new Error(\n `A link of type ##${usesServiceAccountTypeLinkId} and from ##${triggeredByLinkId} is not found`\n );\n }\n if (!serviceAccountLink.value?.value) {\n throw new Error(`##${serviceAccountLink.id} must have value`);\n }\n return serviceAccountLink.value.value;\n }\n\n async function getDeviceRegistrationToken({\n containTypeLinkId,\n deviceLinkId,\n }) {\n const deviceRegistrationTokenTypeLinkId = await deep.id(\n deep.linkId,\n 'DeviceRegistrationToken'\n );\n const selectData = {\n type_id: deviceRegistrationTokenTypeLinkId,\n in: {\n type_id: containTypeLinkId,\n from_id: deviceLinkId,\n },\n };\n const {\n data: [deviceRegistrationTokenLink],\n } = await deep.select(selectData);\n if (!deviceRegistrationTokenLink) {\n throw new Error(\n `##${deviceLinkId} must have contained a link of type ##${deviceRegistrationTokenTypeLinkId}. Select with data ${JSON.stringify(\n selectData\n )} returned empty result`\n );\n }\n if (!deviceRegistrationTokenLink.value?.value) {\n throw new Error(`##${deviceRegistrationTokenLink.id} must have value`);\n }\n return deviceRegistrationTokenLink.value.value;\n }\n\n async function getFirebaseApplication({ firebaseAdmin, serviceAccount }) {\n return firebaseAdmin.apps.length === 0\n ? firebaseAdmin.initializeApp({\n credential: firebaseAdmin.credential.cert(serviceAccount),\n })\n : firebaseAdmin.app();\n }\n};\n"
249+
}
250+
},
251+
{
252+
"id": "PushNotificationTree",
253+
"type": 17
254254
}
255255
],
256256
"errors": [],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"keywords": [
44
"deep-package"
55
],
6-
"version": "14.0.3-dev.0",
6+
"version": "14.0.4",
77
"description": "Provides links for working with @firebase/messaging",
88
"repository": {
99
"type": "git",

0 commit comments

Comments
 (0)