@marteye/studiojs 1.0.0 → 1.1.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/src/net/http.ts DELETED
@@ -1,53 +0,0 @@
1
- export default function SimpleHttpClient(
2
- baseUrl: string,
3
- apiKey: string,
4
- fetch: any,
5
- defaultTimeout: number
6
- ) {
7
- async function request<T>(method: string, path: string, body?: any) {
8
- let controller = new AbortController();
9
-
10
- let t = setTimeout(() => {
11
- controller.abort();
12
- }, defaultTimeout);
13
-
14
- let requestInit: any = {
15
- method,
16
- headers: {
17
- "Content-Type": "application/json",
18
- Authorization: `Bearer ${apiKey}`,
19
- },
20
- signal: controller.signal,
21
- };
22
-
23
- if (body) {
24
- requestInit.body = typeof body === "string" ? body : JSON.stringify(body);
25
- }
26
-
27
- let response = await fetch(`${baseUrl}${path}`, requestInit);
28
- clearTimeout(t);
29
-
30
- if (response.ok) {
31
- return response.json() as T;
32
- }
33
-
34
- if (response.status === 404) {
35
- throw new Error(`${baseUrl}${path} not found`);
36
- }
37
-
38
- throw new Error(
39
- `Request failed with status ${response.status}: ${await response.text()}}`
40
- );
41
- }
42
-
43
- return {
44
- get: async <T>(path: string) => {
45
- return request<T>("GET", path);
46
- },
47
- post: async <T>(path: string, body: any) => {
48
- return request<T>("GET", path, body);
49
- },
50
- };
51
- }
52
-
53
- export type HttpClient = ReturnType<typeof SimpleHttpClient>;
@@ -1,10 +0,0 @@
1
- import { Lot } from "../all-types";
2
- import { HttpClient } from "../net/http";
3
-
4
- export default function create(httpClient: HttpClient) {
5
- return {
6
- get: async (marketId: string, saleId: string, lotId: string) => {
7
- return httpClient.get<Lot>(`/${marketId}/sales/${saleId}/lots/${lotId}`);
8
- },
9
- };
10
- }
@@ -1,14 +0,0 @@
1
- // Path: studiojs/src/resources/markets.ts
2
-
3
- import { Market } from "../all-types";
4
- import { HttpClient } from "../net/http";
5
-
6
- export default function create(httpClient: HttpClient) {
7
- const markets = {
8
- get: async (marketId: string) => {
9
- return httpClient.get<Market>(`/${marketId}`);
10
- },
11
- };
12
-
13
- return markets;
14
- }
@@ -1,5 +0,0 @@
1
- test("hello world", () => {
2
- expect(1).toBe(1);
3
- });
4
-
5
- export {};
@@ -1,10 +0,0 @@
1
- import { Sale } from "../all-types";
2
- import { HttpClient } from "../net/http";
3
-
4
- export default function create(httpClient: HttpClient) {
5
- return {
6
- get: async (marketId: string, saleId: string) => {
7
- return httpClient.get<Sale>(`/${marketId}/sales/${saleId}`);
8
- },
9
- };
10
- }
package/src/resources.ts DELETED
@@ -1,13 +0,0 @@
1
- import { HttpClient } from "./net/http";
2
-
3
- import lots from "./resources/lots";
4
- import markets from "./resources/markets";
5
- import sales from "./resources/sales";
6
-
7
- export default function resources(httpClient: HttpClient) {
8
- return {
9
- markets: markets(httpClient),
10
- sales: sales(httpClient),
11
- lots: lots(httpClient),
12
- };
13
- }
package/src/studio.ts DELETED
@@ -1,18 +0,0 @@
1
- import getFetch from "./net/fetch";
2
- import HttpClient from "./net/http";
3
- import Resources from "./resources";
4
-
5
- const BaseUrl = "https://marteyestudio.com/api";
6
- const DefaultTimeout = 10000;
7
-
8
- export default function Studio(
9
- apiKey: string,
10
- baseUrl: string = BaseUrl,
11
- defaultTimeout: number = DefaultTimeout
12
- ) {
13
- let httpClient = HttpClient(baseUrl, apiKey, getFetch(), defaultTimeout);
14
-
15
- return {
16
- ...Resources(httpClient),
17
- };
18
- }
package/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "esModuleInterop": true,
4
- "isolatedModules": true,
5
- "types": ["jest", "node"],
6
- }
7
- }