diff --git a/CHANGELOG.md b/CHANGELOG.md index c1e5283..9bc79df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,3 +14,4 @@ Full Changelog: [v0.0.1-alpha.0...v0.1.0-alpha.1](https://github.com/sentdm/sent * go live ([#1](https://github.com/sentdm/sent-node/issues/1)) ([9e7d1ac](https://github.com/sentdm/sent-node/commit/9e7d1ac28875aca0edda778691dfb9657669603c)) * update SDK settings ([#3](https://github.com/sentdm/sent-node/issues/3)) ([637e824](https://github.com/sentdm/sent-node/commit/637e82433f081d79e7d8172aa8901731eec5a050)) + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4780d61..79f0ef1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,12 +55,12 @@ $ cd sent-node # With yarn $ yarn link $ cd ../my-package -$ yarn link @sent/node +$ yarn link sentdm # With pnpm $ pnpm link --global $ cd ../my-package -$ pnpm link -—global @sent/node +$ pnpm link -—global sentdm ``` ## Running tests diff --git a/README.md b/README.md index c02398a..46cb13a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Sent Node API Library -[![NPM version](https://img.shields.io/npm/v/@sent/node.svg)](https://npmjs.org/package/@sent/node) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@sent/node) +[![NPM version](https://img.shields.io/npm/v/sentdm.svg)](https://npmjs.org/package/sentdm) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/sentdm) This library provides convenient access to the Sent 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 @sent/node +npm install sentdm ``` ## Usage @@ -20,7 +20,7 @@ The full API of this library can be found in [api.md](api.md). ```js -import Sent from '@sent/node'; +import Sent from 'sentdm'; const client = new Sent(); @@ -37,7 +37,7 @@ This library includes TypeScript definitions for all request params and response ```ts -import Sent from '@sent/node'; +import Sent from 'sentdm'; const client = new Sent(); @@ -204,11 +204,11 @@ add the following import before your first import `from "Sent"`: ```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 '@sent/node/shims/web'; -import Sent from '@sent/node'; +import 'sentdm/shims/web'; +import Sent from 'sentdm'; ``` -To do the inverse, add `import "@sent/node/shims/node"` (which does import polyfills). +To do the inverse, add `import "sentdm/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/sentdm/sent-node/tree/main/src/_shims#readme)). ### Logging and middleware @@ -218,7 +218,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 Sent from '@sent/node'; +import Sent from 'sentdm'; const client = new Sent({ fetch: async (url: RequestInfo, init?: RequestInit): Promise => { diff --git a/jest.config.ts b/jest.config.ts index afc18f0..b8aab19 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -7,9 +7,9 @@ const config: JestConfigWithTsJest = { '^.+\\.(t|j)sx?$': ['@swc/jest', { sourceMaps: 'inline' }], }, moduleNameMapper: { - '^@sent/node$': '/src/index.ts', - '^@sent/node/_shims/auto/(.*)$': '/src/_shims/auto/$1-node', - '^@sent/node/(.*)$': '/src/$1', + '^sentdm$': '/src/index.ts', + '^sentdm/_shims/auto/(.*)$': '/src/_shims/auto/$1-node', + '^sentdm/(.*)$': '/src/$1', }, modulePathIgnorePatterns: [ '/ecosystem-tests/', diff --git a/package.json b/package.json index 780b555..3b796de 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@sent/node", + "name": "sentdm", "version": "0.1.0-alpha.1", "description": "The official TypeScript library for the Sent API", "author": "Sent ", @@ -60,8 +60,8 @@ "./shims/web.mjs" ], "imports": { - "@sent/node": ".", - "@sent/node/*": "./src/*" + "sentdm": ".", + "sentdm/*": "./src/*" }, "exports": { "./_shims/auto/*": { diff --git a/scripts/build b/scripts/build index e5ab626..466b6a9 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 `"@sent/node/resources/foo"` works +# This way importing from `"sentdm/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("@sent/node")') -(cd dist && node -e 'import("@sent/node")' --input-type=module) +(cd dist && node -e 'require("sentdm")') +(cd dist && node -e 'import("sentdm")' --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 bc76423..69d45cd 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'] ?? '@sent/node/'; +const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'sentdm/'; 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 '@sent/node/_shims/index'`, + // if we have `import { type Readable } from 'sentdm/_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 09f2418..497c711 100644 --- a/src/_shims/README.md +++ b/src/_shims/README.md @@ -1,9 +1,9 @@ # 👋 Wondering what everything in here does? -`@sent/node` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various +`sentdm` 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, `@sent/node` 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, `sentdm` 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 '@sent/node/shims/node'` -- `import '@sent/node/shims/web'` +- `import 'sentdm/shims/node'` +- `import 'sentdm/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 `@sent/node/_shims/registry`. +Runtime shims get installed by calling `setShims` exported by `sentdm/_shims/registry`. -Manually importing `@sent/node/shims/node` or `@sent/node/shims/web`, calls `setShims` with the respective runtime shims. +Manually importing `sentdm/shims/node` or `sentdm/shims/web`, calls `setShims` with the respective runtime shims. -All client code imports shims from `@sent/node/_shims/index`, which: +All client code imports shims from `sentdm/_shims/index`, which: - checks if shims have been set manually -- if not, calls `setShims` with the shims from `@sent/node/_shims/auto/runtime` -- re-exports the installed shims from `@sent/node/_shims/registry`. +- if not, calls `setShims` with the shims from `sentdm/_shims/auto/runtime` +- re-exports the installed shims from `sentdm/_shims/registry`. -`@sent/node/_shims/auto/runtime` exports web runtime shims. -If the `node` export condition is set, the export map replaces it with `@sent/node/_shims/auto/runtime-node`. +`sentdm/_shims/auto/runtime` exports web runtime shims. +If the `node` export condition is set, the export map replaces it with `sentdm/_shims/auto/runtime-node`. ### How it works - Type time -All client code imports shim types from `@sent/node/_shims/index`, which selects the manual types from `@sent/node/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `@sent/node/_shims/auto/types`. +All client code imports shim types from `sentdm/_shims/index`, which selects the manual types from `sentdm/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `sentdm/_shims/auto/types`. -`@sent/node/_shims/manual-types` exports an empty namespace. -Manually importing `@sent/node/shims/node` or `@sent/node/shims/web` merges declarations into this empty namespace, so they get picked up by `@sent/node/_shims/index`. +`sentdm/_shims/manual-types` exports an empty namespace. +Manually importing `sentdm/shims/node` or `sentdm/shims/web` merges declarations into this empty namespace, so they get picked up by `sentdm/_shims/index`. -`@sent/node/_shims/auto/types` exports web type definitions. -If the `node` export condition is set, the export map replaces it with `@sent/node/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`. +`sentdm/_shims/auto/types` exports web type definitions. +If the `node` export condition is set, the export map replaces it with `sentdm/_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 107d461..533f7eb 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 '@sent/node/_shims/auto/types'; +import * as auto from 'sentdm/_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 e42d919..38b5e29 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('@sent/node/_shims/auto/runtime'); +const auto = require('sentdm/_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 3ecc65e..9604cc6 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 '@sent/node/_shims/auto/runtime'; +import * as auto from 'sentdm/_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 f2d4fdc..3a0a138 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 '@sent/node/shims/node' - * import '@sent/node/shims/web' + * import 'sentdm/shims/node' + * import 'sentdm/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 e8ae322..cf16bd3 100644 --- a/src/_shims/registry.ts +++ b/src/_shims/registry.ts @@ -42,13 +42,11 @@ 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 '@sent/node/shims/${shims.kind}'\` before importing anything else from @sent/node`, + `you must \`import 'sentdm/shims/${shims.kind}'\` before importing anything else from sentdm`, ); } if (kind) { - throw new Error( - `can't \`import '@sent/node/shims/${shims.kind}'\` after \`import '@sent/node/shims/${kind}'\``, - ); + throw new Error(`can't \`import 'sentdm/shims/${shims.kind}'\` after \`import 'sentdm/shims/${kind}'\``); } auto = options.auto; kind = shims.kind; diff --git a/src/_shims/web-runtime.ts b/src/_shims/web-runtime.ts index 0585369..9c5cbf7 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 '@sent/node'\`: -- \`import '@sent/node/shims/node'\` (if you're running on Node) -- \`import '@sent/node/shims/web'\` (otherwise) + : `Add one of these imports before your first \`import … from 'sentdm'\`: +- \`import 'sentdm/shims/node'\` (if you're running on Node) +- \`import 'sentdm/shims/web'\` (otherwise) `; let _fetch, _Request, _Response, _Headers; diff --git a/src/core.ts b/src/core.ts index 9b44a7f..b4a1559 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 '@sent/node'`: - * - `import '@sent/node/shims/node'` (if you're running on Node) - * - `import '@sent/node/shims/web'` (otherwise) + * or add one of these imports before your first `import … from 'sentdm'`: + * - `import 'sentdm/shims/node'` (if you're running on Node) + * - `import 'sentdm/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 '@sent/node'`: - * - `import '@sent/node/shims/node'` (if you're running on Node) - * - `import '@sent/node/shims/web'` (otherwise) + * or add one of these imports before your first `import … from 'sentdm'`: + * - `import 'sentdm/shims/node'` (if you're running on Node) + * - `import 'sentdm/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/contacts/contacts.test.ts b/tests/api-resources/contacts/contacts.test.ts index fcac05e..fee32b1 100644 --- a/tests/api-resources/contacts/contacts.test.ts +++ b/tests/api-resources/contacts/contacts.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Sent from '@sent/node'; +import Sent from 'sentdm'; import { Response } from 'node-fetch'; const client = new Sent({ diff --git a/tests/api-resources/contacts/id.test.ts b/tests/api-resources/contacts/id.test.ts index 4b9b298..ad08250 100644 --- a/tests/api-resources/contacts/id.test.ts +++ b/tests/api-resources/contacts/id.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Sent from '@sent/node'; +import Sent from 'sentdm'; import { Response } from 'node-fetch'; const client = new Sent({ diff --git a/tests/api-resources/contacts/phone.test.ts b/tests/api-resources/contacts/phone.test.ts index ab998b1..9c8c134 100644 --- a/tests/api-resources/contacts/phone.test.ts +++ b/tests/api-resources/contacts/phone.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Sent from '@sent/node'; +import Sent from 'sentdm'; import { Response } from 'node-fetch'; const client = new Sent({ diff --git a/tests/api-resources/customers.test.ts b/tests/api-resources/customers.test.ts index 1ac58eb..1ec165c 100644 --- a/tests/api-resources/customers.test.ts +++ b/tests/api-resources/customers.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Sent from '@sent/node'; +import Sent from 'sentdm'; import { Response } from 'node-fetch'; const client = new Sent({ diff --git a/tests/api-resources/messages.test.ts b/tests/api-resources/messages.test.ts index 8e3159f..0a9bc84 100644 --- a/tests/api-resources/messages.test.ts +++ b/tests/api-resources/messages.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Sent from '@sent/node'; +import Sent from 'sentdm'; import { Response } from 'node-fetch'; const client = new Sent({ diff --git a/tests/api-resources/sms.test.ts b/tests/api-resources/sms.test.ts index 4a82e55..1bb5021 100644 --- a/tests/api-resources/sms.test.ts +++ b/tests/api-resources/sms.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Sent from '@sent/node'; +import Sent from 'sentdm'; import { Response } from 'node-fetch'; const client = new Sent({ diff --git a/tests/api-resources/templates.test.ts b/tests/api-resources/templates.test.ts index 16ffa95..f04c27a 100644 --- a/tests/api-resources/templates.test.ts +++ b/tests/api-resources/templates.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Sent from '@sent/node'; +import Sent from 'sentdm'; import { Response } from 'node-fetch'; const client = new Sent({ diff --git a/tests/api-resources/whatsapp.test.ts b/tests/api-resources/whatsapp.test.ts index c58a5d6..550e6c7 100644 --- a/tests/api-resources/whatsapp.test.ts +++ b/tests/api-resources/whatsapp.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Sent from '@sent/node'; +import Sent from 'sentdm'; import { Response } from 'node-fetch'; const client = new Sent({ diff --git a/tests/form.test.ts b/tests/form.test.ts index a196511..fd15772 100644 --- a/tests/form.test.ts +++ b/tests/form.test.ts @@ -1,6 +1,6 @@ -import { multipartFormRequestOptions, createForm } from '@sent/node/core'; -import { Blob } from '@sent/node/_shims/index'; -import { toFile } from '@sent/node'; +import { multipartFormRequestOptions, createForm } from 'sentdm/core'; +import { Blob } from 'sentdm/_shims/index'; +import { toFile } from 'sentdm'; describe('form data validation', () => { test('valid values do not error', async () => { diff --git a/tests/index.test.ts b/tests/index.test.ts index df64e8b..b30f767 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 Sent from '@sent/node'; -import { APIUserAbortError } from '@sent/node'; -import { Headers } from '@sent/node/core'; +import Sent from 'sentdm'; +import { APIUserAbortError } from 'sentdm'; +import { Headers } from 'sentdm/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 cce2861..959505b 100644 --- a/tests/responses.test.ts +++ b/tests/responses.test.ts @@ -1,5 +1,5 @@ -import { createResponseHeaders } from '@sent/node/core'; -import { Headers } from '@sent/node/_shims/index'; +import { createResponseHeaders } from 'sentdm/core'; +import { Headers } from 'sentdm/_shims/index'; describe('response parsing', () => { // TODO: test unicode characters diff --git a/tests/stringifyQuery.test.ts b/tests/stringifyQuery.test.ts index 8a6fb87..93ccf10 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 { Sent } from '@sent/node'; +import { Sent } from 'sentdm'; const { stringifyQuery } = Sent.prototype as any; diff --git a/tests/uploads.test.ts b/tests/uploads.test.ts index 2f4a6f3..cf99e9b 100644 --- a/tests/uploads.test.ts +++ b/tests/uploads.test.ts @@ -1,6 +1,6 @@ import fs from 'fs'; -import { toFile, type ResponseLike } from '@sent/node/uploads'; -import { File } from '@sent/node/_shims/index'; +import { toFile, type ResponseLike } from 'sentdm/uploads'; +import { File } from 'sentdm/_shims/index'; class MyClass { name: string = 'foo'; diff --git a/tsconfig.build.json b/tsconfig.build.json index 5488377..1796cc3 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -5,8 +5,8 @@ "compilerOptions": { "rootDir": "./dist/src", "paths": { - "@sent/node/*": ["dist/src/*"], - "@sent/node": ["dist/src/index.ts"], + "sentdm/*": ["dist/src/*"], + "sentdm": ["dist/src/index.ts"], }, "noEmit": false, "declaration": true, diff --git a/tsconfig.deno.json b/tsconfig.deno.json index 0232d2d..5ce4cde 100644 --- a/tsconfig.deno.json +++ b/tsconfig.deno.json @@ -6,9 +6,9 @@ "rootDir": "./deno", "lib": ["es2020", "DOM"], "paths": { - "@sent/node/_shims/auto/*": ["deno/_shims/auto/*-deno"], - "@sent/node/*": ["deno/*"], - "@sent/node": ["deno/index.ts"], + "sentdm/_shims/auto/*": ["deno/_shims/auto/*-deno"], + "sentdm/*": ["deno/*"], + "sentdm": ["deno/index.ts"], }, "noEmit": true, "declaration": true, diff --git a/tsconfig.json b/tsconfig.json index 98662bb..ff7f7d9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,9 +9,9 @@ "esModuleInterop": true, "baseUrl": "./", "paths": { - "@sent/node/_shims/auto/*": ["src/_shims/auto/*-node"], - "@sent/node/*": ["src/*"], - "@sent/node": ["src/index.ts"], + "sentdm/_shims/auto/*": ["src/_shims/auto/*-node"], + "sentdm/*": ["src/*"], + "sentdm": ["src/index.ts"], }, "noEmit": true,