- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
Simla: new action and source components #14047
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
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            2 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    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
        
          
          
            115 changes: 115 additions & 0 deletions
          
          115 
        
  components/simla_com/actions/create-customer/create-customer.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,115 @@ | ||
| import app from "../../simla_com.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "simla_com-create-customer", | ||
| name: "Create Customer", | ||
| description: "Creates a new customer profile. [See the documentation](https://docs.simla.com/Developers/API/APIVersions/APIv5#post--api-v5-customers-create).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| firstName: { | ||
| type: "string", | ||
| label: "First Name", | ||
| description: "The name of the customer.", | ||
| }, | ||
| lastName: { | ||
| type: "string", | ||
| label: "Last Name", | ||
| description: "The last name of the customer.", | ||
| optional: true, | ||
| }, | ||
| phones: { | ||
| type: "string[]", | ||
| label: "Phone Numbers", | ||
| description: "The phone numbers of the customer.", | ||
| optional: true, | ||
| }, | ||
| email: { | ||
| type: "string", | ||
| label: "Email", | ||
| description: "The email address of the customer.", | ||
| optional: true, | ||
| }, | ||
| postalCode: { | ||
| type: "string", | ||
| label: "Postal Code", | ||
| description: "The postal code of the customer.", | ||
| optional: true, | ||
| }, | ||
| countryIso: { | ||
| optional: true, | ||
| propDefinition: [ | ||
| app, | ||
| "countryIso", | ||
| ], | ||
| }, | ||
| region: { | ||
| type: "string", | ||
| label: "Region", | ||
| description: "The region of the customer.", | ||
| optional: true, | ||
| }, | ||
| city: { | ||
| type: "string", | ||
| label: "City", | ||
| description: "The city of the customer.", | ||
| optional: true, | ||
| }, | ||
| street: { | ||
| type: "string", | ||
| label: "Street", | ||
| description: "The street of the customer.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| createCustomer(args = {}) { | ||
| return this.app.post({ | ||
| path: "/customers/create", | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| createCustomer, | ||
| firstName, | ||
| lastName, | ||
| phones, | ||
| email, | ||
| postalCode, | ||
| countryIso, | ||
| region, | ||
| city, | ||
| street, | ||
| } = this; | ||
|  | ||
| const response = await createCustomer({ | ||
| $, | ||
| data: { | ||
| customer: JSON.stringify({ | ||
| firstName, | ||
| lastName, | ||
| email, | ||
| address: { | ||
| index: postalCode, | ||
| countryIso, | ||
| region, | ||
| city, | ||
| street, | ||
| }, | ||
| ...(phones?.length && { | ||
| phones: phones.map((number) => ({ | ||
| number, | ||
| })), | ||
| }), | ||
| }), | ||
| }, | ||
| }); | ||
|  | ||
| $.export("$summary", `Successfully created customer with ID \`${response.id}\`.`); | ||
|  | ||
| return response; | ||
| }, | ||
| }; | 
        
          
          
            195 changes: 195 additions & 0 deletions
          
          195 
        
  components/simla_com/actions/create-order/create-order.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,195 @@ | ||
