{"openapi":"3.0.3","info":{"title":"SMA Invoice Service API","version":"v1","description":"Documentación de los endpoints expuestos en el servidor Express dentro de Firebase Functions."},"servers":[{"url":"/v1","description":"Base path bajo la función onRequest"}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"ApiResponse":{"type":"object","properties":{"status":{"type":"string","enum":["ok","error","failure"]},"code":{"type":"string"},"message":{"type":"string"},"data":{"type":"object","nullable":true}},"required":["status","code","message","data"]},"Source":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"url":{"type":"string"},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"deleted_at":{"type":"string","format":"date-time","nullable":true}}},"Client":{"type":"object","properties":{"id":{"type":"string"},"sourceId":{"type":"string"},"name":{"type":"string"},"rfc":{"type":"string"},"regimenFiscal":{"type":"string"},"activityPreference":{"type":"string"},"publicKeyUrl":{"type":"string"},"privateKeyUrl":{"type":"string"},"stampingProvider":{"type":"string","enum":["MOCK","FOLIOS_DIGITALES","SVAM"]},"stampingSandbox":{"type":"boolean"},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"deleted_at":{"type":"string","format":"date-time","nullable":true}}},"Invoice":{"type":"object","properties":{"id":{"type":"string"},"source_id":{"type":"string"},"client_id":{"type":"string"},"external_id":{"type":"string"},"xml_url":{"type":"string"},"sealed":{"type":"boolean"},"stamped":{"type":"boolean"},"stamped_xml_url":{"type":"string"},"status":{"type":"string","enum":["CREATED","SEALED","STAMPING","STAMPED","CANCELLING","CANCELED","FAILED_CANCEL","ERROR"]},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"deleted_at":{"type":"string","format":"date-time","nullable":true}}},"Operation":{"type":"object","properties":{"id":{"type":"string"},"type":{"type":"string","enum":["INVOICES_BATCH_CREATE","INVOICES_BATCH_STAMP"]},"status":{"type":"string","enum":["PENDING","RUNNING","DONE","ERROR"]},"source_id":{"type":"string"},"total":{"type":"number"},"processed":{"type":"number"},"success":{"type":"number"},"error":{"type":"number"},"details":{"type":"object","nullable":true},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"}}}}},"paths":{"/health":{"get":{"summary":"Health Check","responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}}},"/sources/login":{"post":{"summary":"Source Login","security":[],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string"},"secret":{"type":"string"}},"required":["id","secret"]}}}},"responses":{"200":{"description":"Token issued","content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/ApiResponse"},{"properties":{"data":{"type":"object","properties":{"accessToken":{"type":"string"},"expiresIn":{"type":"number"}}}}}]}}}}}}},"/sources":{"get":{"summary":"List Sources","security":[{"bearerAuth":[]}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}},"post":{"summary":"Create Source","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"url":{"type":"string"}},"required":["name","url"]}}}},"responses":{"201":{"$ref":"#/components/schemas/ApiResponse"}}}},"/sources/{id}":{"get":{"summary":"Get Source","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}},"put":{"summary":"Update Source","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"url":{"type":"string"}}}}}},"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}},"delete":{"summary":"Delete Source","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}}},"/sources/{id}/rotate-secret":{"post":{"summary":"Rotate Source Secret","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}}},"/sources/{id}/webhooks":{"get":{"summary":"Get Source Webhooks","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}},"post":{"summary":"Upsert Source Webhooks","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"invoice_created":{"type":"string"},"invoice_error":{"type":"string"},"invoice_sealed":{"type":"string"},"invoice_stamped":{"type":"string"},"invoice_stamp_requested":{"type":"string"},"invoice_stamp_failed":{"type":"string"},"invoice_cancel_requested":{"type":"string"},"invoice_canceled":{"type":"string"},"invoice_cancel_failed":{"type":"string"}}}}}},"responses":{"201":{"$ref":"#/components/schemas/ApiResponse"}}},"delete":{"summary":"Delete Source Webhooks","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}}},"/clients":{"get":{"summary":"List Clients","security":[{"bearerAuth":[]}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}},"post":{"summary":"Create Client","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"rfc":{"type":"string"},"regimenFiscal":{"type":"string"},"activityPreference":{"type":"string"},"publicKey":{"type":"string"},"privateKey":{"type":"string"},"stampingProvider":{"type":"string","enum":["MOCK","FOLIOS_DIGITALES","SVAM"]},"stampingSandbox":{"type":"boolean"}},"required":["name","rfc","regimenFiscal"]}}}},"responses":{"201":{"$ref":"#/components/schemas/ApiResponse"}}}},"/clients/{id}":{"get":{"summary":"Get Client","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}},"put":{"summary":"Update Client","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"rfc":{"type":"string"},"regimenFiscal":{"type":"string"},"activityPreference":{"type":"string"},"publicKey":{"type":"string"},"privateKey":{"type":"string"},"stampingProvider":{"type":"string","enum":["MOCK","FOLIOS_DIGITALES","SVAM"]},"stampingSandbox":{"type":"boolean"}}}}}},"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}},"delete":{"summary":"Delete Client","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}}},"/clients/{id}/provider/balance":{"get":{"summary":"Get Client Provider Balance","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}}},"/clients/{id}/stamping-provider-config":{"post":{"summary":"Upsert Client Stamping Provider Config","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"provider":{"type":"string","enum":["MOCK","FOLIOS_DIGITALES","SVAM"]},"foliosDigitales":{"type":"object"},"svam":{"type":"object"}},"required":["provider"]}}}},"responses":{"201":{"$ref":"#/components/schemas/ApiResponse"}}},"put":{"summary":"Update Client Stamping Provider Config","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object"}}}},"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}},"delete":{"summary":"Delete Client Stamping Provider Config","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}}},"/invoices":{"get":{"summary":"List Invoices","security":[{"bearerAuth":[]}],"parameters":[{"name":"source_id","in":"query","schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}},"post":{"summary":"Create Invoice","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"client_id":{"type":"string"},"external_id":{"type":"string"},"xml_url":{"type":"string"},"source_id":{"type":"string","description":"Optional in dev mode"}},"required":["client_id","external_id","xml_url"]}}}},"responses":{"201":{"$ref":"#/components/schemas/ApiResponse"}}}},"/invoices/{id}":{"get":{"summary":"Get Invoice","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}},"put":{"summary":"Update Invoice","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"xml_url":{"type":"string"}}}}}},"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}},"delete":{"summary":"Delete/Cancel Invoice","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"cveMotivo","in":"query","schema":{"type":"string"}},{"name":"folioSustituye","in":"query","schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}}},"/invoices/{id}/seal":{"post":{"summary":"Seal Invoice","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}}},"/invoices/{id}/stamp":{"post":{"summary":"Stamp Invoice","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"202":{"$ref":"#/components/schemas/ApiResponse"}}}},"/invoices/batch":{"post":{"summary":"Batch Create Invoices","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"items":{"type":"array","items":{"type":"object","properties":{"client_id":{"type":"string"},"external_id":{"type":"string"},"xml_url":{"type":"string"}},"required":["client_id","external_id","xml_url"]}},"source_id":{"type":"string"}}}}}},"responses":{"202":{"$ref":"#/components/schemas/ApiResponse"}}}},"/invoices/batch-stamp":{"post":{"summary":"Batch Stamp Invoices","security":[{"bearerAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"ids":{"type":"array","items":{"type":"string"}},"source_id":{"type":"string"}}}}}},"responses":{"202":{"$ref":"#/components/schemas/ApiResponse"}}}},"/operations/{id}":{"get":{"summary":"Get Operation","security":[{"bearerAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/schemas/ApiResponse"}}}}}}