Skip to content

Commit 9e9575e

Browse files
authored
Merge branch 'main' into feat/add-write-conflict-options
2 parents 120c42b + 9b81c81 commit 9e9575e

29 files changed

+208
-402
lines changed

.openapi-generator-ignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
.npmignore
2+
configuration.ts
3+
common.ts
4+
base.ts

.openapi-generator/FILES

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,16 @@
11
.codecov.yml
2-
.eslintignore
3-
.eslintrc.js
4-
.fossa.yml
52
.github/CODEOWNERS
63
.github/ISSUE_TEMPLATE/bug_report.yaml
74
.github/ISSUE_TEMPLATE/config.yaml
85
.github/ISSUE_TEMPLATE/feature_request.yaml
96
.gitignore
10-
.gitignore
11-
.madgerc
127
.npmrc
13-
CHANGELOG.md
148
CONTRIBUTING.md
159
LICENSE
1610
README.md
1711
VERSION.txt
1812
api.ts
1913
apiModel.ts
20-
base.ts
21-
client.ts
22-
common.ts
23-
configuration.ts
24-
credentials/credentials.ts
25-
credentials/index.ts
26-
credentials/types.ts
27-
docs/opentelemetry.md
28-
errors.ts
29-
example/Makefile
30-
example/README.md
31-
example/example1/example1.mjs
32-
example/example1/package.json
33-
example/opentelemetry/.env.example
34-
example/opentelemetry/.npmrc
35-
example/opentelemetry/README.md
36-
example/opentelemetry/instrumentation.mjs
37-
example/opentelemetry/opentelemetry.mjs
38-
example/opentelemetry/package.json
14+
constants/index.ts
3915
git_push.sh
4016
index.ts
41-
package.json
42-
telemetry/attributes.ts
43-
telemetry/configuration.ts
44-
telemetry/counters.ts
45-
telemetry/histograms.ts
46-
telemetry/metrics.ts
47-
tests/client.test.ts
48-
tests/headers.test.ts
49-
tests/helpers/default-config.ts
50-
tests/helpers/index.ts
51-
tests/helpers/nocks.ts
52-
tests/index.test.ts
53-
tests/jest.config.js
54-
tests/telemetry/attributes.test.ts
55-
tests/telemetry/configuration.test.ts
56-
tests/telemetry/counters.test.ts
57-
tests/telemetry/histograms.test.ts
58-
tests/telemetry/metrics.test.ts
59-
tests/tsconfig.spec.json
60-
tests/validation.test.ts
61-
tsconfig.json
62-
utils/assert-never.ts
63-
utils/chunk-array.ts
64-
utils/generate-random-id.ts
65-
utils/index.ts
66-
utils/set-header-if-not-set.ts
67-
utils/set-not-enumerable-property.ts
68-
validation.ts

