@agnocon/piece-calendly 0.4.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/LICENSE.MIT-AP ADDED
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) Activepieces AB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ Derived helpers in this folder are adapted from Activepieces (MIT) for use
24
+ inside CX without depending on @activepieces/* packages at runtime.
@@ -0,0 +1,2 @@
1
+ export declare const calendly: import("@agnocon/pieces-framework").Piece<import("@agnocon/pieces-framework").SecretTextProperty<true>>;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,QAAQ,yGAkBnB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calendly = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Vendored from Activepieces packages/pieces/community/calendly/src/index.ts (MIT).
6
+ // Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
7
+ const pieces_common_1 = require("@agnocon/pieces-common");
8
+ const pieces_framework_1 = require("@agnocon/pieces-framework");
9
+ const pieces_framework_2 = require("@agnocon/pieces-framework");
10
+ const common_1 = require("./lib/common");
11
+ const invitee_canceled_trigger_1 = require("./lib/trigger/invitee-canceled.trigger");
12
+ const invitee_created_trigger_1 = require("./lib/trigger/invitee-created.trigger");
13
+ const auth_1 = require("./lib/auth");
14
+ const markdown = `
15
+ ## Obtain your Calendly Personal Token
16
+ 1. Go to https://calendly.com/integrations/api_webhooks
17
+ 2. Click on "Create New Token"
18
+ 3. Copy the token and paste it in the field below
19
+ `;
20
+ exports.calendly = (0, pieces_framework_1.createPiece)({
21
+ displayName: 'Calendly',
22
+ description: 'Simple, modern scheduling',
23
+ minimumSupportedRelease: '0.30.0',
24
+ logoUrl: 'https://cdn.activepieces.com/pieces/calendly.png',
25
+ categories: [pieces_framework_2.PieceCategory.PRODUCTIVITY],
26
+ authors: ["kishanprmr", "MoShizzle", "AbdulTheActivePiecer", "khaledmashaly", "abuaboud"],
27
+ auth: auth_1.calendlyAuth,
28
+ actions: [
29
+ (0, pieces_common_1.createCustomApiCallAction)({
30
+ baseUrl: () => common_1.calendlyCommon.baseUrl, // Replace with the actual base URL
31
+ auth: auth_1.calendlyAuth,
32
+ authMapping: (auth) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
33
+ return ({
34
+ Authorization: `Bearer ${auth.secret_text}`,
35
+ });
36
+ }),
37
+ }),
38
+ ],
39
+ triggers: [invitee_created_trigger_1.calendlyInviteeCreated, invitee_canceled_trigger_1.calendlyInviteeCanceled],
40
+ });
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,oFAAoF;AACpF,qEAAqE;AACrE,0DAAmE;AACnE,gEAAmE;AACnE,gEAA0D;AAC1D,yCAA8C;AAC9C,qFAAiF;AACjF,mFAA+E;AAC/E,qCAA0C;AAE1C,MAAM,QAAQ,GAAG;;;;;CAKhB,CAAC;AACW,QAAA,QAAQ,GAAG,IAAA,8BAAW,EAAC;IAClC,WAAW,EAAE,UAAU;IACvB,WAAW,EAAE,2BAA2B;IACxC,uBAAuB,EAAE,QAAQ;IACjC,OAAO,EAAE,kDAAkD;IAC3D,UAAU,EAAE,CAAC,gCAAa,CAAC,YAAY,CAAC;IACxC,OAAO,EAAE,CAAC,YAAY,EAAC,WAAW,EAAC,sBAAsB,EAAC,eAAe,EAAC,UAAU,CAAC;IACrF,IAAI,EAAE,mBAAY;IAClB,OAAO,EAAE;QACP,IAAA,yCAAyB,EAAC;YACxB,OAAO,EAAE,GAAG,EAAE,CAAC,uBAAc,CAAC,OAAO,EAAE,mCAAmC;YAC1E,IAAI,EAAE,mBAAY;YAClB,WAAW,EAAE,CAAO,IAAI,EAAE,EAAE;gBAAC,OAAA,CAAC;oBAC5B,aAAa,EAAE,UAAU,IAAI,CAAC,WAAW,EAAE;iBAC5C,CAAC,CAAA;cAAA;SACH,CAAC;KACH;IACD,QAAQ,EAAE,CAAC,gDAAsB,EAAE,kDAAuB,CAAC;CAC5D,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const calendlyAuth: import("@agnocon/pieces-framework").SecretTextProperty<true>;
2
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,YAAY,8DAiBvB,CAAC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calendlyAuth = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Vendored from Activepieces packages/pieces/community/calendly/src/lib/auth.ts (MIT).
6
+ // Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
7
+ const pieces_framework_1 = require("@agnocon/pieces-framework");
8
+ const common_1 = require("./common");
9
+ const markdown = `
10
+ ## Obtain your Calendly Personal Token
11
+ 1. Go to https://calendly.com/integrations/api_webhooks
12
+ 2. Click on "Create New Token"
13
+ 3. Copy the token and paste it in the field below
14
+ `;
15
+ exports.calendlyAuth = pieces_framework_1.PieceAuth.SecretText({
16
+ displayName: 'Personal Token',
17
+ required: true,
18
+ description: markdown,
19
+ validate: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
20
+ try {
21
+ common_1.calendlyCommon.getUser(auth);
22
+ return {
23
+ valid: true,
24
+ };
25
+ }
26
+ catch (e) {
27
+ return {
28
+ valid: false,
29
+ error: 'Connection failed. Please check your token and try again.',
30
+ };
31
+ }
32
+ }),
33
+ });
34
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":";;;;AAAA,uFAAuF;AACvF,qEAAqE;AACrE,gEAAsD;AACtD,qCAA0C;AAE1C,MAAM,QAAQ,GAAG;;;;;CAKhB,CAAC;AAEW,QAAA,YAAY,GAAG,4BAAS,CAAC,UAAU,CAAC;IAC/C,WAAW,EAAE,gBAAgB;IAC7B,QAAQ,EAAE,IAAI;IACd,WAAW,EAAE,QAAQ;IACrB,QAAQ,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;QACvB,IAAI,CAAC;YACH,uBAAc,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC7B,OAAO;gBACL,KAAK,EAAE,IAAI;aACZ,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO;gBACL,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,2DAA2D;aACnE,CAAC;QACJ,CAAC;IACH,CAAC,CAAA;CACF,CAAC,CAAC"}
@@ -0,0 +1,20 @@
1
+ interface CalendlyUser {
2
+ /**User uri */
3
+ uri: string;
4
+ email: string;
5
+ name: string;
6
+ /**Organization uri */
7
+ current_organization: string;
8
+ }
9
+ export interface CalendlyWebhookInformation {
10
+ webhookId: string;
11
+ }
12
+ export declare const calendlyCommon: {
13
+ baseUrl: string;
14
+ scope: import("@agnocon/pieces-framework").StaticDropdownProperty<string, true>;
15
+ getUser: (personalToken: string) => Promise<CalendlyUser>;
16
+ authorizationHeader: (personalToken: string) => string;
17
+ UuidFromUri: (uri: string) => string | undefined;
18
+ };
19
+ export {};
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/common/index.ts"],"names":[],"mappings":"AASA,UAAU,YAAY;IACpB,cAAc;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AACD,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,cAAc;;;6BAaM,MAAM;yCAaA,MAAM;uBACxB,MAAM;CAC1B,CAAC"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calendlyCommon = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Vendored from Activepieces packages/pieces/community/calendly/src/lib/common/index.ts (MIT).
6
+ // Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
7
+ const pieces_framework_1 = require("@agnocon/pieces-framework");
8
+ const pieces_common_1 = require("@agnocon/pieces-common");
9
+ exports.calendlyCommon = {
10
+ baseUrl: 'https://api.calendly.com',
11
+ scope: pieces_framework_1.Property.StaticDropdown({
12
+ displayName: 'Scope',
13
+ required: true,
14
+ options: {
15
+ options: [
16
+ { value: 'user', label: 'User' },
17
+ { value: 'organization', label: 'Organization' },
18
+ ],
19
+ disabled: false,
20
+ },
21
+ }),
22
+ getUser: (personalToken) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
23
+ const request = {
24
+ method: pieces_common_1.HttpMethod.GET,
25
+ url: `${exports.calendlyCommon.baseUrl}/users/me`,
26
+ headers: {
27
+ Authorization: exports.calendlyCommon.authorizationHeader(personalToken),
28
+ },
29
+ };
30
+ const response = yield pieces_common_1.httpClient.sendRequest(request);
31
+ return response.body.resource;
32
+ }),
33
+ authorizationHeader: (personalToken) => `Bearer ${personalToken}`,
34
+ UuidFromUri: (uri) => uri.split('/').pop(),
35
+ };
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/common/index.ts"],"names":[],"mappings":";;;;AAAA,+FAA+F;AAC/F,qEAAqE;AACrE,gEAAqD;AACrD,0DAIgC;AAcnB,QAAA,cAAc,GAAG;IAC5B,OAAO,EAAE,0BAA0B;IACnC,KAAK,EAAE,2BAAQ,CAAC,cAAc,CAAC;QAC7B,WAAW,EAAE,OAAO;QACpB,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;gBAChC,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,cAAc,EAAE;aACjD;YACD,QAAQ,EAAE,KAAK;SAChB;KACF,CAAC;IACF,OAAO,EAAE,CAAO,aAAqB,EAAE,EAAE;QACvC,MAAM,OAAO,GAAgB;YAC3B,MAAM,EAAE,0BAAU,CAAC,GAAG;YACtB,GAAG,EAAE,GAAG,sBAAc,CAAC,OAAO,WAAW;YACzC,OAAO,EAAE;gBACP,aAAa,EAAE,sBAAc,CAAC,mBAAmB,CAAC,aAAa,CAAC;aACjE;SACF,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,0BAAU,CAAC,WAAW,CAC3C,OAAO,CACR,CAAC;QACF,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;IAChC,CAAC,CAAA;IACD,mBAAmB,EAAE,CAAC,aAAqB,EAAE,EAAE,CAAC,UAAU,aAAa,EAAE;IACzE,WAAW,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE;CACnD,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { TriggerStrategy } from '@agnocon/pieces-framework';
2
+ export declare const calendlyInviteeCanceled: import("@agnocon/pieces-framework").ITrigger<TriggerStrategy.WEBHOOK, import("@agnocon/pieces-framework").SecretTextProperty<true>, {
3
+ scope: import("@agnocon/pieces-framework").StaticDropdownProperty<string, true>;
4
+ }> | import("@agnocon/pieces-framework").ITrigger<TriggerStrategy.POLLING, import("@agnocon/pieces-framework").SecretTextProperty<true>, {
5
+ scope: import("@agnocon/pieces-framework").StaticDropdownProperty<string, true>;
6
+ }> | import("@agnocon/pieces-framework").ITrigger<TriggerStrategy.MANUAL, import("@agnocon/pieces-framework").SecretTextProperty<true>, {
7
+ scope: import("@agnocon/pieces-framework").StaticDropdownProperty<string, true>;
8
+ }> | import("@agnocon/pieces-framework").ITrigger<TriggerStrategy.APP_WEBHOOK, import("@agnocon/pieces-framework").SecretTextProperty<true>, {
9
+ scope: import("@agnocon/pieces-framework").StaticDropdownProperty<string, true>;
10
+ }>;
11
+ //# sourceMappingURL=invitee-canceled.trigger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invitee-canceled.trigger.d.ts","sourceRoot":"","sources":["../../../src/lib/trigger/invitee-canceled.trigger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAY3E,eAAO,MAAM,uBAAuB;;;;;;;;EAkGlC,CAAC"}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calendlyInviteeCanceled = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Vendored from Activepieces packages/pieces/community/calendly/src/lib/trigger/invitee-canceled.trigger.ts (MIT).
6
+ // Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
7
+ const pieces_framework_1 = require("@agnocon/pieces-framework");
8
+ const pieces_common_1 = require("@agnocon/pieces-common");
9
+ const common_1 = require("../common");
10
+ const auth_1 = require("../auth");
11
+ const triggerNameInStore = 'calendly_invitee_canceled_trigger';
12
+ exports.calendlyInviteeCanceled = (0, pieces_framework_1.createTrigger)({
13
+ auth: auth_1.calendlyAuth,
14
+ name: 'invitee_canceled',
15
+ displayName: 'Event Canceled',
16
+ description: 'Triggers when a new Calendly event is canceled',
17
+ aiMetadata: {
18
+ description: 'Fires when an invitee cancels a scheduled Calendly event. Emits the canceled event including the invitee details, the cancellation reason and who canceled it (host or invitee), and the event status set to "canceled".',
19
+ },
20
+ props: {
21
+ scope: common_1.calendlyCommon.scope,
22
+ },
23
+ sampleData: {
24
+ created_at: '2023-01-29T13:57:17.000000Z',
25
+ created_by: 'https://api.calendly.com/users/AAAAAAA',
26
+ event: 'invitee.canceled',
27
+ payload: {
28
+ cancel_url: 'https://calendly.com/cancellations/AAAAAAAA',
29
+ cancellation: {
30
+ canceler_type: 'host',
31
+ canceled_by: 'Ashraf Samhouri',
32
+ reason: 'testing',
33
+ },
34
+ created_at: '2023-01-29T13:56:46.894198Z',
35
+ email: 'test@test.com',
36
+ event: 'https://api.calendly.com/scheduled_events/AAAAAAAAA',
37
+ first_name: null,
38
+ last_name: null,
39
+ name: 'abdul',
40
+ new_invitee: null,
41
+ no_show: null,
42
+ old_invitee: null,
43
+ payment: null,
44
+ questions_and_answers: [],
45
+ reconfirmation: null,
46
+ reschedule_url: 'https://calendly.com/reschedulings/AAAAAAAA',
47
+ rescheduled: false,
48
+ routing_form_submission: null,
49
+ status: 'canceled',
50
+ text_reminder_number: null,
51
+ timezone: 'Asia/Baghdad',
52
+ tracking: {
53
+ utm_campaign: null,
54
+ utm_source: null,
55
+ utm_medium: null,
56
+ utm_content: null,
57
+ utm_term: null,
58
+ salesforce_uuid: null,
59
+ },
60
+ updated_at: '2023-01-29T13:57:17.466943Z',
61
+ uri: 'https://api.calendly.com/scheduled_events/AAAAAAAAAAAaA/invitees/AAAAAAAA',
62
+ },
63
+ },
64
+ type: pieces_framework_1.TriggerStrategy.WEBHOOK,
65
+ onEnable(context) {
66
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
67
+ var _a;
68
+ const calendlyUser = yield common_1.calendlyCommon.getUser(context.auth.secret_text);
69
+ const request = {
70
+ method: pieces_common_1.HttpMethod.POST,
71
+ url: `${common_1.calendlyCommon.baseUrl}/webhook_subscriptions`,
72
+ body: {
73
+ url: context.webhookUrl,
74
+ organization: calendlyUser.current_organization,
75
+ user: calendlyUser.uri,
76
+ scope: context.propsValue.scope,
77
+ events: ['invitee.canceled'],
78
+ },
79
+ authentication: {
80
+ token: context.auth.secret_text,
81
+ type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
82
+ },
83
+ queryParams: {},
84
+ };
85
+ const { body } = yield pieces_common_1.httpClient.sendRequest(request);
86
+ yield ((_a = context.store) === null || _a === void 0 ? void 0 : _a.put(triggerNameInStore, {
87
+ webhookId: common_1.calendlyCommon.UuidFromUri(body.resource.uri),
88
+ }));
89
+ });
90
+ },
91
+ onDisable(context) {
92
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
93
+ var _a;
94
+ const response = yield ((_a = context.store) === null || _a === void 0 ? void 0 : _a.get(triggerNameInStore));
95
+ if (response !== null && response !== undefined) {
96
+ const request = {
97
+ method: pieces_common_1.HttpMethod.DELETE,
98
+ url: `${common_1.calendlyCommon.baseUrl}/webhook_subscriptions/${response.webhookId}`,
99
+ authentication: {
100
+ token: context.auth.secret_text,
101
+ type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
102
+ },
103
+ };
104
+ yield pieces_common_1.httpClient.sendRequest(request);
105
+ }
106
+ });
107
+ },
108
+ run(context) {
109
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
110
+ return [context.payload.body];
111
+ });
112
+ },
113
+ });
114
+ //# sourceMappingURL=invitee-canceled.trigger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invitee-canceled.trigger.js","sourceRoot":"","sources":["../../../src/lib/trigger/invitee-canceled.trigger.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,11 @@
1
+ import { TriggerStrategy } from '@agnocon/pieces-framework';
2
+ export declare const calendlyInviteeCreated: import("@agnocon/pieces-framework").ITrigger<TriggerStrategy.WEBHOOK, import("@agnocon/pieces-framework").SecretTextProperty<true>, {
3
+ scope: import("@agnocon/pieces-framework").StaticDropdownProperty<string, true>;
4
+ }> | import("@agnocon/pieces-framework").ITrigger<TriggerStrategy.POLLING, import("@agnocon/pieces-framework").SecretTextProperty<true>, {
5
+ scope: import("@agnocon/pieces-framework").StaticDropdownProperty<string, true>;
6
+ }> | import("@agnocon/pieces-framework").ITrigger<TriggerStrategy.MANUAL, import("@agnocon/pieces-framework").SecretTextProperty<true>, {
7
+ scope: import("@agnocon/pieces-framework").StaticDropdownProperty<string, true>;
8
+ }> | import("@agnocon/pieces-framework").ITrigger<TriggerStrategy.APP_WEBHOOK, import("@agnocon/pieces-framework").SecretTextProperty<true>, {
9
+ scope: import("@agnocon/pieces-framework").StaticDropdownProperty<string, true>;
10
+ }>;
11
+ //# sourceMappingURL=invitee-created.trigger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invitee-created.trigger.d.ts","sourceRoot":"","sources":["../../../src/lib/trigger/invitee-created.trigger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAiB,MAAM,2BAA2B,CAAC;AAY3E,eAAO,MAAM,sBAAsB;;;;;;;;EAuFjC,CAAC"}
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calendlyInviteeCreated = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Vendored from Activepieces packages/pieces/community/calendly/src/lib/trigger/invitee-created.trigger.ts (MIT).
6
+ // Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
7
+ const pieces_framework_1 = require("@agnocon/pieces-framework");
8
+ const pieces_common_1 = require("@agnocon/pieces-common");
9
+ const common_1 = require("../common");
10
+ const auth_1 = require("../auth");
11
+ const triggerNameInStore = 'calendly_invitee_created_trigger';
12
+ exports.calendlyInviteeCreated = (0, pieces_framework_1.createTrigger)({
13
+ auth: auth_1.calendlyAuth,
14
+ name: 'invitee_created',
15
+ displayName: 'Event Scheduled',
16
+ description: 'Triggers when a new Calendly event is scheduled',
17
+ aiMetadata: {
18
+ description: 'Fires when an invitee schedules a new Calendly event (a booking is created). Emits the new event including the invitee details (name, email), the event URI, scheduling timestamps, and the event status set to "active".',
19
+ },
20
+ props: {
21
+ scope: common_1.calendlyCommon.scope,
22
+ },
23
+ sampleData: {
24
+ created_at: '2023-01-29T13:50:13.000000Z',
25
+ created_by: 'https://api.calendly.com/users/AAAAAAAAAAAA',
26
+ payload: {
27
+ cancel_url: 'https://calendly.com/cancellations/AAAAAAAAAAA',
28
+ created_at: '2023-01-29T13:50:13.072950Z',
29
+ email: 'abdulyki@activepieces.com',
30
+ event: 'https://api.calendly.com/scheduled_events/AAAAAAAAAAAA',
31
+ first_name: null,
32
+ last_name: null,
33
+ name: 'abdul',
34
+ new_invitee: null,
35
+ no_show: null,
36
+ old_invitee: null,
37
+ payment: null,
38
+ questions_and_answers: [],
39
+ reconfirmation: null,
40
+ reschedule_url: 'https://calendly.com/reschedulings/AAAAAAAAAAAA',
41
+ rescheduled: false,
42
+ routing_form_submission: null,
43
+ status: 'active',
44
+ text_reminder_number: null,
45
+ timezone: 'Asia/Baghdad',
46
+ updated_at: '2023-01-29T13:50:13.072950Z',
47
+ uri: 'https://api.calendly.com/scheduled_events/AAAAAAAAAAAaA/invitees/AAAAAAAAAAAA',
48
+ },
49
+ },
50
+ type: pieces_framework_1.TriggerStrategy.WEBHOOK,
51
+ onEnable(context) {
52
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
53
+ var _a;
54
+ const calendlyUser = yield common_1.calendlyCommon.getUser(context.auth.secret_text);
55
+ const request = {
56
+ method: pieces_common_1.HttpMethod.POST,
57
+ url: `${common_1.calendlyCommon.baseUrl}/webhook_subscriptions`,
58
+ body: {
59
+ url: context.webhookUrl,
60
+ organization: calendlyUser.current_organization,
61
+ user: calendlyUser.uri,
62
+ scope: context.propsValue['scope'],
63
+ events: ['invitee.created'],
64
+ },
65
+ authentication: {
66
+ token: context.auth.secret_text,
67
+ type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
68
+ },
69
+ queryParams: {},
70
+ };
71
+ const { body } = yield pieces_common_1.httpClient.sendRequest(request);
72
+ yield ((_a = context.store) === null || _a === void 0 ? void 0 : _a.put(triggerNameInStore, {
73
+ webhookId: common_1.calendlyCommon.UuidFromUri(body.resource.uri),
74
+ }));
75
+ });
76
+ },
77
+ onDisable(context) {
78
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
79
+ var _a;
80
+ const response = yield ((_a = context.store) === null || _a === void 0 ? void 0 : _a.get(triggerNameInStore));
81
+ console.log(response || 'nothing');
82
+ if (response !== null && response !== undefined) {
83
+ const request = {
84
+ method: pieces_common_1.HttpMethod.DELETE,
85
+ url: `${common_1.calendlyCommon.baseUrl}/webhook_subscriptions/${response.webhookId}`,
86
+ authentication: {
87
+ token: context.auth.secret_text,
88
+ type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
89
+ },
90
+ };
91
+ yield pieces_common_1.httpClient.sendRequest(request);
92
+ }
93
+ else {
94
+ throw Error('context store was null');
95
+ }
96
+ });
97
+ },
98
+ run(context) {
99
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
100
+ return [context.payload.body];
101
+ });
102
+ },
103
+ });
104
+ //# sourceMappingURL=invitee-created.trigger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invitee-created.trigger.js","sourceRoot":"","sources":["../../../src/lib/trigger/invitee-created.trigger.ts"],"names":[],"mappings":"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"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@agnocon/piece-calendly",
3
+ "version": "0.4.7",
4
+ "description": "AgnoCon calendly connector",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "require": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src",
17
+ "LICENSE.MIT-AP"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "vendor": "node ../scripts/vendor-ap.mjs piece-calendly"
22
+ },
23
+ "dependencies": {
24
+ "@agnocon/core-utils": "0.2.0",
25
+ "@agnocon/piece-types": "0.3.1",
26
+ "@agnocon/pieces-common": "0.12.8",
27
+ "@agnocon/pieces-framework": "0.36.0",
28
+ "tslib": "2.6.2"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "20.17.6",
32
+ "typescript": "5.5.4"
33
+ },
34
+ "license": "MIT",
35
+ "agnocon": {
36
+ "originVersion": "0.4.7"
37
+ },
38
+ "publishConfig": {
39
+ "access": "restricted",
40
+ "tag": "latest"
41
+ },
42
+ "keywords": [
43
+ "agnocon",
44
+ "connector"
45
+ ]
46
+ }
package/src/index.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { createCustomApiCallAction } from '@agnocon/pieces-common';
2
+ import { PieceAuth, createPiece } from '@agnocon/pieces-framework';
3
+ import { PieceCategory } from '@agnocon/pieces-framework';
4
+ import { calendlyCommon } from './lib/common';
5
+ import { calendlyInviteeCanceled } from './lib/trigger/invitee-canceled.trigger';
6
+ import { calendlyInviteeCreated } from './lib/trigger/invitee-created.trigger';
7
+ import { calendlyAuth } from './lib/auth';
8
+
9
+ const markdown = `
10
+ ## Obtain your Calendly Personal Token
11
+ 1. Go to https://calendly.com/integrations/api_webhooks
12
+ 2. Click on "Create New Token"
13
+ 3. Copy the token and paste it in the field below
14
+ `;
15
+ export const calendly = createPiece({
16
+ displayName: 'Calendly',
17
+ description: 'Simple, modern scheduling',
18
+ minimumSupportedRelease: '0.30.0',
19
+ logoUrl: 'https://cdn.activepieces.com/pieces/calendly.png',
20
+ categories: [PieceCategory.PRODUCTIVITY],
21
+ authors: ["kishanprmr","MoShizzle","AbdulTheActivePiecer","khaledmashaly","abuaboud"],
22
+ auth: calendlyAuth,
23
+ actions: [
24
+ createCustomApiCallAction({
25
+ baseUrl: () => calendlyCommon.baseUrl, // Replace with the actual base URL
26
+ auth: calendlyAuth,
27
+ authMapping: async (auth) => ({
28
+ Authorization: `Bearer ${auth.secret_text}`,
29
+ }),
30
+ }),
31
+ ],
32
+ triggers: [calendlyInviteeCreated, calendlyInviteeCanceled],
33
+ });
@@ -0,0 +1,28 @@
1
+ import { PieceAuth } from '@agnocon/pieces-framework';
2
+ import { calendlyCommon } from './common';
3
+
4
+ const markdown = `
5
+ ## Obtain your Calendly Personal Token
6
+ 1. Go to https://calendly.com/integrations/api_webhooks
7
+ 2. Click on "Create New Token"
8
+ 3. Copy the token and paste it in the field below
9
+ `;
10
+
11
+ export const calendlyAuth = PieceAuth.SecretText({
12
+ displayName: 'Personal Token',
13
+ required: true,
14
+ description: markdown,
15
+ validate: async ({ auth }) => {
16
+ try {
17
+ calendlyCommon.getUser(auth);
18
+ return {
19
+ valid: true,
20
+ };
21
+ } catch (e) {
22
+ return {
23
+ valid: false,
24
+ error: 'Connection failed. Please check your token and try again.',
25
+ };
26
+ }
27
+ },
28
+ });
@@ -0,0 +1,48 @@
1
+ import { Property } from '@agnocon/pieces-framework';
2
+ import {
3
+ HttpRequest,
4
+ HttpMethod,
5
+ httpClient,
6
+ } from '@agnocon/pieces-common';
7
+
8
+ interface CalendlyUser {
9
+ /**User uri */
10
+ uri: string;
11
+ email: string;
12
+ name: string;
13
+ /**Organization uri */
14
+ current_organization: string;
15
+ }
16
+ export interface CalendlyWebhookInformation {
17
+ webhookId: string;
18
+ }
19
+
20
+ export const calendlyCommon = {
21
+ baseUrl: 'https://api.calendly.com',
22
+ scope: Property.StaticDropdown({
23
+ displayName: 'Scope',
24
+ required: true,
25
+ options: {
26
+ options: [
27
+ { value: 'user', label: 'User' },
28
+ { value: 'organization', label: 'Organization' },
29
+ ],
30
+ disabled: false,
31
+ },
32
+ }),
33
+ getUser: async (personalToken: string) => {
34
+ const request: HttpRequest = {
35
+ method: HttpMethod.GET,
36
+ url: `${calendlyCommon.baseUrl}/users/me`,
37
+ headers: {
38
+ Authorization: calendlyCommon.authorizationHeader(personalToken),
39
+ },
40
+ };
41
+ const response = await httpClient.sendRequest<{ resource: CalendlyUser }>(
42
+ request
43
+ );
44
+ return response.body.resource;
45
+ },
46
+ authorizationHeader: (personalToken: string) => `Bearer ${personalToken}`,
47
+ UuidFromUri: (uri: string) => uri.split('/').pop(),
48
+ };
@@ -0,0 +1,111 @@
1
+ import { createTrigger, TriggerStrategy } from '@agnocon/pieces-framework';
2
+ import {
3
+ AuthenticationType,
4
+ httpClient,
5
+ HttpMethod,
6
+ HttpRequest,
7
+ } from '@agnocon/pieces-common';
8
+ import { calendlyCommon, CalendlyWebhookInformation } from '../common';
9
+ import { calendlyAuth } from '../auth';
10
+
11
+ const triggerNameInStore = 'calendly_invitee_canceled_trigger';
12
+
13
+ export const calendlyInviteeCanceled = createTrigger({
14
+ auth: calendlyAuth,
15
+ name: 'invitee_canceled',
16
+ displayName: 'Event Canceled',
17
+ description: 'Triggers when a new Calendly event is canceled',
18
+ aiMetadata: {
19
+ description:
20
+ 'Fires when an invitee cancels a scheduled Calendly event. Emits the canceled event including the invitee details, the cancellation reason and who canceled it (host or invitee), and the event status set to "canceled".',
21
+ },
22
+ props: {
23
+ scope: calendlyCommon.scope,
24
+ },
25
+ sampleData: {
26
+ created_at: '2023-01-29T13:57:17.000000Z',
27
+ created_by: 'https://api.calendly.com/users/AAAAAAA',
28
+ event: 'invitee.canceled',
29
+ payload: {
30
+ cancel_url: 'https://calendly.com/cancellations/AAAAAAAA',
31
+ cancellation: {
32
+ canceler_type: 'host',
33
+ canceled_by: 'Ashraf Samhouri',
34
+ reason: 'testing',
35
+ },
36
+ created_at: '2023-01-29T13:56:46.894198Z',
37
+ email: 'test@test.com',
38
+ event: 'https://api.calendly.com/scheduled_events/AAAAAAAAA',
39
+ first_name: null,
40
+ last_name: null,
41
+ name: 'abdul',
42
+ new_invitee: null,
43
+ no_show: null,
44
+ old_invitee: null,
45
+ payment: null,
46
+ questions_and_answers: [],
47
+ reconfirmation: null,
48
+ reschedule_url: 'https://calendly.com/reschedulings/AAAAAAAA',
49
+ rescheduled: false,
50
+ routing_form_submission: null,
51
+ status: 'canceled',
52
+ text_reminder_number: null,
53
+ timezone: 'Asia/Baghdad',
54
+ tracking: {
55
+ utm_campaign: null,
56
+ utm_source: null,
57
+ utm_medium: null,
58
+ utm_content: null,
59
+ utm_term: null,
60
+ salesforce_uuid: null,
61
+ },
62
+ updated_at: '2023-01-29T13:57:17.466943Z',
63
+ uri: 'https://api.calendly.com/scheduled_events/AAAAAAAAAAAaA/invitees/AAAAAAAA',
64
+ },
65
+ },
66
+ type: TriggerStrategy.WEBHOOK,
67
+ async onEnable(context) {
68
+ const calendlyUser = await calendlyCommon.getUser(context.auth.secret_text);
69
+ const request: HttpRequest = {
70
+ method: HttpMethod.POST,
71
+ url: `${calendlyCommon.baseUrl}/webhook_subscriptions`,
72
+ body: {
73
+ url: context.webhookUrl,
74
+ organization: calendlyUser.current_organization,
75
+ user: calendlyUser.uri,
76
+ scope: context.propsValue.scope,
77
+ events: ['invitee.canceled'],
78
+ },
79
+ authentication: {
80
+ token: context.auth.secret_text,
81
+ type: AuthenticationType.BEARER_TOKEN,
82
+ },
83
+ queryParams: {},
84
+ };
85
+ const { body } = await httpClient.sendRequest<{
86
+ resource: { uri: string };
87
+ }>(request);
88
+ await context.store?.put<CalendlyWebhookInformation>(triggerNameInStore, {
89
+ webhookId: calendlyCommon.UuidFromUri(body.resource.uri)!,
90
+ });
91
+ },
92
+ async onDisable(context) {
93
+ const response = await context.store?.get<CalendlyWebhookInformation>(
94
+ triggerNameInStore
95
+ );
96
+ if (response !== null && response !== undefined) {
97
+ const request: HttpRequest = {
98
+ method: HttpMethod.DELETE,
99
+ url: `${calendlyCommon.baseUrl}/webhook_subscriptions/${response.webhookId}`,
100
+ authentication: {
101
+ token: context.auth.secret_text,
102
+ type: AuthenticationType.BEARER_TOKEN,
103
+ },
104
+ };
105
+ await httpClient.sendRequest(request);
106
+ }
107
+ },
108
+ async run(context) {
109
+ return [context.payload.body];
110
+ },
111
+ });
@@ -0,0 +1,100 @@
1
+ import { TriggerStrategy, createTrigger } from '@agnocon/pieces-framework';
2
+ import {
3
+ HttpRequest,
4
+ HttpMethod,
5
+ AuthenticationType,
6
+ httpClient,
7
+ } from '@agnocon/pieces-common';
8
+ import { calendlyCommon, CalendlyWebhookInformation } from '../common';
9
+ import { calendlyAuth } from '../auth';
10
+
11
+ const triggerNameInStore = 'calendly_invitee_created_trigger';
12
+
13
+ export const calendlyInviteeCreated = createTrigger({
14
+ auth: calendlyAuth,
15
+ name: 'invitee_created',
16
+ displayName: 'Event Scheduled',
17
+ description: 'Triggers when a new Calendly event is scheduled',
18
+ aiMetadata: {
19
+ description:
20
+ 'Fires when an invitee schedules a new Calendly event (a booking is created). Emits the new event including the invitee details (name, email), the event URI, scheduling timestamps, and the event status set to "active".',
21
+ },
22
+ props: {
23
+ scope: calendlyCommon.scope,
24
+ },
25
+ sampleData: {
26
+ created_at: '2023-01-29T13:50:13.000000Z',
27
+ created_by: 'https://api.calendly.com/users/AAAAAAAAAAAA',
28
+ payload: {
29
+ cancel_url: 'https://calendly.com/cancellations/AAAAAAAAAAA',
30
+ created_at: '2023-01-29T13:50:13.072950Z',
31
+ email: 'abdulyki@activepieces.com',
32
+ event: 'https://api.calendly.com/scheduled_events/AAAAAAAAAAAA',
33
+ first_name: null,
34
+ last_name: null,
35
+ name: 'abdul',
36
+ new_invitee: null,
37
+ no_show: null,
38
+ old_invitee: null,
39
+ payment: null,
40
+ questions_and_answers: [],
41
+ reconfirmation: null,
42
+ reschedule_url: 'https://calendly.com/reschedulings/AAAAAAAAAAAA',
43
+ rescheduled: false,
44
+ routing_form_submission: null,
45
+ status: 'active',
46
+ text_reminder_number: null,
47
+ timezone: 'Asia/Baghdad',
48
+ updated_at: '2023-01-29T13:50:13.072950Z',
49
+ uri: 'https://api.calendly.com/scheduled_events/AAAAAAAAAAAaA/invitees/AAAAAAAAAAAA',
50
+ },
51
+ },
52
+ type: TriggerStrategy.WEBHOOK,
53
+ async onEnable(context) {
54
+ const calendlyUser = await calendlyCommon.getUser(context.auth.secret_text);
55
+ const request: HttpRequest = {
56
+ method: HttpMethod.POST,
57
+ url: `${calendlyCommon.baseUrl}/webhook_subscriptions`,
58
+ body: {
59
+ url: context.webhookUrl,
60
+ organization: calendlyUser.current_organization,
61
+ user: calendlyUser.uri,
62
+ scope: context.propsValue['scope'],
63
+ events: ['invitee.created'],
64
+ },
65
+ authentication: {
66
+ token: context.auth.secret_text,
67
+ type: AuthenticationType.BEARER_TOKEN,
68
+ },
69
+ queryParams: {},
70
+ };
71
+ const { body } = await httpClient.sendRequest<{
72
+ resource: { uri: string };
73
+ }>(request);
74
+ await context.store?.put<CalendlyWebhookInformation>(triggerNameInStore, {
75
+ webhookId: calendlyCommon.UuidFromUri(body.resource.uri)!,
76
+ });
77
+ },
78
+ async onDisable(context) {
79
+ const response = await context.store?.get<CalendlyWebhookInformation>(
80
+ triggerNameInStore
81
+ );
82
+ console.log(response || 'nothing');
83
+ if (response !== null && response !== undefined) {
84
+ const request: HttpRequest = {
85
+ method: HttpMethod.DELETE,
86
+ url: `${calendlyCommon.baseUrl}/webhook_subscriptions/${response.webhookId}`,
87
+ authentication: {
88
+ token: context.auth.secret_text,
89
+ type: AuthenticationType.BEARER_TOKEN,
90
+ },
91
+ };
92
+ await httpClient.sendRequest(request);
93
+ } else {
94
+ throw Error('context store was null');
95
+ }
96
+ },
97
+ async run(context) {
98
+ return [context.payload.body];
99
+ },
100
+ });