@unifetch/fortnox 1.0.0 → 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 +181 -0
- 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-routes-CO9qO54b.d.mts → official-COyUx9dP.d.cts} +20 -4
- package/dist/official-COyUx9dP.d.cts.map +1 -0
- package/dist/{official-routes-UGPWNmls.d.cts → official-Lpmk8gr7.d.mts} +20 -4
- 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 -57
- package/dist/official.d.mts +2 -57
- 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 +12388 -51
- package/dist/patched.d.cts.map +1 -1
- package/dist/patched.d.mts +12388 -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 +3 -2
- package/dist/official-routes-CO9qO54b.d.mts.map +0 -1
- package/dist/official-routes-UGPWNmls.d.cts.map +0 -1
- package/dist/official.d.cts.map +0 -1
- package/dist/official.d.mts.map +0 -1
package/dist/official.cjs
CHANGED
|
@@ -1,76 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_create_fortnox = require('./create-fortnox-BRQXlzrc.cjs');
|
|
2
3
|
|
|
3
4
|
//#region src/official.ts
|
|
4
|
-
const
|
|
5
|
-
"get",
|
|
6
|
-
"post",
|
|
7
|
-
"put",
|
|
8
|
-
"delete",
|
|
9
|
-
"patch"
|
|
10
|
-
];
|
|
11
|
-
async function request(reqOptions, initOptions) {
|
|
12
|
-
try {
|
|
13
|
-
let headers;
|
|
14
|
-
let baseUrl;
|
|
15
|
-
if ("accessToken" in initOptions) {
|
|
16
|
-
headers = { Authorization: `Bearer ${initOptions.accessToken}` };
|
|
17
|
-
baseUrl = "https://api.fortnox.se";
|
|
18
|
-
} else {
|
|
19
|
-
headers = {
|
|
20
|
-
"x-api-key": initOptions.proxy.apiKey,
|
|
21
|
-
"x-tenant-id": initOptions.proxy.tenantId
|
|
22
|
-
};
|
|
23
|
-
baseUrl = initOptions.proxy.baseUrl;
|
|
24
|
-
}
|
|
25
|
-
const searchParams = new URLSearchParams();
|
|
26
|
-
if (reqOptions.query) Object.entries(reqOptions.query).forEach(([key, value]) => {
|
|
27
|
-
searchParams.append(key, String(value));
|
|
28
|
-
});
|
|
29
|
-
let path = reqOptions.path;
|
|
30
|
-
if (reqOptions.params) Object.entries(reqOptions.params).forEach(([key, value]) => {
|
|
31
|
-
path = path.replace(`{${key}}`, encodeURIComponent(String(value)));
|
|
32
|
-
});
|
|
33
|
-
const url = `${baseUrl}${path}${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`;
|
|
34
|
-
const response = await fetch(url, {
|
|
35
|
-
method: reqOptions.method.toUpperCase(),
|
|
36
|
-
body: reqOptions.body ? JSON.stringify(reqOptions.body) : null,
|
|
37
|
-
headers
|
|
38
|
-
});
|
|
39
|
-
const responseData = await response.json();
|
|
40
|
-
if (response.status < 300) return {
|
|
41
|
-
error: null,
|
|
42
|
-
data: responseData
|
|
43
|
-
};
|
|
44
|
-
else return {
|
|
45
|
-
error: {
|
|
46
|
-
ErrorSource: "fortnox",
|
|
47
|
-
ErrorInformation: responseData.ErrorInformation
|
|
48
|
-
},
|
|
49
|
-
data: null
|
|
50
|
-
};
|
|
51
|
-
} catch (e) {
|
|
52
|
-
return {
|
|
53
|
-
error: {
|
|
54
|
-
ErrorSource: "unknown",
|
|
55
|
-
ErrorInformation: {
|
|
56
|
-
message: e instanceof Error ? e.message : String(e),
|
|
57
|
-
error: -1,
|
|
58
|
-
code: -1
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
data: null
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function initFortnox(initOptions) {
|
|
66
|
-
return function fortnox(path) {
|
|
67
|
-
return Object.fromEntries(METHODS.map((method) => [method, (options) => request({
|
|
68
|
-
path,
|
|
69
|
-
method,
|
|
70
|
-
...options
|
|
71
|
-
}, initOptions)]));
|
|
72
|
-
};
|
|
73
|
-
}
|
|
5
|
+
const initFortnox = require_create_fortnox.createInitFortnox();
|
|
74
6
|
|
|
75
7
|
//#endregion
|
|
76
8
|
exports.initFortnox = initFortnox;
|
package/dist/official.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"official.cjs","names":[],"sources":["../src/official.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"official.cjs","names":["createInitFortnox"],"sources":["../src/official.ts"],"sourcesContent":["import { createInitFortnox } from \"./create-fortnox\";\r\nimport type { Routes } from \"./types/official-routes.gen\";\r\n\r\nexport const initFortnox = createInitFortnox<Routes>();\r\n"],"mappings":";;;;AAGA,MAAa,cAAcA,0CAA2B"}
|
package/dist/official.d.cts
CHANGED
|
@@ -1,57 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
//#region src/official.d.ts
|
|
4
|
-
type ErrorResponse = {
|
|
5
|
-
ErrorSource: "fortnox" | "unknown";
|
|
6
|
-
ErrorInformation: {
|
|
7
|
-
error: number;
|
|
8
|
-
message: string;
|
|
9
|
-
code: number;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
type InitFortnoxOptions = {
|
|
13
|
-
accessToken: string;
|
|
14
|
-
} | {
|
|
15
|
-
proxy: {
|
|
16
|
-
baseUrl: string;
|
|
17
|
-
apiKey: string;
|
|
18
|
-
tenantId: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
type FortnoxInput<TPath extends keyof Routes, TMethod extends keyof Routes[TPath]> = Routes[TPath][TMethod] extends {
|
|
22
|
-
request: infer R;
|
|
23
|
-
} ? R : never;
|
|
24
|
-
type OmitNever<T> = { [K in keyof T as T[K] extends never ? never : K]: T[K] };
|
|
25
|
-
type FortnoxInputCleaned<TPath extends keyof Routes, TMethod extends keyof Routes[TPath]> = OmitNever<FortnoxInput<TPath, TMethod>>;
|
|
26
|
-
type FortnoxOutput<TPath extends keyof Routes, TMethod extends keyof Routes[TPath]> = Routes[TPath][TMethod] extends {
|
|
27
|
-
response: {
|
|
28
|
-
body: infer B;
|
|
29
|
-
};
|
|
30
|
-
} ? B : never;
|
|
31
|
-
type FortnoxResult<TData> = Promise<{
|
|
32
|
-
error: ErrorResponse;
|
|
33
|
-
data: null;
|
|
34
|
-
} | {
|
|
35
|
-
error: null;
|
|
36
|
-
data: TData;
|
|
37
|
-
}>;
|
|
38
|
-
type FortnoxMethods<TPath extends keyof Routes> = { [TMethod in keyof Routes[TPath]]: Routes[TPath][TMethod] extends {
|
|
39
|
-
request: {
|
|
40
|
-
params: never;
|
|
41
|
-
body: never;
|
|
42
|
-
};
|
|
43
|
-
} ? (options?: FortnoxInputCleaned<TPath, TMethod>) => FortnoxResult<FortnoxOutput<TPath, TMethod>> : (options: FortnoxInputCleaned<TPath, TMethod>) => FortnoxResult<FortnoxOutput<TPath, TMethod>> };
|
|
44
|
-
type FortnoxFn = <TPath extends keyof Routes>(path: TPath) => FortnoxMethods<TPath>;
|
|
45
|
-
declare function initFortnox(options: {
|
|
46
|
-
accessToken: string;
|
|
47
|
-
}): FortnoxFn;
|
|
48
|
-
declare function initFortnox(options: {
|
|
49
|
-
proxy: {
|
|
50
|
-
baseUrl: string;
|
|
51
|
-
apiKey: string;
|
|
52
|
-
tenantId: string;
|
|
53
|
-
};
|
|
54
|
-
}): FortnoxFn;
|
|
55
|
-
//#endregion
|
|
56
|
-
export { InitFortnoxOptions, initFortnox };
|
|
57
|
-
//# sourceMappingURL=official.d.cts.map
|
|
1
|
+
import { t as initFortnox } from "./official-COyUx9dP.cjs";
|
|
2
|
+
export { initFortnox };
|
package/dist/official.d.mts
CHANGED
|
@@ -1,57 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
//#region src/official.d.ts
|
|
4
|
-
type ErrorResponse = {
|
|
5
|
-
ErrorSource: "fortnox" | "unknown";
|
|
6
|
-
ErrorInformation: {
|
|
7
|
-
error: number;
|
|
8
|
-
message: string;
|
|
9
|
-
code: number;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
type InitFortnoxOptions = {
|
|
13
|
-
accessToken: string;
|
|
14
|
-
} | {
|
|
15
|
-
proxy: {
|
|
16
|
-
baseUrl: string;
|
|
17
|
-
apiKey: string;
|
|
18
|
-
tenantId: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
type FortnoxInput<TPath extends keyof Routes, TMethod extends keyof Routes[TPath]> = Routes[TPath][TMethod] extends {
|
|
22
|
-
request: infer R;
|
|
23
|
-
} ? R : never;
|
|
24
|
-
type OmitNever<T> = { [K in keyof T as T[K] extends never ? never : K]: T[K] };
|
|
25
|
-
type FortnoxInputCleaned<TPath extends keyof Routes, TMethod extends keyof Routes[TPath]> = OmitNever<FortnoxInput<TPath, TMethod>>;
|
|
26
|
-
type FortnoxOutput<TPath extends keyof Routes, TMethod extends keyof Routes[TPath]> = Routes[TPath][TMethod] extends {
|
|
27
|
-
response: {
|
|
28
|
-
body: infer B;
|
|
29
|
-
};
|
|
30
|
-
} ? B : never;
|
|
31
|
-
type FortnoxResult<TData> = Promise<{
|
|
32
|
-
error: ErrorResponse;
|
|
33
|
-
data: null;
|
|
34
|
-
} | {
|
|
35
|
-
error: null;
|
|
36
|
-
data: TData;
|
|
37
|
-
}>;
|
|
38
|
-
type FortnoxMethods<TPath extends keyof Routes> = { [TMethod in keyof Routes[TPath]]: Routes[TPath][TMethod] extends {
|
|
39
|
-
request: {
|
|
40
|
-
params: never;
|
|
41
|
-
body: never;
|
|
42
|
-
};
|
|
43
|
-
} ? (options?: FortnoxInputCleaned<TPath, TMethod>) => FortnoxResult<FortnoxOutput<TPath, TMethod>> : (options: FortnoxInputCleaned<TPath, TMethod>) => FortnoxResult<FortnoxOutput<TPath, TMethod>> };
|
|
44
|
-
type FortnoxFn = <TPath extends keyof Routes>(path: TPath) => FortnoxMethods<TPath>;
|
|
45
|
-
declare function initFortnox(options: {
|
|
46
|
-
accessToken: string;
|
|
47
|
-
}): FortnoxFn;
|
|
48
|
-
declare function initFortnox(options: {
|
|
49
|
-
proxy: {
|
|
50
|
-
baseUrl: string;
|
|
51
|
-
apiKey: string;
|
|
52
|
-
tenantId: string;
|
|
53
|
-
};
|
|
54
|
-
}): FortnoxFn;
|
|
55
|
-
//#endregion
|
|
56
|
-
export { InitFortnoxOptions, initFortnox };
|
|
57
|
-
//# sourceMappingURL=official.d.mts.map
|
|
1
|
+
import { t as initFortnox } from "./official-Lpmk8gr7.mjs";
|
|
2
|
+
export { initFortnox };
|
package/dist/official.mjs
CHANGED
|
@@ -1,74 +1,7 @@
|
|
|
1
|
+
import { t as createInitFortnox } from "./create-fortnox-CSULrMkm.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/official.ts
|
|
2
|
-
const
|
|
3
|
-
"get",
|
|
4
|
-
"post",
|
|
5
|
-
"put",
|
|
6
|
-
"delete",
|
|
7
|
-
"patch"
|
|
8
|
-
];
|
|
9
|
-
async function request(reqOptions, initOptions) {
|
|
10
|
-
try {
|
|
11
|
-
let headers;
|
|
12
|
-
let baseUrl;
|
|
13
|
-
if ("accessToken" in initOptions) {
|
|
14
|
-
headers = { Authorization: `Bearer ${initOptions.accessToken}` };
|
|
15
|
-
baseUrl = "https://api.fortnox.se";
|
|
16
|
-
} else {
|
|
17
|
-
headers = {
|
|
18
|
-
"x-api-key": initOptions.proxy.apiKey,
|
|
19
|
-
"x-tenant-id": initOptions.proxy.tenantId
|
|
20
|
-
};
|
|
21
|
-
baseUrl = initOptions.proxy.baseUrl;
|
|
22
|
-
}
|
|
23
|
-
const searchParams = new URLSearchParams();
|
|
24
|
-
if (reqOptions.query) Object.entries(reqOptions.query).forEach(([key, value]) => {
|
|
25
|
-
searchParams.append(key, String(value));
|
|
26
|
-
});
|
|
27
|
-
let path = reqOptions.path;
|
|
28
|
-
if (reqOptions.params) Object.entries(reqOptions.params).forEach(([key, value]) => {
|
|
29
|
-
path = path.replace(`{${key}}`, encodeURIComponent(String(value)));
|
|
30
|
-
});
|
|
31
|
-
const url = `${baseUrl}${path}${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`;
|
|
32
|
-
const response = await fetch(url, {
|
|
33
|
-
method: reqOptions.method.toUpperCase(),
|
|
34
|
-
body: reqOptions.body ? JSON.stringify(reqOptions.body) : null,
|
|
35
|
-
headers
|
|
36
|
-
});
|
|
37
|
-
const responseData = await response.json();
|
|
38
|
-
if (response.status < 300) return {
|
|
39
|
-
error: null,
|
|
40
|
-
data: responseData
|
|
41
|
-
};
|
|
42
|
-
else return {
|
|
43
|
-
error: {
|
|
44
|
-
ErrorSource: "fortnox",
|
|
45
|
-
ErrorInformation: responseData.ErrorInformation
|
|
46
|
-
},
|
|
47
|
-
data: null
|
|
48
|
-
};
|
|
49
|
-
} catch (e) {
|
|
50
|
-
return {
|
|
51
|
-
error: {
|
|
52
|
-
ErrorSource: "unknown",
|
|
53
|
-
ErrorInformation: {
|
|
54
|
-
message: e instanceof Error ? e.message : String(e),
|
|
55
|
-
error: -1,
|
|
56
|
-
code: -1
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
data: null
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function initFortnox(initOptions) {
|
|
64
|
-
return function fortnox(path) {
|
|
65
|
-
return Object.fromEntries(METHODS.map((method) => [method, (options) => request({
|
|
66
|
-
path,
|
|
67
|
-
method,
|
|
68
|
-
...options
|
|
69
|
-
}, initOptions)]));
|
|
70
|
-
};
|
|
71
|
-
}
|
|
4
|
+
const initFortnox = createInitFortnox();
|
|
72
5
|
|
|
73
6
|
//#endregion
|
|
74
7
|
export { initFortnox };
|
package/dist/official.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"official.mjs","names":[],"sources":["../src/official.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"official.mjs","names":[],"sources":["../src/official.ts"],"sourcesContent":["import { createInitFortnox } from \"./create-fortnox\";\r\nimport type { Routes } from \"./types/official-routes.gen\";\r\n\r\nexport const initFortnox = createInitFortnox<Routes>();\r\n"],"mappings":";;;AAGA,MAAa,cAAc,mBAA2B"}
|
package/dist/patched.cjs
CHANGED
|
@@ -1,76 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_create_fortnox = require('./create-fortnox-BRQXlzrc.cjs');
|
|
2
3
|
|
|
3
4
|
//#region src/patched.ts
|
|
4
|
-
const
|
|
5
|
-
"get",
|
|
6
|
-
"post",
|
|
7
|
-
"put",
|
|
8
|
-
"delete",
|
|
9
|
-
"patch"
|
|
10
|
-
];
|
|
11
|
-
async function request(reqOptions, initOptions) {
|
|
12
|
-
try {
|
|
13
|
-
let headers;
|
|
14
|
-
let baseUrl;
|
|
15
|
-
if ("accessToken" in initOptions) {
|
|
16
|
-
headers = { Authorization: `Bearer ${initOptions.accessToken}` };
|
|
17
|
-
baseUrl = "https://api.fortnox.se";
|
|
18
|
-
} else {
|
|
19
|
-
headers = {
|
|
20
|
-
"x-api-key": initOptions.proxy.apiKey,
|
|
21
|
-
"x-tenant-id": initOptions.proxy.tenantId
|
|
22
|
-
};
|
|
23
|
-
baseUrl = initOptions.proxy.baseUrl;
|
|
24
|
-
}
|
|
25
|
-
const searchParams = new URLSearchParams();
|
|
26
|
-
if (reqOptions.query) Object.entries(reqOptions.query).forEach(([key, value]) => {
|
|
27
|
-
searchParams.append(key, String(value));
|
|
28
|
-
});
|
|
29
|
-
let path = reqOptions.path;
|
|
30
|
-
if (reqOptions.params) Object.entries(reqOptions.params).forEach(([key, value]) => {
|
|
31
|
-
path = path.replace(`{${key}}`, encodeURIComponent(String(value)));
|
|
32
|
-
});
|
|
33
|
-
const url = `${baseUrl}${path}${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`;
|
|
34
|
-
const response = await fetch(url, {
|
|
35
|
-
method: reqOptions.method.toUpperCase(),
|
|
36
|
-
body: reqOptions.body ? JSON.stringify(reqOptions.body) : null,
|
|
37
|
-
headers
|
|
38
|
-
});
|
|
39
|
-
const responseData = await response.json();
|
|
40
|
-
if (response.status < 300) return {
|
|
41
|
-
error: null,
|
|
42
|
-
data: responseData
|
|
43
|
-
};
|
|
44
|
-
else return {
|
|
45
|
-
error: {
|
|
46
|
-
ErrorSource: "fortnox",
|
|
47
|
-
ErrorInformation: responseData.ErrorInformation
|
|
48
|
-
},
|
|
49
|
-
data: null
|
|
50
|
-
};
|
|
51
|
-
} catch (e) {
|
|
52
|
-
return {
|
|
53
|
-
error: {
|
|
54
|
-
ErrorSource: "unknown",
|
|
55
|
-
ErrorInformation: {
|
|
56
|
-
message: e instanceof Error ? e.message : String(e),
|
|
57
|
-
error: -1,
|
|
58
|
-
code: -1
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
data: null
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function initFortnox(initOptions) {
|
|
66
|
-
return function fortnox(path) {
|
|
67
|
-
return Object.fromEntries(METHODS.map((method) => [method, (options) => request({
|
|
68
|
-
path,
|
|
69
|
-
method,
|
|
70
|
-
...options
|
|
71
|
-
}, initOptions)]));
|
|
72
|
-
};
|
|
73
|
-
}
|
|
5
|
+
const initFortnox = require_create_fortnox.createInitFortnox();
|
|
74
6
|
|
|
75
7
|
//#endregion
|
|
76
8
|
exports.initFortnox = initFortnox;
|
package/dist/patched.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patched.cjs","names":[],"sources":["../src/patched.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"patched.cjs","names":["createInitFortnox"],"sources":["../src/patched.ts"],"sourcesContent":["import { createInitFortnox } from \"./create-fortnox\";\r\nimport type { Routes } from \"./types/patched-routes.gen\";\r\n\r\nexport const initFortnox = createInitFortnox<Routes>();\r\n"],"mappings":";;;;AAGA,MAAa,cAAcA,0CAA2B"}
|