CONTRIBUTING.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Reading and following these guidelines will help us make the contribution proces
1010
* [Getting Started](#getting-started)
1111
* [Making Changes](#making-changes)
1212
* [Opening Issues](#opening-issues)
13-
* [Submitting Pull Requests](#submitting-pull-requests) [Note: We are not accepting Pull Requests at this time!]
13+
* [Submitting Pull Requests](#submitting-pull-requests)
1414
* [Getting in Touch](#getting-in-touch)
1515
* [Have a question or problem?](#have-a-question-or-problem)
1616
* [Vulnerability Reporting](#vulnerability-reporting)
@@ -23,17 +23,23 @@ By participating and contributing to this project, you are expected to uphold ou
2323

2424
### Making Changes
2525

26-
When contributing to a repository, the first step is to open an issue on [sdk-generator](https://github.com/openfga/sdk-generator) to discuss the change you wish to make before making them.
26+
When contributing to a repository, the first step is to open [an issue](https://github.com/openfga/js-sdk/issues) to discuss the change you wish to make before making them.
2727

2828
### Opening Issues
2929

3030
Before you submit a new issue please make sure to search all open and closed issues. It is possible your feature request/issue has already been answered. Make sure to also check the [OpenFGA discussions](https://github.com/orgs/openfga/discussions).
3131

32-
That repo includes an issue template that will walk through all the places to check before submitting your issue here. Please follow the instructions there to make sure this is not a duplicate issue and that we have everything we need to research and reproduce this problem.
32+
The repo includes an issue template that will walk through all the places to check before submitting your issue here. Please follow the instructions there to make sure this is not a duplicate issue and that we have everything we need to research and reproduce this problem.
33+
34+
If you have found a bug or if you have a feature request, please report them in the [repo issues](https://github.com/openfga/js-sdk/issues). Cross-SDK bugs and feature requests can be additionally reported in the [sdk-generator repo](https://github.com/openfga/sdk-generator/issues) issues section, where the individual SDK issue is then linked.
35+
36+
**Please do not report security vulnerabilities on the public GitHub issue tracker.**
3337

3438
### Submitting Pull Requests
3539

36-
While we accept Pull Requests on this repository, the SDKs are autogenerated so please consider additionally submitting your Pull Requests to the [sdk-generator](https://github.com/openfga/sdk-generator) and linking the two PRs together and to the corresponding issue. This will greatly assist the OpenFGA team in being able to give timely reviews as well as deploying fixes and updates to our other SDKs as well.
40+
Feel free to submit a Pull Request against this repository. Please make sure to follow the existing code style and include tests where applicable.
41+
42+
Some files in this repository are autogenerated. These files have a comment at the top indicating that they are autogenerated and should not be modified directly - the files are usually identified by a header marking them as such, or by their inclusion in [`.openapi-generator/FILES`](./.openapi-generator/FILES). Changes to these files should be made in the [sdk-generator](https://github.com/openfga/sdk-generator) repository in tandem, so please consider additionally submitting your Pull Requests to the [sdk-generator](https://github.com/openfga/sdk-generator) and linking the two PRs together and to the corresponding issue. This will greatly assist the OpenFGA team in being able to give timely reviews as well as deploying fixes and updates to our other SDKs as well.
3743

3844
## Getting in touch
3945

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -909,13 +909,7 @@ This SDK supports producing metrics that can be consumed as part of an [OpenTele
909909

910910
## Contributing
911911

912-
### Issues
913-
914-
If you have found a bug or if you have a feature request, please report them on the [sdk-generator repo](https://github.com/openfga/sdk-generator/issues) issues section. Please do not report security vulnerabilities on the public GitHub issue tracker.
915-
916-
### Pull Requests
917-
918-
While we accept Pull Requests on this repository, the SDKs are autogenerated so please consider additionally submitting your Pull Requests to the [sdk-generator](https://github.com/openfga/sdk-generator) and linking the two PRs together and to the corresponding issue. This will greatly assist the OpenFGA team in being able to give timely reviews as well as deploying fixes and updates to our other SDKs as well.
912+
See [CONTRIBUTING](./CONTRIBUTING.md) for details.
919913

920914
## Author
921915

base.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
/**
2-
* JavaScript and Node.js SDK for OpenFGA
3-
*
4-
* API version: 1.x
5-
* Website: https://openfga.dev
6-
* Documentation: https://openfga.dev/docs
7-
* Support: https://openfga.dev/community
8-
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE)
9-
*
10-
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
11-
*/
12-
13-
14-
// Some imports not used depending on template conditions
151
import globalAxios, { AxiosInstance } from "axios";
162
import * as http from "http";
173
import * as https from "https";

client.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
/**
2-
* JavaScript and Node.js SDK for OpenFGA
3-
*
4-
* API version: 1.x
5-
* Website: https://openfga.dev
6-
* Documentation: https://openfga.dev/docs
7-
* Support: https://openfga.dev/community
8-
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE)
9-
*
10-
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
11-
*/
12-
13-
141
import { AxiosResponse, AxiosInstance } from "axios";
152
import asyncPool = require("tiny-async-pool");
163

@@ -62,6 +49,7 @@ import {
6249
setHeaderIfNotSet,
6350
} from "./utils";
6451
import { isWellFormedUlidString } from "./validation";
52+
import SdkConstants from "./constants";
6553

6654
export type UserClientConfigurationParams = UserConfigurationParams & {
6755
storeId?: string;
@@ -103,10 +91,10 @@ export class ClientConfiguration extends Configuration {
10391
}
10492
}
10593

106-
const DEFAULT_MAX_METHOD_PARALLEL_REQS = 10;
107-
const DEFAULT_MAX_BATCH_SIZE = 50;
108-
const CLIENT_METHOD_HEADER = "X-OpenFGA-Client-Method";
109-
const CLIENT_BULK_REQUEST_ID_HEADER = "X-OpenFGA-Client-Bulk-Request-Id";
94+
const DEFAULT_MAX_METHOD_PARALLEL_REQS = SdkConstants.ClientMaxMethodParallelRequests;
95+
const DEFAULT_MAX_BATCH_SIZE = SdkConstants.ClientMaxBatchSize;
96+
const CLIENT_METHOD_HEADER = SdkConstants.ClientMethodHeader;
97+
const CLIENT_BULK_REQUEST_ID_HEADER = SdkConstants.ClientBulkRequestIdHeader;
11098

11199
export interface ClientRequestOpts {
112100
retryParams?: RetryParams;

common.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
/**
2-
* JavaScript and Node.js SDK for OpenFGA
3-
*
4-
* API version: 1.x
5-
* Website: https://openfga.dev
6-
* Documentation: https://openfga.dev/docs
7-
* Support: https://openfga.dev/community
8-
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE)
9-
*
10-
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
11-
*/
12-
13-
141
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
152

163
import { Configuration } from "./configuration";
4+
import SdkConstants from "./constants";
175
import type { Credentials } from "./credentials";
186
import {
197
FgaApiError,
@@ -26,19 +14,13 @@ import {
2614
} from "./errors";
2715
import { setNotEnumerableProperty } from "./utils";
2816
import { TelemetryAttribute, TelemetryAttributes } from "./telemetry/attributes";
29-
import { MetricRecorder } from "./telemetry/metrics";
3017
import { TelemetryHistograms } from "./telemetry/histograms";
3118

3219
/**
3320
*
3421
* @export
3522
*/
36-
export const DUMMY_BASE_URL = "https://example.com";
37-
// Retry-After header validation: minimum 1 second, maximum 30 minutes (1800 seconds)
38-
const MIN_RETRY_DELAY_MS = 1_000; // 1 second
39-
const MAX_RETRY_DELAY_MS = 1_800_000; // 30 minutes
40-
// Exponential backoff cap: maximum 120 seconds (2 minutes)
41-
const MAX_EXPONENTIAL_BACKOFF_MS = 120_000; // 120 seconds
23+
export const DUMMY_BASE_URL = `https://${SdkConstants.SampleBaseDomain}`;
4224

4325
/**
4426
*
@@ -145,16 +127,16 @@ function calculateExponentialBackoffWithJitter(retryAttempt: number, minWaitInMs
145127
const minDelayMs = Math.ceil(2 ** retryAttempt * minWaitInMs);
146128
const maxDelayMs = Math.ceil(2 ** (retryAttempt + 1) * minWaitInMs);
147129
const randomDelayMs = Math.floor(Math.random() * (maxDelayMs - minDelayMs) + minDelayMs);
148-
return Math.min(randomDelayMs, MAX_EXPONENTIAL_BACKOFF_MS);
130+
return Math.min(randomDelayMs, SdkConstants.MaxBackoffTimeInSec * 1000);
149131
}
150132

151133
/**
152134
* Validates if a retry delay is within acceptable bounds
153135
* @param delayMs - Delay in milliseconds
154-
* @returns True if delay is between MIN_RETRY_DELAY_MS and MAX_RETRY_DELAY_MS
136+
* @returns True if delay is between {@link SdkConstants.DefaultMinWaitInMs}ms and {@link SdkConstants.RetryHeaderMaxAllowableDurationInSec}s
155137
*/
156138
function isValidRetryDelay(delayMs: number): boolean {
157-
return delayMs >= MIN_RETRY_DELAY_MS && delayMs <= MAX_RETRY_DELAY_MS;
139+
return delayMs >= SdkConstants.DefaultMinWaitInMs && delayMs <= SdkConstants.RetryHeaderMaxAllowableDurationInSec * 1000;
158140
}
159141

160142
/**
@@ -163,7 +145,13 @@ function isValidRetryDelay(delayMs: number): boolean {
163145
* @returns Delay in milliseconds if valid, undefined otherwise
164146
*/
165147
function parseRetryAfterHeader(headers: Record<string, string | string[] | undefined>): number | undefined {
166-
const retryAfterHeader = headers["retry-after"] || headers["Retry-After"];
148+
// Find the retry-after header regardless of case
149+
const retryAfterHeaderNameLower = SdkConstants.RetryAfterHeaderName.toLowerCase();
150+
const retryAfterKey = Object.keys(headers).find(key =>
151+
key.toLowerCase() === retryAfterHeaderNameLower
152+
);
153+
154+
const retryAfterHeader = retryAfterKey ? headers[retryAfterKey] : undefined;
167155

168156
if (!retryAfterHeader) {
169157
return undefined;
@@ -281,7 +269,7 @@ export async function attemptHttpRequest<B, R>(
281269
retryDelayMs = calculateExponentialBackoffWithJitter(iterationCount, config.minWaitInMs);
282270
}
283271

284-
await new Promise(r => setTimeout(r, Math.min(retryDelayMs, MAX_RETRY_DELAY_MS)));
272+
await new Promise(r => setTimeout(r, Math.min(retryDelayMs, SdkConstants.RetryHeaderMaxAllowableDurationInSec * 1000)));
285273
}
286274
} while (iterationCount < config.maxRetry + 1);
287275
}
@@ -293,8 +281,8 @@ export const createRequestFunction = function (axiosArgs: RequestArgs, axiosInst
293281
configuration.isValid();
294282

295283
const retryParams = axiosArgs.options?.retryParams ? axiosArgs.options?.retryParams : configuration.retryParams;
296-
const maxRetry:number = retryParams ? retryParams.maxRetry : 0;
297-
const minWaitInMs:number = retryParams ? retryParams.minWaitInMs : 0;
284+
const maxRetry: number = retryParams?.maxRetry ?? 0;
285+
const minWaitInMs: number = retryParams?.minWaitInMs ?? 0;
298286

299287
const start = performance.now();
300288

configuration.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
1-
/**
2-
* JavaScript and Node.js SDK for OpenFGA
3-
*
4-
* API version: 1.x
5-
* Website: https://openfga.dev
6-
* Documentation: https://openfga.dev/docs
7-
* Support: https://openfga.dev/community
8-
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE)
9-
*
10-
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
11-
*/
12-
13-
141
import { ApiTokenConfig, AuthCredentialsConfig, ClientCredentialsConfig, CredentialsMethod } from "./credentials/types";
152
import { FgaValidationError, } from "./errors";
16-
import { assertParamExists, isWellFormedUlidString, isWellFormedUriString } from "./validation";
3+
import { assertParamExists, isWellFormedUriString } from "./validation";
174
import { TelemetryConfig, TelemetryConfiguration } from "./telemetry/configuration";
5+
import SdkConstants from "./constants";
186

197
// default maximum number of retry
20-
const DEFAULT_MAX_RETRY = 3;
8+
const DEFAULT_MAX_RETRY = SdkConstants.DefaultMaxRetry;
219

2210
// default minimum wait period in retry - but will backoff exponentially
23-
const DEFAULT_MIN_WAIT_MS = 100;
11+
const DEFAULT_MIN_WAIT_MS = SdkConstants.DefaultMinWaitInMs;
2412

25-
const DEFAULT_USER_AGENT = "openfga-sdk js/0.9.0";
13+
const DEFAULT_USER_AGENT = SdkConstants.UserAgent;
2614

2715
export interface RetryParams {
2816
maxRetry?: number;
@@ -45,7 +33,7 @@ export interface UserConfigurationParams {
4533
telemetry?: TelemetryConfig;
4634
}
4735

48-
export function GetDefaultRetryParams (maxRetry = DEFAULT_MAX_RETRY, minWaitInMs = DEFAULT_MIN_WAIT_MS) {
36+
export function GetDefaultRetryParams (maxRetry: number = DEFAULT_MAX_RETRY, minWaitInMs: number = DEFAULT_MIN_WAIT_MS) {
4937
return {
5038
maxRetry: maxRetry,
5139
minWaitInMs: minWaitInMs,
@@ -75,7 +63,7 @@ export class Configuration {
7563
* @type {string}
7664
* @memberof Configuration
7765
*/
78-
private static sdkVersion = "0.9.0";
66+
private static sdkVersion = SdkConstants.SdkVersion;
7967

8068
/**
8169
* provide the full api URL (e.g. `https://api.fga.example`)
@@ -192,7 +180,7 @@ export class Configuration {
192180
);
193181
}
194182

195-
if (this.retryParams?.maxRetry && this.retryParams.maxRetry > 15) {
183+
if (this.retryParams?.maxRetry && this.retryParams.maxRetry > SdkConstants.RetryMaxAllowedNumber) {
196184
throw new FgaValidationError("Configuration.retryParams.maxRetry exceeds maximum allowed limit of 15");
197185
}
198186

0 commit comments

Comments
 (0)