@coasy/piece-coasy 0.0.1 → 0.0.3

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 CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@coasy/piece-coasy",
3
- "version": "0.0.1"
3
+ "version": "0.0.3"
4
4
  }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createPiece, PieceAuth, Property } from '@activepieces/pieces-framework';
2
- import { createFunnelParticipant } from './lib/actions/createFunnelParticipant';
2
+ import { createFunnelParticipant } from './lib/actions/create-funnel-participant';
3
+ import { newFunnelParticipant } from './lib/triggers/new-funnel-participant';
3
4
 
4
5
  export const coasyAuth = PieceAuth.CustomAuth({
5
6
  required: true,
@@ -30,5 +31,5 @@ export const coasy = createPiece({
30
31
  logoUrl: 'https://console.achtsamkeitsakademie.de/favicon/apple-icon.png',
31
32
  authors: ["christian-schab"],
32
33
  actions: [createFunnelParticipant],
33
- triggers: []
34
+ triggers: [newFunnelParticipant]
34
35
  });
@@ -1,6 +1,6 @@
1
1
  import { createAction, Property } from '@activepieces/pieces-framework';
2
2
  import { coasyAuth } from '../../index';
3
- import { CoasyClient } from '../../coasyClient';
3
+ import { CoasyClient } from '../common/coasyClient';
4
4
 
5
5
  export const createFunnelParticipant = createAction({
6
6
  auth: coasyAuth,
@@ -30,21 +30,13 @@ export const createFunnelParticipant = createAction({
30
30
  })
31
31
  },
32
32
  async run(configValue) {
33
- console.log(`Run createFunnelParticipant`);
34
-
35
33
  const { propsValue, auth } = configValue;
36
- console.log(`Loaded PropsValue and Auth`);
37
-
38
34
  const client = new CoasyClient(auth.baseUrl, auth.apiKey);
39
- console.log(`Built client`);
40
-
41
35
  const request = {
42
36
  email: propsValue.email,
43
37
  firstName: propsValue.firstName,
44
38
  funnelId: propsValue.funnelId
45
39
  };
46
- console.log(`Built request`, request);
47
-
48
40
  return client.action('createFunnelParticipant', request);
49
41
  }
50
42
  });
@@ -14,6 +14,25 @@ export class CoasyClient {
14
14
  return this.request(`/apps/actions/${actionName}`, request);
15
15
  }
16
16
 
17
+ async createTrigger(trigger: string, hookUrl: string, filter: any) {
18
+ return this.request(`/apps/triggers/create`, {
19
+ hookUrl,
20
+ trigger,
21
+ filter
22
+ });
23
+ }
24
+
25
+ async destroyTrigger(webhookId: string) {
26
+ return this.request(`/apps/triggers/destroy`, { webhookId})
27
+ }
28
+
29
+ async listTriggerEvents(trigger: string) {
30
+ return this.request(`/apps/list`, {
31
+ trigger
32
+ })
33
+ }
34
+
35
+
17
36
  async request(path: string, requestBody: any) {
18
37
  const request: HttpRequest<string> = {
19
38
  method: HttpMethod.POST,
@@ -0,0 +1,40 @@
1
+
2
+ import { CoasyClient } from './coasyClient';
3
+
4
+ import { SecretTextProperty, ShortTextProperty, StaticPropsValue, Store } from '@activepieces/pieces-framework';
5
+
6
+ export interface CreateTriggerRequest {
7
+ triggerName: string;
8
+ webhookUrl: string;
9
+ auth: StaticPropsValue<{
10
+ baseUrl: ShortTextProperty<true>,
11
+ apiKey: SecretTextProperty<true>
12
+ }>
13
+ filter: any;
14
+ store: Store;
15
+ }
16
+
17
+ export interface DestroyTriggerRequest {
18
+ triggerName: string;
19
+ auth: StaticPropsValue<{
20
+ baseUrl: ShortTextProperty<true>,
21
+ apiKey: SecretTextProperty<true>
22
+ }>
23
+ store: Store;
24
+ }
25
+
26
+ export const createCoasyTrigger = async (request: CreateTriggerRequest) => {
27
+ const { triggerName, webhookUrl, filter, auth, store} = request;
28
+ const client = new CoasyClient(auth.baseUrl, auth.apiKey);
29
+ const response = await client.createTrigger(triggerName, webhookUrl, filter);
30
+ await store.put<string>(`${triggerName}__WEBHOOK_ID`, response.id);
31
+ };
32
+
33
+ export const destroyCoasyTrigger = async (request: DestroyTriggerRequest) => {
34
+ const { triggerName, auth, store} = request;
35
+ const webhookId = await store.get<string>(`${triggerName}__WEBHOOK_ID`);
36
+ if (!webhookId) throw new Error(`Webhook Id not found!`);
37
+
38
+ const client = new CoasyClient(auth.baseUrl, auth.apiKey);
39
+ await client.destroyTrigger(webhookId);
40
+ }
@@ -0,0 +1,37 @@
1
+ import { createTrigger, Property, TriggerStrategy } from '@activepieces/pieces-framework';
2
+ import { coasyAuth } from '../..';
3
+ import { createCoasyTrigger, destroyCoasyTrigger } from '../common/triggers';
4
+ import { CoasyClient } from '../common/coasyClient';
5
+
6
+ const triggerName = "NEW_FUNNEL_PARTICIPANT";
7
+
8
+ export const newFunnelParticipant = createTrigger({
9
+ auth: coasyAuth,
10
+ name: 'newFunnelParticipant',
11
+ displayName: 'New Funnel Participant',
12
+ description: 'Triggers when a new funnel particpant is created',
13
+ props: {
14
+ funnelId: Property.Array({
15
+ displayName: 'Funnel IDs',
16
+ description: 'IDs of funnel to react to',
17
+ required: false
18
+ })
19
+ },
20
+ sampleData: {},
21
+ type: TriggerStrategy.WEBHOOK,
22
+ onEnable : (context) => createCoasyTrigger({
23
+ triggerName,
24
+ webhookUrl: context.webhookUrl,
25
+ auth: context.auth,
26
+ filter: context.propsValue,
27
+ store: context.store
28
+ }),
29
+ onDisable : (context) => destroyCoasyTrigger({
30
+ triggerName,
31
+ auth: context.auth,
32
+ store: context.store
33
+ }),
34
+ async run(context) {
35
+ return [context.payload.body];
36
+ }
37
+ });