{
  "name": "Mockups Generator - reviewed collection export",
  "nodes": [
    {
      "id": "run-manually",
      "name": "Run manually",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "parameters": {}
    },
    {
      "id": "workflow-settings",
      "name": "Workflow settings",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        0
      ],
      "parameters": {
        "jsCode": "// Configure IDs from your own workspace. Keep the same run key for a retry.\n// Use a NEW run key only when intentionally creating a different collection.\nconst base_url = 'https://web.mockupsgenerator.com';\nconst template_id = 'REPLACE_TEMPLATE_ID';\nconst asset_id = 'REPLACE_ASSET_ID';\nconst run_key = 'collection-run-001';\nif (template_id.startsWith('REPLACE') || asset_id.startsWith('REPLACE')) throw new Error('Set template_id and asset_id before running.');\nreturn [{json:{base_url,started_at:Date.now(),spec:{templates:[{id:template_id}],assets:[asset_id],idempotency_key:run_key,options:{format:'png',output_profile:'gallery-square-v1'}}}}];"
      }
    },
    {
      "id": "preflight",
      "name": "Preflight",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        0
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $('Workflow settings').first().json.base_url + '/api/v1/bulk-jobs/preflight' }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 60000
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $('Workflow settings').first().json.spec }}"
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "id": "require-valid-plan",
      "name": "Require valid plan",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        0
      ],
      "parameters": {
        "jsCode": "if (!$json.valid) throw new Error(($json.errors || []).map(e => e.message).join('; ') || 'Preflight failed'); return $input.all();"
      }
    },
    {
      "id": "submit-collection",
      "name": "Submit collection",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        960,
        0
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $('Workflow settings').first().json.base_url + '/api/v1/bulk-jobs' }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 60000
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $('Workflow settings').first().json.spec }}"
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "id": "wait-for-worker",
      "name": "Wait for worker",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1200,
        0
      ],
      "parameters": {
        "resume": "timeInterval",
        "amount": 5,
        "unit": "seconds"
      }
    },
    {
      "id": "read-status",
      "name": "Read status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1440,
        0
      ],
      "parameters": {
        "method": "GET",
        "url": "={{ $('Workflow settings').first().json.base_url + '/api/v1/bulk-jobs/' + $('Submit collection').first().json.id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 60000
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "id": "check-job-state",
      "name": "Check job state",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1680,
        0
      ],
      "parameters": {
        "jsCode": "if (['error','cancelled'].includes($json.status)) throw new Error('Collection stopped: ' + ($json.error || $json.status) + '. Open /bulk/' + $json.id + ' to review and retry saved outputs.');\nif (!['queued','running','cancelling','done'].includes($json.status)) throw new Error('Unexpected job status');\nif ($json.status !== 'done' && Date.now() - $('Workflow settings').first().json.started_at > 1800000) throw new Error('Polling stopped after 30 minutes. The server job continues; rerun with the SAME run key to resume.');\nreturn $input.all();"
      }
    },
    {
      "id": "finished",
      "name": "Finished",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1920,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "status-done",
              "leftValue": "={{ $json.status }}",
              "rightValue": "done",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "download-collection",
      "name": "Download collection",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2160,
        0
      ],
      "parameters": {
        "method": "GET",
        "url": "={{ $('Workflow settings').first().json.base_url + '/api/v1/bulk-jobs/' + $('Submit collection').first().json.id + '/result' }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 60000,
          "response": {
            "response": {
              "responseFormat": "file",
              "outputPropertyName": "collection"
            }
          }
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    }
  ],
  "connections": {
    "Run manually": {
      "main": [
        [
          {
            "node": "Workflow settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow settings": {
      "main": [
        [
          {
            "node": "Preflight",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Preflight": {
      "main": [
        [
          {
            "node": "Require valid plan",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Require valid plan": {
      "main": [
        [
          {
            "node": "Submit collection",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Submit collection": {
      "main": [
        [
          {
            "node": "Wait for worker",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for worker": {
      "main": [
        [
          {
            "node": "Read status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read status": {
      "main": [
        [
          {
            "node": "Check job state",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check job state": {
      "main": [
        [
          {
            "node": "Finished",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Finished": {
      "main": [
        [
          {
            "node": "Download collection",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait for worker",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
