@passlock/node 0.9.30 → 2.0.0-beta.1

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.
Files changed (47) hide show
  1. package/README.md +12 -21
  2. package/README.template.md +11 -20
  3. package/dist/index.d.ts +4 -88
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +2 -80
  6. package/dist/index.js.map +1 -1
  7. package/dist/principal/effect.d.ts +53 -0
  8. package/dist/principal/effect.d.ts.map +1 -0
  9. package/dist/principal/effect.js +78 -0
  10. package/dist/principal/effect.js.map +1 -0
  11. package/dist/principal/index.d.ts +42 -0
  12. package/dist/principal/index.d.ts.map +1 -0
  13. package/dist/principal/index.js +60 -0
  14. package/dist/principal/index.js.map +1 -0
  15. package/dist/shared.d.ts +39 -0
  16. package/dist/shared.d.ts.map +1 -0
  17. package/dist/shared.js +21 -0
  18. package/dist/shared.js.map +1 -0
  19. package/dist/user/effect.d.ts +18 -0
  20. package/dist/user/effect.d.ts.map +1 -0
  21. package/dist/user/effect.js +27 -0
  22. package/dist/user/effect.js.map +1 -0
  23. package/dist/user/index.d.ts +18 -0
  24. package/dist/user/index.d.ts.map +1 -0
  25. package/dist/user/index.js +36 -0
  26. package/dist/user/index.js.map +1 -0
  27. package/package.json +59 -52
  28. package/LICENSE +0 -21
  29. package/dist/config/config.d.ts +0 -9
  30. package/dist/config/config.js +0 -4
  31. package/dist/config/config.js.map +0 -1
  32. package/dist/principal/principal.d.ts +0 -27
  33. package/dist/principal/principal.fixture.d.ts +0 -15
  34. package/dist/principal/principal.fixture.js +0 -67
  35. package/dist/principal/principal.fixture.js.map +0 -1
  36. package/dist/principal/principal.js +0 -88
  37. package/dist/principal/principal.js.map +0 -1
  38. package/dist/tsconfig.tsbuildinfo +0 -1
  39. package/dist/version.d.ts +0 -1
  40. package/dist/version.js +0 -2
  41. package/dist/version.js.map +0 -1
  42. package/src/config/config.ts +0 -10
  43. package/src/index.ts +0 -159
  44. package/src/principal/principal.fixture.ts +0 -107
  45. package/src/principal/principal.test.ts +0 -113
  46. package/src/principal/principal.ts +0 -160
  47. package/src/version.ts +0 -1
