@shopware/api-client 0.0.3 → 0.2.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 +160 -5
- package/api-types/apiSchema-6.5.3.0.json +12154 -0
- package/api-types/apiTypes-6.4.19.0.d.ts +1 -1
- package/api-types/apiTypes-6.4.20.0.d.ts +1 -1
- package/api-types/apiTypes-6.5.0.0.d.ts +1 -1
- package/api-types/apiTypes-6.5.2.0.d.ts +1 -1
- package/api-types/apiTypes-6.5.3.0.d.ts +7738 -0
- package/api-types/index.d.ts +1 -1
- package/dist/index.d.ts +207 -161
- package/dist/index.mjs +40 -8
- package/package.json +11 -8
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
import { ofetch } from 'ofetch';
|
|
2
2
|
|
|
3
|
+
class ApiClientError extends Error {
|
|
4
|
+
constructor(response) {
|
|
5
|
+
let message = "Failed request";
|
|
6
|
+
message += response._data?.errors.reduce((message2, error) => {
|
|
7
|
+
let pointer = "";
|
|
8
|
+
if (error.source?.pointer) {
|
|
9
|
+
pointer = `[${error.source.pointer}]`;
|
|
10
|
+
}
|
|
11
|
+
return `${message2}
|
|
12
|
+
- [${error.title}]${pointer} ${error.detail}`;
|
|
13
|
+
}, "");
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "ApiClientError";
|
|
16
|
+
this.details = response._data || {
|
|
17
|
+
errors: [{ title: "Unknown error", detail: "" }]
|
|
18
|
+
};
|
|
19
|
+
this.ok = response.ok;
|
|
20
|
+
this.status = response.status;
|
|
21
|
+
this.statusText = response.statusText;
|
|
22
|
+
this.url = response.url;
|
|
23
|
+
this.headers = response.headers;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function errorInterceptor(response) {
|
|
27
|
+
throw new ApiClientError(response);
|
|
28
|
+
}
|
|
29
|
+
|
|
3
30
|
function createAPIClient(params) {
|
|
4
31
|
const defaultHeaders = {
|
|
5
32
|
"sw-access-key": params.accessToken,
|
|
@@ -15,21 +42,26 @@ function createAPIClient(params) {
|
|
|
15
42
|
defaultHeaders["sw-context-token"] = newContextToken;
|
|
16
43
|
params.onContextChanged?.(newContextToken);
|
|
17
44
|
}
|
|
45
|
+
},
|
|
46
|
+
async onResponseError({ request, response, options }) {
|
|
47
|
+
errorInterceptor(response);
|
|
18
48
|
}
|
|
19
|
-
// async onResponseError({ request, response, options }) {},
|
|
20
49
|
});
|
|
21
50
|
async function invoke(pathParam, params2) {
|
|
22
51
|
const [requestPath, options] = transformPathToQuery(
|
|
23
52
|
pathParam,
|
|
24
53
|
params2
|
|
25
54
|
);
|
|
26
|
-
return apiFetch(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
...
|
|
30
|
-
|
|
55
|
+
return apiFetch(
|
|
56
|
+
requestPath,
|
|
57
|
+
{
|
|
58
|
+
...options,
|
|
59
|
+
headers: {
|
|
60
|
+
...defaultHeaders,
|
|
61
|
+
...options.headers
|
|
62
|
+
}
|
|
31
63
|
}
|
|
32
|
-
|
|
64
|
+
);
|
|
33
65
|
}
|
|
34
66
|
return {
|
|
35
67
|
invoke
|
|
@@ -66,4 +98,4 @@ function transformPathToQuery(path, params) {
|
|
|
66
98
|
return [requestPathWithParams, returnOptions];
|
|
67
99
|
}
|
|
68
100
|
|
|
69
|
-
export { createAPIClient, transformPathToQuery };
|
|
101
|
+
export { ApiClientError, createAPIClient, transformPathToQuery };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/api-client",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Shopware client for API connection.",
|
|
5
5
|
"author": "Shopware",
|
|
6
6
|
"repository": {
|
|
@@ -27,21 +27,24 @@
|
|
|
27
27
|
"import": "./dist/index.mjs"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/prettier": "^2.7.
|
|
31
|
-
"@vitest/coverage-c8": "^0.
|
|
32
|
-
"prettier": "^
|
|
33
|
-
"vitest": "^0.
|
|
34
|
-
"
|
|
30
|
+
"@types/prettier": "^2.7.3",
|
|
31
|
+
"@vitest/coverage-c8": "^0.33.0",
|
|
32
|
+
"prettier": "^3.0.0",
|
|
33
|
+
"vitest": "^0.33.0",
|
|
34
|
+
"@shopware/api-gen": "0.0.5",
|
|
35
|
+
"eslint-config-shopware": "0.0.4",
|
|
35
36
|
"tsconfig": "0.0.0"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"ofetch": "^1.
|
|
39
|
+
"ofetch": "^1.1.1"
|
|
39
40
|
},
|
|
40
41
|
"scripts": {
|
|
41
42
|
"build": "export NODE_ENV=production && unbuild && pnpm build:types",
|
|
42
43
|
"build:types": "tsc ./src/*.ts --declaration --allowJs --emitDeclarationOnly --outDir ./temp --skipLibCheck",
|
|
43
44
|
"dev": "export NODE_ENV=development && unbuild --stub",
|
|
44
|
-
"
|
|
45
|
+
"generate": "esno ../api-gen/src/cli.ts generate",
|
|
46
|
+
"lint": "eslint src/**/*.ts* --fix --max-warnings=0 && pnpm run typecheck",
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
45
48
|
"test": "vitest run && pnpm run test:types",
|
|
46
49
|
"test:types": "vitest typecheck --run",
|
|
47
50
|
"test:bench": "vitest bench",
|