| import app from "../../simla_com.app.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
|  | ||
| export default { | ||
| key: "simla_com-create-order", | ||
| name: "Create Order", | ||
| description: "Creates a new order with customer and order details. [See the documentation](https://docs.simla.com/Developers/API/APIVersions/APIv5#post--api-v5-orders-create).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| site: { | ||
| propDefinition: [ | ||
| app, | ||
| "site", | ||
| ], | ||
| }, | ||
| customerType: { | ||
| propDefinition: [ | ||
| app, | ||
| "customerType", | ||
| ], | ||
| }, | ||
| customerId: { | ||
| propDefinition: [ | ||
| app, | ||
| "customerId", | ||
| ({ customerType }) => ({ | ||
| customerType, | ||
| }), | ||
| ], | ||
| }, | ||
| countryIso: { | ||
| propDefinition: [ | ||
| app, | ||
| "countryIso", | ||
| ], | ||
| }, | ||
| orderType: { | ||
| propDefinition: [ | ||
| app, | ||
| "orderType", | ||
| ], | ||
| }, | ||
| deliveryCost: { | ||
| type: "string", | ||
| label: "Delivery Cost", | ||
| description: "The cost of delivery.", | ||
| }, | ||
| deliveryNetCost: { | ||
| type: "string", | ||
| label: "Delivery Net Cost", | ||
| description: "The net cost of delivery.", | ||
| }, | ||
| numberOfItems: { | ||
| type: "integer", | ||
| label: "Number Of Items", | ||
| description: "The number of items to be ordered.", | ||
| default: 1, | ||
| reloadProps: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| itemsPropsMapper(prefix) { | ||
| const { | ||
| [`${prefix}initialPrice`]: initialPrice, | ||
| [`${prefix}quantity`]: quantity, | ||
| [`${prefix}comment`]: comment, | ||
| [`${prefix}purchasePrice`]: purchasePrice, | ||
| [`${prefix}productName`]: productName, | ||
| [`${prefix}discountManualAmount`]: discountManualAmount, | ||
| [`${prefix}discountManualPercent`]: discountManualPercent, | ||
| } = this; | ||
|  | ||
| return { | ||
| initialPrice, | ||
| quantity, | ||
| comment, | ||
| purchasePrice, | ||
| productName, | ||
| discountManualAmount, | ||
| discountManualPercent, | ||
| }; | ||
| }, | ||
| getItemsPropDefinitions({ | ||
| prefix, | ||
| label, | ||
| } = {}) { | ||
| return { | ||
| [`${prefix}initialPrice`]: { | ||
| type: "string", | ||
| label: `${label} - Initial Price`, | ||
| description: "The initial price of the item.", | ||
| optional: true, | ||
| }, | ||
| [`${prefix}quantity`]: { | ||
| type: "string", | ||
| label: `${label} - Quantity`, | ||
| description: "The quantity of the item.", | ||
| optional: true, | ||
| }, | ||
| [`${prefix}comment`]: { | ||
| type: "string", | ||
| label: `${label} - Comment`, | ||
| description: "The comment for the item.", | ||
| optional: true, | ||
| }, | ||
| [`${prefix}purchasePrice`]: { | ||
| type: "string", | ||
| label: `${label} - Purchase Price`, | ||
| description: "The purchase price of the item.", | ||
| optional: true, | ||
| }, | ||
| [`${prefix}productName`]: { | ||
| type: "string", | ||
| label: `${label} - Product Name`, | ||
| description: "The name of the product.", | ||
| optional: true, | ||
| }, | ||
| [`${prefix}discountManualAmount`]: { | ||
| type: "string", | ||
| label: `${label} - Discount Manual Amount`, | ||
| description: "The manual discount amount for the item.", | ||
| optional: true, | ||
| }, | ||
| [`${prefix}discountManualPercent`]: { | ||
| type: "string", | ||
| label: `${label} - Discount Manual Percent`, | ||
| description: "The manual discount percent for the item.", | ||
| optional: true, | ||
| }, | ||
| }; | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }, | ||
| createOrder(args = {}) { | ||
| return this.app.post({ | ||
| path: "/orders/create", | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async additionalProps() { | ||
| const { | ||
| numberOfItems, | ||
| getItemsPropDefinitions, | ||
| } = this; | ||
|  | ||
| return utils.getAdditionalProps({ | ||
| numberOfFields: numberOfItems, | ||
| fieldName: "item", | ||
| getPropDefinitions: getItemsPropDefinitions, | ||
| }); | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| numberOfItems, | ||
| itemsPropsMapper, | ||
| createOrder, | ||
| countryIso, | ||
| orderType, | ||
| site, | ||
| customerType, | ||
| customerId, | ||
| deliveryCost, | ||
| deliveryNetCost, | ||
| } = this; | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| const response = await createOrder({ | ||
| $, | ||
| data: { | ||
| site, | ||
| customer: JSON.stringify({ | ||
| customerType, | ||
| customerId, | ||
| }), | ||
| order: JSON.stringify({ | ||
| countryIso, | ||
| orderType, | ||
| customerType, | ||
| customerId, | ||
| delivery: { | ||
| cost: deliveryCost, | ||
| netCost: deliveryNetCost, | ||
| }, | ||
| items: utils.getFieldsProps({ | ||
| numberOfFields: numberOfItems, | ||
| fieldName: "item", | ||
| propsMapper: itemsPropsMapper, | ||
| }), | ||
| }), | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully created order with ID \`${response.id}\`.`); | ||
| return response; | ||
| }, | ||
| }; | ||
  
    
      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,29 @@ | ||
| const SUBDOMAIN_PLACEHOLDER = "{subdomain}"; | ||
| const VERSION_PLACEHOLDER = "{version}"; | ||
| const BASE_URL = `https://${SUBDOMAIN_PLACEHOLDER}.simla.com/api/${VERSION_PLACEHOLDER}`; | ||
| const IS_FIRST_RUN = "isFirstRun"; | ||
| const LAST_DATE_AT = "lastDateAt"; | ||
| const DEFAULT_LIMIT = 20; | ||
| const DEFAULT_MAX = 200; | ||
|  | ||
| const CUSTOMER_TYPE = { | ||
| CUSTOMER: { | ||
| label: "Customer", | ||
| value: "customer", | ||
| }, | ||
| CORPORATE: { | ||
| label: "Corporate Customer", | ||
| value: "customer_corporate", | ||
| }, | ||
| }; | ||
|  | ||
| export default { | ||
| SUBDOMAIN_PLACEHOLDER, | ||
| VERSION_PLACEHOLDER, | ||
| BASE_URL, | ||
| IS_FIRST_RUN, | ||
| CUSTOMER_TYPE, | ||
| LAST_DATE_AT, | ||
| DEFAULT_LIMIT, | ||
| DEFAULT_MAX, | ||
| }; | 
      
      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.