package/dist/shared.js ADDED
@@ -0,0 +1,21 @@
1
+ import { Schema } from "effect";
2
+ export class NotFound extends Schema.TaggedError("@error/NotFound")("@error/NotFound", {
3
+ message: Schema.String,
4
+ }) {
5
+ static isNotFound = (payload) => Schema.is(NotFound)(payload);
6
+ }
7
+ // Define a schema for the "Unauthorized" error
8
+ export class Unauthorized extends Schema.TaggedError()("@error/Unauthorized", {}) {
9
+ }
10
+ // Define a schema for the "Unauthorized" error
11
+ export class Forbidden extends Schema.TaggedError()("@error/Forbidden", {}) {
12
+ }
13
+ export class UnexpectedError extends Error {
14
+ _tag;
15
+ constructor(data) {
16
+ super(data.message);
17
+ this._tag = data._tag;
18
+ }
19
+ toString = () => `${this.message} (_tag: ${this._tag})`;
20
+ }
21
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAchC,MAAM,OAAO,QAAS,SAAQ,MAAM,CAAC,WAAW,CAAW,iBAAiB,CAAC,CAC3E,iBAAiB,EACjB;IACE,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CACF;IACC,MAAM,CAAC,UAAU,GAAG,CAAC,OAAgB,EAAuB,EAAE,CAC5D,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC;;AAGjC,+CAA+C;AAC/C,MAAM,OAAO,YAAa,SAAQ,MAAM,CAAC,WAAW,EAAgB,CAClE,qBAAqB,EACrB,EAAE,CACH;CAAG;AAEJ,+CAA+C;AAC/C,MAAM,OAAO,SAAU,SAAQ,MAAM,CAAC,WAAW,EAAa,CAC5D,kBAAkB,EAClB,EAAE,CACH;CAAG;AAEJ,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,IAAI,CAAS;IAEtB,YAAY,IAAuC;QACjD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;IAEiB,QAAQ,GAAG,GAAW,EAAE,CACxC,GAAG,IAAI,CAAC,OAAO,WAAW,IAAI,CAAC,IAAI,GAAG,CAAC;CAC1C","sourcesContent":["import { Schema } from \"effect\";\n\nexport interface ApiOptions {\n tenancyId: string;\n /**\n * @default https://api.passlock.dev\n */\n endpoint?: string;\n}\n\nexport interface AuthorizedApiOptions extends ApiOptions {\n apiKey: string;\n}\n\nexport class NotFound extends Schema.TaggedError<NotFound>(\"@error/NotFound\")(\n \"@error/NotFound\",\n {\n message: Schema.String,\n },\n) {\n static isNotFound = (payload: unknown): payload is NotFound =>\n Schema.is(NotFound)(payload);\n}\n\n// Define a schema for the \"Unauthorized\" error\nexport class Unauthorized extends Schema.TaggedError<Unauthorized>()(\n \"@error/Unauthorized\",\n {},\n) {}\n\n// Define a schema for the \"Unauthorized\" error\nexport class Forbidden extends Schema.TaggedError<Forbidden>()(\n \"@error/Forbidden\",\n {},\n) {}\n\nexport class UnexpectedError extends Error {\n readonly _tag: string;\n\n constructor(data: { _tag: string; message: string }) {\n super(data.message);\n this._tag = data._tag;\n }\n\n override readonly toString = (): string =>\n `${this.message} (_tag: ${this._tag})`;\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import { HttpClient } from "@effect/platform";
2
+ import type { RequestError, ResponseError } from "@effect/platform/HttpClientError";
3
+ import type { HttpBodyError } from "@effect/platform/HttpBody";
4
+ import { Effect, Schema } from "effect";
5
+ import type { ParseError } from "effect/ParseResult";
6
+ import { Forbidden, NotFound, type AuthorizedApiOptions } from "../shared.js";
7
+ export declare const AssignedUser: Schema.Struct<{
8
+ userId: typeof Schema.String;
9
+ authenticatorId: typeof Schema.String;
10
+ updatedAt: typeof Schema.DateFromNumber;
11
+ }>;
12
+ export type AssignedUser = typeof AssignedUser.Type;
13
+ export interface AssignUserOptions extends AuthorizedApiOptions {
14
+ userId: string;
15
+ authenticatorId: string;
16
+ }
17
+ export declare const assignUser: (options: AssignUserOptions) => Effect.Effect<AssignedUser, NotFound | Forbidden | ParseError | RequestError | HttpBodyError | ResponseError, HttpClient.HttpClient>;
18
+ //# sourceMappingURL=effect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../src/user/effect.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAGX,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACd,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,EAAE,MAAM,EAAe,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAE9E,eAAO,MAAM,YAAY;;;;EAIvB,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAC;AASpD,MAAM,WAAW,iBAAkB,SAAQ,oBAAoB;IAC7D,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,UAAU,GACrB,SAAS,iBAAiB,KACzB,MAAM,CAAC,MAAM,CACd,YAAY,EACV,QAAQ,GACR,SAAS,GACT,UAAU,GACV,YAAY,GACZ,aAAa,GACb,aAAa,EACf,UAAU,CAAC,UAAU,CAmCnB,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { HttpClient, HttpClientRequest, HttpClientResponse, } from "@effect/platform";
2
+ import { Effect, Match, pipe, Schema } from "effect";
3
+ import { Forbidden, NotFound } from "../shared.js";
4
+ export const AssignedUser = Schema.Struct({
5
+ userId: Schema.String,
6
+ authenticatorId: Schema.String,
7
+ updatedAt: Schema.DateFromNumber,
8
+ });
9
+ const AssignUserResponse = Schema.Struct({
10
+ _tag: Schema.tag("Success"),
11
+ data: AssignedUser,
12
+ });
13
+ export const assignUser = (options) => Effect.gen(function* () {
14
+ const client = yield* HttpClient.HttpClient;
15
+ const baseUrl = options.endpoint ?? "https://api.passlock.dev";
16
+ const { userId, authenticatorId } = options;
17
+ const url = new URL(`/${options.tenancyId}/authenticator/${authenticatorId}`, baseUrl);
18
+ const response = yield* HttpClientRequest.patch(url, {
19
+ headers: { Authorization: `Bearer ${options.apiKey}` },
20
+ }).pipe(HttpClientRequest.bodyJson({ userId }), Effect.flatMap(client.execute));
21
+ const encoded = yield* HttpClientResponse.matchStatus(response, {
22
+ "2xx": () => HttpClientResponse.schemaBodyJson(AssignUserResponse)(response),
23
+ orElse: () => HttpClientResponse.schemaBodyJson(Schema.Union(NotFound, Forbidden))(response),
24
+ });
25
+ return yield* pipe(Match.value(encoded), Match.tag("Success", ({ data }) => Effect.succeed(data)), Match.tag("@error/NotFound", (err) => Effect.fail(err)), Match.tag("@error/Forbidden", (err) => Effect.fail(err)), Match.exhaustive);
26
+ });
27
+ //# sourceMappingURL=effect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect.js","sourceRoot":"","sources":["../../src/user/effect.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAA6B,MAAM,cAAc,CAAC;AAE9E,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,eAAe,EAAE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QAAQ,CACT;KACJ,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,CAAC,IAAI,CAChB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EACpB,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EACxD,KAAK,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACvD,KAAK,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACxD,KAAK,CAAC,UAAU,CACjB,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import {\n HttpClient,\n HttpClientRequest,\n HttpClientResponse,\n} from \"@effect/platform\";\n\nimport type {\n RequestError,\n ResponseError,\n} from \"@effect/platform/HttpClientError\";\n\nimport type { HttpBodyError } from \"@effect/platform/HttpBody\";\n\nimport { Effect, Match, pipe, Schema } from \"effect\";\nimport type { ParseError } from \"effect/ParseResult\";\nimport { Forbidden, NotFound, type AuthorizedApiOptions } from \"../shared.js\";\n\nexport const AssignedUser = Schema.Struct({\n userId: Schema.String,\n authenticatorId: Schema.String,\n updatedAt: Schema.DateFromNumber,\n});\n\nexport type AssignedUser = typeof AssignedUser.Type;\n\nconst AssignUserResponse = Schema.Struct({\n _tag: Schema.tag(\"Success\"),\n data: AssignedUser,\n});\n\ntype AssignUserResponse = typeof AssignUserResponse.Type;\n\nexport interface AssignUserOptions extends AuthorizedApiOptions {\n userId: string;\n authenticatorId: string;\n}\n\nexport const assignUser = (\n options: AssignUserOptions,\n): Effect.Effect<\n AssignedUser,\n | NotFound\n | Forbidden\n | ParseError\n | RequestError\n | HttpBodyError\n | ResponseError,\n HttpClient.HttpClient\n> =>\n Effect.gen(function* () {\n const client = yield* HttpClient.HttpClient;\n const baseUrl = options.endpoint ?? \"https://api.passlock.dev\";\n const { userId, authenticatorId } = options;\n\n const url = new URL(\n `/${options.tenancyId}/authenticator/${authenticatorId}`,\n baseUrl,\n );\n\n const response = yield* HttpClientRequest.patch(url, {\n headers: { Authorization: `Bearer ${options.apiKey}` },\n }).pipe(\n HttpClientRequest.bodyJson({ userId }),\n Effect.flatMap(client.execute),\n );\n\n const encoded = yield* HttpClientResponse.matchStatus(response, {\n \"2xx\": () =>\n HttpClientResponse.schemaBodyJson(AssignUserResponse)(response),\n orElse: () =>\n HttpClientResponse.schemaBodyJson(Schema.Union(NotFound, Forbidden))(\n response,\n ),\n });\n\n return yield* pipe(\n Match.value(encoded),\n Match.tag(\"Success\", ({ data }) => Effect.succeed(data)),\n Match.tag(\"@error/NotFound\", (err) => Effect.fail(err)),\n Match.tag(\"@error/Forbidden\", (err) => Effect.fail(err)),\n Match.exhaustive,\n );\n });\n"]}
@@ -0,0 +1,18 @@
1
+ import { type Forbidden, type NotFound } from "../shared.js";
2
+ import type { AssignedUser, AssignUserOptions } from "./effect.js";
3
+ export { type AssignedUser, type AssignUserOptions as AssignUserRequest, } from "./effect.js";
4
+ /**
5
+ * Call the Passlock backend API to assign a userId to an authenticator
6
+ * @param request
7
+ * @param options
8
+ * @returns
9
+ */
10
+ export declare const assignUser: (options: AssignUserOptions) => Promise<AssignedUser | NotFound | Forbidden>;
11
+ /**
12
+ * Call the Passlock backend API to assign a userId to an authenticator
13
+ * @param request
14
+ * @param options
15
+ * @returns
16
+ */
17
+ export declare const assignUserUnsafe: (options: AssignUserOptions) => Promise<AssignedUser>;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/user/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAmB,MAAM,cAAc,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGnE,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,iBAAiB,IAAI,iBAAiB,GAC5C,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GACrB,SAAS,iBAAiB,KACzB,OAAO,CAAC,YAAY,GAAG,QAAQ,GAAG,SAAS,CAkB3C,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAC3B,SAAS,iBAAiB,KACzB,OAAO,CAAC,YAAY,CAiBpB,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { FetchHttpClient } from "@effect/platform";
2
+ import { Effect, identity, pipe } from "effect";
3
+ import { UnexpectedError } from "../shared.js";
4
+ import { assignUser as assignUserE } from "./effect.js";
5
+ export {} from "./effect.js";
6
+ /**
7
+ * Call the Passlock backend API to assign a userId to an authenticator
8
+ * @param request
9
+ * @param options
10
+ * @returns
11
+ */
12
+ export const assignUser = (options) => pipe(assignUserE(options), Effect.provide(FetchHttpClient.layer), Effect.catchTags({
13
+ HttpBodyError: (err) => Effect.die(new UnexpectedError({
14
+ message: "Invalid request payload",
15
+ _tag: err.reason._tag,
16
+ })),
17
+ ParseError: (err) => Effect.die(new UnexpectedError(err)),
18
+ RequestError: (err) => Effect.die(new UnexpectedError(err)),
19
+ ResponseError: (err) => Effect.die(new UnexpectedError(err)),
20
+ }), Effect.match({ onFailure: identity, onSuccess: identity }), Effect.runPromise);
21
+ /**
22
+ * Call the Passlock backend API to assign a userId to an authenticator
23
+ * @param request
24
+ * @param options
25
+ * @returns
26
+ */
27
+ export const assignUserUnsafe = (options) => pipe(assignUserE(options), Effect.provide(FetchHttpClient.layer), Effect.catchTags({
28
+ HttpBodyError: (err) => Effect.die(new UnexpectedError({
29
+ message: "Invalid request payload",
30
+ _tag: err.reason._tag,
31
+ })),
32
+ ParseError: (err) => Effect.die(new UnexpectedError(err)),
33
+ RequestError: (err) => Effect.die(new UnexpectedError(err)),
34
+ ResponseError: (err) => Effect.die(new UnexpectedError(err)),
35
+ }), Effect.runPromise);
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/user/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAiC,eAAe,EAAE,MAAM,cAAc,CAAC;AAE9E,OAAO,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAGN,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,OAA0B,EACoB,EAAE,CAChD,IAAI,CACF,WAAW,CAAC,OAAO,CAAC,EACpB,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,EACrC,MAAM,CAAC,SAAS,CAAC;IACf,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CACrB,MAAM,CAAC,GAAG,CACR,IAAI,eAAe,CAAC;QAClB,OAAO,EAAE,yBAAyB;QAClC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI;KACtB,CAAC,CACH;IACH,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC;IACzD,YAAY,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC;IAC3D,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC;CAC7D,CAAC,EACF,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAC1D,MAAM,CAAC,UAAU,CAClB,CAAC;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,OAA0B,EACH,EAAE,CACzB,IAAI,CACF,WAAW,CAAC,OAAO,CAAC,EACpB,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,EACrC,MAAM,CAAC,SAAS,CAAC;IACf,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CACrB,MAAM,CAAC,GAAG,CACR,IAAI,eAAe,CAAC;QAClB,OAAO,EAAE,yBAAyB;QAClC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI;KACtB,CAAC,CACH;IACH,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC;IACzD,YAAY,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC;IAC3D,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC;CAC7D,CAAC,EACF,MAAM,CAAC,UAAU,CAClB,CAAC","sourcesContent":["import { FetchHttpClient } from \"@effect/platform\";\nimport { Effect, identity, pipe } from \"effect\";\nimport { type Forbidden, type NotFound, UnexpectedError } from \"../shared.js\";\nimport type { AssignedUser, AssignUserOptions } from \"./effect.js\";\nimport { assignUser as assignUserE } from \"./effect.js\";\n\nexport {\n type AssignedUser,\n type AssignUserOptions as AssignUserRequest,\n} from \"./effect.js\";\n\n/**\n * Call the Passlock backend API to assign a userId to an authenticator\n * @param request\n * @param options\n * @returns\n */\nexport const assignUser = (\n options: AssignUserOptions,\n): Promise<AssignedUser | NotFound | Forbidden> =>\n pipe(\n assignUserE(options),\n Effect.provide(FetchHttpClient.layer),\n Effect.catchTags({\n HttpBodyError: (err) =>\n Effect.die(\n new UnexpectedError({\n message: \"Invalid request payload\",\n _tag: err.reason._tag,\n }),\n ),\n ParseError: (err) => Effect.die(new UnexpectedError(err)),\n RequestError: (err) => Effect.die(new UnexpectedError(err)),\n ResponseError: (err) => Effect.die(new UnexpectedError(err)),\n }),\n Effect.match({ onFailure: identity, onSuccess: identity }),\n Effect.runPromise,\n );\n\n/**\n * Call the Passlock backend API to assign a userId to an authenticator\n * @param request\n * @param options\n * @returns\n */\nexport const assignUserUnsafe = (\n options: AssignUserOptions,\n): Promise<AssignedUser> =>\n pipe(\n assignUserE(options),\n Effect.provide(FetchHttpClient.layer),\n Effect.catchTags({\n HttpBodyError: (err) =>\n Effect.die(\n new UnexpectedError({\n message: \"Invalid request payload\",\n _tag: err.reason._tag,\n }),\n ),\n ParseError: (err) => Effect.die(new UnexpectedError(err)),\n RequestError: (err) => Effect.die(new UnexpectedError(err)),\n ResponseError: (err) => Effect.die(new UnexpectedError(err)),\n }),\n Effect.runPromise,\n );\n"]}
package/package.json CHANGED
@@ -1,83 +1,90 @@
1
1
  {
2
2
  "name": "@passlock/node",
3
- "type": "module",
4
- "version": "0.9.30",
5
- "description": "Passkey authentication and social login for node.js/express apps",
3
+ "version": "2.0.0-beta.1",
4
+ "description": "Passkey authentication for NodeJS backends",
6
5
  "keywords": [
7
6
  "passkey",
8
- "passkeys",
9
7
  "webauthn",
10
- "node",
11
- "express"
8
+ "node"
12
9
  ],
13
- "author": {
14
- "name": "Toby Hobson",
15
- "email": "toby@passlock.dev"
16
- },
17
- "license": "MIT",
18
10
  "homepage": "https://passlock.dev",
11
+ "bugs": {
12
+ "url": "https://github.com/passlock-dev/passlock/issues",
13
+ "email": "team@passlock.dev"
14
+ },
19
15
  "repository": {
20
16
  "type": "git",
21
17
  "url": "git+https://github.com/passlock-dev/passlock.git",
22
- "directory": "packages/node"
18
+ "directory": "packages/client"
23
19
  },
24
- "bugs": {
25
- "url": "https://github.com/passlock-dev/passlock/issues",
26
- "email": "team@passlock.dev"
20
+ "license": "MIT",
21
+ "author": {
22
+ "name": "Toby Hobson",
23
+ "email": "toby@passlock.dev"
27
24
  },
25
+ "type": "module",
28
26
  "exports": {
29
27
  ".": {
30
28
  "types": "./dist/index.d.ts",
31
- "import": "./dist/index.js"
29
+ "import": "./dist/index.js",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "./principal": {
33
+ "types": "./dist/principal/index.d.ts",
34
+ "import": "./dist/principal/index.js",
35
+ "default": "./dist/principal/index.js"
36
+ },
37
+ "./user": {
38
+ "types": "./dist/user/index.d.ts",
39
+ "import": "./dist/user/index.js",
40
+ "default": "./dist/user/index.js"
32
41
  }
33
42
  },
43
+ "module": "./dist/index.js",
44
+ "types": "./dist/index.d.ts",
34
45
  "files": [
35
- "src",
36
46
  "dist",
37
47
  "!dist/**/*.test.*",
38
48
  "!dist/**/*.spec.*"
39
49
  ],
40
50
  "dependencies": {
41
- "effect": "3.8.4",
42
- "@passlock/shared": "0.9.30"
51
+ "@effect/platform": "^0.93.6",
52
+ "@effect/platform-node": "^0.103.0",
53
+ "effect": "3.19.8",
54
+ "jose": "^6.1.3"
43
55
  },
44
56
  "devDependencies": {
45
- "@effect/schema": "0.74.1",
46
- "@qetza/replacetokens": "^1.7.0",
47
- "@total-typescript/tsconfig": "^1.0.4",
48
- "@trivago/prettier-plugin-sort-imports": "^4.3.0",
49
- "@tsconfig/node20": "^20.1.4",
50
- "@types/node": "^22.7.4",
51
- "@typescript-eslint/eslint-plugin": "^8.8.0",
52
- "@typescript-eslint/parser": "^8.8.0",
53
- "@vitest/coverage-v8": "^2.1.2",
54
- "@vitest/ui": "^2.1.2",
55
- "eslint": "^9.12.0",
56
- "eslint-config-prettier": "^9.1.0",
57
- "globals": "^15.10.0",
58
- "prettier": "^3.3.3",
59
- "publint": "^0.2.11",
60
- "rimraf": "^6.0.1",
61
- "tsx": "^4.19.1",
62
- "typescript": "^5.6.2",
63
- "vite": "^5.4.8",
64
- "vitest": "^2.1.2"
57
+ "@eslint/compat": "^2.0.0",
58
+ "@eslint/js": "^9.39.1",
59
+ "@types/node": "^24.10.1",
60
+ "eslint": "^9.39.1",
61
+ "globals": "^16.5.0",
62
+ "npm-check-updates": "19.1.2",
63
+ "prettier": "^3.7.4",
64
+ "publint": "0.3.15",
65
+ "rimraf": "^6.1.2",
66
+ "tsx": "4.21.0",
67
+ "typescript": "^5.9.3",
68
+ "typescript-eslint": "^8.48.1"
69
+ },
70
+ "engines": {
71
+ "node": ">=21"
65
72
  },
66
73
  "scripts": {
67
- "clean": "rimraf ./dist",
68
- "typecheck": "tsc --noEmit",
74
+ "build": "tsc --build",
75
+ "build:clean": "$npm_execpath run clean:full && $npm_execpath run build",
76
+ "build:production": "$npm_execpath run build:clean && $npm_execpath run build:readme && $npm_execpath run replaceTokens && echo '' && publint",
77
+ "build:readme": "LATEST=${npm_package_version} tsx ../../scripts/replace-readme-tokens.ts ./packages/node",
78
+ "clean": "tsc --build --clean",
79
+ "clean:full": "rimraf dist tsconfig.tsbuildinfo",
80
+ "format": "prettier --write \"src/**/*.+(js|ts|json)\"",
81
+ "lint": "prettier --check \"src/**/*.+(js|ts|json)\" && eslint ./src",
82
+ "lint:fix": "prettier --check \"src/**/*.+(js|ts|json)\" && eslint ./src --fix",
83
+ "replaceTokens": "LATEST=${npm_package_version} tsx ../../scripts/replace-tokens.ts ./packages/node",
69
84
  "test": "vitest run",
70
- "test:watch": "vitest dev",
71
- "test:ui": "vitest --coverage.enabled=true --ui",
72
85
  "test:coverage": "vitest run --coverage",
73
- "build": "tsc --build",
74
- "build:clean": "pnpm run clean && pnpm run build",
75
- "build:readme": "LATEST=${npm_package_version} tsx ../shared/scripts/replace-readme-tokens.ts ./packages/node",
76
- "replaceTokens": "LATEST=${npm_package_version} tsx ../shared/scripts/replace-tokens.ts ./packages/node",
77
- "build:production": "pnpm run build:clean && pnpm run build:readme && pnpm run replaceTokens && echo '' && publint",
78
- "format": "prettier --write \"(src|scripts)/**/*.+(js|ts|json)\"",
79
- "lint": "eslint ./src",
80
- "lint:fix": "pnpm run lint --fix",
81
- "upgrade:deps": "ncu --peer -x effect -x @effect/* -i -u"
86
+ "test:ui": "vitest --coverage.enabled=true --ui",
87
+ "test:watch": "vitest dev",
88
+ "typecheck": "tsc --noEmit"
82
89
  }
83
90
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Passlock
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,9 +0,0 @@
1
- import { Context } from 'effect';
2
- declare const Config_base: Context.TagClass<Config, "Config", {
3
- readonly tenancyId: string;
4
- readonly apiKey: string;
5
- readonly endpoint?: string;
6
- }>;
7
- export declare class Config extends Config_base {
8
- }
9
- export {};
@@ -1,4 +0,0 @@
1
- import { Context } from 'effect';
2
- export class Config extends Context.Tag('Config')() {
3
- }
4
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAEhC,MAAM,OAAO,MAAO,SAAQ,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAO9C;CAAG"}
@@ -1,27 +0,0 @@
1
- import * as https from 'https';
2
- import { Context, Effect as E, Layer, Stream } from 'effect';
3
- import { Forbidden, InternalServerError, NotFound, Unauthorized } from '@passlock/shared/dist/error/error.js';
4
- import { Principal } from '@passlock/shared/dist/schema/principal.js';
5
- import { Config } from '../config/config.js';
6
- declare const StreamResponse_base: Context.TagClass<StreamResponse, "@services/StreamResponse", {
7
- streamResponse: (options: https.RequestOptions) => Stream.Stream<Buffer, PrincipalErrors>;
8
- }>;
9
- export declare class StreamResponse extends StreamResponse_base {
10
- }
11
- export type PrincipalErrors = NotFound | Unauthorized | Forbidden | InternalServerError;
12
- export type PrincipalRequest = {
13
- token: string;
14
- };
15
- declare const PrincipalService_base: Context.TagClass<PrincipalService, "@services/PrincipalService", {
16
- fetchPrincipal: (request: PrincipalRequest) => E.Effect<Principal, PrincipalErrors>;
17
- }>;
18
- export declare class PrincipalService extends PrincipalService_base {
19
- }
20
- export declare const buildError: (res: {
21
- statusCode?: number | undefined;
22
- statusMessage?: string | undefined;
23
- }) => NotFound | Unauthorized | Forbidden | InternalServerError;
24
- export declare const fetchPrincipal: (request: PrincipalRequest) => E.Effect<Principal, PrincipalErrors, StreamResponse | Config>;
25
- export declare const StreamResponseLive: Layer.Layer<StreamResponse, never, never>;
26
- export declare const PrincipalServiceLive: Layer.Layer<PrincipalService, never, Config | StreamResponse>;
27
- export {};
@@ -1,15 +0,0 @@
1
- import { Context, Effect as E, Layer as L, Ref } from 'effect';
2
- import type { RequestOptions } from 'https';
3
- import { Principal } from '@passlock/shared/dist/schema/principal.js';
4
- import { Config } from '../config/config.js';
5
- import { type PrincipalService } from './principal.js';
6
- export declare const principal: Principal;
7
- export declare const tenancyId = "tenancyId";
8
- export declare const apiKey = "apiKey";
9
- export declare const configTest: L.Layer<Config, never, never>;
10
- declare const State_base: Context.TagClass<State, "State", Ref.Ref<RequestOptions | undefined>>;
11
- export declare class State extends State_base {
12
- }
13
- export declare const buildEffect: <A, E>(assertions: E.Effect<A, E, PrincipalService | State>) => E.Effect<void, E>;
14
- export declare const buildErrorEffect: (statusCode: number) => <A>(assertions: E.Effect<void, A, PrincipalService>) => E.Effect<void, A>;
15
- export {};
@@ -1,67 +0,0 @@
1
- import * as S from '@effect/schema/Schema';
2
- import { Context, Effect as E, Layer as L, LogLevel, Logger, Ref, Stream, pipe } from 'effect';
3
- import { Principal } from '@passlock/shared/dist/schema/principal.js';
4
- import { Config } from '../config/config.js';
5
- import { PrincipalServiceLive, StreamResponse, buildError, } from './principal.js';
6
- export const principal = {
7
- jti: 'token',
8
- token: 'token',
9
- sub: 'user-1',
10
- iss: 'idp.passlock.dev',
11
- aud: 'tenancy_id',
12
- // must be at least 1 second
13
- // as it's truncated to seconds
14
- iat: new Date(60 * 1000),
15
- nbf: new Date(120 * 100),
16
- exp: new Date(180 * 1000),
17
- email: 'john.doe@gmail.com',
18
- givenName: 'john',
19
- familyName: 'doe',
20
- emailVerified: false,
21
- authType: 'passkey',
22
- authId: 'auth-1',
23
- userVerified: true,
24
- // legacy
25
- user: {
26
- id: 'user-1',
27
- givenName: 'john',
28
- familyName: 'doe',
29
- email: 'john.doe@gmail.com',
30
- emailVerified: false,
31
- },
32
- authStatement: {
33
- authType: 'passkey',
34
- userVerified: false,
35
- authTimestamp: new Date(0),
36
- },
37
- expireAt: new Date(0),
38
- };
39
- export const tenancyId = 'tenancyId';
40
- export const apiKey = 'apiKey';
41
- export const configTest = L.succeed(Config, Config.of({ tenancyId, apiKey }));
42
- export class State extends Context.Tag('State')() {
43
- }
44
- export const buildEffect = (assertions) => {
45
- const streamResponseTest = L.effect(StreamResponse, E.gen(function* (_) {
46
- const ref = yield* _(State);
47
- const res = S.encodeSync(Principal)(principal);
48
- const buff = Buffer.from(JSON.stringify(res));
49
- return {
50
- streamResponse: options => pipe(Stream.fromEffect(Ref.set(ref, options)), Stream.zipRight(Stream.make(buff))),
51
- };
52
- }));
53
- const service = pipe(PrincipalServiceLive, L.provide(streamResponseTest), L.provide(configTest));
54
- const args = L.effect(State, Ref.make(undefined));
55
- const effect = pipe(E.provide(assertions, service), E.provide(args), Logger.withMinimumLogLevel(LogLevel.None));
56
- return effect;
57
- };
58
- export const buildErrorEffect = (statusCode) => (assertions) => {
59
- const streamResponseTest = L.succeed(StreamResponse, StreamResponse.of({
60
- streamResponse: () => Stream.fail(buildError({ statusCode })),
61
- }));
62
- const service = pipe(PrincipalServiceLive, L.provide(streamResponseTest), L.provide(configTest));
63
- const args = L.effect(State, Ref.make(undefined));
64
- const effect = pipe(E.provide(assertions, service), E.provide(args), Logger.withMinimumLogLevel(LogLevel.None));
65
- return effect;
66
- };
67
- //# sourceMappingURL=principal.fixture.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"principal.fixture.js","sourceRoot":"","sources":["../../src/principal/principal.fixture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,uBAAuB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAG9F,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAA;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAEL,oBAAoB,EACpB,cAAc,EACd,UAAU,GACX,MAAM,gBAAgB,CAAA;AAEvB,MAAM,CAAC,MAAM,SAAS,GAAc;IAClC,GAAG,EAAE,OAAO;IACZ,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,kBAAkB;IACvB,GAAG,EAAE,YAAY;IAC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I,CAAC,UAAU,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;KAC9D,CAAC,CACH,CAAA;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;IAEhG,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAA6B,SAAS,CAAC,CAAC,CAAA;IAE7E,MAAM,MAAM,GAAG,IAAI,CACjB,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,EAC9B,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EACf,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAC1C,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
@@ -1,88 +0,0 @@
1
- import * as https from 'https';
2
- import { Chunk, Console, Context, Effect as E, Layer, Option, Stream, flow, pipe } from 'effect';
3
- import { Forbidden, InternalServerError, NotFound, Unauthorized, } from '@passlock/shared/dist/error/error.js';
4
- import { Principal } from '@passlock/shared/dist/schema/principal.js';
5
- import { createParser } from '@passlock/shared/dist/schema/utils.js';
6
- import { Config } from '../config/config.js';
7
- import { PASSLOCK_CLIENT_VERSION } from '../version.js';
8
- /* Dependencies */
9
- export class StreamResponse extends Context.Tag('@services/StreamResponse')() {
10
- }
11
- /* Service */
12
- const parsePrincipal = createParser(Principal);
13
- export class PrincipalService extends Context.Tag('@services/PrincipalService')() {
14
- }
15
- /* Effects */
16
- const buildHostname = (endpoint) => {
17
- return new URL(endpoint || 'https://api.passlock.dev').hostname;
18
- };
19
- const buildOptions = (token) => pipe(Config, E.map(({ endpoint, tenancyId, apiKey }) => ({
20
- hostname: buildHostname(endpoint),
21
- port: 443,
22
- path: `/${tenancyId}/token/${token}`,
23
- method: 'GET',
24
- headers: {
25
- 'Accept': 'application/json',
26
- 'Authorization': `Bearer ${apiKey}`,
27
- 'X-PASSLOCK-CLIENT-VERSION': PASSLOCK_CLIENT_VERSION,
28
- },
29
- })));
30
- export const buildError = (res) => {
31
- if (res.statusCode === 404)
32
- return new NotFound({ message: 'Invalid token' });
33
- if (res.statusCode === 401)
34
- return new Unauthorized({ message: 'Unauthorized' });
35
- if (res.statusCode === 403)
36
- return new Forbidden({ message: 'Forbidden' });
37
- if (res.statusCode && res.statusMessage)
38
- return new InternalServerError({ message: `${String(res.statusCode)} - ${res.statusMessage}` });
39
- if (res.statusCode)
40
- return new InternalServerError({ message: String(res.statusCode) });
41
- if (res.statusMessage)
42
- return new InternalServerError({ message: res.statusMessage });
43
- return new InternalServerError({ message: 'Received non 200 response' });
44
- };
45
- const fail = (error) => E.fail(Option.some(error));
46
- const succeed = (data) => E.succeed(Chunk.of(data));
47
- const close = E.fail(Option.none());
48
- const buildStream = (token) => pipe(Stream.fromEffect(buildOptions(token)), Stream.zip(StreamResponse), Stream.flatMap(([options, { streamResponse }]) => streamResponse(options)));
49
- export const fetchPrincipal = (request) => {
50
- const stream = buildStream(request.token);
51
- const json = pipe(Stream.runCollect(stream), E.map(Chunk.toReadonlyArray), E.map(buffers => Buffer.concat(buffers)), E.flatMap(buffer => E.try({
52
- try: () => buffer.toString(),
53
- catch: e => new InternalServerError({
54
- message: 'Unable to convert response to string',
55
- detail: String(e),
56
- }),
57
- })), E.flatMap(buffer => E.try({
58
- try: () => JSON.parse(buffer),
59
- catch: e => new InternalServerError({
60
- message: 'Unable to parse response to json',
61
- detail: String(e),
62
- }),
63
- })), E.flatMap(json => pipe(parsePrincipal(json), E.tapError(error => Console.error(error.detail)), E.mapError(() => new InternalServerError({ message: 'Unable to parse response as Principal' })))));
64
- return json;
65
- };
66
- /* Live */
67
- /* v8 ignore start */
68
- export const StreamResponseLive = Layer.succeed(StreamResponse, {
69
- streamResponse: options => Stream.async((emit) => {
70
- https
71
- .request(options, res => {
72
- if (200 !== res.statusCode)
73
- void emit(fail(buildError(res)));
74
- res.on('data', (data) => void emit(succeed(data)));
75
- res.on('close', () => void emit(close));
76
- res.on('error', e => void emit(fail(new InternalServerError({ message: e.message }))));
77
- })
78
- .end();
79
- }),
80
- });
81
- export const PrincipalServiceLive = Layer.effect(PrincipalService, E.gen(function* (_) {
82
- const context = yield* _(E.context());
83
- return PrincipalService.of({
84
- fetchPrincipal: flow(fetchPrincipal, E.provide(context)),
85
- });
86
- }));
87
- /* v8 ignore stop */
88
- //# sourceMappingURL=principal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"principal.js","sourceRoot":"","sources":["../../src/principal/principal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAEhG,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,QAAQ,EACR,YAAY,GACb,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAA;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAA;AAEpE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAEvD,kBAAkB;AAElB,MAAM,OAAO,cAAe,SAAQ,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,EAKxE;CAAG;AAEN,aAAa;AAEb,MAAM,cAAc,GAAG,YAAY,CAAC,SAAS,CAAC,CAAA;AAK9C,MAAM,OAAO,gBAAiB,SAAQ,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,EAK5E;CAAG;AAEN,aAAa;AAEb,MAAM,aAAa,GAAG,CAAC,QAA4B,EAAE,EAAE;IACrD,OAAO,I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GAAG,CAAC,EAAE;YACtB,IAAI,GAAG,KAAK,GAAG,CAAC,UAAU;gBAAE,KAAK,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;YAC5D,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YAC1D,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;YACvC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,mBAAmB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;QACxF,CAAC,CAAC;aACD,GAAG,EAAE,CAAA;IACV,CAAC,CAAC;CACL,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC,MAAM,CAC9C,gBAAgB,EAChB,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;IAChB,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAA2B,CAAC,CAAA;IAC9D,OAAO,gBAAgB,CAAC,EAAE,CAAC;QACzB,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;KACzD,CAAC,CAAA;AACJ,CAAC,CAAC,CACH,CAAA;AACD,oBAAoB"}
@@ -1 +0,0 @@
1
- {"root":["../src/index.ts","../src/version.ts","../src/config/config.ts","../src/principal/principal.fixture.ts","../src/principal/principal.test.ts","../src/principal/principal.ts"],"version":"5.6.2"}
package/dist/version.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const PASSLOCK_CLIENT_VERSION = "0.9.30";
package/dist/version.js DELETED
@@ -1,2 +0,0 @@
1
- export const PASSLOCK_CLIENT_VERSION = '0.9.30';
2
- //# sourceMappingURL=version.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uBAAuB,GAAG,YAAY,CAAA"}
@@ -1,10 +0,0 @@
1
- import { Context } from 'effect'
2
-
3
- export class Config extends Context.Tag('Config')<
4
- Config,
5
- {
6
- readonly tenancyId: string
7
- readonly apiKey: string
8
- readonly endpoint?: string
9
- }
10
- >() {}