# proto-file: metacore/api/v1/schema.proto # proto-message: metacore.api.v1.Schema # The customers of a sales team: accounts, the people in them, deals and the # log of what was done. A message of metacore.api.v1.Schema, in the text # format of Protocol Buffers. # # account identity global what the company is # ownership territory who holds it in each territory # health global a score that another system writes live # contact main global a person of an account # consent global what the person agreed to receive # deal main global what is being sold, and to whom # terms global the amount and the discount # stage global where the deal stands # activity logged global a call, a meeting or an email: stated once # # A gate rule judges the terms of a deal: it passes a discount within the # policy, and holds a larger one for a sales manager. A deal closes through a # workflow, where a sales manager and finance both approve it, and a deal # that is won is handed over to the ERP. The mail provider tells through a # webhook when a customer answers, and the answer is logged. # # The org declares the scope territory under global before the first # deployment. entities { name: "account" key { name: "code" type: FIELD_TYPE_TEXT } layers { name: "identity" scope: "global" fields { name: "name" type: FIELD_TYPE_TEXT required: true min_length: 2 max_length: 160 exposed: true } fields { name: "vat_number" type: FIELD_TYPE_TEXT max_length: 20 } fields { name: "website" type: FIELD_TYPE_TEXT max_length: 200 } fields { name: "segment" type: FIELD_TYPE_TEXT allowed_values: "enterprise" allowed_values: "mid_market" allowed_values: "small" } # One account for each VAT number. uniques { name: "vat_number" fields: "vat_number" scope: "global" ignore_case: true } } layers { name: "ownership" scope: "territory" fields { name: "owner" type: FIELD_TYPE_TEXT } fields { name: "tier" type: FIELD_TYPE_TEXT allowed_values: "key" allowed_values: "standard" allowed_values: "dormant" } } layers { name: "health" scope: "global" overlay: true fields { name: "score" type: FIELD_TYPE_INTEGER } fields { name: "last_touch" type: FIELD_TYPE_TIME } } } entities { name: "contact" key { name: "id" type: FIELD_TYPE_TEXT } layers { name: "main" scope: "global" fields { name: "account" type: FIELD_TYPE_REFERENCE required: true reference { entity: "account" carries: "name" } } fields { name: "name" type: FIELD_TYPE_TEXT required: true } fields { name: "title" type: FIELD_TYPE_TEXT max_length: 120 } fields { name: "email" type: FIELD_TYPE_TEXT restricted { read_roles: "sales" read_roles: "sales_manager" read_roles: "marketing" write_roles: "sales" } } fields { name: "phone" type: FIELD_TYPE_TEXT restricted { read_roles: "sales" read_roles: "sales_manager" write_roles: "sales" } } uniques { name: "email" fields: "email" scope: "global" ignore_case: true } } layers { name: "consent" scope: "global" fields { name: "marketing" type: FIELD_TYPE_BOOLEAN } fields { name: "agreed_on" type: FIELD_TYPE_DATE } } } entities { name: "deal" key { name: "number" type: FIELD_TYPE_TEXT } layers { name: "main" scope: "global" fields { name: "account" type: FIELD_TYPE_REFERENCE required: true reference { entity: "account" carries: "name" } } fields { name: "title" type: FIELD_TYPE_TEXT required: true max_length: 160 } fields { name: "owner" type: FIELD_TYPE_TEXT } fields { name: "source" type: FIELD_TYPE_TEXT allowed_values: "inbound" allowed_values: "outbound" allowed_values: "partner" } } layers { name: "terms" scope: "global" fields { name: "amount" 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: "discount_percent" type: FIELD_TYPE_DECIMAL decimal_places: 2 least { decimal: "0" } greatest { decimal: "100" } } fields { name: "close_on" type: FIELD_TYPE_DATE } } layers { name: "stage" scope: "global" fields { name: "stage" type: FIELD_TYPE_TEXT allowed_values: "lead" allowed_values: "qualified" allowed_values: "proposal" allowed_values: "won" allowed_values: "lost" } fields { name: "lost_reason" type: FIELD_TYPE_TEXT max_length: 300 } } } # What was done is a document: an activity never changes once it is logged, # and a correction is an activity of its own. entities { name: "activity" key { name: "number" type: FIELD_TYPE_TEXT } layers { name: "logged" scope: "global" once: true fields { name: "kind" type: FIELD_TYPE_TEXT required: true allowed_values: "call" allowed_values: "meeting" allowed_values: "email" } fields { name: "day" type: FIELD_TYPE_DATE required: true } fields { name: "deal" type: FIELD_TYPE_REFERENCE reference { entity: "deal" } } fields { name: "contact" type: FIELD_TYPE_REFERENCE reference { entity: "contact" } } fields { name: "note" type: FIELD_TYPE_TEXT max_length: 2000 } } } roles { name: "sales" permissions { operation: OPERATION_READ entity: "account" } permissions { operation: OPERATION_READ entity: "contact" } permissions { operation: OPERATION_READ entity: "deal" } permissions { operation: OPERATION_READ entity: "activity" } permissions { operation: OPERATION_CHANGE entity: "contact" layer: "main" } permissions { operation: OPERATION_CHANGE entity: "deal" layer: "main" } permissions { operation: OPERATION_CHANGE entity: "deal" layer: "terms" } permissions { operation: OPERATION_CHANGE entity: "deal" layer: "stage" } permissions { operation: OPERATION_CHANGE entity: "activity" layer: "logged" } permissions { operation: OPERATION_START workflow: "closing" } } roles { name: "sales_manager" permissions { operation: OPERATION_READ entity: "account" } permissions { operation: OPERATION_READ entity: "contact" } permissions { operation: OPERATION_READ entity: "deal" } permissions { operation: OPERATION_READ entity: "activity" } permissions { operation: OPERATION_CHANGE entity: "account" layer: "ownership" } permissions { operation: OPERATION_DECIDE entity: "deal" layer: "terms" } permissions { operation: OPERATION_GO_BACK entity: "deal" layer: "terms" } } roles { name: "finance" permissions { operation: OPERATION_READ entity: "account" } permissions { operation: OPERATION_READ entity: "deal" } } roles { name: "marketing" permissions { operation: OPERATION_READ entity: "account" } permissions { operation: OPERATION_READ entity: "contact" } permissions { operation: OPERATION_CHANGE entity: "contact" layer: "consent" } } roles { name: "steward" permissions { operation: OPERATION_READ entity: "account" } permissions { operation: OPERATION_CHANGE entity: "account" layer: "identity" } } roles { name: "scoring" permissions { operation: OPERATION_CHANGE entity: "account" layer: "health" } } atoms { name: "discount_policy" connection: "sales_rules" timeout { seconds: 5 } gate_rule { layer { entity: "deal" layer: "terms" } } } atoms { name: "close_deal" connection: "sales_rules" timeout { seconds: 30 } handler { inputs { name: "number" type: FIELD_TYPE_TEXT required: true } outcomes: "won" outcomes: "lost" changes { entity: "deal" layer: "stage" } events: "deal_won" } } # A deal that is won goes to the ERP: the handler asks it through the engine, # with a secret that the org keeps. atoms { name: "handover" connection: "integrations" timeout { seconds: 30 } handler { outcomes: "handed_over" outcomes: "refused" asks: "erp" } } atoms { name: "log_reply" connection: "integrations" timeout { seconds: 15 } handler { outcomes: "logged" outcomes: "ignored" changes { entity: "activity" layer: "logged" } } } atoms { name: "import_accounts" connection: "integrations" timeout { seconds: 60 } source { changes { entity: "account" layer: "identity" } } } events { name: "deal_won" entity: "deal" exposed: true } triggers { name: "after_won" event { event: "deal_won" } atom: "handover" } triggers { name: "nightly_accounts" schedule { cron: "0 2 * * *" time_zone: "UTC" } atom: "import_accounts" } # A sales manager and finance approve the closing of a deal together: one of # them can decline it, and only both move it on. workflows { name: "closing" inputs { name: "number" type: FIELD_TYPE_TEXT required: true } first_stage: "approval" stages { name: "approval" person { roles { role: "sales_manager" } roles { role: "finance" } timeout { seconds: 432000 } outcomes: "approved" outcomes: "declined" agreed_outcome: "approved" second_person: true } transitions { outcome: "approved" next_stage: "close" } transitions { outcome: "declined" } } stages { name: "close" handler: "close_deal" transitions { outcome: "won" } transitions { outcome: "lost" } } } # The mail provider signs the body, and writes the signature in hex. webhooks { name: "mail" handler: "log_reply" proof: WEBHOOK_PROOF_SIGNATURE proof_header: "X-Mail-Signature" signature_encoding: SIGNATURE_ENCODING_HEX id_header: "X-Mail-Event-Id" }