You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 1, 2024. It is now read-only.
* Update readme
* Update README for npm.js search bars
* Remove rewrite of SDK example usage as it's now explicit in the README
* Remove broken Speakeasy generated example usages
---------
Co-authored-by: Stephan Renatus <stephan@styra.com>
> The documentation for this SDK lives at https://docs.styra.com/sdk, with reference documentation available at https://styrainc.github.io/opa-typescript
10
+
11
+
You can use the Styra OPA SDK to connect to [Open Policy Agent](https://www.openpolicyagent.org/) and [Enterprise OPA](https://www.styra.com/enterprise-opa/) deployments.
12
+
8
13
<!-- Start SDK Installation [installation] -->
9
14
## SDK Installation
10
15
@@ -251,37 +256,13 @@ Please refer to [the repository's README.md](https://github.com/StyraInc/opa-typ
251
256
252
257
---
253
258
254
-
<!-- Start SDK Example Usage [usage] -->
255
-
## SDK Example Usage
256
-
257
-
### Example
258
-
259
-
```typescript
260
-
import { OpaApiClient } from"@styra/opa";
261
-
262
-
const opaApiClient =newOpaApiClient();
263
-
264
-
asyncfunction run() {
265
-
const result =awaitopaApiClient.executePolicyWithInput({
266
-
path: "app/rbac",
267
-
requestBody: {
268
-
input: {
269
-
user: "alice",
270
-
action: "read",
271
-
object: "id123",
272
-
type: "dog",
273
-
},
274
-
},
275
-
});
276
-
277
-
// Handle the result
278
-
console.log(result);
279
-
}
259
+
# OPA OpenAPI SDK (low-level)
280
260
281
-
run();
261
+
<!--
262
+
We've removed most of the auto-generated Speakeasy examples because they generate the wrong import path.
263
+
-->
282
264
283
-
```
284
-
<!-- End SDK Example Usage [usage] -->
265
+
<!-- No SDK Example Usage [usage] -->
285
266
286
267
<!-- Start Available Resources and Operations [operations] -->
287
268
## Available Resources and Operations
@@ -293,169 +274,11 @@ run();
293
274
*[health](docs/sdks/opaapiclient/README.md#health) - Verify the server is operational
294
275
<!-- End Available Resources and Operations [operations] -->
295
276
296
-
<!-- Start Error Handling [errors] -->
297
-
## Error Handling
298
-
299
-
All SDK methods return a response object or throw an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Error type.
Validation errors can also occur when either method arguments or data returned from the server do not match the expected format. The `SDKValidationError` that is thrown as a result will capture the raw value that failed validation in an attribute called `rawValue`. Additionally, a `pretty()` method is available on this error that can be used to log a nicely formatted string since validation errors can list many issues and the plain error string may be difficult read when debugging.
You can override the default server globally by passing a server index to the `serverIdx` optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
360
-
361
-
| # | Server | Variables |
362
-
| - | ------ | --------- |
363
-
| 0 |`http://localhost:8181`| None |
364
-
365
-
```typescript
366
-
import { OpaApiClient } from"@styra/opa";
367
-
368
-
const opaApiClient =newOpaApiClient({
369
-
serverIdx: 0,
370
-
});
371
-
372
-
asyncfunction run() {
373
-
const result =awaitopaApiClient.executePolicy({
374
-
path: "app/rbac",
375
-
});
376
-
377
-
// Handle the result
378
-
console.log(result);
379
-
}
380
-
381
-
run();
382
-
383
-
```
384
-
277
+
<!-- No Error Handling [errors] -->
385
278
386
-
### Override Server URL Per-Client
279
+
<!-- No Server Selection [server] -->
387
280
388
-
The default server can also be overridden globally by passing a URL to the `serverURL` optional parameter when initializing the SDK client instance. For example:
389
-
390
-
```typescript
391
-
import { OpaApiClient } from"@styra/opa";
392
-
393
-
const opaApiClient =newOpaApiClient({
394
-
serverURL: "http://localhost:8181",
395
-
});
396
-
397
-
asyncfunction run() {
398
-
const result =awaitopaApiClient.executePolicy({
399
-
path: "app/rbac",
400
-
});
401
-
402
-
// Handle the result
403
-
console.log(result);
404
-
}
405
-
406
-
run();
407
-
408
-
```
409
-
<!-- End Server Selection [server] -->
410
-
411
-
<!-- Start Custom HTTP Client [http-client] -->
412
-
## Custom HTTP Client
413
-
414
-
The TypeScript SDK makes API calls using an `HTTPClient` that wraps the native
415
-
[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). This
416
-
client is a thin wrapper around `fetch` and provides the ability to attach hooks
417
-
around the request lifecycle that can be used to modify the request or handle
418
-
errors and response.
419
-
420
-
The `HTTPClient` constructor takes an optional `fetcher` argument that can be
421
-
used to integrate a third-party HTTP client or when writing tests to mock out
422
-
the HTTP client and feed in fixtures.
423
-
424
-
The following example shows how to use the `"beforeRequest"` hook to to add a
425
-
custom header and a timeout to requests and how to use the `"requestError"` hook
426
-
to log errors:
427
-
428
-
```typescript
429
-
import { OpaApiClient } from"@styra/opa";
430
-
import { HTTPClient } from"@styra/opa/lib/http";
431
-
432
-
const httpClient =newHTTPClient({
433
-
// fetcher takes a function that has the same signature as native `fetch`.
0 commit comments