@endora-commerce/mod-credit-limits 0.100.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 +21 -0
- package/README.md +57 -0
- package/dist/admin/index.d.ts +31 -0
- package/dist/admin/index.d.ts.map +1 -0
- package/dist/admin/index.js +32 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/pages/CreditLimitsPage.d.ts +4 -0
- package/dist/admin/pages/CreditLimitsPage.d.ts.map +1 -0
- package/dist/admin/pages/CreditLimitsPage.js +144 -0
- package/dist/admin/pages/CreditLimitsPage.js.map +1 -0
- package/dist/backend/entities/credit-limit-reservation.entity.d.ts +35 -0
- package/dist/backend/entities/credit-limit-reservation.entity.d.ts.map +1 -0
- package/dist/backend/entities/credit-limit-reservation.entity.js +99 -0
- package/dist/backend/entities/credit-limit-reservation.entity.js.map +1 -0
- package/dist/backend/entities/credit-limit-return-topup.entity.d.ts +29 -0
- package/dist/backend/entities/credit-limit-return-topup.entity.d.ts.map +1 -0
- package/dist/backend/entities/credit-limit-return-topup.entity.js +71 -0
- package/dist/backend/entities/credit-limit-return-topup.entity.js.map +1 -0
- package/dist/backend/entities/credit-limit.entity.d.ts +21 -0
- package/dist/backend/entities/credit-limit.entity.d.ts.map +1 -0
- package/dist/backend/entities/credit-limit.entity.js +66 -0
- package/dist/backend/entities/credit-limit.entity.js.map +1 -0
- package/dist/backend/index.d.ts +80 -0
- package/dist/backend/index.d.ts.map +1 -0
- package/dist/backend/index.js +112 -0
- package/dist/backend/index.js.map +1 -0
- package/dist/backend/routes.d.ts +59 -0
- package/dist/backend/routes.d.ts.map +1 -0
- package/dist/backend/routes.js +114 -0
- package/dist/backend/routes.js.map +1 -0
- package/dist/backend/services/credit-limit-read.d.ts +23 -0
- package/dist/backend/services/credit-limit-read.d.ts.map +1 -0
- package/dist/backend/services/credit-limit-read.js +35 -0
- package/dist/backend/services/credit-limit-read.js.map +1 -0
- package/dist/backend/services/credit-limit-service.d.ts +179 -0
- package/dist/backend/services/credit-limit-service.d.ts.map +1 -0
- package/dist/backend/services/credit-limit-service.js +487 -0
- package/dist/backend/services/credit-limit-service.js.map +1 -0
- package/dist/backend/services/credit-topup.d.ts +33 -0
- package/dist/backend/services/credit-topup.d.ts.map +1 -0
- package/dist/backend/services/credit-topup.js +46 -0
- package/dist/backend/services/credit-topup.js.map +1 -0
- package/dist/manifest.d.ts +169 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +138 -0
- package/dist/manifest.js.map +1 -0
- package/dist/migrations/20260425T063333_credit_limits_init.d.ts +15 -0
- package/dist/migrations/20260425T063333_credit_limits_init.d.ts.map +1 -0
- package/dist/migrations/20260425T063333_credit_limits_init.js +56 -0
- package/dist/migrations/20260425T063333_credit_limits_init.js.map +1 -0
- package/dist/migrations/20260817T201111_credit_limits_return_topups.d.ts +17 -0
- package/dist/migrations/20260817T201111_credit_limits_return_topups.d.ts.map +1 -0
- package/dist/migrations/20260817T201111_credit_limits_return_topups.js +36 -0
- package/dist/migrations/20260817T201111_credit_limits_return_topups.js.map +1 -0
- package/dist/migrations/20260818T081252_credit_limits_credit_limit_reservation_order_fk.d.ts +44 -0
- package/dist/migrations/20260818T081252_credit_limits_credit_limit_reservation_order_fk.d.ts.map +1 -0
- package/dist/migrations/20260818T081252_credit_limits_credit_limit_reservation_order_fk.js +81 -0
- package/dist/migrations/20260818T081252_credit_limits_credit_limit_reservation_order_fk.js.map +1 -0
- package/dist/migrations/20260821T140323_credit_limits_reservation_reserving_organization.d.ts +29 -0
- package/dist/migrations/20260821T140323_credit_limits_reservation_reserving_organization.d.ts.map +1 -0
- package/dist/migrations/20260821T140323_credit_limits_reservation_reserving_organization.js +45 -0
- package/dist/migrations/20260821T140323_credit_limits_reservation_reserving_organization.js.map +1 -0
- package/dist/migrations/index.d.ts +39 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +44 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/ports/index.d.ts +93 -0
- package/dist/ports/index.d.ts.map +1 -0
- package/dist/ports/index.js +2 -0
- package/dist/ports/index.js.map +1 -0
- package/docs/credit_limits.md +53 -0
- package/i18n/en.json +9 -0
- package/i18n/pl.json +9 -0
- package/package.json +92 -0
- package/tailwind.css +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Endora sp. z o.o. and the Endora Commerce contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<!-- Generated by `pnpm --filter backend run manifests:generate`. Delete this line to take the file over; a README without it is never regenerated. -->
|
|
2
|
+
|
|
3
|
+
# @endora-commerce/mod-credit-limits
|
|
4
|
+
|
|
5
|
+
Per-organization credit limits and credit-check enforcement at checkout.
|
|
6
|
+
|
|
7
|
+
## What this is
|
|
8
|
+
|
|
9
|
+
An **Endora Commerce module package**. Its module id is `credit_limits` — the identity of record in the platform's registries, in its migrations and in its setting, permission and translation codes.
|
|
10
|
+
|
|
11
|
+
A module is not imported by application code. The platform discovers the extension packages an instance has installed, reads the manifest on the root subpath and composes the module from it, so installing this package and starting the instance is the whole integration.
|
|
12
|
+
|
|
13
|
+
## Entry points
|
|
14
|
+
|
|
15
|
+
| Import | Contents |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| `@endora-commerce/mod-credit-limits` | the module manifest — its id, version, dependencies, settings and activation |
|
|
18
|
+
| `@endora-commerce/mod-credit-limits/admin` | the Admin UI contribution: the screens, navigation and palette actions it adds |
|
|
19
|
+
| `@endora-commerce/mod-credit-limits/backend` | the composition root the platform calls, with the entities, services, routes and workers it registers |
|
|
20
|
+
| `@endora-commerce/mod-credit-limits/migrations` | the module’s own schema migrations, in the order the platform runs them |
|
|
21
|
+
| `@endora-commerce/mod-credit-limits/ports` | type-only — the port interfaces other modules resolve this one through |
|
|
22
|
+
| `@endora-commerce/mod-credit-limits/tailwind.css` | the Tailwind source declaration for the admin code above |
|
|
23
|
+
|
|
24
|
+
## Depends on
|
|
25
|
+
|
|
26
|
+
Everything below is a **peer** dependency, so the application resolves exactly one copy of each — two copies of a host or of React are a runtime failure rather than a type error. An entry marked *optional* is needed only by the layers that use it.
|
|
27
|
+
|
|
28
|
+
**Endora packages**
|
|
29
|
+
|
|
30
|
+
- `@endora-commerce/admin-kit` — *optional*
|
|
31
|
+
- `@endora-commerce/contracts`
|
|
32
|
+
- `@endora-commerce/platform`
|
|
33
|
+
|
|
34
|
+
**Third-party**
|
|
35
|
+
|
|
36
|
+
- `@mikro-orm/core` ^6
|
|
37
|
+
- `@mikro-orm/migrations` ^6
|
|
38
|
+
- `@mikro-orm/postgresql` ^6
|
|
39
|
+
- `fastify` ^5
|
|
40
|
+
- `react` ^19 — *optional*
|
|
41
|
+
|
|
42
|
+
## What the tarball carries
|
|
43
|
+
|
|
44
|
+
- `dist/` — the compiled JavaScript and its type declarations
|
|
45
|
+
- `i18n/` — the translation bundles this package ships (`en`, `pl`), loaded by the platform
|
|
46
|
+
- `docs/` — the package’s own pages in the Endora Commerce documentation site
|
|
47
|
+
- `tailwind.css` — the Tailwind source declaration
|
|
48
|
+
|
|
49
|
+
## Install
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pnpm add @endora-commerce/mod-credit-limits
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Licence
|
|
56
|
+
|
|
57
|
+
MIT — the text is in `LICENSE`, beside this file.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `credit_limits`' admin surface — one route, one sidebar entry and, through
|
|
3
|
+
* the manifest, one command-palette action (feature 091, Phase 4, batch 8;
|
|
4
|
+
* `specs/091-module-owned-admin-surfaces/contracts/admin-contribution.md`).
|
|
5
|
+
*
|
|
6
|
+
* **Its one drain was `dictionaries`' currency picker**, which the screen
|
|
7
|
+
* renders to choose the currency a limit is denominated in.
|
|
8
|
+
* `backend/scripts/ledgers/cross-module-imports/credit_limits.ts` recorded it;
|
|
9
|
+
* the picker is generic, so it moved into `@endora-commerce/admin-kit` and the
|
|
10
|
+
* shard is deleted rather than edited.
|
|
11
|
+
*
|
|
12
|
+
* **The baseline counted `nav: 2` and only one of them is a sidebar row.**
|
|
13
|
+
* `adminNavEntries` reads any object literal carrying both `to` and `module`,
|
|
14
|
+
* so `AppShell.tsx`'s `PALETTE_ITEMS` was in its population beside `NAV`. The
|
|
15
|
+
* palette half is not a nav declaration and never was: it is a copy of the
|
|
16
|
+
* advertisement the server was never asked about, which went on offering the
|
|
17
|
+
* screen after an operator switched the module off. It arrives as a manifest
|
|
18
|
+
* **action** instead — `open-credit-limits`, in `manifest.ts` — which is the
|
|
19
|
+
* mechanism Principle XVI names and the one the effective enabled-set filters.
|
|
20
|
+
*
|
|
21
|
+
* **One permission code, not two.** Every `/api/v1/admin/credit-limits/*` route
|
|
22
|
+
* enforces `credit_limits:manage`; this module never split read from write, so
|
|
23
|
+
* the route requirement, the nav entry's, the palette action's and the API's
|
|
24
|
+
* are one code.
|
|
25
|
+
*
|
|
26
|
+
* **This entry exports data and nothing else** (R2); the component is a
|
|
27
|
+
* dynamic-import factory (R6).
|
|
28
|
+
*/
|
|
29
|
+
import type { AdminContributions } from '@endora-commerce/admin-kit/contributions';
|
|
30
|
+
export declare const contributions: AdminContributions;
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAQnF,eAAO,MAAM,aAAa,EAAE,kBA0B3B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** The module's only route: limits, balances and active reservations. */
|
|
2
|
+
const ROUTE_PATH = '/credit-limits';
|
|
3
|
+
/** The code every `/api/v1/admin/credit-limits/*` route enforces. */
|
|
4
|
+
const CREDIT_LIMITS_PERMISSION = 'credit_limits:manage';
|
|
5
|
+
export const contributions = {
|
|
6
|
+
routes: [
|
|
7
|
+
{
|
|
8
|
+
path: ROUTE_PATH,
|
|
9
|
+
component: () => import('./pages/CreditLimitsPage.js'),
|
|
10
|
+
requiredPermission: CREDIT_LIMITS_PERMISSION,
|
|
11
|
+
index: true,
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
nav: [
|
|
15
|
+
{
|
|
16
|
+
to: ROUTE_PATH,
|
|
17
|
+
// Module-relative (R8), out of `packages/modules/credit_limits/i18n/`.
|
|
18
|
+
labelKey: 'nav.creditLimits.label',
|
|
19
|
+
icon: 'CreditCard',
|
|
20
|
+
section: 'customers',
|
|
21
|
+
// The hand-written table put `/credit-limits` fourth of five in
|
|
22
|
+
// *Customers*, above `/comparisons`. `comparisons` converted in the
|
|
23
|
+
// plan's batch 6 and declares weight 500, so this entry's 400 keeps the
|
|
24
|
+
// two in the order an operator already had — and both still append after
|
|
25
|
+
// the section's remaining host-declared rows, which is `composeNav`'s
|
|
26
|
+
// behaviour until those convert too.
|
|
27
|
+
weight: 400,
|
|
28
|
+
requiredPermission: CREDIT_LIMITS_PERMISSION,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AA8BA,yEAAyE;AACzE,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAEpC,qEAAqE;AACrE,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAExD,MAAM,CAAC,MAAM,aAAa,GAAuB;IAC/C,MAAM,EAAE;QACN;YACE,IAAI,EAAE,UAAU;YAChB,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,6BAA6B,CAAC;YACtD,kBAAkB,EAAE,wBAAwB;YAC5C,KAAK,EAAE,IAAI;SACZ;KACF;IACD,GAAG,EAAE;QACH;YACE,EAAE,EAAE,UAAU;YACd,uEAAuE;YACvE,QAAQ,EAAE,wBAAwB;YAClC,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,WAAW;YACpB,gEAAgE;YAChE,oEAAoE;YACpE,wEAAwE;YACxE,yEAAyE;YACzE,sEAAsE;YACtE,qCAAqC;YACrC,MAAM,EAAE,GAAG;YACX,kBAAkB,EAAE,wBAAwB;SAC7C;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreditLimitsPage.d.ts","sourceRoot":"","sources":["../../../src/admin/pages/CreditLimitsPage.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAsBzF,wBAAgB,gBAAgB,IAAI,SAAS,CA2N5C;AA8KD,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import { ApiError, apiClient, formatDateTime, formatMoney } from '@endora-commerce/admin-kit/lib';
|
|
4
|
+
import { Alert, AlertDescription, Button, Card, CardContent, CardHeader, CardTitle, Checkbox, Input, Label, PageHeader, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@endora-commerce/admin-kit/ui';
|
|
5
|
+
import { CurrencyPicker, OrganizationPicker } from '@endora-commerce/admin-kit/components';
|
|
6
|
+
import { useTranslation } from '@endora-commerce/admin-kit/i18n';
|
|
7
|
+
export function CreditLimitsPage() {
|
|
8
|
+
const t = useTranslation('core');
|
|
9
|
+
const [rows, setRows] = useState([]);
|
|
10
|
+
const [loading, setLoading] = useState(true);
|
|
11
|
+
const [error, setError] = useState(null);
|
|
12
|
+
const [info, setInfo] = useState(null);
|
|
13
|
+
const [orgIdInput, setOrgIdInput] = useState('');
|
|
14
|
+
const [selectedOrgId, setSelectedOrgId] = useState(null);
|
|
15
|
+
const [selectedOrgName, setSelectedOrgName] = useState(null);
|
|
16
|
+
const [selected, setSelected] = useState(null);
|
|
17
|
+
const [selectedLoading, setSelectedLoading] = useState(false);
|
|
18
|
+
const refreshList = useCallback(async () => {
|
|
19
|
+
setLoading(true);
|
|
20
|
+
setError(null);
|
|
21
|
+
try {
|
|
22
|
+
const res = await apiClient.get('/api/v1/admin/credit-limits');
|
|
23
|
+
setRows(res.data);
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
setError(err instanceof ApiError ? err.envelope.error.message : t('creditLimits.error.load'));
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
setLoading(false);
|
|
30
|
+
}
|
|
31
|
+
}, [t]);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
void refreshList();
|
|
34
|
+
}, [refreshList]);
|
|
35
|
+
const loadSelected = useCallback(async (orgId, knownName) => {
|
|
36
|
+
setSelectedLoading(true);
|
|
37
|
+
setSelected(null);
|
|
38
|
+
setSelectedOrgId(orgId);
|
|
39
|
+
setSelectedOrgName(knownName ?? null);
|
|
40
|
+
try {
|
|
41
|
+
const res = await apiClient.get(`/api/v1/admin/organizations/${orgId}/credit-limit`);
|
|
42
|
+
setSelected(res.data);
|
|
43
|
+
setSelectedOrgName(res.data.organizationName ?? knownName ?? null);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
if (err instanceof ApiError && err.envelope.error.code === 'CREDIT_LIMIT_NOT_GRANTED') {
|
|
47
|
+
setSelected(null);
|
|
48
|
+
// No limit yet ⇒ no name from the credit-limit payload. Best-effort
|
|
49
|
+
// resolve the organization name so the grant panel shows it (falls
|
|
50
|
+
// back to the id prefix if the lookup isn't permitted).
|
|
51
|
+
if (!knownName) {
|
|
52
|
+
try {
|
|
53
|
+
const org = await apiClient.get(`/api/v1/admin/organizations/${orgId}`);
|
|
54
|
+
setSelectedOrgName(org.data.name);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
/* keep the id-prefix fallback */
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
setError(err instanceof ApiError ? err.envelope.error.message : t('creditLimits.error.lookup'));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
setSelectedLoading(false);
|
|
67
|
+
}
|
|
68
|
+
}, [t]);
|
|
69
|
+
const handleGrant = useCallback(async (input) => {
|
|
70
|
+
if (!selectedOrgId)
|
|
71
|
+
return;
|
|
72
|
+
try {
|
|
73
|
+
await apiClient.post(`/api/v1/admin/organizations/${selectedOrgId}/credit-limit`, input);
|
|
74
|
+
setInfo(t('creditLimits.success.grant', {
|
|
75
|
+
amount: input.grantedAmount,
|
|
76
|
+
currency: input.currency,
|
|
77
|
+
orgId: selectedOrgName ?? selectedOrgId.slice(0, 8),
|
|
78
|
+
}));
|
|
79
|
+
await loadSelected(selectedOrgId);
|
|
80
|
+
await refreshList();
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
setError(err instanceof ApiError ? err.envelope.error.message : t('creditLimits.error.grant'));
|
|
84
|
+
}
|
|
85
|
+
}, [selectedOrgId, selectedOrgName, loadSelected, refreshList, t]);
|
|
86
|
+
const handleAdjust = useCallback(async (input) => {
|
|
87
|
+
if (!selectedOrgId)
|
|
88
|
+
return;
|
|
89
|
+
try {
|
|
90
|
+
await apiClient.patch(`/api/v1/admin/organizations/${selectedOrgId}/credit-limit`, input);
|
|
91
|
+
setInfo(t('creditLimits.success.adjust', { orgId: selectedOrgName ?? selectedOrgId.slice(0, 8) }));
|
|
92
|
+
await loadSelected(selectedOrgId);
|
|
93
|
+
await refreshList();
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
setError(err instanceof ApiError ? err.envelope.error.message : t('creditLimits.error.adjust'));
|
|
97
|
+
}
|
|
98
|
+
}, [selectedOrgId, selectedOrgName, loadSelected, refreshList, t]);
|
|
99
|
+
return (_jsxs(_Fragment, { children: [_jsx(PageHeader, { title: t('creditLimits.page.title'), description: t('creditLimits.page.description') }), error ? (_jsx(Alert, { variant: "destructive", className: "mb-4", children: _jsx(AlertDescription, { children: error }) })) : null, info ? (_jsx(Alert, { variant: "success", className: "mb-4", children: _jsx(AlertDescription, { children: info }) })) : null, _jsx(Card, { className: "mb-4", children: _jsx(CardContent, { className: "pt-6", children: loading ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('creditLimits.loading') })) : rows.length === 0 ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('creditLimits.empty') })) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('creditLimits.column.organization') }), _jsx(TableHead, { children: t('creditLimits.column.granted') }), _jsx(TableHead, { children: t('creditLimits.column.available') }), _jsx(TableHead, { children: t('creditLimits.column.reservations') }), _jsx(TableHead, { children: t('creditLimits.column.grantedAt') }), _jsx(TableHead, {})] }) }), _jsx(TableBody, { children: rows.map((r) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: r.organizationName ? (_jsx("span", { className: "font-medium", children: r.organizationName })) : (_jsx("code", { className: "font-mono text-xs", children: r.organizationId.slice(0, 8) })) }), _jsx(TableCell, { children: formatMoney(r.grantedAmount, r.currency) }), _jsx(TableCell, { children: formatMoney(r.availableAmount, r.currency) }), _jsx(TableCell, { children: r.activeReservations.length }), _jsx(TableCell, { children: formatDateTime(r.grantedAt) }), _jsx(TableCell, { children: _jsx(Button, { variant: "outline", size: "sm", onClick: () => {
|
|
100
|
+
setOrgIdInput(r.organizationId);
|
|
101
|
+
void loadSelected(r.organizationId, r.organizationName);
|
|
102
|
+
}, children: t('creditLimits.action.open') }) })] }, r.organizationId))) })] })) }) }), _jsxs(Card, { className: "mb-4", children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: t('creditLimits.editor.title') }) }), _jsx(CardContent, { children: _jsxs("form", { className: "flex flex-wrap items-end gap-2", onSubmit: (e) => {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
void loadSelected(orgIdInput.trim());
|
|
105
|
+
}, children: [_jsxs("div", { className: "flex-1 space-y-2", children: [_jsx(Label, { children: t('creditLimits.field.orgId') }), _jsx(OrganizationPicker, { value: orgIdInput || null, onChange: (v) => setOrgIdInput(v ?? '') })] }), _jsx(Button, { type: "submit", variant: "outline", children: t('creditLimits.action.lookup') })] }) })] }), selectedOrgId && !selectedLoading ? (selected ? (_jsx(ExistingLimitPanel, { limit: selected, onAdjust: handleAdjust })) : (_jsx(GrantPanel, { orgId: selectedOrgId, orgName: selectedOrgName, onGrant: handleGrant }))) : null] }));
|
|
106
|
+
}
|
|
107
|
+
function ExistingLimitPanel({ limit, onAdjust, }) {
|
|
108
|
+
const t = useTranslation('core');
|
|
109
|
+
const [grantedAmount, setGrantedAmount] = useState(String(limit.grantedAmount));
|
|
110
|
+
const [reason, setReason] = useState('');
|
|
111
|
+
const [allowOverAllocation, setAllowOverAllocation] = useState(false);
|
|
112
|
+
return (_jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: t('creditLimits.adjust.title', {
|
|
113
|
+
orgId: limit.organizationName ?? limit.organizationId.slice(0, 8),
|
|
114
|
+
currency: limit.currency,
|
|
115
|
+
}) }) }), _jsxs(CardContent, { className: "space-y-4", children: [_jsx("p", { className: "text-sm text-muted-foreground", children: t('creditLimits.adjust.summary', {
|
|
116
|
+
granted: limit.grantedAmount.toFixed(2),
|
|
117
|
+
available: limit.availableAmount.toFixed(2),
|
|
118
|
+
reserved: (limit.grantedAmount - limit.availableAmount).toFixed(2),
|
|
119
|
+
count: limit.activeReservations.length,
|
|
120
|
+
}) }), limit.activeReservations.length > 0 ? (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('creditLimits.column.order') }), _jsx(TableHead, { children: t('creditLimits.column.reserved') }), _jsx(TableHead, { children: t('creditLimits.column.since') })] }) }), _jsx(TableBody, { children: limit.activeReservations.map((r) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: _jsx("code", { className: "font-mono text-xs", children: r.orderId.slice(0, 8) }) }), _jsx(TableCell, { children: formatMoney(r.amount, limit.currency) }), _jsx(TableCell, { children: formatDateTime(r.createdAt) })] }, r.orderId))) })] })) : null, _jsxs("form", { className: "space-y-4", onSubmit: (e) => {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
void onAdjust({
|
|
123
|
+
grantedAmount: Number(grantedAmount),
|
|
124
|
+
...(reason ? { reason } : {}),
|
|
125
|
+
allowOverAllocation,
|
|
126
|
+
});
|
|
127
|
+
}, children: [_jsxs("div", { className: "space-y-2", children: [_jsx(Label, { children: t('creditLimits.field.newGranted', { currency: limit.currency }) }), _jsx(Input, { type: "number", step: "0.01", min: "0", value: grantedAmount, onChange: (e) => setGrantedAmount(e.target.value), required: true })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { children: t('creditLimits.field.reasonAudit') }), _jsx(Input, { value: reason, onChange: (e) => setReason(e.target.value), maxLength: 2000 })] }), _jsxs("label", { className: "inline-flex items-center gap-2 text-sm", children: [_jsx(Checkbox, { checked: allowOverAllocation, onChange: (e) => setAllowOverAllocation(e.target.checked) }), t('creditLimits.field.allowOverAllocation')] }), _jsx("div", { children: _jsx(Button, { type: "submit", children: t('creditLimits.action.saveAdjust') }) })] })] })] }));
|
|
128
|
+
}
|
|
129
|
+
function GrantPanel({ orgId, orgName, onGrant, }) {
|
|
130
|
+
const t = useTranslation('core');
|
|
131
|
+
const [grantedAmount, setGrantedAmount] = useState('5000');
|
|
132
|
+
const [currency, setCurrency] = useState('PLN');
|
|
133
|
+
const [reason, setReason] = useState('');
|
|
134
|
+
return (_jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: t('creditLimits.grant.title', { orgId: orgName ?? orgId.slice(0, 8) }) }) }), _jsxs(CardContent, { children: [_jsx("p", { className: "mb-4 text-sm text-muted-foreground", children: t('creditLimits.grant.notGrantedYet') }), _jsxs("form", { className: "space-y-4", onSubmit: (e) => {
|
|
135
|
+
e.preventDefault();
|
|
136
|
+
void onGrant({
|
|
137
|
+
grantedAmount: Number(grantedAmount),
|
|
138
|
+
currency,
|
|
139
|
+
...(reason ? { reason } : {}),
|
|
140
|
+
});
|
|
141
|
+
}, children: [_jsxs("div", { className: "grid gap-4 md:grid-cols-[2fr_1fr]", children: [_jsxs("div", { className: "space-y-2", children: [_jsx(Label, { children: t('creditLimits.field.grantedAmount') }), _jsx(Input, { type: "number", step: "0.01", min: "0.01", value: grantedAmount, onChange: (e) => setGrantedAmount(e.target.value), required: true })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { children: t('creditLimits.field.currency') }), _jsx(CurrencyPicker, { value: currency, onChange: (e) => setCurrency(e.target.value), required: true })] })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { children: t('creditLimits.field.reasonOptional') }), _jsx(Input, { value: reason, onChange: (e) => setReason(e.target.value), maxLength: 2000 })] }), _jsx(Button, { type: "submit", children: t('creditLimits.action.grant') })] })] })] }));
|
|
142
|
+
}
|
|
143
|
+
export default CreditLimitsPage;
|
|
144
|
+
//# sourceMappingURL=CreditLimitsPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreditLimitsPage.js","sourceRoot":"","sources":["../../../src/admin/pages/CreditLimitsPage.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAkC,MAAM,OAAO,CAAC;AACzF,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClG,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC7N,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAkBjE,MAAM,UAAU,gBAAgB;IAC9B,MAAM,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IACjC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAoB,EAAE,CAAC,CAAC;IACx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C,CAAC,EAAQ,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAChD,SAAS,EAAE,IAAI,GACf,IACE,EACN,KAAC,MAAM,IAAC,IAAI,EAAC,QAAQ,YAAE,CAAC,CAAC,2BAA2B,CAAC,GAAU,IAC1D,IACK,IACT,CACR,CAAC;AACJ,CAAC;AACD,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { OptionalProps } from '@mikro-orm/core';
|
|
2
|
+
/**
|
|
3
|
+
* One row per Order placed against a credit-limit payment method. Active until
|
|
4
|
+
* the order is paid (releasedReason='invoice_paid') or cancelled
|
|
5
|
+
* (releasedReason='order_cancelled') — both transitions flip status to
|
|
6
|
+
* 'released' and the available amount on the parent CreditLimit grows back.
|
|
7
|
+
*/
|
|
8
|
+
export declare class CreditLimitReservation {
|
|
9
|
+
[OptionalProps]?: 'id' | 'createdAt' | 'updatedAt' | 'releasedAt' | 'releasedReason' | 'status';
|
|
10
|
+
id: string;
|
|
11
|
+
creditLimitId: string;
|
|
12
|
+
orderId: string;
|
|
13
|
+
/**
|
|
14
|
+
* The organization that drew the credit — the reserving descendant, which in
|
|
15
|
+
* `independent_default` mode is not the organization the limit row belongs
|
|
16
|
+
* to. Recorded here rather than read back off the order, so the
|
|
17
|
+
* `independent_default` sum is a query over this module's own table (feature
|
|
18
|
+
* 075).
|
|
19
|
+
*
|
|
20
|
+
* Deliberately **not** called `organizationId`, and this entity stays
|
|
21
|
+
* `@GlobalEntity`: the column is a record of who consumed the credit, not the
|
|
22
|
+
* row's tenant key. `@OrgScoped` over it would confine the sums to the
|
|
23
|
+
* ambient tenant, and the `shared_pool` sum has to see the whole subtree —
|
|
24
|
+
* including branches outside the reserving descendant's own scope.
|
|
25
|
+
*/
|
|
26
|
+
reservingOrganizationId: string;
|
|
27
|
+
amount: string;
|
|
28
|
+
currency: string;
|
|
29
|
+
status: 'active' | 'released';
|
|
30
|
+
releasedAt?: Date | null;
|
|
31
|
+
releasedReason?: 'invoice_paid' | 'order_cancelled' | 'admin_revocation' | null;
|
|
32
|
+
createdAt: Date;
|
|
33
|
+
updatedAt: Date;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=credit-limit-reservation.entity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credit-limit-reservation.entity.d.ts","sourceRoot":"","sources":["../../../src/backend/entities/credit-limit-reservation.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,aAAa,EAAwB,MAAM,iBAAiB,CAAC;AAIrF;;;;;GAKG;AACH,qBAEa,sBAAsB;IACjC,CAAC,aAAa,CAAC,CAAC,EAAE,IAAI,GAAG,WAAW,GAAG,WAAW,GAAG,YAAY,GAAG,gBAAgB,GAAG,QAAQ,CAAC;IAGhG,EAAE,EAAE,MAAM,CAAgB;IAI1B,aAAa,EAAG,MAAM,CAAC;IAIvB,OAAO,EAAG,MAAM,CAAC;IAEjB;;;;;;;;;;;;OAYG;IAGH,uBAAuB,EAAG,MAAM,CAAC;IAGjC,MAAM,EAAG,MAAM,CAAC;IAGhB,QAAQ,EAAG,MAAM,CAAC;IAIlB,MAAM,EAAE,QAAQ,GAAG,UAAU,CAAY;IAGzC,UAAU,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAGzB,cAAc,CAAC,EAAE,cAAc,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,IAAI,CAAC;IAGhF,SAAS,EAAE,IAAI,CAAc;IAG7B,SAAS,EAAE,IAAI,CAAc;CAC9B"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Entity, Index, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core';
|
|
11
|
+
import { GlobalEntity } from '@endora-commerce/platform/tenancy';
|
|
12
|
+
import { randomUUID } from 'crypto';
|
|
13
|
+
/**
|
|
14
|
+
* One row per Order placed against a credit-limit payment method. Active until
|
|
15
|
+
* the order is paid (releasedReason='invoice_paid') or cancelled
|
|
16
|
+
* (releasedReason='order_cancelled') — both transitions flip status to
|
|
17
|
+
* 'released' and the available amount on the parent CreditLimit grows back.
|
|
18
|
+
*/
|
|
19
|
+
let CreditLimitReservation = class CreditLimitReservation {
|
|
20
|
+
[OptionalProps];
|
|
21
|
+
id = randomUUID();
|
|
22
|
+
creditLimitId;
|
|
23
|
+
orderId;
|
|
24
|
+
/**
|
|
25
|
+
* The organization that drew the credit — the reserving descendant, which in
|
|
26
|
+
* `independent_default` mode is not the organization the limit row belongs
|
|
27
|
+
* to. Recorded here rather than read back off the order, so the
|
|
28
|
+
* `independent_default` sum is a query over this module's own table (feature
|
|
29
|
+
* 075).
|
|
30
|
+
*
|
|
31
|
+
* Deliberately **not** called `organizationId`, and this entity stays
|
|
32
|
+
* `@GlobalEntity`: the column is a record of who consumed the credit, not the
|
|
33
|
+
* row's tenant key. `@OrgScoped` over it would confine the sums to the
|
|
34
|
+
* ambient tenant, and the `shared_pool` sum has to see the whole subtree —
|
|
35
|
+
* including branches outside the reserving descendant's own scope.
|
|
36
|
+
*/
|
|
37
|
+
reservingOrganizationId;
|
|
38
|
+
amount;
|
|
39
|
+
currency;
|
|
40
|
+
status = 'active';
|
|
41
|
+
releasedAt;
|
|
42
|
+
releasedReason;
|
|
43
|
+
createdAt = new Date();
|
|
44
|
+
updatedAt = new Date();
|
|
45
|
+
};
|
|
46
|
+
__decorate([
|
|
47
|
+
PrimaryKey({ type: 'uuid' }),
|
|
48
|
+
__metadata("design:type", String)
|
|
49
|
+
], CreditLimitReservation.prototype, "id", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
Property({ type: 'uuid' }),
|
|
52
|
+
Index(),
|
|
53
|
+
__metadata("design:type", String)
|
|
54
|
+
], CreditLimitReservation.prototype, "creditLimitId", void 0);
|
|
55
|
+
__decorate([
|
|
56
|
+
Property({ type: 'uuid' }),
|
|
57
|
+
Index(),
|
|
58
|
+
__metadata("design:type", String)
|
|
59
|
+
], CreditLimitReservation.prototype, "orderId", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
Property({ type: 'uuid' }),
|
|
62
|
+
Index(),
|
|
63
|
+
__metadata("design:type", String)
|
|
64
|
+
], CreditLimitReservation.prototype, "reservingOrganizationId", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
Property({ type: 'decimal', precision: 14, scale: 2 }),
|
|
67
|
+
__metadata("design:type", String)
|
|
68
|
+
], CreditLimitReservation.prototype, "amount", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
Property({ type: 'string', length: 3 }),
|
|
71
|
+
__metadata("design:type", String)
|
|
72
|
+
], CreditLimitReservation.prototype, "currency", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
Property({ type: 'string', length: 16 }),
|
|
75
|
+
Index(),
|
|
76
|
+
__metadata("design:type", String)
|
|
77
|
+
], CreditLimitReservation.prototype, "status", void 0);
|
|
78
|
+
__decorate([
|
|
79
|
+
Property({ type: 'datetime', nullable: true }),
|
|
80
|
+
__metadata("design:type", Object)
|
|
81
|
+
], CreditLimitReservation.prototype, "releasedAt", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
Property({ type: 'string', length: 32, nullable: true }),
|
|
84
|
+
__metadata("design:type", Object)
|
|
85
|
+
], CreditLimitReservation.prototype, "releasedReason", void 0);
|
|
86
|
+
__decorate([
|
|
87
|
+
Property({ type: 'datetime', onCreate: () => new Date() }),
|
|
88
|
+
__metadata("design:type", Date)
|
|
89
|
+
], CreditLimitReservation.prototype, "createdAt", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
Property({ type: 'datetime', onUpdate: () => new Date() }),
|
|
92
|
+
__metadata("design:type", Date)
|
|
93
|
+
], CreditLimitReservation.prototype, "updatedAt", void 0);
|
|
94
|
+
CreditLimitReservation = __decorate([
|
|
95
|
+
GlobalEntity(),
|
|
96
|
+
Entity({ tableName: 'credit_limit_reservations' })
|
|
97
|
+
], CreditLimitReservation);
|
|
98
|
+
export { CreditLimitReservation };
|
|
99
|
+
//# sourceMappingURL=credit-limit-reservation.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credit-limit-reservation.entity.js","sourceRoot":"","sources":["../../../src/backend/entities/credit-limit-reservation.entity.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC;;;;;GAKG;AAGI,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,CAAC,aAAa,CAAC,CAAiF;IAGhG,EAAE,GAAW,UAAU,EAAE,CAAC;IAI1B,aAAa,CAAU;IAIvB,OAAO,CAAU;IAEjB;;;;;;;;;;;;OAYG;IAGH,uBAAuB,CAAU;IAGjC,MAAM,CAAU;IAGhB,QAAQ,CAAU;IAIlB,MAAM,GAA0B,QAAQ,CAAC;IAGzC,UAAU,CAAe;IAGzB,cAAc,CAAkE;IAGhF,SAAS,GAAS,IAAI,IAAI,EAA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sB;IAFlC,YAAY,EAAE;IACd,MAAM,CAAC,EAAE,SAAS,EAAE,2BAA2B,EAAE,CAAC;GACtC,sBAAsB,CAoDlC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { OptionalProps } from '@mikro-orm/core';
|
|
2
|
+
/**
|
|
3
|
+
* One row per return case whose settlement has credited this organization
|
|
4
|
+
* (D-91).
|
|
5
|
+
*
|
|
6
|
+
* The settlement ordering law attempts every external effect before it writes
|
|
7
|
+
* any state, so a refusal from a later step leaves a retryable case — and the
|
|
8
|
+
* retry calls `creditFromReturn` again with the same `returnCaseId`. Without
|
|
9
|
+
* this row the second call reads the grant and adds to it a second time, which
|
|
10
|
+
* is money. `returnCaseId` is unique, and the credit and the row are written in
|
|
11
|
+
* one Command, so either the organization is credited and the fact is recorded
|
|
12
|
+
* or neither happened.
|
|
13
|
+
*
|
|
14
|
+
* `returnCaseId` carries **no** foreign key on purpose: it is a key this module
|
|
15
|
+
* is handed, not a row it may read. `returns` depends on `credit_limits`, and a
|
|
16
|
+
* constraint the other way would invert that and put `returns` in this module's
|
|
17
|
+
* manifest `dependencies`.
|
|
18
|
+
*/
|
|
19
|
+
export declare class CreditLimitReturnTopup {
|
|
20
|
+
[OptionalProps]?: 'id' | 'appliedAt';
|
|
21
|
+
id: string;
|
|
22
|
+
/** The settling return case. Opaque here — see the class comment. */
|
|
23
|
+
returnCaseId: string;
|
|
24
|
+
organizationId: string;
|
|
25
|
+
amount: string;
|
|
26
|
+
currency: string;
|
|
27
|
+
appliedAt: Date;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=credit-limit-return-topup.entity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credit-limit-return-topup.entity.d.ts","sourceRoot":"","sources":["../../../src/backend/entities/credit-limit-return-topup.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,aAAa,EAAgC,MAAM,iBAAiB,CAAC;AAI7F;;;;;;;;;;;;;;;;GAgBG;AACH,qBAEa,sBAAsB;IACjC,CAAC,aAAa,CAAC,CAAC,EAAE,IAAI,GAAG,WAAW,CAAC;IAGrC,EAAE,EAAE,MAAM,CAAgB;IAE1B,qEAAqE;IAGrE,YAAY,EAAG,MAAM,CAAC;IAItB,cAAc,EAAG,MAAM,CAAC;IAGxB,MAAM,EAAG,MAAM,CAAC;IAGhB,QAAQ,EAAG,MAAM,CAAC;IAGlB,SAAS,EAAE,IAAI,CAAc;CAC9B"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Entity, Index, OptionalProps, PrimaryKey, Property, Unique } from '@mikro-orm/core';
|
|
11
|
+
import { randomUUID } from 'crypto';
|
|
12
|
+
import { OrgScoped } from '@endora-commerce/platform/tenancy';
|
|
13
|
+
/**
|
|
14
|
+
* One row per return case whose settlement has credited this organization
|
|
15
|
+
* (D-91).
|
|
16
|
+
*
|
|
17
|
+
* The settlement ordering law attempts every external effect before it writes
|
|
18
|
+
* any state, so a refusal from a later step leaves a retryable case — and the
|
|
19
|
+
* retry calls `creditFromReturn` again with the same `returnCaseId`. Without
|
|
20
|
+
* this row the second call reads the grant and adds to it a second time, which
|
|
21
|
+
* is money. `returnCaseId` is unique, and the credit and the row are written in
|
|
22
|
+
* one Command, so either the organization is credited and the fact is recorded
|
|
23
|
+
* or neither happened.
|
|
24
|
+
*
|
|
25
|
+
* `returnCaseId` carries **no** foreign key on purpose: it is a key this module
|
|
26
|
+
* is handed, not a row it may read. `returns` depends on `credit_limits`, and a
|
|
27
|
+
* constraint the other way would invert that and put `returns` in this module's
|
|
28
|
+
* manifest `dependencies`.
|
|
29
|
+
*/
|
|
30
|
+
let CreditLimitReturnTopup = class CreditLimitReturnTopup {
|
|
31
|
+
[OptionalProps];
|
|
32
|
+
id = randomUUID();
|
|
33
|
+
/** The settling return case. Opaque here — see the class comment. */
|
|
34
|
+
returnCaseId;
|
|
35
|
+
organizationId;
|
|
36
|
+
amount;
|
|
37
|
+
currency;
|
|
38
|
+
appliedAt = new Date();
|
|
39
|
+
};
|
|
40
|
+
__decorate([
|
|
41
|
+
PrimaryKey({ type: 'uuid' }),
|
|
42
|
+
__metadata("design:type", String)
|
|
43
|
+
], CreditLimitReturnTopup.prototype, "id", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
Property({ type: 'uuid' }),
|
|
46
|
+
Unique(),
|
|
47
|
+
__metadata("design:type", String)
|
|
48
|
+
], CreditLimitReturnTopup.prototype, "returnCaseId", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
Property({ type: 'uuid' }),
|
|
51
|
+
Index(),
|
|
52
|
+
__metadata("design:type", String)
|
|
53
|
+
], CreditLimitReturnTopup.prototype, "organizationId", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
Property({ type: 'decimal', precision: 14, scale: 2 }),
|
|
56
|
+
__metadata("design:type", String)
|
|
57
|
+
], CreditLimitReturnTopup.prototype, "amount", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
Property({ type: 'string', length: 3 }),
|
|
60
|
+
__metadata("design:type", String)
|
|
61
|
+
], CreditLimitReturnTopup.prototype, "currency", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
Property({ type: 'datetime', onCreate: () => new Date() }),
|
|
64
|
+
__metadata("design:type", Date)
|
|
65
|
+
], CreditLimitReturnTopup.prototype, "appliedAt", void 0);
|
|
66
|
+
CreditLimitReturnTopup = __decorate([
|
|
67
|
+
OrgScoped(),
|
|
68
|
+
Entity({ tableName: 'credit_limit_return_topups' })
|
|
69
|
+
], CreditLimitReturnTopup);
|
|
70
|
+
export { CreditLimitReturnTopup };
|
|
71
|
+
//# sourceMappingURL=credit-limit-return-topup.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credit-limit-return-topup.entity.js","sourceRoot":"","sources":["../../../src/backend/entities/credit-limit-return-topup.entity.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAE9D;;;;;;;;;;;;;;;;GAgBG;AAGI,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,CAAC,aAAa,CAAC,CAAsB;IAGrC,EAAE,GAAW,UAAU,EAAE,CAAC;IAE1B,qEAAqE;IAGrE,YAAY,CAAU;IAItB,cAAc,CAAU;IAGxB,MAAM,CAAU;IAGhB,QAAQ,CAAU;IAGlB,SAAS,GAAS,IAAI,IAAI,EAAE,CAAC;CAC9B,CAAA;AAnBC;IADC,UAAU,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;kDACH;AAK1B;IAFC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC1B,MAAM,EAAE;;4DACa;AAItB;IAFC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC1B,KAAK,EAAE;;8DACgB;AAGxB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;;sDACvC;AAGhB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;;wDACtB;AAGlB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;8BAChD,IAAI;yDAAc;AAtBlB,sBAAsB;IAFlC,SAAS,EAAE;IACX,MAAM,CAAC,EAAE,SAAS,EAAE,4BAA4B,EAAE,CAAC;GACvC,sBAAsB,CAuBlC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { OptionalProps } from '@mikro-orm/core';
|
|
2
|
+
/**
|
|
3
|
+
* Per-Organization credit limit grant. One row per organization (enforced by
|
|
4
|
+
* the migration's unique index). `grantedAmount = 0` is the soft-revoke shape;
|
|
5
|
+
* the row is preserved for audit history.
|
|
6
|
+
*
|
|
7
|
+
* `@OrgScoped` (feature 050): reads are auto-confined to the ambient tenant. The
|
|
8
|
+
* grant/adjust routes additionally gate on org membership because inserts are not
|
|
9
|
+
* reachable by the column filter.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CreditLimit {
|
|
12
|
+
[OptionalProps]?: 'id' | 'createdAt' | 'updatedAt' | 'grantedByAdminUserId';
|
|
13
|
+
id: string;
|
|
14
|
+
organizationId: string;
|
|
15
|
+
grantedAmount: string;
|
|
16
|
+
currency: string;
|
|
17
|
+
grantedByAdminUserId?: string | null;
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
updatedAt: Date;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=credit-limit.entity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credit-limit.entity.d.ts","sourceRoot":"","sources":["../../../src/backend/entities/credit-limit.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,aAAa,EAAwB,MAAM,iBAAiB,CAAC;AAIrF;;;;;;;;GAQG;AACH,qBAEa,WAAW;IACtB,CAAC,aAAa,CAAC,CAAC,EAAE,IAAI,GAAG,WAAW,GAAG,WAAW,GAAG,sBAAsB,CAAC;IAG5E,EAAE,EAAE,MAAM,CAAgB;IAI1B,cAAc,EAAG,MAAM,CAAC;IAGxB,aAAa,EAAG,MAAM,CAAC;IAGvB,QAAQ,EAAG,MAAM,CAAC;IAGlB,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAGrC,SAAS,EAAE,IAAI,CAAc;IAG7B,SAAS,EAAE,IAAI,CAAc;CAC9B"}
|