@sonatel-os/strapi-plugin-split 0.0.0-stage → 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/README.md CHANGED
@@ -1,3 +1,138 @@
1
- # Temporary Holding Version
1
+ # @sonatel-os/strapi-plugin-split
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A shared-expenses ledger for **Strapi v5**. Drop it into any Strapi install and you get the whole backend of a bill-splitting app plus the admin screens to support it: groups, members, expenses split three ways, balances, the fewest payments that settle a group, and settlements that are written once however many times they are sent.
4
+
5
+ It assumes nothing about its host. Who the people are (a header your gateway sets), what an invite code looks like, how debts get settled, how large an amount may be, which country's phone numbers are local: all of it is configuration, and the defaults name no country and no payment brand. It was first built for Dieural, a mini-program for sharing expenses.
6
+
7
+ ---
8
+
9
+ ## What you get
10
+
11
+ | Area | In the admin | For the app (`/api/split`) |
12
+ | --------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
13
+ | **People** | Search by name or phone (masked), reveal a full number (permission, logged), deactivate. | `GET /me` |
14
+ | **Home** | Dashboard: people, groups, amount spent together, amount settled, by method. | `GET /overview` (what to pay, who owes you, every group), `GET /activity` |
15
+ | **Groups** | Search by name or invite code; one group's books: seats, balances, payments, history. Archive. | `POST /groups`, `POST /groups/join`, `GET/PATCH/PUT /groups/:group`, `…/archive`, `…/leave` |
16
+ | **Members** | Seats with their state: uses the app, added by name, left. | `POST /groups/:group/members`, `DELETE /groups/:group/members/:member` |
17
+ | **Expenses** | The most recent fifty of a group. | `GET/POST /groups/:group/expenses`, `PUT/DELETE …/expenses/:expense` |
18
+ | **Settlements** | Look a payment up by the reference the customer has. | `GET/POST /groups/:group/settlements`, `POST …/settlements/:settlement/confirm`, `…/reject`, `…/cancel` |
19
+ | **Audit** | Who did what in which group, newest first. | — |
20
+
21
+ All plugin tables are prefixed `split_` and hidden from the Content Manager: a ledger is not edited by hand, and the admin screens are read-mostly on purpose.
22
+
23
+ ## The rules the ledger keeps
24
+
25
+ - **Amounts are integers** in the currency's smallest unit. Every split adds up to the amount exactly: the leftover units of a division go to the first participants (`equal`, `weighted`), and a `free` split is refused when it is off by one.
26
+ - **Written once.** `POST` an expense or a settlement with your own `clientRef`; sending it again answers the same record with `200` and `meta.replayed: true` instead of `201`. A settlement the host paid also carries the host's `reference` (a mobile-money transaction id, for instance), and the same reference is never written twice in a group. The columns are unique at the database level, so two requests at once cannot both write.
27
+ - **Never more than is owed.** A settlement is checked against the books inside the transaction that writes it, behind the group's lock: no more than the payer owes, no more than the receiver is owed, less what is already declared between them. The refusal says how much is left (`details.outstanding`).
28
+ - **Who confirms.** A method marked `instant` is one the host pays itself: confirmed at once. Otherwise the settlement is `pending` until the receiver confirms (or rejects; the payer can cancel). Pending settlements do not move balances.
29
+ - **Seats before people.** A member can be added by name and phone before they ever open the app; the seat is theirs on their first visit. A member added by name only can owe and be owed, and what they are paid needs nobody's confirmation.
30
+ - **No seat, no group.** Asking for a group you are not in answers the same `404` as a group that does not exist.
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ yarn add @sonatel-os/strapi-plugin-split
36
+ ```
37
+
38
+ ```js
39
+ // config/plugins.js — everything is optional
40
+ split: {
41
+ enabled: true,
42
+ config: {
43
+ inviteCodePrefix: 'SPL', // the SPL in SPL-A7K2QX
44
+ countryCode: '', // home calling code to drop from phone numbers, e.g. '221'
45
+ people: {
46
+ idHeader: 'x-person-id', // how the caller names the person
47
+ nameHeader: 'x-person-name', // optional display-name hint (may be percent-encoded)
48
+ autoProvision: true, // unknown ids create a person; false → 404 PERSON_NOT_FOUND
49
+ },
50
+ methods: {
51
+ mobile_money: { instant: true }, // name them as your app does: orange_money, wave, card…
52
+ cash: { instant: false },
53
+ other: { instant: false },
54
+ },
55
+ limits: { maxGroupsPerPerson: 50, maxMembersPerGroup: 50, maxAmount: 50000000 },
56
+ },
57
+ },
58
+ ```
59
+
60
+ Rebuild the admin (`yarn build`), restart, then give roles the **Split** permissions under _Settings → Roles → Plugins_.
61
+
62
+ ## Protecting the API
63
+
64
+ The plugin has no authentication of its own. Its routes under `/api/split` are ordinary Strapi **content-API** routes: create an API token (_Settings → API Tokens_), tick the Split actions it may call, and have your gateway send it as `Authorization: Bearer <token>`.
65
+
66
+ Every route also needs the person header. The plugin trusts it: whoever holds the token can act as anyone, so the token belongs in a gateway that authenticated the person, never in a client.
67
+
68
+ ```http
69
+ POST /api/split/groups/abc123/settlements
70
+ Authorization: Bearer <strapi api token>
71
+ x-person-id: 770000002
72
+ x-person-name: Fatou%20Sow
73
+
74
+ { "to": "<member id>", "amount": 30000, "method": "mobile_money",
75
+ "reference": "PP261122.1135.A64593", "clientRef": "5f1c…" }
76
+ ```
77
+
78
+ The receiver can write a payment too, with `from` instead of `to`: "this member paid me". It is confirmed at once whatever the method, since it is the receiver's own word that the money came, and it is how a debt is closed for a member who does not use the app. It is held to the same ceiling: never more than that member owes the caller.
79
+
80
+ ```json
81
+ { "from": "<member id>", "amount": 30000, "method": "cash", "clientRef": "8a2d…" }
82
+ ```
83
+
84
+ The id can be anything stable the host owns. When it is a phone number it has one spelling: digits only, and without the country code when `countryCode` is set (with `221`, `+221 77 000 00 01`, `00221770000001` and `770000001` are the same person). A seat added by phone is matched to the person on that spelling. Missing header → `400 PERSON_REQUIRED`; deactivated in the admin → `403 PERSON_INACTIVE`.
85
+
86
+ ## Language
87
+
88
+ The admin screens are in English with French labels for the menu. The messages the API sends back are in French; they are meant for logs and fallbacks, and an app shows its own wording from the `code`.
89
+
90
+ ## Error envelope
91
+
92
+ ```json
93
+ {
94
+ "error": {
95
+ "status": 422,
96
+ "code": "SETTLEMENT_EXCEEDS_DEBT",
97
+ "message": "Le montant dépasse ce qui est dû.",
98
+ "details": { "outstanding": 12000 }
99
+ }
100
+ }
101
+ ```
102
+
103
+ Clients branch on `code` (see `server/src/constants.js`), never on the French message.
104
+
105
+ ## Permissions
106
+
107
+ | Action | Lets a role… |
108
+ | ------------------------------ | --------------------------------------------- |
109
+ | `access` | see the Split menu entry |
110
+ | `dashboard.read`, `audit.read` | read the dashboard, the audit trail |
111
+ | `groups.read` / `groups.write` | read groups and their books / archive a group |
112
+ | `people.read` | look people up, phone numbers masked |
113
+ | `people.phone` | reveal a full phone number (logged) |
114
+ | `people.write` | deactivate and reactivate people |
115
+ | `settlements.read` | look settlements up |
116
+ | `settings.read` | see the configuration page |
117
+
118
+ ## Development
119
+
120
+ ```bash
121
+ yarn install
122
+ yarn test # jest: the maths, and the whole ledger on an in-memory database
123
+ yarn build # dist/ for admin + server
124
+ ```
125
+
126
+ In a host app, point at your checkout while iterating:
127
+
128
+ ```js
129
+ split: { enabled: true, resolve: '../strapi-plugin-split', config: { /* … */ } }
130
+ ```
131
+
132
+ Layout: `server/src` (content-types, services, controllers, routes, utils), `admin/src` (pages, components, RTK Query slice, translations EN/FR).
133
+
134
+ ## Not there yet
135
+
136
+ - Reads load a group's whole books to compute balances, and the home overview does it once per group. Fine for groups of friends; a running balance per seat is the next step if groups grow large.
137
+ - No push or SMS when someone is added, pays or confirms.
138
+ - No export of a group's expenses.