Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): OpenAPI spec update via Stainless API #27

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2024 Lumaai
Copyright 2024 LumaAI

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Lumaai Node API Library
# LumaAI Node API Library

[![NPM version](https://img.shields.io/npm/v/lumaai.svg)](https://npmjs.org/package/lumaai) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/lumaai)

This library provides convenient access to the Lumaai REST API from server-side TypeScript or JavaScript.
This library provides convenient access to the LumaAI REST API from server-side TypeScript or JavaScript.

The REST API documentation can be found on [lumalabs.ai](https://lumalabs.ai). The full API of this library can be found in [api.md](api.md).

Expand All @@ -18,9 +18,9 @@ The full API of this library can be found in [api.md](api.md).

<!-- prettier-ignore -->
```js
import Lumaai from 'lumaai';
import LumaAI from 'lumaai';

const client = new Lumaai({
const client = new LumaAI({
authToken: process.env['LUMAAI_API_KEY'], // This is the default and can be omitted
});

Expand All @@ -43,19 +43,19 @@ This library includes TypeScript definitions for all request params and response

<!-- prettier-ignore -->
```ts
import Lumaai from 'lumaai';
import LumaAI from 'lumaai';

const client = new Lumaai({
const client = new LumaAI({
authToken: process.env['LUMAAI_API_KEY'], // This is the default and can be omitted
});

async function main() {
const params: Lumaai.GenerationCreateParams = {
const params: LumaAI.GenerationCreateParams = {
aspect_ratio: '16:9',
prompt:
'A teddy bear in sunglasses playing electric guitar, dancing and headbanging in the jungle in front of a large beautiful waterfall',
};
const generation: Lumaai.Generation = await client.generations.create(params);
const generation: LumaAI.Generation = await client.generations.create(params);
}

main();
Expand All @@ -79,7 +79,7 @@ async function main() {
'A teddy bear in sunglasses playing electric guitar, dancing and headbanging in the jungle in front of a large beautiful waterfall',
})
.catch(async (err) => {
if (err instanceof Lumaai.APIError) {
if (err instanceof LumaAI.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
Expand Down Expand Up @@ -116,7 +116,7 @@ You can use the `maxRetries` option to configure or disable this:
<!-- prettier-ignore -->
```js
// Configure the default for all requests:
const client = new Lumaai({
const client = new LumaAI({
maxRetries: 0, // default is 2
});

Expand All @@ -133,7 +133,7 @@ Requests time out after 1 minute by default. You can configure this with a `time
<!-- prettier-ignore -->
```ts
// Configure the default for all requests:
const client = new Lumaai({
const client = new LumaAI({
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
});

Expand All @@ -157,7 +157,7 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi

<!-- prettier-ignore -->
```ts
const client = new Lumaai();
const client = new LumaAI();

const response = await client.generations
.create({
Expand Down Expand Up @@ -230,13 +230,13 @@ By default, this library uses `node-fetch` in Node, and expects a global `fetch`

If you would prefer to use a global, web-standards-compliant `fetch` function even in a Node environment,
(for example, if you are running Node with `--experimental-fetch` or using NextJS which polyfills with `undici`),
add the following import before your first import `from "Lumaai"`:
add the following import before your first import `from "LumaAI"`:

```ts
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
import 'lumaai/shims/web';
import Lumaai from 'lumaai';
import LumaAI from 'lumaai';
```

To do the inverse, add `import "lumaai/shims/node"` (which does import polyfills).
Expand All @@ -249,9 +249,9 @@ which can be used to inspect or alter the `Request` or `Response` before/after e

```ts
import { fetch } from 'undici'; // as one example
import Lumaai from 'lumaai';
import LumaAI from 'lumaai';

const client = new Lumaai({
const client = new LumaAI({
fetch: async (url: RequestInfo, init?: RequestInit): Promise<Response> => {
console.log('About to make a request', url, init);
const response = await fetch(url, init);
Expand All @@ -276,7 +276,7 @@ import http from 'http';
import { HttpsProxyAgent } from 'https-proxy-agent';

// Configure the default for all requests:
const client = new Lumaai({
const client = new LumaAI({
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
});

Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ before making any information public.
## Reporting Non-SDK Related Security Issues

If you encounter security issues that are not directly related to SDKs but pertain to the services
or products provided by Lumaai please follow the respective company's security reporting guidelines.
or products provided by LumaAI please follow the respective company's security reporting guidelines.

### Lumaai Terms and Policies
### LumaAI Terms and Policies

Please contact support@lumalabs.ai for any questions or concerns regarding security of our services.

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "lumaai",
"version": "1.0.1",
"description": "The official TypeScript library for the Lumaai API",
"author": "Lumaai <support@lumalabs.ai>",
"description": "The official TypeScript library for the LumaAI API",
"author": "LumaAI <support@lumalabs.ai>",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"type": "commonjs",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ npm exec tsc-multi
# copy over handwritten .js/.mjs/.d.ts files
cp src/_shims/*.{d.ts,js,mjs,md} dist/_shims
cp src/_shims/auto/*.{d.ts,js,mjs} dist/_shims/auto
# we need to add exports = module.exports = Lumaai Node to index.js;
# we need to add exports = module.exports = LumaAI Node to index.js;
# No way to get that from index.ts because it would cause compile errors
# when building .mjs
node scripts/utils/fix-index-exports.cjs
Expand Down
20 changes: 10 additions & 10 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { VERSION } from './version';
import {
LumaaiError,
LumaAIError,
APIError,
APIConnectionError,
APIConnectionTimeoutError,
Expand Down Expand Up @@ -486,7 +486,7 @@ export abstract class APIClient {
if (value === null) {
return `${encodeURIComponent(key)}=`;
}
throw new LumaaiError(
throw new LumaAIError(
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
);
})
Expand Down Expand Up @@ -632,7 +632,7 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
async getNextPage(): Promise<this> {
const nextInfo = this.nextPageInfo();
if (!nextInfo) {
throw new LumaaiError(
throw new LumaAIError(
'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',
);
}
Expand Down Expand Up @@ -968,10 +968,10 @@ export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve

const validatePositiveInteger = (name: string, n: unknown): number => {
if (typeof n !== 'number' || !Number.isInteger(n)) {
throw new LumaaiError(`${name} must be an integer`);
throw new LumaAIError(`${name} must be an integer`);
}
if (n < 0) {
throw new LumaaiError(`${name} must be a positive integer`);
throw new LumaAIError(`${name} must be a positive integer`);
}
return n;
};
Expand All @@ -987,7 +987,7 @@ export const castToError = (err: any): Error => {
};

export const ensurePresent = <T>(value: T | null | undefined): T => {
if (value == null) throw new LumaaiError(`Expected a value to be given but received ${value} instead.`);
if (value == null) throw new LumaAIError(`Expected a value to be given but received ${value} instead.`);
return value;
};

Expand All @@ -1012,14 +1012,14 @@ export const coerceInteger = (value: unknown): number => {
if (typeof value === 'number') return Math.round(value);
if (typeof value === 'string') return parseInt(value, 10);

throw new LumaaiError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
throw new LumaAIError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
};

export const coerceFloat = (value: unknown): number => {
if (typeof value === 'number') return value;
if (typeof value === 'string') return parseFloat(value);

throw new LumaaiError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
throw new LumaAIError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
};

export const coerceBoolean = (value: unknown): boolean => {
Expand Down Expand Up @@ -1085,7 +1085,7 @@ function applyHeadersMut(targetHeaders: Headers, newHeaders: Headers): void {

export function debug(action: string, ...args: any[]) {
if (typeof process !== 'undefined' && process?.env?.['DEBUG'] === 'true') {
console.log(`Lumaai:DEBUG:${action}`, ...args);
console.log(`LumaAI:DEBUG:${action}`, ...args);
}
}

Expand Down Expand Up @@ -1162,7 +1162,7 @@ export const toBase64 = (str: string | null | undefined): string => {
return btoa(str);
}

throw new LumaaiError('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined');
throw new LumaAIError('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined');
};

export function isObj(obj: unknown): obj is Record<string, unknown> {
Expand Down
4 changes: 2 additions & 2 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import { castToError, Headers } from './core';

export class LumaaiError extends Error {}
export class LumaAIError extends Error {}

export class APIError extends LumaaiError {
export class APIError extends LumaAIError {
readonly status: number | undefined;
readonly headers: Headers | undefined;
readonly error: Object | undefined;
Expand Down
20 changes: 10 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ export interface ClientOptions {
}

/**
* API Client for interfacing with the Lumaai API.
* API Client for interfacing with the LumaAI API.
*/
export class Lumaai extends Core.APIClient {
export class LumaAI extends Core.APIClient {
authToken: string;

private _options: ClientOptions;

/**
* API Client for interfacing with the Lumaai API.
* API Client for interfacing with the LumaAI API.
*
* @param {string | undefined} [opts.authToken=process.env['LUMAAI_API_KEY'] ?? undefined]
* @param {string} [opts.baseURL=process.env['LUMAAI_BASE_URL'] ?? https://api.lumalabs.ai/dream-machine/v1] - Override the default base URL for the API.
Expand All @@ -95,8 +95,8 @@ export class Lumaai extends Core.APIClient {
...opts
}: ClientOptions = {}) {
if (authToken === undefined) {
throw new Errors.LumaaiError(
"The LUMAAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the Lumaai client with an authToken option, like new Lumaai({ authToken: 'My Auth Token' }).",
throw new Errors.LumaAIError(
"The LUMAAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the LumaAI client with an authToken option, like new LumaAI({ authToken: 'My Auth Token' }).",
);
}

Expand Down Expand Up @@ -137,10 +137,10 @@ export class Lumaai extends Core.APIClient {
return { Authorization: `Bearer ${this.authToken}` };
}

static Lumaai = this;
static LumaAI = this;
static DEFAULT_TIMEOUT = 60000; // 1 minute

static LumaaiError = Errors.LumaaiError;
static LumaAIError = Errors.LumaAIError;
static APIError = Errors.APIError;
static APIConnectionError = Errors.APIConnectionError;
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
Expand All @@ -159,7 +159,7 @@ export class Lumaai extends Core.APIClient {
}

export const {
LumaaiError,
LumaAIError,
APIError,
APIConnectionError,
APIConnectionTimeoutError,
Expand All @@ -177,7 +177,7 @@ export const {
export import toFile = Uploads.toFile;
export import fileFromPath = Uploads.fileFromPath;

export namespace Lumaai {
export namespace LumaAI {
export import RequestOptions = Core.RequestOptions;

export import Generations = API.Generations;
Expand All @@ -190,4 +190,4 @@ export namespace Lumaai {
export import PingCheckResponse = API.PingCheckResponse;
}

export default Lumaai;
export default LumaAI;
6 changes: 3 additions & 3 deletions src/resource.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import type { Lumaai } from './index';
import type { LumaAI } from './index';

export class APIResource {
protected _client: Lumaai;
protected _client: LumaAI;

constructor(client: Lumaai) {
constructor(client: LumaAI) {
this._client = client;
}
}
6 changes: 3 additions & 3 deletions tests/api-resources/generations/camera-motion.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Lumaai from 'lumaai';
import LumaAI from 'lumaai';
import { Response } from 'node-fetch';

const client = new Lumaai({
const client = new LumaAI({
authToken: 'My Auth Token',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
Expand All @@ -23,7 +23,7 @@ describe('resource cameraMotion', () => {
test('list: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(client.generations.cameraMotion.list({ path: '/_stainless_unknown_path' })).rejects.toThrow(
Lumaai.NotFoundError,
LumaAI.NotFoundError,
);
});
});
Loading