This repository has been archived by the owner on Oct 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Invoice.ts
157 lines (157 loc) · 3.79 KB
/
Invoice.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* Auto-generated file. Do not change.
*/
import { CompanyEntity } from './CompanyEntity'
import { CreditMemo } from './CreditMemo'
import { InvoiceItem } from './InvoiceItem'
import { Money } from './Money'
import { Type } from './Type'
import { ApiObjectRef } from '../types/ApiObjectRef'
import { linkObject } from '../links'
import { Option } from 'fp-ts/lib/Option'
import { ResolvableObject } from '../types/Link'
import { TypedApiObject } from '../types/TypedApiObject'
export enum InvoiceStatusTypes {
OUTSTANDING = 'outstanding',
PAST_DUE = 'past_due',
VOID = 'void',
PAID = 'paid',
PAYMENT_PENDING = 'payment_pending',
}
export enum InvoiceTypeTypes {
SHIPMENT = 'Shipment',
CLIENT = 'Client',
}
export type Invoice = {
/**
* Type of the object. Always '/invoice' for this object.
*/
readonly _object: Type.Invoice
/**
* Unique ID for the invoice
*
* JSON-schema: string
* @example "gwdpaYrhTI-T1ljn1M7o7w"
*/
readonly id?: string
/**
* Unique name for the invoice
*
* JSON-schema: string
* @example "FLEX-123456-1"
*/
readonly name?: string
/**
* When the invoice was issued
*
* JSON-schema: string (date-time)
* @example "2019-05-22T18:39:53.679Z"
*/
readonly issued_at?: string
/**
* Due date of the invoice
*
* JSON-schema: string (date)
* @example "2019-05-22"
*/
readonly due_date?: string
/**
* Sum of charges on the invoice
*
*/
readonly total?: Money
/**
* Outstanding balance on the invoice
*
*/
readonly balance?: Money
/**
* Status of the invoice
*
* JSON-schema: string
*/
readonly status?: InvoiceStatusTypes
/**
* What the invoice is being issued for. Shipment related charges are type `Shipment` and non-shipment related charges are type `Client`
*
* JSON-schema: string
*/
readonly type?: InvoiceTypeTypes
/**
* When the invoice was voided (if applicable)
*
* JSON-schema: string (date-time)
* @example "2019-05-22T20:49:15.639Z"
*/
readonly voided_at?: string
/**
* Time of the last adjustment to in invoice
*
* JSON-schema: string (date-time)
* @example "2019-05-22T20:49:15.639Z"
*/
readonly last_updated_at?: string
/**
* Entity receiving the invoice (i.e. the customer)
*
*/
readonly recipient?: CompanyEntity
/**
* Entity issuing the invoice (i.e. Flexport)
*
*/
readonly issuer?: CompanyEntity
/**
* JSON-schema: array
*/
readonly items?: InvoiceItem[]
/**
* JSON-schema: array
* @example "['Markdown formatted note 1', 'Markdown formatted note 2']"
*/
readonly notes?: string[]
/**
* List of any credits applied to this invoice.
*
* JSON-schema: array
*/
readonly credit_memos?: CreditMemo[]
/**
* Expandable link to shipment(s) related to this invoice.
*
*/
readonly shipments?: ApiObjectRef
}
export type LiftedInvoice = TypedApiObject &
Omit<Invoice, 'issued_at' | 'voided_at' | 'last_updated_at' | 'shipments'> & {
/**
* When the invoice was issued
*/
readonly issued_at?: Date
/**
* When the invoice was voided (if applicable)
*/
readonly voided_at?: Date
/**
* Time of the last adjustment to in invoice
*/
readonly last_updated_at?: Date
/**
* Expandable link to shipment(s) related to this invoice.
*/
readonly shipments: Option<ResolvableObject>
}
/**
* Lifts an object return from a Flexport API responses into the SDK domain by augmenting them with higher level properties.
*/
export const liftInvoice = (original: Invoice): LiftedInvoice => {
const { issued_at, voided_at, last_updated_at, shipments, ...rest } = original
return {
...rest,
issued_at: issued_at !== undefined ? new Date(issued_at) : undefined,
voided_at: voided_at !== undefined ? new Date(voided_at) : undefined,
last_updated_at:
last_updated_at !== undefined ? new Date(last_updated_at) : undefined,
shipments: linkObject(shipments),
}
}