@passlock/client 0.9.32 → 2.0.0-beta.2
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 -23
- 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 -72
- 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 -25
- 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 -77
- package/dist/registration/register.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 -16
- package/dist/rpc/connection.js.map +0 -1
- package/dist/rpc/passkey/authentication.d.ts +0 -8
- package/dist/rpc/passkey/authentication.js +0 -17
- package/dist/rpc/passkey/authentication.js.map +0 -1
- package/dist/rpc/passkey/registration.d.ts +0 -8
- package/dist/rpc/passkey/registration.js +0 -17
- package/dist/rpc/passkey/registration.js.map +0 -1
- package/dist/rpc/social.d.ts +0 -10
- package/dist/rpc/social.js +0 -19
- package/dist/rpc/social.js.map +0 -1
- package/dist/rpc/user.d.ts +0 -8
- package/dist/rpc/user.js +0 -20
- package/dist/rpc/user.js.map +0 -1
- package/dist/social/social.d.ts +0 -23
- 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 -38
- 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 -37
- 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 -143
- 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 -156
- package/src/rpc/client.ts +0 -174
- package/src/rpc/config.ts +0 -18
- package/src/rpc/connection.ts +0 -32
- package/src/rpc/passkey/authentication.ts +0 -52
- package/src/rpc/passkey/registration.ts +0 -52
- package/src/rpc/social.ts +0 -55
- package/src/rpc/user.ts +0 -68
- package/src/social/social.fixture.ts +0 -44
- package/src/social/social.test.ts +0 -179
- package/src/social/social.ts +0 -79
- 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 -71
- package/src/version.ts +0 -1
package/src/rpc/client.ts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import * as S from '@effect/schema/Schema'
|
|
2
|
-
import { Context, Effect as E, Layer, pipe } from 'effect'
|
|
3
|
-
|
|
4
|
-
import { NetworkError } from '@passlock/shared/dist/error/error.js'
|
|
5
|
-
|
|
6
|
-
import { PASSLOCK_CLIENT_VERSION } from '../version.js'
|
|
7
|
-
import { RetrySchedule, RpcConfig } from './config.js'
|
|
8
|
-
|
|
9
|
-
export type DispatcherResponse = {
|
|
10
|
-
status: number
|
|
11
|
-
body: object
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** To send the JSON to the backend */
|
|
15
|
-
export class Dispatcher extends Context.Tag('@rpc/Dispatcher')<
|
|
16
|
-
Dispatcher,
|
|
17
|
-
{
|
|
18
|
-
get: (path: string) => E.Effect<DispatcherResponse, NetworkError>
|
|
19
|
-
post: (path: string, body: string) => E.Effect<DispatcherResponse, NetworkError>
|
|
20
|
-
}
|
|
21
|
-
>() {}
|
|
22
|
-
|
|
23
|
-
/** Fires off client requests using fetch */
|
|
24
|
-
/** TODO: Write tests */
|
|
25
|
-
/** TODO: Evaluate platform/http client (if now stable) */
|
|
26
|
-
export const DispatcherLive = Layer.effect(
|
|
27
|
-
Dispatcher,
|
|
28
|
-
E.gen(function* (_) {
|
|
29
|
-
const { schedule } = yield* _(RetrySchedule)
|
|
30
|
-
const { tenancyId, clientId, endpoint: maybeEndpoint } = yield* _(RpcConfig)
|
|
31
|
-
|
|
32
|
-
const parseJson = (res: Response, url: string) =>
|
|
33
|
-
E.tryPromise({
|
|
34
|
-
try: () => res.json() as Promise<unknown>,
|
|
35
|
-
catch: e =>
|
|
36
|
-
new NetworkError({
|
|
37
|
-
message: 'Unable to extract json response from ' + url,
|
|
38
|
-
detail: String(e),
|
|
39
|
-
}),
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
// 400 errors are reflected in the RPC response error channel
|
|
43
|
-
// so in network terms they're still "ok"
|
|
44
|
-
const assertNo500s = (res: Response, url: string) => {
|
|
45
|
-
if (res.status >= 500) {
|
|
46
|
-
return E.fail(
|
|
47
|
-
new NetworkError({
|
|
48
|
-
message: 'Received 500 response code from ' + url,
|
|
49
|
-
}),
|
|
50
|
-
)
|
|
51
|
-
} else return E.void
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const parseJsonObject = (json: unknown) => {
|
|
55
|
-
return typeof json === 'object' && json !== null
|
|
56
|
-
? E.succeed(json)
|
|
57
|
-
: E.fail(
|
|
58
|
-
new NetworkError({
|
|
59
|
-
message: `Expected JSON object to be returned from RPC endpoint, actual ${typeof json}`,
|
|
60
|
-
}),
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const buildUrl = (_path: string) => {
|
|
65
|
-
const endpoint = maybeEndpoint || 'https://api.v1.passlock.dev'
|
|
66
|
-
// drop leading /
|
|
67
|
-
const path = _path.replace(/^\//, '')
|
|
68
|
-
return `${endpoint}/${tenancyId}/${path}`
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
get: (path: string) => {
|
|
73
|
-
const effect = E.gen(function* (_) {
|
|
74
|
-
const headers = {
|
|
75
|
-
'Accept': 'application/json',
|
|
76
|
-
'X-CLIENT-ID': clientId,
|
|
77
|
-
'X-PASSLOCK-CLIENT-VERSION': PASSLOCK_CLIENT_VERSION,
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const url = buildUrl(path)
|
|
81
|
-
|
|
82
|
-
const res = yield* _(
|
|
83
|
-
E.tryPromise({
|
|
84
|
-
try: () => fetch(url, { method: 'GET', headers }),
|
|
85
|
-
catch: e =>
|
|
86
|
-
new NetworkError({ message: 'Unable to fetch from ' + url, detail: String(e) }),
|
|
87
|
-
}),
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
const json = yield* _(parseJson(res, url))
|
|
91
|
-
yield* _(assertNo500s(res, url))
|
|
92
|
-
const jsonObject = yield* _(parseJsonObject(json))
|
|
93
|
-
|
|
94
|
-
return { status: res.status, body: jsonObject }
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
return E.retry(effect, { schedule })
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
post: (_path: string, body: string) => {
|
|
101
|
-
const effect = E.gen(function* (_) {
|
|
102
|
-
const headers = {
|
|
103
|
-
'Content-Type': 'application/json',
|
|
104
|
-
'Accept': 'application/json',
|
|
105
|
-
'X-CLIENT-ID': clientId,
|
|
106
|
-
'X-PASSLOCK-CLIENT-VERSION': PASSLOCK_CLIENT_VERSION,
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// drop leading /
|
|
110
|
-
const url = buildUrl(_path)
|
|
111
|
-
|
|
112
|
-
const res = yield* _(
|
|
113
|
-
E.tryPromise({
|
|
114
|
-
try: () => fetch(url, { method: 'POST', headers, body }),
|
|
115
|
-
catch: e =>
|
|
116
|
-
new NetworkError({ message: 'Unable to fetch from ' + url, detail: String(e) }),
|
|
117
|
-
}),
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
const json = yield* _(parseJson(res, url))
|
|
121
|
-
yield* _(assertNo500s(res, url))
|
|
122
|
-
const jsonObject = yield* _(parseJsonObject(json))
|
|
123
|
-
|
|
124
|
-
return { status: res.status, body: jsonObject }
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
return E.retry(effect, { schedule })
|
|
128
|
-
},
|
|
129
|
-
}
|
|
130
|
-
}),
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
export const makeGetRequest =
|
|
134
|
-
<Res, ResEnc, Err, ErrEnc>(
|
|
135
|
-
responseSchema: S.Schema<Res, ResEnc, never>,
|
|
136
|
-
errorSchema: S.Schema<Err, ErrEnc, never>,
|
|
137
|
-
dispatcher: Dispatcher['Type'],
|
|
138
|
-
) =>
|
|
139
|
-
(path: string) =>
|
|
140
|
-
pipe(
|
|
141
|
-
dispatcher.get(path),
|
|
142
|
-
E.flatMap(res => {
|
|
143
|
-
if (res.status === 200) return S.decodeUnknown(responseSchema)(res.body)
|
|
144
|
-
return pipe(
|
|
145
|
-
S.decodeUnknown(errorSchema)(res.body),
|
|
146
|
-
E.flatMap(err => E.fail(err)),
|
|
147
|
-
)
|
|
148
|
-
}),
|
|
149
|
-
E.catchTag('ParseError', e => E.die(e)),
|
|
150
|
-
E.catchTag('NetworkError', e => E.die(e)),
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
export const makePostRequest =
|
|
154
|
-
<Req, ReqEnc, Res, ResEnc, Err, ErrEnc>(
|
|
155
|
-
requestSchema: S.Schema<Req, ReqEnc, never>,
|
|
156
|
-
responseSchema: S.Schema<Res, ResEnc, never>,
|
|
157
|
-
errorSchema: S.Schema<Err, ErrEnc, never>,
|
|
158
|
-
dispatcher: Dispatcher['Type'],
|
|
159
|
-
) =>
|
|
160
|
-
(path: string, request: Req) => {
|
|
161
|
-
return pipe(
|
|
162
|
-
S.encode(requestSchema)(request),
|
|
163
|
-
E.flatMap(request => dispatcher.post(path, JSON.stringify(request))),
|
|
164
|
-
E.flatMap(res => {
|
|
165
|
-
if (res.status === 200) return S.decodeUnknown(responseSchema)(res.body)
|
|
166
|
-
return pipe(
|
|
167
|
-
S.decodeUnknown(errorSchema)(res.body),
|
|
168
|
-
E.flatMap(err => E.fail(err)),
|
|
169
|
-
)
|
|
170
|
-
}),
|
|
171
|
-
E.catchTag('ParseError', e => E.die(e)),
|
|
172
|
-
E.catchTag('NetworkError', e => E.die(e)),
|
|
173
|
-
)
|
|
174
|
-
}
|
package/src/rpc/config.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Schedule } from 'effect'
|
|
2
|
-
import { Context } from 'effect'
|
|
3
|
-
|
|
4
|
-
export class RpcConfig extends Context.Tag('@rpc/RpcConfig')<
|
|
5
|
-
RpcConfig,
|
|
6
|
-
{
|
|
7
|
-
endpoint?: string
|
|
8
|
-
tenancyId: string
|
|
9
|
-
clientId: string
|
|
10
|
-
}
|
|
11
|
-
>() {}
|
|
12
|
-
|
|
13
|
-
export class RetrySchedule extends Context.Tag('@rpc/RetrySchedule')<
|
|
14
|
-
RetrySchedule,
|
|
15
|
-
{
|
|
16
|
-
schedule: Schedule.Schedule<unknown>
|
|
17
|
-
}
|
|
18
|
-
>() {}
|
package/src/rpc/connection.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as S from '@effect/schema/Schema'
|
|
2
|
-
import { Context, Effect as E, Layer } from 'effect'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
CONNECT_ENDPOINT,
|
|
6
|
-
ConnectResponse,
|
|
7
|
-
type ConnectionService,
|
|
8
|
-
} from '@passlock/shared/dist/rpc/connection.js'
|
|
9
|
-
|
|
10
|
-
import { Dispatcher, makeGetRequest } from './client.js'
|
|
11
|
-
|
|
12
|
-
/* Client */
|
|
13
|
-
|
|
14
|
-
export class ConnectionClient extends Context.Tag('@connection/client')<
|
|
15
|
-
ConnectionClient,
|
|
16
|
-
ConnectionService
|
|
17
|
-
>() {}
|
|
18
|
-
|
|
19
|
-
export const ConnectionClientLive = Layer.effect(
|
|
20
|
-
ConnectionClient,
|
|
21
|
-
E.gen(function* (_) {
|
|
22
|
-
const dispatcher = yield* _(Dispatcher)
|
|
23
|
-
|
|
24
|
-
const preConnectResolver = makeGetRequest(ConnectResponse, S.Never, dispatcher)
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
preConnect: () => preConnectResolver(CONNECT_ENDPOINT),
|
|
28
|
-
}
|
|
29
|
-
}),
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
export { ConnectResponse } from '@passlock/shared/dist/rpc/connection.js'
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Context, Effect as E, Layer } from 'effect'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
type AuthenticationService,
|
|
5
|
-
OPTIONS_ENDPOINT,
|
|
6
|
-
OptionsErrors,
|
|
7
|
-
OptionsRequest,
|
|
8
|
-
OptionsResponse,
|
|
9
|
-
VERIFICATION_ENDPOINT,
|
|
10
|
-
VerificationErrors,
|
|
11
|
-
VerificationRequest,
|
|
12
|
-
VerificationResponse,
|
|
13
|
-
} from '@passlock/shared/dist/rpc/passkey/authentication.js'
|
|
14
|
-
|
|
15
|
-
import { Dispatcher, makePostRequest } from '../client.js'
|
|
16
|
-
|
|
17
|
-
/* Client */
|
|
18
|
-
|
|
19
|
-
export class AuthenticationClient extends Context.Tag('@passkey/authentication/client')<
|
|
20
|
-
AuthenticationClient,
|
|
21
|
-
AuthenticationService
|
|
22
|
-
>() { }
|
|
23
|
-
|
|
24
|
-
export const AuthenticationClientLive = Layer.effect(
|
|
25
|
-
AuthenticationClient,
|
|
26
|
-
E.gen(function* (_) {
|
|
27
|
-
const dispatcher = yield* _(Dispatcher)
|
|
28
|
-
|
|
29
|
-
const optionsResolver = makePostRequest(OptionsRequest, OptionsResponse, OptionsErrors, dispatcher)
|
|
30
|
-
|
|
31
|
-
const verifyResolver = makePostRequest(
|
|
32
|
-
VerificationRequest,
|
|
33
|
-
VerificationResponse,
|
|
34
|
-
VerificationErrors,
|
|
35
|
-
dispatcher,
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
getAuthenticationOptions: req => optionsResolver(OPTIONS_ENDPOINT, req),
|
|
40
|
-
verifyAuthenticationCredential: req => verifyResolver(VERIFICATION_ENDPOINT, req),
|
|
41
|
-
}
|
|
42
|
-
}),
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
export {
|
|
46
|
-
OptionsErrors,
|
|
47
|
-
OptionsRequest,
|
|
48
|
-
OptionsResponse,
|
|
49
|
-
VerificationErrors,
|
|
50
|
-
VerificationRequest,
|
|
51
|
-
VerificationResponse,
|
|
52
|
-
} from '@passlock/shared/dist/rpc/passkey/authentication.js'
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Context, Effect as E, Layer } from 'effect'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
OptionsErrors,
|
|
5
|
-
OptionsRequest,
|
|
6
|
-
OptionsResponse,
|
|
7
|
-
type RegistrationService,
|
|
8
|
-
VerificationErrors,
|
|
9
|
-
VerificationRequest,
|
|
10
|
-
VerificationResponse,
|
|
11
|
-
OPTIONS_ENDPOINT,
|
|
12
|
-
VERIFICATION_ENDPOINT
|
|
13
|
-
} from '@passlock/shared/dist/rpc/passkey/registration.js'
|
|
14
|
-
|
|
15
|
-
import { Dispatcher, makePostRequest } from '../client.js'
|
|
16
|
-
|
|
17
|
-
/* Client */
|
|
18
|
-
|
|
19
|
-
export class RegistrationClient extends Context.Tag('@passkey/register/client')<
|
|
20
|
-
RegistrationClient,
|
|
21
|
-
RegistrationService
|
|
22
|
-
>() {}
|
|
23
|
-
|
|
24
|
-
export const RegistrationClientLive = Layer.effect(
|
|
25
|
-
RegistrationClient,
|
|
26
|
-
E.gen(function* (_) {
|
|
27
|
-
const dispatcher = yield* _(Dispatcher)
|
|
28
|
-
|
|
29
|
-
const optionsResolver = makePostRequest(OptionsRequest, OptionsResponse, OptionsErrors, dispatcher)
|
|
30
|
-
|
|
31
|
-
const verifyResolver = makePostRequest(
|
|
32
|
-
VerificationRequest,
|
|
33
|
-
VerificationResponse,
|
|
34
|
-
VerificationErrors,
|
|
35
|
-
dispatcher,
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
getRegistrationOptions: req => optionsResolver(OPTIONS_ENDPOINT, req),
|
|
40
|
-
verifyRegistrationCredential: req => verifyResolver(VERIFICATION_ENDPOINT, req),
|
|
41
|
-
}
|
|
42
|
-
}),
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
export {
|
|
46
|
-
OptionsErrors,
|
|
47
|
-
OptionsRequest,
|
|
48
|
-
OptionsResponse,
|
|
49
|
-
VerificationErrors,
|
|
50
|
-
VerificationRequest,
|
|
51
|
-
VerificationResponse,
|
|
52
|
-
} from '@passlock/shared/dist/rpc/passkey/registration.js'
|
package/src/rpc/social.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Context, Effect as E, Layer } from 'effect'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
OIDCRegistrationRequest,
|
|
5
|
-
OIDCRegistrationErrors,
|
|
6
|
-
OIDCAuthenticationRequest,
|
|
7
|
-
OIDCAuthenticationErrors,
|
|
8
|
-
OIDC_REGISTRATION_ENDPOINT,
|
|
9
|
-
OIDC_AUTHENTICATION_ENDPOINT,
|
|
10
|
-
PrincipalResponse,
|
|
11
|
-
type SocialService
|
|
12
|
-
} from '@passlock/shared/dist/rpc/social.js'
|
|
13
|
-
|
|
14
|
-
import { Dispatcher, makePostRequest } from './client.js'
|
|
15
|
-
|
|
16
|
-
/* Client */
|
|
17
|
-
|
|
18
|
-
export const OIDC_REGISTER_ENDPOINT = '/social/oidc/register'
|
|
19
|
-
export const OIDC_AUTH_ENDPOINT = '/social/oidc/auth'
|
|
20
|
-
|
|
21
|
-
export class SocialClient extends Context.Tag('@social/client')<SocialClient, SocialService>() {}
|
|
22
|
-
|
|
23
|
-
export const SocialClientLive = Layer.effect(
|
|
24
|
-
SocialClient,
|
|
25
|
-
E.gen(function* (_) {
|
|
26
|
-
const dispatcher = yield* _(Dispatcher)
|
|
27
|
-
|
|
28
|
-
const registerResolver = makePostRequest(
|
|
29
|
-
OIDCRegistrationRequest,
|
|
30
|
-
PrincipalResponse,
|
|
31
|
-
OIDCRegistrationErrors,
|
|
32
|
-
dispatcher,
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
const authenticateResolver = makePostRequest(
|
|
36
|
-
OIDCAuthenticationRequest,
|
|
37
|
-
PrincipalResponse,
|
|
38
|
-
OIDCAuthenticationErrors,
|
|
39
|
-
dispatcher,
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
oidcRegistration: req => registerResolver(OIDC_REGISTRATION_ENDPOINT, req),
|
|
44
|
-
oidcAuthentication: req => authenticateResolver(OIDC_AUTHENTICATION_ENDPOINT, req),
|
|
45
|
-
}
|
|
46
|
-
}),
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
export {
|
|
50
|
-
OIDCRegistrationRequest,
|
|
51
|
-
OIDCRegistrationErrors,
|
|
52
|
-
OIDCAuthenticationRequest,
|
|
53
|
-
OIDCAuthenticationErrors,
|
|
54
|
-
PrincipalResponse,
|
|
55
|
-
} from '@passlock/shared/dist/rpc/social.js'
|
package/src/rpc/user.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import * as S from '@effect/schema/Schema'
|
|
2
|
-
import { Context, Effect as E, Layer } from 'effect'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
IsExistingUserRequest,
|
|
6
|
-
IsExistingUserResponse,
|
|
7
|
-
RESEND_EMAIL_ENDPOINT,
|
|
8
|
-
ResendEmailErrors,
|
|
9
|
-
ResendEmailRequest,
|
|
10
|
-
ResendEmailResponse,
|
|
11
|
-
USER_STATUS_ENDPOINT,
|
|
12
|
-
type UserService,
|
|
13
|
-
VERIFY_EMAIL_ENDPOINT,
|
|
14
|
-
VerifyEmailErrors,
|
|
15
|
-
VerifyEmailRequest,
|
|
16
|
-
VerifyEmailResponse,
|
|
17
|
-
} from '@passlock/shared/dist/rpc/user.js'
|
|
18
|
-
|
|
19
|
-
import { Dispatcher, makePostRequest } from './client.js'
|
|
20
|
-
|
|
21
|
-
/* Client */
|
|
22
|
-
|
|
23
|
-
export class UserClient extends Context.Tag('@user/client')<UserClient, UserService>() {}
|
|
24
|
-
|
|
25
|
-
export const UserClientLive = Layer.effect(
|
|
26
|
-
UserClient,
|
|
27
|
-
E.gen(function* (_) {
|
|
28
|
-
const dispatcher = yield* _(Dispatcher)
|
|
29
|
-
|
|
30
|
-
const isExistingUserResolver = makePostRequest(
|
|
31
|
-
IsExistingUserRequest,
|
|
32
|
-
IsExistingUserResponse,
|
|
33
|
-
S.Never,
|
|
34
|
-
dispatcher,
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
const verifyEmailResolver = makePostRequest(
|
|
38
|
-
VerifyEmailRequest,
|
|
39
|
-
VerifyEmailResponse,
|
|
40
|
-
VerifyEmailErrors,
|
|
41
|
-
dispatcher,
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
const resendEmailResolver = makePostRequest(
|
|
45
|
-
ResendEmailRequest,
|
|
46
|
-
ResendEmailResponse,
|
|
47
|
-
ResendEmailErrors,
|
|
48
|
-
dispatcher,
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
isExistingUser: req => isExistingUserResolver(USER_STATUS_ENDPOINT, req),
|
|
53
|
-
verifyEmail: req => verifyEmailResolver(VERIFY_EMAIL_ENDPOINT, req),
|
|
54
|
-
resendVerificationEmail: req => resendEmailResolver(RESEND_EMAIL_ENDPOINT, req),
|
|
55
|
-
}
|
|
56
|
-
}),
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
export {
|
|
60
|
-
IsExistingUserRequest,
|
|
61
|
-
IsExistingUserResponse,
|
|
62
|
-
ResendEmailErrors,
|
|
63
|
-
ResendEmailRequest,
|
|
64
|
-
ResendEmailResponse,
|
|
65
|
-
VerifyEmailErrors,
|
|
66
|
-
VerifyEmailRequest,
|
|
67
|
-
VerifyEmailResponse,
|
|
68
|
-
} from '@passlock/shared/dist/rpc/user.js'
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Effect as E, Layer as L, Option as O } from 'effect'
|
|
2
|
-
|
|
3
|
-
import * as Fixtures from '../test/fixtures.js'
|
|
4
|
-
import { SocialClient } from '../rpc/social.js'
|
|
5
|
-
import type { AuthenticateOidcReq } from './social.js'
|
|
6
|
-
import { OIDCAuthenticationRequest, OIDCRegistrationRequest, PrincipalResponse } from '@passlock/shared/dist/rpc/social.js'
|
|
7
|
-
|
|
8
|
-
export const session = 'session'
|
|
9
|
-
export const token = 'token'
|
|
10
|
-
export const code = 'code'
|
|
11
|
-
export const authType = 'passkey'
|
|
12
|
-
export const expireAt = Date.now() + 10000
|
|
13
|
-
|
|
14
|
-
export const registerOidcReq = new OIDCRegistrationRequest({
|
|
15
|
-
provider: 'google',
|
|
16
|
-
idToken: 'google-token',
|
|
17
|
-
nonce: 'nonce',
|
|
18
|
-
givenName: O.some('john'),
|
|
19
|
-
familyName: O.some('doe'),
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
export const authOidcReq: AuthenticateOidcReq = new OIDCAuthenticationRequest({
|
|
23
|
-
provider: 'google',
|
|
24
|
-
idToken: 'google-token',
|
|
25
|
-
nonce: 'nonce',
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
export const rpcRegisterRes = new PrincipalResponse({ principal: Fixtures.principal })
|
|
29
|
-
|
|
30
|
-
export const rpcAuthenticateRes = new PrincipalResponse({ principal: Fixtures.principal })
|
|
31
|
-
|
|
32
|
-
export const rpcClientTest = L.succeed(
|
|
33
|
-
SocialClient,
|
|
34
|
-
SocialClient.of({
|
|
35
|
-
oidcRegistration: () => E.fail(Fixtures.notImplemented),
|
|
36
|
-
oidcAuthentication: () => E.fail(Fixtures.notImplemented),
|
|
37
|
-
}),
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
export const principal = Fixtures.principal
|
|
41
|
-
|
|
42
|
-
export const capabilitiesTest = Fixtures.capabilitiesTest
|
|
43
|
-
|
|
44
|
-
export const storageServiceTest = Fixtures.storageServiceTest
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { Effect as E, Layer as L, Layer, LogLevel, Logger, pipe } from 'effect'
|
|
2
|
-
import { describe, expect, test } from 'vitest'
|
|
3
|
-
import { mock } from 'vitest-mock-extended'
|
|
4
|
-
|
|
5
|
-
import { Duplicate, NotFound } from '@passlock/shared/dist/error/error.js'
|
|
6
|
-
|
|
7
|
-
import * as Fixture from './social.fixture.js'
|
|
8
|
-
import { SocialClient } from '../rpc/social.js'
|
|
9
|
-
import { SocialService, SocialServiceLive } from './social.js'
|
|
10
|
-
|
|
11
|
-
describe('registerOidc should', () => {
|
|
12
|
-
test('return a valid credential', async () => {
|
|
13
|
-
const assertions = E.gen(function* (_) {
|
|
14
|
-
const service = yield* _(SocialService)
|
|
15
|
-
const result = yield* _(service.registerOidc(Fixture.registerOidcReq))
|
|
16
|
-
expect(result).toEqual(Fixture.principal)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const rpcClientTest = L.effect(
|
|
20
|
-
SocialClient,
|
|
21
|
-
E.sync(() => {
|
|
22
|
-
const rpcMock = mock<SocialClient['Type']>()
|
|
23
|
-
|
|
24
|
-
rpcMock.oidcRegistration.mockReturnValue(E.succeed(Fixture.rpcRegisterRes))
|
|
25
|
-
|
|
26
|
-
return rpcMock
|
|
27
|
-
}),
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
const service = pipe(SocialServiceLive, L.provide(rpcClientTest))
|
|
31
|
-
|
|
32
|
-
const layers = Layer.merge(service, rpcClientTest)
|
|
33
|
-
const effect = pipe(E.provide(assertions, layers), Logger.withMinimumLogLevel(LogLevel.None))
|
|
34
|
-
|
|
35
|
-
return E.runPromise(effect)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
test('pass the request to the backend', async () => {
|
|
39
|
-
const assertions = E.gen(function* (_) {
|
|
40
|
-
const service = yield* _(SocialService)
|
|
41
|
-
yield* _(service.registerOidc(Fixture.registerOidcReq))
|
|
42
|
-
|
|
43
|
-
const rpcClient = yield* _(SocialClient)
|
|
44
|
-
expect(rpcClient.oidcRegistration).toHaveBeenCalledWith(Fixture.registerOidcReq)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
const rpcClientTest = L.effect(
|
|
48
|
-
SocialClient,
|
|
49
|
-
E.sync(() => {
|
|
50
|
-
const rpcMock = mock<SocialClient['Type']>()
|
|
51
|
-
|
|
52
|
-
rpcMock.oidcRegistration.mockReturnValue(E.succeed(Fixture.rpcRegisterRes))
|
|
53
|
-
|
|
54
|
-
return rpcMock
|
|
55
|
-
}),
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
const service = pipe(SocialServiceLive, L.provide(rpcClientTest))
|
|
59
|
-
|
|
60
|
-
const layers = Layer.merge(service, rpcClientTest)
|
|
61
|
-
const effect = pipe(E.provide(assertions, layers), Logger.withMinimumLogLevel(LogLevel.None))
|
|
62
|
-
|
|
63
|
-
return E.runPromise(effect)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test('return an error if we try to register an existing user', async () => {
|
|
67
|
-
const assertions = E.gen(function* (_) {
|
|
68
|
-
const service = yield* _(SocialService)
|
|
69
|
-
|
|
70
|
-
const defect = yield* _(service.registerOidc(Fixture.registerOidcReq), E.flip)
|
|
71
|
-
|
|
72
|
-
expect(defect).toBeInstanceOf(Duplicate)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
const rpcClientTest = L.effect(
|
|
76
|
-
SocialClient,
|
|
77
|
-
E.sync(() => {
|
|
78
|
-
const rpcMock = mock<SocialClient['Type']>()
|
|
79
|
-
|
|
80
|
-
rpcMock.oidcRegistration.mockReturnValue(E.fail(new Duplicate({ message: 'Duplicate user' })))
|
|
81
|
-
|
|
82
|
-
return rpcMock
|
|
83
|
-
}),
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
const service = pipe(SocialServiceLive, L.provide(rpcClientTest))
|
|
87
|
-
|
|
88
|
-
const layers = Layer.merge(service, rpcClientTest)
|
|
89
|
-
const effect = pipe(E.provide(assertions, layers), Logger.withMinimumLogLevel(LogLevel.None))
|
|
90
|
-
|
|
91
|
-
return E.runPromise(effect)
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
describe('authenticateIodc should', () => {
|
|
96
|
-
test('return a valid credential', async () => {
|
|
97
|
-
const assertions = E.gen(function* (_) {
|
|
98
|
-
const service = yield* _(SocialService)
|
|
99
|
-
const result = yield* _(service.authenticateOidc(Fixture.authOidcReq))
|
|
100
|
-
expect(result).toEqual(Fixture.principal)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
const rpcClientTest = L.effect(
|
|
104
|
-
SocialClient,
|
|
105
|
-
E.sync(() => {
|
|
106
|
-
const rpcMock = mock<SocialClient['Type']>()
|
|
107
|
-
|
|
108
|
-
rpcMock.oidcAuthentication.mockReturnValue(E.succeed(Fixture.rpcRegisterRes))
|
|
109
|
-
|
|
110
|
-
return rpcMock
|
|
111
|
-
}),
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
const service = pipe(SocialServiceLive, L.provide(rpcClientTest))
|
|
115
|
-
|
|
116
|
-
const layers = Layer.merge(service, rpcClientTest)
|
|
117
|
-
const effect = pipe(E.provide(assertions, layers), Logger.withMinimumLogLevel(LogLevel.None))
|
|
118
|
-
|
|
119
|
-
return E.runPromise(effect)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
test('pass the request to the backend', async () => {
|
|
123
|
-
const assertions = E.gen(function* (_) {
|
|
124
|
-
const service = yield* _(SocialService)
|
|
125
|
-
yield* _(service.authenticateOidc(Fixture.authOidcReq))
|
|
126
|
-
|
|
127
|
-
const rpcClient = yield* _(SocialClient)
|
|
128
|
-
expect(rpcClient.oidcAuthentication).toHaveBeenCalledWith(Fixture.authOidcReq)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
const rpcClientTest = L.effect(
|
|
132
|
-
SocialClient,
|
|
133
|
-
E.sync(() => {
|
|
134
|
-
const rpcMock = mock<SocialClient['Type']>()
|
|
135
|
-
|
|
136
|
-
rpcMock.oidcAuthentication.mockReturnValue(E.succeed(Fixture.rpcAuthenticateRes))
|
|
137
|
-
|
|
138
|
-
return rpcMock
|
|
139
|
-
}),
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
const service = pipe(SocialServiceLive, L.provide(rpcClientTest))
|
|
143
|
-
|
|
144
|
-
const layers = Layer.merge(service, rpcClientTest)
|
|
145
|
-
const effect = pipe(E.provide(assertions, layers), Logger.withMinimumLogLevel(LogLevel.None))
|
|
146
|
-
|
|
147
|
-
return E.runPromise(effect)
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
test('return an error if we try to authenticate a non-existing user', async () => {
|
|
151
|
-
const assertions = E.gen(function* (_) {
|
|
152
|
-
const service = yield* _(SocialService)
|
|
153
|
-
|
|
154
|
-
const defect = yield* _(service.authenticateOidc(Fixture.authOidcReq), E.flip)
|
|
155
|
-
|
|
156
|
-
expect(defect).toBeInstanceOf(NotFound)
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
const rpcClientTest = L.effect(
|
|
160
|
-
SocialClient,
|
|
161
|
-
E.sync(() => {
|
|
162
|
-
const rpcMock = mock<SocialClient['Type']>()
|
|
163
|
-
|
|
164
|
-
rpcMock.oidcAuthentication.mockReturnValue(
|
|
165
|
-
E.fail(new NotFound({ message: 'User not found' })),
|
|
166
|
-
)
|
|
167
|
-
|
|
168
|
-
return rpcMock
|
|
169
|
-
}),
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
const service = pipe(SocialServiceLive, L.provide(rpcClientTest))
|
|
173
|
-
|
|
174
|
-
const layers = Layer.merge(service, rpcClientTest)
|
|
175
|
-
const effect = pipe(E.provide(assertions, layers), Logger.withMinimumLogLevel(LogLevel.None))
|
|
176
|
-
|
|
177
|
-
return E.runPromise(effect)
|
|
178
|
-
})
|
|
179
|
-
})
|