src/scope/ActionApp.js
/**
   * Helper function to create an action with extra data.
   *
   * @param {string} type - Action Type. Must exist in Application project scope.
   * @param {Object} [data] - Optional extra action data associated with the web page.
   *                          Add 'thng' or 'product' to set that ID as the action target.
   * @returns {Promise<Object>} The action that was created.
   */
Helper function to create an action with extra data.
@param {string} type - Action Type. Must exist in Application project scope.
@param {Object} [data] - Optional extra action data associated with the web page.
Add 'thng' or 'product' to set that ID as the action target.
@returns {Promise} The action that was created.
Helper function to create an action with extra data . @param { string } type - Action Type . Must exist in Application project scope . @param { Object } [ data ] - Optional extra action data associated with the web page . Add ' thng ' or ' product ' to set that ID as the action target . @returns { Promise } The action that was created .
async createAction (type, data = {}) {
    if (!this.anonUser) {
      throw new Error('Anonymous user not yet prepared. Use actionApp.init() to wait for this.')
    }
    if (type.startsWith('_')) {
      try {
        await this.anonUser.actionType(type).read()
      } catch (e) {
        console.error(e)
        throw new Error('The action type was not found. Is it in project scope?')
      }
    }
    const { thng, product, ...customFields } = data
    if (thng && product) {
      throw new Error('Either thng or product can be specified as target, not both')
    }
    const payload = { type, customFields }
    if (thng) {
      payload.thng = thng
    }
    if (product) {
      payload.product = product
    }
    return this.anonUser.action(type).create(payload)
  }
async createAction ( type , data = { } ) { if ( ! this . anonUser ) { throw new Error ( 'Anonymous user not yet prepared. Use actionApp.init() to wait for this.' ) } if ( type . startsWith ( '_' ) ) { try { await this . anonUser . actionType ( type ) . read ( ) } catch ( e ) { console . error ( e ) throw new Error ( 'The action type was not found. Is it in project scope?' ) } } const { thng , product , ... customFields } = data if ( thng && product ) { throw new Error ( 'Either thng or product can be specified as target, not both' ) } const payload = { type , customFields } if ( thng ) { payload . thng = thng } if ( product ) { payload . product = product } return this . anonUser . action ( type ) . create ( payload ) }
Helper function to create an action with extra data.
Helper function to create an action with extra data .
// Check the custom action type is visible to the user