Skip to content

Commit

Permalink
updated changelog and OAuth2UrlCallback type
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Apr 17, 2023
1 parent 08ccf66 commit cf5d381
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 59 deletions.
27 changes: 16 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
## 0.14.0-rc

- Added new `pb.files` service:
```js
// Builds and returns an absolute record file url for the provided filename.
🔓 pb.files.getUrl(record, filename, queryParams = {});

// Requests a new private file access token for the current auth model (admin or record).
🔐 pb.files.getToken(queryParams = {});
```
_`pb.getFileUrl()` is soft-deprecated and acts as alias calling `pb.files.getUrl()` under the hood._
## 0.14.0

- Added simplified `authWithOAuth2()` version without having to implement custom redirect, deeplink or even page reload:
```js
Expand All @@ -17,6 +7,8 @@
})
```

Works with PocketBase v0.15.0+.

This method initializes a one-off realtime subscription and will
open a popup window with the OAuth2 vendor page to authenticate.
Once the external OAuth2 sign-in/sign-up flow is completed, the popup
Expand All @@ -28,8 +20,21 @@
as redirect URL.

_The "manual" code exchange flow is still supported as `authWithOAuth2Code(provider, code, codeVerifier, redirectUrl)`._

_For backward compatibility it is also available as soft-deprecated function overload of `authWithOAuth2(provider, code, codeVerifier, redirectUrl)`._

- Added new `pb.files` service:
```js
// Builds and returns an absolute record file url for the provided filename.
🔓 pb.files.getUrl(record, filename, queryParams = {});

// Requests a new private file access token for the current auth model (admin or record).
🔐 pb.files.getToken(queryParams = {});
```
_`pb.getFileUrl()` is soft-deprecated and acts as alias calling `pb.files.getUrl()` under the hood._

Works with PocketBase v0.15.0+.


