@bloque/sdk 0.6.0 → 0.8.0

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/bloque.d.ts CHANGED
@@ -1,9 +1,38 @@
1
1
  import { AccountsClient } from '@bloque/sdk-accounts';
2
2
  import { ComplianceClient } from '@bloque/sdk-compliance';
3
3
  import { type BloqueSDKConfig } from '@bloque/sdk-core';
4
- import { type CreateIdentityParams, IdentityClient, type IdentityMe, type OriginMetadataPatch, type UpdateOriginMetadataResult } from '@bloque/sdk-identity';
4
+ import { type CreateIdentityParams, IdentityClient, type IdentityMe } from '@bloque/sdk-identity';
5
5
  import { OrgsClient } from '@bloque/sdk-orgs';
6
6
  import { SwapClient } from '@bloque/sdk-swap';
7
+ /**
8
+ * Self-serviceable presentation metadata for an API-key origin. This is the
9
+ * complete allowlist accepted by `bloque.origins.updateMetadata()` — any
10
+ * other field on an origin's `metadata` (e.g. `contactEmail`) is owned by
11
+ * other systems and can't be set through this surface.
12
+ */
13
+ export interface OriginMetadataPatch {
14
+ /**
15
+ * Developer-facing display name substituted as `{{developer_name}}` into
16
+ * the hosted TOS document. Non-empty, at most 200 characters.
17
+ */
18
+ company?: string;
19
+ /** Skip the hosted TOS gate's intro screens. */
20
+ tosGateShowHome?: boolean;
21
+ /**
22
+ * Brand accent color applied to both hosted gates' `--accent` CSS
23
+ * variable. Strict 3- or 6-digit CSS hex (e.g. `#f80` or `#ff8800`) —
24
+ * anything else is silently dropped server-side, never partially applied.
25
+ */
26
+ gateAccentColor?: string;
27
+ /**
28
+ * Bare origins (scheme + host + port, no path or trailing slash) allowed
29
+ * as `returnUrl` on `compliance.verificationGate.start()`, in addition to
30
+ * the deployment-wide `VERIFICATION_GATE_RETURN_URL_ALLOWLIST` env var —
31
+ * either being satisfied is enough. Replaces the whole array; it does not
32
+ * append to whatever is already configured.
33
+ */
34
+ verificationGateReturnUrlAllowlist?: string[];
35
+ }
7
36
  export interface UpdateOriginMetadataOptions {
8
37
  /**
9
38
  * Origin namespace to patch. Defaults to the SDK's configured `origin` —
@@ -20,6 +49,13 @@ export interface UpdateOriginMetadataOptions {
20
49
  apiKey?: string;
21
50
  metadata: OriginMetadataPatch;
22
51
  }
52
+ export interface UpdateOriginMetadataResult {
53
+ /** Origin namespace that was updated. */
54
+ originName: string;
55
+ /** The origin's full metadata after the patch was merged in. */
56
+ metadata: Record<string, unknown>;
57
+ updated: true;
58
+ }
23
59
  export interface BloqueClients {
24
60
  accounts: AccountsClient;
25
61
  compliance: ComplianceClient;
@@ -52,12 +88,37 @@ export declare class SDK {
52
88
  }>;
53
89
  authenticate(): Promise<BloqueClients>;
54
90
  me(): Promise<IdentityMe>;
91
+ /**
92
+ * Register a new identity on this SDK's configured origin, authenticated
93
+ * by the origin's own key (`API_KEY` challenge).
94
+ *
95
+ * If you're calling this from your own backend on behalf of an end user,
96
+ * pass their real IP as `params.clientIp` — Bloque uses it to resolve
97
+ * their usage country and records it on the compliance audit trail,
98
+ * instead of falling back to your server's IP.
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * await bloque.register('user-123', {
103
+ * type: 'individual',
104
+ * profile: { firstName: 'Jane', lastName: 'Doe', ... },
105
+ * clientIp: req.headers['x-forwarded-for'],
106
+ * });
107
+ * ```
108
+ */
55
109
  register(alias: string, params: CreateIdentityParams): Promise<BloqueClients>;
56
110
  connect(): Promise<BloqueClients>;
57
111
  connect(options: {
58
112
  scopes?: string[];
59
113
  }): Promise<BloqueClients>;
60
- connect(alias: string): Promise<BloqueClients>;
114
+ /**
115
+ * `originKey` auth only. `options.clientIp` forwards the end user's real
116
+ * IP when your backend connects on their behalf — see `register()`'s docs
117
+ * for why that matters.
118
+ */
119
+ connect(alias: string, options?: {
120
+ clientIp?: string;
121
+ }): Promise<BloqueClients>;
61
122
  connect(origin: string, alias: string, code: string): Promise<BloqueClients>;
62
123
  /**
63
124
  * Self-service origin configuration, authenticated purely by the origin's
@@ -65,7 +126,7 @@ export declare class SDK {
65
126
  * `register()`, but for configuring the origin itself rather than one of
66
127
  * its identities.
67
128
  */
68
- get origin(): {
129
+ get origins(): {
69
130
  /**
70
131
  * Patch this origin's own presentation metadata (`company`,
71
132
  * `tosGateShowHome`, `gateAccentColor`,
@@ -74,15 +135,18 @@ export declare class SDK {
74
135
  * you typically only pass `metadata`:
75
136
  *
76
137
  * ```typescript
77
- * await bloque.origin.metadata({
138
+ * await bloque.origins.updateMetadata({
78
139
  * metadata: { gateAccentColor: '#1a73e8' },
79
140
  * });
80
141
  * ```
81
142
  *
82
143
  * This is a one-time/deploy-script call, not something you run
83
- * per-request or per-user.
144
+ * per-request or per-user. Fields you omit from `metadata` are left
145
+ * untouched on the origin (shallow merge) — the response echoes the
146
+ * full post-merge metadata so you can confirm what actually took
147
+ * effect.
84
148
  */
85
- metadata: (options: UpdateOriginMetadataOptions) => Promise<UpdateOriginMetadataResult>;
149
+ updateMetadata: (options: UpdateOriginMetadataOptions) => Promise<UpdateOriginMetadataResult>;
86
150
  };
87
151
  private updateOriginMetadata;
88
152
  private resolveOwnApiKey;
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,r)=>{for(var t in r)__webpack_require__.o(r,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},__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__,{BloqueInsufficientFundsError:()=>sdk_core_namespaceObject.BloqueInsufficientFundsError,BloqueAuthenticationError:()=>sdk_core_namespaceObject.BloqueAuthenticationError,BloqueNetworkError:()=>sdk_core_namespaceObject.BloqueNetworkError,BloqueRateLimitError:()=>sdk_core_namespaceObject.BloqueRateLimitError,BloqueAPIError:()=>sdk_core_namespaceObject.BloqueAPIError,BloqueConfigError:()=>sdk_core_namespaceObject.BloqueConfigError,BloqueTierLimitExceededError:()=>sdk_core_namespaceObject.BloqueTierLimitExceededError,BloqueValidationError:()=>sdk_core_namespaceObject.BloqueValidationError,BloqueVerificationPendingError:()=>sdk_core_namespaceObject.BloqueVerificationPendingError,BloqueVerificationRequiredError:()=>sdk_core_namespaceObject.BloqueVerificationRequiredError,BloqueNotFoundError:()=>sdk_core_namespaceObject.BloqueNotFoundError,SDK:()=>SDK,BloqueTimeoutError:()=>sdk_core_namespaceObject.BloqueTimeoutError});const sdk_core_namespaceObject=require("@bloque/sdk-core"),sdk_accounts_namespaceObject=require("@bloque/sdk-accounts"),sdk_compliance_namespaceObject=require("@bloque/sdk-compliance"),sdk_identity_namespaceObject=require("@bloque/sdk-identity"),sdk_orgs_namespaceObject=require("@bloque/sdk-orgs"),sdk_swap_namespaceObject=require("@bloque/sdk-swap");class SDK{httpClient;identity;constructor(e){this.httpClient=new sdk_core_namespaceObject.HttpClient(e),this.identity=new sdk_identity_namespaceObject.IdentityClient(this.httpClient)}buildClients(e,r){return{accounts:new sdk_accounts_namespaceObject.AccountsClient(e),compliance:new sdk_compliance_namespaceObject.ComplianceClient(e),identity:new sdk_identity_namespaceObject.IdentityClient(e),orgs:new sdk_orgs_namespaceObject.OrgsClient(e),swap:new sdk_swap_namespaceObject.SwapClient(e),urn:e.urn,get accessToken(){return r}}}getOriginKey(){let{auth:e}=this.httpClient;return"originKey"===e.type?e.originKey:""}buildUrn(e){let r=this.httpClient.origin;if(!r)throw Error("Origin is required to build a urn");return`did:bloque:${r}:${e}`}requireOrigin(){let e=this.httpClient.origin;if(!e)throw Error("Origin is required for this operation");return e}buildOtpValue(e,r){let t=e.trim();return t.includes("@")?{code:r,email:t}:{code:r,phone:t}}assertJwtAuth(){if("jwt"!==this.httpClient.auth.type)throw Error("This operation is only available for JWT auth")}async assert(e,r){return this.assertJwtAuth(),await this.httpClient.request({path:`/api/origins/${e}/assert?alias=${encodeURIComponent(r)}`,method:"GET"})}async authenticate(){let{auth:e}=this.httpClient;if("jwt"!==e.type)throw Error("authenticate is only available for JWT auth");let r=await this.identity.me();return this.httpClient.setOrigin(r.origin),this.httpClient.setUrn(r.urn),this.buildClients(this.httpClient,this.httpClient.getJwtToken()??"")}async me(){return await this.identity.me()}async register(e,r){if("originKey"!==this.httpClient.auth.type)throw Error("register() is only available for originKey auth");r.extraContext||(r.extraContext={});let t=this.buildUrn(e),i=this.requireOrigin(),o=await this.identity.origins.register(e,i,{assertionResult:{alias:e,challengeType:"API_KEY",value:{apiKey:this.getOriginKey(),alias:e}},...r}),n=this.httpClient.fork();return n.setAccessToken(o.accessToken),n.setUrn(t),this.buildClients(n,o.accessToken)}async connect(e,r,t){let i=this.httpClient.auth.type;if("apiKey"===i){if("string"==typeof e)throw Error("connect() takes no alias for apiKey auth. Use connect() or connect({ scopes })");await this.httpClient.ensureExchanged();let r=this.httpClient.fork(),t=await new sdk_identity_namespaceObject.IdentityClient(r).me();return r.setOrigin(t.origin),r.setUrn(t.urn),this.buildClients(r,r.accessToken??"")}if("originKey"===i){if(!e||"string"!=typeof e)throw Error("connect(alias) is required for originKey auth");let r=this.buildUrn(e),t=this.requireOrigin(),i=await this.httpClient.request({path:`/api/origins/${t}/connect`,method:"POST",body:{assertion_result:{challengeType:"API_KEY",value:{api_key:this.getOriginKey(),alias:e}},extra_context:{}}}),o=this.httpClient.fork();return o.setAccessToken(i.result.access_token),o.setUrn(r),this.buildClients(o,i.result.access_token)}if(this.assertJwtAuth(),!e||"string"!=typeof e||!r||!t)throw Error("connect(origin, alias, code) is required for JWT auth");let o=await this.httpClient.request({path:`/api/origins/${e}/connect`,method:"POST",body:{assertion_result:{challengeType:"OTP",alias:r,value:this.buildOtpValue(r,t)},extra_context:{}}}),n=`did:bloque:${e}:${r}`,a=this.httpClient.fork();return a.setJwtToken(o.result.access_token),a.setOrigin(e),a.setUrn(n),this.buildClients(a,o.result.access_token)}get origin(){return{metadata:e=>this.updateOriginMetadata(e)}}async updateOriginMetadata(e){let r=e.originName??this.httpClient.origin;if(!r)throw Error("origin.metadata() requires originName (or configure the SDK with an origin)");let t=e.apiKey??this.resolveOwnApiKey();if(!t)throw Error("origin.metadata() requires apiKey (or configure the SDK with apiKey/originKey auth)");return this.identity.origins.updateMetadata({originName:r,apiKey:t,metadata:e.metadata})}resolveOwnApiKey(){let{auth:e}=this.httpClient;return"apiKey"===e.type?e.apiKey:"originKey"===e.type?e.originKey:void 0}}for(var __rspack_i in exports.BloqueAPIError=__webpack_exports__.BloqueAPIError,exports.BloqueAuthenticationError=__webpack_exports__.BloqueAuthenticationError,exports.BloqueConfigError=__webpack_exports__.BloqueConfigError,exports.BloqueInsufficientFundsError=__webpack_exports__.BloqueInsufficientFundsError,exports.BloqueNetworkError=__webpack_exports__.BloqueNetworkError,exports.BloqueNotFoundError=__webpack_exports__.BloqueNotFoundError,exports.BloqueRateLimitError=__webpack_exports__.BloqueRateLimitError,exports.BloqueTierLimitExceededError=__webpack_exports__.BloqueTierLimitExceededError,exports.BloqueTimeoutError=__webpack_exports__.BloqueTimeoutError,exports.BloqueValidationError=__webpack_exports__.BloqueValidationError,exports.BloqueVerificationPendingError=__webpack_exports__.BloqueVerificationPendingError,exports.BloqueVerificationRequiredError=__webpack_exports__.BloqueVerificationRequiredError,exports.SDK=__webpack_exports__.SDK,__webpack_exports__)-1===["BloqueAPIError","BloqueAuthenticationError","BloqueConfigError","BloqueInsufficientFundsError","BloqueNetworkError","BloqueNotFoundError","BloqueRateLimitError","BloqueTierLimitExceededError","BloqueTimeoutError","BloqueValidationError","BloqueVerificationPendingError","BloqueVerificationRequiredError","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 r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__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__,{BloqueInsufficientFundsError:()=>sdk_core_namespaceObject.BloqueInsufficientFundsError,BloqueAuthenticationError:()=>sdk_core_namespaceObject.BloqueAuthenticationError,BloqueNetworkError:()=>sdk_core_namespaceObject.BloqueNetworkError,BloqueRateLimitError:()=>sdk_core_namespaceObject.BloqueRateLimitError,BloqueAPIError:()=>sdk_core_namespaceObject.BloqueAPIError,BloqueConfigError:()=>sdk_core_namespaceObject.BloqueConfigError,BloqueTierLimitExceededError:()=>sdk_core_namespaceObject.BloqueTierLimitExceededError,BloqueValidationError:()=>sdk_core_namespaceObject.BloqueValidationError,BloqueVerificationPendingError:()=>sdk_core_namespaceObject.BloqueVerificationPendingError,BloqueVerificationRequiredError:()=>sdk_core_namespaceObject.BloqueVerificationRequiredError,BloqueNotFoundError:()=>sdk_core_namespaceObject.BloqueNotFoundError,SDK:()=>SDK,BloqueTimeoutError:()=>sdk_core_namespaceObject.BloqueTimeoutError});const sdk_core_namespaceObject=require("@bloque/sdk-core"),sdk_accounts_namespaceObject=require("@bloque/sdk-accounts"),sdk_compliance_namespaceObject=require("@bloque/sdk-compliance"),sdk_identity_namespaceObject=require("@bloque/sdk-identity"),sdk_orgs_namespaceObject=require("@bloque/sdk-orgs"),sdk_swap_namespaceObject=require("@bloque/sdk-swap");class SDK{httpClient;identity;constructor(e){this.httpClient=new sdk_core_namespaceObject.HttpClient(e),this.identity=new sdk_identity_namespaceObject.IdentityClient(this.httpClient)}buildClients(e,t){return{accounts:new sdk_accounts_namespaceObject.AccountsClient(e),compliance:new sdk_compliance_namespaceObject.ComplianceClient(e),identity:new sdk_identity_namespaceObject.IdentityClient(e),orgs:new sdk_orgs_namespaceObject.OrgsClient(e),swap:new sdk_swap_namespaceObject.SwapClient(e),urn:e.urn,get accessToken(){return t}}}getOriginKey(){let{auth:e}=this.httpClient;return"originKey"===e.type?e.originKey:""}buildUrn(e){let t=this.httpClient.origin;if(!t)throw Error("Origin is required to build a urn");return`did:bloque:${t}:${e}`}requireOrigin(){let e=this.httpClient.origin;if(!e)throw Error("Origin is required for this operation");return e}buildOtpValue(e,t){let r=e.trim();return r.includes("@")?{code:t,email:r}:{code:t,phone:r}}assertJwtAuth(){if("jwt"!==this.httpClient.auth.type)throw Error("This operation is only available for JWT auth")}async assert(e,t){return this.assertJwtAuth(),await this.httpClient.request({path:`/api/origins/${e}/assert?alias=${encodeURIComponent(t)}`,method:"GET"})}async authenticate(){let{auth:e}=this.httpClient;if("jwt"!==e.type)throw Error("authenticate is only available for JWT auth");let t=await this.identity.me();return this.httpClient.setOrigin(t.origin),this.httpClient.setUrn(t.urn),this.buildClients(this.httpClient,this.httpClient.getJwtToken()??"")}async me(){return await this.identity.me()}async register(e,t){if("originKey"!==this.httpClient.auth.type)throw Error("register() is only available for originKey auth");t.extraContext||(t.extraContext={});let r=this.buildUrn(e),i=this.requireOrigin(),o=await this.identity.origins.register(e,i,{assertionResult:{alias:e,challengeType:"API_KEY",value:{apiKey:this.getOriginKey(),alias:e}},...t}),a=this.httpClient.fork();return a.setAccessToken(o.accessToken),a.setUrn(r),this.buildClients(a,o.accessToken)}async connect(e,t,r){let i=this.httpClient.auth.type;if("apiKey"===i){if("string"==typeof e)throw Error("connect() takes no alias for apiKey auth. Use connect() or connect({ scopes })");await this.httpClient.ensureExchanged();let t=this.httpClient.fork(),r=await new sdk_identity_namespaceObject.IdentityClient(t).me();return t.setOrigin(r.origin),t.setUrn(r.urn),this.buildClients(t,t.accessToken??"")}if("originKey"===i){if(!e||"string"!=typeof e)throw Error("connect(alias) is required for originKey auth");let r=this.buildUrn(e),i=this.requireOrigin(),o=t&&"object"==typeof t?t.clientIp:void 0,a=await this.httpClient.request({path:`/api/origins/${i}/connect`,method:"POST",body:{assertion_result:{challengeType:"API_KEY",value:{api_key:this.getOriginKey(),alias:e}},extra_context:{}},headers:o?{"x-original-client-ip":o}:void 0}),n=this.httpClient.fork();return n.setAccessToken(a.result.access_token),n.setUrn(r),this.buildClients(n,a.result.access_token)}if(this.assertJwtAuth(),!e||"string"!=typeof e||!t||"string"!=typeof t||!r)throw Error("connect(origin, alias, code) is required for JWT auth");let o=await this.httpClient.request({path:`/api/origins/${e}/connect`,method:"POST",body:{assertion_result:{challengeType:"OTP",alias:t,value:this.buildOtpValue(t,r)},extra_context:{}}}),a=`did:bloque:${e}:${t}`,n=this.httpClient.fork();return n.setJwtToken(o.result.access_token),n.setOrigin(e),n.setUrn(a),this.buildClients(n,o.result.access_token)}get origins(){return{updateMetadata:e=>this.updateOriginMetadata(e)}}async updateOriginMetadata(e){let t=e.originName??this.httpClient.origin;if(!t)throw Error("origins.updateMetadata() requires originName (or configure the SDK with an origin)");let r=e.apiKey??this.resolveOwnApiKey();if(!r)throw Error("origins.updateMetadata() requires apiKey (or configure the SDK with apiKey/originKey auth)");let i={};void 0!==e.metadata.company&&(i.company=e.metadata.company),void 0!==e.metadata.tosGateShowHome&&(i.tos_gate_show_home=e.metadata.tosGateShowHome),void 0!==e.metadata.gateAccentColor&&(i.gate_accent_color=e.metadata.gateAccentColor),void 0!==e.metadata.verificationGateReturnUrlAllowlist&&(i.verification_gate_return_url_allowlist=e.metadata.verificationGateReturnUrlAllowlist);let o=await this.httpClient.request({method:"PATCH",path:`/api/origins/${t}/metadata`,body:{api_key:r,metadata:i},_skipExchange:!0});return{originName:o.origin_name,metadata:o.metadata,updated:!0}}resolveOwnApiKey(){let{auth:e}=this.httpClient;return"apiKey"===e.type?e.apiKey:"originKey"===e.type?e.originKey:void 0}}for(var __rspack_i in exports.BloqueAPIError=__webpack_exports__.BloqueAPIError,exports.BloqueAuthenticationError=__webpack_exports__.BloqueAuthenticationError,exports.BloqueConfigError=__webpack_exports__.BloqueConfigError,exports.BloqueInsufficientFundsError=__webpack_exports__.BloqueInsufficientFundsError,exports.BloqueNetworkError=__webpack_exports__.BloqueNetworkError,exports.BloqueNotFoundError=__webpack_exports__.BloqueNotFoundError,exports.BloqueRateLimitError=__webpack_exports__.BloqueRateLimitError,exports.BloqueTierLimitExceededError=__webpack_exports__.BloqueTierLimitExceededError,exports.BloqueTimeoutError=__webpack_exports__.BloqueTimeoutError,exports.BloqueValidationError=__webpack_exports__.BloqueValidationError,exports.BloqueVerificationPendingError=__webpack_exports__.BloqueVerificationPendingError,exports.BloqueVerificationRequiredError=__webpack_exports__.BloqueVerificationRequiredError,exports.SDK=__webpack_exports__.SDK,__webpack_exports__)-1===["BloqueAPIError","BloqueAuthenticationError","BloqueConfigError","BloqueInsufficientFundsError","BloqueNetworkError","BloqueNotFoundError","BloqueRateLimitError","BloqueTierLimitExceededError","BloqueTimeoutError","BloqueValidationError","BloqueVerificationPendingError","BloqueVerificationRequiredError","SDK"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
package/dist/index.d.ts CHANGED
@@ -7,5 +7,5 @@ export type * from '@bloque/sdk-identity';
7
7
  export type * from '@bloque/sdk-orgs';
8
8
  export type * from '@bloque/sdk-swap';
9
9
  export type { BrebClient as SwapBrebClient, ExternalUsBankSwapClient, } from '@bloque/sdk-swap';
10
- export type { BloqueClients, UpdateOriginMetadataOptions } from './bloque';
10
+ export type { BloqueClients, OriginMetadataPatch, UpdateOriginMetadataOptions, UpdateOriginMetadataResult, } from './bloque';
11
11
  export { SDK } from './bloque';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{BloqueAPIError as t,BloqueAuthenticationError as e,BloqueConfigError as i,BloqueInsufficientFundsError as r,BloqueNetworkError as n,BloqueNotFoundError as o,BloqueRateLimitError as s,BloqueTierLimitExceededError as a,BloqueTimeoutError as l,BloqueValidationError as h,BloqueVerificationPendingError as u,BloqueVerificationRequiredError as p,HttpClient as c}from"@bloque/sdk-core";import{AccountsClient as d}from"@bloque/sdk-accounts";import{ComplianceClient as g}from"@bloque/sdk-compliance";import{IdentityClient as y}from"@bloque/sdk-identity";import{OrgsClient as w}from"@bloque/sdk-orgs";import{SwapClient as f}from"@bloque/sdk-swap";class m{httpClient;identity;constructor(t){this.httpClient=new c(t),this.identity=new y(this.httpClient)}buildClients(t,e){return{accounts:new d(t),compliance:new g(t),identity:new y(t),orgs:new w(t),swap:new f(t),urn:t.urn,get accessToken(){return e}}}getOriginKey(){let{auth:t}=this.httpClient;return"originKey"===t.type?t.originKey:""}buildUrn(t){let e=this.httpClient.origin;if(!e)throw Error("Origin is required to build a urn");return`did:bloque:${e}:${t}`}requireOrigin(){let t=this.httpClient.origin;if(!t)throw Error("Origin is required for this operation");return t}buildOtpValue(t,e){let i=t.trim();return i.includes("@")?{code:e,email:i}:{code:e,phone:i}}assertJwtAuth(){if("jwt"!==this.httpClient.auth.type)throw Error("This operation is only available for JWT auth")}async assert(t,e){return this.assertJwtAuth(),await this.httpClient.request({path:`/api/origins/${t}/assert?alias=${encodeURIComponent(e)}`,method:"GET"})}async authenticate(){let{auth:t}=this.httpClient;if("jwt"!==t.type)throw Error("authenticate is only available for JWT auth");let e=await this.identity.me();return this.httpClient.setOrigin(e.origin),this.httpClient.setUrn(e.urn),this.buildClients(this.httpClient,this.httpClient.getJwtToken()??"")}async me(){return await this.identity.me()}async register(t,e){if("originKey"!==this.httpClient.auth.type)throw Error("register() is only available for originKey auth");e.extraContext||(e.extraContext={});let i=this.buildUrn(t),r=this.requireOrigin(),n=await this.identity.origins.register(t,r,{assertionResult:{alias:t,challengeType:"API_KEY",value:{apiKey:this.getOriginKey(),alias:t}},...e}),o=this.httpClient.fork();return o.setAccessToken(n.accessToken),o.setUrn(i),this.buildClients(o,n.accessToken)}async connect(t,e,i){let r=this.httpClient.auth.type;if("apiKey"===r){if("string"==typeof t)throw Error("connect() takes no alias for apiKey auth. Use connect() or connect({ scopes })");await this.httpClient.ensureExchanged();let e=this.httpClient.fork(),i=await new y(e).me();return e.setOrigin(i.origin),e.setUrn(i.urn),this.buildClients(e,e.accessToken??"")}if("originKey"===r){if(!t||"string"!=typeof t)throw Error("connect(alias) is required for originKey auth");let e=this.buildUrn(t),i=this.requireOrigin(),r=await this.httpClient.request({path:`/api/origins/${i}/connect`,method:"POST",body:{assertion_result:{challengeType:"API_KEY",value:{api_key:this.getOriginKey(),alias:t}},extra_context:{}}}),n=this.httpClient.fork();return n.setAccessToken(r.result.access_token),n.setUrn(e),this.buildClients(n,r.result.access_token)}if(this.assertJwtAuth(),!t||"string"!=typeof t||!e||!i)throw Error("connect(origin, alias, code) is required for JWT auth");let n=await this.httpClient.request({path:`/api/origins/${t}/connect`,method:"POST",body:{assertion_result:{challengeType:"OTP",alias:e,value:this.buildOtpValue(e,i)},extra_context:{}}}),o=`did:bloque:${t}:${e}`,s=this.httpClient.fork();return s.setJwtToken(n.result.access_token),s.setOrigin(t),s.setUrn(o),this.buildClients(s,n.result.access_token)}get origin(){return{metadata:t=>this.updateOriginMetadata(t)}}async updateOriginMetadata(t){let e=t.originName??this.httpClient.origin;if(!e)throw Error("origin.metadata() requires originName (or configure the SDK with an origin)");let i=t.apiKey??this.resolveOwnApiKey();if(!i)throw Error("origin.metadata() requires apiKey (or configure the SDK with apiKey/originKey auth)");return this.identity.origins.updateMetadata({originName:e,apiKey:i,metadata:t.metadata})}resolveOwnApiKey(){let{auth:t}=this.httpClient;return"apiKey"===t.type?t.apiKey:"originKey"===t.type?t.originKey:void 0}}export{t as BloqueAPIError,e as BloqueAuthenticationError,i as BloqueConfigError,r as BloqueInsufficientFundsError,n as BloqueNetworkError,o as BloqueNotFoundError,s as BloqueRateLimitError,a as BloqueTierLimitExceededError,l as BloqueTimeoutError,h as BloqueValidationError,u as BloqueVerificationPendingError,p as BloqueVerificationRequiredError,m as SDK};
1
+ import{BloqueAPIError as t,BloqueAuthenticationError as e,BloqueConfigError as i,BloqueInsufficientFundsError as r,BloqueNetworkError as n,BloqueNotFoundError as o,BloqueRateLimitError as a,BloqueTierLimitExceededError as s,BloqueTimeoutError as l,BloqueValidationError as h,BloqueVerificationPendingError as u,BloqueVerificationRequiredError as c,HttpClient as p}from"@bloque/sdk-core";import{AccountsClient as d}from"@bloque/sdk-accounts";import{ComplianceClient as g}from"@bloque/sdk-compliance";import{IdentityClient as y}from"@bloque/sdk-identity";import{OrgsClient as m}from"@bloque/sdk-orgs";import{SwapClient as w}from"@bloque/sdk-swap";class f{httpClient;identity;constructor(t){this.httpClient=new p(t),this.identity=new y(this.httpClient)}buildClients(t,e){return{accounts:new d(t),compliance:new g(t),identity:new y(t),orgs:new m(t),swap:new w(t),urn:t.urn,get accessToken(){return e}}}getOriginKey(){let{auth:t}=this.httpClient;return"originKey"===t.type?t.originKey:""}buildUrn(t){let e=this.httpClient.origin;if(!e)throw Error("Origin is required to build a urn");return`did:bloque:${e}:${t}`}requireOrigin(){let t=this.httpClient.origin;if(!t)throw Error("Origin is required for this operation");return t}buildOtpValue(t,e){let i=t.trim();return i.includes("@")?{code:e,email:i}:{code:e,phone:i}}assertJwtAuth(){if("jwt"!==this.httpClient.auth.type)throw Error("This operation is only available for JWT auth")}async assert(t,e){return this.assertJwtAuth(),await this.httpClient.request({path:`/api/origins/${t}/assert?alias=${encodeURIComponent(e)}`,method:"GET"})}async authenticate(){let{auth:t}=this.httpClient;if("jwt"!==t.type)throw Error("authenticate is only available for JWT auth");let e=await this.identity.me();return this.httpClient.setOrigin(e.origin),this.httpClient.setUrn(e.urn),this.buildClients(this.httpClient,this.httpClient.getJwtToken()??"")}async me(){return await this.identity.me()}async register(t,e){if("originKey"!==this.httpClient.auth.type)throw Error("register() is only available for originKey auth");e.extraContext||(e.extraContext={});let i=this.buildUrn(t),r=this.requireOrigin(),n=await this.identity.origins.register(t,r,{assertionResult:{alias:t,challengeType:"API_KEY",value:{apiKey:this.getOriginKey(),alias:t}},...e}),o=this.httpClient.fork();return o.setAccessToken(n.accessToken),o.setUrn(i),this.buildClients(o,n.accessToken)}async connect(t,e,i){let r=this.httpClient.auth.type;if("apiKey"===r){if("string"==typeof t)throw Error("connect() takes no alias for apiKey auth. Use connect() or connect({ scopes })");await this.httpClient.ensureExchanged();let e=this.httpClient.fork(),i=await new y(e).me();return e.setOrigin(i.origin),e.setUrn(i.urn),this.buildClients(e,e.accessToken??"")}if("originKey"===r){if(!t||"string"!=typeof t)throw Error("connect(alias) is required for originKey auth");let i=this.buildUrn(t),r=this.requireOrigin(),n=e&&"object"==typeof e?e.clientIp:void 0,o=await this.httpClient.request({path:`/api/origins/${r}/connect`,method:"POST",body:{assertion_result:{challengeType:"API_KEY",value:{api_key:this.getOriginKey(),alias:t}},extra_context:{}},headers:n?{"x-original-client-ip":n}:void 0}),a=this.httpClient.fork();return a.setAccessToken(o.result.access_token),a.setUrn(i),this.buildClients(a,o.result.access_token)}if(this.assertJwtAuth(),!t||"string"!=typeof t||!e||"string"!=typeof e||!i)throw Error("connect(origin, alias, code) is required for JWT auth");let n=await this.httpClient.request({path:`/api/origins/${t}/connect`,method:"POST",body:{assertion_result:{challengeType:"OTP",alias:e,value:this.buildOtpValue(e,i)},extra_context:{}}}),o=`did:bloque:${t}:${e}`,a=this.httpClient.fork();return a.setJwtToken(n.result.access_token),a.setOrigin(t),a.setUrn(o),this.buildClients(a,n.result.access_token)}get origins(){return{updateMetadata:t=>this.updateOriginMetadata(t)}}async updateOriginMetadata(t){let e=t.originName??this.httpClient.origin;if(!e)throw Error("origins.updateMetadata() requires originName (or configure the SDK with an origin)");let i=t.apiKey??this.resolveOwnApiKey();if(!i)throw Error("origins.updateMetadata() requires apiKey (or configure the SDK with apiKey/originKey auth)");let r={};void 0!==t.metadata.company&&(r.company=t.metadata.company),void 0!==t.metadata.tosGateShowHome&&(r.tos_gate_show_home=t.metadata.tosGateShowHome),void 0!==t.metadata.gateAccentColor&&(r.gate_accent_color=t.metadata.gateAccentColor),void 0!==t.metadata.verificationGateReturnUrlAllowlist&&(r.verification_gate_return_url_allowlist=t.metadata.verificationGateReturnUrlAllowlist);let n=await this.httpClient.request({method:"PATCH",path:`/api/origins/${e}/metadata`,body:{api_key:i,metadata:r},_skipExchange:!0});return{originName:n.origin_name,metadata:n.metadata,updated:!0}}resolveOwnApiKey(){let{auth:t}=this.httpClient;return"apiKey"===t.type?t.apiKey:"originKey"===t.type?t.originKey:void 0}}export{t as BloqueAPIError,e as BloqueAuthenticationError,i as BloqueConfigError,r as BloqueInsufficientFundsError,n as BloqueNetworkError,o as BloqueNotFoundError,a as BloqueRateLimitError,s as BloqueTierLimitExceededError,l as BloqueTimeoutError,h as BloqueValidationError,u as BloqueVerificationPendingError,c as BloqueVerificationRequiredError,f as SDK};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bloque/sdk",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Official Bloque SDK",
5
5
  "type": "module",
6
6
  "keywords": [