Skip to content

Commit

Permalink
Fix wx request json decode (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackstorm authored May 26, 2023
1 parent b344ddf commit 8267c3d
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 20 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Official JavaScript SDK (browser and node) for interacting with the [PocketBase
- [Definitions](#definitions)
- [Development](#development)

## Knew issues
- Auto cancellation not work


## Installation

Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.cjs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.iife.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.iife.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.umd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.15.0",
"version": "0.0.2",
"name": "pocketbase",
"description": "PocketBase JavaScript SDK",
"author": "Gani Georgiev",
Expand Down
8 changes: 5 additions & 3 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default class Client {

private cancelControllers: { [key: string]: AbortController } = {};
private recordServices: { [key: string]: RecordService } = {};
private enableAutoCancellation: boolean = true;
private enableAutoCancellation: boolean = false;

constructor(
baseUrl = '/',
Expand Down Expand Up @@ -298,9 +298,11 @@ export default class Client {

// send the request
return wxFetch(url, options).then(async (response) => {
let data = JSON.parse(response.data);
let data = response.data

if (this.afterSend) data = await this.afterSend(response, data);
if (this.afterSend) {
data = await this.afterSend(response, data);
}

if (response.statusCode >= 400) {
throw new ClientResponseError({
Expand Down
12 changes: 6 additions & 6 deletions src/stores/LocalAuthStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export default class LocalAuthStore extends BaseAuthStore {
* (or runtime/memory if local storage is undefined).
*/
private _storageGet(key: string): any {
if (typeof window !== 'undefined' && window?.localStorage) {
const rawValue = window.localStorage.getItem(key) || '';
if (wx) {
const rawValue = wx.getStorageSync(key) || '';
try {
return JSON.parse(rawValue);
} catch (e) { // not a json
Expand All @@ -96,13 +96,13 @@ export default class LocalAuthStore extends BaseAuthStore {
* (or runtime/memory if local storage is undefined).
*/
private _storageSet(key: string, value: any) {
if (typeof window !== 'undefined' && window?.localStorage) {
if (wx) {
// store in local storage
let normalizedVal = value;
if (typeof value !== 'string') {
normalizedVal = JSON.stringify(value);
}
window.localStorage.setItem(key, normalizedVal);
wx.setStorageSync(key, normalizedVal);
} else {
// store in fallback
this.storageFallback[key] = value;
Expand All @@ -114,8 +114,8 @@ export default class LocalAuthStore extends BaseAuthStore {
*/
private _storageRemove(key: string) {
// delete from local storage
if (typeof window !== 'undefined' && window?.localStorage) {
window.localStorage?.removeItem(key);
if (wx) {
wx.removeStorageSync(key);
}

// delete from fallback
Expand Down

0 comments on commit 8267c3d

Please sign in to comment.