UNPKG

@nextplus/js-sdk

Version:

A TypeScript SDK for interacting with the NextPlus API, automatically generated from OpenAPI specifications.

84 lines (72 loc) 2.31 kB
import { configure } from './index'; async function main() { console.log('=== Testing with email and returnType: data ==='); const sdk = configure({ baseURL: 'http://127.0.0.1:3000/api', email: 'operator@operator.com', password: 'operator@operator.com', returnType: 'data', // Only return data, not full response }); console.log('SDK configured (email)'); // Test with returnType: 'data' - should return only the data array const tables = await sdk.TableService.find({ query: { filter: JSON.stringify({ language: 'he', limit: 10, order: 'created DESC', fields: { id: true, name: true, created: true }, where: { name: 'no-such-table!' } }) } }); console.log( 'Tables found (data only):', Array.isArray(tables) ? `Array with ${tables.length} items` : tables, ); // Test validation error handling try { const newTable = await sdk.TableService.create({ body: {} } as any); console.log('New table created:', newTable); } catch (error: any) { console.log('Expected validation error caught:', error.message); } console.log('\n=== Testing with username and returnType: raw ==='); const sdk2 = configure({ baseURL: 'http://127.0.0.1:3000/api', username: 'operator', // Using username instead of email password: 'operator@operator.com', returnType: 'raw', // Return full response object }); console.log('SDK configured (username)'); // Test with returnType: 'raw' - should return { data, request, response } const tablesRaw = await sdk2.TableService.find({ query: { filter: JSON.stringify({ where: { name: 'test' }, limit: 5 }) } }); console.log('Tables found (raw response):', { hasData: 'data' in tablesRaw, hasRequest: 'request' in tablesRaw, hasResponse: 'response' in tablesRaw, dataLength: tablesRaw.data ? tablesRaw.data.length : 'no data', }); try { const createTable = await sdk2.TableService.create({ body: {} } as any); console.log('Table created:', createTable); } catch (error: any) { console.log('Expected validation error caught (raw mode):', error.message); } } main().catch(console.error);