@passlock/node 0.9.21 → 0.9.23
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 +51 -0
- package/dist/config/config.d.ts +0 -1
- package/dist/index.d.ts +34 -7
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/principal/principal.d.ts +10 -6
- package/dist/principal/principal.fixture.d.ts +2 -3
- package/dist/principal/principal.fixture.js +34 -10
- package/dist/principal/principal.fixture.js.map +1 -1
- package/dist/principal/principal.js +19 -9
- package/dist/principal/principal.js.map +1 -1
- package/dist/version.d.ts +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/package.json +38 -28
- package/src/index.ts +18 -11
- package/src/principal/principal.fixture.ts +41 -14
- package/src/principal/principal.test.ts +4 -4
- package/src/principal/principal.ts +37 -30
- package/src/version.ts +1 -0
- package/dist/config/config.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/principal/principal.d.ts.map +0 -1
- package/dist/principal/principal.fixture.d.ts.map +0 -1
- package/dist/principal/principal.test.d.ts +0 -2
- package/dist/principal/principal.test.d.ts.map +0 -1
- package/dist/principal/principal.test.js +0 -81
- package/dist/principal/principal.test.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://github.com/passlock-dev/ts-clients">
|
|
3
|
+
<img src="https://github.com/passlock-dev/passkeys-frontend/assets/208345/53ee00d3-8e6c-49ea-b43c-3f901450c73b" alt="Passlock logo" width="80" height="80">
|
|
4
|
+
</a>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<div>
|
|
8
|
+
<h1 align="center">Passkeys, Social Login & more <br /> for Node.js apps</h1>
|
|
9
|
+
<p align="center">
|
|
10
|
+
Node SDK for Passkey authentication, Social Login using Apple, Google and more...
|
|
11
|
+
<br />
|
|
12
|
+
<a href="https://passlock.dev"><strong>Project website »</strong></a>
|
|
13
|
+
<br />
|
|
14
|
+
<a href="https://github.com/passlock-dev/ts-clients">GitHub</a>
|
|
15
|
+
·
|
|
16
|
+
<a href="https://passlock.dev/#demo">Demo</a>
|
|
17
|
+
·
|
|
18
|
+
<a href="https://docs.passlock.dev">Documentation</a>
|
|
19
|
+
·
|
|
20
|
+
<a href="https://docs.passlock.dev/docs/tutorial/introduction">Tutorial</a>
|
|
21
|
+
</p>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
<br />
|
|
25
|
+
|
|
26
|
+
## See also
|
|
27
|
+
|
|
28
|
+
For frontend usage please see the accompanying [@passlock/client][client] package
|
|
29
|
+
|
|
30
|
+
## Requirements
|
|
31
|
+
|
|
32
|
+
Node 16+
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
Generate a secure token in your frontend then use this API to obtain the passkey registration or authentication details:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { Passlock } from '@passlock/node'
|
|
40
|
+
|
|
41
|
+
const passlock = new Passlock({ tenancyId, apiKey })
|
|
42
|
+
|
|
43
|
+
// token comes from your frontend
|
|
44
|
+
const principal = await passlock.fetchPrincipal({ token })
|
|
45
|
+
|
|
46
|
+
// get the user id
|
|
47
|
+
console.log(principal.user.id)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
[contact]: https://passlock.dev/contact
|
|
51
|
+
[client]: https://www.npmjs.com/package/@passlock/client
|
package/dist/config/config.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -17,17 +17,31 @@ export declare class PasslockUnsafe {
|
|
|
17
17
|
});
|
|
18
18
|
private readonly runPromise;
|
|
19
19
|
fetchPrincipal: (request: PrincipalRequest) => Promise<{
|
|
20
|
+
readonly givenName?: string;
|
|
21
|
+
readonly familyName?: string;
|
|
22
|
+
readonly email?: string;
|
|
23
|
+
readonly emailVerified?: boolean;
|
|
24
|
+
readonly iss: string;
|
|
25
|
+
readonly aud: string;
|
|
26
|
+
readonly sub: string;
|
|
27
|
+
readonly iat: Date;
|
|
28
|
+
readonly nbf: Date;
|
|
29
|
+
readonly exp: Date;
|
|
30
|
+
readonly jti: string;
|
|
20
31
|
readonly token: string;
|
|
21
|
-
readonly
|
|
32
|
+
readonly userVerified: boolean;
|
|
33
|
+
readonly authType: "email" | "apple" | "google" | "passkey";
|
|
34
|
+
readonly authId: string;
|
|
35
|
+
readonly user?: {
|
|
22
36
|
readonly id: string;
|
|
37
|
+
readonly email: string;
|
|
23
38
|
readonly givenName: string;
|
|
24
39
|
readonly familyName: string;
|
|
25
|
-
readonly email: string;
|
|
26
40
|
readonly emailVerified: boolean;
|
|
27
41
|
};
|
|
28
42
|
readonly authStatement: {
|
|
29
|
-
readonly authType: "email" | "apple" | "google" | "passkey";
|
|
30
43
|
readonly userVerified: boolean;
|
|
44
|
+
readonly authType: "email" | "apple" | "google" | "passkey";
|
|
31
45
|
readonly authTimestamp: Date;
|
|
32
46
|
};
|
|
33
47
|
readonly expireAt: Date;
|
|
@@ -42,20 +56,33 @@ export declare class Passlock {
|
|
|
42
56
|
});
|
|
43
57
|
private readonly runPromise;
|
|
44
58
|
fetchPrincipal: (request: PrincipalRequest) => Promise<{
|
|
59
|
+
readonly givenName?: string;
|
|
60
|
+
readonly familyName?: string;
|
|
61
|
+
readonly email?: string;
|
|
62
|
+
readonly emailVerified?: boolean;
|
|
63
|
+
readonly iss: string;
|
|
64
|
+
readonly aud: string;
|
|
65
|
+
readonly sub: string;
|
|
66
|
+
readonly iat: Date;
|
|
67
|
+
readonly nbf: Date;
|
|
68
|
+
readonly exp: Date;
|
|
69
|
+
readonly jti: string;
|
|
45
70
|
readonly token: string;
|
|
46
|
-
readonly
|
|
71
|
+
readonly userVerified: boolean;
|
|
72
|
+
readonly authType: "email" | "apple" | "google" | "passkey";
|
|
73
|
+
readonly authId: string;
|
|
74
|
+
readonly user?: {
|
|
47
75
|
readonly id: string;
|
|
76
|
+
readonly email: string;
|
|
48
77
|
readonly givenName: string;
|
|
49
78
|
readonly familyName: string;
|
|
50
|
-
readonly email: string;
|
|
51
79
|
readonly emailVerified: boolean;
|
|
52
80
|
};
|
|
53
81
|
readonly authStatement: {
|
|
54
|
-
readonly authType: "email" | "apple" | "google" | "passkey";
|
|
55
82
|
readonly userVerified: boolean;
|
|
83
|
+
readonly authType: "email" | "apple" | "google" | "passkey";
|
|
56
84
|
readonly authTimestamp: Date;
|
|
57
85
|
};
|
|
58
86
|
readonly expireAt: Date;
|
|
59
87
|
} | PasslockError>;
|
|
60
88
|
}
|
|
61
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ErrorCode
|
|
2
|
-
import { Effect as E, Layer as L, Runtime, Scope, pipe } from 'effect';
|
|
1
|
+
import { ErrorCode } from '@passlock/shared/dist/error/error.js';
|
|
3
2
|
import { Config } from './config/config.js';
|
|
3
|
+
import { Effect as E, Layer as L, Runtime, Scope, pipe } from 'effect';
|
|
4
4
|
import { PrincipalService, PrincipalServiceLive, StreamResponseLive, } from './principal/principal.js';
|
|
5
5
|
export { ErrorCode } from '@passlock/shared/dist/error/error.js';
|
|
6
6
|
export class PasslockError extends Error {
|
|
@@ -38,6 +38,7 @@ const transformErrors = (effect) => {
|
|
|
38
38
|
: E.succeed(new PasslockError('Sorry, something went wrong', ErrorCode.InternalServerError));
|
|
39
39
|
},
|
|
40
40
|
Interrupt: () => {
|
|
41
|
+
console.error("Interrupt");
|
|
41
42
|
return E.succeed(new PasslockError('Operation aborted', ErrorCode.InternalBrowserError));
|
|
42
43
|
},
|
|
43
44
|
Sequential: errors => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EA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C,IAAI,CACF,gBAAgB,EAChB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,EACrD,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAClC,CAAA;CACJ"}
|
|
@@ -3,16 +3,20 @@ import { Principal } from '@passlock/shared/dist/schema/principal.js';
|
|
|
3
3
|
import { Context, Effect as E, Layer, Stream } from 'effect';
|
|
4
4
|
import * as https from 'https';
|
|
5
5
|
import { Config } from '../config/config.js';
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
}
|
|
8
11
|
export type PrincipalErrors = NotFound | Unauthorized | Forbidden | InternalServerError;
|
|
9
12
|
export type PrincipalRequest = {
|
|
10
13
|
token: string;
|
|
11
14
|
};
|
|
12
|
-
|
|
15
|
+
declare const PrincipalService_base: Context.TagClass<PrincipalService, "@services/PrincipalService", {
|
|
13
16
|
fetchPrincipal: (request: PrincipalRequest) => E.Effect<Principal, PrincipalErrors>;
|
|
14
|
-
}
|
|
15
|
-
export declare
|
|
17
|
+
}>;
|
|
18
|
+
export declare class PrincipalService extends PrincipalService_base {
|
|
19
|
+
}
|
|
16
20
|
export declare const buildError: (res: {
|
|
17
21
|
statusCode?: number | undefined;
|
|
18
22
|
statusMessage?: string | undefined;
|
|
@@ -20,4 +24,4 @@ export declare const buildError: (res: {
|
|
|
20
24
|
export declare const fetchPrincipal: (request: PrincipalRequest) => E.Effect<Principal, PrincipalErrors, StreamResponse | Config>;
|
|
21
25
|
export declare const StreamResponseLive: Layer.Layer<StreamResponse, never, never>;
|
|
22
26
|
export declare const PrincipalServiceLive: Layer.Layer<PrincipalService, never, Config | StreamResponse>;
|
|
23
|
-
|
|
27
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Principal } from '@passlock/shared/dist/schema/principal.js';
|
|
2
2
|
import { Context, Effect as E, Layer as L, Ref } from 'effect';
|
|
3
3
|
import type { RequestOptions } from 'https';
|
|
4
|
-
import { Config } from '../config/config.js';
|
|
5
4
|
import { type PrincipalService } from './principal.js';
|
|
5
|
+
import { Config } from '../config/config.js';
|
|
6
6
|
export declare const principal: Principal;
|
|
7
7
|
export declare const tenancyId = "tenancyId";
|
|
8
8
|
export declare const apiKey = "apiKey";
|
|
@@ -13,4 +13,3 @@ export declare class State extends State_base {
|
|
|
13
13
|
export declare const buildEffect: <A, E>(assertions: E.Effect<A, E, PrincipalService | State>) => E.Effect<void, E>;
|
|
14
14
|
export declare const buildErrorEffect: (statusCode: number) => <A>(assertions: E.Effect<void, A, PrincipalService>) => E.Effect<void, A>;
|
|
15
15
|
export {};
|
|
16
|
-
//# sourceMappingURL=principal.fixture.d.ts.map
|
|
@@ -1,14 +1,33 @@
|
|
|
1
|
+
import * as S from '@effect/schema/Schema';
|
|
2
|
+
import { Principal } from '@passlock/shared/dist/schema/principal.js';
|
|
1
3
|
import { Context, Effect as E, Layer as L, LogLevel, Logger, Ref, Stream, pipe } from 'effect';
|
|
2
|
-
import { Config } from '../config/config.js';
|
|
3
4
|
import { PrincipalServiceLive, StreamResponse, buildError, } from './principal.js';
|
|
5
|
+
import { Config } from '../config/config.js';
|
|
4
6
|
export const principal = {
|
|
7
|
+
jti: 'token',
|
|
5
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
|
|
6
25
|
user: {
|
|
7
|
-
id: '1',
|
|
8
|
-
email: 'john.doe@gmail.com',
|
|
26
|
+
id: 'user-1',
|
|
9
27
|
givenName: 'john',
|
|
10
28
|
familyName: 'doe',
|
|
11
|
-
|
|
29
|
+
email: 'john.doe@gmail.com',
|
|
30
|
+
emailVerified: false
|
|
12
31
|
},
|
|
13
32
|
authStatement: {
|
|
14
33
|
authType: 'passkey',
|
|
@@ -23,19 +42,24 @@ export const configTest = L.succeed(Config, Config.of({ tenancyId, apiKey }));
|
|
|
23
42
|
export class State extends Context.Tag('State')() {
|
|
24
43
|
}
|
|
25
44
|
export const buildEffect = (assertions) => {
|
|
26
|
-
const
|
|
45
|
+
const streamResponseTest = L.effect(StreamResponse, E.gen(function* (_) {
|
|
27
46
|
const ref = yield* _(State);
|
|
28
|
-
const
|
|
29
|
-
|
|
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
|
+
};
|
|
30
52
|
}));
|
|
31
|
-
const service = pipe(PrincipalServiceLive, L.provide(
|
|
53
|
+
const service = pipe(PrincipalServiceLive, L.provide(streamResponseTest), L.provide(configTest));
|
|
32
54
|
const args = L.effect(State, Ref.make(undefined));
|
|
33
55
|
const effect = pipe(E.provide(assertions, service), E.provide(args), Logger.withMinimumLogLevel(LogLevel.None));
|
|
34
56
|
return effect;
|
|
35
57
|
};
|
|
36
58
|
export const buildErrorEffect = (statusCode) => (assertions) => {
|
|
37
|
-
const
|
|
38
|
-
|
|
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));
|
|
39
63
|
const args = L.effect(State, Ref.make(undefined));
|
|
40
64
|
const effect = pipe(E.provide(assertions, service), E.provide(args), Logger.withMinimumLogLevel(LogLevel.None));
|
|
41
65
|
return effect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principal.fixture.js","sourceRoot":"","sources":["../../src/principal/principal.fixture.ts"],"names":[],"mappings":"
|
|
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,SAAS,EAAE,MAAM,2CAA2C,CAAA;AACrE,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,EAEL,oBAAoB,EACpB,cAAc,EACd,UAAU,GACX,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,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;IACjB,4BAA4B;IAC5B,+BAA+B;IAC/B,GAAG,EAAE,IAAI,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;IACxB,GAAG,EAAE,IAAI,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACxB,GAAG,EAAE,IAAI,IAAI,CAAC,GAAG,GAA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AU,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,12 +1,18 @@
|
|
|
1
1
|
import { Forbidden, InternalServerError, NotFound, Unauthorized, } from '@passlock/shared/dist/error/error.js';
|
|
2
|
-
import { Principal
|
|
2
|
+
import { Principal } from '@passlock/shared/dist/schema/principal.js';
|
|
3
3
|
import { createParser } from '@passlock/shared/dist/schema/utils.js';
|
|
4
4
|
import { Chunk, Console, Context, Effect as E, Layer, Option, Stream, flow, pipe } from 'effect';
|
|
5
5
|
import * as https from 'https';
|
|
6
|
+
import { PASSLOCK_CLIENT_VERSION } from '../version.js';
|
|
6
7
|
import { Config } from '../config/config.js';
|
|
7
|
-
|
|
8
|
+
/* Dependencies */
|
|
9
|
+
export class StreamResponse extends Context.Tag('@services/StreamResponse')() {
|
|
10
|
+
}
|
|
11
|
+
/* Service */
|
|
8
12
|
const parsePrincipal = createParser(Principal);
|
|
9
|
-
export
|
|
13
|
+
export class PrincipalService extends Context.Tag('@services/PrincipalService')() {
|
|
14
|
+
}
|
|
15
|
+
/* Effects */
|
|
10
16
|
const buildHostname = (endpoint) => {
|
|
11
17
|
return new URL(endpoint || 'https://api.passlock.dev').hostname;
|
|
12
18
|
};
|
|
@@ -16,8 +22,9 @@ const buildOptions = (token) => pipe(Config, E.map(({ endpoint, tenancyId, apiKe
|
|
|
16
22
|
path: `/${tenancyId}/token/${token}`,
|
|
17
23
|
method: 'GET',
|
|
18
24
|
headers: {
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
Accept: 'application/json',
|
|
26
|
+
Authorization: `Bearer ${apiKey}`,
|
|
27
|
+
'X-PASSLOCK-CLIENT-VERSION': PASSLOCK_CLIENT_VERSION
|
|
21
28
|
},
|
|
22
29
|
})));
|
|
23
30
|
export const buildError = (res) => {
|
|
@@ -38,7 +45,7 @@ export const buildError = (res) => {
|
|
|
38
45
|
const fail = (error) => E.fail(Option.some(error));
|
|
39
46
|
const succeed = (data) => E.succeed(Chunk.of(data));
|
|
40
47
|
const close = E.fail(Option.none());
|
|
41
|
-
const buildStream = (token) => pipe(Stream.fromEffect(buildOptions(token)), Stream.zip(StreamResponse), Stream.flatMap(([options, streamResponse]) => streamResponse(options)));
|
|
48
|
+
const buildStream = (token) => pipe(Stream.fromEffect(buildOptions(token)), Stream.zip(StreamResponse), Stream.flatMap(([options, { streamResponse }]) => streamResponse(options)));
|
|
42
49
|
export const fetchPrincipal = (request) => {
|
|
43
50
|
const stream = buildStream(request.token);
|
|
44
51
|
const json = pipe(Stream.runCollect(stream), E.map(Chunk.toReadonlyArray), E.map(buffers => Buffer.concat(buffers)), E.flatMap(buffer => E.try({
|
|
@@ -56,8 +63,10 @@ export const fetchPrincipal = (request) => {
|
|
|
56
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' })))));
|
|
57
64
|
return json;
|
|
58
65
|
};
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
/* Live */
|
|
67
|
+
/* v8 ignore start */
|
|
68
|
+
export const StreamResponseLive = Layer.succeed(StreamResponse, {
|
|
69
|
+
streamResponse: options => Stream.async((emit) => {
|
|
61
70
|
https
|
|
62
71
|
.request(options, res => {
|
|
63
72
|
if (200 !== res.statusCode)
|
|
@@ -67,7 +76,7 @@ export const StreamResponseLive = Layer.succeed(StreamResponse, options => {
|
|
|
67
76
|
res.on('error', e => void emit(fail(new InternalServerError({ message: e.message }))));
|
|
68
77
|
})
|
|
69
78
|
.end();
|
|
70
|
-
})
|
|
79
|
+
}),
|
|
71
80
|
});
|
|
72
81
|
export const PrincipalServiceLive = Layer.effect(PrincipalService, E.gen(function* (_) {
|
|
73
82
|
const context = yield* _(E.context());
|
|
@@ -75,4 +84,5 @@ export const PrincipalServiceLive = Layer.effect(PrincipalService, E.gen(functio
|
|
|
75
84
|
fetchPrincipal: flow(fetchPrincipal, E.provide(context)),
|
|
76
85
|
});
|
|
77
86
|
}));
|
|
87
|
+
/* v8 ignore stop */
|
|
78
88
|
//# sourceMappingURL=principal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principal.js","sourceRoot":"","sources":["../../src/principal/principal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,QAAQ,EACR,YAAY,GACb,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"principal.js","sourceRoot":"","sources":["../../src/principal/principal.ts"],"names":[],"mappings":"AAAA,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,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAChG,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,kBAAkB;AAElB,MAAM,OAAO,cAAe,SAAQ,OAAO,CAAC,GAAG,CAA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,CAAC;KACzD,CAAC,CAAA;AACJ,CAAC,CAAC,CACH,CAAA;AACD,oBAAoB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PASSLOCK_CLIENT_VERSION = "0.9.23";
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uBAAuB,GAAG,YAAY,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@passlock/node",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.9.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "0.9.23",
|
|
5
|
+
"description": "Passkey authentication and social login for node.js/express apps",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"passkey",
|
|
8
8
|
"passkeys",
|
|
@@ -16,57 +16,67 @@
|
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"homepage": "https://passlock.dev",
|
|
19
|
-
"repository":
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/passlock-dev/ts-clients.git",
|
|
22
|
+
"directory": "packages/node"
|
|
23
|
+
},
|
|
20
24
|
"bugs": {
|
|
21
|
-
"url": "https://github.com/passlock-dev/
|
|
25
|
+
"url": "https://github.com/passlock-dev/ts-clients/issues",
|
|
22
26
|
"email": "team@passlock.dev"
|
|
23
27
|
},
|
|
24
28
|
"exports": {
|
|
25
29
|
".": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js"
|
|
28
32
|
}
|
|
29
33
|
},
|
|
30
34
|
"files": [
|
|
31
35
|
"src",
|
|
32
|
-
"dist"
|
|
36
|
+
"dist",
|
|
37
|
+
"!dist/**/*.test.*",
|
|
38
|
+
"!dist/**/*.spec.*"
|
|
33
39
|
],
|
|
34
40
|
"dependencies": {
|
|
35
|
-
"effect": "
|
|
36
|
-
"@passlock/shared": "
|
|
41
|
+
"effect": "3.6.3",
|
|
42
|
+
"@passlock/shared": "0.9.23"
|
|
37
43
|
},
|
|
38
44
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@typescript
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"eslint": "^8.
|
|
45
|
+
"@effect/schema": "0.70.4",
|
|
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.2.0",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^8.0.1",
|
|
52
|
+
"@typescript-eslint/parser": "^8.0.1",
|
|
53
|
+
"@vitest/coverage-v8": "^2.0.5",
|
|
54
|
+
"@vitest/ui": "^2.0.5",
|
|
55
|
+
"eslint": "^9.9.0",
|
|
46
56
|
"eslint-config-prettier": "^9.1.0",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"vitest": "^2.0.3"
|
|
57
|
+
"prettier": "^3.3.3",
|
|
58
|
+
"publint": "^0.2.9",
|
|
59
|
+
"rimraf": "^6.0.1",
|
|
60
|
+
"tsx": "^4.17.0",
|
|
61
|
+
"typescript": "^5.5.4",
|
|
62
|
+
"vite": "^5.4.0",
|
|
63
|
+
"vitest": "^2.0.5"
|
|
55
64
|
},
|
|
56
65
|
"scripts": {
|
|
57
|
-
"clean": "
|
|
66
|
+
"clean": "rimraf ./dist",
|
|
58
67
|
"typecheck": "tsc --noEmit",
|
|
59
68
|
"test": "vitest run",
|
|
60
69
|
"test:watch": "vitest dev",
|
|
61
70
|
"test:ui": "vitest --coverage.enabled=true --ui",
|
|
62
71
|
"test:coverage": "vitest run --coverage",
|
|
63
|
-
"
|
|
72
|
+
"replaceTokens": "LATEST=${npm_package_version} replacetokens --sources ./dist/version.* --log-level error --missing-var-action keep --use-env > /dev/null",
|
|
73
|
+
"build": "tsc --build && pnpm run replaceTokens && publint",
|
|
64
74
|
"build:clean": "pnpm run clean && pnpm run build",
|
|
65
75
|
"build:watch": "tsc --build --watch",
|
|
66
76
|
"format": "prettier --write \"src/**/*.+(js|ts|json)\"",
|
|
67
77
|
"lint": "eslint --ext .ts src",
|
|
68
78
|
"lint:fix": "pnpm run lint --fix",
|
|
69
|
-
"
|
|
70
|
-
"
|
|
79
|
+
"upgrade:deps": "ncu --peer -x effect -x @effect/* -u",
|
|
80
|
+
"upgrade:pnpm": "corepack use pnpm@latest"
|
|
71
81
|
}
|
|
72
82
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { ErrorCode } from '@passlock/shared/dist/error/error.js'
|
|
2
|
+
import { Config } from './config/config.js'
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
Forbidden,
|
|
6
|
+
InternalServerError,
|
|
7
|
+
NotFound,
|
|
8
|
+
Unauthorized,
|
|
7
9
|
} from '@passlock/shared/dist/error/error.js'
|
|
10
|
+
|
|
8
11
|
import { Effect as E, Layer as L, Runtime, Scope, pipe } from 'effect'
|
|
9
|
-
|
|
12
|
+
|
|
10
13
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
type PrincipalRequest,
|
|
15
|
+
PrincipalService,
|
|
16
|
+
PrincipalServiceLive,
|
|
17
|
+
StreamResponseLive,
|
|
15
18
|
} from './principal/principal.js'
|
|
16
19
|
|
|
17
20
|
export type { PrincipalRequest } from './principal/principal.js'
|
|
@@ -69,11 +72,14 @@ const transformErrors = <A, R>(
|
|
|
69
72
|
},
|
|
70
73
|
|
|
71
74
|
Interrupt: () => {
|
|
75
|
+
console.error("Interrupt")
|
|
76
|
+
|
|
72
77
|
return E.succeed(new PasslockError('Operation aborted', ErrorCode.InternalBrowserError))
|
|
73
78
|
},
|
|
74
79
|
|
|
75
80
|
Sequential: errors => {
|
|
76
81
|
console.error(errors)
|
|
82
|
+
|
|
77
83
|
return E.succeed(
|
|
78
84
|
new PasslockError('Sorry, something went wrong', ErrorCode.InternalServerError),
|
|
79
85
|
)
|
|
@@ -81,6 +87,7 @@ const transformErrors = <A, R>(
|
|
|
81
87
|
|
|
82
88
|
Parallel: errors => {
|
|
83
89
|
console.error(errors)
|
|
90
|
+
|
|
84
91
|
return E.succeed(
|
|
85
92
|
new PasslockError('Sorry, something went wrong', ErrorCode.InternalServerError),
|
|
86
93
|
)
|
|
@@ -1,22 +1,42 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as S from '@effect/schema/Schema'
|
|
2
|
+
import { Principal } from '@passlock/shared/dist/schema/principal.js'
|
|
2
3
|
import { Context, Effect as E, Layer as L, LogLevel, Logger, Ref, Stream, pipe } from 'effect'
|
|
3
4
|
import type { RequestOptions } from 'https'
|
|
4
|
-
|
|
5
|
+
|
|
5
6
|
import {
|
|
7
|
+
type PrincipalService,
|
|
6
8
|
PrincipalServiceLive,
|
|
7
9
|
StreamResponse,
|
|
8
10
|
buildError,
|
|
9
|
-
type PrincipalService,
|
|
10
11
|
} from './principal.js'
|
|
11
12
|
|
|
13
|
+
import { Config } from '../config/config.js'
|
|
14
|
+
|
|
12
15
|
export const principal: Principal = {
|
|
16
|
+
jti: 'token',
|
|
13
17
|
token: 'token',
|
|
18
|
+
sub: 'user-1',
|
|
19
|
+
iss: 'idp.passlock.dev',
|
|
20
|
+
aud: 'tenancy_id',
|
|
21
|
+
// must be at least 1 second
|
|
22
|
+
// as it's truncated to seconds
|
|
23
|
+
iat: new Date(60 * 1000),
|
|
24
|
+
nbf: new Date(120 * 100),
|
|
25
|
+
exp: new Date(180 * 1000),
|
|
26
|
+
email: 'john.doe@gmail.com',
|
|
27
|
+
givenName: 'john',
|
|
28
|
+
familyName: 'doe',
|
|
29
|
+
emailVerified: false,
|
|
30
|
+
authType: 'passkey',
|
|
31
|
+
authId: 'auth-1',
|
|
32
|
+
userVerified: true,
|
|
33
|
+
// legacy
|
|
14
34
|
user: {
|
|
15
|
-
id: '1',
|
|
16
|
-
email: 'john.doe@gmail.com',
|
|
35
|
+
id: 'user-1',
|
|
17
36
|
givenName: 'john',
|
|
18
37
|
familyName: 'doe',
|
|
19
|
-
|
|
38
|
+
email: 'john.doe@gmail.com',
|
|
39
|
+
emailVerified: false
|
|
20
40
|
},
|
|
21
41
|
authStatement: {
|
|
22
42
|
authType: 'passkey',
|
|
@@ -36,17 +56,21 @@ export class State extends Context.Tag('State')<State, Ref.Ref<RequestOptions |
|
|
|
36
56
|
export const buildEffect = <A, E>(
|
|
37
57
|
assertions: E.Effect<A, E, PrincipalService | State>,
|
|
38
58
|
): E.Effect<void, E> => {
|
|
39
|
-
const
|
|
59
|
+
const streamResponseTest = L.effect(
|
|
40
60
|
StreamResponse,
|
|
41
61
|
E.gen(function* (_) {
|
|
42
62
|
const ref = yield* _(State)
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
63
|
+
const res = S.encodeSync(Principal)(principal)
|
|
64
|
+
const buff = Buffer.from(JSON.stringify(res))
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
streamResponse: options =>
|
|
68
|
+
pipe(Stream.fromEffect(Ref.set(ref, options)), Stream.zipRight(Stream.make(buff))),
|
|
69
|
+
}
|
|
46
70
|
}),
|
|
47
71
|
)
|
|
48
72
|
|
|
49
|
-
const service = pipe(PrincipalServiceLive, L.provide(
|
|
73
|
+
const service = pipe(PrincipalServiceLive, L.provide(streamResponseTest), L.provide(configTest))
|
|
50
74
|
|
|
51
75
|
const args = L.effect(State, Ref.make<RequestOptions | undefined>(undefined))
|
|
52
76
|
|
|
@@ -62,11 +86,14 @@ export const buildEffect = <A, E>(
|
|
|
62
86
|
export const buildErrorEffect =
|
|
63
87
|
(statusCode: number) =>
|
|
64
88
|
<A>(assertions: E.Effect<void, A, PrincipalService>): E.Effect<void, A> => {
|
|
65
|
-
const
|
|
66
|
-
|
|
89
|
+
const streamResponseTest = L.succeed(
|
|
90
|
+
StreamResponse,
|
|
91
|
+
StreamResponse.of({
|
|
92
|
+
streamResponse: () => Stream.fail(buildError({ statusCode })),
|
|
93
|
+
}),
|
|
67
94
|
)
|
|
68
95
|
|
|
69
|
-
const service = pipe(PrincipalServiceLive, L.provide(
|
|
96
|
+
const service = pipe(PrincipalServiceLive, L.provide(streamResponseTest), L.provide(configTest))
|
|
70
97
|
|
|
71
98
|
const args = L.effect(State, Ref.make<RequestOptions | undefined>(undefined))
|
|
72
99
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
Forbidden,
|
|
3
|
+
InternalServerError,
|
|
4
|
+
NotFound,
|
|
5
|
+
Unauthorized,
|
|
6
6
|
} from '@passlock/shared/dist/error/error.js'
|
|
7
7
|
import { Effect as E, Effect, Ref } from 'effect'
|
|
8
8
|
import { describe, expect, test } from 'vitest'
|
|
@@ -4,19 +4,23 @@ import {
|
|
|
4
4
|
NotFound,
|
|
5
5
|
Unauthorized,
|
|
6
6
|
} from '@passlock/shared/dist/error/error.js'
|
|
7
|
-
import { Principal
|
|
7
|
+
import { Principal } from '@passlock/shared/dist/schema/principal.js'
|
|
8
8
|
import { createParser } from '@passlock/shared/dist/schema/utils.js'
|
|
9
9
|
import type { StreamEmit } from 'effect'
|
|
10
10
|
import { Chunk, Console, Context, Effect as E, Layer, Option, Stream, flow, pipe } from 'effect'
|
|
11
11
|
import * as https from 'https'
|
|
12
|
+
import { PASSLOCK_CLIENT_VERSION } from '../version.js'
|
|
13
|
+
|
|
12
14
|
import { Config } from '../config/config.js'
|
|
13
15
|
|
|
14
16
|
/* Dependencies */
|
|
15
17
|
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
export class StreamResponse extends Context.Tag('@services/StreamResponse')<
|
|
19
|
+
StreamResponse,
|
|
20
|
+
{
|
|
21
|
+
streamResponse: (options: https.RequestOptions) => Stream.Stream<Buffer, PrincipalErrors>
|
|
22
|
+
}
|
|
23
|
+
>() {}
|
|
20
24
|
|
|
21
25
|
/* Service */
|
|
22
26
|
|
|
@@ -25,16 +29,17 @@ const parsePrincipal = createParser(Principal)
|
|
|
25
29
|
export type PrincipalErrors = NotFound | Unauthorized | Forbidden | InternalServerError
|
|
26
30
|
export type PrincipalRequest = { token: string }
|
|
27
31
|
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
export class PrincipalService extends Context.Tag('@services/PrincipalService')<
|
|
33
|
+
PrincipalService,
|
|
34
|
+
{
|
|
35
|
+
fetchPrincipal: (request: PrincipalRequest) => E.Effect<Principal, PrincipalErrors>
|
|
36
|
+
}
|
|
37
|
+
>() {}
|
|
33
38
|
|
|
34
39
|
/* Effects */
|
|
35
40
|
|
|
36
|
-
const buildHostname = (endpoint: string | undefined) => {
|
|
37
|
-
return new URL(endpoint || 'https://api.passlock.dev').hostname
|
|
41
|
+
const buildHostname = (endpoint: string | undefined) => {
|
|
42
|
+
return new URL(endpoint || 'https://api.passlock.dev').hostname
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
const buildOptions = (token: string) =>
|
|
@@ -46,8 +51,9 @@ const buildOptions = (token: string) =>
|
|
|
46
51
|
path: `/${tenancyId}/token/${token}`,
|
|
47
52
|
method: 'GET',
|
|
48
53
|
headers: {
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
Accept: 'application/json',
|
|
55
|
+
Authorization: `Bearer ${apiKey}`,
|
|
56
|
+
'X-PASSLOCK-CLIENT-VERSION': PASSLOCK_CLIENT_VERSION
|
|
51
57
|
},
|
|
52
58
|
})),
|
|
53
59
|
)
|
|
@@ -62,10 +68,10 @@ export const buildError = (res: {
|
|
|
62
68
|
|
|
63
69
|
if (res.statusCode && res.statusMessage)
|
|
64
70
|
return new InternalServerError({ message: `${String(res.statusCode)} - ${res.statusMessage}` })
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
|
|
72
|
+
if (res.statusCode) return new InternalServerError({ message: String(res.statusCode) })
|
|
73
|
+
|
|
74
|
+
if (res.statusMessage) return new InternalServerError({ message: res.statusMessage })
|
|
69
75
|
|
|
70
76
|
return new InternalServerError({ message: 'Received non 200 response' })
|
|
71
77
|
}
|
|
@@ -78,7 +84,7 @@ const buildStream = (token: string) =>
|
|
|
78
84
|
pipe(
|
|
79
85
|
Stream.fromEffect(buildOptions(token)),
|
|
80
86
|
Stream.zip(StreamResponse),
|
|
81
|
-
Stream.flatMap(([options, streamResponse]) => streamResponse(options)),
|
|
87
|
+
Stream.flatMap(([options, { streamResponse }]) => streamResponse(options)),
|
|
82
88
|
)
|
|
83
89
|
|
|
84
90
|
export const fetchPrincipal = (
|
|
@@ -127,17 +133,18 @@ export const fetchPrincipal = (
|
|
|
127
133
|
/* Live */
|
|
128
134
|
|
|
129
135
|
/* v8 ignore start */
|
|
130
|
-
export const StreamResponseLive = Layer.succeed(StreamResponse,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
export const StreamResponseLive = Layer.succeed(StreamResponse, {
|
|
137
|
+
streamResponse: options =>
|
|
138
|
+
Stream.async((emit: StreamEmit.Emit<never, PrincipalErrors, Buffer, void>) => {
|
|
139
|
+
https
|
|
140
|
+
.request(options, res => {
|
|
141
|
+
if (200 !== res.statusCode) void emit(fail(buildError(res)))
|
|
142
|
+
res.on('data', (data: Buffer) => void emit(succeed(data)))
|
|
143
|
+
res.on('close', () => void emit(close))
|
|
144
|
+
res.on('error', e => void emit(fail(new InternalServerError({ message: e.message }))))
|
|
145
|
+
})
|
|
146
|
+
.end()
|
|
147
|
+
}),
|
|
141
148
|
})
|
|
142
149
|
|
|
143
150
|
export const PrincipalServiceLive = Layer.effect(
|
package/src/version.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PASSLOCK_CLIENT_VERSION = '#{LATEST}#'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;;wBAKR,MAAM;qBACT,MAAM;wBACH,MAAM;;AAL9B,qBAAa,MAAO,SAAQ,WAOzB;CAAG"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EAKZ,MAAM,sCAAsC,CAAA;AAG7C,OAAO,EAIH,KAAK,gBAAgB,EACxB,MAAM,0BAA0B,CAAA;AAEjC,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAA;AAEhE,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,mBAAkB;IAC/B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;gBAEZ,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS;IAK5C,MAAM,CAAC,QAAQ,CAAC,OAAO,UAAW,OAAO,KAAG,KAAK,IAAI,aAAa,CAOjE;CACF;AAyDD,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CA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AQ,UAAkE;CAAG;AAEhG,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,CAAC,cAClB,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAAC,KACnD,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAsBlB,CAAA;AAED,eAAO,MAAM,gBAAgB,eACd,MAAM,MAClB,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,gBAAgB,CAAC,KAAG,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAgBrE,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"principal.test.d.ts","sourceRoot":"","sources":["../../src/principal/principal.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { Forbidden, InternalServerError, NotFound, Unauthorized, } from '@passlock/shared/dist/error/error.js';
|
|
2
|
-
import { Effect as E, Effect, Ref } from 'effect';
|
|
3
|
-
import { describe, expect, test } from 'vitest';
|
|
4
|
-
import * as Fixture from './principal.fixture.js';
|
|
5
|
-
import { PrincipalService } from './principal.js';
|
|
6
|
-
describe('fetchPrincipal should', () => {
|
|
7
|
-
test('return a valid principal', () => {
|
|
8
|
-
const assertions = E.gen(function* (_) {
|
|
9
|
-
const service = yield* _(PrincipalService);
|
|
10
|
-
const result = yield* _(service.fetchPrincipal({ token: 'token' }));
|
|
11
|
-
expect(result).toEqual(Fixture.principal);
|
|
12
|
-
});
|
|
13
|
-
const effect = Fixture.buildEffect(assertions);
|
|
14
|
-
return E.runPromise(effect);
|
|
15
|
-
});
|
|
16
|
-
test('call the correct url', () => {
|
|
17
|
-
const assertions = E.gen(function* (_) {
|
|
18
|
-
const service = yield* _(PrincipalService);
|
|
19
|
-
yield* _(service.fetchPrincipal({ token: 'myToken' }));
|
|
20
|
-
const state = yield* _(Fixture.State);
|
|
21
|
-
const args = yield* _(Ref.get(state));
|
|
22
|
-
expect(args?.hostname).toEqual('api.passlock.dev');
|
|
23
|
-
expect(args?.method).toEqual('GET');
|
|
24
|
-
expect(args?.path).toEqual(`/${Fixture.tenancyId}/token/myToken`);
|
|
25
|
-
});
|
|
26
|
-
const effect = Fixture.buildEffect(assertions);
|
|
27
|
-
return E.runPromise(effect);
|
|
28
|
-
});
|
|
29
|
-
test('pass the api key as a header', () => {
|
|
30
|
-
const assertions = E.gen(function* (_) {
|
|
31
|
-
const service = yield* _(PrincipalService);
|
|
32
|
-
yield* _(service.fetchPrincipal({ token: 'myToken' }));
|
|
33
|
-
const state = yield* _(Fixture.State);
|
|
34
|
-
const args = yield* _(Ref.get(state));
|
|
35
|
-
expect(args?.headers?.['Authorization']).toEqual(`Bearer ${Fixture.apiKey}`);
|
|
36
|
-
});
|
|
37
|
-
const effect = Fixture.buildEffect(assertions);
|
|
38
|
-
return E.runPromise(effect);
|
|
39
|
-
});
|
|
40
|
-
test('propagate a 401 error', () => {
|
|
41
|
-
const assertions = E.gen(function* (_) {
|
|
42
|
-
const service = yield* _(PrincipalService);
|
|
43
|
-
const result = service.fetchPrincipal({ token: 'myToken' });
|
|
44
|
-
const error = yield* _(Effect.flip(result));
|
|
45
|
-
expect(error).toBeInstanceOf(Unauthorized);
|
|
46
|
-
});
|
|
47
|
-
const effect = Fixture.buildErrorEffect(401)(assertions);
|
|
48
|
-
return E.runPromise(effect);
|
|
49
|
-
});
|
|
50
|
-
test('propagate a 403 error', () => {
|
|
51
|
-
const assertions = E.gen(function* (_) {
|
|
52
|
-
const service = yield* _(PrincipalService);
|
|
53
|
-
const result = service.fetchPrincipal({ token: 'myToken' });
|
|
54
|
-
const error = yield* _(Effect.flip(result));
|
|
55
|
-
expect(error).toBeInstanceOf(Forbidden);
|
|
56
|
-
});
|
|
57
|
-
const effect = Fixture.buildErrorEffect(403)(assertions);
|
|
58
|
-
return E.runPromise(effect);
|
|
59
|
-
});
|
|
60
|
-
test('propagate a 404 error', () => {
|
|
61
|
-
const assertions = E.gen(function* (_) {
|
|
62
|
-
const service = yield* _(PrincipalService);
|
|
63
|
-
const result = service.fetchPrincipal({ token: 'myToken' });
|
|
64
|
-
const error = yield* _(Effect.flip(result));
|
|
65
|
-
expect(error).toBeInstanceOf(NotFound);
|
|
66
|
-
});
|
|
67
|
-
const effect = Fixture.buildErrorEffect(404)(assertions);
|
|
68
|
-
return E.runPromise(effect);
|
|
69
|
-
});
|
|
70
|
-
test('propagate a 500 error', () => {
|
|
71
|
-
const assertions = E.gen(function* (_) {
|
|
72
|
-
const service = yield* _(PrincipalService);
|
|
73
|
-
const result = service.fetchPrincipal({ token: 'myToken' });
|
|
74
|
-
const error = yield* _(Effect.flip(result));
|
|
75
|
-
expect(error).toBeInstanceOf(InternalServerError);
|
|
76
|
-
});
|
|
77
|
-
const effect = Fixture.buildErrorEffect(500)(assertions);
|
|
78
|
-
return E.runPromise(effect);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
//# sourceMappingURL=principal.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"principal.test.js","sourceRoot":"","sources":["../../src/principal/principal.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EACT,mBAAmB,EACnB,QAAQ,EACR,YAAY,GACf,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEjD,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,IAAI,CAAC,0BAA0B,EAAE,GAAG,EAAE;QACpC,MAAM,UAAU,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC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