From dd243211027d1b8e0538ba5e7a103046ef397ab7 Mon Sep 17 00:00:00 2001 From: Raghd Hamzeh Date: Wed, 8 Oct 2025 14:06:06 -0400 Subject: [PATCH 1/5] chore: reduce generated code --- .openapi-generator-ignore | 3 + .openapi-generator/FILES | 53 +-------- CONTRIBUTING.md | 12 +- README.md | 8 +- base.ts | 14 --- client.ts | 22 +--- common.ts | 34 ++---- configuration.ts | 26 ++-- constants/index.ts | 165 ++++++++++++++++++++++++++ errors.ts | 13 -- tests/client.test.ts | 13 -- tests/headers.test.ts | 13 -- tests/helpers/default-config.ts | 13 -- tests/helpers/index.ts | 13 -- tests/helpers/nocks.ts | 13 -- tests/index.test.ts | 13 -- tests/telemetry/attributes.test.ts | 13 -- tests/telemetry/configuration.test.ts | 13 -- tests/telemetry/counters.test.ts | 13 -- tests/telemetry/histograms.test.ts | 13 -- tests/telemetry/metrics.test.ts | 13 -- tests/validation.test.ts | 13 -- utils/assert-never.ts | 13 -- utils/chunk-array.ts | 13 -- utils/generate-random-id.ts | 13 -- utils/index.ts | 13 -- utils/set-header-if-not-set.ts | 13 -- utils/set-not-enumerable-property.ts | 13 -- validation.ts | 13 -- 29 files changed, 199 insertions(+), 398 deletions(-) create mode 100644 constants/index.ts diff --git a/.openapi-generator-ignore b/.openapi-generator-ignore index 2370ae1..a706e15 100644 --- a/.openapi-generator-ignore +++ b/.openapi-generator-ignore @@ -1 +1,4 @@ .npmignore +configuration.ts +common.ts +base.ts diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index d2f6975..34c0d50 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -1,68 +1,17 @@ .codecov.yml -.eslintignore -.eslintrc.js -.fossa.yml .github/CODEOWNERS .github/ISSUE_TEMPLATE/bug_report.yaml .github/ISSUE_TEMPLATE/config.yaml .github/ISSUE_TEMPLATE/feature_request.yaml .gitignore .gitignore -.madgerc .npmrc -CHANGELOG.md CONTRIBUTING.md LICENSE README.md VERSION.txt api.ts apiModel.ts -base.ts -client.ts -common.ts -configuration.ts -credentials/credentials.ts -credentials/index.ts -credentials/types.ts -docs/opentelemetry.md -errors.ts -example/Makefile -example/README.md -example/example1/example1.mjs -example/example1/package.json -example/opentelemetry/.env.example -example/opentelemetry/.npmrc -example/opentelemetry/README.md -example/opentelemetry/instrumentation.mjs -example/opentelemetry/opentelemetry.mjs -example/opentelemetry/package.json +constants/index.ts git_push.sh index.ts -package.json -telemetry/attributes.ts -telemetry/configuration.ts -telemetry/counters.ts -telemetry/histograms.ts -telemetry/metrics.ts -tests/client.test.ts -tests/headers.test.ts -tests/helpers/default-config.ts -tests/helpers/index.ts -tests/helpers/nocks.ts -tests/index.test.ts -tests/jest.config.js -tests/telemetry/attributes.test.ts -tests/telemetry/configuration.test.ts -tests/telemetry/counters.test.ts -tests/telemetry/histograms.test.ts -tests/telemetry/metrics.test.ts -tests/tsconfig.spec.json -tests/validation.test.ts -tsconfig.json -utils/assert-never.ts -utils/chunk-array.ts -utils/generate-random-id.ts -utils/index.ts -utils/set-header-if-not-set.ts -utils/set-not-enumerable-property.ts -validation.ts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 47cff81..99485a2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,17 +23,23 @@ By participating and contributing to this project, you are expected to uphold ou ### Making Changes -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. +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. ### Opening Issues 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). -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. +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. + +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. + +**Please do not report security vulnerabilities on the public GitHub issue tracker.** ### Submitting Pull Requests -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. +Feel free to submit a Pull Request against this repository. Please make sure to follow the existing code style and include tests where applicable. + +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. ## Getting in touch diff --git a/README.md b/README.md index aa199e4..eea0edd 100644 --- a/README.md +++ b/README.md @@ -830,13 +830,7 @@ This SDK supports producing metrics that can be consumed as part of an [OpenTele ## Contributing -### Issues - -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. - -### Pull Requests - -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. +See [CONTRIBUTING](./CONTRIBUTING.md) for details. ## Author diff --git a/base.ts b/base.ts index 58d84cb..ed01083 100644 --- a/base.ts +++ b/base.ts @@ -1,17 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - -// Some imports not used depending on template conditions import globalAxios, { AxiosInstance } from "axios"; import * as http from "http"; import * as https from "https"; diff --git a/client.ts b/client.ts index c5cdf28..d6278fa 100644 --- a/client.ts +++ b/client.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import { AxiosResponse, AxiosInstance } from "axios"; import asyncPool = require("tiny-async-pool"); @@ -60,6 +47,7 @@ import { setHeaderIfNotSet, } from "./utils"; import { isWellFormedUlidString } from "./validation"; +import SdkConstants from "./constants"; export type UserClientConfigurationParams = UserConfigurationParams & { storeId?: string; @@ -101,10 +89,10 @@ export class ClientConfiguration extends Configuration { } } -const DEFAULT_MAX_METHOD_PARALLEL_REQS = 10; -const DEFAULT_MAX_BATCH_SIZE = 50; -const CLIENT_METHOD_HEADER = "X-OpenFGA-Client-Method"; -const CLIENT_BULK_REQUEST_ID_HEADER = "X-OpenFGA-Client-Bulk-Request-Id"; +const DEFAULT_MAX_METHOD_PARALLEL_REQS = SdkConstants.ClientMaxMethodParallelRequests; +const DEFAULT_MAX_BATCH_SIZE = SdkConstants.ClientMaxBatchSize; +const CLIENT_METHOD_HEADER = SdkConstants.ClientMethodHeader; +const CLIENT_BULK_REQUEST_ID_HEADER = SdkConstants.ClientBulkRequestIdHeader; export interface ClientRequestOpts { retryParams?: RetryParams; diff --git a/common.ts b/common.ts index 4bdd79e..87ab8cb 100644 --- a/common.ts +++ b/common.ts @@ -1,19 +1,7 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; import { Configuration } from "./configuration"; +import SdkConstants from "./constants"; import type { Credentials } from "./credentials"; import { FgaApiError, @@ -26,19 +14,13 @@ import { } from "./errors"; import { setNotEnumerableProperty } from "./utils"; import { TelemetryAttribute, TelemetryAttributes } from "./telemetry/attributes"; -import { MetricRecorder } from "./telemetry/metrics"; import { TelemetryHistograms } from "./telemetry/histograms"; /** * * @export */ -export const DUMMY_BASE_URL = "https://example.com"; -// Retry-After header validation: minimum 1 second, maximum 30 minutes (1800 seconds) -const MIN_RETRY_DELAY_MS = 1_000; // 1 second -const MAX_RETRY_DELAY_MS = 1_800_000; // 30 minutes -// Exponential backoff cap: maximum 120 seconds (2 minutes) -const MAX_EXPONENTIAL_BACKOFF_MS = 120_000; // 120 seconds +export const DUMMY_BASE_URL = `https://${SdkConstants.SampleBaseDomain}`; /** * @@ -145,16 +127,16 @@ function calculateExponentialBackoffWithJitter(retryAttempt: number, minWaitInMs const minDelayMs = Math.ceil(2 ** retryAttempt * minWaitInMs); const maxDelayMs = Math.ceil(2 ** (retryAttempt + 1) * minWaitInMs); const randomDelayMs = Math.floor(Math.random() * (maxDelayMs - minDelayMs) + minDelayMs); - return Math.min(randomDelayMs, MAX_EXPONENTIAL_BACKOFF_MS); + return Math.min(randomDelayMs, SdkConstants.MaxBackoffTimeInSec * 1000); } /** * Validates if a retry delay is within acceptable bounds * @param delayMs - Delay in milliseconds - * @returns True if delay is between MIN_RETRY_DELAY_MS and MAX_RETRY_DELAY_MS + * @returns True if delay is between {@link SdkConstants.DefaultMinWaitInMs} and {@link SdkConstants.RetryHeaderMaxAllowableDurationInSec} */ function isValidRetryDelay(delayMs: number): boolean { - return delayMs >= MIN_RETRY_DELAY_MS && delayMs <= MAX_RETRY_DELAY_MS; + return delayMs >= SdkConstants.DefaultMinWaitInMs && delayMs <= SdkConstants.RetryHeaderMaxAllowableDurationInSec * 1000; } /** @@ -281,7 +263,7 @@ export async function attemptHttpRequest( retryDelayMs = calculateExponentialBackoffWithJitter(iterationCount, config.minWaitInMs); } - await new Promise(r => setTimeout(r, Math.min(retryDelayMs, MAX_RETRY_DELAY_MS))); + await new Promise(r => setTimeout(r, Math.min(retryDelayMs, SdkConstants.RetryHeaderMaxAllowableDurationInSec * 1000))); } } while (iterationCount < config.maxRetry + 1); } @@ -293,8 +275,8 @@ export const createRequestFunction = function (axiosArgs: RequestArgs, axiosInst configuration.isValid(); const retryParams = axiosArgs.options?.retryParams ? axiosArgs.options?.retryParams : configuration.retryParams; - const maxRetry:number = retryParams ? retryParams.maxRetry : 0; - const minWaitInMs:number = retryParams ? retryParams.minWaitInMs : 0; + const maxRetry: number = retryParams ? retryParams.maxRetry : 0; + const minWaitInMs: number = retryParams ? retryParams.minWaitInMs : 0; const start = performance.now(); diff --git a/configuration.ts b/configuration.ts index 537a300..a6387a9 100644 --- a/configuration.ts +++ b/configuration.ts @@ -1,28 +1,16 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import { ApiTokenConfig, AuthCredentialsConfig, ClientCredentialsConfig, CredentialsMethod } from "./credentials/types"; import { FgaValidationError, } from "./errors"; -import { assertParamExists, isWellFormedUlidString, isWellFormedUriString } from "./validation"; +import { assertParamExists, isWellFormedUriString } from "./validation"; import { TelemetryConfig, TelemetryConfiguration } from "./telemetry/configuration"; +import SdkConstants from "./constants"; // default maximum number of retry -const DEFAULT_MAX_RETRY = 3; +const DEFAULT_MAX_RETRY = SdkConstants.DefaultMaxRetry; // default minimum wait period in retry - but will backoff exponentially -const DEFAULT_MIN_WAIT_MS = 100; +const DEFAULT_MIN_WAIT_MS = SdkConstants.DefaultMinWaitInMs; -const DEFAULT_USER_AGENT = "openfga-sdk js/0.9.0"; +const DEFAULT_USER_AGENT = SdkConstants.UserAgent; export interface RetryParams { maxRetry?: number; @@ -45,7 +33,7 @@ export interface UserConfigurationParams { telemetry?: TelemetryConfig; } -export function GetDefaultRetryParams (maxRetry = DEFAULT_MAX_RETRY, minWaitInMs = DEFAULT_MIN_WAIT_MS) { +export function GetDefaultRetryParams (maxRetry: number = DEFAULT_MAX_RETRY, minWaitInMs: number = DEFAULT_MIN_WAIT_MS) { return { maxRetry: maxRetry, minWaitInMs: minWaitInMs, @@ -75,7 +63,7 @@ export class Configuration { * @type {string} * @memberof Configuration */ - private static sdkVersion = "0.9.0"; + private static sdkVersion = SdkConstants.SdkVersion; /** * provide the full api URL (e.g. `https://api.fga.example`) diff --git a/constants/index.ts b/constants/index.ts new file mode 100644 index 0000000..d5b9844 --- /dev/null +++ b/constants/index.ts @@ -0,0 +1,165 @@ +/** + * JavaScript and Node.js SDK for OpenFGA + * + * API version: 1.x + * Website: https://openfga.dev + * Documentation: https://openfga.dev/docs + * Support: https://openfga.dev/community + * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) + * + * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. + */ + + +/** + * Version of the OpenFGA JavaScript SDK. + */ +const SdkVersion = "0.9.0"; + +/** + * User agent used in HTTP requests. + */ +const UserAgent = "openfga-sdk js/0.9.0"; + +/** + * Example API domain for documentation/tests. + */ +const SampleBaseDomain = "fga.example"; + +/** + * API URL used for tests. + */ +const TestApiUrl = `https://api.${SampleBaseDomain}`; + +/** + * API Token Issuer URL used for tests. + */ +const TestIssuerUrl = `https://issuer.${SampleBaseDomain}`; + +/** + * Default API URL. + */ +const DefaultApiUrl = "http://localhost:8080"; + +// Retry configuration + +/** + * Maximum allowed number of retries for HTTP requests. + */ +const RetryMaxAllowedNumber = 15; + +/** + * Default maximum number of retries for HTTP requests. + */ +const DefaultMaxRetry = 3; + +/** + * Default minimum wait time between retries in milliseconds. + */ +const DefaultMinWaitInMs = 100; + +/** + * Maximum backoff time in seconds. + */ +const MaxBackoffTimeInSec = 120; + +/** + * Maximum allowable duration for retry headers in seconds. + */ +const RetryHeaderMaxAllowableDurationInSec = 1800; + +/** + * Standard HTTP header for retry-after. + */ +const RetryAfterHeaderName = "Retry-After"; + +/** + * Rate limit reset header name. + */ +const RateLimitResetHeaderName = "X-RateLimit-Reset"; + +/** + * Alternative rate limit reset header name. + */ +const RateLimitResetAltHeaderName = "X-Rate-Limit-Reset"; + +// Client methods + +/** + * Maximum number of parallel requests for a single method. + */ +const ClientMaxMethodParallelRequests = 10; + +/** + * Maximum batch size for batch requests. + */ +const ClientMaxBatchSize = 50; + +/** + * Header used to identify the client method. + */ +const ClientMethodHeader = "X-OpenFGA-Client-Method"; + +/** + * Header used to identify bulk requests. + */ +const ClientBulkRequestIdHeader = "X-OpenFGA-Client-Bulk-Request-Id"; + +// Connection options + +/** + * Default timeout for HTTP requests in milliseconds. + */ +const DefaultRequestTimeoutInMs = 10000; + +/** + * Default connection timeout in milliseconds. + */ +const DefaultConnectionTimeoutInMs = 10000; + +// Token management + +/** + * Buffer time in seconds before token expiry to consider it expired. + */ +const TokenExpiryThresholdBufferInSec = 300; + +/** + * Jitter time in seconds to add randomness to token expiry checks. + */ +const TokenExpiryJitterInSec = 300; + +// FGA Response Headers + +/** + * Response header name for query duration in milliseconds. + */ +const QueryDurationHeaderName = "fga-query-duration-ms"; + +const SdkConstants = Object.freeze({ + SdkVersion, + UserAgent, + SampleBaseDomain, + TestApiUrl, + TestIssuerUrl, + DefaultApiUrl, + RetryMaxAllowedNumber, + DefaultMaxRetry, + DefaultMinWaitInMs, + MaxBackoffTimeInSec, + RetryHeaderMaxAllowableDurationInSec, + RetryAfterHeaderName, + RateLimitResetHeaderName, + RateLimitResetAltHeaderName, + ClientMaxMethodParallelRequests, + ClientMaxBatchSize, + ClientMethodHeader, + ClientBulkRequestIdHeader, + DefaultRequestTimeoutInMs, + DefaultConnectionTimeoutInMs, + TokenExpiryThresholdBufferInSec, + TokenExpiryJitterInSec, + QueryDurationHeaderName, +}); + +export default SdkConstants; \ No newline at end of file diff --git a/errors.ts b/errors.ts index f947d0f..7629107 100644 --- a/errors.ts +++ b/errors.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import { AxiosError, AxiosHeaderValue, Method } from "axios"; import { ErrorCode, diff --git a/tests/client.test.ts b/tests/client.test.ts index 39c09c2..a8c06fc 100644 --- a/tests/client.test.ts +++ b/tests/client.test.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import * as nock from "nock"; import { diff --git a/tests/headers.test.ts b/tests/headers.test.ts index 73c2d6d..cfc3f5e 100644 --- a/tests/headers.test.ts +++ b/tests/headers.test.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import * as nock from "nock"; import { OpenFgaClient, UserClientConfigurationParams } from "../index"; import { baseConfig } from "./helpers/default-config"; diff --git a/tests/helpers/default-config.ts b/tests/helpers/default-config.ts index e44bb00..1dd2beb 100644 --- a/tests/helpers/default-config.ts +++ b/tests/helpers/default-config.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import { ClientConfiguration, UserClientConfigurationParams } from "../../client"; import { CredentialsMethod } from "../../credentials"; diff --git a/tests/helpers/index.ts b/tests/helpers/index.ts index 89707c0..3a37f22 100644 --- a/tests/helpers/index.ts +++ b/tests/helpers/index.ts @@ -1,15 +1,2 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - export { getNocks } from "./nocks"; export { baseConfig, defaultConfiguration } from "./default-config"; diff --git a/tests/helpers/nocks.ts b/tests/helpers/nocks.ts index f865c90..bc46123 100644 --- a/tests/helpers/nocks.ts +++ b/tests/helpers/nocks.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import type * as Nock from "nock"; import { diff --git a/tests/index.test.ts b/tests/index.test.ts index 0c4a267..5be22a4 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import * as nock from "nock"; import { diff --git a/tests/telemetry/attributes.test.ts b/tests/telemetry/attributes.test.ts index 8116207..4a004fe 100644 --- a/tests/telemetry/attributes.test.ts +++ b/tests/telemetry/attributes.test.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import { TelemetryAttribute, TelemetryAttributes } from "../../telemetry/attributes"; describe("TelemetryAttributes", () => { diff --git a/tests/telemetry/configuration.test.ts b/tests/telemetry/configuration.test.ts index 1b0f781..ade0081 100644 --- a/tests/telemetry/configuration.test.ts +++ b/tests/telemetry/configuration.test.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import { TelemetryConfiguration, TelemetryMetricConfig } from "../../telemetry/configuration"; import { TelemetryAttribute } from "../../telemetry/attributes"; import { TelemetryMetric } from "../../telemetry/metrics"; diff --git a/tests/telemetry/counters.test.ts b/tests/telemetry/counters.test.ts index 5fb4453..64ddb57 100644 --- a/tests/telemetry/counters.test.ts +++ b/tests/telemetry/counters.test.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import { TelemetryCounters } from "../../telemetry/counters"; describe("TelemetryCounters", () => { diff --git a/tests/telemetry/histograms.test.ts b/tests/telemetry/histograms.test.ts index 265ef38..a62a9a2 100644 --- a/tests/telemetry/histograms.test.ts +++ b/tests/telemetry/histograms.test.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import { TelemetryHistograms } from "../../telemetry/histograms"; describe("TelemetryHistograms", () => { diff --git a/tests/telemetry/metrics.test.ts b/tests/telemetry/metrics.test.ts index 823c6ff..7414194 100644 --- a/tests/telemetry/metrics.test.ts +++ b/tests/telemetry/metrics.test.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import { MetricRecorder } from "../../telemetry/metrics"; import { TelemetryCounters } from "../../telemetry/counters"; import { TelemetryHistograms } from "../../telemetry/histograms"; diff --git a/tests/validation.test.ts b/tests/validation.test.ts index e0d45e3..96e3ddc 100644 --- a/tests/validation.test.ts +++ b/tests/validation.test.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import { isWellFormedUlidString } from "../validation"; describe("validation.ts", () => { diff --git a/utils/assert-never.ts b/utils/assert-never.ts index 15bcb94..f7affa0 100644 --- a/utils/assert-never.ts +++ b/utils/assert-never.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - export function assertNever(value: never): never { throw new Error(`Assertion failed. Unacceptable value: '${value}'`); } diff --git a/utils/chunk-array.ts b/utils/chunk-array.ts index 48da58f..a15a0ca 100644 --- a/utils/chunk-array.ts +++ b/utils/chunk-array.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - export function chunkArray(inputArray: T[], maxChunkSize: number): T[][] { const arrayOfArrays = []; diff --git a/utils/generate-random-id.ts b/utils/generate-random-id.ts index 681311a..ba88ec0 100644 --- a/utils/generate-random-id.ts +++ b/utils/generate-random-id.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import { randomUUID, randomBytes } from "crypto"; /** diff --git a/utils/index.ts b/utils/index.ts index aaf4f57..441a9a1 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - export * from "./assert-never"; export * from "./chunk-array"; export * from "./generate-random-id"; diff --git a/utils/set-header-if-not-set.ts b/utils/set-header-if-not-set.ts index 29a79eb..c9b2622 100644 --- a/utils/set-header-if-not-set.ts +++ b/utils/set-header-if-not-set.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - export function setHeaderIfNotSet(headers: Record, key: string, value: string): void { if (!headers[key] && value) { headers[key] = value; diff --git a/utils/set-not-enumerable-property.ts b/utils/set-not-enumerable-property.ts index 3397f0b..c5976db 100644 --- a/utils/set-not-enumerable-property.ts +++ b/utils/set-not-enumerable-property.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - export function setNotEnumerableProperty(entity: object, property: string, value: T) { Object.defineProperty(entity, property, { enumerable: false, diff --git a/validation.ts b/validation.ts index ee4d6ea..33d75b2 100644 --- a/validation.ts +++ b/validation.ts @@ -1,16 +1,3 @@ -/** - * JavaScript and Node.js SDK for OpenFGA - * - * API version: 1.x - * Website: https://openfga.dev - * Documentation: https://openfga.dev/docs - * Support: https://openfga.dev/community - * License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE) - * - * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. - */ - - import { FgaRequiredParamError } from "./errors"; /** From f0aea91753a99ce08a3a63c32fb168bcac72c72b Mon Sep 17 00:00:00 2001 From: Raghd Hamzeh Date: Fri, 24 Oct 2025 12:20:43 -0400 Subject: [PATCH 2/5] chore: tidy up confusing documentation --- common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.ts b/common.ts index 87ab8cb..1ee1022 100644 --- a/common.ts +++ b/common.ts @@ -133,7 +133,7 @@ function calculateExponentialBackoffWithJitter(retryAttempt: number, minWaitInMs /** * Validates if a retry delay is within acceptable bounds * @param delayMs - Delay in milliseconds - * @returns True if delay is between {@link SdkConstants.DefaultMinWaitInMs} and {@link SdkConstants.RetryHeaderMaxAllowableDurationInSec} + * @returns True if delay is between {@link SdkConstants.DefaultMinWaitInMs}ms and {@link SdkConstants.RetryHeaderMaxAllowableDurationInSec}s */ function isValidRetryDelay(delayMs: number): boolean { return delayMs >= SdkConstants.DefaultMinWaitInMs && delayMs <= SdkConstants.RetryHeaderMaxAllowableDurationInSec * 1000; From 7818afd350c89af266eda024b0a2bb813254dd93 Mon Sep 17 00:00:00 2001 From: Raghd Hamzeh Date: Fri, 24 Oct 2025 14:04:53 -0400 Subject: [PATCH 3/5] chore: fix defaulting retry options to 0 --- .openapi-generator/FILES | 1 - common.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index 34c0d50..585091b 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -4,7 +4,6 @@ .github/ISSUE_TEMPLATE/config.yaml .github/ISSUE_TEMPLATE/feature_request.yaml .gitignore -.gitignore .npmrc CONTRIBUTING.md LICENSE diff --git a/common.ts b/common.ts index 1ee1022..47040fa 100644 --- a/common.ts +++ b/common.ts @@ -275,8 +275,8 @@ export const createRequestFunction = function (axiosArgs: RequestArgs, axiosInst configuration.isValid(); const retryParams = axiosArgs.options?.retryParams ? axiosArgs.options?.retryParams : configuration.retryParams; - const maxRetry: number = retryParams ? retryParams.maxRetry : 0; - const minWaitInMs: number = retryParams ? retryParams.minWaitInMs : 0; + const maxRetry: number = retryParams?.maxRetry ?? 0; + const minWaitInMs: number = retryParams?.minWaitInMs ?? 0; const start = performance.now(); From 5a631e1af0fdf10ca91d8d2bee07f336e8d7778d Mon Sep 17 00:00:00 2001 From: Raghd Hamzeh Date: Fri, 24 Oct 2025 14:06:33 -0400 Subject: [PATCH 4/5] chore: fix contributing guide --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 99485a2..17efe5f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ Reading and following these guidelines will help us make the contribution proces * [Getting Started](#getting-started) * [Making Changes](#making-changes) * [Opening Issues](#opening-issues) - * [Submitting Pull Requests](#submitting-pull-requests) [Note: We are not accepting Pull Requests at this time!] + * [Submitting Pull Requests](#submitting-pull-requests) * [Getting in Touch](#getting-in-touch) * [Have a question or problem?](#have-a-question-or-problem) * [Vulnerability Reporting](#vulnerability-reporting) From fe04171edc778700aa18295704188ddbcf7ccbd2 Mon Sep 17 00:00:00 2001 From: Raghd Hamzeh Date: Fri, 24 Oct 2025 14:14:51 -0400 Subject: [PATCH 5/5] fix: retry header check should be case insensitive --- common.ts | 8 +++++++- configuration.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common.ts b/common.ts index 47040fa..f48c28e 100644 --- a/common.ts +++ b/common.ts @@ -145,7 +145,13 @@ function isValidRetryDelay(delayMs: number): boolean { * @returns Delay in milliseconds if valid, undefined otherwise */ function parseRetryAfterHeader(headers: Record): number | undefined { - const retryAfterHeader = headers["retry-after"] || headers["Retry-After"]; + // Find the retry-after header regardless of case + const retryAfterHeaderNameLower = SdkConstants.RetryAfterHeaderName.toLowerCase(); + const retryAfterKey = Object.keys(headers).find(key => + key.toLowerCase() === retryAfterHeaderNameLower + ); + + const retryAfterHeader = retryAfterKey ? headers[retryAfterKey] : undefined; if (!retryAfterHeader) { return undefined; diff --git a/configuration.ts b/configuration.ts index a6387a9..feb2627 100644 --- a/configuration.ts +++ b/configuration.ts @@ -180,7 +180,7 @@ export class Configuration { ); } - if (this.retryParams?.maxRetry && this.retryParams.maxRetry > 15) { + if (this.retryParams?.maxRetry && this.retryParams.maxRetry > SdkConstants.RetryMaxAllowedNumber) { throw new FgaValidationError("Configuration.retryParams.maxRetry exceeds maximum allowed limit of 15"); }