ofpos-shared-core 1.1.0 → 2.0.0-alpha.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.
Files changed (69) hide show
  1. package/dist/DomainServices.d.ts +2 -1
  2. package/dist/IntegrationServices.d.ts +0 -4
  3. package/dist/PosCore.d.ts +51 -1
  4. package/dist/data/schema.d.ts +1 -3
  5. package/dist/finance/offinanceProjection.d.ts +196 -0
  6. package/dist/index.browser.mjs +4 -4
  7. package/dist/index.browser.mjs.LEGAL.txt +1 -1
  8. package/dist/index.cjs.js +4 -4
  9. package/dist/index.cjs.js.LEGAL.txt +1 -1
  10. package/dist/index.d.ts +5 -4
  11. package/dist/index.esm.js +4 -4
  12. package/dist/index.esm.js.LEGAL.txt +1 -1
  13. package/dist/index.umd.js +4 -4
  14. package/dist/index.umd.js.LEGAL.txt +1 -1
  15. package/dist/integration/NotificationAdapter.d.ts +6 -67
  16. package/dist/integration/authorizationService.d.ts +2 -19
  17. package/dist/integration/changeQueuePort.d.ts +5 -0
  18. package/dist/integration/loggerAdapter.d.ts +6 -43
  19. package/dist/integration/socket.d.ts +13 -0
  20. package/dist/integration/userService.d.ts +17 -32
  21. package/dist/models/User.d.ts +0 -6
  22. package/dist/services/bomService.d.ts +1 -1
  23. package/dist/services/categoryService.d.ts +1 -1
  24. package/dist/services/customerGroupService.d.ts +1 -1
  25. package/dist/services/customerService.d.ts +1 -1
  26. package/dist/services/expenseService.d.ts +5 -2
  27. package/dist/services/exportAdapter.d.ts +6 -46
  28. package/dist/services/financialSettingService.d.ts +1 -1
  29. package/dist/services/historyService.d.ts +1 -1
  30. package/dist/services/inventoryLogService.d.ts +2 -1
  31. package/dist/services/inventoryService.d.ts +7 -1
  32. package/dist/services/orderItemService.d.ts +1 -1
  33. package/dist/services/orderService.d.ts +1 -1
  34. package/dist/services/payableService.d.ts +1 -1
  35. package/dist/services/priceHistoryService.d.ts +1 -1
  36. package/dist/services/priceTierService.d.ts +1 -1
  37. package/dist/services/productService.d.ts +1 -1
  38. package/dist/services/promotionService.d.ts +1 -1
  39. package/dist/services/purchaseItemService.d.ts +1 -1
  40. package/dist/services/purchaseOrderItemService.d.ts +1 -1
  41. package/dist/services/purchaseOrderService.d.ts +1 -1
  42. package/dist/services/purchaseService.d.ts +7 -2
  43. package/dist/services/receivableService.d.ts +1 -1
  44. package/dist/services/reportScheduleService.d.ts +1 -1
  45. package/dist/services/reportingService.d.ts +1 -1
  46. package/dist/services/returnItemService.d.ts +1 -1
  47. package/dist/services/returnService.d.ts +5 -2
  48. package/dist/services/roleService.d.ts +1 -1
  49. package/dist/services/runtimeSupport.d.ts +12 -0
  50. package/dist/services/saleItemService.d.ts +1 -1
  51. package/dist/services/saleService.d.ts +6 -2
  52. package/dist/services/settlementService.d.ts +5 -2
  53. package/dist/services/shiftService.d.ts +1 -1
  54. package/dist/services/stockAdjustmentService.d.ts +1 -1
  55. package/dist/services/stockOpnameItemService.d.ts +1 -1
  56. package/dist/services/stockOpnameService.d.ts +1 -1
  57. package/dist/services/supplierService.d.ts +1 -1
  58. package/dist/services/taxRateService.d.ts +1 -1
  59. package/dist/services/transactionService.d.ts +5 -2
  60. package/dist/services/uiProductService.d.ts +0 -1
  61. package/dist/services/uomService.d.ts +1 -1
  62. package/dist/services/userService.d.ts +1 -1
  63. package/dist/stores/storageAdapter.d.ts +8 -39
  64. package/dist/stores/syncService.d.ts +16 -0
  65. package/package.json +28 -7
  66. package/dist/data/inMemoryDbAdapter.d.ts +0 -65
  67. package/dist/data/seed.d.ts +0 -370
  68. package/dist/integration/ofauthBridge.d.ts +0 -29
  69. package/dist/integration/ofauthCoreBridge.d.ts +0 -19
