diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 58799c9..3c2193a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,12 +55,12 @@ $ cd arcade-js # With yarn $ yarn link $ cd ../my-package -$ yarn link arcadejs +$ yarn link @arcadeai/arcadejs # With pnpm $ pnpm link --global $ cd ../my-package -$ pnpm link -—global arcadejs +$ pnpm link -—global @arcadeai/arcadejs ``` ## Running tests diff --git a/README.md b/README.md index bdcacea..697bf42 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Arcade Node API Library -[![NPM version](https://img.shields.io/npm/v/arcadejs.svg)](https://npmjs.org/package/arcadejs) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/arcadejs) +[![NPM version](https://img.shields.io/npm/v/@arcadeai/arcadejs.svg)](https://npmjs.org/package/@arcadeai/arcadejs) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@arcadeai/arcadejs) This library provides convenient access to the Arcade REST API from server-side TypeScript or JavaScript. @@ -11,7 +11,7 @@ It is generated with [Stainless](https://www.stainlessapi.com/). ## Installation ```sh -npm install arcadejs +npm install @arcadeai/arcadejs ``` ## Usage @@ -20,7 +20,7 @@ The full API of this library can be found in [api.md](api.md). ```js -import Arcade from 'arcadejs'; +import Arcade from '@arcadeai/arcadejs'; const client = new Arcade({ apiKey: process.env['ARCADE_API_KEY'], // This is the default and can be omitted @@ -46,7 +46,7 @@ This library includes TypeScript definitions for all request params and response ```ts -import Arcade from 'arcadejs'; +import Arcade from '@arcadeai/arcadejs'; const client = new Arcade({ apiKey: process.env['ARCADE_API_KEY'], // This is the default and can be omitted @@ -224,11 +224,11 @@ add the following import before your first import `from "Arcade"`: ```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 'arcadejs/shims/web'; -import Arcade from 'arcadejs'; +import '@arcadeai/arcadejs/shims/web'; +import Arcade from '@arcadeai/arcadejs'; ``` -To do the inverse, add `import "arcadejs/shims/node"` (which does import polyfills). +To do the inverse, add `import "@arcadeai/arcadejs/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/ArcadeAI/arcade-js/tree/main/src/_shims#readme)). ### Logging and middleware @@ -238,7 +238,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 Arcade from 'arcadejs'; +import Arcade from '@arcadeai/arcadejs'; const client = new Arcade({ fetch: async (url: RequestInfo, init?: RequestInit): Promise => { diff --git a/jest.config.ts b/jest.config.ts index 4e59df1..60cc95c 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -7,9 +7,9 @@ const config: JestConfigWithTsJest = { '^.+\\.(t|j)sx?$': ['@swc/jest', { sourceMaps: 'inline' }], }, moduleNameMapper: { - '^arcadejs$': '/src/index.ts', - '^arcadejs/_shims/auto/(.*)$': '/src/_shims/auto/$1-node', - '^arcadejs/(.*)$': '/src/$1', + '^@arcadeai/arcadejs$': '/src/index.ts', + '^@arcadeai/arcadejs/_shims/auto/(.*)$': '/src/_shims/auto/$1-node', + '^@arcadeai/arcadejs/(.*)$': '/src/$1', }, modulePathIgnorePatterns: [ '/ecosystem-tests/', diff --git a/package.json b/package.json index db2adb5..de287d5 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "arcadejs", + "name": "@arcadeai/arcadejs", "version": "0.1.1", "description": "The official TypeScript library for the Arcade API", "author": "Arcade ", @@ -60,8 +60,8 @@ "./shims/web.mjs" ], "imports": { - "arcadejs": ".", - "arcadejs/*": "./src/*" + "@arcadeai/arcadejs": ".", + "@arcadeai/arcadejs/*": "./src/*" }, "exports": { "./_shims/auto/*": { diff --git a/scripts/build b/scripts/build index a658002..543c8f8 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 `"arcadejs/resources/foo"` works +# This way importing from `"@arcadeai/arcadejs/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("arcadejs")') -(cd dist && node -e 'import("arcadejs")' --input-type=module) +(cd dist && node -e 'require("@arcadeai/arcadejs")') +(cd dist && node -e 'import("@arcadeai/arcadejs")' --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 fb48303..e991ec1 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'] ?? 'arcadejs/'; +const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? '@arcadeai/arcadejs/'; 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 'arcadejs/_shims/index'`, + // if we have `import { type Readable } from '@arcadeai/arcadejs/_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 7094e69..1e822ef 100644 --- a/src/_shims/README.md +++ b/src/_shims/README.md @@ -1,9 +1,9 @@ # 👋 Wondering what everything in here does? -`arcadejs` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various +`@arcadeai/arcadejs` 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, `arcadejs` 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, `@arcadeai/arcadejs` 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 'arcadejs/shims/node'` -- `import 'arcadejs/shims/web'` +- `import '@arcadeai/arcadejs/shims/node'` +- `import '@arcadeai/arcadejs/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 `arcadejs/_shims/registry`. +Runtime shims get installed by calling `setShims` exported by `@arcadeai/arcadejs/_shims/registry`. -Manually importing `arcadejs/shims/node` or `arcadejs/shims/web`, calls `setShims` with the respective runtime shims. +Manually importing `@arcadeai/arcadejs/shims/node` or `@arcadeai/arcadejs/shims/web`, calls `setShims` with the respective runtime shims. -All client code imports shims from `arcadejs/_shims/index`, which: +All client code imports shims from `@arcadeai/arcadejs/_shims/index`, which: - checks if shims have been set manually -- if not, calls `setShims` with the shims from `arcadejs/_shims/auto/runtime` -- re-exports the installed shims from `arcadejs/_shims/registry`. +- if not, calls `setShims` with the shims from `@arcadeai/arcadejs/_shims/auto/runtime` +- re-exports the installed shims from `@arcadeai/arcadejs/_shims/registry`. -`arcadejs/_shims/auto/runtime` exports web runtime shims. -If the `node` export condition is set, the export map replaces it with `arcadejs/_shims/auto/runtime-node`. +`@arcadeai/arcadejs/_shims/auto/runtime` exports web runtime shims. +If the `node` export condition is set, the export map replaces it with `@arcadeai/arcadejs/_shims/auto/runtime-node`. ### How it works - Type time -All client code imports shim types from `arcadejs/_shims/index`, which selects the manual types from `arcadejs/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `arcadejs/_shims/auto/types`. +All client code imports shim types from `@arcadeai/arcadejs/_shims/index`, which selects the manual types from `@arcadeai/arcadejs/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `@arcadeai/arcadejs/_shims/auto/types`. -`arcadejs/_shims/manual-types` exports an empty namespace. -Manually importing `arcadejs/shims/node` or `arcadejs/shims/web` merges declarations into this empty namespace, so they get picked up by `arcadejs/_shims/index`. +`@arcadeai/arcadejs/_shims/manual-types` exports an empty namespace. +Manually importing `@arcadeai/arcadejs/shims/node` or `@arcadeai/arcadejs/shims/web` merges declarations into this empty namespace, so they get picked up by `@arcadeai/arcadejs/_shims/index`. -`arcadejs/_shims/auto/types` exports web type definitions. -If the `node` export condition is set, the export map replaces it with `arcadejs/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`. +`@arcadeai/arcadejs/_shims/auto/types` exports web type definitions. +If the `node` export condition is set, the export map replaces it with `@arcadeai/arcadejs/_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 319a47d..b2fe01f 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 'arcadejs/_shims/auto/types'; +import * as auto from '@arcadeai/arcadejs/_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 d75e24d..b4e8c7b 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('arcadejs/_shims/auto/runtime'); +const auto = require('@arcadeai/arcadejs/_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 4a09777..564013d 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 'arcadejs/_shims/auto/runtime'; +import * as auto from '@arcadeai/arcadejs/_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 5579909..26609ec 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 'arcadejs/shims/node' - * import 'arcadejs/shims/web' + * import '@arcadeai/arcadejs/shims/node' + * import '@arcadeai/arcadejs/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 7567aae..26a3041 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 'arcadejs/shims/${shims.kind}'\` before importing anything else from arcadejs`, + `you must \`import '@arcadeai/arcadejs/shims/${shims.kind}'\` before importing anything else from @arcadeai/arcadejs`, ); } if (kind) { throw new Error( - `can't \`import 'arcadejs/shims/${shims.kind}'\` after \`import 'arcadejs/shims/${kind}'\``, + `can't \`import '@arcadeai/arcadejs/shims/${shims.kind}'\` after \`import '@arcadeai/arcadejs/shims/${kind}'\``, ); } auto = options.auto; diff --git a/src/_shims/web-runtime.ts b/src/_shims/web-runtime.ts index e6db131..196802b 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 'arcadejs'\`: -- \`import 'arcadejs/shims/node'\` (if you're running on Node) -- \`import 'arcadejs/shims/web'\` (otherwise) + : `Add one of these imports before your first \`import … from '@arcadeai/arcadejs'\`: +- \`import '@arcadeai/arcadejs/shims/node'\` (if you're running on Node) +- \`import '@arcadeai/arcadejs/shims/web'\` (otherwise) `; let _fetch, _Request, _Response, _Headers; diff --git a/src/core.ts b/src/core.ts index 6f6089e..0f3ad6a 100644 --- a/src/core.ts +++ b/src/core.ts @@ -99,9 +99,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 'arcadejs'`: - * - `import 'arcadejs/shims/node'` (if you're running on Node) - * - `import 'arcadejs/shims/web'` (otherwise) + * or add one of these imports before your first `import … from '@arcadeai/arcadejs'`: + * - `import '@arcadeai/arcadejs/shims/node'` (if you're running on Node) + * - `import '@arcadeai/arcadejs/shims/web'` (otherwise) */ asResponse(): Promise { return this.responsePromise.then((p) => p.response); @@ -115,9 +115,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 'arcadejs'`: - * - `import 'arcadejs/shims/node'` (if you're running on Node) - * - `import 'arcadejs/shims/web'` (otherwise) + * or add one of these imports before your first `import … from '@arcadeai/arcadejs'`: + * - `import '@arcadeai/arcadejs/shims/node'` (if you're running on Node) + * - `import '@arcadeai/arcadejs/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/auth.test.ts b/tests/api-resources/auth.test.ts index 152c800..3acdb8f 100644 --- a/tests/api-resources/auth.test.ts +++ b/tests/api-resources/auth.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Arcade from 'arcadejs'; +import Arcade from '@arcadeai/arcadejs'; import { Response } from 'node-fetch'; const client = new Arcade({ diff --git a/tests/api-resources/chat/completions.test.ts b/tests/api-resources/chat/completions.test.ts index a0feed2..9df0f19 100644 --- a/tests/api-resources/chat/completions.test.ts +++ b/tests/api-resources/chat/completions.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Arcade from 'arcadejs'; +import Arcade from '@arcadeai/arcadejs'; import { Response } from 'node-fetch'; const client = new Arcade({ diff --git a/tests/api-resources/health.test.ts b/tests/api-resources/health.test.ts index 4c600ef..b4e1eb7 100644 --- a/tests/api-resources/health.test.ts +++ b/tests/api-resources/health.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Arcade from 'arcadejs'; +import Arcade from '@arcadeai/arcadejs'; import { Response } from 'node-fetch'; const client = new Arcade({ diff --git a/tests/api-resources/tools/formatted.test.ts b/tests/api-resources/tools/formatted.test.ts index 32f40d3..acf4aca 100644 --- a/tests/api-resources/tools/formatted.test.ts +++ b/tests/api-resources/tools/formatted.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Arcade from 'arcadejs'; +import Arcade from '@arcadeai/arcadejs'; import { Response } from 'node-fetch'; const client = new Arcade({ diff --git a/tests/api-resources/tools/tools.test.ts b/tests/api-resources/tools/tools.test.ts index e9ca560..db4552b 100644 --- a/tests/api-resources/tools/tools.test.ts +++ b/tests/api-resources/tools/tools.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Arcade from 'arcadejs'; +import Arcade from '@arcadeai/arcadejs'; import { Response } from 'node-fetch'; const client = new Arcade({ diff --git a/tests/form.test.ts b/tests/form.test.ts index 95250c4..d681111 100644 --- a/tests/form.test.ts +++ b/tests/form.test.ts @@ -1,6 +1,6 @@ -import { multipartFormRequestOptions, createForm } from 'arcadejs/core'; -import { Blob } from 'arcadejs/_shims/index'; -import { toFile } from 'arcadejs'; +import { multipartFormRequestOptions, createForm } from '@arcadeai/arcadejs/core'; +import { Blob } from '@arcadeai/arcadejs/_shims/index'; +import { toFile } from '@arcadeai/arcadejs'; describe('form data validation', () => { test('valid values do not error', async () => { diff --git a/tests/index.test.ts b/tests/index.test.ts index 1c370f2..1684e11 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 Arcade from 'arcadejs'; -import { APIUserAbortError } from 'arcadejs'; -import { Headers } from 'arcadejs/core'; +import Arcade from '@arcadeai/arcadejs'; +import { APIUserAbortError } from '@arcadeai/arcadejs'; +import { Headers } from '@arcadeai/arcadejs/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 2102ca1..1cb1ca1 100644 --- a/tests/responses.test.ts +++ b/tests/responses.test.ts @@ -1,5 +1,5 @@ -import { createResponseHeaders } from 'arcadejs/core'; -import { Headers } from 'arcadejs/_shims/index'; +import { createResponseHeaders } from '@arcadeai/arcadejs/core'; +import { Headers } from '@arcadeai/arcadejs/_shims/index'; describe('response parsing', () => { // TODO: test unicode characters diff --git a/tests/stringifyQuery.test.ts b/tests/stringifyQuery.test.ts index 4cef46d..a2f815c 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 { Arcade } from 'arcadejs'; +import { Arcade } from '@arcadeai/arcadejs'; const { stringifyQuery } = Arcade.prototype as any; diff --git a/tests/uploads.test.ts b/tests/uploads.test.ts index 97641b6..8581aaa 100644 --- a/tests/uploads.test.ts +++ b/tests/uploads.test.ts @@ -1,6 +1,6 @@ import fs from 'fs'; -import { toFile, type ResponseLike } from 'arcadejs/uploads'; -import { File } from 'arcadejs/_shims/index'; +import { toFile, type ResponseLike } from '@arcadeai/arcadejs/uploads'; +import { File } from '@arcadeai/arcadejs/_shims/index'; class MyClass { name: string = 'foo'; diff --git a/tsconfig.build.json b/tsconfig.build.json index 0a73f41..957599c 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -5,8 +5,8 @@ "compilerOptions": { "rootDir": "./dist/src", "paths": { - "arcadejs/*": ["dist/src/*"], - "arcadejs": ["dist/src/index.ts"], + "@arcadeai/arcadejs/*": ["dist/src/*"], + "@arcadeai/arcadejs": ["dist/src/index.ts"], }, "noEmit": false, "declaration": true, diff --git a/tsconfig.deno.json b/tsconfig.deno.json index d5b49bf..867e321 100644 --- a/tsconfig.deno.json +++ b/tsconfig.deno.json @@ -6,9 +6,9 @@ "rootDir": "./deno", "lib": ["es2020", "DOM"], "paths": { - "arcadejs/_shims/auto/*": ["deno/_shims/auto/*-deno"], - "arcadejs/*": ["deno/*"], - "arcadejs": ["deno/index.ts"], + "@arcadeai/arcadejs/_shims/auto/*": ["deno/_shims/auto/*-deno"], + "@arcadeai/arcadejs/*": ["deno/*"], + "@arcadeai/arcadejs": ["deno/index.ts"], }, "noEmit": true, "declaration": true, diff --git a/tsconfig.json b/tsconfig.json index e639b52..a07692c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,9 +9,9 @@ "esModuleInterop": true, "baseUrl": "./", "paths": { - "arcadejs/_shims/auto/*": ["src/_shims/auto/*-node"], - "arcadejs/*": ["src/*"], - "arcadejs": ["src/index.ts"], + "@arcadeai/arcadejs/_shims/auto/*": ["src/_shims/auto/*-node"], + "@arcadeai/arcadejs/*": ["src/*"], + "@arcadeai/arcadejs": ["src/index.ts"], }, "noEmit": true,