@contember/graphql-client 1.3.0-alpha.2

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.
Files changed (39) hide show
  1. package/dist/development/GraphQlClient.cjs +83 -0
  2. package/dist/development/GraphQlClient.cjs.map +1 -0
  3. package/dist/development/GraphQlClient.js +83 -0
  4. package/dist/development/GraphQlClient.js.map +1 -0
  5. package/dist/development/GraphQlClientError.cjs +15 -0
  6. package/dist/development/GraphQlClientError.cjs.map +1 -0
  7. package/dist/development/GraphQlClientError.js +15 -0
  8. package/dist/development/GraphQlClientError.js.map +1 -0
  9. package/dist/development/index.cjs +7 -0
  10. package/dist/development/index.cjs.map +1 -0
  11. package/dist/development/index.js +7 -0
  12. package/dist/development/index.js.map +1 -0
  13. package/dist/production/GraphQlClient.cjs +83 -0
  14. package/dist/production/GraphQlClient.cjs.map +1 -0
  15. package/dist/production/GraphQlClient.js +83 -0
  16. package/dist/production/GraphQlClient.js.map +1 -0
  17. package/dist/production/GraphQlClientError.cjs +15 -0
  18. package/dist/production/GraphQlClientError.cjs.map +1 -0
  19. package/dist/production/GraphQlClientError.js +15 -0
  20. package/dist/production/GraphQlClientError.js.map +1 -0
  21. package/dist/production/index.cjs +7 -0
  22. package/dist/production/index.cjs.map +1 -0
  23. package/dist/production/index.js +7 -0
  24. package/dist/production/index.js.map +1 -0
  25. package/dist/types/GraphQlClient.d.ts +9 -0
  26. package/dist/types/GraphQlClient.d.ts.map +1 -0
  27. package/dist/types/GraphQlClientError.d.ts +15 -0
  28. package/dist/types/GraphQlClientError.d.ts.map +1 -0
  29. package/dist/types/GraphQlClientRequestOptions.d.ts +16 -0
  30. package/dist/types/GraphQlClientRequestOptions.d.ts.map +1 -0
  31. package/dist/types/index.d.ts +4 -0
  32. package/dist/types/index.d.ts.map +1 -0
  33. package/dist/types/tsconfig.tsbuildinfo +1 -0
  34. package/package.json +43 -0
  35. package/src/GraphQlClient.ts +96 -0
  36. package/src/GraphQlClientError.ts +26 -0
  37. package/src/GraphQlClientRequestOptions.ts +13 -0
  38. package/src/index.ts +3 -0
  39. package/src/tsconfig.json +6 -0
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const GraphQlClientError = require("./GraphQlClientError.cjs");
4
+ class GraphQlClient {
5
+ constructor(apiUrl, apiToken) {
6
+ this.apiUrl = apiUrl;
7
+ this.apiToken = apiToken;
8
+ }
9
+ async execute(query, options = {}) {
10
+ let body = null;
11
+ let response = null;
12
+ const createError = (type, errors, cause) => {
13
+ const request = {
14
+ url: this.apiUrl,
15
+ query,
16
+ variables: options.variables ?? {}
17
+ };
18
+ const details = `HTTP response: ${response ? response.status + " " + response.statusText : "<no response>"}
19
+ HTTP body:
20
+ ${body !== null ? body : "<no body>"}
21
+
22
+ GraphQL query:
23
+ ${query}`;
24
+ return new GraphQlClientError.GraphQlClientError(`GraphQL request failed: ${type}`, type, request, response ?? void 0, errors, details, cause);
25
+ };
26
+ options?.onBeforeRequest?.({ query, variables: options.variables ?? {} });
27
+ try {
28
+ response = await this.doExecute(query, options);
29
+ } catch (e) {
30
+ const aborted = typeof e === "object" && e !== null && e.name === "AbortError";
31
+ throw createError(aborted ? "aborted" : "network error", void 0, e);
32
+ }
33
+ options?.onResponse?.(response);
34
+ body = await response.text();
35
+ let data;
36
+ try {
37
+ data = JSON.parse(body);
38
+ } catch (e) {
39
+ throw createError("invalid response body", void 0, e);
40
+ }
41
+ options?.onData?.(data);
42
+ if (response.status === 401) {
43
+ throw createError("unauthorized");
44
+ }
45
+ if (response.status === 403) {
46
+ throw createError("forbidden");
47
+ }
48
+ if (response.status >= 400 && response.status < 500) {
49
+ throw createError("bad request", data.errors);
50
+ }
51
+ if (response.status >= 500) {
52
+ throw createError("server error");
53
+ }
54
+ if (!(typeof data === "object") || data === null) {
55
+ throw createError("invalid response body");
56
+ }
57
+ if ("errors" in data) {
58
+ throw createError("response errors", data.errors);
59
+ }
60
+ if (!("data" in data)) {
61
+ throw createError("invalid response body");
62
+ }
63
+ return data.data;
64
+ }
65
+ async doExecute(query, { apiToken, signal, variables, headers } = {}) {
66
+ const resolvedHeaders = {
67
+ "Content-Type": "application/json",
68
+ ...headers
69
+ };
70
+ const resolvedToken = apiToken ?? this.apiToken;
71
+ if (resolvedToken !== void 0) {
72
+ resolvedHeaders["Authorization"] = `Bearer ${resolvedToken}`;
73
+ }
74
+ return await fetch(this.apiUrl, {
75
+ method: "POST",
76
+ headers: resolvedHeaders,
77
+ signal,
78
+ body: JSON.stringify({ query, variables })
79
+ });
80
+ }
81
+ }
82
+ exports.GraphQlClient = GraphQlClient;
83
+ //# sourceMappingURL=GraphQlClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphQlClient.cjs","sources":["../../src/GraphQlClient.ts"],"sourcesContent":["import { GraphQlClientError, GraphQlErrorType } from './GraphQlClientError'\nimport { GraphQlClientRequestOptions } from './GraphQlClientRequestOptions'\n\nexport class GraphQlClient {\n\tconstructor(public readonly apiUrl: string, private readonly apiToken?: string) { }\n\n\tasync execute<T = unknown>(query: string, options: GraphQlClientRequestOptions = {}): Promise<T> {\n\t\tlet body: string | null = null\n\t\tlet response: Response | null = null\n\t\tconst createError = (type: GraphQlErrorType, errors?: any[], cause?: unknown) => {\n\t\t\tconst request = {\n\t\t\t\turl: this.apiUrl,\n\t\t\t\tquery,\n\t\t\t\tvariables: options.variables ?? {},\n\t\t\t}\n\n\t\t\tconst details = `HTTP response: ${response ? (response.status + ' ' + response.statusText) : '<no response>'}\nHTTP body: \n${body !== null ? body : '<no body>'}\n\nGraphQL query: \n${query}`\n\n\t\t\treturn new GraphQlClientError(`GraphQL request failed: ${type}`, type, request, response ?? undefined, errors, details, cause)\n\t\t}\n\n\t\toptions?.onBeforeRequest?.({ query, variables: options.variables ?? {} })\n\n\t\ttry {\n\t\t\tresponse = await this.doExecute(query, options)\n\t\t} catch (e) {\n\t\t\tconst aborted = typeof e === 'object' && e !== null && (e as { name?: unknown }).name === 'AbortError'\n\t\t\tthrow createError(aborted ? 'aborted' : 'network error', undefined, e)\n\t\t}\n\n\t\toptions?.onResponse?.(response)\n\n\t\tbody = await response.text()\n\n\t\tlet data: any\n\t\ttry {\n\t\t\tdata = JSON.parse(body)\n\t\t} catch (e) {\n\t\t\tthrow createError('invalid response body', undefined, e)\n\t\t}\n\t\toptions?.onData?.(data)\n\n\t\tif (response.status === 401) {\n\t\t\tthrow createError('unauthorized')\n\t\t}\n\t\tif (response.status === 403) {\n\t\t\tthrow createError('forbidden')\n\t\t}\n\t\tif (response.status >= 400 && response.status < 500) {\n\t\t\tthrow createError('bad request', data.errors)\n\t\t}\n\t\tif (response.status >= 500) {\n\t\t\tthrow createError('server error')\n\t\t}\n\t\tif (!(typeof data === 'object') || data === null) {\n\t\t\tthrow createError('invalid response body')\n\t\t}\n\t\tif ('errors' in data) {\n\t\t\tthrow createError('response errors', data.errors)\n\t\t}\n\t\tif (!('data' in data)) {\n\t\t\tthrow createError('invalid response body')\n\t\t}\n\n\t\treturn data.data\n\t}\n\n\n\tprotected async doExecute(\n\t\tquery: string,\n\t\t{ apiToken, signal, variables, headers }: GraphQlClientRequestOptions = {},\n\t): Promise<Response> {\n\t\tconst resolvedHeaders: Record<string, string> = {\n\t\t\t'Content-Type': 'application/json',\n\t\t\t...headers,\n\t\t}\n\t\tconst resolvedToken = apiToken ?? this.apiToken\n\n\t\tif (resolvedToken !== undefined) {\n\t\t\tresolvedHeaders['Authorization'] = `Bearer ${resolvedToken}`\n\t\t}\n\n\t\treturn await fetch(this.apiUrl, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: resolvedHeaders,\n\t\t\tsignal,\n\t\t\tbody: JSON.stringify({ query, variables }),\n\t\t})\n\t}\n}\n\n"],"names":["GraphQlClientError"],"mappings":";;;AAGO,MAAM,cAAc;AAAA,EAC1B,YAA4B,QAAiC,UAAmB;AAApD,SAAA,SAAA;AAAiC,SAAA,WAAA;AAAA,EAAqB;AAAA,EAElF,MAAM,QAAqB,OAAe,UAAuC,IAAgB;AAChG,QAAI,OAAsB;AAC1B,QAAI,WAA4B;AAChC,UAAM,cAAc,CAAC,MAAwB,QAAgB,UAAoB;AAChF,YAAM,UAAU;AAAA,QACf,KAAK,KAAK;AAAA,QACV;AAAA,QACA,WAAW,QAAQ,aAAa,CAAC;AAAA,MAAA;AAGlC,YAAM,UAAU,kBAAkB,WAAY,SAAS,SAAS,MAAM,SAAS,aAAc;AAAA;AAAA,EAE9F,SAAS,OAAO,OAAO;AAAA;AAAA;AAAA,EAGvB;AAEQ,aAAA,IAAIA,mBAAAA,mBAAmB,2BAA2B,QAAQ,MAAM,SAAS,YAAY,QAAW,QAAQ,SAAS,KAAK;AAAA,IAAA;AAGrH,aAAA,kBAAkB,EAAE,OAAO,WAAW,QAAQ,aAAa,IAAI;AAEpE,QAAA;AACH,iBAAW,MAAM,KAAK,UAAU,OAAO,OAAO;AAAA,aACtC;AACR,YAAM,UAAU,OAAO,MAAM,YAAY,MAAM,QAAS,EAAyB,SAAS;AAC1F,YAAM,YAAY,UAAU,YAAY,iBAAiB,QAAW,CAAC;AAAA,IACtE;AAEA,aAAS,aAAa,QAAQ;AAEvB,WAAA,MAAM,SAAS;AAElB,QAAA;AACA,QAAA;AACI,aAAA,KAAK,MAAM,IAAI;AAAA,aACd;AACF,YAAA,YAAY,yBAAyB,QAAW,CAAC;AAAA,IACxD;AACA,aAAS,SAAS,IAAI;AAElB,QAAA,SAAS,WAAW,KAAK;AAC5B,YAAM,YAAY,cAAc;AAAA,IACjC;AACI,QAAA,SAAS,WAAW,KAAK;AAC5B,YAAM,YAAY,WAAW;AAAA,IAC9B;AACA,QAAI,SAAS,UAAU,OAAO,SAAS,SAAS,KAAK;AAC9C,YAAA,YAAY,eAAe,KAAK,MAAM;AAAA,IAC7C;AACI,QAAA,SAAS,UAAU,KAAK;AAC3B,YAAM,YAAY,cAAc;AAAA,IACjC;AACA,QAAI,EAAE,OAAO,SAAS,aAAa,SAAS,MAAM;AACjD,YAAM,YAAY,uBAAuB;AAAA,IAC1C;AACA,QAAI,YAAY,MAAM;AACf,YAAA,YAAY,mBAAmB,KAAK,MAAM;AAAA,IACjD;AACI,QAAA,EAAE,UAAU,OAAO;AACtB,YAAM,YAAY,uBAAuB;AAAA,IAC1C;AAEA,WAAO,KAAK;AAAA,EACb;AAAA,EAGA,MAAgB,UACf,OACA,EAAE,UAAU,QAAQ,WAAW,QAAyC,IAAA,IACpD;AACpB,UAAM,kBAA0C;AAAA,MAC/C,gBAAgB;AAAA,MAChB,GAAG;AAAA,IAAA;AAEE,UAAA,gBAAgB,YAAY,KAAK;AAEvC,QAAI,kBAAkB,QAAW;AAChB,sBAAA,eAAe,IAAI,UAAU;AAAA,IAC9C;AAEO,WAAA,MAAM,MAAM,KAAK,QAAQ;AAAA,MAC/B,QAAQ;AAAA,MACR,SAAS;AAAA,MACT;AAAA,MACA,MAAM,KAAK,UAAU,EAAE,OAAO,WAAW;AAAA,IAAA,CACzC;AAAA,EACF;AACD;;"}
@@ -0,0 +1,83 @@
1
+ import { GraphQlClientError } from "./GraphQlClientError.js";
2
+ class GraphQlClient {
3
+ constructor(apiUrl, apiToken) {
4
+ this.apiUrl = apiUrl;
5
+ this.apiToken = apiToken;
6
+ }
7
+ async execute(query, options = {}) {
8
+ let body = null;
9
+ let response = null;
10
+ const createError = (type, errors, cause) => {
11
+ const request = {
12
+ url: this.apiUrl,
13
+ query,
14
+ variables: options.variables ?? {}
15
+ };
16
+ const details = `HTTP response: ${response ? response.status + " " + response.statusText : "<no response>"}
17
+ HTTP body:
18
+ ${body !== null ? body : "<no body>"}
19
+
20
+ GraphQL query:
21
+ ${query}`;
22
+ return new GraphQlClientError(`GraphQL request failed: ${type}`, type, request, response ?? void 0, errors, details, cause);
23
+ };
24
+ options?.onBeforeRequest?.({ query, variables: options.variables ?? {} });
25
+ try {
26
+ response = await this.doExecute(query, options);
27
+ } catch (e) {
28
+ const aborted = typeof e === "object" && e !== null && e.name === "AbortError";
29
+ throw createError(aborted ? "aborted" : "network error", void 0, e);
30
+ }
31
+ options?.onResponse?.(response);
32
+ body = await response.text();
33
+ let data;
34
+ try {
35
+ data = JSON.parse(body);
36
+ } catch (e) {
37
+ throw createError("invalid response body", void 0, e);
38
+ }
39
+ options?.onData?.(data);
40
+ if (response.status === 401) {
41
+ throw createError("unauthorized");
42
+ }
43
+ if (response.status === 403) {
44
+ throw createError("forbidden");
45
+ }
46
+ if (response.status >= 400 && response.status < 500) {
47
+ throw createError("bad request", data.errors);
48
+ }
49
+ if (response.status >= 500) {
50
+ throw createError("server error");
51
+ }
52
+ if (!(typeof data === "object") || data === null) {
53
+ throw createError("invalid response body");
54
+ }
55
+ if ("errors" in data) {
56
+ throw createError("response errors", data.errors);
57
+ }
58
+ if (!("data" in data)) {
59
+ throw createError("invalid response body");
60
+ }
61
+ return data.data;
62
+ }
63
+ async doExecute(query, { apiToken, signal, variables, headers } = {}) {
64
+ const resolvedHeaders = {
65
+ "Content-Type": "application/json",
66
+ ...headers
67
+ };
68
+ const resolvedToken = apiToken ?? this.apiToken;
69
+ if (resolvedToken !== void 0) {
70
+ resolvedHeaders["Authorization"] = `Bearer ${resolvedToken}`;
71
+ }
72
+ return await fetch(this.apiUrl, {
73
+ method: "POST",
74
+ headers: resolvedHeaders,
75
+ signal,
76
+ body: JSON.stringify({ query, variables })
77
+ });
78
+ }
79
+ }
80
+ export {
81
+ GraphQlClient
82
+ };
83
+ //# sourceMappingURL=GraphQlClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphQlClient.js","sources":["../../src/GraphQlClient.ts"],"sourcesContent":["import { GraphQlClientError, GraphQlErrorType } from './GraphQlClientError'\nimport { GraphQlClientRequestOptions } from './GraphQlClientRequestOptions'\n\nexport class GraphQlClient {\n\tconstructor(public readonly apiUrl: string, private readonly apiToken?: string) { }\n\n\tasync execute<T = unknown>(query: string, options: GraphQlClientRequestOptions = {}): Promise<T> {\n\t\tlet body: string | null = null\n\t\tlet response: Response | null = null\n\t\tconst createError = (type: GraphQlErrorType, errors?: any[], cause?: unknown) => {\n\t\t\tconst request = {\n\t\t\t\turl: this.apiUrl,\n\t\t\t\tquery,\n\t\t\t\tvariables: options.variables ?? {},\n\t\t\t}\n\n\t\t\tconst details = `HTTP response: ${response ? (response.status + ' ' + response.statusText) : '<no response>'}\nHTTP body: \n${body !== null ? body : '<no body>'}\n\nGraphQL query: \n${query}`\n\n\t\t\treturn new GraphQlClientError(`GraphQL request failed: ${type}`, type, request, response ?? undefined, errors, details, cause)\n\t\t}\n\n\t\toptions?.onBeforeRequest?.({ query, variables: options.variables ?? {} })\n\n\t\ttry {\n\t\t\tresponse = await this.doExecute(query, options)\n\t\t} catch (e) {\n\t\t\tconst aborted = typeof e === 'object' && e !== null && (e as { name?: unknown }).name === 'AbortError'\n\t\t\tthrow createError(aborted ? 'aborted' : 'network error', undefined, e)\n\t\t}\n\n\t\toptions?.onResponse?.(response)\n\n\t\tbody = await response.text()\n\n\t\tlet data: any\n\t\ttry {\n\t\t\tdata = JSON.parse(body)\n\t\t} catch (e) {\n\t\t\tthrow createError('invalid response body', undefined, e)\n\t\t}\n\t\toptions?.onData?.(data)\n\n\t\tif (response.status === 401) {\n\t\t\tthrow createError('unauthorized')\n\t\t}\n\t\tif (response.status === 403) {\n\t\t\tthrow createError('forbidden')\n\t\t}\n\t\tif (response.status >= 400 && response.status < 500) {\n\t\t\tthrow createError('bad request', data.errors)\n\t\t}\n\t\tif (response.status >= 500) {\n\t\t\tthrow createError('server error')\n\t\t}\n\t\tif (!(typeof data === 'object') || data === null) {\n\t\t\tthrow createError('invalid response body')\n\t\t}\n\t\tif ('errors' in data) {\n\t\t\tthrow createError('response errors', data.errors)\n\t\t}\n\t\tif (!('data' in data)) {\n\t\t\tthrow createError('invalid response body')\n\t\t}\n\n\t\treturn data.data\n\t}\n\n\n\tprotected async doExecute(\n\t\tquery: string,\n\t\t{ apiToken, signal, variables, headers }: GraphQlClientRequestOptions = {},\n\t): Promise<Response> {\n\t\tconst resolvedHeaders: Record<string, string> = {\n\t\t\t'Content-Type': 'application/json',\n\t\t\t...headers,\n\t\t}\n\t\tconst resolvedToken = apiToken ?? this.apiToken\n\n\t\tif (resolvedToken !== undefined) {\n\t\t\tresolvedHeaders['Authorization'] = `Bearer ${resolvedToken}`\n\t\t}\n\n\t\treturn await fetch(this.apiUrl, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: resolvedHeaders,\n\t\t\tsignal,\n\t\t\tbody: JSON.stringify({ query, variables }),\n\t\t})\n\t}\n}\n\n"],"names":[],"mappings":";AAGO,MAAM,cAAc;AAAA,EAC1B,YAA4B,QAAiC,UAAmB;AAApD,SAAA,SAAA;AAAiC,SAAA,WAAA;AAAA,EAAqB;AAAA,EAElF,MAAM,QAAqB,OAAe,UAAuC,IAAgB;AAChG,QAAI,OAAsB;AAC1B,QAAI,WAA4B;AAChC,UAAM,cAAc,CAAC,MAAwB,QAAgB,UAAoB;AAChF,YAAM,UAAU;AAAA,QACf,KAAK,KAAK;AAAA,QACV;AAAA,QACA,WAAW,QAAQ,aAAa,CAAC;AAAA,MAAA;AAGlC,YAAM,UAAU,kBAAkB,WAAY,SAAS,SAAS,MAAM,SAAS,aAAc;AAAA;AAAA,EAE9F,SAAS,OAAO,OAAO;AAAA;AAAA;AAAA,EAGvB;AAEQ,aAAA,IAAI,mBAAmB,2BAA2B,QAAQ,MAAM,SAAS,YAAY,QAAW,QAAQ,SAAS,KAAK;AAAA,IAAA;AAGrH,aAAA,kBAAkB,EAAE,OAAO,WAAW,QAAQ,aAAa,IAAI;AAEpE,QAAA;AACH,iBAAW,MAAM,KAAK,UAAU,OAAO,OAAO;AAAA,aACtC;AACR,YAAM,UAAU,OAAO,MAAM,YAAY,MAAM,QAAS,EAAyB,SAAS;AAC1F,YAAM,YAAY,UAAU,YAAY,iBAAiB,QAAW,CAAC;AAAA,IACtE;AAEA,aAAS,aAAa,QAAQ;AAEvB,WAAA,MAAM,SAAS;AAElB,QAAA;AACA,QAAA;AACI,aAAA,KAAK,MAAM,IAAI;AAAA,aACd;AACF,YAAA,YAAY,yBAAyB,QAAW,CAAC;AAAA,IACxD;AACA,aAAS,SAAS,IAAI;AAElB,QAAA,SAAS,WAAW,KAAK;AAC5B,YAAM,YAAY,cAAc;AAAA,IACjC;AACI,QAAA,SAAS,WAAW,KAAK;AAC5B,YAAM,YAAY,WAAW;AAAA,IAC9B;AACA,QAAI,SAAS,UAAU,OAAO,SAAS,SAAS,KAAK;AAC9C,YAAA,YAAY,eAAe,KAAK,MAAM;AAAA,IAC7C;AACI,QAAA,SAAS,UAAU,KAAK;AAC3B,YAAM,YAAY,cAAc;AAAA,IACjC;AACA,QAAI,EAAE,OAAO,SAAS,aAAa,SAAS,MAAM;AACjD,YAAM,YAAY,uBAAuB;AAAA,IAC1C;AACA,QAAI,YAAY,MAAM;AACf,YAAA,YAAY,mBAAmB,KAAK,MAAM;AAAA,IACjD;AACI,QAAA,EAAE,UAAU,OAAO;AACtB,YAAM,YAAY,uBAAuB;AAAA,IAC1C;AAEA,WAAO,KAAK;AAAA,EACb;AAAA,EAGA,MAAgB,UACf,OACA,EAAE,UAAU,QAAQ,WAAW,QAAyC,IAAA,IACpD;AACpB,UAAM,kBAA0C;AAAA,MAC/C,gBAAgB;AAAA,MAChB,GAAG;AAAA,IAAA;AAEE,UAAA,gBAAgB,YAAY,KAAK;AAEvC,QAAI,kBAAkB,QAAW;AAChB,sBAAA,eAAe,IAAI,UAAU;AAAA,IAC9C;AAEO,WAAA,MAAM,MAAM,KAAK,QAAQ;AAAA,MAC/B,QAAQ;AAAA,MACR,SAAS;AAAA,MACT;AAAA,MACA,MAAM,KAAK,UAAU,EAAE,OAAO,WAAW;AAAA,IAAA,CACzC;AAAA,EACF;AACD;"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ class GraphQlClientError extends Error {
4
+ constructor(message, type, request, response, errors, details, cause) {
5
+ super(message);
6
+ this.type = type;
7
+ this.request = request;
8
+ this.response = response;
9
+ this.errors = errors;
10
+ this.details = details;
11
+ this.cause = cause;
12
+ }
13
+ }
14
+ exports.GraphQlClientError = GraphQlClientError;
15
+ //# sourceMappingURL=GraphQlClientError.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphQlClientError.cjs","sources":["../../src/GraphQlClientError.ts"],"sourcesContent":["export type GraphQlErrorRequest = { url: string, query: string, variables: Record<string, any> };\n\nexport type GraphQlErrorType =\n\t| 'aborted'\n\t| 'network error'\n\t| 'invalid response body'\n\t| 'bad request'\n\t| 'unauthorized'\n\t| 'forbidden'\n\t| 'server error'\n\t| 'response errors'\n\nexport class GraphQlClientError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly type: GraphQlErrorType,\n\t\tpublic readonly request: GraphQlErrorRequest,\n\t\tpublic readonly response?: Response,\n\t\tpublic readonly errors?: readonly any[],\n\t\tpublic readonly details?: string,\n\t\tcause?: unknown,\n\t) {\n\t\tsuper(message)\n\t\tthis.cause = cause\n\t}\n}\n"],"names":[],"mappings":";;AAYO,MAAM,2BAA2B,MAAM;AAAA,EAC7C,YACC,SACgB,MACA,SACA,UACA,QACA,SAChB,OACC;AACD,UAAM,OAAO;AAPG,SAAA,OAAA;AACA,SAAA,UAAA;AACA,SAAA,WAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AAIhB,SAAK,QAAQ;AAAA,EACd;AACD;;"}
@@ -0,0 +1,15 @@
1
+ class GraphQlClientError extends Error {
2
+ constructor(message, type, request, response, errors, details, cause) {
3
+ super(message);
4
+ this.type = type;
5
+ this.request = request;
6
+ this.response = response;
7
+ this.errors = errors;
8
+ this.details = details;
9
+ this.cause = cause;
10
+ }
11
+ }
12
+ export {
13
+ GraphQlClientError
14
+ };
15
+ //# sourceMappingURL=GraphQlClientError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphQlClientError.js","sources":["../../src/GraphQlClientError.ts"],"sourcesContent":["export type GraphQlErrorRequest = { url: string, query: string, variables: Record<string, any> };\n\nexport type GraphQlErrorType =\n\t| 'aborted'\n\t| 'network error'\n\t| 'invalid response body'\n\t| 'bad request'\n\t| 'unauthorized'\n\t| 'forbidden'\n\t| 'server error'\n\t| 'response errors'\n\nexport class GraphQlClientError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly type: GraphQlErrorType,\n\t\tpublic readonly request: GraphQlErrorRequest,\n\t\tpublic readonly response?: Response,\n\t\tpublic readonly errors?: readonly any[],\n\t\tpublic readonly details?: string,\n\t\tcause?: unknown,\n\t) {\n\t\tsuper(message)\n\t\tthis.cause = cause\n\t}\n}\n"],"names":[],"mappings":"AAYO,MAAM,2BAA2B,MAAM;AAAA,EAC7C,YACC,SACgB,MACA,SACA,UACA,QACA,SAChB,OACC;AACD,UAAM,OAAO;AAPG,SAAA,OAAA;AACA,SAAA,UAAA;AACA,SAAA,WAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AAIhB,SAAK,QAAQ;AAAA,EACd;AACD;"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const GraphQlClient = require("./GraphQlClient.cjs");
4
+ const GraphQlClientError = require("./GraphQlClientError.cjs");
5
+ exports.GraphQlClient = GraphQlClient.GraphQlClient;
6
+ exports.GraphQlClientError = GraphQlClientError.GraphQlClientError;
7
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -0,0 +1,7 @@
1
+ import { GraphQlClient } from "./GraphQlClient.js";
2
+ import { GraphQlClientError } from "./GraphQlClientError.js";
3
+ export {
4
+ GraphQlClient,
5
+ GraphQlClientError
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const GraphQlClientError = require("./GraphQlClientError.cjs");
4
+ class GraphQlClient {
5
+ constructor(apiUrl, apiToken) {
6
+ this.apiUrl = apiUrl;
7
+ this.apiToken = apiToken;
8
+ }
9
+ async execute(query, options = {}) {
10
+ let body = null;
11
+ let response = null;
12
+ const createError = (type, errors, cause) => {
13
+ const request = {
14
+ url: this.apiUrl,
15
+ query,
16
+ variables: options.variables ?? {}
17
+ };
18
+ const details = `HTTP response: ${response ? response.status + " " + response.statusText : "<no response>"}
19
+ HTTP body:
20
+ ${body !== null ? body : "<no body>"}
21
+
22
+ GraphQL query:
23
+ ${query}`;
24
+ return new GraphQlClientError.GraphQlClientError(`GraphQL request failed: ${type}`, type, request, response ?? void 0, errors, details, cause);
25
+ };
26
+ options?.onBeforeRequest?.({ query, variables: options.variables ?? {} });
27
+ try {
28
+ response = await this.doExecute(query, options);
29
+ } catch (e) {
30
+ const aborted = typeof e === "object" && e !== null && e.name === "AbortError";
31
+ throw createError(aborted ? "aborted" : "network error", void 0, e);
32
+ }
33
+ options?.onResponse?.(response);
34
+ body = await response.text();
35
+ let data;
36
+ try {
37
+ data = JSON.parse(body);
38
+ } catch (e) {
39
+ throw createError("invalid response body", void 0, e);
40
+ }
41
+ options?.onData?.(data);
42
+ if (response.status === 401) {
43
+ throw createError("unauthorized");
44
+ }
45
+ if (response.status === 403) {
46
+ throw createError("forbidden");
47
+ }
48
+ if (response.status >= 400 && response.status < 500) {
49
+ throw createError("bad request", data.errors);
50
+ }
51
+ if (response.status >= 500) {
52
+ throw createError("server error");
53
+ }
54
+ if (!(typeof data === "object") || data === null) {
55
+ throw createError("invalid response body");
56
+ }
57
+ if ("errors" in data) {
58
+ throw createError("response errors", data.errors);
59
+ }
60
+ if (!("data" in data)) {
61
+ throw createError("invalid response body");
62
+ }
63
+ return data.data;
64
+ }
65
+ async doExecute(query, { apiToken, signal, variables, headers } = {}) {
66
+ const resolvedHeaders = {
67
+ "Content-Type": "application/json",
68
+ ...headers
69
+ };
70
+ const resolvedToken = apiToken ?? this.apiToken;
71
+ if (resolvedToken !== void 0) {
72
+ resolvedHeaders["Authorization"] = `Bearer ${resolvedToken}`;
73
+ }
74
+ return await fetch(this.apiUrl, {
75
+ method: "POST",
76
+ headers: resolvedHeaders,
77
+ signal,
78
+ body: JSON.stringify({ query, variables })
79
+ });
80
+ }
81
+ }
82
+ exports.GraphQlClient = GraphQlClient;
83
+ //# sourceMappingURL=GraphQlClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphQlClient.cjs","sources":["../../src/GraphQlClient.ts"],"sourcesContent":["import { GraphQlClientError, GraphQlErrorType } from './GraphQlClientError'\nimport { GraphQlClientRequestOptions } from './GraphQlClientRequestOptions'\n\nexport class GraphQlClient {\n\tconstructor(public readonly apiUrl: string, private readonly apiToken?: string) { }\n\n\tasync execute<T = unknown>(query: string, options: GraphQlClientRequestOptions = {}): Promise<T> {\n\t\tlet body: string | null = null\n\t\tlet response: Response | null = null\n\t\tconst createError = (type: GraphQlErrorType, errors?: any[], cause?: unknown) => {\n\t\t\tconst request = {\n\t\t\t\turl: this.apiUrl,\n\t\t\t\tquery,\n\t\t\t\tvariables: options.variables ?? {},\n\t\t\t}\n\n\t\t\tconst details = `HTTP response: ${response ? (response.status + ' ' + response.statusText) : '<no response>'}\nHTTP body: \n${body !== null ? body : '<no body>'}\n\nGraphQL query: \n${query}`\n\n\t\t\treturn new GraphQlClientError(`GraphQL request failed: ${type}`, type, request, response ?? undefined, errors, details, cause)\n\t\t}\n\n\t\toptions?.onBeforeRequest?.({ query, variables: options.variables ?? {} })\n\n\t\ttry {\n\t\t\tresponse = await this.doExecute(query, options)\n\t\t} catch (e) {\n\t\t\tconst aborted = typeof e === 'object' && e !== null && (e as { name?: unknown }).name === 'AbortError'\n\t\t\tthrow createError(aborted ? 'aborted' : 'network error', undefined, e)\n\t\t}\n\n\t\toptions?.onResponse?.(response)\n\n\t\tbody = await response.text()\n\n\t\tlet data: any\n\t\ttry {\n\t\t\tdata = JSON.parse(body)\n\t\t} catch (e) {\n\t\t\tthrow createError('invalid response body', undefined, e)\n\t\t}\n\t\toptions?.onData?.(data)\n\n\t\tif (response.status === 401) {\n\t\t\tthrow createError('unauthorized')\n\t\t}\n\t\tif (response.status === 403) {\n\t\t\tthrow createError('forbidden')\n\t\t}\n\t\tif (response.status >= 400 && response.status < 500) {\n\t\t\tthrow createError('bad request', data.errors)\n\t\t}\n\t\tif (response.status >= 500) {\n\t\t\tthrow createError('server error')\n\t\t}\n\t\tif (!(typeof data === 'object') || data === null) {\n\t\t\tthrow createError('invalid response body')\n\t\t}\n\t\tif ('errors' in data) {\n\t\t\tthrow createError('response errors', data.errors)\n\t\t}\n\t\tif (!('data' in data)) {\n\t\t\tthrow createError('invalid response body')\n\t\t}\n\n\t\treturn data.data\n\t}\n\n\n\tprotected async doExecute(\n\t\tquery: string,\n\t\t{ apiToken, signal, variables, headers }: GraphQlClientRequestOptions = {},\n\t): Promise<Response> {\n\t\tconst resolvedHeaders: Record<string, string> = {\n\t\t\t'Content-Type': 'application/json',\n\t\t\t...headers,\n\t\t}\n\t\tconst resolvedToken = apiToken ?? this.apiToken\n\n\t\tif (resolvedToken !== undefined) {\n\t\t\tresolvedHeaders['Authorization'] = `Bearer ${resolvedToken}`\n\t\t}\n\n\t\treturn await fetch(this.apiUrl, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: resolvedHeaders,\n\t\t\tsignal,\n\t\t\tbody: JSON.stringify({ query, variables }),\n\t\t})\n\t}\n}\n\n"],"names":["GraphQlClientError"],"mappings":";;;AAGO,MAAM,cAAc;AAAA,EAC1B,YAA4B,QAAiC,UAAmB;AAApD,SAAA,SAAA;AAAiC,SAAA,WAAA;AAAA,EAAqB;AAAA,EAElF,MAAM,QAAqB,OAAe,UAAuC,IAAgB;AAChG,QAAI,OAAsB;AAC1B,QAAI,WAA4B;AAChC,UAAM,cAAc,CAAC,MAAwB,QAAgB,UAAoB;AAChF,YAAM,UAAU;AAAA,QACf,KAAK,KAAK;AAAA,QACV;AAAA,QACA,WAAW,QAAQ,aAAa,CAAC;AAAA,MAAA;AAGlC,YAAM,UAAU,kBAAkB,WAAY,SAAS,SAAS,MAAM,SAAS,aAAc;AAAA;AAAA,EAE9F,SAAS,OAAO,OAAO;AAAA;AAAA;AAAA,EAGvB;AAEQ,aAAA,IAAIA,mBAAAA,mBAAmB,2BAA2B,QAAQ,MAAM,SAAS,YAAY,QAAW,QAAQ,SAAS,KAAK;AAAA,IAAA;AAGrH,aAAA,kBAAkB,EAAE,OAAO,WAAW,QAAQ,aAAa,IAAI;AAEpE,QAAA;AACH,iBAAW,MAAM,KAAK,UAAU,OAAO,OAAO;AAAA,aACtC;AACR,YAAM,UAAU,OAAO,MAAM,YAAY,MAAM,QAAS,EAAyB,SAAS;AAC1F,YAAM,YAAY,UAAU,YAAY,iBAAiB,QAAW,CAAC;AAAA,IACtE;AAEA,aAAS,aAAa,QAAQ;AAEvB,WAAA,MAAM,SAAS;AAElB,QAAA;AACA,QAAA;AACI,aAAA,KAAK,MAAM,IAAI;AAAA,aACd;AACF,YAAA,YAAY,yBAAyB,QAAW,CAAC;AAAA,IACxD;AACA,aAAS,SAAS,IAAI;AAElB,QAAA,SAAS,WAAW,KAAK;AAC5B,YAAM,YAAY,cAAc;AAAA,IACjC;AACI,QAAA,SAAS,WAAW,KAAK;AAC5B,YAAM,YAAY,WAAW;AAAA,IAC9B;AACA,QAAI,SAAS,UAAU,OAAO,SAAS,SAAS,KAAK;AAC9C,YAAA,YAAY,eAAe,KAAK,MAAM;AAAA,IAC7C;AACI,QAAA,SAAS,UAAU,KAAK;AAC3B,YAAM,YAAY,cAAc;AAAA,IACjC;AACA,QAAI,EAAE,OAAO,SAAS,aAAa,SAAS,MAAM;AACjD,YAAM,YAAY,uBAAuB;AAAA,IAC1C;AACA,QAAI,YAAY,MAAM;AACf,YAAA,YAAY,mBAAmB,KAAK,MAAM;AAAA,IACjD;AACI,QAAA,EAAE,UAAU,OAAO;AACtB,YAAM,YAAY,uBAAuB;AAAA,IAC1C;AAEA,WAAO,KAAK;AAAA,EACb;AAAA,EAGA,MAAgB,UACf,OACA,EAAE,UAAU,QAAQ,WAAW,QAAyC,IAAA,IACpD;AACpB,UAAM,kBAA0C;AAAA,MAC/C,gBAAgB;AAAA,MAChB,GAAG;AAAA,IAAA;AAEE,UAAA,gBAAgB,YAAY,KAAK;AAEvC,QAAI,kBAAkB,QAAW;AAChB,sBAAA,eAAe,IAAI,UAAU;AAAA,IAC9C;AAEO,WAAA,MAAM,MAAM,KAAK,QAAQ;AAAA,MAC/B,QAAQ;AAAA,MACR,SAAS;AAAA,MACT;AAAA,MACA,MAAM,KAAK,UAAU,EAAE,OAAO,WAAW;AAAA,IAAA,CACzC;AAAA,EACF;AACD;;"}
@@ -0,0 +1,83 @@
1
+ import { GraphQlClientError } from "./GraphQlClientError.js";
2
+ class GraphQlClient {
3
+ constructor(apiUrl, apiToken) {
4
+ this.apiUrl = apiUrl;
5
+ this.apiToken = apiToken;
6
+ }
7
+ async execute(query, options = {}) {
8
+ let body = null;
9
+ let response = null;
10
+ const createError = (type, errors, cause) => {
11
+ const request = {
12
+ url: this.apiUrl,
13
+ query,
14
+ variables: options.variables ?? {}
15
+ };
16
+ const details = `HTTP response: ${response ? response.status + " " + response.statusText : "<no response>"}
17
+ HTTP body:
18
+ ${body !== null ? body : "<no body>"}
19
+
20
+ GraphQL query:
21
+ ${query}`;
22
+ return new GraphQlClientError(`GraphQL request failed: ${type}`, type, request, response ?? void 0, errors, details, cause);
23
+ };
24
+ options?.onBeforeRequest?.({ query, variables: options.variables ?? {} });
25
+ try {
26
+ response = await this.doExecute(query, options);
27
+ } catch (e) {
28
+ const aborted = typeof e === "object" && e !== null && e.name === "AbortError";
29
+ throw createError(aborted ? "aborted" : "network error", void 0, e);
30
+ }
31
+ options?.onResponse?.(response);
32
+ body = await response.text();
33
+ let data;
34
+ try {
35
+ data = JSON.parse(body);
36
+ } catch (e) {
37
+ throw createError("invalid response body", void 0, e);
38
+ }
39
+ options?.onData?.(data);
40
+ if (response.status === 401) {
41
+ throw createError("unauthorized");
42
+ }
43
+ if (response.status === 403) {
44
+ throw createError("forbidden");
45
+ }
46
+ if (response.status >= 400 && response.status < 500) {
47
+ throw createError("bad request", data.errors);
48
+ }
49
+ if (response.status >= 500) {
50
+ throw createError("server error");
51
+ }
52
+ if (!(typeof data === "object") || data === null) {
53
+ throw createError("invalid response body");
54
+ }
55
+ if ("errors" in data) {
56
+ throw createError("response errors", data.errors);
57
+ }
58
+ if (!("data" in data)) {
59
+ throw createError("invalid response body");
60
+ }
61
+ return data.data;
62
+ }
63
+ async doExecute(query, { apiToken, signal, variables, headers } = {}) {
64
+ const resolvedHeaders = {
65
+ "Content-Type": "application/json",
66
+ ...headers
67
+ };
68
+ const resolvedToken = apiToken ?? this.apiToken;
69
+ if (resolvedToken !== void 0) {
70
+ resolvedHeaders["Authorization"] = `Bearer ${resolvedToken}`;
71
+ }
72
+ return await fetch(this.apiUrl, {
73
+ method: "POST",
74
+ headers: resolvedHeaders,
75
+ signal,
76
+ body: JSON.stringify({ query, variables })
77
+ });
78
+ }
79
+ }
80
+ export {
81
+ GraphQlClient
82
+ };
83
+ //# sourceMappingURL=GraphQlClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphQlClient.js","sources":["../../src/GraphQlClient.ts"],"sourcesContent":["import { GraphQlClientError, GraphQlErrorType } from './GraphQlClientError'\nimport { GraphQlClientRequestOptions } from './GraphQlClientRequestOptions'\n\nexport class GraphQlClient {\n\tconstructor(public readonly apiUrl: string, private readonly apiToken?: string) { }\n\n\tasync execute<T = unknown>(query: string, options: GraphQlClientRequestOptions = {}): Promise<T> {\n\t\tlet body: string | null = null\n\t\tlet response: Response | null = null\n\t\tconst createError = (type: GraphQlErrorType, errors?: any[], cause?: unknown) => {\n\t\t\tconst request = {\n\t\t\t\turl: this.apiUrl,\n\t\t\t\tquery,\n\t\t\t\tvariables: options.variables ?? {},\n\t\t\t}\n\n\t\t\tconst details = `HTTP response: ${response ? (response.status + ' ' + response.statusText) : '<no response>'}\nHTTP body: \n${body !== null ? body : '<no body>'}\n\nGraphQL query: \n${query}`\n\n\t\t\treturn new GraphQlClientError(`GraphQL request failed: ${type}`, type, request, response ?? undefined, errors, details, cause)\n\t\t}\n\n\t\toptions?.onBeforeRequest?.({ query, variables: options.variables ?? {} })\n\n\t\ttry {\n\t\t\tresponse = await this.doExecute(query, options)\n\t\t} catch (e) {\n\t\t\tconst aborted = typeof e === 'object' && e !== null && (e as { name?: unknown }).name === 'AbortError'\n\t\t\tthrow createError(aborted ? 'aborted' : 'network error', undefined, e)\n\t\t}\n\n\t\toptions?.onResponse?.(response)\n\n\t\tbody = await response.text()\n\n\t\tlet data: any\n\t\ttry {\n\t\t\tdata = JSON.parse(body)\n\t\t} catch (e) {\n\t\t\tthrow createError('invalid response body', undefined, e)\n\t\t}\n\t\toptions?.onData?.(data)\n\n\t\tif (response.status === 401) {\n\t\t\tthrow createError('unauthorized')\n\t\t}\n\t\tif (response.status === 403) {\n\t\t\tthrow createError('forbidden')\n\t\t}\n\t\tif (response.status >= 400 && response.status < 500) {\n\t\t\tthrow createError('bad request', data.errors)\n\t\t}\n\t\tif (response.status >= 500) {\n\t\t\tthrow createError('server error')\n\t\t}\n\t\tif (!(typeof data === 'object') || data === null) {\n\t\t\tthrow createError('invalid response body')\n\t\t}\n\t\tif ('errors' in data) {\n\t\t\tthrow createError('response errors', data.errors)\n\t\t}\n\t\tif (!('data' in data)) {\n\t\t\tthrow createError('invalid response body')\n\t\t}\n\n\t\treturn data.data\n\t}\n\n\n\tprotected async doExecute(\n\t\tquery: string,\n\t\t{ apiToken, signal, variables, headers }: GraphQlClientRequestOptions = {},\n\t): Promise<Response> {\n\t\tconst resolvedHeaders: Record<string, string> = {\n\t\t\t'Content-Type': 'application/json',\n\t\t\t...headers,\n\t\t}\n\t\tconst resolvedToken = apiToken ?? this.apiToken\n\n\t\tif (resolvedToken !== undefined) {\n\t\t\tresolvedHeaders['Authorization'] = `Bearer ${resolvedToken}`\n\t\t}\n\n\t\treturn await fetch(this.apiUrl, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: resolvedHeaders,\n\t\t\tsignal,\n\t\t\tbody: JSON.stringify({ query, variables }),\n\t\t})\n\t}\n}\n\n"],"names":[],"mappings":";AAGO,MAAM,cAAc;AAAA,EAC1B,YAA4B,QAAiC,UAAmB;AAApD,SAAA,SAAA;AAAiC,SAAA,WAAA;AAAA,EAAqB;AAAA,EAElF,MAAM,QAAqB,OAAe,UAAuC,IAAgB;AAChG,QAAI,OAAsB;AAC1B,QAAI,WAA4B;AAChC,UAAM,cAAc,CAAC,MAAwB,QAAgB,UAAoB;AAChF,YAAM,UAAU;AAAA,QACf,KAAK,KAAK;AAAA,QACV;AAAA,QACA,WAAW,QAAQ,aAAa,CAAC;AAAA,MAAA;AAGlC,YAAM,UAAU,kBAAkB,WAAY,SAAS,SAAS,MAAM,SAAS,aAAc;AAAA;AAAA,EAE9F,SAAS,OAAO,OAAO;AAAA;AAAA;AAAA,EAGvB;AAEQ,aAAA,IAAI,mBAAmB,2BAA2B,QAAQ,MAAM,SAAS,YAAY,QAAW,QAAQ,SAAS,KAAK;AAAA,IAAA;AAGrH,aAAA,kBAAkB,EAAE,OAAO,WAAW,QAAQ,aAAa,IAAI;AAEpE,QAAA;AACH,iBAAW,MAAM,KAAK,UAAU,OAAO,OAAO;AAAA,aACtC;AACR,YAAM,UAAU,OAAO,MAAM,YAAY,MAAM,QAAS,EAAyB,SAAS;AAC1F,YAAM,YAAY,UAAU,YAAY,iBAAiB,QAAW,CAAC;AAAA,IACtE;AAEA,aAAS,aAAa,QAAQ;AAEvB,WAAA,MAAM,SAAS;AAElB,QAAA;AACA,QAAA;AACI,aAAA,KAAK,MAAM,IAAI;AAAA,aACd;AACF,YAAA,YAAY,yBAAyB,QAAW,CAAC;AAAA,IACxD;AACA,aAAS,SAAS,IAAI;AAElB,QAAA,SAAS,WAAW,KAAK;AAC5B,YAAM,YAAY,cAAc;AAAA,IACjC;AACI,QAAA,SAAS,WAAW,KAAK;AAC5B,YAAM,YAAY,WAAW;AAAA,IAC9B;AACA,QAAI,SAAS,UAAU,OAAO,SAAS,SAAS,KAAK;AAC9C,YAAA,YAAY,eAAe,KAAK,MAAM;AAAA,IAC7C;AACI,QAAA,SAAS,UAAU,KAAK;AAC3B,YAAM,YAAY,cAAc;AAAA,IACjC;AACA,QAAI,EAAE,OAAO,SAAS,aAAa,SAAS,MAAM;AACjD,YAAM,YAAY,uBAAuB;AAAA,IAC1C;AACA,QAAI,YAAY,MAAM;AACf,YAAA,YAAY,mBAAmB,KAAK,MAAM;AAAA,IACjD;AACI,QAAA,EAAE,UAAU,OAAO;AACtB,YAAM,YAAY,uBAAuB;AAAA,IAC1C;AAEA,WAAO,KAAK;AAAA,EACb;AAAA,EAGA,MAAgB,UACf,OACA,EAAE,UAAU,QAAQ,WAAW,QAAyC,IAAA,IACpD;AACpB,UAAM,kBAA0C;AAAA,MAC/C,gBAAgB;AAAA,MAChB,GAAG;AAAA,IAAA;AAEE,UAAA,gBAAgB,YAAY,KAAK;AAEvC,QAAI,kBAAkB,QAAW;AAChB,sBAAA,eAAe,IAAI,UAAU;AAAA,IAC9C;AAEO,WAAA,MAAM,MAAM,KAAK,QAAQ;AAAA,MAC/B,QAAQ;AAAA,MACR,SAAS;AAAA,MACT;AAAA,MACA,MAAM,KAAK,UAAU,EAAE,OAAO,WAAW;AAAA,IAAA,CACzC;AAAA,EACF;AACD;"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ class GraphQlClientError extends Error {
4
+ constructor(message, type, request, response, errors, details, cause) {
5
+ super(message);
6
+ this.type = type;
7
+ this.request = request;
8
+ this.response = response;
9
+ this.errors = errors;
10
+ this.details = details;
11
+ this.cause = cause;
12
+ }
13
+ }
14
+ exports.GraphQlClientError = GraphQlClientError;
15
+ //# sourceMappingURL=GraphQlClientError.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphQlClientError.cjs","sources":["../../src/GraphQlClientError.ts"],"sourcesContent":["export type GraphQlErrorRequest = { url: string, query: string, variables: Record<string, any> };\n\nexport type GraphQlErrorType =\n\t| 'aborted'\n\t| 'network error'\n\t| 'invalid response body'\n\t| 'bad request'\n\t| 'unauthorized'\n\t| 'forbidden'\n\t| 'server error'\n\t| 'response errors'\n\nexport class GraphQlClientError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly type: GraphQlErrorType,\n\t\tpublic readonly request: GraphQlErrorRequest,\n\t\tpublic readonly response?: Response,\n\t\tpublic readonly errors?: readonly any[],\n\t\tpublic readonly details?: string,\n\t\tcause?: unknown,\n\t) {\n\t\tsuper(message)\n\t\tthis.cause = cause\n\t}\n}\n"],"names":[],"mappings":";;AAYO,MAAM,2BAA2B,MAAM;AAAA,EAC7C,YACC,SACgB,MACA,SACA,UACA,QACA,SAChB,OACC;AACD,UAAM,OAAO;AAPG,SAAA,OAAA;AACA,SAAA,UAAA;AACA,SAAA,WAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AAIhB,SAAK,QAAQ;AAAA,EACd;AACD;;"}
@@ -0,0 +1,15 @@
1
+ class GraphQlClientError extends Error {
2
+ constructor(message, type, request, response, errors, details, cause) {
3
+ super(message);
4
+ this.type = type;
5
+ this.request = request;
6
+ this.response = response;
7
+ this.errors = errors;
8
+ this.details = details;
9
+ this.cause = cause;
10
+ }
11
+ }
12
+ export {
13
+ GraphQlClientError
14
+ };
15
+ //# sourceMappingURL=GraphQlClientError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphQlClientError.js","sources":["../../src/GraphQlClientError.ts"],"sourcesContent":["export type GraphQlErrorRequest = { url: string, query: string, variables: Record<string, any> };\n\nexport type GraphQlErrorType =\n\t| 'aborted'\n\t| 'network error'\n\t| 'invalid response body'\n\t| 'bad request'\n\t| 'unauthorized'\n\t| 'forbidden'\n\t| 'server error'\n\t| 'response errors'\n\nexport class GraphQlClientError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly type: GraphQlErrorType,\n\t\tpublic readonly request: GraphQlErrorRequest,\n\t\tpublic readonly response?: Response,\n\t\tpublic readonly errors?: readonly any[],\n\t\tpublic readonly details?: string,\n\t\tcause?: unknown,\n\t) {\n\t\tsuper(message)\n\t\tthis.cause = cause\n\t}\n}\n"],"names":[],"mappings":"AAYO,MAAM,2BAA2B,MAAM;AAAA,EAC7C,YACC,SACgB,MACA,SACA,UACA,QACA,SAChB,OACC;AACD,UAAM,OAAO;AAPG,SAAA,OAAA;AACA,SAAA,UAAA;AACA,SAAA,WAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AAIhB,SAAK,QAAQ;AAAA,EACd;AACD;"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const GraphQlClient = require("./GraphQlClient.cjs");
4
+ const GraphQlClientError = require("./GraphQlClientError.cjs");
5
+ exports.GraphQlClient = GraphQlClient.GraphQlClient;
6
+ exports.GraphQlClientError = GraphQlClientError.GraphQlClientError;
7
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -0,0 +1,7 @@
1
+ import { GraphQlClient } from "./GraphQlClient.js";
2
+ import { GraphQlClientError } from "./GraphQlClientError.js";
3
+ export {
4
+ GraphQlClient,
5
+ GraphQlClientError
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,9 @@
1
+ import { GraphQlClientRequestOptions } from './GraphQlClientRequestOptions';
2
+ export declare class GraphQlClient {
3
+ readonly apiUrl: string;
4
+ private readonly apiToken?;
5
+ constructor(apiUrl: string, apiToken?: string | undefined);
6
+ execute<T = unknown>(query: string, options?: GraphQlClientRequestOptions): Promise<T>;
7
+ protected doExecute(query: string, { apiToken, signal, variables, headers }?: GraphQlClientRequestOptions): Promise<Response>;
8
+ }
9
+ //# sourceMappingURL=GraphQlClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphQlClient.d.ts","sourceRoot":"","sources":["../../src/GraphQlClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAA;AAE3E,qBAAa,aAAa;aACG,MAAM,EAAE,MAAM;IAAE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBAA1C,MAAM,EAAE,MAAM,EAAmB,QAAQ,CAAC,oBAAQ;IAExE,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,2BAAgC,GAAG,OAAO,CAAC,CAAC,CAAC;cAmEhF,SAAS,CACxB,KAAK,EAAE,MAAM,EACb,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAE,2BAAgC,GACxE,OAAO,CAAC,QAAQ,CAAC;CAkBpB"}
@@ -0,0 +1,15 @@
1
+ export type GraphQlErrorRequest = {
2
+ url: string;
3
+ query: string;
4
+ variables: Record<string, any>;
5
+ };
6
+ export type GraphQlErrorType = 'aborted' | 'network error' | 'invalid response body' | 'bad request' | 'unauthorized' | 'forbidden' | 'server error' | 'response errors';
7
+ export declare class GraphQlClientError extends Error {
8
+ readonly type: GraphQlErrorType;
9
+ readonly request: GraphQlErrorRequest;
10
+ readonly response?: Response | undefined;
11
+ readonly errors?: readonly any[] | undefined;
12
+ readonly details?: string | undefined;
13
+ constructor(message: string, type: GraphQlErrorType, request: GraphQlErrorRequest, response?: Response | undefined, errors?: readonly any[] | undefined, details?: string | undefined, cause?: unknown);
14
+ }
15
+ //# sourceMappingURL=GraphQlClientError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphQlClientError.d.ts","sourceRoot":"","sources":["../../src/GraphQlClientError.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,CAAC;AAEjG,MAAM,MAAM,gBAAgB,GACzB,SAAS,GACT,eAAe,GACf,uBAAuB,GACvB,aAAa,GACb,cAAc,GACd,WAAW,GACX,cAAc,GACd,iBAAiB,CAAA;AAEpB,qBAAa,kBAAmB,SAAQ,KAAK;aAG3B,IAAI,EAAE,gBAAgB;aACtB,OAAO,EAAE,mBAAmB;aAC5B,QAAQ,CAAC;aACT,MAAM,CAAC;aACP,OAAO,CAAC;gBALxB,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,mBAAmB,EAC5B,QAAQ,CAAC,sBAAU,EACnB,MAAM,CAAC,4BAAgB,EACvB,OAAO,CAAC,oBAAQ,EAChC,KAAK,CAAC,EAAE,OAAO;CAKhB"}
@@ -0,0 +1,16 @@
1
+ export interface GraphQlClientRequestOptions {
2
+ variables?: GraphQlClientVariables;
3
+ apiToken?: string;
4
+ signal?: AbortSignal;
5
+ headers?: Record<string, string>;
6
+ onBeforeRequest?: (query: {
7
+ query: string;
8
+ variables: GraphQlClientVariables;
9
+ }) => void;
10
+ onResponse?: (response: Response) => void;
11
+ onData?: (json: unknown) => void;
12
+ }
13
+ export interface GraphQlClientVariables {
14
+ [name: string]: any;
15
+ }
16
+ //# sourceMappingURL=GraphQlClientRequestOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphQlClientRequestOptions.d.ts","sourceRoot":"","sources":["../../src/GraphQlClientRequestOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,2BAA2B;IAC3C,SAAS,CAAC,EAAE,sBAAsB,CAAA;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,sBAAsB,CAAA;KAAE,KAAK,IAAI,CAAA;IACvF,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAA;IACzC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;CAChC;AAED,MAAM,WAAW,sBAAsB;IACtC,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB"}
@@ -0,0 +1,4 @@
1
+ export * from './GraphQlClient';
2
+ export * from './GraphQlClientRequestOptions';
3
+ export * from './GraphQlClientError';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,+BAA+B,CAAA;AAC7C,cAAc,sBAAsB,CAAA"}
@@ -0,0 +1 @@
1
+ {"program":{"fileNames":["../../../../node_modules/typescript/lib/lib.es5.d.ts","../../../../node_modules/typescript/lib/lib.es2015.d.ts","../../../../node_modules/typescript/lib/lib.es2016.d.ts","../../../../node_modules/typescript/lib/lib.es2017.d.ts","../../../../node_modules/typescript/lib/lib.es2018.d.ts","../../../../node_modules/typescript/lib/lib.es2019.d.ts","../../../../node_modules/typescript/lib/lib.es2020.d.ts","../../../../node_modules/typescript/lib/lib.es2021.d.ts","../../../../node_modules/typescript/lib/lib.es2022.d.ts","../../../../node_modules/typescript/lib/lib.es2023.d.ts","../../../../node_modules/typescript/lib/lib.esnext.d.ts","../../../../node_modules/typescript/lib/lib.dom.d.ts","../../../../node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../../node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../../node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2022.array.d.ts","../../../../node_modules/typescript/lib/lib.es2022.error.d.ts","../../../../node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2022.object.d.ts","../../../../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../../../../node_modules/typescript/lib/lib.es2022.string.d.ts","../../../../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../../../node_modules/typescript/lib/lib.es2023.array.d.ts","../../../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../../../node_modules/typescript/lib/lib.decorators.d.ts","../../../../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../../node_modules/@types/react/ts5.0/global.d.ts","../../../../node_modules/@types/react/node_modules/csstype/index.d.ts","../../../../node_modules/@types/prop-types/index.d.ts","../../../../node_modules/@types/scheduler/tracing.d.ts","../../../../node_modules/@types/react/ts5.0/index.d.ts","../../../../node_modules/@types/react/ts5.0/jsx-runtime.d.ts","../../src/GraphQlClientError.ts","../../src/GraphQlClientRequestOptions.ts","../../src/GraphQlClient.ts","../../src/index.ts","../../../../node_modules/vite/types/hmrPayload.d.ts","../../../../node_modules/vite/types/customEvent.d.ts","../../../../node_modules/vite/types/hot.d.ts","../../../../node_modules/vite/types/importGlob.d.ts","../../../../node_modules/vite/types/importMeta.d.ts","../../../../node_modules/vite/client.d.ts"],"fileInfos":[{"version":"6a6b471e7e43e15ef6f8fe617a22ce4ecb0e34efa6c3dfcfe7cebd392bcca9d2","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","dc48272d7c333ccf58034c0026162576b7d50ea0e69c3b9292f803fc20720fd5","27147504487dc1159369da4f4da8a26406364624fa9bc3db632f7d94a5bae2c3","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","f4e736d6c8d69ae5b3ab0ddfcaa3dc365c3e76909d6660af5b4e979b3934ac20","eeeb3aca31fbadef8b82502484499dfd1757204799a6f5b33116201c810676ec",{"version":"fcd3ecc9f764f06f4d5c467677f4f117f6abf49dee6716283aa204ff1162498b","affectsGlobalScope":true},{"version":"9a60b92bca4c1257db03b349d58e63e4868cfc0d1c8d0ba60c2dbc63f4e6c9f6","affectsGlobalScope":true},{"version":"f296963760430fb65b4e5d91f0ed770a91c6e77455bacf8fa23a1501654ede0e","affectsGlobalScope":true},{"version":"5114a95689b63f96b957e00216bc04baf9e1a1782aa4d8ee7e5e9acbf768e301","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"ab22100fdd0d24cfc2cc59d0a00fc8cf449830d9c4030dc54390a46bd562e929","affectsGlobalScope":true},{"version":"f7bd636ae3a4623c503359ada74510c4005df5b36de7f23e1db8a5c543fd176b","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"0c20f4d2358eb679e4ae8a4432bdd96c857a2960fd6800b21ec4008ec59d60ea","affectsGlobalScope":true},{"version":"36ae84ccc0633f7c0787bc6108386c8b773e95d3b052d9464a99cd9b8795fbec","affectsGlobalScope":true},{"version":"82d0d8e269b9eeac02c3bd1c9e884e85d483fcb2cd168bccd6bc54df663da031","affectsGlobalScope":true},{"version":"b8deab98702588840be73d67f02412a2d45a417a3c097b2e96f7f3a42ac483d1","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"376d554d042fb409cb55b5cbaf0b2b4b7e669619493c5d18d5fa8bd67273f82a","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"c4138a3dd7cd6cf1f363ca0f905554e8d81b45844feea17786cdf1626cb8ea06","affectsGlobalScope":true},{"version":"6ff3e2452b055d8f0ec026511c6582b55d935675af67cdb67dd1dc671e8065df","affectsGlobalScope":true},{"version":"03de17b810f426a2f47396b0b99b53a82c1b60e9cba7a7edda47f9bb077882f4","affectsGlobalScope":true},{"version":"8184c6ddf48f0c98429326b428478ecc6143c27f79b79e85740f17e6feb090f1","affectsGlobalScope":true},{"version":"261c4d2cf86ac5a89ad3fb3fafed74cbb6f2f7c1d139b0540933df567d64a6ca","affectsGlobalScope":true},{"version":"6af1425e9973f4924fca986636ac19a0cf9909a7e0d9d3009c349e6244e957b6","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"15a630d6817718a2ddd7088c4f83e4673fde19fa992d2eae2cf51132a302a5d3","affectsGlobalScope":true},{"version":"b7e9f95a7387e3f66be0ed6db43600c49cec33a3900437ce2fd350d9b7cb16f2","affectsGlobalScope":true},{"version":"01e0ee7e1f661acedb08b51f8a9b7d7f959e9cdb6441360f06522cc3aea1bf2e","affectsGlobalScope":true},{"version":"ac17a97f816d53d9dd79b0d235e1c0ed54a8cc6a0677e9a3d61efb480b2a3e4e","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"ec0104fee478075cb5171e5f4e3f23add8e02d845ae0165bfa3f1099241fa2aa","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"9cc66b0513ad41cb5f5372cca86ef83a0d37d1c1017580b7dace3ea5661836df","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"709efdae0cb5df5f49376cde61daacc95cdd44ae4671da13a540da5088bf3f30","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"61ed9b6d07af959e745fb11f9593ecd743b279418cc8a99448ea3cd5f3b3eb22","affectsGlobalScope":true},{"version":"038a2f66a34ee7a9c2fbc3584c8ab43dff2995f8c68e3f566f4c300d2175e31e","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"f5c92f2c27b06c1a41b88f6db8299205aee52c2a2943f7ed29bd585977f254e8","affectsGlobalScope":true},{"version":"b7feb7967c6c6003e11f49efa8f5de989484e0a6ba2e5a6c41b55f8b8bd85dba","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"b9ea5778ff8b50d7c04c9890170db34c26a5358cccba36844fe319f50a43a61a","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"25de46552b782d43cb7284df22fe2a265de387cf0248b747a7a1b647d81861f6","affectsGlobalScope":true},{"version":"307c8b7ebbd7f23a92b73a4c6c0a697beca05b06b036c23a34553e5fe65e4fdc","affectsGlobalScope":true},{"version":"189c0703923150aa30673fa3de411346d727cc44a11c75d05d7cf9ef095daa22","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},{"version":"49a253ec027e56c55c7450a0c331cfe96212b3d1cc215b1710ba94a083404cf3","affectsGlobalScope":true},"1c29793071152b207c01ea1954e343be9a44d85234447b2b236acae9e709a383","6a386ff939f180ae8ef064699d8b7b6e62bc2731a62d7fbf5e02589383838dea","f5a8b384f182b3851cec3596ccc96cb7464f8d3469f48c74bf2befb782a19de5",{"version":"278fe30e638dad09488d130287c728f99f61cb315ed86b70c36040e4311f9cf5","affectsGlobalScope":true},"af7fd2870746deed40e130fc0a3966de74e8f52a97ec114d0fbb35876ab05ca9",{"version":"317df6f67cd84eb05f8190314cd60526f8563553f8b73e3ed6cf8f465f130282","signature":"4d023a0827a63ad5e6b498f92830d79e40e6fd487ed6b7c6fc2528eb9b3c0937"},{"version":"f271a74afa1913c319ee7f124ef2b7928849255d8eab4af9813b3044e3ed3ae0","signature":"8c56ed339fb7ea09a933aae91daa038e669730da6b6d422275d0a7e5293b46a7"},{"version":"3fb49697afa1fb63be67efb19eac4d558f106ce62deae86b5fd92413177aa5ed","signature":"711255f9dda18a35389ec1e3fa8ebe6e906e67902550afad96b0ac6c5a5de327"},{"version":"5f2c3b244c56a91793fe2c4e81c47fce91cede200a1ef4190d31cd7ea5efc4a3","signature":"e17fbde86ef68adc663fff12c63cce11175482b3f108afd90fa3c11754afe6c6"},"bcb6ea18f23dae2c48459d7b86d3adccd6898f824fcbf9da08b935f559896580","0aa7220845f5f3902fe043f646f9d9218bd7dd6c4046e8471580866ea6b03aa2","4d5fb5d6b35f731b2ae4d9d7c592d48e91d6de531dd130628edf4eba16add893","739c2c46edc112421fc023c24b4898b1f413f792bb6a02b40ba182c648e56c2f",{"version":"df93bb67d5ae7be3d599323de42e12cb8da59f0b490c3186ae91d493632b5e36","affectsGlobalScope":true},{"version":"f8b8b34c4f7651c9f7b126af8affda4139a0499e62e74f0f8dc2be36e9f14b59","affectsGlobalScope":true}],"root":[[68,71]],"options":{"allowSyntheticDefaultImports":true,"composite":true,"declaration":true,"declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":true,"experimentalDecorators":true,"jsx":4,"module":99,"noEmitOnError":true,"noImplicitOverride":true,"outDir":"./","skipLibCheck":true,"sourceMap":true,"strict":true,"target":7,"useDefineForClassFields":true},"fileIdsList":[[62,63,64,65],[66],[76],[72],[73],[74,75],[67,68,69],[67],[67,68,69,70],[69],[68,69,70]],"referencedMap":[[66,1],[67,2],[77,3],[73,4],[74,5],[76,6],[70,7],[68,8],[69,8],[71,9]],"exportedModulesMap":[[66,1],[67,2],[77,3],[73,4],[74,5],[76,6],[70,10],[71,11]],"semanticDiagnosticsPerFile":[64,63,62,66,67,65,60,61,12,13,15,14,2,16,17,18,19,20,21,22,23,3,4,27,24,25,26,28,29,30,5,31,32,33,34,6,38,35,36,37,39,7,40,45,46,41,42,43,44,8,50,47,48,49,51,9,52,53,54,57,55,56,58,10,1,11,59,77,73,72,74,75,76,70,68,69,71],"latestChangedDtsFile":"./index.d.ts"},"version":"5.0.4"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@contember/graphql-client",
3
+ "license": "Apache-2.0",
4
+ "version": "1.3.0-alpha.2",
5
+ "main": "./dist/production/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "import": {
9
+ "types": "./dist/types/index.d.ts",
10
+ "development": "./dist/development/index.js",
11
+ "production": "./dist/production/index.js",
12
+ "default": "./dist/production/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/types/index.d.ts",
16
+ "development": "./dist/development/index.cjs",
17
+ "production": "./dist/production/index.cjs",
18
+ "default": "./dist/production/index.cjs"
19
+ }
20
+ }
21
+ },
22
+ "files": [
23
+ "dist/",
24
+ "src/"
25
+ ],
26
+ "typings": "./dist/types/index.d.ts",
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "scripts": {
30
+ "build": "yarn build:js:dev && yarn build:js:prod",
31
+ "build:js:dev": "NODE_ENV=development vite build --mode development",
32
+ "build:js:prod": "vite build --mode production",
33
+ "ae:build": "api-extractor run --local",
34
+ "ae:test": "api-extractor run",
35
+ "test": "vitest"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/contember/interface.git",
40
+ "directory": "packages/graphql-client"
41
+ },
42
+ "stableVersion": "0.0.0"
43
+ }
@@ -0,0 +1,96 @@
1
+ import { GraphQlClientError, GraphQlErrorType } from './GraphQlClientError'
2
+ import { GraphQlClientRequestOptions } from './GraphQlClientRequestOptions'
3
+
4
+ export class GraphQlClient {
5
+ constructor(public readonly apiUrl: string, private readonly apiToken?: string) { }
6
+
7
+ async execute<T = unknown>(query: string, options: GraphQlClientRequestOptions = {}): Promise<T> {
8
+ let body: string | null = null
9
+ let response: Response | null = null
10
+ const createError = (type: GraphQlErrorType, errors?: any[], cause?: unknown) => {
11
+ const request = {
12
+ url: this.apiUrl,
13
+ query,
14
+ variables: options.variables ?? {},
15
+ }
16
+
17
+ const details = `HTTP response: ${response ? (response.status + ' ' + response.statusText) : '<no response>'}
18
+ HTTP body:
19
+ ${body !== null ? body : '<no body>'}
20
+
21
+ GraphQL query:
22
+ ${query}`
23
+
24
+ return new GraphQlClientError(`GraphQL request failed: ${type}`, type, request, response ?? undefined, errors, details, cause)
25
+ }
26
+
27
+ options?.onBeforeRequest?.({ query, variables: options.variables ?? {} })
28
+
29
+ try {
30
+ response = await this.doExecute(query, options)
31
+ } catch (e) {
32
+ const aborted = typeof e === 'object' && e !== null && (e as { name?: unknown }).name === 'AbortError'
33
+ throw createError(aborted ? 'aborted' : 'network error', undefined, e)
34
+ }
35
+
36
+ options?.onResponse?.(response)
37
+
38
+ body = await response.text()
39
+
40
+ let data: any
41
+ try {
42
+ data = JSON.parse(body)
43
+ } catch (e) {
44
+ throw createError('invalid response body', undefined, e)
45
+ }
46
+ options?.onData?.(data)
47
+
48
+ if (response.status === 401) {
49
+ throw createError('unauthorized')
50
+ }
51
+ if (response.status === 403) {
52
+ throw createError('forbidden')
53
+ }
54
+ if (response.status >= 400 && response.status < 500) {
55
+ throw createError('bad request', data.errors)
56
+ }
57
+ if (response.status >= 500) {
58
+ throw createError('server error')
59
+ }
60
+ if (!(typeof data === 'object') || data === null) {
61
+ throw createError('invalid response body')
62
+ }
63
+ if ('errors' in data) {
64
+ throw createError('response errors', data.errors)
65
+ }
66
+ if (!('data' in data)) {
67
+ throw createError('invalid response body')
68
+ }
69
+
70
+ return data.data
71
+ }
72
+
73
+
74
+ protected async doExecute(
75
+ query: string,
76
+ { apiToken, signal, variables, headers }: GraphQlClientRequestOptions = {},
77
+ ): Promise<Response> {
78
+ const resolvedHeaders: Record<string, string> = {
79
+ 'Content-Type': 'application/json',
80
+ ...headers,
81
+ }
82
+ const resolvedToken = apiToken ?? this.apiToken
83
+
84
+ if (resolvedToken !== undefined) {
85
+ resolvedHeaders['Authorization'] = `Bearer ${resolvedToken}`
86
+ }
87
+
88
+ return await fetch(this.apiUrl, {
89
+ method: 'POST',
90
+ headers: resolvedHeaders,
91
+ signal,
92
+ body: JSON.stringify({ query, variables }),
93
+ })
94
+ }
95
+ }
96
+
@@ -0,0 +1,26 @@
1
+ export type GraphQlErrorRequest = { url: string, query: string, variables: Record<string, any> };
2
+
3
+ export type GraphQlErrorType =
4
+ | 'aborted'
5
+ | 'network error'
6
+ | 'invalid response body'
7
+ | 'bad request'
8
+ | 'unauthorized'
9
+ | 'forbidden'
10
+ | 'server error'
11
+ | 'response errors'
12
+
13
+ export class GraphQlClientError extends Error {
14
+ constructor(
15
+ message: string,
16
+ public readonly type: GraphQlErrorType,
17
+ public readonly request: GraphQlErrorRequest,
18
+ public readonly response?: Response,
19
+ public readonly errors?: readonly any[],
20
+ public readonly details?: string,
21
+ cause?: unknown,
22
+ ) {
23
+ super(message)
24
+ this.cause = cause
25
+ }
26
+ }
@@ -0,0 +1,13 @@
1
+ export interface GraphQlClientRequestOptions {
2
+ variables?: GraphQlClientVariables
3
+ apiToken?: string
4
+ signal?: AbortSignal
5
+ headers?: Record<string, string>
6
+ onBeforeRequest?: (query: { query: string, variables: GraphQlClientVariables }) => void
7
+ onResponse?: (response: Response) => void
8
+ onData?: (json: unknown) => void
9
+ }
10
+
11
+ export interface GraphQlClientVariables {
12
+ [name: string]: any
13
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './GraphQlClient'
2
+ export * from './GraphQlClientRequestOptions'
3
+ export * from './GraphQlClientError'
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "../../../tsconfig.settings.json",
3
+ "compilerOptions": {
4
+ "outDir": "../dist/types"
5
+ }
6
+ }