Skip to content

Commit

Permalink
feat(api): manual updates
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed May 22, 2024
1 parent 88620bd commit a147290
Show file tree
Hide file tree
Showing 39 changed files with 224 additions and 224 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ cd meorphis-test
# With yarn
yarn link
cd ../my-package
yarn link meorphis-test-41
yarn link meorphis-test-40

# With pnpm
pnpm link --global
cd ../my-package
pnpm link -—global meorphis-test-41
pnpm link -—global meorphis-test-40
```

## Running tests
Expand Down
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 Meorphis Test 41
Copyright 2024 Meorphis Test 40

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

[![NPM version](https://img.shields.io/npm/v/meorphis-test-41.svg)](https://npmjs.org/package/meorphis-test-41)
[![NPM version](https://img.shields.io/npm/v/meorphis-test-40.svg)](https://npmjs.org/package/meorphis-test-40)

This library provides convenient access to the Meorphis Test 41 REST API from server-side TypeScript or JavaScript.
This library provides convenient access to the Meorphis Test 40 REST API from server-side TypeScript or JavaScript.

The REST API documentation can be found [on help.bolt.com](https://help.bolt.com/api-bolt/). The full API of this library can be found in [api.md](api.md).

Expand All @@ -15,23 +15,23 @@ npm install git+ssh://[email protected]:stainless-api/meorphis-test.git
```

