Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(js-sdk): port back sdk changes #432

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
node-version: [14, 16, 18, 20]

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
fetch-depth: 0

Expand All @@ -42,7 +42,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
fetch-depth: 0

Expand All @@ -65,7 +65,7 @@ jobs:
run: npm test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
continue-on-error: true
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -81,7 +81,7 @@ jobs:
id-token: write

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
fetch-depth: 0

Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
contents: write

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
fetch-depth: 0

Expand Down
2 changes: 1 addition & 1 deletion config/clients/js/template/README_initializing.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
We strongly recommend you initialize the `{{appShortName}}Client` only once and then re-use it throughout your app, otherwise you will incur the cost of having to re-initialize multiple times or at every request, the cost of reduced connection pooling and re-use, and would be particularly costly in the client credentials flow, as that flow will be preformed on every request.
We strongly recommend you initialize the `OpenFgaClient` only once and then re-use it throughout your app, otherwise you will incur the cost of having to re-initialize multiple times or at every request, the cost of reduced connection pooling and re-use, and would be particularly costly in the client credentials flow, as that flow will be performed on every request.

> The `{{appShortName}}Client` will by default retry API requests up to {{defaultMaxRetry}} times on 429 and 5xx errors.

Expand Down
2 changes: 1 addition & 1 deletion config/clients/js/template/README_retries.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ If a network request fails with a 429 or 5xx error from the server, the SDK will

To customize this behavior, create an object with `maxRetry` and `minWaitInMs` properties. `maxRetry` determines the maximum number of retries (up to {{retryMaxAllowedNumber}}), while `minWaitInMs` sets the minimum wait time between retries in milliseconds.

Apply your custom retry values by setting to `retryParams` on the to the configuration object passed to the `OpenFgaClient` call.
Apply your custom retry values by setting to `retryParams` on the configuration object passed to the `OpenFgaClient` call.

```javascript
const { OpenFgaClient } = require('@openfga/sdk'); // OR import { OpenFgaClient } from '@openfga/sdk';
Expand Down
2 changes: 0 additions & 2 deletions config/clients/js/template/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ export class {{appShortName}}Client extends BaseAPI {
this.configuration = new ClientConfiguration(configuration);
}
this.configuration.isValid();


this.api = new {{appShortName}}Api(this.configuration, axios);
this.storeId = configuration.storeId;
this.authorizationModelId = configuration.authorizationModelId;
Expand Down
5 changes: 2 additions & 3 deletions config/clients/js/template/configuration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ export class Configuration {
* @throws {FgaValidationError}
*/
public isValid(): boolean {
if (!this.apiUrl) {
assertParamExists("Configuration", "apiScheme", this.apiScheme);
assertParamExists("Configuration", "apiHost", this.apiHost);
if (!this.apiUrl && !this.apiHost) {
assertParamExists("Configuration", "apiUrl", this.apiUrl);
}

if (!isWellFormedUriString(this.getBasePath())) {
Expand Down
8 changes: 4 additions & 4 deletions config/clients/js/template/docs/opentelemetry.md.mustache
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# OpenTelemetry

This SDK produces [metrics](https://opentelemetry.io/docs/concepts/signals/metrics/) using [OpenTelemetry](https://opentelemetry.io/) that allow you to view data such as request timings. These metrics also include attributes for the model and store ID, as well as the API called to allow you to build reporting.
This SDK produces [metrics](https://opentelemetry.io/docs/concepts/signals/metrics/) using [OpenTelemetry](https://opentelemetry.io/) to allow you to view data such as request timings. These metrics also include attributes for the model and store ID and the API called to allow you to build reporting.

When an OpenTelemetry SDK instance is configured, the metrics will be exported and sent to the collector configured as part of your applications configuration. If you are not using OpenTelemetry, the metric functionality is a no-op and the events are never sent.
When an OpenTelemetry SDK instance is configured, the metrics will be exported and sent to the collector configured as part of your application's configuration. If you are not using OpenTelemetry, the metric functionality is a no-op and the events are never sent.

In cases when metrics events are sent, they will not be viewable outside of infrastructure configured in your application, and are never available to the OpenFGA team or contributors.

Expand Down Expand Up @@ -40,7 +40,7 @@ In cases when metrics events are sent, they will not be viewable outside of infr

Not all attributes are enabled by default.

Some attributes, like `fga-client.user` have been disabled by default due to their high cardinality, which may result for very high costs when using some SaaS metric collectors. If you expect to have a high cardinality for a specific attribute, you can disable it by updating the telemetry configuration accordingly.
Some attributes, like `fga-client.user` have been disabled by default due to their high cardinality, which may result in very high costs when using some SaaS metric collectors. If you expect high cardinality for a specific attribute, you can disable it by updating the telemetry configuration accordingly.

If your configuration does not specify a given metric, the default attributes for that metric will be used.

Expand Down Expand Up @@ -97,4 +97,4 @@ const fgaClient = new OpenFgaClient({

## Example

There is an [example project](https://github.com/openfga/js-sdk/blob/main/example/opentelemetry) that provides some guidance on how to configure OpenTelemetry available in the examples directory.
There is an [example project](https://github.com/openfga/js-sdk/blob/main/example/opentelemetry) that provides some guidance on how to configure OpenTelemetry available in the examples directory.
4 changes: 2 additions & 2 deletions config/clients/js/template/example/README.md.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A set of Examples on how to call the OpenFGA JS SDK

### Examples
Example 1:
A bare-bones example. It creates a store, and runs a set of calls against it including creating a model, writing tuples and checking for access.
A bare-bones example. It creates a store and runs a set of calls against it including creating a model, writing tuples, and checking for access.

OpenTelemetry:
An example that demonstrates how to integrate the OpenFGA JS SDK with OpenTelemetry.
Expand Down Expand Up @@ -42,4 +42,4 @@ to a `file:` reference like below
```
3. If you have an OpenFGA server running, you can use it, otherwise run `make run-openfga` to spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done)
4. Run `make setup` to install dependencies
5. Run `make run` to run the example
5. Run `make run` to run the example
2 changes: 1 addition & 1 deletion config/common/files/.github/workflows/semgrep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
image: returntocorp/semgrep
if: (github.actor != 'dependabot[bot]' && github.actor != 'snyk-bot')
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
fetch-depth: 0
- run: semgrep ci --no-suppress-errors
Expand Down
Loading