# Labels System - Labels depends on a booking existing? - Use the booking id as the root identifier for labels? - Use api standardisation - Flags vs status - `"IsReady":true` vs `"Status":"Ready"` - Raise webhooks, sockets and events. - Support disabling labels (ie when a booking is cancelled, disable label downloads). # Questions - What about customs docs? - What about commercial invoices? - We can send digital invoices or; - customer can download a printable version - Can we group all types of booking together? - How do we know which formats are available for a spceific courier? - If a label within a batch fails does the entire file fail? - Can we change the batches between request and response? - Do labels need any additional information or just booking info? (SKU, etc). - Lots of overlap with invoices # Document API ## Reqs - Access rules / Auditing - document worker library (and react library) supporting : - Progress reporting - Access rules (HMAC & ) - Invalidation / expiry - Caching - Auditing - Invalidation - Archive rules - Different document types are different workers (query api style) ## Notes - Use prns for refs - Allows us to use bookingids, orderlines, etc. - Allows a system to request a doc type with an unsupported prn. - We may need to hard-code this mapping or have a db table of prn to system mappings. ## Endpoints /{tenant}/labels ### Request ``` json { "labels" : [{ "refs" : ["prn:booking:123", "prn:customerid:234"], "type" : "prn:label", "format" : "pdf", "tags" : ["IncludeCoverPage"], // onerror": "skip" "tagos" : { "overrides": { "cobranding" : "s3://..." } } }, { "refs" : ["prn:booking:123"], "format" : "qrcode", "tags" : "" }, { "refs" : ["prn:123", "prn:234"], "type" : "customs", "format" : "pdf", "tags" : [], "tagos" : { } }] } ``` ### Response ``` json { "Result" : { "Labels": [ { "BookingIds" : ["prn:123", "prn:234"], "IsReady" : true, "State" : "Ready", "link" : "s3://", "Tags" : ["IncludeCoverPage"], "Tagos" : [] }, { "BookingIds" : ["prn:123"], "IsReady" : false, "State" : "Waiting", }] }, // api standards "Success": true, "ValidationErrors" : {} } ``` ## Worker Package ``` csharp public async Task FunctionHandler(EventMessage<GenerateDocumentCommand> input, ILambdaContext context) { // Sets status to "started". // Handles timeouts // When disposed if the document isn't complete it will set it to error using (_docsApi.Begin(input.Id)) try { var docurl = GenerateDocument(input); _docsApi.Success(input, docurl); } catch (Exception ex) { _docsApi.Fail(input, ex); } } // we can support progress.. string GenerateDocument(GenerateDocumentCommand event) { _docsApi.Progress("Started", 0); var document = new PdfDocument("s3-bucket"); for(int i=0; i < event.Refs.Count; i++) { AppendDocumentToFile(event.refs[i], document); _docsApi.Progress(i / event.Refs.Count); } return document.S3Path; } ```