@burdenoff/sdk-libs 2026.501.6
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/LICENSE +4 -0
- package/README.md +52 -0
- package/dist/chunk-NEREAHJ6.js +1 -0
- package/dist/chunk-YGVAZ3D7.js +2 -0
- package/dist/core/index.cjs +2 -0
- package/dist/core/index.d.cts +52 -0
- package/dist/core/index.d.ts +52 -0
- package/dist/core/index.js +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/module-JDbvil5h.d.cts +194 -0
- package/dist/module-JDbvil5h.d.ts +194 -0
- package/dist/modules/auth/index.cjs +71 -0
- package/dist/modules/auth/index.d.cts +94 -0
- package/dist/modules/auth/index.d.ts +94 -0
- package/dist/modules/auth/index.js +71 -0
- package/dist/modules/billing/index.cjs +203 -0
- package/dist/modules/billing/index.d.cts +377 -0
- package/dist/modules/billing/index.d.ts +377 -0
- package/dist/modules/billing/index.js +203 -0
- package/dist/modules/channels/index.cjs +108 -0
- package/dist/modules/channels/index.d.cts +146 -0
- package/dist/modules/channels/index.d.ts +146 -0
- package/dist/modules/channels/index.js +108 -0
- package/dist/modules/conversations/index.cjs +61 -0
- package/dist/modules/conversations/index.d.cts +112 -0
- package/dist/modules/conversations/index.d.ts +112 -0
- package/dist/modules/conversations/index.js +61 -0
- package/dist/modules/devportal/index.cjs +216 -0
- package/dist/modules/devportal/index.d.cts +303 -0
- package/dist/modules/devportal/index.d.ts +303 -0
- package/dist/modules/devportal/index.js +216 -0
- package/dist/modules/export/index.cjs +61 -0
- package/dist/modules/export/index.d.cts +169 -0
- package/dist/modules/export/index.d.ts +169 -0
- package/dist/modules/export/index.js +61 -0
- package/dist/modules/files/index.cjs +51 -0
- package/dist/modules/files/index.d.cts +102 -0
- package/dist/modules/files/index.d.ts +102 -0
- package/dist/modules/files/index.js +51 -0
- package/dist/modules/groups/index.cjs +80 -0
- package/dist/modules/groups/index.d.cts +168 -0
- package/dist/modules/groups/index.d.ts +168 -0
- package/dist/modules/groups/index.js +80 -0
- package/dist/modules/health/index.cjs +5 -0
- package/dist/modules/health/index.d.cts +18 -0
- package/dist/modules/health/index.d.ts +18 -0
- package/dist/modules/health/index.js +5 -0
- package/dist/modules/integrations/index.cjs +65 -0
- package/dist/modules/integrations/index.d.cts +120 -0
- package/dist/modules/integrations/index.d.ts +120 -0
- package/dist/modules/integrations/index.js +65 -0
- package/dist/modules/notifications/index.cjs +53 -0
- package/dist/modules/notifications/index.d.cts +140 -0
- package/dist/modules/notifications/index.d.ts +140 -0
- package/dist/modules/notifications/index.js +53 -0
- package/dist/modules/organizations/index.cjs +72 -0
- package/dist/modules/organizations/index.d.cts +88 -0
- package/dist/modules/organizations/index.d.ts +88 -0
- package/dist/modules/organizations/index.js +72 -0
- package/dist/modules/products/index.cjs +149 -0
- package/dist/modules/products/index.d.cts +361 -0
- package/dist/modules/products/index.d.ts +361 -0
- package/dist/modules/products/index.js +149 -0
- package/dist/modules/rbac/index.cjs +55 -0
- package/dist/modules/rbac/index.d.cts +100 -0
- package/dist/modules/rbac/index.d.ts +100 -0
- package/dist/modules/rbac/index.js +55 -0
- package/dist/modules/scheduler/index.cjs +61 -0
- package/dist/modules/scheduler/index.d.cts +121 -0
- package/dist/modules/scheduler/index.d.ts +121 -0
- package/dist/modules/scheduler/index.js +61 -0
- package/dist/modules/security/index.cjs +61 -0
- package/dist/modules/security/index.d.cts +110 -0
- package/dist/modules/security/index.d.ts +110 -0
- package/dist/modules/security/index.js +61 -0
- package/dist/modules/store/index.cjs +82 -0
- package/dist/modules/store/index.d.cts +139 -0
- package/dist/modules/store/index.d.ts +139 -0
- package/dist/modules/store/index.js +82 -0
- package/dist/modules/support/index.cjs +56 -0
- package/dist/modules/support/index.d.cts +147 -0
- package/dist/modules/support/index.d.ts +147 -0
- package/dist/modules/support/index.js +56 -0
- package/dist/modules/tags/index.cjs +55 -0
- package/dist/modules/tags/index.d.cts +131 -0
- package/dist/modules/tags/index.d.ts +131 -0
- package/dist/modules/tags/index.js +55 -0
- package/dist/modules/tours/index.cjs +37 -0
- package/dist/modules/tours/index.d.cts +61 -0
- package/dist/modules/tours/index.d.ts +61 -0
- package/dist/modules/tours/index.js +37 -0
- package/dist/modules/vibecontrols/index.cjs +1081 -0
- package/dist/modules/vibecontrols/index.d.cts +1483 -0
- package/dist/modules/vibecontrols/index.d.ts +1483 -0
- package/dist/modules/vibecontrols/index.js +1081 -0
- package/dist/modules/workspaces/index.cjs +91 -0
- package/dist/modules/workspaces/index.d.cts +128 -0
- package/dist/modules/workspaces/index.d.ts +128 -0
- package/dist/modules/workspaces/index.js +91 -0
- package/package.json +117 -0
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @burdenoff/sdk-libs
|
|
2
|
+
|
|
3
|
+
Modular SDK library shared across all Burdenoff product SDKs (Node/TypeScript).
|
|
4
|
+
|
|
5
|
+
Each module under `src/modules/<name>/` exports an `SdkModule` with `attach(ctx) -> API`. Product SDKs (`@vibecontrols/sdk-node`, `@botlit/sdk-node`, etc.) become thin shells that pick which modules to mount. Sister to [`@burdenoff/cli-sdk`](https://github.com/algoshred/cli-sdk).
|
|
6
|
+
|
|
7
|
+
## Architecture
|
|
8
|
+
|
|
9
|
+
- **Core** (`src/core/`): `SdkContext` prop bag, `SdkModule` contract, `BaseGraphQLClient` (dual workspace+global gateway), `AuthStore` with pluggable `TokenStore` (`InMemory`, `File`, `Env`), error hierarchy with token redaction, `ModuleRegistry` for cross-module access.
|
|
10
|
+
- **Modules** (`src/modules/<name>/`): `index.ts` (default-exports `SdkModule`), `operations.ts` (hand-written `gql` strings), `api.ts` (the class returned by `attach`), `types.ts` (re-exports from `__generated__/`), `__generated__/types.ts` (codegen output, gitignored).
|
|
11
|
+
- **Hard rules**: Modules NEVER import each other directly — use `ctx.modules.get<API>('id')`. Modules NEVER call `process.exit` or write secrets to logs.
|
|
12
|
+
|
|
13
|
+
## Build
|
|
14
|
+
|
|
15
|
+
- **tsup** dual ESM+CJS, multi-entry, `dts: true`. Entries: `src/index.ts`, `src/core/index.ts`, `src/modules/*/index.ts`.
|
|
16
|
+
- `external`: `graphql`, `graphql-request`, `graphql-ws` (peer deps).
|
|
17
|
+
- Subpath imports: `@burdenoff/sdk-libs/core`, `@burdenoff/sdk-libs/modules/<name>`.
|
|
18
|
+
|
|
19
|
+
## Commands
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bun install
|
|
23
|
+
bun run dev # tsup watch
|
|
24
|
+
bun run build # tsup once
|
|
25
|
+
bun run sanity # format:check + lint + typecheck + build + test
|
|
26
|
+
bun run test # vitest run
|
|
27
|
+
bun run codegen # GraphQL types from pinned Hive supergraph
|
|
28
|
+
bun run parity:check # cross-language manifest diff vs sdk-libs-python
|
|
29
|
+
bun run publish:verdaccio # alpha tag to internal Verdaccio
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Adding a module
|
|
33
|
+
|
|
34
|
+
1. `mkdir src/modules/<name>` with `index.ts`, `operations.ts`, `api.ts`, `types.ts`.
|
|
35
|
+
2. Default-export an `SdkModule<API>` from `index.ts`.
|
|
36
|
+
3. Add the module to `schema/modules.yaml` (operations + dependsOn).
|
|
37
|
+
4. Mirror in `~/products/sdk-libs-python/` in the same PR pair.
|
|
38
|
+
5. tsup picks it up automatically (`src/modules/*/index.ts` glob).
|
|
39
|
+
|
|
40
|
+
## Testing
|
|
41
|
+
|
|
42
|
+
- Unit (`tests/unit/`): pure logic — arg parsers, response transformers, gql doc builders. No HTTP. Vitest, <5s.
|
|
43
|
+
- Integration (`tests/integration/`): MSW intercepts GraphQL requests. Mock factories derived from `__generated__/types`. Schema rename breaks mock = test fail.
|
|
44
|
+
- E2E (`tests/e2e/`): real svc + state, run nightly. Mirrors `~/products/vibecontrols/vibecontrols-doctor/scripts/test-*-crud.sh`.
|
|
45
|
+
- Parity (`tests/parity/<scenario>.yaml`): same scenario file run by node + python. CI fails if shapes diverge.
|
|
46
|
+
|
|
47
|
+
## Reference
|
|
48
|
+
|
|
49
|
+
- `~/products/burdenoff-be-sdk-node/` — reference for tsup multi-entry + verdaccio publish.
|
|
50
|
+
- `~/products/cli-sdk/` — sister CLI SDK.
|
|
51
|
+
- `~/products/vibecontrols/vibecontrols-sdk-node/` — first consumer (thin shell).
|
|
52
|
+
- `~/products/dev/audit/index/vibecontrols.md` — 23-module ground-truth.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var x=["password","secret","clientSecret","apiKey","token","mfaCode","accessToken","refreshToken","workspaceToken","authorization"],h=/\b(eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)\b/g;function _(s){let e=s.replace(h,"<redacted-jwt>");for(let t of x){let r=new RegExp(`("${t}"\\s*:\\s*")[^"]*(")`,"gi");e=e.replace(r,"$1<redacted>$2");}return e}var n=class extends Error{code;cause;constructor(e,t="SDK_ERROR",r){super(_(e)),this.name="SdkError",this.code=t,this.cause=r;}},o=class extends n{constructor(e="Authentication failed",t){super(e,"AUTHENTICATION_ERROR",t),this.name="AuthenticationError";}},c=class extends n{constructor(e="Not authorized",t){super(e,"AUTHORIZATION_ERROR",t),this.name="AuthorizationError";}},a=class extends n{constructor(e,t){super(e,"NETWORK_ERROR",t),this.name="NetworkError";}},i=class extends n{constructor(e,t){super(e,"VALIDATION_ERROR",t),this.name="ValidationError";}},d=class extends n{constructor(e="Rate limit exceeded",t){super(e,"RATE_LIMIT_ERROR",t),this.name="RateLimitError";}},u=class extends n{constructor(e="Device code expired"){super(e,"DEVICE_CODE_EXPIRED"),this.name="DeviceCodeExpiredError";}},p=class extends n{constructor(e="Device authorization denied by user"){super(e,"DEVICE_CODE_DENIED"),this.name="DeviceCodeDeniedError";}},E=class extends n{constructor(e,t){super(`Module '${e}' declares dependency on '${t}', but '${t}' is not in the module list.`,"MISSING_DEPENDENCY"),this.name="MissingDependencyError";}},l=class extends n{constructor(e){super(`Circular dependency detected among modules: ${e.join(" -> ")}`,"CIRCULAR_DEPENDENCY"),this.name="CircularDependencyError";}},R=class extends n{constructor(e){super(`Module '${e}' is not mounted on this SDK instance. Add it to the modules array passed to createSdk().`,"MODULE_NOT_MOUNTED"),this.name="ModuleNotMountedError";}};export{_ as a,n as b,o as c,c as d,a as e,i as f,d as g,u as h,p as i,E as j,l as k,R as l};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {c,b as b$1,g as g$1,d,e,a,l,j as j$1,k}from'./chunk-NEREAHJ6.js';import {GraphQLClient}from'graphql-request';import {readFile,mkdir,writeFile,unlink}from'fs/promises';import {dirname}from'path';var $=3e4,D=3,B=1e3,j=300*1e3;function Q(t,e){return new Promise((r,o)=>{if(e?.aborted)return o(new b$1("Aborted","ABORTED"));let n=setTimeout(()=>r(),t);e?.addEventListener("abort",()=>{clearTimeout(n),o(new b$1("Aborted","ABORTED"));});})}function U(t){if(t instanceof TypeError)return true;if(t&&typeof t=="object"&&"response"in t){let e=t.response;if(e&&typeof e.status=="number"&&e.status>=500)return true}return false}function K(t){if(t&&typeof t=="object"&&"response"in t){let e=t.response;if(e&&typeof e.status=="number"&&e.status>=400&&e.status<500)return e.status}return null}function M(t){if(t&&typeof t=="object"&&"response"in t){let e=t,r=e.response?.errors?.[0];if(r?.message)return a(r.message);if(e.message)return a(e.message)}return t instanceof Error?a(t.message):a(String(t))}var h=class{workspaceClient;globalClient;opts;constructor(e){this.opts=e,this.workspaceClient=new GraphQLClient(e.workspaceEndpoint),this.globalClient=new GraphQLClient(e.globalEndpoint);}async buildHeaders(e){let r={},o=this.opts.auth.getApiKey();o&&(r["X-API-Key"]=o);let n=await this.opts.auth.getTokens();if(n?.accessToken&&(r.Authorization=`Bearer ${n.accessToken}`),e==="workspace"){let s=this.opts.auth.getWorkspaceToken();s&&(r["X-Workspace-Authorization"]=`Bearer ${s}`);}return r}isExpiringSoon(e){return e?Date.now()+j>=e:false}async ensureFresh(){if(this.opts.autoRefresh===false)return;let e=await this.opts.auth.getTokens();e?.expiresAt&&this.isExpiringSoon(e.expiresAt)&&await this.performTokenRefresh();}async performTokenRefresh(){let e=await this.opts.auth.getTokens();if(!e?.refreshToken)throw new c("No refresh token available");let o=await this.globalClient.request("mutation RefreshToken($token: String!) { refreshToken(token: $token) { accessToken refreshToken expiresIn } }",{token:e.refreshToken}),n=Date.now()+o.refreshToken.expiresIn*1e3,s={accessToken:o.refreshToken.accessToken,refreshToken:o.refreshToken.refreshToken,expiresAt:n};return await this.opts.auth.setTokens(s),this.opts.onTokenRefresh&&await this.opts.onTokenRefresh(s),s}async executeWithRetry(e$1,r,o,n,s){let i=this.opts.timeout??$,a;for(let u=0;u<D;u++){let x=new AbortController,E=s?.signal??this.opts.defaultSignal,G=()=>x.abort();E?.addEventListener("abort",G);let F=setTimeout(()=>x.abort(),i);try{let f=await this.buildHeaders(r);return await e$1.request({document:o,variables:n,signal:x.signal,requestHeaders:f})}catch(f){if(a=f,K(f)!==null)break;if(U(f)&&u<D-1){await Q(B*2**u,E);continue}break}finally{clearTimeout(F),E?.removeEventListener("abort",G);}}let l=K(a);if(l!==null){let u=M(a);switch(l){case 401:throw new c(u,a);case 403:throw new d(u,a);case 429:throw new g$1(u,a);default:throw new b$1(u,`HTTP_${l}`,a)}}throw a instanceof TypeError?new e(M(a),a):a instanceof b$1?a:new b$1(M(a),"SDK_ERROR",a)}async globalRequest(e,r,o){return this.executeWithRetry(this.globalClient,"global",e,r,o)}async workspaceRequest(e,r,o){return await this.ensureFresh(),this.executeWithRetry(this.workspaceClient,"workspace",e,r,o)}async workspaceAuthOnlyRequest(e,r,o){return this.executeWithRetry(this.workspaceClient,"workspace",e,r,o)}};function m(t,e){return e==="workspace"?{request:(r,o,n)=>t.workspaceRequest(r,o,n)}:e==="global"?{request:(r,o,n)=>t.globalRequest(r,o,n)}:{request:(r,o,n)=>t.workspaceAuthOnlyRequest(r,o,n)}}var g=class{tokens;constructor(e){this.tokens=e??null;}async get(){return this.tokens?{...this.tokens}:null}async set(e){this.tokens={...e};}async clear(){this.tokens=null;}},S=class{constructor(e){this.opts=e;}opts;async get(){try{let e=await readFile(this.opts.path,"utf8"),r=JSON.parse(e);return r&&typeof r.accessToken=="string"?{accessToken:r.accessToken,refreshToken:r.refreshToken??"",expiresAt:typeof r.expiresAt=="number"?r.expiresAt:void 0}:null}catch(e){if(V(e)==="ENOENT")return null;throw new Error(a(`FileTokenStore.get failed: ${e.message}`))}}async set(e){await mkdir(dirname(this.opts.path),{recursive:true}),await writeFile(this.opts.path,JSON.stringify(e,null,2),{mode:384});}async clear(){try{await unlink(this.opts.path);}catch(e){if(V(e)!=="ENOENT")throw e}}};function V(t){if(t&&typeof t=="object"&&"code"in t&&typeof t.code=="string")return t.code}var b=class{constructor(e){this.opts=e;}opts;async get(){let e=process.env[this.opts.accessTokenVar];if(!e)return null;let r=this.opts.refreshTokenVar?process.env[this.opts.refreshTokenVar]??"":"",o=this.opts.expiresAtVar?process.env[this.opts.expiresAtVar]:void 0,n=o?Number.parseInt(o,10):void 0;return {accessToken:e,refreshToken:r,expiresAt:n}}async set(e){}async clear(){}};var T=class{constructor(e){this.tokenStore=e;}tokenStore;workspaceToken=null;apiKey=null;async getTokens(){return this.tokenStore.get()}async setTokens(e){await this.tokenStore.set(e);}async clearTokens(){await this.tokenStore.clear(),this.workspaceToken=null;}setWorkspaceToken(e){this.workspaceToken=e;}getWorkspaceToken(){return this.workspaceToken}setApiKey(e){this.apiKey=e;}getApiKey(){return this.apiKey}async isAuthenticated(){return (await this.getTokens())?.accessToken?true:!!this.apiKey}};function v(t){let e=t?.tokenStore??new g(t?.tokens??null),r=new T(e);return t?.workspaceToken&&r.setWorkspaceToken(t.workspaceToken),t?.apiKey&&r.setApiKey(t.apiKey),r}var _={debug:10,info:20,warn:30,error:40};function O(t={}){let e=_[t.level??"warn"],r=t.prefix?`[${t.prefix}]`:"";function o(n,s,i){if(_[n]<e)return;let a$1=`${r}[${n}] ${a(s)}`,l=i?JSON.parse(a(JSON.stringify(i))):void 0;n==="error"||n==="warn"?console.error(a$1,l??""):console.warn(a$1,l??"");}return {debug:(n,s)=>o("debug",n,s),info:(n,s)=>o("info",n,s),warn:(n,s)=>o("warn",n,s),error:(n,s)=>o("error",n,s)}}var y=class{apis=new Map;set(e,r){this.apis.set(e,r);}get(e){if(!this.apis.has(e))throw new l(e);return this.apis.get(e)}has(e){return this.apis.has(e)}ids(){return Array.from(this.apis.keys())}};function Y(t){let e=t.productVersion??"0.0.0",r=t.env??Z(t.workspaceEndpoint),o=t.logger??O({level:t.logLevel??"warn",prefix:t.productName}),n=t.accessToken?{accessToken:t.accessToken,refreshToken:t.refreshToken??""}:null,s=v({tokens:n,workspaceToken:t.workspaceToken??null,apiKey:t.apiKey??null,tokenStore:t.tokenStore}),a={issuer:t.oidcIssuer??ee(t.globalEndpoint),clientId:t.clientId,clientSecret:t.clientSecret,redirectUri:t.redirectUri},l=new h({workspaceEndpoint:t.workspaceEndpoint,globalEndpoint:t.globalEndpoint,auth:s,timeout:t.timeout,autoRefresh:t.autoRefresh,onTokenRefresh:t.onTokenRefresh,defaultSignal:t.signal});return {productName:t.productName,productVersion:e,env:r,gql:{workspace:m(l,"workspace"),global:m(l,"global"),workspaceAuthOnly:m(l,"workspaceAuthOnly")},client:l,auth:s,oidc:a,logger:o,modules:new y,signal:t.signal}}function Z(t){return t.includes("localhost")||t.includes("127.0.0.1")?"local":t.includes("alpha")?"alpha":t.includes("dev")?"dev":"prod"}function ee(t){return t.includes("localhost")||t.includes("127.0.0.1")?t.replace(/\/graphql$/,"").replace(/\/global\/graphql$/,"/global"):"https://graphql.burdenoff.com/global"}function I(t){let e=new Map;for(let i of t){if(e.has(i.id))throw new b$1(`Duplicate module id: '${i.id}'`,"DUPLICATE_MODULE");e.set(i.id,i);}for(let i of t)for(let a of i.dependsOn??[])if(!e.has(a))throw new j$1(i.id,a);let r=[],o=new Set,n=new Set,s=(i,a)=>{if(!n.has(i.id)){if(o.has(i.id))throw new k([...a,i.id]);o.add(i.id);for(let l of i.dependsOn??[]){let u=e.get(l);u&&s(u,[...a,i.id]);}o.delete(i.id),n.add(i.id),r.push(i);}};for(let i of t)s(i,[]);return r}function De(t,e){let r=I(e),o={};for(let n of r){let s=n.attach(t);t.modules.set(n.id,s),o[n.id]=s;}return {ctx:t,modules:o}}
|
|
2
|
+
export{h as a,m as b,g as c,S as d,b as e,T as f,v as g,O as h,y as i,Y as j,I as k,De as l};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var graphqlRequest=require('graphql-request'),promises=require('fs/promises'),path=require('path');var j=["password","secret","clientSecret","apiKey","token","mfaCode","accessToken","refreshToken","workspaceToken","authorization"],B=/\b(eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)\b/g;function p(t){let e=t.replace(B,"<redacted-jwt>");for(let r of j){let o=new RegExp(`("${r}"\\s*:\\s*")[^"]*(")`,"gi");e=e.replace(o,"$1<redacted>$2");}return e}var c=class extends Error{code;cause;constructor(e,r="SDK_ERROR",o){super(p(e)),this.name="SdkError",this.code=r,this.cause=o;}},k=class extends c{constructor(e="Authentication failed",r){super(e,"AUTHENTICATION_ERROR",r),this.name="AuthenticationError";}},f=class extends c{constructor(e="Not authorized",r){super(e,"AUTHORIZATION_ERROR",r),this.name="AuthorizationError";}},m=class extends c{constructor(e,r){super(e,"NETWORK_ERROR",r),this.name="NetworkError";}},L=class extends c{constructor(e,r){super(e,"VALIDATION_ERROR",r),this.name="ValidationError";}},T=class extends c{constructor(e="Rate limit exceeded",r){super(e,"RATE_LIMIT_ERROR",r),this.name="RateLimitError";}},M=class extends c{constructor(e="Device code expired"){super(e,"DEVICE_CODE_EXPIRED"),this.name="DeviceCodeExpiredError";}},q=class extends c{constructor(e="Device authorization denied by user"){super(e,"DEVICE_CODE_DENIED"),this.name="DeviceCodeDeniedError";}},y=class extends c{constructor(e,r){super(`Module '${e}' declares dependency on '${r}', but '${r}' is not in the module list.`,"MISSING_DEPENDENCY"),this.name="MissingDependencyError";}},w=class extends c{constructor(e){super(`Circular dependency detected among modules: ${e.join(" -> ")}`,"CIRCULAR_DEPENDENCY"),this.name="CircularDependencyError";}},E=class extends c{constructor(e){super(`Module '${e}' is not mounted on this SDK instance. Add it to the modules array passed to createSdk().`,"MODULE_NOT_MOUNTED"),this.name="ModuleNotMountedError";}};var Q=3e4,K=3,z=1e3,W=300*1e3;function H(t,e){return new Promise((r,o)=>{if(e?.aborted)return o(new c("Aborted","ABORTED"));let n=setTimeout(()=>r(),t);e?.addEventListener("abort",()=>{clearTimeout(n),o(new c("Aborted","ABORTED"));});})}function J(t){if(t instanceof TypeError)return true;if(t&&typeof t=="object"&&"response"in t){let e=t.response;if(e&&typeof e.status=="number"&&e.status>=500)return true}return false}function V(t){if(t&&typeof t=="object"&&"response"in t){let e=t.response;if(e&&typeof e.status=="number"&&e.status>=400&&e.status<500)return e.status}return null}function I(t){if(t&&typeof t=="object"&&"response"in t){let e=t,r=e.response?.errors?.[0];if(r?.message)return p(r.message);if(e.message)return p(e.message)}return t instanceof Error?p(t.message):p(String(t))}var x=class{workspaceClient;globalClient;opts;constructor(e){this.opts=e,this.workspaceClient=new graphqlRequest.GraphQLClient(e.workspaceEndpoint),this.globalClient=new graphqlRequest.GraphQLClient(e.globalEndpoint);}async buildHeaders(e){let r={},o=this.opts.auth.getApiKey();o&&(r["X-API-Key"]=o);let n=await this.opts.auth.getTokens();if(n?.accessToken&&(r.Authorization=`Bearer ${n.accessToken}`),e==="workspace"){let s=this.opts.auth.getWorkspaceToken();s&&(r["X-Workspace-Authorization"]=`Bearer ${s}`);}return r}isExpiringSoon(e){return e?Date.now()+W>=e:false}async ensureFresh(){if(this.opts.autoRefresh===false)return;let e=await this.opts.auth.getTokens();e?.expiresAt&&this.isExpiringSoon(e.expiresAt)&&await this.performTokenRefresh();}async performTokenRefresh(){let e=await this.opts.auth.getTokens();if(!e?.refreshToken)throw new k("No refresh token available");let o=await this.globalClient.request("mutation RefreshToken($token: String!) { refreshToken(token: $token) { accessToken refreshToken expiresIn } }",{token:e.refreshToken}),n=Date.now()+o.refreshToken.expiresIn*1e3,s={accessToken:o.refreshToken.accessToken,refreshToken:o.refreshToken.refreshToken,expiresAt:n};return await this.opts.auth.setTokens(s),this.opts.onTokenRefresh&&await this.opts.onTokenRefresh(s),s}async executeWithRetry(e,r,o,n,s){let i=this.opts.timeout??Q,a;for(let u=0;u<K;u++){let O=new AbortController,P=s?.signal??this.opts.defaultSignal,_=()=>O.abort();P?.addEventListener("abort",_);let U=setTimeout(()=>O.abort(),i);try{let g=await this.buildHeaders(r);return await e.request({document:o,variables:n,signal:O.signal,requestHeaders:g})}catch(g){if(a=g,V(g)!==null)break;if(J(g)&&u<K-1){await H(z*2**u,P);continue}break}finally{clearTimeout(U),P?.removeEventListener("abort",_);}}let l=V(a);if(l!==null){let u=I(a);switch(l){case 401:throw new k(u,a);case 403:throw new f(u,a);case 429:throw new T(u,a);default:throw new c(u,`HTTP_${l}`,a)}}throw a instanceof TypeError?new m(I(a),a):a instanceof c?a:new c(I(a),"SDK_ERROR",a)}async globalRequest(e,r,o){return this.executeWithRetry(this.globalClient,"global",e,r,o)}async workspaceRequest(e,r,o){return await this.ensureFresh(),this.executeWithRetry(this.workspaceClient,"workspace",e,r,o)}async workspaceAuthOnlyRequest(e,r,o){return this.executeWithRetry(this.workspaceClient,"workspace",e,r,o)}};function S(t,e){return e==="workspace"?{request:(r,o,n)=>t.workspaceRequest(r,o,n)}:e==="global"?{request:(r,o,n)=>t.globalRequest(r,o,n)}:{request:(r,o,n)=>t.workspaceAuthOnlyRequest(r,o,n)}}var h=class{tokens;constructor(e){this.tokens=e??null;}async get(){return this.tokens?{...this.tokens}:null}async set(e){this.tokens={...e};}async clear(){this.tokens=null;}},v=class{constructor(e){this.opts=e;}opts;async get(){try{let e=await promises.readFile(this.opts.path,"utf8"),r=JSON.parse(e);return r&&typeof r.accessToken=="string"?{accessToken:r.accessToken,refreshToken:r.refreshToken??"",expiresAt:typeof r.expiresAt=="number"?r.expiresAt:void 0}:null}catch(e){if($(e)==="ENOENT")return null;throw new Error(p(`FileTokenStore.get failed: ${e.message}`))}}async set(e){await promises.mkdir(path.dirname(this.opts.path),{recursive:true}),await promises.writeFile(this.opts.path,JSON.stringify(e,null,2),{mode:384});}async clear(){try{await promises.unlink(this.opts.path);}catch(e){if($(e)!=="ENOENT")throw e}}};function $(t){if(t&&typeof t=="object"&&"code"in t&&typeof t.code=="string")return t.code}var A=class{constructor(e){this.opts=e;}opts;async get(){let e=process.env[this.opts.accessTokenVar];if(!e)return null;let r=this.opts.refreshTokenVar?process.env[this.opts.refreshTokenVar]??"":"",o=this.opts.expiresAtVar?process.env[this.opts.expiresAtVar]:void 0,n=o?Number.parseInt(o,10):void 0;return {accessToken:e,refreshToken:r,expiresAt:n}}async set(e){}async clear(){}};var R=class{constructor(e){this.tokenStore=e;}tokenStore;workspaceToken=null;apiKey=null;async getTokens(){return this.tokenStore.get()}async setTokens(e){await this.tokenStore.set(e);}async clearTokens(){await this.tokenStore.clear(),this.workspaceToken=null;}setWorkspaceToken(e){this.workspaceToken=e;}getWorkspaceToken(){return this.workspaceToken}setApiKey(e){this.apiKey=e;}getApiKey(){return this.apiKey}async isAuthenticated(){return (await this.getTokens())?.accessToken?true:!!this.apiKey}};function C(t){let e=t?.tokenStore??new h(t?.tokens??null),r=new R(e);return t?.workspaceToken&&r.setWorkspaceToken(t.workspaceToken),t?.apiKey&&r.setApiKey(t.apiKey),r}var F={debug:10,info:20,warn:30,error:40};function D(t={}){let e=F[t.level??"warn"],r=t.prefix?`[${t.prefix}]`:"";function o(n,s,i){if(F[n]<e)return;let a=`${r}[${n}] ${p(s)}`,l=i?JSON.parse(p(JSON.stringify(i))):void 0;n==="error"||n==="warn"?console.error(a,l??""):console.warn(a,l??"");}return {debug:(n,s)=>o("debug",n,s),info:(n,s)=>o("info",n,s),warn:(n,s)=>o("warn",n,s),error:(n,s)=>o("error",n,s)}}var b=class{apis=new Map;set(e,r){this.apis.set(e,r);}get(e){if(!this.apis.has(e))throw new E(e);return this.apis.get(e)}has(e){return this.apis.has(e)}ids(){return Array.from(this.apis.keys())}};function re(t){let e=t.productVersion??"0.0.0",r=t.env??oe(t.workspaceEndpoint),o=t.logger??D({level:t.logLevel??"warn",prefix:t.productName}),n=t.accessToken?{accessToken:t.accessToken,refreshToken:t.refreshToken??""}:null,s=C({tokens:n,workspaceToken:t.workspaceToken??null,apiKey:t.apiKey??null,tokenStore:t.tokenStore}),a={issuer:t.oidcIssuer??ne(t.globalEndpoint),clientId:t.clientId,clientSecret:t.clientSecret,redirectUri:t.redirectUri},l=new x({workspaceEndpoint:t.workspaceEndpoint,globalEndpoint:t.globalEndpoint,auth:s,timeout:t.timeout,autoRefresh:t.autoRefresh,onTokenRefresh:t.onTokenRefresh,defaultSignal:t.signal});return {productName:t.productName,productVersion:e,env:r,gql:{workspace:S(l,"workspace"),global:S(l,"global"),workspaceAuthOnly:S(l,"workspaceAuthOnly")},client:l,auth:s,oidc:a,logger:o,modules:new b,signal:t.signal}}function oe(t){return t.includes("localhost")||t.includes("127.0.0.1")?"local":t.includes("alpha")?"alpha":t.includes("dev")?"dev":"prod"}function ne(t){return t.includes("localhost")||t.includes("127.0.0.1")?t.replace(/\/graphql$/,"").replace(/\/global\/graphql$/,"/global"):"https://graphql.burdenoff.com/global"}function N(t){let e=new Map;for(let i of t){if(e.has(i.id))throw new c(`Duplicate module id: '${i.id}'`,"DUPLICATE_MODULE");e.set(i.id,i);}for(let i of t)for(let a of i.dependsOn??[])if(!e.has(a))throw new y(i.id,a);let r=[],o=new Set,n=new Set,s=(i,a)=>{if(!n.has(i.id)){if(o.has(i.id))throw new w([...a,i.id]);o.add(i.id);for(let l of i.dependsOn??[]){let u=e.get(l);u&&s(u,[...a,i.id]);}o.delete(i.id),n.add(i.id),r.push(i);}};for(let i of t)s(i,[]);return r}function Ve(t,e){let r=N(e),o={};for(let n of r){let s=n.attach(t);t.modules.set(n.id,s),o[n.id]=s;}return {ctx:t,modules:o}}
|
|
2
|
+
exports.AuthStore=R;exports.AuthenticationError=k;exports.AuthorizationError=f;exports.BaseGraphQLClient=x;exports.CircularDependencyError=w;exports.DeviceCodeDeniedError=q;exports.DeviceCodeExpiredError=M;exports.EnvTokenStore=A;exports.FileTokenStore=v;exports.InMemoryTokenStore=h;exports.MissingDependencyError=y;exports.ModuleNotMountedError=E;exports.ModuleRegistry=b;exports.NetworkError=m;exports.RateLimitError=T;exports.SdkError=c;exports.ValidationError=L;exports.buildContext=re;exports.createAuthStore=C;exports.createLogger=D;exports.createSdk=Ve;exports.gqlClient=S;exports.redactTokens=p;exports.sortModules=N;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { S as SdkModule, a as SdkContext } from '../module-JDbvil5h.cjs';
|
|
2
|
+
export { A as AuthStore, B as BaseGraphQLClient, C as ContextInput, E as Env, b as EnvTokenStore, c as EnvTokenStoreOptions, F as FileTokenStore, d as FileTokenStoreOptions, G as GqlClient, e as GqlRequestOptions, I as InMemoryTokenStore, J as Json, L as LogLevel, f as Logger, M as ModuleRegistry, O as OidcConfig, P as PaginationInput, g as SdkContextConfig, T as TokenPair, h as TokenStore, i as buildContext, j as createAuthStore, k as createLogger, l as gqlClient, s as sortModules } from '../module-JDbvil5h.cjs';
|
|
3
|
+
import 'graphql-request';
|
|
4
|
+
|
|
5
|
+
declare function redactTokens(input: string): string;
|
|
6
|
+
declare class SdkError extends Error {
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly cause: unknown;
|
|
9
|
+
constructor(message: string, code?: string, cause?: unknown);
|
|
10
|
+
}
|
|
11
|
+
declare class AuthenticationError extends SdkError {
|
|
12
|
+
constructor(message?: string, cause?: unknown);
|
|
13
|
+
}
|
|
14
|
+
declare class AuthorizationError extends SdkError {
|
|
15
|
+
constructor(message?: string, cause?: unknown);
|
|
16
|
+
}
|
|
17
|
+
declare class NetworkError extends SdkError {
|
|
18
|
+
constructor(message: string, cause?: unknown);
|
|
19
|
+
}
|
|
20
|
+
declare class ValidationError extends SdkError {
|
|
21
|
+
constructor(message: string, cause?: unknown);
|
|
22
|
+
}
|
|
23
|
+
declare class RateLimitError extends SdkError {
|
|
24
|
+
constructor(message?: string, cause?: unknown);
|
|
25
|
+
}
|
|
26
|
+
declare class DeviceCodeExpiredError extends SdkError {
|
|
27
|
+
constructor(message?: string);
|
|
28
|
+
}
|
|
29
|
+
declare class DeviceCodeDeniedError extends SdkError {
|
|
30
|
+
constructor(message?: string);
|
|
31
|
+
}
|
|
32
|
+
declare class MissingDependencyError extends SdkError {
|
|
33
|
+
constructor(moduleId: string, missingDep: string);
|
|
34
|
+
}
|
|
35
|
+
declare class CircularDependencyError extends SdkError {
|
|
36
|
+
constructor(cycle: readonly string[]);
|
|
37
|
+
}
|
|
38
|
+
declare class ModuleNotMountedError extends SdkError {
|
|
39
|
+
constructor(moduleId: string);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface MountedSdk<MountedModules extends readonly SdkModule[]> {
|
|
43
|
+
ctx: SdkContext;
|
|
44
|
+
modules: {
|
|
45
|
+
[K in MountedModules[number]['id']]: ReturnType<Extract<MountedModules[number], {
|
|
46
|
+
id: K;
|
|
47
|
+
}>['attach']>;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
declare function createSdk<const Modules extends readonly SdkModule[]>(ctx: SdkContext, modules: Modules): MountedSdk<Modules>;
|
|
51
|
+
|
|
52
|
+
export { AuthenticationError, AuthorizationError, CircularDependencyError, DeviceCodeDeniedError, DeviceCodeExpiredError, MissingDependencyError, ModuleNotMountedError, type MountedSdk, NetworkError, RateLimitError, SdkContext, SdkError, SdkModule, ValidationError, createSdk, redactTokens };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { S as SdkModule, a as SdkContext } from '../module-JDbvil5h.js';
|
|
2
|
+
export { A as AuthStore, B as BaseGraphQLClient, C as ContextInput, E as Env, b as EnvTokenStore, c as EnvTokenStoreOptions, F as FileTokenStore, d as FileTokenStoreOptions, G as GqlClient, e as GqlRequestOptions, I as InMemoryTokenStore, J as Json, L as LogLevel, f as Logger, M as ModuleRegistry, O as OidcConfig, P as PaginationInput, g as SdkContextConfig, T as TokenPair, h as TokenStore, i as buildContext, j as createAuthStore, k as createLogger, l as gqlClient, s as sortModules } from '../module-JDbvil5h.js';
|
|
3
|
+
import 'graphql-request';
|
|
4
|
+
|
|
5
|
+
declare function redactTokens(input: string): string;
|
|
6
|
+
declare class SdkError extends Error {
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly cause: unknown;
|
|
9
|
+
constructor(message: string, code?: string, cause?: unknown);
|
|
10
|
+
}
|
|
11
|
+
declare class AuthenticationError extends SdkError {
|
|
12
|
+
constructor(message?: string, cause?: unknown);
|
|
13
|
+
}
|
|
14
|
+
declare class AuthorizationError extends SdkError {
|
|
15
|
+
constructor(message?: string, cause?: unknown);
|
|
16
|
+
}
|
|
17
|
+
declare class NetworkError extends SdkError {
|
|
18
|
+
constructor(message: string, cause?: unknown);
|
|
19
|
+
}
|
|
20
|
+
declare class ValidationError extends SdkError {
|
|
21
|
+
constructor(message: string, cause?: unknown);
|
|
22
|
+
}
|
|
23
|
+
declare class RateLimitError extends SdkError {
|
|
24
|
+
constructor(message?: string, cause?: unknown);
|
|
25
|
+
}
|
|
26
|
+
declare class DeviceCodeExpiredError extends SdkError {
|
|
27
|
+
constructor(message?: string);
|
|
28
|
+
}
|
|
29
|
+
declare class DeviceCodeDeniedError extends SdkError {
|
|
30
|
+
constructor(message?: string);
|
|
31
|
+
}
|
|
32
|
+
declare class MissingDependencyError extends SdkError {
|
|
33
|
+
constructor(moduleId: string, missingDep: string);
|
|
34
|
+
}
|
|
35
|
+
declare class CircularDependencyError extends SdkError {
|
|
36
|
+
constructor(cycle: readonly string[]);
|
|
37
|
+
}
|
|
38
|
+
declare class ModuleNotMountedError extends SdkError {
|
|
39
|
+
constructor(moduleId: string);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface MountedSdk<MountedModules extends readonly SdkModule[]> {
|
|
43
|
+
ctx: SdkContext;
|
|
44
|
+
modules: {
|
|
45
|
+
[K in MountedModules[number]['id']]: ReturnType<Extract<MountedModules[number], {
|
|
46
|
+
id: K;
|
|
47
|
+
}>['attach']>;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
declare function createSdk<const Modules extends readonly SdkModule[]>(ctx: SdkContext, modules: Modules): MountedSdk<Modules>;
|
|
51
|
+
|
|
52
|
+
export { AuthenticationError, AuthorizationError, CircularDependencyError, DeviceCodeDeniedError, DeviceCodeExpiredError, MissingDependencyError, ModuleNotMountedError, type MountedSdk, NetworkError, RateLimitError, SdkContext, SdkError, SdkModule, ValidationError, createSdk, redactTokens };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{f as AuthStore,a as BaseGraphQLClient,e as EnvTokenStore,d as FileTokenStore,c as InMemoryTokenStore,i as ModuleRegistry,j as buildContext,g as createAuthStore,h as createLogger,l as createSdk,b as gqlClient,k as sortModules}from'../chunk-YGVAZ3D7.js';export{c as AuthenticationError,d as AuthorizationError,k as CircularDependencyError,i as DeviceCodeDeniedError,h as DeviceCodeExpiredError,j as MissingDependencyError,l as ModuleNotMountedError,e as NetworkError,g as RateLimitError,b as SdkError,f as ValidationError,a as redactTokens}from'../chunk-NEREAHJ6.js';
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var graphqlRequest=require('graphql-request'),promises=require('fs/promises'),path=require('path');var j=["password","secret","clientSecret","apiKey","token","mfaCode","accessToken","refreshToken","workspaceToken","authorization"],B=/\b(eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)\b/g;function p(t){let e=t.replace(B,"<redacted-jwt>");for(let r of j){let o=new RegExp(`("${r}"\\s*:\\s*")[^"]*(")`,"gi");e=e.replace(o,"$1<redacted>$2");}return e}var c=class extends Error{code;cause;constructor(e,r="SDK_ERROR",o){super(p(e)),this.name="SdkError",this.code=r,this.cause=o;}},k=class extends c{constructor(e="Authentication failed",r){super(e,"AUTHENTICATION_ERROR",r),this.name="AuthenticationError";}},f=class extends c{constructor(e="Not authorized",r){super(e,"AUTHORIZATION_ERROR",r),this.name="AuthorizationError";}},m=class extends c{constructor(e,r){super(e,"NETWORK_ERROR",r),this.name="NetworkError";}},L=class extends c{constructor(e,r){super(e,"VALIDATION_ERROR",r),this.name="ValidationError";}},T=class extends c{constructor(e="Rate limit exceeded",r){super(e,"RATE_LIMIT_ERROR",r),this.name="RateLimitError";}},M=class extends c{constructor(e="Device code expired"){super(e,"DEVICE_CODE_EXPIRED"),this.name="DeviceCodeExpiredError";}},q=class extends c{constructor(e="Device authorization denied by user"){super(e,"DEVICE_CODE_DENIED"),this.name="DeviceCodeDeniedError";}},y=class extends c{constructor(e,r){super(`Module '${e}' declares dependency on '${r}', but '${r}' is not in the module list.`,"MISSING_DEPENDENCY"),this.name="MissingDependencyError";}},w=class extends c{constructor(e){super(`Circular dependency detected among modules: ${e.join(" -> ")}`,"CIRCULAR_DEPENDENCY"),this.name="CircularDependencyError";}},E=class extends c{constructor(e){super(`Module '${e}' is not mounted on this SDK instance. Add it to the modules array passed to createSdk().`,"MODULE_NOT_MOUNTED"),this.name="ModuleNotMountedError";}};var Q=3e4,K=3,z=1e3,W=300*1e3;function H(t,e){return new Promise((r,o)=>{if(e?.aborted)return o(new c("Aborted","ABORTED"));let n=setTimeout(()=>r(),t);e?.addEventListener("abort",()=>{clearTimeout(n),o(new c("Aborted","ABORTED"));});})}function J(t){if(t instanceof TypeError)return true;if(t&&typeof t=="object"&&"response"in t){let e=t.response;if(e&&typeof e.status=="number"&&e.status>=500)return true}return false}function V(t){if(t&&typeof t=="object"&&"response"in t){let e=t.response;if(e&&typeof e.status=="number"&&e.status>=400&&e.status<500)return e.status}return null}function I(t){if(t&&typeof t=="object"&&"response"in t){let e=t,r=e.response?.errors?.[0];if(r?.message)return p(r.message);if(e.message)return p(e.message)}return t instanceof Error?p(t.message):p(String(t))}var x=class{workspaceClient;globalClient;opts;constructor(e){this.opts=e,this.workspaceClient=new graphqlRequest.GraphQLClient(e.workspaceEndpoint),this.globalClient=new graphqlRequest.GraphQLClient(e.globalEndpoint);}async buildHeaders(e){let r={},o=this.opts.auth.getApiKey();o&&(r["X-API-Key"]=o);let n=await this.opts.auth.getTokens();if(n?.accessToken&&(r.Authorization=`Bearer ${n.accessToken}`),e==="workspace"){let s=this.opts.auth.getWorkspaceToken();s&&(r["X-Workspace-Authorization"]=`Bearer ${s}`);}return r}isExpiringSoon(e){return e?Date.now()+W>=e:false}async ensureFresh(){if(this.opts.autoRefresh===false)return;let e=await this.opts.auth.getTokens();e?.expiresAt&&this.isExpiringSoon(e.expiresAt)&&await this.performTokenRefresh();}async performTokenRefresh(){let e=await this.opts.auth.getTokens();if(!e?.refreshToken)throw new k("No refresh token available");let o=await this.globalClient.request("mutation RefreshToken($token: String!) { refreshToken(token: $token) { accessToken refreshToken expiresIn } }",{token:e.refreshToken}),n=Date.now()+o.refreshToken.expiresIn*1e3,s={accessToken:o.refreshToken.accessToken,refreshToken:o.refreshToken.refreshToken,expiresAt:n};return await this.opts.auth.setTokens(s),this.opts.onTokenRefresh&&await this.opts.onTokenRefresh(s),s}async executeWithRetry(e,r,o,n,s){let i=this.opts.timeout??Q,a;for(let u=0;u<K;u++){let O=new AbortController,P=s?.signal??this.opts.defaultSignal,_=()=>O.abort();P?.addEventListener("abort",_);let U=setTimeout(()=>O.abort(),i);try{let g=await this.buildHeaders(r);return await e.request({document:o,variables:n,signal:O.signal,requestHeaders:g})}catch(g){if(a=g,V(g)!==null)break;if(J(g)&&u<K-1){await H(z*2**u,P);continue}break}finally{clearTimeout(U),P?.removeEventListener("abort",_);}}let l=V(a);if(l!==null){let u=I(a);switch(l){case 401:throw new k(u,a);case 403:throw new f(u,a);case 429:throw new T(u,a);default:throw new c(u,`HTTP_${l}`,a)}}throw a instanceof TypeError?new m(I(a),a):a instanceof c?a:new c(I(a),"SDK_ERROR",a)}async globalRequest(e,r,o){return this.executeWithRetry(this.globalClient,"global",e,r,o)}async workspaceRequest(e,r,o){return await this.ensureFresh(),this.executeWithRetry(this.workspaceClient,"workspace",e,r,o)}async workspaceAuthOnlyRequest(e,r,o){return this.executeWithRetry(this.workspaceClient,"workspace",e,r,o)}};function S(t,e){return e==="workspace"?{request:(r,o,n)=>t.workspaceRequest(r,o,n)}:e==="global"?{request:(r,o,n)=>t.globalRequest(r,o,n)}:{request:(r,o,n)=>t.workspaceAuthOnlyRequest(r,o,n)}}var h=class{tokens;constructor(e){this.tokens=e??null;}async get(){return this.tokens?{...this.tokens}:null}async set(e){this.tokens={...e};}async clear(){this.tokens=null;}},v=class{constructor(e){this.opts=e;}opts;async get(){try{let e=await promises.readFile(this.opts.path,"utf8"),r=JSON.parse(e);return r&&typeof r.accessToken=="string"?{accessToken:r.accessToken,refreshToken:r.refreshToken??"",expiresAt:typeof r.expiresAt=="number"?r.expiresAt:void 0}:null}catch(e){if($(e)==="ENOENT")return null;throw new Error(p(`FileTokenStore.get failed: ${e.message}`))}}async set(e){await promises.mkdir(path.dirname(this.opts.path),{recursive:true}),await promises.writeFile(this.opts.path,JSON.stringify(e,null,2),{mode:384});}async clear(){try{await promises.unlink(this.opts.path);}catch(e){if($(e)!=="ENOENT")throw e}}};function $(t){if(t&&typeof t=="object"&&"code"in t&&typeof t.code=="string")return t.code}var A=class{constructor(e){this.opts=e;}opts;async get(){let e=process.env[this.opts.accessTokenVar];if(!e)return null;let r=this.opts.refreshTokenVar?process.env[this.opts.refreshTokenVar]??"":"",o=this.opts.expiresAtVar?process.env[this.opts.expiresAtVar]:void 0,n=o?Number.parseInt(o,10):void 0;return {accessToken:e,refreshToken:r,expiresAt:n}}async set(e){}async clear(){}};var R=class{constructor(e){this.tokenStore=e;}tokenStore;workspaceToken=null;apiKey=null;async getTokens(){return this.tokenStore.get()}async setTokens(e){await this.tokenStore.set(e);}async clearTokens(){await this.tokenStore.clear(),this.workspaceToken=null;}setWorkspaceToken(e){this.workspaceToken=e;}getWorkspaceToken(){return this.workspaceToken}setApiKey(e){this.apiKey=e;}getApiKey(){return this.apiKey}async isAuthenticated(){return (await this.getTokens())?.accessToken?true:!!this.apiKey}};function C(t){let e=t?.tokenStore??new h(t?.tokens??null),r=new R(e);return t?.workspaceToken&&r.setWorkspaceToken(t.workspaceToken),t?.apiKey&&r.setApiKey(t.apiKey),r}var F={debug:10,info:20,warn:30,error:40};function D(t={}){let e=F[t.level??"warn"],r=t.prefix?`[${t.prefix}]`:"";function o(n,s,i){if(F[n]<e)return;let a=`${r}[${n}] ${p(s)}`,l=i?JSON.parse(p(JSON.stringify(i))):void 0;n==="error"||n==="warn"?console.error(a,l??""):console.warn(a,l??"");}return {debug:(n,s)=>o("debug",n,s),info:(n,s)=>o("info",n,s),warn:(n,s)=>o("warn",n,s),error:(n,s)=>o("error",n,s)}}var b=class{apis=new Map;set(e,r){this.apis.set(e,r);}get(e){if(!this.apis.has(e))throw new E(e);return this.apis.get(e)}has(e){return this.apis.has(e)}ids(){return Array.from(this.apis.keys())}};function re(t){let e=t.productVersion??"0.0.0",r=t.env??oe(t.workspaceEndpoint),o=t.logger??D({level:t.logLevel??"warn",prefix:t.productName}),n=t.accessToken?{accessToken:t.accessToken,refreshToken:t.refreshToken??""}:null,s=C({tokens:n,workspaceToken:t.workspaceToken??null,apiKey:t.apiKey??null,tokenStore:t.tokenStore}),a={issuer:t.oidcIssuer??ne(t.globalEndpoint),clientId:t.clientId,clientSecret:t.clientSecret,redirectUri:t.redirectUri},l=new x({workspaceEndpoint:t.workspaceEndpoint,globalEndpoint:t.globalEndpoint,auth:s,timeout:t.timeout,autoRefresh:t.autoRefresh,onTokenRefresh:t.onTokenRefresh,defaultSignal:t.signal});return {productName:t.productName,productVersion:e,env:r,gql:{workspace:S(l,"workspace"),global:S(l,"global"),workspaceAuthOnly:S(l,"workspaceAuthOnly")},client:l,auth:s,oidc:a,logger:o,modules:new b,signal:t.signal}}function oe(t){return t.includes("localhost")||t.includes("127.0.0.1")?"local":t.includes("alpha")?"alpha":t.includes("dev")?"dev":"prod"}function ne(t){return t.includes("localhost")||t.includes("127.0.0.1")?t.replace(/\/graphql$/,"").replace(/\/global\/graphql$/,"/global"):"https://graphql.burdenoff.com/global"}function N(t){let e=new Map;for(let i of t){if(e.has(i.id))throw new c(`Duplicate module id: '${i.id}'`,"DUPLICATE_MODULE");e.set(i.id,i);}for(let i of t)for(let a of i.dependsOn??[])if(!e.has(a))throw new y(i.id,a);let r=[],o=new Set,n=new Set,s=(i,a)=>{if(!n.has(i.id)){if(o.has(i.id))throw new w([...a,i.id]);o.add(i.id);for(let l of i.dependsOn??[]){let u=e.get(l);u&&s(u,[...a,i.id]);}o.delete(i.id),n.add(i.id),r.push(i);}};for(let i of t)s(i,[]);return r}function Ve(t,e){let r=N(e),o={};for(let n of r){let s=n.attach(t);t.modules.set(n.id,s),o[n.id]=s;}return {ctx:t,modules:o}}
|
|
2
|
+
exports.AuthStore=R;exports.AuthenticationError=k;exports.AuthorizationError=f;exports.BaseGraphQLClient=x;exports.CircularDependencyError=w;exports.DeviceCodeDeniedError=q;exports.DeviceCodeExpiredError=M;exports.EnvTokenStore=A;exports.FileTokenStore=v;exports.InMemoryTokenStore=h;exports.MissingDependencyError=y;exports.ModuleNotMountedError=E;exports.ModuleRegistry=b;exports.NetworkError=m;exports.RateLimitError=T;exports.SdkError=c;exports.ValidationError=L;exports.buildContext=re;exports.createAuthStore=C;exports.createLogger=D;exports.createSdk=Ve;exports.gqlClient=S;exports.redactTokens=p;exports.sortModules=N;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { AuthenticationError, AuthorizationError, CircularDependencyError, DeviceCodeDeniedError, DeviceCodeExpiredError, MissingDependencyError, ModuleNotMountedError, MountedSdk, NetworkError, RateLimitError, SdkError, ValidationError, createSdk, redactTokens } from './core/index.cjs';
|
|
2
|
+
export { A as AuthStore, B as BaseGraphQLClient, C as ContextInput, E as Env, b as EnvTokenStore, c as EnvTokenStoreOptions, F as FileTokenStore, d as FileTokenStoreOptions, G as GqlClient, e as GqlRequestOptions, I as InMemoryTokenStore, J as Json, L as LogLevel, f as Logger, M as ModuleRegistry, O as OidcConfig, P as PaginationInput, a as SdkContext, g as SdkContextConfig, S as SdkModule, T as TokenPair, h as TokenStore, i as buildContext, j as createAuthStore, k as createLogger, l as gqlClient, s as sortModules } from './module-JDbvil5h.cjs';
|
|
3
|
+
import 'graphql-request';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { AuthenticationError, AuthorizationError, CircularDependencyError, DeviceCodeDeniedError, DeviceCodeExpiredError, MissingDependencyError, ModuleNotMountedError, MountedSdk, NetworkError, RateLimitError, SdkError, ValidationError, createSdk, redactTokens } from './core/index.js';
|
|
2
|
+
export { A as AuthStore, B as BaseGraphQLClient, C as ContextInput, E as Env, b as EnvTokenStore, c as EnvTokenStoreOptions, F as FileTokenStore, d as FileTokenStoreOptions, G as GqlClient, e as GqlRequestOptions, I as InMemoryTokenStore, J as Json, L as LogLevel, f as Logger, M as ModuleRegistry, O as OidcConfig, P as PaginationInput, a as SdkContext, g as SdkContextConfig, S as SdkModule, T as TokenPair, h as TokenStore, i as buildContext, j as createAuthStore, k as createLogger, l as gqlClient, s as sortModules } from './module-JDbvil5h.js';
|
|
3
|
+
import 'graphql-request';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{f as AuthStore,a as BaseGraphQLClient,e as EnvTokenStore,d as FileTokenStore,c as InMemoryTokenStore,i as ModuleRegistry,j as buildContext,g as createAuthStore,h as createLogger,l as createSdk,b as gqlClient,k as sortModules}from'./chunk-YGVAZ3D7.js';export{c as AuthenticationError,d as AuthorizationError,k as CircularDependencyError,i as DeviceCodeDeniedError,h as DeviceCodeExpiredError,j as MissingDependencyError,l as ModuleNotMountedError,e as NetworkError,g as RateLimitError,b as SdkError,f as ValidationError,a as redactTokens}from'./chunk-NEREAHJ6.js';
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { RequestDocument, Variables } from 'graphql-request';
|
|
2
|
+
|
|
3
|
+
interface TokenPair {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
refreshToken: string;
|
|
6
|
+
expiresAt?: number;
|
|
7
|
+
}
|
|
8
|
+
type Json = unknown;
|
|
9
|
+
type Env = 'prod' | 'alpha' | 'dev' | 'local';
|
|
10
|
+
interface PaginationInput {
|
|
11
|
+
limit?: number;
|
|
12
|
+
offset?: number;
|
|
13
|
+
sortBy?: string;
|
|
14
|
+
sortOrder?: 'asc' | 'desc';
|
|
15
|
+
}
|
|
16
|
+
interface ContextInput {
|
|
17
|
+
userId?: string;
|
|
18
|
+
workspaceId?: string;
|
|
19
|
+
projectId?: string;
|
|
20
|
+
appId?: string;
|
|
21
|
+
custom?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface TokenStore {
|
|
25
|
+
get(): Promise<TokenPair | null>;
|
|
26
|
+
set(tokens: TokenPair): Promise<void>;
|
|
27
|
+
clear(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
declare class InMemoryTokenStore implements TokenStore {
|
|
30
|
+
private tokens;
|
|
31
|
+
constructor(initial?: TokenPair | null);
|
|
32
|
+
get(): Promise<TokenPair | null>;
|
|
33
|
+
set(tokens: TokenPair): Promise<void>;
|
|
34
|
+
clear(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
interface FileTokenStoreOptions {
|
|
37
|
+
path: string;
|
|
38
|
+
}
|
|
39
|
+
declare class FileTokenStore implements TokenStore {
|
|
40
|
+
private readonly opts;
|
|
41
|
+
constructor(opts: FileTokenStoreOptions);
|
|
42
|
+
get(): Promise<TokenPair | null>;
|
|
43
|
+
set(tokens: TokenPair): Promise<void>;
|
|
44
|
+
clear(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
interface EnvTokenStoreOptions {
|
|
47
|
+
accessTokenVar: string;
|
|
48
|
+
refreshTokenVar?: string;
|
|
49
|
+
expiresAtVar?: string;
|
|
50
|
+
}
|
|
51
|
+
declare class EnvTokenStore implements TokenStore {
|
|
52
|
+
private readonly opts;
|
|
53
|
+
constructor(opts: EnvTokenStoreOptions);
|
|
54
|
+
get(): Promise<TokenPair | null>;
|
|
55
|
+
set(_tokens: TokenPair): Promise<void>;
|
|
56
|
+
clear(): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare class AuthStore {
|
|
60
|
+
private readonly tokenStore;
|
|
61
|
+
private workspaceToken;
|
|
62
|
+
private apiKey;
|
|
63
|
+
constructor(tokenStore: TokenStore);
|
|
64
|
+
getTokens(): Promise<TokenPair | null>;
|
|
65
|
+
setTokens(tokens: TokenPair): Promise<void>;
|
|
66
|
+
clearTokens(): Promise<void>;
|
|
67
|
+
setWorkspaceToken(token: string | null): void;
|
|
68
|
+
getWorkspaceToken(): string | null;
|
|
69
|
+
setApiKey(key: string | null): void;
|
|
70
|
+
getApiKey(): string | null;
|
|
71
|
+
isAuthenticated(): Promise<boolean>;
|
|
72
|
+
}
|
|
73
|
+
declare function createAuthStore(initial?: {
|
|
74
|
+
tokens?: TokenPair | null;
|
|
75
|
+
workspaceToken?: string | null;
|
|
76
|
+
apiKey?: string | null;
|
|
77
|
+
tokenStore?: TokenStore;
|
|
78
|
+
}): AuthStore;
|
|
79
|
+
|
|
80
|
+
interface BaseGraphQLClientOptions {
|
|
81
|
+
workspaceEndpoint: string;
|
|
82
|
+
globalEndpoint: string;
|
|
83
|
+
auth: AuthStore;
|
|
84
|
+
timeout?: number;
|
|
85
|
+
autoRefresh?: boolean;
|
|
86
|
+
onTokenRefresh?: (tokens: {
|
|
87
|
+
accessToken: string;
|
|
88
|
+
refreshToken: string;
|
|
89
|
+
expiresAt?: number;
|
|
90
|
+
}) => void | Promise<void>;
|
|
91
|
+
defaultSignal?: AbortSignal;
|
|
92
|
+
}
|
|
93
|
+
interface GqlRequestOptions {
|
|
94
|
+
signal?: AbortSignal;
|
|
95
|
+
}
|
|
96
|
+
declare class BaseGraphQLClient {
|
|
97
|
+
private readonly workspaceClient;
|
|
98
|
+
private readonly globalClient;
|
|
99
|
+
private readonly opts;
|
|
100
|
+
constructor(opts: BaseGraphQLClientOptions);
|
|
101
|
+
private buildHeaders;
|
|
102
|
+
private isExpiringSoon;
|
|
103
|
+
private ensureFresh;
|
|
104
|
+
performTokenRefresh(): Promise<{
|
|
105
|
+
accessToken: string;
|
|
106
|
+
refreshToken: string;
|
|
107
|
+
expiresAt?: number;
|
|
108
|
+
}>;
|
|
109
|
+
private executeWithRetry;
|
|
110
|
+
globalRequest<T>(document: RequestDocument, variables?: Variables, options?: GqlRequestOptions): Promise<T>;
|
|
111
|
+
workspaceRequest<T>(document: RequestDocument, variables?: Variables, options?: GqlRequestOptions): Promise<T>;
|
|
112
|
+
workspaceAuthOnlyRequest<T>(document: RequestDocument, variables?: Variables, options?: GqlRequestOptions): Promise<T>;
|
|
113
|
+
}
|
|
114
|
+
interface GqlClient {
|
|
115
|
+
request<T>(document: RequestDocument, variables?: Variables, options?: GqlRequestOptions): Promise<T>;
|
|
116
|
+
}
|
|
117
|
+
declare function gqlClient(base: BaseGraphQLClient, scope: 'workspace' | 'global' | 'workspaceAuthOnly'): GqlClient;
|
|
118
|
+
|
|
119
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
120
|
+
interface Logger {
|
|
121
|
+
debug(msg: string, meta?: Record<string, unknown>): void;
|
|
122
|
+
info(msg: string, meta?: Record<string, unknown>): void;
|
|
123
|
+
warn(msg: string, meta?: Record<string, unknown>): void;
|
|
124
|
+
error(msg: string, meta?: Record<string, unknown>): void;
|
|
125
|
+
}
|
|
126
|
+
declare function createLogger(opts?: {
|
|
127
|
+
level?: LogLevel;
|
|
128
|
+
prefix?: string;
|
|
129
|
+
}): Logger;
|
|
130
|
+
|
|
131
|
+
declare class ModuleRegistry {
|
|
132
|
+
private readonly apis;
|
|
133
|
+
set(id: string, api: unknown): void;
|
|
134
|
+
get<API>(id: string): API;
|
|
135
|
+
has(id: string): boolean;
|
|
136
|
+
ids(): readonly string[];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface SdkContextConfig {
|
|
140
|
+
productName: string;
|
|
141
|
+
productVersion?: string;
|
|
142
|
+
workspaceEndpoint: string;
|
|
143
|
+
globalEndpoint: string;
|
|
144
|
+
oidcIssuer?: string;
|
|
145
|
+
clientId?: string;
|
|
146
|
+
clientSecret?: string;
|
|
147
|
+
redirectUri?: string;
|
|
148
|
+
apiKey?: string;
|
|
149
|
+
accessToken?: string;
|
|
150
|
+
refreshToken?: string;
|
|
151
|
+
workspaceToken?: string;
|
|
152
|
+
tokenStore?: TokenStore;
|
|
153
|
+
timeout?: number;
|
|
154
|
+
autoRefresh?: boolean;
|
|
155
|
+
onTokenRefresh?: (tokens: TokenPair) => void | Promise<void>;
|
|
156
|
+
env?: Env;
|
|
157
|
+
logLevel?: LogLevel;
|
|
158
|
+
logger?: Logger;
|
|
159
|
+
signal?: AbortSignal;
|
|
160
|
+
}
|
|
161
|
+
interface OidcConfig {
|
|
162
|
+
issuer: string;
|
|
163
|
+
clientId?: string;
|
|
164
|
+
clientSecret?: string;
|
|
165
|
+
redirectUri?: string;
|
|
166
|
+
}
|
|
167
|
+
interface SdkContext {
|
|
168
|
+
readonly productName: string;
|
|
169
|
+
readonly productVersion: string;
|
|
170
|
+
readonly env: Env;
|
|
171
|
+
readonly gql: {
|
|
172
|
+
workspace: GqlClient;
|
|
173
|
+
global: GqlClient;
|
|
174
|
+
workspaceAuthOnly: GqlClient;
|
|
175
|
+
};
|
|
176
|
+
readonly client: BaseGraphQLClient;
|
|
177
|
+
readonly auth: AuthStore;
|
|
178
|
+
readonly oidc: OidcConfig;
|
|
179
|
+
readonly logger: Logger;
|
|
180
|
+
readonly modules: ModuleRegistry;
|
|
181
|
+
readonly signal?: AbortSignal;
|
|
182
|
+
}
|
|
183
|
+
declare function buildContext(config: SdkContextConfig): SdkContext;
|
|
184
|
+
|
|
185
|
+
interface SdkModule<API = unknown> {
|
|
186
|
+
readonly id: string;
|
|
187
|
+
readonly version: string;
|
|
188
|
+
readonly displayName: string;
|
|
189
|
+
readonly dependsOn?: readonly string[];
|
|
190
|
+
attach(ctx: SdkContext): API;
|
|
191
|
+
}
|
|
192
|
+
declare function sortModules(modules: readonly SdkModule[]): SdkModule[];
|
|
193
|
+
|
|
194
|
+
export { AuthStore as A, BaseGraphQLClient as B, type ContextInput as C, type Env as E, FileTokenStore as F, type GqlClient as G, InMemoryTokenStore as I, type Json as J, type LogLevel as L, ModuleRegistry as M, type OidcConfig as O, type PaginationInput as P, type SdkModule as S, type TokenPair as T, type SdkContext as a, EnvTokenStore as b, type EnvTokenStoreOptions as c, type FileTokenStoreOptions as d, type GqlRequestOptions as e, type Logger as f, type SdkContextConfig as g, type TokenStore as h, buildContext as i, createAuthStore as j, createLogger as k, gqlClient as l, sortModules as s };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { RequestDocument, Variables } from 'graphql-request';
|
|
2
|
+
|
|
3
|
+
interface TokenPair {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
refreshToken: string;
|
|
6
|
+
expiresAt?: number;
|
|
7
|
+
}
|
|
8
|
+
type Json = unknown;
|
|
9
|
+
type Env = 'prod' | 'alpha' | 'dev' | 'local';
|
|
10
|
+
interface PaginationInput {
|
|
11
|
+
limit?: number;
|
|
12
|
+
offset?: number;
|
|
13
|
+
sortBy?: string;
|
|
14
|
+
sortOrder?: 'asc' | 'desc';
|
|
15
|
+
}
|
|
16
|
+
interface ContextInput {
|
|
17
|
+
userId?: string;
|
|
18
|
+
workspaceId?: string;
|
|
19
|
+
projectId?: string;
|
|
20
|
+
appId?: string;
|
|
21
|
+
custom?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface TokenStore {
|
|
25
|
+
get(): Promise<TokenPair | null>;
|
|
26
|
+
set(tokens: TokenPair): Promise<void>;
|
|
27
|
+
clear(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
declare class InMemoryTokenStore implements TokenStore {
|
|
30
|
+
private tokens;
|
|
31
|
+
constructor(initial?: TokenPair | null);
|
|
32
|
+
get(): Promise<TokenPair | null>;
|
|
33
|
+
set(tokens: TokenPair): Promise<void>;
|
|
34
|
+
clear(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
interface FileTokenStoreOptions {
|
|
37
|
+
path: string;
|
|
38
|
+
}
|
|
39
|
+
declare class FileTokenStore implements TokenStore {
|
|
40
|
+
private readonly opts;
|
|
41
|
+
constructor(opts: FileTokenStoreOptions);
|
|
42
|
+
get(): Promise<TokenPair | null>;
|
|
43
|
+
set(tokens: TokenPair): Promise<void>;
|
|
44
|
+
clear(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
interface EnvTokenStoreOptions {
|
|
47
|
+
accessTokenVar: string;
|
|
48
|
+
refreshTokenVar?: string;
|
|
49
|
+
expiresAtVar?: string;
|
|
50
|
+
}
|
|
51
|
+
declare class EnvTokenStore implements TokenStore {
|
|
52
|
+
private readonly opts;
|
|
53
|
+
constructor(opts: EnvTokenStoreOptions);
|
|
54
|
+
get(): Promise<TokenPair | null>;
|
|
55
|
+
set(_tokens: TokenPair): Promise<void>;
|
|
56
|
+
clear(): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare class AuthStore {
|
|
60
|
+
private readonly tokenStore;
|
|
61
|
+
private workspaceToken;
|
|
62
|
+
private apiKey;
|
|
63
|
+
constructor(tokenStore: TokenStore);
|
|
64
|
+
getTokens(): Promise<TokenPair | null>;
|
|
65
|
+
setTokens(tokens: TokenPair): Promise<void>;
|
|
66
|
+
clearTokens(): Promise<void>;
|
|
67
|
+
setWorkspaceToken(token: string | null): void;
|
|
68
|
+
getWorkspaceToken(): string | null;
|
|
69
|
+
setApiKey(key: string | null): void;
|
|
70
|
+
getApiKey(): string | null;
|
|
71
|
+
isAuthenticated(): Promise<boolean>;
|
|
72
|
+
}
|
|
73
|
+
declare function createAuthStore(initial?: {
|
|
74
|
+
tokens?: TokenPair | null;
|
|
75
|
+
workspaceToken?: string | null;
|
|
76
|
+
apiKey?: string | null;
|
|
77
|
+
tokenStore?: TokenStore;
|
|
78
|
+
}): AuthStore;
|
|
79
|
+
|
|
80
|
+
interface BaseGraphQLClientOptions {
|
|
81
|
+
workspaceEndpoint: string;
|
|
82
|
+
globalEndpoint: string;
|
|
83
|
+
auth: AuthStore;
|
|
84
|
+
timeout?: number;
|
|
85
|
+
autoRefresh?: boolean;
|
|
86
|
+
onTokenRefresh?: (tokens: {
|
|
87
|
+
accessToken: string;
|
|
88
|
+
refreshToken: string;
|
|
89
|
+
expiresAt?: number;
|
|
90
|
+
}) => void | Promise<void>;
|
|
91
|
+
defaultSignal?: AbortSignal;
|
|
92
|
+
}
|
|
93
|
+
interface GqlRequestOptions {
|
|
94
|
+
signal?: AbortSignal;
|
|
95
|
+
}
|
|
96
|
+
declare class BaseGraphQLClient {
|
|
97
|
+
private readonly workspaceClient;
|
|
98
|
+
private readonly globalClient;
|
|
99
|
+
private readonly opts;
|
|
100
|
+
constructor(opts: BaseGraphQLClientOptions);
|
|
101
|
+
private buildHeaders;
|
|
102
|
+
private isExpiringSoon;
|
|
103
|
+
private ensureFresh;
|
|
104
|
+
performTokenRefresh(): Promise<{
|
|
105
|
+
accessToken: string;
|
|
106
|
+
refreshToken: string;
|
|
107
|
+
expiresAt?: number;
|
|
108
|
+
}>;
|
|
109
|
+
private executeWithRetry;
|
|
110
|
+
globalRequest<T>(document: RequestDocument, variables?: Variables, options?: GqlRequestOptions): Promise<T>;
|
|
111
|
+
workspaceRequest<T>(document: RequestDocument, variables?: Variables, options?: GqlRequestOptions): Promise<T>;
|
|
112
|
+
workspaceAuthOnlyRequest<T>(document: RequestDocument, variables?: Variables, options?: GqlRequestOptions): Promise<T>;
|
|
113
|
+
}
|
|
114
|
+
interface GqlClient {
|
|
115
|
+
request<T>(document: RequestDocument, variables?: Variables, options?: GqlRequestOptions): Promise<T>;
|
|
116
|
+
}
|
|
117
|
+
declare function gqlClient(base: BaseGraphQLClient, scope: 'workspace' | 'global' | 'workspaceAuthOnly'): GqlClient;
|
|
118
|
+
|
|
119
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
120
|
+
interface Logger {
|
|
121
|
+
debug(msg: string, meta?: Record<string, unknown>): void;
|
|
122
|
+
info(msg: string, meta?: Record<string, unknown>): void;
|
|
123
|
+
warn(msg: string, meta?: Record<string, unknown>): void;
|
|
124
|
+
error(msg: string, meta?: Record<string, unknown>): void;
|
|
125
|
+
}
|
|
126
|
+
declare function createLogger(opts?: {
|
|
127
|
+
level?: LogLevel;
|
|
128
|
+
prefix?: string;
|
|
129
|
+
}): Logger;
|
|
130
|
+
|
|
131
|
+
declare class ModuleRegistry {
|
|
132
|
+
private readonly apis;
|
|
133
|
+
set(id: string, api: unknown): void;
|
|
134
|
+
get<API>(id: string): API;
|
|
135
|
+
has(id: string): boolean;
|
|
136
|
+
ids(): readonly string[];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface SdkContextConfig {
|
|
140
|
+
productName: string;
|
|
141
|
+
productVersion?: string;
|
|
142
|
+
workspaceEndpoint: string;
|
|
143
|
+
globalEndpoint: string;
|
|
144
|
+
oidcIssuer?: string;
|
|
145
|
+
clientId?: string;
|
|
146
|
+
clientSecret?: string;
|
|
147
|
+
redirectUri?: string;
|
|
148
|
+
apiKey?: string;
|
|
149
|
+
accessToken?: string;
|
|
150
|
+
refreshToken?: string;
|
|
151
|
+
workspaceToken?: string;
|
|
152
|
+
tokenStore?: TokenStore;
|
|
153
|
+
timeout?: number;
|
|
154
|
+
autoRefresh?: boolean;
|
|
155
|
+
onTokenRefresh?: (tokens: TokenPair) => void | Promise<void>;
|
|
156
|
+
env?: Env;
|
|
157
|
+
logLevel?: LogLevel;
|
|
158
|
+
logger?: Logger;
|
|
159
|
+
signal?: AbortSignal;
|
|
160
|
+
}
|
|
161
|
+
interface OidcConfig {
|
|
162
|
+
issuer: string;
|
|
163
|
+
clientId?: string;
|
|
164
|
+
clientSecret?: string;
|
|
165
|
+
redirectUri?: string;
|
|
166
|
+
}
|
|
167
|
+
interface SdkContext {
|
|
168
|
+
readonly productName: string;
|
|
169
|
+
readonly productVersion: string;
|
|
170
|
+
readonly env: Env;
|
|
171
|
+
readonly gql: {
|
|
172
|
+
workspace: GqlClient;
|
|
173
|
+
global: GqlClient;
|
|
174
|
+
workspaceAuthOnly: GqlClient;
|
|
175
|
+
};
|
|
176
|
+
readonly client: BaseGraphQLClient;
|
|
177
|
+
readonly auth: AuthStore;
|
|
178
|
+
readonly oidc: OidcConfig;
|
|
179
|
+
readonly logger: Logger;
|
|
180
|
+
readonly modules: ModuleRegistry;
|
|
181
|
+
readonly signal?: AbortSignal;
|
|
182
|
+
}
|
|
183
|
+
declare function buildContext(config: SdkContextConfig): SdkContext;
|
|
184
|
+
|
|
185
|
+
interface SdkModule<API = unknown> {
|
|
186
|
+
readonly id: string;
|
|
187
|
+
readonly version: string;
|
|
188
|
+
readonly displayName: string;
|
|
189
|
+
readonly dependsOn?: readonly string[];
|
|
190
|
+
attach(ctx: SdkContext): API;
|
|
191
|
+
}
|
|
192
|
+
declare function sortModules(modules: readonly SdkModule[]): SdkModule[];
|
|
193
|
+
|
|
194
|
+
export { AuthStore as A, BaseGraphQLClient as B, type ContextInput as C, type Env as E, FileTokenStore as F, type GqlClient as G, InMemoryTokenStore as I, type Json as J, type LogLevel as L, ModuleRegistry as M, type OidcConfig as O, type PaginationInput as P, type SdkModule as S, type TokenPair as T, type SdkContext as a, EnvTokenStore as b, type EnvTokenStoreOptions as c, type FileTokenStoreOptions as d, type GqlRequestOptions as e, type Logger as f, type SdkContextConfig as g, type TokenStore as h, buildContext as i, createAuthStore as j, createLogger as k, gqlClient as l, sortModules as s };
|