rotur-sdk 1.0.7 → 1.0.9

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/index.js CHANGED
@@ -66,8 +66,14 @@ var Http = class {
66
66
  throw new ApiError(401, {
67
67
  error: "Not authenticated \u2014 call rotur.login() first"
68
68
  });
69
- const allParams = auth && token ? { ...params, auth: token } : params;
70
- const res = await fetch(this.buildUrl(path, allParams));
69
+ const allParams = params;
70
+ const opts = {
71
+ method: "GET",
72
+ headers: {
73
+ ...token ? { Authorization: `Bearer ${token}` } : {}
74
+ }
75
+ };
76
+ const res = await fetch(this.buildUrl(path, allParams), opts);
71
77
  return this.handle(res);
72
78
  }
73
79
  async post(path, body, auth = true) {
@@ -78,13 +84,13 @@ var Http = class {
78
84
  });
79
85
  const opts = {
80
86
  method: "POST",
81
- headers: { "Content-Type": "application/json" }
87
+ headers: {
88
+ "Content-Type": "application/json",
89
+ ...token ? { Authorization: `Bearer ${token}` } : {}
90
+ },
91
+ body: body ? JSON.stringify(body) : void 0
82
92
  };
83
- if (body !== void 0) opts.body = JSON.stringify(body);
84
- const res = await fetch(
85
- this.buildUrl(path, auth && token ? { auth: token } : void 0),
86
- opts
87
- );
93
+ const res = await fetch(`${this.baseUrl}${path}`, opts);
88
94
  return this.handle(res);
89
95
  }
90
96
  async patch(path, body) {
@@ -92,10 +98,13 @@ var Http = class {
92
98
  if (!token) throw new ApiError(401, { error: "Not authenticated" });
93
99
  const opts = {
94
100
  method: "PATCH",
95
- headers: { "Content-Type": "application/json" }
101
+ headers: {
102
+ "Content-Type": "application/json",
103
+ Authorization: `Bearer ${token}`
104
+ }
96
105
  };
97
106
  if (body !== void 0) opts.body = JSON.stringify(body);
98
- const res = await fetch(this.buildUrl(path, { auth: token }), opts);
107
+ const res = await fetch(`${this.baseUrl}${path}`, opts);
99
108
  return this.handle(res);
100
109
  }
101
110
  async del(path, body) {
@@ -103,10 +112,13 @@ var Http = class {
103
112
  if (!token) throw new ApiError(401, { error: "Not authenticated" });
104
113
  const opts = {
105
114
  method: "DELETE",
106
- headers: { "Content-Type": "application/json" }
115
+ headers: {
116
+ "Content-Type": "application/json",
117
+ Authorization: `Bearer ${token}`
118
+ }
107
119
  };
108
120
  if (body !== void 0) opts.body = JSON.stringify(body);
109
- const res = await fetch(this.buildUrl(path, { auth: token }), opts);
121
+ const res = await fetch(`${this.baseUrl}${path}`, opts);
110
122
  return this.handle(res);
111
123
  }
112
124
  async handle(res) {
package/dist/index.mjs CHANGED
@@ -36,8 +36,14 @@ var Http = class {
36
36
  throw new ApiError(401, {
37
37
  error: "Not authenticated \u2014 call rotur.login() first"
38
38
  });
39
- const allParams = auth && token ? { ...params, auth: token } : params;
40
- const res = await fetch(this.buildUrl(path, allParams));
39
+ const allParams = params;
40
+ const opts = {
41
+ method: "GET",
42
+ headers: {
43
+ ...token ? { Authorization: `Bearer ${token}` } : {}
44
+ }
45
+ };
46
+ const res = await fetch(this.buildUrl(path, allParams), opts);
41
47
  return this.handle(res);
42
48
  }
43
49
  async post(path, body, auth = true) {
@@ -48,13 +54,13 @@ var Http = class {
48
54
  });
49
55
  const opts = {
50
56
  method: "POST",
51
- headers: { "Content-Type": "application/json" }
57
+ headers: {
58
+ "Content-Type": "application/json",
59
+ ...token ? { Authorization: `Bearer ${token}` } : {}
60
+ },
61
+ body: body ? JSON.stringify(body) : void 0
52
62
  };
53
- if (body !== void 0) opts.body = JSON.stringify(body);
54
- const res = await fetch(
55
- this.buildUrl(path, auth && token ? { auth: token } : void 0),
56
- opts
57
- );
63
+ const res = await fetch(`${this.baseUrl}${path}`, opts);
58
64
  return this.handle(res);
59
65
  }
60
66
  async patch(path, body) {
@@ -62,10 +68,13 @@ var Http = class {
62
68
  if (!token) throw new ApiError(401, { error: "Not authenticated" });
63
69
  const opts = {
64
70
  method: "PATCH",
65
- headers: { "Content-Type": "application/json" }
71
+ headers: {
72
+ "Content-Type": "application/json",
73
+ Authorization: `Bearer ${token}`
74
+ }
66
75
  };
67
76
  if (body !== void 0) opts.body = JSON.stringify(body);
68
- const res = await fetch(this.buildUrl(path, { auth: token }), opts);
77
+ const res = await fetch(`${this.baseUrl}${path}`, opts);
69
78
  return this.handle(res);
70
79
  }
71
80
  async del(path, body) {
@@ -73,10 +82,13 @@ var Http = class {
73
82
  if (!token) throw new ApiError(401, { error: "Not authenticated" });
74
83
  const opts = {
75
84
  method: "DELETE",
76
- headers: { "Content-Type": "application/json" }
85
+ headers: {
86
+ "Content-Type": "application/json",
87
+ Authorization: `Bearer ${token}`
88
+ }
77
89
  };
78
90
  if (body !== void 0) opts.body = JSON.stringify(body);
79
- const res = await fetch(this.buildUrl(path, { auth: token }), opts);
91
+ const res = await fetch(`${this.baseUrl}${path}`, opts);
80
92
  return this.handle(res);
81
93
  }
82
94
  async handle(res) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rotur-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "The official SDK for the Rotur platform - auth, profiles, posts, credits, keys, groups, items, gifts, tokens, validators, status, files, cosmetics, push notifications, and more",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",