@go-avro/avro-js 0.0.86 → 0.0.88

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.
@@ -82,6 +82,7 @@ AvroQueryClient.prototype.useCreateBill = function () {
82
82
  entityKey: 'bills',
83
83
  id: result.id,
84
84
  fetchPath: `/bill/${result.id}`,
85
+ construct: (d) => new Bill(d),
85
86
  });
86
87
  },
87
88
  onError: (_err, _variables, context) => {
@@ -131,6 +132,7 @@ AvroQueryClient.prototype.useUpdateBill = function () {
131
132
  entityKey: 'bills',
132
133
  id: billId,
133
134
  fetchPath: `/bill/${billId}`,
135
+ construct: (d) => new Bill(d),
134
136
  });
135
137
  },
136
138
  onError: (err, variables, context) => {
@@ -162,6 +164,7 @@ AvroQueryClient.prototype.useUpdateBillLineItemStatus = function () {
162
164
  entityKey: 'bills',
163
165
  id: billId,
164
166
  fetchPath: `/bill/${billId}`,
167
+ construct: (d) => new Bill(d),
165
168
  });
166
169
  // Item paid state also lives on the underlying events,
167
170
  // service months and prepayments
@@ -18,7 +18,6 @@ declare module '../../types/api/Bill' {
18
18
  invoice_id: number;
19
19
  intuit_id: string | null;
20
20
  name: string;
21
- amount: number;
22
21
  billed_by: string;
23
22
  customer_email: string | null;
24
23
  manual_emails: string[][];
@@ -31,7 +30,6 @@ declare module '../../types/api/Bill' {
31
30
  intent_created_at: number;
32
31
  intent_last_created_at: number;
33
32
  payments: BillPayment[];
34
- /** Every billable item on the bill, discriminated by line_item_type. */
35
33
  line_items: LineItem[];
36
34
  prepayments: string[];
37
35
  months: string[];
@@ -41,18 +39,13 @@ declare module '../../types/api/Bill' {
41
39
  }
42
40
  export declare class Bill {
43
41
  constructor(init?: Partial<Bill>);
44
- /** Every distinct job label across the bill's line items. */
42
+ total: () => number;
45
43
  labels: () => string[];
46
- /** Custom (and fee) rows only — the classic pre-unified view. */
47
44
  customItems: () => BillLineItem[];
48
- /** Top-level rows (parent_id null), in server order. */
49
45
  topLevelItems: () => LineItem[];
50
- /** Child rows of one line item, e.g. an event's additional charges. */
51
46
  childItems: (parentId: string) => LineItem[];
52
47
  }
53
- /** Line-item kinds addressable by PUT /bill/<id>/line-items/status. */
54
48
  export type BillLineItemStatusKind = 'event' | 'service_month' | 'prepayment' | 'line_item';
55
- /** One per-line-item paid/unpaid marking on a bill. */
56
49
  export interface BillLineItemStatusUpdate {
57
50
  type: BillLineItemStatusKind;
58
51
  id: string;
@@ -7,15 +7,15 @@ export const BillStatus = {
7
7
  };
8
8
  export class Bill {
9
9
  constructor(init) {
10
- /** Every distinct job label across the bill's line items. */
10
+ this.total = () => (this.line_items ?? []).reduce((sum, item) => {
11
+ const cost = item.line_item_type === 'EVENT' ? Math.max(item.cost, 0) : item.cost;
12
+ return sum + cost * (item.amount ?? 1);
13
+ }, 0);
11
14
  this.labels = () => [
12
15
  ...new Set((this.line_items ?? []).flatMap((item) => item.job_labels ?? [])),
13
16
  ];
14
- /** Custom (and fee) rows only — the classic pre-unified view. */
15
17
  this.customItems = () => (this.line_items ?? []).filter((item) => item.line_item_type === 'CUSTOM' || item.line_item_type === 'PROCESSING_FEE');
16
- /** Top-level rows (parent_id null), in server order. */
17
18
  this.topLevelItems = () => (this.line_items ?? []).filter((item) => !item.parent_id);
18
- /** Child rows of one line item, e.g. an event's additional charges. */
19
19
  this.childItems = (parentId) => (this.line_items ?? []).filter((item) => item.parent_id === parentId);
20
20
  Object.assign(this, init);
21
21
  if (init?.line_items) {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.0.86";
1
+ export declare const AVRO_JS_VERSION = "0.0.88";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // AUTO-GENERATED by scripts/gen-version.js — do not edit by hand.
2
2
  // Regenerated from package.json by the `prebuild` npm hook.
3
- export const AVRO_JS_VERSION = '0.0.86';
3
+ export const AVRO_JS_VERSION = '0.0.88';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.86",
3
+ "version": "0.0.88",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",