@stacksjs/api 0.68.1 → 0.69.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.
package/dist/ofetch.d.ts CHANGED
@@ -17,10 +17,87 @@ declare type FetchResponse = string | Blob | ArrayBuffer | ReadableStream<Uint8A
17
17
  let loading = false
18
18
  let token = ''
19
19
  const baseURL = '/'
20
- declare function get(url: string, params?: Params, headers?: Headers): Promise<FetchResponse>;
21
- declare function post(url: string, params?: Params, headers?: Headers): Promise<any>;
22
- declare function patch(url: string, params?: Params, headers?: Headers): Promise<FetchResponse>;
23
- declare function put(url: string, params?: Params, headers?: Headers): Promise<FetchResponse>;
24
- declare function destroy(url: string, params?: Params, headers?: Headers): Promise<FetchResponse>;
25
- declare function setToken(authToken: string): void;
26
- export declare const Fetch: ApiFetch;
20
+
21
+ async function get(url: string, params?: Params, headers?: Headers): Promise<FetchResponse> {
22
+ if (headers) {
23
+ if (token)
24
+ headers.set('Authorization', `Bearer ${token}`)
25
+ }
26
+
27
+ return await ofetch(url, { method: 'GET', baseURL, params, headers })
28
+ }
29
+
30
+ async function post(url: string, params?: Params, headers?: Headers): Promise<any> {
31
+ if (headers) {
32
+ if (token)
33
+ headers.set('Authorization', `Bearer ${token}`)
34
+ }
35
+
36
+ loading = true
37
+
38
+ try {
39
+ const result: string | FetchResponse | Blob | ArrayBuffer | ReadableStream<Uint8Array> = await ofetch(url, {
40
+ method: 'POST',
41
+ baseURL,
42
+ params,
43
+ headers,
44
+ })
45
+
46
+ loading = false
47
+ return result
48
+ }
49
+ catch (err: any) {
50
+ loading = false
51
+
52
+ throw err
53
+ }
54
+ }
55
+
56
+ async function patch(url: string, params?: Params, headers?: Headers): Promise<FetchResponse> {
57
+ if (headers) {
58
+ if (token)
59
+ headers.set('Authorization', `Bearer ${token}`)
60
+ }
61
+
62
+ loading = true
63
+
64
+ return await ofetch(url, {
65
+ method: 'PATCH',
66
+ baseURL,
67
+ params,
68
+ headers,
69
+ })
70
+ }
71
+
72
+ async function put(url: string, params?: Params, headers?: Headers): Promise<FetchResponse> {
73
+ if (headers) {
74
+ if (token)
75
+ headers.set('Authorization', `Bearer ${token}`)
76
+ }
77
+
78
+ loading = true
79
+
80
+ return await ofetch(url, {
81
+ method: 'PUT',
82
+ baseURL,
83
+ params,
84
+ headers,
85
+ })
86
+ }
87
+
88
+ async function destroy(url: string, params?: Params, headers?: Headers): Promise<FetchResponse> {
89
+ if (headers) {
90
+ if (token)
91
+ headers.set('Authorization', `Bearer ${token}`)
92
+ }
93
+
94
+ loading = true
95
+
96
+ return await ofetch(url, {
97
+ method: 'DELETE',
98
+ baseURL,
99
+ params,
100
+ headers,
101
+ })
102
+ }
103
+ declare function setToken(authToken: string): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/api",
3
3
  "type": "module",
4
- "version": "0.68.1",
4
+ "version": "0.69.2",
5
5
  "description": "The Stacks array utilities.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": ["Chris Breuer <chris@stacksjs.org>"],
@@ -41,12 +41,10 @@
41
41
  "typecheck": "bun tsc --noEmit",
42
42
  "prepublishOnly": "bun run build"
43
43
  },
44
- "dependencies": {
45
- "@stacksjs/utils": "0.67.0",
46
- "ofetch": "^1.4.1",
47
- "openapi-typescript": "^7.4.2"
48
- },
49
44
  "devDependencies": {
50
- "@stacksjs/development": "0.67.0"
45
+ "@stacksjs/development": "0.69.2",
46
+ "@stacksjs/utils": "0.69.2",
47
+ "ofetch": "^1.4.1",
48
+ "openapi-typescript": "^7.6.1"
51
49
  }
52
50
  }
Binary file