- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.5k
 
New Components - moaform #14133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    New Components - moaform #14133
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      6437ac6
              
                moaform init
              
              
                luancazarine 06d4f36
              
                [Components] moaform #14132
              
              
                luancazarine 9634cee
              
                pnpm update
              
              
                luancazarine f57484e
              
                Fix retention days label
              
              
                vunguyenhung b3aa956
              
                some adjusts
              
              
                luancazarine b5c8861
              
                Merge branch 'master' into issue-14132
              
              
                luancazarine b4c5190
              
                Merge branch 'master' into issue-14132
              
              
                luancazarine File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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,30 @@ | ||
| export const RETENTION_DAYS_OPTIONS = [ | ||
| { | ||
| label: "1", | ||
| value: 1, | ||
| }, | ||
| { | ||
| label: "3", | ||
| value: 3, | ||
| }, | ||
| { | ||
| label: "5", | ||
| value: 5, | ||
| }, | ||
| { | ||
| label: "7", | ||
| value: 7, | ||
| }, | ||
| { | ||
| label: "10", | ||
| value: 10, | ||
| }, | ||
| { | ||
| label: "15", | ||
| value: 15, | ||
| }, | ||
| { | ||
| label: "30", | ||
| value: 30, | ||
| }, | ||
| ]; | 
  
    
      This file contains hidden or 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 | 
|---|---|---|
| @@ -1,11 +1,68 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
| 
     | 
||
| export default { | ||
| type: "app", | ||
| app: "moaform", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| formId: { | ||
| type: "string", | ||
| label: "Form ID", | ||
| description: "The ID of the form to monitor for new submissions", | ||
| async options({ page }) { | ||
| const { items } = await this.getForms({ | ||
| params: { | ||
| page: page + 1, | ||
| }, | ||
| }); | ||
| return items.map(({ | ||
| id: value, title: label, | ||
| }) => ({ | ||
| label, | ||
| value, | ||
| })); | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.moaform.com/v1"; | ||
| }, | ||
| _headers() { | ||
| return { | ||
| Authorization: `Bearer ${this.$auth.api_key}`, | ||
| }; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: this._baseUrl() + path, | ||
| headers: this._headers(), | ||
| ...opts, | ||
| }); | ||
| }, | ||
| getForms(opts = {}) { | ||
| return this._makeRequest({ | ||
| ...opts, | ||
| path: "/forms", | ||
| }); | ||
| }, | ||
                
      
                  GTFalcao marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| createWebhook({ | ||
| formId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: `/forms/${formId}/webhooks`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
                
      
                  GTFalcao marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| deleteWebhook({ | ||
| formId, webhookId, | ||
| }) { | ||
| return this._makeRequest({ | ||
| method: "DELETE", | ||
| path: `/forms/${formId}/webhooks/${webhookId}`, | ||
| }); | ||
                
      
                  GTFalcao marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
  
    
      This file contains hidden or 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
    
  
  
    
              
        
          
          
            100 changes: 100 additions & 0 deletions
          
          100 
        
  components/moaform/sources/new-submission-instant/new-submission-instant.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,100 @@ | ||
| import crypto from "crypto"; | ||
| import { RETENTION_DAYS_OPTIONS } from "../../common/constants.mjs"; | ||
| import moaform from "../../moaform.app.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
| 
     | 
||
| export default { | ||
| key: "moaform-new-submission-instant", | ||
| name: "New Submission (Instant)", | ||
| description: "Emit new event every time a new form submission is received.", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| moaform, | ||
| http: { | ||
| type: "$.interface.http", | ||
| customResponse: true, | ||
| }, | ||
| db: "$.service.db", | ||
| formId: { | ||
| propDefinition: [ | ||
| moaform, | ||
| "formId", | ||
| ], | ||
| }, | ||
| retentionDays: { | ||
| type: "integer", | ||
| label: "Retention Days", | ||
| description: "Resend restriction days", | ||
| options: RETENTION_DAYS_OPTIONS, | ||
| optional: true, | ||
| }, | ||
| secret: { | ||
| type: "string", | ||
| label: "Secret Code", | ||
| description: "This code is used to verify that the data received at the specified endpoint has indeed been sent from Moaform and has not been tampered with.", | ||
| secret: true, | ||
| optional: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getWebhookId() { | ||
| return this.db.get("webhookId"); | ||
| }, | ||
| _setWebhookId(id) { | ||
| this.db.set("webhookId", id); | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async activate() { | ||
| const response = await this.moaform.createWebhook({ | ||
| formId: this.formId, | ||
| data: { | ||
| endpoint: this.http.endpoint, | ||
| enabled: true, | ||
| secret: this.secret, | ||
| verify_ssl: true, | ||
| retention_days: this.retentionDays, | ||
| }, | ||
| }); | ||
                
      
                  luancazarine marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| this._setWebhookId(response.id); | ||
| }, | ||
| async deactivate() { | ||
| const webhookId = this.db.get("webhookId"); | ||
| await this.moaform.deleteWebhook({ | ||
| formId: this.formId, | ||
| webhookId, | ||
| }); | ||
| }, | ||
                
      
                  luancazarine marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| }, | ||
| async run({ | ||
| bodyRaw, body, headers, | ||
| }) { | ||
| 
     | 
||
| if (this.secret) { | ||
| const signature = headers["moaform-signature"]; | ||
| const receivedSig = signature.split("sha256=")[1]; | ||
| 
     | 
||
| const calculatedSig = crypto | ||
| .createHmac("sha256", this.secret) | ||
| .update(bodyRaw) | ||
| .digest("base64"); | ||
| 
     | 
||
| if (receivedSig !== calculatedSig) { | ||
| return this.http.respond({ | ||
| status: 401, | ||
| body: "Unauthorized", | ||
| }); | ||
| } | ||
| } | ||
                
      
                  luancazarine marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| const ts = Date.parse(body.submitted_at); | ||
| this.$emit(body, { | ||
| id: body.event_id, | ||
| summary: `New submission received for form ${this.formId}`, | ||
| ts: ts, | ||
| }); | ||
                
      
                  luancazarine marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| }, | ||
| sampleEmit, | ||
| }; | ||
        
          
          
            18 changes: 18 additions & 0 deletions
          
          18 
        
  components/moaform/sources/new-submission-instant/test-event.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,18 @@ | ||
| export default { | ||
| "event_id": "105fa72f-9e6e-4667-8ead-22b0a3ed254a", | ||
| "event_type": "response_completed", | ||
| "hidden": {}, | ||
| "response_id": "test#123-45-67890", | ||
| "submitted_at": "2024-09-27T21:00:55Z", | ||
| "form": { | ||
| "id": "MG7eAk", | ||
| "title": "form title", | ||
| "report_url": "https://www.moaform.com/reports/q945EegynYD8G2xM", | ||
| "answer_url": "https://moaform.com/q/not-started-collecting" | ||
| }, | ||
| "answers": [], | ||
| "thankyou": { | ||
| "id": "cm1l7axyf2t9x0fqrly27vdn7", | ||
| "url": "https://answer.moaform.com/answers/MG7eAk/thankyou/Wo2b1Z09wx5" | ||
| } | ||
| } | 
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.