Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@openctx/client

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@openctx/client - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

6

dist/client/client.d.ts

@@ -6,3 +6,3 @@ import type { AnnotationsParams, ItemsParams, ItemsResult, MentionsParams, MentionsResult, MetaParams, MetaResult } from '@openctx/protocol';

import { type Annotation, type EachWithProviderUri, type ObservableProviderClient } from '../api.js';
import { type ConfigurationUserInput } from '../configuration.js';
import { type ConfigurationUserInput, type ImportedProviderConfiguration } from '../configuration.js';
import type { Logger } from '../logger.js';

@@ -33,2 +33,6 @@ /**

/**
* The list of providers already resolved and imported.
*/
providers?: ImportedProviderConfiguration[];
/**
* The authentication info for the provider.

@@ -35,0 +39,0 @@ *

14

dist/client/client.js
import { LRUCache } from 'lru-cache';
import { catchError, combineLatest, distinctUntilChanged, firstValueFrom, from, map, mergeMap, of, shareReplay, } from 'rxjs';
import { observeAnnotations, observeItems, observeMentions, observeMeta, } from '../api.js';
import { configurationFromUserInput } from '../configuration.js';
import { configurationFromUserInput, } from '../configuration.js';
import { createProviderClient } from '../providerClient/createProviderClient.js';

@@ -26,4 +26,4 @@ /**

};
function providerClientsWithSettings(...args) {
return from(env.configuration(...args))
function providerClientsWithSettings(resource) {
return from(env.configuration(resource))
.pipe(map(config => {

@@ -33,3 +33,3 @@ if (!config.enable) {

}
return configurationFromUserInput(config);
return configurationFromUserInput(config, env.providers);
}))

@@ -45,3 +45,3 @@ .pipe(mergeMap(configuration => configuration.providers.length > 0

importProvider: env.importProvider,
}),
}, env.providers?.find(provider => provider.providerUri === providerUri)?.provider),
settings,

@@ -121,3 +121,3 @@ })), catchError(error => {

return {
getOrCreate(key, env) {
getOrCreate(key, env, provider) {
const existing = cache.get(cacheKey(key));

@@ -132,3 +132,3 @@ if (existing) {

importProvider: env.importProvider,
});
}, provider);
cache.set(cacheKey(key), c);

@@ -135,0 +135,0 @@ return c;

import type { ProviderSettings } from '@openctx/protocol';
import type { Provider } from '@openctx/provider';
/**

@@ -26,6 +27,11 @@ * Raw configuration set by the user in the client application. Use

}
export interface ImportedProviderConfiguration {
providerUri: string;
settings: boolean | ProviderSettings;
provider: Provider;
}
/**
* Apply defaults to and normalize the raw {@link ConfigurationUserInput}.
*/
export declare function configurationFromUserInput(raw: ConfigurationUserInput): Configuration;
export declare function configurationFromUserInput(raw: ConfigurationUserInput, providers?: ImportedProviderConfiguration[]): Configuration;
//# sourceMappingURL=configuration.d.ts.map
/**
* Apply defaults to and normalize the raw {@link ConfigurationUserInput}.
*/
export function configurationFromUserInput(raw) {
export function configurationFromUserInput(raw, providers = []) {
return {
enable: raw.enable ?? true,
debug: raw.debug ?? false,
providers: providersFromUserInput(raw.providers),
providers: [
...providersFromUserInput(raw.providers),
...providers.map(({ providerUri, settings }) => ({
providerUri,
settings: typeof settings === 'boolean' ? {} : settings,
})),
],
};

@@ -10,0 +16,0 @@ }

import type { AnnotationsParams, AnnotationsResult, ItemsParams, ItemsResult, MentionsParams, MentionsResult, MetaResult, ProviderSettings } from '@openctx/protocol';
import type { Provider } from '@openctx/provider';
import { type ProviderTransportOptions } from './transport/createTransport.js';

@@ -26,3 +27,3 @@ /**

*/
export declare function createProviderClient(providerUri: string, { logger, ...options }?: ProviderClientOptions): ProviderClient;
export declare function createProviderClient(providerUri: string, { logger, ...options }?: ProviderClientOptions, provider?: Provider): ProviderClient;
//# sourceMappingURL=createProviderClient.d.ts.map

@@ -7,5 +7,5 @@ import { scopedLogger } from '../logger.js';

*/
export function createProviderClient(providerUri, { logger, ...options } = {}) {
export function createProviderClient(providerUri, { logger, ...options } = {}, provider) {
logger = scopedLogger(logger, `providerClient(${providerUri})`);
const transport = createTransport(providerUri, { ...options, cache: true, logger });
const transport = provider || createTransport(providerUri, { ...options, cache: true, logger });
return {

@@ -23,3 +23,3 @@ async meta(params, settings) {

try {
return await transport.mentions(params, settings);
return (await transport.mentions?.(params, settings)) || null;
}

@@ -33,3 +33,3 @@ catch (error) {

try {
return await transport.items(params, settings);
return (await transport.items?.(params, settings)) || null;
}

@@ -59,3 +59,3 @@ catch (error) {

try {
return await transport.annotations(params, settings);
return (await transport.annotations?.(params, settings)) || null;
}

@@ -62,0 +62,0 @@ catch (error) {

{
"name": "@openctx/client",
"version": "0.0.12",
"version": "0.0.13",
"description": "OpenCtx client library",

@@ -21,9 +21,14 @@ "license": "Apache-2.0",

"sideEffects": false,
"scripts": {
"build": "tsc --build",
"test": "vitest",
"prepublishOnly": "tsc --build --clean && pnpm run build"
},
"dependencies": {
"@openctx/protocol": "workspace:*",
"@openctx/provider": "workspace:*",
"@openctx/schema": "workspace:*",
"lru-cache": "^10.1.0",
"picomatch": "^3.0.1",
"rxjs": "^7.8.1",
"@openctx/provider": "0.0.11",
"@openctx/protocol": "0.0.11",
"@openctx/schema": "0.0.10"
"rxjs": "^7.8.1"
},

@@ -33,7 +38,3 @@ "devDependencies": {

"vitest-fetch-mock": "^0.2.2"
},
"scripts": {
"build": "tsc --build",
"test": "vitest"
}
}
}

@@ -38,3 +38,7 @@ import type {

} from '../api.js'
import { type ConfigurationUserInput, configurationFromUserInput } from '../configuration.js'
import {
type ConfigurationUserInput,
type ImportedProviderConfiguration,
configurationFromUserInput,
} from '../configuration.js'
import type { Logger } from '../logger.js'

@@ -69,2 +73,7 @@ import { type ProviderClient, createProviderClient } from '../providerClient/createProviderClient.js'

/**
* The list of providers already resolved and imported.
*/
providers?: ImportedProviderConfiguration[]
/**
* The authentication info for the provider.

@@ -232,6 +241,4 @@ *

function providerClientsWithSettings(
...args: Parameters<typeof env.configuration>
): Observable<ProviderClientWithSettings[]> {
return from(env.configuration(...args))
function providerClientsWithSettings(resource?: string): Observable<ProviderClientWithSettings[]> {
return from(env.configuration(resource))
.pipe(

@@ -242,3 +249,3 @@ map(config => {

}
return configurationFromUserInput(config)
return configurationFromUserInput(config, env.providers)
})

@@ -262,3 +269,7 @@ )

importProvider: env.importProvider,
}
},
env.providers?.find(
provider =>
provider.providerUri === providerUri
)?.provider
),

@@ -402,3 +413,4 @@ settings,

key: ProviderCacheKey,
env: Pick<ClientEnv<any>, 'providerBaseUri' | 'logger' | 'importProvider'>
env: Pick<ClientEnv<any>, 'providerBaseUri' | 'logger' | 'importProvider'>,
provider?: Provider
) => ProviderClient

@@ -417,3 +429,3 @@ } {

return {
getOrCreate(key, env) {
getOrCreate(key, env, provider) {
const existing = cache.get(cacheKey(key))

@@ -424,8 +436,12 @@ if (existing) {

const c = createProviderClient(key.providerUri, {
providerBaseUri: env.providerBaseUri,
authInfo: key.authInfo,
logger: env.logger,
importProvider: env.importProvider,
})
const c = createProviderClient(
key.providerUri,
{
providerBaseUri: env.providerBaseUri,
authInfo: key.authInfo,
logger: env.logger,
importProvider: env.importProvider,
},
provider
)
cache.set(cacheKey(key), c)

@@ -432,0 +448,0 @@ return c

import type { ProviderSettings } from '@openctx/protocol'
import type { Provider } from '@openctx/provider'

@@ -25,10 +26,24 @@ /**

export interface ImportedProviderConfiguration {
providerUri: string
settings: boolean | ProviderSettings
provider: Provider
}
/**
* Apply defaults to and normalize the raw {@link ConfigurationUserInput}.
*/
export function configurationFromUserInput(raw: ConfigurationUserInput): Configuration {
export function configurationFromUserInput(
raw: ConfigurationUserInput,
providers: ImportedProviderConfiguration[] = []
): Configuration {
return {
enable: raw.enable ?? true,
debug: raw.debug ?? false,
providers: providersFromUserInput(raw.providers),
providers: [
...providersFromUserInput(raw.providers),
...providers.map(({ providerUri, settings }) => ({
providerUri,
settings: typeof settings === 'boolean' ? {} : settings,
})),
],
}

@@ -35,0 +50,0 @@ }

@@ -12,2 +12,3 @@ import type {

} from '@openctx/protocol'
import type { Provider } from '@openctx/provider'
import { scopedLogger } from '../logger.js'

@@ -50,7 +51,8 @@ import { matchSelectors } from './selector.js'

providerUri: string,
{ logger, ...options }: ProviderClientOptions = {}
{ logger, ...options }: ProviderClientOptions = {},
provider?: Provider
): ProviderClient {
logger = scopedLogger(logger, `providerClient(${providerUri})`)
const transport = createTransport(providerUri, { ...options, cache: true, logger })
const transport = provider || createTransport(providerUri, { ...options, cache: true, logger })

@@ -71,3 +73,3 @@ return {

try {
return await transport.mentions(params, settings)
return (await transport.mentions?.(params, settings)) || null
} catch (error) {

@@ -80,3 +82,3 @@ logger?.(`failed to get mentions: ${error}`)

try {
return await transport.items(params, settings)
return (await transport.items?.(params, settings)) || null
} catch (error) {

@@ -112,3 +114,3 @@ logger?.(`failed to get items: ${error}`)

try {
return await transport.annotations(params, settings)
return (await transport.annotations?.(params, settings)) || null
} catch (error) {

@@ -115,0 +117,0 @@ logger?.(`failed to get annotations: ${error}`)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc