@fleetless/contracts 6.3.0-next.5 → 6.4.0-next.1
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/CHANGELOG.md +79 -0
- package/CONTRIBUTING.md +4 -4
- package/artifacts/openapi.json +4386 -1883
- package/artifacts/routes.json +461 -2
- package/artifacts/schema/admin-org-detail.schema.json +641 -0
- package/artifacts/schema/admin-search-query.schema.json +14 -0
- package/artifacts/schema/admin-search-response.schema.json +219 -0
- package/artifacts/schema/billing-address.schema.json +49 -0
- package/artifacts/schema/billing-cancel-request.schema.json +12 -0
- package/artifacts/schema/billing-change-request.schema.json +60 -0
- package/artifacts/schema/billing-change-response.schema.json +799 -0
- package/artifacts/schema/billing-details-update.schema.json +25 -0
- package/artifacts/schema/billing-details.schema.json +176 -0
- package/artifacts/schema/billing-invoice.schema.json +76 -0
- package/artifacts/schema/billing-view.schema.json +705 -0
- package/artifacts/schema/checkout-request.schema.json +252 -0
- package/artifacts/schema/checkout-response.schema.json +22 -0
- package/artifacts/schema/checkout-status.schema.json +49 -0
- package/artifacts/schema/noop-command-request.schema.json +75 -0
- package/artifacts/schema/noop-command-response.schema.json +134 -0
- package/artifacts/schema/operator-audit-ref.schema.json +28 -0
- package/artifacts/schema/operator-preview.schema.json +66 -0
- package/artifacts/schema/payment-method-change-request.schema.json +19 -0
- package/artifacts/schema/payment-method.schema.json +86 -0
- package/artifacts/schema/payment-provider-unavailable-details.schema.json +29 -0
- package/artifacts/schema/preview-stale-details.schema.json +80 -0
- package/artifacts/schema/vat-id-check-request.schema.json +22 -0
- package/artifacts/schema/vat-id-check-response.schema.json +36 -0
- package/dist/admin.d.ts +217 -0
- package/dist/admin.js +39 -0
- package/dist/app-users.d.ts +3 -3
- package/dist/billing.d.ts +812 -0
- package/dist/billing.js +471 -0
- package/dist/errors.d.ts +23 -11
- package/dist/errors.js +47 -0
- package/dist/index.d.ts +12 -4
- package/dist/index.js +10 -2
- package/dist/operator-commands.d.ts +137 -0
- package/dist/operator-commands.js +51 -0
- package/dist/operator.d.ts +63 -0
- package/dist/operator.js +48 -0
- package/dist/plans.d.ts +25 -25
- package/dist/realtime.d.ts +2 -2
- package/dist/rest.d.ts +3 -3
- package/dist/routes.d.ts +21 -2
- package/dist/routes.js +270 -4
- package/package.json +1 -1
package/dist/routes.js
CHANGED
|
@@ -12,12 +12,17 @@ import { jobRunListResponse, jobRunQuery, jobRunSummary, jobRunSummaryQuery } fr
|
|
|
12
12
|
import { MCP_APP_PATHS, mcpRobotDatasheet, mcpRolePreviewResponse } from './mcp.js';
|
|
13
13
|
import { authorizationServerMetadata, dynamicClientRegistrationRequest, dynamicClientRegistrationResponse, oauthAuthorizeQuery, oauthRedirectResponse, oauthTokenRequest, oauthTokenResponse, protectedResourceMetadata, } from './oauth.js';
|
|
14
14
|
import { adminPlanChangeRequest, orgPlan, planChangeRequest } from './plans.js';
|
|
15
|
+
import { OPERATOR_ROLES } from './operator.js';
|
|
16
|
+
import { noopCommandRequest, noopCommandResponse } from './operator-commands.js';
|
|
17
|
+
import { adminSearchQuery, adminSearchResponse, adminOrgDetail } from './admin.js';
|
|
18
|
+
import { billingCancelRequest, billingChangeRequest, billingChangeResponse, billingDetailsUpdate, billingView, checkoutRequest, checkoutResponse, checkoutStatus, paymentMethodChangeRequest, vatIdCheckRequest, vatIdCheckResponse, } from './billing.js';
|
|
15
19
|
import { cameraListResponse, cancelRequest, configDraftResponse, configVersionResponse, configVersionsResponse, createRobotRequest, createRobotResponse, datapointListResponse, datapointValue, exposureListResponse, fetchTypesRequest, fetchTypesResponse, historyQuery, historyResponse, introspectionResponse, invokeOrServiceResponse, invokeRequest, jobResponse, liveSessionResponse, orgHealthQuery, orgLatencyQuery, orgLatencyResponse, orgQuotaUsage, orgUsageQuery, orgUsageResponse, patchRobotRequest, patchRobotResponse, publishConfigResponse, publishRequest, putConfigDraftRequest, putRobotDetailsRequest, putRobotDetailsResponse, robotTokenRotateResponse, jointStatePutRequest, jointStatePutResponse, releaseLiveQuery, renameSlugRequest, renameSlugResponse, robotDeleteQuery, resourceHealthListResponse, robotDeletionSummary, robotDetailResponse, robotJobsResponse, robotListResponse, slugUsageResponse, snapshotMetaResponse, typesResponse, } from './rest.js';
|
|
16
20
|
export const ROUTE_SECTIONS = [
|
|
17
21
|
{ id: 'health', title: 'Health' },
|
|
18
22
|
{ id: 'developer-auth', title: 'Developer auth' },
|
|
19
23
|
{ id: 'client-auth', title: 'App-user (client) auth' },
|
|
20
24
|
{ id: 'org', title: 'Org' },
|
|
25
|
+
{ id: 'billing', title: 'Billing' },
|
|
21
26
|
{ id: 'users', title: 'Team' },
|
|
22
27
|
{ id: 'apps', title: 'Apps' },
|
|
23
28
|
{ id: 'robots', title: 'Robots' },
|
|
@@ -92,6 +97,17 @@ export const IN_HANDLER_ROUTES = [
|
|
|
92
97
|
* than an undocumented one: a consumer branches on it and the branch is dead.
|
|
93
98
|
*/
|
|
94
99
|
const DEVELOPER_GUARD = ['unauthorized', 'token_expired', 'token_revoked'];
|
|
100
|
+
/**
|
|
101
|
+
* The billing section's shorthand for the two refusals that come from
|
|
102
|
+
* billing's own infrastructure rather than from what the caller sent
|
|
103
|
+
* (2026-10-04, fleetless/fleetless#104): `BILLING_OFF` is no payment
|
|
104
|
+
* provider configured at all, `MOLLIE` is Mollie itself not
|
|
105
|
+
* answering. Every billing route that charges or opens a Mollie checkout
|
|
106
|
+
* lists both; a route that only reads or edits local state lists neither,
|
|
107
|
+
* and answers normally without a key.
|
|
108
|
+
*/
|
|
109
|
+
const BILLING_OFF = ['billing_unavailable'];
|
|
110
|
+
const MOLLIE = ['payment_provider_unavailable'];
|
|
95
111
|
/**
|
|
96
112
|
* The same, for `auth: 'developer_or_client'` — one guard resolving a developer
|
|
97
113
|
* bearer, an end-user bearer **or** a server key through a single token lookup.
|
|
@@ -2810,8 +2826,8 @@ export const ROUTES = [
|
|
|
2810
2826
|
params: [], query: null, request: planChangeRequest, response: orgPlan,
|
|
2811
2827
|
errors: [...DEVELOPER_GUARD, 'tier_required', 'validation_error', 'plan_limit', 'target_state_conflict'], transport: 'http',
|
|
2812
2828
|
notes: 'Owner tier, and **downward only**: this route moves the org to a lower plan or cancels it outright to Basic. It never moves the org ' +
|
|
2813
|
-
'up —
|
|
2814
|
-
'
|
|
2829
|
+
'up — an upgrade or an add-on goes through the billing routes instead (`POST /api/billing/checkout`, `POST /api/billing/change`). ' +
|
|
2830
|
+
'`409 target_state_conflict` names `target_plan` with rule `not_lower` when the ' +
|
|
2815
2831
|
'chosen plan is not below the org\'s current one; with rule `locked_basic_only` when the org is locked (`orgLock`) and the chosen ' +
|
|
2816
2832
|
'plan is anything but Basic; and with rule `migration_basic_only` when the org is still on the beta, awaiting the switch to priced ' +
|
|
2817
2833
|
'plans, and the chosen plan is anything but Basic — that choice is exactly what the org lands on at the switch. An owner is never ' +
|
|
@@ -2840,14 +2856,251 @@ export const ROUTES = [
|
|
|
2840
2856
|
audience: 'internal', auth: 'ops', rateLimited: true, ownerTier: false, status: 200,
|
|
2841
2857
|
params: [{ name: 'id', description: 'The org\'s uuid, whose plan, add-ons or overrides the operator is changing.' }],
|
|
2842
2858
|
query: null, request: adminPlanChangeRequest, response: orgPlan,
|
|
2843
|
-
errors: ['unauthorized', 'not_found', 'validation_error', 'plan_limit', 'rate_limited'], transport: 'http',
|
|
2859
|
+
errors: ['unauthorized', 'not_found', 'validation_error', 'plan_limit', 'rate_limited', 'target_state_conflict'], transport: 'http',
|
|
2844
2860
|
notes: 'Every public host answers `404 not_found` for every `/api/admin/*` path — this route is reachable only on the cloud\'s private ' +
|
|
2845
2861
|
'address — and that same address answers `404` here too while `OPS_API_TOKEN` is not configured, so a door with no key behind it ' +
|
|
2846
2862
|
'reads exactly like one nobody opened. An unknown `:id` is the same `404`. Applies at once, never queued as a `pending_change`, ' +
|
|
2847
2863
|
'and only when the org\'s current usage fits the result: `409 plan_limit` when a lower plan, a lowered override or a removed add-on ' +
|
|
2848
2864
|
'would leave the org over a limit — the operator never deletes an org\'s things, only the owner\'s own choice does. On success it ' +
|
|
2849
2865
|
'also withdraws any `pending_change`, ends a beta org\'s wait for the switch and lifts a lock. Audited as `org.plan_changed` with ' +
|
|
2850
|
-
'the `fleetless` actor, never a developer\'s — the row names what an operator did, not who in the org asked for it.'
|
|
2866
|
+
'the `fleetless` actor, never a developer\'s — the row names what an operator did, not who in the org asked for it. ' +
|
|
2867
|
+
'`409 target_state_conflict` names `currency` or `period_ends_at` with rule `billed` when the org has a billing account ' +
|
|
2868
|
+
'in `active` or `past_due` and the request names either field: both are fixed at the first payment and billing, not the operator, ' +
|
|
2869
|
+
'owns them from then on. The plan itself keeps working on a billed org — a plan, an add-on or an override the operator sets here is ' +
|
|
2870
|
+
'charged from the next renewal, except `enterprise` and `basic`, which the sweep cancels the billing account for instead.',
|
|
2871
|
+
},
|
|
2872
|
+
/* --- operator admin API (fleetless/fleetless#268) -----------------------
|
|
2873
|
+
*
|
|
2874
|
+
* Every route below is `audience: 'internal'`, `section: 'org'` and
|
|
2875
|
+
* reachable only on the cloud's private admin listener, behind the
|
|
2876
|
+
* operator gate: with it off, each answers exactly what an unregistered
|
|
2877
|
+
* path answers, even for a perfectly valid assertion.
|
|
2878
|
+
*/
|
|
2879
|
+
{
|
|
2880
|
+
method: 'POST', path: '/api/admin/commands/noop', section: 'org',
|
|
2881
|
+
summary: 'Runs the no-op command: proves the preview-reason-execute protocol without changing anything.',
|
|
2882
|
+
audience: 'internal', auth: 'operator', rateLimited: true, ownerTier: false, status: 200,
|
|
2883
|
+
operator: { roles: OPERATOR_ROLES, confirmation: 'click' },
|
|
2884
|
+
params: [], query: null, request: noopCommandRequest, response: noopCommandResponse,
|
|
2885
|
+
errors: ['unauthorized', 'forbidden', 'not_found', 'validation_error', 'preview_stale', 'idempotency_key_reused', 'rate_limited'],
|
|
2886
|
+
transport: 'http',
|
|
2887
|
+
notes: 'Reachable only where the cloud enables it (`OPERATOR_NOOP_COMMAND=true`; refused in production). Proves the command path end to ' +
|
|
2888
|
+
'end without a real effect: a preview always answers one `keeps` effect, and an execute writes the operator audit plus an ' +
|
|
2889
|
+
'`operator.noop` row in the named org\'s audit, and nothing else. Every public host, and the private address while the operator ' +
|
|
2890
|
+
'API is not enabled, answers `404 not_found` for this path like any other unregistered one. A role the route does not list is ' +
|
|
2891
|
+
'refused with `403 forbidden`: a command says no where a read stays silent.',
|
|
2892
|
+
},
|
|
2893
|
+
{
|
|
2894
|
+
method: 'GET', path: '/api/admin/search', section: 'org',
|
|
2895
|
+
summary: 'Finds an org, person, invoice, payment or robot by a literal, case-insensitive match.',
|
|
2896
|
+
audience: 'internal', auth: 'operator', rateLimited: true, ownerTier: false, status: 200,
|
|
2897
|
+
operator: { roles: OPERATOR_ROLES },
|
|
2898
|
+
params: [], query: adminSearchQuery, request: null, response: adminSearchResponse,
|
|
2899
|
+
errors: ['unauthorized', 'not_found', 'validation_error', 'rate_limited'], transport: 'http',
|
|
2900
|
+
notes: '`q` is matched literally — `%`, `_` and `\\` carry no wildcard meaning — never as an `ILIKE` pattern, so a two-character query ' +
|
|
2901
|
+
'never dumps a table. At most `ADMIN_SEARCH_LIMIT` hits come back; `truncated` says whether more exist. A hit kind the caller\'s ' +
|
|
2902
|
+
'role may not see is left out rather than refused: `operator-support` gets no `invoice` or `payment` hits. Every public host, and ' +
|
|
2903
|
+
'the private address while the operator API is not enabled, answers `404 not_found` for this path. A role the route does not ' +
|
|
2904
|
+
'list gets that same `404 not_found`, so a read never reveals that it exists.',
|
|
2905
|
+
},
|
|
2906
|
+
{
|
|
2907
|
+
method: 'GET', path: '/api/admin/orgs/:id', section: 'org',
|
|
2908
|
+
summary: "Reads an org's detail as the operator: its owner, plan, billing state and counts.",
|
|
2909
|
+
audience: 'internal', auth: 'operator', rateLimited: true, ownerTier: false, status: 200,
|
|
2910
|
+
operator: { roles: OPERATOR_ROLES },
|
|
2911
|
+
params: [{ name: 'id', description: "The org's uuid, whose detail the operator is reading." }],
|
|
2912
|
+
query: null, request: null, response: adminOrgDetail,
|
|
2913
|
+
errors: ['unauthorized', 'not_found', 'rate_limited'], transport: 'http',
|
|
2914
|
+
notes: '`billing` carries the account\'s state and next charge only — never the payer, address or payment method. An unknown `:id` is ' +
|
|
2915
|
+
'`404 not_found`, the same every public host and the private address answer for this path while the operator API is not ' +
|
|
2916
|
+
'enabled. A role the route does not list gets that same `404 not_found`, so a read never reveals that it exists.',
|
|
2917
|
+
},
|
|
2918
|
+
{
|
|
2919
|
+
method: 'GET', path: '/api/admin/orgs/:id/usage', section: 'org',
|
|
2920
|
+
summary: "Reads what an org consumed per day, per app and per metric, as the operator.",
|
|
2921
|
+
audience: 'internal', auth: 'operator', rateLimited: true, ownerTier: false, status: 200,
|
|
2922
|
+
operator: { roles: OPERATOR_ROLES },
|
|
2923
|
+
params: [{ name: 'id', description: "The org's uuid, whose usage the operator is reading." }],
|
|
2924
|
+
query: orgUsageQuery, request: null, response: orgUsageResponse,
|
|
2925
|
+
errors: ['unauthorized', 'not_found', 'validation_error', 'rate_limited'], transport: 'http',
|
|
2926
|
+
notes: "Identical to `GET /api/org/usage` for the named org: the same window rule, the same `from_day <= to_day` cross-field check, and " +
|
|
2927
|
+
'the same echoed window. An unknown `:id` is `404 not_found`, the same every public host and the private address answer for ' +
|
|
2928
|
+
'this path while the operator API is not enabled. A role the route does not list gets that same `404 not_found`, so a read ' +
|
|
2929
|
+
'never reveals that it exists.',
|
|
2930
|
+
},
|
|
2931
|
+
/* --- billing (2026-10-04, fleetless/fleetless#104) ----------------------
|
|
2932
|
+
*
|
|
2933
|
+
* Every route here but the webhook is owner-only (`ownerTier: true`), a
|
|
2934
|
+
* developer answers `403 tier_required` and `GET /api/billing`
|
|
2935
|
+
* is no exception — a developer reads #103's plan cards from
|
|
2936
|
+
* `GET /api/org/plan` instead, without the payer, payment method or
|
|
2937
|
+
* invoices. The routes that list `billing_unavailable` and
|
|
2938
|
+
* `payment_provider_unavailable` spread them from the `BILLING_OFF` and
|
|
2939
|
+
* `MOLLIE` constants near the top of this file.
|
|
2940
|
+
*/
|
|
2941
|
+
{
|
|
2942
|
+
method: 'GET', path: '/api/billing', section: 'billing',
|
|
2943
|
+
summary: "Reads the org's billing account, payment method and invoices.",
|
|
2944
|
+
audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: true, status: 200,
|
|
2945
|
+
params: [], query: null, request: null, response: billingView,
|
|
2946
|
+
errors: [...DEVELOPER_GUARD, 'tier_required'], transport: 'http',
|
|
2947
|
+
notes: '`available: false` when `MOLLIE_API_KEY` is not configured — this cloud takes no payments, and every billing route that ' +
|
|
2948
|
+
'charges or opens a Mollie checkout answers `503 billing_unavailable` instead of acting; cancel, resume, the details and the ' +
|
|
2949
|
+
'VAT-ID check need no Mollie and answer normally. `account` is `null` before the org has ever checked out; the plan ' +
|
|
2950
|
+
'and its limits still come from `GET /api/org/plan` (fleetless/fleetless issue 103) and are not repeated here.',
|
|
2951
|
+
},
|
|
2952
|
+
{
|
|
2953
|
+
method: 'POST', path: '/api/billing/checkout', section: 'billing',
|
|
2954
|
+
summary: 'Starts a Mollie checkout for a plan, or an upgrade paid at once.',
|
|
2955
|
+
audience: 'developer', auth: 'developer', rateLimited: true, ownerTier: true, status: 201,
|
|
2956
|
+
params: [], query: null, request: checkoutRequest, response: checkoutResponse,
|
|
2957
|
+
errors: [...DEVELOPER_GUARD, 'tier_required', 'validation_error', 'plan_limit', 'target_state_conflict', 'rate_limited', ...BILLING_OFF, ...MOLLIE],
|
|
2958
|
+
transport: 'http',
|
|
2959
|
+
notes: 'Rate limited on the `billing.checkout` bucket, same as `POST /api/billing/payment-method` and `POST /api/billing/invoices/:id/pay` ' +
|
|
2960
|
+
'— the three routes that mint a Mollie checkout. `400 validation_error` names who may not pay with these rules: ' +
|
|
2961
|
+
'`{ field: \'billing.address.country\', rule: \'eu_person\' }` for a person in another EU country, ' +
|
|
2962
|
+
'`{ field: \'billing.vat_id\', rule: \'vat_id_required\' }` for a company there with no VAT ID, ' +
|
|
2963
|
+
'`{ field: \'billing.vat_id\', rule: \'vat_id_invalid\' }` once VIES has said so, and ' +
|
|
2964
|
+
'`{ field: \'accept_withdrawal\', rule: \'required\' }` for a person who did not confirm it. `409 target_state_conflict` names ' +
|
|
2965
|
+
'`plan` with rule `already_billed` when the org already has an `active` or `past_due` billing account — checkout is for the first ' +
|
|
2966
|
+
'payment only, every later change is `POST /api/billing/change`. `checkout_url` is Mollie\'s hosted page, where the payer ' +
|
|
2967
|
+
'chooses card, PayPal or Apple Pay; the return lands on ' +
|
|
2968
|
+
'`<console>/settings/billing?checkout=<checkout_id>`, which polls `GET /api/billing/checkout/:id` until the webhook — or the poll ' +
|
|
2969
|
+
'itself — has reconciled the payment. `409 plan_limit` is the org\'s own usage against the plan being bought.',
|
|
2970
|
+
},
|
|
2971
|
+
{
|
|
2972
|
+
method: 'GET', path: '/api/billing/checkout/:id', section: 'billing',
|
|
2973
|
+
summary: "Reads a checkout's status, for the return page's poll.",
|
|
2974
|
+
audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: true, status: 200,
|
|
2975
|
+
params: [{ name: 'id', description: 'The checkout id from `checkoutResponse.checkout_id`, carried on the return URL.' }],
|
|
2976
|
+
query: null, request: null, response: checkoutStatus,
|
|
2977
|
+
errors: [...DEVELOPER_GUARD, 'tier_required', 'not_found'], transport: 'http',
|
|
2978
|
+
notes: 'Calls the same `reconcilePayment(deps, molliePaymentId)` the webhook calls, so a return page that lands before the ' +
|
|
2979
|
+
'webhook does still sees the payment applied — this route, not the webhook, is what the dev stack and the test-mode suite rely on, ' +
|
|
2980
|
+
'since Mollie refuses an unreachable webhook URL. `plan` is the org\'s plan after applying, unchanged unless `purpose` ' +
|
|
2981
|
+
'is `upgrade` and `status` is `paid`.',
|
|
2982
|
+
},
|
|
2983
|
+
{
|
|
2984
|
+
method: 'POST', path: '/api/billing/vat-id/check', section: 'billing',
|
|
2985
|
+
summary: 'Checks a VAT ID against VIES, for the checkout form and the details page.',
|
|
2986
|
+
audience: 'developer', auth: 'developer', rateLimited: true, ownerTier: true, status: 200,
|
|
2987
|
+
params: [], query: null, request: vatIdCheckRequest, response: vatIdCheckResponse,
|
|
2988
|
+
errors: [...DEVELOPER_GUARD, 'tier_required', 'validation_error', 'rate_limited'], transport: 'http',
|
|
2989
|
+
notes: 'Rate limited on its own `billing.vat_check` bucket, sized for a form checked on blur rather than for a checkout. Never refuses for ' +
|
|
2990
|
+
'an `unverified` VIES answer — the checkout itself accepts `unverified` and the hourly sweep re-checks it — this route ' +
|
|
2991
|
+
'only reports what VIES currently says, in a different place for the same ID, entered either at checkout or on `PATCH ' +
|
|
2992
|
+
'/api/billing/details`.',
|
|
2993
|
+
},
|
|
2994
|
+
{
|
|
2995
|
+
method: 'PATCH', path: '/api/billing/details', section: 'billing',
|
|
2996
|
+
summary: "Edits the billing account's invoice email or VAT ID.",
|
|
2997
|
+
audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: true, status: 200,
|
|
2998
|
+
params: [], query: null, request: billingDetailsUpdate, response: billingView,
|
|
2999
|
+
errors: [...DEVELOPER_GUARD, 'tier_required', 'validation_error', 'not_found'], transport: 'http',
|
|
3000
|
+
notes: '`404 not_found` when the org has no billing account yet — there is nothing here to edit before the first checkout. A new `vat_id` ' +
|
|
3001
|
+
'is re-checked through VIES the same way `POST /api/billing/vat-id/check` does; a valid ID entered here lifts the block a definitive ' +
|
|
3002
|
+
'`invalid` answer placed on the next renewal.',
|
|
3003
|
+
},
|
|
3004
|
+
{
|
|
3005
|
+
method: 'POST', path: '/api/billing/change', section: 'billing',
|
|
3006
|
+
summary: "Moves the org's plan, cycle or add-ons, charging increases at once.",
|
|
3007
|
+
audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: true, status: 200,
|
|
3008
|
+
params: [], query: null, request: billingChangeRequest, response: billingChangeResponse,
|
|
3009
|
+
errors: [...DEVELOPER_GUARD, 'tier_required', 'validation_error', 'plan_limit', 'target_state_conflict', ...BILLING_OFF, ...MOLLIE],
|
|
3010
|
+
transport: 'http',
|
|
3011
|
+
notes: 'The body names the **absolute** target — plan, cycle and add-ons — never a delta: the route compares it with the ' +
|
|
3012
|
+
'org\'s current state and splits the difference. The increasing part is charged now, through the same proration `changeNetCents` ' +
|
|
3013
|
+
'computes, and takes effect the moment Mollie accepts the `recurring` payment with anything but `failed`, `canceled` or `expired` ' +
|
|
3014
|
+
'— card mandates, Apple Pay\'s included, usually answer `paid` within seconds, a PayPal one may stay `pending` for a while; if it ' +
|
|
3015
|
+
'fails later, its open invoice enters dunning like a failed renewal. If Mollie refuses or does not answer, nothing is applied ' +
|
|
3016
|
+
'and this answers `502 payment_provider_unavailable` instead. The decreasing part — a lower plan, yearly → monthly, fewer add-ons — ' +
|
|
3017
|
+
'is stored as a pending change and applied at the period\'s end, same as `PUT /api/org/plan/change`; a lower plan over the target\'s ' +
|
|
3018
|
+
'limits answers `409 plan_limit` and the console opens its choose-what-stays page. Any increase first withdraws a pending ' +
|
|
3019
|
+
'downgrade or cancel, exactly as the admin route does. `409 target_state_conflict` names `billing` with rule `no_account` (no ' +
|
|
3020
|
+
'checkout yet — use `POST /api/billing/checkout`), `past_due` (an open invoice has to be paid first) or `no_valid_mandate` (the ' +
|
|
3021
|
+
'payment method needs renewing first, `POST /api/billing/payment-method`). `charged` in the response is the invoice from the part ' +
|
|
3022
|
+
'charged now, or `null` when the whole request was a decrease.',
|
|
3023
|
+
},
|
|
3024
|
+
{
|
|
3025
|
+
method: 'POST', path: '/api/billing/payment-method', section: 'billing',
|
|
3026
|
+
summary: 'Starts a Mollie checkout for a new payment method.',
|
|
3027
|
+
audience: 'developer', auth: 'developer', rateLimited: true, ownerTier: true, status: 201,
|
|
3028
|
+
params: [], query: null, request: paymentMethodChangeRequest, response: checkoutResponse,
|
|
3029
|
+
errors: [...DEVELOPER_GUARD, 'tier_required', 'validation_error', 'not_found', 'rate_limited', ...BILLING_OFF, ...MOLLIE],
|
|
3030
|
+
transport: 'http',
|
|
3031
|
+
notes: 'Rate limited on the `billing.checkout` bucket, same as `POST /api/billing/checkout`. Creates a hosted `first` payment on the ' +
|
|
3032
|
+
'existing Mollie customer, restricted to the chosen method (`card` → Mollie\'s `creditcard`, `paypal`, `applepay`). For `card` ' +
|
|
3033
|
+
'and `paypal` it is a payment of `0.00` in the org\'s currency that pays no open invoice: the invoice stays open, the next ' +
|
|
3034
|
+
'dunning retry charges the new mandate — except for an invoice that was charged back, which is never charged again ' +
|
|
3035
|
+
'automatically; pay it with `POST /api/billing/invoices/:id/pay` — and that route still pays any open invoice at once. ' +
|
|
3036
|
+
'`applepay` behaves the ' +
|
|
3037
|
+
'same where Mollie accepts a zero-amount Apple Pay payment; where it does not, a change to Apple Pay is only offered together ' +
|
|
3038
|
+
'with paying an open invoice — the payment is then that invoice\'s amount and pays it — and without one this answers ' +
|
|
3039
|
+
'`400 validation_error` with `{ field: \'method\', rule: \'applepay_needs_open_invoice\' }`. A client offers what ' +
|
|
3040
|
+
'`payment_method_options` in `GET /api/billing` lists. `404 not_found` when the org has no billing account yet. When the new ' +
|
|
3041
|
+
'mandate turns `valid` it becomes the account\'s — an Apple Pay one is a card mandate, shown as `applepay` — and every other ' +
|
|
3042
|
+
'mandate of the customer is revoked.',
|
|
3043
|
+
},
|
|
3044
|
+
{
|
|
3045
|
+
method: 'POST', path: '/api/billing/cancel', section: 'billing',
|
|
3046
|
+
summary: "Schedules the org's plan to cancel to Basic at the period's end.",
|
|
3047
|
+
audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: true, status: 200,
|
|
3048
|
+
params: [], query: null, request: billingCancelRequest, requestOptional: true, response: billingView,
|
|
3049
|
+
errors: [...DEVELOPER_GUARD, 'tier_required', 'validation_error', 'not_found', 'plan_limit'], transport: 'http',
|
|
3050
|
+
notes: 'A body is optional — `reason` alone, and nobody but Fleetless reads it. `404 not_found` when the org has no billing account to ' +
|
|
3051
|
+
'cancel. Takes effect at the period\'s end, nothing credited or refunded; over Basic\'s limits this is refused `409 ' +
|
|
3052
|
+
'plan_limit` and the console sends the owner to its choose-what-stays page instead, the same as a plan downgrade. "Cancel at ' +
|
|
3053
|
+
'period end" is not a flag here — it reads as `pending_change.target_plan === \'basic\'` on `GET /api/org/plan`.',
|
|
3054
|
+
},
|
|
3055
|
+
{
|
|
3056
|
+
method: 'POST', path: '/api/billing/resume', section: 'billing',
|
|
3057
|
+
summary: 'Withdraws a scheduled cancel, keeping the current plan.',
|
|
3058
|
+
audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: true, status: 200,
|
|
3059
|
+
params: [], query: null, request: null, response: billingView,
|
|
3060
|
+
errors: [...DEVELOPER_GUARD, 'tier_required', 'not_found'], transport: 'http',
|
|
3061
|
+
notes: '`404 not_found` when nothing is pending — there is no scheduled cancel to withdraw. The org stays on its current plan, unchanged.',
|
|
3062
|
+
},
|
|
3063
|
+
{
|
|
3064
|
+
method: 'GET', path: '/api/billing/invoices/:id/pdf', section: 'billing',
|
|
3065
|
+
summary: "Downloads one invoice's rendered PDF.",
|
|
3066
|
+
audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: true, status: 200,
|
|
3067
|
+
params: [{ name: 'id', description: 'The invoice id, from `billingInvoice.id` in `GET /api/billing`\'s `invoices`.' }],
|
|
3068
|
+
query: null, request: null, response: null, contentType: 'application/pdf',
|
|
3069
|
+
errors: [...DEVELOPER_GUARD, 'tier_required', 'not_found'], transport: 'http',
|
|
3070
|
+
notes: 'Rendered once, with `pdfkit`, when the invoice is issued, and stored as bytes — an issued invoice never changes, so this always ' +
|
|
3071
|
+
'answers the same PDF for the same id. `404 not_found` for an unknown id or one from another org.',
|
|
3072
|
+
},
|
|
3073
|
+
{
|
|
3074
|
+
method: 'POST', path: '/api/billing/invoices/:id/pay', section: 'billing',
|
|
3075
|
+
summary: 'Pays one open invoice, through a new Mollie payment.',
|
|
3076
|
+
audience: 'developer', auth: 'developer', rateLimited: true, ownerTier: true, status: 201,
|
|
3077
|
+
params: [{ name: 'id', description: 'The invoice id, from `billingInvoice.id`, of the open invoice to pay — or a due charge\'s id, from `dunning.invoice_id`.' }],
|
|
3078
|
+
query: null, request: null, response: checkoutResponse,
|
|
3079
|
+
errors: [...DEVELOPER_GUARD, 'tier_required', 'not_found', 'target_state_conflict', 'rate_limited', ...BILLING_OFF, ...MOLLIE],
|
|
3080
|
+
transport: 'http',
|
|
3081
|
+
notes: 'Rate limited on the `billing.checkout` bucket, same as `POST /api/billing/checkout`. `409 target_state_conflict` names `invoice` ' +
|
|
3082
|
+
'with rule `not_open` when the invoice is already `paid` or `uncollectible` — there is nothing left to pay. Paying the open ' +
|
|
3083
|
+
'invoice of a locked org unlocks it and keeps the plan running to the period\'s end, the same as a renewal that ' +
|
|
3084
|
+
'succeeds on a retry. `:id` may also be a due charge\'s id from `dunning.invoice_id` in `GET /api/billing`: while the payer\'s ' +
|
|
3085
|
+
'VAT ID is unsettled a held renewal is a due charge that has no number yet, and it is numbered and issued as an invoice ' +
|
|
3086
|
+
'once this payment is paid. The payment charges the amount owed (`dunning.gross_cents`). While that due charge is held by ' +
|
|
3087
|
+
'the VAT ID this answers `409 target_state_conflict` with `{ field: \'billing\', rule: \'vat_id_invalid\' }`. ' +
|
|
3088
|
+
'`404 not_found` for an unknown id or one from another org.',
|
|
3089
|
+
},
|
|
3090
|
+
{
|
|
3091
|
+
method: 'POST', path: '/api/billing/mollie/webhook', section: 'billing',
|
|
3092
|
+
summary: "Takes Mollie's payment-changed notification and reconciles the payment.",
|
|
3093
|
+
audience: 'internal', auth: 'none', rateLimited: true, ownerTier: false, status: 200,
|
|
3094
|
+
params: [], query: null, request: null, response: null,
|
|
3095
|
+
errors: ['rate_limited'], transport: 'http',
|
|
3096
|
+
notes: '**The body is never trusted**: it names only a payment id (`id=tr_…`, form-encoded, Mollie\'s own shape), and this route ' +
|
|
3097
|
+
'does nothing with it but call `reconcilePayment(deps, molliePaymentId)` — the same function `GET /api/billing/checkout/:id` and ' +
|
|
3098
|
+
'the hourly sweep call — which fetches the payment from Mollie itself and applies what Mollie says, idempotently. Rate limited on ' +
|
|
3099
|
+
'the `billing.webhook` bucket, per ip, 600/min — generous, because this is Mollie\'s own infrastructure calling, not a browser; ' +
|
|
3100
|
+
'over it the answer is `429 rate_limited`, and Mollie retries the notification later. **Every other answer is `200`**, including an id this cloud does not recognise, which is logged and otherwise ignored, **except a ' +
|
|
3101
|
+
'processing fault, which is `500`** so Mollie retries the notification rather than this cloud losing it. `auth: \'none\'` because ' +
|
|
3102
|
+
'Mollie signs nothing Fleetless checks here — the payment is only ever trusted once fetched back from Mollie\'s own API with the ' +
|
|
3103
|
+
'configured key.',
|
|
2851
3104
|
},
|
|
2852
3105
|
/* ------------------------------------------------- assets (robot upload) */
|
|
2853
3106
|
{
|
|
@@ -2883,3 +3136,16 @@ export const ROUTES = [
|
|
|
2883
3136
|
notes: 'Authentication happens in the first frame, not on the upgrade. The frame types are the `realtime` schemas.',
|
|
2884
3137
|
},
|
|
2885
3138
|
];
|
|
3139
|
+
/** Every `auth: 'operator'` route, keyed `METHOD path`, for `operatorAccess`. */
|
|
3140
|
+
const OPERATOR_ACCESS = new Map(ROUTES.filter((r) => r.auth === 'operator').map((r) => [`${r.method} ${r.path}`, r.operator]));
|
|
3141
|
+
/**
|
|
3142
|
+
* The roles (and, for a command, the confirmation level) a caller of this
|
|
3143
|
+
* operator route needs, looked up by method and path (fleetless/fleetless#268).
|
|
3144
|
+
* Throws for a route that is not `auth: 'operator'`.
|
|
3145
|
+
*/
|
|
3146
|
+
export function operatorAccess(method, path) {
|
|
3147
|
+
const access = OPERATOR_ACCESS.get(`${method} ${path}`);
|
|
3148
|
+
if (!access)
|
|
3149
|
+
throw new Error(`${method} ${path} is not an operator route`);
|
|
3150
|
+
return access;
|
|
3151
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fleetless/contracts",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0-next.1",
|
|
4
4
|
"description": "Fleetless wire contracts: the bridge-cloud protocol, the REST API schemas and the error codes, as zod schemas with generated JSON Schema and OpenAPI artifacts.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Dehne Robotik GmbH",
|