@nxgt/datasource-rest 1.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 ADDED
@@ -0,0 +1,15 @@
1
+ # @nxgt/shared
2
+
3
+ To install dependencies:
4
+
5
+ ```bash
6
+ bun i
7
+ ```
8
+
9
+ To run:
10
+
11
+ ```bash
12
+ bun run src/index.ts
13
+ ```
14
+
15
+ This project was created using `bun init` in bun v1.3.9. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
@@ -0,0 +1,3 @@
1
+ import { CustomException } from '@nxgt/shared-exceptions';
2
+ export declare function errorToException(error: any, response: Response): CustomException<any>;
3
+ //# sourceMappingURL=error-handling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handling.d.ts","sourceRoot":"","sources":["../../src/helpers/error-handling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAa,MAAM,yBAAyB,CAAC;AAErE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,wBAyB9D"}
@@ -0,0 +1,3 @@
1
+ export * from './error-handling';
2
+ export * from './pagination.utils';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Connection, Paginated } from '../types';
2
+ export declare function relayPaginate<T extends {
3
+ id: string;
4
+ }>(data: Paginated<T>): Connection<T>;
5
+ //# sourceMappingURL=pagination.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.utils.d.ts","sourceRoot":"","sources":["../../src/helpers/pagination.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEtD,wBAAgB,aAAa,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EACrD,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,GAChB,UAAU,CAAC,CAAC,CAAC,CAcf"}
@@ -0,0 +1,4 @@
1
+ export * from './helpers';
2
+ export * from './middlewares';
3
+ export * from './rest-datasource';
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,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,111 @@
1
+ // src/helpers/error-handling.ts
2
+ import { CustomException, ErrorCode } from "@nxgt/shared-exceptions";
3
+ function errorToException(error, response) {
4
+ let status = ErrorCode.BadRequest;
5
+ switch (response.status) {
6
+ case 401:
7
+ status = ErrorCode.Unauthenticated;
8
+ break;
9
+ case 403:
10
+ status = ErrorCode.Forbidden;
11
+ break;
12
+ case 404:
13
+ status = ErrorCode.NotFound;
14
+ break;
15
+ case 500:
16
+ status = ErrorCode.InternalServerError;
17
+ break;
18
+ default:
19
+ status = ErrorCode.BadRequest;
20
+ }
21
+ return CustomException.from({
22
+ message: error?.message || "An error occurred",
23
+ code: status,
24
+ options: {},
25
+ debugMessage: error?.debugMessage
26
+ });
27
+ }
28
+ // src/helpers/pagination.utils.ts
29
+ function relayPaginate(data) {
30
+ const { data: items, metadata } = data;
31
+ return {
32
+ edges: (items ?? []).map((item) => ({
33
+ node: item,
34
+ cursor: item.id
35
+ })),
36
+ pageInfo: metadata ?? {
37
+ startCursor: undefined,
38
+ endCursor: undefined,
39
+ hasNextPage: false,
40
+ totalElements: 0
41
+ }
42
+ };
43
+ }
44
+ // src/middlewares/auth.middleware.ts
45
+ var authMiddleware = (options) => ({
46
+ onRequest({ request }) {
47
+ if (!options.token) {
48
+ return;
49
+ }
50
+ if (options.shouldUseToken && !options.shouldUseToken(request)) {
51
+ return;
52
+ }
53
+ request.headers.set("Authorization", `Bearer ${typeof options.token === "function" ? options.token() : options.token}`);
54
+ }
55
+ });
56
+ // src/middlewares/cache.middleware.ts
57
+ var cache = new Map;
58
+ var getCacheKey = (request) => `${request.method}:${request.url}`;
59
+ var cacheMiddleware = ({
60
+ ttl = 5 * 60 * 1000,
61
+ shouldCachePostRequest = (req) => req.url.includes("/search")
62
+ } = {}) => ({
63
+ onRequest({ request }) {
64
+ const key = getCacheKey(request);
65
+ const cached = cache.get(key);
66
+ if (cached && cached.expiry > Date.now()) {
67
+ return cached.value.clone();
68
+ }
69
+ cache.delete(key);
70
+ },
71
+ onResponse({ request, response }) {
72
+ if (response.ok) {
73
+ if (request.method === "POST" && !shouldCachePostRequest?.(request)) {
74
+ return;
75
+ }
76
+ const key = getCacheKey(request);
77
+ cache.set(key, {
78
+ expiry: Date.now() + ttl,
79
+ value: response.clone()
80
+ });
81
+ }
82
+ }
83
+ });
84
+ // src/rest-datasource.ts
85
+ class RESTDataSource {
86
+ constructor(options) {
87
+ this.client = options.client;
88
+ this.client.use(cacheMiddleware(options.cacheOptions));
89
+ if (options.authOptions) {
90
+ this.client.use(authMiddleware(options.authOptions));
91
+ }
92
+ this.get = this.client.GET;
93
+ this.post = this.client.POST;
94
+ this.put = this.client.PUT;
95
+ this.patch = this.client.PATCH;
96
+ this.delete = this.client.DELETE;
97
+ this.head = this.client.HEAD;
98
+ this.options = this.client.OPTIONS;
99
+ this.trace = this.client.TRACE;
100
+ }
101
+ }
102
+ export {
103
+ RESTDataSource,
104
+ authMiddleware,
105
+ cacheMiddleware,
106
+ errorToException,
107
+ relayPaginate
108
+ };
109
+
110
+ //# debugId=B0900E11F81FD7B064756E2164756E21
111
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/helpers/error-handling.ts", "../src/helpers/pagination.utils.ts", "../src/middlewares/auth.middleware.ts", "../src/middlewares/cache.middleware.ts", "../src/rest-datasource.ts"],
4
+ "sourcesContent": [
5
+ "import { CustomException, ErrorCode } from '@nxgt/shared-exceptions';\n\nexport function errorToException(error: any, response: Response) {\n\tlet status = ErrorCode.BadRequest;\n\tswitch (response.status) {\n\t\tcase 401:\n\t\t\tstatus = ErrorCode.Unauthenticated;\n\t\t\tbreak;\n\t\tcase 403:\n\t\t\tstatus = ErrorCode.Forbidden;\n\t\t\tbreak;\n\t\tcase 404:\n\t\t\tstatus = ErrorCode.NotFound;\n\t\t\tbreak;\n\t\tcase 500:\n\t\t\tstatus = ErrorCode.InternalServerError;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tstatus = ErrorCode.BadRequest;\n\t}\n\n\treturn CustomException.from({\n\t\tmessage: error?.message || 'An error occurred',\n\t\tcode: status,\n\t\toptions: {},\n\t\tdebugMessage: error?.debugMessage,\n\t});\n}\n",
6
+ "import type { Connection, Paginated } from '../types';\n\nexport function relayPaginate<T extends { id: string }>(\n\tdata: Paginated<T>,\n): Connection<T> {\n\tconst { data: items, metadata } = data;\n\treturn {\n\t\tedges: (items ?? []).map((item) => ({\n\t\t\tnode: item,\n\t\t\tcursor: item.id,\n\t\t})),\n\t\tpageInfo: metadata ?? {\n\t\t\tstartCursor: undefined,\n\t\t\tendCursor: undefined,\n\t\t\thasNextPage: false,\n\t\t\ttotalElements: 0,\n\t\t},\n\t};\n}\n",
7
+ "import type { Middleware } from 'openapi-fetch';\n\nexport type AuthMiddlewareOptions = {\n\ttoken?: string | (() => Promise<string>);\n\tshouldUseToken?: (request: Request) => boolean;\n};\n\nexport const authMiddleware = (options: AuthMiddlewareOptions): Middleware => ({\n\tonRequest({ request }) {\n\t\tif (!options.token) {\n\t\t\treturn;\n\t\t}\n\t\tif (options.shouldUseToken && !options.shouldUseToken(request)) {\n\t\t\treturn;\n\t\t}\n\t\trequest.headers.set(\n\t\t\t'Authorization',\n\t\t\t`Bearer ${typeof options.token === 'function' ? options.token() : options.token}`,\n\t\t);\n\t},\n});\n",
8
+ "import type { Middleware } from 'openapi-fetch';\n\nconst cache = new Map<string, { expiry: number; value: Response }>();\nconst getCacheKey = (request: Request) => `${request.method}:${request.url}`;\n\nexport type CacheMiddlewareOptions = {\n\tttl?: number;\n\tshouldCachePostRequest?: (req: Request) => boolean;\n};\n\nexport const cacheMiddleware = ({\n\tttl = 5 * 60 * 1000, // default TTL: 5 minutes\n\tshouldCachePostRequest = (req) => req.url.includes('/search'),\n}: CacheMiddlewareOptions = {}): Middleware => ({\n\tonRequest({ request }) {\n\t\tconst key = getCacheKey(request);\n\t\tconst cached = cache.get(key);\n\t\tif (cached && cached.expiry > Date.now()) {\n\t\t\treturn cached.value.clone();\n\t\t}\n\t\tcache.delete(key);\n\t},\n\tonResponse({ request, response }) {\n\t\tif (response.ok) {\n\t\t\tif (request.method === 'POST' && !shouldCachePostRequest?.(request)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst key = getCacheKey(request);\n\t\t\tcache.set(key, {\n\t\t\t\texpiry: Date.now() + ttl,\n\t\t\t\tvalue: response.clone(),\n\t\t\t});\n\t\t}\n\t},\n});\n",
9
+ "import type { Client, ClientMethod } from 'openapi-fetch';\nimport {\n\ttype AuthMiddlewareOptions,\n\tauthMiddleware,\n\ttype CacheMiddlewareOptions,\n\tcacheMiddleware,\n} from './middlewares';\nimport type { MediaType } from './types';\n\nexport type RESTDataSourceOptions<\n\tPaths extends {},\n\tMedia extends MediaType = MediaType,\n> = {\n\tclient: Client<Paths, Media>;\n\tcacheOptions?: CacheMiddlewareOptions;\n\tauthOptions?: AuthMiddlewareOptions;\n};\n\nexport class RESTDataSource<\n\tPaths extends {},\n\tMedia extends MediaType = MediaType,\n> {\n\tprotected client: Client<Paths, Media>;\n\n\tget: ClientMethod<Paths, 'get', Media>;\n\tpost: ClientMethod<Paths, 'post', Media>;\n\tput: ClientMethod<Paths, 'put', Media>;\n\tpatch: ClientMethod<Paths, 'patch', Media>;\n\tdelete: ClientMethod<Paths, 'delete', Media>;\n\thead: ClientMethod<Paths, 'head', Media>;\n\toptions: ClientMethod<Paths, 'options', Media>;\n\ttrace: ClientMethod<Paths, 'trace', Media>;\n\n\tconstructor(options: RESTDataSourceOptions<Paths, Media>) {\n\t\tthis.client = options.client;\n\t\tthis.client.use(cacheMiddleware(options.cacheOptions));\n\t\tif (options.authOptions) {\n\t\t\tthis.client.use(authMiddleware(options.authOptions));\n\t\t}\n\t\tthis.get = this.client.GET;\n\t\tthis.post = this.client.POST;\n\t\tthis.put = this.client.PUT;\n\t\tthis.patch = this.client.PATCH;\n\t\tthis.delete = this.client.DELETE;\n\t\tthis.head = this.client.HEAD;\n\t\tthis.options = this.client.OPTIONS;\n\t\tthis.trace = this.client.TRACE;\n\t}\n}\n"
10
+ ],
11
+ "mappings": "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",
12
+ "debugId": "B0900E11F81FD7B064756E2164756E21",
13
+ "names": []
14
+ }
@@ -0,0 +1,7 @@
1
+ import type { Middleware } from 'openapi-fetch';
2
+ export type AuthMiddlewareOptions = {
3
+ token?: string | (() => Promise<string>);
4
+ shouldUseToken?: (request: Request) => boolean;
5
+ };
6
+ export declare const authMiddleware: (options: AuthMiddlewareOptions) => Middleware;
7
+ //# sourceMappingURL=auth.middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.middleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/auth.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,MAAM,qBAAqB,GAAG;IACnC,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACzC,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;CAC/C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,SAAS,qBAAqB,KAAG,UAa9D,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Middleware } from 'openapi-fetch';
2
+ export type CacheMiddlewareOptions = {
3
+ ttl?: number;
4
+ shouldCachePostRequest?: (req: Request) => boolean;
5
+ };
6
+ export declare const cacheMiddleware: ({ ttl, shouldCachePostRequest, }?: CacheMiddlewareOptions) => Middleware;
7
+ //# sourceMappingURL=cache.middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.middleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/cache.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAKhD,MAAM,MAAM,sBAAsB,GAAG;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,sBAAsB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;CACnD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,mCAG7B,sBAA2B,KAAG,UAqB/B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './auth.middleware';
2
+ export * from './cache.middleware';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { Client, ClientMethod } from 'openapi-fetch';
2
+ import { type AuthMiddlewareOptions, type CacheMiddlewareOptions } from './middlewares';
3
+ import type { MediaType } from './types';
4
+ export type RESTDataSourceOptions<Paths extends {}, Media extends MediaType = MediaType> = {
5
+ client: Client<Paths, Media>;
6
+ cacheOptions?: CacheMiddlewareOptions;
7
+ authOptions?: AuthMiddlewareOptions;
8
+ };
9
+ export declare class RESTDataSource<Paths extends {}, Media extends MediaType = MediaType> {
10
+ protected client: Client<Paths, Media>;
11
+ get: ClientMethod<Paths, 'get', Media>;
12
+ post: ClientMethod<Paths, 'post', Media>;
13
+ put: ClientMethod<Paths, 'put', Media>;
14
+ patch: ClientMethod<Paths, 'patch', Media>;
15
+ delete: ClientMethod<Paths, 'delete', Media>;
16
+ head: ClientMethod<Paths, 'head', Media>;
17
+ options: ClientMethod<Paths, 'options', Media>;
18
+ trace: ClientMethod<Paths, 'trace', Media>;
19
+ constructor(options: RESTDataSourceOptions<Paths, Media>);
20
+ }
21
+ //# sourceMappingURL=rest-datasource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest-datasource.d.ts","sourceRoot":"","sources":["../src/rest-datasource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EACN,KAAK,qBAAqB,EAE1B,KAAK,sBAAsB,EAE3B,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,MAAM,qBAAqB,CAChC,KAAK,SAAS,EAAE,EAChB,KAAK,SAAS,SAAS,GAAG,SAAS,IAChC;IACH,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC7B,YAAY,CAAC,EAAE,sBAAsB,CAAC;IACtC,WAAW,CAAC,EAAE,qBAAqB,CAAC;CACpC,CAAC;AAEF,qBAAa,cAAc,CAC1B,KAAK,SAAS,EAAE,EAChB,KAAK,SAAS,SAAS,GAAG,SAAS;IAEnC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAEvC,GAAG,EAAE,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACvC,IAAI,EAAE,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACzC,GAAG,EAAE,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACvC,KAAK,EAAE,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3C,MAAM,EAAE,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC7C,IAAI,EAAE,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACzC,OAAO,EAAE,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAC/C,KAAK,EAAE,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;gBAE/B,OAAO,EAAE,qBAAqB,CAAC,KAAK,EAAE,KAAK,CAAC;CAexD"}
@@ -0,0 +1,39 @@
1
+ export type MediaType = `${string}/${string}`;
2
+ export type UpperHttpMethod = 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH' | 'TRACE';
3
+ export type HttpMethod = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace';
4
+ export type ErrorResponse = {
5
+ status?: number;
6
+ message?: string;
7
+ debugMessage?: string;
8
+ };
9
+ export interface PageInfo {
10
+ /**
11
+ * The cursor of the first item in the result set.
12
+ */
13
+ startCursor?: string;
14
+ /**
15
+ * The cursor of the last item in the result set.
16
+ */
17
+ endCursor?: string;
18
+ /**
19
+ * Indicates whether there are more items after the current page.
20
+ */
21
+ hasNextPage: boolean;
22
+ /**
23
+ * The total number of elements across all pages.
24
+ */
25
+ totalElements: number;
26
+ }
27
+ export type Paginated<T> = {
28
+ data?: T[];
29
+ metadata?: PageInfo;
30
+ };
31
+ export type Edge<T> = {
32
+ node: T;
33
+ cursor: string;
34
+ };
35
+ export type Connection<T> = {
36
+ edges: Edge<T>[];
37
+ pageInfo: PageInfo;
38
+ };
39
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;AAE9C,MAAM,MAAM,eAAe,GACxB,KAAK,GACL,KAAK,GACL,MAAM,GACN,QAAQ,GACR,SAAS,GACT,MAAM,GACN,OAAO,GACP,OAAO,CAAC;AAEX,MAAM,MAAM,UAAU,GACnB,KAAK,GACL,KAAK,GACL,MAAM,GACN,QAAQ,GACR,SAAS,GACT,MAAM,GACN,OAAO,GACP,OAAO,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,WAAW,QAAQ;IACxB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAC1B,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;IACX,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;IACrB,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAC3B,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;CACnB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@nxgt/datasource-rest",
3
+ "version": "1.0.0",
4
+ "license": "UNLICENSED",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md",
11
+ "package.json"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js",
17
+ "default": "./dist/index.js"
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/softistx/nxgt-core.git",
24
+ "directory": "packages/datasource-rest"
25
+ },
26
+ "publishConfig": {
27
+ "registry": "https://registry.npmjs.org",
28
+ "access": "public"
29
+ },
30
+ "scripts": {
31
+ "build": "bun run ../../build.ts",
32
+ "typecheck": "tsc --noEmit"
33
+ },
34
+ "nxgt": {
35
+ "entrypoints": [
36
+ "src/index.ts"
37
+ ]
38
+ },
39
+ "dependencies": {
40
+ "lodash": "^4.18.1",
41
+ "@nxgt/shared": "1.0.0",
42
+ "@nxgt/shared-exceptions": "1.0.0",
43
+ "openapi-fetch": "^0.17.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/bun": "^1.4.0",
47
+ "@types/lodash": "^4.17.24"
48
+ },
49
+ "peerDependencies": {
50
+ "typescript": "^6.0.3"
51
+ }
52
+ }