@coasy/piece-coasy 0.0.11 → 0.1.0-rc.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/.eslintrc.json +33 -0
- package/README.md +143 -4
- package/package.json +2 -17
- package/project.json +38 -0
- package/src/index.ts +84 -0
- package/src/lib/actions/create-event-participant.ts +34 -0
- package/src/lib/actions/create-funnel-participant.ts +42 -0
- package/src/lib/actions/create-voucher.ts +28 -0
- package/src/lib/actions/enroll-user-course.ts +40 -0
- package/src/lib/actions/find-event.ts +28 -0
- package/src/lib/common/coasyClient.ts +58 -0
- package/src/lib/common/triggers.ts +58 -0
- package/src/lib/triggers/cancelled-membership.ts +34 -0
- package/src/lib/triggers/cancelled-order-item.ts +34 -0
- package/src/lib/triggers/cancelled-order.ts +34 -0
- package/src/lib/triggers/cancelled-orderprocess.ts +34 -0
- package/src/lib/triggers/cancelled-subscription.ts +34 -0
- package/src/lib/triggers/get-events.ts +34 -0
- package/src/lib/triggers/new-app-user-sign-up.ts +34 -0
- package/src/lib/triggers/new-auth-event.ts +93 -0
- package/src/lib/triggers/new-customer.ts +34 -0
- package/src/lib/triggers/new-event-participant.ts +34 -0
- package/src/lib/triggers/new-funnel-participant.ts +40 -0
- package/src/lib/triggers/new-lead.ts +40 -0
- package/src/lib/triggers/new-membership.ts +34 -0
- package/src/lib/triggers/new-order-item.ts +41 -0
- package/src/lib/triggers/new-order.ts +34 -0
- package/src/lib/triggers/new-subscription.ts +34 -0
- package/src/lib/triggers/new-webinar-participant.ts +54 -0
- package/src/lib/triggers/webinar-participant-attend.ts +61 -0
- package/src/lib/triggers/webinar-participant-reminder.ts +61 -0
- package/tsconfig.json +19 -0
- package/tsconfig.lib.json +11 -0
- package/src/index.d.ts +0 -8
- package/src/index.js +0 -35
- package/src/index.js.map +0 -1
- package/src/lib/actions/create-funnel-participant.d.ts +0 -9
- package/src/lib/actions/create-funnel-participant.js +0 -48
- package/src/lib/actions/create-funnel-participant.js.map +0 -1
- package/src/lib/common/coasyClient.d.ts +0 -10
- package/src/lib/common/coasyClient.js +0 -59
- package/src/lib/common/coasyClient.js.map +0 -1
- package/src/lib/common/triggers.d.ts +0 -29
- package/src/lib/common/triggers.js +0 -31
- package/src/lib/common/triggers.js.map +0 -1
- package/src/lib/triggers/new-auth-event.d.ts +0 -20
- package/src/lib/triggers/new-auth-event.js +0 -82
- package/src/lib/triggers/new-auth-event.js.map +0 -1
- package/src/lib/triggers/new-funnel-participant.d.ts +0 -17
- package/src/lib/triggers/new-funnel-participant.js +0 -41
- package/src/lib/triggers/new-funnel-participant.js.map +0 -1
- package/src/lib/triggers/new-webinar-participant.d.ts +0 -20
- package/src/lib/triggers/new-webinar-participant.js +0 -55
- package/src/lib/triggers/new-webinar-participant.js.map +0 -1
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"../../../../.eslintrc.base.json"
|
|
4
|
+
],
|
|
5
|
+
"ignorePatterns": [
|
|
6
|
+
"!**/*"
|
|
7
|
+
],
|
|
8
|
+
"overrides": [
|
|
9
|
+
{
|
|
10
|
+
"files": [
|
|
11
|
+
"*.ts",
|
|
12
|
+
"*.tsx",
|
|
13
|
+
"*.js",
|
|
14
|
+
"*.jsx"
|
|
15
|
+
],
|
|
16
|
+
"rules": {}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"files": [
|
|
20
|
+
"*.ts",
|
|
21
|
+
"*.tsx"
|
|
22
|
+
],
|
|
23
|
+
"rules": {}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"files": [
|
|
27
|
+
"*.js",
|
|
28
|
+
"*.jsx"
|
|
29
|
+
],
|
|
30
|
+
"rules": {}
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
package/README.md
CHANGED
|
@@ -1,7 +1,146 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Coasy Piece for Activepieces
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This is the Coasy integration piece for Activepieces, providing actions and triggers to interact with the Coasy platform for funnel and webinar management.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Overview
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The Coasy piece includes:
|
|
8
|
+
- **Actions**: Create funnel participants
|
|
9
|
+
- **Triggers**: New funnel participants, new webinar participants, new auth events
|
|
10
|
+
- **Authentication**: Custom auth with base URL and API key
|
|
11
|
+
|
|
12
|
+
## Development Setup
|
|
13
|
+
|
|
14
|
+
### Prerequisites
|
|
15
|
+
1. Clone the activepieces repository
|
|
16
|
+
2. Install dependencies: `npm install`
|
|
17
|
+
3. Ensure you're in the root directory of the activepieces monorepo
|
|
18
|
+
|
|
19
|
+
### Development Commands
|
|
20
|
+
|
|
21
|
+
#### Building the Piece
|
|
22
|
+
```bash
|
|
23
|
+
# Build the coasy piece specifically
|
|
24
|
+
nx build pieces-coasy
|
|
25
|
+
|
|
26
|
+
# Build with watch mode for development
|
|
27
|
+
nx build pieces-coasy --watch
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
#### Testing
|
|
31
|
+
```bash
|
|
32
|
+
# Run tests for the coasy piece
|
|
33
|
+
nx test pieces-coasy
|
|
34
|
+
|
|
35
|
+
# Run tests with watch mode
|
|
36
|
+
nx test pieces-coasy --watch
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Linting
|
|
40
|
+
```bash
|
|
41
|
+
# Lint the coasy piece
|
|
42
|
+
nx lint pieces-coasy
|
|
43
|
+
|
|
44
|
+
# Auto-fix lint issues
|
|
45
|
+
nx lint pieces-coasy --fix
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Development Workflow
|
|
49
|
+
|
|
50
|
+
#### 1. Start Development Environment
|
|
51
|
+
```bash
|
|
52
|
+
# Start the full development environment (frontend + backend + engine + pieces)
|
|
53
|
+
npm run dev
|
|
54
|
+
|
|
55
|
+
# Or start just backend services if only testing the piece
|
|
56
|
+
npm run dev:backend
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### 2. Testing Your Changes
|
|
60
|
+
- Navigate to `http://localhost:4200` (frontend)
|
|
61
|
+
- Create a new flow and add Coasy actions/triggers
|
|
62
|
+
- Test authentication with your Coasy credentials
|
|
63
|
+
- Verify actions and triggers work as expected
|
|
64
|
+
|
|
65
|
+
#### 3. Adding New Features
|
|
66
|
+
|
|
67
|
+
**Adding a New Action:**
|
|
68
|
+
1. Create a new file in `src/lib/actions/`
|
|
69
|
+
2. Export the action from `src/index.ts`
|
|
70
|
+
3. Follow the existing patterns in `create-funnel-participant.ts`
|
|
71
|
+
|
|
72
|
+
**Adding a New Trigger:**
|
|
73
|
+
1. Create a new file in `src/lib/triggers/`
|
|
74
|
+
2. Export the trigger from `src/index.ts`
|
|
75
|
+
3. Follow the existing patterns in `new-funnel-participant.ts`
|
|
76
|
+
|
|
77
|
+
#### 4. File Structure
|
|
78
|
+
```
|
|
79
|
+
packages/pieces/community/coasy/
|
|
80
|
+
├── README.md # This file
|
|
81
|
+
├── package.json # Package configuration
|
|
82
|
+
├── project.json # Nx project configuration
|
|
83
|
+
├── tsconfig.json # TypeScript config
|
|
84
|
+
└── src/
|
|
85
|
+
├── index.ts # Main piece definition and exports
|
|
86
|
+
└── lib/
|
|
87
|
+
├── actions/ # Action implementations
|
|
88
|
+
├── triggers/ # Trigger implementations
|
|
89
|
+
└── common/ # Shared utilities
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Code Standards
|
|
93
|
+
|
|
94
|
+
### Authentication
|
|
95
|
+
The piece uses custom authentication with:
|
|
96
|
+
- `baseUrl`: Coasy instance base URL
|
|
97
|
+
- `apiKey`: API key for authentication
|
|
98
|
+
|
|
99
|
+
### Error Handling
|
|
100
|
+
- Use proper error messages for user-facing errors
|
|
101
|
+
- Handle API errors gracefully
|
|
102
|
+
- Validate inputs before making API calls
|
|
103
|
+
|
|
104
|
+
### Properties
|
|
105
|
+
- Use descriptive `displayName` and `description` for all properties
|
|
106
|
+
- Mark required fields appropriately
|
|
107
|
+
- Use proper property types from `@activepieces/pieces-framework`
|
|
108
|
+
|
|
109
|
+
## Testing in Activepieces
|
|
110
|
+
|
|
111
|
+
1. **Authentication Testing**:
|
|
112
|
+
- Verify connection works with valid credentials
|
|
113
|
+
- Test error handling with invalid credentials
|
|
114
|
+
|
|
115
|
+
2. **Action Testing**:
|
|
116
|
+
- Test with valid inputs
|
|
117
|
+
- Test error scenarios
|
|
118
|
+
- Verify data transformation
|
|
119
|
+
|
|
120
|
+
3. **Trigger Testing**:
|
|
121
|
+
- Set up webhooks/polling as needed
|
|
122
|
+
- Test trigger conditions
|
|
123
|
+
- Verify payload structure
|
|
124
|
+
|
|
125
|
+
## Publishing
|
|
126
|
+
|
|
127
|
+
The piece is published as `@coasy/piece-coasy` to npm. Version is currently `0.0.12`.
|
|
128
|
+
|
|
129
|
+
To publish a new version:
|
|
130
|
+
1. Navigate to the coasy piece directory:
|
|
131
|
+
```bash
|
|
132
|
+
cd packages/pieces/community/coasy
|
|
133
|
+
```
|
|
134
|
+
2. Update the `version` in `package.json` (e.g., from `0.0.11` to `0.0.12`)
|
|
135
|
+
3. Publish directly to npm:
|
|
136
|
+
```bash
|
|
137
|
+
npm publish
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Note**: The monorepo's `npm run publish-piece` script currently has dependency resolution issues. Use the direct `npm publish` method above instead.
|
|
141
|
+
|
|
142
|
+
## Resources
|
|
143
|
+
|
|
144
|
+
- [Activepieces Documentation](https://www.activepieces.com/docs)
|
|
145
|
+
- [Pieces Framework Reference](https://www.activepieces.com/docs/developers/piece-reference/properties)
|
|
146
|
+
- [Piece Development Guide](https://www.activepieces.com/docs/developers/building-pieces/create-action)
|
package/package.json
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coasy/piece-coasy",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
|
|
5
|
-
"@sinclair/typebox": "0.26.8",
|
|
6
|
-
"axios": "1.6.7",
|
|
7
|
-
"dayjs": "1.11.9",
|
|
8
|
-
"is-base64": "1.1.0",
|
|
9
|
-
"lodash": "4.17.21",
|
|
10
|
-
"nanoid": "3.3.6",
|
|
11
|
-
"semver": "7.6.0",
|
|
12
|
-
"@activepieces/pieces-common": "0.2.12",
|
|
13
|
-
"@activepieces/pieces-framework": "0.7.29",
|
|
14
|
-
"@activepieces/shared": "0.10.104",
|
|
15
|
-
"tslib": "1.14.1"
|
|
16
|
-
},
|
|
17
|
-
"main": "./src/index.js",
|
|
18
|
-
"type": "commonjs"
|
|
19
|
-
}
|
|
3
|
+
"version": "0.1.0-rc.1"
|
|
4
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pieces-coasy",
|
|
3
|
+
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/pieces/community/coasy/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"targets": {
|
|
7
|
+
"build": {
|
|
8
|
+
"executor": "@nx/js:tsc",
|
|
9
|
+
"outputs": [
|
|
10
|
+
"{options.outputPath}"
|
|
11
|
+
],
|
|
12
|
+
"options": {
|
|
13
|
+
"outputPath": "dist/packages/pieces/community/coasy",
|
|
14
|
+
"tsConfig": "packages/pieces/community/coasy/tsconfig.lib.json",
|
|
15
|
+
"packageJson": "packages/pieces/community/coasy/package.json",
|
|
16
|
+
"main": "packages/pieces/community/coasy/src/index.ts",
|
|
17
|
+
"assets": [
|
|
18
|
+
"packages/pieces/community/coasy/*.md"
|
|
19
|
+
],
|
|
20
|
+
"buildableProjectDepsInPackageJsonType": "dependencies",
|
|
21
|
+
"updateBuildableProjectDepsInPackageJson": true
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"publish": {
|
|
25
|
+
"command": "node tools/scripts/publish.mjs pieces-coasy {args.ver} {args.tag}",
|
|
26
|
+
"dependsOn": [
|
|
27
|
+
"build"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"lint": {
|
|
31
|
+
"executor": "@nx/eslint:lint",
|
|
32
|
+
"outputs": [
|
|
33
|
+
"{options.outputFile}"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"tags": []
|
|
38
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createPiece,
|
|
3
|
+
PieceAuth,
|
|
4
|
+
Property,
|
|
5
|
+
} from '@activepieces/pieces-framework';
|
|
6
|
+
import { createEventParticipant } from './lib/actions/create-event-participant';
|
|
7
|
+
import { createFunnelParticipant } from './lib/actions/create-funnel-participant';
|
|
8
|
+
import { createVoucher } from './lib/actions/create-voucher';
|
|
9
|
+
import { enrollUserCourse } from './lib/actions/enroll-user-course';
|
|
10
|
+
import { findEvent } from './lib/actions/find-event';
|
|
11
|
+
import { cancelledMembership } from './lib/triggers/cancelled-membership';
|
|
12
|
+
import { cancelledOrder } from './lib/triggers/cancelled-order';
|
|
13
|
+
import { cancelledOrderItem } from './lib/triggers/cancelled-order-item';
|
|
14
|
+
import { cancelledOrderprocess } from './lib/triggers/cancelled-orderprocess';
|
|
15
|
+
import { cancelledSubscription } from './lib/triggers/cancelled-subscription';
|
|
16
|
+
import { getEvents } from './lib/triggers/get-events';
|
|
17
|
+
import { newAppUserSignUp } from './lib/triggers/new-app-user-sign-up';
|
|
18
|
+
import { newAuthEvent } from './lib/triggers/new-auth-event';
|
|
19
|
+
import { newCustomer } from './lib/triggers/new-customer';
|
|
20
|
+
import { newEventParticipant } from './lib/triggers/new-event-participant';
|
|
21
|
+
import { newFunnelParticipant } from './lib/triggers/new-funnel-participant';
|
|
22
|
+
import { newLead } from './lib/triggers/new-lead';
|
|
23
|
+
import { newMembership } from './lib/triggers/new-membership';
|
|
24
|
+
import { newOrder } from './lib/triggers/new-order';
|
|
25
|
+
import { newOrderItem } from './lib/triggers/new-order-item';
|
|
26
|
+
import { newSubscription } from './lib/triggers/new-subscription';
|
|
27
|
+
import { newWebinarParticipant } from './lib/triggers/new-webinar-participant';
|
|
28
|
+
import { webinarParticipantAttend } from './lib/triggers/webinar-participant-attend';
|
|
29
|
+
import { webinarParticipantReminder } from './lib/triggers/webinar-participant-reminder';
|
|
30
|
+
|
|
31
|
+
export const coasyAuth = PieceAuth.CustomAuth({
|
|
32
|
+
required: true,
|
|
33
|
+
description: 'Enter coasy authentication details',
|
|
34
|
+
props: {
|
|
35
|
+
baseUrl: Property.ShortText({
|
|
36
|
+
displayName: 'Base URL',
|
|
37
|
+
description: 'Enter the base URL',
|
|
38
|
+
required: false,
|
|
39
|
+
defaultValue: 'https://backend.api.prod.coasy.io',
|
|
40
|
+
}),
|
|
41
|
+
apiKey: PieceAuth.SecretText({
|
|
42
|
+
displayName: 'API Key',
|
|
43
|
+
description: 'Enter the api key',
|
|
44
|
+
required: true,
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const coasy = createPiece({
|
|
50
|
+
displayName: 'Coasy',
|
|
51
|
+
auth: coasyAuth,
|
|
52
|
+
description: 'Communicate with Coasy',
|
|
53
|
+
minimumSupportedRelease: '0.20.0',
|
|
54
|
+
logoUrl: 'https://console.coasy.io/favicon/apple-icon.png',
|
|
55
|
+
authors: ['christian-schab'],
|
|
56
|
+
actions: [
|
|
57
|
+
createEventParticipant,
|
|
58
|
+
createFunnelParticipant,
|
|
59
|
+
createVoucher,
|
|
60
|
+
enrollUserCourse,
|
|
61
|
+
findEvent,
|
|
62
|
+
],
|
|
63
|
+
triggers: [
|
|
64
|
+
cancelledMembership,
|
|
65
|
+
cancelledOrder,
|
|
66
|
+
cancelledOrderItem,
|
|
67
|
+
cancelledOrderprocess,
|
|
68
|
+
cancelledSubscription,
|
|
69
|
+
getEvents,
|
|
70
|
+
newAppUserSignUp,
|
|
71
|
+
newAuthEvent,
|
|
72
|
+
newCustomer,
|
|
73
|
+
newEventParticipant,
|
|
74
|
+
newFunnelParticipant,
|
|
75
|
+
newLead,
|
|
76
|
+
newMembership,
|
|
77
|
+
newOrder,
|
|
78
|
+
newOrderItem,
|
|
79
|
+
newSubscription,
|
|
80
|
+
newWebinarParticipant,
|
|
81
|
+
webinarParticipantAttend,
|
|
82
|
+
webinarParticipantReminder,
|
|
83
|
+
],
|
|
84
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createAction, Property } from "@activepieces/pieces-framework";
|
|
2
|
+
import { coasyAuth } from "../..";
|
|
3
|
+
import { CoasyClient } from "../common/coasyClient";
|
|
4
|
+
|
|
5
|
+
export const createEventParticipant = createAction({
|
|
6
|
+
auth: coasyAuth,
|
|
7
|
+
name: "createEventParticipant",
|
|
8
|
+
displayName: "Create Event Participant",
|
|
9
|
+
description: "Creates a new event participant",
|
|
10
|
+
props: {
|
|
11
|
+
eventId: Property.ShortText({
|
|
12
|
+
displayName: "Event ID",
|
|
13
|
+
description: "ID of event",
|
|
14
|
+
required: true
|
|
15
|
+
}),
|
|
16
|
+
categoryId: Property.ShortText({
|
|
17
|
+
displayName: "Category ID",
|
|
18
|
+
description: "ID of category",
|
|
19
|
+
required: false
|
|
20
|
+
})
|
|
21
|
+
},
|
|
22
|
+
async run(configValue) {
|
|
23
|
+
const { propsValue, auth } = configValue;
|
|
24
|
+
const client = new CoasyClient(
|
|
25
|
+
auth.baseUrl ?? "https://backend.api.prod.coasy.io",
|
|
26
|
+
auth.apiKey
|
|
27
|
+
);
|
|
28
|
+
const request = {
|
|
29
|
+
eventId: propsValue.eventId,
|
|
30
|
+
categoryId: propsValue.categoryId
|
|
31
|
+
};
|
|
32
|
+
return client.action("createEventParticipant", request);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createAction, Property } from '@activepieces/pieces-framework';
|
|
2
|
+
import { coasyAuth } from '../../index';
|
|
3
|
+
import { CoasyClient } from '../common/coasyClient';
|
|
4
|
+
|
|
5
|
+
export const createFunnelParticipant = createAction({
|
|
6
|
+
auth: coasyAuth,
|
|
7
|
+
name: 'createFunnelParticipant',
|
|
8
|
+
displayName: 'Create Funnel Participant',
|
|
9
|
+
description: 'Create a new funnel participant',
|
|
10
|
+
props: {
|
|
11
|
+
funnelId: Property.ShortText({
|
|
12
|
+
displayName: 'Funnel ID',
|
|
13
|
+
description: 'ID of funnel',
|
|
14
|
+
required: true
|
|
15
|
+
}),
|
|
16
|
+
firstName: Property.ShortText({
|
|
17
|
+
displayName: 'First name',
|
|
18
|
+
description: 'first name of participant',
|
|
19
|
+
required: true
|
|
20
|
+
}),
|
|
21
|
+
lastName: Property.ShortText({
|
|
22
|
+
displayName: 'Last name',
|
|
23
|
+
description: 'last name of participant',
|
|
24
|
+
required: false
|
|
25
|
+
}),
|
|
26
|
+
email: Property.ShortText({
|
|
27
|
+
displayName: 'Email',
|
|
28
|
+
description: 'email address of partipant',
|
|
29
|
+
required: true
|
|
30
|
+
})
|
|
31
|
+
},
|
|
32
|
+
async run(configValue) {
|
|
33
|
+
const { propsValue, auth } = configValue;
|
|
34
|
+
const client = new CoasyClient(auth.baseUrl ?? 'https://backend.api.prod.coasy.io', auth.apiKey);
|
|
35
|
+
const request = {
|
|
36
|
+
email: propsValue.email,
|
|
37
|
+
firstName: propsValue.firstName,
|
|
38
|
+
funnelId: propsValue.funnelId
|
|
39
|
+
};
|
|
40
|
+
return client.action('createFunnelParticipant', request);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createAction, Property } from '@activepieces/pieces-framework';
|
|
2
|
+
import { coasyAuth } from '../..';
|
|
3
|
+
import { CoasyClient } from '../common/coasyClient';
|
|
4
|
+
|
|
5
|
+
export const createVoucher = createAction({
|
|
6
|
+
auth: coasyAuth,
|
|
7
|
+
name: 'createVoucher',
|
|
8
|
+
displayName: 'Create Voucher',
|
|
9
|
+
description: 'Creates a new voucher',
|
|
10
|
+
props: {
|
|
11
|
+
offerId: Property.ShortText({
|
|
12
|
+
displayName: 'Offer ID',
|
|
13
|
+
description: 'ID of offer',
|
|
14
|
+
required: true,
|
|
15
|
+
}),
|
|
16
|
+
},
|
|
17
|
+
async run(configValue) {
|
|
18
|
+
const { propsValue, auth } = configValue;
|
|
19
|
+
const client = new CoasyClient(
|
|
20
|
+
auth.baseUrl ?? 'https://backend.api.prod.coasy.io',
|
|
21
|
+
auth.apiKey
|
|
22
|
+
);
|
|
23
|
+
const request = {
|
|
24
|
+
offerId: propsValue.offerId,
|
|
25
|
+
};
|
|
26
|
+
return client.action('createVoucher', request);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createAction, Property } from "@activepieces/pieces-framework";
|
|
2
|
+
import { coasyAuth } from "../..";
|
|
3
|
+
import { CoasyClient } from "../common/coasyClient";
|
|
4
|
+
|
|
5
|
+
export const enrollUserCourse = createAction({
|
|
6
|
+
auth: coasyAuth,
|
|
7
|
+
name: "enrollUserCourse",
|
|
8
|
+
displayName: "Enroll User Course",
|
|
9
|
+
description: "Enrolls user course",
|
|
10
|
+
props: {
|
|
11
|
+
userId: Property.ShortText({
|
|
12
|
+
displayName: "User ID",
|
|
13
|
+
description: "ID of User",
|
|
14
|
+
required: true
|
|
15
|
+
}),
|
|
16
|
+
courseId: Property.ShortText({
|
|
17
|
+
displayName: "Course ID",
|
|
18
|
+
description: "ID of Course",
|
|
19
|
+
required: true
|
|
20
|
+
}),
|
|
21
|
+
directGrant: Property.Checkbox({
|
|
22
|
+
displayName: "Direct Grant",
|
|
23
|
+
description: "Give direct grant",
|
|
24
|
+
required: true
|
|
25
|
+
})
|
|
26
|
+
},
|
|
27
|
+
async run(configValue) {
|
|
28
|
+
const { propsValue, auth } = configValue;
|
|
29
|
+
const client = new CoasyClient(
|
|
30
|
+
auth.baseUrl ?? "https://backend.api.prod.coasy.io",
|
|
31
|
+
auth.apiKey
|
|
32
|
+
);
|
|
33
|
+
const request = {
|
|
34
|
+
userId: propsValue.userId,
|
|
35
|
+
courseId: propsValue.courseId,
|
|
36
|
+
directGrant: propsValue.directGrant
|
|
37
|
+
};
|
|
38
|
+
return client.action("enrollUserCourse", request);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createAction, Property } from "@activepieces/pieces-framework";
|
|
2
|
+
import { coasyAuth } from "../..";
|
|
3
|
+
import { CoasyClient } from "../common/coasyClient";
|
|
4
|
+
|
|
5
|
+
export const findEvent = createAction({
|
|
6
|
+
auth: coasyAuth,
|
|
7
|
+
name: "findEvent",
|
|
8
|
+
displayName: "Find Event",
|
|
9
|
+
description: "Finds Event",
|
|
10
|
+
props: {
|
|
11
|
+
title: Property.ShortText({
|
|
12
|
+
displayName: "Title",
|
|
13
|
+
description: "Title Name",
|
|
14
|
+
required: false
|
|
15
|
+
})
|
|
16
|
+
},
|
|
17
|
+
async run(configValue) {
|
|
18
|
+
const { propsValue, auth } = configValue;
|
|
19
|
+
const client = new CoasyClient(
|
|
20
|
+
auth.baseUrl ?? "https://backend.api.prod.coasy.io",
|
|
21
|
+
auth.apiKey
|
|
22
|
+
);
|
|
23
|
+
const request = {
|
|
24
|
+
title: propsValue.title
|
|
25
|
+
};
|
|
26
|
+
return client.action("findEvent", request);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthenticationType,
|
|
3
|
+
httpClient,
|
|
4
|
+
HttpMethod,
|
|
5
|
+
HttpRequest,
|
|
6
|
+
} from '@activepieces/pieces-common';
|
|
7
|
+
|
|
8
|
+
export class CoasyClient {
|
|
9
|
+
private baseUrl: string;
|
|
10
|
+
private apiKey: string;
|
|
11
|
+
|
|
12
|
+
constructor(baseUrl: string, apiKey: string) {
|
|
13
|
+
this.baseUrl = baseUrl;
|
|
14
|
+
this.apiKey = apiKey;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async action(actionName: string, request: any) {
|
|
18
|
+
return this.request(`/apps/actions/${actionName}`, request);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async createTrigger(trigger: string, hookUrl: string, filter: any) {
|
|
22
|
+
return this.request(`/apps/triggers/create`, {
|
|
23
|
+
hookUrl,
|
|
24
|
+
trigger,
|
|
25
|
+
filter,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async destroyTrigger(webhookId: string) {
|
|
30
|
+
return this.request(`/apps/triggers/destroy`, { webhookId });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async listTriggerEvents(trigger: string) {
|
|
34
|
+
return this.request(`/apps/list`, {
|
|
35
|
+
trigger,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async request(path: string, requestBody: any) {
|
|
40
|
+
const request: HttpRequest<string> = {
|
|
41
|
+
method: HttpMethod.POST,
|
|
42
|
+
url: `${this.baseUrl}${path}`,
|
|
43
|
+
body: JSON.stringify(requestBody),
|
|
44
|
+
authentication: {
|
|
45
|
+
type: AuthenticationType.BEARER_TOKEN,
|
|
46
|
+
token: this.apiKey,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const response = await httpClient.sendRequest(request);
|
|
51
|
+
|
|
52
|
+
if (response.status !== 200) {
|
|
53
|
+
throw new Error(`Failed to communicate with Mailjet`);
|
|
54
|
+
} else {
|
|
55
|
+
return response.body;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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<false>,
|
|
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<false>,
|
|
21
|
+
apiKey: SecretTextProperty<true>
|
|
22
|
+
}>
|
|
23
|
+
store: Store;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface TestTriggerRequest {
|
|
27
|
+
triggerName: string;
|
|
28
|
+
auth: StaticPropsValue<{
|
|
29
|
+
baseUrl: ShortTextProperty<false>,
|
|
30
|
+
apiKey: SecretTextProperty<true>
|
|
31
|
+
}>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const createCoasyTrigger = async (request: CreateTriggerRequest) => {
|
|
35
|
+
const { triggerName, webhookUrl, filter, auth, store} = request;
|
|
36
|
+
const client = new CoasyClient(auth.baseUrl ?? 'https://backend.api.prod.coasy.io', auth.apiKey);
|
|
37
|
+
const response = await client.createTrigger(triggerName, webhookUrl, filter);
|
|
38
|
+
if (!response.id) throw new Error(`Failed to create Trigger!`);
|
|
39
|
+
await store.put<string>(`${triggerName}__WEBHOOK_ID`, response.id);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const destroyCoasyTrigger = async (request: DestroyTriggerRequest) => {
|
|
43
|
+
const { triggerName, auth, store} = request;
|
|
44
|
+
const webhookId = await store.get<string>(`${triggerName}__WEBHOOK_ID`);
|
|
45
|
+
if (!webhookId) throw new Error(`Webhook Id not found!`);
|
|
46
|
+
|
|
47
|
+
const client = new CoasyClient(auth.baseUrl ?? 'https://backend.api.prod.coasy.io', auth.apiKey);
|
|
48
|
+
await client.destroyTrigger(webhookId);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const testCoasyTrigger = async (request: TestTriggerRequest): Promise<any[]> => {
|
|
52
|
+
const { triggerName, auth} = request;
|
|
53
|
+
|
|
54
|
+
const client = new CoasyClient(auth.baseUrl ?? 'https://backend.api.prod.coasy.io', auth.apiKey);
|
|
55
|
+
const response = await client.listTriggerEvents(triggerName);
|
|
56
|
+
|
|
57
|
+
return [{ test: true}];
|
|
58
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createTrigger, Property, TriggerStrategy } from '@activepieces/pieces-framework';
|
|
2
|
+
import { coasyAuth } from '../..';
|
|
3
|
+
import { createCoasyTrigger, destroyCoasyTrigger, testCoasyTrigger } from '../common/triggers';
|
|
4
|
+
|
|
5
|
+
const triggerName = "CANCELLED_MEMBERSHIP";
|
|
6
|
+
|
|
7
|
+
export const cancelledMembership = createTrigger({
|
|
8
|
+
auth: coasyAuth,
|
|
9
|
+
name: 'cancelledMembership',
|
|
10
|
+
displayName: 'Cancelled Membership',
|
|
11
|
+
description: 'Triggers when a customer requests a membership cancellation.',
|
|
12
|
+
props: {},
|
|
13
|
+
sampleData: {},
|
|
14
|
+
type: TriggerStrategy.WEBHOOK,
|
|
15
|
+
onEnable: (context) => createCoasyTrigger({
|
|
16
|
+
triggerName,
|
|
17
|
+
webhookUrl: context.webhookUrl,
|
|
18
|
+
auth: context.auth,
|
|
19
|
+
filter: context.propsValue,
|
|
20
|
+
store: context.store
|
|
21
|
+
}),
|
|
22
|
+
onDisable: (context) => destroyCoasyTrigger({
|
|
23
|
+
triggerName,
|
|
24
|
+
auth: context.auth,
|
|
25
|
+
store: context.store
|
|
26
|
+
}),
|
|
27
|
+
test: (context) => testCoasyTrigger({
|
|
28
|
+
triggerName,
|
|
29
|
+
auth: context.auth
|
|
30
|
+
}),
|
|
31
|
+
async run(context) {
|
|
32
|
+
return [context.payload.body];
|
|
33
|
+
}
|
|
34
|
+
});
|