@segment/action-destinations 3.74.1-alpha.1 → 3.74.1-alpha.12
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/gainsight-px-cloud-action/index.js +1 -1
- package/dist/destinations/google-analytics-4/addPaymentInfo/index.js +2 -2
- package/dist/destinations/google-analytics-4/addPaymentInfo/index.js.map +1 -1
- package/dist/destinations/google-analytics-4/addToCart/index.js +1 -1
- package/dist/destinations/google-analytics-4/addToCart/index.js.map +1 -1
- package/dist/destinations/google-analytics-4/addToWishlist/index.js +2 -2
- package/dist/destinations/google-analytics-4/addToWishlist/index.js.map +1 -1
- package/dist/destinations/google-analytics-4/beginCheckout/index.js +2 -2
- package/dist/destinations/google-analytics-4/beginCheckout/index.js.map +1 -1
- package/dist/destinations/google-analytics-4/generateLead/index.js +1 -1
- package/dist/destinations/google-analytics-4/generateLead/index.js.map +1 -1
- package/dist/destinations/google-analytics-4/purchase/index.js +2 -2
- package/dist/destinations/google-analytics-4/purchase/index.js.map +1 -1
- package/dist/destinations/google-analytics-4/refund/index.js +2 -2
- package/dist/destinations/google-analytics-4/refund/index.js.map +1 -1
- package/dist/destinations/google-analytics-4/removeFromCart/index.js +2 -2
- package/dist/destinations/google-analytics-4/removeFromCart/index.js.map +1 -1
- package/dist/destinations/google-analytics-4/selectItem/index.js +1 -1
- package/dist/destinations/google-analytics-4/selectItem/index.js.map +1 -1
- package/dist/destinations/google-analytics-4/selectPromotion/index.js +1 -1
- package/dist/destinations/google-analytics-4/selectPromotion/index.js.map +1 -1
- package/dist/destinations/google-analytics-4/viewCart/index.js +2 -2
- package/dist/destinations/google-analytics-4/viewCart/index.js.map +1 -1
- package/dist/destinations/google-analytics-4/viewItem/index.js +2 -2
- package/dist/destinations/google-analytics-4/viewItem/index.js.map +1 -1
- package/dist/destinations/google-analytics-4/viewItemList/index.js +1 -1
- package/dist/destinations/google-analytics-4/viewItemList/index.js.map +1 -1
- package/dist/destinations/google-analytics-4/viewPromotion/index.js +1 -1
- package/dist/destinations/google-analytics-4/viewPromotion/index.js.map +1 -1
- package/dist/destinations/google-sheets/constants.d.ts +3 -0
- package/dist/destinations/google-sheets/constants.js +7 -0
- package/dist/destinations/google-sheets/constants.js.map +1 -0
- package/dist/destinations/google-sheets/generated-types.d.ts +2 -0
- package/dist/destinations/google-sheets/generated-types.js +3 -0
- package/dist/destinations/google-sheets/generated-types.js.map +1 -0
- package/dist/destinations/google-sheets/googleapis/index.d.ts +17 -0
- package/dist/destinations/google-sheets/googleapis/index.js +34 -0
- package/dist/destinations/google-sheets/googleapis/index.js.map +1 -0
- package/dist/destinations/google-sheets/index.d.ts +4 -0
- package/dist/destinations/google-sheets/index.js +27 -0
- package/dist/destinations/google-sheets/index.js.map +1 -0
- package/dist/destinations/google-sheets/postSheet/generated-types.d.ts +10 -0
- package/dist/destinations/google-sheets/postSheet/generated-types.js +3 -0
- package/dist/destinations/google-sheets/postSheet/generated-types.js.map +1 -0
- package/dist/destinations/google-sheets/postSheet/index.d.ts +5 -0
- package/dist/destinations/google-sheets/postSheet/index.js +71 -0
- package/dist/destinations/google-sheets/postSheet/index.js.map +1 -0
- package/dist/destinations/google-sheets/postSheet/operations.d.ts +10 -0
- package/dist/destinations/google-sheets/postSheet/operations.js +96 -0
- package/dist/destinations/google-sheets/postSheet/operations.js.map +1 -0
- package/dist/destinations/personas-messaging-sendgrid/generated-types.d.ts +8 -0
- package/dist/destinations/personas-messaging-sendgrid/generated-types.js +3 -0
- package/dist/destinations/personas-messaging-sendgrid/generated-types.js.map +1 -0
- package/dist/destinations/personas-messaging-sendgrid/index.d.ts +4 -0
- package/dist/destinations/personas-messaging-sendgrid/index.js +59 -0
- package/dist/destinations/personas-messaging-sendgrid/index.js.map +1 -0
- package/dist/destinations/personas-messaging-sendgrid/sendEmail/generated-types.d.ts +26 -0
- package/dist/destinations/personas-messaging-sendgrid/sendEmail/generated-types.js +3 -0
- package/dist/destinations/personas-messaging-sendgrid/sendEmail/generated-types.js.map +1 -0
- package/dist/destinations/personas-messaging-sendgrid/sendEmail/index.d.ts +5 -0
- package/dist/destinations/personas-messaging-sendgrid/sendEmail/index.js +310 -0
- package/dist/destinations/personas-messaging-sendgrid/sendEmail/index.js.map +1 -0
- package/dist/destinations/personas-messaging-twilio/generated-types.d.ts +11 -0
- package/dist/destinations/personas-messaging-twilio/generated-types.js +3 -0
- package/dist/destinations/personas-messaging-twilio/generated-types.js.map +1 -0
- package/dist/destinations/personas-messaging-twilio/index.d.ts +4 -0
- package/dist/destinations/personas-messaging-twilio/index.js +150 -0
- package/dist/destinations/personas-messaging-twilio/index.js.map +1 -0
- package/dist/destinations/personas-messaging-twilio/sendSms/generated-types.d.ts +16 -0
- package/dist/destinations/personas-messaging-twilio/sendSms/generated-types.js +3 -0
- package/dist/destinations/personas-messaging-twilio/sendSms/generated-types.js.map +1 -0
- package/dist/destinations/personas-messaging-twilio/sendSms/index.d.ts +5 -0
- package/dist/destinations/personas-messaging-twilio/sendSms/index.js +166 -0
- package/dist/destinations/personas-messaging-twilio/sendSms/index.js.map +1 -0
- package/dist/destinations/salesforce/sf-operations.d.ts +1 -0
- package/dist/destinations/salesforce/sf-operations.js +13 -1
- package/dist/destinations/salesforce/sf-operations.js.map +1 -1
- package/dist/destinations/snap-conversions-api/index.js +1 -1
- package/package.json +10 -5
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const operations_1 = require("./operations");
|
|
4
|
+
const action = {
|
|
5
|
+
title: 'Post Sheet',
|
|
6
|
+
description: 'Write values to a Google Sheets spreadsheet.',
|
|
7
|
+
defaultSubscription: 'type = "track" and event = "updated" or event = "new" or event = "deleted"',
|
|
8
|
+
fields: {
|
|
9
|
+
record_identifier: {
|
|
10
|
+
label: 'Record Identifier',
|
|
11
|
+
description: 'Property which uniquely identifies each row in the spreadsheet.',
|
|
12
|
+
type: 'hidden',
|
|
13
|
+
required: true,
|
|
14
|
+
default: { '@path': '$.__segment_id' }
|
|
15
|
+
},
|
|
16
|
+
operation_type: {
|
|
17
|
+
label: 'Operation Type',
|
|
18
|
+
description: "Describes the nature of the operation being performed. Only supported values are 'new', 'updated', and 'deleted'.",
|
|
19
|
+
type: 'hidden',
|
|
20
|
+
required: true,
|
|
21
|
+
default: { '@path': '$.event' }
|
|
22
|
+
},
|
|
23
|
+
spreadsheet_id: {
|
|
24
|
+
label: 'Spreadsheet ID',
|
|
25
|
+
description: 'The identifier of the spreadsheet. You can find this value in the URL of the spreadsheet. e.g. https://docs.google.com/spreadsheets/d/{SPREADSHEET_ID}/edit',
|
|
26
|
+
type: 'string',
|
|
27
|
+
required: true,
|
|
28
|
+
default: ''
|
|
29
|
+
},
|
|
30
|
+
spreadsheet_name: {
|
|
31
|
+
label: 'Spreadsheet Name',
|
|
32
|
+
description: 'The name of the spreadsheet. You can find this value on the tab at the bottom of the spreadsheet. Please provide a valid name of a sheet that already exists.',
|
|
33
|
+
type: 'string',
|
|
34
|
+
required: true,
|
|
35
|
+
default: 'Sheet1'
|
|
36
|
+
},
|
|
37
|
+
data_format: {
|
|
38
|
+
label: 'Data Format',
|
|
39
|
+
description: 'The way Google will interpret values. If you select raw, values will not be parsed and will be stored as-is. If you select user entered, values will be parsed as if you typed them into the UI. Numbers will stay as numbers, but strings may be converted to numbers, dates, etc. following the same rules that are applied when entering text into a cell via the Google Sheets UI.',
|
|
40
|
+
type: 'string',
|
|
41
|
+
required: true,
|
|
42
|
+
default: 'RAW',
|
|
43
|
+
choices: [
|
|
44
|
+
{ label: 'Raw', value: 'RAW' },
|
|
45
|
+
{ label: 'User Entered', value: 'USER_ENTERED' }
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
fields: {
|
|
49
|
+
label: 'Fields',
|
|
50
|
+
description: `
|
|
51
|
+
The fields to write to the spreadsheet.
|
|
52
|
+
On the left-hand side, input the name of the field as it will appear in the Google Sheet.
|
|
53
|
+
On the right-hand side, select the field from your data model that maps to the given field in your sheet.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
`,
|
|
58
|
+
type: 'object',
|
|
59
|
+
required: true,
|
|
60
|
+
defaultObjectUI: 'keyvalue:only'
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
perform: (request, { payload }) => {
|
|
64
|
+
return operations_1.processData(request, [payload]);
|
|
65
|
+
},
|
|
66
|
+
performBatch: (request, { payload }) => {
|
|
67
|
+
return operations_1.processData(request, payload);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.default = action;
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/google-sheets/postSheet/index.ts"],"names":[],"mappings":";;AAIA,6CAA0C;AAE1C,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,YAAY;IACnB,WAAW,EAAE,8CAA8C;IAC3D,mBAAmB,EAAE,4EAA4E;IAEjG,MAAM,EAAE;QACN,iBAAiB,EAAE;YACjB,KAAK,EAAE,mBAAmB;YAC1B,WAAW,EAAE,iEAAiE;YAC9E,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE;SACvC;QACD,cAAc,EAAE;YACd,KAAK,EAAE,gBAAgB;YACvB,WAAW,EACT,mHAAmH;YACrH,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE;SAChC;QACD,cAAc,EAAE;YACd,KAAK,EAAE,gBAAgB;YACvB,WAAW,EACT,6JAA6J;YAC/J,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE;SACZ;QACD,gBAAgB,EAAE;YAChB,KAAK,EAAE,kBAAkB;YACzB,WAAW,EACT,+JAA+J;YACjK,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,QAAQ;SAClB;QACD,WAAW,EAAE;YACX,KAAK,EAAE,aAAa;YACpB,WAAW,EACT,wXAAwX;YAC1X,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,KAAK;YACd,OAAO,EAAE;gBACP,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;gBAC9B,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,cAAc,EAAE;aACjD;SACF;QACD,MAAM,EAAE;YACN,KAAK,EAAE,QAAQ;YACf,WAAW,EAAE;;;;;;;OAOZ;YACD,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,eAAe,EAAE,eAAe;SACjC;KACF;IACD,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QAChC,OAAO,wBAAW,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IACxC,CAAC;IACD,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACrC,OAAO,wBAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACtC,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Payload } from './generated-types';
|
|
2
|
+
import { RequestClient } from '@segment/actions-core';
|
|
3
|
+
export declare type MappingSettings = {
|
|
4
|
+
spreadsheetId: string;
|
|
5
|
+
spreadsheetName: string;
|
|
6
|
+
dataFormat: string;
|
|
7
|
+
columns: string[];
|
|
8
|
+
};
|
|
9
|
+
declare function processData(request: RequestClient, events: Payload[]): Promise<(import("@segment/actions-core").ModifiedResponse<unknown> | undefined)[]>;
|
|
10
|
+
export { processData };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.processData = void 0;
|
|
7
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
8
|
+
const index_1 = require("../googleapis/index");
|
|
9
|
+
const constants_1 = require("../constants");
|
|
10
|
+
const a1_notation_1 = __importDefault(require("@segment/a1-notation"));
|
|
11
|
+
const DATA_ROW_OFFSET = 2;
|
|
12
|
+
const generateColumnValuesFromFields = (identifier, fields, columns) => {
|
|
13
|
+
const retVal = columns.map((col) => fields[col] ?? '');
|
|
14
|
+
retVal.unshift(identifier);
|
|
15
|
+
return retVal;
|
|
16
|
+
};
|
|
17
|
+
function processGetSpreadsheetResponse(response, events, mappingSettings) {
|
|
18
|
+
const numColumns = mappingSettings.columns.length;
|
|
19
|
+
const numRows = response.values?.length;
|
|
20
|
+
if (numRows * numColumns > constants_1.CONSTANTS.MAX_CELLS) {
|
|
21
|
+
throw new actions_core_1.IntegrationError('Sheet has reached maximum limit', 'INVALID_REQUEST_DATA', 400);
|
|
22
|
+
}
|
|
23
|
+
const updateBatch = [];
|
|
24
|
+
const appendBatch = [];
|
|
25
|
+
const eventMap = new Map(events.map((e) => [e.record_identifier, e]));
|
|
26
|
+
if (response.values && response.values.length > 0) {
|
|
27
|
+
for (let i = 0; i < response.values.length; i++) {
|
|
28
|
+
const targetIdentifier = response.values[i][0];
|
|
29
|
+
if (eventMap.has(targetIdentifier)) {
|
|
30
|
+
const targetEvent = eventMap.get(targetIdentifier);
|
|
31
|
+
if (targetEvent.operation_type != 'deleted') {
|
|
32
|
+
updateBatch.push({
|
|
33
|
+
identifier: targetIdentifier,
|
|
34
|
+
event: targetEvent.fields,
|
|
35
|
+
targetIndex: i
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
eventMap.delete(targetIdentifier);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
eventMap.forEach((value, key) => {
|
|
43
|
+
if (value.operation_type != 'deleted') {
|
|
44
|
+
appendBatch.push({
|
|
45
|
+
identifier: key,
|
|
46
|
+
event: value.fields
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return { appendBatch, updateBatch };
|
|
51
|
+
}
|
|
52
|
+
async function processUpdateBatch(mappingSettings, updateBatch, gs) {
|
|
53
|
+
const getRange = (targetIndex, columnCount) => {
|
|
54
|
+
const targetRange = new a1_notation_1.default(1, targetIndex);
|
|
55
|
+
targetRange.addX(columnCount);
|
|
56
|
+
return targetRange.toString();
|
|
57
|
+
};
|
|
58
|
+
const batchPayload = updateBatch.map(({ identifier, event, targetIndex }) => {
|
|
59
|
+
const values = generateColumnValuesFromFields(identifier, event, mappingSettings.columns);
|
|
60
|
+
return {
|
|
61
|
+
range: `${mappingSettings.spreadsheetName}!${getRange(targetIndex + DATA_ROW_OFFSET, values.length)}`,
|
|
62
|
+
values: [values]
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
const headerRowRange = new a1_notation_1.default(1, 1, 1, mappingSettings.columns.length + 1);
|
|
66
|
+
batchPayload.push({
|
|
67
|
+
range: `${mappingSettings.spreadsheetName}!${headerRowRange.toString()}`,
|
|
68
|
+
values: [['id', ...mappingSettings.columns]]
|
|
69
|
+
});
|
|
70
|
+
return gs.batchUpdate(mappingSettings, batchPayload);
|
|
71
|
+
}
|
|
72
|
+
async function processAppendBatch(mappingSettings, appendBatch, gs) {
|
|
73
|
+
if (appendBatch.length <= 0) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const values = appendBatch.map(({ identifier, event }) => generateColumnValuesFromFields(identifier, event, mappingSettings.columns));
|
|
77
|
+
return gs.append(mappingSettings, `A${DATA_ROW_OFFSET}`, values);
|
|
78
|
+
}
|
|
79
|
+
async function processData(request, events) {
|
|
80
|
+
const mappingSettings = {
|
|
81
|
+
spreadsheetId: events[0].spreadsheet_id,
|
|
82
|
+
spreadsheetName: events[0].spreadsheet_name,
|
|
83
|
+
dataFormat: events[0].data_format,
|
|
84
|
+
columns: Object.getOwnPropertyNames(events[0].fields)
|
|
85
|
+
};
|
|
86
|
+
const gs = new index_1.GoogleSheets(request);
|
|
87
|
+
const response = await gs.get(mappingSettings, `A${DATA_ROW_OFFSET}:A`);
|
|
88
|
+
const { appendBatch, updateBatch } = processGetSpreadsheetResponse(response.data, events, mappingSettings);
|
|
89
|
+
const promises = [
|
|
90
|
+
processUpdateBatch(mappingSettings, updateBatch, gs),
|
|
91
|
+
processAppendBatch(mappingSettings, appendBatch, gs)
|
|
92
|
+
];
|
|
93
|
+
return await Promise.all(promises);
|
|
94
|
+
}
|
|
95
|
+
exports.processData = processData;
|
|
96
|
+
//# sourceMappingURL=operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../../../src/destinations/google-sheets/postSheet/operations.ts"],"names":[],"mappings":";;;;;;AACA,wDAAuE;AACvE,+CAA+D;AAC/D,4CAAwC;AAExC,uEAAqC;AAiBrC,MAAM,eAAe,GAAG,CAAC,CAAA;AAwBzB,MAAM,8BAA8B,GAAG,CAAC,UAAkB,EAAE,MAAc,EAAE,OAAiB,EAAE,EAAE;IAC/F,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;IACtD,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IAC1B,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAQD,SAAS,6BAA6B,CAAC,QAAqB,EAAE,MAAiB,EAAE,eAAgC;IAC/G,MAAM,UAAU,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM,CAAA;IACjD,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IAEvC,IA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AED,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AACpC,CAAC;AAEQ,kCAAW"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../src/destinations/personas-messaging-sendgrid/generated-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const sendEmail_1 = __importDefault(require("./sendEmail"));
|
|
7
|
+
const destination = {
|
|
8
|
+
name: 'Actions Personas Messaging Sendgrid',
|
|
9
|
+
mode: 'cloud',
|
|
10
|
+
description: 'This is a personas specific action to send an email',
|
|
11
|
+
authentication: {
|
|
12
|
+
scheme: 'custom',
|
|
13
|
+
fields: {
|
|
14
|
+
unlayerApiKey: {
|
|
15
|
+
label: 'Unlayer API Key',
|
|
16
|
+
type: 'password',
|
|
17
|
+
description: 'The API key for your Unlayer account'
|
|
18
|
+
},
|
|
19
|
+
sendGridApiKey: {
|
|
20
|
+
label: 'API Key',
|
|
21
|
+
type: 'password',
|
|
22
|
+
description: 'The Api Key for your sendGrid account',
|
|
23
|
+
required: true
|
|
24
|
+
},
|
|
25
|
+
profileApiEnvironment: {
|
|
26
|
+
label: 'Profile API Environment',
|
|
27
|
+
description: 'Profile API Environment',
|
|
28
|
+
type: 'string',
|
|
29
|
+
required: true
|
|
30
|
+
},
|
|
31
|
+
profileApiAccessToken: {
|
|
32
|
+
label: 'Profile API Access Token',
|
|
33
|
+
description: 'Profile API Access Token',
|
|
34
|
+
type: 'password',
|
|
35
|
+
required: true
|
|
36
|
+
},
|
|
37
|
+
spaceId: {
|
|
38
|
+
label: 'Space ID',
|
|
39
|
+
description: 'Space ID',
|
|
40
|
+
type: 'string',
|
|
41
|
+
required: true
|
|
42
|
+
},
|
|
43
|
+
sourceId: {
|
|
44
|
+
label: 'Source ID',
|
|
45
|
+
description: 'Source ID',
|
|
46
|
+
type: 'string',
|
|
47
|
+
required: true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
testAuthentication: (request) => {
|
|
51
|
+
return request('https://api.sendgrid.com/v3/mail_settings');
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
actions: {
|
|
55
|
+
sendEmail: sendEmail_1.default
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
exports.default = destination;
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/personas-messaging-sendgrid/index.ts"],"names":[],"mappings":";;;;;AAEA,4DAAmC;AAEnC,MAAM,WAAW,GAAoC;IACnD,IAAI,EAAE,qCAAqC;IAC3C,IAAI,EAAE,OAAO;IACb,WAAW,EAAE,qDAAqD;IAClE,cAAc,EAAE;QACd,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE;YACN,aAAa,EAAE;gBACb,KAAK,EAAE,iBAAiB;gBACxB,IAAI,EAAE,UAAU;gBAChB,WAAW,EAAE,sCAAsC;aACpD;YACD,cAAc,EAAE;gBACd,KAAK,EAAE,SAAS;gBAChB,IAAI,EAAE,UAAU;gBAChB,WAAW,EAAE,uCAAuC;gBACpD,QAAQ,EAAE,IAAI;aACf;YACD,qBAAqB,EAAE;gBACrB,KAAK,EAAE,yBAAyB;gBAChC,WAAW,EAAE,yBAAyB;gBACtC,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;aACf;YACD,qBAAqB,EAAE;gBACrB,KAAK,EAAE,0BAA0B;gBACjC,WAAW,EAAE,0BAA0B;gBACvC,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE,IAAI;aACf;YACD,OAAO,EAAE;gBACP,KAAK,EAAE,UAAU;gBACjB,WAAW,EAAE,UAAU;gBACvB,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;aACf;YACD,QAAQ,EAAE;gBACR,KAAK,EAAE,WAAW;gBAClB,WAAW,EAAE,WAAW;gBACxB,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;aACf;SACF;QACD,kBAAkB,EAAE,CAAC,OAAO,EAAE,EAAE;YAC9B,OAAO,OAAO,CAAC,2CAA2C,CAAC,CAAA;QAC7D,CAAC;KACF;IACD,OAAO,EAAE;QACP,SAAS,EAAT,mBAAS;KACV;CACF,CAAA;AAED,kBAAe,WAAW,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface Payload {
|
|
2
|
+
send?: boolean;
|
|
3
|
+
userId: string;
|
|
4
|
+
toEmail?: string;
|
|
5
|
+
fromDomain?: string | null;
|
|
6
|
+
fromEmail: string;
|
|
7
|
+
fromName: string;
|
|
8
|
+
replyToEqualsFrom?: boolean;
|
|
9
|
+
replyToEmail: string;
|
|
10
|
+
replyToName: string;
|
|
11
|
+
bcc: string;
|
|
12
|
+
previewText?: string;
|
|
13
|
+
subject: string;
|
|
14
|
+
body?: string;
|
|
15
|
+
bodyUrl?: string;
|
|
16
|
+
bodyType: string;
|
|
17
|
+
bodyHtml?: string;
|
|
18
|
+
externalIds?: {
|
|
19
|
+
id?: string;
|
|
20
|
+
type?: string;
|
|
21
|
+
subscriptionStatus?: string;
|
|
22
|
+
}[];
|
|
23
|
+
customArgs?: {
|
|
24
|
+
[k: string]: unknown;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/personas-messaging-sendgrid/sendEmail/generated-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
7
|
+
const liquidjs_1 = require("liquidjs");
|
|
8
|
+
const cheerio_1 = __importDefault(require("cheerio"));
|
|
9
|
+
const escape_goat_1 = require("escape-goat");
|
|
10
|
+
const Liquid = new liquidjs_1.Liquid();
|
|
11
|
+
const insertEmailPreviewText = (html, previewText) => {
|
|
12
|
+
const $ = cheerio_1.default.load(html);
|
|
13
|
+
$('body').prepend(`
|
|
14
|
+
<div style='display: none; max-height: 0px; overflow: hidden;'>
|
|
15
|
+
${escape_goat_1.htmlEscape(previewText)}
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
<div style='display: none; max-height: 0px; overflow: hidden;'>
|
|
19
|
+
${' ‌'.repeat(13)}
|
|
20
|
+
</div>
|
|
21
|
+
`);
|
|
22
|
+
return $.html();
|
|
23
|
+
};
|
|
24
|
+
const getProfileApiEndpoint = (environment) => {
|
|
25
|
+
return `https://profiles.segment.${environment === 'production' ? 'com' : 'build'}`;
|
|
26
|
+
};
|
|
27
|
+
const fetchProfileTraits = async (request, settings, profileId) => {
|
|
28
|
+
const endpoint = getProfileApiEndpoint(settings.profileApiEnvironment);
|
|
29
|
+
const response = await request(`${endpoint}/v1/spaces/${settings.spaceId}/collections/users/profiles/user_id:${profileId}/traits?limit=200`, {
|
|
30
|
+
headers: {
|
|
31
|
+
authorization: `Basic ${Buffer.from(settings.profileApiAccessToken + ':').toString('base64')}`,
|
|
32
|
+
'content-type': 'application/json'
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const body = await response.json();
|
|
36
|
+
return body.traits;
|
|
37
|
+
};
|
|
38
|
+
const isRestrictedDomain = (email) => {
|
|
39
|
+
const restricted = ['gmailx.com', 'yahoox.com', 'aolx.com', 'hotmailx.com'];
|
|
40
|
+
const matches = /^.+@(.+)$/.exec(email.toLowerCase());
|
|
41
|
+
if (!matches) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const domain = matches[1];
|
|
45
|
+
return restricted.includes(domain);
|
|
46
|
+
};
|
|
47
|
+
const generateEmailHtml = async (request, apiKey, design) => {
|
|
48
|
+
const response = await request('https://api.unlayer.com/v2/export/html', {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: {
|
|
51
|
+
authorization: `Basic ${Buffer.from(`${apiKey}:`).toString('base64')}`,
|
|
52
|
+
'content-type': 'application/json'
|
|
53
|
+
},
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
displayMode: 'email',
|
|
56
|
+
design: JSON.parse(design)
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
const body = await response.json();
|
|
60
|
+
return body.data.html;
|
|
61
|
+
};
|
|
62
|
+
const EXTERNAL_ID_KEY = 'email';
|
|
63
|
+
const action = {
|
|
64
|
+
title: 'Send Email',
|
|
65
|
+
description: 'Sends Email to a user powered by SendGrid',
|
|
66
|
+
defaultSubscription: 'type = "track" and event = "Audience Entered"',
|
|
67
|
+
fields: {
|
|
68
|
+
send: {
|
|
69
|
+
label: 'Send Message',
|
|
70
|
+
description: 'Whether or not the message should actually get sent.',
|
|
71
|
+
type: 'boolean',
|
|
72
|
+
required: false,
|
|
73
|
+
default: false
|
|
74
|
+
},
|
|
75
|
+
userId: {
|
|
76
|
+
label: 'User ID',
|
|
77
|
+
description: 'User ID in Segment',
|
|
78
|
+
type: 'string',
|
|
79
|
+
required: true,
|
|
80
|
+
default: { '@path': '$.userId' }
|
|
81
|
+
},
|
|
82
|
+
toEmail: {
|
|
83
|
+
label: 'Test Email',
|
|
84
|
+
description: 'Email to send to when testing',
|
|
85
|
+
type: 'string'
|
|
86
|
+
},
|
|
87
|
+
fromDomain: {
|
|
88
|
+
label: 'From Domain',
|
|
89
|
+
description: 'Verified domain in Sendgrid',
|
|
90
|
+
type: 'string',
|
|
91
|
+
allowNull: true
|
|
92
|
+
},
|
|
93
|
+
fromEmail: {
|
|
94
|
+
label: 'From Email',
|
|
95
|
+
description: 'From Email',
|
|
96
|
+
type: 'string',
|
|
97
|
+
required: true
|
|
98
|
+
},
|
|
99
|
+
fromName: {
|
|
100
|
+
label: 'From Name',
|
|
101
|
+
description: 'From Name displayed to end user email',
|
|
102
|
+
type: 'string',
|
|
103
|
+
required: true
|
|
104
|
+
},
|
|
105
|
+
replyToEqualsFrom: {
|
|
106
|
+
label: 'Reply To Equals From',
|
|
107
|
+
description: 'Whether "reply to" settings are the same as "from"',
|
|
108
|
+
type: 'boolean'
|
|
109
|
+
},
|
|
110
|
+
replyToEmail: {
|
|
111
|
+
label: 'Reply To Email',
|
|
112
|
+
description: 'The Email used by user to Reply To',
|
|
113
|
+
type: 'string',
|
|
114
|
+
required: true
|
|
115
|
+
},
|
|
116
|
+
replyToName: {
|
|
117
|
+
label: 'Reply To Name',
|
|
118
|
+
description: 'The Name used by user to Reply To',
|
|
119
|
+
type: 'string',
|
|
120
|
+
required: true
|
|
121
|
+
},
|
|
122
|
+
bcc: {
|
|
123
|
+
label: 'BCC',
|
|
124
|
+
description: 'BCC list of emails',
|
|
125
|
+
type: 'string',
|
|
126
|
+
required: true
|
|
127
|
+
},
|
|
128
|
+
previewText: {
|
|
129
|
+
label: 'Preview Text',
|
|
130
|
+
description: 'Preview Text',
|
|
131
|
+
type: 'string'
|
|
132
|
+
},
|
|
133
|
+
subject: {
|
|
134
|
+
label: 'Subject',
|
|
135
|
+
description: 'Subject for the email to be sent',
|
|
136
|
+
type: 'string',
|
|
137
|
+
required: true
|
|
138
|
+
},
|
|
139
|
+
body: {
|
|
140
|
+
label: 'Body',
|
|
141
|
+
description: 'The message body',
|
|
142
|
+
type: 'text'
|
|
143
|
+
},
|
|
144
|
+
bodyUrl: {
|
|
145
|
+
label: 'Body URL',
|
|
146
|
+
description: 'URL to the message body',
|
|
147
|
+
type: 'text'
|
|
148
|
+
},
|
|
149
|
+
bodyType: {
|
|
150
|
+
label: 'Body Type',
|
|
151
|
+
description: 'The type of body which is used generally html | design',
|
|
152
|
+
type: 'string',
|
|
153
|
+
required: true
|
|
154
|
+
},
|
|
155
|
+
bodyHtml: {
|
|
156
|
+
label: 'Body Html',
|
|
157
|
+
description: 'The HTML content of the body',
|
|
158
|
+
type: 'string'
|
|
159
|
+
},
|
|
160
|
+
externalIds: {
|
|
161
|
+
label: 'External IDs',
|
|
162
|
+
description: 'An array of user profile identity information.',
|
|
163
|
+
type: 'object',
|
|
164
|
+
multiple: true,
|
|
165
|
+
properties: {
|
|
166
|
+
id: {
|
|
167
|
+
label: 'ID',
|
|
168
|
+
description: 'A unique identifier for the collection.',
|
|
169
|
+
type: 'string'
|
|
170
|
+
},
|
|
171
|
+
type: {
|
|
172
|
+
label: 'type',
|
|
173
|
+
description: 'The external ID contact type.',
|
|
174
|
+
type: 'string'
|
|
175
|
+
},
|
|
176
|
+
subscriptionStatus: {
|
|
177
|
+
label: 'ID',
|
|
178
|
+
description: 'The subscription status for the identity.',
|
|
179
|
+
type: 'string'
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
default: {
|
|
183
|
+
'@arrayPath': [
|
|
184
|
+
'$.external_ids',
|
|
185
|
+
{
|
|
186
|
+
id: {
|
|
187
|
+
'@path': '$.id'
|
|
188
|
+
},
|
|
189
|
+
type: {
|
|
190
|
+
'@path': '$.type'
|
|
191
|
+
},
|
|
192
|
+
subscriptionStatus: {
|
|
193
|
+
'@path': '$.isSubscribed'
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
customArgs: {
|
|
200
|
+
label: 'Custom Args',
|
|
201
|
+
description: 'Additional custom args that we be passed back opaquely on webhook events',
|
|
202
|
+
type: 'object',
|
|
203
|
+
required: false
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
perform: async (request, { settings, payload }) => {
|
|
207
|
+
if (!payload.send) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const emailProfile = payload?.externalIds?.find((meta) => meta.type === 'email');
|
|
211
|
+
if (!emailProfile?.subscriptionStatus ||
|
|
212
|
+
['unsubscribed', 'did not subscribed', 'false'].includes(emailProfile.subscriptionStatus)) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
else if (['subscribed', 'true'].includes(emailProfile?.subscriptionStatus)) {
|
|
216
|
+
const traits = await fetchProfileTraits(request, settings, payload.userId);
|
|
217
|
+
const profile = {
|
|
218
|
+
email: emailProfile.id,
|
|
219
|
+
traits
|
|
220
|
+
};
|
|
221
|
+
const toEmail = payload.toEmail || profile.email;
|
|
222
|
+
if (!toEmail) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (isRestrictedDomain(toEmail)) {
|
|
226
|
+
throw new actions_core_1.IntegrationError('Emails with gmailx.com, yahoox.com, aolx.com, and hotmailx.com domains are blocked.', 'Invalid input', 400);
|
|
227
|
+
}
|
|
228
|
+
let name;
|
|
229
|
+
if (traits.first_name && traits.last_name) {
|
|
230
|
+
name = `${traits.first_name} ${traits.last_name}`;
|
|
231
|
+
}
|
|
232
|
+
else if (traits.firstName && traits.lastName) {
|
|
233
|
+
name = `${traits.firstName} ${traits.lastName}`;
|
|
234
|
+
}
|
|
235
|
+
else if (traits.name) {
|
|
236
|
+
name = traits.name;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
name = traits.first_name || traits.last_name || traits.firstName || traits.lastName || 'User';
|
|
240
|
+
}
|
|
241
|
+
const bcc = JSON.parse(payload.bcc ?? '[]');
|
|
242
|
+
let bodyHtml = payload.bodyHtml ?? '';
|
|
243
|
+
if (payload.bodyUrl && settings.unlayerApiKey) {
|
|
244
|
+
const response = await request(payload.bodyUrl);
|
|
245
|
+
const body = await response.text();
|
|
246
|
+
bodyHtml = payload.bodyType === 'html' ? body : await generateEmailHtml(request, settings.unlayerApiKey, body);
|
|
247
|
+
if (payload.previewText) {
|
|
248
|
+
bodyHtml = insertEmailPreviewText(bodyHtml, payload.previewText);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const [parsedSubject, parsedBody] = await Promise.all([
|
|
252
|
+
Liquid.parseAndRender(payload.subject, { profile }),
|
|
253
|
+
Liquid.parseAndRender(bodyHtml, { profile })
|
|
254
|
+
]);
|
|
255
|
+
return request('https://api.sendgrid.com/v3/mail/send', {
|
|
256
|
+
method: 'post',
|
|
257
|
+
headers: {
|
|
258
|
+
authorization: `Bearer ${settings.sendGridApiKey}`
|
|
259
|
+
},
|
|
260
|
+
json: {
|
|
261
|
+
personalizations: [
|
|
262
|
+
{
|
|
263
|
+
to: [
|
|
264
|
+
{
|
|
265
|
+
email: toEmail,
|
|
266
|
+
name: name
|
|
267
|
+
}
|
|
268
|
+
],
|
|
269
|
+
bcc: bcc.length > 0 ? bcc : undefined,
|
|
270
|
+
custom_args: {
|
|
271
|
+
...payload.customArgs,
|
|
272
|
+
source_id: settings.sourceId,
|
|
273
|
+
space_id: settings.spaceId,
|
|
274
|
+
user_id: payload.userId,
|
|
275
|
+
__segment_internal_external_id_key__: EXTERNAL_ID_KEY,
|
|
276
|
+
__segment_internal_external_id_value__: profile[EXTERNAL_ID_KEY]
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
],
|
|
280
|
+
from: {
|
|
281
|
+
email: payload.fromEmail,
|
|
282
|
+
name: payload.fromName
|
|
283
|
+
},
|
|
284
|
+
reply_to: {
|
|
285
|
+
email: payload.replyToEmail,
|
|
286
|
+
name: payload.replyToName
|
|
287
|
+
},
|
|
288
|
+
subject: parsedSubject,
|
|
289
|
+
content: [
|
|
290
|
+
{
|
|
291
|
+
type: 'text/html',
|
|
292
|
+
value: parsedBody
|
|
293
|
+
}
|
|
294
|
+
],
|
|
295
|
+
tracking_settings: {
|
|
296
|
+
subscription_tracking: {
|
|
297
|
+
enable: true,
|
|
298
|
+
substitution_tag: '[unsubscribe]'
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
throw new actions_core_1.IntegrationError(`Failed to process the subscription state: "${emailProfile.subscriptionStatus}"`, 'Invalid subscriptionStatus value', 400);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
exports.default = action;
|
|
310
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/personas-messaging-sendgrid/sendEmail/index.ts"],"names":[],"mappings":";;;;;AAAA,wDAA0F;AAG1F,uCAA6C;AAC7C,sDAA6B;AAC7B,6CAAwC;AAExC,MAAM,MAAM,GAAG,IAAI,iBAAQ,EAAE,CAAA;AAE7B,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAE,WAAmB,EAAU,EAAE;IAC3E,MAAM,CAAC,GAAG,iBAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAG5B,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;;QAEZ,wBAAU,CAAC,WAAW,CAAC;;;;QAIvB,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;;GAE9B,CAAC,CAAA;IAEF,OAAO,CAAC,CAAC,IAAI,EAAE,CAAA;AACjB,CAAC,CAAA;AAGD,MAAM,qBAAqB,GAAG,CAAC,WAAmB,EAAU,EAAE;IAC5D,OAAO,4BAA4B,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAA;AACrF,CAAC,CAAA;AAID,MAAM,kBAAkB,GAAG,KAAK,EAC9B,OAAkB,EAClB,QAAkB,EAClB,SAAiB,EACgB,EAAE;IACnC,MAAM,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAA;IACtE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAC5B,GAAG,QAAQ,cAAc,QAAQ,CAAC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OAAO,CAAC,WAAW;qBAC1B;oBACD,OAAO,EAAE,aAAa;oBACtB,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,WAAW;4BACjB,KAAK,EAAE,UAAU;yBAClB;qBACF;oBACD,iBAAiB,EAAE;wBACjB,qBAAqB,EAAE;4BACrB,MAAM,EAAE,IAAI;4BACZ,gBAAgB,EAAE,eAAe;yBAClC;qBACF;iBACF;aACF,CAAC,CAAA;SACH;aAAM;YACL,MAAM,IAAI,+BAAgB,CACxB,8CAA8C,YAAY,CAAC,kBAAkB,GAAG,EAChF,kCAAkC,EAClC,GAAG,CACJ,CAAA;SACF;IACH,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface Settings {
|
|
2
|
+
twilioAccountSID: string;
|
|
3
|
+
twilioApiKeySID: string;
|
|
4
|
+
twilioApiKeySecret: string;
|
|
5
|
+
profileApiEnvironment: string;
|
|
6
|
+
profileApiAccessToken: string;
|
|
7
|
+
spaceId: string;
|
|
8
|
+
sourceId: string;
|
|
9
|
+
webhookUrl?: string;
|
|
10
|
+
connectionOverrides?: string;
|
|
11
|
+
}
|