@bodhiapp/bodhi-js-core 0.0.26 → 0.0.28
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/access-request.d.ts +4 -4
- package/dist/bodhi-core.cjs.js +3 -3
- package/dist/bodhi-core.esm.js +275 -290
- package/dist/cli/setup-modal.js +2 -2
- package/dist/direct-client-base.d.ts +7 -8
- package/dist/errors.d.ts +9 -9
- package/dist/facade-client-base.d.ts +7 -8
- package/dist/index.d.ts +1 -2
- package/dist/interface.d.ts +13 -10
- package/dist/openai-client-compat.d.ts +2 -2
- package/dist/types/client-state.d.ts +4 -4
- package/dist/types/index.cjs.js +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.esm.js +168 -38
- package/package.json +4 -4
- package/dist/protocol-utils-7g8EeigP.cjs +0 -1
- package/dist/protocol-utils-DqAh8xyi.js +0 -182
- package/dist/types/api.d.ts +0 -33
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { AccessRequestStatusResponse, CreateAccessRequest, CreateAccessRequestResponse, DeploymentMode, UserScope } from '@bodhiapp/ts-client';
|
|
1
|
+
import { AccessRequestStatusResponse, CreateAccessRequest, CreateAccessRequestResponse, DeploymentMode, PingResponse, UserScope } from '@bodhiapp/ts-client';
|
|
2
|
+
import { ApiResponse } from '@bodhiapp/bodhi-browser-types';
|
|
2
3
|
import { IDirectClient } from './interface';
|
|
3
4
|
import { Logger } from './logger';
|
|
4
5
|
import { Chat, Models, Embeddings, Toolsets, Mcps } from './openai-client-compat';
|
|
5
6
|
import { OAuthEndpoints, RefreshTokenResponse } from './oauth';
|
|
6
7
|
import { StorageKeys } from './storage';
|
|
7
|
-
import {
|
|
8
|
+
import { AuthState, BackendServerState, ClientState, DirectState, InitParams, LogLevel, SerializedDirectState, StateChangeCallback } from './types';
|
|
8
9
|
/**
|
|
9
10
|
* DirectClientBase - Abstract base class for DirectClient implementations
|
|
10
11
|
*
|
|
@@ -84,10 +85,8 @@ export declare abstract class DirectClientBase implements IDirectClient {
|
|
|
84
85
|
* Ensures client is initialized before operations
|
|
85
86
|
*/
|
|
86
87
|
private ensureInitialized;
|
|
87
|
-
sendApiRequest<TReq = void, TRes = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>, authenticated?: boolean): Promise<
|
|
88
|
-
pingApi(): Promise<
|
|
89
|
-
message: string;
|
|
90
|
-
}>>;
|
|
88
|
+
sendApiRequest<TReq = void, TRes = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>, authenticated?: boolean): Promise<ApiResponse<TRes>>;
|
|
89
|
+
pingApi(): Promise<ApiResponse<PingResponse>>;
|
|
91
90
|
/**
|
|
92
91
|
* Get backend server state
|
|
93
92
|
* Calls /bodhi/v1/info and returns structured server state
|
|
@@ -111,8 +110,8 @@ export declare abstract class DirectClientBase implements IDirectClient {
|
|
|
111
110
|
* Debug dump of DirectClient internal state
|
|
112
111
|
*/
|
|
113
112
|
debug(): Promise<Record<string, unknown>>;
|
|
114
|
-
requestAccess(body: CreateAccessRequest): Promise<
|
|
115
|
-
getAccessRequestStatus(requestId: string): Promise<
|
|
113
|
+
requestAccess(body: CreateAccessRequest): Promise<ApiResponse<CreateAccessRequestResponse>>;
|
|
114
|
+
getAccessRequestStatus(requestId: string): Promise<ApiResponse<AccessRequestStatusResponse>>;
|
|
116
115
|
pollAccessRequestStatus(requestId: string, options?: {
|
|
117
116
|
intervalMs?: number;
|
|
118
117
|
timeoutMs?: number;
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BodhiError, BodhiApiError } from '@bodhiapp/bodhi-browser-types';
|
|
2
|
+
import { OpenAiApiError } from '@bodhiapp/ts-client';
|
|
2
3
|
/**
|
|
3
4
|
* Create API error (HTTP 4xx/5xx from server)
|
|
4
|
-
*
|
|
5
|
+
* Extracts Error.message from body.error.message automatically.
|
|
5
6
|
*
|
|
6
|
-
* @param message - Error message
|
|
7
7
|
* @param status - HTTP status code
|
|
8
|
-
* @param body - Error body from server
|
|
8
|
+
* @param body - Error body from server (OpenAI error format)
|
|
9
9
|
* @param headers - Optional response headers
|
|
10
|
-
* @returns
|
|
10
|
+
* @returns BodhiApiError instance
|
|
11
11
|
*/
|
|
12
|
-
export declare const createApiError: (
|
|
12
|
+
export declare const createApiError: (status: number, body: OpenAiApiError, headers?: Record<string, string>) => BodhiApiError;
|
|
13
13
|
/**
|
|
14
14
|
* Create operation error (network/extension level)
|
|
15
15
|
* Thrown when HTTP request couldn't complete
|
|
16
16
|
*
|
|
17
|
+
* @param code - Error code (network_error, timeout_error, etc.)
|
|
17
18
|
* @param message - Error message
|
|
18
|
-
* @
|
|
19
|
-
* @returns OperationError instance
|
|
19
|
+
* @returns BodhiError instance
|
|
20
20
|
*/
|
|
21
|
-
export declare const createOperationError: (
|
|
21
|
+
export declare const createOperationError: (code: string, message: string) => BodhiError;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AccessRequestStatusResponse, CreateAccessRequest, CreateAccessRequestResponse } from '@bodhiapp/ts-client';
|
|
1
|
+
import { AccessRequestStatusResponse, CreateAccessRequest, CreateAccessRequestResponse, PingResponse } from '@bodhiapp/ts-client';
|
|
2
|
+
import { ApiResponse } from '@bodhiapp/bodhi-browser-types';
|
|
2
3
|
import { IConnectionClient, IExtensionClient } from './interface';
|
|
3
4
|
import { Logger } from './logger';
|
|
4
5
|
import { BodhiClientUserPrefsManager } from './storage';
|
|
5
6
|
import { Chat, Models, Embeddings, Toolsets, Mcps } from './openai-client-compat';
|
|
6
|
-
import {
|
|
7
|
+
import { AuthState, BackendServerState, ClientState, ConnectionMode, DirectState, ExtensionState, InitParams, LoginOptions, SerializedClientState, SerializedDirectState, SerializedExtensionState, StateChange, StateChangeCallback } from './types';
|
|
7
8
|
/**
|
|
8
9
|
* Base facade client with common delegation logic
|
|
9
10
|
*
|
|
@@ -99,19 +100,17 @@ export declare abstract class BaseFacadeClient<TConfig, TExtClient extends IExte
|
|
|
99
100
|
isClientInitialized(): boolean;
|
|
100
101
|
isServerReady(): boolean;
|
|
101
102
|
sendExtRequest<TParams = void, TRes = unknown>(action: string, params?: TParams): Promise<TRes>;
|
|
102
|
-
sendApiRequest<TReq = void, TRes = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>, authenticated?: boolean): Promise<
|
|
103
|
+
sendApiRequest<TReq = void, TRes = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>, authenticated?: boolean): Promise<ApiResponse<TRes>>;
|
|
103
104
|
login(options?: LoginOptions): Promise<AuthState>;
|
|
104
105
|
logout(): Promise<AuthState>;
|
|
105
106
|
getAuthState(): Promise<AuthState>;
|
|
106
|
-
requestAccess(body: CreateAccessRequest): Promise<
|
|
107
|
-
getAccessRequestStatus(requestId: string): Promise<
|
|
107
|
+
requestAccess(body: CreateAccessRequest): Promise<ApiResponse<CreateAccessRequestResponse>>;
|
|
108
|
+
getAccessRequestStatus(requestId: string): Promise<ApiResponse<AccessRequestStatusResponse>>;
|
|
108
109
|
pollAccessRequestStatus(requestId: string, options?: {
|
|
109
110
|
intervalMs?: number;
|
|
110
111
|
timeoutMs?: number;
|
|
111
112
|
}): Promise<AccessRequestStatusResponse>;
|
|
112
|
-
pingApi(): Promise<
|
|
113
|
-
message: string;
|
|
114
|
-
}>>;
|
|
113
|
+
pingApi(): Promise<ApiResponse<PingResponse>>;
|
|
115
114
|
getServerState(): Promise<BackendServerState>;
|
|
116
115
|
stream<TReq = unknown, TRes = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>, authenticated?: boolean): AsyncGenerator<TRes>;
|
|
117
116
|
get chat(): Chat;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @bodhiapp/bodhi-js-core - Minimal shared types and interfaces
|
|
3
3
|
*
|
|
4
4
|
* This package contains the minimal shared code between ext and web SDKs:
|
|
5
|
-
* - Types (
|
|
5
|
+
* - Types (ClientState, UserInfo, BodhiError, etc.)
|
|
6
6
|
* - Error factories (createApiError, createOperationError)
|
|
7
7
|
* - Logger (centralized logging)
|
|
8
8
|
* - UIClient interface (base interface)
|
|
@@ -20,5 +20,4 @@ export * from './oauth';
|
|
|
20
20
|
export * from './direct-client-base';
|
|
21
21
|
export * from './facade-client-base';
|
|
22
22
|
export * from './openai-client-compat';
|
|
23
|
-
export { isOperationError, type OperationError } from '@bodhiapp/bodhi-browser-types';
|
|
24
23
|
export { BUILD_MODE as CORE_BUILD_MODE } from './build-info';
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { AccessRequestStatusResponse, CreateAccessRequest, CreateAccessRequestResponse } from '@bodhiapp/ts-client';
|
|
2
|
-
import {
|
|
1
|
+
import { AccessRequestStatusResponse, CreateAccessRequest, CreateAccessRequestResponse, PingResponse } from '@bodhiapp/ts-client';
|
|
2
|
+
import { ApiResponse } from '@bodhiapp/bodhi-browser-types';
|
|
3
|
+
import { AuthState, BackendServerState, ClientState, ConnectionMode, DirectState, ExtensionState, InitParams, LoginOptions, StateChangeCallback } from './types';
|
|
3
4
|
import { Chat, Models, Embeddings, Toolsets, Mcps } from './openai-client-compat';
|
|
4
5
|
/**
|
|
5
6
|
* ConnectionClient - Base interface for all client implementations
|
|
@@ -43,16 +44,16 @@ export interface IConnectionClient<IParams = unknown, SerialState = unknown> {
|
|
|
43
44
|
/**
|
|
44
45
|
* Send API request to local server
|
|
45
46
|
* @param authenticated - If true, injects access token automatically
|
|
46
|
-
* @returns
|
|
47
|
+
* @returns ApiResponse with body and status
|
|
48
|
+
* @throws BodhiError on operational errors (network, timeout, not initialized)
|
|
47
49
|
*/
|
|
48
|
-
sendApiRequest<TReq = void, TRes = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>, authenticated?: boolean): Promise<
|
|
50
|
+
sendApiRequest<TReq = void, TRes = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>, authenticated?: boolean): Promise<ApiResponse<TRes>>;
|
|
49
51
|
/**
|
|
50
52
|
* Ping API endpoint
|
|
51
|
-
* @returns
|
|
53
|
+
* @returns ApiResponse with ping response
|
|
54
|
+
* @throws BodhiError on operational errors
|
|
52
55
|
*/
|
|
53
|
-
pingApi(): Promise<
|
|
54
|
-
message: string;
|
|
55
|
-
}>>;
|
|
56
|
+
pingApi(): Promise<ApiResponse<PingResponse>>;
|
|
56
57
|
/**
|
|
57
58
|
* Get backend server state
|
|
58
59
|
* Calls /bodhi/v1/info and returns structured server state
|
|
@@ -88,13 +89,15 @@ export interface IConnectionClient<IParams = unknown, SerialState = unknown> {
|
|
|
88
89
|
/**
|
|
89
90
|
* Request access for this app (draft → review flow)
|
|
90
91
|
* POST /bodhi/v1/apps/request-access
|
|
92
|
+
* @throws BodhiError on operational errors
|
|
91
93
|
*/
|
|
92
|
-
requestAccess(body: CreateAccessRequest): Promise<
|
|
94
|
+
requestAccess(body: CreateAccessRequest): Promise<ApiResponse<CreateAccessRequestResponse>>;
|
|
93
95
|
/**
|
|
94
96
|
* Get status of an access request
|
|
95
97
|
* GET /bodhi/v1/apps/access-requests/{id}?app_client_id=xxx
|
|
98
|
+
* @throws BodhiError on operational errors
|
|
96
99
|
*/
|
|
97
|
-
getAccessRequestStatus(requestId: string): Promise<
|
|
100
|
+
getAccessRequestStatus(requestId: string): Promise<ApiResponse<AccessRequestStatusResponse>>;
|
|
98
101
|
/**
|
|
99
102
|
* Poll access request until approved/denied/failed/expired
|
|
100
103
|
*/
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { CreateChatCompletionRequest, CreateChatCompletionResponse, CreateChatCompletionStreamResponse, CreateEmbeddingRequest, CreateEmbeddingResponse, Model, ListToolsetsResponse, ListMcpsResponse, McpToolsResponse } from '@bodhiapp/ts-client';
|
|
2
|
-
import {
|
|
2
|
+
import { ApiResponse } from '@bodhiapp/bodhi-browser-types';
|
|
3
3
|
/**
|
|
4
4
|
* Minimal client interface required by resource classes
|
|
5
5
|
*/
|
|
6
6
|
export interface ResourceClient {
|
|
7
|
-
sendApiRequest<TReq = void, TRes = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>, authenticated?: boolean): Promise<
|
|
7
|
+
sendApiRequest<TReq = void, TRes = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>, authenticated?: boolean): Promise<ApiResponse<TRes>>;
|
|
8
8
|
stream<TReq = unknown, TRes = unknown>(method: string, endpoint: string, body?: TReq, headers?: Record<string, string>, authenticated?: boolean): AsyncGenerator<TRes>;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OperationErrorResponse } from '@bodhiapp/bodhi-browser-types';
|
|
2
|
-
import { DeploymentMode } from '@bodhiapp/ts-client';
|
|
2
|
+
import { AppStatus, DeploymentMode } from '@bodhiapp/ts-client';
|
|
3
3
|
/**
|
|
4
4
|
* Serialized direct client state for persistence
|
|
5
5
|
* Stores minimal state needed to restore direct connection
|
|
@@ -32,7 +32,7 @@ export declare const SERVER_ERROR_CODES: {
|
|
|
32
32
|
* All possible server status values
|
|
33
33
|
* Unified across extension and direct modes
|
|
34
34
|
*/
|
|
35
|
-
export type ServerStatus = 'not-connected' | 'pending-extension-ready' | 'ready' | 'setup' | 'resource_admin' | '
|
|
35
|
+
export type ServerStatus = 'not-connected' | 'pending-extension-ready' | 'ready' | 'setup' | 'resource_admin' | 'error' | 'not-reachable';
|
|
36
36
|
/**
|
|
37
37
|
* Backend server state - flat interface with nullable fields
|
|
38
38
|
* Replaces discriminated union of 5 separate interfaces
|
|
@@ -52,14 +52,14 @@ export declare const BACKEND_SERVER_NOT_CONNECTED: BackendServerState;
|
|
|
52
52
|
* Raw response from /bodhi/v1/info endpoint
|
|
53
53
|
*/
|
|
54
54
|
export interface ServerInfoResponse {
|
|
55
|
-
status:
|
|
55
|
+
status: AppStatus | 'error';
|
|
56
56
|
version?: string;
|
|
57
57
|
error?: OperationErrorResponse;
|
|
58
58
|
deployment?: DeploymentMode;
|
|
59
59
|
client_id?: string;
|
|
60
60
|
}
|
|
61
61
|
export declare function isServerReady(state: BackendServerState): boolean;
|
|
62
|
-
export declare function backendServerNotReady(status:
|
|
62
|
+
export declare function backendServerNotReady(status: Exclude<AppStatus, 'ready'> | 'error', version?: string, error?: OperationErrorResponse, deployment?: DeploymentMode, client_id?: string): BackendServerState;
|
|
63
63
|
/**
|
|
64
64
|
* ClientState - Unified state for extension or direct connectivity
|
|
65
65
|
* Discriminated union with type field: 'extension' | 'direct'
|
package/dist/types/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@bodhiapp/bodhi-browser-types"),A=(e,r,t)=>{const n=r?.error?.message||`HTTP ${e}`;return new i.BodhiApiError(e,r,n,t)},y=(e,r)=>new i.BodhiError(e,r),o={NOT_REACHABLE:{message:"server is not reachable on given url",type:"network_error"},SERVER_NOT_READY:{message:"server is not in ready state, configure to complete setup",type:"extension_error"}},a={status:"not-reachable",version:null,error:o.NOT_REACHABLE},s={status:"pending-extension-ready",version:null,error:null},c={status:"not-connected",version:null,error:null};function u(e){return e.status==="ready"}function I(e,r="unknown",t=o.SERVER_NOT_READY,n,_){return{status:e,version:r,error:t,deployment:n??null,client_id:_??null}}function E(e){return e.type==="extension"}function d(e){return e.type==="direct"}function p(e){return typeof e.server=="object"&&e.server.status!=="not-connected"&&u(e.server)}function l(e){return e.url!==null}const O={type:"direct",url:null,server:c};function v(e,r="unknown"){return{type:"direct",server:{status:"ready",version:r,error:null},url:e}}function D(e){return{type:"direct",server:a,url:e}}function f(e,r){return{type:"direct",server:r,url:e}}const N={type:"extension",extension:"not-initialized",extensionId:null,server:s},R={type:"extension",extension:"not-found",extensionId:null,server:s};function C(e){return e.extension==="ready"&&e.server.status!=="pending-extension-ready"&&u(e.server)}function T(e){return e.extension==="ready"}function x(){return N}function b(){return R}function h(e){return E(e)?T(e):l(e)}function g(e){return e.server}function B(e){return E(e)?e.extensionId??void 0:void 0}function L(e){return d(e)?e.url??void 0:void 0}function k(e){return e.status==="authenticated"}function P(e){return e.status==="loading"}function w(e){return e.status==="error"}const V={status:"idle",user:null,accessToken:null,error:null},m=()=>{};function H(e,r){return{kind:"event",type:e,payload:r}}function S(e,r,t){return{kind:"response",type:r,requestId:e,payload:t}}function K(e,r){return{kind:"error",requestId:e,error:r}}function U(e,r){const t=r[e.type];if(!t)return null;const n=t(e.payload);return S(e.requestId,e.type,n)}Object.defineProperty(exports,"BodhiApiError",{enumerable:!0,get:()=>i.BodhiApiError});Object.defineProperty(exports,"BodhiError",{enumerable:!0,get:()=>i.BodhiError});Object.defineProperty(exports,"unwrapResponse",{enumerable:!0,get:()=>i.unwrapResponse});exports.BACKEND_SERVER_NOT_CONNECTED=c;exports.BACKEND_SERVER_NOT_REACHABLE=a;exports.DIRECT_STATE_NOT_INITIALIZED=O;exports.EXTENSION_STATE_NOT_FOUND=R;exports.EXTENSION_STATE_NOT_INITIALIZED=N;exports.INITIAL_AUTH_STATE=V;exports.NOOP_STATE_CALLBACK=m;exports.PENDING_EXTENSION_READY=s;exports.SERVER_ERROR_CODES=o;exports.backendServerNotReady=I;exports.buildError=K;exports.buildEvent=H;exports.buildResponse=S;exports.createApiError=A;exports.createDirectStateNotReachable=D;exports.createDirectStateNotReady=f;exports.createDirectStateReady=v;exports.createExtensionStateNotFound=b;exports.createExtensionStateNotInitialized=x;exports.createOperationError=y;exports.getBackendServerState=g;exports.getExtensionId=B;exports.getServerUrl=L;exports.handleRequest=U;exports.isAuthError=w;exports.isAuthLoading=P;exports.isAuthenticated=k;exports.isClientReady=h;exports.isDirectClientReady=l;exports.isDirectServerReady=p;exports.isDirectState=d;exports.isExtensionClientReady=T;exports.isExtensionServerReady=C;exports.isExtensionState=E;exports.isServerReady=u;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { FlowType, RequestedResources, UserScope } from '@bodhiapp/ts-client';
|
|
|
2
2
|
/**
|
|
3
3
|
* Shared types used by both ext2ext and web2ext clients
|
|
4
4
|
*/
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
5
|
+
export { BodhiError, BodhiApiError, unwrapResponse } from '@bodhiapp/bodhi-browser-types';
|
|
6
|
+
export type { BodhiErrorCode } from '@bodhiapp/bodhi-browser-types';
|
|
7
7
|
export { createApiError, createOperationError } from '../errors';
|
|
8
8
|
export { BACKEND_SERVER_NOT_CONNECTED, BACKEND_SERVER_NOT_REACHABLE, backendServerNotReady, createDirectStateNotReachable, createDirectStateNotReady, createDirectStateReady, createExtensionStateNotFound, createExtensionStateNotInitialized, DIRECT_STATE_NOT_INITIALIZED, EXTENSION_STATE_NOT_FOUND, EXTENSION_STATE_NOT_INITIALIZED, getBackendServerState, getExtensionId, getServerUrl, isClientReady, isDirectClientReady, isDirectServerReady, isDirectState, isExtensionClientReady, isExtensionServerReady, isExtensionState, isServerReady, PENDING_EXTENSION_READY, SERVER_ERROR_CODES, } from './client-state';
|
|
9
9
|
export type { BackendServerState, ClientState, ConnectionMode, DirectState, ExtensionState, InitParams, SerializedClientState, SerializedDirectState, SerializedExtensionState, ServerInfoResponse, ServerStatus, } from './client-state';
|
package/dist/types/index.esm.js
CHANGED
|
@@ -1,41 +1,171 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BodhiApiError as d, BodhiError as a } from "@bodhiapp/bodhi-browser-types";
|
|
2
|
+
import { BodhiApiError as F, BodhiError as Z, unwrapResponse as j } from "@bodhiapp/bodhi-browser-types";
|
|
3
|
+
const v = (e, n, r) => {
|
|
4
|
+
const t = n?.error?.message || `HTTP ${e}`;
|
|
5
|
+
return new d(e, n, t, r);
|
|
6
|
+
}, A = (e, n) => new a(e, n), o = {
|
|
7
|
+
NOT_REACHABLE: {
|
|
8
|
+
message: "server is not reachable on given url",
|
|
9
|
+
type: "network_error"
|
|
10
|
+
},
|
|
11
|
+
SERVER_NOT_READY: {
|
|
12
|
+
message: "server is not in ready state, configure to complete setup",
|
|
13
|
+
type: "extension_error"
|
|
14
|
+
}
|
|
15
|
+
}, l = {
|
|
16
|
+
status: "not-reachable",
|
|
17
|
+
version: null,
|
|
18
|
+
error: o.NOT_REACHABLE
|
|
19
|
+
}, i = {
|
|
20
|
+
status: "pending-extension-ready",
|
|
21
|
+
version: null,
|
|
22
|
+
error: null
|
|
23
|
+
}, E = {
|
|
24
|
+
status: "not-connected",
|
|
25
|
+
version: null,
|
|
26
|
+
error: null
|
|
27
|
+
};
|
|
28
|
+
function u(e) {
|
|
29
|
+
return e.status === "ready";
|
|
30
|
+
}
|
|
31
|
+
function S(e, n = "unknown", r = o.SERVER_NOT_READY, t, c) {
|
|
32
|
+
return {
|
|
33
|
+
status: e,
|
|
34
|
+
version: n,
|
|
35
|
+
error: r,
|
|
36
|
+
deployment: t ?? null,
|
|
37
|
+
client_id: c ?? null
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function s(e) {
|
|
41
|
+
return e.type === "extension";
|
|
42
|
+
}
|
|
43
|
+
function R(e) {
|
|
44
|
+
return e.type === "direct";
|
|
45
|
+
}
|
|
46
|
+
function I(e) {
|
|
47
|
+
return typeof e.server == "object" && e.server.status !== "not-connected" && u(e.server);
|
|
48
|
+
}
|
|
49
|
+
function _(e) {
|
|
50
|
+
return e.url !== null;
|
|
51
|
+
}
|
|
52
|
+
const x = {
|
|
53
|
+
type: "direct",
|
|
54
|
+
url: null,
|
|
55
|
+
server: E
|
|
56
|
+
};
|
|
57
|
+
function O(e, n = "unknown") {
|
|
58
|
+
return { type: "direct", server: { status: "ready", version: n, error: null }, url: e };
|
|
59
|
+
}
|
|
60
|
+
function D(e) {
|
|
61
|
+
return { type: "direct", server: l, url: e };
|
|
62
|
+
}
|
|
63
|
+
function C(e, n) {
|
|
64
|
+
return { type: "direct", server: n, url: e };
|
|
65
|
+
}
|
|
66
|
+
const p = {
|
|
67
|
+
type: "extension",
|
|
68
|
+
extension: "not-initialized",
|
|
69
|
+
extensionId: null,
|
|
70
|
+
server: i
|
|
71
|
+
}, N = {
|
|
72
|
+
type: "extension",
|
|
73
|
+
extension: "not-found",
|
|
74
|
+
extensionId: null,
|
|
75
|
+
server: i
|
|
76
|
+
};
|
|
77
|
+
function h(e) {
|
|
78
|
+
return e.extension === "ready" && e.server.status !== "pending-extension-ready" && u(e.server);
|
|
79
|
+
}
|
|
80
|
+
function T(e) {
|
|
81
|
+
return e.extension === "ready";
|
|
82
|
+
}
|
|
83
|
+
function B() {
|
|
84
|
+
return p;
|
|
85
|
+
}
|
|
86
|
+
function g() {
|
|
87
|
+
return N;
|
|
88
|
+
}
|
|
89
|
+
function k(e) {
|
|
90
|
+
return s(e) ? T(e) : _(e);
|
|
91
|
+
}
|
|
92
|
+
function L(e) {
|
|
93
|
+
return e.server;
|
|
94
|
+
}
|
|
95
|
+
function b(e) {
|
|
96
|
+
return s(e) ? e.extensionId ?? void 0 : void 0;
|
|
97
|
+
}
|
|
98
|
+
function m(e) {
|
|
99
|
+
return R(e) ? e.url ?? void 0 : void 0;
|
|
100
|
+
}
|
|
101
|
+
function w(e) {
|
|
102
|
+
return e.status === "authenticated";
|
|
103
|
+
}
|
|
104
|
+
function H(e) {
|
|
105
|
+
return e.status === "loading";
|
|
106
|
+
}
|
|
107
|
+
function V(e) {
|
|
108
|
+
return e.status === "error";
|
|
109
|
+
}
|
|
110
|
+
const K = {
|
|
111
|
+
status: "idle",
|
|
112
|
+
user: null,
|
|
113
|
+
accessToken: null,
|
|
114
|
+
error: null
|
|
115
|
+
}, P = () => {
|
|
116
|
+
};
|
|
117
|
+
function U(e, n) {
|
|
118
|
+
return { kind: "event", type: e, payload: n };
|
|
119
|
+
}
|
|
120
|
+
function f(e, n, r) {
|
|
121
|
+
return { kind: "response", type: n, requestId: e, payload: r };
|
|
122
|
+
}
|
|
123
|
+
function X(e, n) {
|
|
124
|
+
return { kind: "error", requestId: e, error: n };
|
|
125
|
+
}
|
|
126
|
+
function Y(e, n) {
|
|
127
|
+
const r = n[e.type];
|
|
128
|
+
if (!r) return null;
|
|
129
|
+
const t = r(e.payload);
|
|
130
|
+
return f(e.requestId, e.type, t);
|
|
131
|
+
}
|
|
2
132
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
N as
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
D as
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
g as isAuthenticated,
|
|
133
|
+
E as BACKEND_SERVER_NOT_CONNECTED,
|
|
134
|
+
l as BACKEND_SERVER_NOT_REACHABLE,
|
|
135
|
+
F as BodhiApiError,
|
|
136
|
+
Z as BodhiError,
|
|
137
|
+
x as DIRECT_STATE_NOT_INITIALIZED,
|
|
138
|
+
N as EXTENSION_STATE_NOT_FOUND,
|
|
139
|
+
p as EXTENSION_STATE_NOT_INITIALIZED,
|
|
140
|
+
K as INITIAL_AUTH_STATE,
|
|
141
|
+
P as NOOP_STATE_CALLBACK,
|
|
142
|
+
i as PENDING_EXTENSION_READY,
|
|
143
|
+
o as SERVER_ERROR_CODES,
|
|
144
|
+
S as backendServerNotReady,
|
|
145
|
+
X as buildError,
|
|
146
|
+
U as buildEvent,
|
|
147
|
+
f as buildResponse,
|
|
148
|
+
v as createApiError,
|
|
149
|
+
D as createDirectStateNotReachable,
|
|
150
|
+
C as createDirectStateNotReady,
|
|
151
|
+
O as createDirectStateReady,
|
|
152
|
+
g as createExtensionStateNotFound,
|
|
153
|
+
B as createExtensionStateNotInitialized,
|
|
154
|
+
A as createOperationError,
|
|
155
|
+
L as getBackendServerState,
|
|
156
|
+
b as getExtensionId,
|
|
157
|
+
m as getServerUrl,
|
|
158
|
+
Y as handleRequest,
|
|
159
|
+
V as isAuthError,
|
|
160
|
+
H as isAuthLoading,
|
|
161
|
+
w as isAuthenticated,
|
|
33
162
|
k as isClientReady,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
163
|
+
_ as isDirectClientReady,
|
|
164
|
+
I as isDirectServerReady,
|
|
165
|
+
R as isDirectState,
|
|
166
|
+
T as isExtensionClientReady,
|
|
167
|
+
h as isExtensionServerReady,
|
|
168
|
+
s as isExtensionState,
|
|
169
|
+
u as isServerReady,
|
|
170
|
+
j as unwrapResponse
|
|
41
171
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bodhiapp/bodhi-js-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"description": "Core types and interfaces for Bodhi Browser SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/bodhi-core.cjs.js",
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"typecheck": "tsc --noEmit"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@bodhiapp/bodhi-browser-types": "0.0.
|
|
60
|
-
"@bodhiapp/setup-modal-types": "0.0.
|
|
61
|
-
"@bodhiapp/ts-client": "0.1.
|
|
59
|
+
"@bodhiapp/bodhi-browser-types": "0.0.28",
|
|
60
|
+
"@bodhiapp/setup-modal-types": "0.0.28",
|
|
61
|
+
"@bodhiapp/ts-client": "0.1.23",
|
|
62
62
|
"ua-parser-js": "^1.0.40"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const E=require("@bodhiapp/bodhi-browser-types");function T(e){return e!==null&&typeof e=="object"&&"error"in e&&!("body"in e)&&E.isOperationErrorStructure(e.error)}function y(e){return"body"in e&&"status"in e&&typeof e.status=="number"&&e.status>=200&&e.status<300}function p(e){return"body"in e&&"status"in e&&typeof e.status=="number"&&e.status>=400&&E.isOpenAiApiErrorBody(e.body)}const I=(e,t,r,n)=>{const i=new Error(e);return i.response={status:t,body:r,headers:n},i},O=(e,t)=>{const r=new Error(e);return r.error={message:e,type:t},r},o={NOT_REACHABLE:{message:"server is not reachable on given url",type:"network_error"},SERVER_NOT_READY:{message:"server is not in ready state, configure to complete setup",type:"extension_error"}},a={status:"not-reachable",version:null,error:o.NOT_REACHABLE},s={status:"pending-extension-ready",version:null,error:null},d={status:"not-connected",version:null,error:null};function u(e){return e.status==="ready"}function v(e,t="unknown",r=o.SERVER_NOT_READY,n,i){return{status:e,version:t,error:r,deployment:n??null,client_id:i??null}}function c(e){return e.type==="extension"}function l(e){return e.type==="direct"}function f(e){return typeof e.server=="object"&&e.server.status!=="not-connected"&&u(e.server)}function R(e){return e.url!==null}const D={type:"direct",url:null,server:d};function C(e,t="unknown"){return{type:"direct",server:{status:"ready",version:t,error:null},url:e}}function x(e){return{type:"direct",server:a,url:e}}function b(e,t){return{type:"direct",server:t,url:e}}const N={type:"extension",extension:"not-initialized",extensionId:null,server:s},S={type:"extension",extension:"not-found",extensionId:null,server:s};function L(e){return e.extension==="ready"&&e.server.status!=="pending-extension-ready"&&u(e.server)}function _(e){return e.extension==="ready"}function h(){return N}function B(){return S}function g(e){return c(e)?_(e):R(e)}function k(e){return e.server}function V(e){return c(e)?e.extensionId??void 0:void 0}function w(e){return l(e)?e.url??void 0:void 0}function H(e){return e.status==="authenticated"}function K(e){return e.status==="loading"}function U(e){return e.status==="error"}const X={status:"idle",user:null,accessToken:null,error:null},q=()=>{};function F(e,t){return{kind:"event",type:e,payload:t}}function A(e,t,r){return{kind:"response",type:t,requestId:e,payload:r}}function P(e,t){return{kind:"error",requestId:e,error:t}}function Y(e,t){const r=t[e.type];if(!r)return null;const n=r(e.payload);return A(e.requestId,e.type,n)}exports.BACKEND_SERVER_NOT_CONNECTED=d;exports.BACKEND_SERVER_NOT_REACHABLE=a;exports.DIRECT_STATE_NOT_INITIALIZED=D;exports.EXTENSION_STATE_NOT_FOUND=S;exports.EXTENSION_STATE_NOT_INITIALIZED=N;exports.INITIAL_AUTH_STATE=X;exports.NOOP_STATE_CALLBACK=q;exports.PENDING_EXTENSION_READY=s;exports.SERVER_ERROR_CODES=o;exports.backendServerNotReady=v;exports.buildError=P;exports.buildEvent=F;exports.buildResponse=A;exports.createApiError=I;exports.createDirectStateNotReachable=x;exports.createDirectStateNotReady=b;exports.createDirectStateReady=C;exports.createExtensionStateNotFound=B;exports.createExtensionStateNotInitialized=h;exports.createOperationError=O;exports.getBackendServerState=k;exports.getExtensionId=V;exports.getServerUrl=w;exports.handleRequest=Y;exports.isApiResultError=p;exports.isApiResultOperationError=T;exports.isApiResultSuccess=y;exports.isAuthError=U;exports.isAuthLoading=K;exports.isAuthenticated=H;exports.isClientReady=g;exports.isDirectClientReady=R;exports.isDirectServerReady=f;exports.isDirectState=l;exports.isExtensionClientReady=_;exports.isExtensionServerReady=L;exports.isExtensionState=c;exports.isServerReady=u;
|