1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//! The BREP PLM server.
//!
//! Parts have a permanent identity and a configurable number; revisions carry
//! the lifecycle and the CAD document; a draft is edited under an explicit
//! checkout; a released revision is immutable. The HTTP surface is in
//! [`api`], the rules are in [`db`] and [`lifecycle`], and the records are in
//! [`model`].
//!
//! # What is built
//!
//! The spine, plus the administrator's scripting layer ([`scripting`]): part
//! types number by counter, free text, pattern or script
//! ([`model::NumberMode`]); revision labels are free text; every part carries a
//! fixed [`model::DocumentClass`]; and four hooks — part number, revision
//! label, before release, after release — let an organization override the
//! defaults with JavaScript files in a directory it can keep in git.
//!
//! The catalog ([`catalog`]): a tree of categories, each adding typed
//! attributes to what it inherits from its parent; every part sits in one
//! category, carries free tags, and holds attribute values that are
//! type-checked when written and must be complete before a release.
//!
//! Sourcing ([`sourcing`]): manufacturers and suppliers, and on each part its
//! manufacturer parts with their supplier offers. Administrator settings
//! ([`model::Settings`]) decide whether a part may have several revisions in
//! work and whether a released part's catalog values lock.
//!
//! Families and templates ([`family`], [`seed`]): the family page, Generate by
//! the plm-build-spec §3.2 row rules — from the CAD app with its documents, or
//! assembled here and queued for a headless CAD worker's bake — CSV import into
//! a family's table, and template spin-out.
//!
//! Assembly structure ([`bom`]): each revision's "uses" list — the one the CAD
//! app will publish on save — and the indented and flat BOM, the diff between
//! two revisions' lists, where-used, and an administrator's release gate on
//! unreleased children, all computed from it.
//!
//! Security ([`security`], `api::credentials`, [`tls`]): CSRF tokens on browser
//! sessions, scoped API tokens for everything else, a sign-in throttle, session
//! limits, password change and sign-out everywhere, response headers, `Secure`
//! cookies, optional native TLS, and a switch for the in-browser script editor.
//!
//! The audit log ([`audit`]): every change the store commits, found by diffing
//! what the change touched before and after, attributed to the request's
//! actor, committed with the change and read through `/api/audit`.
//!
//! Storage ([`sql`], [`table`]): the metadata in one SQLite file, each change
//! one transaction with its audit events; a trigram full-text index over what
//! a person searches a part by; paged part listings; and a one-time import
//! from the JSON-file store earlier versions wrote.
//!
//! Review and approval ([`review`]): submitting a revision opens a review
//! round judged by the settings' rule or the nearest override, reviewers
//! approve or reject, a rejection sends the revision back to Draft, release
//! waits for the rule, and every revision carries a threaded discussion. One
//! process holds a data directory at a time ([`dirlock`]).
//!
//! Change orders ([`eco`]): a set of revisions to release or obsolete, with
//! its own numbering, reviewed as a whole and released as a whole — every
//! item's gates and hooks, then all of them applied in one transaction, or
//! none.
//!
//! Library import is designed but not built — where the design named a field it
//! will need ([`model::Origin`], `external_ref`), the field is here and inert.
//!
//! # The document API
//!
//! `/api/store/*` is deliberately shaped to what the CAD app's `StoreBackend`
//! requires of a remote backend: a metadata-only index (so a client never
//! hydrates the corpus), a per-key read, a write, a delete, and a monotonic
//! change sequence with a "what moved" feed. The CAD app is not touched by
//! this crate; this is the surface it will adopt.
use StatusCode;
use ;
use Json;
/// A refusal, with the status the API answers it with and the message a person
/// reads. Every refusal in this server carries a reason — a bare status code
/// tells the user nothing about what to do next.