@passlock/client 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.
- package/README.md +14 -86
- package/README.template.md +16 -88
- package/dist/index.d.ts +4 -206
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -158
- package/dist/index.js.map +1 -1
- package/dist/logger/index.d.ts +24 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +47 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/network.d.ts +39 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/network.js +83 -0
- package/dist/network.js.map +1 -0
- package/dist/passkey/authentication/index.d.ts +21 -0
- package/dist/passkey/authentication/index.d.ts.map +1 -0
- package/dist/passkey/authentication/index.js +22 -0
- package/dist/passkey/authentication/index.js.map +1 -0
- package/dist/passkey/authentication/micro.d.ts +71 -0
- package/dist/passkey/authentication/micro.d.ts.map +1 -0
- package/dist/passkey/authentication/micro.js +107 -0
- package/dist/passkey/authentication/micro.js.map +1 -0
- package/dist/passkey/index.d.ts +7 -0
- package/dist/passkey/index.d.ts.map +1 -0
- package/dist/passkey/index.js +5 -0
- package/dist/passkey/index.js.map +1 -0
- package/dist/passkey/registration/index.d.ts +19 -0
- package/dist/passkey/registration/index.d.ts.map +1 -0
- package/dist/passkey/registration/index.js +20 -0
- package/dist/passkey/registration/index.js.map +1 -0
- package/dist/passkey/registration/micro.d.ts +101 -0
- package/dist/passkey/registration/micro.d.ts.map +1 -0
- package/dist/passkey/registration/micro.js +126 -0
- package/dist/passkey/registration/micro.js.map +1 -0
- package/dist/passkey/shared.d.ts +24 -0
- package/dist/passkey/shared.d.ts.map +1 -0
- package/dist/passkey/shared.js +10 -0
- package/dist/passkey/shared.js.map +1 -0
- package/dist/passkey/support.d.ts +3 -0
- package/dist/passkey/support.d.ts.map +1 -0
- package/dist/passkey/support.js +4 -0
- package/dist/passkey/support.js.map +1 -0
- package/dist/passkey/types.d.ts +26 -0
- package/dist/passkey/types.d.ts.map +1 -0
- package/dist/passkey/types.js +2 -0
- package/dist/passkey/types.js.map +1 -0
- package/dist/promise.d.ts +15 -0
- package/dist/promise.d.ts.map +1 -0
- package/dist/promise.js +46 -0
- package/dist/promise.js.map +1 -0
- package/dist/shared.d.ts +15 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +2 -0
- package/dist/shared.js.map +1 -0
- package/dist/tenancy.d.ts +8 -0
- package/dist/tenancy.d.ts.map +1 -0
- package/dist/tenancy.js +4 -0
- package/dist/tenancy.js.map +1 -0
- package/package.json +52 -58
- package/LICENSE +0 -21
- package/dist/authentication/authenticate.d.ts +0 -24
- package/dist/authentication/authenticate.fixture.d.ts +0 -52
- package/dist/authentication/authenticate.fixture.js +0 -50
- package/dist/authentication/authenticate.fixture.js.map +0 -1
- package/dist/authentication/authenticate.js +0 -73
- package/dist/authentication/authenticate.js.map +0 -1
- package/dist/capabilities/capabilities.d.ts +0 -19
- package/dist/capabilities/capabilities.js +0 -37
- package/dist/capabilities/capabilities.js.map +0 -1
- package/dist/connection/connection.d.ts +0 -15
- package/dist/connection/connection.fixture.d.ts +0 -10
- package/dist/connection/connection.fixture.js +0 -13
- package/dist/connection/connection.fixture.js.map +0 -1
- package/dist/connection/connection.js +0 -23
- package/dist/connection/connection.js.map +0 -1
- package/dist/effect.d.ts +0 -26
- package/dist/effect.js +0 -78
- package/dist/effect.js.map +0 -1
- package/dist/email/email.d.ts +0 -70
- package/dist/email/email.fixture.d.ts +0 -46
- package/dist/email/email.fixture.js +0 -25
- package/dist/email/email.fixture.js.map +0 -1
- package/dist/email/email.js +0 -83
- package/dist/email/email.js.map +0 -1
- package/dist/event/event.d.ts +0 -8
- package/dist/event/event.js +0 -23
- package/dist/event/event.js.map +0 -1
- package/dist/logging/eventLogger.d.ts +0 -17
- package/dist/logging/eventLogger.js +0 -38
- package/dist/logging/eventLogger.js.map +0 -1
- package/dist/registration/register.d.ts +0 -27
- package/dist/registration/register.fixture.d.ts +0 -53
- package/dist/registration/register.fixture.js +0 -66
- package/dist/registration/register.fixture.js.map +0 -1
- package/dist/registration/register.js +0 -78
- package/dist/registration/register.js.map +0 -1
- package/dist/rpc/authentication.d.ts +0 -8
- package/dist/rpc/authentication.js +0 -16
- package/dist/rpc/authentication.js.map +0 -1
- package/dist/rpc/client.d.ts +0 -30
- package/dist/rpc/client.js +0 -101
- package/dist/rpc/client.js.map +0 -1
- package/dist/rpc/config.d.ts +0 -15
- package/dist/rpc/config.js +0 -6
- package/dist/rpc/config.js.map +0 -1
- package/dist/rpc/connection.d.ts +0 -8
- package/dist/rpc/connection.js +0 -15
- package/dist/rpc/connection.js.map +0 -1
- package/dist/rpc/registration.d.ts +0 -8
- package/dist/rpc/registration.js +0 -16
- package/dist/rpc/registration.js.map +0 -1
- package/dist/rpc/social.d.ts +0 -10
- package/dist/rpc/social.js +0 -18
- package/dist/rpc/social.js.map +0 -1
- package/dist/rpc/user.d.ts +0 -8
- package/dist/rpc/user.js +0 -19
- package/dist/rpc/user.js.map +0 -1
- package/dist/social/social.d.ts +0 -24
- package/dist/social/social.fixture.d.ts +0 -46
- package/dist/social/social.fixture.js +0 -31
- package/dist/social/social.fixture.js.map +0 -1
- package/dist/social/social.js +0 -39
- package/dist/social/social.js.map +0 -1
- package/dist/storage/storage.d.ts +0 -56
- package/dist/storage/storage.fixture.d.ts +0 -4
- package/dist/storage/storage.fixture.js +0 -10
- package/dist/storage/storage.fixture.js.map +0 -1
- package/dist/storage/storage.js +0 -111
- package/dist/storage/storage.js.map +0 -1
- package/dist/test/fixtures.d.ts +0 -15
- package/dist/test/fixtures.js +0 -56
- package/dist/test/fixtures.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/user/user.d.ts +0 -25
- package/dist/user/user.fixture.d.ts +0 -12
- package/dist/user/user.fixture.js +0 -20
- package/dist/user/user.fixture.js.map +0 -1
- package/dist/user/user.js +0 -38
- package/dist/user/user.js.map +0 -1
- package/dist/version.d.ts +0 -1
- package/dist/version.js +0 -2
- package/dist/version.js.map +0 -1
- package/src/authentication/authenticate.fixture.ts +0 -73
- package/src/authentication/authenticate.test.ts +0 -249
- package/src/authentication/authenticate.ts +0 -149
- package/src/capabilities/capabilities.ts +0 -83
- package/src/connection/connection.fixture.ts +0 -20
- package/src/connection/connection.test.ts +0 -60
- package/src/connection/connection.ts +0 -51
- package/src/effect.ts +0 -280
- package/src/email/email.fixture.ts +0 -44
- package/src/email/email.test.ts +0 -186
- package/src/email/email.ts +0 -148
- package/src/event/event.node.test.ts +0 -21
- package/src/event/event.test.ts +0 -37
- package/src/event/event.ts +0 -25
- package/src/index.ts +0 -407
- package/src/logging/eventLogger.test.ts +0 -104
- package/src/logging/eventLogger.ts +0 -41
- package/src/registration/register.fixture.ts +0 -96
- package/src/registration/register.test.ts +0 -216
- package/src/registration/register.ts +0 -158
- package/src/rpc/authentication.ts +0 -43
- package/src/rpc/client.ts +0 -174
- package/src/rpc/config.ts +0 -18
- package/src/rpc/connection.ts +0 -30
- package/src/rpc/registration.ts +0 -41
- package/src/rpc/social.ts +0 -45
- package/src/rpc/user.ts +0 -57
- package/src/social/social.fixture.ts +0 -45
- package/src/social/social.test.ts +0 -179
- package/src/social/social.ts +0 -82
- package/src/storage/storage.fixture.ts +0 -16
- package/src/storage/storage.test.ts +0 -206
- package/src/storage/storage.ts +0 -168
- package/src/test/fixtures.ts +0 -70
- package/src/user/user.fixture.ts +0 -33
- package/src/user/user.test.ts +0 -84
- package/src/user/user.ts +0 -73
- package/src/version.ts +0 -1
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Effect as E, Layer as L, Option as O } from 'effect';
|
|
2
|
-
import { VerifyEmailReq, VerifyEmailRes } from '@passlock/shared/dist/rpc/user.js';
|
|
3
|
-
import * as Fixtures from '../test/fixtures.js';
|
|
4
|
-
import { AuthenticationService } from '../authentication/authenticate.js';
|
|
5
|
-
import { UserClient } from '../rpc/user.js';
|
|
6
|
-
import { URLQueryString } from './email.js';
|
|
7
|
-
export const token = 'token';
|
|
8
|
-
export const code = 'code';
|
|
9
|
-
export const authType = 'passkey';
|
|
10
|
-
export const expireAt = Date.now() + 10000;
|
|
11
|
-
export const locationSearchTest = L.succeed(URLQueryString, URLQueryString.of(E.succeed(`?code=${code}`)));
|
|
12
|
-
export const authenticationServiceTest = L.succeed(AuthenticationService, AuthenticationService.of({
|
|
13
|
-
authenticatePasskey: () => E.succeed(Fixtures.principal),
|
|
14
|
-
}));
|
|
15
|
-
export const rpcVerifyEmailReq = new VerifyEmailReq({ token, code });
|
|
16
|
-
export const rpcVerifyEmailRes = new VerifyEmailRes({ principal: Fixtures.principal });
|
|
17
|
-
export const rpcClientTest = L.succeed(UserClient, UserClient.of({
|
|
18
|
-
isExistingUser: () => E.succeed({ existingUser: true, detail: O.none() }),
|
|
19
|
-
verifyEmail: () => E.succeed(rpcVerifyEmailRes),
|
|
20
|
-
resendVerificationEmail: () => E.fail(Fixtures.notImplemented),
|
|
21
|
-
}));
|
|
22
|
-
export const principal = Fixtures.principal;
|
|
23
|
-
export const storedToken = Fixtures.storedToken;
|
|
24
|
-
export const storageServiceTest = Fixtures.storageServiceTest;
|
|
25
|
-
//# sourceMappingURL=email.fixture.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"email.fixture.js","sourceRoot":"","sources":["../../src/email/email.fixture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AAE7D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAElF,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,cAAc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Ac,CAAC;CAC/D,CAAC,CACH,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAA;AAE3C,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAA;AAE/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC,kBAAkB,CAAA"}
|
package/dist/email/email.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Email verification effects
|
|
3
|
-
*/
|
|
4
|
-
import { Context, Effect as E, Layer, Option as O, flow, identity, pipe } from 'effect';
|
|
5
|
-
import { BadRequest } from '@passlock/shared/dist/error/error.js';
|
|
6
|
-
import { VerifyEmailReq } from '@passlock/shared/dist/rpc/user.js';
|
|
7
|
-
import { AuthenticationService } from '../authentication/authenticate.js';
|
|
8
|
-
import { UserClient } from '../rpc/user.js';
|
|
9
|
-
import { StorageService } from '../storage/storage.js';
|
|
10
|
-
/* Dependencies */
|
|
11
|
-
export class URLQueryString extends Context.Tag('@utils/URLQueryString')() {
|
|
12
|
-
}
|
|
13
|
-
/* Service */
|
|
14
|
-
export class EmailService extends Context.Tag('@services/EmailService')() {
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Check for existing token in sessionStorage,
|
|
18
|
-
* otherwise force passkey re-authentication
|
|
19
|
-
* @returns
|
|
20
|
-
*/
|
|
21
|
-
const getToken = () => {
|
|
22
|
-
return E.gen(function* (_) {
|
|
23
|
-
// Check for existing token
|
|
24
|
-
const storageService = yield* _(StorageService);
|
|
25
|
-
const existingTokenE = storageService.getToken('passkey');
|
|
26
|
-
const authenticationService = yield* _(AuthenticationService);
|
|
27
|
-
const tokenE = E.matchEffect(existingTokenE, {
|
|
28
|
-
onSuccess: token => E.succeed(token),
|
|
29
|
-
onFailure: () =>
|
|
30
|
-
// No token, need to authenticate the user
|
|
31
|
-
pipe(authenticationService.authenticatePasskey({
|
|
32
|
-
userVerification: O.some('preferred'),
|
|
33
|
-
email: O.none(),
|
|
34
|
-
}), E.map(principal => ({
|
|
35
|
-
token: principal.jti,
|
|
36
|
-
authType: principal.authType,
|
|
37
|
-
expiry: principal.exp.getTime(),
|
|
38
|
-
}))),
|
|
39
|
-
});
|
|
40
|
-
const token = yield* _(tokenE);
|
|
41
|
-
yield* _(storageService.clearToken('passkey'));
|
|
42
|
-
return token;
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Look for ?code=<code> in the url
|
|
47
|
-
* @returns
|
|
48
|
-
*/
|
|
49
|
-
export const extractCodeFromHref = () => {
|
|
50
|
-
return pipe(URLQueryString, E.flatMap(identity), E.map(search => new URLSearchParams(search)), E.flatMap(params => O.fromNullable(params.get('code'))));
|
|
51
|
-
};
|
|
52
|
-
/* Effects */
|
|
53
|
-
/**
|
|
54
|
-
* Verify the mailbox using the given code
|
|
55
|
-
* @param request
|
|
56
|
-
* @returns
|
|
57
|
-
*/
|
|
58
|
-
export const verifyEmail = (request) => {
|
|
59
|
-
return E.gen(function* (_) {
|
|
60
|
-
// Re-authenticate the user if required
|
|
61
|
-
const { token } = yield* _(getToken());
|
|
62
|
-
yield* _(E.logDebug('Making request'));
|
|
63
|
-
const client = yield* _(UserClient);
|
|
64
|
-
const { principal } = yield* _(client.verifyEmail(new VerifyEmailReq({ token, code: request.code })));
|
|
65
|
-
return principal;
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Look for a code in the current url and verify it
|
|
70
|
-
* @returns
|
|
71
|
-
*/
|
|
72
|
-
export const verifyEmailLink = () => pipe(extractCodeFromHref(), E.mapError(() => new BadRequest({ message: 'Expected ?code=xxx in window.location' })), E.flatMap(code => verifyEmail({ code })));
|
|
73
|
-
/* Live */
|
|
74
|
-
/* v8 ignore start */
|
|
75
|
-
export const EmailServiceLive = Layer.effect(EmailService, E.gen(function* (_) {
|
|
76
|
-
const context = yield* _(E.context());
|
|
77
|
-
return EmailService.of({
|
|
78
|
-
verifyEmailCode: flow(verifyEmail, E.provide(context)),
|
|
79
|
-
verifyEmailLink: flow(verifyEmailLink, E.provide(context)),
|
|
80
|
-
});
|
|
81
|
-
}));
|
|
82
|
-
/* v8 ignore stop */
|
|
83
|
-
//# sourceMappingURL=email.js.map
|
package/dist/email/email.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"email.js","sourceRoot":"","sources":["../../src/email/email.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAEvF,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AAEjE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAGlE,OAAO,EAA6B,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AACpG,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAoB,MAAM,uBAAuB,CAAA;AAYxE,kBAAkB;AAElB,MAAM,OAAO,cAAe,SAAQ,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,EAGrE;CAAG;AAEN,aAAa;AAEb,MAAM,OAAO,YAAa,SAAQ,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,EAMpE;CAAG;AAMN;;;;GAIG;AACH,MAAM,QAAQ,GAAG,GAAG,EAAE;IACpB,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvB,2BAA2B;QAC3B,MAAM,cAAc,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAA;QAC/C,MAAM,cAAc,GAAG,cAAc,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QACzD,MAAM,qBAAqB,GAAG,KAAK,CAAC,CAAC,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AAC;QACrB,eAAe,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACtD,eAAe,EAAE,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;KAC3D,CAAC,CAAA;AACJ,CAAC,CAAC,CACH,CAAA;AACD,oBAAoB"}
|
package/dist/event/event.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fire DOM events
|
|
3
|
-
*/
|
|
4
|
-
import { Effect } from 'effect';
|
|
5
|
-
import { InternalBrowserError } from '@passlock/shared/dist/error/error.js';
|
|
6
|
-
export declare const DebugMessage = "PasslogDebugMessage";
|
|
7
|
-
export declare const fireEvent: (message: string) => Effect.Effect<void, InternalBrowserError, never>;
|
|
8
|
-
export declare function isPasslockEvent(event: Event): event is CustomEvent;
|
package/dist/event/event.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fire DOM events
|
|
3
|
-
*/
|
|
4
|
-
import { Effect } from 'effect';
|
|
5
|
-
import { InternalBrowserError } from '@passlock/shared/dist/error/error.js';
|
|
6
|
-
export const DebugMessage = 'PasslogDebugMessage';
|
|
7
|
-
export const fireEvent = (message) => {
|
|
8
|
-
return Effect.try({
|
|
9
|
-
try: () => {
|
|
10
|
-
const evt = new CustomEvent(DebugMessage, { detail: message });
|
|
11
|
-
globalThis.dispatchEvent(evt);
|
|
12
|
-
},
|
|
13
|
-
catch: () => {
|
|
14
|
-
return new InternalBrowserError({ message: 'Unable to fire custom event' });
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
export function isPasslockEvent(event) {
|
|
19
|
-
if (event.type !== DebugMessage)
|
|
20
|
-
return false;
|
|
21
|
-
return 'detail' in event;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=event.js.map
|
package/dist/event/event.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/event/event.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAA;AAE3E,MAAM,CAAC,MAAM,YAAY,GAAG,qBAAqB,CAAA;AAEjD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAe,EAAE,EAAE;IAC3C,OAAO,MAAM,CAAC,GAAG,CAAC;QAChB,GAAG,EAAE,GAAG,EAAE;YACR,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,YAAY,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;YAC9D,UAAU,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;QAC/B,CAAC;QACD,KAAK,EAAE,GAAG,EAAE;YACV,OAAO,IAAI,oBAAoB,CAAC,EAAE,OAAO,EAAE,6BAA6B,EAAE,CAAC,CAAA;QAC7E,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,UAAU,eAAe,CAAC,KAAY;IAC1C,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,KAAK,CAAA;IAC7C,OAAO,QAAQ,IAAI,KAAK,CAAA;AAC1B,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logger implementation that also fires DOM events.
|
|
3
|
-
* This is useful to allow external code to plug into the logging
|
|
4
|
-
* mechanism. E.g. the Passlock demo subscribes to events to generate
|
|
5
|
-
* a typewriter style effect
|
|
6
|
-
*/
|
|
7
|
-
import { Effect as E } from 'effect';
|
|
8
|
-
/**
|
|
9
|
-
* Some log messages span multiple lines/include json etc which is
|
|
10
|
-
* better output without being formatted by Effect's logging framework
|
|
11
|
-
*
|
|
12
|
-
* @param message
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export declare const logRaw: <T>(message: T) => E.Effect<void, never, never>;
|
|
16
|
-
export declare const DebugMessage = "PasslogDebugMessage";
|
|
17
|
-
export declare const eventLoggerLive: import("effect/Layer").Layer<never, never, never>;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logger implementation that also fires DOM events.
|
|
3
|
-
* This is useful to allow external code to plug into the logging
|
|
4
|
-
* mechanism. E.g. the Passlock demo subscribes to events to generate
|
|
5
|
-
* a typewriter style effect
|
|
6
|
-
*/
|
|
7
|
-
import { Effect as E, LogLevel, Logger } from 'effect';
|
|
8
|
-
/**
|
|
9
|
-
* Some log messages span multiple lines/include json etc which is
|
|
10
|
-
* better output without being formatted by Effect's logging framework
|
|
11
|
-
*
|
|
12
|
-
* @param message
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export const logRaw = (message) => {
|
|
16
|
-
return E.sync(() => {
|
|
17
|
-
console.log(message);
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
export const DebugMessage = 'PasslogDebugMessage';
|
|
21
|
-
const dispatch = (message) => {
|
|
22
|
-
try {
|
|
23
|
-
const evt = new CustomEvent(DebugMessage, { detail: message });
|
|
24
|
-
globalThis.dispatchEvent(evt);
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
globalThis.console.log('Unable to fire custom event');
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
export const eventLoggerLive = Logger.add(Logger.make(({ logLevel, message }) => {
|
|
31
|
-
if (typeof message === 'string' && logLevel !== LogLevel.Debug) {
|
|
32
|
-
dispatch(message);
|
|
33
|
-
}
|
|
34
|
-
else if (Array.isArray(message) && logLevel !== LogLevel.Debug) {
|
|
35
|
-
message.forEach(dispatch);
|
|
36
|
-
}
|
|
37
|
-
}));
|
|
38
|
-
//# sourceMappingURL=eventLogger.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"eventLogger.js","sourceRoot":"","sources":["../../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-
import { Context, Effect as E, Layer } from 'effect';
|
|
2
|
-
import type { Duplicate, NotSupported } from '@passlock/shared/dist/error/error.js';
|
|
3
|
-
import { InternalBrowserError } from '@passlock/shared/dist/error/error.js';
|
|
4
|
-
import type { OptionsErrors, VerificationErrors } from '@passlock/shared/dist/rpc/registration.js';
|
|
5
|
-
import { OptionsReq } from '@passlock/shared/dist/rpc/registration.js';
|
|
6
|
-
import type { RegistrationCredential } from '@passlock/shared/dist/schema/passkey.js';
|
|
7
|
-
import type { Principal } from '@passlock/shared/dist/schema/principal.js';
|
|
8
|
-
import { Capabilities } from '../capabilities/capabilities.js';
|
|
9
|
-
import { RegistrationClient } from '../rpc/registration.js';
|
|
10
|
-
import { StorageService } from '../storage/storage.js';
|
|
11
|
-
import type { UserService } from '../user/user.js';
|
|
12
|
-
export type RegistrationRequest = OptionsReq;
|
|
13
|
-
declare const CreateCredential_base: Context.TagClass<CreateCredential, "@services/CreateCredential", {
|
|
14
|
-
createCredential: (request: CredentialCreationOptions) => E.Effect<RegistrationCredential, InternalBrowserError | Duplicate>;
|
|
15
|
-
}>;
|
|
16
|
-
export declare class CreateCredential extends CreateCredential_base {
|
|
17
|
-
}
|
|
18
|
-
export type RegistrationErrors = NotSupported | OptionsErrors | VerificationErrors;
|
|
19
|
-
declare const RegistrationService_base: Context.TagClass<RegistrationService, "@services/RegistrationService", {
|
|
20
|
-
registerPasskey: (request: RegistrationRequest) => E.Effect<Principal, RegistrationErrors>;
|
|
21
|
-
}>;
|
|
22
|
-
export declare class RegistrationService extends RegistrationService_base {
|
|
23
|
-
}
|
|
24
|
-
type Dependencies = Capabilities | CreateCredential | StorageService | UserService | RegistrationClient;
|
|
25
|
-
export declare const registerPasskey: (request: RegistrationRequest) => E.Effect<Principal, RegistrationErrors, Dependencies>;
|
|
26
|
-
export declare const RegistrationServiceLive: Layer.Layer<RegistrationService, never, Capabilities | StorageService | RegistrationClient | UserService | CreateCredential>;
|
|
27
|
-
export {};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Layer as L } from 'effect';
|
|
2
|
-
import { OptionsReq, OptionsRes, VerificationReq, VerificationRes } from '@passlock/shared/dist/rpc/registration.js';
|
|
3
|
-
import type { RegistrationCredential } from '@passlock/shared/dist/schema/passkey.js';
|
|
4
|
-
import { RegistrationClient } from '../rpc/registration.js';
|
|
5
|
-
import { UserService } from '../user/user.js';
|
|
6
|
-
import { CreateCredential, type RegistrationRequest } from './register.js';
|
|
7
|
-
export declare const session = "session";
|
|
8
|
-
export declare const token = "token";
|
|
9
|
-
export declare const code = "code";
|
|
10
|
-
export declare const authType = "passkey";
|
|
11
|
-
export declare const expireAt: number;
|
|
12
|
-
export declare const registrationRequest: RegistrationRequest;
|
|
13
|
-
export declare const rpcOptionsReq: OptionsReq;
|
|
14
|
-
export declare const registrationOptions: OptionsRes;
|
|
15
|
-
export declare const rpcOptionsRes: OptionsRes;
|
|
16
|
-
export declare const credential: RegistrationCredential;
|
|
17
|
-
export declare const rpcVerificationReq: VerificationReq;
|
|
18
|
-
export declare const rpcVerificationRes: VerificationRes;
|
|
19
|
-
export declare const createCredentialTest: L.Layer<CreateCredential, never, never>;
|
|
20
|
-
export declare const userServiceTest: L.Layer<UserService, never, never>;
|
|
21
|
-
export declare const rpcClientTest: L.Layer<RegistrationClient, never, never>;
|
|
22
|
-
export declare const principal: {
|
|
23
|
-
readonly email?: string;
|
|
24
|
-
readonly givenName?: string;
|
|
25
|
-
readonly familyName?: string;
|
|
26
|
-
readonly emailVerified?: boolean;
|
|
27
|
-
readonly user?: {
|
|
28
|
-
readonly id: string;
|
|
29
|
-
readonly email: string;
|
|
30
|
-
readonly givenName: string;
|
|
31
|
-
readonly familyName: string;
|
|
32
|
-
readonly emailVerified: boolean;
|
|
33
|
-
};
|
|
34
|
-
readonly iss: string;
|
|
35
|
-
readonly aud: string;
|
|
36
|
-
readonly sub: string;
|
|
37
|
-
readonly iat: Date;
|
|
38
|
-
readonly nbf: Date;
|
|
39
|
-
readonly exp: Date;
|
|
40
|
-
readonly jti: string;
|
|
41
|
-
readonly token: string;
|
|
42
|
-
readonly userVerified: boolean;
|
|
43
|
-
readonly authType: "email" | "apple" | "google" | "passkey";
|
|
44
|
-
readonly authId: string;
|
|
45
|
-
readonly authStatement: {
|
|
46
|
-
readonly userVerified: boolean;
|
|
47
|
-
readonly authType: "email" | "apple" | "google" | "passkey";
|
|
48
|
-
readonly authTimestamp: Date;
|
|
49
|
-
};
|
|
50
|
-
readonly expireAt: Date;
|
|
51
|
-
};
|
|
52
|
-
export declare const capabilitiesTest: L.Layer<import("../capabilities/capabilities.js").Capabilities, never, never>;
|
|
53
|
-
export declare const storageServiceTest: L.Layer<import("../storage/storage.js").StorageService, never, never>;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Effect as E, Layer as L, Option as O } from 'effect';
|
|
2
|
-
import { OptionsReq, OptionsRes, VerificationReq, VerificationRes, } from '@passlock/shared/dist/rpc/registration.js';
|
|
3
|
-
import * as Fixtures from '../test/fixtures.js';
|
|
4
|
-
import { RegistrationClient } from '../rpc/registration.js';
|
|
5
|
-
import { UserService } from '../user/user.js';
|
|
6
|
-
import { CreateCredential } from './register.js';
|
|
7
|
-
export const session = 'session';
|
|
8
|
-
export const token = 'token';
|
|
9
|
-
export const code = 'code';
|
|
10
|
-
export const authType = 'passkey';
|
|
11
|
-
export const expireAt = Date.now() + 10000;
|
|
12
|
-
export const registrationRequest = {
|
|
13
|
-
email: 'jdoe@gmail.com',
|
|
14
|
-
givenName: O.some('john'),
|
|
15
|
-
familyName: O.some('doe'),
|
|
16
|
-
userVerification: O.none(),
|
|
17
|
-
verifyEmail: O.none(),
|
|
18
|
-
};
|
|
19
|
-
export const rpcOptionsReq = new OptionsReq(registrationRequest);
|
|
20
|
-
export const registrationOptions = {
|
|
21
|
-
session,
|
|
22
|
-
publicKey: {
|
|
23
|
-
rp: {
|
|
24
|
-
name: 'passlock',
|
|
25
|
-
id: 'passlock.dev',
|
|
26
|
-
},
|
|
27
|
-
user: {
|
|
28
|
-
name: 'john doe',
|
|
29
|
-
id: 'jdoe',
|
|
30
|
-
displayName: 'john doe',
|
|
31
|
-
},
|
|
32
|
-
challenge: 'FKZSl_saKu5OXjLLwoq8eK3wlD8XgpGiS10SszW5RiE',
|
|
33
|
-
pubKeyCredParams: [],
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
export const rpcOptionsRes = new OptionsRes(registrationOptions);
|
|
37
|
-
export const credential = {
|
|
38
|
-
type: 'public-key',
|
|
39
|
-
id: '1',
|
|
40
|
-
rawId: '1',
|
|
41
|
-
response: {
|
|
42
|
-
transports: [],
|
|
43
|
-
clientDataJSON: '',
|
|
44
|
-
attestationObject: '',
|
|
45
|
-
},
|
|
46
|
-
clientExtensionResults: {},
|
|
47
|
-
};
|
|
48
|
-
export const rpcVerificationReq = new VerificationReq({
|
|
49
|
-
session,
|
|
50
|
-
credential,
|
|
51
|
-
verifyEmail: O.none(),
|
|
52
|
-
});
|
|
53
|
-
export const rpcVerificationRes = new VerificationRes({ principal: Fixtures.principal });
|
|
54
|
-
export const createCredentialTest = L.succeed(CreateCredential, CreateCredential.of({ createCredential: () => E.succeed(credential) }));
|
|
55
|
-
export const userServiceTest = L.succeed(UserService, UserService.of({
|
|
56
|
-
isExistingUser: () => E.succeed(false),
|
|
57
|
-
resendVerificationEmail: () => E.succeed(true),
|
|
58
|
-
}));
|
|
59
|
-
export const rpcClientTest = L.succeed(RegistrationClient, RegistrationClient.of({
|
|
60
|
-
getRegistrationOptions: () => E.succeed(rpcOptionsRes),
|
|
61
|
-
verifyRegistrationCredential: () => E.succeed(rpcVerificationRes),
|
|
62
|
-
}));
|
|
63
|
-
export const principal = Fixtures.principal;
|
|
64
|
-
export const capabilitiesTest = Fixtures.capabilitiesTest;
|
|
65
|
-
export const storageServiceTest = Fixtures.storageServiceTest;
|
|
66
|
-
//# sourceMappingURL=register.fixture.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"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AAC,OAAO,CACpC,kBAAkB,EAClB,kBAAkB,CAAC,EAAE,CAAC;IACpB,sBAAsB,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IACtD,4BAA4B,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC;CAClE,CAAC,CACH,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAA;AAE3C,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAA;AAEzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC,kBAAkB,CAAA"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* User & passkey registration effects
|
|
3
|
-
*/
|
|
4
|
-
import { parseCreationOptionsFromJSON, } from '@github/webauthn-json/browser-ponyfill';
|
|
5
|
-
import { Context, Effect as E, Layer, flow, pipe } from 'effect';
|
|
6
|
-
import { InternalBrowserError } from '@passlock/shared/dist/error/error.js';
|
|
7
|
-
import { OptionsReq, VerificationReq } from '@passlock/shared/dist/rpc/registration.js';
|
|
8
|
-
import { Capabilities } from '../capabilities/capabilities.js';
|
|
9
|
-
import { RegistrationClient } from '../rpc/registration.js';
|
|
10
|
-
import { StorageService } from '../storage/storage.js';
|
|
11
|
-
/* Dependencies */
|
|
12
|
-
export class CreateCredential extends Context.Tag('@services/CreateCredential')() {
|
|
13
|
-
}
|
|
14
|
-
/* Service */
|
|
15
|
-
export class RegistrationService extends Context.Tag('@services/RegistrationService')() {
|
|
16
|
-
}
|
|
17
|
-
/* Utilities */
|
|
18
|
-
const fetchOptions = (request) => {
|
|
19
|
-
return E.gen(function* (_) {
|
|
20
|
-
yield* _(E.logDebug('Making request'));
|
|
21
|
-
const rpcClient = yield* _(RegistrationClient);
|
|
22
|
-
const { publicKey, session } = yield* _(rpcClient.getRegistrationOptions(request));
|
|
23
|
-
yield* _(E.logDebug('Converting Passlock options to CredentialCreationOptions'));
|
|
24
|
-
const options = yield* _(toCreationOptions({ publicKey }));
|
|
25
|
-
return { options, session };
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
const toCreationOptions = (jsonOptions) => {
|
|
29
|
-
return pipe(E.try(() => parseCreationOptionsFromJSON(jsonOptions)), E.mapError(error => new InternalBrowserError({
|
|
30
|
-
message: 'Browser was unable to create credential creation options',
|
|
31
|
-
detail: String(error.error),
|
|
32
|
-
})));
|
|
33
|
-
};
|
|
34
|
-
const verifyCredential = (request) => {
|
|
35
|
-
return E.gen(function* (_) {
|
|
36
|
-
yield* _(E.logDebug('Making request'));
|
|
37
|
-
const rpcClient = yield* _(RegistrationClient);
|
|
38
|
-
const { principal } = yield* _(rpcClient.verifyRegistrationCredential(request));
|
|
39
|
-
return principal;
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
export const registerPasskey = (request) => {
|
|
43
|
-
const effect = E.gen(function* (_) {
|
|
44
|
-
yield* _(E.logInfo('Checking if browser supports Passkeys'));
|
|
45
|
-
const capabilities = yield* _(Capabilities);
|
|
46
|
-
yield* _(capabilities.passkeySupport);
|
|
47
|
-
yield* _(E.logInfo('Fetching registration options from Passlock'));
|
|
48
|
-
const { options, session } = yield* fetchOptions(new OptionsReq(request));
|
|
49
|
-
yield* _(E.logInfo('Building new credential'));
|
|
50
|
-
const { createCredential } = yield* _(CreateCredential);
|
|
51
|
-
const credential = yield* _(createCredential(options));
|
|
52
|
-
yield* _(E.logInfo('Storing credential public key in Passlock'));
|
|
53
|
-
const verificationRequest = new VerificationReq({
|
|
54
|
-
...request,
|
|
55
|
-
credential,
|
|
56
|
-
session,
|
|
57
|
-
});
|
|
58
|
-
const principal = yield* _(verifyCredential(verificationRequest));
|
|
59
|
-
const storageService = yield* _(StorageService);
|
|
60
|
-
yield* _(storageService.storeToken(principal));
|
|
61
|
-
yield* _(E.logDebug('Storing token in local storage'));
|
|
62
|
-
yield* _(E.logDebug('Defering local token deletion'));
|
|
63
|
-
const delayedClearTokenE = pipe(storageService.clearExpiredToken('passkey'), E.delay('6 minutes'), E.fork);
|
|
64
|
-
yield* _(delayedClearTokenE);
|
|
65
|
-
return principal;
|
|
66
|
-
});
|
|
67
|
-
return E.catchTag(effect, 'InternalBrowserError', e => E.die(e));
|
|
68
|
-
};
|
|
69
|
-
/* Live */
|
|
70
|
-
/* v8 ignore start */
|
|
71
|
-
export const RegistrationServiceLive = Layer.effect(RegistrationService, E.gen(function* (_) {
|
|
72
|
-
const context = yield* _(E.context());
|
|
73
|
-
return RegistrationService.of({
|
|
74
|
-
registerPasskey: flow(registerPasskey, E.provide(context)),
|
|
75
|
-
});
|
|
76
|
-
}));
|
|
77
|
-
/* v8 ignore stop */
|
|
78
|
-
//# sourceMappingURL=register.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/registration/register.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAEL,4BAA4B,GAC7B,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAGhE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAA;AAE3E,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAA;AAIvF,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAOtD,kBAAkB;AAElB,MAAM,OAAO,gBAAiB,SAAQ,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,EAO5E;CAAG;AAMN,aAAa;AAEb,MAAM,OAAO,mBAAoB,SAAQ,OAAO,CAAC,GAAG,CAAC,+BAA+B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B,eAAe,EAAE,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;KAC3D,CAAC,CAAA;AACJ,CAAC,CAAC,CACH,CAAA;AACD,oBAAoB"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Context, Layer } from 'effect';
|
|
2
|
-
import { type AuthenticationService } from '@passlock/shared/dist/rpc/authentication.js';
|
|
3
|
-
import { Dispatcher } from './client.js';
|
|
4
|
-
declare const AuthenticationClient_base: Context.TagClass<AuthenticationClient, "@passkey/auth/client", AuthenticationService>;
|
|
5
|
-
export declare class AuthenticationClient extends AuthenticationClient_base {
|
|
6
|
-
}
|
|
7
|
-
export declare const AuthenticationClientLive: Layer.Layer<AuthenticationClient, never, Dispatcher>;
|
|
8
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Context, Effect as E, Layer } from 'effect';
|
|
2
|
-
import { OPTIONS_ENDPOINT, OptionsErrors, OptionsReq, OptionsRes, VERIFY_ENDPOINT, VerificationErrors, VerificationReq, VerificationRes, } from '@passlock/shared/dist/rpc/authentication.js';
|
|
3
|
-
import { Dispatcher, makePostRequest } from './client.js';
|
|
4
|
-
/* Client */
|
|
5
|
-
export class AuthenticationClient extends Context.Tag('@passkey/auth/client')() {
|
|
6
|
-
}
|
|
7
|
-
export const AuthenticationClientLive = Layer.effect(AuthenticationClient, E.gen(function* (_) {
|
|
8
|
-
const dispatcher = yield* _(Dispatcher);
|
|
9
|
-
const optionsResolver = makePostRequest(OptionsReq, OptionsRes, OptionsErrors, dispatcher);
|
|
10
|
-
const verifyResolver = makePostRequest(VerificationReq, VerificationRes, VerificationErrors, dispatcher);
|
|
11
|
-
return {
|
|
12
|
-
getAuthenticationOptions: req => optionsResolver(OPTIONS_ENDPOINT, req),
|
|
13
|
-
verifyAuthenticationCredential: req => verifyResolver(VERIFY_ENDPOINT, req),
|
|
14
|
-
};
|
|
15
|
-
}));
|
|
16
|
-
//# sourceMappingURL=authentication.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../src/rpc/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAEpD,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,eAAe,GAChB,MAAM,6CAA6C,CAAA;AAEpD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAEzD,YAAY;AAEZ,MAAM,OAAO,oBAAqB,SAAQ,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,EAG1E;CAAG;AAEN,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC,MAAM,CAClD,oBAAoB,EACpB,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;IAChB,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAA;IAEvC,MAAM,eAAe,GAAG,eAAe,CAAC,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,CAAC,CAAA;IAE1F,MAAM,cAAc,GAAG,eAAe,CACpC,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,UAAU,CACX,CAAA;IAED,OAAO;QACL,wBAAwB,EAAE,GAAG,CAAC,EAAE,CAAC,eAAe,CAAC,gBAAgB,EAAE,GAAG,CAAC;QACvE,8BAA8B,EAAE,GAAG,CAAC,EAAE,CAAC,cAAc,CAAC,eAAe,EAAE,GAAG,CAAC;KAC5E,CAAA;AACH,CAAC,CAAC,CACH,CAAA"}
|
package/dist/rpc/client.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as S from '@effect/schema/Schema';
|
|
2
|
-
import { Context, Effect as E, Layer } from 'effect';
|
|
3
|
-
import { NetworkError } from '@passlock/shared/dist/error/error.js';
|
|
4
|
-
import { RetrySchedule, RpcConfig } from './config.js';
|
|
5
|
-
export type DispatcherResponse = {
|
|
6
|
-
status: number;
|
|
7
|
-
body: object;
|
|
8
|
-
};
|
|
9
|
-
declare const Dispatcher_base: Context.TagClass<Dispatcher, "@rpc/Dispatcher", {
|
|
10
|
-
get: (path: string) => E.Effect<DispatcherResponse, NetworkError>;
|
|
11
|
-
post: (path: string, body: string) => E.Effect<DispatcherResponse, NetworkError>;
|
|
12
|
-
}>;
|
|
13
|
-
/** To send the JSON to the backend */
|
|
14
|
-
export declare class Dispatcher extends Dispatcher_base {
|
|
15
|
-
}
|
|
16
|
-
/** Fires off client requests using fetch */
|
|
17
|
-
/** TODO: Write tests */
|
|
18
|
-
/** TODO: Evaluate platform/http client (if now stable) */
|
|
19
|
-
export declare const DispatcherLive: Layer.Layer<Dispatcher, never, RpcConfig | RetrySchedule>;
|
|
20
|
-
export declare const makeGetRequest: <Res, ResEnc, Err, ErrEnc>(responseSchema: S.Schema<Res, ResEnc, never>, errorSchema: S.Schema<Err, ErrEnc, never>, dispatcher: Dispatcher["Type"]) => (path: string) => E.Effect<Res, Exclude<Exclude<Err, {
|
|
21
|
-
_tag: "ParseError";
|
|
22
|
-
}>, {
|
|
23
|
-
_tag: "NetworkError";
|
|
24
|
-
}>, never>;
|
|
25
|
-
export declare const makePostRequest: <Req, ReqEnc, Res, ResEnc, Err, ErrEnc>(requestSchema: S.Schema<Req, ReqEnc, never>, responseSchema: S.Schema<Res, ResEnc, never>, errorSchema: S.Schema<Err, ErrEnc, never>, dispatcher: Dispatcher["Type"]) => (path: string, request: Req) => E.Effect<Res, Exclude<Exclude<Err, {
|
|
26
|
-
_tag: "ParseError";
|
|
27
|
-
}>, {
|
|
28
|
-
_tag: "NetworkError";
|
|
29
|
-
}>, never>;
|
|
30
|
-
export {};
|
package/dist/rpc/client.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import * as S from '@effect/schema/Schema';
|
|
2
|
-
import { Context, Effect as E, Layer, pipe } from 'effect';
|
|
3
|
-
import { NetworkError } from '@passlock/shared/dist/error/error.js';
|
|
4
|
-
import { PASSLOCK_CLIENT_VERSION } from '../version.js';
|
|
5
|
-
import { RetrySchedule, RpcConfig } from './config.js';
|
|
6
|
-
/** To send the JSON to the backend */
|
|
7
|
-
export class Dispatcher extends Context.Tag('@rpc/Dispatcher')() {
|
|
8
|
-
}
|
|
9
|
-
/** Fires off client requests using fetch */
|
|
10
|
-
/** TODO: Write tests */
|
|
11
|
-
/** TODO: Evaluate platform/http client (if now stable) */
|
|
12
|
-
export const DispatcherLive = Layer.effect(Dispatcher, E.gen(function* (_) {
|
|
13
|
-
const { schedule } = yield* _(RetrySchedule);
|
|
14
|
-
const { tenancyId, clientId, endpoint: maybeEndpoint } = yield* _(RpcConfig);
|
|
15
|
-
const parseJson = (res, url) => E.tryPromise({
|
|
16
|
-
try: () => res.json(),
|
|
17
|
-
catch: e => new NetworkError({
|
|
18
|
-
message: 'Unable to extract json response from ' + url,
|
|
19
|
-
detail: String(e),
|
|
20
|
-
}),
|
|
21
|
-
});
|
|
22
|
-
// 400 errors are reflected in the RPC response error channel
|
|
23
|
-
// so in network terms they're still "ok"
|
|
24
|
-
const assertNo500s = (res, url) => {
|
|
25
|
-
if (res.status >= 500) {
|
|
26
|
-
return E.fail(new NetworkError({
|
|
27
|
-
message: 'Received 500 response code from ' + url,
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
else
|
|
31
|
-
return E.void;
|
|
32
|
-
};
|
|
33
|
-
const parseJsonObject = (json) => {
|
|
34
|
-
return typeof json === 'object' && json !== null
|
|
35
|
-
? E.succeed(json)
|
|
36
|
-
: E.fail(new NetworkError({
|
|
37
|
-
message: `Expected JSON object to be returned from RPC endpoint, actual ${typeof json}`,
|
|
38
|
-
}));
|
|
39
|
-
};
|
|
40
|
-
const buildUrl = (_path) => {
|
|
41
|
-
const endpoint = maybeEndpoint || 'https://api.passlock.dev';
|
|
42
|
-
// drop leading /
|
|
43
|
-
const path = _path.replace(/^\//, '');
|
|
44
|
-
return `${endpoint}/${tenancyId}/${path}`;
|
|
45
|
-
};
|
|
46
|
-
return {
|
|
47
|
-
get: (path) => {
|
|
48
|
-
const effect = E.gen(function* (_) {
|
|
49
|
-
const headers = {
|
|
50
|
-
'Accept': 'application/json',
|
|
51
|
-
'X-CLIENT-ID': clientId,
|
|
52
|
-
'X-PASSLOCK-CLIENT-VERSION': PASSLOCK_CLIENT_VERSION,
|
|
53
|
-
};
|
|
54
|
-
const url = buildUrl(path);
|
|
55
|
-
const res = yield* _(E.tryPromise({
|
|
56
|
-
try: () => fetch(url, { method: 'GET', headers }),
|
|
57
|
-
catch: e => new NetworkError({ message: 'Unable to fetch from ' + url, detail: String(e) }),
|
|
58
|
-
}));
|
|
59
|
-
const json = yield* _(parseJson(res, url));
|
|
60
|
-
yield* _(assertNo500s(res, url));
|
|
61
|
-
const jsonObject = yield* _(parseJsonObject(json));
|
|
62
|
-
return { status: res.status, body: jsonObject };
|
|
63
|
-
});
|
|
64
|
-
return E.retry(effect, { schedule });
|
|
65
|
-
},
|
|
66
|
-
post: (_path, body) => {
|
|
67
|
-
const effect = E.gen(function* (_) {
|
|
68
|
-
const headers = {
|
|
69
|
-
'Content-Type': 'application/json',
|
|
70
|
-
'Accept': 'application/json',
|
|
71
|
-
'X-CLIENT-ID': clientId,
|
|
72
|
-
'X-PASSLOCK-CLIENT-VERSION': PASSLOCK_CLIENT_VERSION,
|
|
73
|
-
};
|
|
74
|
-
// drop leading /
|
|
75
|
-
const url = buildUrl(_path);
|
|
76
|
-
const res = yield* _(E.tryPromise({
|
|
77
|
-
try: () => fetch(url, { method: 'POST', headers, body }),
|
|
78
|
-
catch: e => new NetworkError({ message: 'Unable to fetch from ' + url, detail: String(e) }),
|
|
79
|
-
}));
|
|
80
|
-
const json = yield* _(parseJson(res, url));
|
|
81
|
-
yield* _(assertNo500s(res, url));
|
|
82
|
-
const jsonObject = yield* _(parseJsonObject(json));
|
|
83
|
-
return { status: res.status, body: jsonObject };
|
|
84
|
-
});
|
|
85
|
-
return E.retry(effect, { schedule });
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
}));
|
|
89
|
-
export const makeGetRequest = (responseSchema, errorSchema, dispatcher) => (path) => pipe(dispatcher.get(path), E.flatMap(res => {
|
|
90
|
-
if (res.status === 200)
|
|
91
|
-
return S.decodeUnknown(responseSchema)(res.body);
|
|
92
|
-
return pipe(S.decodeUnknown(errorSchema)(res.body), E.flatMap(err => E.fail(err)));
|
|
93
|
-
}), E.catchTag('ParseError', e => E.die(e)), E.catchTag('NetworkError', e => E.die(e)));
|
|
94
|
-
export const makePostRequest = (requestSchema, responseSchema, errorSchema, dispatcher) => (path, request) => {
|
|
95
|
-
return pipe(S.encode(requestSchema)(request), E.flatMap(request => dispatcher.post(path, JSON.stringify(request))), E.flatMap(res => {
|
|
96
|
-
if (res.status === 200)
|
|
97
|
-
return S.decodeUnknown(responseSchema)(res.body);
|
|
98
|
-
return pipe(S.decodeUnknown(errorSchema)(res.body), E.flatMap(err => E.fail(err)));
|
|
99
|
-
}), E.catchTag('ParseError', e => E.die(e)), E.catchTag('NetworkError', e => E.die(e)));
|
|
100
|
-
};
|
|
101
|
-
//# sourceMappingURL=client.js.map
|