@activepieces/piece-surveymonkey 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 +16 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +28 -0
- package/src/index.js.map +1 -0
- package/src/lib/common/index.d.ts +8 -0
- package/src/lib/common/index.js +93 -0
- package/src/lib/common/index.js.map +1 -0
- package/src/lib/triggers/new-response.d.ts +4 -0
- package/src/lib/triggers/new-response.js +47 -0
- package/src/lib/triggers/new-response.js.map +1 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@activepieces/piece-surveymonkey",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@sinclair/typebox": "^0.26.3",
|
|
6
|
+
"axios": "1.2.4",
|
|
7
|
+
"nanoid": "^3.3.4",
|
|
8
|
+
"semver": "7.5.3",
|
|
9
|
+
"@activepieces/pieces-common": "0.2.0",
|
|
10
|
+
"@activepieces/pieces-framework": "0.6.0",
|
|
11
|
+
"@activepieces/shared": "0.5.5",
|
|
12
|
+
"tslib": "1.14.1"
|
|
13
|
+
},
|
|
14
|
+
"main": "./src/index.js",
|
|
15
|
+
"types": "./src/index.d.ts"
|
|
16
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const smAuth: import("@activepieces/pieces-framework").OAuth2Property<true, import("@activepieces/pieces-framework").OAuth2Props>;
|
|
2
|
+
export declare const surveymonkey: import("@activepieces/pieces-framework").Piece<import("@activepieces/pieces-framework").OAuth2Property<true, import("@activepieces/pieces-framework").OAuth2Props>>;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.surveymonkey = exports.smAuth = void 0;
|
|
4
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
5
|
+
const new_response_1 = require("./lib/triggers/new-response");
|
|
6
|
+
exports.smAuth = pieces_framework_1.PieceAuth.OAuth2({
|
|
7
|
+
displayName: 'Authentication',
|
|
8
|
+
authUrl: 'https://api.surveymonkey.com/oauth/authorize',
|
|
9
|
+
tokenUrl: 'https://api.surveymonkey.com/oauth/token',
|
|
10
|
+
required: true,
|
|
11
|
+
scope: [
|
|
12
|
+
'responses_read',
|
|
13
|
+
'responses_read_detail',
|
|
14
|
+
'webhooks_read',
|
|
15
|
+
'webhooks_write',
|
|
16
|
+
'surveys_read'
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
exports.surveymonkey = (0, pieces_framework_1.createPiece)({
|
|
20
|
+
displayName: "SurveyMonkey",
|
|
21
|
+
auth: exports.smAuth,
|
|
22
|
+
minimumSupportedRelease: '0.5.0',
|
|
23
|
+
logoUrl: "https://cdn.activepieces.com/pieces/surveymonkey.png",
|
|
24
|
+
authors: ['MoShizzle'],
|
|
25
|
+
actions: [],
|
|
26
|
+
triggers: [new_response_1.newResponse],
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/pieces/surveymonkey/src/index.ts"],"names":[],"mappings":";;;AAAA,qEAAwE;AAExE,8DAA0D;AAE7C,QAAA,MAAM,GAAG,4BAAS,CAAC,MAAM,CAAC;IACnC,WAAW,EAAE,gBAAgB;IAC7B,OAAO,EAAE,8CAA8C;IACvD,QAAQ,EAAE,0CAA0C;IACpD,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE;QACH,gBAAgB;QAChB,uBAAuB;QACvB,eAAe;QACf,gBAAgB;QAChB,cAAc;KACjB;CACJ,CAAC,CAAA;AAEW,QAAA,YAAY,GAAG,IAAA,8BAAW,EAAC;IACpC,WAAW,EAAE,cAAc;IAC3B,IAAI,EAAE,cAAM;IACZ,uBAAuB,EAAE,OAAO;IAChC,OAAO,EAAE,sDAAsD;IAC/D,OAAO,EAAE,CAAC,WAAW,CAAC;IACtB,OAAO,EAAE,EAAE;IACX,QAAQ,EAAE,CAAC,0BAAW,CAAC;CAC1B,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const smCommon: {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
survey: import("@activepieces/pieces-framework").DropdownProperty<unknown, true>;
|
|
4
|
+
getSurveys: (accessToken: string) => Promise<any>;
|
|
5
|
+
subscribeWebhook: (surveyId: string | number, webhookUrl: string, accessToken: string) => Promise<any>;
|
|
6
|
+
unsubscribeWebhook: (webhookId: string | number, accessToken: string) => Promise<import("@activepieces/pieces-common").HttpResponse<import("@activepieces/pieces-common").HttpMessageBody>>;
|
|
7
|
+
getResponseDetails(accessToken: string, surveyId: string | number, responseId: string | number): Promise<import("@activepieces/pieces-common").HttpMessageBody>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.smCommon = 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
|
+
exports.smCommon = {
|
|
8
|
+
baseUrl: 'https://api.surveymonkey.com/v3',
|
|
9
|
+
survey: pieces_framework_1.Property.Dropdown({
|
|
10
|
+
displayName: 'Survey',
|
|
11
|
+
required: true,
|
|
12
|
+
refreshers: [],
|
|
13
|
+
options: (context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
if (!context['auth']) {
|
|
15
|
+
return {
|
|
16
|
+
disabled: true,
|
|
17
|
+
options: [],
|
|
18
|
+
placeholder: 'Connect your account'
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const authProp = context['auth'];
|
|
22
|
+
const options = yield exports.smCommon.getSurveys(authProp.access_token);
|
|
23
|
+
return {
|
|
24
|
+
options: options,
|
|
25
|
+
placeholder: 'Choose survey to connect'
|
|
26
|
+
};
|
|
27
|
+
})
|
|
28
|
+
}),
|
|
29
|
+
getSurveys: (accessToken) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
const request = {
|
|
31
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
32
|
+
url: `${exports.smCommon.baseUrl}/surveys`,
|
|
33
|
+
authentication: {
|
|
34
|
+
type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
|
|
35
|
+
token: accessToken
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const response = yield pieces_common_1.httpClient.sendRequest(request);
|
|
39
|
+
const newValues = response.body['data'].map((survey) => {
|
|
40
|
+
return {
|
|
41
|
+
label: survey.title,
|
|
42
|
+
value: survey.id
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
return newValues;
|
|
46
|
+
}),
|
|
47
|
+
subscribeWebhook: (surveyId, webhookUrl, accessToken) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
const request = {
|
|
49
|
+
method: pieces_common_1.HttpMethod.POST,
|
|
50
|
+
url: `${exports.smCommon.baseUrl}/webhooks`,
|
|
51
|
+
authentication: {
|
|
52
|
+
type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
|
|
53
|
+
token: accessToken
|
|
54
|
+
},
|
|
55
|
+
body: {
|
|
56
|
+
name: 'New Response Webhook',
|
|
57
|
+
event_type: 'response_created',
|
|
58
|
+
object_type: 'survey',
|
|
59
|
+
object_ids: [surveyId],
|
|
60
|
+
subscription_url: webhookUrl
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
const webhookData = yield pieces_common_1.httpClient.sendRequest(request);
|
|
64
|
+
return webhookData.body['id'];
|
|
65
|
+
}),
|
|
66
|
+
unsubscribeWebhook: (webhookId, accessToken) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
const request = {
|
|
68
|
+
method: pieces_common_1.HttpMethod.DELETE,
|
|
69
|
+
url: `${exports.smCommon.baseUrl}/webhooks/${webhookId}`,
|
|
70
|
+
authentication: {
|
|
71
|
+
type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
|
|
72
|
+
token: accessToken
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
const deleteResponse = yield pieces_common_1.httpClient.sendRequest(request);
|
|
76
|
+
return deleteResponse;
|
|
77
|
+
}),
|
|
78
|
+
getResponseDetails(accessToken, surveyId, responseId) {
|
|
79
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const request = {
|
|
81
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
82
|
+
url: `${exports.smCommon.baseUrl}/surveys/${surveyId}/responses/${responseId}/details`,
|
|
83
|
+
authentication: {
|
|
84
|
+
type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
|
|
85
|
+
token: accessToken
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const response = yield pieces_common_1.httpClient.sendRequest(request);
|
|
89
|
+
return response.body;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/surveymonkey/src/lib/common/index.ts"],"names":[],"mappings":";;;;AAAA,qEAA+E;AAC/E,+DAAsG;AAEzF,QAAA,QAAQ,GAAG;IACpB,OAAO,EAAE,iCAAiC;IAC1C,MAAM,EAAE,2BAAQ,CAAC,QAAQ,CAAC;QACtB,WAAW,EAAE,QAAQ;QACrB,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,EAAE;QACd,OAAO,EAAE,CAAO,OAAO,EAAE,EAAE;YACvB,IAAI,CAAC,OAAO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1
|
+
import { TriggerStrategy } from "@activepieces/pieces-framework";
|
|
2
|
+
export declare const newResponse: import("@activepieces/pieces-framework").ITrigger<TriggerStrategy.WEBHOOK, import("@activepieces/pieces-framework").OAuth2Property<true, import("@activepieces/pieces-framework").OAuth2Props>, {
|
|
3
|
+
survey: import("@activepieces/pieces-framework").DropdownProperty<unknown, true>;
|
|
4
|
+
}>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newResponse = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const common_1 = require("../common");
|
|
7
|
+
const __1 = require("../..");
|
|
8
|
+
exports.newResponse = (0, pieces_framework_1.createTrigger)({
|
|
9
|
+
auth: __1.smAuth,
|
|
10
|
+
name: 'new_response',
|
|
11
|
+
displayName: 'New Response',
|
|
12
|
+
description: 'Triggers when a new response is submitted',
|
|
13
|
+
type: pieces_framework_1.TriggerStrategy.WEBHOOK,
|
|
14
|
+
sampleData: {},
|
|
15
|
+
props: {
|
|
16
|
+
survey: common_1.smCommon.survey
|
|
17
|
+
},
|
|
18
|
+
//Create the webhook in SurveyMonkey and save the webhook ID in store for disable behavior
|
|
19
|
+
onEnable(context) {
|
|
20
|
+
var _a;
|
|
21
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const webhookId = yield common_1.smCommon.subscribeWebhook(context.propsValue.survey, context.webhookUrl, context.auth['access_token']);
|
|
23
|
+
yield ((_a = context.store) === null || _a === void 0 ? void 0 : _a.put('_new_response_trigger', {
|
|
24
|
+
webhookId: webhookId,
|
|
25
|
+
}));
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
//Delete the webhook from SurveyMonkey
|
|
29
|
+
onDisable(context) {
|
|
30
|
+
var _a;
|
|
31
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const response = yield ((_a = context.store) === null || _a === void 0 ? void 0 : _a.get('_new_response_trigger'));
|
|
33
|
+
if (response !== null && response !== undefined) {
|
|
34
|
+
yield common_1.smCommon.unsubscribeWebhook(response.webhookId, context.auth['access_token']);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
//Return new response
|
|
39
|
+
run(context) {
|
|
40
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const response = context.payload.body;
|
|
42
|
+
const responseData = yield common_1.smCommon.getResponseDetails(context.auth['access_token'], context.propsValue['survey'], response.object_id);
|
|
43
|
+
return [responseData];
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=new-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new-response.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/surveymonkey/src/lib/triggers/new-response.ts"],"names":[],"mappings":";;;;AAAA,qEAAgF;AAChF,sCAAqC;AACrC,6BAA+B;AAElB,QAAA,WAAW,GAAG,IAAA,gCAAa,EAAC;IACrC,IAAI,EAAE,UAAM;IACZ,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,cAAc;IAC3B,WAAW,EAAE,2CAA2C;IACxD,IAAI,EAAE,kCAAe,CAAC,OAAO;IAC7B,UAAU,EAAE,EAAE;IACd,KAAK,EAAE;QACH,MAAM,EAAE,iBAAQ,CAAC,MAAM;KAC1B;IACD,0FAA0F;IACpF,QAAQ,CAAC,OAAO;;;YAClB,MAAM,SAAS,GAAG,MAAM,iBAAQ,CAAC,gBAAgB,CAC7C,OAAO,CAAC,UAAU,CAAC,MAAgB,EACnC,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAC/B,CAAC;YAEF,MAAM,CAAA,MAAA,OAAO,CAAC,KAAK,0CAAE,GAAG,CAAC,uBAAuB,EAAE;gBAC9C,S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