@asaidimu/hestia 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@asaidimu/network-client"),t=require("@asaidimu/utils-error"),n=require("@asaidimu/utils-store"),r=require("@asaidimu/utils-sync"),i=require("@asaidimu/query");async function a(e){try{return(await e.clone().json())?.error??null}catch{return null}}function o(e,n){if(n)return new t.SystemError({code:n.code??`UNKNOWN`,message:n.message??`Unknown error`,issues:n.details?.issues});let r=e.error?.message;if(typeof r==`object`&&r){let e=r;return new t.SystemError({code:e.code??`UNKNOWN`,message:e.message??`Unknown error`})}return new t.SystemError({code:`UNKNOWN`,message:r??`Unknown error`})}function s(e){return t.Errors.notFound(e)}function c(e){return t.Errors.permissionDenied(e)}function l(e){return t.Errors.internalError(e)}var u=class{data;status;constructor(e,t){this.data=e,this.status=t}},d=class{baseUrl;apiPrefix;tokens;onAuthStateChanged;raw;constructor(t,n,r,i){this.baseUrl=t,this.apiPrefix=n,this.tokens=r,this.onAuthStateChanged=i,this.raw=(0,e.createNetworkClient)({baseUrl:t,defaultResponseType:`json`,defaultBodyType:`json`})}base(){return this.baseUrl}prefix(){return this.apiPrefix}canonicalPath(e){let t=e.replace(/^\/+/,``);if(this.apiPrefix){let e=this.apiPrefix.replace(/^\/+/,``),n=RegExp(`^${e}/?`);return t=t.replace(n,``),`${e}/${t}`}return t}async request(e,n,r,i){let s=this.canonicalPath(n),c={};i?.headers&&(c.headers={...i.headers}),i?.responseType&&(c.responseType=i.responseType),i?.bodyType&&(c.bodyType=i.bodyType),i?.signal&&(c.signal=i.signal),c.headers||={};let l;if(e===`GET`)l=await this.raw.get(s,c);else{let t=i?.bodyType?{type:i.bodyType}:void 0;l=await this.raw[e.toLowerCase()](s,r,c,t)}if(l.success||l.status===204)return new u(l.data,l.status);if(l.status===401||l.status===403)throw i?.headers?.[`X-API-Key`]||this.onAuthStateChanged?.(),new t.SystemError({code:`AUTH-002-UNAUTH`,message:`Session expired`});let d=l.raw?await a(l.raw):null;throw o(l,d)}async get(e,t){return this.request(`GET`,e,void 0,t)}async post(e,t,n){return this.request(`POST`,e,t,n)}async patch(e,t,n){return this.request(`PATCH`,e,t,n)}async put(e,t,n){return this.request(`PUT`,e,t,n)}async delete(e,t,n){return this.request(`DELETE`,e,t,n)}async openStream(e,n,r){let i={Accept:`text/event-stream`,...r?.headers??{}},a=`${this.baseUrl.replace(/\/+$/,``)}/${this.canonicalPath(e)}`,o;try{o=await fetch(a,{method:`GET`,headers:i,signal:r?.signal})}catch(e){if(e instanceof Error&&e.name===`AbortError`){n.onClose?.();return}n.onError?.(e instanceof Error?e:Error(String(e)));return}if(o.status===401){this.onAuthStateChanged?.(),n.onError?.(new t.SystemError({code:`AUTH-002-UNAUTH`,message:`Session expired`}));return}if(!o.ok||!o.body){n.onError?.(Error(`Stream request failed with status ${o.status}`));return}n.onOpen?.();let s=o.body.getReader(),c=new TextDecoder,l=``;try{for(;;){let{done:e,value:t}=await s.read();if(e)break;l+=c.decode(t,{stream:!0});let r=l.indexOf(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@asaidimu/network-client"),t=require("@asaidimu/utils-error"),n=require("@asaidimu/utils-store"),r=require("@asaidimu/utils-sync"),i=require("@asaidimu/query");async function a(e){try{return(await e.clone().json())?.error??null}catch{return null}}function o(e,n){if(n)return new t.SystemError({code:n.code??`UNKNOWN`,message:n.message??`Unknown error`,issues:n.details?.issues});let r=e.error?.message;if(typeof r==`object`&&r){let e=r;return new t.SystemError({code:e.code??`UNKNOWN`,message:e.message??`Unknown error`})}return new t.SystemError({code:`UNKNOWN`,message:r??`Unknown error`})}function s(e){return t.Errors.notFound(e)}function c(e){return t.Errors.permissionDenied(e)}function l(e){return t.Errors.internalError(e)}var u=class{data;status;constructor(e,t){this.data=e,this.status=t}},d=class{baseUrl;apiPrefix;provider;onAuthStateChanged;raw;constructor(t,n,r,i){this.baseUrl=t,this.apiPrefix=n,this.provider=r,this.onAuthStateChanged=i,this.raw=(0,e.createNetworkClient)({baseUrl:t,defaultResponseType:`json`,defaultBodyType:`json`})}base(){return this.baseUrl}prefix(){return this.apiPrefix}canonicalPath(e){let t=e.replace(/^\/+/,``);if(this.apiPrefix){let e=this.apiPrefix.replace(/^\/+/,``),n=RegExp(`^${e}/?`);return t=t.replace(n,``),`${e}/${t}`}return t}async request(e,n,r,i){let s=this.canonicalPath(n),c={};i?.headers&&(c.headers={...i.headers}),i?.responseType&&(c.responseType=i.responseType),i?.bodyType&&(c.bodyType=i.bodyType),i?.signal&&(c.signal=i.signal),c.headers||={};let l;if(e===`GET`)l=await this.raw.get(s,c);else{let t=i?.bodyType?{type:i.bodyType}:void 0;l=await this.raw[e.toLowerCase()](s,r,c,t)}if(l.success||l.status===204)return new u(l.data,l.status);if(l.status===401)throw i?.headers?.[`X-API-Key`]||(await this.provider.clear(),this.onAuthStateChanged?.()),new t.SystemError({code:`AUTH-002-UNAUTH`,message:`Session expired`});let d=l.raw?await a(l.raw):null;throw o(l,d)}async get(e,t){return this.request(`GET`,e,void 0,t)}async post(e,t,n){return this.request(`POST`,e,t,n)}async patch(e,t,n){return this.request(`PATCH`,e,t,n)}async put(e,t,n){return this.request(`PUT`,e,t,n)}async delete(e,t,n){return this.request(`DELETE`,e,t,n)}async openStream(e,n,r){let i={Accept:`text/event-stream`,...r?.headers??{}},a=`${this.baseUrl.replace(/\/+$/,``)}/${this.canonicalPath(e)}`,o;try{o=await fetch(a,{method:`GET`,headers:i,signal:r?.signal})}catch(e){if(e instanceof Error&&e.name===`AbortError`){n.onClose?.();return}n.onError?.(e instanceof Error?e:Error(String(e)));return}if(o.status===401){this.onAuthStateChanged?.(),n.onError?.(new t.SystemError({code:`AUTH-002-UNAUTH`,message:`Session expired`}));return}if(!o.ok||!o.body){n.onError?.(Error(`Stream request failed with status ${o.status}`));return}n.onOpen?.();let s=o.body.getReader(),c=new TextDecoder,l=``;try{for(;;){let{done:e,value:t}=await s.read();if(e)break;l+=c.decode(t,{stream:!0});let r=l.indexOf(`
2
2
 
3
3
  `);for(;r!==-1;){let e=l.slice(0,r);l=l.slice(r+2);let t=e.split(`
4
4
  `).filter(e=>e.startsWith(`data:`)).map(e=>e.slice(5).trim());t.length>0&&n.onMessage(t.join(`
package/index.d.cts CHANGED
@@ -291,10 +291,10 @@ interface StreamOptions {
291
291
  declare class HestiaNetworkClient {
292
292
  private baseUrl;
293
293
  private apiPrefix;
294
- private tokens;
294
+ private provider;
295
295
  private onAuthStateChanged?;
296
296
  private raw;
297
- constructor(baseUrl: string, apiPrefix: string, tokens: IdentityProvider, onAuthStateChanged?: (() => void) | undefined);
297
+ constructor(baseUrl: string, apiPrefix: string, provider: IdentityProvider, onAuthStateChanged?: (() => void) | undefined);
298
298
  base(): string;
299
299
  prefix(): string;
300
300
  private canonicalPath;
package/index.d.mts CHANGED
@@ -291,10 +291,10 @@ interface StreamOptions {
291
291
  declare class HestiaNetworkClient {
292
292
  private baseUrl;
293
293
  private apiPrefix;
294
- private tokens;
294
+ private provider;
295
295
  private onAuthStateChanged?;
296
296
  private raw;
297
- constructor(baseUrl: string, apiPrefix: string, tokens: IdentityProvider, onAuthStateChanged?: (() => void) | undefined);
297
+ constructor(baseUrl: string, apiPrefix: string, provider: IdentityProvider, onAuthStateChanged?: (() => void) | undefined);
298
298
  base(): string;
299
299
  prefix(): string;
300
300
  private canonicalPath;
package/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import{createNetworkClient as e}from"@asaidimu/network-client";import{Errors as t,SystemError as n}from"@asaidimu/utils-error";import{DELETE_SYMBOL as r,ReactiveDataStore as i}from"@asaidimu/utils-store";import{Debouncer as a}from"@asaidimu/utils-sync";import{createMatcher as o,createSorter as s}from"@asaidimu/query";async function c(e){try{return(await e.clone().json())?.error??null}catch{return null}}function l(e,t){if(t)return new n({code:t.code??`UNKNOWN`,message:t.message??`Unknown error`,issues:t.details?.issues});let r=e.error?.message;if(typeof r==`object`&&r){let e=r;return new n({code:e.code??`UNKNOWN`,message:e.message??`Unknown error`})}return new n({code:`UNKNOWN`,message:r??`Unknown error`})}function u(e){return t.notFound(e)}function d(e){return t.permissionDenied(e)}function f(e){return t.internalError(e)}var p=class{data;status;constructor(e,t){this.data=e,this.status=t}},m=class{baseUrl;apiPrefix;tokens;onAuthStateChanged;raw;constructor(t,n,r,i){this.baseUrl=t,this.apiPrefix=n,this.tokens=r,this.onAuthStateChanged=i,this.raw=e({baseUrl:t,defaultResponseType:`json`,defaultBodyType:`json`})}base(){return this.baseUrl}prefix(){return this.apiPrefix}canonicalPath(e){let t=e.replace(/^\/+/,``);if(this.apiPrefix){let e=this.apiPrefix.replace(/^\/+/,``),n=RegExp(`^${e}/?`);return t=t.replace(n,``),`${e}/${t}`}return t}async request(e,t,r,i){let a=this.canonicalPath(t),o={};i?.headers&&(o.headers={...i.headers}),i?.responseType&&(o.responseType=i.responseType),i?.bodyType&&(o.bodyType=i.bodyType),i?.signal&&(o.signal=i.signal),o.headers||={};let s;if(e===`GET`)s=await this.raw.get(a,o);else{let t=i?.bodyType?{type:i.bodyType}:void 0;s=await this.raw[e.toLowerCase()](a,r,o,t)}if(s.success||s.status===204)return new p(s.data,s.status);if(s.status===401||s.status===403)throw i?.headers?.[`X-API-Key`]||this.onAuthStateChanged?.(),new n({code:`AUTH-002-UNAUTH`,message:`Session expired`});let u=s.raw?await c(s.raw):null;throw l(s,u)}async get(e,t){return this.request(`GET`,e,void 0,t)}async post(e,t,n){return this.request(`POST`,e,t,n)}async patch(e,t,n){return this.request(`PATCH`,e,t,n)}async put(e,t,n){return this.request(`PUT`,e,t,n)}async delete(e,t,n){return this.request(`DELETE`,e,t,n)}async openStream(e,t,r){let i={Accept:`text/event-stream`,...r?.headers??{}},a=`${this.baseUrl.replace(/\/+$/,``)}/${this.canonicalPath(e)}`,o;try{o=await fetch(a,{method:`GET`,headers:i,signal:r?.signal})}catch(e){if(e instanceof Error&&e.name===`AbortError`){t.onClose?.();return}t.onError?.(e instanceof Error?e:Error(String(e)));return}if(o.status===401){this.onAuthStateChanged?.(),t.onError?.(new n({code:`AUTH-002-UNAUTH`,message:`Session expired`}));return}if(!o.ok||!o.body){t.onError?.(Error(`Stream request failed with status ${o.status}`));return}t.onOpen?.();let s=o.body.getReader(),c=new TextDecoder,l=``;try{for(;;){let{done:e,value:n}=await s.read();if(e)break;l+=c.decode(n,{stream:!0});let r=l.indexOf(`
1
+ import{createNetworkClient as e}from"@asaidimu/network-client";import{Errors as t,SystemError as n}from"@asaidimu/utils-error";import{DELETE_SYMBOL as r,ReactiveDataStore as i}from"@asaidimu/utils-store";import{Debouncer as a}from"@asaidimu/utils-sync";import{createMatcher as o,createSorter as s}from"@asaidimu/query";async function c(e){try{return(await e.clone().json())?.error??null}catch{return null}}function l(e,t){if(t)return new n({code:t.code??`UNKNOWN`,message:t.message??`Unknown error`,issues:t.details?.issues});let r=e.error?.message;if(typeof r==`object`&&r){let e=r;return new n({code:e.code??`UNKNOWN`,message:e.message??`Unknown error`})}return new n({code:`UNKNOWN`,message:r??`Unknown error`})}function u(e){return t.notFound(e)}function d(e){return t.permissionDenied(e)}function f(e){return t.internalError(e)}var p=class{data;status;constructor(e,t){this.data=e,this.status=t}},m=class{baseUrl;apiPrefix;provider;onAuthStateChanged;raw;constructor(t,n,r,i){this.baseUrl=t,this.apiPrefix=n,this.provider=r,this.onAuthStateChanged=i,this.raw=e({baseUrl:t,defaultResponseType:`json`,defaultBodyType:`json`})}base(){return this.baseUrl}prefix(){return this.apiPrefix}canonicalPath(e){let t=e.replace(/^\/+/,``);if(this.apiPrefix){let e=this.apiPrefix.replace(/^\/+/,``),n=RegExp(`^${e}/?`);return t=t.replace(n,``),`${e}/${t}`}return t}async request(e,t,r,i){let a=this.canonicalPath(t),o={};i?.headers&&(o.headers={...i.headers}),i?.responseType&&(o.responseType=i.responseType),i?.bodyType&&(o.bodyType=i.bodyType),i?.signal&&(o.signal=i.signal),o.headers||={};let s;if(e===`GET`)s=await this.raw.get(a,o);else{let t=i?.bodyType?{type:i.bodyType}:void 0;s=await this.raw[e.toLowerCase()](a,r,o,t)}if(s.success||s.status===204)return new p(s.data,s.status);if(s.status===401)throw i?.headers?.[`X-API-Key`]||(await this.provider.clear(),this.onAuthStateChanged?.()),new n({code:`AUTH-002-UNAUTH`,message:`Session expired`});let u=s.raw?await c(s.raw):null;throw l(s,u)}async get(e,t){return this.request(`GET`,e,void 0,t)}async post(e,t,n){return this.request(`POST`,e,t,n)}async patch(e,t,n){return this.request(`PATCH`,e,t,n)}async put(e,t,n){return this.request(`PUT`,e,t,n)}async delete(e,t,n){return this.request(`DELETE`,e,t,n)}async openStream(e,t,r){let i={Accept:`text/event-stream`,...r?.headers??{}},a=`${this.baseUrl.replace(/\/+$/,``)}/${this.canonicalPath(e)}`,o;try{o=await fetch(a,{method:`GET`,headers:i,signal:r?.signal})}catch(e){if(e instanceof Error&&e.name===`AbortError`){t.onClose?.();return}t.onError?.(e instanceof Error?e:Error(String(e)));return}if(o.status===401){this.onAuthStateChanged?.(),t.onError?.(new n({code:`AUTH-002-UNAUTH`,message:`Session expired`}));return}if(!o.ok||!o.body){t.onError?.(Error(`Stream request failed with status ${o.status}`));return}t.onOpen?.();let s=o.body.getReader(),c=new TextDecoder,l=``;try{for(;;){let{done:e,value:n}=await s.read();if(e)break;l+=c.decode(n,{stream:!0});let r=l.indexOf(`
2
2
 
3
3
  `);for(;r!==-1;){let e=l.slice(0,r);l=l.slice(r+2);let n=e.split(`
4
4
  `).filter(e=>e.startsWith(`data:`)).map(e=>e.slice(5).trim());n.length>0&&t.onMessage(n.join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asaidimu/hestia",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "TypeScript client SDK for the Hestia platform — auth, collections, API keys, policies, audit logs, blobs, and capabilities",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",