@nocloud/sdk 0.1.0 → 0.1.1

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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- var{defineProperty:u,getOwnPropertyNames:j,getOwnPropertyDescriptor:v}=Object,G=Object.prototype.hasOwnProperty;var U=new WeakMap,M=(r)=>{var x=U.get(r),F;if(x)return x;if(x=u({},"__esModule",{value:!0}),r&&typeof r==="object"||typeof r==="function")j(r).map((f)=>!G.call(x,f)&&u(x,f,{get:()=>r[f],enumerable:!(F=v(r,f))||F.enumerable}));return U.set(r,x),x};var P=(r,x)=>{for(var F in x)u(r,F,{get:x[F],enumerable:!0,configurable:!0,set:(f)=>x[F]=()=>f})};var C={};P(C,{default:()=>w,NoCloudAPIError:()=>h,NoCloud:()=>_});module.exports=M(C);var V="https://api.nonefivem.com";class h extends Error{status;constructor(r,x){super(r);this.status=x;this.name="NoCloudAPIError"}}function k(r){return new Promise((x)=>setTimeout(x,r))}async function W(r,x=3,F=1000){let f;for(let K=0;K<=x;K++)try{return await r()}catch(c){if(f=c,K<x)await k(F)}throw f}var A={iVBORw0KGgo:"image/png","/9j/":"image/jpeg",R0lGOD:"image/gif",UklGR:"image/webp",AAAA:"video/mp4",JVBERi0:"application/pdf",UEsDB:"application/zip",PD94bWw:"application/xml",PHN2Zw:"image/svg+xml"};function X(r){let x=r.match(/^data:([^;,]+)/);if(x?.[1])return x[1];for(let[F,f]of Object.entries(A))if(r.startsWith(F))return f;return null}function Y(r){let x=r.match(/^data:[^;,]+;base64,(.+)$/);if(x?.[1])return x[1];return r}function Z(r){let x=(r.match(/=+$/)||[""])[0].length;return Math.floor(r.length*3/4)-x}class D{baseUrl;apiKey;retryCount;retryDelayMs;constructor(r){if(this.apiKey=r.apiKey,this.baseUrl=r.baseUrl||V,this.retryCount=r.retries??3,this.retryDelayMs=r.retryDelayMs??1000,!this.apiKey)throw Error("API key is required")}buildUrl(r){return`${this.baseUrl}/cloud/${r}`}fetch(r,x={}){let F=this.buildUrl(r);return W(()=>fetch(F,{...x,headers:{Authorization:`Bearer ${this.apiKey}`,...x.headers||{}}}),x.retries??this.retryCount,x.retryDelayMs??this.retryDelayMs)}}async function B(r){if(!r.ok)try{let x=await r.json();throw new h(x.message||"API Error",r.status)}catch(x){throw new h("Unknown error",r.status)}return await r.json()}class H{fetcher;constructor(r){this.fetcher=r}fetch(r,x){return this.fetcher.fetch(r,x)}}class Q extends H{async generateSignedUrl(r,x,F){let f=await this.fetch("storage/signed-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({contentType:r,size:x,metadata:F})});return B(f)}getBodyInfo(r){if(typeof Blob<"u"&&r instanceof Blob)return{contentType:r.type||"application/octet-stream",size:r.size};if(typeof ArrayBuffer<"u"&&r instanceof ArrayBuffer)return{contentType:"application/octet-stream",size:r.byteLength};if(typeof r==="string"){let x=X(r);if(x){let F=Y(r),f=Z(F);return{contentType:x,size:f}}return{contentType:"text/plain",size:new TextEncoder().encode(r).length}}throw new h("Unsupported body type",400)}async upload(r,x){let{contentType:F,size:f}=this.getBodyInfo(r),{url:K,mediaUrl:c,mediaId:$}=await this.generateSignedUrl(F,f,x),O=await fetch(K,{method:"PUT",headers:{"Content-Type":F,"Content-Length":f.toString()},body:r});if(!O.ok){let q=await O.text().catch(()=>O.statusText);throw new h(`Failed to upload file to R2: ${q}`,O.status)}return{id:$,url:c}}async uploadStream(r,x,F,f){let{url:K,mediaUrl:c,mediaId:$}=await this.generateSignedUrl(x,F,f),O=await fetch(K,{method:"PUT",headers:{"Content-Type":x,"Content-Length":F.toString()},body:r,duplex:"half"});if(!O.ok){let q=await O.text().catch(()=>O.statusText);throw new h(`Failed to upload stream to R2: ${q}`,O.status)}return{id:$,url:c}}async delete(r){let x=await this.fetch(`storage/${r}`,{method:"DELETE"});return B(x)}}class _{fetcher;constructor(r){if(typeof r==="string")r={apiKey:r};this.fetcher=new D({apiKey:r.apiKey,baseUrl:r.baseUrl,retries:r.retries,retryDelayMs:r.retryDelayMs})}_storage;get storage(){return this._storage??=new Q(this.fetcher)}}var w=_;
1
+ var{defineProperty:A,getOwnPropertyNames:Y,getOwnPropertyDescriptor:Z}=Object,j=Object.prototype.hasOwnProperty;var H=new WeakMap,E=(r)=>{var h=H.get(r),x;if(h)return h;if(h=A({},"__esModule",{value:!0}),r&&typeof r==="object"||typeof r==="function")Y(r).map((F)=>!j.call(h,F)&&A(h,F,{get:()=>r[F],enumerable:!(x=Z(r,F))||x.enumerable}));return H.set(r,h),h};var G=(r,h)=>{for(var x in h)A(r,x,{get:h[x],enumerable:!0,configurable:!0,set:(F)=>h[x]=()=>F})};var C={};G(C,{default:()=>L,NoCloudAPIError:()=>f,NoCloud:()=>_});module.exports=E(C);var U="https://api.nonefivem.com",v="/cloud";class f extends Error{status;constructor(r,h){super(r);this.status=h;this.name="NoCloudAPIError"}}function M(r){return new Promise((h)=>setTimeout(h,r))}async function Q(r,h=3,x=1000){let F;for(let O=0;O<=h;O++)try{return await r()}catch(P){if(F=P,O<h)await M(x)}throw F}var k={iVBORw0KGgo:"image/png","/9j/":"image/jpeg",R0lGOD:"image/gif",UklGR:"image/webp",AAAA:"video/mp4",JVBERi0:"application/pdf",UEsDB:"application/zip",PD94bWw:"application/xml",PHN2Zw:"image/svg+xml"};function V(r){let h=r.match(/^data:([^;,]+)/);if(h?.[1])return h[1];for(let[x,F]of Object.entries(k))if(r.startsWith(x))return F;return null}function W(r){let h=r.match(/^data:[^;,]+;base64,(.+)$/);if(h?.[1])return h[1];return r}function X(r){let h=(r.match(/=+$/)||[""])[0].length;return Math.floor(r.length*3/4)-h}class D{baseUrl;basePath;apiKey;retryCount;retryDelayMs;constructor(r){if(this.apiKey=r.apiKey,this.baseUrl=(r.baseUrl||U).replace(/\/+$/,""),this.basePath=(r.basePath??v).replace(/^\/+|\/+$/g,""),this.retryCount=r.retries??3,this.retryDelayMs=r.retryDelayMs??1000,!this.apiKey)throw Error("API key is required")}buildUrl(r){let h=this.basePath?`${this.basePath}/${r}`:r;return`${this.baseUrl}/${h}`}fetch(r,h={}){let x=this.buildUrl(r);return Q(()=>fetch(x,{...h,headers:{Authorization:`Bearer ${this.apiKey}`,...h.headers||{}}}),h.retries??this.retryCount,h.retryDelayMs??this.retryDelayMs)}}async function B(r){if(!r.ok)try{let h=await r.json();throw new f(h.message||"API Error",r.status)}catch(h){throw new f("Unknown error",r.status)}return await r.json()}class q{fetcher;constructor(r){this.fetcher=r}fetch(r,h){return this.fetcher.fetch(r,h)}}class u extends q{async generateSignedUrl(r,h,x){let F=await this.fetch("storage/signed-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({contentType:r,size:h,metadata:x})});return B(F)}getBodyInfo(r){if(typeof Blob<"u"&&r instanceof Blob)return{contentType:r.type||"application/octet-stream",size:r.size};if(typeof ArrayBuffer<"u"&&r instanceof ArrayBuffer)return{contentType:"application/octet-stream",size:r.byteLength};if(typeof r==="string"){let h=V(r);if(h){let x=W(r),F=X(x);return{contentType:h,size:F}}return{contentType:"text/plain",size:new TextEncoder().encode(r).length}}throw new f("Unsupported body type",400)}async upload(r,h){let{contentType:x,size:F}=this.getBodyInfo(r),{url:O,mediaUrl:P,mediaId:$}=await this.generateSignedUrl(x,F,h),c=await fetch(O,{method:"PUT",headers:{"Content-Type":x,"Content-Length":F.toString()},body:r});if(!c.ok){let K=await c.text().catch(()=>c.statusText);throw new f(`Failed to upload file to R2: ${K}`,c.status)}return{id:$,url:P}}async uploadStream(r,h,x,F){let{url:O,mediaUrl:P,mediaId:$}=await this.generateSignedUrl(h,x,F),c=await fetch(O,{method:"PUT",headers:{"Content-Type":h,"Content-Length":x.toString()},body:r,duplex:"half"});if(!c.ok){let K=await c.text().catch(()=>c.statusText);throw new f(`Failed to upload stream to R2: ${K}`,c.status)}return{id:$,url:P}}async delete(r){let h=await this.fetch(`storage/${r}`,{method:"DELETE"});return B(h)}}class _{fetcher;constructor(r){if(typeof r==="string")r={apiKey:r};this.fetcher=new D({apiKey:r.apiKey,baseUrl:r.baseUrl,basePath:r.basePath,retries:r.retries,retryDelayMs:r.retryDelayMs})}_storage;get storage(){return this._storage??=new u(this.fetcher)}}var L=_;
package/dist/index.d.ts CHANGED
@@ -7,10 +7,12 @@ export interface FetchOptionsBase {
7
7
  export interface FetcherOptions extends FetchOptionsBase {
8
8
  apiKey: string;
9
9
  baseUrl?: string;
10
+ basePath?: string;
10
11
  }
11
12
  export type FetchOptions = RequestInit & FetchOptionsBase;
12
13
  declare class Fetcher {
13
14
  private readonly baseUrl;
15
+ private readonly basePath;
14
16
  private readonly apiKey;
15
17
  private readonly retryCount;
16
18
  private readonly retryDelayMs;
@@ -120,6 +122,11 @@ export interface NoCloudOptions {
120
122
  * @default "https://api.nonefivem.com"
121
123
  */
122
124
  baseUrl?: string;
125
+ /**
126
+ * Optional base path for API endpoints.
127
+ * @default "/cloud"
128
+ */
129
+ basePath?: string;
123
130
  /**
124
131
  * Number of retry attempts for failed requests.
125
132
  * @default 3
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var Q="https://api.nonefivem.com";class h extends Error{status;constructor(r,x){super(r);this.status=x;this.name="NoCloudAPIError"}}function Y(r){return new Promise((x)=>setTimeout(x,r))}async function U(r,x=3,F=1000){let f;for(let K=0;K<=x;K++)try{return await r()}catch(c){if(f=c,K<x)await Y(F)}throw f}var Z={iVBORw0KGgo:"image/png","/9j/":"image/jpeg",R0lGOD:"image/gif",UklGR:"image/webp",AAAA:"video/mp4",JVBERi0:"application/pdf",UEsDB:"application/zip",PD94bWw:"application/xml",PHN2Zw:"image/svg+xml"};function V(r){let x=r.match(/^data:([^;,]+)/);if(x?.[1])return x[1];for(let[F,f]of Object.entries(Z))if(r.startsWith(F))return f;return null}function W(r){let x=r.match(/^data:[^;,]+;base64,(.+)$/);if(x?.[1])return x[1];return r}function X(r){let x=(r.match(/=+$/)||[""])[0].length;return Math.floor(r.length*3/4)-x}class q{baseUrl;apiKey;retryCount;retryDelayMs;constructor(r){if(this.apiKey=r.apiKey,this.baseUrl=r.baseUrl||Q,this.retryCount=r.retries??3,this.retryDelayMs=r.retryDelayMs??1000,!this.apiKey)throw Error("API key is required")}buildUrl(r){return`${this.baseUrl}/cloud/${r}`}fetch(r,x={}){let F=this.buildUrl(r);return U(()=>fetch(F,{...x,headers:{Authorization:`Bearer ${this.apiKey}`,...x.headers||{}}}),x.retries??this.retryCount,x.retryDelayMs??this.retryDelayMs)}}async function u(r){if(!r.ok)try{let x=await r.json();throw new h(x.message||"API Error",r.status)}catch(x){throw new h("Unknown error",r.status)}return await r.json()}class D{fetcher;constructor(r){this.fetcher=r}fetch(r,x){return this.fetcher.fetch(r,x)}}class B extends D{async generateSignedUrl(r,x,F){let f=await this.fetch("storage/signed-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({contentType:r,size:x,metadata:F})});return u(f)}getBodyInfo(r){if(typeof Blob<"u"&&r instanceof Blob)return{contentType:r.type||"application/octet-stream",size:r.size};if(typeof ArrayBuffer<"u"&&r instanceof ArrayBuffer)return{contentType:"application/octet-stream",size:r.byteLength};if(typeof r==="string"){let x=V(r);if(x){let F=W(r),f=X(F);return{contentType:x,size:f}}return{contentType:"text/plain",size:new TextEncoder().encode(r).length}}throw new h("Unsupported body type",400)}async upload(r,x){let{contentType:F,size:f}=this.getBodyInfo(r),{url:K,mediaUrl:c,mediaId:_}=await this.generateSignedUrl(F,f,x),O=await fetch(K,{method:"PUT",headers:{"Content-Type":F,"Content-Length":f.toString()},body:r});if(!O.ok){let $=await O.text().catch(()=>O.statusText);throw new h(`Failed to upload file to R2: ${$}`,O.status)}return{id:_,url:c}}async uploadStream(r,x,F,f){let{url:K,mediaUrl:c,mediaId:_}=await this.generateSignedUrl(x,F,f),O=await fetch(K,{method:"PUT",headers:{"Content-Type":x,"Content-Length":F.toString()},body:r,duplex:"half"});if(!O.ok){let $=await O.text().catch(()=>O.statusText);throw new h(`Failed to upload stream to R2: ${$}`,O.status)}return{id:_,url:c}}async delete(r){let x=await this.fetch(`storage/${r}`,{method:"DELETE"});return u(x)}}class H{fetcher;constructor(r){if(typeof r==="string")r={apiKey:r};this.fetcher=new q({apiKey:r.apiKey,baseUrl:r.baseUrl,retries:r.retries,retryDelayMs:r.retryDelayMs})}_storage;get storage(){return this._storage??=new B(this.fetcher)}}var s=H;export{s as default,h as NoCloudAPIError,H as NoCloud};
1
+ var u="https://api.nonefivem.com",H="/cloud";class f extends Error{status;constructor(r,h){super(r);this.status=h;this.name="NoCloudAPIError"}}function W(r){return new Promise((h)=>setTimeout(h,r))}async function U(r,h=3,x=1000){let F;for(let O=0;O<=h;O++)try{return await r()}catch(P){if(F=P,O<h)await W(x)}throw F}var X={iVBORw0KGgo:"image/png","/9j/":"image/jpeg",R0lGOD:"image/gif",UklGR:"image/webp",AAAA:"video/mp4",JVBERi0:"application/pdf",UEsDB:"application/zip",PD94bWw:"application/xml",PHN2Zw:"image/svg+xml"};function v(r){let h=r.match(/^data:([^;,]+)/);if(h?.[1])return h[1];for(let[x,F]of Object.entries(X))if(r.startsWith(x))return F;return null}function Q(r){let h=r.match(/^data:[^;,]+;base64,(.+)$/);if(h?.[1])return h[1];return r}function V(r){let h=(r.match(/=+$/)||[""])[0].length;return Math.floor(r.length*3/4)-h}class K{baseUrl;basePath;apiKey;retryCount;retryDelayMs;constructor(r){if(this.apiKey=r.apiKey,this.baseUrl=(r.baseUrl||u).replace(/\/+$/,""),this.basePath=(r.basePath??H).replace(/^\/+|\/+$/g,""),this.retryCount=r.retries??3,this.retryDelayMs=r.retryDelayMs??1000,!this.apiKey)throw Error("API key is required")}buildUrl(r){let h=this.basePath?`${this.basePath}/${r}`:r;return`${this.baseUrl}/${h}`}fetch(r,h={}){let x=this.buildUrl(r);return U(()=>fetch(x,{...h,headers:{Authorization:`Bearer ${this.apiKey}`,...h.headers||{}}}),h.retries??this.retryCount,h.retryDelayMs??this.retryDelayMs)}}async function A(r){if(!r.ok)try{let h=await r.json();throw new f(h.message||"API Error",r.status)}catch(h){throw new f("Unknown error",r.status)}return await r.json()}class D{fetcher;constructor(r){this.fetcher=r}fetch(r,h){return this.fetcher.fetch(r,h)}}class B extends D{async generateSignedUrl(r,h,x){let F=await this.fetch("storage/signed-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({contentType:r,size:h,metadata:x})});return A(F)}getBodyInfo(r){if(typeof Blob<"u"&&r instanceof Blob)return{contentType:r.type||"application/octet-stream",size:r.size};if(typeof ArrayBuffer<"u"&&r instanceof ArrayBuffer)return{contentType:"application/octet-stream",size:r.byteLength};if(typeof r==="string"){let h=v(r);if(h){let x=Q(r),F=V(x);return{contentType:h,size:F}}return{contentType:"text/plain",size:new TextEncoder().encode(r).length}}throw new f("Unsupported body type",400)}async upload(r,h){let{contentType:x,size:F}=this.getBodyInfo(r),{url:O,mediaUrl:P,mediaId:_}=await this.generateSignedUrl(x,F,h),c=await fetch(O,{method:"PUT",headers:{"Content-Type":x,"Content-Length":F.toString()},body:r});if(!c.ok){let $=await c.text().catch(()=>c.statusText);throw new f(`Failed to upload file to R2: ${$}`,c.status)}return{id:_,url:P}}async uploadStream(r,h,x,F){let{url:O,mediaUrl:P,mediaId:_}=await this.generateSignedUrl(h,x,F),c=await fetch(O,{method:"PUT",headers:{"Content-Type":h,"Content-Length":x.toString()},body:r,duplex:"half"});if(!c.ok){let $=await c.text().catch(()=>c.statusText);throw new f(`Failed to upload stream to R2: ${$}`,c.status)}return{id:_,url:P}}async delete(r){let h=await this.fetch(`storage/${r}`,{method:"DELETE"});return A(h)}}class q{fetcher;constructor(r){if(typeof r==="string")r={apiKey:r};this.fetcher=new K({apiKey:r.apiKey,baseUrl:r.baseUrl,basePath:r.basePath,retries:r.retries,retryDelayMs:r.retryDelayMs})}_storage;get storage(){return this._storage??=new B(this.fetcher)}}var e=q;export{e as default,f as NoCloudAPIError,q as NoCloud};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocloud/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Official SDK for NoCloud services - file storage and more",
5
5
  "author": {
6
6
  "name": "sinanovicanes",