@sneat/extension-splitus 0.1.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 ADDED
@@ -0,0 +1,5 @@
1
+ # Splitus runtime
2
+
3
+ Private runtime providers for Splitus. It implements the public
4
+ `@sneat/extension-splitus-contract` service contract and is wired only by the
5
+ Splitus application composition root.
@@ -0,0 +1,103 @@
1
+ import { HttpParams } from '@angular/common/http';
2
+ import * as i0 from '@angular/core';
3
+ import { inject, Injectable } from '@angular/core';
4
+ import { SneatApiService } from '@sneat/api';
5
+ import { map } from 'rxjs';
6
+ import { SPLITUS_SERVICE } from '@sneat/extension-splitus-contract';
7
+
8
+ /** Converts the backend's fixed-point cents (e.g. 9000) to major units (90). */
9
+ const centsToAmount = (cents) => cents / 100;
10
+ class SplitusService {
11
+ sneatApiService = inject(SneatApiService);
12
+ /** REAL: POST /api4splitus/create-split. Payer is the authenticated user. */
13
+ createSplit(request) {
14
+ const body = {
15
+ spaceID: request.spaceID,
16
+ title: request.title,
17
+ currency: request.currency,
18
+ amount: request.amount,
19
+ splitMode: request.splitMode,
20
+ participantContactIDs: request.participantContactIDs,
21
+ shares: request.shares,
22
+ };
23
+ return this.sneatApiService
24
+ .post('api4splitus/create-split', body)
25
+ .pipe(map((dto) => this.mapCreateSplitResponse(dto)));
26
+ }
27
+ /** REAL: GET /api4splitus/split?spaceID=&id= */
28
+ getSplit(spaceID, id) {
29
+ const params = new HttpParams().set('spaceID', spaceID).set('id', id);
30
+ return this.sneatApiService
31
+ .get('api4splitus/split', params)
32
+ .pipe(map((dto) => this.mapSplit(dto)));
33
+ }
34
+ /** REAL: GET /api4splitus/splits?spaceID= */
35
+ getSplits(spaceID) {
36
+ const params = new HttpParams().set('spaceID', spaceID);
37
+ return this.sneatApiService
38
+ .get('api4splitus/splits', params)
39
+ .pipe(map((dto) => dto.splits.map((s) => this.mapSplitListItem(s))));
40
+ }
41
+ mapCreateSplitResponse(dto) {
42
+ return {
43
+ id: dto.id,
44
+ transfers: (dto.transfers ?? []).map((t) => ({
45
+ id: t.id,
46
+ contactID: t.contactID,
47
+ amount: centsToAmount(t.amount),
48
+ })),
49
+ };
50
+ }
51
+ mapSplit(dto) {
52
+ return {
53
+ id: dto.id,
54
+ title: dto.title,
55
+ currency: dto.currency,
56
+ amount: centsToAmount(dto.amount),
57
+ status: dto.status,
58
+ participants: (dto.participants ?? []).map((p) => this.mapParticipant(p)),
59
+ };
60
+ }
61
+ // Settled/outstanding is read verbatim off the API response — Splitus
62
+ // never computes or caches settled state on the client (see
63
+ // handleGetSplit's Debtus read-through in api_get_splits.go).
64
+ mapParticipant(dto) {
65
+ return {
66
+ contactID: dto.contactID,
67
+ userID: dto.userID,
68
+ name: dto.name,
69
+ share: centsToAmount(dto.share),
70
+ isPayer: dto.isPayer,
71
+ status: dto.status,
72
+ };
73
+ }
74
+ mapSplitListItem(dto) {
75
+ return {
76
+ id: dto.id,
77
+ title: dto.title,
78
+ amount: centsToAmount(dto.amount),
79
+ currency: dto.currency,
80
+ status: dto.status,
81
+ membersCount: dto.membersCount,
82
+ };
83
+ }
84
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: SplitusService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
85
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: SplitusService });
86
+ }
87
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: SplitusService, decorators: [{
88
+ type: Injectable
89
+ }] });
90
+
91
+ // Registers the concrete SplitusService and binds it to the SPLITUS_SERVICE token so
92
+ // consumers depend only on the ISplitusService contract. Wired in at app
93
+ // bootstrap (consumers do not import this factory directly).
94
+ function provideSplitus() {
95
+ return [SplitusService, { provide: SPLITUS_SERVICE, useExisting: SplitusService }];
96
+ }
97
+
98
+ /**
99
+ * Generated bundle index. Do not edit.
100
+ */
101
+
102
+ export { SplitusService, provideSplitus };
103
+ //# sourceMappingURL=sneat-extension-splitus.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sneat-extension-splitus.mjs","sources":["../../../../../../libs/extensions/splitus/runtime/src/lib/services/splitus.service.ts","../../../../../../libs/extensions/splitus/runtime/src/lib/provide-splitus.ts","../../../../../../libs/extensions/splitus/runtime/src/sneat-extension-splitus.ts"],"sourcesContent":["import { HttpParams } from '@angular/common/http';\nimport { Injectable, inject } from '@angular/core';\nimport { SneatApiService } from '@sneat/api';\nimport {\n CurrencyCode,\n ICreateSplitRequest,\n ICreateSplitResponse,\n ISplit,\n ISplitListItem,\n ISplitParticipant,\n ISplitusService,\n SplitShareStatus,\n} from '@sneat/extension-splitus-contract';\nimport { Observable, map } from 'rxjs';\n\n// Backend DTO shapes (backend/splitus/api4splitusbot/api_create_split.go,\n// api_get_splits.go). decimal.Decimal64p2 fields (amount/share) marshal as\n// plain integer CENTS (e.g. 9000 == \"90.00\" — see strongo/decimal\n// MarshalJSON), unlike the create-split REQUEST's `amount`/shares, which the\n// Go DTO types as decimal strings (\"90.00\") and are sent through unchanged.\ninterface IApiCreateSplitTransferDto {\n readonly id: string;\n readonly contactID: string;\n readonly amount: number; // cents\n}\n\ninterface IApiCreateSplitResponseDto {\n readonly id: string;\n readonly transfers: IApiCreateSplitTransferDto[];\n}\n\ninterface IApiSplitParticipantDto {\n readonly contactID?: string;\n readonly userID?: string;\n readonly name: string;\n readonly share: number; // cents\n readonly isPayer?: boolean;\n readonly status: SplitShareStatus;\n}\n\ninterface IApiGetSplitResponseDto {\n readonly id: string;\n readonly title?: string;\n readonly currency: CurrencyCode;\n readonly amount: number; // cents\n readonly status: string;\n readonly participants: IApiSplitParticipantDto[];\n}\n\ninterface IApiSplitListItemDto {\n readonly id: string;\n readonly title?: string;\n readonly amount: number; // cents\n readonly currency: CurrencyCode;\n readonly status: string;\n readonly membersCount: number;\n}\n\ninterface IApiGetSplitsResponseDto {\n readonly splits: IApiSplitListItemDto[];\n}\n\n/** Converts the backend's fixed-point cents (e.g. 9000) to major units (90). */\nconst centsToAmount = (cents: number): number => cents / 100;\n\n@Injectable()\nexport class SplitusService implements ISplitusService {\n private readonly sneatApiService = inject(SneatApiService);\n\n /** REAL: POST /api4splitus/create-split. Payer is the authenticated user. */\n public createSplit(\n request: ICreateSplitRequest,\n ): Observable<ICreateSplitResponse> {\n const body = {\n spaceID: request.spaceID,\n title: request.title,\n currency: request.currency,\n amount: request.amount,\n splitMode: request.splitMode,\n participantContactIDs: request.participantContactIDs,\n shares: request.shares,\n };\n return this.sneatApiService\n .post<IApiCreateSplitResponseDto>('api4splitus/create-split', body)\n .pipe(map((dto) => this.mapCreateSplitResponse(dto)));\n }\n\n /** REAL: GET /api4splitus/split?spaceID=&id= */\n public getSplit(spaceID: string, id: string): Observable<ISplit> {\n const params = new HttpParams().set('spaceID', spaceID).set('id', id);\n return this.sneatApiService\n .get<IApiGetSplitResponseDto>('api4splitus/split', params)\n .pipe(map((dto) => this.mapSplit(dto)));\n }\n\n /** REAL: GET /api4splitus/splits?spaceID= */\n public getSplits(spaceID: string): Observable<ISplitListItem[]> {\n const params = new HttpParams().set('spaceID', spaceID);\n return this.sneatApiService\n .get<IApiGetSplitsResponseDto>('api4splitus/splits', params)\n .pipe(map((dto) => dto.splits.map((s) => this.mapSplitListItem(s))));\n }\n\n private mapCreateSplitResponse(\n dto: IApiCreateSplitResponseDto,\n ): ICreateSplitResponse {\n return {\n id: dto.id,\n transfers: (dto.transfers ?? []).map((t) => ({\n id: t.id,\n contactID: t.contactID,\n amount: centsToAmount(t.amount),\n })),\n };\n }\n\n private mapSplit(dto: IApiGetSplitResponseDto): ISplit {\n return {\n id: dto.id,\n title: dto.title,\n currency: dto.currency,\n amount: centsToAmount(dto.amount),\n status: dto.status,\n participants: (dto.participants ?? []).map((p) =>\n this.mapParticipant(p),\n ),\n };\n }\n\n // Settled/outstanding is read verbatim off the API response — Splitus\n // never computes or caches settled state on the client (see\n // handleGetSplit's Debtus read-through in api_get_splits.go).\n private mapParticipant(dto: IApiSplitParticipantDto): ISplitParticipant {\n return {\n contactID: dto.contactID,\n userID: dto.userID,\n name: dto.name,\n share: centsToAmount(dto.share),\n isPayer: dto.isPayer,\n status: dto.status,\n };\n }\n\n private mapSplitListItem(dto: IApiSplitListItemDto): ISplitListItem {\n return {\n id: dto.id,\n title: dto.title,\n amount: centsToAmount(dto.amount),\n currency: dto.currency,\n status: dto.status,\n membersCount: dto.membersCount,\n };\n }\n}\n","import { Provider } from '@angular/core';\nimport { SPLITUS_SERVICE } from '@sneat/extension-splitus-contract';\nimport { SplitusService } from './services';\n\n// Registers the concrete SplitusService and binds it to the SPLITUS_SERVICE token so\n// consumers depend only on the ISplitusService contract. Wired in at app\n// bootstrap (consumers do not import this factory directly).\nexport function provideSplitus(): Provider[] {\n return [SplitusService, { provide: SPLITUS_SERVICE, useExisting: SplitusService }];\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AA8DA;AACA,MAAM,aAAa,GAAG,CAAC,KAAa,KAAa,KAAK,GAAG,GAAG;MAG/C,cAAc,CAAA;AACR,IAAA,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;;AAGnD,IAAA,WAAW,CAChB,OAA4B,EAAA;AAE5B,QAAA,MAAM,IAAI,GAAG;YACX,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,qBAAqB,EAAE,OAAO,CAAC,qBAAqB;YACpD,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB;QACD,OAAO,IAAI,CAAC;AACT,aAAA,IAAI,CAA6B,0BAA0B,EAAE,IAAI;AACjE,aAAA,IAAI,CAAC,GAAG,CAAC,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E,CAAC;AACpF;;ACTA;;AAEG;;;;"}
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@sneat/extension-splitus",
3
+ "version": "0.1.0",
4
+ "peerDependencies": {
5
+ "@angular/core": ">=22.0.0 <23.0.0",
6
+ "rxjs": "^7.0.0",
7
+ "@sneat/api": "^0.26.4",
8
+ "@sneat/extension-splitus-contract": "^0.2.0"
9
+ },
10
+ "dependencies": {
11
+ "tslib": "^2.3.0"
12
+ },
13
+ "sideEffects": false,
14
+ "module": "fesm2022/sneat-extension-splitus.mjs",
15
+ "typings": "types/sneat-extension-splitus.d.ts",
16
+ "exports": {
17
+ "./package.json": {
18
+ "default": "./package.json"
19
+ },
20
+ ".": {
21
+ "types": "./types/sneat-extension-splitus.d.ts",
22
+ "default": "./fesm2022/sneat-extension-splitus.mjs"
23
+ }
24
+ },
25
+ "type": "module"
26
+ }
@@ -0,0 +1,24 @@
1
+ import { ISplitusService, ICreateSplitRequest, ICreateSplitResponse, ISplit, ISplitListItem } from '@sneat/extension-splitus-contract';
2
+ import { Observable } from 'rxjs';
3
+ import * as i0 from '@angular/core';
4
+ import { Provider } from '@angular/core';
5
+
6
+ declare class SplitusService implements ISplitusService {
7
+ private readonly sneatApiService;
8
+ /** REAL: POST /api4splitus/create-split. Payer is the authenticated user. */
9
+ createSplit(request: ICreateSplitRequest): Observable<ICreateSplitResponse>;
10
+ /** REAL: GET /api4splitus/split?spaceID=&id= */
11
+ getSplit(spaceID: string, id: string): Observable<ISplit>;
12
+ /** REAL: GET /api4splitus/splits?spaceID= */
13
+ getSplits(spaceID: string): Observable<ISplitListItem[]>;
14
+ private mapCreateSplitResponse;
15
+ private mapSplit;
16
+ private mapParticipant;
17
+ private mapSplitListItem;
18
+ static ɵfac: i0.ɵɵFactoryDeclaration<SplitusService, never>;
19
+ static ɵprov: i0.ɵɵInjectableDeclaration<SplitusService>;
20
+ }
21
+
22
+ declare function provideSplitus(): Provider[];
23
+
24
+ export { SplitusService, provideSplitus };