Socket
Socket
Sign inDemoInstall

pocketbase

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pocketbase - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

134

dist/pocketbase.cjs.d.ts

@@ -67,2 +67,11 @@ declare abstract class BaseModel {

}
/**
* The minimal AuthStore interface.
*
* This interface predates the abstract BaseAuthStore class
* and it is kept mainly for backward compatibility.
*
* New AuthStore implementations should extend directly the
* BaseAuthStore abstract class.
*/
type AuthStore = {

@@ -478,15 +487,124 @@ /**

declare class Client {
/**
* The base PocketBase backend url address (eg. 'http://localhost.8090').
*/
baseUrl: string;
/**
* Hook that get triggered right before sending the fetch request,
* allowing you to inspect/modify the request config.
*
* Returns the new modified config that will be used to send the request.
*
* For list of the possible options check https://developer.mozilla.org/en-US/docs/Web/API/fetch#options
*
* Example:
* ```js
* client.beforeSend = function (url, reqConfig) {
* reqConfig.headers = Object.assign(reqConfig.headers, {
* 'X-Custom-Header': 'example',
* });
*
* return reqConfig;
* };
* ```
*/
beforeSend?: (url: string, reqConfig: {
[key: string]: any;
}) => {
[key: string]: any;
};
/**
* Hook that get triggered after successfully sending the fetch request,
* allowing you to inspect/modify the response object and its parsed data.
*
* Returns the new Promise resolved `data` that will be returned to the client.
*
* Example:
* ```js
* client.afterSend = function (response, data) {
* if (response.status != 200) {
* throw new ClientResponseError({
* url: response.url,
* status: response.status,
* data: data,
* });
* }
*
* return data;
* };
* ```
*/
afterSend?: (response: Response, data: any) => any;
/**
* Optional language code (default to `en-US`) that will be sent
* with the requests to the server as `Accept-Language` header.
*/
lang: string;
AuthStore: AuthStore;
readonly Settings: Settings;
readonly Admins: Admins;
readonly Users: Users;
readonly Collections: Collections;
readonly Records: Records;
readonly Logs: Logs;
readonly Realtime: Realtime;
/**
* A replacable instance of the local `AuthStore` service.
*/
authStore: AuthStore;
/**
* An instance of the service that handles the **Settings APIs**.
*/
readonly settings: Settings;
/**
* An instance of the service that handles the **Admin APIs**.
*/
readonly admins: Admins;
/**
* An instance of the service that handles the **User APIs**.
*/
readonly users: Users;
/**
* An instance of the service that handles the **Collection APIs**.
*/
readonly collections: Collections;
/**
* An instance of the service that handles the **Record APIs**.
*/
readonly records: Records;
/**
* An instance of the service that handles the **Log APIs**.
*/
readonly logs: Logs;
/**
* An instance of the service that handles the **Realtime APIs**.
*/
readonly realtime: Realtime;
private cancelControllers;
constructor(baseUrl?: string, lang?: string, authStore?: AuthStore | null);
/**
* @deprecated Legacy alias for `this.authStore`.
*/
get AuthStore(): AuthStore;
/**
* @deprecated Legacy alias for `this.settings`.
*/
get Settings(): Settings;
/**
* @deprecated Legacy alias for `this.admins`.
*/
get Admins(): Admins;
/**
* @deprecated Legacy alias for `this.users`.
*/
get Users(): Users;
/**
* @deprecated Legacy alias for `this.collections`.
*/
get Collections(): Collections;
/**
* @deprecated Legacy alias for `this.records`.
*/
get Records(): Records;
/**
* @deprecated Legacy alias for `this.logs`.
*/
get Logs(): Logs;
/**
* @deprecated Legacy alias for `this.realtime`.
*/
get Realtime(): Realtime;
/**
* Cancels single request by its cancellation key.

@@ -493,0 +611,0 @@ */

2

dist/pocketbase.cjs.js

@@ -1,1 +0,1 @@

"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}var n=function(){return n=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function i(t,e,n,i){return new(n||(n=Promise))((function(o,r){function s(t){try{a(i.next(t))}catch(t){r(t)}}function u(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}a((i=i.apply(t,e||[])).next())}))}function o(t,e){var n,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function u(r){return function(u){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){s.label=r[1];break}if(6===r[0]&&s.label<o[1]){s.label=o[1],o=r;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(r);break}o[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(t){r=[6,t],i=0}finally{n=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,u])}}}var r,s=function(t){function i(e){var n,i=this;return(i=t.call(this,"ClientResponseError")||this).url="",i.status=0,i.data={},i.isAbort=!1,i.originalError=null,e instanceof Error&&!(e instanceof i.constructor)&&(i.originalError=e),null!==e&&"object"==typeof e&&(i.url="string"==typeof e.url?e.url:"",i.status="number"==typeof e.status?e.status:0,i.data=null!==e.data&&"object"==typeof e.data?e.data:{}),"undefined"!=typeof DOMException&&e instanceof DOMException&&(i.isAbort=!0),i.name="ClientResponseError "+i.status,i.message=(null===(n=i.data)||void 0===n?void 0:n.message)||"Something went wrong while processing your request.",i}return e(i,t),i.prototype.toJSON=function(){return n({},this)},i}(Error);r="function"==typeof atob?atob:function(t){return Buffer.from(t,"base64").toString("binary")};var u=function(){function t(){}return t.getPayload=function(t){if(t)try{var e=decodeURIComponent(r(t.split(".")[1]).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(e)||{}}catch(t){}return{}},t.isExpired=function(e,n){void 0===n&&(n=0);var i=t.getPayload(e);return!(Object.keys(i).length>0&&(!i.exp||i.exp-n>Date.now()/1e3))},t}(),a=function(){function t(t){void 0===t&&(t={}),this.load(t||{})}return t.prototype.load=function(t){this.id=void 0!==t.id?t.id:"",this.created=void 0!==t.created?t.created:"",this.updated=void 0!==t.updated?t.updated:""},Object.defineProperty(t.prototype,"isNew",{get:function(){return!this.id||"00000000-0000-0000-0000-000000000000"===this.id},enumerable:!1,configurable:!0}),t.prototype.clone=function(){return new this.constructor(JSON.parse(JSON.stringify(this)))},t.prototype.export=function(){return Object.assign({},this)},t}(),l=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e);for(var n=0,i=Object.entries(e);n<i.length;n++){var o=i[n],r=o[0],s=o[1];this[r]=s}this["@collectionId"]=void 0!==e["@collectionId"]?e["@collectionId"]:"",this["@collectionName"]=void 0!==e["@collectionName"]?e["@collectionName"]:"",this["@expand"]=void 0!==e["@expand"]?e["@expand"]:{}},n}(a),c=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.email="string"==typeof e.email?e.email:"",this.verified=!!e.verified,this.lastResetSentAt="string"==typeof e.lastResetSentAt?e.lastResetSentAt:"",this.lastVerificationSentAt="string"==typeof e.lastVerificationSentAt?e.lastVerificationSentAt:"",this.profile=e.profile?new l(e.profile):null},n}(a),d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.avatar="number"==typeof e.avatar?e.avatar:0,this.email="string"==typeof e.email?e.email:"",this.lastResetSentAt="string"==typeof e.lastResetSentAt?e.lastResetSentAt:""},n}(a),h=function(){function t(t){void 0===t&&(t="pocketbase_auth"),this.fallback={},this.storageKey=t}return Object.defineProperty(t.prototype,"token",{get:function(){return(this._storageGet(this.storageKey)||{}).token||""},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"model",{get:function(){var t,e=this._storageGet(this.storageKey)||{};return null===e||"object"!=typeof e||null===e.model||"object"!=typeof e.model?{}:void 0!==(null===(t=e.model)||void 0===t?void 0:t.verified)?new c(e.model):new d(e.model)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isValid",{get:function(){return!u.isExpired(this.token)},enumerable:!1,configurable:!0}),t.prototype.save=function(t,e){this._storageSet(this.storageKey,{token:t,model:e})},t.prototype.clear=function(){return this._storageRemove(this.storageKey)},t.prototype._storageGet=function(t){var e;if("undefined"!=typeof window&&(null===window||void 0===window?void 0:window.localStorage)){var n=(null===(e=null===window||void 0===window?void 0:window.localStorage)||void 0===e?void 0:e.getItem(t))||"";try{return JSON.parse(n)}catch(t){return n}}return this.fallback[t]},t.prototype._storageSet=function(t,e){var n;if("undefined"!=typeof window&&(null===window||void 0===window?void 0:window.localStorage)){var i=e;"string"!=typeof e&&(i=JSON.stringify(e)),null===(n=null===window||void 0===window?void 0:window.localStorage)||void 0===n||n.setItem(t,i)}else this.fallback[t]=e},t.prototype._storageRemove=function(t){var e;"undefined"!=typeof window&&(null===(e=null===window||void 0===window?void 0:window.localStorage)||void 0===e||e.removeItem(t)),delete this.fallback[t]},t}(),p=function(t){this.client=t},f=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getAll=function(t){return void 0===t&&(t={}),this.client.send("/api/settings",{method:"GET",params:t}).then((function(t){return t||{}}))},n.prototype.update=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send("/api/settings",{method:"PATCH",params:e,body:t}).then((function(t){return t||{}}))},n}(p),v=function(t,e,n,i){this.page=t>0?t:1,this.perPage=e>=0?e:0,this.totalItems=n>=0?n:0,this.items=i||[]},y=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype._getFullList=function(t,e,n){var r=this;void 0===e&&(e=100),void 0===n&&(n={});var s=[],u=function(a){return i(r,void 0,void 0,(function(){return o(this,(function(i){return[2,this._getList(t,a,e,n).then((function(t){var e=t,n=e.items,i=e.totalItems;return s=s.concat(n),n.length&&i>s.length?u(a+1):s}))]}))}))};return u(1)},n.prototype._getList=function(t,e,n,i){var o=this;return void 0===e&&(e=1),void 0===n&&(n=30),void 0===i&&(i={}),i=Object.assign({page:e,perPage:n},i),this.client.send(t,{method:"GET",params:i}).then((function(t){var e=[];if(null==t?void 0:t.items){t.items=t.items||[];for(var n=0,i=t.items;n<i.length;n++){var r=i[n];e.push(o.decode(r))}}return new v((null==t?void 0:t.page)||1,(null==t?void 0:t.perPage)||0,(null==t?void 0:t.totalItems)||0,e)}))},n.prototype._getOne=function(t,e,n){var i=this;return void 0===n&&(n={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"GET",params:n}).then((function(t){return i.decode(t)}))},n.prototype._create=function(t,e,n){var i=this;return void 0===e&&(e={}),void 0===n&&(n={}),this.client.send(t,{method:"POST",params:n,body:e}).then((function(t){return i.decode(t)}))},n.prototype._update=function(t,e,n,i){var o=this;return void 0===n&&(n={}),void 0===i&&(i={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"PATCH",params:i,body:n}).then((function(t){return o.decode(t)}))},n.prototype._delete=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"DELETE",params:i,body:n}).then((function(){return!0}))},n}(p),m=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getFullList=function(t,e){return void 0===t&&(t=100),void 0===e&&(e={}),this._getFullList(this.baseCrudPath(),t,e)},n.prototype.getList=function(t,e,n){return void 0===t&&(t=1),void 0===e&&(e=30),void 0===n&&(n={}),this._getList(this.baseCrudPath(),t,e,n)},n.prototype.getOne=function(t,e){return void 0===e&&(e={}),this._getOne(this.baseCrudPath(),t,e)},n.prototype.create=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this._create(this.baseCrudPath(),t,e)},n.prototype.update=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._update(this.baseCrudPath(),t,e,n)},n.prototype.delete=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._delete(this.baseCrudPath(),t,e,n)},n}(y),b=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new d(t)},n.prototype.baseCrudPath=function(){return"/api/admins"},n.prototype.authResponse=function(t){var e=this.decode((null==t?void 0:t.admin)||{});return(null==t?void 0:t.token)&&(null==t?void 0:t.admin)&&this.client.AuthStore.save(t.token,e),Object.assign({},t,{token:(null==t?void 0:t.token)||"",admin:e})},n.prototype.authViaEmail=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({email:t,password:e},n),this.client.send(this.baseCrudPath()+"/auth-via-email",{method:"POST",params:i,body:n,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.refresh=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send(this.baseCrudPath()+"/refresh",{method:"POST",params:e,body:t}).then(this.authResponse.bind(this))},n.prototype.requestPasswordReset=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-password-reset",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmPasswordReset=function(t,e,n,i,o){return void 0===i&&(i={}),void 0===o&&(o={}),i=Object.assign({token:t,password:e,passwordConfirm:n},i),this.client.send(this.baseCrudPath()+"/confirm-password-reset",{method:"POST",params:o,body:i}).then(this.authResponse.bind(this))},n}(m),g=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new c(t)},n.prototype.baseCrudPath=function(){return"/api/users"},n.prototype.authResponse=function(t){var e=this.decode((null==t?void 0:t.user)||{});return(null==t?void 0:t.token)&&(null==t?void 0:t.user)&&this.client.AuthStore.save(t.token,e),Object.assign({},t,{token:(null==t?void 0:t.token)||"",user:e})},n.prototype.listAuthMethods=function(t){return void 0===t&&(t={}),this.client.send(this.baseCrudPath()+"/auth-methods",{method:"GET",params:t}).then((function(t){return Object.assign({},t,{emailPassword:!!(null==t?void 0:t.emailPassword),authProviders:Array.isArray(null==t?void 0:t.authProviders)?null==t?void 0:t.authProviders:[]})}))},n.prototype.authViaEmail=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({email:t,password:e},n),this.client.send(this.baseCrudPath()+"/auth-via-email",{method:"POST",params:i,body:n,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.authViaOAuth2=function(t,e,n,i,o,r){return void 0===o&&(o={}),void 0===r&&(r={}),o=Object.assign({provider:t,code:e,codeVerifier:n,redirectUrl:i},o),this.client.send(this.baseCrudPath()+"/auth-via-oauth2",{method:"POST",params:r,body:o,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.refresh=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send(this.baseCrudPath()+"/refresh",{method:"POST",params:e,body:t}).then(this.authResponse.bind(this))},n.prototype.requestPasswordReset=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-password-reset",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmPasswordReset=function(t,e,n,i,o){return void 0===i&&(i={}),void 0===o&&(o={}),i=Object.assign({token:t,password:e,passwordConfirm:n},i),this.client.send(this.baseCrudPath()+"/confirm-password-reset",{method:"POST",params:o,body:i}).then(this.authResponse.bind(this))},n.prototype.requestVerification=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-verification",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmVerification=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({token:t},e),this.client.send(this.baseCrudPath()+"/confirm-verification",{method:"POST",params:n,body:e}).then(this.authResponse.bind(this))},n.prototype.requestEmailChange=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({newEmail:t},e),this.client.send(this.baseCrudPath()+"/request-email-change",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmEmailChange=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({token:t,password:e},n),this.client.send(this.baseCrudPath()+"/confirm-email-change",{method:"POST",params:i,body:n}).then(this.authResponse.bind(this))},n}(m),w=function(){function t(t){void 0===t&&(t={}),this.load(t||{})}return t.prototype.load=function(t){this.id=void 0!==t.id?t.id:"",this.name=void 0!==t.name?t.name:"",this.type=void 0!==t.type?t.type:"text",this.system=!!t.system,this.required=!!t.required,this.unique=!!t.unique,this.options="object"==typeof t.options&&null!==t.options?t.options:{}},t}(),S=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.name="string"==typeof e.name?e.name:"",this.system=!!e.system,this.listRule="string"==typeof e.listRule?e.listRule:null,this.viewRule="string"==typeof e.viewRule?e.viewRule:null,this.createRule="string"==typeof e.createRule?e.createRule:null,this.updateRule="string"==typeof e.updateRule?e.updateRule:null,this.deleteRule="string"==typeof e.deleteRule?e.deleteRule:null,e.schema=Array.isArray(e.schema)?e.schema:[],this.schema=[];for(var n=0,i=e.schema;n<i.length;n++){var o=i[n];this.schema.push(new w(o))}},n}(a),P=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new S(t)},n.prototype.baseCrudPath=function(){return"/api/collections"},n}(m),O=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new l(t)},n.prototype.baseCrudPath=function(t){return"/api/collections/"+encodeURIComponent(t)+"/records"},n.prototype.getFileUrl=function(t,e,n){void 0===n&&(n={});var i=[];i.push(this.client.baseUrl.replace(/\/+$/gm,"")),i.push("api"),i.push("files"),i.push(t["@collectionId"]),i.push(t.id),i.push(e);var o=i.join("/");if(Object.keys(n).length){var r=new URLSearchParams(n);o+=(o.includes("?")?"&":"?")+r}return o},n}(function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getFullList=function(t,e,n){return void 0===e&&(e=100),void 0===n&&(n={}),this._getFullList(this.baseCrudPath(t),e,n)},n.prototype.getList=function(t,e,n,i){return void 0===e&&(e=1),void 0===n&&(n=30),void 0===i&&(i={}),this._getList(this.baseCrudPath(t),e,n,i)},n.prototype.getOne=function(t,e,n){return void 0===n&&(n={}),this._getOne(this.baseCrudPath(t),e,n)},n.prototype.create=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._create(this.baseCrudPath(t),e,n)},n.prototype.update=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this._update(this.baseCrudPath(t),e,n,i)},n.prototype.delete=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this._delete(this.baseCrudPath(t),e,n,i)},n}(y)),C=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.url="string"==typeof e.url?e.url:"",this.method="string"==typeof e.method?e.method:"GET",this.status="number"==typeof e.status?e.status:200,this.auth="string"==typeof e.auth?e.auth:"guest",this.ip="string"==typeof e.ip?e.ip:"",this.referer="string"==typeof e.referer?e.referer:"",this.userAgent="string"==typeof e.userAgent?e.userAgent:"",this.meta="object"==typeof e.meta&&null!==e.meta?e.meta:{}},n}(a),R=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getRequestsList=function(t,e,n){return void 0===t&&(t=1),void 0===e&&(e=30),void 0===n&&(n={}),n=Object.assign({page:t,perPage:e},n),this.client.send("/api/logs/requests",{method:"GET",params:n}).then((function(t){var e=[];if(null==t?void 0:t.items){t.items=(null==t?void 0:t.items)||[];for(var n=0,i=t.items;n<i.length;n++){var o=i[n];e.push(new C(o))}}return new v((null==t?void 0:t.page)||1,(null==t?void 0:t.perPage)||0,(null==t?void 0:t.totalItems)||0,e)}))},n.prototype.getRequest=function(t,e){return void 0===e&&(e={}),this.client.send("/api/logs/requests/"+encodeURIComponent(t),{method:"GET",params:e}).then((function(t){return new C(t)}))},n.prototype.getRequestsStats=function(t){return void 0===t&&(t={}),this.client.send("/api/logs/requests/stats",{method:"GET",params:t}).then((function(t){return t}))},n}(p),j=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.clientId="",e.eventSource=null,e.subscriptions={},e}return e(n,t),n.prototype.subscribe=function(t,e){var n;return i(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:if(!t)throw new Error("subscription must be set.");return this.subscriptions[t]&&(null===(n=this.eventSource)||void 0===n||n.removeEventListener(t,this.subscriptions[t])),this.subscriptions[t]=function(t){var n,i=t;try{n=JSON.parse(null==i?void 0:i.data)}catch(t){}e(n||{})},this.eventSource?[3,1]:(this.connect(),[3,3]);case 1:return this.clientId?[4,this.submitSubscriptions()]:[3,3];case 2:i.sent(),i.label=3;case 3:return[2]}}))}))},n.prototype.unsubscribe=function(t){var e;return i(this,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:if(t){if(!this.subscriptions[t])return[2];null===(e=this.eventSource)||void 0===e||e.removeEventListener(t,this.subscriptions[t]),delete this.subscriptions[t]}else this.removeSubscriptionListeners(),this.subscriptions={};return this.clientId?[4,this.submitSubscriptions()]:[3,2];case 1:n.sent(),n.label=2;case 2:return Object.keys(this.subscriptions).length||this.disconnect(),[2]}}))}))},n.prototype.submitSubscriptions=function(){return i(this,void 0,void 0,(function(){return o(this,(function(t){return this.addSubscriptionListeners(),[2,this.client.send("/api/realtime",{method:"POST",body:{clientId:this.clientId,subscriptions:Object.keys(this.subscriptions)}}).then((function(){return!0}))]}))}))},n.prototype.addSubscriptionListeners=function(){if(this.eventSource)for(var t in this.removeSubscriptionListeners(),this.subscriptions)this.eventSource.addEventListener(t,this.subscriptions[t])},n.prototype.removeSubscriptionListeners=function(){if(this.eventSource)for(var t in this.subscriptions)this.eventSource.removeEventListener(t,this.subscriptions[t])},n.prototype.connectHandler=function(t){var e=t;this.clientId=null==e?void 0:e.lastEventId,this.submitSubscriptions()},n.prototype.connect=function(){var t=this;this.disconnect(),this.eventSource=new EventSource(this.client.buildUrl("/api/realtime")),this.eventSource.addEventListener("PB_CONNECT",(function(e){return t.connectHandler(e)}))},n.prototype.disconnect=function(){var t,e,n=this;this.removeSubscriptionListeners(),null===(t=this.eventSource)||void 0===t||t.removeEventListener("PB_CONNECT",(function(t){return n.connectHandler(t)})),null===(e=this.eventSource)||void 0===e||e.close(),this.eventSource=null,this.clientId=""},n}(p),A=function(){function t(t,e,n){void 0===t&&(t="/"),void 0===e&&(e="en-US"),this.cancelControllers={},this.baseUrl=t,this.lang=e,this.AuthStore=n||new h,this.Settings=new f(this),this.Admins=new b(this),this.Users=new g(this),this.Collections=new P(this),this.Records=new O(this),this.Logs=new R(this),this.Realtime=new j(this)}return t.prototype.cancelRequest=function(t){return this.cancelControllers[t]&&(this.cancelControllers[t].abort(),delete this.cancelControllers[t]),this},t.prototype.cancelAllRequests=function(){for(var t in this.cancelControllers)this.cancelControllers[t].abort();return this.cancelControllers={},this},t.prototype.send=function(t,e){var n,r,u,a,l,c,d,h,p,f=this,v=Object.assign({method:"GET"},e);if(v.body&&"FormData"!==v.body.constructor.name&&("string"!=typeof v.body&&(v.body=JSON.stringify(v.body)),void 0===(null===(n=null==v?void 0:v.headers)||void 0===n?void 0:n["Content-Type"])&&(v.headers=Object.assign({},v.headers,{"Content-Type":"application/json"}))),void 0===(null===(r=null==v?void 0:v.headers)||void 0===r?void 0:r["Accept-Language"])&&(v.headers=Object.assign({},v.headers,{"Accept-Language":this.lang})),(null===(u=this.AuthStore)||void 0===u?void 0:u.token)&&void 0===(null===(a=null==v?void 0:v.headers)||void 0===a?void 0:a.Authorization)){var y="Admin";void 0!==(null===(l=this.AuthStore.model)||void 0===l?void 0:l.verified)&&(y="User"),v.headers=Object.assign({},v.headers,{Authorization:y+" "+this.AuthStore.token})}if(!1!==(null===(c=v.params)||void 0===c?void 0:c.$autoCancel)){var m=(null===(d=v.params)||void 0===d?void 0:d.$cancelKey)||(v.method||"GET")+t;this.cancelRequest(m);var b=new AbortController;this.cancelControllers[m]=b,v.signal=b.signal}null===(h=v.params)||void 0===h||delete h.$autoCancel,null===(p=v.params)||void 0===p||delete p.$cancelKey;var g=this.buildUrl(t);if(void 0!==v.params){var w=this.serializeQueryParams(v.params);w&&(g+=(g.includes("?")?"&":"?")+w),delete v.params}return fetch(g,v).then((function(t){return i(f,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:e={},n.label=1;case 1:return n.trys.push([1,3,,4]),[4,t.json()];case 2:return e=n.sent(),[3,4];case 3:return n.sent(),[3,4];case 4:if(t.status>=400)throw new s({url:t.url,status:t.status,data:e});return[2,e]}}))}))})).catch((function(t){if(t instanceof s)throw t;throw new s(t)}))},t.prototype.buildUrl=function(t){var e=this.baseUrl+(this.baseUrl.endsWith("/")?"":"/");return t&&(e+=t.startsWith("/")?t.substring(1):t),e},t.prototype.serializeQueryParams=function(t){var e=[];for(var n in t)if(null!==t[n]){var i=t[n],o=encodeURIComponent(n);if(Array.isArray(i))for(var r=0,s=i;r<s.length;r++){var u=s[r];e.push(o+"="+encodeURIComponent(u))}else i instanceof Date?e.push(o+"="+encodeURIComponent(i.toISOString())):null!==typeof i&&"object"==typeof i?e.push(o+"="+encodeURIComponent(JSON.stringify(i))):e.push(o+"="+encodeURIComponent(i))}return e.join("&")},t}();module.exports=A;
"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}var n=function(){return n=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function i(t,e,n,i){return new(n||(n=Promise))((function(o,r){function s(t){try{a(i.next(t))}catch(t){r(t)}}function u(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}a((i=i.apply(t,e||[])).next())}))}function o(t,e){var n,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function u(r){return function(u){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){s.label=r[1];break}if(6===r[0]&&s.label<o[1]){s.label=o[1],o=r;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(r);break}o[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(t){r=[6,t],i=0}finally{n=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,u])}}}var r,s=function(t){function i(e){var n,i=this;return(i=t.call(this,"ClientResponseError")||this).url="",i.status=0,i.data={},i.isAbort=!1,i.originalError=null,e instanceof Error&&!(e instanceof i.constructor)&&(i.originalError=e),null!==e&&"object"==typeof e&&(i.url="string"==typeof e.url?e.url:"",i.status="number"==typeof e.status?e.status:0,i.data=null!==e.data&&"object"==typeof e.data?e.data:{}),"undefined"!=typeof DOMException&&e instanceof DOMException&&(i.isAbort=!0),i.name="ClientResponseError "+i.status,i.message=(null===(n=i.data)||void 0===n?void 0:n.message)||"Something went wrong while processing your request.",i}return e(i,t),i.prototype.toJSON=function(){return n({},this)},i}(Error);r="function"==typeof atob?atob:function(t){return Buffer.from(t,"base64").toString("binary")};var u=function(){function t(){}return t.getPayload=function(t){if(t)try{var e=decodeURIComponent(r(t.split(".")[1]).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(e)||{}}catch(t){}return{}},t.isExpired=function(e,n){void 0===n&&(n=0);var i=t.getPayload(e);return!(Object.keys(i).length>0&&(!i.exp||i.exp-n>Date.now()/1e3))},t}(),a=function(){function t(){this.baseToken="",this.baseModel={},this._onChangeCallbacks=[]}return Object.defineProperty(t.prototype,"token",{get:function(){return this.baseToken},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"model",{get:function(){return this.baseModel},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isValid",{get:function(){return!u.isExpired(this.token)},enumerable:!1,configurable:!0}),t.prototype.save=function(t,e){this.baseToken=t,this.baseModel=e,this._triggerChange()},t.prototype.clear=function(){this._triggerChange()},t.prototype.onChange=function(t){var e=this;return this._onChangeCallbacks.push(t),function(){for(var n=e._onChangeCallbacks.length-1;n>=0;n--)if(e._onChangeCallbacks[n]==t)return delete e._onChangeCallbacks[n],void e._onChangeCallbacks.splice(n,1)}},t.prototype._triggerChange=function(){for(var t=0,e=this._onChangeCallbacks;t<e.length;t++){var n=e[t];n&&n(this.token,this.model)}},t}(),l=function(){function t(t){void 0===t&&(t={}),this.load(t||{})}return t.prototype.load=function(t){this.id=void 0!==t.id?t.id:"",this.created=void 0!==t.created?t.created:"",this.updated=void 0!==t.updated?t.updated:""},Object.defineProperty(t.prototype,"isNew",{get:function(){return!this.id||"00000000-0000-0000-0000-000000000000"===this.id},enumerable:!1,configurable:!0}),t.prototype.clone=function(){return new this.constructor(JSON.parse(JSON.stringify(this)))},t.prototype.export=function(){return Object.assign({},this)},t}(),c=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e);for(var n=0,i=Object.entries(e);n<i.length;n++){var o=i[n],r=o[0],s=o[1];this[r]=s}this["@collectionId"]=void 0!==e["@collectionId"]?e["@collectionId"]:"",this["@collectionName"]=void 0!==e["@collectionName"]?e["@collectionName"]:"",this["@expand"]=void 0!==e["@expand"]?e["@expand"]:{}},n}(l),h=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.email="string"==typeof e.email?e.email:"",this.verified=!!e.verified,this.lastResetSentAt="string"==typeof e.lastResetSentAt?e.lastResetSentAt:"",this.lastVerificationSentAt="string"==typeof e.lastVerificationSentAt?e.lastVerificationSentAt:"",this.profile=e.profile?new c(e.profile):null},n}(l),d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.avatar="number"==typeof e.avatar?e.avatar:0,this.email="string"==typeof e.email?e.email:"",this.lastResetSentAt="string"==typeof e.lastResetSentAt?e.lastResetSentAt:""},n}(l),p=function(t){function n(e){void 0===e&&(e="pocketbase_auth");var n=t.call(this)||this;return n.fallback={},n.storageKey=e,n}return e(n,t),Object.defineProperty(n.prototype,"token",{get:function(){return(this._storageGet(this.storageKey)||{}).token||""},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"model",{get:function(){var t,e=this._storageGet(this.storageKey)||{};return null===e||"object"!=typeof e||null===e.model||"object"!=typeof e.model?{}:void 0!==(null===(t=e.model)||void 0===t?void 0:t.verified)?new h(e.model):new d(e.model)},enumerable:!1,configurable:!0}),n.prototype.save=function(e,n){this._storageSet(this.storageKey,{token:e,model:n}),t.prototype.save.call(this,e,n)},n.prototype.clear=function(){this._storageRemove(this.storageKey),t.prototype.clear.call(this)},n.prototype._storageGet=function(t){var e;if("undefined"!=typeof window&&(null===window||void 0===window?void 0:window.localStorage)){var n=(null===(e=null===window||void 0===window?void 0:window.localStorage)||void 0===e?void 0:e.getItem(t))||"";try{return JSON.parse(n)}catch(t){return n}}return this.fallback[t]},n.prototype._storageSet=function(t,e){var n;if("undefined"!=typeof window&&(null===window||void 0===window?void 0:window.localStorage)){var i=e;"string"!=typeof e&&(i=JSON.stringify(e)),null===(n=null===window||void 0===window?void 0:window.localStorage)||void 0===n||n.setItem(t,i)}else this.fallback[t]=e},n.prototype._storageRemove=function(t){var e;"undefined"!=typeof window&&(null===(e=null===window||void 0===window?void 0:window.localStorage)||void 0===e||e.removeItem(t)),delete this.fallback[t]},n}(a),f=function(t){this.client=t},v=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getAll=function(t){return void 0===t&&(t={}),this.client.send("/api/settings",{method:"GET",params:t}).then((function(t){return t||{}}))},n.prototype.update=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send("/api/settings",{method:"PATCH",params:e,body:t}).then((function(t){return t||{}}))},n}(f),y=function(t,e,n,i){this.page=t>0?t:1,this.perPage=e>=0?e:0,this.totalItems=n>=0?n:0,this.items=i||[]},b=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype._getFullList=function(t,e,n){var r=this;void 0===e&&(e=100),void 0===n&&(n={});var s=[],u=function(a){return i(r,void 0,void 0,(function(){return o(this,(function(i){return[2,this._getList(t,a,e,n).then((function(t){var e=t,n=e.items,i=e.totalItems;return s=s.concat(n),n.length&&i>s.length?u(a+1):s}))]}))}))};return u(1)},n.prototype._getList=function(t,e,n,i){var o=this;return void 0===e&&(e=1),void 0===n&&(n=30),void 0===i&&(i={}),i=Object.assign({page:e,perPage:n},i),this.client.send(t,{method:"GET",params:i}).then((function(t){var e=[];if(null==t?void 0:t.items){t.items=t.items||[];for(var n=0,i=t.items;n<i.length;n++){var r=i[n];e.push(o.decode(r))}}return new y((null==t?void 0:t.page)||1,(null==t?void 0:t.perPage)||0,(null==t?void 0:t.totalItems)||0,e)}))},n.prototype._getOne=function(t,e,n){var i=this;return void 0===n&&(n={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"GET",params:n}).then((function(t){return i.decode(t)}))},n.prototype._create=function(t,e,n){var i=this;return void 0===e&&(e={}),void 0===n&&(n={}),this.client.send(t,{method:"POST",params:n,body:e}).then((function(t){return i.decode(t)}))},n.prototype._update=function(t,e,n,i){var o=this;return void 0===n&&(n={}),void 0===i&&(i={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"PATCH",params:i,body:n}).then((function(t){return o.decode(t)}))},n.prototype._delete=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"DELETE",params:i,body:n}).then((function(){return!0}))},n}(f),m=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getFullList=function(t,e){return void 0===t&&(t=100),void 0===e&&(e={}),this._getFullList(this.baseCrudPath(),t,e)},n.prototype.getList=function(t,e,n){return void 0===t&&(t=1),void 0===e&&(e=30),void 0===n&&(n={}),this._getList(this.baseCrudPath(),t,e,n)},n.prototype.getOne=function(t,e){return void 0===e&&(e={}),this._getOne(this.baseCrudPath(),t,e)},n.prototype.create=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this._create(this.baseCrudPath(),t,e)},n.prototype.update=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._update(this.baseCrudPath(),t,e,n)},n.prototype.delete=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._delete(this.baseCrudPath(),t,e,n)},n}(b),g=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new d(t)},n.prototype.baseCrudPath=function(){return"/api/admins"},n.prototype.authResponse=function(t){var e=this.decode((null==t?void 0:t.admin)||{});return(null==t?void 0:t.token)&&(null==t?void 0:t.admin)&&this.client.authStore.save(t.token,e),Object.assign({},t,{token:(null==t?void 0:t.token)||"",admin:e})},n.prototype.authViaEmail=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({email:t,password:e},n),this.client.send(this.baseCrudPath()+"/auth-via-email",{method:"POST",params:i,body:n,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.refresh=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send(this.baseCrudPath()+"/refresh",{method:"POST",params:e,body:t}).then(this.authResponse.bind(this))},n.prototype.requestPasswordReset=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-password-reset",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmPasswordReset=function(t,e,n,i,o){return void 0===i&&(i={}),void 0===o&&(o={}),i=Object.assign({token:t,password:e,passwordConfirm:n},i),this.client.send(this.baseCrudPath()+"/confirm-password-reset",{method:"POST",params:o,body:i}).then(this.authResponse.bind(this))},n}(m),w=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new h(t)},n.prototype.baseCrudPath=function(){return"/api/users"},n.prototype.authResponse=function(t){var e=this.decode((null==t?void 0:t.user)||{});return(null==t?void 0:t.token)&&(null==t?void 0:t.user)&&this.client.authStore.save(t.token,e),Object.assign({},t,{token:(null==t?void 0:t.token)||"",user:e})},n.prototype.listAuthMethods=function(t){return void 0===t&&(t={}),this.client.send(this.baseCrudPath()+"/auth-methods",{method:"GET",params:t}).then((function(t){return Object.assign({},t,{emailPassword:!!(null==t?void 0:t.emailPassword),authProviders:Array.isArray(null==t?void 0:t.authProviders)?null==t?void 0:t.authProviders:[]})}))},n.prototype.authViaEmail=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({email:t,password:e},n),this.client.send(this.baseCrudPath()+"/auth-via-email",{method:"POST",params:i,body:n,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.authViaOAuth2=function(t,e,n,i,o,r){return void 0===o&&(o={}),void 0===r&&(r={}),o=Object.assign({provider:t,code:e,codeVerifier:n,redirectUrl:i},o),this.client.send(this.baseCrudPath()+"/auth-via-oauth2",{method:"POST",params:r,body:o,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.refresh=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send(this.baseCrudPath()+"/refresh",{method:"POST",params:e,body:t}).then(this.authResponse.bind(this))},n.prototype.requestPasswordReset=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-password-reset",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmPasswordReset=function(t,e,n,i,o){return void 0===i&&(i={}),void 0===o&&(o={}),i=Object.assign({token:t,password:e,passwordConfirm:n},i),this.client.send(this.baseCrudPath()+"/confirm-password-reset",{method:"POST",params:o,body:i}).then(this.authResponse.bind(this))},n.prototype.requestVerification=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-verification",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmVerification=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({token:t},e),this.client.send(this.baseCrudPath()+"/confirm-verification",{method:"POST",params:n,body:e}).then(this.authResponse.bind(this))},n.prototype.requestEmailChange=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({newEmail:t},e),this.client.send(this.baseCrudPath()+"/request-email-change",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmEmailChange=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({token:t,password:e},n),this.client.send(this.baseCrudPath()+"/confirm-email-change",{method:"POST",params:i,body:n}).then(this.authResponse.bind(this))},n}(m),S=function(){function t(t){void 0===t&&(t={}),this.load(t||{})}return t.prototype.load=function(t){this.id=void 0!==t.id?t.id:"",this.name=void 0!==t.name?t.name:"",this.type=void 0!==t.type?t.type:"text",this.system=!!t.system,this.required=!!t.required,this.unique=!!t.unique,this.options="object"==typeof t.options&&null!==t.options?t.options:{}},t}(),C=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.name="string"==typeof e.name?e.name:"",this.system=!!e.system,this.listRule="string"==typeof e.listRule?e.listRule:null,this.viewRule="string"==typeof e.viewRule?e.viewRule:null,this.createRule="string"==typeof e.createRule?e.createRule:null,this.updateRule="string"==typeof e.updateRule?e.updateRule:null,this.deleteRule="string"==typeof e.deleteRule?e.deleteRule:null,e.schema=Array.isArray(e.schema)?e.schema:[],this.schema=[];for(var n=0,i=e.schema;n<i.length;n++){var o=i[n];this.schema.push(new S(o))}},n}(l),P=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new C(t)},n.prototype.baseCrudPath=function(){return"/api/collections"},n}(m),O=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new c(t)},n.prototype.baseCrudPath=function(t){return"/api/collections/"+encodeURIComponent(t)+"/records"},n.prototype.getFileUrl=function(t,e,n){void 0===n&&(n={});var i=[];i.push(this.client.baseUrl.replace(/\/+$/gm,"")),i.push("api"),i.push("files"),i.push(t["@collectionId"]),i.push(t.id),i.push(e);var o=i.join("/");if(Object.keys(n).length){var r=new URLSearchParams(n);o+=(o.includes("?")?"&":"?")+r}return o},n}(function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getFullList=function(t,e,n){return void 0===e&&(e=100),void 0===n&&(n={}),this._getFullList(this.baseCrudPath(t),e,n)},n.prototype.getList=function(t,e,n,i){return void 0===e&&(e=1),void 0===n&&(n=30),void 0===i&&(i={}),this._getList(this.baseCrudPath(t),e,n,i)},n.prototype.getOne=function(t,e,n){return void 0===n&&(n={}),this._getOne(this.baseCrudPath(t),e,n)},n.prototype.create=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._create(this.baseCrudPath(t),e,n)},n.prototype.update=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this._update(this.baseCrudPath(t),e,n,i)},n.prototype.delete=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this._delete(this.baseCrudPath(t),e,n,i)},n}(b)),R=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.url="string"==typeof e.url?e.url:"",this.method="string"==typeof e.method?e.method:"GET",this.status="number"==typeof e.status?e.status:200,this.auth="string"==typeof e.auth?e.auth:"guest",this.ip="string"==typeof e.ip?e.ip:"",this.referer="string"==typeof e.referer?e.referer:"",this.userAgent="string"==typeof e.userAgent?e.userAgent:"",this.meta="object"==typeof e.meta&&null!==e.meta?e.meta:{}},n}(l),j=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getRequestsList=function(t,e,n){return void 0===t&&(t=1),void 0===e&&(e=30),void 0===n&&(n={}),n=Object.assign({page:t,perPage:e},n),this.client.send("/api/logs/requests",{method:"GET",params:n}).then((function(t){var e=[];if(null==t?void 0:t.items){t.items=(null==t?void 0:t.items)||[];for(var n=0,i=t.items;n<i.length;n++){var o=i[n];e.push(new R(o))}}return new y((null==t?void 0:t.page)||1,(null==t?void 0:t.perPage)||0,(null==t?void 0:t.totalItems)||0,e)}))},n.prototype.getRequest=function(t,e){return void 0===e&&(e={}),this.client.send("/api/logs/requests/"+encodeURIComponent(t),{method:"GET",params:e}).then((function(t){return new R(t)}))},n.prototype.getRequestsStats=function(t){return void 0===t&&(t={}),this.client.send("/api/logs/requests/stats",{method:"GET",params:t}).then((function(t){return t}))},n}(f),_=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.clientId="",e.eventSource=null,e.subscriptions={},e}return e(n,t),n.prototype.subscribe=function(t,e){var n;return i(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:if(!t)throw new Error("subscription must be set.");return this.subscriptions[t]&&(null===(n=this.eventSource)||void 0===n||n.removeEventListener(t,this.subscriptions[t])),this.subscriptions[t]=function(t){var n,i=t;try{n=JSON.parse(null==i?void 0:i.data)}catch(t){}e(n||{})},this.eventSource?[3,1]:(this.connect(),[3,3]);case 1:return this.clientId?[4,this.submitSubscriptions()]:[3,3];case 2:i.sent(),i.label=3;case 3:return[2]}}))}))},n.prototype.unsubscribe=function(t){var e;return i(this,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:if(t){if(!this.subscriptions[t])return[2];null===(e=this.eventSource)||void 0===e||e.removeEventListener(t,this.subscriptions[t]),delete this.subscriptions[t]}else this.removeSubscriptionListeners(),this.subscriptions={};return this.clientId?[4,this.submitSubscriptions()]:[3,2];case 1:n.sent(),n.label=2;case 2:return Object.keys(this.subscriptions).length||this.disconnect(),[2]}}))}))},n.prototype.submitSubscriptions=function(){return i(this,void 0,void 0,(function(){return o(this,(function(t){return this.addSubscriptionListeners(),[2,this.client.send("/api/realtime",{method:"POST",body:{clientId:this.clientId,subscriptions:Object.keys(this.subscriptions)}}).then((function(){return!0}))]}))}))},n.prototype.addSubscriptionListeners=function(){if(this.eventSource)for(var t in this.removeSubscriptionListeners(),this.subscriptions)this.eventSource.addEventListener(t,this.subscriptions[t])},n.prototype.removeSubscriptionListeners=function(){if(this.eventSource)for(var t in this.subscriptions)this.eventSource.removeEventListener(t,this.subscriptions[t])},n.prototype.connectHandler=function(t){var e=t;this.clientId=null==e?void 0:e.lastEventId,this.submitSubscriptions()},n.prototype.connect=function(){var t=this;this.disconnect(),this.eventSource=new EventSource(this.client.buildUrl("/api/realtime")),this.eventSource.addEventListener("PB_CONNECT",(function(e){return t.connectHandler(e)}))},n.prototype.disconnect=function(){var t,e,n=this;this.removeSubscriptionListeners(),null===(t=this.eventSource)||void 0===t||t.removeEventListener("PB_CONNECT",(function(t){return n.connectHandler(t)})),null===(e=this.eventSource)||void 0===e||e.close(),this.eventSource=null,this.clientId=""},n}(f),k=function(){function t(t,e,n){void 0===t&&(t="/"),void 0===e&&(e="en-US"),this.cancelControllers={},this.baseUrl=t,this.lang=e,this.authStore=n||new p,this.admins=new g(this),this.users=new w(this),this.records=new O(this),this.collections=new P(this),this.logs=new j(this),this.settings=new v(this),this.realtime=new _(this)}return Object.defineProperty(t.prototype,"AuthStore",{get:function(){return this.authStore},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Settings",{get:function(){return this.settings},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Admins",{get:function(){return this.admins},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Users",{get:function(){return this.users},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Collections",{get:function(){return this.collections},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Records",{get:function(){return this.records},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Logs",{get:function(){return this.logs},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Realtime",{get:function(){return this.realtime},enumerable:!1,configurable:!0}),t.prototype.cancelRequest=function(t){return this.cancelControllers[t]&&(this.cancelControllers[t].abort(),delete this.cancelControllers[t]),this},t.prototype.cancelAllRequests=function(){for(var t in this.cancelControllers)this.cancelControllers[t].abort();return this.cancelControllers={},this},t.prototype.send=function(t,e){var n,r,u,a,l,c,h,d,p;return i(this,void 0,void 0,(function(){var f,v,y,b,m,g,w=this;return o(this,(function(S){return(f=Object.assign({method:"GET"},e)).body&&"FormData"!==f.body.constructor.name&&("string"!=typeof f.body&&(f.body=JSON.stringify(f.body)),void 0===(null===(n=null==f?void 0:f.headers)||void 0===n?void 0:n["Content-Type"])&&(f.headers=Object.assign({},f.headers,{"Content-Type":"application/json"}))),void 0===(null===(r=null==f?void 0:f.headers)||void 0===r?void 0:r["Accept-Language"])&&(f.headers=Object.assign({},f.headers,{"Accept-Language":this.lang})),(null===(u=this.authStore)||void 0===u?void 0:u.token)&&void 0===(null===(a=null==f?void 0:f.headers)||void 0===a?void 0:a.Authorization)&&(v="Admin",void 0!==(null===(l=this.authStore.model)||void 0===l?void 0:l.verified)&&(v="User"),f.headers=Object.assign({},f.headers,{Authorization:v+" "+this.authStore.token})),!1!==(null===(c=f.params)||void 0===c?void 0:c.$autoCancel)&&(y=(null===(h=f.params)||void 0===h?void 0:h.$cancelKey)||(f.method||"GET")+t,this.cancelRequest(y),b=new AbortController,this.cancelControllers[y]=b,f.signal=b.signal),null===(d=f.params)||void 0===d||delete d.$autoCancel,null===(p=f.params)||void 0===p||delete p.$cancelKey,m=this.buildUrl(t),void 0!==f.params&&((g=this.serializeQueryParams(f.params))&&(m+=(m.includes("?")?"&":"?")+g),delete f.params),this.beforeSend&&(f=Object.assign({},this.beforeSend(m,f))),[2,fetch(m,f).then((function(t){return i(w,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:e={},n.label=1;case 1:return n.trys.push([1,3,,4]),[4,t.json()];case 2:return e=n.sent(),[3,4];case 3:return n.sent(),[3,4];case 4:if(this.afterSend&&(e=this.afterSend(t,e)),t.status>=400)throw new s({url:t.url,status:t.status,data:e});return[2,e]}}))}))})).catch((function(t){if(t instanceof s)throw t;throw new s(t)}))]}))}))},t.prototype.buildUrl=function(t){var e=this.baseUrl+(this.baseUrl.endsWith("/")?"":"/");return t&&(e+=t.startsWith("/")?t.substring(1):t),e},t.prototype.serializeQueryParams=function(t){var e=[];for(var n in t)if(null!==t[n]){var i=t[n],o=encodeURIComponent(n);if(Array.isArray(i))for(var r=0,s=i;r<s.length;r++){var u=s[r];e.push(o+"="+encodeURIComponent(u))}else i instanceof Date?e.push(o+"="+encodeURIComponent(i.toISOString())):null!==typeof i&&"object"==typeof i?e.push(o+"="+encodeURIComponent(JSON.stringify(i))):e.push(o+"="+encodeURIComponent(i))}return e.join("&")},t}();module.exports=k;

