@juhuu/sdk-ts 1.2.145 → 1.2.146

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.d.mts CHANGED
@@ -539,6 +539,9 @@ declare class Service {
539
539
  readonly httpBaseUrl: string;
540
540
  readonly wssBaseUrl: string;
541
541
  readonly clientVersion: string;
542
+ readonly apiKey: string | null;
543
+ readonly defaultRequestOptions: JUHUU.RequestOptions;
544
+ readonly authenticationMode: "jwt" | "apiKey";
542
545
  onException: <T>(response: JUHUU.HttpResponse<T>) => Promise<"abort" | "retry">;
543
546
  getAccessToken: () => Promise<string | null> | null;
544
547
  setAccessToken: (accessToken: string) => Promise<void>;
@@ -893,13 +896,16 @@ declare class Juhuu {
893
896
  }
894
897
  declare namespace JUHUU {
895
898
  interface SetupConfig {
896
- environment: Environment;
897
- getAccessToken: () => Promise<string | null>;
898
- onException: <T>(response: JUHUU.HttpResponse<T>) => Promise<"abort">;
899
- setAccessToken: (accessToken: string) => Promise<void>;
900
- getRefreshToken: () => Promise<string | null>;
901
- setRefreshToken: (refreshToken: string) => Promise<void>;
899
+ environment?: Environment;
900
+ getAccessToken?: () => Promise<string | null>;
901
+ onException?: <T>(response: JUHUU.HttpResponse<T>) => Promise<"abort">;
902
+ setAccessToken?: (accessToken: string) => Promise<void>;
903
+ getRefreshToken?: () => Promise<string | null>;
904
+ setRefreshToken?: (refreshToken: string) => Promise<void>;
902
905
  clientVersion: string;
906
+ apiKey?: string;
907
+ defaultRequestOptions?: JUHUU.RequestOptions;
908
+ authenticationMode?: "jwt" | "apiKey";
903
909
  }
904
910
  interface HttpResponse<T> {
905
911
  ok: boolean;
@@ -925,6 +931,10 @@ declare namespace JUHUU {
925
931
  * If this is true, a new accessToken will be requested if the current one is expired.
926
932
  */
927
933
  refreshTokensIfNecessary?: boolean;
934
+ /**
935
+ * If this API key is provided, the request will be sent with this API key instead of the one passed to config.
936
+ */
937
+ apiKey?: string | null;
928
938
  };
929
939
  interface LocaleString {
930
940
  de?: string;
@@ -1488,6 +1498,7 @@ declare namespace JUHUU {
1488
1498
  namespace Create {
1489
1499
  type Params = {
1490
1500
  propertyId: string;
1501
+ name?: string;
1491
1502
  };
1492
1503
  type Options = JUHUU.RequestOptions;
1493
1504
  type Response = {
package/dist/index.d.ts CHANGED
@@ -539,6 +539,9 @@ declare class Service {
539
539
  readonly httpBaseUrl: string;
540
540
  readonly wssBaseUrl: string;
541
541
  readonly clientVersion: string;
542
+ readonly apiKey: string | null;
543
+ readonly defaultRequestOptions: JUHUU.RequestOptions;
544
+ readonly authenticationMode: "jwt" | "apiKey";
542
545
  onException: <T>(response: JUHUU.HttpResponse<T>) => Promise<"abort" | "retry">;
543
546
  getAccessToken: () => Promise<string | null> | null;
544
547
  setAccessToken: (accessToken: string) => Promise<void>;
@@ -893,13 +896,16 @@ declare class Juhuu {
893
896
  }
894
897
  declare namespace JUHUU {
895
898
  interface SetupConfig {
896
- environment: Environment;
897
- getAccessToken: () => Promise<string | null>;
898
- onException: <T>(response: JUHUU.HttpResponse<T>) => Promise<"abort">;
899
- setAccessToken: (accessToken: string) => Promise<void>;
900
- getRefreshToken: () => Promise<string | null>;
901
- setRefreshToken: (refreshToken: string) => Promise<void>;
899
+ environment?: Environment;
900
+ getAccessToken?: () => Promise<string | null>;
901
+ onException?: <T>(response: JUHUU.HttpResponse<T>) => Promise<"abort">;
902
+ setAccessToken?: (accessToken: string) => Promise<void>;
903
+ getRefreshToken?: () => Promise<string | null>;
904
+ setRefreshToken?: (refreshToken: string) => Promise<void>;
902
905
  clientVersion: string;
906
+ apiKey?: string;
907
+ defaultRequestOptions?: JUHUU.RequestOptions;
908
+ authenticationMode?: "jwt" | "apiKey";
903
909
  }
904
910
  interface HttpResponse<T> {
905
911
  ok: boolean;
@@ -925,6 +931,10 @@ declare namespace JUHUU {
925
931
  * If this is true, a new accessToken will be requested if the current one is expired.
926
932
  */
927
933
  refreshTokensIfNecessary?: boolean;
934
+ /**
935
+ * If this API key is provided, the request will be sent with this API key instead of the one passed to config.
936
+ */
937
+ apiKey?: string | null;
928
938
  };
929
939
  interface LocaleString {
930
940
  de?: string;
@@ -1488,6 +1498,7 @@ declare namespace JUHUU {
1488
1498
  namespace Create {
1489
1499
  type Params = {
1490
1500
  propertyId: string;
1501
+ name?: string;
1491
1502
  };
1492
1503
  type Options = JUHUU.RequestOptions;
1493
1504
  type Response = {
package/dist/index.js CHANGED
@@ -46,14 +46,17 @@ module.exports = __toCommonJS(src_exports);
46
46
  var import_socket = __toESM(require("socket.io-client"));
47
47
  var Service = class {
48
48
  constructor(config) {
49
- this.environment = config.environment;
50
- this.getAccessToken = config.getAccessToken;
51
- this.onException = config.onException;
52
- this.setAccessToken = config.setAccessToken;
53
- this.getAccessToken = config.getAccessToken;
54
- this.setRefreshToken = config.setRefreshToken;
55
- this.getRefreshToken = config.getRefreshToken;
49
+ this.environment = config.environment ?? "production";
50
+ this.getAccessToken = config.getAccessToken ?? (() => null);
51
+ this.onException = config.onException ?? (() => Promise.resolve("abort"));
52
+ this.setAccessToken = config.setAccessToken ?? (() => Promise.resolve());
53
+ this.getAccessToken = config.getAccessToken ?? (() => null);
54
+ this.setRefreshToken = config.setRefreshToken ?? (() => Promise.resolve());
55
+ this.getRefreshToken = config.getRefreshToken ?? (() => Promise.resolve(null));
56
56
  this.clientVersion = config.clientVersion;
57
+ this.apiKey = config.apiKey ?? null;
58
+ this.defaultRequestOptions = config.defaultRequestOptions ?? {};
59
+ this.authenticationMode = config.authenticationMode ?? "jwt";
57
60
  switch (config.environment) {
58
61
  case "development":
59
62
  this.httpBaseUrl = "https://api.juhuu.dev/v1/";
@@ -69,6 +72,9 @@ var Service = class {
69
72
  httpBaseUrl;
70
73
  wssBaseUrl;
71
74
  clientVersion;
75
+ apiKey;
76
+ defaultRequestOptions;
77
+ authenticationMode;
72
78
  onException;
73
79
  getAccessToken;
74
80
  setAccessToken;
@@ -80,29 +86,76 @@ var Service = class {
80
86
  body = void 0,
81
87
  authenticationNotOptional
82
88
  }, options = {}) {
83
- if (options.triggerOnException === void 0) {
84
- options.triggerOnException = true;
89
+ const currentOptions = {
90
+ ...this.defaultRequestOptions,
91
+ ...options
92
+ };
93
+ if (currentOptions.triggerOnException === void 0) {
94
+ switch (this.authenticationMode) {
95
+ case "jwt": {
96
+ currentOptions.triggerOnException = true;
97
+ break;
98
+ }
99
+ case "apiKey": {
100
+ currentOptions.triggerOnException = false;
101
+ break;
102
+ }
103
+ }
85
104
  }
86
- if (options.refreshTokensIfNecessary === void 0) {
87
- options.refreshTokensIfNecessary = true;
105
+ if (currentOptions.refreshTokensIfNecessary === void 0) {
106
+ switch (this.authenticationMode) {
107
+ case "jwt": {
108
+ currentOptions.refreshTokensIfNecessary = true;
109
+ break;
110
+ }
111
+ case "apiKey": {
112
+ currentOptions.refreshTokensIfNecessary = false;
113
+ break;
114
+ }
115
+ }
88
116
  }
89
117
  let token = null;
90
- if (options.accessToken === void 0 || options.accessToken === null) {
91
- token = await this.getAccessToken();
92
- } else {
93
- token = options.accessToken;
94
- }
95
- console.log("accessToken:", token);
96
- if ((token === null || token === void 0) && authenticationNotOptional === true) {
97
- console.error(
98
- "endpoint",
99
- url,
100
- "should use authentication but no token was found"
101
- );
102
- return {
103
- ok: false,
104
- data: {}
105
- };
118
+ let apiKey = null;
119
+ switch (this.authenticationMode) {
120
+ case "jwt": {
121
+ if (currentOptions.accessToken === void 0 || currentOptions.accessToken === null) {
122
+ token = await this.getAccessToken();
123
+ } else {
124
+ token = currentOptions.accessToken;
125
+ }
126
+ console.log("accessToken:", token);
127
+ if ((token === null || token === void 0) && authenticationNotOptional === true) {
128
+ console.error(
129
+ "endpoint",
130
+ url,
131
+ "should use authentication but no token was found"
132
+ );
133
+ return {
134
+ ok: false,
135
+ data: {}
136
+ };
137
+ }
138
+ break;
139
+ }
140
+ case "apiKey": {
141
+ if (currentOptions.apiKey === void 0 || currentOptions.apiKey === null) {
142
+ apiKey = this.apiKey;
143
+ } else {
144
+ apiKey = currentOptions.apiKey;
145
+ }
146
+ if (apiKey === null) {
147
+ console.error(
148
+ "endpoint",
149
+ url,
150
+ "should use authentication but no apiKey was found"
151
+ );
152
+ return {
153
+ ok: false,
154
+ data: {}
155
+ };
156
+ }
157
+ break;
158
+ }
106
159
  }
107
160
  const uri = this.httpBaseUrl + url;
108
161
  let response = null;
@@ -110,19 +163,19 @@ var Service = class {
110
163
  try {
111
164
  switch (method) {
112
165
  case "GET": {
113
- response = await this.sendGetRequest(token, uri);
166
+ response = await this.sendGetRequest({ token, uri, apiKey });
114
167
  break;
115
168
  }
116
169
  case "POST": {
117
- response = await this.sendPostRequest(token, uri, body);
170
+ response = await this.sendPostRequest({ token, uri, body, apiKey });
118
171
  break;
119
172
  }
120
173
  case "PATCH": {
121
- response = await this.sendPatchRequest(token, uri, body);
174
+ response = await this.sendPatchRequest({ token, uri, body, apiKey });
122
175
  break;
123
176
  }
124
177
  case "DELETE": {
125
- response = await this.sendDeleteRequest(token, uri);
178
+ response = await this.sendDeleteRequest({ token, uri, apiKey });
126
179
  break;
127
180
  }
128
181
  }
@@ -210,7 +263,11 @@ var Service = class {
210
263
  }
211
264
  return responseObject;
212
265
  }
213
- async sendGetRequest(token, uri) {
266
+ async sendGetRequest({
267
+ token,
268
+ apiKey,
269
+ uri
270
+ }) {
214
271
  const headers = {
215
272
  "Content-Type": "application/json",
216
273
  "Client-Version": this.clientVersion
@@ -218,12 +275,20 @@ var Service = class {
218
275
  if (token !== void 0 && token !== null) {
219
276
  headers.Authorization = `Bearer ${token}`;
220
277
  }
278
+ if (apiKey !== null) {
279
+ headers["X-API-KEY"] = apiKey;
280
+ }
221
281
  return await fetch(uri, {
222
282
  method: "GET",
223
283
  headers
224
284
  });
225
285
  }
226
- async sendPostRequest(token, uri, body) {
286
+ async sendPostRequest({
287
+ token,
288
+ uri,
289
+ apiKey,
290
+ body
291
+ }) {
227
292
  const headers = {
228
293
  "Content-Type": "application/json",
229
294
  "Client-Version": this.clientVersion
@@ -231,13 +296,21 @@ var Service = class {
231
296
  if (token !== void 0 && token !== null) {
232
297
  headers.Authorization = `Bearer ${token}`;
233
298
  }
299
+ if (apiKey !== null) {
300
+ headers["X-API-KEY"] = apiKey;
301
+ }
234
302
  return await fetch(uri, {
235
303
  method: "POST",
236
304
  headers,
237
305
  body: JSON.stringify(body)
238
306
  });
239
307
  }
240
- async sendPatchRequest(token, uri, body) {
308
+ async sendPatchRequest({
309
+ token,
310
+ uri,
311
+ apiKey,
312
+ body
313
+ }) {
241
314
  const headers = {
242
315
  "Content-Type": "application/json",
243
316
  "Client-Version": this.clientVersion
@@ -245,13 +318,20 @@ var Service = class {
245
318
  if (token !== void 0 && token !== null) {
246
319
  headers.Authorization = `Bearer ${token}`;
247
320
  }
321
+ if (apiKey !== null) {
322
+ headers["X-API-KEY"] = apiKey;
323
+ }
248
324
  return await fetch(uri, {
249
325
  method: "PATCH",
250
326
  headers,
251
327
  body: JSON.stringify(body)
252
328
  });
253
329
  }
254
- async sendDeleteRequest(token, uri) {
330
+ async sendDeleteRequest({
331
+ token,
332
+ uri,
333
+ apiKey
334
+ }) {
255
335
  const headers = {
256
336
  "Content-Type": "application/json",
257
337
  "Client-Version": this.clientVersion
@@ -259,6 +339,9 @@ var Service = class {
259
339
  if (token !== void 0 && token !== null) {
260
340
  headers.Authorization = `Bearer ${token}`;
261
341
  }
342
+ if (apiKey !== null) {
343
+ headers["X-API-KEY"] = apiKey;
344
+ }
262
345
  return await fetch(uri, {
263
346
  method: "DELETE",
264
347
  headers
package/dist/index.mjs CHANGED
@@ -2,14 +2,17 @@
2
2
  import io from "socket.io-client";
3
3
  var Service = class {
4
4
  constructor(config) {
5
- this.environment = config.environment;
6
- this.getAccessToken = config.getAccessToken;
7
- this.onException = config.onException;
8
- this.setAccessToken = config.setAccessToken;
9
- this.getAccessToken = config.getAccessToken;
10
- this.setRefreshToken = config.setRefreshToken;
11
- this.getRefreshToken = config.getRefreshToken;
5
+ this.environment = config.environment ?? "production";
6
+ this.getAccessToken = config.getAccessToken ?? (() => null);
7
+ this.onException = config.onException ?? (() => Promise.resolve("abort"));
8
+ this.setAccessToken = config.setAccessToken ?? (() => Promise.resolve());
9
+ this.getAccessToken = config.getAccessToken ?? (() => null);
10
+ this.setRefreshToken = config.setRefreshToken ?? (() => Promise.resolve());
11
+ this.getRefreshToken = config.getRefreshToken ?? (() => Promise.resolve(null));
12
12
  this.clientVersion = config.clientVersion;
13
+ this.apiKey = config.apiKey ?? null;
14
+ this.defaultRequestOptions = config.defaultRequestOptions ?? {};
15
+ this.authenticationMode = config.authenticationMode ?? "jwt";
13
16
  switch (config.environment) {
14
17
  case "development":
15
18
  this.httpBaseUrl = "https://api.juhuu.dev/v1/";
@@ -25,6 +28,9 @@ var Service = class {
25
28
  httpBaseUrl;
26
29
  wssBaseUrl;
27
30
  clientVersion;
31
+ apiKey;
32
+ defaultRequestOptions;
33
+ authenticationMode;
28
34
  onException;
29
35
  getAccessToken;
30
36
  setAccessToken;
@@ -36,29 +42,76 @@ var Service = class {
36
42
  body = void 0,
37
43
  authenticationNotOptional
38
44
  }, options = {}) {
39
- if (options.triggerOnException === void 0) {
40
- options.triggerOnException = true;
45
+ const currentOptions = {
46
+ ...this.defaultRequestOptions,
47
+ ...options
48
+ };
49
+ if (currentOptions.triggerOnException === void 0) {
50
+ switch (this.authenticationMode) {
51
+ case "jwt": {
52
+ currentOptions.triggerOnException = true;
53
+ break;
54
+ }
55
+ case "apiKey": {
56
+ currentOptions.triggerOnException = false;
57
+ break;
58
+ }
59
+ }
41
60
  }
42
- if (options.refreshTokensIfNecessary === void 0) {
43
- options.refreshTokensIfNecessary = true;
61
+ if (currentOptions.refreshTokensIfNecessary === void 0) {
62
+ switch (this.authenticationMode) {
63
+ case "jwt": {
64
+ currentOptions.refreshTokensIfNecessary = true;
65
+ break;
66
+ }
67
+ case "apiKey": {
68
+ currentOptions.refreshTokensIfNecessary = false;
69
+ break;
70
+ }
71
+ }
44
72
  }
45
73
  let token = null;
46
- if (options.accessToken === void 0 || options.accessToken === null) {
47
- token = await this.getAccessToken();
48
- } else {
49
- token = options.accessToken;
50
- }
51
- console.log("accessToken:", token);
52
- if ((token === null || token === void 0) && authenticationNotOptional === true) {
53
- console.error(
54
- "endpoint",
55
- url,
56
- "should use authentication but no token was found"
57
- );
58
- return {
59
- ok: false,
60
- data: {}
61
- };
74
+ let apiKey = null;
75
+ switch (this.authenticationMode) {
76
+ case "jwt": {
77
+ if (currentOptions.accessToken === void 0 || currentOptions.accessToken === null) {
78
+ token = await this.getAccessToken();
79
+ } else {
80
+ token = currentOptions.accessToken;
81
+ }
82
+ console.log("accessToken:", token);
83
+ if ((token === null || token === void 0) && authenticationNotOptional === true) {
84
+ console.error(
85
+ "endpoint",
86
+ url,
87
+ "should use authentication but no token was found"
88
+ );
89
+ return {
90
+ ok: false,
91
+ data: {}
92
+ };
93
+ }
94
+ break;
95
+ }
96
+ case "apiKey": {
97
+ if (currentOptions.apiKey === void 0 || currentOptions.apiKey === null) {
98
+ apiKey = this.apiKey;
99
+ } else {
100
+ apiKey = currentOptions.apiKey;
101
+ }
102
+ if (apiKey === null) {
103
+ console.error(
104
+ "endpoint",
105
+ url,
106
+ "should use authentication but no apiKey was found"
107
+ );
108
+ return {
109
+ ok: false,
110
+ data: {}
111
+ };
112
+ }
113
+ break;
114
+ }
62
115
  }
63
116
  const uri = this.httpBaseUrl + url;
64
117
  let response = null;
@@ -66,19 +119,19 @@ var Service = class {
66
119
  try {
67
120
  switch (method) {
68
121
  case "GET": {
69
- response = await this.sendGetRequest(token, uri);
122
+ response = await this.sendGetRequest({ token, uri, apiKey });
70
123
  break;
71
124
  }
72
125
  case "POST": {
73
- response = await this.sendPostRequest(token, uri, body);
126
+ response = await this.sendPostRequest({ token, uri, body, apiKey });
74
127
  break;
75
128
  }
76
129
  case "PATCH": {
77
- response = await this.sendPatchRequest(token, uri, body);
130
+ response = await this.sendPatchRequest({ token, uri, body, apiKey });
78
131
  break;
79
132
  }
80
133
  case "DELETE": {
81
- response = await this.sendDeleteRequest(token, uri);
134
+ response = await this.sendDeleteRequest({ token, uri, apiKey });
82
135
  break;
83
136
  }
84
137
  }
@@ -166,7 +219,11 @@ var Service = class {
166
219
  }
167
220
  return responseObject;
168
221
  }
169
- async sendGetRequest(token, uri) {
222
+ async sendGetRequest({
223
+ token,
224
+ apiKey,
225
+ uri
226
+ }) {
170
227
  const headers = {
171
228
  "Content-Type": "application/json",
172
229
  "Client-Version": this.clientVersion
@@ -174,12 +231,20 @@ var Service = class {
174
231
  if (token !== void 0 && token !== null) {
175
232
  headers.Authorization = `Bearer ${token}`;
176
233
  }
234
+ if (apiKey !== null) {
235
+ headers["X-API-KEY"] = apiKey;
236
+ }
177
237
  return await fetch(uri, {
178
238
  method: "GET",
179
239
  headers
180
240
  });
181
241
  }
182
- async sendPostRequest(token, uri, body) {
242
+ async sendPostRequest({
243
+ token,
244
+ uri,
245
+ apiKey,
246
+ body
247
+ }) {
183
248
  const headers = {
184
249
  "Content-Type": "application/json",
185
250
  "Client-Version": this.clientVersion
@@ -187,13 +252,21 @@ var Service = class {
187
252
  if (token !== void 0 && token !== null) {
188
253
  headers.Authorization = `Bearer ${token}`;
189
254
  }
255
+ if (apiKey !== null) {
256
+ headers["X-API-KEY"] = apiKey;
257
+ }
190
258
  return await fetch(uri, {
191
259
  method: "POST",
192
260
  headers,
193
261
  body: JSON.stringify(body)
194
262
  });
195
263
  }
196
- async sendPatchRequest(token, uri, body) {
264
+ async sendPatchRequest({
265
+ token,
266
+ uri,
267
+ apiKey,
268
+ body
269
+ }) {
197
270
  const headers = {
198
271
  "Content-Type": "application/json",
199
272
  "Client-Version": this.clientVersion
@@ -201,13 +274,20 @@ var Service = class {
201
274
  if (token !== void 0 && token !== null) {
202
275
  headers.Authorization = `Bearer ${token}`;
203
276
  }
277
+ if (apiKey !== null) {
278
+ headers["X-API-KEY"] = apiKey;
279
+ }
204
280
  return await fetch(uri, {
205
281
  method: "PATCH",
206
282
  headers,
207
283
  body: JSON.stringify(body)
208
284
  });
209
285
  }
210
- async sendDeleteRequest(token, uri) {
286
+ async sendDeleteRequest({
287
+ token,
288
+ uri,
289
+ apiKey
290
+ }) {
211
291
  const headers = {
212
292
  "Content-Type": "application/json",
213
293
  "Client-Version": this.clientVersion
@@ -215,6 +295,9 @@ var Service = class {
215
295
  if (token !== void 0 && token !== null) {
216
296
  headers.Authorization = `Bearer ${token}`;
217
297
  }
298
+ if (apiKey !== null) {
299
+ headers["X-API-KEY"] = apiKey;
300
+ }
218
301
  return await fetch(uri, {
219
302
  method: "DELETE",
220
303
  headers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juhuu/sdk-ts",
3
- "version": "1.2.145",
3
+ "version": "1.2.146",
4
4
  "description": "Typescript wrapper for JUHUU services",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",