@superfaceai/one-sdk
Advanced tools
Comparing version 3.0.0-beta.3 to 3.0.0-beta.4
@@ -56,3 +56,3 @@ import { AppContext, FileSystem, Network, TextCoder, Timers, WasiContext, Persistence } from './interfaces.js'; | ||
/** | ||
* @throws {PerformError | UnexpectedError} | ||
* @throws {PerformError | ValidationError | UnexpectedError} | ||
*/ | ||
@@ -59,0 +59,0 @@ perform(profileUrl: string, providerUrl: string, mapUrl: string, usecase: string, input: unknown, parameters: Record<string, string>, security: SecurityValuesMap): Promise<unknown>; |
import { Asyncify } from './asyncify.js'; | ||
import { HandleMap } from './handle_map.js'; | ||
import { PerformError, UnexpectedError, UninitializedError, WasiErrno, WasiError } from './error.js'; | ||
import { PerformError, UnexpectedError, UninitializedError, ValidationError, WasiErrno, WasiError } from './error.js'; | ||
import * as sf_host from './sf_host.js'; | ||
@@ -157,3 +157,3 @@ class ReadableStreamAdapter { | ||
/** | ||
* @throws {PerformError | UnexpectedError} | ||
* @throws {PerformError | ValidationError | UnexpectedError} | ||
*/ | ||
@@ -177,3 +177,3 @@ async perform(profileUrl, providerUrl, mapUrl, usecase, input, parameters, security) { | ||
async handleMessage(message) { | ||
switch (message['kind']) { | ||
switch (message.kind) { | ||
case 'perform-input': | ||
@@ -197,3 +197,8 @@ return { | ||
case 'perform-output-exception': | ||
this.performState.exception = new UnexpectedError(message.exception.error_code, message.exception.message); | ||
if (message.exception.error_code === "InputValidationError") { | ||
this.performState.exception = new ValidationError(message.exception.message); | ||
} | ||
else { | ||
this.performState.exception = new UnexpectedError(message.exception.error_code, message.exception.message); | ||
} | ||
return { kind: 'ok' }; | ||
@@ -200,0 +205,0 @@ case 'file-open': { |
@@ -6,3 +6,3 @@ import { jest } from '@jest/globals'; | ||
import { App } from './app.js'; | ||
import { UnexpectedError } from './error.js'; | ||
import { UnexpectedError, ValidationError } from './error.js'; | ||
class TestNetwork { | ||
@@ -62,3 +62,3 @@ fetch(input, init) { | ||
await app.loadCore(await readFile(createRequire(import.meta.url).resolve('../../assets/test-core-async.wasm'))); | ||
await app.init(new WASI()); | ||
await app.init(new WASI({ version: 'preview1' })); | ||
handleMessage = jest.spyOn(app, 'handleMessage'); | ||
@@ -98,7 +98,11 @@ handleMessage.mockImplementation(async (message) => { | ||
catch (e) { } | ||
await app.init(new WASI()); | ||
await app.init(new WASI({ version: 'preview1' })); | ||
const result = await app.perform('', '', '', 'CORE_PERFORM_TRUE', null, {}, {}); | ||
expect(result).toBe(true); | ||
}); | ||
test('invalid user input', async () => { | ||
handleMessage.mockRestore(); | ||
await expect(app.perform('', '', '', 'CORE_PERFORM_INPUT_VALIDATION_ERROR', null, {}, {})).rejects.toThrowError(ValidationError); | ||
}); | ||
}); | ||
//# sourceMappingURL=app.test.js.map |
@@ -8,2 +8,5 @@ export declare abstract class BaseError extends Error { | ||
} | ||
export declare class ValidationError extends BaseError { | ||
constructor(message: string); | ||
} | ||
export declare class UnexpectedError extends BaseError { | ||
@@ -10,0 +13,0 @@ constructor(name: string, message: string); |
@@ -13,2 +13,7 @@ export class BaseError extends Error { | ||
} | ||
export class ValidationError extends BaseError { | ||
constructor(message) { | ||
super(ValidationError.name, message); | ||
} | ||
} | ||
export class UnexpectedError extends BaseError { | ||
@@ -15,0 +20,0 @@ constructor(name, message) { |
import { SecurityValuesMap } from '../common/index.js'; | ||
export { PerformError, UnexpectedError } from '../common/index.js'; | ||
export { PerformError, UnexpectedError, ValidationError } from '../common/index.js'; | ||
export type ClientOptions = { | ||
@@ -4,0 +4,0 @@ /** |
@@ -8,3 +8,3 @@ import fs from 'node:fs/promises'; | ||
import { fetchErrorToHostError, systemErrorToWasiError } from './error.js'; | ||
export { PerformError, UnexpectedError } from '../common/index.js'; | ||
export { PerformError, UnexpectedError, ValidationError } from '../common/index.js'; | ||
const CORE_PATH = process.env.CORE_PATH ?? createRequire(import.meta.url).resolve('../assets/core-async.wasm'); | ||
@@ -11,0 +11,0 @@ const ASSETS_FOLDER = 'superface'; |
{ | ||
"name": "@superfaceai/one-sdk", | ||
"version": "3.0.0-beta.3", | ||
"main": "node/index.js", | ||
"version": "3.0.0-beta.4", | ||
"exports": { | ||
"./node": "./node/index.js", | ||
"./node/index.js": "./node/index.js", | ||
"./cloudflare": "./cloudflare/index.js", | ||
"./cloudflare/index.js": "./cloudflare/index.js" | ||
}, | ||
"type": "module", | ||
@@ -6,0 +11,0 @@ "license": "MIT", |
@@ -81,2 +81,3 @@ [Website](https://superface.ai) | [Get Started](https://superface.ai/docs/getting-started) | [Documentation](https://superface.ai/docs) | [GitHub Discussions](https://sfc.is/discussions) | [Twitter](https://twitter.com/superfaceai) | [Support](https://superface.ai/support) | ||
UnexpectedError, | ||
ValidationError, | ||
} from '@superfaceai/one-sdk/node'; | ||
@@ -107,5 +108,9 @@ | ||
); | ||
console.log('RESULT:', result); | ||
} catch (e) { | ||
if (e instanceof PerformError) { | ||
console.log('ERROR RESULT:', e.errorResult); | ||
} else if (e instanceof ValidationError) { | ||
console.error('VALIDATION ERROR:', e.message); | ||
} else if (e instanceof UnexpectedError) { | ||
@@ -112,0 +117,0 @@ console.error('ERROR:', e); |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4701667
1916
220