@@ -46,6 +46,7 @@ import { IReportingService } from './services/reportingService';
46
46
  import { ICartService } from './services/cartService';
47
47
  import { ITaxService } from './services/taxService';
48
48
  import { IStockTransferService } from './services/stockTransferService';
49
+ import type { ServiceRuntimeOptions } from './services/runtimeSupport';
49
50
  /**
50
51
  * Override type for domain services, allowing custom implementations.
51
52
  */
@@ -147,5 +148,5 @@ export declare class DomainServices {
147
148
  * @param context The PosCore context.
148
149
  * @param overrides Optional overrides for domain services.
149
150
  */
150
- constructor(context: PosCore, overrides?: Partial<DomainServicesOverride>);
151
+ constructor(context: PosCore, overrides?: Partial<DomainServicesOverride>, runtimeOptions?: Partial<ServiceRuntimeOptions>);
151
152
  }
@@ -9,7 +9,6 @@ import { ISocketService } from './integration/socket';
9
9
  import { INotificationService } from './integration/notificationService';
10
10
  import { IConfigService } from './integration/configService';
11
11
  import { IBackupScheduler } from './integration/backupScheduler';
12
- import { IOfauthBridge } from './integration/ofauthBridge';
13
12
  /**
14
13
  * Override layanan integrasi untuk menginisialisasi IntegrationServices dengan implementasi kustom.
15
14
  */
@@ -33,7 +32,6 @@ export type IntegrationServicesOverride = {
33
32
  /** Layanan pencatatan aktivitas. */
34
33
  activityLogger: IActivityLogger;
35
34
  backupScheduler: IBackupScheduler;
36
- ofauthBridge: IOfauthBridge;
37
35
  };
38
36
  /**
39
37
  * Penyedia seluruh layanan integrasi yang digunakan oleh PosCore.
@@ -62,8 +60,6 @@ export declare class IntegrationServices {
62
60
  /** Layanan pencatatan aktivitas. */
63
61
  activityLogger: IActivityLogger;
64
62
  backupScheduler: IBackupScheduler;
65
- /** Bridge auth compatibility (opsional) untuk adopsi ofauth-shared-core bertahap. */
66
- ofauthBridge: IOfauthBridge;
67
63
  /**
68
64
  * Membuat instance IntegrationServices.
69
65
  * @param context - Instans PosCore yang menggunakan layanan ini.
package/dist/PosCore.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import type { ReadonlyStore } from 'ofcore';
2
2
  import { DomainServices, DomainServicesOverride } from './DomainServices';
3
- import { SyncStore } from './stores/syncStore';
3
+ import { SyncStore, type State as SyncState, type SyncChange } from './stores/syncStore';
4
4
  import { ConfigService } from './integration/configService';
5
5
  import { AdapterRegistry, AdapterRegistryOptions } from './AdapterRegistry';
6
6
  import { IntegrationServices, IntegrationServicesOverride } from './IntegrationServices';
7
7
  import { DbAdapter } from 'ofcore';
8
8
  import { SessionStore } from './stores/sessionStore';
9
+ import type { ServiceRuntimeOptions } from './services/runtimeSupport';
9
10
  /**
10
11
  * Opsi untuk memulai PosCore.
11
12
  * @property runMigrations Jika true, jalankan migrasi database sebelum inisialisasi plugin.
@@ -22,6 +23,11 @@ export interface PosRuntimeState {
22
23
  lastError: string | null;
23
24
  lastTransitionAt: string;
24
25
  }
26
+ export type DomainChangeQueueState = SyncState;
27
+ export type DomainChangeQueueItem = SyncChange;
28
+ export type SyncOrchestrationMode = 'host-managed';
29
+ export type AuthBridgePolicyMode = 'bridge-required';
30
+ export type DomainChangeSink = (change: DomainChangeQueueItem) => void | Promise<void>;
25
31
  /**
26
32
  * Kelas utama PosCore yang mengatur lifecycle, registri adapter,
27
33
  * domain services, integration services, dan plugin.
@@ -43,13 +49,39 @@ export declare class PosCore {
43
49
  domainServiceOverrides: Partial<DomainServicesOverride>;
44
50
  /** Override untuk integration services sebelum inisialisasi. */
45
51
  integrationServiceOverrides: Partial<IntegrationServicesOverride>;
52
+ /** Runtime options lintas service (mis. finance projection sink). */
53
+ serviceRuntimeOptions: Partial<ServiceRuntimeOptions>;
46
54
  private runtime;
47
55
  private pluginSpecs;
56
+ private authBridgePolicyMode;
57
+ private domainChangeSink?;
48
58
  constructor();
