@bloque/sdk 0.5.0 → 0.7.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
@@ -4,6 +4,58 @@ import { type BloqueSDKConfig } from '@bloque/sdk-core';
4
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
+ }
36
+ export interface UpdateOriginMetadataOptions {
37
+ /**
38
+ * Origin namespace to patch. Defaults to the SDK's configured `origin` —
39
+ * only pass this to target a *different* origin than the one this SDK
40
+ * instance is otherwise configured for.
41
+ */
42
+ originName?: string;
43
+ /**
44
+ * The origin's own provisioned secret key. Defaults to the configured
45
+ * `apiKey`/`originKey` auth credential — only pass this if `originName`
46
+ * is overridden too, or your own credential differs from the origin
47
+ * being patched.
48
+ */
49
+ apiKey?: string;
50
+ metadata: OriginMetadataPatch;
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
+ }
7
59
  export interface BloqueClients {
8
60
  accounts: AccountsClient;
9
61
  compliance: ComplianceClient;
@@ -43,4 +95,34 @@ export declare class SDK {
43
95
  }): Promise<BloqueClients>;
44
96
  connect(alias: string): Promise<BloqueClients>;
45
97
  connect(origin: string, alias: string, code: string): Promise<BloqueClients>;
98
+ /**
99
+ * Self-service origin configuration, authenticated purely by the origin's
100
+ * own key — no connected session required. Sibling to `connect()`/
101
+ * `register()`, but for configuring the origin itself rather than one of
102
+ * its identities.
103
+ */
104
+ get origins(): {
105
+ /**
106
+ * Patch this origin's own presentation metadata (`company`,
107
+ * `tosGateShowHome`, `gateAccentColor`,
108
+ * `verificationGateReturnUrlAllowlist`). `originName`/`apiKey` default
109
+ * to this SDK instance's own config, so with `apiKey`/`originKey` auth
110
+ * you typically only pass `metadata`:
111
+ *
112
+ * ```typescript
113
+ * await bloque.origins.updateMetadata({
114
+ * metadata: { gateAccentColor: '#1a73e8' },
115
+ * });
116
+ * ```
117
+ *
118
+ * This is a one-time/deploy-script call, not something you run
119
+ * per-request or per-user. Fields you omit from `metadata` are left
120
+ * untouched on the origin (shallow merge) — the response echoes the
121
+ * full post-merge metadata so you can confirm what actually took
122
+ * effect.
123
+ */
124
+ updateMetadata: (options: UpdateOriginMetadataOptions) => Promise<UpdateOriginMetadataResult>;
125
+ };
126
+ private updateOriginMetadata;
127
+ private resolveOwnApiKey;
46
128
  }
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}`,s=this.httpClient.fork();return s.setJwtToken(o.result.access_token),s.setOrigin(e),s.setUrn(n),this.buildClients(s,o.result.access_token)}}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 t=this.buildUrn(e),r=this.requireOrigin(),i=await this.httpClient.request({path:`/api/origins/${r}/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(t),this.buildClients(o,i.result.access_token)}if(this.assertJwtAuth(),!e||"string"!=typeof e||!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 } 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 s,BloqueRateLimitError as o,BloqueTierLimitExceededError as a,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 f}from"@bloque/sdk-orgs";import{SwapClient as w}from"@bloque/sdk-swap";class C{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 f(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}),s=this.httpClient.fork();return s.setAccessToken(n.accessToken),s.setUrn(i),this.buildClients(s,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:{}}}),s=`did:bloque:${t}:${e}`,o=this.httpClient.fork();return o.setJwtToken(n.result.access_token),o.setOrigin(t),o.setUrn(s),this.buildClients(o,n.result.access_token)}}export{t as BloqueAPIError,e as BloqueAuthenticationError,i as BloqueConfigError,r as BloqueInsufficientFundsError,n as BloqueNetworkError,s as BloqueNotFoundError,o as BloqueRateLimitError,a as BloqueTierLimitExceededError,l as BloqueTimeoutError,h as BloqueValidationError,u as BloqueVerificationPendingError,c as BloqueVerificationRequiredError,C 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 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}`,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.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Official Bloque SDK",
5
5
  "type": "module",
6
6
  "keywords": [