@activepieces/piece-sendpulse 0.1.5 → 0.1.7
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/package.json +7 -12
- package/src/index.js +13 -56
- package/src/index.d.ts +0 -5
- package/src/index.d.ts.map +0 -1
- package/src/index.js.map +0 -1
- package/src/lib/actions/add-subscriber.d.ts +0 -13
- package/src/lib/actions/add-subscriber.d.ts.map +0 -1
- package/src/lib/actions/add-subscriber.js +0 -84
- package/src/lib/actions/add-subscriber.js.map +0 -1
- package/src/lib/actions/change-variable-for-subscriber.d.ts +0 -16
- package/src/lib/actions/change-variable-for-subscriber.d.ts.map +0 -1
- package/src/lib/actions/change-variable-for-subscriber.js +0 -146
- package/src/lib/actions/change-variable-for-subscriber.js.map +0 -1
- package/src/lib/actions/delete-contact.d.ts +0 -7
- package/src/lib/actions/delete-contact.d.ts.map +0 -1
- package/src/lib/actions/delete-contact.js +0 -51
- package/src/lib/actions/delete-contact.js.map +0 -1
- package/src/lib/actions/unsubscribe-user.d.ts +0 -11
- package/src/lib/actions/unsubscribe-user.d.ts.map +0 -1
- package/src/lib/actions/unsubscribe-user.js +0 -66
- package/src/lib/actions/unsubscribe-user.js.map +0 -1
- package/src/lib/actions/update-subscriber.d.ts +0 -13
- package/src/lib/actions/update-subscriber.d.ts.map +0 -1
- package/src/lib/actions/update-subscriber.js +0 -102
- package/src/lib/actions/update-subscriber.js.map +0 -1
- package/src/lib/common/auth.d.ts +0 -5
- package/src/lib/common/auth.d.ts.map +0 -1
- package/src/lib/common/auth.js +0 -38
- package/src/lib/common/auth.js.map +0 -1
- package/src/lib/common/client.d.ts +0 -14
- package/src/lib/common/client.d.ts.map +0 -1
- package/src/lib/common/client.js +0 -63
- package/src/lib/common/client.js.map +0 -1
- package/src/lib/common/props.d.ts +0 -5
- package/src/lib/common/props.d.ts.map +0 -1
- package/src/lib/common/props.js +0 -54
- package/src/lib/common/props.js.map +0 -1
- package/src/lib/triggers/new-subscriber.d.ts +0 -35
- package/src/lib/triggers/new-subscriber.d.ts.map +0 -1
- package/src/lib/triggers/new-subscriber.js +0 -120
- package/src/lib/triggers/new-subscriber.js.map +0 -1
- package/src/lib/triggers/new-unsubscriber.d.ts +0 -35
- package/src/lib/triggers/new-unsubscriber.d.ts.map +0 -1
- package/src/lib/triggers/new-unsubscriber.js +0 -124
- package/src/lib/triggers/new-unsubscriber.js.map +0 -1
- package/src/lib/triggers/updated-subscriber.d.ts +0 -35
- package/src/lib/triggers/updated-subscriber.d.ts.map +0 -1
- package/src/lib/triggers/updated-subscriber.js +0 -145
- package/src/lib/triggers/updated-subscriber.js.map +0 -1
package/src/lib/common/props.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
const auth_1 = require("./auth");
|
|
9
|
-
exports.mailingListDropdown = pieces_framework_1.Property.Dropdown({
|
|
10
|
-
auth: auth_1.sendpulseAuth,
|
|
11
|
-
displayName: 'Mailing List',
|
|
12
|
-
description: 'Select one of your SendPulse mailing lists',
|
|
13
|
-
required: true,
|
|
14
|
-
refreshers: [],
|
|
15
|
-
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
16
|
-
if (!auth) {
|
|
17
|
-
return {
|
|
18
|
-
disabled: true,
|
|
19
|
-
options: [],
|
|
20
|
-
placeholder: 'Please connect your SendPulse account.',
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
const typedAuth = auth.props;
|
|
24
|
-
try {
|
|
25
|
-
const lists = yield (0, client_1.sendpulseApiCall)({
|
|
26
|
-
auth: auth.props,
|
|
27
|
-
method: pieces_common_1.HttpMethod.GET,
|
|
28
|
-
resourceUri: '/addressbooks?limit=100&offset=0',
|
|
29
|
-
});
|
|
30
|
-
if (!lists.length) {
|
|
31
|
-
return {
|
|
32
|
-
disabled: true,
|
|
33
|
-
options: [],
|
|
34
|
-
placeholder: 'No mailing lists found in your account.',
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
disabled: false,
|
|
39
|
-
options: lists.map((list) => ({
|
|
40
|
-
label: `${list.name} (${list.status_explain})`,
|
|
41
|
-
value: list.id,
|
|
42
|
-
})),
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
return {
|
|
47
|
-
disabled: true,
|
|
48
|
-
options: [],
|
|
49
|
-
placeholder: `Failed to load mailing lists: ${error.message}`,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
}),
|
|
53
|
-
});
|
|
54
|
-
//# sourceMappingURL=props.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"props.js","sourceRoot":"","sources":["../../../../src/lib/common/props.ts"],"names":[],"mappings":";;;;AAAA,qEAA0D;AAC1D,+DAAyD;AACzD,qCAA4C;AAC5C,iCAAuC;AAQ1B,QAAA,mBAAmB,GAAG,2BAAQ,CAAC,QAAQ,CAAC;IACnD,IAAI,EAAE,oBAAa;IACnB,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,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO;gBACL,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,EAAE;gBACX,WAAW,EAAE,wCAAwC;aACtD,CAAC;QACJ,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAA;QAE5B,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,IAAA,yBAAgB,EAAyB;gBAC3D,IAAI,EAAE,IAAI,CAAC,KAAK;gBAChB,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"}
|
|
@@ -1,35 +0,0 @@
|
|
|
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, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
7
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
8
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
9
|
-
}>>;
|
|
10
|
-
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.POLLING, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
11
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
12
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
13
|
-
}>, {
|
|
14
|
-
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
15
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
16
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
17
|
-
}>>;
|
|
18
|
-
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.MANUAL, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
19
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
20
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
21
|
-
}>, {
|
|
22
|
-
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
23
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
24
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
25
|
-
}>>;
|
|
26
|
-
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.APP_WEBHOOK, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
27
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
28
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
29
|
-
}>, {
|
|
30
|
-
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
31
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
32
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
33
|
-
}>>;
|
|
34
|
-
}>;
|
|
35
|
-
//# sourceMappingURL=new-subscriber.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"new-subscriber.d.ts","sourceRoot":"","sources":["../../../../src/lib/triggers/new-subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAEhB,MAAM,gCAAgC,CAAC;AAMxC,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2H/B,CAAC"}
|
|
@@ -1,120 +0,0 @@
|
|
|
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
|
-
aiMetadata: {
|
|
16
|
-
description: 'Fires when a new email contact is added to the selected SendPulse mailing list (address book), via any source such as a subscription form or import. Each event represents one newly added subscriber and includes their email, source, and variables.',
|
|
17
|
-
},
|
|
18
|
-
type: pieces_framework_1.TriggerStrategy.WEBHOOK,
|
|
19
|
-
props: {
|
|
20
|
-
mailingListId: props_1.mailingListDropdown,
|
|
21
|
-
},
|
|
22
|
-
onEnable(context) {
|
|
23
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
var _a;
|
|
25
|
-
const { mailingListId } = context.propsValue;
|
|
26
|
-
try {
|
|
27
|
-
const webhookResponse = yield (0, client_1.sendpulseApiCall)({
|
|
28
|
-
method: pieces_common_1.HttpMethod.POST,
|
|
29
|
-
auth: context.auth.props,
|
|
30
|
-
resourceUri: '/v2/email-service/webhook',
|
|
31
|
-
body: {
|
|
32
|
-
url: context.webhookUrl,
|
|
33
|
-
actions: ['new_emails'],
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
if (webhookResponse.success && ((_a = webhookResponse.data) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
37
|
-
const webhook = webhookResponse.data.find(w => w.action === 'new_emails');
|
|
38
|
-
if (webhook) {
|
|
39
|
-
yield context.store.put('webhook_id', webhook.id);
|
|
40
|
-
yield context.store.put('mailing_list_id', mailingListId);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
throw new Error('Failed to create webhook');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
throw new Error(`Failed to enable new subscriber trigger: ${error.message}`);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
},
|
|
52
|
-
onDisable(context) {
|
|
53
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
try {
|
|
55
|
-
const webhookId = yield context.store.get('webhook_id');
|
|
56
|
-
if (webhookId) {
|
|
57
|
-
yield (0, client_1.sendpulseApiCall)({
|
|
58
|
-
method: pieces_common_1.HttpMethod.DELETE,
|
|
59
|
-
auth: context.auth.props,
|
|
60
|
-
resourceUri: `/v2/email-service/webhook/${webhookId}`,
|
|
61
|
-
});
|
|
62
|
-
yield context.store.delete('webhook_id');
|
|
63
|
-
yield context.store.delete('mailing_list_id');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
console.warn('Failed to delete webhook during disable:', error);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
run(context) {
|
|
72
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
const storedListId = yield context.store.get('mailing_list_id');
|
|
74
|
-
const payload = context.payload.body;
|
|
75
|
-
const payloads = Array.isArray(payload) ? payload : [payload];
|
|
76
|
-
const results = [];
|
|
77
|
-
for (const item of payloads) {
|
|
78
|
-
if (item.event === 'new_emails' && item.book_id === storedListId) {
|
|
79
|
-
results.push({
|
|
80
|
-
id: `${item.email}_${item.timestamp}`,
|
|
81
|
-
email: item.email,
|
|
82
|
-
mailingListId: item.book_id,
|
|
83
|
-
source: item.source,
|
|
84
|
-
variables: item.variables || {},
|
|
85
|
-
addedAt: new Date(parseInt(item.timestamp) * 1000).toISOString(),
|
|
86
|
-
timestamp: item.timestamp,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return results;
|
|
91
|
-
});
|
|
92
|
-
},
|
|
93
|
-
test() {
|
|
94
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
return [
|
|
96
|
-
{
|
|
97
|
-
id: 'demo@example.com_1496827625',
|
|
98
|
-
email: 'demo@example.com',
|
|
99
|
-
mailingListId: '123456',
|
|
100
|
-
source: 'address book',
|
|
101
|
-
variables: {},
|
|
102
|
-
addedAt: new Date().toISOString(),
|
|
103
|
-
timestamp: '1496827625',
|
|
104
|
-
},
|
|
105
|
-
];
|
|
106
|
-
});
|
|
107
|
-
},
|
|
108
|
-
sampleData: {
|
|
109
|
-
id: 'subscriber@example.com_1496827625',
|
|
110
|
-
email: 'subscriber@example.com',
|
|
111
|
-
mailingListId: '123456',
|
|
112
|
-
source: 'subscription form',
|
|
113
|
-
variables: {
|
|
114
|
-
name: 'John Doe',
|
|
115
|
-
},
|
|
116
|
-
addedAt: '2023-06-01T12:00:00.000Z',
|
|
117
|
-
timestamp: '1496827625',
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
//# sourceMappingURL=new-subscriber.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"new-subscriber.js","sourceRoot":"","sources":["../../../../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,EAAE,oBAAa;IACnB,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,gBAAgB;IAC7B,WAAW,EAAE,oCAAoC;IACjD,UAAU,EAAE;QACV,WAAW,EAAE,wPAAwP;KACtQ;IACD,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,CAAC,KAAK;oBACxB,WAAW,EAAE,2BAA2B;oBACxC,IAAI,EAAE;wBACJ,GAAG,EAAE,OAAO,CAAC,UAAU;wBACvB,OAAO,EAAE,CAAC,YAAY,CAAC;qBACxB;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,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,YAAY,CAAC,CAAC;oBAC1E,IAAI,OAAO,EAAE,CAAC;wBACZ,MAAM,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,EAAE,OAA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CACF,CAAC,CAAC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
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, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
7
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
8
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
9
|
-
}>>;
|
|
10
|
-
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.POLLING, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
11
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
12
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
13
|
-
}>, {
|
|
14
|
-
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
15
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
16
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
17
|
-
}>>;
|
|
18
|
-
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.MANUAL, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
19
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
20
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
21
|
-
}>, {
|
|
22
|
-
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
23
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
24
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
25
|
-
}>>;
|
|
26
|
-
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.APP_WEBHOOK, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
27
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
28
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
29
|
-
}>, {
|
|
30
|
-
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
31
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
32
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
33
|
-
}>>;
|
|
34
|
-
}>;
|
|
35
|
-
//# sourceMappingURL=new-unsubscriber.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"new-unsubscriber.d.ts","sourceRoot":"","sources":["../../../../src/lib/triggers/new-unsubscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAEhB,MAAM,gCAAgC,CAAC;AAMxC,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiIjC,CAAC"}
|
|
@@ -1,124 +0,0 @@
|
|
|
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
|
-
aiMetadata: {
|
|
16
|
-
description: 'Fires when a contact unsubscribes from the selected SendPulse mailing list (address book). Each event represents one unsubscribe and includes the email, the reason if provided, and whether they opted out of all lists.',
|
|
17
|
-
},
|
|
18
|
-
type: pieces_framework_1.TriggerStrategy.WEBHOOK,
|
|
19
|
-
props: {
|
|
20
|
-
mailingListId: props_1.mailingListDropdown,
|
|
21
|
-
},
|
|
22
|
-
onEnable(context) {
|
|
23
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
var _a;
|
|
25
|
-
const { mailingListId } = context.propsValue;
|
|
26
|
-
try {
|
|
27
|
-
const webhookResponse = yield (0, client_1.sendpulseApiCall)({
|
|
28
|
-
method: pieces_common_1.HttpMethod.POST,
|
|
29
|
-
auth: context.auth.props,
|
|
30
|
-
resourceUri: '/v2/email-service/webhook',
|
|
31
|
-
body: {
|
|
32
|
-
url: context.webhookUrl,
|
|
33
|
-
actions: ['unsubscribe'],
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
if (webhookResponse.success && ((_a = webhookResponse.data) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
37
|
-
const webhook = webhookResponse.data.find(w => w.action === 'unsubscribe');
|
|
38
|
-
if (webhook) {
|
|
39
|
-
yield context.store.put('webhook_id', webhook.id);
|
|
40
|
-
yield context.store.put('mailing_list_id', mailingListId);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
throw new Error('Failed to create webhook');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
throw new Error(`Failed to enable unsubscriber trigger: ${error.message}`);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
},
|
|
52
|
-
onDisable(context) {
|
|
53
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
try {
|
|
55
|
-
const webhookId = yield context.store.get('webhook_id');
|
|
56
|
-
if (webhookId) {
|
|
57
|
-
yield (0, client_1.sendpulseApiCall)({
|
|
58
|
-
method: pieces_common_1.HttpMethod.DELETE,
|
|
59
|
-
auth: context.auth.props,
|
|
60
|
-
resourceUri: `/v2/email-service/webhook/${webhookId}`,
|
|
61
|
-
});
|
|
62
|
-
yield context.store.delete('webhook_id');
|
|
63
|
-
yield context.store.delete('mailing_list_id');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
console.warn('Failed to delete webhook during disable:', error);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
run(context) {
|
|
72
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
const storedListId = yield context.store.get('mailing_list_id');
|
|
74
|
-
const payload = context.payload.body;
|
|
75
|
-
const payloads = Array.isArray(payload) ? payload : [payload];
|
|
76
|
-
const results = [];
|
|
77
|
-
for (const item of payloads) {
|
|
78
|
-
if (item.event === 'unsubscribe' && item.book_id === storedListId) {
|
|
79
|
-
results.push({
|
|
80
|
-
id: `${item.email}_${item.timestamp}`,
|
|
81
|
-
email: item.email,
|
|
82
|
-
mailingListId: item.book_id,
|
|
83
|
-
taskId: item.task_id,
|
|
84
|
-
fromAll: item.from_all === '1',
|
|
85
|
-
reason: item.reason || 'No reason provided',
|
|
86
|
-
categories: item.categories || '',
|
|
87
|
-
unsubscribedAt: new Date(parseInt(item.timestamp) * 1000).toISOString(),
|
|
88
|
-
timestamp: item.timestamp,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return results;
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
|
-
test() {
|
|
96
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
return [
|
|
98
|
-
{
|
|
99
|
-
id: 'test-unsubscribe@example.com_1496827872',
|
|
100
|
-
email: 'test-unsubscribe@example.com',
|
|
101
|
-
mailingListId: '123456',
|
|
102
|
-
taskId: '3668141',
|
|
103
|
-
fromAll: true,
|
|
104
|
-
reason: 'User clicked unsubscribe link',
|
|
105
|
-
categories: '',
|
|
106
|
-
unsubscribedAt: new Date().toISOString(),
|
|
107
|
-
timestamp: '1496827872',
|
|
108
|
-
},
|
|
109
|
-
];
|
|
110
|
-
});
|
|
111
|
-
},
|
|
112
|
-
sampleData: {
|
|
113
|
-
id: 'unsub@example.com_1496827872',
|
|
114
|
-
email: 'unsub@example.com',
|
|
115
|
-
mailingListId: '123456',
|
|
116
|
-
taskId: '3668141',
|
|
117
|
-
fromAll: false,
|
|
118
|
-
reason: 'Manual unsubscribe',
|
|
119
|
-
categories: 'newsletter',
|
|
120
|
-
unsubscribedAt: '2023-06-01T12:30:00.000Z',
|
|
121
|
-
timestamp: '1496827872',
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
//# sourceMappingURL=new-unsubscriber.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"new-unsubscriber.js","sourceRoot":"","sources":["../../../../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,UAAU,EAAE;QACV,WAAW,EAAE,2NAA2N;KACzO;IACD,IAAI,EAAE,kCAAe,CAAC,OAAO;IAC7B,KAAK,EAAE;QACL,aAAa,EAAE,2BAAmB;KACnC;IAEK,QAAQ,CAAC,OAAO;;;YACpB,MAAM,EAAE,aAAa,EA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AAE,IAAI,CAAC,UAAU,IAAI,EAAE;wBACjC,cAAc,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE;wBACvE,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,yCAAyC;oBAC7C,KAAK,EAAE,8BAA8B;oBACrC,aAAa,EAAE,QAAQ;oBACvB,MAAM,EAAE,SAAS;oBACjB,OAAO,EAAE,IAAI;oBACb,MAAM,EAAE,+BAA+B;oBACvC,UAAU,EAAE,EAAE;oBACd,cAAc,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"}
|
|
@@ -1,35 +0,0 @@
|
|
|
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, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
7
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
8
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
9
|
-
}>>;
|
|
10
|
-
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.POLLING, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
11
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
12
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
13
|
-
}>, {
|
|
14
|
-
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
15
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
16
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
17
|
-
}>>;
|
|
18
|
-
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.MANUAL, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
19
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
20
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
21
|
-
}>, {
|
|
22
|
-
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
23
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
24
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
25
|
-
}>>;
|
|
26
|
-
}> | import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.APP_WEBHOOK, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
27
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
28
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
29
|
-
}>, {
|
|
30
|
-
mailingListId: import("@activepieces/pieces-framework").DropdownProperty<number, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
31
|
-
clientId: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
32
|
-
clientSecret: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
33
|
-
}>>;
|
|
34
|
-
}>;
|
|
35
|
-
//# sourceMappingURL=updated-subscriber.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updated-subscriber.d.ts","sourceRoot":"","sources":["../../../../src/lib/triggers/updated-subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAChB,MAAM,gCAAgC,CAAC;AAuBxC,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+HnC,CAAC"}
|
|
@@ -1,145 +0,0 @@
|
|
|
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
|
-
aiMetadata: {
|
|
29
|
-
description: 'Polls the selected SendPulse mailing list (address book) and fires when an existing subscriber\'s details or variables change between checks. Each event represents one changed contact and includes the previous data, current data, and a diff of the changed fields.',
|
|
30
|
-
},
|
|
31
|
-
type: pieces_framework_1.TriggerStrategy.POLLING,
|
|
32
|
-
props: {
|
|
33
|
-
mailingListId: props_1.mailingListDropdown,
|
|
34
|
-
},
|
|
35
|
-
onEnable(context) {
|
|
36
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
yield context.store.put('mailing_list_id', String(context.propsValue.mailingListId));
|
|
38
|
-
yield context.store.put('last_check', Date.now().toString());
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
onDisable(context) {
|
|
42
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
yield context.store.delete('mailing_list_id');
|
|
44
|
-
yield context.store.delete('last_check');
|
|
45
|
-
yield context.store.delete('subscribers_cache');
|
|
46
|
-
});
|
|
47
|
-
},
|
|
48
|
-
run(context) {
|
|
49
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const mailingListId = yield context.store.get('mailing_list_id');
|
|
51
|
-
if (!mailingListId) {
|
|
52
|
-
return [];
|
|
53
|
-
}
|
|
54
|
-
try {
|
|
55
|
-
const currentSubscribers = yield (0, client_1.sendpulseApiCall)({
|
|
56
|
-
method: pieces_common_1.HttpMethod.GET,
|
|
57
|
-
auth: context.auth.props,
|
|
58
|
-
resourceUri: `/addressbooks/${mailingListId}/emails`,
|
|
59
|
-
});
|
|
60
|
-
const cachedSubscribers = yield context.store.get('subscribers_cache');
|
|
61
|
-
if (!cachedSubscribers) {
|
|
62
|
-
yield context.store.put('subscribers_cache', JSON.stringify(currentSubscribers));
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
const previousSubscribers = JSON.parse(cachedSubscribers);
|
|
66
|
-
const changes = [];
|
|
67
|
-
for (const current of currentSubscribers) {
|
|
68
|
-
const previous = previousSubscribers.find((p) => p.email === current.email);
|
|
69
|
-
if (previous) {
|
|
70
|
-
const hasChanges = JSON.stringify(current) !== JSON.stringify(previous);
|
|
71
|
-
if (hasChanges) {
|
|
72
|
-
changes.push({
|
|
73
|
-
id: `${current.email}_${Date.now()}`,
|
|
74
|
-
email: current.email,
|
|
75
|
-
mailingListId,
|
|
76
|
-
previousData: previous,
|
|
77
|
-
currentData: current,
|
|
78
|
-
updatedAt: new Date().toISOString(),
|
|
79
|
-
changes: detectChanges(previous, current),
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
yield context.store.put('subscribers_cache', JSON.stringify(currentSubscribers));
|
|
85
|
-
yield context.store.put('last_check', Date.now().toString());
|
|
86
|
-
return changes;
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
console.error('Error checking for subscriber updates:', error);
|
|
90
|
-
return [];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
},
|
|
94
|
-
test() {
|
|
95
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
return [
|
|
97
|
-
{
|
|
98
|
-
id: 'test-updated@example.com_1234567890',
|
|
99
|
-
email: 'test-updated@example.com',
|
|
100
|
-
mailingListId: '123456',
|
|
101
|
-
previousData: {
|
|
102
|
-
email: 'test-updated@example.com',
|
|
103
|
-
variables: { name: 'Old Name' },
|
|
104
|
-
},
|
|
105
|
-
currentData: {
|
|
106
|
-
email: 'test-updated@example.com',
|
|
107
|
-
variables: { name: 'New Name' },
|
|
108
|
-
},
|
|
109
|
-
updatedAt: new Date().toISOString(),
|
|
110
|
-
changes: {
|
|
111
|
-
'variables.name': {
|
|
112
|
-
from: 'Old Name',
|
|
113
|
-
to: 'New Name',
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
];
|
|
118
|
-
});
|
|
119
|
-
},
|
|
120
|
-
sampleData: {
|
|
121
|
-
id: 'updated-user@example.com_1234567890',
|
|
122
|
-
email: 'updated-user@example.com',
|
|
123
|
-
mailingListId: '123456',
|
|
124
|
-
previousData: {
|
|
125
|
-
email: 'updated-user@example.com',
|
|
126
|
-
variables: { phone: '+1234567890', name: 'John' },
|
|
127
|
-
},
|
|
128
|
-
currentData: {
|
|
129
|
-
email: 'updated-user@example.com',
|
|
130
|
-
variables: { phone: '+0987654321', name: 'John Updated' },
|
|
131
|
-
},
|
|
132
|
-
updatedAt: '2023-06-01T12:30:00.000Z',
|
|
133
|
-
changes: {
|
|
134
|
-
'variables.phone': {
|
|
135
|
-
from: '+1234567890',
|
|
136
|
-
to: '+0987654321',
|
|
137
|
-
},
|
|
138
|
-
'variables.name': {
|
|
139
|
-
from: 'John',
|
|
140
|
-
to: 'John Updated',
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
//# sourceMappingURL=updated-subscriber.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updated-subscriber.js","sourceRoot":"","sources":["../../../../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,CA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