@saasicat/spec 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +59 -0
- package/acceptance/README.md +62 -0
- package/acceptance/manifest/full-manifest-requires-super-admin.yaml +43 -0
- package/acceptance/manifest/public-boot-no-auth.yaml +40 -0
- package/acceptance/mfa/totp-verify-good-and-bad-code.yaml +57 -0
- package/acceptance/plan-version/publish-does-not-touch-bestand.yaml +62 -0
- package/acceptance/promo/first-time-only-blocks-second-redemption.yaml +40 -0
- package/acceptance/tenant/suspend-creates-audit-and-blocks-login.yaml +69 -0
- package/admin-api.openapi.yaml +1724 -0
- package/cli-conventions.md +158 -0
- package/index.cjs +18 -0
- package/index.d.cts +13 -0
- package/index.d.ts +14 -0
- package/index.js +17 -0
- package/package.json +63 -0
- package/prisma-fragments/01-subscription.prisma +216 -0
- package/prisma-fragments/02-promo-code.prisma +145 -0
- package/prisma-fragments/03-plan-versions.prisma +94 -0
- package/prisma-fragments/04-audit-log.prisma +38 -0
- package/prisma-fragments/05-bundle-business-type.prisma +206 -0
- package/prisma-fragments/06-catalog-entries.prisma +279 -0
- package/prisma-fragments/07-promotion.prisma +65 -0
- package/prisma-fragments/08-subscription-contract.prisma +92 -0
- package/prisma-fragments/09-pending-registration.prisma +96 -0
- package/prisma-fragments/README.md +115 -0
- package/schemas/admin-manifest.schema.json +328 -0
- package/schemas/audit-event.schema.json +73 -0
- package/schemas/plan-catalog.schema.json +166 -0
- package/schemas/promo-code.schema.json +214 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @saasicat/spec
|
|
2
|
+
|
|
3
|
+
Language-neutral spec of the SaaS platform — JSON Schemas, OpenAPI and
|
|
4
|
+
acceptance test scenarios.
|
|
5
|
+
|
|
6
|
+
## Contents
|
|
7
|
+
|
|
8
|
+
| File | Purpose |
|
|
9
|
+
| --------------------------------------- | ------------------------------------------------- |
|
|
10
|
+
| `schemas/admin-manifest.schema.json` | UI discovery projection of an app |
|
|
11
|
+
| `schemas/plan-catalog.schema.json` | App identity config format (`config/saas.yaml`) |
|
|
12
|
+
| `schemas/promo-code.schema.json` | Promo code format incl. redemption lifecycle |
|
|
13
|
+
| `schemas/audit-event.schema.json` | Audit log entry format |
|
|
14
|
+
| `admin-api.openapi.yaml` | NORMATIVE REST contract of the SuperAdmin backend |
|
|
15
|
+
| `acceptance/` | HTTP test scenarios (stubs; runner planned) |
|
|
16
|
+
| `index.js` / `index.cjs` / `index.d.ts` | Re-exports for JS/TS consumers |
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
In a consuming backend:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { adminManifestSchema, planCatalogSchema } from '@saasicat/spec';
|
|
24
|
+
import Ajv2020 from 'ajv/dist/2020';
|
|
25
|
+
|
|
26
|
+
const ajv = new Ajv2020({ strict: false, allErrors: true });
|
|
27
|
+
const validateManifest = ajv.compile(adminManifestSchema);
|
|
28
|
+
const validateCatalog = ajv.compile(planCatalogSchema);
|
|
29
|
+
|
|
30
|
+
if (!validateManifest(myManifest)) console.error(validateManifest.errors);
|
|
31
|
+
if (!validateCatalog(mySaasYaml)) console.error(validateCatalog.errors);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Reading acceptance test scenarios as YAML:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
// in the acceptance test runner (planned)
|
|
38
|
+
import * as fs from 'node:fs';
|
|
39
|
+
import * as path from 'node:path';
|
|
40
|
+
import { fileURLToPath } from 'node:url';
|
|
41
|
+
import { glob } from 'glob';
|
|
42
|
+
|
|
43
|
+
const specRoot = path.dirname(fileURLToPath(import.meta.resolve('@saasicat/spec/index.js')));
|
|
44
|
+
const scenarios = await glob('acceptance/**/*.yaml', { cwd: specRoot, absolute: true });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pnpm add @saasicat/spec
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Binding principles
|
|
52
|
+
|
|
53
|
+
- **Language-neutral:** no TS code, no runtime logic. Only JSON Schemas,
|
|
54
|
+
YAML OpenAPI and JSON/YAML acceptance scenarios.
|
|
55
|
+
- **No domain truth:** the schema describes the _format_, not the data.
|
|
56
|
+
App identity content lives in the consumer's `config/saas.yaml`; plans
|
|
57
|
+
live in the DB, curated via the SuperAdmin UI.
|
|
58
|
+
- **`schemaVersion` is required** in every top-level schema. Major bumps
|
|
59
|
+
break — that is allowed, but must be documented in a migration note.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Acceptance Test Scenarios
|
|
2
|
+
|
|
3
|
+
HTTP-based black-box tests that run against **every** implementation of the
|
|
4
|
+
SaaS platform (reference implementation: `@saasicat/nest`).
|
|
5
|
+
This makes the OpenAPI contract from `admin-api.openapi.yaml` not just a
|
|
6
|
+
document, but an executable set of guarantees.
|
|
7
|
+
|
|
8
|
+
## Format
|
|
9
|
+
|
|
10
|
+
Each scenario is a YAML file with the structure:
|
|
11
|
+
|
|
12
|
+
```yaml
|
|
13
|
+
scenario: 'Kurzbeschreibung des Verhaltens (1 Satz)'
|
|
14
|
+
description: |
|
|
15
|
+
Längere Beschreibung — was wird hier abgesichert, warum ist es wichtig.
|
|
16
|
+
Verweise auf SPEC-Sektion oder offene Frage.
|
|
17
|
+
|
|
18
|
+
setup: # state setup via Admin API calls
|
|
19
|
+
- createTenant: { slug: '...', email: '...' }
|
|
20
|
+
- createPromoCode: { code: '...', ... }
|
|
21
|
+
|
|
22
|
+
when: # the action under test
|
|
23
|
+
- redeemPromoCode: { code: '...', tenantSlug: '...' }
|
|
24
|
+
|
|
25
|
+
then: # expected HTTP response
|
|
26
|
+
status: 200
|
|
27
|
+
body:
|
|
28
|
+
# JSON pattern; AnyOf, contains, etc. allowed
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Test Runner
|
|
32
|
+
|
|
33
|
+
An acceptance test runner (planned) reads each scenario, boots a test
|
|
34
|
+
server, and verifies `setup` → `when` → `then` sequentially.
|
|
35
|
+
|
|
36
|
+
## Scenario Backlog
|
|
37
|
+
|
|
38
|
+
| Area | Scenario | Status |
|
|
39
|
+
| --------------- | --------------------------------------------------------------------------------------------------- | ------- |
|
|
40
|
+
| `manifest/` | Public boot is retrievable without auth and contains **only** branding | 🟡 stub |
|
|
41
|
+
| `manifest/` | Full manifest requires SUPER_ADMIN, otherwise 403 | 🟡 stub |
|
|
42
|
+
| `manifest/` | manifestHash stable across two boots | 🔴 |
|
|
43
|
+
| `manifest/` | ETag match returns 304 | 🔴 |
|
|
44
|
+
| `promo/` | First-time-customers-only rejects a second redemption | 🟡 stub |
|
|
45
|
+
| `promo/` | Allow-zero-invoice false blocks a 100% discount | 🔴 |
|
|
46
|
+
| `promo/` | Code with `valueType=PERCENT, value>100` is rejected | 🔴 |
|
|
47
|
+
| `plan-version/` | Publish does not touch `Subscription.planVersionId` of existing tenants (P1 guarantee from SPEC §6) | 🟡 stub |
|
|
48
|
+
| `plan-version/` | Regressive version requires tenant opt-in | 🔴 |
|
|
49
|
+
| `plan-version/` | 6-week notification cron sends mail to affected subscriptions | 🔴 |
|
|
50
|
+
| `tenant/` | Suspend → 403 for tenant login + audit entry with reason | 🟡 stub |
|
|
51
|
+
| `tenant/` | Suspend without MFA header → 401 MFA_REQUIRED | 🔴 |
|
|
52
|
+
| `mfa/` | TOTP verify with a good code → 200, with a bad one → 401 | 🟡 stub |
|
|
53
|
+
| `mfa/` | System rejects MFA skip via env flag in production | 🔴 |
|
|
54
|
+
|
|
55
|
+
🟡 = Stub file present, but the test runner does not process it yet
|
|
56
|
+
🔴 = Yet to be written
|
|
57
|
+
|
|
58
|
+
## Convention
|
|
59
|
+
|
|
60
|
+
- **Scenario language:** English (wire format, language-neutral).
|
|
61
|
+
- **Comments:** German is allowed, as they serve a documentation purpose.
|
|
62
|
+
- **Data:** do not use real emails / slugs — `test-*` prefixes.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
scenario: 'Full manifest endpoint requires SUPER_ADMIN role'
|
|
2
|
+
description: |
|
|
3
|
+
GET /api/v1/admin/manifest MUST:
|
|
4
|
+
- 401 without JWT
|
|
5
|
+
- 403 with JWT but role != SUPER_ADMIN
|
|
6
|
+
- 200 with SUPER_ADMIN JWT
|
|
7
|
+
The manifest is never a security source, but the endpoint itself is
|
|
8
|
+
worth protecting (it exposes capabilities, endpoints, page list).
|
|
9
|
+
Spec: SPEC §10.4.
|
|
10
|
+
|
|
11
|
+
setup:
|
|
12
|
+
- createTenant: { slug: 'test-acme', email: 'owner@test-acme.example' }
|
|
13
|
+
- createUser:
|
|
14
|
+
{ tenantSlug: 'test-acme', email: 'tenant-admin@test-acme.example', role: 'TENANT_ADMIN' }
|
|
15
|
+
- createUser: { email: 'super@platform.example', role: 'SUPER_ADMIN' }
|
|
16
|
+
|
|
17
|
+
cases:
|
|
18
|
+
- name: 'anonymous'
|
|
19
|
+
request:
|
|
20
|
+
method: GET
|
|
21
|
+
path: /api/v1/admin/manifest
|
|
22
|
+
then:
|
|
23
|
+
status: 401
|
|
24
|
+
|
|
25
|
+
- name: 'tenant-admin'
|
|
26
|
+
request:
|
|
27
|
+
method: GET
|
|
28
|
+
path: /api/v1/admin/manifest
|
|
29
|
+
auth: { as: 'tenant-admin@test-acme.example' }
|
|
30
|
+
then:
|
|
31
|
+
status: 403
|
|
32
|
+
|
|
33
|
+
- name: 'super-admin'
|
|
34
|
+
request:
|
|
35
|
+
method: GET
|
|
36
|
+
path: /api/v1/admin/manifest
|
|
37
|
+
auth: { as: 'super@platform.example' }
|
|
38
|
+
then:
|
|
39
|
+
status: 200
|
|
40
|
+
headers:
|
|
41
|
+
ETag: { matches: '^"?sha256-[A-Za-z0-9+/=_-]+"?$' }
|
|
42
|
+
Cache-Control: { contains: 'private' }
|
|
43
|
+
bodyMustValidateAgainstSchema: admin-manifest.schema.json
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
scenario: 'Public-Boot is reachable without auth and contains only branding'
|
|
2
|
+
description: |
|
|
3
|
+
Pre-login boot (/api/v1/admin/boot) MUST be reachable without a Bearer token
|
|
4
|
+
and return only branding fields. Never Capabilities, pages, or endpoints.
|
|
5
|
+
Spec: SPEC §10.4 + admin-api.openapi.yaml.
|
|
6
|
+
|
|
7
|
+
setup: []
|
|
8
|
+
|
|
9
|
+
when:
|
|
10
|
+
- request:
|
|
11
|
+
method: GET
|
|
12
|
+
path: /api/v1/admin/boot
|
|
13
|
+
# No Authorization header
|
|
14
|
+
|
|
15
|
+
then:
|
|
16
|
+
status: 200
|
|
17
|
+
bodyShape:
|
|
18
|
+
type: object
|
|
19
|
+
required: [project]
|
|
20
|
+
additionalProperties: false
|
|
21
|
+
properties:
|
|
22
|
+
project:
|
|
23
|
+
type: object
|
|
24
|
+
required: [key, displayName]
|
|
25
|
+
additionalProperties: false
|
|
26
|
+
properties:
|
|
27
|
+
key: { type: string }
|
|
28
|
+
displayName: { type: string }
|
|
29
|
+
logoUrl: { type: string }
|
|
30
|
+
environment: { type: string, enum: [production, staging, development] }
|
|
31
|
+
# Defense-in-depth check: explicitly confirm that the critical
|
|
32
|
+
# fields do NOT appear (even though additionalProperties: false
|
|
33
|
+
# implies it — the test should still fail clearly on schema drift).
|
|
34
|
+
bodyMustNotContain:
|
|
35
|
+
- capabilities
|
|
36
|
+
- navigation
|
|
37
|
+
- dashboard
|
|
38
|
+
- tenants
|
|
39
|
+
- audit
|
|
40
|
+
- planCatalogSnapshot
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
scenario: 'TOTP-Verify accepts good code, rejects bad code'
|
|
2
|
+
description: |
|
|
3
|
+
MFA mechanics. SuperAdmin has a registered TOTP secret. For
|
|
4
|
+
MFA-required endpoints the X-Mfa-Code is verified via @levminer/speakeasy
|
|
5
|
+
(Nest) or pyotp (Django). Spec: SPEC §10.5.
|
|
6
|
+
|
|
7
|
+
setup:
|
|
8
|
+
- createUser:
|
|
9
|
+
email: 'super@platform.example'
|
|
10
|
+
role: 'SUPER_ADMIN'
|
|
11
|
+
- enrollMfa:
|
|
12
|
+
email: 'super@platform.example'
|
|
13
|
+
# In the test the TOTP secret is deterministic via mock RNG; the
|
|
14
|
+
# acceptance runner knows the secret and can generate valid
|
|
15
|
+
# codes.
|
|
16
|
+
|
|
17
|
+
cases:
|
|
18
|
+
- name: 'valid TOTP code'
|
|
19
|
+
request:
|
|
20
|
+
method: POST
|
|
21
|
+
path: /api/v1/admin/tenants/test-mandant/suspend
|
|
22
|
+
auth: { as: 'super@platform.example' }
|
|
23
|
+
headers:
|
|
24
|
+
X-Mfa-Code: '{{generateTotpFor: super@platform.example}}'
|
|
25
|
+
body: { reason: 'test reason' }
|
|
26
|
+
pre:
|
|
27
|
+
- createTenant: { slug: 'test-mandant', email: 'x@test-mandant.example' }
|
|
28
|
+
then:
|
|
29
|
+
status: 200
|
|
30
|
+
|
|
31
|
+
- name: 'invalid TOTP code'
|
|
32
|
+
request:
|
|
33
|
+
method: POST
|
|
34
|
+
path: /api/v1/admin/tenants/test-mandant/suspend
|
|
35
|
+
auth: { as: 'super@platform.example' }
|
|
36
|
+
headers:
|
|
37
|
+
X-Mfa-Code: '000000'
|
|
38
|
+
body: { reason: 'test reason' }
|
|
39
|
+
pre:
|
|
40
|
+
- createTenant: { slug: 'test-mandant-2', email: 'y@test-mandant-2.example' }
|
|
41
|
+
then:
|
|
42
|
+
status: 401
|
|
43
|
+
body:
|
|
44
|
+
code: 'MFA_FAILED'
|
|
45
|
+
|
|
46
|
+
- name: 'missing TOTP header'
|
|
47
|
+
request:
|
|
48
|
+
method: POST
|
|
49
|
+
path: /api/v1/admin/tenants/test-mandant-3/suspend
|
|
50
|
+
auth: { as: 'super@platform.example' }
|
|
51
|
+
body: { reason: 'test reason' }
|
|
52
|
+
pre:
|
|
53
|
+
- createTenant: { slug: 'test-mandant-3', email: 'z@test-mandant-3.example' }
|
|
54
|
+
then:
|
|
55
|
+
status: 401
|
|
56
|
+
body:
|
|
57
|
+
code: 'MFA_REQUIRED'
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
scenario: 'Plan-Version publish does not modify existing Subscription.planVersionId'
|
|
2
|
+
description: |
|
|
3
|
+
P1 guarantee from SPEC §6: When a new plan version is published,
|
|
4
|
+
`Subscription.planVersionId` of the existing tenants is NOT touched.
|
|
5
|
+
Only publishedAt of the new version + supersededAt of the old version
|
|
6
|
+
are written. Migration runs exclusively through the
|
|
7
|
+
notification + renewal cron with a 6-week lead time.
|
|
8
|
+
|
|
9
|
+
This is the core guarantee for grandfathering protection. If this
|
|
10
|
+
test goes red, the implementation violates that contract protection.
|
|
11
|
+
|
|
12
|
+
setup:
|
|
13
|
+
- createTenant:
|
|
14
|
+
slug: 'test-bestand'
|
|
15
|
+
email: 'owner@test-bestand.example'
|
|
16
|
+
planId: 'STANDARD'
|
|
17
|
+
billingCycle: MONTHLY
|
|
18
|
+
- assertSubscriptionVersion:
|
|
19
|
+
tenantSlug: 'test-bestand'
|
|
20
|
+
version: 1 # initial version
|
|
21
|
+
- storeAs:
|
|
22
|
+
key: 'originalPlanVersionId'
|
|
23
|
+
from: 'tenant.subscription.planVersionId'
|
|
24
|
+
tenantSlug: 'test-bestand'
|
|
25
|
+
|
|
26
|
+
when:
|
|
27
|
+
# SUPER_ADMIN publishes a new version — e.g. with a price increase.
|
|
28
|
+
- createPlanVersionDraft:
|
|
29
|
+
planId: 'STANDARD'
|
|
30
|
+
changes:
|
|
31
|
+
monthlyNet: { from: 24.90, to: 29.90 }
|
|
32
|
+
changeNote: 'Q2 price increase'
|
|
33
|
+
- publishPlanVersion:
|
|
34
|
+
planId: 'STANDARD'
|
|
35
|
+
mfaCode: '{{validTotpFromAdmin}}'
|
|
36
|
+
|
|
37
|
+
then:
|
|
38
|
+
# Existing subscription remains unchanged.
|
|
39
|
+
- assertSubscription:
|
|
40
|
+
tenantSlug: 'test-bestand'
|
|
41
|
+
planVersionId: '{{originalPlanVersionId}}' # ← same value as before publish
|
|
42
|
+
# The tenant keeps paying the old price.
|
|
43
|
+
- assertSubscriptionPriceMonthlyNet:
|
|
44
|
+
tenantSlug: 'test-bestand'
|
|
45
|
+
value: 24.90
|
|
46
|
+
# pendingPlanVersion fields are not yet set (the notification cron
|
|
47
|
+
# has not run yet).
|
|
48
|
+
- assertSubscription:
|
|
49
|
+
tenantSlug: 'test-bestand'
|
|
50
|
+
pendingPlanVersionId: null
|
|
51
|
+
pendingPlanVersionEffectiveAt: null
|
|
52
|
+
|
|
53
|
+
# Catalog: the old version has supersededAt, the new one has publishedAt.
|
|
54
|
+
- assertPlanVersion:
|
|
55
|
+
planId: 'STANDARD'
|
|
56
|
+
version: 1
|
|
57
|
+
supersededAt: { isNotNull: true }
|
|
58
|
+
- assertPlanVersion:
|
|
59
|
+
planId: 'STANDARD'
|
|
60
|
+
version: 2
|
|
61
|
+
publishedAt: { isNotNull: true }
|
|
62
|
+
supersededAt: null
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
scenario: 'PromoCode with firstTimeCustomersOnly rejects second redemption from same email domain'
|
|
2
|
+
description: |
|
|
3
|
+
When a code has firstTimeCustomersOnly=true, each email domain may redeem it
|
|
4
|
+
at most once. Second redemption → 422 FIRST_TIME_ONLY.
|
|
5
|
+
|
|
6
|
+
setup:
|
|
7
|
+
- createPromoCode:
|
|
8
|
+
code: 'WELCOME25'
|
|
9
|
+
valueType: PERCENT
|
|
10
|
+
value: 25
|
|
11
|
+
durationType: ONCE
|
|
12
|
+
firstTimeCustomersOnly: true
|
|
13
|
+
- createTenant:
|
|
14
|
+
slug: 'test-a'
|
|
15
|
+
email: 'ada@example.com'
|
|
16
|
+
planId: 'STARTER' # consumer-specific; acceptance runner maps to a matching marketed plan
|
|
17
|
+
- redeemPromoCode:
|
|
18
|
+
code: 'WELCOME25'
|
|
19
|
+
tenantSlug: 'test-a'
|
|
20
|
+
|
|
21
|
+
when:
|
|
22
|
+
# Second creation with a different domain — should work.
|
|
23
|
+
# But a second one with the same domain (sub.example.com) must block,
|
|
24
|
+
# if the implementation deduplicates by email domain.
|
|
25
|
+
- createTenant:
|
|
26
|
+
slug: 'test-a-second'
|
|
27
|
+
email: 'bob@example.com'
|
|
28
|
+
planId: 'STARTER'
|
|
29
|
+
- request:
|
|
30
|
+
method: POST
|
|
31
|
+
path: /api/v1/admin/promo-codes/redeem
|
|
32
|
+
body:
|
|
33
|
+
code: 'WELCOME25'
|
|
34
|
+
tenantSlug: 'test-a-second'
|
|
35
|
+
|
|
36
|
+
then:
|
|
37
|
+
status: 422
|
|
38
|
+
body:
|
|
39
|
+
code: 'PROMO_FIRST_TIME_ONLY'
|
|
40
|
+
message: { type: string }
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
scenario: 'Tenant suspend writes audit log and blocks subsequent tenant-user login'
|
|
2
|
+
description: |
|
|
3
|
+
Standard SuperAdmin action. Required behavior:
|
|
4
|
+
- 401 without MFA header (MfaGuard)
|
|
5
|
+
- 200 with valid MFA + reason
|
|
6
|
+
- AuditLog entry with action=TENANT_SUSPEND, actorTag=web:..., reason
|
|
7
|
+
- Subsequent login of a tenant user → 403 or 401 (tenant is suspended)
|
|
8
|
+
|
|
9
|
+
Spec: SPEC §10 + admin-api.openapi.yaml /tenants/{slug}/suspend.
|
|
10
|
+
|
|
11
|
+
setup:
|
|
12
|
+
- createTenant:
|
|
13
|
+
slug: 'test-suspended'
|
|
14
|
+
email: 'owner@test-suspended.example'
|
|
15
|
+
- createUser:
|
|
16
|
+
tenantSlug: 'test-suspended'
|
|
17
|
+
email: 'user@test-suspended.example'
|
|
18
|
+
role: 'TENANT_USER'
|
|
19
|
+
password: 'test-password-123'
|
|
20
|
+
|
|
21
|
+
cases:
|
|
22
|
+
- name: 'without MFA header'
|
|
23
|
+
request:
|
|
24
|
+
method: POST
|
|
25
|
+
path: /api/v1/admin/tenants/test-suspended/suspend
|
|
26
|
+
auth: { as: 'super@platform.example' }
|
|
27
|
+
body: { reason: 'Outstanding invoices' }
|
|
28
|
+
then:
|
|
29
|
+
status: 401
|
|
30
|
+
body:
|
|
31
|
+
code: 'MFA_REQUIRED'
|
|
32
|
+
|
|
33
|
+
- name: 'with valid MFA'
|
|
34
|
+
request:
|
|
35
|
+
method: POST
|
|
36
|
+
path: /api/v1/admin/tenants/test-suspended/suspend
|
|
37
|
+
auth: { as: 'super@platform.example' }
|
|
38
|
+
headers:
|
|
39
|
+
X-Mfa-Code: '{{validTotpFromAdmin}}'
|
|
40
|
+
body: { reason: 'Outstanding invoices over 90 days' }
|
|
41
|
+
then:
|
|
42
|
+
status: 200
|
|
43
|
+
|
|
44
|
+
- name: 'tenant-user can no longer log in'
|
|
45
|
+
request:
|
|
46
|
+
method: POST
|
|
47
|
+
path: /api/auth/login
|
|
48
|
+
body:
|
|
49
|
+
email: 'user@test-suspended.example'
|
|
50
|
+
password: 'test-password-123'
|
|
51
|
+
then:
|
|
52
|
+
status: 401
|
|
53
|
+
body:
|
|
54
|
+
code: { matches: 'TENANT_(SUSPENDED|INACTIVE)' }
|
|
55
|
+
|
|
56
|
+
- name: 'audit log contains the suspension'
|
|
57
|
+
request:
|
|
58
|
+
method: GET
|
|
59
|
+
path: /api/v1/admin/audit?entity=Tenant&action=TENANT_SUSPEND
|
|
60
|
+
auth: { as: 'super@platform.example' }
|
|
61
|
+
then:
|
|
62
|
+
status: 200
|
|
63
|
+
bodyContains:
|
|
64
|
+
items:
|
|
65
|
+
- action: TENANT_SUSPEND
|
|
66
|
+
entity: Tenant
|
|
67
|
+
actorTag: { matches: "^web:super@platform\\.example:" }
|
|
68
|
+
changes:
|
|
69
|
+
reason: 'Outstanding invoices over 90 days'
|