@distilled.cloud/okta 1.0.0-rc.11 → 1.0.0-rc.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # @distilled.cloud/okta
2
+
3
+ Effect-native SDK for [okta](https://www.npmjs.com/package/@distilled.cloud/okta).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @distilled.cloud/okta effect
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```ts
14
+ import { Effect, Layer } from "effect";
15
+ import * as FetchHttpClient from "effect/http/FetchHttpClient";
16
+ import * as Okta from "@distilled.cloud/okta";
17
+
18
+ const program = Effect.gen(function* () {
19
+ const result = yield* Okta.listUsers({});
20
+ return result;
21
+ });
22
+
23
+ const Live = Layer.mergeAll(
24
+ FetchHttpClient.layer,
25
+ Okta.CredentialsFromEnv,
26
+ Okta.OktaProtocol,
27
+ );
28
+
29
+ program.pipe(Effect.provide(Live), Effect.runPromise);
30
+ ```
31
+
32
+ ## Auth
33
+
34
+ Required: `OKTA_API_TOKEN`, `OKTA_AUTH_SCHEME`. Optional: `OKTA_ORG_URL`. Sent as `Authorization: Bearer`.
package/lib/protocol.d.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  import type * as Layer from "effect/Layer";
2
- import type * as HttpClient from "effect/unstable/http/HttpClient";
3
- import type * as HttpClientError from "effect/unstable/http/HttpClientError";
2
+ import type * as HttpClient from "effect/http/HttpClient";
3
+ import type * as HttpClientError from "effect/http/HttpClientError";
4
4
  import type * as API from "@distilled.cloud/core/api";
5
5
  import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
6
6
  import { Credentials } from "./credentials.ts";
7
- import { UnknownOktaError } from "./errors.ts";
7
+ import { UnknownOktaError, OktaParseError } from "./errors.ts";
8
8
  /**
9
9
  * Error channel shared by every generated Okta operation. Generated service
10
10
  * files annotate operations with `API.OperationMethod<I, O, OktaOpError,
11
11
  * OktaOpContext>` explicitly so the compiler never infers these back out of
12
12
  * the schema generics.
13
13
  */
14
- export type OktaOpError = InstanceType<(typeof API_ERRORS)[number]> | UnknownOktaError | ConfigError | HttpClientError.HttpClientError;
14
+ export type OktaOpError = InstanceType<(typeof API_ERRORS)[number]> | UnknownOktaError | ConfigError | HttpClientError.HttpClientError | OktaParseError;
15
15
  /** Context (requirements) shared by every generated Okta operation. */
16
16
  export type OktaOpContext = Credentials | HttpClient.HttpClient;
17
17
  export declare const OktaProtocol: Layer.Layer<API.Protocol>;
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,KAAK,UAAU,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,KAAK,eAAe,MAAM,sCAAsC,CAAC;AAC7E,OAAO,KAAK,KAAK,GAAG,MAAM,2BAA2B,CAAC;AAKtD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,WAAW,EAA8B,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GACnB,YAAY,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GACzC,gBAAgB,GAChB,WAAW,GACX,eAAe,CAAC,eAAe,CAAC;AAEpC,uEAAuE;AACvE,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AA0BhE,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAuBlD,CAAC"}
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,KAAK,eAAe,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,KAAK,GAAG,MAAM,2BAA2B,CAAC;AAKtD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,WAAW,EAA8B,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GACnB,YAAY,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GACzC,gBAAgB,GAChB,WAAW,GACX,eAAe,CAAC,eAAe,GAC/B,cAAc,CAAC;AAEnB,uEAAuE;AACvE,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AA0BhE,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAwBlD,CAAC"}
package/lib/protocol.js CHANGED
@@ -17,7 +17,7 @@
17
17
  import * as Effect from "effect/Effect";
18
18
  import { makeRestProtocol, } from "@distilled.cloud/core/protocol-rest";
19
19
  import { Credentials, formatHeaders } from "./credentials.js";
20
- import { UnknownOktaError } from "./errors.js";
20
+ import { UnknownOktaError, OktaParseError } from "./errors.js";
21
21
  /**
22
22
  * Okta error bodies are `{ errorCode, errorSummary, errorLink?, errorId?,
23
23
  * errorCauses? }`. A response that arrives without that envelope falls
@@ -60,5 +60,6 @@ export const OktaProtocol = makeRestProtocol({
60
60
  message,
61
61
  body,
62
62
  }),
63
+ parseError: ({ body, cause }) => new OktaParseError({ body, cause }),
63
64
  });
64
65
  //# sourceMappingURL=protocol.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"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1,4 @@
1
+ import { OktaParseError } from "./errors.ts";
2
+ import type { OktaOpError } from "./protocol.ts";
3
+ export declare const parseErrorIsDeclared: [OktaParseError] extends [OktaOpError] ? true : false;
4
+ //# sourceMappingURL=response-validation.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-validation.test.d.ts","sourceRoot":"","sources":["../src/response-validation.test.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA8CjD,eAAO,MAAM,oBAAoB,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC,WAAW,CAAC,GACrE,IAAI,GACJ,KAAY,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { runValidationModes } from "@distilled.cloud/core/testing";
3
+ import * as Effect from "effect/Effect";
4
+ import { fromApiToken } from "./credentials.js";
5
+ import { OktaParseError } from "./errors.js";
6
+ import * as Retry from "./retry.js";
7
+ import { getDRStatus } from "./services/okta.js";
8
+ // getDRStatus declares `{ status?: { domain?: string; isFailedOver?: boolean }[] }`.
9
+ // Its members are all optional, so the mismatch is a wrong primitive.
10
+ const run = (body) => runValidationModes(getDRStatus({}).pipe(Retry.none, Effect.provide(fromApiToken({
11
+ apiToken: "test",
12
+ apiBaseUrl: "https://example.okta.com",
13
+ }))), { body });
14
+ describe("Okta response validation", () => {
15
+ test("a matching body succeeds unchanged in both modes", async () => {
16
+ const body = {
17
+ status: [{ domain: "example.okta.com", isFailedOver: false }],
18
+ };
19
+ const { lenient, strict } = await run(JSON.stringify(body));
20
+ expect(lenient).toMatchObject({ _tag: "Success", success: body });
21
+ expect(strict).toMatchObject({ _tag: "Success", success: body });
22
+ });
23
+ test("a member with the wrong primitive type: lenient returns it, strict fails", async () => {
24
+ const body = {
25
+ status: [{ domain: "example.okta.com", isFailedOver: "no" }],
26
+ };
27
+ const { lenient, strict } = await run(JSON.stringify(body));
28
+ expect(lenient).toMatchObject({ _tag: "Success", success: body });
29
+ expect(strict._tag).toBe("Failure");
30
+ expect(strict.failure).toBeInstanceOf(OktaParseError);
31
+ });
32
+ test("a non-JSON body: lenient returns the text, strict fails", async () => {
33
+ const { lenient, strict } = await run("not json");
34
+ expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
35
+ expect(strict.failure).toBeInstanceOf(OktaParseError);
36
+ });
37
+ });
38
+ // OktaParseError is part of every operation's declared error type.
39
+ export const parseErrorIsDeclared = true;
40
+ //# sourceMappingURL=response-validation.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-validation.test.js","sourceRoot":"","sources":["../src/response-validation.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,qFAAqF;AACrF,sEAAsE;AACtE,MAAM,GAAG,GAAG,CAAC,IAAY,EAAE,EAAE,CAC3B,kBAAkB,CAChB,WAAW,CAAC,EAAE,CAAC,CAAC,IAAI,CAClB,KAAK,CAAC,IAAI,EACV,MAAM,CAAC,OAAO,CACZ,YAAY,CAAC;IACX,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,0BAA0B;CACvC,CAAC,CACH,CACF,EACD,EAAE,IAAI,EAAE,CACT,CAAC;AAEJ,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,IAAI,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;QAClE,MAAM,I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AAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QACxE,MAAM,CAAE,MAAc,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,mEAAmE;AACnE,MAAM,CAAC,MAAM,oBAAoB,GAErB,IAAI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distilled.cloud/okta",
3
- "version": "1.0.0-rc.11",
3
+ "version": "1.0.0-rc.13",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/alchemy-run/distilled",
@@ -64,15 +64,15 @@
64
64
  }
65
65
  },
66
66
  "dependencies": {
67
- "@distilled.cloud/core": "1.0.0-rc.11"
67
+ "@distilled.cloud/core": "1.0.0-rc.13"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@types/bun": "1.3.14",
71
71
  "@types/node": "26.2.0",
72
- "@effect/platform-bun": ">=4.0.0-rc.115 || >=4.0.0"
72
+ "@effect/platform-bun": "^4.0.0"
73
73
  },
74
74
  "peerDependencies": {
75
- "effect": ">=4.0.0-rc.115 || >=4.0.0"
75
+ "effect": "^4.0.0"
76
76
  },
77
77
  "scripts": {
78
78
  "build": "tsc -b",
package/src/protocol.ts CHANGED
@@ -16,8 +16,8 @@
16
16
  */
17
17
  import * as Effect from "effect/Effect";
18
18
  import type * as Layer from "effect/Layer";
19
- import type * as HttpClient from "effect/unstable/http/HttpClient";
20
- import type * as HttpClientError from "effect/unstable/http/HttpClientError";
19
+ import type * as HttpClient from "effect/http/HttpClient";
20
+ import type * as HttpClientError from "effect/http/HttpClientError";
21
21
  import type * as API from "@distilled.cloud/core/api";
22
22
  import {
23
23
  makeRestProtocol,
@@ -25,7 +25,7 @@ import {
25
25
  } from "@distilled.cloud/core/protocol-rest";
26
26
  import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
27
27
  import { Credentials, formatHeaders, type Config } from "./credentials.ts";
28
- import { UnknownOktaError } from "./errors.ts";
28
+ import { UnknownOktaError, OktaParseError } from "./errors.ts";
29
29
 
30
30
  /**
31
31
  * Error channel shared by every generated Okta operation. Generated service
@@ -37,7 +37,8 @@ export type OktaOpError =
37
37
  | InstanceType<(typeof API_ERRORS)[number]>
38
38
  | UnknownOktaError
39
39
  | ConfigError
40
- | HttpClientError.HttpClientError;
40
+ | HttpClientError.HttpClientError
41
+ | OktaParseError;
41
42
 
42
43
  /** Context (requirements) shared by every generated Okta operation. */
43
44
  export type OktaOpContext = Credentials | HttpClient.HttpClient;
@@ -88,5 +89,6 @@ export const OktaProtocol: Layer.Layer<API.Protocol> = makeRestProtocol<Config>(
88
89
  message,
89
90
  body,
90
91
  }),
92
+ parseError: ({ body, cause }) => new OktaParseError({ body, cause }),
91
93
  },