49
59
  /**
50
60
  * Dapatkan instansi SyncStore.
51
61
  */
52
62
  getSyncStore(): SyncStore | undefined;
63
+ /**
64
+ * Ambil snapshot antrean perubahan domain (API netral, tanpa surface sync runtime).
65
+ */
66
+ getDomainChangeQueueState(): DomainChangeQueueState;
67
+ /**
68
+ * Subscribe perubahan antrean domain.
69
+ */
70
+ subscribeDomainChangeQueue(listener: (state: DomainChangeQueueState) => void): () => void;
71
+ /**
72
+ * Ambil daftar perubahan domain yang belum tersinkron.
73
+ */
74
+ getQueuedDomainChanges(): DomainChangeQueueItem[];
75
+ /**
76
+ * Tambahkan perubahan domain ke antrean.
77
+ */
78
+ enqueueDomainChange(change: unknown): void;
79
+ /**
80
+ * Hapus item antrean domain (biasanya setelah ack sinkronisasi host).
81
+ */
82
+ removeDomainQueuedChange(changeId: string): void;
83
+ setDomainChangeSink(sink?: DomainChangeSink): void;
84
+ withServiceRuntimeOptions(options: Partial<ServiceRuntimeOptions>): this;
53
85
  /**
54
86
  * Dapatkan instansi SessionStore untuk update status login.
55
87
  */
