@segment/action-destinations 3.79.0 → 3.79.1-alpha.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/destinations/webhook/__test__/webhook.test.js +34 -9
- package/dist/destinations/webhook/__test__/webhook.test.js.map +1 -1
- package/dist/destinations/webhook/generated-types.d.ts +1 -0
- package/dist/destinations/webhook/index.js +20 -0
- package/dist/destinations/webhook/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -6,16 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const nock_1 = __importDefault(require("nock"));
|
|
7
7
|
const actions_core_1 = require("@segment/actions-core");
|
|
8
8
|
const index_1 = __importDefault(require("../index"));
|
|
9
|
+
const crypto_1 = require("crypto");
|
|
9
10
|
const testDestination = actions_core_1.createTestIntegration(index_1.default);
|
|
10
|
-
const timestamp = new Date().toISOString();
|
|
11
11
|
describe('Webhook', () => {
|
|
12
12
|
describe('send', () => {
|
|
13
13
|
it('should work with default mapping', async () => {
|
|
14
14
|
const url = 'https://example.com';
|
|
15
|
-
const event = actions_core_1.createTestEvent(
|
|
16
|
-
timestamp,
|
|
17
|
-
event: 'Test Event'
|
|
18
|
-
});
|
|
15
|
+
const event = actions_core_1.createTestEvent();
|
|
19
16
|
nock_1.default(url)
|
|
20
17
|
.post('/', event)
|
|
21
18
|
.reply(200);
|
|
@@ -31,10 +28,7 @@ describe('Webhook', () => {
|
|
|
31
28
|
});
|
|
32
29
|
it('supports customizations', async () => {
|
|
33
30
|
const url = 'https://example.build';
|
|
34
|
-
const event = actions_core_1.createTestEvent(
|
|
35
|
-
timestamp,
|
|
36
|
-
event: 'Test Event'
|
|
37
|
-
});
|
|
31
|
+
const event = actions_core_1.createTestEvent();
|
|
38
32
|
const headerField = 'Custom-Header';
|
|
39
33
|
const headerValue = 'Custom-Value';
|
|
40
34
|
const data = { cool: true };
|
|
@@ -51,6 +45,37 @@ describe('Webhook', () => {
|
|
|
51
45
|
expect(responses.length).toBe(1);
|
|
52
46
|
expect(responses[0].status).toBe(200);
|
|
53
47
|
});
|
|
48
|
+
it('supports request signing', async () => {
|
|
49
|
+
const url = 'https://example.com';
|
|
50
|
+
const event = actions_core_1.createTestEvent({
|
|
51
|
+
properties: { cool: true }
|
|
52
|
+
});
|
|
53
|
+
const payload = JSON.stringify(event.properties);
|
|
54
|
+
const sharedSecret = 'abc123';
|
|
55
|
+
nock_1.default(url)
|
|
56
|
+
.post('/', payload)
|
|
57
|
+
.reply(async function (_uri, body) {
|
|
58
|
+
const bodyString = JSON.stringify(body);
|
|
59
|
+
const expectSignature = this.req.headers['x-signature'][0];
|
|
60
|
+
const actualSignature = crypto_1.createHmac('sha1', sharedSecret).update(bodyString).digest('hex');
|
|
61
|
+
if (expectSignature.length !== actualSignature.length ||
|
|
62
|
+
!crypto_1.timingSafeEqual(Buffer.from(actualSignature, 'hex'), Buffer.from(expectSignature, 'hex'))) {
|
|
63
|
+
return [400, 'Invalid signature'];
|
|
64
|
+
}
|
|
65
|
+
return [200, 'OK'];
|
|
66
|
+
});
|
|
67
|
+
const responses = await testDestination.testAction('send', {
|
|
68
|
+
event,
|
|
69
|
+
mapping: {
|
|
70
|
+
url,
|
|
71
|
+
data: { '@path': '$.properties' }
|
|
72
|
+
},
|
|
73
|
+
settings: { sharedSecret },
|
|
74
|
+
useDefaultMappings: true
|
|
75
|
+
});
|
|
76
|
+
expect(responses.length).toBe(1);
|
|
77
|
+
expect(responses[0].status).toBe(200);
|
|
78
|
+
});
|
|
54
79
|
});
|
|
55
80
|
});
|
|
56
81
|
//# sourceMappingURL=webhook.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.test.js","sourceRoot":"","sources":["../../../../src/destinations/webhook/__test__/webhook.test.ts"],"names":[],"mappings":";;;;;AAAA,gDAAuB;AACvB,wDAA8E;AAC9E,qDAA8B;
|
|
1
|
+
{"version":3,"file":"webhook.test.js","sourceRoot":"","s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C,MAAM,KAAK,eAAe,CAAC,MAAM;oBACjD,CAAC,wBAAe,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,EAC1F;oBACA,OAAO,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAA;iBAClC;gBAED,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;YACpB,CAAC,CAAC,CAAA;YAEJ,MAAM,SAAS,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC,MAAM,EAAE;gBACzD,KAAK;gBACL,OAAO,EAAE;oBACP,GAAG;oBACH,IAAI,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE;iBAClC;gBACD,QAAQ,EAAE,EAAE,YAAY,EAAE;gBAC1B,kBAAkB,EAAE,IAAI;aACzB,CAAC,CAAA;YAEF,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YAChC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACvC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -3,11 +3,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
6
7
|
const send_1 = __importDefault(require("./send"));
|
|
7
8
|
const destination = {
|
|
8
9
|
name: 'Webhook',
|
|
9
10
|
slug: 'actions-webhook',
|
|
10
11
|
mode: 'cloud',
|
|
12
|
+
authentication: {
|
|
13
|
+
scheme: 'custom',
|
|
14
|
+
fields: {
|
|
15
|
+
sharedSecret: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
label: 'Shared Secret',
|
|
18
|
+
description: 'If set, Segment will sign requests with an HMAC in the "X-Signature" request header. The HMAC is a hex-encoded SHA1 hash generated using this shared secret and the request body.'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
extendRequest: ({ settings, payload }) => {
|
|
23
|
+
if (settings.sharedSecret && payload?.data) {
|
|
24
|
+
const digest = crypto_1.createHmac('sha1', settings.sharedSecret)
|
|
25
|
+
.update(JSON.stringify(payload.data), 'utf8')
|
|
26
|
+
.digest('hex');
|
|
27
|
+
return { headers: { 'X-Signature': digest } };
|
|
28
|
+
}
|
|
29
|
+
return {};
|
|
30
|
+
},
|
|
11
31
|
actions: {
|
|
12
32
|
send: send_1.default
|
|
13
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/webhook/index.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/webhook/index.ts"],"names":[],"mappings":";;;;;AAEA,mCAAmC;AAEnC,kDAAyB;AAEzB,MAAM,WAAW,GAAoC;IACnD,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,iBAAiB;IACvB,IAAI,EAAE,OAAO;IACb,cAAc,EAAE;QACd,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE;YACN,YAAY,EAAE;gBACZ,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,eAAe;gBACtB,WAAW,EACT,mLAAmL;aACtL;SACF;KACF;IACD,aAAa,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;QACvC,IAAI,QAAQ,CAAC,YAAY,IAAI,OAAO,EAAE,IAAI,EAAE;YAC1C,MAAM,MAAM,GAAG,mBAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC;iBACrD,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;iBAC5C,MAAM,CAAC,KAAK,CAAC,CAAA;YAChB,OAAO,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,EAAE,CAAA;SAC9C;QACD,OAAO,EAAE,CAAA;IACX,CAAC;IACD,OAAO,EAAE;QACP,IAAI,EAAJ,cAAI;KACL;CACF,CAAA;AAED,kBAAe,WAAW,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segment/action-destinations",
|
|
3
3
|
"description": "Destination Actions engine and definitions.",
|
|
4
|
-
"version": "3.79.
|
|
4
|
+
"version": "3.79.1-alpha.1",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/segmentio/action-destinations",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@amplitude/ua-parser-js": "^0.7.25",
|
|
40
40
|
"@segment/a1-notation": "^2.1.4",
|
|
41
|
-
"@segment/actions-core": "^3.27.
|
|
42
|
-
"@segment/actions-shared": "^1.10.
|
|
41
|
+
"@segment/actions-core": "^3.27.1-alpha.1",
|
|
42
|
+
"@segment/actions-shared": "^1.10.1-alpha.1",
|
|
43
43
|
"cheerio": "^1.0.0-rc.10",
|
|
44
44
|
"dayjs": "^1.10.7",
|
|
45
45
|
"escape-goat": "^3",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"lcov"
|
|
66
66
|
]
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "850844a8e31bfc5bb016795493018ec76a059991"
|
|
69
69
|
}
|