- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
17438 afosto #18476
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
                    17438 afosto #18476
Changes from 2 commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      fd15883
              
                Implement Afosto cart actions and update component structure
              
              
                luancazarine 40a1a0d
              
                pnpm update
              
              
                luancazarine 2f20f95
              
                Merge branch 'master' into 17438-afosto
              
              
                luancazarine 5c48cd9
              
                pnpm update
              
              
                luancazarine 8bd3d5e
              
                Remove optional flag from billing address fields and correct paramete…
              
              
                luancazarine 0440eb9
              
                Add Afosto cart mutations and refactor actions to utilize them
              
              
                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
        
          
          
            452 changes: 452 additions & 0 deletions
          
          452 
        
  components/afosto/actions/add-information-to-cart/add-information-to-cart.mjs
  
  
      
      
   
        
      
      
    Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  
        
          
          
            78 changes: 78 additions & 0 deletions
          
          78 
        
  components/afosto/actions/add-item-to-cart/add-item-to-cart.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,78 @@ | ||
| import app from "../../afosto.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "afosto-add-item-to-cart", | ||
| name: "Add Item to Cart", | ||
| description: "Add an item to a cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/integration/add-and-remove-items/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| sku: { | ||
| type: "string", | ||
| label: "SKU", | ||
| description: "The SKU of the item to add to the cart.", | ||
| }, | ||
| quantity: { | ||
| type: "integer", | ||
| label: "Quantity", | ||
| description: "The quantity of the item to add to the cart.", | ||
| }, | ||
| cartId: { | ||
| propDefinition: [ | ||
| app, | ||
| "cartId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| try { | ||
| const response = await this.app.query({ | ||
| $, | ||
| data: JSON.stringify({ | ||
| query: `mutation AddItemToCart( | ||
|         
                  luancazarine marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| $input: AddItemsToCartInput! | ||
| ) { | ||
| addItemsToCart(input: $input) { | ||
| cart { | ||
| id | ||
| items { | ||
| ids | ||
| label | ||
| brand | ||
| mpn | ||
| gtin | ||
| image | ||
| hs_code | ||
| country_of_origin | ||
| url | ||
| sku | ||
| quantity | ||
| subtotal | ||
| total | ||
| parent_id | ||
| } | ||
| } | ||
|         
                  luancazarine marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| } | ||
| }`, | ||
| variables: { | ||
| input: { | ||
| cart_id: this.cartId, | ||
| items: [ | ||
| { | ||
| sku: this.sku, | ||
| quantity: this.quantity, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }), | ||
| }); | ||
|         
                  luancazarine marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| $.export("$summary", `Successfully added item to cart with SKU: ${response.data.addItemsToCart.cart.items[0].sku}`); | ||
| return response.data.addItemsToCart.cart; | ||
| } catch ({ response }) { | ||
| throw new Error(`${response.data?.errors?.[0]?.message}`); | ||
| } | ||
| }, | ||
| }; | ||
        
          
          
            66 changes: 66 additions & 0 deletions
          
          66 
        
  components/afosto/actions/add-note-to-cart/add-note-to-cart.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,66 @@ | ||
| import app from "../../afosto.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "afosto-add-note-to-cart", | ||
| name: "Add Note to Cart", | ||
| description: "Add a note to a cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/custom-checkout/checkout-summary/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| cartId: { | ||
| propDefinition: [ | ||
| app, | ||
| "cartId", | ||
| ], | ||
| }, | ||
| note: { | ||
| type: "string", | ||
| label: "Note", | ||
| description: "The note to add to the cart", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| try { | ||
| const variables = { | ||
| cartId: this.cartId, | ||
| note: this.note, | ||
| }; | ||
|  | ||
| const response = await this.app.query({ | ||
| $, | ||
| maxBodyLength: Infinity, | ||
| headers: { | ||
| "DisablePreParseMultipartForm": "true", | ||
| }, | ||
| data: JSON.stringify({ | ||
| query: `mutation SetNoteForCart ( | ||
| $cartId: String! | ||
| $note: String! | ||
| ) { | ||
| setNoteForCart(input: { cart_id: $cartId, note: $note }) { | ||
| cart { | ||
| id | ||
| number | ||
| total | ||
| subtotal | ||
| total_excluding_vat | ||
| currency | ||
| is_including_vat | ||
| is_vat_shifted | ||
| created_at | ||
| updated_at | ||
| } | ||
| } | ||
| }`, | ||
| variables, | ||
| }), | ||
| }); | ||
|         
                  luancazarine marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| $.export("$summary", `Successfully added note to cart with ID: ${this.cartId}`); | ||
| return response.data.setNoteForCart.cart; | ||
| } catch (error) { | ||
| throw new Error(`${error.errors?.[0]?.message || "An unknown error occurred"}`); | ||
| } | ||
| }, | ||
| }; | ||
  
    
      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,45 @@ | ||
| import app from "../../afosto.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "afosto-confirm-cart", | ||
| name: "Confirm Cart", | ||
| description: "Confirm a cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/custom-checkout/payment-process/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| cartId: { | ||
| propDefinition: [ | ||
| app, | ||
| "cartId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| try { | ||
| const response = await this.app.query({ | ||
| $, | ||
| data: JSON.stringify({ | ||
| query: `mutation ConfirmCart ( | ||
| $cartId: String! | ||
| ) { | ||
| confirmCart(input: { cart_id: $cartId }) { | ||
| order { | ||
| id | ||
| } | ||
| } | ||
| } | ||
| `, | ||
| variables: { | ||
| cartId: this.cartId, | ||
| }, | ||
| }), | ||
| }); | ||
|         
                  luancazarine marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| $.export("$summary", `Successfully confirmed cart with ID: ${response.data.confirmCart.order.id}`); | ||
| return response.data.confirmCart.order; | ||
|         
                  luancazarine marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| } catch ({ response }) { | ||
| throw new Error(`${response.data?.errors?.[0]?.message}`); | ||
| } | ||
| }, | ||
| }; | ||
  
    
      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,41 @@ | ||
