@go-avro/avro-js 0.0.8 → 0.0.9-beta.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.
@@ -526,6 +526,10 @@ export declare class AvroQueryClient {
526
526
  token: string;
527
527
  cancelToken?: CancelToken;
528
528
  }>>;
529
+ useAppleLogin(): ReturnType<typeof useMutation<LoginResponse, StandardError, {
530
+ token: string;
531
+ cancelToken?: CancelToken;
532
+ }>>;
529
533
  setTokens(tokens: Tokens): Promise<void>;
530
534
  setCache(data: Partial<CacheData> | Object): Promise<void>;
531
535
  getCache(key?: keyof CacheData | string): Promise<CacheData[keyof CacheData] | Object | string | null>;
@@ -185,6 +185,34 @@ export class AvroQueryClient {
185
185
  }
186
186
  });
187
187
  }
188
+ useAppleLogin() {
189
+ const queryClient = this.getQueryClient();
190
+ return useMutation({
191
+ mutationFn: async ({ token, cancelToken }) => {
192
+ const resp = await this._xhr('POST', `/apple/authorize?token=${encodeURIComponent(token)}`, {}, cancelToken, { 'Content-Type': 'application/json' });
193
+ if (!resp || !('access_token' in resp)) {
194
+ if (resp.msg === "TOTP required") {
195
+ return LoginResponse.NEEDS_TOTP;
196
+ }
197
+ throw new StandardError(401, 'Invalid Apple login response');
198
+ }
199
+ this.setAuthState(AuthState.AUTHENTICATED);
200
+ this.socket.auth = { token: resp.access_token };
201
+ if (!this.socket.connected) {
202
+ this.socket.connect();
203
+ }
204
+ await this.config.authManager.setTokens({ access_token: resp.access_token, refresh_token: resp.refresh_token });
205
+ return LoginResponse.SUCCESS;
206
+ },
207
+ onSettled: () => {
208
+ queryClient.invalidateQueries();
209
+ },
210
+ onError: (err) => {
211
+ this.config.authManager.clearCache();
212
+ throw new StandardError(err.status, err.message || 'Apple Login failed');
213
+ }
214
+ });
215
+ }
188
216
  setTokens(tokens) {
189
217
  return this.config.authManager.setTokens(tokens);
190
218
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.8",
3
+ "version": "0.0.9-beta.0",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",