@@ -122,6 +154,9 @@ export declare class PosCore {
122
154
  */
123
155
  get config(): ConfigService;
124
156
  isOnline(): boolean | undefined;
157
+ /**
158
+ * Generate correlation id untuk tracing lintas request/log.
159
+ */
125
160
  /**
126
161
  * Generate correlation id untuk tracing lintas request/log.
127
162
  */
@@ -141,6 +176,7 @@ export declare class PosCore {
141
176
  export declare class PosCoreBuilder {
142
177
  private core;
143
178
  private adapterOpts;
179
+ private syncOrchestrationMode;
144
180
  /**
145
181
  * Set platform adapter.
146
182
  */
@@ -197,6 +233,20 @@ export declare class PosCoreBuilder {
197
233
  * Override default integration services.
198
234
  */
199
235
  overrideIntegrationServices(overrides?: Partial<IntegrationServicesOverride>): this;
236
+ withServiceRuntimeOptions(options?: Partial<ServiceRuntimeOptions>): this;
237
+ /**
238
+ * Pilih mode orchestration sinkronisasi.
239
+ * Saat ini hanya `host-managed` yang didukung:
240
+ * orchestration wajib diserahkan ke host (mis. ofsync-shared-core).
241
+ */
242
+ withSyncOrchestrationMode(mode: SyncOrchestrationMode): this;
243
+ withDomainChangeSink(sink?: DomainChangeSink): this;
244
+ /**
245
+ * Nonaktifkan orchestration sinkronisasi internal (sync + socket).
246
+ * Gunakan ini saat host menyerahkan sync ke ofsync-shared-core.
247
+ */
248
+ disableInternalSyncOrchestration(): this;
249
+ private applySyncOrchestrationMode;
200
250
  /**
201
251
  * Build PosCore: inisialisasi registry dan stores, lalu kembalikan instansi.
202
252
  */
@@ -2,8 +2,6 @@
2
2
  * Schema definitions for database tables and columns.
3
3
  */
4
4
  import { TableSchema } from "./DbAdapter";
5
- /**
6
- * Array of table schemas to initialize or migrate the database.
7
- */
8
5
  declare const schemas: TableSchema[];
6
+ export declare const POS_DOMAIN_TABLES: readonly string[];
9
7
  export { schemas };
@@ -0,0 +1,196 @@
1
+ import type { Sale } from '../models/Sale';
2
+ import type { Purchase } from '../models/Purchase';
3
+ import type { Return } from '../models/Return';
4
+ import type { Expense } from '../models/Expense';
5
+ import { type FinanceAccount, type FinanceDbAdapterLike, type FinanceProjectionServicesRef, type FinanceSyncEnqueuer, type JournalDraftInput } from 'offinance-shared-core';
6
+ import type { ServiceRuntimeOptions } from '../services/runtimeSupport';
7
+ export interface ScopedAccountMapping<TMapping> {
8
+ default: TMapping;
9
+ byTenant?: Record<string, Partial<TMapping>>;
10
+ byBranch?: Record<string, Partial<TMapping>>;
11
+ }
12
+ export interface PosSaleAccountMapping {
13
+ paymentAccountId: string;
14
+ revenueAccountId: string;
15
+ discountAccountId?: string;
16
+ taxPayableAccountId?: string;
17
+ }
18
+ export interface PosPurchaseAccountMapping {
19
+ inventoryAccountId: string;
20
+ paymentAccountId?: string;
21
+ payableAccountId?: string;
22
+ }
23
+ export interface PosReturnAccountMapping {
24
+ salesReturnAccountId: string;
25
+ purchaseReturnAccountId: string;
26
+ settlementAccountId: string;
27
+ }
28
+ export interface PosExpenseAccountMapping {
29
+ expenseAccountId: string;
30
+ paymentAccountId: string;
31
+ }
32
+ export interface PosSettlementAccountMapping {
33
+ cashAccountId: string;
34
+ receivableAccountId: string;
35
+ payableAccountId: string;
36
+ }
37
+ export interface PosCashAdjustmentAccountMapping {
38
+ cashAccountId: string;
39
+ cashOverShortIncomeAccountId: string;
40
+ cashOverShortExpenseAccountId: string;
41
+ }
42
+ export interface PosFinanceAdapterContext {
43
+ journalId: string;
44
+ tenantId: string;
45
+ branchId?: string;
46
+ occurredAt: string;
47
+ reference?: string;
48
+ }
49
+ export interface ScopedPosSaleFinanceProjection {
50
+ kind?: 'sale';
51
+ context: PosFinanceAdapterContext;
52
+ input: {
53
+ grossAmount: number;
54
+ discountAmount?: number;
55
+ taxAmount?: number;
56
+ scopedAccountMapping: ScopedAccountMapping<PosSaleAccountMapping>;
57
+ };
58
+ }
59
+ export interface PosPurchaseFinanceProjection {
60
+ kind: 'purchase';
61
+ context: PosFinanceAdapterContext;
62
+ input: {
63
+ totalAmount: number;
64
+ paymentMethod: 'cash' | 'card' | 'bank_transfer' | 'tempo';
65
+ scopedAccountMapping: ScopedAccountMapping<PosPurchaseAccountMapping>;
66
+ };
67
+ }
68
+ export interface PosReturnFinanceProjection {
69
+ kind: 'sale_return' | 'purchase_return';
70
+ context: PosFinanceAdapterContext;
71
+ input: {
72
+ actualRefund: number;
73
+ scopedAccountMapping: ScopedAccountMapping<PosReturnAccountMapping>;
74
+ };
75
+ }
76
+ export interface PosExpenseFinanceProjection {
77
+ kind: 'expense';
78
+ context: PosFinanceAdapterContext;
79
+ input: {
80
+ amount: number;
81
+ category?: string | null;
82
+ description?: string | null;
83
+ scopedAccountMapping: ScopedAccountMapping<PosExpenseAccountMapping>;
84
+ };
85
+ }
86
+ export interface PosSettlementFinanceProjection {
87
+ kind: 'receivable_payment' | 'payable_payment';
88
+ context: PosFinanceAdapterContext;
89
+ input: {
90
+ amount: number;
91
+ method: string;
92
+ receivableId?: string | null;
93
+ payableId?: string | null;
94
+ scopedAccountMapping: ScopedAccountMapping<PosSettlementAccountMapping>;
95
+ };
96
+ }
97
+ export interface PosCashAdjustmentFinanceProjection {
98
+ kind: 'cash_adjustment';
99
+ context: PosFinanceAdapterContext;
100
+ input: {
101
+ amount: number;
102
+ direction: 'in' | 'out';
103
+ reason?: string | null;
104
+ scopedAccountMapping: ScopedAccountMapping<PosCashAdjustmentAccountMapping>;
105
+ };
106
+ }
107
+ export type ScopedPosFinanceProjection = ScopedPosSaleFinanceProjection | PosPurchaseFinanceProjection | PosReturnFinanceProjection | PosExpenseFinanceProjection | PosSettlementFinanceProjection | PosCashAdjustmentFinanceProjection;
108
+ export interface ProjectScopedPosSaleFinanceInput {
109
+ sale: Pick<Sale, 'id' | 'date' | 'total' | 'discount' | 'ppn' | 'finalTotal'>;
110
+ tenantId: string;
111
+ branchId?: string;
112
+ scopedAccountMapping: ScopedAccountMapping<PosSaleAccountMapping>;
113
+ journalId?: string;
114
+ referencePrefix?: string;
115
+ }
116
+ export interface ProjectPosPurchaseFinanceInput {
117
+ purchase: Pick<Purchase, 'id' | 'date' | 'total'>;
118
+ tenantId: string;
119
+ branchId?: string;
120
+ paymentMethod: 'cash' | 'card' | 'bank_transfer' | 'tempo';
121
+ scopedAccountMapping: ScopedAccountMapping<PosPurchaseAccountMapping>;
122
+ journalId?: string;
123
+ referencePrefix?: string;
124
+ }
125
+ export interface ProjectPosReturnFinanceInput {
126
+ returnEntry: Pick<Return, 'id' | 'date' | 'type' | 'actualRefund'>;
127
+ tenantId: string;
128
+ branchId?: string;
129
+ scopedAccountMapping: ScopedAccountMapping<PosReturnAccountMapping>;
130
+ journalId?: string;
131
+ referencePrefix?: string;
132
+ }
133
+ export interface ProjectPosExpenseFinanceInput {
134
+ expense: Pick<Expense, 'id' | 'date' | 'amount' | 'category' | 'description'>;
135
+ tenantId: string;
136
+ branchId?: string;
137
+ scopedAccountMapping: ScopedAccountMapping<PosExpenseAccountMapping>;
138
+ journalId?: string;
139
+ referencePrefix?: string;
140
+ }
141
+ export interface ProjectPosSettlementFinanceInput {
142
+ settlement: {
143
+ id: string;
144
+ date?: string | null;
145
+ amount: number;
146
+ method: string;
147
+ receivableId?: string | null;
148
+ payableId?: string | null;
149
+ };
150
+ tenantId: string;
151
+ branchId?: string;
152
+ scopedAccountMapping: ScopedAccountMapping<PosSettlementAccountMapping>;
153
+ journalId?: string;
154
+ referencePrefix?: string;
155
+ }
156
+ export interface ProjectPosCashAdjustmentFinanceInput {
157
+ adjustment: {
158
+ id: string;
159
+ date?: string | null;
160
+ amount: number;
161
+ direction: 'in' | 'out';
162
+ reason?: string | null;
163
+ };
164
+ tenantId: string;
165
+ branchId?: string;
166
+ scopedAccountMapping: ScopedAccountMapping<PosCashAdjustmentAccountMapping>;
167
+ journalId?: string;
168
+ referencePrefix?: string;
169
+ }
170
+ export interface CreatePosFinanceRuntimeOptions {
171
+ dbAdapter: FinanceDbAdapterLike;
172
+ resolveFinanceServices: () => FinanceProjectionServicesRef | null;
173
+ resolveLedgerProfileId: () => string;
174
+ resolveSyncEnqueuer?: () => FinanceSyncEnqueuer | null;
175
+ requiredAccounts: FinanceAccount[];
176
+ saleAccountMapping: ScopedAccountMapping<PosSaleAccountMapping>;
177
+ purchaseAccountMapping?: ScopedAccountMapping<PosPurchaseAccountMapping>;
178
+ returnAccountMapping?: ScopedAccountMapping<PosReturnAccountMapping>;
179
+ expenseAccountMapping?: ScopedAccountMapping<PosExpenseAccountMapping>;
180
+ settlementAccountMapping?: ScopedAccountMapping<PosSettlementAccountMapping>;
181
+ cashAdjustmentAccountMapping?: ScopedAccountMapping<PosCashAdjustmentAccountMapping>;
182
+ financeDomainId?: string;
183
+ missingServicesErrorCode?: string;
184
+ missingLedgerProfileErrorCode?: string;
185
+ }
186
+ export declare function projectScopedPosSaleFinance(input: ProjectScopedPosSaleFinanceInput): ScopedPosSaleFinanceProjection;
187
+ export declare function projectPosPurchaseFinance(input: ProjectPosPurchaseFinanceInput): PosPurchaseFinanceProjection;
188
+ export declare function projectPosReturnFinance(input: ProjectPosReturnFinanceInput): PosReturnFinanceProjection;
189
+ export declare function projectPosExpenseFinance(input: ProjectPosExpenseFinanceInput): PosExpenseFinanceProjection;
190
+ export declare function projectPosSettlementFinance(input: ProjectPosSettlementFinanceInput): PosSettlementFinanceProjection;
191
+ export declare function projectPosCashAdjustmentFinance(input: ProjectPosCashAdjustmentFinanceInput): PosCashAdjustmentFinanceProjection;
192
+ export declare function buildJournalDraftFromPosFinanceProjection(projection: ScopedPosFinanceProjection, options: {
193
+ ledgerProfileId: string;
194
+ financeDomainId?: string;
195
+ }): JournalDraftInput;
196
+ export declare function createPosFinanceRuntimeOptions(options: CreatePosFinanceRuntimeOptions): Partial<ServiceRuntimeOptions>;