@segment/action-destinations 3.33.1-alpha.7 → 3.33.3-alpha.9
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/salesforce/generated-types.d.ts +1 -0
- package/dist/destinations/salesforce/index.js +11 -3
- package/dist/destinations/salesforce/index.js.map +1 -1
- package/dist/destinations/salesforce/lead/generated-types.d.ts +10 -3
- package/dist/destinations/salesforce/lead/index.d.ts +1 -1
- package/dist/destinations/salesforce/lead/index.js +66 -14
- package/dist/destinations/salesforce/lead/index.js.map +1 -1
- package/dist/destinations/salesforce/salesforce-operations.d.ts +4 -0
- package/dist/destinations/salesforce/salesforce-operations.js +15 -0
- package/dist/destinations/salesforce/salesforce-operations.js.map +1 -0
- package/dist/destinations/slack/postToChannel/index.d.ts +1 -1
- package/dist/destinations/slack/postToChannel/index.js +18 -9
- package/dist/destinations/slack/postToChannel/index.js.map +1 -1
- package/dist/destinations/webhook/__test__/webhook.test.js +51 -8
- package/dist/destinations/webhook/__test__/webhook.test.js.map +1 -1
- package/dist/destinations/webhook/send/index.d.ts +1 -1
- package/dist/destinations/webhook/send/index.js +11 -0
- package/dist/destinations/webhook/send/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -3,6 +3,7 @@ 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 salesforce_operations_1 = require("./salesforce-operations");
|
|
6
7
|
const lead_1 = __importDefault(require("./lead"));
|
|
7
8
|
const destination = {
|
|
8
9
|
name: 'Salesforce (Actions)',
|
|
@@ -10,7 +11,14 @@ const destination = {
|
|
|
10
11
|
mode: 'cloud',
|
|
11
12
|
authentication: {
|
|
12
13
|
scheme: 'oauth2',
|
|
13
|
-
fields: {
|
|
14
|
+
fields: {
|
|
15
|
+
instanceUrl: {
|
|
16
|
+
label: 'Instance URL',
|
|
17
|
+
description: 'Base Url of the request. For local testing only. refreshAccessToken will eventually be able to fetch this value via Oauth',
|
|
18
|
+
type: 'string',
|
|
19
|
+
required: true
|
|
20
|
+
}
|
|
21
|
+
},
|
|
14
22
|
refreshAccessToken: async (request, { auth }) => {
|
|
15
23
|
const res = await request('https://login.salesforce.com/services/oauth2/token', {
|
|
16
24
|
method: 'POST',
|
|
@@ -21,8 +29,8 @@ const destination = {
|
|
|
21
29
|
grant_type: 'refresh_token'
|
|
22
30
|
})
|
|
23
31
|
});
|
|
24
|
-
|
|
25
|
-
return { accessToken: res.data.
|
|
32
|
+
salesforce_operations_1.setInstanceUrl(res.data.instance_url);
|
|
33
|
+
return { accessToken: res.data.accessToken };
|
|
26
34
|
}
|
|
27
35
|
},
|
|
28
36
|
extendRequest({ auth }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/salesforce/index.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/salesforce/index.ts"],"names":[],"mappings":";;;;;AAEA,mEAAwD;AACxD,kDAAyB;AAKzB,MAAM,WAAW,GAAoC;IACnD,IAAI,EAAE,sBAAsB;IAC5B,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,OAAO;IAEb,cAAc,EAAE;QACd,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE;YACN,WAAW,EAAE;gBACX,KAAK,EAAE,cAAc;gBACrB,WAAW,EACT,2HAA2H;gBAC7H,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;aACf;SACF;QACD,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;YAE9C,MAAM,GAAG,GAAG,MAAM,OAAO,CACvB,oDAAoD,EACpD;gBACE,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,IAAI,eAAe,CAAC;oBACxB,aAAa,EAAE,IAAI,CAAC,YAAY;oBAChC,SAAS,EAAE,IAAI,CAAC,QAAQ;oBACxB,aAAa,EAAE,IAAI,CAAC,YAAY;oBAChC,UAAU,EAAE,eAAe;iBAC5B,CAAC;aACH,CACF,CAAA;YACD,sCAAc,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YACrC,OAAO,EAAE,WAAW,EAAE,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAA;QAC9C,CAAC;KACF;IACD,aAAa,CAAC,EAAE,IAAI,EAAE;QACpB,OAAO;YACL,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,IAAI,EAAE,WAAW,EAAE;aAC7C;SACF,CAAA;IACH,CAAC;IAED,OAAO,EAAE;QACP,IAAI,EAAJ,cAAI;KACL;CACF,CAAA;AAED,kBAAe,WAAW,CAAA"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
export interface Payload {
|
|
2
|
-
|
|
2
|
+
operation: string;
|
|
3
3
|
external_id_value?: string;
|
|
4
|
-
company
|
|
5
|
-
last_name
|
|
4
|
+
company: string;
|
|
5
|
+
last_name: string;
|
|
6
|
+
first_name?: string;
|
|
7
|
+
email?: string;
|
|
8
|
+
city?: string;
|
|
9
|
+
postal_code?: string;
|
|
10
|
+
country?: string;
|
|
11
|
+
street?: string;
|
|
12
|
+
state?: string;
|
|
6
13
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ActionDefinition } from '@segment/actions-core';
|
|
2
2
|
import type { Settings } from '../generated-types';
|
|
3
3
|
import type { Payload } from './generated-types';
|
|
4
4
|
declare const action: ActionDefinition<Settings, Payload>;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
4
|
+
const salesforce_operations_1 = require("../salesforce-operations");
|
|
3
5
|
const API_VERSION = 'v53.0';
|
|
4
6
|
const action = {
|
|
5
7
|
title: 'Lead',
|
|
6
8
|
description: 'Lead action',
|
|
7
9
|
fields: {
|
|
8
|
-
|
|
9
|
-
label: '
|
|
10
|
-
description: '
|
|
10
|
+
operation: {
|
|
11
|
+
label: 'Operation',
|
|
12
|
+
description: 'Operation',
|
|
11
13
|
type: 'string',
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
required: true,
|
|
15
|
+
choices: [{ label: 'Create', value: 'create' }]
|
|
14
16
|
},
|
|
15
17
|
external_id_value: {
|
|
16
18
|
label: 'External ID Value',
|
|
@@ -20,22 +22,72 @@ const action = {
|
|
|
20
22
|
company: {
|
|
21
23
|
label: 'Company',
|
|
22
24
|
description: 'Company',
|
|
23
|
-
type: 'string'
|
|
25
|
+
type: 'string',
|
|
26
|
+
required: true
|
|
24
27
|
},
|
|
25
28
|
last_name: {
|
|
26
29
|
label: 'Last Name',
|
|
27
|
-
description: '',
|
|
30
|
+
description: 'Last Name',
|
|
31
|
+
type: 'string',
|
|
32
|
+
required: true
|
|
33
|
+
},
|
|
34
|
+
first_name: {
|
|
35
|
+
label: 'First Name',
|
|
36
|
+
description: 'First Name',
|
|
37
|
+
type: 'string'
|
|
38
|
+
},
|
|
39
|
+
email: {
|
|
40
|
+
label: 'Email',
|
|
41
|
+
description: 'Email',
|
|
42
|
+
type: 'string'
|
|
43
|
+
},
|
|
44
|
+
city: {
|
|
45
|
+
label: 'City',
|
|
46
|
+
description: 'City',
|
|
47
|
+
type: 'string'
|
|
48
|
+
},
|
|
49
|
+
postal_code: {
|
|
50
|
+
label: 'Postal Code',
|
|
51
|
+
description: 'Postal Code',
|
|
52
|
+
type: 'string'
|
|
53
|
+
},
|
|
54
|
+
country: {
|
|
55
|
+
label: 'Country',
|
|
56
|
+
description: 'Country',
|
|
57
|
+
type: 'string'
|
|
58
|
+
},
|
|
59
|
+
street: {
|
|
60
|
+
label: 'Street',
|
|
61
|
+
description: 'Street',
|
|
62
|
+
type: 'string'
|
|
63
|
+
},
|
|
64
|
+
state: {
|
|
65
|
+
label: 'State',
|
|
66
|
+
description: 'State',
|
|
28
67
|
type: 'string'
|
|
29
68
|
}
|
|
30
69
|
},
|
|
31
70
|
perform: (request, { payload }) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
71
|
+
const instanceUrl = salesforce_operations_1.getInstanceUrl();
|
|
72
|
+
if (!instanceUrl) {
|
|
73
|
+
throw new actions_core_1.IntegrationError('Oauth Error', 'Missing Instance URL', 400);
|
|
74
|
+
}
|
|
75
|
+
if (payload.operation === 'create') {
|
|
76
|
+
return request(`${instanceUrl}/services/data/${API_VERSION}/sobjects/Lead`, {
|
|
77
|
+
method: 'post',
|
|
78
|
+
json: {
|
|
79
|
+
LastName: payload.last_name,
|
|
80
|
+
Company: payload.company,
|
|
81
|
+
FirstName: payload.first_name,
|
|
82
|
+
State: payload.state,
|
|
83
|
+
Street: payload.street,
|
|
84
|
+
Country: payload.country,
|
|
85
|
+
PostalCode: payload.postal_code,
|
|
86
|
+
City: payload.city,
|
|
87
|
+
Email: payload.email
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
39
91
|
}
|
|
40
92
|
};
|
|
41
93
|
exports.default = action;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/salesforce/lead/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/salesforce/lead/index.ts"],"names":[],"mappings":";;AAAA,wDAA0E;AAG1E,oEAAyD;AAEzD,MAAM,WAAW,GAAG,OAAO,CAAA;AAC3B,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,MAAM;IACb,WAAW,EAAE,aAAa;IAC1B,MAAM,EAAE;QACN,SAAS,EAAE;YACT,KAAK,EAAE,WAAW;YAClB,WAA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,WAAW,GAAG,sCAAc,EAAE,CAAA;QACpC,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,+BAAgB,CAAC,aAAa,EAAE,sBAAsB,EAAE,GAAG,CAAC,CAAA;SACvE;QAED,IAAI,OAAO,CAAC,SAAS,KAAK,QAAQ,EAAE;YAClC,OAAO,OAAO,CAAC,GAAG,WAAW,kBAAkB,WAAW,gBAAgB,EAAE;gBAC1E,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE;oBACJ,QAAQ,EAAE,OAAO,CAAC,SAAS;oBAC3B,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,SAAS,EAAE,OAAO,CAAC,UAAU;oBAC7B,KAAK,EAAE,OAAO,CAAC,KAAK;oBACpB,MAAM,EAAE,OAAO,CAAC,MAAM;oBACtB,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,UAAU,EAAE,OAAO,CAAC,WAAW;oBAC/B,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,KAAK,EAAE,OAAO,CAAC,KAAK;iBACrB;aACF,CAAC,CAAA;SACH;IACH,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setInstanceUrl = exports.getInstanceUrl = void 0;
|
|
4
|
+
let instance_url = null;
|
|
5
|
+
const getInstanceUrl = () => {
|
|
6
|
+
console.log('get', instance_url);
|
|
7
|
+
return instance_url;
|
|
8
|
+
};
|
|
9
|
+
exports.getInstanceUrl = getInstanceUrl;
|
|
10
|
+
const setInstanceUrl = (value) => {
|
|
11
|
+
console.log('set', instance_url);
|
|
12
|
+
instance_url = value;
|
|
13
|
+
};
|
|
14
|
+
exports.setInstanceUrl = setInstanceUrl;
|
|
15
|
+
//# sourceMappingURL=salesforce-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"salesforce-operations.js","sourceRoot":"","sources":["../../../src/destinations/salesforce/salesforce-operations.ts"],"names":[],"mappings":";;;AAEA,IAAI,YAAY,GAAiB,IAAI,CAAA;AAE9B,MAAM,cAAc,GAAG,GAAiB,EAAE;IAC/C,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;IAChC,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAHY,QAAA,cAAc,kBAG1B;AAEM,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE;IAC9C,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;IAChC,YAAY,GAAG,KAAK,CAAA;AACtB,CAAC,CAAA;AAHY,QAAA,cAAc,kBAG1B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ActionDefinition } from '@segment/actions-core';
|
|
2
2
|
import type { Settings } from '../generated-types';
|
|
3
3
|
import type { Payload } from './generated-types';
|
|
4
4
|
declare const action: ActionDefinition<Settings, Payload>;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
4
|
+
function isValidSlackUrl(webhookUrl) {
|
|
5
|
+
return /^https:\/\/[a-zA-Z0-9.-]+\.slack.com[/a-zA-Z0-9]+$/.test(webhookUrl);
|
|
6
|
+
}
|
|
3
7
|
const action = {
|
|
4
8
|
title: 'Post Message',
|
|
5
9
|
description: 'Post a message to the specified Slack workspace and channel when the associated trigger criteria are met.',
|
|
@@ -36,15 +40,20 @@ const action = {
|
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
perform: (request, { payload }) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
if (!isValidSlackUrl(payload.url)) {
|
|
44
|
+
throw new actions_core_1.IntegrationError('Invalid Slack URL', 'Bad Request', 400);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return request(payload.url, {
|
|
48
|
+
method: 'post',
|
|
49
|
+
json: {
|
|
50
|
+
channel: payload.channel,
|
|
51
|
+
text: payload.text,
|
|
52
|
+
username: payload.username,
|
|
53
|
+
icon_url: payload.icon_url
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
48
57
|
}
|
|
49
58
|
};
|
|
50
59
|
exports.default = action;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/slack/postToChannel/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/slack/postToChannel/index.ts"],"names":[],"mappings":";;AAAA,wDAA0E;AAI1E,SAAS,eAAe,CAAC,UAAkB;IACzC,OAAO,oDAAoD,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AAC9E,CAAC;AAED,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,cAAc;IACrB,WAAW,EACT,2GAA2G;IAC7G,MAAM,EAAE;QACN,GAAG,EAAE;YACH,KAAK,EAAE,aAAa;YACpB,WAAW,EAAE,4EAA4E;YACzF,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,KAAK;SACd;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,SAAS;YAChB,QAAQ,EAAE,IAAI;YACd,WAAW,EACT,kIAAkI;YACpI,IAAI,EAAE,MAAM;SACb;QACD,OAAO,EAAE;YACP,KAAK,EAAE,SAAS;YAChB,WAAW,EACT,uHAAuH;YACzH,IAAI,EAAE,QAAQ;SACf;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,MAAM;YACb,WAAW,EAAE,mCAAmC;YAChD,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,SAAS;SACnB;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,UAAU;YACjB,WAAW,EAAE,qDAAqD;YAClE,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,uCAAuC;SACjD;KACF;IAED,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QAChC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACjC,MAAM,IAAI,+BAAgB,CAAC,mBAAmB,EAAE,aAAa,EAAE,GAAG,CAAC,CAAA;SACpE;aAAM;YACL,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE;gBAC1B,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE;oBACJ,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,QAAQ,EAAE,OAAO,CAAC,QAAQ;oBAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ;iBAC3B;aACF,CAAC,CAAA;SACH;IACH,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -11,19 +11,18 @@ const timestamp = new Date().toISOString();
|
|
|
11
11
|
describe('Webhook', () => {
|
|
12
12
|
describe('send', () => {
|
|
13
13
|
it('should work with default mapping', async () => {
|
|
14
|
-
const url = 'https://
|
|
15
|
-
const path = '/1234';
|
|
14
|
+
const url = 'https://mme-e2e.segment.com';
|
|
16
15
|
const event = actions_core_1.createTestEvent({
|
|
17
16
|
timestamp,
|
|
18
17
|
event: 'Test Event'
|
|
19
18
|
});
|
|
20
19
|
nock_1.default(url)
|
|
21
|
-
.post(
|
|
20
|
+
.post('/', event)
|
|
22
21
|
.reply(200);
|
|
23
22
|
const responses = await testDestination.testAction('send', {
|
|
24
23
|
event,
|
|
25
24
|
mapping: {
|
|
26
|
-
url
|
|
25
|
+
url
|
|
27
26
|
},
|
|
28
27
|
useDefaultMappings: true
|
|
29
28
|
});
|
|
@@ -31,18 +30,17 @@ describe('Webhook', () => {
|
|
|
31
30
|
expect(responses[0].status).toBe(200);
|
|
32
31
|
});
|
|
33
32
|
it('supports customizations', async () => {
|
|
34
|
-
const url = 'https://
|
|
35
|
-
const path = '/1234';
|
|
33
|
+
const url = 'https://mme-e2e.segment.build';
|
|
36
34
|
const event = actions_core_1.createTestEvent({
|
|
37
35
|
timestamp,
|
|
38
36
|
event: 'Test Event'
|
|
39
37
|
});
|
|
40
38
|
const data = { cool: true };
|
|
41
|
-
nock_1.default(url).put(
|
|
39
|
+
nock_1.default(url).put('/', data).reply(200);
|
|
42
40
|
const responses = await testDestination.testAction('send', {
|
|
43
41
|
event,
|
|
44
42
|
mapping: {
|
|
45
|
-
url
|
|
43
|
+
url,
|
|
46
44
|
method: 'PUT',
|
|
47
45
|
data: { cool: true }
|
|
48
46
|
}
|
|
@@ -50,6 +48,51 @@ describe('Webhook', () => {
|
|
|
50
48
|
expect(responses.length).toBe(1);
|
|
51
49
|
expect(responses[0].status).toBe(200);
|
|
52
50
|
});
|
|
51
|
+
it('supports customizations', async () => {
|
|
52
|
+
const url = 'https://mme-e2e.segment.build';
|
|
53
|
+
const event = actions_core_1.createTestEvent({
|
|
54
|
+
timestamp,
|
|
55
|
+
event: 'Test Event'
|
|
56
|
+
});
|
|
57
|
+
const data = { cool: true };
|
|
58
|
+
nock_1.default(url).put('/', data).reply(200);
|
|
59
|
+
const responses = await testDestination.testAction('send', {
|
|
60
|
+
event,
|
|
61
|
+
mapping: {
|
|
62
|
+
url,
|
|
63
|
+
method: 'PUT',
|
|
64
|
+
data: { cool: true }
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
expect(responses.length).toBe(1);
|
|
68
|
+
expect(responses[0].status).toBe(200);
|
|
69
|
+
});
|
|
70
|
+
it('restricts usage to mme-e2e urls', async () => {
|
|
71
|
+
const url = 'https://api.acme.com/webhook';
|
|
72
|
+
const event = actions_core_1.createTestEvent({
|
|
73
|
+
timestamp,
|
|
74
|
+
event: 'Test Event'
|
|
75
|
+
});
|
|
76
|
+
const data = { cool: true };
|
|
77
|
+
nock_1.default(url).put('/', data).reply(200);
|
|
78
|
+
try {
|
|
79
|
+
await testDestination.testAction('send', {
|
|
80
|
+
event,
|
|
81
|
+
mapping: {
|
|
82
|
+
url,
|
|
83
|
+
method: 'PUT',
|
|
84
|
+
data: { cool: true }
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
fail('expected testAction to reject');
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
const error = err;
|
|
91
|
+
expect(error.status).toBe(400);
|
|
92
|
+
expect(error.code).toBe('Bad Request');
|
|
93
|
+
expect(error.message).toBe("invalid url 'https://api.acme.com/webhook'");
|
|
94
|
+
}
|
|
95
|
+
});
|
|
53
96
|
});
|
|
54
97
|
});
|
|
55
98
|
//# 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,
|
|
1
|
+
{"version":3,"file":"webhook.test.js","sourceRoot":"","sources":["../../../../src/destinations/webhook/__test__/webhook.test.ts"],"names":[],"mappings":";;;;;AAAA,gDAAuB;AACvB,wDAAgG;AAChG,qDAA8B;AAE9B,MAAM,eAAe,GAAG,oCAAqB,CAAC,eAAO,CAAC,CAAA;AACtD,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;AAE1C,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;QACpB,EAAE,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;YAChD,MAAM,GAAG,GAAG,6BAA6B,CAAA;YACzC,MAAM,KAAK,GAAG,8BAAe,CAAC;gBAC5B,SAAS;gBACT,KAAK,EAAE,YAAY;aACpB,CAAC,CAAA;YAEF,cAAI,CAAC,GAAG,CAAC;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AI,EAAE,IAAI,EAAE;qBACrB;iBACF,CAAC,CAAA;gBACF,IAAI,CAAC,+BAA+B,CAAC,CAAA;aACtC;YAAC,OAAO,GAAG,EAAE;gBACZ,MAAM,KAAK,GAAG,GAAuB,CAAA;gBACrC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;gBAC9B,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;gBACtC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAA;aACzE;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ActionDefinition } from '@segment/actions-core';
|
|
2
2
|
import type { Settings } from '../generated-types';
|
|
3
3
|
import type { Payload } from './generated-types';
|
|
4
4
|
declare const action: ActionDefinition<Settings, Payload>;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
4
|
+
const MME_E2E_URLS = [
|
|
5
|
+
'https://mme-e2e.segment.com',
|
|
6
|
+
'https://mme-e2e.segment.build'
|
|
7
|
+
];
|
|
3
8
|
const action = {
|
|
4
9
|
title: 'Send',
|
|
5
10
|
description: 'Send an HTTP request.',
|
|
@@ -33,6 +38,9 @@ const action = {
|
|
|
33
38
|
}
|
|
34
39
|
},
|
|
35
40
|
perform: (request, { payload }) => {
|
|
41
|
+
if (!MME_E2E_URLS.includes(payload.url)) {
|
|
42
|
+
throw new actions_core_1.IntegrationError(`invalid url '${payload.url}'`, 'Bad Request', 400);
|
|
43
|
+
}
|
|
36
44
|
return request(payload.url, {
|
|
37
45
|
method: payload.method,
|
|
38
46
|
json: payload.data
|
|
@@ -40,6 +48,9 @@ const action = {
|
|
|
40
48
|
},
|
|
41
49
|
performBatch: (request, { payload }) => {
|
|
42
50
|
const { url, method } = payload[0];
|
|
51
|
+
if (!MME_E2E_URLS.includes(url)) {
|
|
52
|
+
throw new actions_core_1.IntegrationError(`invalid url '${url}'`, 'Bad Request', 400);
|
|
53
|
+
}
|
|
43
54
|
return request(url, {
|
|
44
55
|
method: method,
|
|
45
56
|
json: payload.map(({ data }) => data)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/webhook/send/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/webhook/send/index.ts"],"names":[],"mappings":";;AAAA,wDAA0E;AAM1E,MAAM,YAAY,GAAG;IACnB,6BAA6B;IAC7B,+BAA+B;CAChC,CAAA;AAED,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,MAAM;IACb,WAAW,EAAE,uBAAuB;IACpC,MAAM,EAAE;QACN,GAAG,EAAE;YACH,KAAK,EAAE,KAAK;YACZ,WAAW,EAAE,yBAAyB;YACtC,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,KAAK;SACd;QACD,MAAM,EAAE;YACN,KAAK,EAAE,QAAQ;YACf,WAAW,EAAE,qBAAqB;YAClC,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;gBAChC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;gBAC9B,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;gBAClC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;gBACpC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;aAC/B;YACD,O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and definitions.",
|
|
4
|
-
"version": "3.33.
|
|
4
|
+
"version": "3.33.3-alpha.9",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/segmentio/action-destinations",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@amplitude/ua-parser-js": "^0.7.25",
|
|
41
|
-
"@segment/actions-core": "^3.21.2-alpha.
|
|
41
|
+
"@segment/actions-core": "^3.21.2-alpha.9",
|
|
42
42
|
"dayjs": "^1.10.7",
|
|
43
43
|
"lodash": "^4.17.21",
|
|
44
44
|
"mustache": "^4.2.0"
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"<rootDir>/test/setup-after-env.ts"
|
|
59
59
|
]
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "b0fae6247cea7ee4ffc59fc7da654cd4450427e4"
|
|
62
62
|
}
|