-
Notifications
You must be signed in to change notification settings - Fork 962
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3816 from MoShizzle/interface-trigger
feat: interfaces trigger poc
- Loading branch information
Showing
24 changed files
with
646 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "@activepieces/piece-interfaces", | ||
"version": "0.0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
}); |
43 changes: 43 additions & 0 deletions
43
packages/pieces/community/interfaces/src/lib/actions/return-file.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}); |
31 changes: 31 additions & 0 deletions
31
packages/pieces/community/interfaces/src/lib/actions/return-markdown.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}); |
66 changes: 66 additions & 0 deletions
66
packages/pieces/community/interfaces/src/lib/triggers/interface-trigger.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.