@activepieces/piece-sendpulse 0.0.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/README.md +7 -0
- package/package.json +38 -0
- package/src/index.d.ts +4 -0
- package/src/index.js +56 -0
- package/src/index.js.map +1 -0
- package/src/lib/actions/add-subscriber.d.ts +9 -0
- package/src/lib/actions/add-subscriber.js +82 -0
- package/src/lib/actions/add-subscriber.js.map +1 -0
- package/src/lib/actions/change-variable-for-subscriber.d.ts +9 -0
- package/src/lib/actions/change-variable-for-subscriber.js +143 -0
- package/src/lib/actions/change-variable-for-subscriber.js.map +1 -0
- package/src/lib/actions/delete-contact.d.ts +6 -0
- package/src/lib/actions/delete-contact.js +49 -0
- package/src/lib/actions/delete-contact.js.map +1 -0
- package/src/lib/actions/unsubscribe-user.d.ts +7 -0
- package/src/lib/actions/unsubscribe-user.js +64 -0
- package/src/lib/actions/unsubscribe-user.js.map +1 -0
- package/src/lib/actions/update-subscriber.d.ts +9 -0
- package/src/lib/actions/update-subscriber.js +100 -0
- package/src/lib/actions/update-subscriber.js.map +1 -0
- package/src/lib/common/auth.d.ts +4 -0
- package/src/lib/common/auth.js +38 -0
- package/src/lib/common/auth.js.map +1 -0
- package/src/lib/common/client.d.ts +13 -0
- package/src/lib/common/client.js +63 -0
- package/src/lib/common/client.js.map +1 -0
- package/src/lib/common/props.d.ts +1 -0
- package/src/lib/common/props.js +52 -0
- package/src/lib/common/props.js.map +1 -0
- package/src/lib/triggers/new-subscriber.d.ts +17 -0
- package/src/lib/triggers/new-subscriber.js +117 -0
- package/src/lib/triggers/new-subscriber.js.map +1 -0
- package/src/lib/triggers/new-unsubscriber.d.ts +17 -0
- package/src/lib/triggers/new-unsubscriber.js +121 -0
- package/src/lib/triggers/new-unsubscriber.js.map +1 -0
- package/src/lib/triggers/updated-subscriber.d.ts +17 -0
- package/src/lib/triggers/updated-subscriber.js +142 -0
- package/src/lib/triggers/updated-subscriber.js.map +1 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendpulseAuth = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const client_1 = require("./client");
|
|
7
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
8
|
+
exports.sendpulseAuth = pieces_framework_1.PieceAuth.CustomAuth({
|
|
9
|
+
description: 'Enter your SendPulse client credentials',
|
|
10
|
+
props: {
|
|
11
|
+
clientId: pieces_framework_1.PieceAuth.SecretText({
|
|
12
|
+
displayName: 'Client ID',
|
|
13
|
+
required: true,
|
|
14
|
+
}),
|
|
15
|
+
clientSecret: pieces_framework_1.PieceAuth.SecretText({
|
|
16
|
+
displayName: 'Client Secret',
|
|
17
|
+
required: true,
|
|
18
|
+
}),
|
|
19
|
+
},
|
|
20
|
+
validate: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
21
|
+
try {
|
|
22
|
+
yield (0, client_1.sendpulseApiCall)({
|
|
23
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
24
|
+
resourceUri: '/addressbooks',
|
|
25
|
+
auth,
|
|
26
|
+
});
|
|
27
|
+
return { valid: true };
|
|
28
|
+
}
|
|
29
|
+
catch (_b) {
|
|
30
|
+
return {
|
|
31
|
+
valid: false,
|
|
32
|
+
error: 'Invalid Client ID or Client Secret',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}),
|
|
36
|
+
required: true,
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/sendpulse/src/lib/common/auth.ts"],"names":[],"mappings":";;;;AAAA,qEAA2D;AAC3D,qCAA4C;AAC5C,+DAAyD;AAE5C,QAAA,aAAa,GAAG,4BAAS,CAAC,UAAU,CAAC;IAChD,WAAW,EAAE,yCAAyC;IACtD,KAAK,EAAE;QACL,QAAQ,EAAE,4BAAS,CAAC,UAAU,CAAC;YAC7B,WAAW,EAAE,WAAW;YACxB,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,YAAY,EAAE,4BAAS,CAAC,UAAU,CAAC;YACjC,WAAW,EAAE,eAAe;YAC5B,QAAQ,EAAE,IAAI;SACf,CAAC;KACH;IACD,QAAQ,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;QACvB,IAAI,CAAC;YACH,MAAM,IAAA,yBAAgB,EAAC;gBACrB,MAAM,EAAE,0BAAU,CAAC,GAAG;gBACtB,WAAW,EAAE,eAAe;gBAC5B,IAAI;aACL,CAAC,CAAC;YACH,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACzB,CAAC;QAAC,WAAM,CAAC;YACP,OAAO;gBACL,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,oCAAoC;aAC5C,CAAC;QACJ,CAAC;IACH,CAAC,CAAA;IACD,QAAQ,EAAE,IAAI;CACf,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { HttpMethod, HttpMessageBody } from '@activepieces/pieces-common';
|
|
2
|
+
export type SendPulseAuthProps = {
|
|
3
|
+
clientId: string;
|
|
4
|
+
clientSecret: string;
|
|
5
|
+
};
|
|
6
|
+
export type SendPulseApiCallParams = {
|
|
7
|
+
method: HttpMethod;
|
|
8
|
+
resourceUri: string;
|
|
9
|
+
query?: Record<string, string | number | string[] | undefined>;
|
|
10
|
+
body?: any;
|
|
11
|
+
auth: SendPulseAuthProps;
|
|
12
|
+
};
|
|
13
|
+
export declare function sendpulseApiCall<T extends HttpMessageBody>({ method, resourceUri, query, body, auth, }: SendPulseApiCallParams): Promise<T>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendpulseApiCall = sendpulseApiCall;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
6
|
+
let cachedToken = null;
|
|
7
|
+
let tokenExpiresAt = 0;
|
|
8
|
+
function getAccessToken(auth) {
|
|
9
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
10
|
+
if (cachedToken && Date.now() < tokenExpiresAt) {
|
|
11
|
+
return cachedToken;
|
|
12
|
+
}
|
|
13
|
+
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
14
|
+
method: pieces_common_1.HttpMethod.POST,
|
|
15
|
+
url: 'https://api.sendpulse.com/oauth/access_token',
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
},
|
|
19
|
+
body: {
|
|
20
|
+
grant_type: 'client_credentials',
|
|
21
|
+
client_id: auth.clientId,
|
|
22
|
+
client_secret: auth.clientSecret,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
cachedToken = response.body.access_token;
|
|
26
|
+
tokenExpiresAt = Date.now() + response.body.expires_in * 1000 - 30 * 1000;
|
|
27
|
+
return cachedToken;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function sendpulseApiCall(_a) {
|
|
31
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ method, resourceUri, query, body, auth, }) {
|
|
32
|
+
var _b, _c, _d;
|
|
33
|
+
const token = yield getAccessToken(auth);
|
|
34
|
+
const queryParams = {};
|
|
35
|
+
if (query) {
|
|
36
|
+
for (const [key, value] of Object.entries(query)) {
|
|
37
|
+
if (value !== null && value !== undefined) {
|
|
38
|
+
queryParams[key] = String(value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const request = {
|
|
43
|
+
method,
|
|
44
|
+
url: `https://api.sendpulse.com${resourceUri}`,
|
|
45
|
+
headers: {
|
|
46
|
+
Authorization: `Bearer ${token}`,
|
|
47
|
+
'Content-Type': 'application/json',
|
|
48
|
+
},
|
|
49
|
+
queryParams,
|
|
50
|
+
body,
|
|
51
|
+
};
|
|
52
|
+
try {
|
|
53
|
+
const response = yield pieces_common_1.httpClient.sendRequest(request);
|
|
54
|
+
return response.body;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const statusCode = (_b = error.response) === null || _b === void 0 ? void 0 : _b.status;
|
|
58
|
+
const errorMessage = ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message) || error.message || 'Unknown error';
|
|
59
|
+
throw new Error(`SendPulse API Error (${statusCode || 'Unknown'}): ${errorMessage}`);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/sendpulse/src/lib/common/client.ts"],"names":[],"mappings":";;AAkDA,4CAsCC;;AAxFD,+DAMqC;AAOrC,IAAI,WAAW,GAAkB,IAAI,CAAC;AACtC,IAAI,cAAc,GAAG,CAAC,CAAC;AAEvB,SAAe,cAAc,CAAC,IAAwB;;QACpD,IAAI,WAAW,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,cAAc,EAAE,CAAC;YAC/C,OAAO,WAAW,CAAC;QACrB,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,0BAAU,CAAC,WAAW,CAG1C;YACD,MAAM,EAAE,0BAAU,CAAC,IAAI;YACvB,GAAG,EAAE,8CAA8C;YACnD,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE;gBACJ,UAAU,EAAE,oBAAoB;gBAChC,SAAS,EAAE,IAAI,CAAC,QAAQ;gBACxB,aAAa,EAAE,IAAI,CAAC,YAAY;aACjC;SACF,CAAC,CAAC;QAEH,WAAW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AI,KAAK,CAAC,OAAO,IAAI,eAAe,CAAC;YAEvF,MAAM,IAAI,KAAK,CAAC,wBAAwB,UAAU,IAAI,SAAS,MAAM,YAAY,EAAE,CAAC,CAAC;QACvF,CAAC;IACH,CAAC;CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mailingListDropdown: import("@activepieces/pieces-framework").DropdownProperty<number, true>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mailingListDropdown = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
7
|
+
const client_1 = require("./client");
|
|
8
|
+
exports.mailingListDropdown = pieces_framework_1.Property.Dropdown({
|
|
9
|
+
displayName: 'Mailing List',
|
|
10
|
+
description: 'Select one of your SendPulse mailing lists',
|
|
11
|
+
required: true,
|
|
12
|
+
refreshers: [],
|
|
13
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
14
|
+
const typedAuth = auth;
|
|
15
|
+
if (!typedAuth.clientId || !typedAuth.clientSecret) {
|
|
16
|
+
return {
|
|
17
|
+
disabled: true,
|
|
18
|
+
options: [],
|
|
19
|
+
placeholder: 'Please connect your SendPulse account.',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const lists = yield (0, client_1.sendpulseApiCall)({
|
|
24
|
+
auth: auth,
|
|
25
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
26
|
+
resourceUri: '/addressbooks?limit=100&offset=0',
|
|
27
|
+
});
|
|
28
|
+
if (!lists.length) {
|
|
29
|
+
return {
|
|
30
|
+
disabled: true,
|
|
31
|
+
options: [],
|
|
32
|
+
placeholder: 'No mailing lists found in your account.',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
disabled: false,
|
|
37
|
+
options: lists.map((list) => ({
|
|
38
|
+
label: `${list.name} (${list.status_explain})`,
|
|
39
|
+
value: list.id,
|
|
40
|
+
})),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return {
|
|
45
|
+
disabled: true,
|
|
46
|
+
options: [],
|
|
47
|
+
placeholder: `Failed to load mailing lists: ${error.message}`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/sendpulse/src/lib/common/props.ts"],"names":[],"mappings":";;;;AAAA,qEAA0D;AAC1D,+DAAyD;AACzD,qCAA4C;AAS/B,QAAA,mBAAmB,GAAG,2BAAQ,CAAC,QAAQ,CAAC;IACnD,WAAW,EAAE,cAAc;IAC3B,WAAW,EAAE,4CAA4C;IACzD,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,EAAE;IACd,OAAO,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;QACtB,MAAM,SAAS,GAAG,IAAoD,CAAC;QACvE,IAAI,CAAC,SAAS,CAAC,QAAQ,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC;YACnD,OAAO;gBACL,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,EAAE;gBACX,WAAW,EAAE,wCAAwC;aACtD,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,IAAA,yBAAgB,EAAyB;gBAC3D,IAAI,EAAE,IAA6C;gBACnD,MAAM,EAAE,0BAAU,CAAC,GAAG;gBACtB,WAAW,EAAE,kCAAkC;aAChD,CAAC,CAAC;YAEH,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;gBAClB,OAAO;oBACL,QAAQ,EAAE,IAAI;oBACd,OAAO,EAAE,EAAE;oBACX,WAAW,EAAE,yCAAyC;iBACvD,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;oBAC5B,KAAK,EAAE,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,cAAc,GAAG;oBAC9C,KAAK,EAAE,IAAI,CAAC,EAAE;iBACf,CAAC,CAAC;aACJ,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO;gBACL,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,EAAE;gBACX,WAAW,EAAE,iCAAiC,KAAK,CAAC,OAAO,EAAE;aAC9D,CAAC;QACJ,CAAC;IACH,CAAC,CAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TriggerStrategy } from '@activepieces/pieces-framework';
|
|
2
|
+
export declare const newSubscriberTrigger: import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.WEBHOOK, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
3
|
+
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
4
|
+
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
5
|
+
}>, {
|
|
6
|
+
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true>;
|
|
7
|
+
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.POLLING, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
8
|
+
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
9
|
+
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
10
|
+
}>, {
|
|
11
|
+
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true>;
|
|
12
|
+
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.APP_WEBHOOK, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
13
|
+
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
14
|
+
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
15
|
+
}>, {
|
|
16
|
+
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true>;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newSubscriberTrigger = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const auth_1 = require("../common/auth");
|
|
7
|
+
const client_1 = require("../common/client");
|
|
8
|
+
const props_1 = require("../common/props");
|
|
9
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
10
|
+
exports.newSubscriberTrigger = (0, pieces_framework_1.createTrigger)({
|
|
11
|
+
auth: auth_1.sendpulseAuth,
|
|
12
|
+
name: 'new_subscriber',
|
|
13
|
+
displayName: 'New Subscriber',
|
|
14
|
+
description: 'Fires when new subscriber is added',
|
|
15
|
+
type: pieces_framework_1.TriggerStrategy.WEBHOOK,
|
|
16
|
+
props: {
|
|
17
|
+
mailingListId: props_1.mailingListDropdown,
|
|
18
|
+
},
|
|
19
|
+
onEnable(context) {
|
|
20
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
var _a;
|
|
22
|
+
const { mailingListId } = context.propsValue;
|
|
23
|
+
try {
|
|
24
|
+
const webhookResponse = yield (0, client_1.sendpulseApiCall)({
|
|
25
|
+
method: pieces_common_1.HttpMethod.POST,
|
|
26
|
+
auth: context.auth,
|
|
27
|
+
resourceUri: '/v2/email-service/webhook',
|
|
28
|
+
body: {
|
|
29
|
+
url: context.webhookUrl,
|
|
30
|
+
actions: ['new_emails'],
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
if (webhookResponse.success && ((_a = webhookResponse.data) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
34
|
+
const webhook = webhookResponse.data.find(w => w.action === 'new_emails');
|
|
35
|
+
if (webhook) {
|
|
36
|
+
yield context.store.put('webhook_id', webhook.id);
|
|
37
|
+
yield context.store.put('mailing_list_id', mailingListId);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error('Failed to create webhook');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw new Error(`Failed to enable new subscriber trigger: ${error.message}`);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
onDisable(context) {
|
|
50
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
try {
|
|
52
|
+
const webhookId = yield context.store.get('webhook_id');
|
|
53
|
+
if (webhookId) {
|
|
54
|
+
yield (0, client_1.sendpulseApiCall)({
|
|
55
|
+
method: pieces_common_1.HttpMethod.DELETE,
|
|
56
|
+
auth: context.auth,
|
|
57
|
+
resourceUri: `/v2/email-service/webhook/${webhookId}`,
|
|
58
|
+
});
|
|
59
|
+
yield context.store.delete('webhook_id');
|
|
60
|
+
yield context.store.delete('mailing_list_id');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.warn('Failed to delete webhook during disable:', error);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
run(context) {
|
|
69
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const storedListId = yield context.store.get('mailing_list_id');
|
|
71
|
+
const payload = context.payload.body;
|
|
72
|
+
const payloads = Array.isArray(payload) ? payload : [payload];
|
|
73
|
+
const results = [];
|
|
74
|
+
for (const item of payloads) {
|
|
75
|
+
if (item.event === 'new_emails' && item.book_id === storedListId) {
|
|
76
|
+
results.push({
|
|
77
|
+
id: `${item.email}_${item.timestamp}`,
|
|
78
|
+
email: item.email,
|
|
79
|
+
mailingListId: item.book_id,
|
|
80
|
+
source: item.source,
|
|
81
|
+
variables: item.variables || {},
|
|
82
|
+
addedAt: new Date(parseInt(item.timestamp) * 1000).toISOString(),
|
|
83
|
+
timestamp: item.timestamp,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return results;
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
test() {
|
|
91
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
return [
|
|
93
|
+
{
|
|
94
|
+
id: 'demo@example.com_1496827625',
|
|
95
|
+
email: 'demo@example.com',
|
|
96
|
+
mailingListId: '123456',
|
|
97
|
+
source: 'address book',
|
|
98
|
+
variables: {},
|
|
99
|
+
addedAt: new Date().toISOString(),
|
|
100
|
+
timestamp: '1496827625',
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
sampleData: {
|
|
106
|
+
id: 'subscriber@example.com_1496827625',
|
|
107
|
+
email: 'subscriber@example.com',
|
|
108
|
+
mailingListId: '123456',
|
|
109
|
+
source: 'subscription form',
|
|
110
|
+
variables: {
|
|
111
|
+
name: 'John Doe',
|
|
112
|
+
},
|
|
113
|
+
addedAt: '2023-06-01T12:00:00.000Z',
|
|
114
|
+
timestamp: '1496827625',
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=new-subscriber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new-subscriber.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/sendpulse/src/lib/triggers/new-subscriber.ts"],"names":[],"mappings":";;;;AAAA,qEAIwC;AACxC,yCAA+C;AAC/C,6CAAoD;AACpD,2CAAsD;AACtD,+DAAyD;AAE5C,QAAA,oBAAoB,GAAG,IAAA,gCAAa,EAAC;IAChD,IAAI,EA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AAI,CAAC,KAAK;wBACjB,aAAa,EAAE,IAAI,CAAC,OAAO;wBAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;wBACnB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,EAAE;wBAC/B,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE;wBAChE,SAAS,EAAE,IAAI,CAAC,SAAS;qBAC1B,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;KAAA;IAEK,IAAI;;YACR,OAAO;gBACL;oBACE,EAAE,EAAE,6BAA6B;oBACjC,KAAK,EAAE,kBAAkB;oBACzB,aAAa,EAAE,QAAQ;oBACvB,MAAM,EAAE,cAAc;oBACtB,SAAS,EAAE,EAAE;oBACb,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;oBACjC,SAAS,EAAE,YAAY;iBACxB;aACF,CAAC;QACJ,CAAC;KAAA;IAED,UAAU,EAAE;QACV,EAAE,EAAE,mCAAmC;QACvC,KAAK,EAAE,wBAAwB;QAC/B,aAAa,EAAE,QAAQ;QACvB,MAAM,EAAE,mBAAmB;QAC3B,SAAS,EAAE;YACT,IAAI,EAAE,UAAU;SACjB;QACD,OAAO,EAAE,0BAA0B;QACnC,SAAS,EAAE,YAAY;KACxB;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TriggerStrategy } from '@activepieces/pieces-framework';
|
|
2
|
+
export declare const newUnsubscriberTrigger: import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.WEBHOOK, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
3
|
+
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
4
|
+
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
5
|
+
}>, {
|
|
6
|
+
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true>;
|
|
7
|
+
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.POLLING, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
8
|
+
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
9
|
+
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
10
|
+
}>, {
|
|
11
|
+
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true>;
|
|
12
|
+
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.APP_WEBHOOK, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
13
|
+
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
14
|
+
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
15
|
+
}>, {
|
|
16
|
+
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true>;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newUnsubscriberTrigger = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const auth_1 = require("../common/auth");
|
|
7
|
+
const client_1 = require("../common/client");
|
|
8
|
+
const props_1 = require("../common/props");
|
|
9
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
10
|
+
exports.newUnsubscriberTrigger = (0, pieces_framework_1.createTrigger)({
|
|
11
|
+
auth: auth_1.sendpulseAuth,
|
|
12
|
+
name: 'new_unsubscriber',
|
|
13
|
+
displayName: 'New Unsubscriber',
|
|
14
|
+
description: 'Fires when subscriber unsubscribes',
|
|
15
|
+
type: pieces_framework_1.TriggerStrategy.WEBHOOK,
|
|
16
|
+
props: {
|
|
17
|
+
mailingListId: props_1.mailingListDropdown,
|
|
18
|
+
},
|
|
19
|
+
onEnable(context) {
|
|
20
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
var _a;
|
|
22
|
+
const { mailingListId } = context.propsValue;
|
|
23
|
+
try {
|
|
24
|
+
const webhookResponse = yield (0, client_1.sendpulseApiCall)({
|
|
25
|
+
method: pieces_common_1.HttpMethod.POST,
|
|
26
|
+
auth: context.auth,
|
|
27
|
+
resourceUri: '/v2/email-service/webhook',
|
|
28
|
+
body: {
|
|
29
|
+
url: context.webhookUrl,
|
|
30
|
+
actions: ['unsubscribe'],
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
if (webhookResponse.success && ((_a = webhookResponse.data) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
34
|
+
const webhook = webhookResponse.data.find(w => w.action === 'unsubscribe');
|
|
35
|
+
if (webhook) {
|
|
36
|
+
yield context.store.put('webhook_id', webhook.id);
|
|
37
|
+
yield context.store.put('mailing_list_id', mailingListId);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error('Failed to create webhook');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw new Error(`Failed to enable unsubscriber trigger: ${error.message}`);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
onDisable(context) {
|
|
50
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
try {
|
|
52
|
+
const webhookId = yield context.store.get('webhook_id');
|
|
53
|
+
if (webhookId) {
|
|
54
|
+
yield (0, client_1.sendpulseApiCall)({
|
|
55
|
+
method: pieces_common_1.HttpMethod.DELETE,
|
|
56
|
+
auth: context.auth,
|
|
57
|
+
resourceUri: `/v2/email-service/webhook/${webhookId}`,
|
|
58
|
+
});
|
|
59
|
+
yield context.store.delete('webhook_id');
|
|
60
|
+
yield context.store.delete('mailing_list_id');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.warn('Failed to delete webhook during disable:', error);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
run(context) {
|
|
69
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const storedListId = yield context.store.get('mailing_list_id');
|
|
71
|
+
const payload = context.payload.body;
|
|
72
|
+
const payloads = Array.isArray(payload) ? payload : [payload];
|
|
73
|
+
const results = [];
|
|
74
|
+
for (const item of payloads) {
|
|
75
|
+
if (item.event === 'unsubscribe' && item.book_id === storedListId) {
|
|
76
|
+
results.push({
|
|
77
|
+
id: `${item.email}_${item.timestamp}`,
|
|
78
|
+
email: item.email,
|
|
79
|
+
mailingListId: item.book_id,
|
|
80
|
+
taskId: item.task_id,
|
|
81
|
+
fromAll: item.from_all === '1',
|
|
82
|
+
reason: item.reason || 'No reason provided',
|
|
83
|
+
categories: item.categories || '',
|
|
84
|
+
unsubscribedAt: new Date(parseInt(item.timestamp) * 1000).toISOString(),
|
|
85
|
+
timestamp: item.timestamp,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return results;
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
test() {
|
|
93
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
return [
|
|
95
|
+
{
|
|
96
|
+
id: 'test-unsubscribe@example.com_1496827872',
|
|
97
|
+
email: 'test-unsubscribe@example.com',
|
|
98
|
+
mailingListId: '123456',
|
|
99
|
+
taskId: '3668141',
|
|
100
|
+
fromAll: true,
|
|
101
|
+
reason: 'User clicked unsubscribe link',
|
|
102
|
+
categories: '',
|
|
103
|
+
unsubscribedAt: new Date().toISOString(),
|
|
104
|
+
timestamp: '1496827872',
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
sampleData: {
|
|
110
|
+
id: 'unsub@example.com_1496827872',
|
|
111
|
+
email: 'unsub@example.com',
|
|
112
|
+
mailingListId: '123456',
|
|
113
|
+
taskId: '3668141',
|
|
114
|
+
fromAll: false,
|
|
115
|
+
reason: 'Manual unsubscribe',
|
|
116
|
+
categories: 'newsletter',
|
|
117
|
+
unsubscribedAt: '2023-06-01T12:30:00.000Z',
|
|
118
|
+
timestamp: '1496827872',
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
//# sourceMappingURL=new-unsubscriber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new-unsubscriber.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/sendpulse/src/lib/triggers/new-unsubscriber.ts"],"names":[],"mappings":";;;;AAAA,qEAIwC;AACxC,yCAA+C;AAC/C,6CAAoD;AACpD,2CAAsD;AACtD,+DAAyD;AAE5C,QAAA,sBAAsB,GAAG,IAAA,gCAAa,EAAC;IAClD,IAAI,EAAE,oBAAa;IACnB,IAAI,EAAE,kBAAkB;IACxB,WAAW,EAAE,kBAAkB;IAC/B,WAAW,EAAE,oCAAoC;IACjD,IAAI,EAAE,kCAAe,CAAC,OAAO;IAC7B,KAAK,EAAE;QACL,aAAa,EAAE,2BAAmB;KACnC;IAEK,QAAQ,CAAC,OAAO;;;YACpB,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;YAE7C,IAAI,CAAC;gBACH,MAAM,eAAe,GAAG,MAAM,IAAA,yBAAgB,EAG3C;oBACD,MAAM,EAAE,0BAAU,CAAC,IAAI;oBACvB,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,WAAW,EAAE,2BAA2B;oBACxC,IAAI,EAAE;wBACJ,GAAG,EAAE,OAAO,CAAC,UAAU;wBACvB,OAAO,EAAE,CAAC,aAAa,CAAC;qBACzB;iBACF,CAAC,CAAC;gBAEH,IAAI,eAAe,CAAC,OAAO,IAAI,CAAA,MAAA,eAAe,CAAC,IAAI,0CAAE,MAAM,IAAG,CAAC,EAAE,CAAC;oBAChE,MAAM,OAAO,GAAG,eAAe,CAAC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c,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;oBACxC,SAAS,EAAE,YAAY;iBACxB;aACF,CAAC;QACJ,CAAC;KAAA;IAED,UAAU,EAAE;QACV,EAAE,EAAE,8BAA8B;QAClC,KAAK,EAAE,mBAAmB;QAC1B,aAAa,EAAE,QAAQ;QACvB,MAAM,EAAE,SAAS;QACjB,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,oBAAoB;QAC5B,UAAU,EAAE,YAAY;QACxB,cAAc,EAAE,0BAA0B;QAC1C,SAAS,EAAE,YAAY;KACxB;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TriggerStrategy } from '@activepieces/pieces-framework';
|
|
2
|
+
export declare const updatedSubscriberTrigger: import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.WEBHOOK, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
3
|
+
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
4
|
+
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
5
|
+
}>, {
|
|
6
|
+
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true>;
|
|
7
|
+
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.POLLING, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
8
|
+
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
9
|
+
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
10
|
+
}>, {
|
|
11
|
+
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true>;
|
|
12
|
+
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.APP_WEBHOOK, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
13
|
+
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
14
|
+
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
15
|
+
}>, {
|
|
16
|
+
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true>;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updatedSubscriberTrigger = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const auth_1 = require("../common/auth");
|
|
7
|
+
const client_1 = require("../common/client");
|
|
8
|
+
const props_1 = require("../common/props");
|
|
9
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
10
|
+
function detectChanges(previous, current) {
|
|
11
|
+
const changes = {};
|
|
12
|
+
const allKeys = new Set([...Object.keys(previous), ...Object.keys(current)]);
|
|
13
|
+
for (const key of allKeys) {
|
|
14
|
+
if (JSON.stringify(previous[key]) !== JSON.stringify(current[key])) {
|
|
15
|
+
changes[key] = {
|
|
16
|
+
from: previous[key],
|
|
17
|
+
to: current[key],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return changes;
|
|
22
|
+
}
|
|
23
|
+
exports.updatedSubscriberTrigger = (0, pieces_framework_1.createTrigger)({
|
|
24
|
+
auth: auth_1.sendpulseAuth,
|
|
25
|
+
name: 'updated_subscriber',
|
|
26
|
+
displayName: 'Updated Subscriber',
|
|
27
|
+
description: 'Fires when subscriber details change (polling)',
|
|
28
|
+
type: pieces_framework_1.TriggerStrategy.POLLING,
|
|
29
|
+
props: {
|
|
30
|
+
mailingListId: props_1.mailingListDropdown,
|
|
31
|
+
},
|
|
32
|
+
onEnable(context) {
|
|
33
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
yield context.store.put('mailing_list_id', String(context.propsValue.mailingListId));
|
|
35
|
+
yield context.store.put('last_check', Date.now().toString());
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
onDisable(context) {
|
|
39
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
yield context.store.delete('mailing_list_id');
|
|
41
|
+
yield context.store.delete('last_check');
|
|
42
|
+
yield context.store.delete('subscribers_cache');
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
run(context) {
|
|
46
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const mailingListId = yield context.store.get('mailing_list_id');
|
|
48
|
+
if (!mailingListId) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const currentSubscribers = yield (0, client_1.sendpulseApiCall)({
|
|
53
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
54
|
+
auth: context.auth,
|
|
55
|
+
resourceUri: `/addressbooks/${mailingListId}/emails`,
|
|
56
|
+
});
|
|
57
|
+
const cachedSubscribers = yield context.store.get('subscribers_cache');
|
|
58
|
+
if (!cachedSubscribers) {
|
|
59
|
+
yield context.store.put('subscribers_cache', JSON.stringify(currentSubscribers));
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
const previousSubscribers = JSON.parse(cachedSubscribers);
|
|
63
|
+
const changes = [];
|
|
64
|
+
for (const current of currentSubscribers) {
|
|
65
|
+
const previous = previousSubscribers.find((p) => p.email === current.email);
|
|
66
|
+
if (previous) {
|
|
67
|
+
const hasChanges = JSON.stringify(current) !== JSON.stringify(previous);
|
|
68
|
+
if (hasChanges) {
|
|
69
|
+
changes.push({
|
|
70
|
+
id: `${current.email}_${Date.now()}`,
|
|
71
|
+
email: current.email,
|
|
72
|
+
mailingListId,
|
|
73
|
+
previousData: previous,
|
|
74
|
+
currentData: current,
|
|
75
|
+
updatedAt: new Date().toISOString(),
|
|
76
|
+
changes: detectChanges(previous, current),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
yield context.store.put('subscribers_cache', JSON.stringify(currentSubscribers));
|
|
82
|
+
yield context.store.put('last_check', Date.now().toString());
|
|
83
|
+
return changes;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.error('Error checking for subscriber updates:', error);
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
test() {
|
|
92
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
return [
|
|
94
|
+
{
|
|
95
|
+
id: 'test-updated@example.com_1234567890',
|
|
96
|
+
email: 'test-updated@example.com',
|
|
97
|
+
mailingListId: '123456',
|
|
98
|
+
previousData: {
|
|
99
|
+
email: 'test-updated@example.com',
|
|
100
|
+
variables: { name: 'Old Name' },
|
|
101
|
+
},
|
|
102
|
+
currentData: {
|
|
103
|
+
email: 'test-updated@example.com',
|
|
104
|
+
variables: { name: 'New Name' },
|
|
105
|
+
},
|
|
106
|
+
updatedAt: new Date().toISOString(),
|
|
107
|
+
changes: {
|
|
108
|
+
'variables.name': {
|
|
109
|
+
from: 'Old Name',
|
|
110
|
+
to: 'New Name',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
sampleData: {
|
|
118
|
+
id: 'updated-user@example.com_1234567890',
|
|
119
|
+
email: 'updated-user@example.com',
|
|
120
|
+
mailingListId: '123456',
|
|
121
|
+
previousData: {
|
|
122
|
+
email: 'updated-user@example.com',
|
|
123
|
+
variables: { phone: '+1234567890', name: 'John' },
|
|
124
|
+
},
|
|
125
|
+
currentData: {
|
|
126
|
+
email: 'updated-user@example.com',
|
|
127
|
+
variables: { phone: '+0987654321', name: 'John Updated' },
|
|
128
|
+
},
|
|
129
|
+
updatedAt: '2023-06-01T12:30:00.000Z',
|
|
130
|
+
changes: {
|
|
131
|
+
'variables.phone': {
|
|
132
|
+
from: '+1234567890',
|
|
133
|
+
to: '+0987654321',
|
|
134
|
+
},
|
|
135
|
+
'variables.name': {
|
|
136
|
+
from: 'John',
|
|
137
|
+
to: 'John Updated',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
//# sourceMappingURL=updated-subscriber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updated-subscriber.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/sendpulse/src/lib/triggers/updated-subscriber.ts"],"names":[],"mappings":";;;;AAAA,qEAGwC;AACxC,yCAA+C;AAC/C,6CAAoD;AACpD,2CAAsD;AACtD,+DAAyD;AAEzD,SAAS,aAAa,CAAC,QAAa,EAAE,OAAY;IAChD,MAAM,OAAO,GAA2C,EAAE,CAAC;IAE3D,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAE7E,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACnE,OAAO,CAAC,GAAG,CAAC,GAAG;gBACb,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC;gBACnB,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC;aACjB,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAEY,QAAA,wBAAwB,GAAG,IAAA,gCAAa,EAAC;IACpD,IAAI,EAAE,oBAAa;IACnB,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EAAE,oBAAoB;IACjC,WAAW,EAAE,gDAAgD;IAC7D,IAAI,EAAE,kCAAe,CAAC,OAAO;IAC7B,KAAK,EAAE;QACL,aAAa,EAAE,2BAAmB;KACnC;IAEK,QAAQ,CAAC,OAAO;;YACpB,MAAM,OAA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