92
94
  );
@@ -0,0 +1,56 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { runValidationModes } from "@distilled.cloud/core/testing";
3
+ import * as Effect from "effect/Effect";
4
+ import { fromApiToken } from "./credentials.ts";
5
+ import { OktaParseError } from "./errors.ts";
6
+ import * as Retry from "./retry.ts";
7
+ import { getDRStatus } from "./services/okta.ts";
8
+ import type { OktaOpError } from "./protocol.ts";
9
+
10
+ // getDRStatus declares `{ status?: { domain?: string; isFailedOver?: boolean }[] }`.
11
+ // Its members are all optional, so the mismatch is a wrong primitive.
12
+ const run = (body: string) =>
13
+ runValidationModes(
14
+ getDRStatus({}).pipe(
15
+ Retry.none,
16
+ Effect.provide(
17
+ fromApiToken({
18
+ apiToken: "test",
19
+ apiBaseUrl: "https://example.okta.com",
20
+ }),
21
+ ),
22
+ ),
23
+ { body },
24
+ );
25
+
26
+ describe("Okta response validation", () => {
27
+ test("a matching body succeeds unchanged in both modes", async () => {
28
+ const body = {
29
+ status: [{ domain: "example.okta.com", isFailedOver: false }],
30
+ };
31
+ const { lenient, strict } = await run(JSON.stringify(body));
32
+ expect(lenient).toMatchObject({ _tag: "Success", success: body });
33
+ expect(strict).toMatchObject({ _tag: "Success", success: body });
34
+ });
35
+
36
+ test("a member with the wrong primitive type: lenient returns it, strict fails", async () => {
37
+ const body = {
38
+ status: [{ domain: "example.okta.com", isFailedOver: "no" }],
39
+ };
40
+ const { lenient, strict } = await run(JSON.stringify(body));
41
+ expect(lenient).toMatchObject({ _tag: "Success", success: body });
42
+ expect(strict._tag).toBe("Failure");
43
+ expect((strict as any).failure).toBeInstanceOf(OktaParseError);
44
+ });
45
+
46
+ test("a non-JSON body: lenient returns the text, strict fails", async () => {
47
+ const { lenient, strict } = await run("not json");
48
+ expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
49
+ expect((strict as any).failure).toBeInstanceOf(OktaParseError);
50
+ });
51
+ });
52
+
53
+ // OktaParseError is part of every operation's declared error type.
54
+ export const parseErrorIsDeclared: [OktaParseError] extends [OktaOpError]
55
+ ? true
56
+ : false = true;