conductor-node 0.0.5 → 0.0.8

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.
@@ -0,0 +1,152 @@
1
+ import type Client from "@conductor/client/Client";
2
+ import type {
3
+ AccountAdd,
4
+ AccountAddRs,
5
+ AccountQueryRq,
6
+ AccountQueryRs,
7
+ AccountRet,
8
+ } from "@conductor/client/qb/qbXMLTypes/Account";
9
+ import type {
10
+ EmployeeAdd,
11
+ EmployeeAddRs,
12
+ EmployeeMod,
13
+ EmployeeModRs,
14
+ EmployeeQueryRq,
15
+ EmployeeQueryRs,
16
+ EmployeeRet,
17
+ } from "@conductor/client/qb/qbXMLTypes/Employee";
18
+
19
+ export default class ClientQBD {
20
+ private readonly client: Client;
21
+
22
+ public constructor(rootClient: Client) {
23
+ this.client = rootClient;
24
+ }
25
+
26
+ public async sendRequest(
27
+ qbwcUsername: string,
28
+ requestObj: object
29
+ ): Promise<object> {
30
+ if (this.client.verbose) {
31
+ console.log(
32
+ `Client sent request for user ${qbwcUsername}:`,
33
+ JSON.stringify(requestObj, null, 2)
34
+ );
35
+ }
36
+
37
+ const response = await fetch("https://conductor.ngrok.io", {
38
+ body: JSON.stringify({ qbwcUsername, requestObj }),
39
+ headers: {
40
+ "Content-Type": "application/json",
41
+ Authorization: `Bearer ${this.client.apiKey}`,
42
+ },
43
+ method: "POST",
44
+ });
45
+ const responseObj = (await response.json()) as object;
46
+
47
+ if (this.client.verbose) {
48
+ console.log(
49
+ `Client received response for user ${qbwcUsername}:`,
50
+ JSON.stringify(responseObj, null, 2)
51
+ );
52
+ }
53
+
54
+ return responseObj;
55
+ }
56
+
57
+ // https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/qbdesktop/accountadd
58
+ public async accountAdd(
59
+ qbwcUsername: string,
60
+ params: AccountAdd
61
+ ): Promise<AccountRet> {
62
+ const response = (await this.sendRequest(qbwcUsername, {
63
+ AccountAddRq: { AccountAdd: params },
64
+ })) as { AccountAddRs: AccountAddRs };
65
+ const responseBody = response.AccountAddRs.AccountRet;
66
+ if (!responseBody) {
67
+ throw new Error("No response");
68
+ }
69
+ return responseBody;
70
+ }
71
+
72
+ /**
73
+ * `AccountQuery` is a list query that returns data for all accounts that match
74
+ * the provided filter criteria. Notice that it returns only data internal to
75
+ * the account itself. It does not return any data about transactions
76
+ * involving the account. It does, however, return the parent account, if
77
+ * there is one. You can search across all accounts or you can specify an
78
+ * account type and search only those.
79
+ *
80
+ * https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/qbdesktop/accountquery
81
+ */
82
+ public async accountQuery(
83
+ qbwcUsername: string,
84
+ params: AccountQueryRq
85
+ ): Promise<AccountRet> {
86
+ const response = (await this.sendRequest(qbwcUsername, {
87
+ AccountQueryRq: params,
88
+ })) as { AccountQueryRs: AccountQueryRs };
89
+ const responseBody = response.AccountQueryRs.AccountRet;
90
+ if (!responseBody) {
91
+ throw new Error("No response");
92
+ }
93
+ return responseBody;
94
+ }
95
+
96
+ /**
97
+ * Adds an employee with personal data about the employee as well as certain payroll-related data.
98
+ *
99
+ * https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/qbdesktop/employeeAdd
100
+ */
101
+ public async employeeAdd(
102
+ qbwcUsername: string,
103
+ params: EmployeeAdd
104
+ ): Promise<EmployeeRet> {
105
+ const response = (await this.sendRequest(qbwcUsername, {
106
+ EmployeeAddRq: { EmployeeAdd: params },
107
+ })) as { EmployeeAddRs: EmployeeAddRs };
108
+ const responseBody = response.EmployeeAddRs.EmployeeRet;
109
+ if (!responseBody) {
110
+ throw new Error("No response");
111
+ }
112
+ return responseBody;
113
+ }
114
+
115
+ /**
116
+ * Modifies an existing employee.
117
+ *
118
+ * https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/qbdesktop/employeemod
119
+ */
120
+ public async employeeMod(
121
+ qbwcUsername: string,
122
+ params: EmployeeMod
123
+ ): Promise<EmployeeRet> {
124
+ const response = (await this.sendRequest(qbwcUsername, {
125
+ EmployeeModRq: { EmployeeMod: params },
126
+ })) as { EmployeeModRs: EmployeeModRs };
127
+ const responseBody = response.EmployeeModRs.EmployeeRet;
128
+ if (!responseBody) {
129
+ throw new Error("No response");
130
+ }
131
+ return responseBody;
132
+ }
133
+
134
+ /**
135
+ * Returns employee data.
136
+ *
137
+ * https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/qbdesktop/employeeQuery
138
+ */
139
+ public async employeeQuery(
140
+ qbwcUsername: string,
141
+ params: EmployeeQueryRq
142
+ ): Promise<EmployeeRet> {
143
+ const response = (await this.sendRequest(qbwcUsername, {
144
+ EmployeeQueryRq: params,
145
+ })) as { EmployeeQueryRs: EmployeeQueryRs };
146
+ const responseBody = response.EmployeeQueryRs.EmployeeRet;
147
+ if (!responseBody) {
148
+ throw new Error("No response");
149
+ }
150
+ return responseBody;
151
+ }
152
+ }
@@ -0,0 +1,325 @@
1
+ import type {
2
+ ActiveStatus,
3
+ DataExtRet,
4
+ NameFilter,
5
+ NameRangeFilter,
6
+ } from "@conductor/client/qb/qbXMLTypes/shared";
7
+
8
+ // https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/qbdesktop/accountadd
9
+ export interface AccountAddRq {
10
+ AccountAdd: AccountAdd;
11
+ IncludeRetElement?: string;
12
+ }
13
+
14
+ export interface AccountAddRs {
15
+ // TODO: Confirm whether this is an array or not.
16
+ AccountRet?: AccountRet;
17
+ }
18
+
19
+ export interface AccountAdd {
20
+ /**
21
+ * The case-insensitive name of a list object, not including the names of its
22
+ * ancestors. Name must be unique, unless it is the Name of a “hierarchical”
23
+ * list object. List objects in different hierarchies can have duplicate names
24
+ * because their FullNames will still be unique. For example, two objects
25
+ * could both have the Name kitchen, but they could have unique FullNames,
26
+ * such as Job12:kitchen and Baker:kitchen. For built-in currencies, Name is
27
+ * the internationally accepted currency name and is not editable.
28
+ */
29
+ Name: string;
30
+ /**
31
+ * If `IsActive` is `true`, this object is currently enabled for use by
32
+ * QuickBooks. The default value is `true`.
33
+ */
34
+ IsActive?: boolean;
35
+ /**
36
+ * A reference to the list object that is one level above this one. For
37
+ * example, an inventory item with the `FullName` of
38
+ * `GermanCars:Mercedes-Benz:CL500I99AA` might have a parent object with the
39
+ * `FullName` of `GermanCars:Mercedes-Benz`. In a request, if a `ParentRef`
40
+ * aggregate includes both `FullName` and `ListID`, `FullName` will be
41
+ * ignored.
42
+ */
43
+ ParentRef?: ParentRef;
44
+ /**
45
+ * The type of QuickBooks account. You cannot create or modify a non-posting
46
+ * account through the SDK, because QuickBooks creates these accounts behind
47
+ * the scenes. This means that you cannot send an AccountAdd request with an
48
+ * AccountType of NonPosting.
49
+ */
50
+ AccountType: AccountType;
51
+ /**
52
+ * Account numbers appear in the QuickBooks chart of accounts, Account fields,
53
+ * and reports and graphs. If the `IsUsingAccountNumber` preference is `false`
54
+ * (that is, if the QuickBooks user has the account numbers Preference turned
55
+ * off), you can still set account numbers through the SDK, but the numbers
56
+ * will not be visible in the user interface.
57
+ */
58
+ AccountNumber?: string;
59
+ /**
60
+ * The bank account number or an identifying note about the account. If a
61
+ * `BankNumber` exists in a QuickBooks company file, it will only be returned
62
+ * to applications that have been granted permission to access sensitive data
63
+ * and that are using SDK v2.0 or greater.
64
+ */
65
+ BankNumber?: string;
66
+ /**
67
+ * A descriptive text field.
68
+ */
69
+ Desc?: string;
70
+ /**
71
+ * The amount of money in, or the value of, this account as of
72
+ * `OpenBalanceDate`. On a bank statement, the amount of money in the account
73
+ * at the beginning of the statement period.
74
+ */
75
+ OpenBalance?: string;
76
+ /**
77
+ * The date when an opening balance was entered for this account.
78
+ */
79
+ OpenBalanceDate?: Date;
80
+ /**
81
+ * Each item on a sales form is assigned a sales-tax code that indicates
82
+ * whether the item is taxable or non-taxable, and why. Two general codes,
83
+ * which can be modified but not deleted, appear on the sales-tax code list by
84
+ * default: `Non-taxable (Name = NON; Desc = Non-Taxable; IsTaxable = false)`,
85
+ * `Taxable (Name = TAX; Desc = Taxable; IsTaxable = true)`. A sales-tax code
86
+ * can be deleted only if it is no longer associated with any customer, item,
87
+ * or transaction. If the “Do You Charge Sales Tax?” preference within
88
+ * QuickBooks is set to No, QuickBooks will assign the default non-taxable
89
+ * sales-tax code to all sales. A `SalesTaxCodeRef` aggregate refers to a
90
+ * sales-tax code on the list. In a request, if a `SalesTaxCodeRef` aggregate
91
+ * includes both FullName and `ListID`, FullName will be ignored. In a
92
+ * Customer message, `SalesTaxCodeRef` refers to the sales-tax code that will
93
+ * be used for items related to this customer. In an ItemInventory message,
94
+ * `SalesTaxCodeRef` refers to the type of sales tax that will be charged for
95
+ * this item, if it is a taxable item and if sales tax is set up within
96
+ * QuickBooks.
97
+ */
98
+ SalesTaxCodeRef?: SalesTaxCodeRef;
99
+ /**
100
+ * An internal representation of the tax line associated with this account.
101
+ */
102
+ TaxLineID?: number;
103
+ /**
104
+ * The currency object contains all of the information needed by QuickBooks to
105
+ * display and use. For built-in currencies, the name and currency code values
106
+ * are internationally accepted values and thus are not editable. The comma
107
+ * format is editable, as is the IsActive status. For user-defined currencies,
108
+ * every value in the object is editable including name and currency code.
109
+ * When used with PriceLevels, the CurrencyRef should only be used with “per
110
+ * item” price levels.
111
+ */
112
+ CurrencyRef?: CurrencyRef;
113
+ }
114
+
115
+ // https://developer.intuit.com/app/developer/qbdesktop/docs/api-reference/qbdesktop/accountquery
116
+ // FIXME: This does not account for the use of "OR" and "may repeat" in the
117
+ // XMLOps, which might indicate using an array.
118
+ export interface AccountQueryRq {
119
+ ListID?: string;
120
+ FullName?: string;
121
+ /**
122
+ * Limits the number of objects that a query returns. (To get a count of how
123
+ * many objects could possibly be returned, use the metaData query attribute.)
124
+ * If you include a `MaxReturned` value, it must be at least 1.
125
+ */
126
+ MaxReturned?: number;
127
+ /**
128
+ * Used in filters to select list objects based on whether or not they are
129
+ * currently enabled for use by QuickBooks. The default value is `ActiveOnly`,
130
+ * which selects only list objects that are active.
131
+ */
132
+ ActiveStatus?: ActiveStatus;
133
+ FromModifiedDate?: Date;
134
+ ToModifiedDate?: Date;
135
+ /**
136
+ * Filters according to the object’s `Name`.
137
+ */
138
+ NameFilter?: NameFilter;
139
+ /**
140
+ * Filters according to the object’s `Name`.
141
+ */
142
+ NameRangeFilter?: NameRangeFilter;
143
+ AccountType?: AccountType;
144
+ CurrencyFilter?: CurrencyFilter;
145
+ }
146
+
147
+ export interface AccountQueryRs {
148
+ // TODO: Confirm whether this is an array or not.
149
+ AccountRet?: AccountRet;
150
+ }
151
+
152
+ export interface AccountRet {
153
+ /**
154
+ * Along with `FullName`, `ListID` is a way to identify a list object. When a
155
+ * list object is added to QuickBooks through the SDK or through the
156
+ * QuickBooks user interface, the server assigns it a `ListID`. A `ListID` is
157
+ * not unique across lists, but it is unique across each particular type of
158
+ * list. For example, two customers could not have the same `ListID`, and a
159
+ * customer could not have the same `ListID` as an employee (because Customer
160
+ * and Employee are both name lists). But a customer could have the same
161
+ * `ListID` as a non-inventory item.
162
+ */
163
+ ListID: string;
164
+ /**
165
+ * Time the object was created.
166
+ */
167
+ TimeCreated: string;
168
+ /**
169
+ * Time the object was last modified.
170
+ */
171
+ TimeModified: string;
172
+ /**
173
+ * A number that the server generates and assigns to this object. Every time
174
+ * the object is changed, the server will change its `EditSequence` value.
175
+ * When you try to modify a list object, you must provide its `EditSequence`.
176
+ * The server compares the `EditSequence` you provide with the `EditSequence`
177
+ * in memory to make sure you are dealing with the latest copy of the object.
178
+ * If you are not, the server will reject the request and return an error.
179
+ * Because `EditSequence` is only used to check whether two objects match,
180
+ * there is no reason to interpret its value.
181
+ */
182
+ EditSequence: string;
183
+ /**
184
+ * The case-insensitive name of a list object, not including the names of its
185
+ * ancestors. `Name` must be unique, unless it is the `Name` of a
186
+ * “hierarchical” list object. List objects in different hierarchies can have
187
+ * duplicate names because their `FullNames` will still be unique. For
188
+ * example, two objects could both have the `Name` kitchen, but they could
189
+ * have unique `FullNames`, such as Job12:kitchen and Baker:kitchen. For
190
+ * built-in currencies, `Name` is the internationally accepted currency name
191
+ * and is not editable.
192
+ */
193
+ Name: string;
194
+ /**
195
+ * `FullName` (along with `ListID`) is a way to identify a list object. The
196
+ * `FullName` is the name prefixed by the names of each ancestor, for example
197
+ * `Jones:Kitchen:Cabinets`. `FullName` values are not case-sensitive.
198
+ */
199
+ FullName: string;
200
+ /**
201
+ * If `IsActive` is true, this object is currently enabled for use by
202
+ * QuickBooks. The default value is `true`.
203
+ */
204
+ IsActive?: boolean;
205
+ /**
206
+ * A reference to the list object that is one level above this one. For
207
+ * example, an inventory item with the `FullName` of
208
+ * `GermanCars:Mercedes-Benz:CL500I99AA` might have a parent object with the
209
+ * `FullName` of `GermanCars:Mercedes-Benz`. In a request, if a `ParentRef`
210
+ * aggregate includes both `FullName` and `ListID`, `FullName` will be
211
+ * ignored.
212
+ */
213
+ ParentRef?: ParentRef;
214
+ /**
215
+ * The number of ancestors. For example, The customer job with `Name =
216
+ * carpets` and `FullName = Jones:Building2:carpets` would have a sublevel of
217
+ * 2.
218
+ */
219
+ Sublevel: number;
220
+ /**
221
+ * The type of QuickBooks account. You cannot create or modify a non-posting
222
+ * account through the SDK, because QuickBooks creates these accounts behind
223
+ * the scenes. This means that you cannot send an `AccountAdd` request with an
224
+ * `AccountType` of `NonPosting`.
225
+ */
226
+ AccountType: AccountType;
227
+ /**
228
+ * If `SpecialAccountType` returns a value, then QuickBooks automatically
229
+ * created this account when it was needed. Some special accounts cannot be
230
+ * overridden, because QuickBooks uses them exclusively for special purposes.
231
+ */
232
+ SpecialAccountType?: SpecialAccountType;
233
+ /**
234
+ * Indicates whether the account is used for tax.
235
+ */
236
+ IsTaxAccount?: boolean;
237
+ /**
238
+ * Account numbers appear in the QuickBooks chart of accounts, `Account`
239
+ * fields, and reports and graphs. If the `IsUsingAccountNumber` preference is
240
+ * false (that is, if the QuickBooks user has the account numbers Preference
241
+ * turned off), you can still set account numbers through the SDK, but the
242
+ * numbers will not be visible in the user interface.
243
+ */
244
+ AccountNumber?: string;
245
+ BankNumber?: string;
246
+ Desc?: string;
247
+ Balance?: string;
248
+ TotalBalance?: string;
249
+ SalesTaxCodeRef?: SalesTaxCodeRef;
250
+ TaxLineInfoRet?: {
251
+ TaxLineID: number;
252
+ TaxLineName?: string;
253
+ };
254
+ CashFlowClassification?: CashFlowClassification;
255
+ CurrencyRef?: CurrencyRef;
256
+ DataExtRet?: DataExtRet;
257
+ }
258
+
259
+ interface CurrencyFilter {
260
+ ListID?: string;
261
+ FullName?: string;
262
+ }
263
+
264
+ interface ParentRef {
265
+ ListID?: string;
266
+ FullName?: string;
267
+ }
268
+
269
+ interface SalesTaxCodeRef {
270
+ ListID?: string;
271
+ FullName?: string;
272
+ }
273
+
274
+ interface CurrencyRef {
275
+ ListID?: string;
276
+ FullName?: string;
277
+ }
278
+
279
+ type AccountType =
280
+ | "AccountsPayable"
281
+ | "AccountsReceivable"
282
+ | "Bank"
283
+ | "CostOfGoodsSold"
284
+ | "CreditCard"
285
+ | "Equity"
286
+ | "Expense"
287
+ | "FixedAsset"
288
+ | "Income"
289
+ | "LongTermLiability"
290
+ | "NonPosting"
291
+ | "OtherAsset"
292
+ | "OtherCurrentAsset"
293
+ | "OtherCurrentLiability"
294
+ | "OtherExpense"
295
+ | "OtherIncome";
296
+
297
+ type SpecialAccountType =
298
+ | "AccountsPayable"
299
+ | "AccountsReceivable"
300
+ | "CondenseItemAdjustmentExpenses"
301
+ | "CostOfGoodsSold"
302
+ | "DirectDepositLiabilities"
303
+ | "Estimates"
304
+ | "ExchangeGainLoss"
305
+ | "InventoryAssets"
306
+ | "ItemReceiptAccount"
307
+ | "OpeningBalanceEquity"
308
+ | "PayrollExpenses"
309
+ | "PayrollLiabilities"
310
+ | "PettyCash"
311
+ | "PurchaseOrders"
312
+ | "ReconciliationDifferences"
313
+ | "RetainedEarnings"
314
+ | "SalesOrders"
315
+ | "SalesTaxPayable"
316
+ | "UncategorizedExpenses"
317
+ | "UncategorizedIncome"
318
+ | "UndepositedFunds";
319
+
320
+ type CashFlowClassification =
321
+ | "Financing"
322
+ | "Investing"
323
+ | "None"
324
+ | "NotApplicable"
325
+ | "Operating";