diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5315279..a48affb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,12 +55,12 @@ cd sdk-node # With yarn yarn link cd ../my-package -yarn link runwayml +yarn link @runwayml/sdk # With pnpm pnpm link --global cd ../my-package -pnpm link -—global runwayml +pnpm link -—global @runwayml/sdk ``` ## Running tests diff --git a/README.md b/README.md index 6922442..d946e12 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # RunwayML Node API Library -[![NPM version](https://img.shields.io/npm/v/runwayml.svg)](https://npmjs.org/package/runwayml) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/runwayml) +[![NPM version](https://img.shields.io/npm/v/@runwayml/sdk.svg)](https://npmjs.org/package/@runwayml/sdk) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@runwayml/sdk) This library provides convenient access to the RunwayML REST API from server-side TypeScript or JavaScript. @@ -11,19 +11,16 @@ It is generated with [Stainless](https://www.stainlessapi.com/). ## Installation ```sh -npm install git+ssh://git@github.com:runwayml/sdk-node.git +npm install @runwayml/sdk ``` -> [!NOTE] -> Once this package is [published to npm](https://app.stainlessapi.com/docs/guides/publish), this will become: `npm install runwayml` - ## Usage The full API of this library can be found in [api.md](api.md). ```js -import RunwayML from 'runwayml'; +import RunwayML from '@runwayml/sdk'; const client = new RunwayML({ apiKey: process.env['RUNWAYML_API_SECRET'], // This is the default and can be omitted @@ -48,7 +45,7 @@ This library includes TypeScript definitions for all request params and response ```ts -import RunwayML from 'runwayml'; +import RunwayML from '@runwayml/sdk'; const client = new RunwayML({ apiKey: process.env['RUNWAYML_API_SECRET'], // This is the default and can be omitted @@ -240,11 +237,11 @@ add the following import before your first import `from "RunwayML"`: ```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 'runwayml/shims/web'; -import RunwayML from 'runwayml'; +import '@runwayml/sdk/shims/web'; +import RunwayML from '@runwayml/sdk'; ``` -To do the inverse, add `import "runwayml/shims/node"` (which does import polyfills). +To do the inverse, add `import "@runwayml/sdk/shims/node"` (which does import polyfills). This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/runwayml/sdk-node/tree/main/src/_shims#readme)). ### Logging and middleware @@ -254,7 +251,7 @@ which can be used to inspect or alter the `Request` or `Response` before/after e ```ts import { fetch } from 'undici'; // as one example -import RunwayML from 'runwayml'; +import RunwayML from '@runwayml/sdk'; const client = new RunwayML({ fetch: async (url: RequestInfo, init?: RequestInit): Promise => { diff --git a/jest.config.ts b/jest.config.ts index 96d1ef6..b1f1429 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -7,9 +7,9 @@ const config: JestConfigWithTsJest = { '^.+\\.(t|j)sx?$': ['@swc/jest', { sourceMaps: 'inline' }], }, moduleNameMapper: { - '^runwayml$': '/src/index.ts', - '^runwayml/_shims/auto/(.*)$': '/src/_shims/auto/$1-node', - '^runwayml/(.*)$': '/src/$1', + '^@runwayml/sdk$': '/src/index.ts', + '^@runwayml/sdk/_shims/auto/(.*)$': '/src/_shims/auto/$1-node', + '^@runwayml/sdk/(.*)$': '/src/$1', }, modulePathIgnorePatterns: [ '/ecosystem-tests/', diff --git a/package.json b/package.json index 0d1b3c8..d29a344 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "runwayml", + "name": "@runwayml/sdk", "version": "0.0.1-alpha.0", "description": "The official TypeScript library for the RunwayML API", "author": "RunwayML ", @@ -59,8 +59,8 @@ "./shims/web.mjs" ], "imports": { - "runwayml": ".", - "runwayml/*": "./src/*" + "@runwayml/sdk": ".", + "@runwayml/sdk/*": "./src/*" }, "exports": { "./_shims/auto/*": { diff --git a/scripts/build b/scripts/build index 7937b91..23d1cb0 100755 --- a/scripts/build +++ b/scripts/build @@ -8,7 +8,7 @@ node scripts/utils/check-version.cjs # Build into dist and will publish the package from there, # so that src/resources/foo.ts becomes /resources/foo.js -# This way importing from `"runwayml/resources/foo"` works +# This way importing from `"@runwayml/sdk/resources/foo"` works # even with `"moduleResolution": "node"` rm -rf dist; mkdir dist @@ -47,8 +47,8 @@ node scripts/utils/postprocess-files.cjs # make sure that nothing crashes when we require the output CJS or # import the output ESM -(cd dist && node -e 'require("runwayml")') -(cd dist && node -e 'import("runwayml")' --input-type=module) +(cd dist && node -e 'require("@runwayml/sdk")') +(cd dist && node -e 'import("@runwayml/sdk")' --input-type=module) if command -v deno &> /dev/null && [ -e ./scripts/build-deno ] then diff --git a/scripts/utils/postprocess-files.cjs b/scripts/utils/postprocess-files.cjs index fece96e..e8ed8ce 100644 --- a/scripts/utils/postprocess-files.cjs +++ b/scripts/utils/postprocess-files.cjs @@ -2,7 +2,7 @@ const fs = require('fs'); const path = require('path'); const { parse } = require('@typescript-eslint/parser'); -const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'runwayml/'; +const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? '@runwayml/sdk/'; const distDir = process.env['DIST_PATH'] ? @@ -142,7 +142,7 @@ async function postprocess() { if (file.endsWith('.d.ts')) { // work around bad tsc behavior - // if we have `import { type Readable } from 'runwayml/_shims/index'`, + // if we have `import { type Readable } from '@runwayml/sdk/_shims/index'`, // tsc sometimes replaces `Readable` with `import("stream").Readable` inline // in the output .d.ts transformed = transformed.replace(/import\("stream"\).Readable/g, 'Readable'); diff --git a/src/_shims/README.md b/src/_shims/README.md index f1286f9..9ab80d6 100644 --- a/src/_shims/README.md +++ b/src/_shims/README.md @@ -1,9 +1,9 @@ # 👋 Wondering what everything in here does? -`runwayml` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various +`@runwayml/sdk` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various edge runtimes, as well as both CommonJS (CJS) and EcmaScript Modules (ESM). -To do this, `runwayml` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node. +To do this, `@runwayml/sdk` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node. It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to automatically select the correct shims for each environment. However, conditional exports are a fairly new @@ -15,32 +15,32 @@ getting the wrong raw `Response` type from `.asResponse()`, for example. The user can work around these issues by manually importing one of: -- `import 'runwayml/shims/node'` -- `import 'runwayml/shims/web'` +- `import '@runwayml/sdk/shims/node'` +- `import '@runwayml/sdk/shims/web'` All of the code here in `_shims` handles selecting the automatic default shims or manual overrides. ### How it works - Runtime -Runtime shims get installed by calling `setShims` exported by `runwayml/_shims/registry`. +Runtime shims get installed by calling `setShims` exported by `@runwayml/sdk/_shims/registry`. -Manually importing `runwayml/shims/node` or `runwayml/shims/web`, calls `setShims` with the respective runtime shims. +Manually importing `@runwayml/sdk/shims/node` or `@runwayml/sdk/shims/web`, calls `setShims` with the respective runtime shims. -All client code imports shims from `runwayml/_shims/index`, which: +All client code imports shims from `@runwayml/sdk/_shims/index`, which: - checks if shims have been set manually -- if not, calls `setShims` with the shims from `runwayml/_shims/auto/runtime` -- re-exports the installed shims from `runwayml/_shims/registry`. +- if not, calls `setShims` with the shims from `@runwayml/sdk/_shims/auto/runtime` +- re-exports the installed shims from `@runwayml/sdk/_shims/registry`. -`runwayml/_shims/auto/runtime` exports web runtime shims. -If the `node` export condition is set, the export map replaces it with `runwayml/_shims/auto/runtime-node`. +`@runwayml/sdk/_shims/auto/runtime` exports web runtime shims. +If the `node` export condition is set, the export map replaces it with `@runwayml/sdk/_shims/auto/runtime-node`. ### How it works - Type time -All client code imports shim types from `runwayml/_shims/index`, which selects the manual types from `runwayml/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `runwayml/_shims/auto/types`. +All client code imports shim types from `@runwayml/sdk/_shims/index`, which selects the manual types from `@runwayml/sdk/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `@runwayml/sdk/_shims/auto/types`. -`runwayml/_shims/manual-types` exports an empty namespace. -Manually importing `runwayml/shims/node` or `runwayml/shims/web` merges declarations into this empty namespace, so they get picked up by `runwayml/_shims/index`. +`@runwayml/sdk/_shims/manual-types` exports an empty namespace. +Manually importing `@runwayml/sdk/shims/node` or `@runwayml/sdk/shims/web` merges declarations into this empty namespace, so they get picked up by `@runwayml/sdk/_shims/index`. -`runwayml/_shims/auto/types` exports web type definitions. -If the `node` export condition is set, the export map replaces it with `runwayml/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`. +`@runwayml/sdk/_shims/auto/types` exports web type definitions. +If the `node` export condition is set, the export map replaces it with `@runwayml/sdk/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`. diff --git a/src/_shims/index.d.ts b/src/_shims/index.d.ts index 53304e8..4b5547c 100644 --- a/src/_shims/index.d.ts +++ b/src/_shims/index.d.ts @@ -2,7 +2,7 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ import { manual } from './manual-types'; -import * as auto from 'runwayml/_shims/auto/types'; +import * as auto from '@runwayml/sdk/_shims/auto/types'; import { type RequestOptions } from '../core'; type SelectType = unknown extends Manual ? Auto : Manual; diff --git a/src/_shims/index.js b/src/_shims/index.js index 0676f4c..6b8892b 100644 --- a/src/_shims/index.js +++ b/src/_shims/index.js @@ -2,7 +2,7 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ const shims = require('./registry'); -const auto = require('runwayml/_shims/auto/runtime'); +const auto = require('@runwayml/sdk/_shims/auto/runtime'); if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); for (const property of Object.keys(shims)) { Object.defineProperty(exports, property, { diff --git a/src/_shims/index.mjs b/src/_shims/index.mjs index 1335fb0..b1d59f5 100644 --- a/src/_shims/index.mjs +++ b/src/_shims/index.mjs @@ -2,6 +2,6 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ import * as shims from './registry.mjs'; -import * as auto from 'runwayml/_shims/auto/runtime'; +import * as auto from '@runwayml/sdk/_shims/auto/runtime'; if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); export * from './registry.mjs'; diff --git a/src/_shims/manual-types.d.ts b/src/_shims/manual-types.d.ts index 7b8ee44..fee9223 100644 --- a/src/_shims/manual-types.d.ts +++ b/src/_shims/manual-types.d.ts @@ -4,8 +4,8 @@ /** * Types will get added to this namespace when you import one of the following: * - * import 'runwayml/shims/node' - * import 'runwayml/shims/web' + * import '@runwayml/sdk/shims/node' + * import '@runwayml/sdk/shims/web' * * Importing more than one will cause type and runtime errors. */ diff --git a/src/_shims/registry.ts b/src/_shims/registry.ts index 7101a24..3c805da 100644 --- a/src/_shims/registry.ts +++ b/src/_shims/registry.ts @@ -42,12 +42,12 @@ export let isFsReadStream: Shims['isFsReadStream'] | undefined = undefined; export function setShims(shims: Shims, options: { auto: boolean } = { auto: false }) { if (auto) { throw new Error( - `you must \`import 'runwayml/shims/${shims.kind}'\` before importing anything else from runwayml`, + `you must \`import '@runwayml/sdk/shims/${shims.kind}'\` before importing anything else from @runwayml/sdk`, ); } if (kind) { throw new Error( - `can't \`import 'runwayml/shims/${shims.kind}'\` after \`import 'runwayml/shims/${kind}'\``, + `can't \`import '@runwayml/sdk/shims/${shims.kind}'\` after \`import '@runwayml/sdk/shims/${kind}'\``, ); } auto = options.auto; diff --git a/src/_shims/web-runtime.ts b/src/_shims/web-runtime.ts index 2a7665e..25639a3 100644 --- a/src/_shims/web-runtime.ts +++ b/src/_shims/web-runtime.ts @@ -9,9 +9,9 @@ export function getRuntime({ manuallyImported }: { manuallyImported?: boolean } const recommendation = manuallyImported ? `You may need to use polyfills` - : `Add one of these imports before your first \`import … from 'runwayml'\`: -- \`import 'runwayml/shims/node'\` (if you're running on Node) -- \`import 'runwayml/shims/web'\` (otherwise) + : `Add one of these imports before your first \`import … from '@runwayml/sdk'\`: +- \`import '@runwayml/sdk/shims/node'\` (if you're running on Node) +- \`import '@runwayml/sdk/shims/web'\` (otherwise) `; let _fetch, _Request, _Response, _Headers; diff --git a/src/core.ts b/src/core.ts index 1285534..0141a38 100644 --- a/src/core.ts +++ b/src/core.ts @@ -97,9 +97,9 @@ export class APIPromise extends Promise { * * 👋 Getting the wrong TypeScript type for `Response`? * Try setting `"moduleResolution": "NodeNext"` if you can, - * or add one of these imports before your first `import … from 'runwayml'`: - * - `import 'runwayml/shims/node'` (if you're running on Node) - * - `import 'runwayml/shims/web'` (otherwise) + * or add one of these imports before your first `import … from '@runwayml/sdk'`: + * - `import '@runwayml/sdk/shims/node'` (if you're running on Node) + * - `import '@runwayml/sdk/shims/web'` (otherwise) */ asResponse(): Promise { return this.responsePromise.then((p) => p.response); @@ -113,9 +113,9 @@ export class APIPromise extends Promise { * * 👋 Getting the wrong TypeScript type for `Response`? * Try setting `"moduleResolution": "NodeNext"` if you can, - * or add one of these imports before your first `import … from 'runwayml'`: - * - `import 'runwayml/shims/node'` (if you're running on Node) - * - `import 'runwayml/shims/web'` (otherwise) + * or add one of these imports before your first `import … from '@runwayml/sdk'`: + * - `import '@runwayml/sdk/shims/node'` (if you're running on Node) + * - `import '@runwayml/sdk/shims/web'` (otherwise) */ async withResponse(): Promise<{ data: T; response: Response }> { const [data, response] = await Promise.all([this.parse(), this.asResponse()]); diff --git a/tests/api-resources/image-to-video.test.ts b/tests/api-resources/image-to-video.test.ts index 2b2f403..ef7e8d5 100644 --- a/tests/api-resources/image-to-video.test.ts +++ b/tests/api-resources/image-to-video.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import RunwayML from 'runwayml'; +import RunwayML from '@runwayml/sdk'; import { Response } from 'node-fetch'; const client = new RunwayML({ diff --git a/tests/api-resources/tasks.test.ts b/tests/api-resources/tasks.test.ts index 6715db9..086553e 100644 --- a/tests/api-resources/tasks.test.ts +++ b/tests/api-resources/tasks.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import RunwayML from 'runwayml'; +import RunwayML from '@runwayml/sdk'; import { Response } from 'node-fetch'; const client = new RunwayML({ diff --git a/tests/form.test.ts b/tests/form.test.ts index 4528720..5764646 100644 --- a/tests/form.test.ts +++ b/tests/form.test.ts @@ -1,6 +1,6 @@ -import { multipartFormRequestOptions, createForm } from 'runwayml/core'; -import { Blob } from 'runwayml/_shims/index'; -import { toFile } from 'runwayml'; +import { multipartFormRequestOptions, createForm } from '@runwayml/sdk/core'; +import { Blob } from '@runwayml/sdk/_shims/index'; +import { toFile } from '@runwayml/sdk'; describe('form data validation', () => { test('valid values do not error', async () => { diff --git a/tests/index.test.ts b/tests/index.test.ts index acbe074..bc1ed0c 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import RunwayML from 'runwayml'; -import { APIUserAbortError } from 'runwayml'; -import { Headers } from 'runwayml/core'; +import RunwayML from '@runwayml/sdk'; +import { APIUserAbortError } from '@runwayml/sdk'; +import { Headers } from '@runwayml/sdk/core'; import defaultFetch, { Response, type RequestInit, type RequestInfo } from 'node-fetch'; describe('instantiate client', () => { diff --git a/tests/responses.test.ts b/tests/responses.test.ts index f02dac5..c3622fd 100644 --- a/tests/responses.test.ts +++ b/tests/responses.test.ts @@ -1,5 +1,5 @@ -import { createResponseHeaders } from 'runwayml/core'; -import { Headers } from 'runwayml/_shims/index'; +import { createResponseHeaders } from '@runwayml/sdk/core'; +import { Headers } from '@runwayml/sdk/_shims/index'; describe('response parsing', () => { // TODO: test unicode characters diff --git a/tests/stringifyQuery.test.ts b/tests/stringifyQuery.test.ts index ee0321e..22c1d3f 100644 --- a/tests/stringifyQuery.test.ts +++ b/tests/stringifyQuery.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { RunwayML } from 'runwayml'; +import { RunwayML } from '@runwayml/sdk'; const { stringifyQuery } = RunwayML.prototype as any; diff --git a/tests/uploads.test.ts b/tests/uploads.test.ts index e209506..50155c9 100644 --- a/tests/uploads.test.ts +++ b/tests/uploads.test.ts @@ -1,6 +1,6 @@ import fs from 'fs'; -import { toFile, type ResponseLike } from 'runwayml/uploads'; -import { File } from 'runwayml/_shims/index'; +import { toFile, type ResponseLike } from '@runwayml/sdk/uploads'; +import { File } from '@runwayml/sdk/_shims/index'; class MyClass { name: string = 'foo'; diff --git a/tsconfig.build.json b/tsconfig.build.json index 2c2faee..e9e3def 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -5,8 +5,8 @@ "compilerOptions": { "rootDir": "./dist/src", "paths": { - "runwayml/*": ["dist/src/*"], - "runwayml": ["dist/src/index.ts"], + "@runwayml/sdk/*": ["dist/src/*"], + "@runwayml/sdk": ["dist/src/index.ts"], }, "noEmit": false, "declaration": true, diff --git a/tsconfig.deno.json b/tsconfig.deno.json index 062cd6a..24dd9b1 100644 --- a/tsconfig.deno.json +++ b/tsconfig.deno.json @@ -6,9 +6,9 @@ "rootDir": "./deno", "lib": ["es2020", "DOM"], "paths": { - "runwayml/_shims/auto/*": ["deno/_shims/auto/*-deno"], - "runwayml/*": ["deno/*"], - "runwayml": ["deno/index.ts"], + "@runwayml/sdk/_shims/auto/*": ["deno/_shims/auto/*-deno"], + "@runwayml/sdk/*": ["deno/*"], + "@runwayml/sdk": ["deno/index.ts"], }, "noEmit": true, "declaration": true, diff --git a/tsconfig.json b/tsconfig.json index 7a38861..77548ea 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,9 +9,9 @@ "esModuleInterop": true, "baseUrl": "./", "paths": { - "runwayml/_shims/auto/*": ["src/_shims/auto/*-node"], - "runwayml/*": ["src/*"], - "runwayml": ["src/index.ts"], + "@runwayml/sdk/_shims/auto/*": ["src/_shims/auto/*-node"], + "@runwayml/sdk/*": ["src/*"], + "@runwayml/sdk": ["src/index.ts"], }, "noEmit": true,