Skip to content

Commit 6c6d3e1

Browse files
feat(api): manual updates
1 parent a78fd51 commit 6c6d3e1

File tree

12 files changed

+235
-73
lines changed

12 files changed

+235
-73
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
name: CI
22
on:
33
push:
4-
branches:
5-
- main
6-
pull_request:
7-
branches:
8-
- main
9-
- next
4+
branches-ignore:
5+
- 'generated'
6+
- 'codegen/**'
7+
- 'integrated/**'
8+
- 'stl-preview-head/**'
9+
- 'stl-preview-base/**'
1010

1111
jobs:
1212
lint:
13+
timeout-minutes: 10
1314
name: lint
14-
runs-on: ubuntu-latest
15-
16-
15+
runs-on: ${{ github.repository == 'stainless-sdks/zeroentropy-node' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
1716
steps:
1817
- uses: actions/checkout@v4
1918

@@ -29,10 +28,12 @@ jobs:
2928
run: ./scripts/lint
3029

3130
build:
31+
timeout-minutes: 5
3232
name: build
33-
runs-on: ubuntu-latest
34-
35-
33+
runs-on: ${{ github.repository == 'stainless-sdks/zeroentropy-node' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
34+
permissions:
35+
contents: read
36+
id-token: write
3637
steps:
3738
- uses: actions/checkout@v4
3839

@@ -46,17 +47,32 @@ jobs:
4647

4748
- name: Check build
4849
run: ./scripts/build
50+
51+
- name: Get GitHub OIDC Token
52+
if: github.repository == 'stainless-sdks/zeroentropy-node'
53+
id: github-oidc
54+
uses: actions/github-script@v6
55+
with:
56+
script: core.setOutput('github_token', await core.getIDToken());
57+
58+
- name: Upload tarball
59+
if: github.repository == 'stainless-sdks/zeroentropy-node'
60+
env:
61+
URL: https://pkg.stainless.com/s
62+
AUTH: ${{ steps.github-oidc.outputs.github_token }}
63+
SHA: ${{ github.sha }}
64+
run: ./scripts/utils/upload-artifact.sh
4965
test:
66+
timeout-minutes: 10
5067
name: test
51-
runs-on: ubuntu-latest
52-
68+
runs-on: ${{ github.repository == 'stainless-sdks/zeroentropy-node' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
5369
steps:
5470
- uses: actions/checkout@v4
5571

5672
- name: Set up Node
5773
uses: actions/setup-node@v4
5874
with:
59-
node-version: '18'
75+
node-version: '20'
6076

6177
- name: Bootstrap
6278
run: ./scripts/bootstrap

.github/workflows/publish-npm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Set up Node
2020
uses: actions/setup-node@v3
2121
with:
22-
node-version: '18'
22+
node-version: '20'
2323

2424
- name: Install dependencies
2525
run: |

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 15
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/zeroentropy%2Fzeroentropy-99a41bb73e432cb47fe1937219b3c7b109ae534456e8dd019cc00cc1e6018a16.yml
3-
openapi_spec_hash: 25800181cde6b0a31d6726d77ade2aff
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/zeroentropy%2Fzeroentropy-6d4d2509d6d6d6f6cb90dcad9ddc75dc7562ff8ed3a055bee111921a83cb26d3.yml
3+
openapi_spec_hash: 9cf0d15c10c9061cebd0816868366d1d
44
config_hash: caa8421b07b8eb2eeb82175ec8427837

README.md

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,13 @@ const client = new ZeroEntropy({
2626
apiKey: process.env['ZEROENTROPY_API_KEY'], // This is the default and can be omitted
2727
});
2828

29-
async function main() {
30-
const response = await client.documents.add({
31-
collection_name: 'example_collection',
32-
content: { type: 'text', text: 'Example Content' },
33-
path: 'my_document.txt',
34-
});
35-
36-
console.log(response.message);
37-
}
29+
const response = await client.documents.add({
30+
collection_name: 'example_collection',
31+
content: { type: 'text', text: 'Example Content' },
32+
path: 'my_document.txt',
33+
});
3834

39-
main();
35+
console.log(response.message);
4036
```
4137

4238
### Request & Response types
@@ -51,11 +47,7 @@ const client = new ZeroEntropy({
5147
apiKey: process.env['ZEROENTROPY_API_KEY'], // This is the default and can be omitted
5248
});
5349

54-
async function main() {
55-
const response: ZeroEntropy.StatusGetStatusResponse = await client.status.getStatus();
56-
}
57-
58-
main();
50+
const response: ZeroEntropy.StatusGetStatusResponse = await client.status.getStatus();
5951
```
6052

6153
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
@@ -68,22 +60,18 @@ a subclass of `APIError` will be thrown:
6860

6961
<!-- prettier-ignore -->
7062
```ts
71-
async function main() {
72-
const response = await client.status.getStatus().catch(async (err) => {
73-
if (err instanceof ZeroEntropy.APIError) {
74-
console.log(err.status); // 400
75-
console.log(err.name); // BadRequestError
76-
console.log(err.headers); // {server: 'nginx', ...}
77-
} else {
78-
throw err;
79-
}
80-
});
81-
}
82-
83-
main();
63+
const response = await client.status.getStatus().catch(async (err) => {
64+
if (err instanceof ZeroEntropy.APIError) {
65+
console.log(err.status); // 400
66+
console.log(err.name); // BadRequestError
67+
console.log(err.headers); // {server: 'nginx', ...}
68+
} else {
69+
throw err;
70+
}
71+
});
8472
```
8573

86-
Error codes are as followed:
74+
Error codes are as follows:
8775

8876
| Status Code | Error Type |
8977
| ----------- | -------------------------- |

SECURITY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ before making any information public.
1616
## Reporting Non-SDK Related Security Issues
1717

1818
If you encounter security issues that are not directly related to SDKs but pertain to the services
19-
or products provided by ZeroEntropy please follow the respective company's security reporting guidelines.
19+
or products provided by ZeroEntropy, please follow the respective company's security reporting guidelines.
2020

2121
### ZeroEntropy Terms and Policies
2222

23-
Please contact founders@zeroentropy.dev for any questions or concerns regarding security of our services.
23+
Please contact founders@zeroentropy.dev for any questions or concerns regarding the security of our services.
2424

2525
---
2626

bin/publish-npm

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,35 @@ set -eux
44

55
npm config set '//registry.npmjs.org/:_authToken' "$NPM_TOKEN"
66

7-
# Build the project
87
yarn build
9-
10-
# Navigate to the dist directory
118
cd dist
129

13-
# Get the version from package.json
10+
# Get latest version from npm
11+
#
12+
# If the package doesn't exist, yarn will return
13+
# {"type":"error","data":"Received invalid response from npm."}
14+
# where .data.version doesn't exist so LAST_VERSION will be an empty string.
15+
LAST_VERSION="$(yarn info --json 2> /dev/null | jq -r '.data.version')"
16+
17+
# Get current version from package.json
1418
VERSION="$(node -p "require('./package.json').version")"
1519

16-
# Extract the pre-release tag if it exists
20+
# Check if current version is pre-release (e.g. alpha / beta / rc)
21+
CURRENT_IS_PRERELEASE=false
1722
if [[ "$VERSION" =~ -([a-zA-Z]+) ]]; then
18-
# Extract the part before any dot in the pre-release identifier
19-
TAG="${BASH_REMATCH[1]}"
23+
CURRENT_IS_PRERELEASE=true
24+
CURRENT_TAG="${BASH_REMATCH[1]}"
25+
fi
26+
27+
# Check if last version is a stable release
28+
LAST_IS_STABLE_RELEASE=true
29+
if [[ -z "$LAST_VERSION" || "$LAST_VERSION" =~ -([a-zA-Z]+) ]]; then
30+
LAST_IS_STABLE_RELEASE=false
31+
fi
32+
33+
# Use a corresponding alpha/beta tag if there already is a stable release and we're publishing a prerelease.
34+
if $CURRENT_IS_PRERELEASE && $LAST_IS_STABLE_RELEASE; then
35+
TAG="$CURRENT_TAG"
2036
else
2137
TAG="latest"
2238
fi

scripts/utils/upload-artifact.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -exuo pipefail
3+
4+
RESPONSE=$(curl -X POST "$URL" \
5+
-H "Authorization: Bearer $AUTH" \
6+
-H "Content-Type: application/json")
7+
8+
SIGNED_URL=$(echo "$RESPONSE" | jq -r '.url')
9+
10+
if [[ "$SIGNED_URL" == "null" ]]; then
11+
echo -e "\033[31mFailed to get signed URL.\033[0m"
12+
exit 1
13+
fi
14+
15+
UPLOAD_RESPONSE=$(tar -cz dist | curl -v -X PUT \
16+
-H "Content-Type: application/gzip" \
17+
--data-binary @- "$SIGNED_URL" 2>&1)
18+
19+
if echo "$UPLOAD_RESPONSE" | grep -q "HTTP/[0-9.]* 200"; then
20+
echo -e "\033[32mUploaded build to Stainless storage.\033[0m"
21+
echo -e "\033[32mInstallation: npm install 'https://pkg.stainless.com/s/zeroentropy-node/$SHA'\033[0m"
22+
else
23+
echo -e "\033[31mFailed to upload artifact.\033[0m"
24+
exit 1
25+
fi

src/core.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ export {
3333

3434
export type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;
3535

36+
/**
37+
* An alias to the builtin `Array` type so we can
38+
* easily alias it in import statements if there are name clashes.
39+
*/
40+
type _Array<T> = Array<T>;
41+
42+
/**
43+
* An alias to the builtin `Record` type so we can
44+
* easily alias it in import statements if there are name clashes.
45+
*/
46+
type _Record<K extends keyof any, T> = Record<K, T>;
47+
48+
export type { _Array as Array, _Record as Record };
49+
3650
type PromiseOrValue<T> = T | Promise<T>;
3751

3852
type APIResponseProps = {
@@ -282,10 +296,10 @@ export abstract class APIClient {
282296
}
283297

284298
buildRequest<Req>(
285-
options: FinalRequestOptions<Req>,
299+
inputOptions: FinalRequestOptions<Req>,
286300
{ retryCount = 0 }: { retryCount?: number } = {},
287301
): { req: RequestInit; url: string; timeout: number } {
288-
options = { ...options };
302+
const options = { ...inputOptions };
289303
const { method, path, query, headers: headers = {} } = options;
290304

291305
const body =
@@ -313,8 +327,8 @@ export abstract class APIClient {
313327
}
314328

315329
if (this.idempotencyHeader && method !== 'get') {
316-
if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
317-
headers[this.idempotencyHeader] = options.idempotencyKey;
330+
if (!inputOptions.idempotencyKey) inputOptions.idempotencyKey = this.defaultIdempotencyKey();
331+
headers[this.idempotencyHeader] = inputOptions.idempotencyKey;
318332
}
319333

320334
const reqHeaders = this.buildHeaders({ options, headers, contentLength, retryCount });
@@ -371,7 +385,7 @@ export abstract class APIClient {
371385
getHeader(headers, 'x-stainless-timeout') === undefined &&
372386
options.timeout
373387
) {
374-
reqHeaders['x-stainless-timeout'] = String(options.timeout);
388+
reqHeaders['x-stainless-timeout'] = String(Math.trunc(options.timeout / 1000));
375389
}
376390

377391
this.validateHeaders(reqHeaders, headers);

0 commit comments

Comments
 (0)