> [!NOTE]
> Once this package is [published to npm](https://app.stainlessapi.com/docs/guides/publish), this will become: `npm install meorphis-test-41`
> Once this package is [published to npm](https://app.stainlessapi.com/docs/guides/publish), this will become: `npm install meorphis-test-40`
## Usage

The full API of this library can be found in [api.md](api.md).

<!-- prettier-ignore -->
```js
import MeorphisTest41 from 'meorphis-test-41';
import MeorphisTest40 from 'meorphis-test-40';

const meorphisTest41 = new MeorphisTest41({
const meorphisTest40 = new MeorphisTest40({
environment: 'environment_1', // defaults to 'production'
apiKey: 'My API Key',
});

async function main() {
const accountAccountGetResponse = await meorphisTest41.accounts.accountGet({
const accountAccountGetResponse = await meorphisTest40.accounts.accountGet({
'X-Publishable-Key': 'string',
});

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

<!-- prettier-ignore -->
```ts
import MeorphisTest41 from 'meorphis-test-41';
import MeorphisTest40 from 'meorphis-test-40';

const meorphisTest41 = new MeorphisTest41({
const meorphisTest40 = new MeorphisTest40({
environment: 'environment_1', // defaults to 'production'
apiKey: 'My API Key',
});

async function main() {
const params: MeorphisTest41.AccountAccountGetParams = { 'X-Publishable-Key': 'string' };
const accountAccountGetResponse: MeorphisTest41.AccountAccountGetResponse =
await meorphisTest41.accounts.accountGet(params);
const params: MeorphisTest40.AccountAccountGetParams = { 'X-Publishable-Key': 'string' };
const accountAccountGetResponse: MeorphisTest40.AccountAccountGetResponse =
await meorphisTest40.accounts.accountGet(params);
}

main();
Expand All @@ -74,10 +74,10 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const accountAccountGetResponse = await meorphisTest41.accounts
const accountAccountGetResponse = await meorphisTest40.accounts
.accountGet({ 'X-Publishable-Key': 'string' })
.catch(async (err) => {
if (err instanceof MeorphisTest41.APIError) {
if (err instanceof MeorphisTest40.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
Expand Down Expand Up @@ -114,13 +114,13 @@ You can use the `maxRetries` option to configure or disable this:
<!-- prettier-ignore -->
```js
// Configure the default for all requests:
const meorphisTest41 = new MeorphisTest41({
const meorphisTest40 = new MeorphisTest40({
maxRetries: 0, // default is 2
apiKey: 'My API Key',
});

// Or, configure per-request:
await meorphisTest41.accounts.accountGet({ 'X-Publishable-Key': 'string' }, {
await meorphisTest40.accounts.accountGet({ 'X-Publishable-Key': 'string' }, {
maxRetries: 5,
});
```
Expand All @@ -132,13 +132,13 @@ 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 meorphisTest41 = new MeorphisTest41({
const meorphisTest40 = new MeorphisTest40({
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
apiKey: 'My API Key',
});

// Override per-request:
await meorphisTest41.accounts.accountGet({ 'X-Publishable-Key': 'string' }, {
await meorphisTest40.accounts.accountGet({ 'X-Publishable-Key': 'string' }, {
timeout: 5 * 1000,
});
```
Expand All @@ -157,13 +157,13 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi

<!-- prettier-ignore -->
```ts
const meorphisTest41 = new MeorphisTest41();
const meorphisTest40 = new MeorphisTest40();

const response = await meorphisTest41.accounts.accountGet({ 'X-Publishable-Key': 'string' }).asResponse();
const response = await meorphisTest40.accounts.accountGet({ 'X-Publishable-Key': 'string' }).asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: accountAccountGetResponse, response: raw } = await meorphisTest41.accounts
const { data: accountAccountGetResponse, response: raw } = await meorphisTest40.accounts
.accountGet({ 'X-Publishable-Key': 'string' })
.withResponse();
console.log(raw.headers.get('X-My-Header'));
Expand Down Expand Up @@ -220,16 +220,16 @@ 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 "MeorphisTest41"`:
add the following import before your first import `from "MeorphisTest40"`:

```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 'meorphis-test-41/shims/web';
import MeorphisTest41 from 'meorphis-test-41';
import 'meorphis-test-40/shims/web';
import MeorphisTest40 from 'meorphis-test-40';
```

To do the inverse, add `import "meorphis-test-41/shims/node"` (which does import polyfills).
To do the inverse, add `import "meorphis-test-40/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/stainless-api/meorphis-test/tree/main/src/_shims#readme)).

### Logging and middleware
Expand All @@ -239,9 +239,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 MeorphisTest41 from 'meorphis-test-41';
import MeorphisTest40 from 'meorphis-test-40';

const client = new MeorphisTest41({
const client = new MeorphisTest40({
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 @@ -266,13 +266,13 @@ import http from 'http';
import { HttpsProxyAgent } from 'https-proxy-agent';

// Configure the default for all requests:
const meorphisTest41 = new MeorphisTest41({
const meorphisTest40 = new MeorphisTest40({
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
apiKey: 'My API Key',
});

// Override per-request:
await meorphisTest41.accounts.accountGet(
await meorphisTest40.accounts.accountGet(
{ 'X-Publishable-Key': 'string' },
{
httpAgent: new http.Agent({ keepAlive: false }),
Expand All @@ -299,7 +299,7 @@ TypeScript >= 4.5 is supported.
The following runtimes are supported:

- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
- Deno v1.28.0 or higher, using `import MeorphisTest41 from "npm:meorphis-test-41"`.
- Deno v1.28.0 or higher, using `import MeorphisTest40 from "npm:meorphis-test-40"`.
- Bun 1.0 or later.
- Cloudflare Workers.
- Vercel Edge Runtime.
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 Meorphis Test 41 please follow the respective company's security reporting guidelines.
or products provided by Meorphis Test 40 please follow the respective company's security reporting guidelines.

### Meorphis Test 41 Terms and Policies
### Meorphis Test 40 Terms and Policies

Please contact [email protected] for any questions or concerns regarding security of our services.

Expand Down
6 changes: 3 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const config: JestConfigWithTsJest = {
'^.+\\.(t|j)sx?$': ['@swc/jest', { sourceMaps: 'inline' }],
},
moduleNameMapper: {
'^meorphis-test-41$': '<rootDir>/src/index.ts',
'^meorphis-test-41/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
'^meorphis-test-41/(.*)$': '<rootDir>/src/$1',
'^meorphis-test-40$': '<rootDir>/src/index.ts',
'^meorphis-test-40/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
'^meorphis-test-40/(.*)$': '<rootDir>/src/$1',
},
modulePathIgnorePatterns: [
'<rootDir>/ecosystem-tests/',
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "meorphis-test-41",
"name": "meorphis-test-40",
"version": "0.0.1-alpha.0",
"description": "The official TypeScript library for the Meorphis Test 41 API",
"author": "Meorphis Test 41 <[email protected]>",
"description": "The official TypeScript library for the Meorphis Test 40 API",
"author": "Meorphis Test 40 <[email protected]>",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"type": "commonjs",
Expand Down Expand Up @@ -63,8 +63,8 @@
"./shims/web.mjs"
],
"imports": {
"meorphis-test-41": ".",
"meorphis-test-41/*": "./src/*"
"meorphis-test-40": ".",
"meorphis-test-40/*": "./src/*"
},
"exports": {
"./_shims/auto/*": {
Expand Down
8 changes: 4 additions & 4 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -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 <package root>/resources/foo.js
# This way importing from `"meorphis-test-41/resources/foo"` works
# This way importing from `"meorphis-test-40/resources/foo"` works
# even with `"moduleResolution": "node"`

rm -rf dist; mkdir dist
Expand All @@ -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 = Meorphis Test 41 Node to index.js;
# we need to add exports = module.exports = Meorphis Test 40 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 All @@ -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("meorphis-test-41")')
(cd dist && node -e 'import("meorphis-test-41")' --input-type=module)
(cd dist && node -e 'require("meorphis-test-40")')
(cd dist && node -e 'import("meorphis-test-40")' --input-type=module)

if command -v deno &> /dev/null && [ -e ./scripts/build-deno ]
then
Expand Down
4 changes: 2 additions & 2 deletions scripts/utils/postprocess-files.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? 'meorphis-test-41/';
const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'meorphis-test-40/';

const distDir =
process.env['DIST_PATH'] ?
Expand Down Expand Up @@ -142,7 +142,7 @@ async function postprocess() {

if (file.endsWith('.d.ts')) {
// work around bad tsc behavior
// if we have `import { type Readable } from 'meorphis-test-41/_shims/index'`,
// if we have `import { type Readable } from 'meorphis-test-40/_shims/index'`,
// tsc sometimes replaces `Readable` with `import("stream").Readable` inline
// in the output .d.ts
transformed = transformed.replace(/import\("stream"\).Readable/g, 'Readable');
Expand Down
32 changes: 16 additions & 16 deletions src/_shims/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 👋 Wondering what everything in here does?

`meorphis-test-41` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
`meorphis-test-40` 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, `meorphis-test-41` 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, `meorphis-test-40` 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
Expand All @@ -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 'meorphis-test-41/shims/node'`
- `import 'meorphis-test-41/shims/web'`
- `import 'meorphis-test-40/shims/node'`
- `import 'meorphis-test-40/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 `meorphis-test-41/_shims/registry`.
Runtime shims get installed by calling `setShims` exported by `meorphis-test-40/_shims/registry`.

Manually importing `meorphis-test-41/shims/node` or `meorphis-test-41/shims/web`, calls `setShims` with the respective runtime shims.
Manually importing `meorphis-test-40/shims/node` or `meorphis-test-40/shims/web`, calls `setShims` with the respective runtime shims.

All client code imports shims from `meorphis-test-41/_shims/index`, which:
All client code imports shims from `meorphis-test-40/_shims/index`, which:

- checks if shims have been set manually
- if not, calls `setShims` with the shims from `meorphis-test-41/_shims/auto/runtime`
- re-exports the installed shims from `meorphis-test-41/_shims/registry`.
- if not, calls `setShims` with the shims from `meorphis-test-40/_shims/auto/runtime`
- re-exports the installed shims from `meorphis-test-40/_shims/registry`.

`meorphis-test-41/_shims/auto/runtime` exports web runtime shims.
If the `node` export condition is set, the export map replaces it with `meorphis-test-41/_shims/auto/runtime-node`.
`meorphis-test-40/_shims/auto/runtime` exports web runtime shims.
If the `node` export condition is set, the export map replaces it with `meorphis-test-40/_shims/auto/runtime-node`.

### How it works - Type time

All client code imports shim types from `meorphis-test-41/_shims/index`, which selects the manual types from `meorphis-test-41/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `meorphis-test-41/_shims/auto/types`.
All client code imports shim types from `meorphis-test-40/_shims/index`, which selects the manual types from `meorphis-test-40/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `meorphis-test-40/_shims/auto/types`.

`meorphis-test-41/_shims/manual-types` exports an empty namespace.
Manually importing `meorphis-test-41/shims/node` or `meorphis-test-41/shims/web` merges declarations into this empty namespace, so they get picked up by `meorphis-test-41/_shims/index`.
`meorphis-test-40/_shims/manual-types` exports an empty namespace.
Manually importing `meorphis-test-40/shims/node` or `meorphis-test-40/shims/web` merges declarations into this empty namespace, so they get picked up by `meorphis-test-40/_shims/index`.

`meorphis-test-41/_shims/auto/types` exports web type definitions.
If the `node` export condition is set, the export map replaces it with `meorphis-test-41/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
`meorphis-test-40/_shims/auto/types` exports web type definitions.
If the `node` export condition is set, the export map replaces it with `meorphis-test-40/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
2 changes: 1 addition & 1 deletion src/_shims/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 'meorphis-test-41/_shims/auto/types';
import * as auto from 'meorphis-test-40/_shims/auto/types';
import { type RequestOptions } from '../core';

type SelectType<Manual, Auto> = unknown extends Manual ? Auto : Manual;
Expand Down
2 changes: 1 addition & 1 deletion src/_shims/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
const shims = require('./registry');
const auto = require('meorphis-test-41/_shims/auto/runtime');
const auto = require('meorphis-test-40/_shims/auto/runtime');
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
for (const property of Object.keys(shims)) {
Object.defineProperty(exports, property, {
Expand Down
2 changes: 1 addition & 1 deletion src/_shims/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 'meorphis-test-41/_shims/auto/runtime';
import * as auto from 'meorphis-test-40/_shims/auto/runtime';
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
export * from './registry.mjs';
4 changes: 2 additions & 2 deletions src/_shims/manual-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
/**
* Types will get added to this namespace when you import one of the following:
*
* import 'meorphis-test-41/shims/node'
* import 'meorphis-test-41/shims/web'
* import 'meorphis-test-40/shims/node'
* import 'meorphis-test-40/shims/web'
*
* Importing more than one will cause type and runtime errors.
*/
Expand Down
Loading

0 comments on commit a147290

Please sign in to comment.