{ "steps": [ { "name": "Find inventory item", "slug": "find-inventory-item", "type": "GAIIA_API_GATEWAY_V1_GRAPHQL_REQUEST", "nodeSlug": "gaiia-public-api-gateway-graphql-request", "allowSkipExecution": false, "outputMapper": "({ output }) => {\n const assignee = output.response.inventoryItem?.assignation?.assignee;\n if (!assignee || assignee.__typename !== 'Account') {\n workflow.fail('Inventory item is not assigned to an account.', 'NO_ACCOUNT');\n }\n return { id: assignee.id, gaiiaId: assignee.readableId };\n}", "inputs": [ { "key": "query", "type": "LITERAL", "value": "string:query IpAssignmentWorkflowInventoryItemQuery($id: ID!) {\n inventoryItem(id: $id) {\n id\n assignation {\n assignee {\n ... on Account { id readableId }\n }\n }\n }\n}" }, { "key": "variables", "type": "FUNCTION", "value": "({ state }) => ({ id: state.input.objectId })" } ], "nextSteps": [ { "slug": "find-account-cpes" } ] }, { "name": "Find account CPEs", "slug": "find-account-cpes", "type": "GAIIA_FIND_ACCOUNT_CPES", "nodeSlug": "find-account-cpes", "allowSkipExecution": false, "inputs": [ { "key": "accountId", "type": "FUNCTION", "value": "({ state }) => state.steps['find-inventory-item'].output.id" } ], "nextSteps": [ { "slug": "find-account-internet-plans" } ] }, { "name": "Find account Internet plans", "slug": "find-account-internet-plans", "type": "GAIIA_FIND_ACCOUNT_INTERNET_PLANS", "nodeSlug": "find-account-internet-plans", "allowSkipExecution": false, "inputs": [ { "key": "accountId", "type": "FUNCTION", "value": "({ state }) => state.steps['find-inventory-item'].output.id" } ], "nextSteps": [ { "slug": "preseem-update-service" } ] }, { "name": "Preseem update service", "slug": "preseem-update-service", "type": "PRESEEM_REST_REQUEST", "nodeSlug": "preseem-rest-request", "allowSkipExecution": false, "inputs": [ { "key": "body", "type": "FUNCTION", "value": "({ state }) => {\n const { gaiiaId } = state.steps['find-inventory-item'].output;\n const [{ slug }] = state.steps['find-account-internet-plans'].output.internetPlans;\n const cpes = state.steps['find-account-cpes'].output.accountCpe;\n const eventMac = state.input.payload.macAddress;\n const macAddresses = [\n ...new Set([\n ...cpes.map(({ macAddress }) => macAddress),\n eventMac\n ])\n ];\n return {\n id: String(gaiiaId),\n attachments: macAddresses\n .filter(Boolean)\n .map((macAddress) => ({ cpe_mac: macAddress.toLowerCase() })),\n account: String(gaiiaId),\n package: slug\n };\n }" }, { "key": "method", "type": "LITERAL", "value": "string:PUT" }, { "key": "path", "type": "FUNCTION", "value": "({ state }) => /services/${state.steps['find-inventory-item'].output.gaiiaId}" } ], "nextSteps": [ { "slug": "end" } ] } ], "trigger": { "nextSteps": [ { "slug": "find-inventory-item" } ], "type": "EVENT", "events": [ "inventory_item.ip_address_assigned", "inventory_item.ip_address_unassigned" ] } }