@@ -67,2 +67,11 @@ declare abstract class BaseModel {

}
/**
* The minimal AuthStore interface.
*
* This interface predates the abstract BaseAuthStore class
* and it is kept mainly for backward compatibility.
*
* New AuthStore implementations should extend directly the
* BaseAuthStore abstract class.
*/
type AuthStore = {

@@ -478,15 +487,124 @@ /**

declare class Client {
/**
* The base PocketBase backend url address (eg. 'http://localhost.8090').
*/
baseUrl: string;
/**
* Hook that get triggered right before sending the fetch request,
* allowing you to inspect/modify the request config.
*
* Returns the new modified config that will be used to send the request.
*
* For list of the possible options check https://developer.mozilla.org/en-US/docs/Web/API/fetch#options
*
* Example:
* ```js
* client.beforeSend = function (url, reqConfig) {
* reqConfig.headers = Object.assign(reqConfig.headers, {
* 'X-Custom-Header': 'example',
* });
*
* return reqConfig;
* };
* ```
*/
beforeSend?: (url: string, reqConfig: {
[key: string]: any;
}) => {
[key: string]: any;
};
/**
* Hook that get triggered after successfully sending the fetch request,
* allowing you to inspect/modify the response object and its parsed data.
*
* Returns the new Promise resolved `data` that will be returned to the client.
*
* Example:
* ```js
* client.afterSend = function (response, data) {
* if (response.status != 200) {
* throw new ClientResponseError({
* url: response.url,
* status: response.status,
* data: data,
* });
* }
*
* return data;
* };
* ```
*/
afterSend?: (response: Response, data: any) => any;
/**
* Optional language code (default to `en-US`) that will be sent
* with the requests to the server as `Accept-Language` header.
*/
lang: string;
AuthStore: AuthStore;
readonly Settings: Settings;
readonly Admins: Admins;
readonly Users: Users;
readonly Collections: Collections;
readonly Records: Records;
readonly Logs: Logs;
readonly Realtime: Realtime;
/**
* A replacable instance of the local `AuthStore` service.
*/
authStore: AuthStore;
/**
* An instance of the service that handles the **Settings APIs**.
*/
readonly settings: Settings;
/**
* An instance of the service that handles the **Admin APIs**.
*/
readonly admins: Admins;
/**
* An instance of the service that handles the **User APIs**.
*/
readonly users: Users;
/**
* An instance of the service that handles the **Collection APIs**.
*/
readonly collections: Collections;
/**
* An instance of the service that handles the **Record APIs**.
*/
readonly records: Records;
/**
* An instance of the service that handles the **Log APIs**.
*/
readonly logs: Logs;
/**
* An instance of the service that handles the **Realtime APIs**.
*/
readonly realtime: Realtime;
private cancelControllers;
constructor(baseUrl?: string, lang?: string, authStore?: AuthStore | null);
/**
* @deprecated Legacy alias for `this.authStore`.
*/
get AuthStore(): AuthStore;
/**
* @deprecated Legacy alias for `this.settings`.
*/
get Settings(): Settings;
/**
* @deprecated Legacy alias for `this.admins`.
*/
get Admins(): Admins;
/**
* @deprecated Legacy alias for `this.users`.
*/
get Users(): Users;
/**
* @deprecated Legacy alias for `this.collections`.
*/
get Collections(): Collections;
/**
* @deprecated Legacy alias for `this.records`.
*/
get Records(): Records;
/**
* @deprecated Legacy alias for `this.logs`.
*/
get Logs(): Logs;
/**
* @deprecated Legacy alias for `this.realtime`.
*/
get Realtime(): Realtime;
/**
* Cancels single request by its cancellation key.

@@ -532,6 +650,42 @@ */

/**
* Default token store for browsers with auto fallback
* to runtime/memory if local storage is undefined (eg. node env).
* Base AuthStore class that is intented to be extended by all other
* PocketBase AuthStore implementations.
*/
declare class LocalAuthStore implements AuthStore {
declare abstract class BaseAuthStore implements AuthStore {
protected baseToken: string;
protected baseModel: User | Admin | {};
private _onChangeCallbacks;
/**
* Retrieves the stored token (if any).
*/
get token(): string;
/**
* Retrieves the stored model data (if any).
*/
get model(): User | Admin | {};
/**
* Checks if the store has valid (aka. existing and unexpired) token.
*/
get isValid(): boolean;
/**
* Saves the provided new token and model data in the auth store.
*/
save(token: string, model: User | Admin | {}): void;
/**
* Removes the stored token and model data form the auth store.
*/
clear(): void;
/**
* Register a callback function that will be called on store change.
*
* Returns a removal function that you could call to "unsubscibe" from the changes.
*/
onChange(callback: () => void): () => void;
private _triggerChange;
}
/**
* The default token store for browsers with auto fallback
* to runtime/memory if local storage is undefined (eg. in node env).
*/
declare class LocalAuthStore extends BaseAuthStore {
private fallback;

@@ -551,6 +705,2 @@ private storageKey;

*/
get isValid(): boolean;
/**
* @inheritdoc
*/
save(token: string, model: User | Admin | {}): void;

@@ -579,2 +729,2 @@ /**

}
export { Client as default, ClientResponseError, LocalAuthStore, User, Admin, Collection, Record, LogRequest, SchemaField };
export { Client as default, ClientResponseError, BaseAuthStore, LocalAuthStore, User, Admin, Collection, Record, LogRequest, SchemaField };

@@ -67,2 +67,11 @@ declare abstract class BaseModel {

}
/**
* The minimal AuthStore interface.
*
* This interface predates the abstract BaseAuthStore class
* and it is kept mainly for backward compatibility.
*
* New AuthStore implementations should extend directly the
* BaseAuthStore abstract class.
*/
type AuthStore = {

@@ -478,15 +487,124 @@ /**

declare class Client {
/**
* The base PocketBase backend url address (eg. 'http://localhost.8090').
*/
baseUrl: string;
/**
* Hook that get triggered right before sending the fetch request,
* allowing you to inspect/modify the request config.
*
* Returns the new modified config that will be used to send the request.
*
* For list of the possible options check https://developer.mozilla.org/en-US/docs/Web/API/fetch#options
*
* Example:
* ```js
* client.beforeSend = function (url, reqConfig) {
* reqConfig.headers = Object.assign(reqConfig.headers, {
* 'X-Custom-Header': 'example',
* });
*
* return reqConfig;
* };
* ```
*/
beforeSend?: (url: string, reqConfig: {
[key: string]: any;
}) => {
[key: string]: any;
};
/**
* Hook that get triggered after successfully sending the fetch request,
* allowing you to inspect/modify the response object and its parsed data.
*
* Returns the new Promise resolved `data` that will be returned to the client.
*
* Example:
* ```js
* client.afterSend = function (response, data) {
* if (response.status != 200) {
* throw new ClientResponseError({
* url: response.url,
* status: response.status,
* data: data,
* });
* }
*
* return data;
* };
* ```
*/
afterSend?: (response: Response, data: any) => any;
/**
* Optional language code (default to `en-US`) that will be sent
* with the requests to the server as `Accept-Language` header.
*/
lang: string;
AuthStore: AuthStore;
readonly Settings: Settings;
readonly Admins: Admins;
readonly Users: Users;
readonly Collections: Collections;
readonly Records: Records;
readonly Logs: Logs;
readonly Realtime: Realtime;
/**
* A replacable instance of the local `AuthStore` service.
*/
authStore: AuthStore;
/**
* An instance of the service that handles the **Settings APIs**.
*/
readonly settings: Settings;
/**
* An instance of the service that handles the **Admin APIs**.
*/
readonly admins: Admins;
/**
* An instance of the service that handles the **User APIs**.
*/
readonly users: Users;
/**
* An instance of the service that handles the **Collection APIs**.
*/
readonly collections: Collections;
/**
* An instance of the service that handles the **Record APIs**.
*/
readonly records: Records;
/**
* An instance of the service that handles the **Log APIs**.
*/
readonly logs: Logs;
/**
* An instance of the service that handles the **Realtime APIs**.
*/
readonly realtime: Realtime;
private cancelControllers;
constructor(baseUrl?: string, lang?: string, authStore?: AuthStore | null);
/**
* @deprecated Legacy alias for `this.authStore`.
*/
get AuthStore(): AuthStore;
/**
* @deprecated Legacy alias for `this.settings`.
*/
get Settings(): Settings;
/**
* @deprecated Legacy alias for `this.admins`.
*/
get Admins(): Admins;
/**
* @deprecated Legacy alias for `this.users`.
*/
get Users(): Users;
/**
* @deprecated Legacy alias for `this.collections`.
*/
get Collections(): Collections;
/**
* @deprecated Legacy alias for `this.records`.
*/
get Records(): Records;
/**
* @deprecated Legacy alias for `this.logs`.
*/
get Logs(): Logs;
/**
* @deprecated Legacy alias for `this.realtime`.
*/
get Realtime(): Realtime;
/**
* Cancels single request by its cancellation key.

@@ -493,0 +611,0 @@ */

@@ -1,1 +0,1 @@

var PocketBase=function(){"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}var n=function(){return n=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function i(t,e,n,i){return new(n||(n=Promise))((function(o,r){function s(t){try{a(i.next(t))}catch(t){r(t)}}function u(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}a((i=i.apply(t,e||[])).next())}))}function o(t,e){var n,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function u(r){return function(u){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){s.label=r[1];break}if(6===r[0]&&s.label<o[1]){s.label=o[1],o=r;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(r);break}o[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(t){r=[6,t],i=0}finally{n=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,u])}}}var r,s=function(t){function i(e){var n,i=this;return(i=t.call(this,"ClientResponseError")||this).url="",i.status=0,i.data={},i.isAbort=!1,i.originalError=null,e instanceof Error&&!(e instanceof i.constructor)&&(i.originalError=e),null!==e&&"object"==typeof e&&(i.url="string"==typeof e.url?e.url:"",i.status="number"==typeof e.status?e.status:0,i.data=null!==e.data&&"object"==typeof e.data?e.data:{}),"undefined"!=typeof DOMException&&e instanceof DOMException&&(i.isAbort=!0),i.name="ClientResponseError "+i.status,i.message=(null===(n=i.data)||void 0===n?void 0:n.message)||"Something went wrong while processing your request.",i}return e(i,t),i.prototype.toJSON=function(){return n({},this)},i}(Error);r="function"==typeof atob?atob:function(t){return Buffer.from(t,"base64").toString("binary")};var u=function(){function t(){}return t.getPayload=function(t){if(t)try{var e=decodeURIComponent(r(t.split(".")[1]).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(e)||{}}catch(t){}return{}},t.isExpired=function(e,n){void 0===n&&(n=0);var i=t.getPayload(e);return!(Object.keys(i).length>0&&(!i.exp||i.exp-n>Date.now()/1e3))},t}(),a=function(){function t(t){void 0===t&&(t={}),this.load(t||{})}return t.prototype.load=function(t){this.id=void 0!==t.id?t.id:"",this.created=void 0!==t.created?t.created:"",this.updated=void 0!==t.updated?t.updated:""},Object.defineProperty(t.prototype,"isNew",{get:function(){return!this.id||"00000000-0000-0000-0000-000000000000"===this.id},enumerable:!1,configurable:!0}),t.prototype.clone=function(){return new this.constructor(JSON.parse(JSON.stringify(this)))},t.prototype.export=function(){return Object.assign({},this)},t}(),l=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e);for(var n=0,i=Object.entries(e);n<i.length;n++){var o=i[n],r=o[0],s=o[1];this[r]=s}this["@collectionId"]=void 0!==e["@collectionId"]?e["@collectionId"]:"",this["@collectionName"]=void 0!==e["@collectionName"]?e["@collectionName"]:"",this["@expand"]=void 0!==e["@expand"]?e["@expand"]:{}},n}(a),c=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.email="string"==typeof e.email?e.email:"",this.verified=!!e.verified,this.lastResetSentAt="string"==typeof e.lastResetSentAt?e.lastResetSentAt:"",this.lastVerificationSentAt="string"==typeof e.lastVerificationSentAt?e.lastVerificationSentAt:"",this.profile=e.profile?new l(e.profile):null},n}(a),d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.avatar="number"==typeof e.avatar?e.avatar:0,this.email="string"==typeof e.email?e.email:"",this.lastResetSentAt="string"==typeof e.lastResetSentAt?e.lastResetSentAt:""},n}(a),h=function(){function t(t){void 0===t&&(t="pocketbase_auth"),this.fallback={},this.storageKey=t}return Object.defineProperty(t.prototype,"token",{get:function(){return(this._storageGet(this.storageKey)||{}).token||""},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"model",{get:function(){var t,e=this._storageGet(this.storageKey)||{};return null===e||"object"!=typeof e||null===e.model||"object"!=typeof e.model?{}:void 0!==(null===(t=e.model)||void 0===t?void 0:t.verified)?new c(e.model):new d(e.model)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isValid",{get:function(){return!u.isExpired(this.token)},enumerable:!1,configurable:!0}),t.prototype.save=function(t,e){this._storageSet(this.storageKey,{token:t,model:e})},t.prototype.clear=function(){return this._storageRemove(this.storageKey)},t.prototype._storageGet=function(t){var e;if("undefined"!=typeof window&&(null===window||void 0===window?void 0:window.localStorage)){var n=(null===(e=null===window||void 0===window?void 0:window.localStorage)||void 0===e?void 0:e.getItem(t))||"";try{return JSON.parse(n)}catch(t){return n}}return this.fallback[t]},t.prototype._storageSet=function(t,e){var n;if("undefined"!=typeof window&&(null===window||void 0===window?void 0:window.localStorage)){var i=e;"string"!=typeof e&&(i=JSON.stringify(e)),null===(n=null===window||void 0===window?void 0:window.localStorage)||void 0===n||n.setItem(t,i)}else this.fallback[t]=e},t.prototype._storageRemove=function(t){var e;"undefined"!=typeof window&&(null===(e=null===window||void 0===window?void 0:window.localStorage)||void 0===e||e.removeItem(t)),delete this.fallback[t]},t}(),p=function(t){this.client=t},f=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getAll=function(t){return void 0===t&&(t={}),this.client.send("/api/settings",{method:"GET",params:t}).then((function(t){return t||{}}))},n.prototype.update=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send("/api/settings",{method:"PATCH",params:e,body:t}).then((function(t){return t||{}}))},n}(p),v=function(t,e,n,i){this.page=t>0?t:1,this.perPage=e>=0?e:0,this.totalItems=n>=0?n:0,this.items=i||[]},y=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype._getFullList=function(t,e,n){var r=this;void 0===e&&(e=100),void 0===n&&(n={});var s=[],u=function(a){return i(r,void 0,void 0,(function(){return o(this,(function(i){return[2,this._getList(t,a,e,n).then((function(t){var e=t,n=e.items,i=e.totalItems;return s=s.concat(n),n.length&&i>s.length?u(a+1):s}))]}))}))};return u(1)},n.prototype._getList=function(t,e,n,i){var o=this;return void 0===e&&(e=1),void 0===n&&(n=30),void 0===i&&(i={}),i=Object.assign({page:e,perPage:n},i),this.client.send(t,{method:"GET",params:i}).then((function(t){var e=[];if(null==t?void 0:t.items){t.items=t.items||[];for(var n=0,i=t.items;n<i.length;n++){var r=i[n];e.push(o.decode(r))}}return new v((null==t?void 0:t.page)||1,(null==t?void 0:t.perPage)||0,(null==t?void 0:t.totalItems)||0,e)}))},n.prototype._getOne=function(t,e,n){var i=this;return void 0===n&&(n={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"GET",params:n}).then((function(t){return i.decode(t)}))},n.prototype._create=function(t,e,n){var i=this;return void 0===e&&(e={}),void 0===n&&(n={}),this.client.send(t,{method:"POST",params:n,body:e}).then((function(t){return i.decode(t)}))},n.prototype._update=function(t,e,n,i){var o=this;return void 0===n&&(n={}),void 0===i&&(i={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"PATCH",params:i,body:n}).then((function(t){return o.decode(t)}))},n.prototype._delete=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"DELETE",params:i,body:n}).then((function(){return!0}))},n}(p),m=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getFullList=function(t,e){return void 0===t&&(t=100),void 0===e&&(e={}),this._getFullList(this.baseCrudPath(),t,e)},n.prototype.getList=function(t,e,n){return void 0===t&&(t=1),void 0===e&&(e=30),void 0===n&&(n={}),this._getList(this.baseCrudPath(),t,e,n)},n.prototype.getOne=function(t,e){return void 0===e&&(e={}),this._getOne(this.baseCrudPath(),t,e)},n.prototype.create=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this._create(this.baseCrudPath(),t,e)},n.prototype.update=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._update(this.baseCrudPath(),t,e,n)},n.prototype.delete=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._delete(this.baseCrudPath(),t,e,n)},n}(y),b=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new d(t)},n.prototype.baseCrudPath=function(){return"/api/admins"},n.prototype.authResponse=function(t){var e=this.decode((null==t?void 0:t.admin)||{});return(null==t?void 0:t.token)&&(null==t?void 0:t.admin)&&this.client.AuthStore.save(t.token,e),Object.assign({},t,{token:(null==t?void 0:t.token)||"",admin:e})},n.prototype.authViaEmail=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({email:t,password:e},n),this.client.send(this.baseCrudPath()+"/auth-via-email",{method:"POST",params:i,body:n,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.refresh=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send(this.baseCrudPath()+"/refresh",{method:"POST",params:e,body:t}).then(this.authResponse.bind(this))},n.prototype.requestPasswordReset=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-password-reset",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmPasswordReset=function(t,e,n,i,o){return void 0===i&&(i={}),void 0===o&&(o={}),i=Object.assign({token:t,password:e,passwordConfirm:n},i),this.client.send(this.baseCrudPath()+"/confirm-password-reset",{method:"POST",params:o,body:i}).then(this.authResponse.bind(this))},n}(m),g=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new c(t)},n.prototype.baseCrudPath=function(){return"/api/users"},n.prototype.authResponse=function(t){var e=this.decode((null==t?void 0:t.user)||{});return(null==t?void 0:t.token)&&(null==t?void 0:t.user)&&this.client.AuthStore.save(t.token,e),Object.assign({},t,{token:(null==t?void 0:t.token)||"",user:e})},n.prototype.listAuthMethods=function(t){return void 0===t&&(t={}),this.client.send(this.baseCrudPath()+"/auth-methods",{method:"GET",params:t}).then((function(t){return Object.assign({},t,{emailPassword:!!(null==t?void 0:t.emailPassword),authProviders:Array.isArray(null==t?void 0:t.authProviders)?null==t?void 0:t.authProviders:[]})}))},n.prototype.authViaEmail=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({email:t,password:e},n),this.client.send(this.baseCrudPath()+"/auth-via-email",{method:"POST",params:i,body:n,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.authViaOAuth2=function(t,e,n,i,o,r){return void 0===o&&(o={}),void 0===r&&(r={}),o=Object.assign({provider:t,code:e,codeVerifier:n,redirectUrl:i},o),this.client.send(this.baseCrudPath()+"/auth-via-oauth2",{method:"POST",params:r,body:o,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.refresh=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send(this.baseCrudPath()+"/refresh",{method:"POST",params:e,body:t}).then(this.authResponse.bind(this))},n.prototype.requestPasswordReset=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-password-reset",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmPasswordReset=function(t,e,n,i,o){return void 0===i&&(i={}),void 0===o&&(o={}),i=Object.assign({token:t,password:e,passwordConfirm:n},i),this.client.send(this.baseCrudPath()+"/confirm-password-reset",{method:"POST",params:o,body:i}).then(this.authResponse.bind(this))},n.prototype.requestVerification=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-verification",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmVerification=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({token:t},e),this.client.send(this.baseCrudPath()+"/confirm-verification",{method:"POST",params:n,body:e}).then(this.authResponse.bind(this))},n.prototype.requestEmailChange=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({newEmail:t},e),this.client.send(this.baseCrudPath()+"/request-email-change",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmEmailChange=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({token:t,password:e},n),this.client.send(this.baseCrudPath()+"/confirm-email-change",{method:"POST",params:i,body:n}).then(this.authResponse.bind(this))},n}(m),w=function(){function t(t){void 0===t&&(t={}),this.load(t||{})}return t.prototype.load=function(t){this.id=void 0!==t.id?t.id:"",this.name=void 0!==t.name?t.name:"",this.type=void 0!==t.type?t.type:"text",this.system=!!t.system,this.required=!!t.required,this.unique=!!t.unique,this.options="object"==typeof t.options&&null!==t.options?t.options:{}},t}(),S=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.name="string"==typeof e.name?e.name:"",this.system=!!e.system,this.listRule="string"==typeof e.listRule?e.listRule:null,this.viewRule="string"==typeof e.viewRule?e.viewRule:null,this.createRule="string"==typeof e.createRule?e.createRule:null,this.updateRule="string"==typeof e.updateRule?e.updateRule:null,this.deleteRule="string"==typeof e.deleteRule?e.deleteRule:null,e.schema=Array.isArray(e.schema)?e.schema:[],this.schema=[];for(var n=0,i=e.schema;n<i.length;n++){var o=i[n];this.schema.push(new w(o))}},n}(a),P=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new S(t)},n.prototype.baseCrudPath=function(){return"/api/collections"},n}(m),O=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getFullList=function(t,e,n){return void 0===e&&(e=100),void 0===n&&(n={}),this._getFullList(this.baseCrudPath(t),e,n)},n.prototype.getList=function(t,e,n,i){return void 0===e&&(e=1),void 0===n&&(n=30),void 0===i&&(i={}),this._getList(this.baseCrudPath(t),e,n,i)},n.prototype.getOne=function(t,e,n){return void 0===n&&(n={}),this._getOne(this.baseCrudPath(t),e,n)},n.prototype.create=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._create(this.baseCrudPath(t),e,n)},n.prototype.update=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this._update(this.baseCrudPath(t),e,n,i)},n.prototype.delete=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this._delete(this.baseCrudPath(t),e,n,i)},n}(y),C=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new l(t)},n.prototype.baseCrudPath=function(t){return"/api/collections/"+encodeURIComponent(t)+"/records"},n.prototype.getFileUrl=function(t,e,n){void 0===n&&(n={});var i=[];i.push(this.client.baseUrl.replace(/\/+$/gm,"")),i.push("api"),i.push("files"),i.push(t["@collectionId"]),i.push(t.id),i.push(e);var o=i.join("/");if(Object.keys(n).length){var r=new URLSearchParams(n);o+=(o.includes("?")?"&":"?")+r}return o},n}(O),R=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.url="string"==typeof e.url?e.url:"",this.method="string"==typeof e.method?e.method:"GET",this.status="number"==typeof e.status?e.status:200,this.auth="string"==typeof e.auth?e.auth:"guest",this.ip="string"==typeof e.ip?e.ip:"",this.referer="string"==typeof e.referer?e.referer:"",this.userAgent="string"==typeof e.userAgent?e.userAgent:"",this.meta="object"==typeof e.meta&&null!==e.meta?e.meta:{}},n}(a),j=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getRequestsList=function(t,e,n){return void 0===t&&(t=1),void 0===e&&(e=30),void 0===n&&(n={}),n=Object.assign({page:t,perPage:e},n),this.client.send("/api/logs/requests",{method:"GET",params:n}).then((function(t){var e=[];if(null==t?void 0:t.items){t.items=(null==t?void 0:t.items)||[];for(var n=0,i=t.items;n<i.length;n++){var o=i[n];e.push(new R(o))}}return new v((null==t?void 0:t.page)||1,(null==t?void 0:t.perPage)||0,(null==t?void 0:t.totalItems)||0,e)}))},n.prototype.getRequest=function(t,e){return void 0===e&&(e={}),this.client.send("/api/logs/requests/"+encodeURIComponent(t),{method:"GET",params:e}).then((function(t){return new R(t)}))},n.prototype.getRequestsStats=function(t){return void 0===t&&(t={}),this.client.send("/api/logs/requests/stats",{method:"GET",params:t}).then((function(t){return t}))},n}(p),A=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.clientId="",e.eventSource=null,e.subscriptions={},e}return e(n,t),n.prototype.subscribe=function(t,e){var n;return i(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:if(!t)throw new Error("subscription must be set.");return this.subscriptions[t]&&(null===(n=this.eventSource)||void 0===n||n.removeEventListener(t,this.subscriptions[t])),this.subscriptions[t]=function(t){var n,i=t;try{n=JSON.parse(null==i?void 0:i.data)}catch(t){}e(n||{})},this.eventSource?[3,1]:(this.connect(),[3,3]);case 1:return this.clientId?[4,this.submitSubscriptions()]:[3,3];case 2:i.sent(),i.label=3;case 3:return[2]}}))}))},n.prototype.unsubscribe=function(t){var e;return i(this,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:if(t){if(!this.subscriptions[t])return[2];null===(e=this.eventSource)||void 0===e||e.removeEventListener(t,this.subscriptions[t]),delete this.subscriptions[t]}else this.removeSubscriptionListeners(),this.subscriptions={};return this.clientId?[4,this.submitSubscriptions()]:[3,2];case 1:n.sent(),n.label=2;case 2:return Object.keys(this.subscriptions).length||this.disconnect(),[2]}}))}))},n.prototype.submitSubscriptions=function(){return i(this,void 0,void 0,(function(){return o(this,(function(t){return this.addSubscriptionListeners(),[2,this.client.send("/api/realtime",{method:"POST",body:{clientId:this.clientId,subscriptions:Object.keys(this.subscriptions)}}).then((function(){return!0}))]}))}))},n.prototype.addSubscriptionListeners=function(){if(this.eventSource)for(var t in this.removeSubscriptionListeners(),this.subscriptions)this.eventSource.addEventListener(t,this.subscriptions[t])},n.prototype.removeSubscriptionListeners=function(){if(this.eventSource)for(var t in this.subscriptions)this.eventSource.removeEventListener(t,this.subscriptions[t])},n.prototype.connectHandler=function(t){var e=t;this.clientId=null==e?void 0:e.lastEventId,this.submitSubscriptions()},n.prototype.connect=function(){var t=this;this.disconnect(),this.eventSource=new EventSource(this.client.buildUrl("/api/realtime")),this.eventSource.addEventListener("PB_CONNECT",(function(e){return t.connectHandler(e)}))},n.prototype.disconnect=function(){var t,e,n=this;this.removeSubscriptionListeners(),null===(t=this.eventSource)||void 0===t||t.removeEventListener("PB_CONNECT",(function(t){return n.connectHandler(t)})),null===(e=this.eventSource)||void 0===e||e.close(),this.eventSource=null,this.clientId=""},n}(p);return function(){function t(t,e,n){void 0===t&&(t="/"),void 0===e&&(e="en-US"),this.cancelControllers={},this.baseUrl=t,this.lang=e,this.AuthStore=n||new h,this.Settings=new f(this),this.Admins=new b(this),this.Users=new g(this),this.Collections=new P(this),this.Records=new C(this),this.Logs=new j(this),this.Realtime=new A(this)}return t.prototype.cancelRequest=function(t){return this.cancelControllers[t]&&(this.cancelControllers[t].abort(),delete this.cancelControllers[t]),this},t.prototype.cancelAllRequests=function(){for(var t in this.cancelControllers)this.cancelControllers[t].abort();return this.cancelControllers={},this},t.prototype.send=function(t,e){var n,r,u,a,l,c,d,h,p,f=this,v=Object.assign({method:"GET"},e);if(v.body&&"FormData"!==v.body.constructor.name&&("string"!=typeof v.body&&(v.body=JSON.stringify(v.body)),void 0===(null===(n=null==v?void 0:v.headers)||void 0===n?void 0:n["Content-Type"])&&(v.headers=Object.assign({},v.headers,{"Content-Type":"application/json"}))),void 0===(null===(r=null==v?void 0:v.headers)||void 0===r?void 0:r["Accept-Language"])&&(v.headers=Object.assign({},v.headers,{"Accept-Language":this.lang})),(null===(u=this.AuthStore)||void 0===u?void 0:u.token)&&void 0===(null===(a=null==v?void 0:v.headers)||void 0===a?void 0:a.Authorization)){var y="Admin";void 0!==(null===(l=this.AuthStore.model)||void 0===l?void 0:l.verified)&&(y="User"),v.headers=Object.assign({},v.headers,{Authorization:y+" "+this.AuthStore.token})}if(!1!==(null===(c=v.params)||void 0===c?void 0:c.$autoCancel)){var m=(null===(d=v.params)||void 0===d?void 0:d.$cancelKey)||(v.method||"GET")+t;this.cancelRequest(m);var b=new AbortController;this.cancelControllers[m]=b,v.signal=b.signal}null===(h=v.params)||void 0===h||delete h.$autoCancel,null===(p=v.params)||void 0===p||delete p.$cancelKey;var g=this.buildUrl(t);if(void 0!==v.params){var w=this.serializeQueryParams(v.params);w&&(g+=(g.includes("?")?"&":"?")+w),delete v.params}return fetch(g,v).then((function(t){return i(f,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:e={},n.label=1;case 1:return n.trys.push([1,3,,4]),[4,t.json()];case 2:return e=n.sent(),[3,4];case 3:return n.sent(),[3,4];case 4:if(t.status>=400)throw new s({url:t.url,status:t.status,data:e});return[2,e]}}))}))})).catch((function(t){if(t instanceof s)throw t;throw new s(t)}))},t.prototype.buildUrl=function(t){var e=this.baseUrl+(this.baseUrl.endsWith("/")?"":"/");return t&&(e+=t.startsWith("/")?t.substring(1):t),e},t.prototype.serializeQueryParams=function(t){var e=[];for(var n in t)if(null!==t[n]){var i=t[n],o=encodeURIComponent(n);if(Array.isArray(i))for(var r=0,s=i;r<s.length;r++){var u=s[r];e.push(o+"="+encodeURIComponent(u))}else i instanceof Date?e.push(o+"="+encodeURIComponent(i.toISOString())):null!==typeof i&&"object"==typeof i?e.push(o+"="+encodeURIComponent(JSON.stringify(i))):e.push(o+"="+encodeURIComponent(i))}return e.join("&")},t}()}();
var PocketBase=function(){"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}var n=function(){return n=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function i(t,e,n,i){return new(n||(n=Promise))((function(o,r){function s(t){try{a(i.next(t))}catch(t){r(t)}}function u(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}a((i=i.apply(t,e||[])).next())}))}function o(t,e){var n,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function u(r){return function(u){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){s.label=r[1];break}if(6===r[0]&&s.label<o[1]){s.label=o[1],o=r;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(r);break}o[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(t){r=[6,t],i=0}finally{n=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,u])}}}var r,s=function(t){function i(e){var n,i=this;return(i=t.call(this,"ClientResponseError")||this).url="",i.status=0,i.data={},i.isAbort=!1,i.originalError=null,e instanceof Error&&!(e instanceof i.constructor)&&(i.originalError=e),null!==e&&"object"==typeof e&&(i.url="string"==typeof e.url?e.url:"",i.status="number"==typeof e.status?e.status:0,i.data=null!==e.data&&"object"==typeof e.data?e.data:{}),"undefined"!=typeof DOMException&&e instanceof DOMException&&(i.isAbort=!0),i.name="ClientResponseError "+i.status,i.message=(null===(n=i.data)||void 0===n?void 0:n.message)||"Something went wrong while processing your request.",i}return e(i,t),i.prototype.toJSON=function(){return n({},this)},i}(Error);r="function"==typeof atob?atob:function(t){return Buffer.from(t,"base64").toString("binary")};var u=function(){function t(){}return t.getPayload=function(t){if(t)try{var e=decodeURIComponent(r(t.split(".")[1]).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(e)||{}}catch(t){}return{}},t.isExpired=function(e,n){void 0===n&&(n=0);var i=t.getPayload(e);return!(Object.keys(i).length>0&&(!i.exp||i.exp-n>Date.now()/1e3))},t}(),a=function(){function t(){this.baseToken="",this.baseModel={},this._onChangeCallbacks=[]}return Object.defineProperty(t.prototype,"token",{get:function(){return this.baseToken},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"model",{get:function(){return this.baseModel},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isValid",{get:function(){return!u.isExpired(this.token)},enumerable:!1,configurable:!0}),t.prototype.save=function(t,e){this.baseToken=t,this.baseModel=e,this._triggerChange()},t.prototype.clear=function(){this._triggerChange()},t.prototype.onChange=function(t){var e=this;return this._onChangeCallbacks.push(t),function(){for(var n=e._onChangeCallbacks.length-1;n>=0;n--)if(e._onChangeCallbacks[n]==t)return delete e._onChangeCallbacks[n],void e._onChangeCallbacks.splice(n,1)}},t.prototype._triggerChange=function(){for(var t=0,e=this._onChangeCallbacks;t<e.length;t++){var n=e[t];n&&n(this.token,this.model)}},t}(),l=function(){function t(t){void 0===t&&(t={}),this.load(t||{})}return t.prototype.load=function(t){this.id=void 0!==t.id?t.id:"",this.created=void 0!==t.created?t.created:"",this.updated=void 0!==t.updated?t.updated:""},Object.defineProperty(t.prototype,"isNew",{get:function(){return!this.id||"00000000-0000-0000-0000-000000000000"===this.id},enumerable:!1,configurable:!0}),t.prototype.clone=function(){return new this.constructor(JSON.parse(JSON.stringify(this)))},t.prototype.export=function(){return Object.assign({},this)},t}(),c=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e);for(var n=0,i=Object.entries(e);n<i.length;n++){var o=i[n],r=o[0],s=o[1];this[r]=s}this["@collectionId"]=void 0!==e["@collectionId"]?e["@collectionId"]:"",this["@collectionName"]=void 0!==e["@collectionName"]?e["@collectionName"]:"",this["@expand"]=void 0!==e["@expand"]?e["@expand"]:{}},n}(l),h=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.email="string"==typeof e.email?e.email:"",this.verified=!!e.verified,this.lastResetSentAt="string"==typeof e.lastResetSentAt?e.lastResetSentAt:"",this.lastVerificationSentAt="string"==typeof e.lastVerificationSentAt?e.lastVerificationSentAt:"",this.profile=e.profile?new c(e.profile):null},n}(l),d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.avatar="number"==typeof e.avatar?e.avatar:0,this.email="string"==typeof e.email?e.email:"",this.lastResetSentAt="string"==typeof e.lastResetSentAt?e.lastResetSentAt:""},n}(l),p=function(t){function n(e){void 0===e&&(e="pocketbase_auth");var n=t.call(this)||this;return n.fallback={},n.storageKey=e,n}return e(n,t),Object.defineProperty(n.prototype,"token",{get:function(){return(this._storageGet(this.storageKey)||{}).token||""},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"model",{get:function(){var t,e=this._storageGet(this.storageKey)||{};return null===e||"object"!=typeof e||null===e.model||"object"!=typeof e.model?{}:void 0!==(null===(t=e.model)||void 0===t?void 0:t.verified)?new h(e.model):new d(e.model)},enumerable:!1,configurable:!0}),n.prototype.save=function(e,n){this._storageSet(this.storageKey,{token:e,model:n}),t.prototype.save.call(this,e,n)},n.prototype.clear=function(){this._storageRemove(this.storageKey),t.prototype.clear.call(this)},n.prototype._storageGet=function(t){var e;if("undefined"!=typeof window&&(null===window||void 0===window?void 0:window.localStorage)){var n=(null===(e=null===window||void 0===window?void 0:window.localStorage)||void 0===e?void 0:e.getItem(t))||"";try{return JSON.parse(n)}catch(t){return n}}return this.fallback[t]},n.prototype._storageSet=function(t,e){var n;if("undefined"!=typeof window&&(null===window||void 0===window?void 0:window.localStorage)){var i=e;"string"!=typeof e&&(i=JSON.stringify(e)),null===(n=null===window||void 0===window?void 0:window.localStorage)||void 0===n||n.setItem(t,i)}else this.fallback[t]=e},n.prototype._storageRemove=function(t){var e;"undefined"!=typeof window&&(null===(e=null===window||void 0===window?void 0:window.localStorage)||void 0===e||e.removeItem(t)),delete this.fallback[t]},n}(a),f=function(t){this.client=t},v=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getAll=function(t){return void 0===t&&(t={}),this.client.send("/api/settings",{method:"GET",params:t}).then((function(t){return t||{}}))},n.prototype.update=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send("/api/settings",{method:"PATCH",params:e,body:t}).then((function(t){return t||{}}))},n}(f),y=function(t,e,n,i){this.page=t>0?t:1,this.perPage=e>=0?e:0,this.totalItems=n>=0?n:0,this.items=i||[]},b=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype._getFullList=function(t,e,n){var r=this;void 0===e&&(e=100),void 0===n&&(n={});var s=[],u=function(a){return i(r,void 0,void 0,(function(){return o(this,(function(i){return[2,this._getList(t,a,e,n).then((function(t){var e=t,n=e.items,i=e.totalItems;return s=s.concat(n),n.length&&i>s.length?u(a+1):s}))]}))}))};return u(1)},n.prototype._getList=function(t,e,n,i){var o=this;return void 0===e&&(e=1),void 0===n&&(n=30),void 0===i&&(i={}),i=Object.assign({page:e,perPage:n},i),this.client.send(t,{method:"GET",params:i}).then((function(t){var e=[];if(null==t?void 0:t.items){t.items=t.items||[];for(var n=0,i=t.items;n<i.length;n++){var r=i[n];e.push(o.decode(r))}}return new y((null==t?void 0:t.page)||1,(null==t?void 0:t.perPage)||0,(null==t?void 0:t.totalItems)||0,e)}))},n.prototype._getOne=function(t,e,n){var i=this;return void 0===n&&(n={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"GET",params:n}).then((function(t){return i.decode(t)}))},n.prototype._create=function(t,e,n){var i=this;return void 0===e&&(e={}),void 0===n&&(n={}),this.client.send(t,{method:"POST",params:n,body:e}).then((function(t){return i.decode(t)}))},n.prototype._update=function(t,e,n,i){var o=this;return void 0===n&&(n={}),void 0===i&&(i={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"PATCH",params:i,body:n}).then((function(t){return o.decode(t)}))},n.prototype._delete=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"DELETE",params:i,body:n}).then((function(){return!0}))},n}(f),m=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getFullList=function(t,e){return void 0===t&&(t=100),void 0===e&&(e={}),this._getFullList(this.baseCrudPath(),t,e)},n.prototype.getList=function(t,e,n){return void 0===t&&(t=1),void 0===e&&(e=30),void 0===n&&(n={}),this._getList(this.baseCrudPath(),t,e,n)},n.prototype.getOne=function(t,e){return void 0===e&&(e={}),this._getOne(this.baseCrudPath(),t,e)},n.prototype.create=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this._create(this.baseCrudPath(),t,e)},n.prototype.update=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._update(this.baseCrudPath(),t,e,n)},n.prototype.delete=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._delete(this.baseCrudPath(),t,e,n)},n}(b),g=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new d(t)},n.prototype.baseCrudPath=function(){return"/api/admins"},n.prototype.authResponse=function(t){var e=this.decode((null==t?void 0:t.admin)||{});return(null==t?void 0:t.token)&&(null==t?void 0:t.admin)&&this.client.authStore.save(t.token,e),Object.assign({},t,{token:(null==t?void 0:t.token)||"",admin:e})},n.prototype.authViaEmail=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({email:t,password:e},n),this.client.send(this.baseCrudPath()+"/auth-via-email",{method:"POST",params:i,body:n,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.refresh=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send(this.baseCrudPath()+"/refresh",{method:"POST",params:e,body:t}).then(this.authResponse.bind(this))},n.prototype.requestPasswordReset=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-password-reset",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmPasswordReset=function(t,e,n,i,o){return void 0===i&&(i={}),void 0===o&&(o={}),i=Object.assign({token:t,password:e,passwordConfirm:n},i),this.client.send(this.baseCrudPath()+"/confirm-password-reset",{method:"POST",params:o,body:i}).then(this.authResponse.bind(this))},n}(m),w=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new h(t)},n.prototype.baseCrudPath=function(){return"/api/users"},n.prototype.authResponse=function(t){var e=this.decode((null==t?void 0:t.user)||{});return(null==t?void 0:t.token)&&(null==t?void 0:t.user)&&this.client.authStore.save(t.token,e),Object.assign({},t,{token:(null==t?void 0:t.token)||"",user:e})},n.prototype.listAuthMethods=function(t){return void 0===t&&(t={}),this.client.send(this.baseCrudPath()+"/auth-methods",{method:"GET",params:t}).then((function(t){return Object.assign({},t,{emailPassword:!!(null==t?void 0:t.emailPassword),authProviders:Array.isArray(null==t?void 0:t.authProviders)?null==t?void 0:t.authProviders:[]})}))},n.prototype.authViaEmail=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({email:t,password:e},n),this.client.send(this.baseCrudPath()+"/auth-via-email",{method:"POST",params:i,body:n,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.authViaOAuth2=function(t,e,n,i,o,r){return void 0===o&&(o={}),void 0===r&&(r={}),o=Object.assign({provider:t,code:e,codeVerifier:n,redirectUrl:i},o),this.client.send(this.baseCrudPath()+"/auth-via-oauth2",{method:"POST",params:r,body:o,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.refresh=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send(this.baseCrudPath()+"/refresh",{method:"POST",params:e,body:t}).then(this.authResponse.bind(this))},n.prototype.requestPasswordReset=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-password-reset",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmPasswordReset=function(t,e,n,i,o){return void 0===i&&(i={}),void 0===o&&(o={}),i=Object.assign({token:t,password:e,passwordConfirm:n},i),this.client.send(this.baseCrudPath()+"/confirm-password-reset",{method:"POST",params:o,body:i}).then(this.authResponse.bind(this))},n.prototype.requestVerification=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-verification",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmVerification=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({token:t},e),this.client.send(this.baseCrudPath()+"/confirm-verification",{method:"POST",params:n,body:e}).then(this.authResponse.bind(this))},n.prototype.requestEmailChange=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({newEmail:t},e),this.client.send(this.baseCrudPath()+"/request-email-change",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmEmailChange=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({token:t,password:e},n),this.client.send(this.baseCrudPath()+"/confirm-email-change",{method:"POST",params:i,body:n}).then(this.authResponse.bind(this))},n}(m),S=function(){function t(t){void 0===t&&(t={}),this.load(t||{})}return t.prototype.load=function(t){this.id=void 0!==t.id?t.id:"",this.name=void 0!==t.name?t.name:"",this.type=void 0!==t.type?t.type:"text",this.system=!!t.system,this.required=!!t.required,this.unique=!!t.unique,this.options="object"==typeof t.options&&null!==t.options?t.options:{}},t}(),C=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.name="string"==typeof e.name?e.name:"",this.system=!!e.system,this.listRule="string"==typeof e.listRule?e.listRule:null,this.viewRule="string"==typeof e.viewRule?e.viewRule:null,this.createRule="string"==typeof e.createRule?e.createRule:null,this.updateRule="string"==typeof e.updateRule?e.updateRule:null,this.deleteRule="string"==typeof e.deleteRule?e.deleteRule:null,e.schema=Array.isArray(e.schema)?e.schema:[],this.schema=[];for(var n=0,i=e.schema;n<i.length;n++){var o=i[n];this.schema.push(new S(o))}},n}(l),P=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new C(t)},n.prototype.baseCrudPath=function(){return"/api/collections"},n}(m),O=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getFullList=function(t,e,n){return void 0===e&&(e=100),void 0===n&&(n={}),this._getFullList(this.baseCrudPath(t),e,n)},n.prototype.getList=function(t,e,n,i){return void 0===e&&(e=1),void 0===n&&(n=30),void 0===i&&(i={}),this._getList(this.baseCrudPath(t),e,n,i)},n.prototype.getOne=function(t,e,n){return void 0===n&&(n={}),this._getOne(this.baseCrudPath(t),e,n)},n.prototype.create=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._create(this.baseCrudPath(t),e,n)},n.prototype.update=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this._update(this.baseCrudPath(t),e,n,i)},n.prototype.delete=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this._delete(this.baseCrudPath(t),e,n,i)},n}(b),R=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new c(t)},n.prototype.baseCrudPath=function(t){return"/api/collections/"+encodeURIComponent(t)+"/records"},n.prototype.getFileUrl=function(t,e,n){void 0===n&&(n={});var i=[];i.push(this.client.baseUrl.replace(/\/+$/gm,"")),i.push("api"),i.push("files"),i.push(t["@collectionId"]),i.push(t.id),i.push(e);var o=i.join("/");if(Object.keys(n).length){var r=new URLSearchParams(n);o+=(o.includes("?")?"&":"?")+r}return o},n}(O),j=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.url="string"==typeof e.url?e.url:"",this.method="string"==typeof e.method?e.method:"GET",this.status="number"==typeof e.status?e.status:200,this.auth="string"==typeof e.auth?e.auth:"guest",this.ip="string"==typeof e.ip?e.ip:"",this.referer="string"==typeof e.referer?e.referer:"",this.userAgent="string"==typeof e.userAgent?e.userAgent:"",this.meta="object"==typeof e.meta&&null!==e.meta?e.meta:{}},n}(l),_=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getRequestsList=function(t,e,n){return void 0===t&&(t=1),void 0===e&&(e=30),void 0===n&&(n={}),n=Object.assign({page:t,perPage:e},n),this.client.send("/api/logs/requests",{method:"GET",params:n}).then((function(t){var e=[];if(null==t?void 0:t.items){t.items=(null==t?void 0:t.items)||[];for(var n=0,i=t.items;n<i.length;n++){var o=i[n];e.push(new j(o))}}return new y((null==t?void 0:t.page)||1,(null==t?void 0:t.perPage)||0,(null==t?void 0:t.totalItems)||0,e)}))},n.prototype.getRequest=function(t,e){return void 0===e&&(e={}),this.client.send("/api/logs/requests/"+encodeURIComponent(t),{method:"GET",params:e}).then((function(t){return new j(t)}))},n.prototype.getRequestsStats=function(t){return void 0===t&&(t={}),this.client.send("/api/logs/requests/stats",{method:"GET",params:t}).then((function(t){return t}))},n}(f),k=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.clientId="",e.eventSource=null,e.subscriptions={},e}return e(n,t),n.prototype.subscribe=function(t,e){var n;return i(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:if(!t)throw new Error("subscription must be set.");return this.subscriptions[t]&&(null===(n=this.eventSource)||void 0===n||n.removeEventListener(t,this.subscriptions[t])),this.subscriptions[t]=function(t){var n,i=t;try{n=JSON.parse(null==i?void 0:i.data)}catch(t){}e(n||{})},this.eventSource?[3,1]:(this.connect(),[3,3]);case 1:return this.clientId?[4,this.submitSubscriptions()]:[3,3];case 2:i.sent(),i.label=3;case 3:return[2]}}))}))},n.prototype.unsubscribe=function(t){var e;return i(this,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:if(t){if(!this.subscriptions[t])return[2];null===(e=this.eventSource)||void 0===e||e.removeEventListener(t,this.subscriptions[t]),delete this.subscriptions[t]}else this.removeSubscriptionListeners(),this.subscriptions={};return this.clientId?[4,this.submitSubscriptions()]:[3,2];case 1:n.sent(),n.label=2;case 2:return Object.keys(this.subscriptions).length||this.disconnect(),[2]}}))}))},n.prototype.submitSubscriptions=function(){return i(this,void 0,void 0,(function(){return o(this,(function(t){return this.addSubscriptionListeners(),[2,this.client.send("/api/realtime",{method:"POST",body:{clientId:this.clientId,subscriptions:Object.keys(this.subscriptions)}}).then((function(){return!0}))]}))}))},n.prototype.addSubscriptionListeners=function(){if(this.eventSource)for(var t in this.removeSubscriptionListeners(),this.subscriptions)this.eventSource.addEventListener(t,this.subscriptions[t])},n.prototype.removeSubscriptionListeners=function(){if(this.eventSource)for(var t in this.subscriptions)this.eventSource.removeEventListener(t,this.subscriptions[t])},n.prototype.connectHandler=function(t){var e=t;this.clientId=null==e?void 0:e.lastEventId,this.submitSubscriptions()},n.prototype.connect=function(){var t=this;this.disconnect(),this.eventSource=new EventSource(this.client.buildUrl("/api/realtime")),this.eventSource.addEventListener("PB_CONNECT",(function(e){return t.connectHandler(e)}))},n.prototype.disconnect=function(){var t,e,n=this;this.removeSubscriptionListeners(),null===(t=this.eventSource)||void 0===t||t.removeEventListener("PB_CONNECT",(function(t){return n.connectHandler(t)})),null===(e=this.eventSource)||void 0===e||e.close(),this.eventSource=null,this.clientId=""},n}(f);return function(){function t(t,e,n){void 0===t&&(t="/"),void 0===e&&(e="en-US"),this.cancelControllers={},this.baseUrl=t,this.lang=e,this.authStore=n||new p,this.admins=new g(this),this.users=new w(this),this.records=new R(this),this.collections=new P(this),this.logs=new _(this),this.settings=new v(this),this.realtime=new k(this)}return Object.defineProperty(t.prototype,"AuthStore",{get:function(){return this.authStore},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Settings",{get:function(){return this.settings},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Admins",{get:function(){return this.admins},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Users",{get:function(){return this.users},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Collections",{get:function(){return this.collections},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Records",{get:function(){return this.records},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Logs",{get:function(){return this.logs},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Realtime",{get:function(){return this.realtime},enumerable:!1,configurable:!0}),t.prototype.cancelRequest=function(t){return this.cancelControllers[t]&&(this.cancelControllers[t].abort(),delete this.cancelControllers[t]),this},t.prototype.cancelAllRequests=function(){for(var t in this.cancelControllers)this.cancelControllers[t].abort();return this.cancelControllers={},this},t.prototype.send=function(t,e){var n,r,u,a,l,c,h,d,p;return i(this,void 0,void 0,(function(){var f,v,y,b,m,g,w=this;return o(this,(function(S){return(f=Object.assign({method:"GET"},e)).body&&"FormData"!==f.body.constructor.name&&("string"!=typeof f.body&&(f.body=JSON.stringify(f.body)),void 0===(null===(n=null==f?void 0:f.headers)||void 0===n?void 0:n["Content-Type"])&&(f.headers=Object.assign({},f.headers,{"Content-Type":"application/json"}))),void 0===(null===(r=null==f?void 0:f.headers)||void 0===r?void 0:r["Accept-Language"])&&(f.headers=Object.assign({},f.headers,{"Accept-Language":this.lang})),(null===(u=this.authStore)||void 0===u?void 0:u.token)&&void 0===(null===(a=null==f?void 0:f.headers)||void 0===a?void 0:a.Authorization)&&(v="Admin",void 0!==(null===(l=this.authStore.model)||void 0===l?void 0:l.verified)&&(v="User"),f.headers=Object.assign({},f.headers,{Authorization:v+" "+this.authStore.token})),!1!==(null===(c=f.params)||void 0===c?void 0:c.$autoCancel)&&(y=(null===(h=f.params)||void 0===h?void 0:h.$cancelKey)||(f.method||"GET")+t,this.cancelRequest(y),b=new AbortController,this.cancelControllers[y]=b,f.signal=b.signal),null===(d=f.params)||void 0===d||delete d.$autoCancel,null===(p=f.params)||void 0===p||delete p.$cancelKey,m=this.buildUrl(t),void 0!==f.params&&((g=this.serializeQueryParams(f.params))&&(m+=(m.includes("?")?"&":"?")+g),delete f.params),this.beforeSend&&(f=Object.assign({},this.beforeSend(m,f))),[2,fetch(m,f).then((function(t){return i(w,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:e={},n.label=1;case 1:return n.trys.push([1,3,,4]),[4,t.json()];case 2:return e=n.sent(),[3,4];case 3:return n.sent(),[3,4];case 4:if(this.afterSend&&(e=this.afterSend(t,e)),t.status>=400)throw new s({url:t.url,status:t.status,data:e});return[2,e]}}))}))})).catch((function(t){if(t instanceof s)throw t;throw new s(t)}))]}))}))},t.prototype.buildUrl=function(t){var e=this.baseUrl+(this.baseUrl.endsWith("/")?"":"/");return t&&(e+=t.startsWith("/")?t.substring(1):t),e},t.prototype.serializeQueryParams=function(t){var e=[];for(var n in t)if(null!==t[n]){var i=t[n],o=encodeURIComponent(n);if(Array.isArray(i))for(var r=0,s=i;r<s.length;r++){var u=s[r];e.push(o+"="+encodeURIComponent(u))}else i instanceof Date?e.push(o+"="+encodeURIComponent(i.toISOString())):null!==typeof i&&"object"==typeof i?e.push(o+"="+encodeURIComponent(JSON.stringify(i))):e.push(o+"="+encodeURIComponent(i))}return e.join("&")},t}()}();

