@unifetch/fortnox 1.0.1 → 2.0.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/README.md +43 -12
- package/dist/create-fortnox-BRQXlzrc.cjs +1723 -0
- package/dist/create-fortnox-BRQXlzrc.cjs.map +1 -0
- package/dist/create-fortnox-CIWMiQTF.d.mts +1698 -0
- package/dist/create-fortnox-CIWMiQTF.d.mts.map +1 -0
- package/dist/create-fortnox-CSULrMkm.mjs +1717 -0
- package/dist/create-fortnox-CSULrMkm.mjs.map +1 -0
- package/dist/create-fortnox-D9a-YhJ-.d.cts +1698 -0
- package/dist/create-fortnox-D9a-YhJ-.d.cts.map +1 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/{official-Bkifkma6.d.cts → official-COyUx9dP.d.cts} +15 -52
- package/dist/official-COyUx9dP.d.cts.map +1 -0
- package/dist/{official-DAMVj0tE.d.mts → official-Lpmk8gr7.d.mts} +15 -52
- package/dist/official-Lpmk8gr7.d.mts.map +1 -0
- package/dist/official.cjs +2 -70
- package/dist/official.cjs.map +1 -1
- package/dist/official.d.cts +2 -2
- package/dist/official.d.mts +2 -2
- package/dist/official.mjs +3 -70
- package/dist/official.mjs.map +1 -1
- package/dist/patched.cjs +2 -70
- package/dist/patched.cjs.map +1 -1
- package/dist/patched.d.cts +14 -51
- package/dist/patched.d.cts.map +1 -1
- package/dist/patched.d.mts +14 -51
- package/dist/patched.d.mts.map +1 -1
- package/dist/patched.mjs +3 -70
- package/dist/patched.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/official-Bkifkma6.d.cts.map +0 -1
- package/dist/official-DAMVj0tE.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @unifetch/fortnox
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for the [Fortnox](https://
|
|
3
|
+
TypeScript SDK for the [Fortnox API](https://api.fortnox.se/apidocs), fully typed from the official OpenAPI specification — with corrections applied where the spec has incorrect or overly permissive types.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -44,26 +44,31 @@ const fortnox = initFortnox({
|
|
|
44
44
|
|
|
45
45
|
## Usage
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
Every response is a discriminated union of `{ error: null; data: T }` or `{ error: ErrorResponse; data: null }`. Once you handle (or narrow) the error branch, TypeScript automatically infers that `data` is non-null.
|
|
48
|
+
|
|
49
|
+
There are two ways to call the API.
|
|
50
|
+
|
|
51
|
+
### Resource-based API (recommended)
|
|
52
|
+
|
|
53
|
+
Access resources by name and call operations by their ID. Both the resource name and operation ID are autocompleted by TypeScript.
|
|
54
|
+
|
|
55
|
+
> **Note:** The operation names (e.g. `getList`, `create`, `bookkeep`) are **manually curated** and are not derived from the official Fortnox OpenAPI specification. The official spec uses operation ids that are inconsistent and ambiguous across endpoints. The names used here follow a consistent, human-readable convention defined in [`overrides/operation-ids.json`](overrides/operation-ids.json).
|
|
48
56
|
|
|
49
57
|
```ts
|
|
50
|
-
const { data, error } = await fortnox
|
|
58
|
+
const { data, error } = await fortnox.invoices.getList();
|
|
51
59
|
|
|
52
60
|
if (error) {
|
|
53
61
|
console.error(error.ErrorInformation.message);
|
|
54
|
-
// or handle the error some other way
|
|
55
62
|
} else {
|
|
56
63
|
// data is non-null here — TypeScript knows this after the error check
|
|
57
64
|
console.log(data.Invoices);
|
|
58
65
|
}
|
|
59
66
|
```
|
|
60
67
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
### With query parameters
|
|
68
|
+
#### With query parameters
|
|
64
69
|
|
|
65
70
|
```ts
|
|
66
|
-
const { data, error } = await fortnox
|
|
71
|
+
const { data, error } = await fortnox.invoices.getList({
|
|
67
72
|
query: { fromdate: "2024-01-01", todate: "2024-12-31" },
|
|
68
73
|
});
|
|
69
74
|
|
|
@@ -74,10 +79,10 @@ for (const invoice of data.Invoices) {
|
|
|
74
79
|
}
|
|
75
80
|
```
|
|
76
81
|
|
|
77
|
-
|
|
82
|
+
#### Creating a resource
|
|
78
83
|
|
|
79
84
|
```ts
|
|
80
|
-
const { data, error } = await fortnox
|
|
85
|
+
const { data, error } = await fortnox.invoices.create({
|
|
81
86
|
body: {
|
|
82
87
|
Invoice: {
|
|
83
88
|
CustomerNumber: "1",
|
|
@@ -93,10 +98,10 @@ if (error) throw error;
|
|
|
93
98
|
console.log(data.Invoice.DocumentNumber);
|
|
94
99
|
```
|
|
95
100
|
|
|
96
|
-
|
|
101
|
+
#### Fetching a single resource by ID
|
|
97
102
|
|
|
98
103
|
```ts
|
|
99
|
-
const { data, error } = await fortnox
|
|
104
|
+
const { data, error } = await fortnox.invoices.get({
|
|
100
105
|
params: { DocumentNumber: "100" },
|
|
101
106
|
});
|
|
102
107
|
|
|
@@ -105,6 +110,32 @@ if (error) throw error;
|
|
|
105
110
|
console.log(data.Invoice.CustomerName);
|
|
106
111
|
```
|
|
107
112
|
|
|
113
|
+
#### Calling an action on a resource
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
const { data, error } = await fortnox.invoices.bookkeep({
|
|
117
|
+
params: { DocumentNumber: "100" },
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Path-based API
|
|
122
|
+
|
|
123
|
+
If you want to access an endpoint directly by its raw path, use `fortnox.path()`. This is equivalent to the resource-based API under the hood. The path and all the parameters are fully typed.
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
const { data, error } = await fortnox.path("/3/invoices").get();
|
|
127
|
+
|
|
128
|
+
if (error) throw error;
|
|
129
|
+
|
|
130
|
+
console.log(data.Invoices);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
const { data, error } = await fortnox.path("/3/invoices/{DocumentNumber}").get({
|
|
135
|
+
params: { DocumentNumber: "100" },
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
108
139
|
## Type definitions
|
|
109
140
|
|
|
110
141
|
### `@unifetch/fortnox` (default) — patched types
|