@bloque/sdk 0.0.21 → 0.0.22

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/README.md CHANGED
@@ -31,10 +31,13 @@ This SDK is compatible with multiple JavaScript runtimes:
31
31
  - **TypeScript First**: Built with TypeScript for complete type safety
32
32
  - **Simple API**: Intuitive interface for managing organizations, compliance, accounts, and identity
33
33
  - **Identity Registration**: Register individual users (KYC) and businesses (KYB) with multi-method authentication
34
+ - **User Sessions**: Secure user session management with `connect()` for authenticated operations
34
35
  - **Fully Async**: Promise-based API for modern JavaScript workflows
35
36
  - **Lightweight**: Minimal dependencies for optimal bundle size
36
37
  - **Modular**: Import only what you need with tree-shakeable exports
37
38
 
39
+ > **📌 Important:** Most operations require connecting to a user session first using `bloque.connect(urn)`. This ensures proper authentication and authorization. See the [User Sessions](#user-sessions-with-connect) section for details.
40
+
38
41
  ## Installation
39
42
 
40
43
  ```bash
@@ -51,6 +54,7 @@ import type { CreateOrgParams } from '@bloque/sdk/orgs';
51
54
 
52
55
  // Initialize the SDK with API key (backend only)
53
56
  const bloque = new SDK({
57
+ origin: 'your-origin-name', // Required: your origin identifier
54
58
  auth: {
55
59
  type: 'apiKey',
56
60
  apiKey: process.env.BLOQUE_API_KEY!,
@@ -59,7 +63,22 @@ const bloque = new SDK({
59
63
  platform: 'node', // optional: 'node' | 'bun' | 'deno'
60
64
  });
61
65
 
62
- // Create an organization
66
+ // Connect to user session for account operations
67
+ async function createCard() {
68
+ // First, connect to the user's session
69
+ const userSession = await bloque.connect('did:bloque:your-origin:user-alias');
70
+
71
+ // Now create a virtual card through the session
72
+ const card = await userSession.accounts.card.create({
73
+ urn: 'did:bloque:your-origin:user-alias',
74
+ name: 'My Virtual Card',
75
+ });
76
+
77
+ console.log('Card created:', card.urn);
78
+ console.log('Last four digits:', card.lastFour);
79
+ }
80
+
81
+ // Create an organization (direct SDK access, no connect needed)
63
82
  async function createOrganization() {
64
83
  const params: CreateOrgParams = {
65
84
  org_type: 'business',
@@ -79,20 +98,10 @@ async function createOrganization() {
79
98
  },
80
99
  };
81
100
 
82
- const organization = await bloque.orgs.create(params);
101
+ const userSession = await bloque.connect('did:bloque:your-origin:user-alias');
102
+ const organization = await userSession.orgs.create(params);
83
103
  console.log('Organization created:', organization);
84
104
  }
85
-
86
- // Create a virtual card
87
- async function createCard() {
88
- const card = await bloque.accounts.card.create({
89
- urn: 'did:bloque:user:123e4567',
90
- name: 'My Virtual Card',
91
- });
92
-
93
- console.log('Card created:', card.urn);
94
- console.log('Last four digits:', card.lastFour);
95
- }
96
105
  ```
97
106
 
98
107
  ### Frontend (Browser, React Native)
@@ -175,6 +184,10 @@ const bloque = new SDK({
175
184
 
176
185
  ### Configuration Options
177
186
 
187
+ - **`origin`** (string, required): Your origin identifier/namespace
188
+ - This identifies your application or organization in the Bloque platform
189
+ - Example: `'my-app'`, `'bloque-root'`, `'ethereum-mainnet'`
190
+
178
191
  - **`auth`** (object, required): Authentication configuration
179
192
  - `type: 'apiKey'`: For backend platforms
180
193
  - `apiKey` (string, required): Your Bloque API key
@@ -195,6 +208,42 @@ const bloque = new SDK({
195
208
  - Browser automatically uses `localStorage` if not provided
196
209
  - Must implement: `get()`, `set(token)`, `clear()`
197
210
 
211
+ ### User Sessions with `connect()`
212
+
213
+ Most operations in the SDK require connecting to a user session first. This ensures proper authentication and authorization for user-specific operations.
214
+
215
+ ```typescript
216
+ // Initialize SDK
217
+ const bloque = new SDK({
218
+ origin: 'your-origin',
219
+ auth: {
220
+ type: 'apiKey',
221
+ apiKey: process.env.BLOQUE_API_KEY!,
222
+ },
223
+ mode: 'production',
224
+ });
225
+
226
+ // Connect to user session
227
+ const userSession = await bloque.connect('did:bloque:your-origin:user-alias');
228
+
229
+ // Now perform operations through the session
230
+ const card = await userSession.accounts.card.create({
231
+ urn: 'did:bloque:your-origin:user-alias',
232
+ name: 'My Card',
233
+ });
234
+ ```
235
+
236
+ **What `connect()` does:**
237
+ - Authenticates the user with the specified URN
238
+ - Obtains an access token for the user session
239
+ - Returns a session object with access to: `accounts`, `compliance`, `identity`, `orgs`
240
+
241
+ **URN Format:**
242
+ - Pattern: `did:bloque:{origin}:{user-alias}`
243
+ - Example: `did:bloque:my-app:john-doe`
244
+ - The `{origin}` must match the origin specified in SDK configuration
245
+ - The `{user-alias}` is the user's unique identifier in your origin
246
+
198
247
  ### Platform and Authentication Compatibility
199
248
 
200
249
  | Platform | API Key Auth | JWT Auth | Token Storage |
@@ -214,7 +263,11 @@ The organizations resource allows you to create and manage organizations in the
214
263
  #### Create an Organization
215
264
 
216
265
  ```typescript
217
- const organization = await bloque.orgs.create(params);
266
+ // Connect to user session first
267
+ const userSession = await bloque.connect('did:bloque:your-origin:user-alias');
268
+
269
+ // Create organization through the session
270
+ const organization = await userSession.orgs.create(params);
218
271
  ```
219
272
 
220
273
  **Parameters**:
@@ -278,8 +331,12 @@ The compliance resource provides KYC (Know Your Customer) verification functiona
278
331
  Start a KYC verification process for a user:
279
332
 
280
333
  ```typescript
281
- const verification = await bloque.compliance.kyc.startVerification({
282
- urn: 'did:bloque:origin:user-id',
334
+ // Connect to user session
335
+ const userSession = await bloque.connect('did:bloque:your-origin:user-alias');
336
+
337
+ // Start KYC verification
338
+ const verification = await userSession.compliance.kyc.startVerification({
339
+ urn: 'did:bloque:your-origin:user-alias',
283
340
  });
284
341
  ```
285
342
 
@@ -358,8 +415,12 @@ The accounts resource allows you to create virtual cards for users.
358
415
  Create a virtual card for a user:
359
416
 
360
417
  ```typescript
361
- const card = await bloque.accounts.card.create({
362
- urn: 'did:bloque:user:123e4567',
418
+ // Connect to user session
419
+ const userSession = await bloque.connect('did:bloque:your-origin:user-alias');
420
+
421
+ // Create virtual card
422
+ const card = await userSession.accounts.card.create({
423
+ urn: 'did:bloque:your-origin:user-alias',
363
424
  name: 'My Virtual Card', // Optional
364
425
  });
365
426
  ```
package/dist/bloque.d.ts CHANGED
@@ -5,9 +5,12 @@ import { IdentityClient } from '@bloque/sdk-identity';
5
5
  import { OrgsClient } from '@bloque/sdk-orgs';
6
6
  export declare class SDK {
7
7
  private readonly httpClient;
8
- readonly accounts: AccountsClient;
9
- readonly compliance: ComplianceClient;
10
- readonly identity: IdentityClient;
11
- readonly orgs: OrgsClient;
12
8
  constructor(config: BloqueConfig);
9
+ private extractUserAlias;
10
+ connect(urn: string): Promise<{
11
+ accounts: AccountsClient;
12
+ compliance: ComplianceClient;
13
+ identity: IdentityClient;
14
+ orgs: OrgsClient;
15
+ }>;
13
16
  }
package/dist/index.cjs CHANGED
@@ -1 +1 @@
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,_)=>{for(var t in _)__webpack_require__.o(_,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:_[t]})},__webpack_require__.o=(e,_)=>Object.prototype.hasOwnProperty.call(e,_),__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__,{SDK:()=>SDK});const sdk_accounts_namespaceObject=require("@bloque/sdk-accounts"),sdk_compliance_namespaceObject=require("@bloque/sdk-compliance"),sdk_core_namespaceObject=require("@bloque/sdk-core"),sdk_identity_namespaceObject=require("@bloque/sdk-identity"),sdk_orgs_namespaceObject=require("@bloque/sdk-orgs");class SDK{httpClient;accounts;compliance;identity;orgs;constructor(e){this.httpClient=new sdk_core_namespaceObject.HttpClient(e),this.accounts=new sdk_accounts_namespaceObject.AccountsClient(this.httpClient),this.compliance=new sdk_compliance_namespaceObject.ComplianceClient(this.httpClient),this.identity=new sdk_identity_namespaceObject.IdentityClient(this.httpClient),this.orgs=new sdk_orgs_namespaceObject.OrgsClient(this.httpClient)}}for(var __rspack_i in exports.SDK=__webpack_exports__.SDK,__webpack_exports__)-1===["SDK"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
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,t)=>{for(var _ in t)__webpack_require__.o(t,_)&&!__webpack_require__.o(e,_)&&Object.defineProperty(e,_,{enumerable:!0,get:t[_]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__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__,{SDK:()=>SDK});const sdk_accounts_namespaceObject=require("@bloque/sdk-accounts"),sdk_compliance_namespaceObject=require("@bloque/sdk-compliance"),sdk_core_namespaceObject=require("@bloque/sdk-core"),sdk_identity_namespaceObject=require("@bloque/sdk-identity"),sdk_orgs_namespaceObject=require("@bloque/sdk-orgs");class SDK{httpClient;constructor(e){this.httpClient=new sdk_core_namespaceObject.HttpClient(e)}extractUserAlias(e){let t=e.match(/^did:bloque:[^:]+:([^:]+)$/);if(!t)throw Error(`Invalid user alias URN: ${e}`);return t[1]}async connect(e){let t=this.httpClient.config,_=await this.httpClient.request({path:`/api/origins/${t.origin}/connect`,method:"POST",body:{assertion_result:{challengeType:"API_KEY",value:{api_key:"apiKey"===t.auth.type?t.auth.apiKey:"",alias:this.extractUserAlias(e)}},extra_context:{}}});return this.httpClient.config.accessToken=_.result.access_token,{accounts:new sdk_accounts_namespaceObject.AccountsClient(this.httpClient),compliance:new sdk_compliance_namespaceObject.ComplianceClient(this.httpClient),identity:new sdk_identity_namespaceObject.IdentityClient(this.httpClient),orgs:new sdk_orgs_namespaceObject.OrgsClient(this.httpClient)}}}for(var __rspack_i in exports.SDK=__webpack_exports__.SDK,__webpack_exports__)-1===["SDK"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{AccountsClient as t}from"@bloque/sdk-accounts";import{ComplianceClient as i}from"@bloque/sdk-compliance";import{HttpClient as o}from"@bloque/sdk-core";import{IdentityClient as e}from"@bloque/sdk-identity";import{OrgsClient as s}from"@bloque/sdk-orgs";class n{httpClient;accounts;compliance;identity;orgs;constructor(n){this.httpClient=new o(n),this.accounts=new t(this.httpClient),this.compliance=new i(this.httpClient),this.identity=new e(this.httpClient),this.orgs=new s(this.httpClient)}}export{n as SDK};
1
+ import{AccountsClient as t}from"@bloque/sdk-accounts";import{ComplianceClient as e}from"@bloque/sdk-compliance";import{HttpClient as i}from"@bloque/sdk-core";import{IdentityClient as o}from"@bloque/sdk-identity";import{OrgsClient as s}from"@bloque/sdk-orgs";class n{httpClient;constructor(t){this.httpClient=new i(t)}extractUserAlias(t){let e=t.match(/^did:bloque:[^:]+:([^:]+)$/);if(!e)throw Error(`Invalid user alias URN: ${t}`);return e[1]}async connect(i){let n=this.httpClient.config,r=await this.httpClient.request({path:`/api/origins/${n.origin}/connect`,method:"POST",body:{assertion_result:{challengeType:"API_KEY",value:{api_key:"apiKey"===n.auth.type?n.auth.apiKey:"",alias:this.extractUserAlias(i)}},extra_context:{}}});return this.httpClient.config.accessToken=r.result.access_token,{accounts:new t(this.httpClient),compliance:new e(this.httpClient),identity:new o(this.httpClient),orgs:new s(this.httpClient)}}}export{n as SDK};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bloque/sdk",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Official Bloque SDK",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -63,10 +63,10 @@
63
63
  "node": ">=22"
64
64
  },
65
65
  "dependencies": {
66
- "@bloque/sdk-accounts": "0.0.21",
67
- "@bloque/sdk-compliance": "0.0.21",
68
- "@bloque/sdk-core": "0.0.21",
69
- "@bloque/sdk-identity": "0.0.21",
70
- "@bloque/sdk-orgs": "0.0.21"
66
+ "@bloque/sdk-accounts": "0.0.22",
67
+ "@bloque/sdk-compliance": "0.0.22",
68
+ "@bloque/sdk-core": "0.0.22",
69
+ "@bloque/sdk-identity": "0.0.22",
70
+ "@bloque/sdk-orgs": "0.0.22"
71
71
  }
72
72
  }