@bloque/sdk-core 0.0.15 → 0.0.16

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,145 +1 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- API_BASE_URLS: ()=>API_BASE_URLS,
28
- DEFAULT_HEADERS: ()=>DEFAULT_HEADERS,
29
- HttpClient: ()=>HttpClient,
30
- BloqueAPIError: ()=>BloqueAPIError,
31
- BloqueConfigError: ()=>BloqueConfigError
32
- });
33
- const API_BASE_URLS = {
34
- sandbox: 'https://dev.bloque.app',
35
- production: 'https://api.bloque.app'
36
- };
37
- const DEFAULT_HEADERS = {
38
- 'Content-Type': 'application/json'
39
- };
40
- class BloqueAPIError extends Error {
41
- status;
42
- code;
43
- constructor(message, status, code){
44
- super(message);
45
- this.name = 'BloqueAPIError';
46
- this.status = status;
47
- this.code = code;
48
- Object.setPrototypeOf(this, BloqueAPIError.prototype);
49
- }
50
- }
51
- class BloqueConfigError extends Error {
52
- constructor(message){
53
- super(message);
54
- this.name = 'BloqueConfigError';
55
- Object.setPrototypeOf(this, BloqueConfigError.prototype);
56
- }
57
- }
58
- const createLocalStorageAdapter = ()=>({
59
- get: ()=>{
60
- if ('undefined' == typeof localStorage) return null;
61
- return localStorage.getItem('access_token');
62
- },
63
- set: (token)=>{
64
- if ('undefined' != typeof localStorage) localStorage.setItem('access_token', token);
65
- },
66
- clear: ()=>{
67
- if ('undefined' != typeof localStorage) localStorage.removeItem('access_token');
68
- }
69
- });
70
- class HttpClient {
71
- config;
72
- baseUrl;
73
- publicRoutes = [
74
- '/api/aliases',
75
- '/api/origins/*/assert'
76
- ];
77
- constructor(config){
78
- this.validateConfig(config);
79
- this.config = config;
80
- this.baseUrl = API_BASE_URLS[config.mode ?? 'production'];
81
- }
82
- isPublicRoute(path) {
83
- const pathWithoutQuery = path.split('?')[0];
84
- return this.publicRoutes.some((route)=>{
85
- const pattern = route.replace(/\*/g, '[^/]+');
86
- const regex = new RegExp(`^${pattern}$`);
87
- return regex.test(pathWithoutQuery);
88
- });
89
- }
90
- validateConfig(config) {
91
- if (!config.apiKey || '' === config.apiKey.trim()) throw new BloqueConfigError('API key is required');
92
- if (!config.mode) config.mode = 'production';
93
- if (![
94
- 'sandbox',
95
- 'production'
96
- ].includes(config.mode)) throw new BloqueConfigError('Mode must be either "sandbox" or "production"');
97
- if ('client' === config.runtime && !config.tokenStorage) config.tokenStorage = createLocalStorageAdapter();
98
- }
99
- async request(options) {
100
- const { method, path, body, headers = {} } = options;
101
- const url = `${this.baseUrl}${path}`;
102
- const requestHeaders = {
103
- ...DEFAULT_HEADERS,
104
- Authorization: this.config.apiKey,
105
- ...headers
106
- };
107
- if ('client' === this.config.runtime && !this.isPublicRoute(path)) {
108
- const token = this.config.tokenStorage?.get();
109
- if (!token) throw new BloqueConfigError('Authentication token is missing');
110
- requestHeaders.Authorization = `Bearer ${token}`;
111
- }
112
- try {
113
- const response = await fetch(url, {
114
- method,
115
- headers: requestHeaders,
116
- body: body ? JSON.stringify(body) : void 0
117
- });
118
- const responseData = await response.json().catch(()=>({}));
119
- if (!response.ok) {
120
- const errorData = responseData;
121
- throw new BloqueAPIError(errorData.message || `HTTP ${response.status}: ${response.statusText}`, response.status, errorData.code);
122
- }
123
- return responseData;
124
- } catch (error) {
125
- if (error instanceof BloqueAPIError) throw error;
126
- if (error instanceof Error) throw new BloqueAPIError(`Request failed: ${error.message}`, void 0, 'NETWORK_ERROR');
127
- throw new BloqueAPIError('Unknown error occurred', void 0, 'UNKNOWN_ERROR');
128
- }
129
- }
130
- }
131
- exports.API_BASE_URLS = __webpack_exports__.API_BASE_URLS;
132
- exports.BloqueAPIError = __webpack_exports__.BloqueAPIError;
133
- exports.BloqueConfigError = __webpack_exports__.BloqueConfigError;
134
- exports.DEFAULT_HEADERS = __webpack_exports__.DEFAULT_HEADERS;
135
- exports.HttpClient = __webpack_exports__.HttpClient;
136
- for(var __rspack_i in __webpack_exports__)if (-1 === [
137
- "API_BASE_URLS",
138
- "BloqueAPIError",
139
- "BloqueConfigError",
140
- "DEFAULT_HEADERS",
141
- "HttpClient"
142
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
143
- Object.defineProperty(exports, '__esModule', {
144
- value: true
145
- });
1
+ "use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,r)=>{for(var o in r)__webpack_require__.o(r,o)&&!__webpack_require__.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},__webpack_require__.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{API_BASE_URLS:()=>API_BASE_URLS,DEFAULT_HEADERS:()=>DEFAULT_HEADERS,HttpClient:()=>HttpClient,BloqueAPIError:()=>BloqueAPIError,BloqueConfigError:()=>BloqueConfigError});const API_BASE_URLS={sandbox:"https://dev.bloque.app",production:"https://api.bloque.app"},DEFAULT_HEADERS={"Content-Type":"application/json"};class BloqueAPIError extends Error{status;code;constructor(e,r,o){super(e),this.name="BloqueAPIError",this.status=r,this.code=o,Object.setPrototypeOf(this,BloqueAPIError.prototype)}}class BloqueConfigError extends Error{constructor(e){super(e),this.name="BloqueConfigError",Object.setPrototypeOf(this,BloqueConfigError.prototype)}}const createLocalStorageAdapter=()=>({get:()=>"u"<typeof localStorage?null:localStorage.getItem("access_token"),set:e=>{"u">typeof localStorage&&localStorage.setItem("access_token",e)},clear:()=>{"u">typeof localStorage&&localStorage.removeItem("access_token")}});class HttpClient{config;baseUrl;publicRoutes=["/api/aliases","/api/origins/*/assert"];constructor(e){this.validateConfig(e),this.config=e,this.baseUrl=API_BASE_URLS[e.mode??"production"]}isPublicRoute(e){let r=e.split("?")[0];return this.publicRoutes.some(e=>{let o=e.replace(/\*/g,"[^/]+");return RegExp(`^${o}$`).test(r)})}validateConfig(e){if(!e.apiKey||""===e.apiKey.trim())throw new BloqueConfigError("API key is required");if(e.mode||(e.mode="production"),!["sandbox","production"].includes(e.mode))throw new BloqueConfigError('Mode must be either "sandbox" or "production"');"client"!==e.runtime||e.tokenStorage||(e.tokenStorage=createLocalStorageAdapter())}async request(e){let{method:r,path:o,body:t,headers:_={}}=e,i=`${this.baseUrl}${o}`,s={...DEFAULT_HEADERS,Authorization:this.config.apiKey,..._};if("client"===this.config.runtime&&!this.isPublicRoute(o)){let e=this.config.tokenStorage?.get();if(!e)throw new BloqueConfigError("Authentication token is missing");s.Authorization=`Bearer ${e}`}try{let e=await fetch(i,{method:r,headers:s,body:t?JSON.stringify(t):void 0}),o=await e.json().catch(()=>({}));if(!e.ok)throw new BloqueAPIError(o.message||`HTTP ${e.status}: ${e.statusText}`,e.status,o.code);return o}catch(e){if(e instanceof BloqueAPIError)throw e;if(e instanceof Error)throw new BloqueAPIError(`Request failed: ${e.message}`,void 0,"NETWORK_ERROR");throw new BloqueAPIError("Unknown error occurred",void 0,"UNKNOWN_ERROR")}}}for(var __rspack_i in exports.API_BASE_URLS=__webpack_exports__.API_BASE_URLS,exports.BloqueAPIError=__webpack_exports__.BloqueAPIError,exports.BloqueConfigError=__webpack_exports__.BloqueConfigError,exports.DEFAULT_HEADERS=__webpack_exports__.DEFAULT_HEADERS,exports.HttpClient=__webpack_exports__.HttpClient,__webpack_exports__)-1===["API_BASE_URLS","BloqueAPIError","BloqueConfigError","DEFAULT_HEADERS","HttpClient"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
package/dist/index.js CHANGED
@@ -1,99 +1 @@
1
- const API_BASE_URLS = {
2
- sandbox: 'https://dev.bloque.app',
3
- production: 'https://api.bloque.app'
4
- };
5
- const DEFAULT_HEADERS = {
6
- 'Content-Type': 'application/json'
7
- };
8
- class BloqueAPIError extends Error {
9
- status;
10
- code;
11
- constructor(message, status, code){
12
- super(message);
13
- this.name = 'BloqueAPIError';
14
- this.status = status;
15
- this.code = code;
16
- Object.setPrototypeOf(this, BloqueAPIError.prototype);
17
- }
18
- }
19
- class BloqueConfigError extends Error {
20
- constructor(message){
21
- super(message);
22
- this.name = 'BloqueConfigError';
23
- Object.setPrototypeOf(this, BloqueConfigError.prototype);
24
- }
25
- }
26
- const createLocalStorageAdapter = ()=>({
27
- get: ()=>{
28
- if ('undefined' == typeof localStorage) return null;
29
- return localStorage.getItem('access_token');
30
- },
31
- set: (token)=>{
32
- if ('undefined' != typeof localStorage) localStorage.setItem('access_token', token);
33
- },
34
- clear: ()=>{
35
- if ('undefined' != typeof localStorage) localStorage.removeItem('access_token');
36
- }
37
- });
38
- class HttpClient {
39
- config;
40
- baseUrl;
41
- publicRoutes = [
42
- '/api/aliases',
43
- '/api/origins/*/assert'
44
- ];
45
- constructor(config){
46
- this.validateConfig(config);
47
- this.config = config;
48
- this.baseUrl = API_BASE_URLS[config.mode ?? 'production'];
49
- }
50
- isPublicRoute(path) {
51
- const pathWithoutQuery = path.split('?')[0];
52
- return this.publicRoutes.some((route)=>{
53
- const pattern = route.replace(/\*/g, '[^/]+');
54
- const regex = new RegExp(`^${pattern}$`);
55
- return regex.test(pathWithoutQuery);
56
- });
57
- }
58
- validateConfig(config) {
59
- if (!config.apiKey || '' === config.apiKey.trim()) throw new BloqueConfigError('API key is required');
60
- if (!config.mode) config.mode = 'production';
61
- if (![
62
- 'sandbox',
63
- 'production'
64
- ].includes(config.mode)) throw new BloqueConfigError('Mode must be either "sandbox" or "production"');
65
- if ('client' === config.runtime && !config.tokenStorage) config.tokenStorage = createLocalStorageAdapter();
66
- }
67
- async request(options) {
68
- const { method, path, body, headers = {} } = options;
69
- const url = `${this.baseUrl}${path}`;
70
- const requestHeaders = {
71
- ...DEFAULT_HEADERS,
72
- Authorization: this.config.apiKey,
73
- ...headers
74
- };
75
- if ('client' === this.config.runtime && !this.isPublicRoute(path)) {
76
- const token = this.config.tokenStorage?.get();
77
- if (!token) throw new BloqueConfigError('Authentication token is missing');
78
- requestHeaders.Authorization = `Bearer ${token}`;
79
- }
80
- try {
81
- const response = await fetch(url, {
82
- method,
83
- headers: requestHeaders,
84
- body: body ? JSON.stringify(body) : void 0
85
- });
86
- const responseData = await response.json().catch(()=>({}));
87
- if (!response.ok) {
88
- const errorData = responseData;
89
- throw new BloqueAPIError(errorData.message || `HTTP ${response.status}: ${response.statusText}`, response.status, errorData.code);
90
- }
91
- return responseData;
92
- } catch (error) {
93
- if (error instanceof BloqueAPIError) throw error;
94
- if (error instanceof Error) throw new BloqueAPIError(`Request failed: ${error.message}`, void 0, 'NETWORK_ERROR');
95
- throw new BloqueAPIError('Unknown error occurred', void 0, 'UNKNOWN_ERROR');
96
- }
97
- }
98
- }
99
- export { API_BASE_URLS, BloqueAPIError, BloqueConfigError, DEFAULT_HEADERS, HttpClient };
1
+ let t={sandbox:"https://dev.bloque.app",production:"https://api.bloque.app"},e={"Content-Type":"application/json"};class o extends Error{status;code;constructor(t,e,r){super(t),this.name="BloqueAPIError",this.status=e,this.code=r,Object.setPrototypeOf(this,o.prototype)}}class r extends Error{constructor(t){super(t),this.name="BloqueConfigError",Object.setPrototypeOf(this,r.prototype)}}class s{config;baseUrl;publicRoutes=["/api/aliases","/api/origins/*/assert"];constructor(e){this.validateConfig(e),this.config=e,this.baseUrl=t[e.mode??"production"]}isPublicRoute(t){let e=t.split("?")[0];return this.publicRoutes.some(t=>{let o=t.replace(/\*/g,"[^/]+");return RegExp(`^${o}$`).test(e)})}validateConfig(t){if(!t.apiKey||""===t.apiKey.trim())throw new r("API key is required");if(t.mode||(t.mode="production"),!["sandbox","production"].includes(t.mode))throw new r('Mode must be either "sandbox" or "production"');"client"!==t.runtime||t.tokenStorage||(t.tokenStorage={get:()=>"u"<typeof localStorage?null:localStorage.getItem("access_token"),set:t=>{"u">typeof localStorage&&localStorage.setItem("access_token",t)},clear:()=>{"u">typeof localStorage&&localStorage.removeItem("access_token")}})}async request(t){let{method:s,path:i,body:a,headers:n={}}=t,c=`${this.baseUrl}${i}`,l={...e,Authorization:this.config.apiKey,...n};if("client"===this.config.runtime&&!this.isPublicRoute(i)){let t=this.config.tokenStorage?.get();if(!t)throw new r("Authentication token is missing");l.Authorization=`Bearer ${t}`}try{let t=await fetch(c,{method:s,headers:l,body:a?JSON.stringify(a):void 0}),e=await t.json().catch(()=>({}));if(!t.ok)throw new o(e.message||`HTTP ${t.status}: ${t.statusText}`,t.status,e.code);return e}catch(t){if(t instanceof o)throw t;if(t instanceof Error)throw new o(`Request failed: ${t.message}`,void 0,"NETWORK_ERROR");throw new o("Unknown error occurred",void 0,"UNKNOWN_ERROR")}}}export{t as API_BASE_URLS,o as BloqueAPIError,r as BloqueConfigError,e as DEFAULT_HEADERS,s as HttpClient};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bloque/sdk-core",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "Core utilities and types for Bloque SDK.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -34,19 +34,5 @@
34
34
  ],
35
35
  "engines": {
36
36
  "node": ">=22"
37
- },
38
- "scripts": {
39
- "release": "bun publish --provenance",
40
- "build": "rslib build",
41
- "dev": "rslib build --watch",
42
- "clean": "rm -rf node_modules && rm -rf dist",
43
- "check": "biome check --write",
44
- "typecheck": "tsgo --noEmit"
45
- },
46
- "devDependencies": {
47
- "@rslib/core": "^0.18.4",
48
- "@types/node": "^24.10.1",
49
- "@typescript/native-preview": "latest",
50
- "typescript": "^5.9.3"
51
37
  }
52
- }
38
+ }