@jsdev_ninja/core 0.15.3 → 0.16.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/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.es.js +1220 -1164
- package/dist/core.es.js.map +1 -1
- package/dist/core.umd.js +1 -1
- package/dist/core.umd.js.map +1 -1
- package/dist/lib/entities/OrganizationBalance.d.ts +138 -0
- package/dist/lib/entities/OrganizationBalance.d.ts.map +1 -0
- package/dist/lib/entities/OrganizationBalance.js +65 -0
- package/dist/lib/entities/index.d.ts +1 -0
- package/dist/lib/entities/index.d.ts.map +1 -1
- package/dist/lib/entities/index.js +1 -0
- package/dist/lib/firebase-api/index.d.ts +6 -0
- package/dist/lib/firebase-api/index.d.ts.map +1 -1
- package/dist/lib/firebase-api/index.js +2 -0
- package/dist/tsconfig.app.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const OrganizationBalanceEntrySchema: z.ZodObject<{
|
|
3
|
+
/** = deterministic dedup doc id */
|
|
4
|
+
id: z.ZodString;
|
|
5
|
+
organizationId: z.ZodString;
|
|
6
|
+
/** "+" increases owed (accrual), "-" decreases owed (settlement/adjustment) */
|
|
7
|
+
sign: z.ZodEnum<["+", "-"]>;
|
|
8
|
+
kind: z.ZodEnum<["accrual", "settlement", "adjustment"]>;
|
|
9
|
+
/** Integer agorot, always positive; sign carries direction */
|
|
10
|
+
amount: z.ZodNumber;
|
|
11
|
+
currency: z.ZodLiteral<"ILS">;
|
|
12
|
+
source: z.ZodEnum<["delivery_note", "ledger_payment", "manual", "order_reversal"]>;
|
|
13
|
+
/** Present for document-sourced accruals */
|
|
14
|
+
document: z.ZodOptional<z.ZodObject<{
|
|
15
|
+
type: z.ZodEnum<["delivery_note", "invoice"]>;
|
|
16
|
+
id: z.ZodString;
|
|
17
|
+
number: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
type: "invoice" | "delivery_note";
|
|
20
|
+
id: string;
|
|
21
|
+
number?: string | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
type: "invoice" | "delivery_note";
|
|
24
|
+
id: string;
|
|
25
|
+
number?: string | undefined;
|
|
26
|
+
}>>;
|
|
27
|
+
/** Order id (accrual), ledger txId (settlement), or manual ref */
|
|
28
|
+
reference: z.ZodOptional<z.ZodObject<{
|
|
29
|
+
type: z.ZodEnum<["order", "transaction", "manual"]>;
|
|
30
|
+
id: z.ZodString;
|
|
31
|
+
}, "strip", z.ZodTypeAny, {
|
|
32
|
+
type: "order" | "manual" | "transaction";
|
|
33
|
+
id: string;
|
|
34
|
+
}, {
|
|
35
|
+
type: "order" | "manual" | "transaction";
|
|
36
|
+
id: string;
|
|
37
|
+
}>>;
|
|
38
|
+
/** Optional sub-grouping within an org */
|
|
39
|
+
billingAccountId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
40
|
+
/** Deterministic dedup key; doc id is derived from this */
|
|
41
|
+
dedupKey: z.ZodString;
|
|
42
|
+
/** Event id when source is event-driven */
|
|
43
|
+
causedByEventId: z.ZodOptional<z.ZodString>;
|
|
44
|
+
/** Epoch millis — used for date-range queries */
|
|
45
|
+
createdAt: z.ZodNumber;
|
|
46
|
+
companyId: z.ZodString;
|
|
47
|
+
storeId: z.ZodString;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
id: string;
|
|
50
|
+
companyId: string;
|
|
51
|
+
storeId: string;
|
|
52
|
+
currency: "ILS";
|
|
53
|
+
amount: number;
|
|
54
|
+
organizationId: string;
|
|
55
|
+
createdAt: number;
|
|
56
|
+
source: "manual" | "delivery_note" | "ledger_payment" | "order_reversal";
|
|
57
|
+
sign: "+" | "-";
|
|
58
|
+
kind: "accrual" | "settlement" | "adjustment";
|
|
59
|
+
dedupKey: string;
|
|
60
|
+
billingAccountId?: string | null | undefined;
|
|
61
|
+
causedByEventId?: string | undefined;
|
|
62
|
+
document?: {
|
|
63
|
+
type: "invoice" | "delivery_note";
|
|
64
|
+
id: string;
|
|
65
|
+
number?: string | undefined;
|
|
66
|
+
} | undefined;
|
|
67
|
+
reference?: {
|
|
68
|
+
type: "order" | "manual" | "transaction";
|
|
69
|
+
id: string;
|
|
70
|
+
} | undefined;
|
|
71
|
+
}, {
|
|
72
|
+
id: string;
|
|
73
|
+
companyId: string;
|
|
74
|
+
storeId: string;
|
|
75
|
+
currency: "ILS";
|
|
76
|
+
amount: number;
|
|
77
|
+
organizationId: string;
|
|
78
|
+
createdAt: number;
|
|
79
|
+
source: "manual" | "delivery_note" | "ledger_payment" | "order_reversal";
|
|
80
|
+
sign: "+" | "-";
|
|
81
|
+
kind: "accrual" | "settlement" | "adjustment";
|
|
82
|
+
dedupKey: string;
|
|
83
|
+
billingAccountId?: string | null | undefined;
|
|
84
|
+
causedByEventId?: string | undefined;
|
|
85
|
+
document?: {
|
|
86
|
+
type: "invoice" | "delivery_note";
|
|
87
|
+
id: string;
|
|
88
|
+
number?: string | undefined;
|
|
89
|
+
} | undefined;
|
|
90
|
+
reference?: {
|
|
91
|
+
type: "order" | "manual" | "transaction";
|
|
92
|
+
id: string;
|
|
93
|
+
} | undefined;
|
|
94
|
+
}>;
|
|
95
|
+
export type TOrganizationBalanceEntry = z.infer<typeof OrganizationBalanceEntrySchema>;
|
|
96
|
+
export declare const OrganizationBalanceRollupSchema: z.ZodObject<{
|
|
97
|
+
/** = doc id */
|
|
98
|
+
organizationId: z.ZodString;
|
|
99
|
+
/** Σ(+) − Σ(−), clamped ≥ 0; integer agorot. Non-zero only when totalAccrued > totalSettled. */
|
|
100
|
+
owed: z.ZodNumber;
|
|
101
|
+
/**
|
|
102
|
+
* Overpayment credit: max(0, totalSettled − totalAccrued); integer agorot, ≥ 0.
|
|
103
|
+
* Non-zero only when org has paid MORE than it has accrued.
|
|
104
|
+
* Visibility only — not client-spendable. At most one of {owed, credit} is non-zero.
|
|
105
|
+
*/
|
|
106
|
+
credit: z.ZodNumber;
|
|
107
|
+
/** Lifetime Σ(+); integer agorot */
|
|
108
|
+
totalAccrued: z.ZodNumber;
|
|
109
|
+
/** Lifetime Σ(−); integer agorot */
|
|
110
|
+
totalSettled: z.ZodNumber;
|
|
111
|
+
currency: z.ZodLiteral<"ILS">;
|
|
112
|
+
/** Epoch millis */
|
|
113
|
+
updatedAt: z.ZodNumber;
|
|
114
|
+
companyId: z.ZodString;
|
|
115
|
+
storeId: z.ZodString;
|
|
116
|
+
}, "strip", z.ZodTypeAny, {
|
|
117
|
+
companyId: string;
|
|
118
|
+
storeId: string;
|
|
119
|
+
currency: "ILS";
|
|
120
|
+
organizationId: string;
|
|
121
|
+
updatedAt: number;
|
|
122
|
+
owed: number;
|
|
123
|
+
credit: number;
|
|
124
|
+
totalAccrued: number;
|
|
125
|
+
totalSettled: number;
|
|
126
|
+
}, {
|
|
127
|
+
companyId: string;
|
|
128
|
+
storeId: string;
|
|
129
|
+
currency: "ILS";
|
|
130
|
+
organizationId: string;
|
|
131
|
+
updatedAt: number;
|
|
132
|
+
owed: number;
|
|
133
|
+
credit: number;
|
|
134
|
+
totalAccrued: number;
|
|
135
|
+
totalSettled: number;
|
|
136
|
+
}>;
|
|
137
|
+
export type TOrganizationBalanceRollup = z.infer<typeof OrganizationBalanceRollupSchema>;
|
|
138
|
+
//# sourceMappingURL=OrganizationBalance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OrganizationBalance.d.ts","sourceRoot":"","sources":["../../../lib/entities/OrganizationBalance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,8BAA8B;IAC1C,mCAAmC;;;IAGnC,+EAA+E;;;IAG/E,8DAA8D;;;;IAI9D,4CAA4C;;;;;;;;;;;;;;IAQ5C,kEAAkE;;;;;;;;;;;IAOlE,0CAA0C;;IAE1C,2DAA2D;;IAE3D,2CAA2C;;IAE3C,iDAAiD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIhD,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC;AAMvF,eAAO,MAAM,+BAA+B;IAC3C,eAAe;;IAEf,gGAAgG;;IAEhG;;;;OAIG;;IAEH,oCAAoC;;IAEpC,oCAAoC;;;IAGpC,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;EAIlB,CAAC;AAEH,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// Append-only AR entry ledger document
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
export const OrganizationBalanceEntrySchema = z.object({
|
|
6
|
+
/** = deterministic dedup doc id */
|
|
7
|
+
id: z.string().min(1),
|
|
8
|
+
organizationId: z.string().min(1),
|
|
9
|
+
/** "+" increases owed (accrual), "-" decreases owed (settlement/adjustment) */
|
|
10
|
+
sign: z.enum(["+", "-"]),
|
|
11
|
+
kind: z.enum(["accrual", "settlement", "adjustment"]),
|
|
12
|
+
/** Integer agorot, always positive; sign carries direction */
|
|
13
|
+
amount: z.number().int().positive(),
|
|
14
|
+
currency: z.literal("ILS"),
|
|
15
|
+
source: z.enum(["delivery_note", "ledger_payment", "manual", "order_reversal"]),
|
|
16
|
+
/** Present for document-sourced accruals */
|
|
17
|
+
document: z
|
|
18
|
+
.object({
|
|
19
|
+
type: z.enum(["delivery_note", "invoice"]),
|
|
20
|
+
id: z.string().min(1),
|
|
21
|
+
number: z.string().optional(),
|
|
22
|
+
})
|
|
23
|
+
.optional(),
|
|
24
|
+
/** Order id (accrual), ledger txId (settlement), or manual ref */
|
|
25
|
+
reference: z
|
|
26
|
+
.object({
|
|
27
|
+
type: z.enum(["order", "transaction", "manual"]),
|
|
28
|
+
id: z.string().min(1),
|
|
29
|
+
})
|
|
30
|
+
.optional(),
|
|
31
|
+
/** Optional sub-grouping within an org */
|
|
32
|
+
billingAccountId: z.string().nullable().optional(),
|
|
33
|
+
/** Deterministic dedup key; doc id is derived from this */
|
|
34
|
+
dedupKey: z.string().min(1),
|
|
35
|
+
/** Event id when source is event-driven */
|
|
36
|
+
causedByEventId: z.string().optional(),
|
|
37
|
+
/** Epoch millis — used for date-range queries */
|
|
38
|
+
createdAt: z.number().int().positive(),
|
|
39
|
+
companyId: z.string().min(1),
|
|
40
|
+
storeId: z.string().min(1),
|
|
41
|
+
});
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
// Per-org rollup cache (O(1) balance reads)
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
export const OrganizationBalanceRollupSchema = z.object({
|
|
46
|
+
/** = doc id */
|
|
47
|
+
organizationId: z.string().min(1),
|
|
48
|
+
/** Σ(+) − Σ(−), clamped ≥ 0; integer agorot. Non-zero only when totalAccrued > totalSettled. */
|
|
49
|
+
owed: z.number().int(),
|
|
50
|
+
/**
|
|
51
|
+
* Overpayment credit: max(0, totalSettled − totalAccrued); integer agorot, ≥ 0.
|
|
52
|
+
* Non-zero only when org has paid MORE than it has accrued.
|
|
53
|
+
* Visibility only — not client-spendable. At most one of {owed, credit} is non-zero.
|
|
54
|
+
*/
|
|
55
|
+
credit: z.number().int(),
|
|
56
|
+
/** Lifetime Σ(+); integer agorot */
|
|
57
|
+
totalAccrued: z.number().int(),
|
|
58
|
+
/** Lifetime Σ(−); integer agorot */
|
|
59
|
+
totalSettled: z.number().int(),
|
|
60
|
+
currency: z.literal("ILS"),
|
|
61
|
+
/** Epoch millis */
|
|
62
|
+
updatedAt: z.number().int().positive(),
|
|
63
|
+
companyId: z.string().min(1),
|
|
64
|
+
storeId: z.string().min(1),
|
|
65
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/entities/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/entities/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC"}
|
|
@@ -28,6 +28,8 @@ export declare const storeCollections: {
|
|
|
28
28
|
readonly transactions: "transactions";
|
|
29
29
|
readonly paymentLinks: "paymentLinks";
|
|
30
30
|
readonly duplicateChargeAlerts: "duplicateChargeAlerts";
|
|
31
|
+
readonly organizationBalance: "organizationBalance";
|
|
32
|
+
readonly organizationBalanceRollup: "organizationBalanceRollup";
|
|
31
33
|
};
|
|
32
34
|
export declare const FirestoreApi: {
|
|
33
35
|
systemCollections: {
|
|
@@ -60,6 +62,8 @@ export declare const FirestoreApi: {
|
|
|
60
62
|
readonly transactions: "transactions";
|
|
61
63
|
readonly paymentLinks: "paymentLinks";
|
|
62
64
|
readonly duplicateChargeAlerts: "duplicateChargeAlerts";
|
|
65
|
+
readonly organizationBalance: "organizationBalance";
|
|
66
|
+
readonly organizationBalanceRollup: "organizationBalanceRollup";
|
|
63
67
|
};
|
|
64
68
|
getPath: ({ companyId, storeId, collectionName, id, }: {
|
|
65
69
|
companyId: string;
|
|
@@ -110,6 +114,8 @@ export declare const FirebaseAPI: {
|
|
|
110
114
|
readonly transactions: "transactions";
|
|
111
115
|
readonly paymentLinks: "paymentLinks";
|
|
112
116
|
readonly duplicateChargeAlerts: "duplicateChargeAlerts";
|
|
117
|
+
readonly organizationBalance: "organizationBalance";
|
|
118
|
+
readonly organizationBalanceRollup: "organizationBalanceRollup";
|
|
113
119
|
};
|
|
114
120
|
getPath: ({ companyId, storeId, collectionName, id, }: {
|
|
115
121
|
companyId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/firebase-api/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/firebase-api/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;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|
|
30
30
|
duplicateChargeAlerts: "duplicateChargeAlerts",
|
|
31
|
+
organizationBalance: "organizationBalance",
|
|
32
|
+
organizationBalanceRollup: "organizationBalanceRollup",
|
|
31
33
|
};
|
|
32
34
|
export const FirestoreApi = {
|
|
33
35
|
systemCollections,
|