Skip to content

Commit

Permalink
chore: update SDK settings (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stainless Bot committed Oct 29, 2024
1 parent 7dc67e7 commit cb159c9
Show file tree
Hide file tree
Showing 37 changed files with 225 additions and 208 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file is used to automatically assign reviewers to PRs
# For more information see: https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners

* @maestro-org/Typescript
2 changes: 1 addition & 1 deletion .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
run: |
bash ./bin/publish-npm
env:
NPM_TOKEN: ${{ secrets.MAESTRO_ARCH_RPC_NPM_TOKEN || secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.MAESTRO_NPM_TOKEN || secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jobs:
run: |
bash ./bin/check-release-environment
env:
NPM_TOKEN: ${{ secrets.MAESTRO_ARCH_RPC_NPM_TOKEN || secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.MAESTRO_NPM_TOKEN || secrets.NPM_TOKEN }}

12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ If you’d like to use the repository from source, you can either install from g
To install via git:

```sh
$ npm install git+ssh://[email protected]:stainless-sdks/maestro-arch-rpc-node.git
$ npm install git+ssh://[email protected]:maestro-org/maestro-arch-rpc-node-sdk.git
```

Alternatively, to link a local copy of the repo:

```sh
# Clone
$ git clone https://www.github.com/stainless-sdks/maestro-arch-rpc-node
$ cd maestro-arch-rpc-node
$ git clone https://www.github.com/maestro-org/maestro-arch-rpc-node-sdk
$ cd maestro-arch-rpc-node-sdk

# With yarn
$ yarn link
$ cd ../my-package
$ yarn link maestro-arch-rpc
$ yarn link @maestro-org/maestro-arch-rpc-node-sdk

# With pnpm
$ pnpm link --global
$ cd ../my-package
$ pnpm link -—global maestro-arch-rpc
$ pnpm link -—global @maestro-org/maestro-arch-rpc-node-sdk
```

## Running tests
Expand Down Expand Up @@ -99,7 +99,7 @@ the changes aren't made through the automated pipeline, you may want to make rel

### Publish with a GitHub workflow

You can release to package managers by using [the `Publish NPM` GitHub action](https://www.github.com/stainless-sdks/maestro-arch-rpc-node/actions/workflows/publish-npm.yml). This requires a setup organization or repository secret to be set up.
You can release to package managers by using [the `Publish NPM` GitHub action](https://www.github.com/maestro-org/maestro-arch-rpc-node-sdk/actions/workflows/publish-npm.yml). This requires a setup organization or repository secret to be set up.

### Publish manually

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 Maestro Arch Rpc
Copyright 2024 Maestro

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
51 changes: 24 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
# Maestro Arch Rpc Node API Library
# Maestro Node API Library

[![NPM version](https://img.shields.io/npm/v/maestro-arch-rpc.svg)](https://npmjs.org/package/maestro-arch-rpc) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/maestro-arch-rpc)
[![NPM version](https://img.shields.io/npm/v/@maestro-org/maestro-arch-rpc-node-sdk.svg)](https://npmjs.org/package/@maestro-org/maestro-arch-rpc-node-sdk) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@maestro-org/maestro-arch-rpc-node-sdk)

This library provides convenient access to the Maestro Arch Rpc REST API from server-side TypeScript or JavaScript.
This library provides convenient access to the Maestro REST API from server-side TypeScript or JavaScript.

The REST API documentation can be found on [docs.maestro-arch-rpc.com](https://docs.maestro-arch-rpc.com). The full API of this library can be found in [api.md](api.md).
The REST API documentation can be found on [docs.gomaestro.org](https://docs.gomaestro.org/). The full API of this library can be found in [api.md](api.md).

It is generated with [Stainless](https://www.stainlessapi.com/).

## Installation

```sh
npm install git+ssh://[email protected]:stainless-sdks/maestro-arch-rpc-node.git
npm install @maestro-org/maestro-arch-rpc-node-sdk
```

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

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

<!-- prettier-ignore -->
```js
import MaestroArchRpc from 'maestro-arch-rpc';
import Maestro from '@maestro-org/maestro-arch-rpc-node-sdk';

const client = new MaestroArchRpc();
const client = new Maestro();

async function main() {
const response = await client.accounts.address([0, 0, 0]);
Expand All @@ -42,13 +39,13 @@ This library includes TypeScript definitions for all request params and response

<!-- prettier-ignore -->
```ts
import MaestroArchRpc from 'maestro-arch-rpc';
import Maestro from '@maestro-org/maestro-arch-rpc-node-sdk';

const client = new MaestroArchRpc();
const client = new Maestro();

async function main() {
const params: MaestroArchRpc.AccountAddressParams = [0, 0, 0];
const response: MaestroArchRpc.AccountAddressResponse = await client.accounts.address(params);
const params: Maestro.AccountAddressParams = [0, 0, 0];
const response: Maestro.AccountAddressResponse = await client.accounts.address(params);
}

main();
Expand All @@ -66,7 +63,7 @@ a subclass of `APIError` will be thrown:
```ts
async function main() {
const response = await client.accounts.address([0, 0, 0]).catch(async (err) => {
if (err instanceof MaestroArchRpc.APIError) {
if (err instanceof Maestro.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
Expand Down Expand Up @@ -103,7 +100,7 @@ You can use the `maxRetries` option to configure or disable this:
<!-- prettier-ignore -->
```js
// Configure the default for all requests:
const client = new MaestroArchRpc({
const client = new Maestro({
maxRetries: 0, // default is 2
});

Expand All @@ -120,7 +117,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 MaestroArchRpc({
const client = new Maestro({
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
});

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

<!-- prettier-ignore -->
```ts
const client = new MaestroArchRpc();
const client = new Maestro();

const response = await client.accounts.address([0, 0, 0]).asResponse();
console.log(response.headers.get('X-My-Header'));
Expand Down Expand Up @@ -205,17 +202,17 @@ 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 "MaestroArchRpc"`:
add the following import before your first import `from "Maestro"`:

```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 'maestro-arch-rpc/shims/web';
import MaestroArchRpc from 'maestro-arch-rpc';
import '@maestro-org/maestro-arch-rpc-node-sdk/shims/web';
import Maestro from '@maestro-org/maestro-arch-rpc-node-sdk';
```

To do the inverse, add `import "maestro-arch-rpc/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-sdks/maestro-arch-rpc-node/tree/main/src/_shims#readme)).
To do the inverse, add `import "@maestro-org/maestro-arch-rpc-node-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/maestro-org/maestro-arch-rpc-node-sdk/tree/main/src/_shims#readme)).

### Logging and middleware

Expand All @@ -224,9 +221,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 MaestroArchRpc from 'maestro-arch-rpc';
import Maestro from '@maestro-org/maestro-arch-rpc-node-sdk';

const client = new MaestroArchRpc({
const client = new Maestro({
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 @@ -251,7 +248,7 @@ import http from 'http';
import { HttpsProxyAgent } from 'https-proxy-agent';

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

Expand All @@ -271,7 +268,7 @@ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) con

We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.

We are keen for your feedback; please open an [issue](https://www.github.com/stainless-sdks/maestro-arch-rpc-node/issues) with questions, bugs, or suggestions.
We are keen for your feedback; please open an [issue](https://www.github.com/maestro-org/maestro-arch-rpc-node-sdk/issues) with questions, bugs, or suggestions.

## Requirements

Expand Down
6 changes: 3 additions & 3 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ 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 Maestro Arch Rpc please follow the respective company's security reporting guidelines.
or products provided by Maestro please follow the respective company's security reporting guidelines.

### Maestro Arch Rpc Terms and Policies
### Maestro Terms and Policies

Please contact support@gomaestro.org for any questions or concerns regarding security of our services.
Please contact info@gomaestro.org for any questions or concerns regarding security of our services.

---

Expand Down
2 changes: 1 addition & 1 deletion bin/check-release-environment
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
errors=()

if [ -z "${NPM_TOKEN}" ]; then
errors+=("The MAESTRO_ARCH_RPC_NPM_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets")
errors+=("The MAESTRO_NPM_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets")
fi

lenErrors=${#errors[@]}
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: {
'^maestro-arch-rpc$': '<rootDir>/src/index.ts',
'^maestro-arch-rpc/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
'^maestro-arch-rpc/(.*)$': '<rootDir>/src/$1',
'^@maestro-org/maestro-arch-rpc-node-sdk$': '<rootDir>/src/index.ts',
'^@maestro-org/maestro-arch-rpc-node-sdk/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
'^@maestro-org/maestro-arch-rpc-node-sdk/(.*)$': '<rootDir>/src/$1',
},
modulePathIgnorePatterns: [
'<rootDir>/ecosystem-tests/',
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "maestro-arch-rpc",
"name": "@maestro-org/maestro-arch-rpc-node-sdk",
"version": "0.1.0-alpha.1",
"description": "The official TypeScript library for the Maestro Arch Rpc API",
"author": "Maestro Arch Rpc <support@gomaestro.org>",
"description": "The official TypeScript library for the Maestro API",
"author": "Maestro <info@gomaestro.org>",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"type": "commonjs",
"repository": "github:stainless-sdks/maestro-arch-rpc-node",
"repository": "github:maestro-org/maestro-arch-rpc-node-sdk",
"license": "Apache-2.0",
"packageManager": "[email protected]",
"files": [
Expand Down Expand Up @@ -60,8 +60,8 @@
"./shims/web.mjs"
],
"imports": {
"maestro-arch-rpc": ".",
"maestro-arch-rpc/*": "./src/*"
"@maestro-org/maestro-arch-rpc-node-sdk": ".",
"@maestro-org/maestro-arch-rpc-node-sdk/*": "./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 `"maestro-arch-rpc/resources/foo"` works
# This way importing from `"@maestro-org/maestro-arch-rpc-node-sdk/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 = Maestro Arch Rpc Node to index.js;
# we need to add exports = module.exports = Maestro 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("maestro-arch-rpc")')
(cd dist && node -e 'import("maestro-arch-rpc")' --input-type=module)
(cd dist && node -e 'require("@maestro-org/maestro-arch-rpc-node-sdk")')
(cd dist && node -e 'import("@maestro-org/maestro-arch-rpc-node-sdk")' --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'] ?? 'maestro-arch-rpc/';
const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? '@maestro-org/maestro-arch-rpc-node-sdk/';

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 'maestro-arch-rpc/_shims/index'`,
// if we have `import { type Readable } from '@maestro-org/maestro-arch-rpc-node-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');
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?

`maestro-arch-rpc` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
`@maestro-org/maestro-arch-rpc-node-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, `maestro-arch-rpc` 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, `@maestro-org/maestro-arch-rpc-node-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
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 'maestro-arch-rpc/shims/node'`
- `import 'maestro-arch-rpc/shims/web'`
- `import '@maestro-org/maestro-arch-rpc-node-sdk/shims/node'`
- `import '@maestro-org/maestro-arch-rpc-node-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 `maestro-arch-rpc/_shims/registry`.
Runtime shims get installed by calling `setShims` exported by `@maestro-org/maestro-arch-rpc-node-sdk/_shims/registry`.

Manually importing `maestro-arch-rpc/shims/node` or `maestro-arch-rpc/shims/web`, calls `setShims` with the respective runtime shims.
Manually importing `@maestro-org/maestro-arch-rpc-node-sdk/shims/node` or `@maestro-org/maestro-arch-rpc-node-sdk/shims/web`, calls `setShims` with the respective runtime shims.

All client code imports shims from `maestro-arch-rpc/_shims/index`, which:
All client code imports shims from `@maestro-org/maestro-arch-rpc-node-sdk/_shims/index`, which:

- checks if shims have been set manually
- if not, calls `setShims` with the shims from `maestro-arch-rpc/_shims/auto/runtime`
- re-exports the installed shims from `maestro-arch-rpc/_shims/registry`.
- if not, calls `setShims` with the shims from `@maestro-org/maestro-arch-rpc-node-sdk/_shims/auto/runtime`
- re-exports the installed shims from `@maestro-org/maestro-arch-rpc-node-sdk/_shims/registry`.

`maestro-arch-rpc/_shims/auto/runtime` exports web runtime shims.
If the `node` export condition is set, the export map replaces it with `maestro-arch-rpc/_shims/auto/runtime-node`.
`@maestro-org/maestro-arch-rpc-node-sdk/_shims/auto/runtime` exports web runtime shims.
If the `node` export condition is set, the export map replaces it with `@maestro-org/maestro-arch-rpc-node-sdk/_shims/auto/runtime-node`.

### How it works - Type time

All client code imports shim types from `maestro-arch-rpc/_shims/index`, which selects the manual types from `maestro-arch-rpc/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `maestro-arch-rpc/_shims/auto/types`.
All client code imports shim types from `@maestro-org/maestro-arch-rpc-node-sdk/_shims/index`, which selects the manual types from `@maestro-org/maestro-arch-rpc-node-sdk/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `@maestro-org/maestro-arch-rpc-node-sdk/_shims/auto/types`.

`maestro-arch-rpc/_shims/manual-types` exports an empty namespace.
Manually importing `maestro-arch-rpc/shims/node` or `maestro-arch-rpc/shims/web` merges declarations into this empty namespace, so they get picked up by `maestro-arch-rpc/_shims/index`.
`@maestro-org/maestro-arch-rpc-node-sdk/_shims/manual-types` exports an empty namespace.
Manually importing `@maestro-org/maestro-arch-rpc-node-sdk/shims/node` or `@maestro-org/maestro-arch-rpc-node-sdk/shims/web` merges declarations into this empty namespace, so they get picked up by `@maestro-org/maestro-arch-rpc-node-sdk/_shims/index`.

`maestro-arch-rpc/_shims/auto/types` exports web type definitions.
If the `node` export condition is set, the export map replaces it with `maestro-arch-rpc/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
`@maestro-org/maestro-arch-rpc-node-sdk/_shims/auto/types` exports web type definitions.
If the `node` export condition is set, the export map replaces it with `@maestro-org/maestro-arch-rpc-node-sdk/_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-deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function getDefaultAgent(url: string) {
}
export function fileFromPath() {
throw new Error(
'The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/stainless-sdks/maestro-arch-rpc-node#file-uploads',
'The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/maestro-org/maestro-arch-rpc-node-sdk#file-uploads',
);
}

Expand Down
Loading

0 comments on commit cb159c9

Please sign in to comment.