| import app from "../../afosto.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "afosto-create-cart", | ||
| name: "Create Cart", | ||
| description: "Create a new cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/integration/create-a-cart/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| }, | ||
| async run({ $ }) { | ||
| try { | ||
| const response = await this.app.query({ | ||
| $, | ||
| data: JSON.stringify({ | ||
| query: `mutation createCart { | ||
| createCart(input: {}) { | ||
| cart { | ||
| id | ||
| number | ||
| total | ||
| subtotal | ||
| total_excluding_vat | ||
| currency | ||
| is_including_vat | ||
| is_vat_shifted | ||
| created_at | ||
| } | ||
| } | ||
| }`, | ||
| }), | ||
| }); | ||
|  | ||
| $.export("$summary", `Successfully created cart with ID: ${response.data.createCart.cart.id}`); | ||
| return response.data.createCart.cart; | ||
| } catch ({ response }) { | ||
| throw new Error(`${response.data?.errors?.[0]?.message}`); | ||
| } | ||
|         
                  luancazarine marked this conversation as resolved.
              Outdated
          
            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
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,11 +1,40 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|  | ||
| export default { | ||
| type: "app", | ||
| app: "afosto", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| cartId: { | ||
| type: "string", | ||
| label: "Cart ID", | ||
| description: "The ID of the cart", | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _headers(headers = {}) { | ||
| return { | ||
| "Authorization": `Bearer ${this.$auth.auth_token}`, | ||
| "Content-Type": "application/json", | ||
| ...headers, | ||
| }; | ||
| }, | ||
| _baseUrl() { | ||
| return "https://afosto.app/graphql"; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path = "", headers, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: this._baseUrl() + path, | ||
| headers: this._headers(headers), | ||
| ...opts, | ||
| }); | ||
|         
                  luancazarine marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }, | ||
| query(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
  
    
      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,24 @@ | ||
| export const parseObject = (obj) => { | ||
| if (!obj) return undefined; | ||
|         
                  luancazarine marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| if (Array.isArray(obj)) { | ||
| return obj.map((item) => { | ||
| if (typeof item === "string") { | ||
| try { | ||
| return JSON.parse(item); | ||
| } catch (e) { | ||
| return item; | ||
| } | ||
| } | ||
| return item; | ||
| }); | ||
| } | ||
| if (typeof obj === "string") { | ||
| try { | ||
| return JSON.parse(obj); | ||
| } catch (e) { | ||
| return obj; | ||
| } | ||
| } | ||
| return obj; | ||
| }; | ||
  
    
      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,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/afosto", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Afosto Components", | ||
| "main": "afosto.app.mjs", | ||
| "keywords": [ | ||
|  | @@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.0" | ||
| } | ||
| } | ||
| } | ||
      
      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.