@go-avro/avro-js 0.0.2-beta.86 → 0.0.2-beta.88

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.
@@ -263,6 +263,13 @@ export declare class AvroQueryClient {
263
263
  code?: string;
264
264
  cancelToken?: CancelToken;
265
265
  }>>;
266
+ useRequestCode(): ReturnType<typeof useMutation<{
267
+ msg: string;
268
+ }, StandardError, {
269
+ username?: string;
270
+ email?: string;
271
+ cancelToken?: CancelToken;
272
+ }>>;
266
273
  useGoogleLogin(): ReturnType<typeof useMutation<LoginResponse, StandardError, {
267
274
  token: string;
268
275
  cancelToken?: CancelToken;
@@ -77,7 +77,7 @@ export class AvroQueryClient {
77
77
  const queryClient = useQueryClient();
78
78
  return useMutation({
79
79
  mutationFn: async ({ username, password, code, cancelToken }) => {
80
- const resp = await this.post('/login', JSON.stringify({ username, password, code }), cancelToken);
80
+ const resp = await this.post('/login', JSON.stringify({ username, password, code }), cancelToken, { 'Content-Type': 'application/json' });
81
81
  if (!resp || !('access_token' in resp)) {
82
82
  if (resp.msg === "TOTP email sent") {
83
83
  return LoginResponse.NEEDS_TOTP;
@@ -100,6 +100,21 @@ export class AvroQueryClient {
100
100
  }
101
101
  });
102
102
  }
103
+ useRequestCode() {
104
+ const queryClient = useQueryClient();
105
+ return useMutation({
106
+ mutationFn: async ({ username, email, cancelToken }) => {
107
+ const resp = await this.post('/code', JSON.stringify({ username, email }), cancelToken, { 'Content-Type': 'application/json' });
108
+ return resp;
109
+ },
110
+ onSettled: () => {
111
+ queryClient.invalidateQueries();
112
+ },
113
+ onError: (err) => {
114
+ throw new StandardError(err.status, err.message || 'Request code failed');
115
+ }
116
+ });
117
+ }
103
118
  useGoogleLogin() {
104
119
  const queryClient = useQueryClient();
105
120
  return useMutation({
@@ -164,7 +179,10 @@ export class AvroQueryClient {
164
179
  if (!companyGuid || companyGuid.trim() === '') {
165
180
  return Promise.reject(new StandardError(400, 'Company GUID is required'));
166
181
  }
167
- return this._fetch('POST', `/company/${companyGuid}/jobs`, JSON.stringify(body), cancelToken, headers)
182
+ return this._fetch('POST', `/company/${companyGuid}/jobs`, JSON.stringify(body), cancelToken, {
183
+ ...headers,
184
+ 'Content-Type': 'application/json',
185
+ })
168
186
  .then(response => {
169
187
  if (!response || !Array.isArray(response)) {
170
188
  throw new StandardError(400, 'Invalid jobs response');
@@ -180,7 +198,10 @@ export class AvroQueryClient {
180
198
  if (!companyGuid || companyGuid.trim() === '') {
181
199
  return Promise.reject(new StandardError(400, 'Company GUID is required'));
182
200
  }
183
- return this._fetch('POST', `/company/${companyGuid}/chats`, JSON.stringify(body), cancelToken, headers)
201
+ return this._fetch('POST', `/company/${companyGuid}/chats`, JSON.stringify(body), cancelToken, {
202
+ ...headers,
203
+ 'Content-Type': 'application/json',
204
+ })
184
205
  .then(response => {
185
206
  if (!response || !Array.isArray(response)) {
186
207
  throw new StandardError(400, 'Invalid chats response');
@@ -196,7 +217,10 @@ export class AvroQueryClient {
196
217
  if (!chatGuid || chatGuid.trim() === '') {
197
218
  return Promise.reject(new StandardError(400, 'Chat GUID is required'));
198
219
  }
199
- return this._fetch('POST', `/chat/${chatGuid}/messages`, JSON.stringify(body), cancelToken, headers)
220
+ return this._fetch('POST', `/chat/${chatGuid}/messages`, JSON.stringify(body), cancelToken, {
221
+ ...headers,
222
+ 'Content-Type': 'application/json',
223
+ })
200
224
  .then(response => {
201
225
  if (!response || !Array.isArray(response)) {
202
226
  throw new StandardError(400, 'Invalid messages response');
@@ -212,7 +236,10 @@ export class AvroQueryClient {
212
236
  if (!companyGuid || companyGuid.trim() === '') {
213
237
  return Promise.reject(new StandardError(400, 'Company GUID is required'));
214
238
  }
215
- return this._fetch('POST', `/company/${companyGuid}/events`, JSON.stringify(body), cancelToken, headers)
239
+ return this._fetch('POST', `/company/${companyGuid}/events`, JSON.stringify(body), cancelToken, {
240
+ ...headers,
241
+ 'Content-Type': 'application/json',
242
+ })
216
243
  .then(response => {
217
244
  if (!response || !Array.isArray(response)) {
218
245
  throw new StandardError(400, 'Invalid events response');
@@ -228,7 +255,10 @@ export class AvroQueryClient {
228
255
  if (!companyGuid || companyGuid.trim() === '') {
229
256
  return Promise.reject(new StandardError(400, 'Company GUID is required'));
230
257
  }
231
- return this._fetch('POST', `/company/${companyGuid}/months`, JSON.stringify(body), cancelToken, headers)
258
+ return this._fetch('POST', `/company/${companyGuid}/months`, JSON.stringify(body), cancelToken, {
259
+ ...headers,
260
+ 'Content-Type': 'application/json',
261
+ })
232
262
  .then(response => {
233
263
  if (!response || !Array.isArray(response)) {
234
264
  throw new StandardError(400, 'Invalid months response');
@@ -244,7 +274,10 @@ export class AvroQueryClient {
244
274
  if (!companyGuid || companyGuid.trim() === '') {
245
275
  return Promise.reject(new StandardError(400, 'Company GUID is required'));
246
276
  }
247
- return this._fetch('POST', `/company/${companyGuid}/bills`, JSON.stringify(body), cancelToken, headers)
277
+ return this._fetch('POST', `/company/${companyGuid}/bills`, JSON.stringify(body), cancelToken, {
278
+ ...headers,
279
+ 'Content-Type': 'application/json',
280
+ })
248
281
  .then(response => {
249
282
  if (!response || !Array.isArray(response)) {
250
283
  throw new StandardError(400, 'Invalid bills response');
@@ -260,7 +293,10 @@ export class AvroQueryClient {
260
293
  if (!companyGuid || companyGuid.trim() === '') {
261
294
  return Promise.reject(new StandardError(400, 'Company GUID is required'));
262
295
  }
263
- return this._fetch('POST', `/company/${companyGuid}/routes`, JSON.stringify(body), cancelToken, headers)
296
+ return this._fetch('POST', `/company/${companyGuid}/routes`, JSON.stringify(body), cancelToken, {
297
+ ...headers,
298
+ 'Content-Type': 'application/json',
299
+ })
264
300
  .then(response => {
265
301
  if (!response || !Array.isArray(response)) {
266
302
  throw new StandardError(400, 'Invalid routes response');
@@ -276,7 +312,10 @@ export class AvroQueryClient {
276
312
  if (!companyGuid || companyGuid.trim() === '') {
277
313
  return Promise.reject(new StandardError(400, 'Company GUID is required'));
278
314
  }
279
- return this._fetch('POST', `/company/${companyGuid}/teams`, JSON.stringify(body), cancelToken, headers)
315
+ return this._fetch('POST', `/company/${companyGuid}/teams`, JSON.stringify(body), cancelToken, {
316
+ ...headers,
317
+ 'Content-Type': 'application/json',
318
+ })
280
319
  .then(response => {
281
320
  if (!response || !Array.isArray(response)) {
282
321
  throw new StandardError(400, 'Invalid teams response');
@@ -17,7 +17,6 @@ AvroQueryClient.prototype._fetch = async function (method, path, body, cancelTok
17
17
  checkCancelled();
18
18
  const url = this.config.baseUrl + path;
19
19
  const requestHeaders = {
20
- 'Content-Type': 'application/json',
21
20
  Authorization: `Bearer ${token}`,
22
21
  ...headers,
23
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.86",
3
+ "version": "0.0.2-beta.88",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",