PageSourceSearch

https://bitsofbrand.com/assets/pocketbase-client-CicLDX7G.js

js bitsofbrand.com collected 2026-10-08 13:10:14 UTC 38,434 bytes, 1 lines download raw bytes

1class h extends Error{constructor(e){super("ClientResponseError"),this.url="",this.status=0,this.response={},this.isAbort=!1,this.originalError=null,Object.setPrototypeOf(this,h.prototype),e!==null&&typeof e=="object"&&(this.originalError=e.originalError,this.url=typeof e.url=="string"?e.url:"",this.status=typeof e.status=="number"?e.status:0,this.isAbort=!!e.isAbort||e.name==="AbortError"||e.message==="Aborted",e.response!==null&&typeof e.response=="object"?this.response=e.response:e.data!==null&&typeof e.data=="object"?this.response=e.data:this.response={}),this.originalError||e instanceof h||(this.originalError=e),this.name="ClientResponseError "+this.status,this.message=this.response?.message,this.message||(this.isAbort?this.message="The request was aborted (most likely autocancelled; you can find more info in https://github.com/pocketbase/js-sdk#auto-cancellation).":this.originalError?.cause?.message?.includes("ECONNREFUSED ::1")?this.message="Failed to connect to the PocketBase server. Try changing the SDK URL from localhost to 127.0.0.1 (https://github.com/pocketbase/js-sdk/issues/21).":this.message="Something went wrong."),this.cause=this.originalError}get data(){return this.response}toJSON(){return{...this}}}const v=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;function B(o,e){const t={};if(typeof o!="string")return t;const s=Object.assign({},{}).decode||$;let i=0;for(;i<o.length;){const n=o.indexOf("=",i);if(n===-1)break;let r=o.indexOf(";",i);if(r===-1)r=o.length;else if(r<n){i=o.lastIndexOf(";",n-1)+1;continue}const a=o.slice(i,n).trim();if(t[a]===void 0){let c=o.slice(n+1,r).trim();c.charCodeAt(0)===34&&(c=c.slice(1,-1));try{t[a]=s(c)}catch{t[a]=c}}i=r+1}return t}function A(o,e,t){const s=Object.assign({},t||{}),i=s.encode||J;if(!v.test(o))throw new TypeError("argument name is invalid");const n=i(e);if(n&&!v.test(n))throw new TypeError("argument val is invalid");let r=o+"="+n;if(s.maxAge!=null){const a=s.maxAge-0;if(isNaN(a)||!isFinite(a))throw new TypeError("option maxAge is invalid");r+="; Max-Age="+Math.floor(a)}if(s.domain){if(!v.test(s.domain))throw new TypeError("option domain is invalid");r+="; Domain="+s.domain}if(s.path){if(!v.test(s.path))throw new TypeError("option path is invalid");r+="; Path="+s.path}if(s.expires){if(!(function(c){return Object.prototype.toString.call(c)==="[object Date]"||c instanceof Date})(s.expires)||isNaN(s.expires.valueOf()))throw new TypeError("option expires is invali
1d");r+="; Expires="+s.expires.toUTCString()}if(s.httpOnly&&(r+="; HttpOnly"),s.secure&&(r+="; Secure"),s.priority)switch(typeof s.priority=="string"?s.priority.toLowerCase():s.priority){case"low":r+="; Priority=Low";break;case"medium":r+="; Priority=Medium";break;case"high":r+="; Priority=High";break;default:throw new TypeError("option priority is invalid")}if(s.sameSite)switch(typeof s.sameSite=="string"?s.sameSite.toLowerCase():s.sameSite){case!0:r+="; SameSite=Strict";break;case"lax":r+="; SameSite=Lax";break;case"strict":r+="; SameSite=Strict";break;case"none":r+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}return r}function $(o){return o.indexOf("%")!==-1?decodeURIComponent(o):o}function J(o){return encodeURIComponent(o)}const G=typeof navigator<"u"&&navigator.product==="ReactNative"||typeof global<"u"&&global.HermesInternal;let x;function O(o){if(o)try{const e=decodeURIComponent(x(o.split(".")[1]).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(e)||{}}catch{}return{}}function _(o,e=0){let t=O(o);return!(Object.keys(t).length>0&&(!t.exp||t.exp-e>Date.now()/1e3))}x=typeof atob!="function"||G?o=>{let e=String(o).replace(/=+$/,"");if(e.length%4==1)throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");for(var t,s,i=0,n=0,r="";s=e.charAt(n++);~s&&(t=i%4?64*t+s:s,i++%4)?r+=String.fromCharCode(255&t>>(-2*i&6)):0)s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(s);return r}:atob;const q="pb_auth";class k{constructor(){this.baseToken="",this.baseModel=null,this._onChangeCallbacks=[]}get token(){return this.baseToken}get record(){return this.baseModel}get model(){return this.baseModel}get isValid(){return!_(this.token)}get isSuperuser(){let e=O(this.token);return e.type=="auth"&&(this.record?.collectionName=="_superusers"||!this.record?.collectionName&&e.collectionId=="pbc_3142635823")}get isAdmin(){return console.warn("Please replace pb.authStore.isAdmin with pb.authStore.isSuperuser OR simply check the value of pb.authStore.record?.collectionName"),this.isSuperuser}get isAuthRecord(){return console.warn("Please replace pb.authStore.isAuthRecord with !pb.authStore.isSuperuser OR simply check the value of pb.authStore.record?.collectionName"),O(this.token).type=="auth"&&!this.isSuperuser}save(e,t){this.baseToken=e||"",this.baseModel=t||null,this.triggerChange()}clear(){this.baseToken="",this.baseModel=null,this.triggerChange()}loadFromCookie(e,t=q){const s=B(e||"")[t]||"";let i={};try{i=JSON.parse(s),(typeof i===null||typeof i!="object"||Array.isArray(i))&&(i={})}catch{}this.save(i.token||"",i.record||i.model||null)}exportToCookie(e,t=q){const s={secure:!0,sameSite:!0,httpOnly:!0,path:"/"},i=O(this.token);s.expires=i?.exp?new Date(1e3*i.exp):new Date("1970-01-01"),e=Object.assign({},s,e);const n={token:this.token,record:this.record?JSON.parse(JSON.stringify(this.record)):null};let r=A(t,JSON.stringify(n),e);const a=typeof Blob<"u"?new Blob([r]).size:r.length;if(n.record&&a>4096){n.record={id:n.record?.id,email:n.record?.email};const c=["collectionId","collectionName","verified"];for(const l in this.record)c.includes(l)&&(n.record[l]=this.record[l]);r=A(t,JSON.stringify(n),e)}return r}onChange(e,t=!1){return this._onChangeCallbacks.push(e),t&&e(this.token,this.record),()=>{for(let s=this._onChangeCallbacks.length-1;s>=0;s--)if(this._onChangeCallbacks[s]==e)return delete this._onChangeCallbacks[s],void this._onChangeCallbacks.splice(s,1)}}triggerChange(){for(const e of this._onChangeCallbacks)e&&e(this.token,this.record)}}class H extends k{constructor(e="pocketbase_auth"){super(),this.storageFallback={},this.storageKey=e,this._bindStorageEvent()}get token(){return(this._storageGet(this.storageKey)||{}).token||""}get record(){const e=this._storageGet(this.storageKey)||{};return e.record||e.model||null}get model(){return this.record}save(e,t){this._storageSet(this.storageKey,{token:e,record:t}),super.save(e,t)}clear(){this._storageRemove(this.storageKey),super.clear()}_storageGet(e){if(typeof window<"u"&&window?.localStorage){const t=window.localStorage.getItem(e)||"";try{return JSON.parse(t)}catch{return t}}return this.storageFallback[e]}_storageSet(e,t){if(typeof window<"u"&&window?.localStorage){let s=t;typeof t!="string"&&(s=JSON.stringify(t)),window.localStorage.setItem(e,s)}else this.storageFallback[e]=t}_storageRemove(e){typeof window<"u"&&window?.localStorage&&window.localStorage?.removeItem(e),delete this.storageFallback[e]}_bindStorageEvent(){typeof window<"u"&&window?.localStorage&&window.addEventListener&&window.addEventListener("storage",(e=>{if(e.key!=this.storageKey)return;const t=this._storageGet(this.storageKey)||{};super.save(t.token||"",t.record||t.model||null)}))}}class b{constructor(e){this.client=e}}class M extends b{async getAll(e){return e=Object.assign({method:"GET"},e),this.client.send("/api/settings",e)}async update(e,t){return t=Object.assign({method:"PATCH",body:e},t),this.client.send("/api/settings",t)}async testS3(e="storage",t){return t=Object.assign({method:"POST",body:{filesystem:e}},t),this.client.send("/api/settings/test/s3",t).then((()=>!0))}async testEmail(e,t,s,i){return i=Object.assign({method:"POST",body:{email:t,template:s,collection:e}},i),this.client.send("/api/settings/test/email",i).then((()=>!0))}async generateAppleClientSecret(e,t,s,i,n,r){return r=Object.assign({method:"POST",body:{clientId:e,teamId:t,keyId:s,privateKey:i,duration:n}},r),this.client.send("/api/settings/apple/generate-client-secret",r)}}const V=["requestKey","$cancelKey","$autoCancel","fetch","headers","body","query","params","cache","credentials","headers","integrity","keepalive","method","mode","redirect","referrer","referrerPolicy","signal","window"];function I(o){if(o){o.query=o.query||{};for(let e in o)V.includes(e)||(o.query[e]=o[e],delete o[e])}}function E(o){const e=[];for(const t in o){const s=encodeURIComponent(t),i=Array.isArray(o[t])?o[t]:[o[t]];for(let n of i)n=z(n),n!==null&&e.push(s+"="+n)}return e.join("&")}function z(o){return o==null?null:o instanceof Date?encodeURIComponent(o.toISOString().replace("T"," ")):encodeURIComponent(typeof o=="object"?JSON.stringify(o):o)}class D extends b{constructor(){super(...arguments),this.clientId="",this.eventSource=null,this.subscriptions={},this.lastSentSubscriptions=[],this.maxConnectTimeout=15e3,this.reconnectAttempts=0,this.maxReconnectAttempts=1/0,this.predefinedReconnectIntervals=[200,300,500,1e3,1200,1500,2e3],this.pendingConnects=[],this.pendingSubmits=[],this.isProcessingPendingSubmits=!1}get isConnected(){return!!this.eventSource&&!!this.clientId&&!this.pendingConnects.length}
vendor: 20,996 bytes, line 1
1async subscribe(e,t,s){if(!e)throw new Error("topic must be set.");let i=e;if(s){I(s=Object.assign({},s));const r="options="+encodeURIComponent(JSON.stringify({query:s.query,headers:s.headers}));i+=(i.includes("?")?"&":"?")+r}const n=function(r){const a=r;let c;try{c=JSON.parse(a?.data)}catch{}t(c||{})};return this.subscriptions[i]||(this.subscriptions[i]=[]),this.subscriptions[i].push(n),this.isConnected?this.subscriptions[i].length===1?await this.submitSubscriptions():this.eventSource?.addEventListener(i,n):await this.connect(),async()=>this.unsubscribeByTopicAndListener(e,n)}async unsubscribe(e){if(e){const t=this.getSubscriptionsByTopic(e);for(let s in t)if(this.hasSubscriptionListeners(s)){for(let i of this.subscriptions[s])this.eventSource?.removeEventListener(s,i);delete this.subscriptions[s]}}else this.subscriptions={};await this.submitSubscriptions()}async unsubscribeByPrefix(e){let t=!1;for(let s in this.subscriptions)if((s+"?").startsWith(e)){t=!0;for(let i of this.subscriptions[s])this.eventSource?.removeEventListener(s,i);delete this.subscriptions[s]}t&&await this.submitSubscriptions()}async unsubscribeByTopicAndListener(e,t){const s=this.getSubscriptionsByTopic(e);for(let i in s){if(!Array.isArray(this.subscriptions[i])||!this.subscriptions[i].length)continue;let n=!1;for(let r=this.subscriptions[i].length-1;r>=0;r--)this.subscriptions[i][r]===t&&(n=!0,delete this.subscriptions[i][r],this.subscriptions[i].splice(r,1),this.eventSource?.removeEventListener(i,t));n&&(this.subscriptions[i].length||delete this.subscriptions[i])}await this.submitSubscriptions()}hasSubscriptionListeners(e){if(this.subscriptions=this.subscriptions||{},e)return!!this.subscriptions[e]?.length;for(let t in this.subscriptions)if(this.subscriptions[t]?.length)return!0;return!1}async submitSubscriptions(){return new Promise(((e,t)=>{this.pendingSubmits.push({resolve:e,reject:t}),this.pendingSubmits.length==1&&queueMicrotask((()=>this.finalizePendingSubscriptions()))}))}async finalizePendingSubscriptions(){if(this.isProcessingPendingSubmits||!this.pendingSubmits.length)return;const e=this.pendingSubmits.slice();this.pendingSubmits=[],this.isProcessingPendingSubmits=!0;try{await this.sendSubscriptions();for(let t of e)t.resolve()}catch(t){for(let s of e)t?s.reject(t):s.resolve()}finally{this.isProcessingPendingSubmits=!1,this.pendingSubmits.length>0&&await this.finalizePendingSubscriptions()}}getSubscriptionsCancelKey(){return"realtime_"+this.clientId}getSubscriptionsByTopic(e){const t={};e=e.includes("?")?e:e+"?";for(let s in this.subscriptions)(s+"?").startsWith(e)&&(t[s]=this.subscriptions[s]);return t}getNonEmptySubscriptionKeys(){const e=[];for(let t in this.subscriptions)this.subscriptions[t].length&&e.push(t);return e}hasUnsentSubscriptions(){const e=this.getNonEmptySubscriptionKeys();if(e.length!=this.lastSentSubscriptions.length)return!0;for(const t of e)if(!this.lastSentSubscriptions.includes(t))return!0;return!1}async sendSubscriptions(){if(this.clientId){if(!this.hasSubscriptionListeners())return this.disconnect();if(this.hasUnsentSubscriptions())return this.addAllSubscriptionListeners(),this.lastSentSubscriptions=this.getNonEmptySubscriptionKeys(),this.client.send("/api/realtime",{method:"POST",body:{clientId:this.clientId,subscriptions:this.lastSentSubscriptions},requestKey:this.getSubscriptionsCancelKey()}).catch((e=>{if(!e?.isAbort)throw e}))}}addAllSubscriptionListeners(){if(this.eventSource){this.removeAllSubscriptionListeners();for(let e in this.subscriptions)for(let t of this.subscriptions[e])this.eventSource.addEventListener(e,t)}}removeAllSubscriptionListeners(){if(this.eventSource)for(let e in this.subscriptions)for(let t of this.subscriptions[e])this.eventSource.removeEventListener(e,t)}async connect(){if(!(this.reconnectAttempts>0))return new Promise(((e,t)=>{this.pendingConnects.push({resolve:e,reject:t}),this.pendingConnects.length==1&&queueMicrotask((()=>this.initConnect()))}))}initConnect(){this.disconnect(!0),clearTimeout(this.connectTimeoutId),this.connectTimeoutId=setTimeout((()=>{this.connectErrorHandler(new Error("EventSource connect took too long."))}),this.maxConnectTimeout),this.eventSource=new EventSource(this.client.buildURL("/api/realtime")),this.eventSource.onerror=e=>{this.connectErrorHandler(new Error("Failed to establish realtime connection."))},this.eventSource.addEventListener("PB_CONNECT",(e=>{const t=e;this.clientId=t?.lastEventId,this.lastSentSubscriptions=[],this.submitSubscriptions().then((async()=>{let s=3;for(;this.hasUnsentSubscriptions()&&s>0;)s--,await this.submitSubscriptions();for(let n of this.pendingConnects)n.resolve();this.pendingConnects=[],this.reconnectAttempts=0,clearTimeout(this.reconnectTimeoutId),clearTimeout(this.connectTimeoutId);const i=this.getSubscriptionsByTopic("PB_CONNECT");for(let n in i)for(let r of i[n])r(e);this.hasUnsentSubscriptions()&&await this.submitSubscriptions()})).catch((s=>{this.clientId="",this.lastSentSubscriptions=[],this.connectErrorHandler(s)}))}))}connectErrorHandler(e){if(clearTimeout(this.connectTimeoutId),clearTimeout(this.reconnectTimeoutId),!this.clientId&&!this.reconnectAttempts||this.reconnectAttempts>this.maxReconnectAttempts){for(let s of this.pendingConnects)s.reject(new h(e));return this.pendingConnects=[],void this.disconnect()}this.disconnect(!0);const t=this.predefinedReconnectIntervals[this.reconnectAttempts]||this.predefinedReconnectIntervals[this.predefinedReconnectIntervals.length-1];this.reconnectAttempts++,this.reconnectTimeoutId=setTimeout((()=>{this.initConnect()}),t)}disconnect(e=!1){if(this.clientId&&this.onDisconnect&&this.onDisconnect(Object.keys(this.subscriptions)),clearTimeout(this.connectTimeoutId),clearTimeout(this.reconnectTimeoutId),this.removeAllSubscriptionListeners(),this.client.cancelRequest(this.getSubscriptionsCancelKey()),this.eventSource?.close(),this.eventSource=null,this.clientId="",this.lastSentSubscriptions=[],!e){this.reconnectAttempts=0;for(let t of this.pendingConnects)t.resolve();this.pendingConnects=[]}}}class F extends b{decode(e){return e}async getFullList(e,t){if(typeof e=="number")return this._getFullList(e,t);let s=1e3;return(t=Object.assign({},e,t)).batch&&(s=t.batch,delete t.batch),this._getFullList(s,t)}async getList(e=1,t=30,s){return(s=Object.assign({method:"GET"},s)).query=Object.assign({page:e,perPage:t},s.query),this.client.send(this.baseCrudPath,s).then((i=>(i.items=i.items?.map((n=>this.decode(n)))||[],i)))}async getFirstListItem(e,t){return(t=Object.assign({requestKey:"one_by_filter_"+this.baseCrudPath+"_"+e},t)).query=Object.assign({filter:e,skipTotal:1},t.query),this.getList(1,1,t).then((s=>{if(!s?.items?.length)throw new h({status:404,response:{code:404,message:"The requested resource wasn't found.",data:{}}});return s.items[0]}))}async getOne(e,t){if(!e)throw new h({url:this.client.buildURL(this.baseCrudPath+"/"),status:404,response:{code:404,message:"Missing required record id.",data:{}}});return t=Object.assign({method:"GET"},t),this.client.send(this.baseCrudPath+"/"+encodeURIComponent(e),t).then((s=>this.decode(s)))}async create(e,t){return t=Object.assign({method:"POST",body:e},t),this.client.send(this.baseCrudPath,t).then((s=>this.decode(s)))}async update(e,t,s){return s=Object.assign({method:"PATCH",body:t},s),this.client.send(this.baseCrudPath+"/"+encodeURIComponent(e),s).then((i=>this.decode(i)))}async delete(e,t){return t=Object.assign({method:"DELETE"},t),this.client.send(this.baseCrudPath+"/"+encodeURIComponent(e),t).then((()=>!0))}_getFullList(e=1e3,t){(t=t||{}).query=Object.assign({skipTotal:1},t.query);let s=[],i=async n=>this.getList(n,e||1e3,t).then((r=>{const a=r.items;return s=s.concat(a),a.length==r.perPage?i(n+1):s}));return i(1)}}function S(o,e,t,s){const i=s!==void 0;return i||t!==void 0?i?(console.warn(o),e.body=Object.assign({},e.body,t),e.query=Object.assign({},e.query,s),e):Object.assign(e,t):e}function R(o){o._resetAutoRefresh?.()}class Q extends F{constructor(e,t){super(e),this.collectionIdOrName=t}get baseCrudPath(){return this.baseCollectionPath+"/records"}get baseCollectionPath(){return"/api/collections/"+encodeURIComponent(this.collectionIdOrName)}get isSuperusers(){return this.collectionIdOrName=="_superusers"||this.collectionIdOrName=="_pbc_2773867675"}async subscribe(e,t,s){if(!e)throw new Error("Missing topic.");if(!t)throw new Error("Missing subscription callback.");return this.client.realtime.subscribe(this.collectionIdOrName+"/"+e,t,s)}async unsubscribe(e){return e?this.client.realtime.unsubscribe(this.collectionIdOrName+"/"+e):this.client.realtime.unsubscribeByPrefix(this.collectionIdOrName)}async getFullList(e,t){if(typeof e=="number")return super.getFullList(e,t);const s=Object.assign({},e,t);return super.getFullList(s)}async getList(e=1,t=30,s){return super.getList(e,t,s)}async getFirstListItem(e,t){return super.getFirstListItem(e,t)}async getOne(e,t){return super.getOne(e,t)}async create(e,t){return super.create(e,t)}async update(e,t,s){return super.update(e,t,s).then((i=>{if(this.client.authStore.record?.id===i?.id&&(this.client.authStore.record?.collectionId===this.collectionIdOrName||this.client.authStore.record?.collectionName===this.collectionIdOrName)){let n=Object.assign({},this.client.authStore.record.expand),r=Object.assign({},this.client.authStore.record,i);n&&(r.expand=Object.assign(n,i.expand)),this.client.authStore.save(this.client.authStore.token,r)}return i}))}async delete(e,t){return super.delete(e,t).then((s=>(!s||this.client.authStore.record?.id!==e||this.client.authStore.record?.collectionId!==this.collectionIdOrName&&this.client.authStore.record?.collectionName!==this.collectionIdOrName||this.client.authStore.clear(),s)))}authResponse(e){const t=this.decode(e?.record||{});return this.client.authStore.save(e?.token,t),Object.assign({},e,{token:e?.token||"",record:t})}async listAuthMethods(e){return e=Object.assign({method:"GET",fields:"mfa,otp,password,oauth2"},e),this.client.send(this.baseCollectionPath+"/auth-methods",e)}async authWithPassword(e,t,s){let i;s=Object.assign({method:"POST",body:{identity:e,password:t}},s),this.isSuperusers&&(i=s.autoRefreshThreshold,delete s.autoRefreshThreshold,s.autoRefresh||R(this.client));let n=await this.client.send(this.baseCollectionPath+"/auth-with-password",s);return n=this.authResponse(n),i&&this.isSuperusers&&(function(a,c,l,C){R(a);const g=a.beforeSend,m=a.authStore.record,y=a.authStore.onChange(((u,d)=>{(!u||d?.id!=m?.id||(d?.collectionId||m?.collectionId)&&d?.collectionId!=m?.collectionId)&&R(a)}));a._resetAutoRefresh=function(){y(),a.beforeSend=g,delete a._resetAutoRefresh},a.beforeSend=async(u,d)=>{const j=a.authStore.token;if(d.query?.autoRefresh)return g?g(u,d):{url:u,sendOptions:d};let p=a.authStore.isValid;if(p&&_(a.authStore.token,c))try{await l()}catch{p=!1}p||await C();const w=d.headers||{};for(let f in w)if(f.toLowerCase()=="authorization"&&j==w[f]&&a.authStore.token){w[f]=a.authStore.token;break}return d.headers=w,g?g(u,d):{url:u,sendOptions:d}}})(this.client,i,(()=>this.authRefresh({autoRefresh:!0})),(()=>this.authWithPassword(e,t,Object.assign({autoRefresh:!0},s)))),n}async authWithOAuth2Code(e,t,s,i,n,r,a){let c={method:"POST",body:{provider:e,code:t,codeVerifier:s,redirectURL:i,createData:n}};return c=S("This form of authWithOAuth2Code(provider, code, codeVerifier, redirectURL, createData?, body?, query?) is deprecated. Consider replacing it with authWithOAuth2Code(provider, code, codeVerifier, redirectURL, createData?, options?).",c,r,a),this.client.send(this.baseCollectionPath+"/auth-with-oauth2",c).then((l=>this.authResponse(l)))}authWithOAuth2(...e){if(e.length>1||typeof e?.[0]=="string")return console.warn("PocketBase: This form of authWithOAuth2() is deprecated and may get removed in the future. Please replace with authWithOAuth2Code() OR use the authWithOAuth2() realtime form as shown in https://pocketbase.io/docs/authentication/#oauth2-integration."),this.authWithOAuth2Code(e?.[0]||"",e?.[1]||"",e?.[2]||"",e?.[3]||"",e?.[4]||{},e?.[5]||{},e?.[6]||{});const t=e?.[0]||{};let s=null;t.urlCallback||(s=L(void 0));const i=new D(this.client);function n(){s?.close(),i.unsubscribe()}const r={},a=t.requestKey;return a&&(r.requestKey=a),this.listAuthMethods(r).then((c=>{const l=c.oauth2.providers.find((g=>g.name===t.provider));if(!l)throw new h(new Error(`Missing or invalid provider "${t.provider}".`));const C=this.client.buildURL("/api/oauth2-redirect");return new Promise((async(g,m)=>{const y=a?this.client.cancelControllers?.[a]:void 0;y&&(y.signal.onabort=()=>{n(),m(new h({isAbort:!0,message:"manually cancelled"}))}),i.onDisconnect=u=>{u.length&&m&&(n(),m(new h(new Error("realtime connection interrupted"))))};try{await i.subscribe("@oauth2",(async p=>{const w=i.clientId;try{if(!p.state||w!==p.state)throw new Error("State parameters don't match.");if(p.error||!p.code)throw new Error("OAuth2 redirect error or missing code: "+p.error);const f=Object.assign({},t);delete f.provider,delete f.scopes,delete f.createData,delete f.urlCallback,y?.signal?.onabort&&(y.signal.onabort=null);const W=await this.authWithOAuth2Code(l.name,p.code,l.codeVerifier,C,t.createData,f);g(W)}catch(f){m(new h(f))}n()}));const u={state:i.clientId};t.scopes?.length&&(u.scope=t.scopes.join(" "));const d=this._replaceQueryParams(l.authURL+C,u);await(t.urlCallback||function(p){s?s.location.href=p:s=L(p)})(d)}catch(u){y?.signal?.onabort&&(y.signal.onabort=null),n(),m(new h(u))}}))})).catch((c=>{throw n(),c}))}async authRefresh(e,t){let s={method:"POST"};return s=S("This form of authRefresh(body?, query?) is deprecated. Consider replacing it with authRefresh(options?).",s,e,t),this.client.send(this.baseCollectionPath+"/auth-refresh",s).then((i=>this.authResponse(i)))}async requestPasswordReset(e,t,s){let i={method:"POST",body:{email:e}};return i=S("This form of requestPasswordReset(email, body?, query?) is deprecated. Consider replacing it with requestPasswordReset(email, options?).",i,t,s),this.client.send(this.baseCollectionPath+"/request-password-reset",i).then((()=>!0))}async confirmPasswordReset(e,t,s,i,n){let r={method:"POST",body:{token:e,password:t,passwordConfirm:s}};return r=S("This form of confirmPasswordReset(token, password, passwordConfirm, body?, query?) is deprecated. Consider replacing it with confirmPasswordReset(token, password, passwordConfirm, options?).",r,i,n),this.client.send(this.baseCollectionPath+"/confirm-password-reset",r).then((()=>!0))}async requestVerification(e,t,s){let i={method:"POST",body:{email:e}};return i=S("This form of requestVerification(email, body?, query?) is deprecated. Consider replacing it with requestVerification(email, options?).",i,t,s),this.client.send(this.baseCollectionPath+"/request-verification",i).then((()=>!0))}async confirmVerification(e,t,s){let i={method:"POST",body:{token:e}};return i=S("This form of confirmVerification(token, body?, query?) is deprecated. Consider replacing it with confirmVerification(token, options?).",i,t,s),this.client.send(this.baseCollectionPath+"/confirm-verification",i).then((()=>{const n=O(e),r=this.client.authStore.record;return r&&!r.verified&&r.id===n.id&&r.collectionId===n.collectionId&&(r.verified=!0,this.client.authStore.save(this.client.authStore.token,r)),!0}))}async requestEmailChange(e,t,s){let i={method:"POST",body:{newEmail:e}};return i=S("This form of requestEmailChange(newEmail, body?, query?) is deprecated. Consider replacing it with requestEmailChange(newEmail, options?).",i,t,s),this.client.send(this.baseCollectionPath+"/request-email-change",i).then((()=>!0))}async confirmEmailChange(e,t,s,i){let n={method:"POST",body:{token:e,password:t}};return n=S("This form of confirmEmailChange(token, password, body?, query?) is deprecated. Consider replacing it with confirmEmailChange(token, password, options?).",n,s,i),this.client.send(this.baseCollectionPath+"/confirm-email-change",n).then((()=>{const r=O(e),a=this.client.authStore.record;return a&&a.id===r.id&&a.collectionId===r.collectionId&&this.client.authStore.clear(),!0}))}async listExternalAuths(e,t){return this.client.collection("_externalAuths").getFullList(Object.assign({},t,{filter:this.client.filter("recordRef = {:id}",{id:e})}))}async unlinkExternalAuth(e,t,s){const i=await this.client.collection("_externalAuths").getFirstListItem(this.client.filter("recordRef = {:recordId} && provider = {:provider}",{recordId:e,provider:t}));return this.client.collection("_externalAuths").delete(i.id,s).then((()=>!0))}async requestOTP(e,t){return t=Object.assign({method:"POST",body:{email:e}},t),this.client.send(this.baseCollectionPath+"/request-otp",t)}async authWithOTP(e,t,s){return s=Object.assign({method:"POST",body:{otpId:e,password:t}},s),this.client.send(this.baseCollectionPath+"/auth-with-otp",s).then((i=>this.authResponse(i)))}async impersonate(e,t,s){(s=Object.assign({method:"POST",body:{duration:t}},s)).headers=s.headers||{},s.headers.Authorization||(s.headers.Authorization=this.client.authStore.token);const i=new K(this.client.baseURL,new k,this.client.lang),n=await i.send(this.baseCollectionPath+"/impersonate/"+encodeURIComponent(e),s);return i.authStore.save(n?.token,this.decode(n?.record||{})),i}_replaceQueryParams(e,t={}){let s=e,i="";e.indexOf("?")>=0&&(s=e.substring(0,e.indexOf("?")),i=e.substring(e.indexOf("?")+1));const n={},r=i.split("&");for(const a of r){if(a=="")continue;const c=a.split("=");n[decodeURIComponent(c[0].replace(/\+/g," "))]=decodeURIComponent((c[1]||"").replace(/\+/g," "))}for(let a in t)t.hasOwnProperty(a)&&(t[a]==null?delete n[a]:n[a]=t[a]);i="";for(let a in n)n.hasOwnProperty(a)&&(i!=""&&(i+="&"),i+=encodeURIComponent(a.replace(/%20/g,"+"))+"="+encodeURIComponent(n[a].replace(/%20/g,"+")));return i!=""?s+"?"+i:s}}function L(o){if(typeof window>"u"||!window?.open)throw new h(new Error("Not in a browser context - please pass a custom urlCallback function."));let e=1024,t=768,s=window.innerWidth,i=window.innerHeight;e=e>s?s:e,t=t>i?i:t;let n=s/2-e/2,r=i/2-t/2;return window.open(o,"popup_window","width="+e+",height="+t+",top="+r+",left="+n+",resizable,menubar=no")}class X extends F{get baseCrudPath(){return"/api/collections"}async import(e,t=!1,s){return s=Object.assign({method:"PUT",body:{collections:e,deleteMissing:t}},s),this.client.send(this.baseCrudPath+"/import",s).then((()=>!0))}async truncate(e,t){return t=Object.assign({method:"DELETE"},t),this.client.send(this.baseCrudPath+"/"+encodeURIComponent(e)+"/truncate",t).then((()=>!0))}async getScaffolds(e){return e=Object.assign({method:"GET"},e),this.client.send(this.baseCrudPath+"/meta/scaffolds",e)}async getAllOAuth2Providers(e){return e=Object.assign({method:"GET"},e),this.client.send(this.baseCrudPath+"/meta/oauth2-providers",e)}async dryRunViewQuery(e,t){return t=Object.assign({method:"POST",body:{query:e}},t),this.client.send(this.baseCrudPath+"/meta/dry-run-view",t)}}class Y extends b{async getList(e=1,t=30,s){return(s=Object.assign({method:"GET"},s)).query=Object.assign({page:e,perPage:t},s.query),this.client.send("/api/logs",s)}async getOne(e,t){if(!e)throw new h({url:this.client.buildURL("/api/logs/"),status:404,response:{code:404,message:"Missing required log id.",data:{}}});return t=Object.assign({method:"GET"},t),this.client.send("/api/logs/"+encodeURIComponent(e),t)}async getStats(e){return e=Object.assign({method:"GET"},e),this.client.send("/api/logs/stats",e)}async truncate(e){return e=Object.assign({method:"DELETE"},e),this.client.send("/api/logs",e).then((()=>!0))}}class Z extends b{async check(e){return e=Object.assign({method:"GET"},e),this.client.send("/api/health",e)}}class ee extends b{getUrl(e,t,s={}){return console.warn("Please replace pb.files.getUrl() with pb.files.getURL()"),this.getURL(e,t,s)}getURL(e,t,s={}){if(!t||!e?.id||!e?.collectionId&&!e?.collectionName)return"";const i=[];i.push("api"),i.push("files"),i.push(encodeURIComponent(e.collectionId||e.collectionName)),i.push(encodeURIComponent(e.id)),i.push(encodeURIComponent(t));let n=this.client.buildURL(i.join("/"));s.download===!1&&delete s.download;const r=E(s);return r&&(n+=(n.includes("?")?"&":"?")+r),n}async getToken(e){return e=Object.assign({method:"POST"},e),this.client.send("/api/files/token",e).then((t=>t?.token||""))}}class te extends b{async getFullList(e){return e=Object.assign({method:"GET"},e),this.client.send("/api/backups",e)}async create(e,t){return t=Object.assign({method:"POST",body:{name:e}},t),this.client.send("/api/backups",t).then((()=>!0))}async upload(e,t){return t=Object.assign({method:"POST",body:e},t),this.client.send("/api/backups/upload",t).then((()=>!0))}async delete(e,t){return t=Object.assign({method:"DELETE"},t),this.client.send(`/api/backups/${encodeURIComponent(e)}`,t).then((()=>!0))}async restore(e,t){return t=Object.assign({method:"POST"},t),this.client.send(`/api/backups/${encodeURIComponent(e)}/restore`,t).then((()=>!0))}getDownloadUrl(e,t){return console.warn("Please replace pb.backups.getDownloadUrl(
1) with pb.backups.getDownloadURL()"),this.getDownloadURL(e,t)}getDownloadURL(e,t){return this.client.buildURL(`/api/backups/${encodeURIComponent(t)}?token=${encodeURIComponent(e)}`)}}class se extends b{async getFullList(e){return e=Object.assign({method:"GET"},e),this.client.send("/api/crons",e)}async run(e,t){return t=Object.assign({method:"POST"},t),this.client.send(`/api/crons/${encodeURIComponent(e)}`,t).then((()=>!0))}}class ie extends b{async run(e,t){return t=Object.assign({method:"POST",body:{query:e}},t),this.client.send("/api/sql",t)}}function P(o){return typeof Blob<"u"&&o instanceof Blob||typeof File<"u"&&o instanceof File||o!==null&&typeof o=="object"&&o.uri&&(typeof navigator<"u"&&navigator.product==="ReactNative"||typeof global<"u"&&global.HermesInternal)}function T(o){return o&&(o.constructor?.name==="FormData"||typeof FormData<"u"&&o instanceof FormData)}function U(o){for(const e in o){const t=Array.isArray(o[e])?o[e]:[o[e]];for(const s of t)if(P(s))return!0}return!1}const ne=/^[\-\.\d]+$/;function N(o){if(typeof o!="string")return o;if(o=="true")return!0;if(o=="false")return!1;if((o[0]==="-"||o[0]>="0"&&o[0]<="9")&&ne.test(o)){let e=+o;if(""+e===o)return e}return o}class re extends b{constructor(){super(...arguments),this.requests=[],this.subs={}}collection(e){return this.subs[e]||(this.subs[e]=new oe(this.requests,e)),this.subs[e]}async send(e){const t=new FormData,s=[];for(let i=0;i<this.requests.length;i++){const n=this.requests[i];if(s.push({method:n.method,url:n.url,headers:n.headers,body:n.json}),n.files)for(let r in n.files){const a=n.files[r]||[];for(let c of a)t.append("requests."+i+"."+r,c)}}return t.append("@jsonPayload",JSON.stringify({requests:s})),e=Object.assign({method:"POST",body:t},e),this.client.send("/api/batch",e)}}class oe{constructor(e,t){this.requests=[],this.requests=e,this.collectionIdOrName=t}upsert(e,t){t=Object.assign({body:e||{}},t);const s={method:"PUT",url:"/api/collections/"+encodeURIComponent(this.collectionIdOrName)+"/records"};this.prepareRequest(s,t),this.requests.push(s)}create(e,t){t=Object.assign({body:e||{}},t);const s={method:"POST",url:"/api/collections/"+encodeURIComponent(this.collectionIdOrName)+"/records"};this.prepareRequest(s,t),this.requests.push(s)}update(e,t,s){s=Object.assign({body:t||{}},s);const i={method:"PATCH",url:"/api/collections/"+encodeURIComponent(this.collectionIdOrName)+"/records/"+encodeURIComponent(e)};this.prepareRequest(i,s),this.requests.push(i)}delete(e,t){t=Object.assign({},t);const s={method:"DELETE",url:"/api/collections/"+encodeURIComponent(this.collectionIdOrName)+"/records/"+encodeURIComponent(e)};this.prepareRequest(s,t),this.requests.push(s)}prepareRequest(e,t){if(I(t),e.headers=t.headers,e.json={},e.files={},t.query!==void 0){const i=E(t.query);i&&(e.url+=(e.url.includes("?")?"&":"?")+i)}let s=t.body;T(s)&&(s=(function(n){let r={};return n.forEach(((a,c)=>{if(c==="@jsonPayload"&&typeof a=="string")try{let l=JSON.parse(a);Object.assign(r,l)}catch(l){console.warn("@jsonPayload error:",l)}else r[c]!==void 0?(Array.isArray(r[c])||(r[c]=[r[c]]),r[c].push(N(a))):r[c]=N(a)})),r})(s));for(const i in s){const n=s[i];if(P(n))e.files[i]=e.files[i]||[],e.files[i].push(n);else if(Array.isArray(n)){const r=[],a=[];for(const c of n)P(c)?r.push(c):a.push(c);if(r.length>0&&r.length==n.length){e.files[i]=e.files[i]||[];for(let c of r)e.files[i].push(c)}else if(e.json[i]=a,r.length>0){let c=i;i.startsWith("+")||i.endsWith("+")||(c+="+"),e.files[c]=e.files[c]||[];for(let l of r)e.files[c].push(l)}}else e.json[i]=n}}}RegExp.escape||(RegExp.escape=function(o){return o.replace(/[/\-\\^$*+?.()|[\]{}]/g,"\\$&")});class K{get baseUrl(){return this.baseURL}set baseUrl(e){this.baseURL=e}constructor(e="/",t,s="en-US"){this.cancelControllers={},this.recordServices={},this.enableAutoCancellation=!0,this.baseURL=e,this.lang=s,t?this.authStore=t:typeof window<"u"&&window.Deno?this.authStore=new k:this.authStore=new H,this.collections=new X(this),this.files=new ee(this),this.logs=new Y(this),this.settings=new M(this),this.realtime=new D(this),this.health=new Z(this),this.backups=new te(this),this.crons=new se(this),this.sql=ne
1w ie(this)}get admins(){return this.collection("_superusers")}createBatch(){return new re(this)}collection(e){return this.recordServices[e]||(this.recordServices[e]=new Q(this,e)),this.recordServices[e]}autoCancellation(e){return this.enableAutoCancellation=!!e,this}cancelRequest(e){return this.cancelControllers[e]&&(this.cancelControllers[e].abort(),delete this.cancelControllers[e]),this}cancelAllRequests(){for(let e in this.cancelControllers)this.cancelControllers[e].abort();return this.cancelControllers={},this}filter(e,t){if(!t)return e;const s={};for(const n in t)s["{:"+n+"}"]=t[n];const i=Object.keys(s).map((n=>RegExp.escape(n))).join("|");return i?e.replace(new RegExp(i,"g"),(n=>(function(a){switch(typeof a){case"boolean":case"number":return""+a;case"string":return JSON.stringify(a);default:if(a==null)return"null";if(a instanceof Date)return JSON.stringify(a.toISOString().replace("T"," "));const c=JSON.stringify(a);return c.startsWith("[")||c.startsWith("{")?JSON.stringify(c):c}})(s[n]))):e}getFileUrl(e,t,s={}){return console.warn("Please replace pb.getFileUrl() with pb.files.getURL()"),this.files.getURL(e,t,s)}buildUrl(e){return console.warn("Please replace pb.buildUrl() with pb.buildURL()"),this.buildURL(e)}buildURL(e){let t=this.baseURL;return typeof window>"u"||!window.location||t.startsWith("https://")||t.startsWith("http://")||(t=window.location.origin?.endsWith("/")?window.location.origin.substring(0,window.location.origin.length-1):window.location.origin||"",this.baseURL.startsWith("/")||(t+=window.location.pathname||"/",t+=t.endsWith("/")?"":"/"),t+=this.baseURL),e&&(t+=t.endsWith("/")?"":"/",t+=e.startsWith("/")?e.substring(1):e),t}async send(e,t){t=this.initSendOptions(e,t);let s=this.buildURL(e);if(this.beforeSend){const i=Object.assign({},await this.beforeSend(s,t));i.url!==void 0||i.options!==void 0?(s=i.url||s,t=i.options||t):Object.keys(i).length&&(t=i,console?.warn&&console.warn("Deprecated format of beforeSend return: please use `return { url, options }`, instead of `return options`."))}if(t.query!==void 0){const i=E(t.query);i&&(s+=(s.includes("?")?"&":"?")+i),delete t.query}return this.getHeader(t.headers,"Content-Type")=="application/json"&&t.body&&typeof t.body!="string"&&(t.body=JSON.stringify(t.body)),(t.fetch||fetch)(s,t).then((async i=>{let n={};try{n=await i.json()}catch(r){if(t.signal?.aborted||r?.name=="AbortError"||r?.message=="Aborted")throw r}if(this.afterSend&&(n=await this.afterSend(i,n,t)),i.status>=400)throw new h({url:i.url,status:i.status,data:n});return n})).catch((i=>{throw new h(i)}))}initSendOptions(e,t){if((t=Object.assign({method:"GET"},t)).body=(function(i){if(typeof FormData>"u"||i===void 0||typeof i!="object"||i===null||T(i)||!U(i))return i;const n=new FormData;for(const r in i){const a=i[r];if(a!==void 0)if(typeof a!="object"||U({data:a})){const c=Array.isArray(a)?a:[a];for(let l of c)n.append(r,l)}else{let c={};c[r]=a,n.append("@jsonPayload",JSON.stringify(c))}}return n})(t.body),I(t),t.query=Object.assign({},t.params,t.query),t.requestKey===void 0&&(t.$autoCancel===!1||t.query.$autoCancel===!1?t.requestKey=null:(t.$cancelKey||t.query.$cancelKey)&&(t.requestKey=t.$cancelKey||t.query.$cancelKey)),delete t.$autoCancel,delete t.query.$autoCancel,delete t.$cancelKey,delete t.query.$cancelKey,this.getHeader(t.headers,"Content-Type")!==null||T(t.body)||(t.headers=Object.assign({},t.headers,{"Content-Type":"application/json"})),this.getHeader(t.headers,"Accept-Language")===null&&(t.headers=Object.assign({},t.headers,{"Accept-Language":this.lang})),this.authStore.token&&this.getHeader(t.headers,"Authorization")===null&&(t.headers=Object.assign({},t.headers,{Authorization:this.authStore.token})),this.enableAutoCancellation&&t.requestKey!==null){const s=t.requestKey||(t.method||"GET")+e;delete t.requestKey,this.cancelRequest(s);const i=new AbortController;this.cancelControllers[s]=i,t.signal=i.signal}return t}getHeader(e,t){e=e||{},t=t.toLowerCase();for(let s in e)if(s.toLowerCase()==t)return e[s];return null}}const ae="/hcgi/platform",ce=new K(ae);export{ce as p};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.