@cloudcommerce/app-webhooks 0.14.1 → 0.15.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/.turbo/turbo-build.log
CHANGED
|
@@ -22,11 +22,18 @@ const sendWebhook = async (options, doc, urls, manualQueue, appId, customer, doc
|
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
24
|
logger.log(`> Sending ${isCart ? 'cart' : 'order'} notification`);
|
|
25
|
-
const token = options.webhook_token;
|
|
26
25
|
let headers;
|
|
27
|
-
if (
|
|
26
|
+
if (!process.env.WEBHOOKS_TOKEN) {
|
|
27
|
+
const webhookAppToken = options.webhook_token;
|
|
28
|
+
if (typeof webhookAppToken === 'string' && webhookAppToken) {
|
|
29
|
+
process.env.WEBHOOKS_TOKEN = webhookAppToken;
|
|
30
|
+
} else {
|
|
31
|
+
logger.warn('Missing webhooks token');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (process.env.WEBHOOKS_TOKEN) {
|
|
28
35
|
headers = {
|
|
29
|
-
Authorization: `Bearer ${
|
|
36
|
+
Authorization: `Bearer ${process.env.WEBHOOKS_TOKEN}`,
|
|
30
37
|
};
|
|
31
38
|
}
|
|
32
39
|
const body = {
|
|
@@ -70,9 +77,9 @@ const handleApiEvent = async ({
|
|
|
70
77
|
}
|
|
71
78
|
try {
|
|
72
79
|
if (appData.webhooks) {
|
|
73
|
-
let docId;
|
|
80
|
+
let docId = apiDoc._id;
|
|
74
81
|
let manualQueue = null;
|
|
75
|
-
|
|
82
|
+
const isCart = evName === 'carts-delayed';
|
|
76
83
|
if (evName === 'applications-dataSet') {
|
|
77
84
|
const body = appData;
|
|
78
85
|
if (body && Array.isArray(body.manual_queue) && body.manual_queue.length) {
|
|
@@ -83,9 +90,6 @@ const handleApiEvent = async ({
|
|
|
83
90
|
}
|
|
84
91
|
manualQueue.shift();
|
|
85
92
|
}
|
|
86
|
-
} else {
|
|
87
|
-
isCart = evName === 'carts-delayed';
|
|
88
|
-
docId = apiDoc._id;
|
|
89
93
|
}
|
|
90
94
|
if (docId) {
|
|
91
95
|
let customer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events-to-webhooks-app.js","sourceRoot":"","sources":["../src/events-to-webhooks-app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"events-to-webhooks-app.js","sourceRoot":"","sources":["../src/events-to-webhooks-app.ts"],"names":[],"mappings":"AAOA,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,GAAG,MAAM,oBAAoB,CAAC;AACrC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,iBAAiB,GAAG,KAAK,EAC7B,WAAyB,EACzB,KAAa,EACb,EAAE;IACF,IAAI,WAAW,EAAE;QACf,IAAI;YACF,MAAM,GAAG,CAAC,KAAK,CAAC,gBAAgB,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;YAClF,WAAW,GAAG,IAAI,CAAC;SACpB;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACnB;KACF;AACH,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,KAAK,EACvB,OAA6B,EAC7B,GAAwB,EACxB,IAAW,EACX,WAAyB,EACzB,KAAiB,EACjB,QAAoB,EACpB,KAAkB,EAClB,MAAgB,EAChB,EAAE;IACF,MAAM,GAAG,GAAG,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC;IAC3C,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC,EAAE;QACjE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACf,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAA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,QAAQ,EAAE,GAAG,OAAO,CAAC;oBAC7B,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;wBAC3B,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;4BACjC,MAAM,WAAW,CACf,OAAO,EACP,GAAG,EACH,IAAI,EACJ,WAAW,EACX,GAAG,CAAC,GAAG,EACP,QAAQ,EACR,KAAK,EACL,MAAM,CACP,CAAC;wBACJ,CAAC,CAAC,CAAC;qBACJ;oBACD,MAAM,WAAW,CACf,OAAO,EACP,GAAG,EACH,IAAI,EACJ,WAAW,EACX,GAAG,CAAC,GAAG,EACP,QAAQ,EACR,KAAK,EACL,MAAM,CACP,CAAC;oBACF,OAAO,IAAI,CAAC;iBACb;gBAED,MAAM,iBAAiB,CAAC,WAAW,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;aAC/C;SACF;QACD,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClB,OAAO,IAAI,CAAC;KACb;AACH,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/app-webhooks",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.15.0",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce app for general order webhooks",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"repository": {
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
"homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/apps/webhooks#readme",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"axios": "^1.4.0",
|
|
20
|
-
"firebase-admin": "^11.
|
|
21
|
-
"firebase-functions": "^4.4.
|
|
22
|
-
"@cloudcommerce/api": "0.
|
|
23
|
-
"@cloudcommerce/firebase": "0.
|
|
20
|
+
"firebase-admin": "^11.9.0",
|
|
21
|
+
"firebase-functions": "^4.4.1",
|
|
22
|
+
"@cloudcommerce/api": "0.15.0",
|
|
23
|
+
"@cloudcommerce/firebase": "0.15.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@firebase/app-types": "^0.9.0",
|
|
27
|
-
"@cloudcommerce/types": "0.
|
|
27
|
+
"@cloudcommerce/types": "0.15.0"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "bash ../../../scripts/build-lib.sh"
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ApiEventHandler } from '@cloudcommerce/firebase/lib/helpers/pubsub';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Carts,
|
|
4
|
+
Customers,
|
|
5
|
+
Orders,
|
|
6
|
+
ResourceId,
|
|
7
|
+
} from '@cloudcommerce/api/types';
|
|
3
8
|
import logger from 'firebase-functions/logger';
|
|
4
9
|
import api from '@cloudcommerce/api';
|
|
5
10
|
import axios from 'axios';
|
|
@@ -23,9 +28,9 @@ const sendWebhook = async (
|
|
|
23
28
|
doc: Record<string, any>,
|
|
24
29
|
urls: any[],
|
|
25
30
|
manualQueue: any[] | null,
|
|
26
|
-
appId:
|
|
31
|
+
appId: ResourceId,
|
|
27
32
|
customer?: Customers,
|
|
28
|
-
docId?:
|
|
33
|
+
docId?: ResourceId,
|
|
29
34
|
isCart?: boolean,
|
|
30
35
|
) => {
|
|
31
36
|
const url = options && options.webhook_uri;
|
|
@@ -42,12 +47,20 @@ const sendWebhook = async (
|
|
|
42
47
|
|
|
43
48
|
logger.log(`> Sending ${isCart ? 'cart' : 'order'} notification`);
|
|
44
49
|
|
|
45
|
-
const token = options.webhook_token;
|
|
46
50
|
let headers: { Authorization: string; } | undefined;
|
|
47
51
|
|
|
48
|
-
if (
|
|
52
|
+
if (!process.env.WEBHOOKS_TOKEN) {
|
|
53
|
+
const webhookAppToken = options.webhook_token
|
|
54
|
+
if (typeof webhookAppToken === 'string' && webhookAppToken) {
|
|
55
|
+
process.env.WEBHOOKS_TOKEN = webhookAppToken;
|
|
56
|
+
} else {
|
|
57
|
+
logger.warn('Missing webhooks token');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (process.env.WEBHOOKS_TOKEN) {
|
|
49
62
|
headers = {
|
|
50
|
-
Authorization: `Bearer ${
|
|
63
|
+
Authorization: `Bearer ${process.env.WEBHOOKS_TOKEN}`,
|
|
51
64
|
};
|
|
52
65
|
}
|
|
53
66
|
const body = {
|
|
@@ -100,9 +113,9 @@ const handleApiEvent: ApiEventHandler = async ({
|
|
|
100
113
|
|
|
101
114
|
try {
|
|
102
115
|
if (appData.webhooks) {
|
|
103
|
-
let docId
|
|
116
|
+
let docId = apiDoc._id as ResourceId;
|
|
104
117
|
let manualQueue: any[] | null = null;
|
|
105
|
-
|
|
118
|
+
const isCart = evName === 'carts-delayed';
|
|
106
119
|
|
|
107
120
|
if (evName === 'applications-dataSet') {
|
|
108
121
|
const body = appData;
|
|
@@ -110,13 +123,10 @@ const handleApiEvent: ApiEventHandler = async ({
|
|
|
110
123
|
manualQueue = body.manual_queue;
|
|
111
124
|
const nextId = manualQueue[0];
|
|
112
125
|
if (typeof nextId === 'string' && /[a-f0-9]{24}/.test(nextId)) {
|
|
113
|
-
docId = nextId.trim();
|
|
126
|
+
docId = nextId.trim() as ResourceId;
|
|
114
127
|
}
|
|
115
128
|
manualQueue.shift();
|
|
116
129
|
}
|
|
117
|
-
} else {
|
|
118
|
-
isCart = evName === 'carts-delayed';
|
|
119
|
-
docId = apiDoc._id;
|
|
120
130
|
}
|
|
121
131
|
|
|
122
132
|
if (docId) {
|