## 0.13.1

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,12 @@ const pb = new PocketBase(baseUrl = '/', authStore = LocalAuthStore);
// Authenticates a record with their username/email and password.
🔓 pb.collection(collectionIdOrName).authWithPassword(usernameOrEmail, password, bodyParams = {}, queryParams = {});
// Authenticates a record with OAuth2 code.
🔓 pb.collection(collectionIdOrName).authWithOAuth2Code(provider, code, codeVerifier, redirectUrl, createData = {}, bodyParams = {}, queryParams = {});
// Authenticates a record with OAuth2 provider without custom redirects, deeplinks or even page reload.
🔓 pb.collection(collectionIdOrName).authWithOAuth2(authConfig);
// Authenticates a record with OAuth2 code.
🔓 pb.collection(collectionIdOrName).authWithOAuth2Code(provider, code, codeVerifier, redirectUrl, createData = {}, bodyParams = {}, queryParams = {});
// Refreshes the current authenticated record model and auth token.
🔐 pb.collection(collectionIdOrName).authRefresh(bodyParams = {}, queryParams = {});
Expand Down
7 changes: 2 additions & 5 deletions dist/pocketbase.cjs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,7 @@ interface RecordSubscription<T = Record> {
action: string; // eg. create, update, delete
record: T;
}
type OAuth2UrlCallback = (data: OAuth2UrlCallbackData) => void;
interface OAuth2UrlCallbackData {
url: string;
}
type OAuth2UrlCallback = (url: string) => void | Promise<void>;
interface OAuth2AuthConfig {
// the name of the OAuth2 provider (eg. "google")
provider: string;
Expand Down Expand Up @@ -683,7 +680,7 @@ declare class RecordService extends CrudService<Record> {
* Example:
*
* ```js
* const authData = await pb.collection('users').authWithOAuth2({
* const authData = await pb.collection("users").authWithOAuth2({
* provider: "google",
* })
* ```
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.

9 changes: 3 additions & 6 deletions dist/pocketbase.es.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,7 @@ interface RecordSubscription<T = Record> {
action: string; // eg. create, update, delete
record: T;
}
type OAuth2UrlCallback = (data: OAuth2UrlCallbackData) => void;
interface OAuth2UrlCallbackData {
url: string;
}
type OAuth2UrlCallback = (url: string) => void | Promise<void>;
interface OAuth2AuthConfig {
// the name of the OAuth2 provider (eg. "google")
provider: string;
Expand Down Expand Up @@ -683,7 +680,7 @@ declare class RecordService extends CrudService<Record> {
* Example:
*
* ```js
* const authData = await pb.collection('users').authWithOAuth2({
* const authData = await pb.collection("users").authWithOAuth2({
* provider: "google",
* })
* ```
Expand Down Expand Up @@ -1097,4 +1094,4 @@ declare function getTokenPayload(token: string): {
* @param [expirationThreshold] Time in seconds that will be subtracted from the token `exp` property.
*/
declare function isTokenExpired(token: string, expirationThreshold?: number): boolean;
export { Client as default, ClientResponseError, BaseAuthStore, LocalAuthStore, getTokenPayload, isTokenExpired, ExternalAuth, Admin, Collection, Record, LogRequest, BaseModel, ListResult, SchemaField, CrudService, AdminService, CollectionService, LogService, RealtimeService, RecordService, SettingsService, SendOptions, BeforeSendResult, RecordAuthResponse, AuthProviderInfo, AuthMethodsList, RecordSubscription, OAuth2UrlCallback, OAuth2UrlCallbackData, OAuth2AuthConfig, OnStoreChangeFunc, UnsubscribeFunc, BaseQueryParams, ListQueryParams, RecordQueryParams, RecordListQueryParams, LogStatsQueryParams, FileQueryParams, FullListQueryParams, RecordFullListQueryParams };
export { Client as default, ClientResponseError, BaseAuthStore, LocalAuthStore, getTokenPayload, isTokenExpired, ExternalAuth, Admin, Collection, Record, LogRequest, BaseModel, ListResult, SchemaField, CrudService, AdminService, CollectionService, LogService, RealtimeService, RecordService, SettingsService, SendOptions, BeforeSendResult, RecordAuthResponse, AuthProviderInfo, AuthMethodsList, RecordSubscription, OAuth2UrlCallback, OAuth2AuthConfig, OnStoreChangeFunc, UnsubscribeFunc, BaseQueryParams, ListQueryParams, RecordQueryParams, RecordListQueryParams, LogStatsQueryParams, FileQueryParams, FullListQueryParams, RecordFullListQueryParams };
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.

7 changes: 2 additions & 5 deletions dist/pocketbase.iife.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,7 @@ interface RecordSubscription<T = Record> {
action: string; // eg. create, update, delete
record: T;
}
type OAuth2UrlCallback = (data: OAuth2UrlCallbackData) => void;
interface OAuth2UrlCallbackData {
url: string;
}
type OAuth2UrlCallback = (url: string) => void | Promise<void>;
interface OAuth2AuthConfig {
// the name of the OAuth2 provider (eg. "google")
provider: string;
Expand Down Expand Up @@ -683,7 +680,7 @@ declare class RecordService extends CrudService<Record> {
* Example:
*
* ```js
* const authData = await pb.collection('users').authWithOAuth2({
* const authData = await pb.collection("users").authWithOAuth2({
* provider: "google",
* })
* ```
Expand Down
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.

7 changes: 2 additions & 5 deletions dist/pocketbase.umd.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,7 @@ interface RecordSubscription<T = Record> {
action: string; // eg. create, update, delete
record: T;
}
type OAuth2UrlCallback = (data: OAuth2UrlCallbackData) => void;
interface OAuth2UrlCallbackData {
url: string;
}
type OAuth2UrlCallback = (url: string) => void | Promise<void>;
interface OAuth2AuthConfig {
// the name of the OAuth2 provider (eg. "google")
provider: string;
Expand Down Expand Up @@ -683,7 +680,7 @@ declare class RecordService extends CrudService<Record> {
* Example:
*
* ```js
* const authData = await pb.collection('users').authWithOAuth2({
* const authData = await pb.collection("users").authWithOAuth2({
* provider: "google",
* })
* ```
Expand Down
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.14.0-rc2",
"version": "0.14.0",
"name": "pocketbase",
"description": "PocketBase JavaScript SDK",
"author": "Gani Georgiev",
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
AuthMethodsList,
RecordSubscription,
OAuth2UrlCallback,
OAuth2UrlCallbackData,
OAuth2AuthConfig,
} from '@/services/RecordService';
import { UnsubscribeFunc } from '@/services/RealtimeService';
Expand Down Expand Up @@ -79,7 +78,6 @@ export {
AuthMethodsList,
RecordSubscription,
OAuth2UrlCallback,
OAuth2UrlCallbackData,
OAuth2AuthConfig,
OnStoreChangeFunc,
UnsubscribeFunc,
Expand Down
16 changes: 5 additions & 11 deletions src/services/RecordService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ export interface RecordSubscription<T = Record> {
record: T;
}

export type OAuth2UrlCallback = (data: OAuth2UrlCallbackData) => void;

export interface OAuth2UrlCallbackData {
url: string;
}
export type OAuth2UrlCallback = (url: string) => void|Promise<void>;

export interface OAuth2AuthConfig {
// the name of the OAuth2 provider (eg. "google")
Expand Down Expand Up @@ -405,7 +401,7 @@ export default class RecordService extends CrudService<Record> {
* Example:
*
* ```js
* const authData = await pb.collection('users').authWithOAuth2({
* const authData = await pb.collection("users").authWithOAuth2({
* provider: "google",
* })
* ```
Expand Down Expand Up @@ -475,9 +471,7 @@ export default class RecordService extends CrudService<Record> {
url.searchParams.set("scope", config.scopes.join(" "));
}

const callbackData = { url: url.toString() };

config.urlCallback ? config.urlCallback(callbackData) : this._defaultUrlCallback(callbackData);
await (config.urlCallback ? config.urlCallback(url.toString()) : this._defaultUrlCallback(url.toString()));
} catch (err) {
reject(new ClientResponseError(err));
}
Expand Down Expand Up @@ -657,7 +651,7 @@ export default class RecordService extends CrudService<Record> {

// ---------------------------------------------------------------

private _defaultUrlCallback(data: OAuth2UrlCallbackData) {
private _defaultUrlCallback(url: string) {
if (typeof window === "undefined" || !window?.open) {
throw new ClientResponseError(new Error(`Not in a browser context - please pass a custom urlCallback function.`));
}
Expand All @@ -676,7 +670,7 @@ export default class RecordService extends CrudService<Record> {
let top = (windowHeight / 2) - (height / 2);

window.open(
data.url,
url,
"oauth2-popup",
'width='+width+',height='+height+',top='+top+',left='+left+',resizable,menubar=no'
);
Expand Down

0 comments on commit cf5d381

Please sign in to comment.