@@ -67,2 +67,11 @@ declare abstract class BaseModel {

}
/**
* The minimal AuthStore interface.
*
* This interface predates the abstract BaseAuthStore class
* and it is kept mainly for backward compatibility.
*
* New AuthStore implementations should extend directly the
* BaseAuthStore abstract class.
*/
type AuthStore = {

@@ -478,15 +487,124 @@ /**

declare class Client {
/**
* The base PocketBase backend url address (eg. 'http://localhost.8090').
*/
baseUrl: string;
/**
* Hook that get triggered right before sending the fetch request,
* allowing you to inspect/modify the request config.
*
* Returns the new modified config that will be used to send the request.
*
* For list of the possible options check https://developer.mozilla.org/en-US/docs/Web/API/fetch#options
*
* Example:
* ```js
* client.beforeSend = function (url, reqConfig) {
* reqConfig.headers = Object.assign(reqConfig.headers, {
* 'X-Custom-Header': 'example',
* });
*
* return reqConfig;
* };
* ```
*/
beforeSend?: (url: string, reqConfig: {
[key: string]: any;
}) => {
[key: string]: any;
};
/**
* Hook that get triggered after successfully sending the fetch request,
* allowing you to inspect/modify the response object and its parsed data.
*
* Returns the new Promise resolved `data` that will be returned to the client.
*
* Example:
* ```js
* client.afterSend = function (response, data) {
* if (response.status != 200) {
* throw new ClientResponseError({
* url: response.url,
* status: response.status,
* data: data,
* });
* }
*
* return data;
* };
* ```
*/
afterSend?: (response: Response, data: any) => any;
/**
* Optional language code (default to `en-US`) that will be sent
* with the requests to the server as `Accept-Language` header.
*/
lang: string;
AuthStore: AuthStore;
readonly Settings: Settings;
readonly Admins: Admins;
readonly Users: Users;
readonly Collections: Collections;
readonly Records: Records;
readonly Logs: Logs;
readonly Realtime: Realtime;
/**
* A replacable instance of the local `AuthStore` service.
*/
authStore: AuthStore;
/**
* An instance of the service that handles the **Settings APIs**.
*/
readonly settings: Settings;
/**
* An instance of the service that handles the **Admin APIs**.
*/
readonly admins: Admins;
/**
* An instance of the service that handles the **User APIs**.
*/
readonly users: Users;
/**
* An instance of the service that handles the **Collection APIs**.
*/
readonly collections: Collections;
/**
* An instance of the service that handles the **Record APIs**.
*/
readonly records: Records;
/**
* An instance of the service that handles the **Log APIs**.
*/
readonly logs: Logs;
/**
* An instance of the service that handles the **Realtime APIs**.
*/
readonly realtime: Realtime;
private cancelControllers;
constructor(baseUrl?: string, lang?: string, authStore?: AuthStore | null);
/**
* @deprecated Legacy alias for `this.authStore`.
*/
get AuthStore(): AuthStore;
/**
* @deprecated Legacy alias for `this.settings`.
*/
get Settings(): Settings;
/**
* @deprecated Legacy alias for `this.admins`.
*/
get Admins(): Admins;
/**
* @deprecated Legacy alias for `this.users`.
*/
get Users(): Users;
/**
* @deprecated Legacy alias for `this.collections`.
*/
get Collections(): Collections;
/**
* @deprecated Legacy alias for `this.records`.
*/
get Records(): Records;
/**
* @deprecated Legacy alias for `this.logs`.
*/
get Logs(): Logs;
/**
* @deprecated Legacy alias for `this.realtime`.
*/
get Realtime(): Realtime;
/**
* Cancels single request by its cancellation key.

@@ -493,0 +611,0 @@ */

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).PocketBase=e()}(this,(function(){"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}var n=function(){return n=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function i(t,e,n,i){return new(n||(n=Promise))((function(o,r){function s(t){try{a(i.next(t))}catch(t){r(t)}}function u(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}a((i=i.apply(t,e||[])).next())}))}function o(t,e){var n,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function u(r){return function(u){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){s.label=r[1];break}if(6===r[0]&&s.label<o[1]){s.label=o[1],o=r;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(r);break}o[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(t){r=[6,t],i=0}finally{n=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,u])}}}var r,s=function(t){function i(e){var n,i=this;return(i=t.call(this,"ClientResponseError")||this).url="",i.status=0,i.data={},i.isAbort=!1,i.originalError=null,e instanceof Error&&!(e instanceof i.constructor)&&(i.originalError=e),null!==e&&"object"==typeof e&&(i.url="string"==typeof e.url?e.url:"",i.status="number"==typeof e.status?e.status:0,i.data=null!==e.data&&"object"==typeof e.data?e.data:{}),"undefined"!=typeof DOMException&&e instanceof DOMException&&(i.isAbort=!0),i.name="ClientResponseError "+i.status,i.message=(null===(n=i.data)||void 0===n?void 0:n.message)||"Something went wrong while processing your request.",i}return e(i,t),i.prototype.toJSON=function(){return n({},this)},i}(Error);r="function"==typeof atob?atob:function(t){return Buffer.from(t,"base64").toString("binary")};var u=function(){function t(){}return t.getPayload=function(t){if(t)try{var e=decodeURIComponent(r(t.split(".")[1]).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(e)||{}}catch(t){}return{}},t.isExpired=function(e,n){void 0===n&&(n=0);var i=t.getPayload(e);return!(Object.keys(i).length>0&&(!i.exp||i.exp-n>Date.now()/1e3))},t}(),a=function(){function t(t){void 0===t&&(t={}),this.load(t||{})}return t.prototype.load=function(t){this.id=void 0!==t.id?t.id:"",this.created=void 0!==t.created?t.created:"",this.updated=void 0!==t.updated?t.updated:""},Object.defineProperty(t.prototype,"isNew",{get:function(){return!this.id||"00000000-0000-0000-0000-000000000000"===this.id},enumerable:!1,configurable:!0}),t.prototype.clone=function(){return new this.constructor(JSON.parse(JSON.stringify(this)))},t.prototype.export=function(){return Object.assign({},this)},t}(),l=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e);for(var n=0,i=Object.entries(e);n<i.length;n++){var o=i[n],r=o[0],s=o[1];this[r]=s}this["@collectionId"]=void 0!==e["@collectionId"]?e["@collectionId"]:"",this["@collectionName"]=void 0!==e["@collectionName"]?e["@collectionName"]:"",this["@expand"]=void 0!==e["@expand"]?e["@expand"]:{}},n}(a),c=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.email="string"==typeof e.email?e.email:"",this.verified=!!e.verified,this.lastResetSentAt="string"==typeof e.lastResetSentAt?e.lastResetSentAt:"",this.lastVerificationSentAt="string"==typeof e.lastVerificationSentAt?e.lastVerificationSentAt:"",this.profile=e.profile?new l(e.profile):null},n}(a),d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.avatar="number"==typeof e.avatar?e.avatar:0,this.email="string"==typeof e.email?e.email:"",this.lastResetSentAt="string"==typeof e.lastResetSentAt?e.lastResetSentAt:""},n}(a),h=function(){function t(t){void 0===t&&(t="pocketbase_auth"),this.fallback={},this.storageKey=t}return Object.defineProperty(t.prototype,"token",{get:function(){return(this._storageGet(this.storageKey)||{}).token||""},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"model",{get:function(){var t,e=this._storageGet(this.storageKey)||{};return null===e||"object"!=typeof e||null===e.model||"object"!=typeof e.model?{}:void 0!==(null===(t=e.model)||void 0===t?void 0:t.verified)?new c(e.model):new d(e.model)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isValid",{get:function(){return!u.isExpired(this.token)},enumerable:!1,configurable:!0}),t.prototype.save=function(t,e){this._storageSet(this.storageKey,{token:t,model:e})},t.prototype.clear=function(){return this._storageRemove(this.storageKey)},t.prototype._storageGet=function(t){var e;if("undefined"!=typeof window&&(null===window||void 0===window?void 0:window.localStorage)){var n=(null===(e=null===window||void 0===window?void 0:window.localStorage)||void 0===e?void 0:e.getItem(t))||"";try{return JSON.parse(n)}catch(t){return n}}return this.fallback[t]},t.prototype._storageSet=function(t,e){var n;if("undefined"!=typeof window&&(null===window||void 0===window?void 0:window.localStorage)){var i=e;"string"!=typeof e&&(i=JSON.stringify(e)),null===(n=null===window||void 0===window?void 0:window.localStorage)||void 0===n||n.setItem(t,i)}else this.fallback[t]=e},t.prototype._storageRemove=function(t){var e;"undefined"!=typeof window&&(null===(e=null===window||void 0===window?void 0:window.localStorage)||void 0===e||e.removeItem(t)),delete this.fallback[t]},t}(),p=function(t){this.client=t},f=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getAll=function(t){return void 0===t&&(t={}),this.client.send("/api/settings",{method:"GET",params:t}).then((function(t){return t||{}}))},n.prototype.update=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send("/api/settings",{method:"PATCH",params:e,body:t}).then((function(t){return t||{}}))},n}(p),v=function(t,e,n,i){this.page=t>0?t:1,this.perPage=e>=0?e:0,this.totalItems=n>=0?n:0,this.items=i||[]},y=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype._getFullList=function(t,e,n){var r=this;void 0===e&&(e=100),void 0===n&&(n={});var s=[],u=function(a){return i(r,void 0,void 0,(function(){return o(this,(function(i){return[2,this._getList(t,a,e,n).then((function(t){var e=t,n=e.items,i=e.totalItems;return s=s.concat(n),n.length&&i>s.length?u(a+1):s}))]}))}))};return u(1)},n.prototype._getList=function(t,e,n,i){var o=this;return void 0===e&&(e=1),void 0===n&&(n=30),void 0===i&&(i={}),i=Object.assign({page:e,perPage:n},i),this.client.send(t,{method:"GET",params:i}).then((function(t){var e=[];if(null==t?void 0:t.items){t.items=t.items||[];for(var n=0,i=t.items;n<i.length;n++){var r=i[n];e.push(o.decode(r))}}return new v((null==t?void 0:t.page)||1,(null==t?void 0:t.perPage)||0,(null==t?void 0:t.totalItems)||0,e)}))},n.prototype._getOne=function(t,e,n){var i=this;return void 0===n&&(n={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"GET",params:n}).then((function(t){return i.decode(t)}))},n.prototype._create=function(t,e,n){var i=this;return void 0===e&&(e={}),void 0===n&&(n={}),this.client.send(t,{method:"POST",params:n,body:e}).then((function(t){return i.decode(t)}))},n.prototype._update=function(t,e,n,i){var o=this;return void 0===n&&(n={}),void 0===i&&(i={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"PATCH",params:i,body:n}).then((function(t){return o.decode(t)}))},n.prototype._delete=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"DELETE",params:i,body:n}).then((function(){return!0}))},n}(p),m=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getFullList=function(t,e){return void 0===t&&(t=100),void 0===e&&(e={}),this._getFullList(this.baseCrudPath(),t,e)},n.prototype.getList=function(t,e,n){return void 0===t&&(t=1),void 0===e&&(e=30),void 0===n&&(n={}),this._getList(this.baseCrudPath(),t,e,n)},n.prototype.getOne=function(t,e){return void 0===e&&(e={}),this._getOne(this.baseCrudPath(),t,e)},n.prototype.create=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this._create(this.baseCrudPath(),t,e)},n.prototype.update=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._update(this.baseCrudPath(),t,e,n)},n.prototype.delete=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._delete(this.baseCrudPath(),t,e,n)},n}(y),b=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new d(t)},n.prototype.baseCrudPath=function(){return"/api/admins"},n.prototype.authResponse=function(t){var e=this.decode((null==t?void 0:t.admin)||{});return(null==t?void 0:t.token)&&(null==t?void 0:t.admin)&&this.client.AuthStore.save(t.token,e),Object.assign({},t,{token:(null==t?void 0:t.token)||"",admin:e})},n.prototype.authViaEmail=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({email:t,password:e},n),this.client.send(this.baseCrudPath()+"/auth-via-email",{method:"POST",params:i,body:n,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.refresh=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send(this.baseCrudPath()+"/refresh",{method:"POST",params:e,body:t}).then(this.authResponse.bind(this))},n.prototype.requestPasswordReset=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-password-reset",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmPasswordReset=function(t,e,n,i,o){return void 0===i&&(i={}),void 0===o&&(o={}),i=Object.assign({token:t,password:e,passwordConfirm:n},i),this.client.send(this.baseCrudPath()+"/confirm-password-reset",{method:"POST",params:o,body:i}).then(this.authResponse.bind(this))},n}(m),g=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new c(t)},n.prototype.baseCrudPath=function(){return"/api/users"},n.prototype.authResponse=function(t){var e=this.decode((null==t?void 0:t.user)||{});return(null==t?void 0:t.token)&&(null==t?void 0:t.user)&&this.client.AuthStore.save(t.token,e),Object.assign({},t,{token:(null==t?void 0:t.token)||"",user:e})},n.prototype.listAuthMethods=function(t){return void 0===t&&(t={}),this.client.send(this.baseCrudPath()+"/auth-methods",{method:"GET",params:t}).then((function(t){return Object.assign({},t,{emailPassword:!!(null==t?void 0:t.emailPassword),authProviders:Array.isArray(null==t?void 0:t.authProviders)?null==t?void 0:t.authProviders:[]})}))},n.prototype.authViaEmail=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({email:t,password:e},n),this.client.send(this.baseCrudPath()+"/auth-via-email",{method:"POST",params:i,body:n,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.authViaOAuth2=function(t,e,n,i,o,r){return void 0===o&&(o={}),void 0===r&&(r={}),o=Object.assign({provider:t,code:e,codeVerifier:n,redirectUrl:i},o),this.client.send(this.baseCrudPath()+"/auth-via-oauth2",{method:"POST",params:r,body:o,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.refresh=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send(this.baseCrudPath()+"/refresh",{method:"POST",params:e,body:t}).then(this.authResponse.bind(this))},n.prototype.requestPasswordReset=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-password-reset",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmPasswordReset=function(t,e,n,i,o){return void 0===i&&(i={}),void 0===o&&(o={}),i=Object.assign({token:t,password:e,passwordConfirm:n},i),this.client.send(this.baseCrudPath()+"/confirm-password-reset",{method:"POST",params:o,body:i}).then(this.authResponse.bind(this))},n.prototype.requestVerification=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-verification",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmVerification=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({token:t},e),this.client.send(this.baseCrudPath()+"/confirm-verification",{method:"POST",params:n,body:e}).then(this.authResponse.bind(this))},n.prototype.requestEmailChange=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({newEmail:t},e),this.client.send(this.baseCrudPath()+"/request-email-change",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmEmailChange=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({token:t,password:e},n),this.client.send(this.baseCrudPath()+"/confirm-email-change",{method:"POST",params:i,body:n}).then(this.authResponse.bind(this))},n}(m),w=function(){function t(t){void 0===t&&(t={}),this.load(t||{})}return t.prototype.load=function(t){this.id=void 0!==t.id?t.id:"",this.name=void 0!==t.name?t.name:"",this.type=void 0!==t.type?t.type:"text",this.system=!!t.system,this.required=!!t.required,this.unique=!!t.unique,this.options="object"==typeof t.options&&null!==t.options?t.options:{}},t}(),S=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.name="string"==typeof e.name?e.name:"",this.system=!!e.system,this.listRule="string"==typeof e.listRule?e.listRule:null,this.viewRule="string"==typeof e.viewRule?e.viewRule:null,this.createRule="string"==typeof e.createRule?e.createRule:null,this.updateRule="string"==typeof e.updateRule?e.updateRule:null,this.deleteRule="string"==typeof e.deleteRule?e.deleteRule:null,e.schema=Array.isArray(e.schema)?e.schema:[],this.schema=[];for(var n=0,i=e.schema;n<i.length;n++){var o=i[n];this.schema.push(new w(o))}},n}(a),P=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new S(t)},n.prototype.baseCrudPath=function(){return"/api/collections"},n}(m),O=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getFullList=function(t,e,n){return void 0===e&&(e=100),void 0===n&&(n={}),this._getFullList(this.baseCrudPath(t),e,n)},n.prototype.getList=function(t,e,n,i){return void 0===e&&(e=1),void 0===n&&(n=30),void 0===i&&(i={}),this._getList(this.baseCrudPath(t),e,n,i)},n.prototype.getOne=function(t,e,n){return void 0===n&&(n={}),this._getOne(this.baseCrudPath(t),e,n)},n.prototype.create=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._create(this.baseCrudPath(t),e,n)},n.prototype.update=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this._update(this.baseCrudPath(t),e,n,i)},n.prototype.delete=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this._delete(this.baseCrudPath(t),e,n,i)},n}(y),C=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new l(t)},n.prototype.baseCrudPath=function(t){return"/api/collections/"+encodeURIComponent(t)+"/records"},n.prototype.getFileUrl=function(t,e,n){void 0===n&&(n={});var i=[];i.push(this.client.baseUrl.replace(/\/+$/gm,"")),i.push("api"),i.push("files"),i.push(t["@collectionId"]),i.push(t.id),i.push(e);var o=i.join("/");if(Object.keys(n).length){var r=new URLSearchParams(n);o+=(o.includes("?")?"&":"?")+r}return o},n}(O),R=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.url="string"==typeof e.url?e.url:"",this.method="string"==typeof e.method?e.method:"GET",this.status="number"==typeof e.status?e.status:200,this.auth="string"==typeof e.auth?e.auth:"guest",this.ip="string"==typeof e.ip?e.ip:"",this.referer="string"==typeof e.referer?e.referer:"",this.userAgent="string"==typeof e.userAgent?e.userAgent:"",this.meta="object"==typeof e.meta&&null!==e.meta?e.meta:{}},n}(a),j=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getRequestsList=function(t,e,n){return void 0===t&&(t=1),void 0===e&&(e=30),void 0===n&&(n={}),n=Object.assign({page:t,perPage:e},n),this.client.send("/api/logs/requests",{method:"GET",params:n}).then((function(t){var e=[];if(null==t?void 0:t.items){t.items=(null==t?void 0:t.items)||[];for(var n=0,i=t.items;n<i.length;n++){var o=i[n];e.push(new R(o))}}return new v((null==t?void 0:t.page)||1,(null==t?void 0:t.perPage)||0,(null==t?void 0:t.totalItems)||0,e)}))},n.prototype.getRequest=function(t,e){return void 0===e&&(e={}),this.client.send("/api/logs/requests/"+encodeURIComponent(t),{method:"GET",params:e}).then((function(t){return new R(t)}))},n.prototype.getRequestsStats=function(t){return void 0===t&&(t={}),this.client.send("/api/logs/requests/stats",{method:"GET",params:t}).then((function(t){return t}))},n}(p),A=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.clientId="",e.eventSource=null,e.subscriptions={},e}return e(n,t),n.prototype.subscribe=function(t,e){var n;return i(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:if(!t)throw new Error("subscription must be set.");return this.subscriptions[t]&&(null===(n=this.eventSource)||void 0===n||n.removeEventListener(t,this.subscriptions[t])),this.subscriptions[t]=function(t){var n,i=t;try{n=JSON.parse(null==i?void 0:i.data)}catch(t){}e(n||{})},this.eventSource?[3,1]:(this.connect(),[3,3]);case 1:return this.clientId?[4,this.submitSubscriptions()]:[3,3];case 2:i.sent(),i.label=3;case 3:return[2]}}))}))},n.prototype.unsubscribe=function(t){var e;return i(this,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:if(t){if(!this.subscriptions[t])return[2];null===(e=this.eventSource)||void 0===e||e.removeEventListener(t,this.subscriptions[t]),delete this.subscriptions[t]}else this.removeSubscriptionListeners(),this.subscriptions={};return this.clientId?[4,this.submitSubscriptions()]:[3,2];case 1:n.sent(),n.label=2;case 2:return Object.keys(this.subscriptions).length||this.disconnect(),[2]}}))}))},n.prototype.submitSubscriptions=function(){return i(this,void 0,void 0,(function(){return o(this,(function(t){return this.addSubscriptionListeners(),[2,this.client.send("/api/realtime",{method:"POST",body:{clientId:this.clientId,subscriptions:Object.keys(this.subscriptions)}}).then((function(){return!0}))]}))}))},n.prototype.addSubscriptionListeners=function(){if(this.eventSource)for(var t in this.removeSubscriptionListeners(),this.subscriptions)this.eventSource.addEventListener(t,this.subscriptions[t])},n.prototype.removeSubscriptionListeners=function(){if(this.eventSource)for(var t in this.subscriptions)this.eventSource.removeEventListener(t,this.subscriptions[t])},n.prototype.connectHandler=function(t){var e=t;this.clientId=null==e?void 0:e.lastEventId,this.submitSubscriptions()},n.prototype.connect=function(){var t=this;this.disconnect(),this.eventSource=new EventSource(this.client.buildUrl("/api/realtime")),this.eventSource.addEventListener("PB_CONNECT",(function(e){return t.connectHandler(e)}))},n.prototype.disconnect=function(){var t,e,n=this;this.removeSubscriptionListeners(),null===(t=this.eventSource)||void 0===t||t.removeEventListener("PB_CONNECT",(function(t){return n.connectHandler(t)})),null===(e=this.eventSource)||void 0===e||e.close(),this.eventSource=null,this.clientId=""},n}(p);return function(){function t(t,e,n){void 0===t&&(t="/"),void 0===e&&(e="en-US"),this.cancelControllers={},this.baseUrl=t,this.lang=e,this.AuthStore=n||new h,this.Settings=new f(this),this.Admins=new b(this),this.Users=new g(this),this.Collections=new P(this),this.Records=new C(this),this.Logs=new j(this),this.Realtime=new A(this)}return t.prototype.cancelRequest=function(t){return this.cancelControllers[t]&&(this.cancelControllers[t].abort(),delete this.cancelControllers[t]),this},t.prototype.cancelAllRequests=function(){for(var t in this.cancelControllers)this.cancelControllers[t].abort();return this.cancelControllers={},this},t.prototype.send=function(t,e){var n,r,u,a,l,c,d,h,p,f=this,v=Object.assign({method:"GET"},e);if(v.body&&"FormData"!==v.body.constructor.name&&("string"!=typeof v.body&&(v.body=JSON.stringify(v.body)),void 0===(null===(n=null==v?void 0:v.headers)||void 0===n?void 0:n["Content-Type"])&&(v.headers=Object.assign({},v.headers,{"Content-Type":"application/json"}))),void 0===(null===(r=null==v?void 0:v.headers)||void 0===r?void 0:r["Accept-Language"])&&(v.headers=Object.assign({},v.headers,{"Accept-Language":this.lang})),(null===(u=this.AuthStore)||void 0===u?void 0:u.token)&&void 0===(null===(a=null==v?void 0:v.headers)||void 0===a?void 0:a.Authorization)){var y="Admin";void 0!==(null===(l=this.AuthStore.model)||void 0===l?void 0:l.verified)&&(y="User"),v.headers=Object.assign({},v.headers,{Authorization:y+" "+this.AuthStore.token})}if(!1!==(null===(c=v.params)||void 0===c?void 0:c.$autoCancel)){var m=(null===(d=v.params)||void 0===d?void 0:d.$cancelKey)||(v.method||"GET")+t;this.cancelRequest(m);var b=new AbortController;this.cancelControllers[m]=b,v.signal=b.signal}null===(h=v.params)||void 0===h||delete h.$autoCancel,null===(p=v.params)||void 0===p||delete p.$cancelKey;var g=this.buildUrl(t);if(void 0!==v.params){var w=this.serializeQueryParams(v.params);w&&(g+=(g.includes("?")?"&":"?")+w),delete v.params}return fetch(g,v).then((function(t){return i(f,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:e={},n.label=1;case 1:return n.trys.push([1,3,,4]),[4,t.json()];case 2:return e=n.sent(),[3,4];case 3:return n.sent(),[3,4];case 4:if(t.status>=400)throw new s({url:t.url,status:t.status,data:e});return[2,e]}}))}))})).catch((function(t){if(t instanceof s)throw t;throw new s(t)}))},t.prototype.buildUrl=function(t){var e=this.baseUrl+(this.baseUrl.endsWith("/")?"":"/");return t&&(e+=t.startsWith("/")?t.substring(1):t),e},t.prototype.serializeQueryParams=function(t){var e=[];for(var n in t)if(null!==t[n]){var i=t[n],o=encodeURIComponent(n);if(Array.isArray(i))for(var r=0,s=i;r<s.length;r++){var u=s[r];e.push(o+"="+encodeURIComponent(u))}else i instanceof Date?e.push(o+"="+encodeURIComponent(i.toISOString())):null!==typeof i&&"object"==typeof i?e.push(o+"="+encodeURIComponent(JSON.stringify(i))):e.push(o+"="+encodeURIComponent(i))}return e.join("&")},t}()}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).PocketBase=e()}(this,(function(){"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}var n=function(){return n=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function i(t,e,n,i){return new(n||(n=Promise))((function(o,r){function s(t){try{a(i.next(t))}catch(t){r(t)}}function u(t){try{a(i.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}a((i=i.apply(t,e||[])).next())}))}function o(t,e){var n,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function u(r){return function(u){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){s.label=r[1];break}if(6===r[0]&&s.label<o[1]){s.label=o[1],o=r;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(r);break}o[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(t){r=[6,t],i=0}finally{n=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,u])}}}var r,s=function(t){function i(e){var n,i=this;return(i=t.call(this,"ClientResponseError")||this).url="",i.status=0,i.data={},i.isAbort=!1,i.originalError=null,e instanceof Error&&!(e instanceof i.constructor)&&(i.originalError=e),null!==e&&"object"==typeof e&&(i.url="string"==typeof e.url?e.url:"",i.status="number"==typeof e.status?e.status:0,i.data=null!==e.data&&"object"==typeof e.data?e.data:{}),"undefined"!=typeof DOMException&&e instanceof DOMException&&(i.isAbort=!0),i.name="ClientResponseError "+i.status,i.message=(null===(n=i.data)||void 0===n?void 0:n.message)||"Something went wrong while processing your request.",i}return e(i,t),i.prototype.toJSON=function(){return n({},this)},i}(Error);r="function"==typeof atob?atob:function(t){return Buffer.from(t,"base64").toString("binary")};var u=function(){function t(){}return t.getPayload=function(t){if(t)try{var e=decodeURIComponent(r(t.split(".")[1]).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(e)||{}}catch(t){}return{}},t.isExpired=function(e,n){void 0===n&&(n=0);var i=t.getPayload(e);return!(Object.keys(i).length>0&&(!i.exp||i.exp-n>Date.now()/1e3))},t}(),a=function(){function t(){this.baseToken="",this.baseModel={},this._onChangeCallbacks=[]}return Object.defineProperty(t.prototype,"token",{get:function(){return this.baseToken},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"model",{get:function(){return this.baseModel},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isValid",{get:function(){return!u.isExpired(this.token)},enumerable:!1,configurable:!0}),t.prototype.save=function(t,e){this.baseToken=t,this.baseModel=e,this._triggerChange()},t.prototype.clear=function(){this._triggerChange()},t.prototype.onChange=function(t){var e=this;return this._onChangeCallbacks.push(t),function(){for(var n=e._onChangeCallbacks.length-1;n>=0;n--)if(e._onChangeCallbacks[n]==t)return delete e._onChangeCallbacks[n],void e._onChangeCallbacks.splice(n,1)}},t.prototype._triggerChange=function(){for(var t=0,e=this._onChangeCallbacks;t<e.length;t++){var n=e[t];n&&n(this.token,this.model)}},t}(),l=function(){function t(t){void 0===t&&(t={}),this.load(t||{})}return t.prototype.load=function(t){this.id=void 0!==t.id?t.id:"",this.created=void 0!==t.created?t.created:"",this.updated=void 0!==t.updated?t.updated:""},Object.defineProperty(t.prototype,"isNew",{get:function(){return!this.id||"00000000-0000-0000-0000-000000000000"===this.id},enumerable:!1,configurable:!0}),t.prototype.clone=function(){return new this.constructor(JSON.parse(JSON.stringify(this)))},t.prototype.export=function(){return Object.assign({},this)},t}(),c=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e);for(var n=0,i=Object.entries(e);n<i.length;n++){var o=i[n],r=o[0],s=o[1];this[r]=s}this["@collectionId"]=void 0!==e["@collectionId"]?e["@collectionId"]:"",this["@collectionName"]=void 0!==e["@collectionName"]?e["@collectionName"]:"",this["@expand"]=void 0!==e["@expand"]?e["@expand"]:{}},n}(l),d=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.email="string"==typeof e.email?e.email:"",this.verified=!!e.verified,this.lastResetSentAt="string"==typeof e.lastResetSentAt?e.lastResetSentAt:"",this.lastVerificationSentAt="string"==typeof e.lastVerificationSentAt?e.lastVerificationSentAt:"",this.profile=e.profile?new c(e.profile):null},n}(l),h=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.avatar="number"==typeof e.avatar?e.avatar:0,this.email="string"==typeof e.email?e.email:"",this.lastResetSentAt="string"==typeof e.lastResetSentAt?e.lastResetSentAt:""},n}(l),p=function(t){function n(e){void 0===e&&(e="pocketbase_auth");var n=t.call(this)||this;return n.fallback={},n.storageKey=e,n}return e(n,t),Object.defineProperty(n.prototype,"token",{get:function(){return(this._storageGet(this.storageKey)||{}).token||""},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"model",{get:function(){var t,e=this._storageGet(this.storageKey)||{};return null===e||"object"!=typeof e||null===e.model||"object"!=typeof e.model?{}:void 0!==(null===(t=e.model)||void 0===t?void 0:t.verified)?new d(e.model):new h(e.model)},enumerable:!1,configurable:!0}),n.prototype.save=function(e,n){this._storageSet(this.storageKey,{token:e,model:n}),t.prototype.save.call(this,e,n)},n.prototype.clear=function(){this._storageRemove(this.storageKey),t.prototype.clear.call(this)},n.prototype._storageGet=function(t){var e;if("undefined"!=typeof window&&(null===window||void 0===window?void 0:window.localStorage)){var n=(null===(e=null===window||void 0===window?void 0:window.localStorage)||void 0===e?void 0:e.getItem(t))||"";try{return JSON.parse(n)}catch(t){return n}}return this.fallback[t]},n.prototype._storageSet=function(t,e){var n;if("undefined"!=typeof window&&(null===window||void 0===window?void 0:window.localStorage)){var i=e;"string"!=typeof e&&(i=JSON.stringify(e)),null===(n=null===window||void 0===window?void 0:window.localStorage)||void 0===n||n.setItem(t,i)}else this.fallback[t]=e},n.prototype._storageRemove=function(t){var e;"undefined"!=typeof window&&(null===(e=null===window||void 0===window?void 0:window.localStorage)||void 0===e||e.removeItem(t)),delete this.fallback[t]},n}(a),f=function(t){this.client=t},v=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getAll=function(t){return void 0===t&&(t={}),this.client.send("/api/settings",{method:"GET",params:t}).then((function(t){return t||{}}))},n.prototype.update=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send("/api/settings",{method:"PATCH",params:e,body:t}).then((function(t){return t||{}}))},n}(f),y=function(t,e,n,i){this.page=t>0?t:1,this.perPage=e>=0?e:0,this.totalItems=n>=0?n:0,this.items=i||[]},b=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype._getFullList=function(t,e,n){var r=this;void 0===e&&(e=100),void 0===n&&(n={});var s=[],u=function(a){return i(r,void 0,void 0,(function(){return o(this,(function(i){return[2,this._getList(t,a,e,n).then((function(t){var e=t,n=e.items,i=e.totalItems;return s=s.concat(n),n.length&&i>s.length?u(a+1):s}))]}))}))};return u(1)},n.prototype._getList=function(t,e,n,i){var o=this;return void 0===e&&(e=1),void 0===n&&(n=30),void 0===i&&(i={}),i=Object.assign({page:e,perPage:n},i),this.client.send(t,{method:"GET",params:i}).then((function(t){var e=[];if(null==t?void 0:t.items){t.items=t.items||[];for(var n=0,i=t.items;n<i.length;n++){var r=i[n];e.push(o.decode(r))}}return new y((null==t?void 0:t.page)||1,(null==t?void 0:t.perPage)||0,(null==t?void 0:t.totalItems)||0,e)}))},n.prototype._getOne=function(t,e,n){var i=this;return void 0===n&&(n={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"GET",params:n}).then((function(t){return i.decode(t)}))},n.prototype._create=function(t,e,n){var i=this;return void 0===e&&(e={}),void 0===n&&(n={}),this.client.send(t,{method:"POST",params:n,body:e}).then((function(t){return i.decode(t)}))},n.prototype._update=function(t,e,n,i){var o=this;return void 0===n&&(n={}),void 0===i&&(i={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"PATCH",params:i,body:n}).then((function(t){return o.decode(t)}))},n.prototype._delete=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this.client.send(t+"/"+encodeURIComponent(e),{method:"DELETE",params:i,body:n}).then((function(){return!0}))},n}(f),m=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getFullList=function(t,e){return void 0===t&&(t=100),void 0===e&&(e={}),this._getFullList(this.baseCrudPath(),t,e)},n.prototype.getList=function(t,e,n){return void 0===t&&(t=1),void 0===e&&(e=30),void 0===n&&(n={}),this._getList(this.baseCrudPath(),t,e,n)},n.prototype.getOne=function(t,e){return void 0===e&&(e={}),this._getOne(this.baseCrudPath(),t,e)},n.prototype.create=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this._create(this.baseCrudPath(),t,e)},n.prototype.update=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._update(this.baseCrudPath(),t,e,n)},n.prototype.delete=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._delete(this.baseCrudPath(),t,e,n)},n}(b),g=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new h(t)},n.prototype.baseCrudPath=function(){return"/api/admins"},n.prototype.authResponse=function(t){var e=this.decode((null==t?void 0:t.admin)||{});return(null==t?void 0:t.token)&&(null==t?void 0:t.admin)&&this.client.authStore.save(t.token,e),Object.assign({},t,{token:(null==t?void 0:t.token)||"",admin:e})},n.prototype.authViaEmail=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({email:t,password:e},n),this.client.send(this.baseCrudPath()+"/auth-via-email",{method:"POST",params:i,body:n,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.refresh=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send(this.baseCrudPath()+"/refresh",{method:"POST",params:e,body:t}).then(this.authResponse.bind(this))},n.prototype.requestPasswordReset=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-password-reset",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmPasswordReset=function(t,e,n,i,o){return void 0===i&&(i={}),void 0===o&&(o={}),i=Object.assign({token:t,password:e,passwordConfirm:n},i),this.client.send(this.baseCrudPath()+"/confirm-password-reset",{method:"POST",params:o,body:i}).then(this.authResponse.bind(this))},n}(m),w=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new d(t)},n.prototype.baseCrudPath=function(){return"/api/users"},n.prototype.authResponse=function(t){var e=this.decode((null==t?void 0:t.user)||{});return(null==t?void 0:t.token)&&(null==t?void 0:t.user)&&this.client.authStore.save(t.token,e),Object.assign({},t,{token:(null==t?void 0:t.token)||"",user:e})},n.prototype.listAuthMethods=function(t){return void 0===t&&(t={}),this.client.send(this.baseCrudPath()+"/auth-methods",{method:"GET",params:t}).then((function(t){return Object.assign({},t,{emailPassword:!!(null==t?void 0:t.emailPassword),authProviders:Array.isArray(null==t?void 0:t.authProviders)?null==t?void 0:t.authProviders:[]})}))},n.prototype.authViaEmail=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({email:t,password:e},n),this.client.send(this.baseCrudPath()+"/auth-via-email",{method:"POST",params:i,body:n,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.authViaOAuth2=function(t,e,n,i,o,r){return void 0===o&&(o={}),void 0===r&&(r={}),o=Object.assign({provider:t,code:e,codeVerifier:n,redirectUrl:i},o),this.client.send(this.baseCrudPath()+"/auth-via-oauth2",{method:"POST",params:r,body:o,headers:{Authorization:""}}).then(this.authResponse.bind(this))},n.prototype.refresh=function(t,e){return void 0===t&&(t={}),void 0===e&&(e={}),this.client.send(this.baseCrudPath()+"/refresh",{method:"POST",params:e,body:t}).then(this.authResponse.bind(this))},n.prototype.requestPasswordReset=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-password-reset",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmPasswordReset=function(t,e,n,i,o){return void 0===i&&(i={}),void 0===o&&(o={}),i=Object.assign({token:t,password:e,passwordConfirm:n},i),this.client.send(this.baseCrudPath()+"/confirm-password-reset",{method:"POST",params:o,body:i}).then(this.authResponse.bind(this))},n.prototype.requestVerification=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({email:t},e),this.client.send(this.baseCrudPath()+"/request-verification",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmVerification=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({token:t},e),this.client.send(this.baseCrudPath()+"/confirm-verification",{method:"POST",params:n,body:e}).then(this.authResponse.bind(this))},n.prototype.requestEmailChange=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),e=Object.assign({newEmail:t},e),this.client.send(this.baseCrudPath()+"/request-email-change",{method:"POST",params:n,body:e}).then((function(){return!0}))},n.prototype.confirmEmailChange=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),n=Object.assign({token:t,password:e},n),this.client.send(this.baseCrudPath()+"/confirm-email-change",{method:"POST",params:i,body:n}).then(this.authResponse.bind(this))},n}(m),S=function(){function t(t){void 0===t&&(t={}),this.load(t||{})}return t.prototype.load=function(t){this.id=void 0!==t.id?t.id:"",this.name=void 0!==t.name?t.name:"",this.type=void 0!==t.type?t.type:"text",this.system=!!t.system,this.required=!!t.required,this.unique=!!t.unique,this.options="object"==typeof t.options&&null!==t.options?t.options:{}},t}(),C=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.name="string"==typeof e.name?e.name:"",this.system=!!e.system,this.listRule="string"==typeof e.listRule?e.listRule:null,this.viewRule="string"==typeof e.viewRule?e.viewRule:null,this.createRule="string"==typeof e.createRule?e.createRule:null,this.updateRule="string"==typeof e.updateRule?e.updateRule:null,this.deleteRule="string"==typeof e.deleteRule?e.deleteRule:null,e.schema=Array.isArray(e.schema)?e.schema:[],this.schema=[];for(var n=0,i=e.schema;n<i.length;n++){var o=i[n];this.schema.push(new S(o))}},n}(l),P=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new C(t)},n.prototype.baseCrudPath=function(){return"/api/collections"},n}(m),O=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getFullList=function(t,e,n){return void 0===e&&(e=100),void 0===n&&(n={}),this._getFullList(this.baseCrudPath(t),e,n)},n.prototype.getList=function(t,e,n,i){return void 0===e&&(e=1),void 0===n&&(n=30),void 0===i&&(i={}),this._getList(this.baseCrudPath(t),e,n,i)},n.prototype.getOne=function(t,e,n){return void 0===n&&(n={}),this._getOne(this.baseCrudPath(t),e,n)},n.prototype.create=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._create(this.baseCrudPath(t),e,n)},n.prototype.update=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this._update(this.baseCrudPath(t),e,n,i)},n.prototype.delete=function(t,e,n,i){return void 0===n&&(n={}),void 0===i&&(i={}),this._delete(this.baseCrudPath(t),e,n,i)},n}(b),R=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.decode=function(t){return new c(t)},n.prototype.baseCrudPath=function(t){return"/api/collections/"+encodeURIComponent(t)+"/records"},n.prototype.getFileUrl=function(t,e,n){void 0===n&&(n={});var i=[];i.push(this.client.baseUrl.replace(/\/+$/gm,"")),i.push("api"),i.push("files"),i.push(t["@collectionId"]),i.push(t.id),i.push(e);var o=i.join("/");if(Object.keys(n).length){var r=new URLSearchParams(n);o+=(o.includes("?")?"&":"?")+r}return o},n}(O),j=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.load=function(e){t.prototype.load.call(this,e),this.url="string"==typeof e.url?e.url:"",this.method="string"==typeof e.method?e.method:"GET",this.status="number"==typeof e.status?e.status:200,this.auth="string"==typeof e.auth?e.auth:"guest",this.ip="string"==typeof e.ip?e.ip:"",this.referer="string"==typeof e.referer?e.referer:"",this.userAgent="string"==typeof e.userAgent?e.userAgent:"",this.meta="object"==typeof e.meta&&null!==e.meta?e.meta:{}},n}(l),_=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return e(n,t),n.prototype.getRequestsList=function(t,e,n){return void 0===t&&(t=1),void 0===e&&(e=30),void 0===n&&(n={}),n=Object.assign({page:t,perPage:e},n),this.client.send("/api/logs/requests",{method:"GET",params:n}).then((function(t){var e=[];if(null==t?void 0:t.items){t.items=(null==t?void 0:t.items)||[];for(var n=0,i=t.items;n<i.length;n++){var o=i[n];e.push(new j(o))}}return new y((null==t?void 0:t.page)||1,(null==t?void 0:t.perPage)||0,(null==t?void 0:t.totalItems)||0,e)}))},n.prototype.getRequest=function(t,e){return void 0===e&&(e={}),this.client.send("/api/logs/requests/"+encodeURIComponent(t),{method:"GET",params:e}).then((function(t){return new j(t)}))},n.prototype.getRequestsStats=function(t){return void 0===t&&(t={}),this.client.send("/api/logs/requests/stats",{method:"GET",params:t}).then((function(t){return t}))},n}(f),k=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.clientId="",e.eventSource=null,e.subscriptions={},e}return e(n,t),n.prototype.subscribe=function(t,e){var n;return i(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:if(!t)throw new Error("subscription must be set.");return this.subscriptions[t]&&(null===(n=this.eventSource)||void 0===n||n.removeEventListener(t,this.subscriptions[t])),this.subscriptions[t]=function(t){var n,i=t;try{n=JSON.parse(null==i?void 0:i.data)}catch(t){}e(n||{})},this.eventSource?[3,1]:(this.connect(),[3,3]);case 1:return this.clientId?[4,this.submitSubscriptions()]:[3,3];case 2:i.sent(),i.label=3;case 3:return[2]}}))}))},n.prototype.unsubscribe=function(t){var e;return i(this,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:if(t){if(!this.subscriptions[t])return[2];null===(e=this.eventSource)||void 0===e||e.removeEventListener(t,this.subscriptions[t]),delete this.subscriptions[t]}else this.removeSubscriptionListeners(),this.subscriptions={};return this.clientId?[4,this.submitSubscriptions()]:[3,2];case 1:n.sent(),n.label=2;case 2:return Object.keys(this.subscriptions).length||this.disconnect(),[2]}}))}))},n.prototype.submitSubscriptions=function(){return i(this,void 0,void 0,(function(){return o(this,(function(t){return this.addSubscriptionListeners(),[2,this.client.send("/api/realtime",{method:"POST",body:{clientId:this.clientId,subscriptions:Object.keys(this.subscriptions)}}).then((function(){return!0}))]}))}))},n.prototype.addSubscriptionListeners=function(){if(this.eventSource)for(var t in this.removeSubscriptionListeners(),this.subscriptions)this.eventSource.addEventListener(t,this.subscriptions[t])},n.prototype.removeSubscriptionListeners=function(){if(this.eventSource)for(var t in this.subscriptions)this.eventSource.removeEventListener(t,this.subscriptions[t])},n.prototype.connectHandler=function(t){var e=t;this.clientId=null==e?void 0:e.lastEventId,this.submitSubscriptions()},n.prototype.connect=function(){var t=this;this.disconnect(),this.eventSource=new EventSource(this.client.buildUrl("/api/realtime")),this.eventSource.addEventListener("PB_CONNECT",(function(e){return t.connectHandler(e)}))},n.prototype.disconnect=function(){var t,e,n=this;this.removeSubscriptionListeners(),null===(t=this.eventSource)||void 0===t||t.removeEventListener("PB_CONNECT",(function(t){return n.connectHandler(t)})),null===(e=this.eventSource)||void 0===e||e.close(),this.eventSource=null,this.clientId=""},n}(f);return function(){function t(t,e,n){void 0===t&&(t="/"),void 0===e&&(e="en-US"),this.cancelControllers={},this.baseUrl=t,this.lang=e,this.authStore=n||new p,this.admins=new g(this),this.users=new w(this),this.records=new R(this),this.collections=new P(this),this.logs=new _(this),this.settings=new v(this),this.realtime=new k(this)}return Object.defineProperty(t.prototype,"AuthStore",{get:function(){return this.authStore},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Settings",{get:function(){return this.settings},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Admins",{get:function(){return this.admins},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Users",{get:function(){return this.users},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Collections",{get:function(){return this.collections},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Records",{get:function(){return this.records},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Logs",{get:function(){return this.logs},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Realtime",{get:function(){return this.realtime},enumerable:!1,configurable:!0}),t.prototype.cancelRequest=function(t){return this.cancelControllers[t]&&(this.cancelControllers[t].abort(),delete this.cancelControllers[t]),this},t.prototype.cancelAllRequests=function(){for(var t in this.cancelControllers)this.cancelControllers[t].abort();return this.cancelControllers={},this},t.prototype.send=function(t,e){var n,r,u,a,l,c,d,h,p;return i(this,void 0,void 0,(function(){var f,v,y,b,m,g,w=this;return o(this,(function(S){return(f=Object.assign({method:"GET"},e)).body&&"FormData"!==f.body.constructor.name&&("string"!=typeof f.body&&(f.body=JSON.stringify(f.body)),void 0===(null===(n=null==f?void 0:f.headers)||void 0===n?void 0:n["Content-Type"])&&(f.headers=Object.assign({},f.headers,{"Content-Type":"application/json"}))),void 0===(null===(r=null==f?void 0:f.headers)||void 0===r?void 0:r["Accept-Language"])&&(f.headers=Object.assign({},f.headers,{"Accept-Language":this.lang})),(null===(u=this.authStore)||void 0===u?void 0:u.token)&&void 0===(null===(a=null==f?void 0:f.headers)||void 0===a?void 0:a.Authorization)&&(v="Admin",void 0!==(null===(l=this.authStore.model)||void 0===l?void 0:l.verified)&&(v="User"),f.headers=Object.assign({},f.headers,{Authorization:v+" "+this.authStore.token})),!1!==(null===(c=f.params)||void 0===c?void 0:c.$autoCancel)&&(y=(null===(d=f.params)||void 0===d?void 0:d.$cancelKey)||(f.method||"GET")+t,this.cancelRequest(y),b=new AbortController,this.cancelControllers[y]=b,f.signal=b.signal),null===(h=f.params)||void 0===h||delete h.$autoCancel,null===(p=f.params)||void 0===p||delete p.$cancelKey,m=this.buildUrl(t),void 0!==f.params&&((g=this.serializeQueryParams(f.params))&&(m+=(m.includes("?")?"&":"?")+g),delete f.params),this.beforeSend&&(f=Object.assign({},this.beforeSend(m,f))),[2,fetch(m,f).then((function(t){return i(w,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:e={},n.label=1;case 1:return n.trys.push([1,3,,4]),[4,t.json()];case 2:return e=n.sent(),[3,4];case 3:return n.sent(),[3,4];case 4:if(this.afterSend&&(e=this.afterSend(t,e)),t.status>=400)throw new s({url:t.url,status:t.status,data:e});return[2,e]}}))}))})).catch((function(t){if(t instanceof s)throw t;throw new s(t)}))]}))}))},t.prototype.buildUrl=function(t){var e=this.baseUrl+(this.baseUrl.endsWith("/")?"":"/");return t&&(e+=t.startsWith("/")?t.substring(1):t),e},t.prototype.serializeQueryParams=function(t){var e=[];for(var n in t)if(null!==t[n]){var i=t[n],o=encodeURIComponent(n);if(Array.isArray(i))for(var r=0,s=i;r<s.length;r++){var u=s[r];e.push(o+"="+encodeURIComponent(u))}else i instanceof Date?e.push(o+"="+encodeURIComponent(i.toISOString())):null!==typeof i&&"object"==typeof i?e.push(o+"="+encodeURIComponent(JSON.stringify(i))):e.push(o+"="+encodeURIComponent(i))}return e.join("&")},t}()}));
{
"version": "0.2.2",
"version": "0.3.0",
"name": "pocketbase",
"description": "PocketBase JavaScript SDK",
"author": "Gani Georgiev <gani.georgiev@gmail.com>",
"author": "Gani Georgiev",
"license": "MIT",

@@ -7,0 +7,0 @@ "repository": {

@@ -7,4 +7,9 @@ PocketBase JavaScript SDK

- [Installation](#installation)
- [Examples](#examples)
- [Usage](#usage)
- [Caveats](#caveats)
- [File upload](#file-upload)
- [Errors handling](#errors-handling)
- [AuthStore](#authstore)
- [Auto cancellation](#auto-cancellation)
- [Send hooks](#send-hooks)
- [Definitions](#definitions)

@@ -51,3 +56,3 @@ - [Development](#development)

---
> 🔧 Node doesn't have native `EvenSource` implementation, so in order to use the realtime service (aka. `client.Realtime.subscribe()`) you'll need to load a `EventSource` polyfill.
> 🔧 Node doesn't have native `EvenSource` implementation, so in order to use the realtime service (aka. `client.realtime.subscribe()`) you'll need to load a `EventSource` polyfill.
> I recommend [EventSource/eventsource](https://github.com/EventSource/eventsource):

@@ -60,3 +65,3 @@ > ```js

## Examples
## Usage

@@ -70,13 +75,13 @@ ```js

// list and filter "demo" collection records
const result = await client.Records.getList("demo", 1, 20, {
filter: "status = true && totalComments > 0"
// list and filter "example" collection records
const result = await client.records.getList('example', 1, 20, {
filter: 'status = true && created > "2022-08-01 10:00:00"'
});
// authenticate as regular user
const userData = await client.Users.authViaEmail("test@example.com", "123456");
const userData = await client.users.authViaEmail('test@example.com', '123456');
// or as admin
const adminData = await client.Admins.authViaEmail("test@example.com", "123456");
const adminData = await client.admins.authViaEmail('test@example.com', '123456');

@@ -90,10 +95,66 @@ // and much more...

#### File upload
PocketBase Web API supports file upload via `multipart/form-data` requests,
which means that to upload a file it is enough to provide a [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) object as body.
Here is a simple browser example of uploading multiple files together with some other regular fields:
```html
<input type="file" id="fileInput" />
```
```js
import PocketBase from 'pocketbase';
const client = new PocketBase('http://localhost:8090');
...
const formData = new FormData();
const fileInput = document.getElementById('fileInput');
// listen to file input changes and add the selected files to the form data
fileInput.addEventListener('change', function () {
for (let file of fileInput.files) {
formData.append('documents', file);
}
});
// set some other regular text field value
formData.append('title', 'Hello world!');
...
// upload and create new record
const createdRecord = await client.Records.create('example', formData);
```
#### Errors handling
Each request error response is wrapped and normalized in a `ClientResponseError` object with the following fields:
All services return a standard [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)-based response, so the error handling is straightforward:
```js
client.records.getList('example', 1, 50).then((result) {
// success...
console.log('Result:', result);
}).catch((error) {
// error...
console.log('Error:', error);
});
// OR if you are using the async/await syntax:
try {
const result = await client.records.getList('example', 1, 50);
console.log('Result:', result);
} catch (error) {
console.log('Error:', error);
}
```
The response error is normalized and always returned as `ClientResponseError` object with the following public fields that you could use:
```js
ClientResponseError {
url: string, // requested url
status: number, // response status code
data: { ... }, // the api json error response
data: { ... }, // the API JSON error response
isAbort: boolean, // is abort/cancellation error

@@ -104,11 +165,54 @@ originalError: Error|null, // the original non-normalized error

#### AuthStore
The SDK keeps track of the authenticated token and auth model for you via the `client.authStore` instance.
It has the following public members that you can use:
```js
AuthStore {
// fields
token: string // the authenticated token
model: User|Admin // the authenticated User or Admin model
isValid: boolean // checks if the store has existing and unexpired token
// methods
clear() // "logout" the authenticated User or Admin
save(token, model) // update the store with the new auth data
}
```
By default the SDK initialize a [`LocalAuthStore`](https://github.com/pocketbase/js-sdk/blob/master/src/stores/LocalAuthStore.ts), which uses the browser's `LocalStorage` if available, otherwise - will fallback to runtime/memory store (aka. on page refresh or service restart you'll have to authenticate again).
To _"logout"_ an authenticated user or admin, you can just call `client.authStore.clear()`.
To _"listen"_ for changes in the auth store, you can register a new listener via `client.authStore.onChange`, eg:
```js
const removeListener = client.authStore.onChange((token, model) => {
console.log('New store data:', token, model)
});
removeListener(); // (optional) removes the attached listener function
```
If you want to create your own `AuthStore`, you can extend [`BaseAuthStore`](https://github.com/pocketbase/js-sdk/blob/master/src/stores/BaseAuthStore.ts) and pass the new custom instance as constructor argument to the client:
```js
import PocketBase, { BaseAuthStore } from 'pocketbase';
class CustomAuthStore extends BaseAuthStore {
...
}
const client = new PocketBase('http://localhost:8090', 'en-US', CustomAuthStore());
```
#### Auto cancellation
The SDK client auto cancel duplicated pending requests.
The SDK client will auto cancel duplicated pending requests for you.
For example, if you have the following 3 duplicated calls, only the last one will be executed, while the first 2 will be cancelled with `ClientResponseError` error:
```js
client.Records.getList("demo", 1, 20) // cancelled
client.Records.getList("demo", 1, 20) // cancelled
client.Records.getList("demo", 1, 20) // executed
client.records.getList('example', 1, 20) // cancelled
client.records.getList('example', 1, 20) // cancelled
client.records.getList('example', 1, 20) // executed
```

@@ -124,8 +228,8 @@

```js
client.Records.getList("demo", 1, 20); // cancelled
client.Records.getList("demo", 1, 20); // executed
client.Records.getList("demo", 1, 20, { "$autoCancel": false }); // executed
client.Records.getList("demo", 1, 20, { "$autoCancel": false }) // executed
client.Records.getList("demo", 1, 20, { "$cancelKey": "test" }) // cancelled
client.Records.getList("demo", 1, 20, { "$cancelKey": "test" }) // executed
client.records.getList('example', 1, 20); // cancelled
client.records.getList('example', 1, 20); // executed
client.records.getList('example', 1, 20, { '$autoCancel': false }); // executed
client.records.getList('example', 1, 20, { '$autoCancel': false }) // executed
client.records.getList('example', 1, 20, { '$cancelKey': "test" }) // cancelled
client.records.getList('example', 1, 20, { '$cancelKey': "test" }) // executed
```

@@ -135,21 +239,38 @@

#### AuthStore
#### Send hooks
The SDK keeps track of the authenticated token and auth model for you via the `client.AuthStore` instance.
It has the following public fields that you can use:
Sometimes you may want to modify the request sent data or to cursomize the response.
```js
AuthStore {
token: string, // the authenticated token
model: User|Admin, // the authenticated User or Admin model
isValid: boolean, // checks if the store has existing and unexpired token
clear(), // "logout" the authenticated User or Admin
save(token, model), // update the store with the new auth data
}
```
To accomplish this, the SDK provides 2 function hooks:
By default the SDK initialize a `LocalAuthStore`, which uses the browser's `LocalStorage` if available, otherwise - will fallback to runtime/memory store (aka. on page refresh or service restart you'll have to authenticate again).
- `beforeSend` - triggered right before sending the `fetch` request, allowing you to inspect/modify the request config.
```js
const client = new PocketBase('http://localhost:8090');
To "logout" an authenticated user or admin, you can just call `client.AuthStore.clear()`.
client.beforeSend = function (url, reqConfig) {
// For list of the possible reqConfig properties check
// https://developer.mozilla.org/en-US/docs/Web/API/fetch#options
reqConfig.headers = Object.assign(reqConfig.headers, {
'X-Custom-Header': 'example',
});
return reqConfig;
};
```
- `afterSend` - triggered after successfully sending the `fetch` request, allowing you to inspect/modify the response object and its parsed data.
```js
const client = new PocketBase('http://localhost:8090');
client.afterSend = function (response, data) {
// do something with the response state
console.log(response.status);
return Object.assign(data, {
// extend the data...
"additionalField": 123,
});
};
```
## Definitions

@@ -187,53 +308,53 @@

| **[Admins](https://pocketbase.io/docs/api-admins)** | |
| 🔓`client.Admins.authViaEmail(email, password, bodyParams = {}, queryParams = {})` | Authenticate an admin account by its email and password and returns a new admin token and admin data. |
| 🔐`client.Admins.refresh(bodyParams = {}, queryParams = {})` | Refreshes the current admin authenticated instance and returns a new admin token and admin data. |
| 🔓`client.Admins.requestPasswordReset(email, bodyParams = {}, queryParams = {})` | Sends admin password reset request. |
| 🔓`client.Admins.confirmPasswordReset(passwordResetToken, password, passwordConfirm, bodyParams = {}, queryParams = {})` | Confirms admin password reset request. |
| 🔐`client.Admins.getList(page = 1, perPage = 30, queryParams = {})` | Returns paginated admins list. |
| 🔐`client.Admins.getFullList(batchSize = 100, queryParams = {})` | Returns a list with all admins batch fetched at once. |
| 🔐`client.Admins.getOne(id, queryParams = {})` | Returns single admin by its id. |
| 🔐`client.Admins.create(bodyParams = {}, queryParams = {})` | Creates a new admin. |
| 🔐`client.Admins.update(id, bodyParams = {}, queryParams = {})` | Updates an existing admin by its id. |
| 🔐`client.Admins.delete(id, bodyParams = {}, queryParams = {})` | Deletes an existing admin by its id. |
| 🔓`client.admins.authViaEmail(email, password, bodyParams = {}, queryParams = {})` | Authenticate an admin account by its email and password and returns a new admin token and admin data. |
| 🔐`client.admins.refresh(bodyParams = {}, queryParams = {})` | Refreshes the current admin authenticated instance and returns a new admin token and admin data. |
| 🔓`client.admins.requestPasswordReset(email, bodyParams = {}, queryParams = {})` | Sends admin password reset request. |
| 🔓`client.admins.confirmPasswordReset(passwordResetToken, password, passwordConfirm, bodyParams = {}, queryParams = {})` | Confirms admin password reset request. |
| 🔐`client.admins.getList(page = 1, perPage = 30, queryParams = {})` | Returns paginated admins list. |
| 🔐`client.admins.getFullList(batchSize = 100, queryParams = {})` | Returns a list with all admins batch fetched at once. |
| 🔐`client.admins.getOne(id, queryParams = {})` | Returns single admin by its id. |
| 🔐`client.admins.create(bodyParams = {}, queryParams = {})` | Creates a new admin. |
| 🔐`client.admins.update(id, bodyParams = {}, queryParams = {})` | Updates an existing admin by its id. |
| 🔐`client.admins.delete(id, bodyParams = {}, queryParams = {})` | Deletes an existing admin by its id. |
| **[Users](https://pocketbase.io/docs/api-users)** | |
| 🔓`client.Users.listAuthMethods(queryParams = {})` | Returns all available application auth methods. |
| 🔓`client.Users.authViaEmail(email, password, bodyParams = {}, queryParams = {})` | Authenticate a user account by its email and password and returns a new user token and user data. |
| 🔓`client.Users.authViaOAuth2(clientName, code, codeVerifier, redirectUrl, bodyParams = {}, queryParams = {})` | Authenticate a user via OAuth2 client provider. |
| 🔐`client.Users.refresh(bodyParams = {}, queryParams = {})` | Refreshes the current user authenticated instance and returns a new user token and user data. |
| 🔓`client.Users.requestPasswordReset(email, bodyParams = {}, queryParams = {})` | Sends user password reset request. |
| 🔓`client.Users.confirmPasswordReset(passwordResetToken, password, passwordConfirm, bodyParams = {}, queryParams = {})` | Confirms user password reset request. |
| 🔓`client.Users.requestVerification(email, bodyParams = {}, queryParams = {})` | Sends user verification email request. |
| 🔓`client.Users.confirmVerification(verificationToken, bodyParams = {}, queryParams = {})` | Confirms user email verification request. |
| 🔐`client.Users.requestEmailChange(newEmail, bodyParams = {}, queryParams = {})` | Sends an email change request to the authenticated user. |
| 🔓`client.Users.confirmEmailChange(emailChangeToken, password, bodyParams = {}, queryParams = {})` | Confirms user new email address. |
| 🔐`client.Users.getList(page = 1, perPage = 30, queryParams = {})` | Returns paginated users list. |
| 🔐`client.Users.getFullList(batchSize = 100, queryParams = {})` | Returns a list with all users batch fetched at once. |
| 🔐`client.Users.getOne(id, queryParams = {})` | Returns single user by its id. |
| 🔐`client.Users.create(bodyParams = {}, queryParams = {})` | Creates a new user. |
| 🔐`client.Users.update(id, bodyParams = {}, queryParams = {})` | Updates an existing user by its id. |
| 🔐`client.Users.delete(id, bodyParams = {}, queryParams = {})` | Deletes an existing user by its id. |
| 🔓`client.users.listAuthMethods(queryParams = {})` | Returns all available application auth methods. |
| 🔓`client.users.authViaEmail(email, password, bodyParams = {}, queryParams = {})` | Authenticate a user account by its email and password and returns a new user token and user data. |
| 🔓`client.users.authViaOAuth2(clientName, code, codeVerifier, redirectUrl, bodyParams = {}, queryParams = {})` | Authenticate a user via OAuth2 client provider. |
| 🔐`client.users.refresh(bodyParams = {}, queryParams = {})` | Refreshes the current user authenticated instance and returns a new user token and user data. |
| 🔓`client.users.requestPasswordReset(email, bodyParams = {}, queryParams = {})` | Sends user password reset request. |
| 🔓`client.users.confirmPasswordReset(passwordResetToken, password, passwordConfirm, bodyParams = {}, queryParams = {})` | Confirms user password reset request. |
| 🔓`client.users.requestVerification(email, bodyParams = {}, queryParams = {})` | Sends user verification email request. |
| 🔓`client.users.confirmVerification(verificationToken, bodyParams = {}, queryParams = {})` | Confirms user email verification request. |
| 🔐`client.users.requestEmailChange(newEmail, bodyParams = {}, queryParams = {})` | Sends an email change request to the authenticated user. |
| 🔓`client.users.confirmEmailChange(emailChangeToken, password, bodyParams = {}, queryParams = {})` | Confirms user new email address. |
| 🔐`client.users.getList(page = 1, perPage = 30, queryParams = {})` | Returns paginated users list. |
| 🔐`client.users.getFullList(batchSize = 100, queryParams = {})` | Returns a list with all users batch fetched at once. |
| 🔐`client.users.getOne(id, queryParams = {})` | Returns single user by its id. |
| 🔐`client.users.create(bodyParams = {}, queryParams = {})` | Creates a new user. |
| 🔐`client.users.update(id, bodyParams = {}, queryParams = {})` | Updates an existing user by its id. |
| 🔐`client.users.delete(id, bodyParams = {}, queryParams = {})` | Deletes an existing user by its id. |
| **[Realtime](https://pocketbase.io/docs/api-realtime)** <br/> _(for node environments you'll have to install an EventSource polyfill beforehand, eg. https://github.com/EventSource/eventsource)_ | |
| 🔓`client.Realtime.subscribe(subscription, callback)` | Inits the sse connection (if not already) and register the subscription. |
| 🔓`client.Realtime.unsubscribe(subscription = "")` | Unsubscribe from a subscription (if empty - unsubscibe from all registered subscriptions). |
| 🔓`client.realtime.subscribe(subscription, callback)` | Inits the sse connection (if not already) and register the subscription. |
| 🔓`client.realtime.unsubscribe(subscription = "")` | Unsubscribe from a subscription (if empty - unsubscibe from all registered subscriptions). |
| **[Collections](https://pocketbase.io/docs/api-collections)** | |
| 🔐`client.Collections.getList(page = 1, perPage = 30, queryParams = {})` | Returns paginated collections list. |
| 🔐`client.Collections.getFullList(batchSize = 100, queryParams = {})` | Returns a list with all collections batch fetched at once. |
| 🔐`client.Collections.getOne(id, queryParams = {})` | Returns single collection by its id. |
| 🔐`client.Collections.create(bodyParams = {}, queryParams = {})` | Creates a new collection. |
| 🔐`client.Collections.update(id, bodyParams = {}, queryParams = {})` | Updates an existing collection by its id. |
| 🔐`client.Collections.delete(id, bodyParams = {}, queryParams = {})` | Deletes an existing collection by its id. |
| 🔐`client.collections.getList(page = 1, perPage = 30, queryParams = {})` | Returns paginated collections list. |
| 🔐`client.collections.getFullList(batchSize = 100, queryParams = {})` | Returns a list with all collections batch fetched at once. |
| 🔐`client.collections.getOne(id, queryParams = {})` | Returns single collection by its id. |
| 🔐`client.collections.create(bodyParams = {}, queryParams = {})` | Creates a new collection. |
| 🔐`client.collections.update(id, bodyParams = {}, queryParams = {})` | Updates an existing collection by its id. |
| 🔐`client.collections.delete(id, bodyParams = {}, queryParams = {})` | Deletes an existing collection by its id. |
| **[Records](https://pocketbase.io/docs/api-records)** | |
| 🔓`client.Records.getList(collectionIdOrName, page = 1, perPage = 30, queryParams = {})` | Returns paginated records list. |
| 🔓`client.Records.getFullList(collectionIdOrName, batchSize = 100, queryParams = {})` | Returns a list with all records batch fetched at once. |
| 🔓`client.Records.getOne(collectionIdOrName, id, queryParams = {})` | Returns single record by its id. |
| 🔓`client.Records.create(collectionIdOrName, bodyParams = {}, queryParams = {})` | Creates a new record. |
| 🔓`client.Records.update(collectionIdOrName, id, bodyParams = {}, queryParams = {})` | Updates an existing record by its id. |
| 🔓`client.Records.delete(collectionIdOrName, id, bodyParams = {}, queryParams = {})` | Deletes an existing record by its id. |
| 🔓`client.records.getList(collectionIdOrName, page = 1, perPage = 30, queryParams = {})` | Returns paginated records list. |
| 🔓`client.records.getFullList(collectionIdOrName, batchSize = 100, queryParams = {})` | Returns a list with all records batch fetched at once. |
| 🔓`client.records.getOne(collectionIdOrName, id, queryParams = {})` | Returns single record by its id. |
| 🔓`client.records.create(collectionIdOrName, bodyParams = {}, queryParams = {})` | Creates a new record. |
| 🔓`client.records.update(collectionIdOrName, id, bodyParams = {}, queryParams = {})` | Updates an existing record by its id. |
| 🔓`client.records.delete(collectionIdOrName, id, bodyParams = {}, queryParams = {})` | Deletes an existing record by its id. |
| **[Logs](https://pocketbase.io/docs/api-logs)** | |
| 🔐`client.Logs.getRequestsList(page = 1, perPage = 30, queryParams = {})` | Returns paginated request logs list. |
| 🔐`client.Logs.getRequest(id, queryParams = {})` | Returns a single request log by its id. |
| 🔐`client.Logs.getRequestsStats(queryParams = {})` | Returns request logs statistics. |
| 🔐`client.logs.getRequestsList(page = 1, perPage = 30, queryParams = {})` | Returns paginated request logs list. |
| 🔐`client.logs.getRequest(id, queryParams = {})` | Returns a single request log by its id. |
| 🔐`client.logs.getRequestsStats(queryParams = {})` | Returns request logs statistics. |
| **[Settings](https://pocketbase.io/docs/api-records)** | |
| 🔐`client.Settings.getAll(queryParams = {})` | Fetch all available app settings. |
| 🔐`client.Settings.update(bodyParams = {}, queryParams = {})` | Bulk updates app settings. |
| 🔐`client.settings.getAll(queryParams = {})` | Fetch all available app settings. |
| 🔐`client.settings.update(bodyParams = {}, queryParams = {})` | Bulk updates app settings. |

@@ -240,0 +361,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc