@sonatel-os/strapi-plugin-split 0.1.0 → 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
@@ -12,7 +12,7 @@ It assumes nothing about its host. Who the people are (a header your gateway set
12
12
  | --------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
13
13
  | **People** | Search by name or phone (masked), reveal a full number (permission, logged), deactivate. | `GET /me` |
14
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 /groups/:group`, `…/archive`, `…/leave` |
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
16
  | **Members** | Seats with their state: uses the app, added by name, left. | `POST /groups/:group/members`, `DELETE /groups/:group/members/:member` |
17
17
  | **Expenses** | The most recent fifty of a group. | `GET/POST /groups/:group/expenses`, `PUT/DELETE …/expenses/:expense` |
18
18
  | **Settlements** | Look a payment up by the reference the customer has. | `GET/POST /groups/:group/settlements`, `POST …/settlements/:settlement/confirm`, `…/reject`, `…/cancel` |
@@ -75,6 +75,12 @@ x-person-name: Fatou%20Sow
75
75
  "reference": "PP261122.1135.A64593", "clientRef": "5f1c…" }
76
76
  ```
77
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
+
78
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`.
79
85
 
80
86
  ## Language
@@ -909,6 +909,7 @@ const view = ({ strapi }) => {
909
909
  return books.payments.filter((p) => p.to === me.id).map((p) => ({
910
910
  from: format2.member(books.seatById.get(p.from), viewer),
911
911
  amount: p.amount,
912
+ receivable: Math.min(p.amount, books.room(p.from, me.id)),
912
913
  pending: svc("ledger").pendingBetween(books, p.from, me.id)
913
914
  }));
914
915
  },
@@ -1180,6 +1181,8 @@ const contentApi = [
1180
1181
  route$1("POST", "/groups/join", "joinGroup"),
1181
1182
  route$1("GET", "/groups/:group", "group"),
1182
1183
  route$1("PATCH", "/groups/:group", "renameGroup"),
1184
+ // The same under PUT: some app runtimes (mini-programs) cannot send PATCH.
1185
+ route$1("PUT", "/groups/:group", "renameGroup"),
1183
1186
  route$1("POST", "/groups/:group/archive", "archiveGroup"),
1184
1187
  route$1("POST", "/groups/:group/leave", "leaveGroup"),
1185
1188
  // members
@@ -2129,7 +2132,10 @@ const settlement = ({ strapi }) => {
2129
2132
  const svc = (name) => strapi.plugin(PLUGIN_ID).service(name);
2130
2133
  const settlements = () => strapi.db.query(UID.SETTLEMENT);
2131
2134
  return {
2132
- /** What the caller sent, checked. The receiving seat is looked up in the group. */
2135
+ /**
2136
+ * What the caller sent, checked. The other seat is looked up in the group: the one paid
2137
+ * (`to`) when the caller pays, the one who paid (`from`) when the caller received.
2138
+ */
2133
2139
  async parse({ group: group2, me }, input) {
2134
2140
  const { maxAmount } = svc("settings").limits();
2135
2141
  const amount = input?.amount;
@@ -2137,14 +2143,20 @@ const settlement = ({ strapi }) => {
2137
2143
  throw badRequest(ERROR_CODES.VALIDATION, "Montant invalide.", { maxAmount });
2138
2144
  const method = svc("settings").methods()[String(input?.method)];
2139
2145
  if (!method) throw badRequest(ERROR_CODES.METHOD_UNKNOWN, "Moyen de paiement inconnu.");
2140
- const to = await svc("member").find(group2, input?.to);
2141
- if (to.id === me.id)
2146
+ const received = input?.from != null;
2147
+ if (received && input?.to != null)
2148
+ throw badRequest(ERROR_CODES.VALIDATION, "Indique qui paie ou qui reçoit, pas les deux.");
2149
+ const other = await svc("member").find(group2, received ? input.from : input?.to);
2150
+ if (other.id === me.id)
2142
2151
  throw badRequest(ERROR_CODES.VALIDATION, "Tu ne peux pas te régler à toi-même.");
2152
+ const [from, to] = received ? [other, me] : [me, other];
2143
2153
  return {
2144
2154
  amount,
2155
+ from,
2145
2156
  to,
2157
+ received,
2146
2158
  method: String(input.method),
2147
- instant: method.instant || !to.person,
2159
+ instant: received || method.instant || !to.person,
2148
2160
  reference: text(input?.reference, REF_MAX),
2149
2161
  note: text(input?.note, NOTE_MAX),
2150
2162
  clientRef: text(input?.clientRef, REF_MAX)
@@ -2167,7 +2179,7 @@ const settlement = ({ strapi }) => {
2167
2179
  async write({ group: group2, me }, data) {
2168
2180
  await svc("group").lock(group2);
2169
2181
  const books = await svc("ledger").of(group2);
2170
- const outstanding = books.room(me.id, data.to.id);
2182
+ const outstanding = books.room(data.from.id, data.to.id);
2171
2183
  if (data.amount > outstanding)
2172
2184
  throw unprocessable(
2173
2185
  ERROR_CODES.SETTLEMENT_EXCEEDS_DEBT,
@@ -2178,7 +2190,7 @@ const settlement = ({ strapi }) => {
2178
2190
  return settlements().create({
2179
2191
  data: {
2180
2192
  group: group2.id,
2181
- from: me.id,
2193
+ from: data.from.id,
2182
2194
  to: data.to.id,
2183
2195
  amount: data.amount,
2184
2196
  method: data.method,
@@ -2193,8 +2205,8 @@ const settlement = ({ strapi }) => {
2193
2205
  });
2194
2206
  },
2195
2207
  /**
2196
- * @param {{ group: Object, me: Object }} seat the payer's
2197
- * @param {Object} input `{ to, amount, method, reference?, note?, clientRef? }`
2208
+ * @param {{ group: Object, me: Object }} seat the caller's: the payer's, or the receiver's
2209
+ * @param {Object} input `{ to | from, amount, method, reference?, note?, clientRef? }`
2198
2210
  * @returns {Promise<{ settlement: Object, replayed: boolean }>}
2199
2211
  */
2200
2212
  async create(seat, input) {
@@ -2212,7 +2224,8 @@ const settlement = ({ strapi }) => {
2212
2224
  amount: data.amount,
2213
2225
  method: data.method,
2214
2226
  status: created.status,
2215
- reference: data.reference
2227
+ reference: data.reference,
2228
+ declaredBy: data.received ? "receiver" : "payer"
2216
2229
  }
2217
2230
  });
2218
2231
  return { settlement: await this.one(created.id), replayed: false };
@@ -908,6 +908,7 @@ const view = ({ strapi }) => {
908
908
  return books.payments.filter((p) => p.to === me.id).map((p) => ({
909
909
  from: format2.member(books.seatById.get(p.from), viewer),
910
910
  amount: p.amount,
911
+ receivable: Math.min(p.amount, books.room(p.from, me.id)),
911
912
  pending: svc("ledger").pendingBetween(books, p.from, me.id)
912
913
  }));
913
914
  },
@@ -1179,6 +1180,8 @@ const contentApi = [
1179
1180
  route$1("POST", "/groups/join", "joinGroup"),
1180
1181
  route$1("GET", "/groups/:group", "group"),
1181
1182
  route$1("PATCH", "/groups/:group", "renameGroup"),
1183
+ // The same under PUT: some app runtimes (mini-programs) cannot send PATCH.
1184
+ route$1("PUT", "/groups/:group", "renameGroup"),
1182
1185
  route$1("POST", "/groups/:group/archive", "archiveGroup"),
1183
1186
  route$1("POST", "/groups/:group/leave", "leaveGroup"),
1184
1187
  // members
@@ -2128,7 +2131,10 @@ const settlement = ({ strapi }) => {
2128
2131
  const svc = (name) => strapi.plugin(PLUGIN_ID).service(name);
2129
2132
  const settlements = () => strapi.db.query(UID.SETTLEMENT);
2130
2133
  return {
2131
- /** What the caller sent, checked. The receiving seat is looked up in the group. */
2134
+ /**
2135
+ * What the caller sent, checked. The other seat is looked up in the group: the one paid
2136
+ * (`to`) when the caller pays, the one who paid (`from`) when the caller received.
2137
+ */
2132
2138
  async parse({ group: group2, me }, input) {
2133
2139
  const { maxAmount } = svc("settings").limits();
2134
2140
  const amount = input?.amount;
@@ -2136,14 +2142,20 @@ const settlement = ({ strapi }) => {
2136
2142
  throw badRequest(ERROR_CODES.VALIDATION, "Montant invalide.", { maxAmount });
2137
2143
  const method = svc("settings").methods()[String(input?.method)];
2138
2144
  if (!method) throw badRequest(ERROR_CODES.METHOD_UNKNOWN, "Moyen de paiement inconnu.");
2139
- const to = await svc("member").find(group2, input?.to);
2140
- if (to.id === me.id)
2145
+ const received = input?.from != null;
2146
+ if (received && input?.to != null)
2147
+ throw badRequest(ERROR_CODES.VALIDATION, "Indique qui paie ou qui reçoit, pas les deux.");
2148
+ const other = await svc("member").find(group2, received ? input.from : input?.to);
2149
+ if (other.id === me.id)
2141
2150
  throw badRequest(ERROR_CODES.VALIDATION, "Tu ne peux pas te régler à toi-même.");
2151
+ const [from, to] = received ? [other, me] : [me, other];
2142
2152
  return {
2143
2153
  amount,
2154
+ from,
2144
2155
  to,
2156
+ received,
2145
2157
  method: String(input.method),
2146
- instant: method.instant || !to.person,
2158
+ instant: received || method.instant || !to.person,
2147
2159
  reference: text(input?.reference, REF_MAX),
2148
2160
  note: text(input?.note, NOTE_MAX),
2149
2161
  clientRef: text(input?.clientRef, REF_MAX)
@@ -2166,7 +2178,7 @@ const settlement = ({ strapi }) => {
2166
2178
  async write({ group: group2, me }, data) {
2167
2179
  await svc("group").lock(group2);
2168
2180
  const books = await svc("ledger").of(group2);
2169
- const outstanding = books.room(me.id, data.to.id);
2181
+ const outstanding = books.room(data.from.id, data.to.id);
2170
2182
  if (data.amount > outstanding)
2171
2183
  throw unprocessable(
2172
2184
  ERROR_CODES.SETTLEMENT_EXCEEDS_DEBT,
@@ -2177,7 +2189,7 @@ const settlement = ({ strapi }) => {
2177
2189
  return settlements().create({
2178
2190
  data: {
2179
2191
  group: group2.id,
2180
- from: me.id,
2192
+ from: data.from.id,
2181
2193
  to: data.to.id,
2182
2194
  amount: data.amount,
2183
2195
  method: data.method,
@@ -2192,8 +2204,8 @@ const settlement = ({ strapi }) => {
2192
2204
  });
2193
2205
  },
2194
2206
  /**
2195
- * @param {{ group: Object, me: Object }} seat the payer's
2196
- * @param {Object} input `{ to, amount, method, reference?, note?, clientRef? }`
2207
+ * @param {{ group: Object, me: Object }} seat the caller's: the payer's, or the receiver's
2208
+ * @param {Object} input `{ to | from, amount, method, reference?, note?, clientRef? }`
2197
2209
  * @returns {Promise<{ settlement: Object, replayed: boolean }>}
2198
2210
  */
2199
2211
  async create(seat, input) {
@@ -2211,7 +2223,8 @@ const settlement = ({ strapi }) => {
2211
2223
  amount: data.amount,
2212
2224
  method: data.method,
2213
2225
  status: created.status,
2214
- reference: data.reference
2226
+ reference: data.reference,
2227
+ declaredBy: data.received ? "receiver" : "payer"
2215
2228
  }
2216
2229
  });
2217
2230
  return { settlement: await this.one(created.id), replayed: false };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonatel-os/strapi-plugin-split",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "A shared-expenses ledger for Strapi v5: groups, members, expenses split three ways, balances, settlements with idempotent writes — with admin screens and RBAC.",
5
5
  "license": "MIT",
6
6
  "author": "LPIX-11 <mohamed.johnson@orange-sonatel.com>",