Skip to content

Commit

Permalink
Merge pull request #3816 from MoShizzle/interface-trigger
Browse files Browse the repository at this point in the history
feat: interfaces trigger poc
  • Loading branch information
abuaboud committed Feb 7, 2024
2 parents 3f4749f + b693deb commit 1bc0e82
Show file tree
Hide file tree
Showing 24 changed files with 646 additions and 12 deletions.
37 changes: 32 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"lottie-web": "5.12.2",
"mailparser": "3.6.7",
"marked": "4.3.0",
"mime": "4.0.1",
"mime-types": "2.1.35",
"monaco-editor": "0.34.1",
"monday-sdk-js": "0.5.2",
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/app/helper/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const packageManager = {

const config = [
'--prefer-offline',
'--ignore-scripts',
'--config.lockfile=false',
'--config.auto-install-peers=true',
]
Expand Down
33 changes: 33 additions & 0 deletions packages/pieces/community/interfaces/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"extends": [
"../../../../.eslintrc.json"
],
"ignorePatterns": [
"!**/*"
],
"overrides": [
{
"files": [
"*.ts",
"*.tsx",
"*.js",
"*.jsx"
],
"rules": {}
},
{
"files": [
"*.ts",
"*.tsx"
],
"rules": {}
},
{
"files": [
"*.js",
"*.jsx"
],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions packages/pieces/community/interfaces/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pieces-interfaces

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build pieces-interfaces` to build the library.
4 changes: 4 additions & 0 deletions packages/pieces/community/interfaces/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@activepieces/piece-interfaces",
"version": "0.0.1"
}
43 changes: 43 additions & 0 deletions packages/pieces/community/interfaces/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "pieces-interfaces",
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/pieces/community/interfaces/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": [
"{options.outputPath}"
],
"options": {
"outputPath": "dist/packages/pieces/community/interfaces",
"tsConfig": "packages/pieces/community/interfaces/tsconfig.lib.json",
"packageJson": "packages/pieces/community/interfaces/package.json",
"main": "packages/pieces/community/interfaces/src/index.ts",
"assets": [
"packages/pieces/community/interfaces/*.md"
],
"buildableProjectDepsInPackageJsonType": "dependencies",
"updateBuildableProjectDepsInPackageJson": true
}
},
"publish": {
"command": "node tools/scripts/publish.mjs pieces-interfaces {args.ver} {args.tag}",
"dependsOn": [
"build"
]
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": [
"{options.outputFile}"
],
"options": {
"lintFilePatterns": [
"packages/pieces/community/interfaces/**/*.ts"
]
}
}
},
"tags": []
}
14 changes: 14 additions & 0 deletions packages/pieces/community/interfaces/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createPiece, PieceAuth } from '@activepieces/pieces-framework';
import { returnFile } from './lib/actions/return-file';
import { returnMarkdown } from './lib/actions/return-markdown';
import { onFormSubmission } from './lib/triggers/interface-trigger';

export const interfaces = createPiece({
displayName: 'Interfaces',
auth: PieceAuth.None(),
minimumSupportedRelease: '0.9.0',
logoUrl: 'https://cdn.activepieces.com/pieces/interfaces.png',
authors: ['MoShizzle'],
actions: [returnFile, returnMarkdown],
triggers: [onFormSubmission],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Property, createAction } from '@activepieces/pieces-framework';
import { FileResponseInterface } from '@activepieces/shared';
import { StatusCodes } from 'http-status-codes';
import mimeTypes from 'mime-types';
export const returnFile = createAction({
name: 'return_file',
displayName: 'Respond with a file',
description: 'Download a file as a response.',
props: {
file: Property.File({
displayName: 'File',
required: true,
}),
},
async run({ propsValue, run }) {
const fileName = propsValue.file.filename;
const fileExtension = propsValue.file.extension;
const fileBase64 = propsValue.file.base64;

const mimeType = fileExtension ? mimeTypes.lookup(fileExtension) : 'application/octet-stream';
const base64Url = `data:${mimeType};base64,${fileBase64}`;

const value: FileResponseInterface = {
base64Url,
fileName,
extension: fileExtension,

}
const response = {
status: StatusCodes.OK,
body: {
type: 'file',
value,
},
headers: {},
};

run.stop({
response: response,
});
return response;
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Property, createAction } from '@activepieces/pieces-framework';
import { StatusCodes } from 'http-status-codes';

export const returnMarkdown = createAction({
name: 'return_markdown',
displayName: 'Respond with a Markdown',
description: 'Display a markdown as a response.',
props: {
markdown: Property.LongText({
displayName: 'Markdown',
required: true,
}),
},

async run({ propsValue, run }) {

const response = {
status: StatusCodes.OK,
body: {
type: 'markdown',
value: propsValue.markdown,
},
headers: {},
};

run.stop({
response: response,
});
return response;
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {
Property,
TriggerStrategy,
createTrigger,
} from '@activepieces/pieces-framework';

const markdown = `
Go to this URL to see the interface: \n
\`{{interfaceUrl}}\`
`;

export const onFormSubmission = createTrigger({
name: 'form_submission',
displayName: 'On Form Submission',
description: 'Trigger the flow by submitting a form.',
props: {
about: Property.MarkDown({
value: markdown,
}),
inputs: Property.Array({
displayName: 'Inputs',
required: true,
properties: {
displayName: Property.ShortText({
displayName: 'Field Name',
required: true,
}),
type: Property.StaticDropdown({
displayName: 'Field Type',
required: true,
options: {
options: [
{ value: 'text', label: 'Text' },
{ value: 'file', label: 'File' },
],
},
}),
description: Property.ShortText({
displayName: 'Field Description',
required: false,
}),
required: Property.Checkbox({
displayName: 'Required',
required: true,
}),
},
}),
waitForResponse: Property.Checkbox({
displayName: 'Wait for Response',
description:
'If enabled, the interface will return the flow output to the frontend. Make sure to use the Return Response action to return a response.',
required: true,
}),
},
sampleData: {},
type: TriggerStrategy.WEBHOOK,
async onEnable() {
return;
},
async onDisable() {
return;
},
async run(context) {
return [context.payload.body];
},
});
19 changes: 19 additions & 0 deletions packages/pieces/community/interfaces/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
}
]
}
11 changes: 11 additions & 0 deletions packages/pieces/community/interfaces/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
1 change: 1 addition & 0 deletions packages/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export * from './lib/flows/dto/flow-template-request'
export * from './lib/flows'
export * from './lib/flows/dto/list-flows-request'
export * from './lib/project/project'
export { FileResponseInterface } from './lib/interfaces'
import { TypeSystem } from '@sinclair/typebox/system'
export { RetryFlowRequestBody } from './lib/flow-run/test-flow-run-request'
export * from './lib/flows/dto/flow-template-request'
Expand Down
10 changes: 10 additions & 0 deletions packages/shared/src/lib/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Static, Type } from '@sinclair/typebox'


export const FileResponseInterface = Type.Object({
base64Url: Type.String(),
fileName: Type.String(),
extension: Type.Optional(Type.String()),
})

export type FileResponseInterface = Static<typeof FileResponseInterface>
Loading

0 comments on commit 1bc0e82

Please sign in to comment.