# proto-file: metacore/api/v1/schema.proto # proto-message: metacore.api.v1.Schema # An online shop: its products with their prices and their stock, and the # orders that customers place. A message of metacore.api.v1.Schema, in the # text format of Protocol Buffers. # # product identity global what the product is # texts language what a customer reads # media language what a customer sees # pricing market what it costs, by period # stock warehouse its units: balances that many orders add to # order placed global the order as it was placed: stated once # fulfilment global where the order stands # order_line placed global a line of an order: stated once # # The units of a product are conserved: a change set moves them between # warehouses, or between on_hand, reserved and sold, and their sum stays the # same. What a supplier delivers comes from supplied, the one balance with no # least. # # The storefront calls the procedure checkout, which states the order with # its lines and reserves the units in one change set: of two customers who # take the last unit, one order publishes and the other fails whole. The # payment provider and the carrier tell through webhooks what happened to an # order, and a gate rule holds a change of prices that reaches too far. # # The org declares the scopes before the first deployment: language and # market under global, and warehouse under market. entities { name: "product" key { name: "sku" type: FIELD_TYPE_TEXT } layers { name: "identity" scope: "global" fields { name: "name" type: FIELD_TYPE_TEXT required: true min_length: 2 max_length: 120 exposed: true } fields { name: "brand" type: FIELD_TYPE_TEXT max_length: 60 } fields { name: "status" type: FIELD_TYPE_TEXT allowed_values: "draft" allowed_values: "active" allowed_values: "retired" } } layers { name: "texts" scope: "language" fields { name: "title" type: FIELD_TYPE_TEXT max_length: 200 } fields { name: "description" type: FIELD_TYPE_TEXT } fields { name: "slug" type: FIELD_TYPE_TEXT pattern: "[a-z0-9-]{1,80}" } uniques { name: "slug" fields: "slug" scope: "language" ignore_case: true } } layers { name: "media" scope: "language" fields { name: "photos" type: FIELD_TYPE_FILE list: true file { media_types: [FILE_MEDIA_TYPE_JPEG, FILE_MEDIA_TYPE_PNG, FILE_MEDIA_TYPE_WEBP] public: true widths: [320, 640, 1280] max_bytes: 20971520 min_width: 800 min_height: 800 } } } # A price holds over a period that its change names: a price list from a # day, or a promotion of one week over it. layers { name: "pricing" scope: "market" dated: true fields { name: "price" type: FIELD_TYPE_DECIMAL decimal_places: 2 least { decimal: "0" } exposed: true } fields { name: "cost" type: FIELD_TYPE_DECIMAL decimal_places: 4 least { decimal: "0" } restricted { read_roles: "finance" write_roles: "finance" } } } layers { name: "stock" scope: "warehouse" balances: true conserved { key: "sku" } fields { name: "on_hand" type: FIELD_TYPE_INTEGER least { integer: 0 } } fields { name: "reserved" type: FIELD_TYPE_INTEGER least { integer: 0 } } fields { name: "sold" type: FIELD_TYPE_INTEGER least { integer: 0 } } fields { name: "supplied" type: FIELD_TYPE_INTEGER } } } entities { name: "order" key { name: "number" type: FIELD_TYPE_TEXT } layers { name: "placed" scope: "global" once: true fields { name: "customer" type: FIELD_TYPE_TEXT required: true max_length: 120 } fields { name: "email" type: FIELD_TYPE_TEXT restricted { read_roles: "service" write_roles: "service" } } fields { name: "total" type: FIELD_TYPE_DECIMAL decimal_places: 2 least { decimal: "0" } } fields { name: "currency" type: FIELD_TYPE_TEXT allowed_values: "EUR" allowed_values: "USD" allowed_values: "GBP" } fields { name: "day" type: FIELD_TYPE_DATE required: true } } layers { name: "fulfilment" scope: "global" fields { name: "status" type: FIELD_TYPE_TEXT allowed_values: "paid" allowed_values: "picked" allowed_values: "shipped" allowed_values: "delivered" allowed_values: "returned" } fields { name: "carrier" type: FIELD_TYPE_TEXT max_length: 60 } fields { name: "tracking" type: FIELD_TYPE_TEXT max_length: 80 } } } entities { name: "order_line" key { name: "order" type: FIELD_TYPE_TEXT } key { name: "position" type: FIELD_TYPE_INTEGER } layers { name: "placed" scope: "global" once: true fields { name: "product" type: FIELD_TYPE_REFERENCE required: true reference { entity: "product" carries: "name" } } fields { name: "quantity" type: FIELD_TYPE_INTEGER least { integer: 1 } } fields { name: "unit_price" type: FIELD_TYPE_DECIMAL decimal_places: 2 least { decimal: "0" } } } } roles { name: "merchandiser" permissions { operation: OPERATION_READ entity: "product" } permissions { operation: OPERATION_CHANGE entity: "product" layer: "identity" } permissions { operation: OPERATION_CHANGE entity: "product" layer: "texts" } permissions { operation: OPERATION_CHANGE entity: "product" layer: "media" } } roles { name: "pricer" permissions { operation: OPERATION_READ entity: "product" } permissions { operation: OPERATION_CHANGE entity: "product" layer: "pricing" } } roles { name: "price_keeper" permissions { operation: OPERATION_READ entity: "product" } permissions { operation: OPERATION_DECIDE entity: "product" layer: "pricing" } permissions { operation: OPERATION_GO_BACK entity: "product" layer: "pricing" } } roles { name: "finance" permissions { operation: OPERATION_READ entity: "product" } permissions { operation: OPERATION_READ entity: "order" } permissions { operation: OPERATION_READ entity: "order_line" } permissions { operation: OPERATION_CHANGE entity: "product" layer: "pricing" } } roles { name: "storefront" permissions { operation: OPERATION_READ entity: "product" } permissions { operation: OPERATION_CALL procedure: "checkout" } } roles { name: "warehouse" permissions { operation: OPERATION_READ entity: "product" } permissions { operation: OPERATION_READ entity: "order" } permissions { operation: OPERATION_READ entity: "order_line" } permissions { operation: OPERATION_CHANGE entity: "product" layer: "stock" } permissions { operation: OPERATION_CHANGE entity: "order" layer: "fulfilment" } } roles { name: "service" permissions { operation: OPERATION_READ entity: "order" } permissions { operation: OPERATION_READ entity: "order_line" } permissions { operation: OPERATION_CHANGE entity: "order" layer: "fulfilment" } } atoms { name: "price_guard" connection: "pricing" timeout { seconds: 5 } gate_rule { layer { entity: "product" layer: "pricing" } } } atoms { name: "checkout" connection: "shop" timeout { seconds: 15 } handler { inputs { name: "cart" type: FIELD_TYPE_TEXT required: true } outcomes: "placed" outcomes: "refused" changes { entity: "order" layer: "placed" } changes { entity: "order_line" layer: "placed" } changes { entity: "product" layer: "stock" } events: "order_placed" exposed: true } } # One handler takes what the payment provider and the carrier tell, and # states where the order stands. atoms { name: "intake" connection: "shop" timeout { seconds: 30 } handler { outcomes: "taken" outcomes: "ignored" outcomes: "refused" changes { entity: "order" layer: "fulfilment" } changes { entity: "product" layer: "stock" } } } atoms { name: "confirm" connection: "shop" timeout { seconds: 30 } handler { outcomes: "sent" outcomes: "failed" asks: "mail" } } events { name: "order_placed" entity: "order" exposed: true } triggers { name: "after_order" event { event: "order_placed" } atom: "confirm" } # The payment provider signs a timestamp with the body, which no schema # declares: its secret is in the address, and the handler checks the # signature from the header that it receives. webhooks { name: "payments" handler: "intake" proof: WEBHOOK_PROOF_ADDRESS headers: "Payment-Signature" id_header: "Payment-Event-Id" } # The carrier signs the body, and writes the signature in hex after a prefix. webhooks { name: "carrier" handler: "intake" proof: WEBHOOK_PROOF_SIGNATURE proof_header: "X-Carrier-Signature" proof_prefix: "sha256=" signature_encoding: SIGNATURE_ENCODING_HEX id_header: "X-Carrier-Delivery" }